fanli/src/main/java/com/yeshi/fanli/aspect/AdminLoginAspect.java
@@ -1,121 +1,121 @@ package com.yeshi.fanli.aspect; import java.io.IOException; import java.lang.reflect.Method; import java.net.URLDecoder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.yeshi.utils.JsonUtil; import com.yeshi.fanli.entity.common.AdminUser; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.AdminUserService; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.annotation.RequestNoLogin; import net.sf.json.JSONObject; @Component @Aspect public class AdminLoginAspect { @Resource private AdminUserService adminUserService; // @Around("execution(public * com.yeshi.fanli.controller.admin..*.*(..))") public Object verifyLoginState(ProceedingJoinPoint joinPoint) throws IOException { Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method targetMethod = methodSignature.getMethod(); ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); HttpServletRequest request = servletContainer.getRequest(); AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); if (admin == null) { String from = request.getParameter("from"); // 邮件H5来源的不判断是否登录 if ("emailh5".equalsIgnoreCase(from)) { String callback = request.getParameter("callback"); String signAES = request.getParameter("sign"); if (signAES != null && signAES.contains("%")) signAES = URLDecoder.decode(request.getParameter("sign"), "UTF-8"); String sign = AESUtil.decrypt(signAES, Constant.ADMINH5_AESKEY); if (!StringUtil.isNullOrEmpty(sign)) { LogHelper.error("H5审核签名:" + sign); JSONObject json = JSONObject.fromObject(sign); long time = json.optLong("timeStamp"); long adminId = json.optLong("adminId"); AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId); // 1个小时链接失效 if (System.currentTimeMillis() - time > 1000 * 60 * 60 || adminUser == null) { servletContainer.getResponse().getWriter() .print(callback + "(" + JsonUtil.loadFalseResult(2, "链接失效") + ")"); return null; } else { request.getSession().setAttribute(Constant.SESSION_ADMIN, adminUser); request.getSession().setAttribute(Constant.SESSION_EXTRACT_VERIFY_RESULT, "1"); } } else { servletContainer.getResponse().getWriter() .print(callback + "(" + JsonUtil.loadFalseResult(3, "链接失效") + ")"); return null; } } else { Method realMethod = null; try { realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), targetMethod.getParameterTypes()); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } // 判断是否有忽略验证的注解 if (realMethod == null || !realMethod.isAnnotationPresent(RequestNoLogin.class)) { HttpServletResponse response = servletContainer.getResponse(); String callback = request.getParameter("callback"); if (StringUtil.isNullOrEmpty(callback)) { response.getWriter().print(JsonUtil.loadFalseResult(1, "请先登录")); } else { response.getWriter().print(callback + "(" + JsonUtil.loadFalseResult(1, "请先登录") + ")"); } return null; } } } Object[] args = joinPoint.getArgs(); Object obj = null; try { obj = joinPoint.proceed(args); } catch (Throwable e) { e.printStackTrace(); } return obj; } } package com.yeshi.fanli.aspect; import java.io.IOException; import java.lang.reflect.Method; import java.net.URLDecoder; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.Signature; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.yeshi.utils.JsonUtil; import com.yeshi.fanli.entity.common.AdminUser; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.AdminUserService; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.annotation.RequestNoLogin; import net.sf.json.JSONObject; @Component @Aspect public class AdminLoginAspect { @Resource private AdminUserService adminUserService; @Around("execution(public * com.yeshi.fanli.controller.admin..*.*(..))") public Object verifyLoginState(ProceedingJoinPoint joinPoint) throws IOException { Signature signature = joinPoint.getSignature(); MethodSignature methodSignature = (MethodSignature) signature; Method targetMethod = methodSignature.getMethod(); ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder .getRequestAttributes(); HttpServletRequest request = servletContainer.getRequest(); AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN); if (admin == null) { String from = request.getParameter("from"); // 邮件H5来源的不判断是否登录 if ("emailh5".equalsIgnoreCase(from)) { String callback = request.getParameter("callback"); String signAES = request.getParameter("sign"); if (signAES != null && signAES.contains("%")) signAES = URLDecoder.decode(request.getParameter("sign"), "UTF-8"); String sign = AESUtil.decrypt(signAES, Constant.ADMINH5_AESKEY); if (!StringUtil.isNullOrEmpty(sign)) { LogHelper.error("H5审核签名:" + sign); JSONObject json = JSONObject.fromObject(sign); long time = json.optLong("timeStamp"); long adminId = json.optLong("adminId"); AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId); // 1个小时链接失效 if (System.currentTimeMillis() - time > 1000 * 60 * 60 || adminUser == null) { servletContainer.getResponse().getWriter() .print(callback + "(" + JsonUtil.loadFalseResult(2, "链接失效") + ")"); return null; } else { request.getSession().setAttribute(Constant.SESSION_ADMIN, adminUser); request.getSession().setAttribute(Constant.SESSION_EXTRACT_VERIFY_RESULT, "1"); } } else { servletContainer.getResponse().getWriter() .print(callback + "(" + JsonUtil.loadFalseResult(3, "链接失效") + ")"); return null; } } else { Method realMethod = null; try { realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), targetMethod.getParameterTypes()); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } // 判断是否有忽略验证的注解 if (realMethod == null || !realMethod.isAnnotationPresent(RequestNoLogin.class)) { HttpServletResponse response = servletContainer.getResponse(); String callback = request.getParameter("callback"); if (StringUtil.isNullOrEmpty(callback)) { response.getWriter().print(JsonUtil.loadFalseResult(1, "请先登录")); } else { response.getWriter().print(callback + "(" + JsonUtil.loadFalseResult(1, "请先登录") + ")"); } return null; } } } Object[] args = joinPoint.getArgs(); Object obj = null; try { obj = joinPoint.proceed(args); } catch (Throwable e) { e.printStackTrace(); } return obj; } } fanli/src/main/java/com/yeshi/fanli/controller/admin/GoodsEvaluateAdminController.java
@@ -1,6 +1,7 @@ package com.yeshi.fanli.controller.admin; import java.io.PrintWriter; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -16,11 +17,18 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.yeshi.fanli.dto.ConfigParamsDTO; import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.entity.dynamic.CommentInfo; import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate; import com.yeshi.fanli.entity.dynamic.ImgInfo; import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum; import com.yeshi.fanli.entity.goods.CommonGoods; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.dynamic.GoodsEvaluateException; import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.manger.ClipboardAnalysisManager; @@ -31,6 +39,9 @@ import com.yeshi.fanli.util.TimeUtil; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil; import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import net.sf.json.JSONObject; @@ -113,7 +124,28 @@ e.printStackTrace(); } } /** * 保存信息 * * @param callback * @param special * 0a39676f138c4dcba722e321d43c4284 * @param out */ @RequestMapping(value = "saveGoodsCoupon") public void saveGoodsCoupon(String callback, String pid, String tags, String tagDesc, PrintWriter out) { try { goodsEvaluateService.saveGoodsCoupon(pid, tags, tagDesc); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功")); } catch (GoodsEvaluateException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败")); e.printStackTrace(); } } /** * 保存信息 * @@ -152,42 +184,72 @@ String videoPic = ""; Integer picNum = 1; List<String> list = new ArrayList<String>(); GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getImgList() != null && goodsEvaluate.getImgList().size() > 0) { List<ImgInfo> imgList = goodsEvaluate.getImgList(); for (ImgInfo imgInfo : imgList) { ImgEnum type = imgInfo.getType(); if (type == ImgEnum.video) { videoPic = imgInfo.getUrl(); videoUrl = imgInfo.getVideoUrl(); } else if (type == ImgEnum.goods) { list.add(imgInfo.getUrl()); goodsId = imgInfo.getGoods().getGoodsId().toString(); goodsType = imgInfo.getGoods().getGoodsType().toString(); } else if (type == ImgEnum.img) { list.add(imgInfo.getUrl()); if (!StringUtil.isNullOrEmpty(pid)) { GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getImgList() != null && goodsEvaluate.getImgList().size() > 0) { List<ImgInfo> imgList = goodsEvaluate.getImgList(); for (ImgInfo imgInfo : imgList) { ImgEnum type = imgInfo.getType(); if (type == ImgEnum.video) { videoPic = imgInfo.getUrl(); videoUrl = imgInfo.getVideoUrl(); } else if (type == ImgEnum.goods) { list.add(imgInfo.getUrl()); goodsId = imgInfo.getGoods().getGoodsId().toString(); goodsType = imgInfo.getGoods().getGoodsType().toString(); } else if (type == ImgEnum.img) { list.add(imgInfo.getUrl()); } } picNum = goodsEvaluate.getMainPicNum(); } picNum = goodsEvaluate.getMainPicNum(); } JSONObject data = new JSONObject(); data.put("goodsId", goodsId); data.put("goodsType", goodsType); data.put("videoUrl", videoUrl); data.put("videoPic", videoPic); data.put("picNum", picNum); data.put("list", list); data.put("goodsId", goodsId); data.put("goodsType", goodsType); data.put("videoUrl", videoUrl); data.put("videoPic", videoPic); data.put("picNum", picNum); data.put("list", list); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败")); e.printStackTrace(); } } /** * 获取信息 * * @param callback * @param special * 0a39676f138c4dcba722e321d43c4284 * @param out */ @RequestMapping(value = "getCurrencyCoupon") public void getCurrencyCoupon(String callback, String pid, PrintWriter out) { try { CommentInfo commentInfo = new CommentInfo(); if (!StringUtil.isNullOrEmpty(pid)) { GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getComments() != null && goodsEvaluate.getComments().size() > 0) { for (CommentInfo info : goodsEvaluate.getComments()) { if (CommentInfoEnum.currencyCoupon == info.getType()) { commentInfo = info; } } } } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(commentInfo)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败")); e.printStackTrace(); } } /** * 获取信息 * @@ -200,9 +262,16 @@ public void getSingleGoodsCoupon(String callback, String pid, PrintWriter out) { try { CommentInfo commentInfo = new CommentInfo(); GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getComments() != null && goodsEvaluate.getComments().size() > 0) { commentInfo = goodsEvaluate.getComments().get(0); if (!StringUtil.isNullOrEmpty(pid)) { GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getComments() != null && goodsEvaluate.getComments().size() > 0) { for (CommentInfo info : goodsEvaluate.getComments()) { if (CommentInfoEnum.goodsCoupon == info.getType()) { commentInfo = info; } } } } JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(commentInfo)); } catch (Exception e) { @@ -211,7 +280,72 @@ } } /** * 保存多个商品 * * @param out */ @RequestMapping(value = "saveMultipleGoods") public void saveMultipleGoods(String callback, String pid, String videoUrl, String goodsList, HttpServletRequest request, PrintWriter out) { try { MultipartHttpServletRequest fileRequest = null; if (request instanceof MultipartHttpServletRequest) { fileRequest = (MultipartHttpServletRequest) request; } goodsEvaluateService.saveMultipleGoods(pid, videoUrl, goodsList, fileRequest); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功")); } catch (GoodsEvaluateException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败")); e.printStackTrace(); } } /** * 获取多个商品信息 * * @param out */ @RequestMapping(value = "getMultipleGoods") public void getMultipleGoods(String callback, String pid, PrintWriter out) { try { String videoUrl = ""; String videoPic = ""; List<String> list = new ArrayList<String>(); List<String> goodsList = new ArrayList<String>(); if (!StringUtil.isNullOrEmpty(pid)) { GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(pid); if (goodsEvaluate != null && goodsEvaluate.getImgList() != null && goodsEvaluate.getImgList().size() > 0) { List<ImgInfo> imgList = goodsEvaluate.getImgList(); for (ImgInfo imgInfo : imgList) { ImgEnum type = imgInfo.getType(); if (type == ImgEnum.video) { videoPic = imgInfo.getUrl(); videoUrl = imgInfo.getVideoUrl(); } else if (type == ImgEnum.goods) { list.add(imgInfo.getUrl()); goodsList.add(imgInfo.getGoods().getGoodsId() + "-" + imgInfo.getGoods().getGoodsType()); } } } } JSONObject data = new JSONObject(); data.put("list", list); data.put("goodsList", goodsList); data.put("videoUrl", videoUrl); data.put("videoPic", videoPic); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败")); e.printStackTrace(); } } /** * 保存信息 * @@ -221,8 +355,8 @@ * @param out */ @RequestMapping(value = "saveActivityPic") public void saveActivityPic(String callback, String pid, ImgInfo imgInfo, HttpServletRequest request, PrintWriter out) { public void saveActivityPic(String callback, String pid, ImgInfo imgInfo, HttpServletRequest request, PrintWriter out) { try { MultipartHttpServletRequest fileRequest = null; if (request instanceof MultipartHttpServletRequest) { @@ -269,19 +403,43 @@ } JSONObject data = new JSONObject(); data.put("videoUrl", videoUrl); data.put("videoPic", videoPic); data.put("activityPic", activityPic); data.put("activityUrl", activityUrl); data.put("videoUrl", videoUrl); data.put("videoPic", videoPic); data.put("activityPic", activityPic); data.put("activityUrl", activityUrl); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败")); e.printStackTrace(); } } /** * 保存信息 * * @param callback * @param special * 0a39676f138c4dcba722e321d43c4284 * @param out */ @RequestMapping(value = "saveSuCai") public void saveSuCai(String callback, String pid, String videoUrl, String picUrls, HttpServletRequest request, PrintWriter out) { try { MultipartHttpServletRequest fileRequest = null; if (request instanceof MultipartHttpServletRequest) { fileRequest = (MultipartHttpServletRequest) request; } goodsEvaluateService.saveSuCai(pid, videoUrl, picUrls, fileRequest); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("保存成功")); } catch (GoodsEvaluateException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("保存失败")); e.printStackTrace(); } } /** * 保存信息 * @@ -292,7 +450,10 @@ @RequestMapping(value = "getEvaluate") public void getEvaluate(String callback, String id, PrintWriter out) { try { GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id); GoodsEvaluate goodsEvaluate = null; if (!StringUtil.isNullOrEmpty(id)) { goodsEvaluate = goodsEvaluateService.getById(id); } if (goodsEvaluate == null) goodsEvaluate = new GoodsEvaluate(); @@ -308,10 +469,6 @@ e.printStackTrace(); } } /** * 删除图片以及信息 @@ -364,7 +521,7 @@ } try { List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state); List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 1); if (list == null || list.size() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据")); return; @@ -386,7 +543,64 @@ } } long count = goodsEvaluateService.count(key, state); long count = goodsEvaluateService.count(key, state, 1); int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); JSONObject data = new JSONObject(); data.put("pe", pe); data.put("result_list", list); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常")); e.printStackTrace(); } } /** * 查询 * * @param callback * @param pageIndex * @param pageSize * @param bannerId * @param out */ @RequestMapping(value = "querySuCai") public void querySuCai(String callback, Integer pageIndex, Integer pageSize, String key, Integer state, PrintWriter out) { if (pageIndex == null || pageIndex < 1) { pageIndex = 1; } if (pageSize == null || pageSize < 1) { pageSize = Constant.PAGE_SIZE; } try { List<GoodsEvaluate> list = goodsEvaluateService.query((pageIndex - 1) * pageSize, pageSize, key, state, 2); if (list == null || list.size() == 0) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据")); return; } for (GoodsEvaluate article : list) { Date startTime = article.getStartTime(); if (startTime == null) { article.setStartTimeChar(""); } else { article.setStartTimeChar(TimeUtil.formatDateAddT(startTime)); } Date endTime = article.getEndTime(); if (endTime == null) { article.setEndTimeChar(""); } else { article.setEndTimeChar(TimeUtil.formatDateAddT(endTime)); } } long count = goodsEvaluateService.count(key, state, 2); int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1); PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage); @@ -411,85 +625,44 @@ @RequestMapping(value = "getGoodsByUrl") public void getGoodsByUrl(String callback, String link, PrintWriter out) { try { // CommonGoods commonGoods = // clipboardAnalysisManager.parseLink(link); // if (commonGoods == null) { // JsonUtil.printMode(out, callback, // JsonUtil.loadFalseResult("未找到该商品")); // return; // } // CommonGoods commonGoods = clipboardAnalysisManager.parseLink(link); if (commonGoods == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未找到该商品")); return; } GoodsDetailVO goodsDetail = null; // try { // BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); // BigDecimal shareRate = hongBaoManageService.getShareRate(); // BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate(); // ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, // shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate); // TaoBaoGoodsBrief goodsBrief = // redisManager.getTaoBaoGoodsBrief(596617470742L); // goodsDetail = GoodsDetailVOFactory.convertTaoBao(goodsBrief, // params); // } catch (TaobaoGoodsDownException e) { // JsonUtil.printMode(out, callback, // JsonUtil.loadFalseResult("该商品已下架")); // return; // } BigDecimal fanLiRate = hongBaoManageService.getFanLiRate(); BigDecimal shareRate = hongBaoManageService.getShareRate(); BigDecimal vipFanLiRate = hongBaoManageService.getVIPFanLiRate(); ConfigParamsDTO params = new ConfigParamsDTO(fanLiRate, shareRate, Constant.MAX_REWARD_RATE, vipFanLiRate); // if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { // try { // TaoBaoGoodsBrief goodsBrief = // redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId()); // goodsDetail = GoodsDetailVOFactory.convertTaoBao(goodsBrief, // params); // } catch (TaobaoGoodsDownException e) { // JsonUtil.printMode(out, callback, // JsonUtil.loadFalseResult("该商品已下架")); // return; // } // } else if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_JD) // { // JDGoods goodsInfo = // JDApiUtil.queryGoodsDetail(commonGoods.getGoodsId()); // 高级接口 // if (goodsInfo == null) { // goodsInfo = JDUtil.getGoodsDetail(commonGoods.getGoodsId()); // // 爬取网页 // //jdGoods = JDApiUtil.getGoodsDetail(goodsId); // 普通接口 // } //// JDGoods goodsInfo = // jdGoodsCacheUtil.getGoodsInfo(commonGoods.getGoodsId()); // goodsDetail = GoodsDetailVOFactory.convertJDGoods(goodsInfo, // params); // } else if (commonGoods.getGoodsType() == // Constant.SOURCE_TYPE_PDD) { // PDDGoodsDetail goodsInfo = // pinDuoDuoCacheUtil.getGoodsInfo(commonGoods.getGoodsId()); // goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goodsInfo, // params); // } if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { try { TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId()); goodsDetail = GoodsDetailVOFactory.convertTaoBao(goodsBrief, params); } catch (TaobaoGoodsDownException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("该商品已下架")); return; } } else if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_JD) { JDGoods goodsInfo = jdGoodsCacheUtil.getGoodsInfo(commonGoods.getGoodsId()); goodsDetail = GoodsDetailVOFactory.convertJDGoods(goodsInfo, params); } else if (commonGoods.getGoodsType() == Constant.SOURCE_TYPE_PDD) { PDDGoodsDetail goodsInfo = pinDuoDuoCacheUtil.getGoodsInfo(commonGoods.getGoodsId()); goodsDetail = GoodsDetailVOFactory.convertPDDGoods(goodsInfo, params); } // if (goodsDetail == null) { // JsonUtil.printMode(out, callback, // JsonUtil.loadFalseResult("未找到该商品")); // return; // } List<String> imgList = new ArrayList<>(); imgList.add( "https://img.alicdn.com/bao/uploaded/i1/2578900982/O1CN01SUiNLE1J7nWMlpy1A_!!0-item_pic.jpg_220x220"); imgList.add( "https://img.alicdn.com/bao/uploaded/i1/2398662401/O1CN01I2UoTF1TbhXVwhJrz_!!0-item_pic.jpg_220x220"); imgList.add( "https://img.alicdn.com/bao/uploaded/i4/2640238597/O1CN01A5xBr32DNTYWJSDZe_!!0-item_pic.jpg_220x220"); imgList.add( "https://img.alicdn.com/bao/uploaded/i3/2640238597/O1CN01H5Q0Ni2DNTYxGAy3V_!!0-item_pic.jpg_220x220"); if (goodsDetail == null) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未找到该商品")); return; } JSONObject object = new JSONObject(); object.put("goodsId", 551062664275L); object.put("goodsType", 1); object.put("imgList", imgList); object.put("goodsId", goodsDetail.getGoodsId()); object.put("goodsType", goodsDetail.getGoodsType()); object.put("picUrl",goodsDetail.getPicUrl()); object.put("imgList", goodsDetail.getImgList()); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(object)); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("获取失败")); @@ -551,6 +724,31 @@ } /** * 删除信息 * * @param callback * @param idArray * @param out */ @RequestMapping(value = "release") public void release(String callback, String id, PrintWriter out) { try { if (StringUtil.isNullOrEmpty(id)) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请选择操作的数据")); return; } goodsEvaluateService.release(id); JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("发布成功")); } catch (GoodsEvaluateException e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); } catch (Exception e) { JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("发布失败")); e.printStackTrace(); } } /** * 查询品论 * * @param callback @@ -589,4 +787,3 @@ } } fanli/src/main/java/com/yeshi/fanli/controller/client/v2/DynamicControllerV2.java
@@ -1,954 +1,1030 @@ package com.yeshi.fanli.controller.client.v2; import java.io.PrintWriter; import java.lang.reflect.Type; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.JsonUtil; import org.yeshi.utils.entity.FileUploadResult; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.activity.ActivityUser; import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.bus.homemodule.Special; import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture; import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.common.JumpDetailV2; import com.yeshi.fanli.entity.dynamic.CommentInfo; import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum; import com.yeshi.fanli.entity.dynamic.DynamicInfo; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate; import com.yeshi.fanli.entity.dynamic.GoodsPicture; import com.yeshi.fanli.entity.dynamic.ImgInfo; import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum; import com.yeshi.fanli.entity.dynamic.SimpleGoods; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService; import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService; import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.homemodule.SpecialService; import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.taobao.DaTaoKeUtil; import com.yeshi.fanli.vo.dynamic.ArticleVO; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import com.yeshi.fanli.vo.msg.ClientTextStyleVO; import net.sf.json.JSONObject; /** * 动态 * * @author Administrator * */ @Controller @RequestMapping("api/v2/dynamic") public class DynamicControllerV2 { @Resource private HongBaoManageService hongBaoManageService; @Resource private TaoBaoGoodsBriefService taoBaoGoodsBriefService; @Resource private JumpDetailV2Service jumpDetailV2Service; @Resource private DynamicInfoService dynamicInfoService; @Resource private SpecialService specialService; @Resource private ArticleOfficialService articleOfficialService; @Resource private SwiperPictureService swiperPictureService; @Resource private ConfigService configService; @Resource private GoodsEvaluateService goodsEvaluateService; @Resource private UserInfoService userInfoService; @Resource private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; @Resource private JDGoodsCacheUtil jdGoodsCacheUtil; @Resource private QrCodeService qrCodeService; /** * 查询顶部分类 * * @param acceptData * @param page * @param cid * @param out */ @RequestMapping(value = "getClass", method = RequestMethod.POST) public void getClass(AcceptData acceptData, Integer cid, PrintWriter out) { // ios 只返回子集分类 if (cid != null) { List<GoodsClass> list = new ArrayList<GoodsClass>(); switch (cid) { case 1: list.add(new GoodsClass(0L, "今日单品")); list.addAll(DaTaoKeUtil.goodsClasses); break; case 2: break; case 3: break; case 4: break; case 5: list.add(new GoodsClass(0L, "全部")); list.add(new GoodsClass(1L, "淘宝")); list.add(new GoodsClass(2L, "京东")); list.add(new GoodsClass(3L, "拼多多")); break; default: break; } JSONObject data = new JSONObject(); data.put("list", JsonUtil.getApiCommonGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); return; } // Android 返回分类以及顶部数据 List<GoodsClass> listSub = new ArrayList<GoodsClass>(); listSub.add(new GoodsClass(0L, "今日单品")); listSub.addAll(DaTaoKeUtil.goodsClasses); GoodsClass menu1 = new GoodsClass(1L, "热销"); menu1.setListSub(listSub); GoodsClass menu2 = new GoodsClass(2L, "推荐"); menu2.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu3 = new GoodsClass(3L, "好店"); menu3.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu4 = new GoodsClass(4L, "邀请"); menu4.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu5 = new GoodsClass(5L, "活动"); List<GoodsClass> sub5 = new ArrayList<GoodsClass>(); sub5.add(new GoodsClass(0L, "全部")); sub5.add(new GoodsClass(1L, "淘宝")); sub5.add(new GoodsClass(2L, "京东")); sub5.add(new GoodsClass(3L, "拼多多")); menu5.setListSub(sub5); GoodsClass menu6 = new GoodsClass(6L, "学院"); menu6.setListSub(new ArrayList<GoodsClass>()); List<GoodsClass> list = new ArrayList<GoodsClass>(); list.add(menu1); list.add(menu5); list.add(menu2); // 2.0.5版本隐藏 好店栏目 if (!VersionUtil.greaterThan_2_0_5(acceptData.getPlatform(), acceptData.getVersion())) { list.add(menu3); } // 2.0.6版本增加 学院栏目 if (VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) { // list.add(menu6); } list.add(menu4); JSONObject data = new JSONObject(); data.put("list", JsonUtil.getApiCommonGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 动态商品列表 * * @param acceptData * @param page * @param cid * @param subId * @param out */ @RequestMapping(value = "getList", method = RequestMethod.POST) public void getList(AcceptData acceptData, Integer page, Long cid, Long subId, PrintWriter out) { if (cid == null) { out.print(JsonUtil.loadFalseResult("主分类id不能为空")); return; } if (cid != null) { if (cid == 5) { // 活动主题 getSpecialList(acceptData, page, subId, out); return; } else if (cid == 6) { // 学院 getArticleList(acceptData, page, null, false, out); return; } } long count = 0; int platform = 1; if ("ios".equalsIgnoreCase(acceptData.getPlatform())) { platform = 2; } int version = Integer.parseInt(acceptData.getVersion()); List<DynamicInfo> list = dynamicInfoService.queryV2(platform, version, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (list == null) { list = new ArrayList<DynamicInfo>(); } else { count = dynamicInfoService.count(cid, subId); } JSONObject data = new JSONObject(); data.put("count", count); data.put("list", getGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 活动列表 * * @param acceptData * @param out */ private void getSpecialList(AcceptData acceptData, Integer page, Long subId, PrintWriter out) { if (subId == null) { out.print(JsonUtil.loadFalseResult("分类id不能为空")); return; } // 平台区分 int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); List<String> listKey = new ArrayList<String>(); if (subId == 1) { // 淘宝 listKey.add("special_channel_tb"); } else if (subId == 2) { // 京东 listKey.add("special_channel_jd"); } else if (subId == 3) { // 拼多多 listKey.add("special_channel_pdd"); } else { // 全部 listKey.add("special_channel_tb"); listKey.add("special_channel_jd"); listKey.add("special_channel_pdd"); } List<Special> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, listKey, platformCode, Integer.parseInt(acceptData.getVersion())); long time = System.currentTimeMillis(); // 删除尚未启用的过期的 for (int i = 0; i < list.size(); i++) { Special special = list.get(i); if (special.getState() == 1L) { list.remove(i--); } else { if (special.getStartTime() != null && special.getEndTime() != null) special.setTimeTask(true); else special.setTimeTask(false); if (special.isTimeTask()) { if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { list.remove(i--); } else// 设置倒计时 { special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); } } List<SpecialLabel> listLabels = special.getListLabels(); if (listLabels != null && !listLabels.isEmpty()) { List<ClientTextStyleVO> labels = new ArrayList<>(); for (SpecialLabel specialLabel : listLabels) { labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); } special.setLabels(labels); } } } long count = specialService.countByPlaceKeyList(listKey, platformCode, Integer.parseInt(acceptData.getVersion())); GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 时间处理 * * @return */ private Gson getGson() { GsonBuilder gb = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()); gb.excludeFieldsWithoutExposeAnnotation(); gb.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { if (d1 == d2) { long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { desc = "昨天"; } else { desc = (d2 - d1) + "天前"; } } else { int timeDistance = 0; for (int i = y1; i < y2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { timeDistance += 366; // 闰年 } else { timeDistance += 365; // 不是闰年 } } desc = timeDistance + (d2 - d1) + "天前"; } return new JsonPrimitive(desc); } return new JsonPrimitive(""); } }); Gson gson = gb.create(); return gson; } /** * 活动列表 * * @param acceptData * @param out */ private void getArticleList(AcceptData acceptData, Integer page, String key, boolean search, PrintWriter out) { List<ArticleVO> list = articleOfficialService.queryValid((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key); if (list != null) { for (ArticleVO article : list) { String tags = article.getTags(); if (StringUtil.isNullOrEmpty(tags)) { continue; } String[] arrayTags = tags.split("\\s+"); if (arrayTags == null || arrayTags.length == 0) { continue; } String[] arrayTagsColour = null; String tagsColour = article.getTagsColour(); if (!StringUtil.isNullOrEmpty(tagsColour)) { arrayTagsColour = tagsColour.split("\\s+"); } String color = "#FE0014"; List<ClientTextStyleVO> labels = new ArrayList<ClientTextStyleVO>(); for (int i = 0; i < arrayTags.length; i++) { String tag = arrayTags[i]; if (arrayTagsColour != null && arrayTagsColour.length == arrayTags.length) { color = arrayTagsColour[i]; } ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor(color); styleVO.setContent(tag); labels.add(styleVO); } article.setLabels(labels); } } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); if (page == 1 && !search) { List<SwiperPicture> banners = swiperPictureService.getByBannerCardAndVersion("article_banners", acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (banners == null) banners = new ArrayList<>(); data.put("banners", gson.toJson(banners)); List<Special> listSpecial = specialService.listByVersion(0, Integer.MAX_VALUE, "article_specials", acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (listSpecial == null) listSpecial = new ArrayList<>(); for (Special special : listSpecial) { boolean needLogin = special.isJumpLogin(); JumpDetailV2 jumpDetail = special.getJumpDetail(); if (jumpDetail != null) { jumpDetail.setNeedLogin(needLogin); special.setJumpDetail(jumpDetail); } } data.put("specials", gson.toJson(listSpecial)); } data.put("count", articleOfficialService.countValid(key)); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "readArticle", method = RequestMethod.POST) public void readArticle(AcceptData acceptData, String id, PrintWriter out) { if (StringUtil.isNullOrEmpty(id)) { out.print(JsonUtil.loadFalseResult("id不能为空")); return; } articleOfficialService.updateReadNum(id); out.print(JsonUtil.loadTrueResult("操作成功")); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "searchArticle", method = RequestMethod.POST) public void searchArticle(AcceptData acceptData, Integer page, String key, PrintWriter out) { getArticleList(acceptData, page, key, true, out); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "getArticleHot", method = RequestMethod.POST) public void getArticleHot(AcceptData acceptData, PrintWriter out) { JSONObject data = new JSONObject(); data.put("words", configService.get(ConfigKeyEnum.articleHotWords.getKey())); out.print(JsonUtil.loadTrueResult(data)); } // //发圈测试 public void evaluateTest(AcceptData acceptData, PrintWriter out) { JSONObject data = JSONObject.fromObject(configService.get("test")); out.print(data.toString()); } /** * 发圈列表 * * @param acceptData * @param page * @param out */ @RequestMapping(value = "evaluate", method = RequestMethod.POST) public void evaluate(AcceptData acceptData, Integer page, PrintWriter out) { if ("1".equalsIgnoreCase(configService.get("test-open"))) { evaluateTest(acceptData, out); return; } long cid = 1; long subId = 1; List<DynamicInfo> listd = dynamicInfoService.queryV2(2, 74, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (listd == null) { listd = new ArrayList<DynamicInfo>(); } List<GoodsEvaluate> list = new ArrayList<>(); int p = 0; for (DynamicInfo info : listd) { p++; GoodsEvaluate goodsEvaluate = new GoodsEvaluate(); goodsEvaluate.setId(info.getId()); ActivityUser user = info.getUser(); user.setTag("烧烤达人"); goodsEvaluate.setUser(user); goodsEvaluate.setTitle(info.getTitle().get(0).getContent()); goodsEvaluate.setShareNum(info.getShareCount()); goodsEvaluate.setPublishTime(info.getCreateTime()); goodsEvaluate.setLineNum(2); List<GoodsPicture> imgs = info.getImgs(); List<ImgInfo> imgList = new ArrayList<>(); int i = 0; for (GoodsPicture goodsPicture : imgs) { ImgInfo imgInfo = new ImgInfo(); GoodsDetailVO goodsVO = goodsPicture.getGoodsVO(); imgInfo.setH(100); imgInfo.setW(100); if (goodsVO != null) { imgInfo.setType(ImgEnum.goods); SimpleGoods simpleGoods = new SimpleGoods(); simpleGoods.setPrice(goodsVO.getZkPrice()); simpleGoods.setAmount(new BigDecimal(115)); simpleGoods.setGoodsId(goodsVO.getGoodsId()); simpleGoods.setGoodsType(1); simpleGoods.setState(1); imgInfo.setGoods(simpleGoods); goodsEvaluate.setGoods(goodsVO); } else { imgInfo.setType(ImgEnum.img); } imgInfo.setLarge(false); imgInfo.setUrl(goodsPicture.getUrl()); imgInfo.setUrlHD(goodsPicture.getUrl()); // if (i == 0) { // imgInfo.setUrl(goodsPicture.getUrl()); // imgInfo.setType(ImgEnum.video); // imgInfo.setLarge(true); // imgInfo.setVideoUrl( // "http://pgcvideo.cdn.xiaodutv.com/754825344_367171606_2020010816001720200108174342.mp4?Cache-Control=max-age%3D8640000&responseExpires=Fri%2C+17+Apr+2020+18%3A11%3A55+GMT&xcode=0b0f3962eddaf66837d4af61a22c57bae3a5055540c75232&time=1579077845&_=1578992502888"); // } else { // imgInfo.setType(ImgEnum.img); // imgInfo.setLarge(true); // imgInfo.setUrl(goodsPicture.getUrl()); // } // i++; imgList.add(imgInfo); } if (p == 1) { ImgInfo imgInfo = new ImgInfo(); imgInfo.setLarge(true); imgInfo.setType(ImgEnum.img); imgInfo.setUrl( "http://ec-1255749512.file.myqcloud.com/img/invite/new/10ea86eb8db94f7cbb5e68864480d5fe.jpg"); imgInfo.setH(1334); imgInfo.setW(750); imgList.add(0, imgInfo); imgInfo = new ImgInfo(); imgInfo.setType(ImgEnum.video); imgInfo.setLarge(true); imgInfo.setUrl( "http://ec-1255749512.file.myqcloud.com/img/invite/new/10ea86eb8db94f7cbb5e68864480d5fe.jpg"); imgInfo.setH(315); imgInfo.setW(560); imgInfo.setUrl("https://zzya.beva.cn/img/Fr56bczo_F8NvroeG54jLH5ey0aC.jpg"); imgInfo.setVideoUrl("http://img.flqapp.com/resource/video.mp4"); imgList.add(0, imgInfo); } goodsEvaluate.setImgList(imgList); CommentInfo commentInfo = new CommentInfo(); commentInfo.setId(info.getId() + "09"); commentInfo.setContent("😆7.9元🉐1只儿童牙刷!!安妮贝拉卡通版儿童牙⭕PBT材质,毛刷细腻柔⭕外观卡通人物造型设计"); commentInfo.setType(CommentInfoEnum.goodsCoupon); // ClientTextStyleVO text1 = new ClientTextStyleVO(); // text1.setContent("猫超"); // text1.setColor("#1D9B31"); // // ClientTextStyleVO text2 = new ClientTextStyleVO(); // text2.setContent("满150减15"); // text2.setColor("#E5005C"); // List<ClientTextStyleVO> tagList = new ArrayList<>(); // tagList.add(text1); // tagList.add(text2); // commentInfo.setTagList(tagList); // commentInfo.setTagDesc("除生鲜及部分酒水除生鲜及除生鲜及"); CommentInfo commentInfo2 = new CommentInfo(); commentInfo2.setContent("😆7.9元🉐1只儿童牙刷!!安妮贝拉卡通版儿童牙⭕PBT材质,毛刷细腻柔⭕外观卡通人物造型设计"); commentInfo2.setType(CommentInfoEnum.goodsCoupon); ClientTextStyleVO text1 = new ClientTextStyleVO(); text1.setContent("猫超"); text1.setColor("#1D9B31"); ClientTextStyleVO text2 = new ClientTextStyleVO(); text2.setContent("满150减15"); text2.setColor("#E5005C"); List<ClientTextStyleVO> tagList = new ArrayList<>(); tagList.add(text1); tagList.add(text2); commentInfo2.setTagList(tagList); commentInfo2.setTagDesc("除生鲜及部分酒水除生鲜及除生鲜及"); commentInfo.setTagUrl("http://www.baidu.com"); List<CommentInfo> commentList = new ArrayList<>(); commentList.add(commentInfo); commentList.add(commentInfo2); goodsEvaluate.setComments(commentList); list.add(goodsEvaluate); } // List<GoodsEvaluate> list = // goodsEvaluateService.queryValidEvaluateCache((page - 1) * // Constant.PAGE_SIZE, Constant.PAGE_SIZE); // if (list == null) { // list = new ArrayList<>(); // } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); gsonBuilder.registerTypeAdapter(CommentInfoEnum.class, new JsonSerializer<CommentInfoEnum>() { @Override public JsonElement serialize(CommentInfoEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(1); } else { return new JsonPrimitive(value.getDesc()); } } }).registerTypeAdapter(ImgEnum.class, new JsonSerializer<ImgEnum>() { @Override public JsonElement serialize(ImgEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(""); } else { return new JsonPrimitive(value.getVlaue()); } } }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { if (d1 == d2) { long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { desc = "昨天"; } else { desc = (d2 - d1) + "天前"; } } else { int timeDistance = 0; for (int i = y1; i < y2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { timeDistance += 366; // 闰年 } else { timeDistance += 365; // 不是闰年 } } desc = timeDistance + (d2 - d1) + "天前"; } return new JsonPrimitive(desc); } return new JsonPrimitive(""); } }); Gson gson = gsonBuilder.create(); long count = dynamicInfoService.count(cid, subId); // goodsEvaluateService.countValid() JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } @RequestMapping(value = "evaluateShare", method = RequestMethod.POST) public void evaluateShare(AcceptData acceptData, Long uid, String id, Integer type, Long goodsId, Integer goodsType, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (StringUtil.isNullOrEmpty(id) || type == null) { out.print(JsonUtil.loadFalseResult("传递参数不能为空")); return; } if (type == 1 && (goodsId == null || goodsType == null)) { out.print(JsonUtil.loadFalseResult("商品参数不能为空")); return; } DynamicInfo dynamicInfo = dynamicInfoService.getById(id); if (dynamicInfo == null) { out.print(JsonUtil.loadFalseResult("该内容已不存在")); return; } UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (user != null && user.getState() != UserInfo.STATE_NORMAL) { out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); return; } UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); String relationId = null; if (taoBaoInfo != null && taoBaoInfo.getRelationId() != null && taoBaoInfo.getRelationValid() != null && taoBaoInfo.getRelationValid() == true) relationId = taoBaoInfo.getRelationId(); if (StringUtil.isNullOrEmpty(relationId)) { out.print(JsonUtil.loadFalseResult(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号")); return; } List<GoodsPicture> imgs = dynamicInfo.getImgs(); if (imgs == null) { out.print(JsonUtil.loadFalseResult("该图片内容已不存在")); return; } int total = 0; for (GoodsPicture goodsPicture : imgs) { GoodsDetailVO goodsVO = goodsPicture.getGoodsVO(); if (goodsVO != null) { total++; } } List<String> list = new ArrayList<>(); for (GoodsPicture goodsPicture : imgs) { GoodsDetailVO goodsVO = goodsPicture.getGoodsVO(); if (goodsVO == null && total <= 1) { list.add(goodsPicture.getUrl()); continue; } if (type == 1) { if (goodsVO.getGoodsId().longValue() == goodsId.longValue() && goodsVO.getGoodsType() == goodsType.intValue()) { String jumpLink = getJumpLink(goodsVO, user); if (!StringUtil.isNullOrEmpty(jumpLink)) { list.add(jumpLink); } } } else { String jumpLink = getJumpLink(goodsVO, user); if (!StringUtil.isNullOrEmpty(jumpLink)) { list.add(jumpLink); } } } Integer shareCount = dynamicInfo.getShareCount(); if (shareCount == null) { shareCount = 0; } if (type == 3) { shareCount++; dynamicInfoService.updateShareCount(dynamicInfo); } if (list.size() == 0) { out.print(JsonUtil.loadFalseResult("该信息已下架")); return; } JSONObject data = new JSONObject(); data.put("count", shareCount); data.put("list", list); out.print(JsonUtil.loadTrueResult(data)); } private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user) { String jumpLink = null; if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(user.getId() + "", Constant.UIDAESKEY), goodsVO.getGoodsId() + ""); String shortLink = HttpUtil.getShortLink(url); if (!StringUtil.isNullOrEmpty(shortLink)) { url = shortLink; } } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_JD) { JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsVO.getGoodsId()); if (jdGoods == null) { return null; } String couponUrl = null; JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods); if (couponInfo != null) { couponUrl = couponInfo.getLink(); } String materialId = "https://item.jd.com/" + goodsVO.getGoodsId() + ".html"; jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", user.getId() + ""); } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_PDD) { jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsVO.getGoodsId(), PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + ""); } FileUploadResult uploadResult = qrCodeService.drawGoodsPoster(jumpLink, user.getPortrait(), goodsVO); if (uploadResult != null) { return uploadResult.getUrl(); } return null; } /** * 评论复制 * * @param acceptData * @param id * @param cid * 评论id * @param out */ @RequestMapping(value = "evaluateComment", method = RequestMethod.POST) public void evaluateComment(AcceptData acceptData, Long uid, String id, String cid, PrintWriter out) { if (StringUtil.isNullOrEmpty(id)) { out.print(JsonUtil.loadFalseResult("id不能为空")); return; } DynamicInfo dynamicInfo = dynamicInfoService.getById(id); if (dynamicInfo == null) { out.print(JsonUtil.loadFalseResult("该内容已不存在")); return; } UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (user != null && user.getState() != UserInfo.STATE_NORMAL) { out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); return; } UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); String relationId = null; if (taoBaoInfo != null && taoBaoInfo.getRelationId() != null && taoBaoInfo.getRelationValid() != null && taoBaoInfo.getRelationValid() == true) relationId = taoBaoInfo.getRelationId(); if (StringUtil.isNullOrEmpty(relationId)) { out.print(JsonUtil.loadFalseResult(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号")); return; } JSONObject data = new JSONObject(); data.put("text", "安妮贝拉卡通版儿拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版拉卡通版"); out.print(JsonUtil.loadTrueResult(data)); } } package com.yeshi.fanli.controller.client.v2; import java.io.PrintWriter; import java.lang.reflect.Type; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.JsonUtil; import org.yeshi.utils.entity.FileUploadResult; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; import com.yeshi.fanli.dto.jd.JDCouponInfo; import com.yeshi.fanli.entity.accept.AcceptData; import com.yeshi.fanli.entity.bus.activity.ActivityUser; import com.yeshi.fanli.entity.bus.clazz.GoodsClass; import com.yeshi.fanli.entity.bus.homemodule.Special; import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture; import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.common.JumpDetailV2; import com.yeshi.fanli.entity.dynamic.CommentInfo; import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum; import com.yeshi.fanli.entity.dynamic.DynamicInfo; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate; import com.yeshi.fanli.entity.dynamic.GoodsPicture; import com.yeshi.fanli.entity.dynamic.ImgInfo; import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum; import com.yeshi.fanli.entity.dynamic.SimpleGoods; import com.yeshi.fanli.entity.jd.JDGoods; import com.yeshi.fanli.entity.system.ConfigKeyEnum; import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.dynamic.ArticleOfficialService; import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService; import com.yeshi.fanli.service.inter.dynamic.GoodsEvaluateService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.homemodule.SpecialService; import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.VersionUtil; import com.yeshi.fanli.util.cache.JDGoodsCacheUtil; import com.yeshi.fanli.util.jd.JDApiUtil; import com.yeshi.fanli.util.jd.JDUtil; import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; import com.yeshi.fanli.util.taobao.DaTaoKeUtil; import com.yeshi.fanli.vo.dynamic.ArticleVO; import com.yeshi.fanli.vo.goods.GoodsDetailVO; import com.yeshi.fanli.vo.msg.ClientTextStyleVO; import net.sf.json.JSONObject; /** * 动态 * * @author Administrator * */ @Controller @RequestMapping("api/v2/dynamic") public class DynamicControllerV2 { @Resource private HongBaoManageService hongBaoManageService; @Resource private TaoBaoGoodsBriefService taoBaoGoodsBriefService; @Resource private JumpDetailV2Service jumpDetailV2Service; @Resource private DynamicInfoService dynamicInfoService; @Resource private SpecialService specialService; @Resource private ArticleOfficialService articleOfficialService; @Resource private SwiperPictureService swiperPictureService; @Resource private ConfigService configService; @Resource private GoodsEvaluateService goodsEvaluateService; @Resource private UserInfoService userInfoService; @Resource private UserInfoExtraService userInfoExtraService; @Resource private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService; @Resource private JDGoodsCacheUtil jdGoodsCacheUtil; @Resource private QrCodeService qrCodeService; /** * 查询顶部分类 * * @param acceptData * @param page * @param cid * @param out */ @RequestMapping(value = "getClass", method = RequestMethod.POST) public void getClass(AcceptData acceptData, Integer cid, PrintWriter out) { // ios 只返回子集分类 if (cid != null) { List<GoodsClass> list = new ArrayList<GoodsClass>(); switch (cid) { case 1: list.add(new GoodsClass(0L, "今日单品")); list.addAll(DaTaoKeUtil.goodsClasses); break; case 2: break; case 3: break; case 4: break; case 5: list.add(new GoodsClass(0L, "全部")); list.add(new GoodsClass(1L, "淘宝")); list.add(new GoodsClass(2L, "京东")); list.add(new GoodsClass(3L, "拼多多")); break; default: break; } JSONObject data = new JSONObject(); data.put("list", JsonUtil.getApiCommonGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); return; } // Android 返回分类以及顶部数据 List<GoodsClass> listSub = new ArrayList<GoodsClass>(); listSub.add(new GoodsClass(0L, "今日单品")); listSub.addAll(DaTaoKeUtil.goodsClasses); GoodsClass menu1 = new GoodsClass(1L, "热销"); menu1.setListSub(listSub); GoodsClass menu2 = new GoodsClass(2L, "推荐"); menu2.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu3 = new GoodsClass(3L, "好店"); menu3.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu4 = new GoodsClass(4L, "邀请"); menu4.setListSub(new ArrayList<GoodsClass>()); GoodsClass menu5 = new GoodsClass(5L, "活动"); List<GoodsClass> sub5 = new ArrayList<GoodsClass>(); sub5.add(new GoodsClass(0L, "全部")); sub5.add(new GoodsClass(1L, "淘宝")); sub5.add(new GoodsClass(2L, "京东")); sub5.add(new GoodsClass(3L, "拼多多")); menu5.setListSub(sub5); GoodsClass menu6 = new GoodsClass(6L, "学院"); menu6.setListSub(new ArrayList<GoodsClass>()); List<GoodsClass> list = new ArrayList<GoodsClass>(); list.add(menu1); list.add(menu5); list.add(menu2); // 2.0.5版本隐藏 好店栏目 if (!VersionUtil.greaterThan_2_0_5(acceptData.getPlatform(), acceptData.getVersion())) { list.add(menu3); } // 2.0.6版本增加 学院栏目 if (VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) { // list.add(menu6); } list.add(menu4); JSONObject data = new JSONObject(); data.put("list", JsonUtil.getApiCommonGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 动态商品列表 * * @param acceptData * @param page * @param cid * @param subId * @param out */ @RequestMapping(value = "getList", method = RequestMethod.POST) public void getList(AcceptData acceptData, Integer page, Long cid, Long subId, PrintWriter out) { if (cid == null) { out.print(JsonUtil.loadFalseResult("主分类id不能为空")); return; } if (cid != null) { if (cid == 5) { // 活动主题 getSpecialList(acceptData, page, subId, out); return; } else if (cid == 6) { // 学院 getArticleList(acceptData, page, null, false, out); return; } } long count = 0; int platform = 1; if ("ios".equalsIgnoreCase(acceptData.getPlatform())) { platform = 2; } int version = Integer.parseInt(acceptData.getVersion()); List<DynamicInfo> list = dynamicInfoService.queryV2(platform, version, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (list == null) { list = new ArrayList<DynamicInfo>(); } else { count = dynamicInfoService.count(cid, subId); } JSONObject data = new JSONObject(); data.put("count", count); data.put("list", getGson().toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 活动列表 * * @param acceptData * @param out */ private void getSpecialList(AcceptData acceptData, Integer page, Long subId, PrintWriter out) { if (subId == null) { out.print(JsonUtil.loadFalseResult("分类id不能为空")); return; } // 平台区分 int platformCode = Constant.getPlatformCode(acceptData.getPlatform()); List<String> listKey = new ArrayList<String>(); if (subId == 1) { // 淘宝 listKey.add("special_channel_tb"); } else if (subId == 2) { // 京东 listKey.add("special_channel_jd"); } else if (subId == 3) { // 拼多多 listKey.add("special_channel_pdd"); } else { // 全部 listKey.add("special_channel_tb"); listKey.add("special_channel_jd"); listKey.add("special_channel_pdd"); } List<Special> list = specialService.listByPlaceKeyHasLabel((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, listKey, platformCode, Integer.parseInt(acceptData.getVersion())); long time = System.currentTimeMillis(); // 删除尚未启用的过期的 for (int i = 0; i < list.size(); i++) { Special special = list.get(i); if (special.getState() == 1L) { list.remove(i--); } else { if (special.getStartTime() != null && special.getEndTime() != null) special.setTimeTask(true); else special.setTimeTask(false); if (special.isTimeTask()) { if (time < special.getStartTime().getTime() || time > special.getEndTime().getTime()) { list.remove(i--); } else// 设置倒计时 { special.setCountDownTime((special.getEndTime().getTime() - time) / 1000); } } List<SpecialLabel> listLabels = special.getListLabels(); if (listLabels != null && !listLabels.isEmpty()) { List<ClientTextStyleVO> labels = new ArrayList<>(); for (SpecialLabel specialLabel : listLabels) { labels.add(new ClientTextStyleVO(specialLabel.getName(), specialLabel.getBgColor())); } special.setLabels(labels); } } } long count = specialService.countByPlaceKeyList(listKey, platformCode, Integer.parseInt(acceptData.getVersion())); GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 时间处理 * * @return */ private Gson getGson() { GsonBuilder gb = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()); gb.excludeFieldsWithoutExposeAnnotation(); gb.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { if (d1 == d2) { long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { desc = "昨天"; } else { desc = (d2 - d1) + "天前"; } } else { int timeDistance = 0; for (int i = y1; i < y2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { timeDistance += 366; // 闰年 } else { timeDistance += 365; // 不是闰年 } } desc = timeDistance + (d2 - d1) + "天前"; } return new JsonPrimitive(desc); } return new JsonPrimitive(""); } }); Gson gson = gb.create(); return gson; } /** * 活动列表 * * @param acceptData * @param out */ private void getArticleList(AcceptData acceptData, Integer page, String key, boolean search, PrintWriter out) { List<ArticleVO> list = articleOfficialService.queryValid((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key); if (list != null) { for (ArticleVO article : list) { String tags = article.getTags(); if (StringUtil.isNullOrEmpty(tags)) { continue; } String[] arrayTags = tags.split("\\s+"); if (arrayTags == null || arrayTags.length == 0) { continue; } String[] arrayTagsColour = null; String tagsColour = article.getTagsColour(); if (!StringUtil.isNullOrEmpty(tagsColour)) { arrayTagsColour = tagsColour.split("\\s+"); } String color = "#FE0014"; List<ClientTextStyleVO> labels = new ArrayList<ClientTextStyleVO>(); for (int i = 0; i < arrayTags.length; i++) { String tag = arrayTags[i]; if (arrayTagsColour != null && arrayTagsColour.length == arrayTags.length) { color = arrayTagsColour[i]; } ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor(color); styleVO.setContent(tag); labels.add(styleVO); } article.setLabels(labels); } } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); Gson gson = gsonBuilder.create(); JSONObject data = new JSONObject(); if (page == 1 && !search) { List<SwiperPicture> banners = swiperPictureService.getByBannerCardAndVersion("article_banners", acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (banners == null) banners = new ArrayList<>(); data.put("banners", gson.toJson(banners)); List<Special> listSpecial = specialService.listByVersion(0, Integer.MAX_VALUE, "article_specials", acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion())); if (listSpecial == null) listSpecial = new ArrayList<>(); for (Special special : listSpecial) { boolean needLogin = special.isJumpLogin(); JumpDetailV2 jumpDetail = special.getJumpDetail(); if (jumpDetail != null) { jumpDetail.setNeedLogin(needLogin); special.setJumpDetail(jumpDetail); } } data.put("specials", gson.toJson(listSpecial)); } data.put("count", articleOfficialService.countValid(key)); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "readArticle", method = RequestMethod.POST) public void readArticle(AcceptData acceptData, String id, PrintWriter out) { if (StringUtil.isNullOrEmpty(id)) { out.print(JsonUtil.loadFalseResult("id不能为空")); return; } articleOfficialService.updateReadNum(id); out.print(JsonUtil.loadTrueResult("操作成功")); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "searchArticle", method = RequestMethod.POST) public void searchArticle(AcceptData acceptData, Integer page, String key, PrintWriter out) { getArticleList(acceptData, page, key, true, out); } /** * 文章搜索 * * @param acceptData * @param page * @param key * @param out */ @RequestMapping(value = "getArticleHot", method = RequestMethod.POST) public void getArticleHot(AcceptData acceptData, PrintWriter out) { JSONObject data = new JSONObject(); data.put("words", configService.get(ConfigKeyEnum.articleHotWords.getKey())); out.print(JsonUtil.loadTrueResult(data)); } /** * 发圈列表 * * @param acceptData * @param page * @param out */ @RequestMapping(value = "evaluate2", method = RequestMethod.POST) public void evaluate2(AcceptData acceptData, Integer page,Integer type, PrintWriter out) { if(type == null) { type = 1; } List<GoodsEvaluate> list = goodsEvaluateService.queryMaterialsCache((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, type); if (list == null) { list = new ArrayList<>(); } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); gsonBuilder.registerTypeAdapter(CommentInfoEnum.class, new JsonSerializer<CommentInfoEnum>() { @Override public JsonElement serialize(CommentInfoEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(1); } else { return new JsonPrimitive(value.getDesc()); } } }).registerTypeAdapter(ImgEnum.class, new JsonSerializer<ImgEnum>() { @Override public JsonElement serialize(ImgEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(""); } else { return new JsonPrimitive(value.getVlaue()); } } }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { if (d1 == d2) { long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { desc = "昨天"; } else { desc = (d2 - d1) + "天前"; } } else { int timeDistance = 0; for (int i = y1; i < y2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { timeDistance += 366; // 闰年 } else { timeDistance += 365; // 不是闰年 } } desc = timeDistance + (d2 - d1) + "天前"; } return new JsonPrimitive(desc); } return new JsonPrimitive(""); } }); Gson gson = gsonBuilder.create(); long count = goodsEvaluateService.countValidMaterials(type); JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } /** * 发圈列表 * * @param acceptData * @param page * @param out */ @RequestMapping(value = "evaluate", method = RequestMethod.POST) public void evaluate(AcceptData acceptData, Integer page, Integer type, PrintWriter out) { long cid = 1; long subId = 1; List<DynamicInfo> listd = dynamicInfoService.queryV2(2, 74, (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, cid, subId); if (listd == null) { listd = new ArrayList<DynamicInfo>(); } List<GoodsEvaluate> list = new ArrayList<>(); for (DynamicInfo info : listd) { GoodsEvaluate goodsEvaluate = new GoodsEvaluate(); goodsEvaluate.setId(info.getId()); ActivityUser user = info.getUser(); user.setTag("烧烤达人"); goodsEvaluate.setUser(user); goodsEvaluate.setTitle(info.getTitle().get(0).getContent()); goodsEvaluate.setShareNum(info.getShareCount()); goodsEvaluate.setPublishTime(info.getCreateTime()); goodsEvaluate.setLineNum(2); List<GoodsPicture> imgs = info.getImgs(); List<ImgInfo> imgList = new ArrayList<>(); int i = 0; for (GoodsPicture goodsPicture : imgs) { ImgInfo imgInfo = new ImgInfo(); GoodsDetailVO goodsVO = goodsPicture.getGoodsVO(); imgInfo.setH(100); imgInfo.setW(100); if (goodsVO != null) { imgInfo.setType(ImgEnum.goods); SimpleGoods simpleGoods = new SimpleGoods(); simpleGoods.setPrice(goodsVO.getZkPrice()); simpleGoods.setAmount(new BigDecimal(115)); simpleGoods.setGoodsId(goodsVO.getGoodsId()); simpleGoods.setGoodsType(1); simpleGoods.setState(1); imgInfo.setGoods(simpleGoods); goodsEvaluate.setGoods(goodsVO); } else { imgInfo.setType(ImgEnum.img); } imgInfo.setLarge(false); imgInfo.setUrl(goodsPicture.getUrl()); imgInfo.setUrlHD(goodsPicture.getUrl()); // if (i == 0) { // imgInfo.setUrl(goodsPicture.getUrl()); // imgInfo.setType(ImgEnum.video); // imgInfo.setLarge(true); // imgInfo.setVideoUrl( // "http://pgcvideo.cdn.xiaodutv.com/754825344_367171606_2020010816001720200108174342.mp4?Cache-Control=max-age%3D8640000&responseExpires=Fri%2C+17+Apr+2020+18%3A11%3A55+GMT&xcode=0b0f3962eddaf66837d4af61a22c57bae3a5055540c75232&time=1579077845&_=1578992502888"); // } else { // imgInfo.setType(ImgEnum.img); // imgInfo.setLarge(true); // imgInfo.setUrl(goodsPicture.getUrl()); // } // i++; imgList.add(imgInfo); } goodsEvaluate.setImgList(imgList); CommentInfo commentInfo = new CommentInfo(); commentInfo.setId(info.getId() + "09"); commentInfo.setContent("😆7.9元🉐1只儿童牙刷!!安妮贝拉卡通版儿童牙⭕PBT材质,毛刷细腻柔⭕外观卡通人物造型设计"); commentInfo.setType(CommentInfoEnum.goodsCoupon); // ClientTextStyleVO text1 = new ClientTextStyleVO(); // text1.setContent("猫超"); // text1.setColor("#1D9B31"); // // ClientTextStyleVO text2 = new ClientTextStyleVO(); // text2.setContent("满150减15"); // text2.setColor("#E5005C"); // List<ClientTextStyleVO> tagList = new ArrayList<>(); // tagList.add(text1); // tagList.add(text2); // commentInfo.setTagList(tagList); // commentInfo.setTagDesc("除生鲜及部分酒水除生鲜及除生鲜及"); CommentInfo commentInfo2 = new CommentInfo(); commentInfo2.setContent("😆7.9元🉐1只儿童牙刷!!安妮贝拉卡通版儿童牙⭕PBT材质,毛刷细腻柔⭕外观卡通人物造型设计"); commentInfo2.setType(CommentInfoEnum.goodsCoupon); ClientTextStyleVO text1 = new ClientTextStyleVO(); text1.setContent("猫超"); text1.setColor("#1D9B31"); ClientTextStyleVO text2 = new ClientTextStyleVO(); text2.setContent("满150减15"); text2.setColor("#E5005C"); List<ClientTextStyleVO> tagList = new ArrayList<>(); tagList.add(text1); tagList.add(text2); commentInfo2.setTagList(tagList); commentInfo2.setTagDesc("除生鲜及部分酒水除生鲜及除生鲜及"); commentInfo.setTagUrl("http://www.baidu.com"); List<CommentInfo> commentList = new ArrayList<>(); commentList.add(commentInfo); commentList.add(commentInfo2); goodsEvaluate.setComments(commentList); list.add(goodsEvaluate); } // List<GoodsEvaluate> list = goodsEvaluateService.queryValidEvaluateCache((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); // if (list == null) { // list = new ArrayList<>(); // } GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); gsonBuilder.registerTypeAdapter(CommentInfoEnum.class, new JsonSerializer<CommentInfoEnum>() { @Override public JsonElement serialize(CommentInfoEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(1); } else { return new JsonPrimitive(value.getDesc()); } } }).registerTypeAdapter(ImgEnum.class, new JsonSerializer<ImgEnum>() { @Override public JsonElement serialize(ImgEnum value, Type theType, JsonSerializationContext context) { if (value == null) { return new JsonPrimitive(""); } else { return new JsonPrimitive(value.getVlaue()); } } }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { @Override public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { String desc = ""; if (value != null) { // 判断是否是同一天 Calendar calendar = Calendar.getInstance(); calendar.setTime(value); int y1 = calendar.get(Calendar.YEAR);// 获取年份 int d1 = calendar.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 Date nowDate = new Date(); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(nowDate); int y2 = calendar2.get(Calendar.YEAR);// 获取年份 int d2 = calendar2.get(Calendar.DAY_OF_YEAR);// 获取年中第几天 long old = value.getTime(); long now = nowDate.getTime(); if (y1 == y2) { if (d1 == d2) { long cha = now - old; if (cha < 1000 * 60 * 2L) { desc = "刚刚"; } else if (cha < 1000 * 60 * 60L) { desc = (cha / (1000 * 60)) + "分钟前"; } else { desc = (cha / (1000 * 60 * 60)) + "小时前"; } } else if (d2 - d1 == 1) { desc = "昨天"; } else { desc = (d2 - d1) + "天前"; } } else { int timeDistance = 0; for (int i = y1; i < y2; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { timeDistance += 366; // 闰年 } else { timeDistance += 365; // 不是闰年 } } desc = timeDistance + (d2 - d1) + "天前"; } return new JsonPrimitive(desc); } return new JsonPrimitive(""); } }); Gson gson = gsonBuilder.create(); long count = dynamicInfoService.count(cid, subId); // goodsEvaluateService.countValid() JSONObject data = new JSONObject(); data.put("count", count); data.put("list", gson.toJson(list)); out.print(JsonUtil.loadTrueResult(data)); } @RequestMapping(value = "evaluateShare", method = RequestMethod.POST) public void evaluateShare(AcceptData acceptData, Long uid, String id, Integer type, Long goodsId, Integer goodsType, PrintWriter out) { if (uid == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (StringUtil.isNullOrEmpty(id) || type == null) { out.print(JsonUtil.loadFalseResult("传递参数不能为空")); return; } if (type == 1 && (goodsId == null || goodsType == null)) { out.print(JsonUtil.loadFalseResult("商品参数不能为空")); return; } GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id); if (goodsEvaluate == null) { out.print(JsonUtil.loadFalseResult("该内容已不存在")); return; } UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (user != null && user.getState() != UserInfo.STATE_NORMAL) { out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); return; } UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); String relationId = null; if (taoBaoInfo != null && taoBaoInfo.getRelationId() != null && taoBaoInfo.getRelationValid() != null && taoBaoInfo.getRelationValid() == true) relationId = taoBaoInfo.getRelationId(); if (StringUtil.isNullOrEmpty(relationId)) { out.print(JsonUtil.loadFalseResult(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号")); return; } String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); if (StringUtil.isNullOrEmpty(inviteCode)) { out.print(JsonUtil.loadFalseResult(1, "邀请码未激活")); return; } List<ImgInfo> imgs = goodsEvaluate.getImgList(); if (imgs == null) { out.print(JsonUtil.loadFalseResult("该图片内容已不存在")); return; } int total = 0; for (ImgInfo imgInfo : imgs) { SimpleGoods goods = imgInfo.getGoods(); if (goods != null) { total ++; } } List<String> list = new ArrayList<>(); for (ImgInfo imgInfo : imgs) { GoodsDetailVO goodsVO = imgInfo.getGoodsVO(); if (goodsVO == null && total <= 1) { list.add(imgInfo.getUrl()); continue; } if (type == 1) { if (goodsVO.getGoodsId().longValue() == goodsId.longValue() && goodsVO.getGoodsType() == goodsType.intValue()) { String jumpLink = getJumpLink(goodsVO, user, inviteCode); if (!StringUtil.isNullOrEmpty(jumpLink)) { list.add(jumpLink); } } } else { String jumpLink = getJumpLink(goodsVO, user, inviteCode); if (!StringUtil.isNullOrEmpty(jumpLink)) { list.add(jumpLink); } } } Integer shareCount = goodsEvaluate.getShareNum(); if (shareCount == null) { shareCount = 0; } if (type == 3) { shareCount++; goodsEvaluateService.addShareNum(id); } if (list.size() == 0) { out.print(JsonUtil.loadFalseResult("该信息已下架")); return; } JSONObject data = new JSONObject(); data.put("count", shareCount); data.put("list", list); out.print(JsonUtil.loadTrueResult(data)); } private String getJumpLink(GoodsDetailVO goodsVO, UserInfo user, String inviteCode) { String jumpLink = null; if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) { String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(), Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(user.getId() + "", Constant.UIDAESKEY),goodsVO.getGoodsId() + ""); String shortLink = HttpUtil.getShortLink(url); if (!StringUtil.isNullOrEmpty(shortLink)) { url = shortLink; } } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_JD) { JDGoods jdGoods = jdGoodsCacheUtil.getGoodsInfo(goodsVO.getGoodsId()); if (jdGoods == null ) { return null; } String couponUrl = null; JDCouponInfo couponInfo = JDUtil.getShowCouponInfo(jdGoods); if (couponInfo != null) { couponUrl = couponInfo.getLink(); } String materialId = "https://item.jd.com/" + goodsVO.getGoodsId() + ".html"; jumpLink = JDApiUtil.convertLinkWithSubUnionId(materialId, couponUrl, JDApiUtil.POSITION_SHARE + "", user.getId() + ""); } else if (goodsVO.getGoodsType() == Constant.SOURCE_TYPE_PDD) { jumpLink = PinDuoDuoApiUtil.getPromotionUrl(goodsVO.getGoodsId(), PinDuoDuoApiUtil.PID_SHARE + "", user.getId() + ""); } FileUploadResult uploadResult = qrCodeService.drawDynamicGoodsPoster(jumpLink, user.getPortrait(), inviteCode, goodsVO); if (uploadResult != null) { return uploadResult.getUrl(); } return null; } /** * 评论复制 * @param acceptData * @param id * @param cid 评论id * @param out */ @RequestMapping(value = "evaluateComment", method = RequestMethod.POST) public void evaluateComment(AcceptData acceptData, Long uid, String id, String cid, PrintWriter out) { if (StringUtil.isNullOrEmpty(id)) { out.print(JsonUtil.loadFalseResult("id不能为空")); return; } GoodsEvaluate goodsEvaluate = goodsEvaluateService.getById(id); if (goodsEvaluate == null) { out.print(JsonUtil.loadFalseResult("该内容已不存在")); return; } UserInfo user = userInfoService.getUserByIdWithMybatis(uid); if (user == null) { out.print(JsonUtil.loadFalseResult("用户未登录")); return; } if (user != null && user.getState() != UserInfo.STATE_NORMAL) { out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC)); return; } UserExtraTaoBaoInfo taoBaoInfo = userExtraTaoBaoInfoService.getByUid(uid); String relationId = null; if (taoBaoInfo != null && taoBaoInfo.getRelationId() != null && taoBaoInfo.getRelationValid() != null && taoBaoInfo.getRelationValid() == true) relationId = taoBaoInfo.getRelationId(); if (StringUtil.isNullOrEmpty(relationId)) { out.print(JsonUtil.loadFalseResult(2, "淘宝未授权,请前往\"我的\"绑定淘宝账号")); return; } String text = ""; List<CommentInfo> comments = goodsEvaluate.getComments(); if (comments != null) { for (CommentInfo commentInfo: comments){ if (cid.equals(commentInfo.getId())) { text = commentInfo.getContent(); } } } JSONObject data = new JSONObject(); data.put("text", text); out.print(JsonUtil.loadTrueResult(data)); } } fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java
@@ -65,8 +65,9 @@ * * @return */ public List<GoodsEvaluate> query(int start, int count, String key, Integer state) { public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType) { Query query = new Query(); query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); if (state != null) { query.addCriteria(Criteria.where("state").is(state)); } @@ -79,8 +80,10 @@ return mongoTemplate.find(query, GoodsEvaluate.class); } public long count(String key, Integer state) { public long count(String key, Integer state, int dynamicType) { Query query = new Query(); query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); if (state != null) { query.addCriteria(Criteria.where("state").is(state)); } @@ -97,9 +100,10 @@ * @param key * @return */ public List<GoodsEvaluate> queryValid(int start, int count) { public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType) { Date now = new Date(); Query query = new Query(); query.addCriteria(Criteria.where("state").is(dynamicType)); query.addCriteria(Criteria.where("state").is(1)); query.addCriteria(Criteria.where("startTime").lte(now)); query.addCriteria(Criteria.where("endTime").gte(now)); @@ -113,9 +117,10 @@ * @param key * @return */ public long countValid() { public long countValid(int dynamicType) { Date now = new Date(); Query query = new Query(); query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); query.addCriteria(Criteria.where("state").is(1)); query.addCriteria(Criteria.where("startTime").lte(now)); query.addCriteria(Criteria.where("endTime").gte(now)); fanli/src/main/java/com/yeshi/fanli/entity/dynamic/GoodsEvaluate.java
@@ -117,6 +117,8 @@ @Field("mainPicNum") private Integer mainPicNum; // 图片主图 @Field("dynamicType") private Integer dynamicType; // 1发圈 2素材 private String startTimeChar; @@ -281,5 +283,13 @@ public void setType(EvaluateEnum type) { this.type = type; } public Integer getDynamicType() { return dynamicType; } public void setDynamicType(Integer dynamicType) { this.dynamicType = dynamicType; } } fanli/src/main/java/com/yeshi/fanli/entity/dynamic/ImgInfo.java
@@ -3,6 +3,7 @@ import java.io.Serializable; import com.google.gson.annotations.Expose; import com.yeshi.fanli.vo.goods.GoodsDetailVO; public class ImgInfo implements Serializable { private static final long serialVersionUID = 1L; @@ -55,6 +56,8 @@ // 商品信息 @Expose private SimpleGoods goods; private GoodsDetailVO goodsVO; private String activityPic; private String activityUrl; @@ -154,5 +157,13 @@ public void setActivityPic(String activityPic) { this.activityPic = activityPic; } public GoodsDetailVO getGoodsVO() { return goodsVO; } public void setGoodsVO(GoodsDetailVO goodsVO) { this.goodsVO = goodsVO; } } fanli/src/main/java/com/yeshi/fanli/service/impl/dynamic/GoodsEvaluateServiceImpl.java
@@ -25,7 +25,9 @@ import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; import com.yeshi.fanli.entity.bus.activity.ActivityUser; import com.yeshi.fanli.entity.dynamic.CommentInfo; import com.yeshi.fanli.entity.dynamic.CommentInfo.CommentInfoEnum; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate.EvaluateEnum; import com.yeshi.fanli.entity.dynamic.ImgInfo; import com.yeshi.fanli.entity.dynamic.ImgInfo.ImgEnum; import com.yeshi.fanli.entity.dynamic.SimpleGoods; @@ -102,6 +104,11 @@ throw new GoodsEvaluateException(1, "截止时间必须大于开始时间"); } Integer dynamicType = record.getDynamicType(); if (dynamicType == null) { record.setDynamicType(1); } if (record.getShareNum() == null) record.setShareNum(0); @@ -245,87 +252,77 @@ String[] pics = picUrls.split(","); if (pics != null) { listpic = new ArrayList<>(); for (int i = 0; i < pics.length; i++ ) { if(pics[i].startsWith("http")){ listpic.add(pics[i]); for (int i = 0; i < pics.length; i++) { String picLink = pics[i]; if (fileRequest != null) { MultipartFile file = fileRequest.getFile("file" + i); if (file == null) { continue; } picLink = uploadPicture(file); } if (picLink.startsWith("http")) { listpic.add(picLink); } } } } if (fileRequest != null) { for (int i = 0; i < 9; i++) { MultipartFile file = fileRequest.getFile("file" + i); if (file == null) { continue; } // 上传文件 String picLink = uploadPicture(file); if (listpic != null && listpic.size() > i) { // 需要删除的list String delUrl = listpic.get(i); listDel.add(delUrl); listpic.set(i, picLink); continue; } listpic.add(picLink); } // 指定主图 if (picNum == null || picNum > 9 || picNum < 1) { picNum = 1; } // 指定主图 if (picNum == null || picNum > 9 || picNum < 1) { picNum = 1; } if (listpic != null && listpic.size() > 0) { for (int i = 0; i < listpic.size(); i++) { ImgInfo imgInfo0 = new ImgInfo(); imgInfo0.setId(UUID.randomUUID().toString().replace("-", "")); imgInfo0.setW(1); imgInfo0.setH(1); imgInfo0.setLarge(false); imgInfo0.setPid(pid); imgInfo0.setUrl(listpic.get(i)); imgInfo0.setUrlHD(listpic.get(i)); if (listpic != null && listpic.size() > 0) { // 对比图片 for (int j = 0; j < listOld.size(); j++) { boolean del = true; for (int i = 0; i < listpic.size(); i++) { if (listpic.get(i).equals(listOld.get(j))) { del = false; break; } if (picNum - 1 == i) { imgInfo0.setType(ImgEnum.goods); // 商品信息 GoodsDetailVO goodsDetailVO = getGoodsDetailVO(goodsId, goodsType); if (goodsDetailVO == null) { throw new GoodsEvaluateException(1, "该商品信息不存在"); } if (del) listDel.add(listOld.get(j)); } for (int i = 0; i < listpic.size(); i++) { ImgInfo imgInfo0 = new ImgInfo(); imgInfo0.setId(UUID.randomUUID().toString().replace("-", "")); imgInfo0.setW(1); imgInfo0.setH(1); imgInfo0.setLarge(false); imgInfo0.setPid(pid); imgInfo0.setUrl(listpic.get(i)); imgInfo0.setUrlHD(listpic.get(i)); if (picNum - 1 == i) { imgInfo0.setType(ImgEnum.goods); // 商品信息 GoodsDetailVO goodsDetailVO = null; // TODO // getGoodsDetailVO(goodsId, goodsType); // if (goodsDetailVO == null) { // throw new GoodsEvaluateException(1, "该商品信息不存在"); // } SimpleGoods simpleGoods = new SimpleGoods(); simpleGoods.setGoodsId(goodsId); simpleGoods.setGoodsType(goodsType); // simpleGoods.setPrice(goodsDetailVO.getCouponPrice()); // CouponInfoVO couponInfo = goodsDetailVO.getCouponInfo(); // if (couponInfo == null) { // simpleGoods.setState(1); // } else { // simpleGoods.setAmount(couponInfo.getAmount()); // simpleGoods.setState(0); // } imgInfo0.setGoods(simpleGoods); SimpleGoods simpleGoods = new SimpleGoods(); simpleGoods.setGoodsId(goodsId); simpleGoods.setGoodsType(goodsType); simpleGoods.setPrice(goodsDetailVO.getCouponPrice()); CouponInfoVO couponInfo = goodsDetailVO.getCouponInfo(); if (couponInfo == null) { simpleGoods.setState(1); } else { imgInfo0.setType(ImgEnum.img); simpleGoods.setAmount(couponInfo.getAmount()); simpleGoods.setState(0); } listImg.add(imgInfo0); imgInfo0.setGoods(simpleGoods); } else { imgInfo0.setType(ImgEnum.img); } listImg.add(imgInfo0); } } if (listOld != null && listOld.size() > 0) { for (int j = 0; j < listOld.size(); j++) { boolean del = true; String oldPic = listOld.get(j); for (ImgInfo imgInfo: listImg) { String url = imgInfo.getUrl(); if (url.equals(oldPic)) { del = false; } } if (del) listDel.add(listOld.get(j)); } } @@ -333,7 +330,7 @@ resultObj.setMainPicNum(picNum); resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); // 删除图片 if (listDel.size() > 0) { for (String url : listDel) { @@ -366,6 +363,223 @@ } return goodsDetail; } @Override public void saveMultipleGoods(String pid, String videoUrl, String goodsList, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception { if (StringUtil.isNullOrEmpty(pid)) { throw new GoodsEvaluateException(1, "请保存第一部分信息"); } GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid); if (resultObj == null) throw new GoodsEvaluateException(1, "第一部分信息缺失"); // 原封视频面图 ImgInfo imgVideo = null; List<String> listDel = new ArrayList<String>(); List<ImgInfo> oldGoodsList = new ArrayList<ImgInfo>(); // 处理图片 List<ImgInfo> resultList = resultObj.getImgList(); if (resultList != null && resultList.size() > 0) { for (ImgInfo info : resultList) { ImgEnum type = info.getType(); if (type == ImgEnum.video) { imgVideo = info; } else if (type == ImgEnum.goods) { oldGoodsList.add(info); } } } // 视频部分 if (fileRequest != null) { MultipartFile filevideo = fileRequest.getFile("filevideo"); if (filevideo != null) { if (StringUtil.isNullOrEmpty(videoUrl)) { throw new GoodsEvaluateException(1, "视频链接不能为空"); } String picLink = uploadPicture(filevideo); if (imgVideo != null) { String url = imgVideo.getUrl(); if (!StringUtil.isNullOrEmpty(url)) { listDel.add(url); } imgVideo.setUrl(picLink); imgVideo.setUrlHD(picLink); } else { imgVideo = new ImgInfo(); imgVideo.setId(UUID.randomUUID().toString().replace("-", "")); imgVideo.setW(1); imgVideo.setH(1); imgVideo.setLarge(true); imgVideo.setPid(pid); imgVideo.setUrl(picLink); imgVideo.setUrlHD(picLink); imgVideo.setVideoUrl(videoUrl); imgVideo.setType(ImgEnum.video); } } } List<ImgInfo> listImg = new ArrayList<ImgInfo>(); if (imgVideo != null) { if (!StringUtil.isNullOrEmpty(videoUrl)) { if (imgVideo != null && StringUtil.isNullOrEmpty(imgVideo.getUrl())) { throw new GoodsEvaluateException(1, "视频封面图不能为空"); } imgVideo.setVideoUrl(videoUrl); listImg.add(imgVideo); } else { String url = imgVideo.getUrl(); if (!StringUtil.isNullOrEmpty(url)) { listDel.add(url); } } } if (!StringUtil.isNullOrEmpty(goodsList)) { String[] goodsArray = goodsList.split(","); if (goodsArray != null && goodsArray.length > 0) { for (int i = 0; i < goodsArray.length || i < 9; i++) { String goodsids = goodsArray[i]; String[] g = goodsids.split("-"); GoodsDetailVO goodsDetailVO = getGoodsDetailVO(Long.parseLong(g[0]), Integer.parseInt(g[1])); if (goodsDetailVO == null) { continue; } String picUrl = goodsDetailVO.getPicUrl(); if (fileRequest != null) { MultipartFile file = fileRequest.getFile("file" + i); if (file != null) { picUrl = uploadPicture(file); } } ImgInfo imgInfo0 = new ImgInfo(); imgInfo0.setId(UUID.randomUUID().toString().replace("-", "")); imgInfo0.setW(1); imgInfo0.setH(1); imgInfo0.setLarge(false); imgInfo0.setPid(pid); imgInfo0.setUrl(picUrl); imgInfo0.setUrlHD(picUrl); imgInfo0.setType(ImgEnum.goods); SimpleGoods simpleGoods = new SimpleGoods(); simpleGoods.setGoodsId(goodsDetailVO.getGoodsId()); simpleGoods.setGoodsType(goodsDetailVO.getGoodsType()); simpleGoods.setPrice(goodsDetailVO.getCouponPrice()); CouponInfoVO couponInfo = goodsDetailVO.getCouponInfo(); if (couponInfo == null) { simpleGoods.setState(1); } else { simpleGoods.setAmount(couponInfo.getAmount()); simpleGoods.setState(0); } imgInfo0.setGoods(simpleGoods); } } } // 数据对比 删除图片 if (oldGoodsList != null && oldGoodsList.size() > 0) { for (ImgInfo old : oldGoodsList) { ImgEnum type = old.getType(); if (type != ImgEnum.goods) { continue; } boolean del = false; long oldGoodsId = old.getGoods().getGoodsId().longValue(); int oldGoodsType = old.getGoods().getGoodsType().intValue(); for (ImgInfo newInfo : listImg) { ImgEnum type2 = old.getType(); if (type2 != ImgEnum.goods) { continue; } if (oldGoodsId == newInfo.getGoods().getGoodsId().longValue() && oldGoodsType == newInfo.getGoods().getGoodsType().intValue()) { String url = newInfo.getUrl(); if (url.equals(old.getUrl())) { } else if (url.contains(FilePathEnum.goodsEvaluate.getPath())) { del = true; } else { newInfo.setUrl(old.getUrl()); newInfo.setUrlHD(old.getUrlHD()); } break; } } if (del) { listDel.add(old.getUrl()); } } } // 保存图片信息 resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); // 删除图片 if (listDel.size() > 0) { for (String url : listDel) { if (url.contains(FilePathEnum.goodsEvaluate.getPath())) { removePicture(url); } } } } @Override public void saveGoodsCoupon(String pid, String tags, String content) throws GoodsEvaluateException, Exception { if (StringUtil.isNullOrEmpty(pid)) { throw new GoodsEvaluateException(1, "请保存第一部分信息"); } GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid); if (resultObj == null) throw new GoodsEvaluateException(1, "第一部分信息缺失"); CommentInfo goodsCoupon = null; CommentInfo currencyCoupon = null; List<CommentInfo> oldComments = resultObj.getComments(); if (oldComments != null) { for (CommentInfo info: oldComments) { if(CommentInfoEnum.goodsCoupon == info.getType()) { goodsCoupon = info; } else if (CommentInfoEnum.currencyCoupon == info.getType()) { currencyCoupon = info; } } } List<CommentInfo> comments = new ArrayList<>(); if (!StringUtil.isNullOrEmpty(content)) { CommentInfo commentInfo = new CommentInfo(); if (goodsCoupon != null) { commentInfo.setId(goodsCoupon.getId()); } else { commentInfo.setId(UUID.randomUUID().toString().replace("-", "")); } commentInfo.setContent(content); commentInfo.setType(CommentInfoEnum.goodsCoupon); comments.add(currencyCoupon); } if (currencyCoupon != null) { comments.add(currencyCoupon); } resultObj.setComments(comments); goodsEvaluateDao.save(resultObj); } @Override public void saveSingleGoodsCoupon(String pid, CommentInfo commentInfo) throws GoodsEvaluateException, Exception { @@ -377,18 +591,61 @@ if (resultObj == null) throw new GoodsEvaluateException(1, "第一部分信息缺失"); CommentInfo goodsCoupon = null; CommentInfo currencyCoupon = null; List<CommentInfo> oldComments = resultObj.getComments(); if (oldComments != null) { for (CommentInfo info: oldComments) { if(CommentInfoEnum.goodsCoupon == info.getType()) { goodsCoupon = info; } else if (CommentInfoEnum.currencyCoupon == info.getType()) { currencyCoupon = info; } } } List<CommentInfo> comments = new ArrayList<>(); if (goodsCoupon != null) { comments.add(goodsCoupon); } if (commentInfo != null) { if (currencyCoupon != null) { commentInfo.setId(currencyCoupon.getId()); } else { commentInfo.setId(UUID.randomUUID().toString().replace("-", "")); } commentInfo.setType(CommentInfoEnum.currencyCoupon); // 标签信息 List<ClientTextStyleVO> tagList = new ArrayList<>(); String couponSource = commentInfo.getCouponSource(); if (!StringUtil.isNullOrEmpty(couponSource)) { ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor("#16C253"); styleVO.setContent(couponSource); tagList.add(styleVO); } String coupon = commentInfo.getCoupon(); if (!StringUtil.isNullOrEmpty(coupon)) { ClientTextStyleVO styleVO = new ClientTextStyleVO(); styleVO.setColor("#E5005C"); styleVO.setContent(coupon); tagList.add(styleVO); } commentInfo.setTagList(tagList); comments.add(commentInfo); } resultObj.setComments(comments); resultObj.setComments(comments); goodsEvaluateDao.save(resultObj); } @Override public void saveActivityPic(String pid, ImgInfo imgInfo, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception { public void saveActivityPic(String pid, ImgInfo imgInfo, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception { if (StringUtil.isNullOrEmpty(pid)) { throw new GoodsEvaluateException(1, "请保存第一部分信息"); } @@ -403,18 +660,17 @@ ImgInfo imgactivity = null; List<ImgInfo> resultList = resultObj.getImgList(); if (resultList != null && resultList.size() > 0) { for(ImgInfo info: resultList) { for (ImgInfo info : resultList) { if (info.getType() == ImgEnum.activity) { activityPic = info.getActivityPic(); imgVideo = info; imgactivity = info; } else { imgVideo = info; videoPic = info.getUrl(); } } } List<ImgInfo> listImg = new ArrayList<ImgInfo>(); if (fileRequest != null) { MultipartFile filevideo = fileRequest.getFile("filevideo"); @@ -423,7 +679,7 @@ String picLink = uploadPicture(filevideo); videoPic = picLink; } MultipartFile activityfile = fileRequest.getFile("activityfile"); if (activityfile != null) { removePicture(activityPic); @@ -431,9 +687,9 @@ activityPic = picLink; } } if (!StringUtil.isNullOrEmpty(videoPic) || !StringUtil.isNullOrEmpty(imgInfo.getVideoUrl())) { if (imgVideo != null){ if (imgVideo != null) { imgVideo.setUrl(videoPic); imgVideo.setUrlHD(videoPic); imgVideo.setVideoUrl(imgInfo.getVideoUrl()); @@ -451,30 +707,173 @@ } listImg.add(imgVideo); } if (!StringUtil.isNullOrEmpty(activityPic) || !StringUtil.isNullOrEmpty(imgInfo.getActivityUrl())) { if (imgVideo != null){ imgVideo.setUrl(activityPic); imgVideo.setUrlHD(activityPic); imgVideo.setVideoUrl(imgInfo.getVideoUrl()); if (imgactivity != null) { imgactivity.setUrl(activityPic); imgactivity.setUrlHD(activityPic); imgactivity.setActivityUrl(imgInfo.getActivityUrl()); } else { imgVideo = new ImgInfo(); imgVideo.setId(UUID.randomUUID().toString().replace("-", "")); imgVideo.setW(1); imgVideo.setH(1); imgVideo.setLarge(true); imgVideo.setPid(pid); imgVideo.setUrl(activityPic); imgVideo.setUrlHD(activityPic); imgVideo.setActivityUrl(imgInfo.getActivityUrl()); imgVideo.setType(ImgEnum.activity); imgactivity = new ImgInfo(); imgactivity.setId(UUID.randomUUID().toString().replace("-", "")); imgactivity.setW(1); imgactivity.setH(1); imgactivity.setLarge(true); imgactivity.setPid(pid); imgactivity.setUrl(activityPic); imgactivity.setUrlHD(activityPic); imgactivity.setActivityUrl(imgInfo.getActivityUrl()); imgactivity.setType(ImgEnum.activity); } listImg.add(imgVideo); listImg.add(imgactivity); } resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); } @Override public void saveSuCai(String pid, String videoUrl, String picUrls, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception { if (StringUtil.isNullOrEmpty(pid)) { throw new GoodsEvaluateException(1, "请保存第一部分信息"); } GoodsEvaluate resultObj = goodsEvaluateDao.getById(pid); if (resultObj == null) throw new GoodsEvaluateException(1, "第一部分信息缺失"); // 原封视频面图 ImgInfo imgVideo = null; List<String> listDel = new ArrayList<String>(); List<String> listOld = new ArrayList<String>(); // 处理图片 List<ImgInfo> resultList = resultObj.getImgList(); if (resultList != null && resultList.size() > 0) { for (ImgInfo info : resultList) { ImgEnum type = info.getType(); if (type == ImgEnum.video) { imgVideo = info; } else if (type == ImgEnum.img) { String url = info.getUrl(); if (!StringUtil.isNullOrEmpty(url)) { listOld.add(url); } } } } // 视频部分 if (fileRequest != null) { MultipartFile filevideo = fileRequest.getFile("filevideo"); if (filevideo != null) { if (StringUtil.isNullOrEmpty(videoUrl)) { throw new GoodsEvaluateException(1, "视频链接不能为空"); } String picLink = uploadPicture(filevideo); if (imgVideo != null) { String url = imgVideo.getUrl(); if (!StringUtil.isNullOrEmpty(url)) { listDel.add(url); } imgVideo.setUrl(picLink); imgVideo.setUrlHD(picLink); } else { imgVideo = new ImgInfo(); imgVideo.setId(UUID.randomUUID().toString().replace("-", "")); imgVideo.setW(1); imgVideo.setH(1); imgVideo.setLarge(true); imgVideo.setPid(pid); imgVideo.setUrl(picLink); imgVideo.setUrlHD(picLink); imgVideo.setVideoUrl(videoUrl); imgVideo.setType(ImgEnum.video); } } } List<ImgInfo> listImg = new ArrayList<ImgInfo>(); if (imgVideo != null) { if (!StringUtil.isNullOrEmpty(videoUrl)) { if (imgVideo != null && StringUtil.isNullOrEmpty(imgVideo.getUrl())) { throw new GoodsEvaluateException(1, "视频封面图不能为空"); } imgVideo.setVideoUrl(videoUrl); listImg.add(imgVideo); } else { String url = imgVideo.getUrl(); if (!StringUtil.isNullOrEmpty(url)) { listDel.add(url); } } } // 编辑图片 List<String> listpic = null; if (!StringUtil.isNullOrEmpty(picUrls)) { String[] pics = picUrls.split(","); if (pics != null) { listpic = new ArrayList<>(); for (int i = 0; i < pics.length; i++) { String picLink = pics[i]; if (fileRequest != null) { MultipartFile file = fileRequest.getFile("file" + i); if (file != null) { picLink = uploadPicture(file); } } if (picLink.startsWith("http")) { listpic.add(picLink); } } } } if (listpic != null && listpic.size() > 0) { for (int i = 0; i < listpic.size(); i++) { ImgInfo imgInfo0 = new ImgInfo(); imgInfo0.setId(UUID.randomUUID().toString().replace("-", "")); imgInfo0.setW(1); imgInfo0.setH(1); imgInfo0.setLarge(false); imgInfo0.setPid(pid); imgInfo0.setUrl(listpic.get(i)); imgInfo0.setUrlHD(listpic.get(i)); imgInfo0.setType(ImgEnum.img); listImg.add(imgInfo0); } } if (listOld != null && listOld.size() > 0) { for (int j = 0; j < listOld.size(); j++) { boolean del = true; String oldPic = listOld.get(j); for (ImgInfo imgInfo: listImg) { String url = imgInfo.getUrl(); if (url.equals(oldPic)) { del = false; } } if (del) listDel.add(listOld.get(j)); } } resultObj.setImgList(listImg); goodsEvaluateDao.save(resultObj); // 删除图片 if (listDel.size() > 0) { for (String url : listDel) { if (url.contains(FilePathEnum.goodsEvaluate.getPath())) { removePicture(url); } } } } @Override public void deleteBatchByPrimaryKey(List<String> list) { @@ -547,6 +946,17 @@ goodsEvaluate.setComments(comments); goodsEvaluateDao.save(goodsEvaluate); } @Override public void release(String id) throws GoodsEvaluateException { GoodsEvaluate goodsEvaluate = goodsEvaluateDao.getById(id); if (goodsEvaluate == null) { throw new GoodsEvaluateException(1, "动态已不存在"); } goodsEvaluate.setState(1); goodsEvaluateDao.save(goodsEvaluate); } @Override public void deleteComment(String pid, List<String> list) throws GoodsEvaluateException { @@ -597,19 +1007,19 @@ } @Override public List<GoodsEvaluate> query(int start, int count, String key, Integer state) { return goodsEvaluateDao.query(start, count, key, state); public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType) { return goodsEvaluateDao.query(start, count, key, state, dynamicType); } @Override public long count(String key, Integer state) { return goodsEvaluateDao.count(key, state); public long count(String key, Integer state, int dynamicType) { return goodsEvaluateDao.count(key, state, dynamicType); } @Override @Cacheable(value = "dynamicCache", key = "'queryValidEvaluateCache-'+#start") public List<GoodsEvaluate> queryValidEvaluateCache(int start, int count) { List<GoodsEvaluate> list = goodsEvaluateDao.queryValid(start, count); List<GoodsEvaluate> list = goodsEvaluateDao.queryValid(start, count, 1); // 更新商品信息 executor.execute(new Runnable() { @@ -624,7 +1034,26 @@ @Override public long countValid() { return goodsEvaluateDao.countValid(); return goodsEvaluateDao.countValid(1); } @Override @Cacheable(value = "dynamicCache", key = "'queryMaterialsCache-'+#start+'-'+#type") public List<GoodsEvaluate> queryMaterialsCache(int start, int count, int type) { List<GoodsEvaluate> list = goodsEvaluateDao.queryValid(start, count, type); // 更新商品信息 executor.execute(new Runnable() { @Override public void run() { updateGoodInfo(list); } }); return list; } @Override public long countValidMaterials(int type) { return goodsEvaluateDao.countValid(type); } /** fanli/src/main/java/com/yeshi/fanli/service/impl/user/QrCodeServiceImpl.java
@@ -1,332 +1,365 @@ package com.yeshi.fanli.service.impl.user; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; import java.util.UUID; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.QRCodeUtil; import org.yeshi.utils.entity.FileUploadResult; import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.mybatis.share.ShareMapper; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.service.inter.user.SpreadUserImgService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.FilePathEnum; import com.yeshi.fanli.util.FileUtil; import com.yeshi.fanli.util.ImageUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.UserInviteUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; @Service public class QrCodeServiceImpl implements QrCodeService { @Resource private ShareMapper shareMapper; @Resource private SpreadUserImgService spreadUserImgService; @Override public String getPortrait(Long uid) { return shareMapper.getPortrait(uid); } @Override public String drawInviteQrCode(String url, Long uid, String portrait, String inviteCode) throws IOException { if (url != null && !url.equals("")) { String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode); if (new File(targetPath).exists() && new File(targetPath).length() > 0) { // 上传文件 // 将url 转为 md5 让到下面中添加 在比较md5的值 int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); String imgUrl = COSManager.getInstance() .uploadFile(new File(targetPath), FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg") .getUrl(); if (new File(erCodeTempPath).exists()) new File(erCodeTempPath).delete(); if (new File(targetPath).exists()) new File(targetPath).delete(); return imgUrl; } } return null; } @Override public String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY, int erCodeSize, String inviteCode) throws IOException { if (!StringUtil.isNullOrEmpty(url)) { String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, erCodePostionX, erCodePostionY, erCodeSize, inviteCode); if (new File(targetPath).exists() && new File(targetPath).length() > 0) { // 上传文件 // 将url 转为 md5 让到下面中添加 在比较md5的值 int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + urlMd5 + ".jpg").getUrl(); if (new File(erCodeTempPath).exists()) new File(erCodeTempPath).delete(); if (new File(targetPath).exists()) new File(targetPath).delete(); return imgUrl; } } return null; } @Override public String drawInviteQrCodeNew(InputStream urlInputStream, String urlMd5, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException { if (urlInputStream == null) { return null; } String targetPath = null; String erCodeTempPath = null; InputStream erCodeInputStream = null; // 二维码 InputStream portraitInputStream = null; // 头像 // InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 String uuid = UUID.randomUUID().toString().replace("-", ""); if (uid == null) { targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg"; // 官方 邀请码(无效的) inviteCode = "FLQAPP"; // 官方二维码 erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png"); // 官方默认头像 portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png"); } else { targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = UserInviteUtil.getShareUrl(uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 } // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImgWhitecustom(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, pX, pY, size, inviteCode); // 删除二维码文件 if (erCodeInputStream != null) { erCodeInputStream.close(); } if (erCodeTempPath != null && new File(erCodeTempPath).exists()) { new File(erCodeTempPath).delete(); } // 上传文件相对位置 if (new File(targetPath).exists() && new File(targetPath).length() > 0) { String fileUrl = null; if (uid == null) { fileUrl = FilePathEnum.invitePictureDemo.getPath() + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } else { fileUrl = FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } // 上传文件 String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl(); // 删除本地缓存文件 new File(targetPath).delete(); return imgUrl; } return null; } @Override public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, Date date) throws IOException { if (StringUtil.isNullOrEmpty(url)) { return null; } String targetPath = null; String erCodeTempPath = null; InputStream erCodeInputStream = null; // 二维码 InputStream portraitInputStream = null; // 头像 InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 String uuid = UUID.randomUUID().toString().replace("-", ""); if (uid == null) { targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg"; // 官方 邀请码(无效的) inviteCode = "FLQAPP"; // 官方二维码 erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png"); // 官方默认头像 portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png"); } else { targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 } // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.drawInviteToGreet(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode, content, date); // 删除二维码文件 if (erCodeInputStream != null) { erCodeInputStream.close(); } if (erCodeTempPath != null && new File(erCodeTempPath).exists()) { new File(erCodeTempPath).delete(); } // 上传文件 if (new File(targetPath).exists() && new File(targetPath).length() > 0) { int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); // 上传文件相对位置 String fileUrl = null; if (uid == null) { fileUrl = FilePathEnum.invitePictureDemo.getPath() + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } else { fileUrl = FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } // 上传 String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl(); // 删除缓存文件 new File(targetPath).delete(); return imgUrl; } return null; } @Override public FileUploadResult drawGoodsPoster(String erCodeUrl, String portrait, GoodsDetailVO goods) { // 二维码流 InputStream erCodeStream = null; try { erCodeStream = QRCodeUtil.getInstance(250).encode(erCodeUrl); } catch (Exception e1) { e1.printStackTrace(); } // 头像 InputStream portraitStream = null; if (!StringUtil.isNullOrEmpty(portrait)) { try { portraitStream = HttpUtil.getAsInputStream(portrait); } catch (Exception e) { e.printStackTrace(); } } if (portraitStream == null) { portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_default_head.jpg"); } // 画图 InputStream drawStream = ImageUtil.drawGoodsShareSingle(erCodeStream, portraitStream, goods); // 上传位置 String uuid = UUID.randomUUID().toString().replace("-", ""); String upPath = FilePathEnum.shareXCX.getPath() + uuid + "_" + goods.getGoodsId() + "_" + System.currentTimeMillis() + ".png"; // 上传文件 return COSManager.getInstance().uploadInputStream(drawStream, upPath); } @Override public FileUploadResult drawGoodsPosterXCX(InputStream erCodeStream,UserInfo user, GoodsDetailVO goods) { // 画图 InputStream drawStream = ImageUtil.drawGoodsShareXCX(erCodeStream, user, goods); // 上传位置 String uuid = UUID.randomUUID().toString().replace("-", ""); String upPath = FilePathEnum.shareXCX.getPath() + uuid + "_" + goods.getGoodsId() + "_" + System.currentTimeMillis() + ".png"; // 上传文件 return COSManager.getInstance().uploadInputStream(drawStream, upPath); } } package com.yeshi.fanli.service.impl.user; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Date; import java.util.UUID; import javax.annotation.Resource; import org.springframework.stereotype.Service; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.QRCodeUtil; import org.yeshi.utils.entity.FileUploadResult; import org.yeshi.utils.tencentcloud.COSManager; import com.yeshi.fanli.dao.mybatis.share.ShareMapper; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.service.inter.user.QrCodeService; import com.yeshi.fanli.service.inter.user.SpreadUserImgService; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.FilePathEnum; import com.yeshi.fanli.util.FileUtil; import com.yeshi.fanli.util.ImageUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.UserInviteUtil; import com.yeshi.fanli.vo.goods.GoodsDetailVO; @Service public class QrCodeServiceImpl implements QrCodeService { @Resource private ShareMapper shareMapper; @Resource private SpreadUserImgService spreadUserImgService; @Override public String getPortrait(Long uid) { return shareMapper.getPortrait(uid); } @Override public String drawInviteQrCode(String url, Long uid, String portrait, String inviteCode) throws IOException { if (url != null && !url.equals("")) { String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode); if (new File(targetPath).exists() && new File(targetPath).length() > 0) { // 上传文件 // 将url 转为 md5 让到下面中添加 在比较md5的值 int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); String imgUrl = COSManager.getInstance() .uploadFile(new File(targetPath), FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg") .getUrl(); if (new File(erCodeTempPath).exists()) new File(erCodeTempPath).delete(); if (new File(targetPath).exists()) new File(targetPath).delete(); return imgUrl; } } return null; } @Override public String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY, int erCodeSize, String inviteCode) throws IOException { if (!StringUtil.isNullOrEmpty(url)) { String targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 InputStream portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 InputStream erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImg(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, erCodePostionX, erCodePostionY, erCodeSize, inviteCode); if (new File(targetPath).exists() && new File(targetPath).length() > 0) { // 上传文件 // 将url 转为 md5 让到下面中添加 在比较md5的值 int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + urlMd5 + ".jpg").getUrl(); if (new File(erCodeTempPath).exists()) new File(erCodeTempPath).delete(); if (new File(targetPath).exists()) new File(targetPath).delete(); return imgUrl; } } return null; } @Override public String drawInviteQrCodeNew(InputStream urlInputStream, String urlMd5, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException { if (urlInputStream == null) { return null; } String targetPath = null; String erCodeTempPath = null; InputStream erCodeInputStream = null; // 二维码 InputStream portraitInputStream = null; // 头像 // InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 String uuid = UUID.randomUUID().toString().replace("-", ""); if (uid == null) { targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg"; // 官方 邀请码(无效的) inviteCode = "FLQAPP"; // 官方二维码 erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png"); // 官方默认头像 portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png"); } else { targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = UserInviteUtil.getShareUrl(uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); // 二维码 } // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.inviteFriendImgWhitecustom(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, pX, pY, size, inviteCode); // 删除二维码文件 if (erCodeInputStream != null) { erCodeInputStream.close(); } if (erCodeTempPath != null && new File(erCodeTempPath).exists()) { new File(erCodeTempPath).delete(); } // 上传文件相对位置 if (new File(targetPath).exists() && new File(targetPath).length() > 0) { String fileUrl = null; if (uid == null) { fileUrl = FilePathEnum.invitePictureDemo.getPath() + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } else { fileUrl = FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } // 上传文件 String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl(); // 删除本地缓存文件 new File(targetPath).delete(); return imgUrl; } return null; } @Override public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, Date date) throws IOException { if (StringUtil.isNullOrEmpty(url)) { return null; } String targetPath = null; String erCodeTempPath = null; InputStream erCodeInputStream = null; // 二维码 InputStream portraitInputStream = null; // 头像 InputStream urlInputStream = HttpUtil.getAsInputStream(url); // 背景 String uuid = UUID.randomUUID().toString().replace("-", ""); if (uid == null) { targetPath = FileUtil.getCacheDir() + "/share_" + uuid + "_" + System.currentTimeMillis() + ".jpg"; // 官方 邀请码(无效的) inviteCode = "FLQAPP"; // 官方二维码 erCodeInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official.png"); // 官方默认头像 portraitInputStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_icon.png"); } else { targetPath = FileUtil.getCacheDir() + "/share_" + uid + "_" + System.currentTimeMillis() + ".jpg"; erCodeTempPath = FileUtil.getCacheDir() + "/" + uid + "_" + System.currentTimeMillis() + ".jpg"; String erCode = ("http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid); // 生成 try { QRCodeUtil.getInstance(250).encode(erCode, erCodeTempPath); } catch (Exception e) { e.printStackTrace(); } erCodeInputStream = new FileInputStream(new File(erCodeTempPath)); portraitInputStream = HttpUtil.getAsInputStream(portrait); // 头像 } // 开始根据 url(背景图), qrCode(二维码), portrait(头像) 生成图片 ImageUtil.drawInviteToGreet(urlInputStream, portraitInputStream, erCodeInputStream, targetPath, inviteCode, content, date); // 删除二维码文件 if (erCodeInputStream != null) { erCodeInputStream.close(); } if (erCodeTempPath != null && new File(erCodeTempPath).exists()) { new File(erCodeTempPath).delete(); } // 上传文件 if (new File(targetPath).exists() && new File(targetPath).length() > 0) { int index = url.lastIndexOf("/"); String newUrl = url.substring(index + 1); String urlMd5 = newUrl.substring(0, newUrl.lastIndexOf(".")); // 上传文件相对位置 String fileUrl = null; if (uid == null) { fileUrl = FilePathEnum.invitePictureDemo.getPath() + "ercode_" + uuid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } else { fileUrl = FilePathEnum.ercode.getPath() + "ercode_" + uid + "_" + System.currentTimeMillis() + "_" + urlMd5 + ".jpg"; } // 上传 String imgUrl = COSManager.getInstance().uploadFile(new File(targetPath), fileUrl).getUrl(); // 删除缓存文件 new File(targetPath).delete(); return imgUrl; } return null; } @Override public FileUploadResult drawDynamicGoodsPoster(String erCodeUrl, String portrait, String inviteCode, GoodsDetailVO goods) { // 二维码流 InputStream erCodeStream = null; try { erCodeStream = QRCodeUtil.getInstance(250).encode(erCodeUrl); } catch (Exception e1) { e1.printStackTrace(); } // 头像 InputStream portraitStream = null; if (!StringUtil.isNullOrEmpty(portrait)) { try { portraitStream = HttpUtil.getAsInputStream(portrait); } catch (Exception e) { e.printStackTrace(); } } if (portraitStream == null) { portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_default_head.jpg"); } // 画图 InputStream drawStream = ImageUtil.drawGoodsPoster(erCodeStream, portraitStream,inviteCode, goods); // 上传位置 String uuid = UUID.randomUUID().toString().replace("-", ""); String upPath = FilePathEnum.shareGoods.getPath() + uuid + "_" + goods.getGoodsId() + "_" + System.currentTimeMillis() + ".png"; // 上传文件 return COSManager.getInstance().uploadInputStream(drawStream, upPath); } @Override public FileUploadResult drawGoodsPoster(String erCodeUrl, String portrait, GoodsDetailVO goods) { // 二维码流 InputStream erCodeStream = null; try { erCodeStream = QRCodeUtil.getInstance(250).encode(erCodeUrl); } catch (Exception e1) { e1.printStackTrace(); } // 头像 InputStream portraitStream = null; if (!StringUtil.isNullOrEmpty(portrait)) { try { portraitStream = HttpUtil.getAsInputStream(portrait); } catch (Exception e) { e.printStackTrace(); } } if (portraitStream == null) { portraitStream = ImageUtil.class.getClassLoader().getResourceAsStream("image/official_default_head.jpg"); } // 画图 InputStream drawStream = ImageUtil.drawGoodsShareSingle(erCodeStream, portraitStream, goods); // 上传位置 String uuid = UUID.randomUUID().toString().replace("-", ""); String upPath = FilePathEnum.shareXCX.getPath() + uuid + "_" + goods.getGoodsId() + "_" + System.currentTimeMillis() + ".png"; // 上传文件 return COSManager.getInstance().uploadInputStream(drawStream, upPath); } @Override public FileUploadResult drawGoodsPosterXCX(InputStream erCodeStream,UserInfo user, GoodsDetailVO goods) { // 画图 InputStream drawStream = ImageUtil.drawGoodsShareXCX(erCodeStream, user, goods); // 上传位置 String uuid = UUID.randomUUID().toString().replace("-", ""); String upPath = FilePathEnum.shareXCX.getPath() + uuid + "_" + goods.getGoodsId() + "_" + System.currentTimeMillis() + ".png"; // 上传文件 return COSManager.getInstance().uploadInputStream(drawStream, upPath); } } fanli/src/main/java/com/yeshi/fanli/service/inter/dynamic/GoodsEvaluateService.java
@@ -38,9 +38,9 @@ * @param state * @return */ public List<GoodsEvaluate> query(int start, int count, String key, Integer state); public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType); public long count(String key, Integer state); public long count(String key, Integer state,int dynamicType); /** @@ -91,4 +91,47 @@ throws GoodsEvaluateException, Exception; /** * 多个商品保存信息 * @param pid * @param videoUrl * @param goodsList * @param fileRequest * @throws GoodsEvaluateException * @throws Exception */ public void saveMultipleGoods(String pid, String videoUrl, String goodsList, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception; /** * 素材 * @param pid * @param videoUrl * @param picUrls * @param fileRequest * @throws GoodsEvaluateException * @throws Exception */ public void saveSuCai(String pid, String videoUrl, String picUrls, MultipartHttpServletRequest fileRequest) throws GoodsEvaluateException, Exception; /** * 查询素材 * @param start * @param count * @return */ public List<GoodsEvaluate> queryMaterialsCache(int start, int count,int type); public long countValidMaterials(int type); public void saveGoodsCoupon(String pid, String tags, String content) throws GoodsEvaluateException, Exception; public void release(String id) throws GoodsEvaluateException; } fanli/src/main/java/com/yeshi/fanli/service/inter/user/QrCodeService.java
@@ -1,92 +1,94 @@ package com.yeshi.fanli.service.inter.user; import java.io.IOException; import java.io.InputStream; import java.util.Date; import org.yeshi.utils.entity.FileUploadResult; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.vo.goods.GoodsDetailVO; public interface QrCodeService { String getPortrait(Long uid); /** * 生成邀请赚的图片 * * @param url * @param uid * @param portrait * @return * @throws IOException */ String drawInviteQrCode(String url, Long uid, String portrait,String inviteCode) throws IOException; /** * 绘制邀请二维码 * * @param url * -背景图链接 * @param uid * -用户ID * @param portrait * -头像路径 * @param erCodePostionX * 二维码坐标X * @param erCodePostionY * 二维码坐标Y * @param erCodeSize * 二维码尺寸 * @return * @throws IOException */ String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY, int erCodeSize,String inviteCode) throws IOException; /** * 邀请问候 * @param url 背景图链接 * @param uid 用户id 为空时默认官网 * @param portrait 头像 为空时默认官网 * @param inviteCode 邀请码 为空时默认官网 * @param content 图片文字内容 * @param date 日期 * @return * @throws IOException */ public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, Date date) throws IOException; /** * uid为空时 默认官方 * @param url * @param uid * @param portrait * @param inviteCode * @return * @throws IOException */ public String drawInviteQrCodeNew(InputStream urlInputStream,String urlMd5, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException; /** * 分享商品海报图 * @param urlInputStream * @param erCodeUrl * @param uid * @param portrait * @param goods * @return */ public FileUploadResult drawGoodsPoster(String erCodeUrl, String portrait,GoodsDetailVO goods); /** * 分享小程序名片 * @param erCodeStream * @param user * @param goods * @return */ public FileUploadResult drawGoodsPosterXCX(InputStream erCodeStream, UserInfo user, GoodsDetailVO goods); } package com.yeshi.fanli.service.inter.user; import java.io.IOException; import java.io.InputStream; import java.util.Date; import org.yeshi.utils.entity.FileUploadResult; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.vo.goods.GoodsDetailVO; public interface QrCodeService { String getPortrait(Long uid); /** * 生成邀请赚的图片 * * @param url * @param uid * @param portrait * @return * @throws IOException */ String drawInviteQrCode(String url, Long uid, String portrait,String inviteCode) throws IOException; /** * 绘制邀请二维码 * * @param url * -背景图链接 * @param uid * -用户ID * @param portrait * -头像路径 * @param erCodePostionX * 二维码坐标X * @param erCodePostionY * 二维码坐标Y * @param erCodeSize * 二维码尺寸 * @return * @throws IOException */ String drawInviteQrCode(String url, Long uid, String portrait, int erCodePostionX, int erCodePostionY, int erCodeSize,String inviteCode) throws IOException; /** * 邀请问候 * @param url 背景图链接 * @param uid 用户id 为空时默认官网 * @param portrait 头像 为空时默认官网 * @param inviteCode 邀请码 为空时默认官网 * @param content 图片文字内容 * @param date 日期 * @return * @throws IOException */ public String drawInviteToGreet(String url, Long uid, String portrait, String inviteCode, String content, Date date) throws IOException; /** * uid为空时 默认官方 * @param url * @param uid * @param portrait * @param inviteCode * @return * @throws IOException */ public String drawInviteQrCodeNew(InputStream urlInputStream,String urlMd5, Long uid, String portrait, Integer pX, Integer pY, Integer size, String inviteCode) throws IOException; /** * 分享商品海报图 * @param urlInputStream * @param erCodeUrl * @param uid * @param portrait * @param goods * @return */ public FileUploadResult drawGoodsPoster(String erCodeUrl, String portrait,GoodsDetailVO goods); /** * 分享小程序名片 * @param erCodeStream * @param user * @param goods * @return */ public FileUploadResult drawGoodsPosterXCX(InputStream erCodeStream, UserInfo user, GoodsDetailVO goods); public FileUploadResult drawDynamicGoodsPoster(String erCodeUrl, String portrait, String inviteCode, GoodsDetailVO goods); } fanli/src/main/java/com/yeshi/fanli/util/ImageUtil.java
Diff too large fanli/src/main/resource/env-dev/mongo.properties
@@ -1,4 +1,4 @@ mongo.dbname=flq mongo.dbname=flq-wxmp mongo.port=27016 #开发环境 #mongo.host=192.168.1.253 fanli/src/main/resource/env-dev/redis.properties
@@ -1,6 +1,9 @@ redis.addr=192.168.1.253 redis.port=6379 redis.auth=123456 #redis.addr=192.168.1.253 #redis.port=6379 #redis.auth=123456 redis.addr=193.112.34.40 redis.port=6379 redis.auth=weikou2014 redis.max_total=1024 redis.max_idle=200 redis.max_wait=10000 fanli/src/main/resource/image/banlikuaisheng.png
fanli/src/main/resource/image/share/qr_code_frame01.png
fanli/src/test/java/org/fanli/TaoKeTest.java
@@ -1,15 +1,18 @@ package org.fanli; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; import org.junit.Test; import org.yeshi.utils.HttpUtil; @@ -34,6 +37,7 @@ import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService; import com.yeshi.fanli.service.manger.goods.ConvertLinkManager; import com.yeshi.fanli.util.BeanUtil; import com.yeshi.fanli.util.FileUtil; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.TaoBaoConstant; import com.yeshi.fanli.util.TimeUtil; @@ -92,9 +96,12 @@ @Test public void test2() { TaoBaoGoodsBrief goods = TaoKeApiUtil.specialConvertCoupon(571754672318L, new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET)); System.out.println(goods); try { TaoKeApiUtil.getSimpleGoodsInfo(539432362036L); } catch (TaobaoGoodsDownException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @@ -376,4 +383,23 @@ } } @Test public void test12() { try { BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(new File("C:/Users/Administrator/Desktop/新建文本文档 (2).txt")))); String text = ""; String lineTxt = null; while ((lineTxt = br.readLine()) != null) {// 数据以逗号分隔 text += new String(lineTxt.getBytes("unicode"), "UTF-8"); } System.out.println(text); br.close(); } catch (Exception e) { } } }