From 3b65e9fae886d8e0215a103df942e3d9f7589c9b Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Mon, 11 Nov 2024 14:34:51 +0800 Subject: [PATCH] /1 --- .../controller/cms/CmsContentController.java | 1 + .../controller/cms/CmsContentController.java | 75 ++++++++++++++++++- .../java/com/hfkj/model/CmsContentModel.java | 13 ++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 service/src/main/java/com/hfkj/model/CmsContentModel.java diff --git a/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java b/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java index 8a0edb2..f871eb6 100644 --- a/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java +++ b/bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java @@ -70,6 +70,7 @@ public class CmsContentController { cmsContent.setName(body.getName()); cmsContent.setAppid(body.getAppid()); cmsContent.setJumpType(body.getJumpType()); + cmsContent.setShowType(body.getShowType()); cmsContent.setJumpUrl(body.getJumpUrl()); cmsContent.setPlatformCode(body.getPlatformCode()); cmsContent.setImg(body.getImg()); diff --git a/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java index cd99179..0fb2eb9 100644 --- a/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java +++ b/cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java @@ -1,12 +1,20 @@ package com.cweb.controller.cms; import com.hfkj.common.utils.ResponseMsgUtil; +import com.hfkj.entity.CmsContent; +import com.hfkj.entity.GoodsMsg; +import com.hfkj.entity.GoodsSpecs; +import com.hfkj.model.CmsContentModel; import com.hfkj.model.ResponseData; +import com.hfkj.model.goods.GoodsModel; import com.hfkj.service.cms.CmsContentService; +import com.hfkj.service.goods.GoodsMsgService; +import com.hfkj.service.goods.GoodsSpecsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -14,8 +22,12 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Controller @RequestMapping(value="/cms") @@ -27,6 +39,12 @@ public class CmsContentController { @Resource private CmsContentService cmsContentService; + @Resource + private GoodsMsgService goodsMsgService; + + @Resource + private GoodsSpecsService goodsSpecsService; + @RequestMapping(value="/getCms",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询列表") @@ -41,7 +59,62 @@ public class CmsContentController { } map.put("status", 1); map.put("platformCode", platformCode); - return ResponseMsgUtil.success(cmsContentService.getList(map)); + List list = cmsContentService.getList(map); + List goodsMsgList = goodsMsgService.getList(new HashMap<>()); + List specsList = goodsSpecsService.getList(new HashMap<>()); + + List cmsContents = new ArrayList<>(); + + for (CmsContent cmsContent : list) { + List goodsModels = new ArrayList<>(); + if (cmsContent.getShowType() != null) { + + List goodsMsgs = new ArrayList<>(); + + if (cmsContent.getShowType() == 1) { + goodsMsgs = goodsMsgList.stream().filter(s -> s.getGoodsType().equals(cmsContent.getShowDataId().longValue())).limit(2).collect(Collectors.toList()); + } + if (cmsContent.getShowType() == 2) { + goodsMsgs = goodsMsgList.stream().filter(s -> s.getGoodsType().equals(cmsContent.getShowDataId().longValue())).limit(4).collect(Collectors.toList()); + } + if (cmsContent.getShowType() == 3) { + goodsMsgs = goodsMsgList.stream().filter(s -> s.getGoodsType().equals(cmsContent.getShowDataId().longValue())).limit(10).collect(Collectors.toList()); + } + + for (GoodsMsg goodsMsg : goodsMsgs) { + + GoodsModel goodsModel = new GoodsModel(); + + List goodsSpecs = specsList.stream().filter(s -> s.getGoodsId().equals(goodsMsg.getId())).collect(Collectors.toList()); + + if (!goodsSpecs.isEmpty()) { + BigDecimal minPrice = goodsSpecs.get(0).getSalePrice(); + BigDecimal minOriginalPrice = goodsSpecs.get(0).getOriginalPrice(); + + for (GoodsSpecs specs : goodsSpecs) { + if (specs.getSalePrice().compareTo(minPrice) < 0) { + minPrice = specs.getSalePrice(); + minOriginalPrice = specs.getOriginalPrice(); + } + } + BeanUtils.copyProperties(goodsMsg, goodsModel); + goodsModel.setOriginalPrice(minOriginalPrice); + goodsModel.setPrice(minPrice); + + goodsModels.add(goodsModel); + + } + } + + } + CmsContentModel cmsContentModel = new CmsContentModel(); + + BeanUtils.copyProperties(cmsContent, cmsContentModel); + cmsContentModel.setGoodsMsgList(goodsModels); + cmsContents.add(cmsContentModel); + } + + return ResponseMsgUtil.success(cmsContents); } catch (Exception e) { log.error("error!",e); diff --git a/service/src/main/java/com/hfkj/model/CmsContentModel.java b/service/src/main/java/com/hfkj/model/CmsContentModel.java new file mode 100644 index 0000000..92e4639 --- /dev/null +++ b/service/src/main/java/com/hfkj/model/CmsContentModel.java @@ -0,0 +1,13 @@ +package com.hfkj.model; + +import com.hfkj.entity.CmsContent; +import com.hfkj.model.goods.GoodsModel; +import lombok.Data; + +import java.util.List; + +@Data +public class CmsContentModel extends CmsContent { + + List goodsMsgList; +}