袁野 2 weeks ago
parent 0a924233ba
commit 3b65e9fae8
  1. 1
      bweb/src/main/java/com/bweb/controller/cms/CmsContentController.java
  2. 75
      cweb/src/main/java/com/cweb/controller/cms/CmsContentController.java
  3. 13
      service/src/main/java/com/hfkj/model/CmsContentModel.java

@ -70,6 +70,7 @@ public class CmsContentController {
cmsContent.setName(body.getName()); cmsContent.setName(body.getName());
cmsContent.setAppid(body.getAppid()); cmsContent.setAppid(body.getAppid());
cmsContent.setJumpType(body.getJumpType()); cmsContent.setJumpType(body.getJumpType());
cmsContent.setShowType(body.getShowType());
cmsContent.setJumpUrl(body.getJumpUrl()); cmsContent.setJumpUrl(body.getJumpUrl());
cmsContent.setPlatformCode(body.getPlatformCode()); cmsContent.setPlatformCode(body.getPlatformCode());
cmsContent.setImg(body.getImg()); cmsContent.setImg(body.getImg());

@ -1,12 +1,20 @@
package com.cweb.controller.cms; package com.cweb.controller.cms;
import com.hfkj.common.utils.ResponseMsgUtil; 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.ResponseData;
import com.hfkj.model.goods.GoodsModel;
import com.hfkj.service.cms.CmsContentService; 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.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; 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 org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
@Controller @Controller
@RequestMapping(value="/cms") @RequestMapping(value="/cms")
@ -27,6 +39,12 @@ public class CmsContentController {
@Resource @Resource
private CmsContentService cmsContentService; private CmsContentService cmsContentService;
@Resource
private GoodsMsgService goodsMsgService;
@Resource
private GoodsSpecsService goodsSpecsService;
@RequestMapping(value="/getCms",method = RequestMethod.GET) @RequestMapping(value="/getCms",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询列表") @ApiOperation(value = "查询列表")
@ -41,7 +59,62 @@ public class CmsContentController {
} }
map.put("status", 1); map.put("status", 1);
map.put("platformCode", platformCode); map.put("platformCode", platformCode);
return ResponseMsgUtil.success(cmsContentService.getList(map)); List<CmsContent> list = cmsContentService.getList(map);
List<GoodsMsg> goodsMsgList = goodsMsgService.getList(new HashMap<>());
List<GoodsSpecs> specsList = goodsSpecsService.getList(new HashMap<>());
List<CmsContentModel> cmsContents = new ArrayList<>();
for (CmsContent cmsContent : list) {
List<GoodsModel> goodsModels = new ArrayList<>();
if (cmsContent.getShowType() != null) {
List<GoodsMsg> 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> 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) { } catch (Exception e) {
log.error("error!",e); log.error("error!",e);

@ -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<GoodsModel> goodsMsgList;
}
Loading…
Cancel
Save