diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java index 5a1e6e35..1cdfbee7 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsController.java @@ -47,6 +47,10 @@ public class GoodsController extends BaseController { private GoodsStandardService goodsStandardService; @Resource private ISysAreaService sysAreaService; + @Resource + private IInsuranceManagerService insuranceManagerService; + @Resource + private IDeptCategoryInsuranceRelationService deptCategoryInsuranceRelationService; @RequiresPermissions("goods:goods:view") @GetMapping() @@ -322,7 +326,24 @@ public class GoodsController extends BaseController { goodsStandard.setFinalPrice(finalPrice); }); result.setGoodsStandardList(goodsStandards); - + // 所有保险信息 + List insuranceManagers = insuranceManagerService.selectInsuranceManagerList(new InsuranceManager()); + // 查询本类目保险信息 + DeptCategoryInsuranceRelation param = new DeptCategoryInsuranceRelation(); + param.setType("01"); + param.setDeptCategoryId(goodsStandards.get(0).getDeptGoodsCategoryId()); + List deptCategoryInsuranceRelations = deptCategoryInsuranceRelationService.selectDeptCategoryInsuranceRelationList(param); + if(CollectionUtils.isNotEmpty(deptCategoryInsuranceRelations)){ + Map> insuranceMap = deptCategoryInsuranceRelations.stream().collect(Collectors.groupingBy(DeptCategoryInsuranceRelation::getInsuranceId)); + // 目标保险 + List goal = new ArrayList<>(); + insuranceManagers.forEach(model->{ + if(insuranceMap.containsKey(model.getId())){ + goal.add(model); + } + }); + result.setInsuranceManagers(goal); + } return AjaxResult.success(result); } catch (Exception e) { e.printStackTrace(); diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java index b7c1f2df..bd55836d 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/goods/GoodsDeptCategoryController.java @@ -38,6 +38,9 @@ public class GoodsDeptCategoryController extends BaseController { @Resource DeptGoodsCategoryService deptGoodsCategoryService; + @Resource + private GoodsCategoryService goodsCategoryService; + @Resource ICategoryInsuranceRelationService categoryInsuranceRelationService; @@ -157,6 +160,20 @@ public class GoodsDeptCategoryController extends BaseController { CategoryInsuranceRelation relation = new CategoryInsuranceRelation(); relation.setGoodsCategoryId(deptGoodsCategory.getGoodsCategoryId()); List relations = categoryInsuranceRelationService.selectCategoryInsuranceRelationList(relation); + // 当第四级没有的时候,往上找三级 + if(CollectionUtil.isEmpty(relations)){ + GoodsCategory model = goodsCategoryService.selectById(deptGoodsCategory.getGoodsCategoryId()); + CategoryInsuranceRelation parentRelation = new CategoryInsuranceRelation(); + parentRelation.setGoodsCategoryId(model.getParentCategoryId()); + relations = categoryInsuranceRelationService.selectCategoryInsuranceRelationList(parentRelation); + // 当第三级没有的时候,往上找二级 + if(CollectionUtil.isEmpty(relations)){ + GoodsCategory parentModel = goodsCategoryService.selectById(model.getParentCategoryId()); + CategoryInsuranceRelation topRelation = new CategoryInsuranceRelation(); + topRelation.setGoodsCategoryId(parentModel.getParentCategoryId()); + relations = categoryInsuranceRelationService.selectCategoryInsuranceRelationList(topRelation); + } + } // pc保险设置 List pcInsuranceList = new ArrayList<>(); // 商城保险设置 diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index a61a4189..36d77d99 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -108,6 +108,9 @@ public class OrderController extends BaseController { @Resource private GoodsCategoryService goodsCategoryService; + @Resource + private IInsuranceManagerService insuranceManagerService; + @GetMapping("/imgs") public String orderImgs(Long orderId, ModelMap mmap){ @@ -546,6 +549,14 @@ public class OrderController extends BaseController { BigDecimal discountMoney = BigDecimal.ZERO; BigDecimal payMoney = totalPay.subtract(discountMoney); + // 保险金额 + if(appOrderRequest.getInsuranceId() != null){ + InsuranceManager manager = insuranceManagerService.selectInsuranceManagerById(appOrderRequest.getInsuranceId()); + if(manager != null){ + payMoney = payMoney.add(manager.getInsuranceAmount()); + } + } + // 当实付金额payType<=0时 使payType=BigDecimal.ZERO payMoney = BigDecimal.ZERO.max(payMoney); diff --git a/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java b/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java index 9a6a8468..cbb61aac 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java +++ b/ghy-goods/src/main/java/com/ghy/goods/domain/Goods.java @@ -89,4 +89,7 @@ public class Goods extends BaseEntity { private List lbUrl; private String keyword; + + + private List insuranceManagers; } diff --git a/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptCategoryInsuranceRelationServiceImpl.java b/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptCategoryInsuranceRelationServiceImpl.java index 71748874..28137575 100644 --- a/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptCategoryInsuranceRelationServiceImpl.java +++ b/ghy-goods/src/main/java/com/ghy/goods/service/impl/DeptCategoryInsuranceRelationServiceImpl.java @@ -2,6 +2,8 @@ package com.ghy.goods.service.impl; import java.util.List; import com.ghy.common.utils.DateUtils; +import com.ghy.common.utils.StringUtils; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ghy.goods.mapper.DeptCategoryInsuranceRelationMapper; @@ -97,6 +99,50 @@ public class DeptCategoryInsuranceRelationServiceImpl implements IDeptCategoryIn @Override public void updateDeptCategoryInsuranceRelation(String pcInsuranceIds, String shopInsuranceIds, Long deptGoodsCategoryId) { + // pc -- + if(StringUtils.isNotEmpty(pcInsuranceIds)){ + // 删除旧的 + DeptCategoryInsuranceRelation pcRelationParam = new DeptCategoryInsuranceRelation(); + pcRelationParam.setDeptCategoryId(deptGoodsCategoryId); + pcRelationParam.setType("02"); + List pcRelationOld = deptCategoryInsuranceRelationMapper.selectDeptCategoryInsuranceRelationList(pcRelationParam); + if(CollectionUtils.isNotEmpty(pcRelationOld)){ + pcRelationOld.forEach(model->{ + deptCategoryInsuranceRelationMapper.deleteDeptCategoryInsuranceRelationById(model.getId()); + }); + } + // 增加新的 + for (String id : pcInsuranceIds.split(",")) { + DeptCategoryInsuranceRelation pcRelation = new DeptCategoryInsuranceRelation(); + pcRelation.setDeptCategoryId(deptGoodsCategoryId); + pcRelation.setType("02"); + pcRelation.setInsuranceId(Long.valueOf(id)); + deptCategoryInsuranceRelationMapper.insertDeptCategoryInsuranceRelation(pcRelation); + } + + } + // 商城 -- + if(StringUtils.isNotEmpty(shopInsuranceIds)){ + // 删除旧的 + DeptCategoryInsuranceRelation pcRelationParam = new DeptCategoryInsuranceRelation(); + pcRelationParam.setDeptCategoryId(deptGoodsCategoryId); + pcRelationParam.setType("01"); + List pcRelationOld = deptCategoryInsuranceRelationMapper.selectDeptCategoryInsuranceRelationList(pcRelationParam); + if(CollectionUtils.isNotEmpty(pcRelationOld)){ + pcRelationOld.forEach(model->{ + deptCategoryInsuranceRelationMapper.deleteDeptCategoryInsuranceRelationById(model.getId()); + }); + } + // 增加新的 + for (String id : shopInsuranceIds.split(",")) { + DeptCategoryInsuranceRelation pcRelation = new DeptCategoryInsuranceRelation(); + pcRelation.setDeptCategoryId(deptGoodsCategoryId); + pcRelation.setType("01"); + pcRelation.setInsuranceId(Long.valueOf(id)); + deptCategoryInsuranceRelationMapper.insertDeptCategoryInsuranceRelation(pcRelation); + } + + } } } diff --git a/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java b/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java index ffe1b9b6..c835d713 100644 --- a/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java +++ b/ghy-order/src/main/java/com/ghy/order/request/AppOrderRequest.java @@ -44,4 +44,5 @@ public class AppOrderRequest { private Long goodsId; + private Long insuranceId; }