瀏覽代碼

增加销售政策功能

FengChaoYu 4 周之前
父節點
當前提交
40e47bc77a
共有 18 個文件被更改,包括 1719 次插入1 次删除
  1. 26 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/funds/CustomerWalletBean.java
  2. 21 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyBean.java
  3. 20 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyConditionAdd.java
  4. 25 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyConditionMaterialBean.java
  5. 21 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyDelayBean.java
  6. 33 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyMaterialAddBean.java
  7. 27 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyMaterialBean.java
  8. 73 0
      mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyVO.java
  9. 9 0
      mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java
  10. 3 0
      mall-server-api/src/main/java/com/gree/mall/manager/constant/Constant.java
  11. 291 0
      mall-server-api/src/main/java/com/gree/mall/manager/controller/supply/policy/PolicyController.java
  12. 23 0
      mall-server-api/src/main/java/com/gree/mall/manager/enums/supply/PolicyTypeEnum.java
  13. 35 1
      mall-server-api/src/main/java/com/gree/mall/manager/logic/common/CommonLogic.java
  14. 7 0
      mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/funds/CompanyWalletBalanceLogic.java
  15. 75 0
      mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/funds/CompanyWalletLogic.java
  16. 1019 0
      mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/policy/PolicyLogic.java
  17. 11 0
      mall-server-api/src/main/resources/mapper/CommonMapper.xml
  18. 二進制
      mall-server-api/src/main/resources/template/policy_goods.xlsx

+ 26 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/funds/CustomerWalletBean.java

@@ -0,0 +1,26 @@
+package com.gree.mall.manager.bean.supply.funds;
+
+import com.gree.mall.manager.plus.entity.AdminCompanyWalletBalance;
+import com.gree.mall.manager.plus.entity.RebateTypeUseRate;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@ApiModel
+@Data
+public class CustomerWalletBean extends AdminCompanyWalletBalance {
+
+    @ApiModelProperty("钱包名称")
+    private String name;
+
+    @ApiModelProperty("返利使用比例")
+    private List<RebateTypeUseRate> walletRaleTypes;
+
+    private List<String> saleTypeIds;
+
+
+}

+ 21 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyBean.java

@@ -0,0 +1,21 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import com.gree.mall.manager.plus.entity.Policy;
+import com.gree.mall.manager.plus.entity.PolicyCustomer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@Data
+@ApiModel
+public class PolicyBean extends Policy {
+
+    @ApiModelProperty("选择的经销商")
+    private List<PolicyCustomer> policyCustomers;
+    @ApiModelProperty("对应经销商数量")
+    private Integer customerCount;
+}

+ 20 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyConditionAdd.java

@@ -0,0 +1,20 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import com.gree.mall.manager.plus.entity.PolicyCondition;
+import com.gree.mall.manager.plus.entity.PolicyConditionMaterial;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@ApiModel
+@Data
+public class PolicyConditionAdd extends PolicyCondition {
+
+    @ApiModelProperty("条件机型")
+    private List<PolicyConditionMaterial> policyConditionMaterials;
+
+}

+ 25 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyConditionMaterialBean.java

@@ -0,0 +1,25 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import com.gree.mall.manager.bean.supply.funds.CustomerWalletBean;
+import com.gree.mall.manager.plus.entity.PolicyConditionMaterial;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@ApiModel
+@Data
+public class PolicyConditionMaterialBean extends PolicyConditionMaterial {
+
+
+    @ApiModelProperty("现金钱包")
+    private List<CustomerWalletBean> wallets = new ArrayList<>();
+
+    @ApiModelProperty("返利钱包")
+    private List<CustomerWalletBean> rebateWallets = new ArrayList<>();
+
+}

+ 21 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyDelayBean.java

@@ -0,0 +1,21 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.Date;
+
+@ApiModel
+@Data
+public class PolicyDelayBean {
+
+    @NotBlank(message = "政策id不能为空")
+    @ApiModelProperty("政策id")
+    private String policyId;
+    @NotNull(message = "延期时间不能为空")
+    @ApiModelProperty("延期时间")
+    private Date endTime;
+}

+ 33 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyMaterialAddBean.java

@@ -0,0 +1,33 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.List;
+
+@ApiModel
+@Data
+public class PolicyMaterialAddBean {
+
+    @ApiModelProperty("主键id")
+    private String id;
+    @ApiModelProperty("政策id")
+    private String policyId;
+    @ApiModelProperty("物料id")
+    private String goodsMaterialId;
+    @ApiModelProperty("销售类型id")
+    private String salesTypeId;
+    @ApiModelProperty("单价")
+    private BigDecimal price;
+    @ApiModelProperty("原供价")
+    private BigDecimal orgPrice;
+    @ApiModelProperty("备注")
+    private String remark;
+    @ApiModelProperty("钱包id")
+    private List<String> walletIds;
+    @ApiModelProperty("返利钱包id")
+    private List<String> rebateWalletIds;
+
+}

+ 27 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyMaterialBean.java

@@ -0,0 +1,27 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import com.gree.mall.manager.bean.supply.funds.CustomerWalletBean;
+import com.gree.mall.manager.plus.entity.PolicyMaterial;
+import com.gree.mall.manager.plus.entity.PolicyWalletRela;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@EqualsAndHashCode(callSuper = true)
+@ApiModel
+@Data
+public class PolicyMaterialBean extends PolicyMaterial {
+
+    @ApiModelProperty("钱包")
+    private List<PolicyWalletRela> walletRelaList;
+
+    @ApiModelProperty("现金钱包")
+    private List<CustomerWalletBean> wallets = new ArrayList<>();
+
+    @ApiModelProperty("返利钱包")
+    private List<CustomerWalletBean> rebateWallets = new ArrayList<>();
+}

+ 73 - 0
mall-server-api/src/main/java/com/gree/mall/manager/bean/supply/policy/PolicyVO.java

@@ -0,0 +1,73 @@
+package com.gree.mall.manager.bean.supply.policy;
+
+import com.gree.mall.manager.annotation.ZfireField;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.enums.material.StateEnum;
+import com.gree.mall.manager.enums.supply.PolicyTypeEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+@ApiModel
+@ZfireField(tbName = "a")
+public class PolicyVO {
+
+    @ZfireField(hide = true)
+    @ApiModelProperty(value = "id")
+    private String id;
+
+    @ApiModelProperty(value = "销售政策编号")
+    private String code;
+
+    @ApiModelProperty(value = "销售政策名称")
+    private String title;
+
+    @ApiModelProperty(value = "政策类型")
+    private PolicyTypeEnum type;
+
+    @ApiModelProperty(value = "状态")
+    private StateEnum status;
+
+    @ApiModelProperty(value = "表头备注")
+    private String remark;
+
+    @ApiModelProperty(value = "生效日期开始时间")
+    private Date startTime;
+
+    @ApiModelProperty(value = "生效日期结束时间")
+    private Date endTime;
+
+    @ApiModelProperty(value = "审核状态")
+    private ExamineStatusEnum examineStatus;
+
+    @ApiModelProperty(value = "审核备注")
+    private String examineRemark;
+
+    @ApiModelProperty(value = "审核人")
+    private String examineBy;
+
+    @ApiModelProperty(value = "审核时间")
+    private Date examineTime;
+
+    @ApiModelProperty(value = "创建人")
+    private String createBy;
+
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+
+    @ApiModelProperty(value = "修改人")
+    private String updateBy;
+
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+
+//    @ApiModelProperty(value = "最小可提数(0=不限制,一个订单最小下多少台机型,只针对限量政策)")
+//    private Integer minBuyNum;
+//
+//    @ApiModelProperty(value = "最大可提组数(0=不限制,可以最多下多少次该政策的订单,只针对限量政策)")
+//    private Integer maxBuyNum;
+
+}

+ 9 - 0
mall-server-api/src/main/java/com/gree/mall/manager/commonmapper/CommonMapper.java

@@ -30,6 +30,7 @@ import com.gree.mall.manager.bean.supply.funds.AdminCompanyRebateAccVO;
 import com.gree.mall.manager.bean.supply.funds.AdminCompanyWalletAccVO;
 import com.gree.mall.manager.bean.supply.funds.RebateVO;
 import com.gree.mall.manager.bean.supply.funds.ReceiptVO;
+import com.gree.mall.manager.bean.supply.policy.PolicyVO;
 import com.gree.mall.manager.bean.supply.sales.config.*;
 import com.gree.mall.manager.bean.supply.sales.price.ProductPriceUpdateVO;
 import com.gree.mall.manager.bean.supply.sales.price.ProductPriceVO;
@@ -784,4 +785,12 @@ public interface CommonMapper {
      * @return
      */
     IPage<AdminCompanyRebateAccVO> rebateBalanceUseAccList(Page page, @Param("ex") ZfireParamBean zfireParamBean);
+
+    /**
+     * 销售政策列表
+     * @param page
+     * @param zfireParamBean
+     * @return
+     */
+    IPage<PolicyVO> policyList(Page page, @Param("ex") ZfireParamBean zfireParamBean);
 }

+ 3 - 0
mall-server-api/src/main/java/com/gree/mall/manager/constant/Constant.java

@@ -24,6 +24,9 @@ public class Constant {
     // 辅材编号前缀
     public final static String FC = "FC";
 
+    // 政策id前缀
+    public final static String POLICY_ID = "";
+
     public final static List<String> INIT_INCR_LIST = Arrays.asList("WEBSIT_ID");
 
     public class Ali {

+ 291 - 0
mall-server-api/src/main/java/com/gree/mall/manager/controller/supply/policy/PolicyController.java

@@ -0,0 +1,291 @@
+package com.gree.mall.manager.controller.supply.policy;
+
+import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.gree.mall.manager.annotation.ZfireList;
+import com.gree.mall.manager.bean.ExcelData;
+import com.gree.mall.manager.bean.supply.policy.*;
+import com.gree.mall.manager.constant.Constant;
+import com.gree.mall.manager.helper.ResponseHelper;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.logic.supply.policy.PolicyLogic;
+import com.gree.mall.manager.plus.entity.Policy;
+import com.gree.mall.manager.plus.entity.PolicyCondition;
+import com.gree.mall.manager.plus.entity.PolicyCustomer;
+import com.gree.mall.manager.utils.excel.ExcelUtils;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+
+@Slf4j
+@RestController
+@Api(value = "销售政策API", tags = {"销售政策API"})
+@RequestMapping(value = "/supply/policy", produces = "application/json; charset=utf-8")
+public class PolicyController {
+
+    @Resource
+    PolicyLogic policyLogic;
+    @Resource
+    CommonLogic commonLogic;
+
+    @ZfireList
+    @PostMapping("/list")
+    @ApiOperation(value = "列表")
+    public ResponseHelper<IPage<PolicyVO>> list(
+            @RequestBody ZfireParamBean zfireParamBean
+    ) {
+        IPage<PolicyVO> page = policyLogic.list(zfireParamBean);
+        return ResponseHelper.success(page, new TypeReference<PolicyVO>() {
+        });
+    }
+
+    @PostMapping("/list/export")
+    @ApiOperation(value = "导出")
+    public void listExport(@RequestBody ZfireParamBean zfireParamBean, HttpServletRequest request, HttpServletResponse response) throws Exception {
+        //2.查询要导出的内容
+        IPage<PolicyVO> page = policyLogic.list(zfireParamBean);
+        //3.导出
+        FieldUtils.exportData(page.getRecords(), zfireParamBean.getExportFields(), request, response);
+    }
+
+    @PostMapping("/detail")
+    @ApiOperation("获取销售政策详情")
+    public ResponseHelper<Policy> detail(
+            @ApiParam(value = "销售政策id") @RequestParam(required = false) String policyId
+    ) {
+        Policy detail = policyLogic.detail(policyId);
+        return ResponseHelper.success(detail);
+    }
+
+    @PostMapping("/id")
+    @ApiOperation("获取销售政策编号")
+    public ResponseHelper<String> id() {
+        return ResponseHelper.success(commonLogic.generateReqNo("", Constant.POLICY_ID, 14));
+    }
+
+    @PostMapping("/add")
+    @ApiOperation("新增政策和经销商")
+    public ResponseHelper<String> add(@RequestBody PolicyBean policyBean) {
+        String id = policyLogic.add(policyBean);
+        return ResponseHelper.success(id);
+    }
+
+    @PostMapping("/update")
+    @ApiOperation("编辑政策和经销商")
+    public ResponseHelper update(@RequestBody PolicyBean policyBean) {
+        policyLogic.update(policyBean);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/delete")
+    @ApiOperation("删除政策和经销商")
+    public ResponseHelper delete(@RequestParam String id) {
+        policyLogic.delete(id);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/cancel")
+    @ApiOperation("政策-作废")
+    public ResponseHelper cancel(@RequestParam String id) {
+        policyLogic.cancel(id);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/batch/delay/update")
+    @ApiOperation("政策-批量修改延期时间")
+    public ResponseHelper importLimit(
+            @RequestBody List<PolicyDelayBean> list
+    ) throws IOException {
+        policyLogic.batchUpdateDelay(list);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/condition/add")
+    @ApiOperation("新增政策条件")
+    public ResponseHelper addCondition(@RequestBody PolicyConditionAdd policyConditionAdd) {
+        policyLogic.addCondition(policyConditionAdd);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/condition/update")
+    @ApiOperation("修改政策条件")
+    public ResponseHelper addCondition(
+            @ApiParam(value = "id", required = true) @RequestParam String id,
+            @ApiParam(value = "条件名称", required = true) @RequestParam String name
+    ) {
+        policyLogic.updateCondition(id, name);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/condition/delete")
+    @ApiOperation("删除政策条件")
+    public ResponseHelper deleteCondition(@RequestParam String id) {
+        policyLogic.deleteCondition(id);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/condition/detail")
+    @ApiOperation("政策条件-详情")
+    public ResponseHelper<PolicyCondition> conditionDetail(@RequestParam String id) {
+        PolicyCondition policyCondition = policyLogic.detailCondition(id);
+        return ResponseHelper.success(policyCondition);
+    }
+
+    @PostMapping("/submit")
+    @ApiOperation("提审政策")
+    public ResponseHelper submit(
+            @ApiParam(value = "政策id") @RequestParam String policyId
+    ) {
+        policyLogic.submit(policyId);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/examine")
+    @ApiOperation("审核销售政策")
+    public ResponseHelper examine(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId,
+            @ApiParam(value = "审核 OK=通过  FAIL=不通过", required = true) @RequestParam String examineStatus,
+            @ApiParam(value = "审核备注") @RequestParam(required = false) String examineRemark
+    ) {
+        policyLogic.examine(policyId, examineStatus, examineRemark);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/material/list")
+    @ApiOperation("政策机型-列表")
+    public ResponseHelper<IPage<PolicyMaterialBean>> materialList(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId,
+            @ApiParam(value = "机型规格") @RequestParam(required = false) String specification,
+            @ApiParam(value = "是否配提(true=是,false=否)") @RequestParam(required = false) Boolean isProvision,
+            @ApiParam(value = "是否启用(true=是,false=否)") @RequestParam(required = false) Boolean status,
+            @ApiParam(value = "销售类型编号") @RequestParam(required = false) String salesTypeCode,
+            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
+    ) {
+        IPage<PolicyMaterialBean> policyMaterialIPage = policyLogic.materialList(policyId, specification, isProvision, status, salesTypeCode, pageNum, pageSize);
+        return ResponseHelper.success(policyMaterialIPage);
+    }
+
+    @PostMapping("/material/save")
+    @ApiOperation("政策机型-保存")
+    public ResponseHelper addMaterial(
+            @RequestBody List<PolicyMaterialAddBean> policyMaterialAddBeans
+    ) {
+        policyLogic.saveMaterial(policyMaterialAddBeans);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/clone")
+    @ApiOperation("政策-克隆")
+    public ResponseHelper clone(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId
+    ) {
+        policyLogic.clonePolicy(policyId);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/abandon")
+    @ApiOperation("政策弃审")
+    public ResponseHelper abandon(
+            @ApiParam(value = "policyId", required = true) @RequestParam String policyId
+    ) throws Exception {
+        policyLogic.abandon(policyId);
+        return ResponseHelper.success();
+    }
+
+    @PostMapping("/type1/material/list")
+    @ApiOperation("政策-限定机型列表")
+    public ResponseHelper<IPage<PolicyConditionMaterialBean>> type1MaterialList(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId,
+            @ApiParam(value = "销售类型编号") @RequestParam(required = false) String saleTypeCode,
+            @ApiParam(value = "机型型号") @RequestParam(required = false) String specification,
+            @ApiParam(value = "机型状态 true=启用 false=未启用") @RequestParam(required = false) Boolean status,
+            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
+    ) {
+        IPage<PolicyConditionMaterialBean> policyMaterialIPage = policyLogic.type1MaterialList(policyId, saleTypeCode, specification, status, pageNum, pageSize);
+        return ResponseHelper.success(policyMaterialIPage);
+    }
+
+    @PostMapping("/customer/list")
+    @ApiOperation("政策经销商列表")
+    public ResponseHelper<IPage<PolicyCustomer>> customerList(
+            @ApiParam(value = "政策id", required = true) @RequestParam(required = true) String policyId,
+            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
+    ) {
+        IPage<PolicyCustomer> policyCustomerIPage = policyLogic.customerList(policyId, pageNum, pageSize);
+        return ResponseHelper.success(policyCustomerIPage);
+    }
+
+    @PostMapping("/condition/material/list")
+    @ApiOperation("政策条件的机型列表")
+    public ResponseHelper<IPage<PolicyConditionMaterialBean>> conditionList(
+            @ApiParam(value = "政策条件的id", required = true) @RequestParam String policyConditionId,
+            @ApiParam(value = "比例类型 1=比例第一个值的商品 2=比例第二个值的商品") @RequestParam(required = false) Integer popType,
+            @ApiParam(value = "机型型号") @RequestParam(required = false) String specification,
+            @ApiParam(value = "经销商id") @RequestParam(required = false) String customerId,
+            @ApiParam(value = "机型状态 true=启用 false=未启用") @RequestParam(required = false) Boolean status,
+            @ApiParam(value = "页号", required = true) @RequestParam Integer pageNum,
+            @ApiParam(value = "页大小", required = true) @RequestParam Integer pageSize
+    ) {
+        IPage<PolicyConditionMaterialBean> policyConditionMaterialIPage = policyLogic.conditionMaterialList(policyConditionId, popType, specification,
+                customerId, status, pageNum, pageSize);
+        return ResponseHelper.success(policyConditionMaterialIPage);
+    }
+
+    @PostMapping("/condition/list")
+    @ApiOperation("政策条件列表")
+    public ResponseHelper<List<PolicyCondition>> conditionList(
+            @ApiParam(value = "政策id") @RequestParam String policyId
+    ) {
+        List<PolicyCondition> policyConditions = policyLogic.conditionList(policyId);
+        return ResponseHelper.success(policyConditions);
+    }
+
+    @PostMapping("/condition/get")
+    @ApiOperation("根据政策id和物料id反查政策条件")
+    public ResponseHelper<PolicyCustomer> getCondition(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId,
+            @ApiParam(value = "物料id", required = true) @RequestParam String materialId
+    ) {
+        PolicyCondition condition = policyLogic.getCondition(policyId, materialId);
+        return ResponseHelper.success(condition);
+    }
+
+    @PostMapping("/material/import")
+    @ApiOperation("导入政策产品")
+    public ResponseHelper importMaterial(
+            @ApiParam(value = "政策id") @RequestParam String policyId,
+            MultipartFile file
+    ) throws IOException {
+        List<Object> objects = ExcelUtils.importExcel(file);
+        policyLogic.importMaterial(policyId, objects);
+        return ResponseHelper.success();
+    }
+
+    @GetMapping("/material/export")
+    @ApiOperation("导出-政策产品")
+    public void exportMaterial(
+            @ApiParam(value = "政策id", required = true) @RequestParam String policyId,
+            @ApiParam(value = "规格") @RequestParam(required = false) String specification,
+            HttpServletRequest request,
+            HttpServletResponse response
+    ) throws Exception {
+        IPage<PolicyMaterialBean> policyMaterialBeanIPage = policyLogic.materialList(policyId, specification,
+                null, null, null, 1, -1);
+        ExcelData excelData = policyLogic.exportMaterial(policyMaterialBeanIPage.getRecords());
+        ExcelUtils.exportExcel(request, response, "政策产品.xlsx", excelData);
+    }
+}

+ 23 - 0
mall-server-api/src/main/java/com/gree/mall/manager/enums/supply/PolicyTypeEnum.java

@@ -0,0 +1,23 @@
+package com.gree.mall.manager.enums.supply;
+
+
+import com.baomidou.mybatisplus.annotation.EnumValue;
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.gree.mall.manager.enums.base.BaseEnum;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+public enum PolicyTypeEnum implements BaseEnum {
+
+    PROVISION("PROVISION","配提"),
+    LIMIT("LIMIT","限量"),
+            ;
+
+    @EnumValue
+    @JsonValue
+    private final String key;
+    private final String remark;
+}

+ 35 - 1
mall-server-api/src/main/java/com/gree/mall/manager/logic/common/CommonLogic.java

@@ -2,6 +2,7 @@ package com.gree.mall.manager.logic.common;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.extra.servlet.ServletUtil;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.constant.Constant;
@@ -57,6 +58,7 @@ public class CommonLogic {
     private final AdminDeptWebsitService adminDeptWebsitService;
     private final IncrKeyValueService incrKeyValueService;
     private final AdminUserStorageRelaService adminUserStorageRelaService;
+    private final AdminModuleService adminModuleService;
 
 
     public Map<String, String> getOSSConfig() throws UnsupportedEncodingException {
@@ -393,7 +395,7 @@ public class CommonLogic {
         String tNumKey = Constant.RedisPrefix.ORDER_NUM + orderType + dayFmt;
         StringBuffer number = new StringBuffer();
         number.append(start);
-        // number.append(dayFmt);
+        number.append(dayFmt);
         int ramainLen = length - number.toString().length();
         //自增 填充位数
         Object value = redisUtil.incr(tNumKey, 1);
@@ -489,4 +491,36 @@ public class CommonLogic {
         }
         return adminUser;
     }
+
+    public String getIp(){
+        HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
+        String clientIP = ServletUtil.getClientIP(request, null);
+        return clientIP;
+    }
+
+    /**
+     * 保存操作日志
+     */
+    public void saveLog(String id,String type,String content){
+        OperatorLog operatorLog = this.supplyLog(id, type, content);
+        operatorLog.insert();
+    }
+
+    public OperatorLog supplyLog(String id,String type,String content){
+        HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
+        AdminUserCom adminUser = this.getAdminUser(request);
+        //当前菜单ID
+        String moduleId = request.getHeader("moduleId");
+        AdminModule adminModule = adminModuleService.getById(moduleId);
+        OperatorLog operatorLog = new OperatorLog();
+        operatorLog.setObjId(id);
+        if(adminModule != null) {
+            operatorLog.setModuleName(adminModule.getModuleName());
+        }
+        operatorLog.setUserName(adminUser.getNickName()+"("+adminUser.getUserName()+")");
+        operatorLog.setType(type);
+        operatorLog.setContent(content);
+        operatorLog.setIp(this.getIp());
+        return operatorLog;
+    }
 }

+ 7 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/funds/CompanyWalletBalanceLogic.java

@@ -150,4 +150,11 @@ public class CompanyWalletBalanceLogic {
             obtain.unlock();
         }
     }
+
+
+    public List<AdminCompanyWalletBalance> getAllAdminCompanyWallet(String adminCompanyId) {
+        return adminCompanyWalletBalanceService.lambdaQuery()
+                .eq(AdminCompanyWalletBalance::getCompanyWechatId, adminCompanyId)
+                .list();
+    }
 }

+ 75 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/funds/CompanyWalletLogic.java

@@ -2,8 +2,11 @@ package com.gree.mall.manager.logic.supply.funds;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
+import com.aliyuncs.utils.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.gree.mall.manager.bean.admin.AdminUserCom;
 import com.gree.mall.manager.bean.supply.funds.CompanyWalletBalanceDTO;
+import com.gree.mall.manager.bean.supply.funds.CustomerWalletBean;
 import com.gree.mall.manager.enums.ExamineStatusEnum;
 import com.gree.mall.manager.enums.material.DirectFlagEnum;
 import com.gree.mall.manager.enums.supply.BalanceBillTypeEnum;
@@ -11,18 +14,24 @@ import com.gree.mall.manager.enums.supply.BalanceTypeEnum;
 import com.gree.mall.manager.enums.supply.RebateBillTypeEnum;
 import com.gree.mall.manager.enums.supply.ReceiptBillTypeEnum;
 import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.plus.entity.AdminCompanyWalletBalance;
 import com.gree.mall.manager.plus.entity.Rebate;
+import com.gree.mall.manager.plus.entity.RebateTypeUseRate;
 import com.gree.mall.manager.plus.entity.Receipt;
 import com.gree.mall.manager.plus.service.RebateService;
+import com.gree.mall.manager.plus.service.RebateTypeUseRateService;
 import com.gree.mall.manager.plus.service.ReceiptService;
+import com.gree.mall.manager.plus.service.SalesTypeService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Objects;
 import java.util.stream.Collectors;
 
@@ -31,6 +40,8 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor
 public class CompanyWalletLogic {
 
+    public final SalesTypeService salesTypeService;
+    public final RebateTypeUseRateService rebateTypeUseRateService;
     public final ReceiptService receiptService;
     public final RebateService rebateService;
     public final CompanyWalletBalanceLogic companyWalletBalanceLogic;
@@ -152,4 +163,68 @@ public class CompanyWalletLogic {
                 .in(Rebate::getId, rebateList.stream().map(Rebate::getId).collect(Collectors.toSet()))
                 .update();
     }
+
+    /**
+     * 查询商户所有钱包
+     * @param adminCompanyId
+     * @return
+     */
+    public List<CustomerWalletBean> queryWalletByAdminCompanyId(String adminCompanyId) {
+        List<CustomerWalletBean> customerWalletBeanList = new ArrayList<>();
+        if(StringUtils.isEmpty(adminCompanyId)){
+            return customerWalletBeanList;
+        }
+
+        List<AdminCompanyWalletBalance> companyWalletList = companyWalletBalanceLogic.getAllAdminCompanyWallet(adminCompanyId);
+
+        if(CollectionUtils.isEmpty(companyWalletList)){
+            return customerWalletBeanList;
+        }
+
+        // 分出现金和返利钱包
+        List<AdminCompanyWalletBalance> walletList = companyWalletList.stream()
+                .filter(v -> v.getType().equals(BalanceTypeEnum.W.getKey()))
+                .collect(Collectors.toList());
+
+        List<AdminCompanyWalletBalance> rebateWalletList = companyWalletList.stream()
+                .filter(v -> v.getType().equals(BalanceTypeEnum.R.getKey()))
+                .collect(Collectors.toList());
+
+        if (CollectionUtil.isNotEmpty(walletList)) {
+            for (AdminCompanyWalletBalance walletBalance : walletList) {
+                CustomerWalletBean customerWalletBean = new CustomerWalletBean();
+                BeanUtils.copyProperties(walletBalance, customerWalletBean);
+                customerWalletBeanList.add(customerWalletBean);
+            }
+        }
+
+        if (CollectionUtil.isNotEmpty(rebateWalletList)) {
+            // 查询返利使用比例
+            final List<RebateTypeUseRate> typeUseRates = rebateTypeUseRateService.list();
+
+            final Map<String, List<RebateTypeUseRate>> typeUseGroup = typeUseRates.stream()
+                    .filter(RebateTypeUseRate::getStatus)
+                    .collect(Collectors.groupingBy(RebateTypeUseRate::getRebateTypeId));
+
+            for (AdminCompanyWalletBalance walletBalance : rebateWalletList) {
+                CustomerWalletBean customerWalletBean = new CustomerWalletBean();
+                BeanUtils.copyProperties(walletBalance, customerWalletBean);
+
+                // 是否存在返利钱包对应返利使用比例
+                if (typeUseGroup.containsKey(walletBalance.getWalletId())) {
+                    final List<RebateTypeUseRate> rebateTypeUseRates = typeUseGroup.get(walletBalance.getWalletId());
+                    // 返利钱包对象注入返利使用比例list
+                    customerWalletBean.setWalletRaleTypes(rebateTypeUseRates);
+                    // 返利钱包对象注入销售类型id
+                    customerWalletBean.setSaleTypeIds(rebateTypeUseRates.stream()
+                            .map(RebateTypeUseRate::getSalesTypeId)
+                            .collect(Collectors.toList()));
+                }
+
+                customerWalletBeanList.add(customerWalletBean);
+            }
+        }
+
+        return customerWalletBeanList;
+    }
 }

+ 1019 - 0
mall-server-api/src/main/java/com/gree/mall/manager/logic/supply/policy/PolicyLogic.java

@@ -0,0 +1,1019 @@
+package com.gree.mall.manager.logic.supply.policy;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.gree.mall.manager.bean.ExcelData;
+import com.gree.mall.manager.bean.admin.AdminUserCom;
+import com.gree.mall.manager.bean.supply.funds.CustomerWalletBean;
+import com.gree.mall.manager.bean.supply.policy.*;
+import com.gree.mall.manager.commonmapper.CommonMapper;
+import com.gree.mall.manager.enums.ExamineStatusEnum;
+import com.gree.mall.manager.enums.StatusEnum;
+import com.gree.mall.manager.enums.material.StateEnum;
+import com.gree.mall.manager.enums.supply.BalanceTypeEnum;
+import com.gree.mall.manager.enums.supply.PolicyTypeEnum;
+import com.gree.mall.manager.exception.RemoteServiceException;
+import com.gree.mall.manager.logic.common.CommonLogic;
+import com.gree.mall.manager.logic.supply.funds.CompanyWalletLogic;
+import com.gree.mall.manager.logic.supply.sales.config.SupplyPayConfigLogic;
+import com.gree.mall.manager.plus.entity.*;
+import com.gree.mall.manager.plus.service.*;
+import com.gree.mall.manager.utils.CommonUtils;
+import com.gree.mall.manager.zfire.bean.ZfireParamBean;
+import com.gree.mall.manager.zfire.util.FieldUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class PolicyLogic {
+
+    private final CommonLogic commonLogic;
+    private final CommonMapper commonMapper;
+    private final PolicyService policyService;
+    private final PolicyConditionService policyConditionService;
+    private final PolicyCustomerService policyCustomerService;
+    private final PolicyMaterialService policyMaterialService;
+    private final PolicyConditionMaterialService policyConditionMaterialService;
+    private final PolicyWalletRelaService policyWalletRelaService;
+    private final GoodsMaterialService goodsMaterialService;
+    private final SupplyPayConfigLogic supplyPayConfigLogic;
+    private final WalletService walletService;
+    private final RebateTypeService rebateTypeService;
+    private final RebateTypeUseRateService rebateTypeUseRateService;
+    private final CompanyWalletLogic companyWalletLogic;
+    private final SalesTypeService salesTypeService;
+
+    public IPage<PolicyVO> list(ZfireParamBean zfireParamBean) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        FieldUtils.platformParam(zfireParamBean, PolicyVO.class, adminUser);
+
+        return commonMapper.policyList(new Page(zfireParamBean.getPageNum(), zfireParamBean.getPageSize()), zfireParamBean);
+    }
+
+    public Policy detail(String policyId) {
+        Policy policy = policyService.getById(policyId);
+        return policy;
+    }
+
+    /**
+     * 新增销售政策 和 经销商
+     */
+    @Transactional
+    public String add(PolicyBean policyBean) {
+        List<PolicyCustomer> policyCustomers = policyBean.getPolicyCustomers();
+        if (CollectionUtils.isEmpty(policyBean.getPolicyCustomers())) {
+            throw new RemoteServiceException("请选择经销商");
+        }
+        if (StringUtils.isEmpty(policyBean.getType())) {
+            throw new RemoteServiceException("请选择政策类型");
+        }
+
+//        Integer count = policyConditionService.lambdaQuery().eq(PolicyCondition::getPolicyId, policyBean.getCode()).count();
+//        if (count == 0 && StringUtils.equals(policyBean.getType(), PolicyTypeEnum.PROVISION.getKey())) {
+//            throw new RemoteServiceException("配提类型需要创建条件");
+//        }
+
+        policyBean.setStatus(StateEnum.OFF.getKey());
+        policyBean.setExamineStatus(ExamineStatusEnum.SAVE.getKey());
+        policyBean.setId(policyBean.getCode());
+
+        policyBean.insertOrUpdate();
+        //添加经销商
+        policyCustomers = policyCustomers.stream().distinct().collect(Collectors.toList());
+        policyCustomerService.lambdaUpdate().eq(PolicyCustomer::getPolicyId, policyBean.getId()).remove();
+        policyCustomerService.saveBatch(policyCustomers.stream()
+                .peek(v -> v.setPolicyId(policyBean.getCode())
+                .setPolicyTitle(policyBean.getTitle()))
+                .collect(Collectors.toList()));
+
+        return policyBean.getId();
+    }
+
+    @Transactional
+    public void update(PolicyBean policyBean) {
+        //检查是否可以编辑
+        this.checkPolicy(policyBean.getId());
+
+        if (CollectionUtils.isEmpty(policyBean.getPolicyCustomers())) {
+            throw new RemoteServiceException("请选择经销商");
+        }
+        if (StringUtils.isEmpty(policyBean.getType())) {
+            throw new RemoteServiceException("请选择政策类型");
+        }
+
+        Integer count = policyConditionService.lambdaQuery().eq(PolicyCondition::getPolicyId, policyBean.getId()).count();
+        if (count == 0 && StringUtils.equals(policyBean.getType(), PolicyTypeEnum.PROVISION.getKey())) {
+            throw new RemoteServiceException("配提类型需要创建条件");
+        }
+
+        if (StringUtils.equals(policyBean.getType(), PolicyTypeEnum.PROVISION.getKey())) {
+            policyBean.setMinBuyNum(0)
+                    .setMaxBuyNum(0);
+        }
+
+        policyBean.updateById();
+        //先删除经销商,再新增
+        if (CollectionUtils.isNotEmpty(policyBean.getPolicyCustomers())) {
+            List<PolicyCustomer> policyCustomers = policyBean.getPolicyCustomers().stream().distinct().collect(Collectors.toList());
+            policyCustomerService.lambdaUpdate().eq(PolicyCustomer::getPolicyId, policyBean.getId()).remove();
+            policyCustomerService.saveBatch(policyCustomers);
+        }
+    }
+
+    /**
+     * 检查政策是否可以编辑
+     */
+    public void checkPolicy(String policyId) {
+        Policy policy = policyService.getById(policyId);
+        if (policy != null && !StringUtils.equals(policy.getExamineStatus(), ExamineStatusEnum.SAVE.getKey())) {
+            throw new RemoteServiceException("非保存状态不可更改");
+        }
+    }
+
+    /**
+     * 删除政策
+     */
+    @Transactional
+    public void delete(String id) {
+        final boolean remove = policyService.lambdaUpdate()
+                .eq(Policy::getId, id)
+                .eq(Policy::getExamineStatus, ExamineStatusEnum.SAVE.getKey())
+                .remove();
+        if (!remove) {
+            throw new RemoteServiceException("删除失败, 单据状态非“保存”状态");
+        }
+        policyConditionService.lambdaUpdate().eq(PolicyCondition::getPolicyId, id).remove();
+        policyConditionMaterialService.lambdaUpdate().eq(PolicyConditionMaterial::getPolicyId, id).remove();
+        policyMaterialService.lambdaUpdate().eq(PolicyMaterial::getPolicyId, id).remove();
+        policyCustomerService.lambdaUpdate().eq(PolicyCustomer::getPolicyId, id).remove();
+        policyWalletRelaService.lambdaUpdate().eq(PolicyWalletRela::getPolicyId, id).remove();
+    }
+
+    /**
+     * 作废
+     */
+    public void cancel(String id) {
+        policyService.lambdaUpdate()
+                .set(Policy::getStatus, StateEnum.OFF.getKey())
+                .eq(Policy::getId, id).update();
+    }
+
+    /**
+     * 批量延期政策
+     *
+     * @param list
+     */
+    @Transactional
+    public void batchUpdateDelay(List<PolicyDelayBean> list) {
+        if (CollectionUtils.isEmpty(list)) {
+            throw new RemoteServiceException("请传参");
+        }
+        //需要变更的信息,转换成map方便对比修改数据
+        Map<String, Date> map = list.stream().collect(Collectors.toMap(PolicyDelayBean::getPolicyId, PolicyDelayBean::getEndTime));
+
+        List<String> policyIds = list.stream().map(PolicyDelayBean::getPolicyId).collect(Collectors.toList());
+        List<Policy> policyList = policyService.lambdaQuery().in(Policy::getId, policyIds).list();
+        for (Policy policy : policyList) {
+            Date endTime = map.get(policy.getId());
+            if (policy.getEndTime().getTime() != endTime.getTime()) {
+                //需要修改日志
+                String content = "修改前政策结束时间" + DateUtil.formatDateTime(policy.getEndTime()) + ",修改后政策结束时间" + DateUtil.formatDateTime(endTime);
+                //记录操作日志
+                commonLogic.saveLog(policy.getId(), "修改", content);
+            }
+
+            policy.setEndTime(map.get(policy.getId()));
+            policy.setStatus(endTime.getTime() > new Date().getTime() && policy.getStartTime().getTime() < new Date().getTime() ? StateEnum.ON.getKey() : StateEnum.OFF.getKey());
+            policy.updateById();
+        }
+    }
+
+    /**
+     * 新增政策条件
+     */
+    @Transactional
+    public void addCondition(PolicyConditionAdd policyConditionAdd) {
+
+        policyConditionMaterialService.lambdaUpdate().eq(PolicyConditionMaterial::getPolicyId, policyConditionAdd.getPolicyId()).remove();
+        policyConditionService.lambdaUpdate().eq(PolicyCondition::getPolicyId, policyConditionAdd.getPolicyId()).remove();
+
+        //检查是否可以编辑
+        this.checkPolicy(policyConditionAdd.getPolicyId());
+
+        //条件id主键
+        String id = IdWorker.getIdStr();
+        policyConditionAdd.setId(id);
+
+        List<PolicyConditionMaterial> policyConditionMaterials = policyConditionAdd.getPolicyConditionMaterials();
+        if (CollectionUtils.isEmpty(policyConditionMaterials)) {
+            throw new RemoteServiceException("请添加机型");
+        }
+        if (!policyConditionAdd.getPop().contains(":")) {
+            throw new RemoteServiceException("请填写正确的比例");
+        }
+        List<PolicyConditionMaterial> distinctList = policyConditionMaterials.stream().distinct().collect(Collectors.toList());
+        if (policyConditionMaterials.size() != distinctList.size()) {
+            throw new RemoteServiceException("存在政策条件内的限定机型和配提机型配置了重复的机型");
+        }
+        //判断条件的比例和对应的机型是否合格
+        String[] split = policyConditionAdd.getPop().split(":");
+        for (int i = 1; i <= split.length; i++) {
+            int a = i;
+            long count = policyConditionMaterials.stream().filter(v -> v.getPopType() == a).count();
+            if (count == 0) {
+                throw new RemoteServiceException("条件比例与机型配置错误");
+            }
+            //判断比例格式是否正确
+            try {
+                int i1 = Integer.parseInt(split[i - 1]);
+            } catch (Exception e) {
+                throw new RemoteServiceException("请填写正确的比例,例如  1:2");
+            }
+        }
+        //检查条件中的限定机型没在本政策其他条件中被引用过
+        List<String> materialIds = policyConditionMaterials.stream().filter(v -> v.getPopType() == 1)
+                .map(PolicyConditionMaterial::getGoodsMaterialId).collect(Collectors.toList());
+        Integer count = policyConditionMaterialService.lambdaQuery()
+                .in(PolicyConditionMaterial::getGoodsMaterialId, materialIds)
+                .eq(PolicyConditionMaterial::getPolicyId, policyConditionAdd.getPolicyId())
+                .eq(PolicyConditionMaterial::getPopType, 1)
+                .count();
+        if (count > 0) {
+            throw new RemoteServiceException("限定政策商品在各条件中不可重复被引用");
+        }
+        for (PolicyConditionMaterial material : policyConditionMaterials) {
+            PolicyMaterial policyMaterial = this.getPolicyMaterial(material.getPolicyId(), material.getGoodsMaterialId(), material.getSalesTypeId());
+            if (policyMaterial == null) {
+                throw new RemoteServiceException("机型:" + material.getGoodsMaterialName() + material.getSpecsName() + "不存在");
+            }
+            material.setSalesTypeId(policyMaterial.getSalesTypeId());
+            material.setSalesTypeName(policyMaterial.getSalesTypeName());
+            material.setSalesTypeCode(policyMaterial.getSalesTypeCode());
+            material.setMainId(policyMaterial.getMainId());
+            material.setMainName(policyMaterial.getMainName());
+            material.setSmallId(policyMaterial.getSmallId());
+            material.setSmallName(policyMaterial.getSmallName());
+            material.setSeriesName(policyMaterial.getSeriesName());
+            material.setGoodsMaterialName(policyMaterial.getGoodsMaterialName());
+            material.setPolicyMaterialId(policyMaterial.getId());
+            material.setPrice(policyMaterial.getPrice());
+            material.setUnit(policyMaterial.getUnit());
+
+            material.setPolicyConditionId(id);
+        }
+
+        policyConditionService.save(policyConditionAdd);
+        policyConditionMaterialService.saveBatch(policyConditionMaterials);
+    }
+
+    /**
+     * 指定的政策产品
+     */
+    public PolicyMaterial getPolicyMaterial(String policyId, String materialId, String saleTypeId) {
+        return policyMaterialService.lambdaQuery()
+                .eq(PolicyMaterial::getPolicyId, policyId)
+                .eq(PolicyMaterial::getGoodsMaterialId, materialId)
+                .eq(PolicyMaterial::getSalesTypeId, saleTypeId)
+                .one();
+    }
+
+    /**
+     * 修改政策条件
+     *
+     * @param id
+     * @param name
+     */
+    public void updateCondition(String id, String name) {
+        PolicyCondition policyCondition = new PolicyCondition();
+        policyCondition.setId(id);
+        policyCondition.setName(name);
+        policyCondition.updateById();
+    }
+
+    /**
+     * 删除政策条件
+     */
+    public void deleteCondition(String id) {
+        policyConditionService.removeById(id);
+        policyConditionMaterialService.lambdaUpdate().eq(PolicyConditionMaterial::getPolicyConditionId, id).remove();
+    }
+
+    /**
+     * 政策条件-详情
+     */
+    public PolicyCondition detailCondition(String id) {
+        return policyConditionService.getById(id);
+    }
+
+    /**
+     * 提审
+     */
+    public void submit(String policyId) {
+        Policy policy = policyService.getById(policyId);
+        if (!StringUtils.equals(policy.getExamineStatus(), ExamineStatusEnum.SAVE.getKey())) {
+            throw new RemoteServiceException("当前状态无法提审");
+        }
+        policy.setExamineStatus(ExamineStatusEnum.WAIT.getKey());
+        policy.updateById();
+    }
+
+    /**
+     * 销售政策审核
+     */
+    public void examine(String policyId, String examineStatus, String examineRemark) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        Policy policy = policyService.getById(policyId);
+        if (!policy.getExamineStatus().equals(ExamineStatusEnum.WAIT.getKey())) {
+            throw new RemoteServiceException("无需审核");
+        }
+        //检查是否有商品
+        Integer count = policyMaterialService.lambdaQuery().eq(PolicyMaterial::getPolicyId, policyId).count();
+        if (count == 0) {
+            throw new RemoteServiceException("请添加必要的政策机型");
+        }
+        if (policy.getType().equals(PolicyTypeEnum.PROVISION.getKey()) && examineStatus.equals(ExamineStatusEnum.OK.getKey())) {
+            Integer count1 = policyConditionMaterialService.lambdaQuery().eq(PolicyConditionMaterial::getPolicyId, policyId).count();
+            if (count1 == 0) {
+                throw new RemoteServiceException("配提政策请添加必要的政策条件和机型");
+            }
+        }
+        policy.setExamineStatus(examineStatus.equals(ExamineStatusEnum.FAIL.getKey()) ? "SAVE" : examineStatus);
+        policy.setExamineRemark(examineRemark);
+        policy.setExamineTime(new Date());
+        policy.setStatus(policy.getExamineStatus().equals(ExamineStatusEnum.OK.getKey()) ? StateEnum.ON.getKey() : StateEnum.OFF.getKey());
+        policy.setExamineBy(adminUser.getNickName());
+        policy.updateById();
+
+    }
+
+    /**
+     * 政策产品信息列表
+     */
+    public IPage<PolicyMaterialBean> materialList(String policyId, String specification, Boolean isProvision, Boolean status,
+                                                  String salesTypeCode, Integer pageNum, Integer pageSize) {
+
+        List<String> policyMaterialIds = new ArrayList<>();
+        //查询配提机型,则需要过滤限定机型
+        if (isProvision != null && isProvision) {
+            List<PolicyConditionMaterial> policyConditionMaterials = policyConditionMaterialService.lambdaQuery()
+                    .eq(PolicyConditionMaterial::getPolicyId, policyId)
+                    .eq(status != null, PolicyConditionMaterial::getStatus, status)
+                    .eq(PolicyConditionMaterial::getPopType, 1)
+                    .list();
+
+            policyMaterialIds = policyConditionMaterials.stream().map(PolicyConditionMaterial::getPolicyMaterialId).collect(Collectors.toList());
+        }
+
+        IPage page = policyMaterialService.lambdaQuery()
+                .eq(StringUtils.isNotEmpty(salesTypeCode), PolicyMaterial::getSalesTypeCode, salesTypeCode)
+                .like(StringUtils.isNotEmpty(specification), PolicyMaterial::getSpecsName, specification)
+                .eq(PolicyMaterial::getPolicyId, policyId)
+                .eq(status != null, PolicyMaterial::getStatus, status)
+                .notIn(CollectionUtils.isNotEmpty(policyMaterialIds), PolicyMaterial::getGoodsMaterialId, policyMaterialIds)
+                .orderByAsc(PolicyMaterial::getId)
+                .page(new Page<>(pageNum, pageSize));
+
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<CustomerWalletBean> customerWalletBeans = new ArrayList<>();
+        if (adminUser.getType() != 2) {
+            customerWalletBeans = companyWalletLogic.queryWalletByAdminCompanyId(adminUser.getCompanyWechatId());
+        }
+
+        // 政策物料与钱包关系
+        List<PolicyWalletRela> policyWalletRelas = policyWalletRelaService.lambdaQuery()
+                .eq(PolicyWalletRela::getPolicyId, policyId)
+                .orderByAsc(PolicyWalletRela::getId)
+                .list();
+
+        List<PolicyMaterialBean> list = new ArrayList<>();
+        for (Object o : page.getRecords()) {
+            PolicyMaterial policyMaterial = (PolicyMaterial) o;
+            PolicyMaterialBean policyMaterialBean = new PolicyMaterialBean();
+            BeanUtils.copyProperties(policyMaterial, policyMaterialBean);
+
+            List<PolicyWalletRela> walletRelas = policyWalletRelas.stream()
+                    .filter(v -> v.getPolicyMaterialId().equals(policyMaterial.getId()))
+                    .collect(Collectors.toList());
+            List<String> walletIds = walletRelas.stream()
+                    .map(PolicyWalletRela::getWalletId)
+                    .collect(Collectors.toList());
+
+            policyMaterialBean.setWalletRelaList(walletRelas);
+
+            // 找出有关系的商户钱包
+            List<CustomerWalletBean> relaWalletBeans = customerWalletBeans.stream()
+                    .filter(v -> walletIds.contains(v.getWalletId()))
+                    .collect(Collectors.toList());
+
+            // 现金钱包
+            final List<CustomerWalletBean> walletBeanList = relaWalletBeans.stream()
+                    .filter(v -> v.getType().equals(BalanceTypeEnum.W.getKey()))
+                    .collect(Collectors.toList());
+            if (CollectionUtil.isNotEmpty(walletBeanList)) {
+                policyMaterialBean.getWallets().addAll(walletBeanList);
+            }
+
+            // 返利钱包
+            final List<CustomerWalletBean> rebateWalletList = relaWalletBeans.stream()
+                    .filter(v -> v.getType().equals(BalanceTypeEnum.R.getKey()))
+                    .collect(Collectors.toList());
+            if (CollectionUtil.isNotEmpty(rebateWalletList)) {
+                policyMaterialBean.getRebateWallets().addAll(rebateWalletList);
+            }
+
+            list.add(policyMaterialBean);
+        }
+        page.setRecords(list);
+        return page;
+    }
+
+    /**
+     * 保存产品
+     */
+    @Transactional
+    public void saveMaterial(List<PolicyMaterialAddBean> policyMaterialAddBeans) {
+        if (policyMaterialAddBeans.size() == 0) {
+            return;
+        }
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+
+        List<String> policyIds = policyMaterialAddBeans.stream().map(PolicyMaterialAddBean::getPolicyId).distinct().collect(Collectors.toList());
+        if (policyIds.size() > 1) {
+            throw new RemoteServiceException("参数存在错误数据");
+        }
+        String policyId = policyIds.get(0);
+
+        Policy policy = policyService.getById(policyId);
+        if (policy != null) {
+            if (!policy.getExamineStatus().equals(ExamineStatusEnum.SAVE.getKey())) {
+                throw new RemoteServiceException("政策非保存状态不可更改");
+            }
+        }
+
+        List<String> policyMaterialIds = policyMaterialAddBeans.stream().map(PolicyMaterialAddBean::getId).collect(Collectors.toList());
+        List<PolicyConditionMaterial> policyConditionMaterials = policyConditionMaterialService.lambdaQuery().in(PolicyConditionMaterial::getPolicyId, policyId).list();
+        for (PolicyConditionMaterial pcm : policyConditionMaterials) {
+            if (!policyMaterialIds.contains(pcm.getPolicyMaterialId()) && policy != null && policy.getType().equals(PolicyTypeEnum.PROVISION.getKey())) {
+                throw new RemoteServiceException("政策条件的机型【" + pcm.getSpecsName() + "】不存在政策机型中");
+            }
+        }
+
+        Map<String, GoodsMaterial> goodsMaterialMap = new HashMap<>();
+
+        //钱包配置先删后增
+        //1.remove
+        policyWalletRelaService.lambdaUpdate().eq(PolicyWalletRela::getPolicyId, policyMaterialAddBeans.get(0).getPolicyId()).remove();
+        List<String> distincts = new ArrayList<>();
+        for (PolicyMaterialAddBean bean : policyMaterialAddBeans) {
+            String id = bean.getId();
+            String materialId = bean.getGoodsMaterialId();
+            String salesTypeId = bean.getSalesTypeId();
+            BigDecimal price = bean.getPrice();
+            String remark = bean.getRemark();
+            List<String> walletIds = bean.getWalletIds();
+            List<String> rebateWalletIds = bean.getRebateWalletIds();
+
+            if (materialId == null) {
+                throw new RemoteServiceException("请选择机型");
+            }
+            if (CollectionUtils.isEmpty(walletIds)) {
+                throw new RemoteServiceException("请选择钱包");
+            }
+            if (price == null) {
+                throw new RemoteServiceException("请填写单价");
+            }
+            if (distincts.contains(materialId + salesTypeId)) {
+                throw new RemoteServiceException("同一政策不可存在相同销售类型的机型");
+            } else {
+                distincts.add(materialId + salesTypeId);
+            }
+            if (price.doubleValue() < 0) {
+                throw new RemoteServiceException("单价不可小于0");
+            }
+
+            GoodsMaterial detail;
+            if (goodsMaterialMap.containsKey(materialId)) {
+                detail = goodsMaterialMap.get(materialId);
+            } else {
+                detail = goodsMaterialService.getById(materialId);
+                goodsMaterialMap.put(materialId, detail);
+            }
+
+            SalesType salesType = supplyPayConfigLogic.typeDetail(salesTypeId);
+
+            PolicyMaterial policyMaterial = new PolicyMaterial();
+            policyMaterial.setPolicyId(policyId);
+            policyMaterial.setGoodsMaterialId(materialId);
+            policyMaterial.setGoodsMaterialName(detail.getGoodsName());
+            policyMaterial.setFactoryNo(detail.getFactoryNo());
+            policyMaterial.setMainId(detail.getMainId());
+            policyMaterial.setMainName(detail.getMainName());
+            policyMaterial.setSmallId(detail.getSmallId());
+            policyMaterial.setSmallName(detail.getSmallName());
+            policyMaterial.setUnit(detail.getUnit());
+            policyMaterial.setSeriesName(detail.getSeriesName());
+            policyMaterial.setSpecsName(detail.getSpecsName());
+            policyMaterial.setSalesTypeId(salesTypeId);
+            policyMaterial.setSalesTypeCode(salesType.getCode());
+            policyMaterial.setSalesTypeName(salesType.getName());
+            policyMaterial.setPrice(price);
+            policyMaterial.setRemark(remark);
+            policyMaterial.setOrgPrice(bean.getOrgPrice());
+            if (StringUtils.isNotEmpty(id)) {
+                policyMaterial.setId(id);
+            }
+
+            policyMaterial.insertOrUpdate();
+
+
+            //检查是否存在配提机型
+            PolicyConditionMaterial policyConditionMaterial = policyConditionMaterialService.lambdaQuery()
+                    .eq(PolicyConditionMaterial::getPolicyId, policyId)
+                    .eq(PolicyConditionMaterial::getPolicyMaterialId, policyMaterial.getId())
+                    .one();
+            if (policyConditionMaterial != null) {
+                String oldId = policyConditionMaterial.getId();
+                BeanUtils.copyProperties(policyMaterial, policyConditionMaterial);
+                policyConditionMaterial.setId(oldId);
+                policyConditionMaterial.updateById();
+            }
+
+
+            //2.add wallet
+            List<PolicyWalletRela> wallets = new ArrayList<>();
+            for (String wId : walletIds) {
+                Wallet wallet = walletService.getById(wId);
+                PolicyWalletRela policyWalletRela = new PolicyWalletRela();
+                policyWalletRela.setWalletId(wId);
+                policyWalletRela.setWalletName(wallet.getName());
+                policyWalletRela.setPolicyId(policyId);
+                policyWalletRela.setPolicyMaterialId(policyMaterial.getId());
+                policyWalletRela.setType(BalanceTypeEnum.W.getKey());
+                wallets.add(policyWalletRela);
+            }
+            //3.add rebate wallet
+            if (CollectionUtils.isNotEmpty(rebateWalletIds)) {
+                for (String wId : rebateWalletIds) {
+                    Integer count = rebateTypeUseRateService.lambdaQuery()
+                            .eq(RebateTypeUseRate::getSalesTypeId, salesTypeId)
+                            .eq(RebateTypeUseRate::getRebateTypeId, wId)
+                            .count();
+                    RebateType wallet = rebateTypeService.getById(wId);
+                    if (count == 0) {
+                        throw new RemoteServiceException("返利钱包+【" + wallet.getName() + "】与销售类型【" + salesType.getName() + "】对应关系不存在");
+                    }
+                    PolicyWalletRela policyWalletRela = new PolicyWalletRela();
+                    policyWalletRela.setWalletId(wId);
+                    policyWalletRela.setWalletName(wallet.getName());
+                    policyWalletRela.setPolicyId(policyId);
+                    policyWalletRela.setPolicyMaterialId(policyMaterial.getId());
+                    policyWalletRela.setType(BalanceTypeEnum.R.getKey());
+                    wallets.add(policyWalletRela);
+                }
+            }
+            policyWalletRelaService.saveBatch(wallets);
+        }
+        List<PolicyMaterial> list = policyMaterialService.lambdaQuery()
+                .eq(PolicyMaterial::getPolicyId, policyId)
+                .list();
+        List<String> pMaterialIds = list.stream().map(PolicyMaterial::getId).collect(Collectors.toList());
+        //删除配提的机型,可能在外已经不存在的配提机型
+        policyConditionMaterialService.lambdaUpdate()
+                .eq(PolicyConditionMaterial::getPolicyId, policyId)
+                .notIn(PolicyConditionMaterial::getPolicyMaterialId, pMaterialIds).remove();
+    }
+
+    /**
+     * 克隆政策
+     */
+    @Transactional
+    public void clonePolicy(String policyId) {
+        Policy policy = policyService.getById(policyId);
+        List<PolicyMaterial> policyMaterials = policyMaterialService.lambdaQuery()
+                .eq(PolicyMaterial::getPolicyId, policyId).orderByAsc(PolicyMaterial::getId).list();
+        List<PolicyCondition> conditionList = policyConditionService.lambdaQuery().eq(PolicyCondition::getPolicyId, policyId).list();
+        List<PolicyConditionMaterial> conditionMaterials = policyConditionMaterialService.lambdaQuery()
+                .eq(PolicyConditionMaterial::getPolicyId, policyId).orderByAsc(PolicyConditionMaterial::getId).list();
+        List<PolicyCustomer> policyCustomers = policyCustomerService.lambdaQuery()
+                .eq(PolicyCustomer::getPolicyId, policyId)
+                .orderByAsc(PolicyCustomer::getId).list();
+        List<PolicyWalletRela> relas = policyWalletRelaService.lambdaQuery()
+                .eq(PolicyWalletRela::getPolicyId, policyId).orderByAsc(PolicyWalletRela::getId).list();
+
+        //政策
+        policy.setId("P" + IdWorker.getIdStr());
+        policy.setCode(policy.getId());
+        policy.setExamineStatus(ExamineStatusEnum.SAVE.getKey());
+        policy.setStatus(StateEnum.OFF.getKey());
+        policy.setCreateTime(null);
+        policy.setCreateBy(null);
+        policy.setUpdateBy(null);
+        policy.setUpdateTime(null);
+        policy.insert();
+        //政策经销商
+        for (PolicyCustomer policyCustomer : policyCustomers) {
+            policyCustomer.setPolicyId(policy.getId());
+            policyCustomer.setId(IdWorker.getIdStr());
+            policyCustomer.setCreateTime(null);
+            policyCustomer.setCreateBy(null);
+            policyCustomer.setUpdateBy(null);
+            policyCustomer.setUpdateTime(null);
+        }
+        policyCustomerService.saveBatch(policyCustomers);
+
+        //key = 旧id  value = 新id
+        Map<String, String> idMap = new HashMap<>();
+        //政策条件
+        for (PolicyCondition policyCondition : conditionList) {
+
+            String newId = IdWorker.getIdStr();
+            idMap.put(policyCondition.getId(), newId);
+
+            policyCondition.setPolicyId(policy.getId());
+            policyCondition.setId(newId);
+            policyCondition.setCreateTime(null);
+            policyCondition.setCreateBy(null);
+            policyCondition.setUpdateBy(null);
+            policyCondition.setUpdateTime(null);
+        }
+        policyConditionService.saveBatch(conditionList);
+        //政策机型
+        for (PolicyMaterial policyMaterial : policyMaterials) {
+
+            String newId = IdWorker.getIdStr();
+            idMap.put(policyMaterial.getId(), newId);
+
+            policyMaterial.setPolicyId(policy.getId());
+            policyMaterial.setId(newId);
+            policyMaterial.setCreateTime(null);
+            policyMaterial.setCreateBy(null);
+            policyMaterial.setUpdateBy(null);
+            policyMaterial.setUpdateTime(null);
+        }
+        policyMaterialService.saveBatch(policyMaterials);
+        //政策条件机型
+        for (PolicyConditionMaterial conditionMaterial : conditionMaterials) {
+            conditionMaterial.setPolicyId(policy.getId());
+            conditionMaterial.setId(null);
+            conditionMaterial.setPolicyConditionId(idMap.get(conditionMaterial.getPolicyConditionId()));
+            conditionMaterial.setPolicyMaterialId(idMap.get(conditionMaterial.getPolicyMaterialId()));
+            conditionMaterial.setCreateTime(null);
+            conditionMaterial.setCreateBy(null);
+            conditionMaterial.setUpdateBy(null);
+            conditionMaterial.setUpdateTime(null);
+        }
+        policyConditionMaterialService.saveBatch(conditionMaterials);
+
+        List<PolicyWalletRela> newRelas = new ArrayList<>();
+        for (PolicyWalletRela rela : relas) {
+            if (idMap.get(rela.getPolicyMaterialId()) == null) {
+                continue;
+            }
+            rela.setPolicyId(policy.getId());
+            rela.setPolicyMaterialId(idMap.get(rela.getPolicyMaterialId()));
+            rela.setId(null);
+            rela.setCreateTime(null);
+            rela.setCreateBy(null);
+            rela.setUpdateBy(null);
+            rela.setUpdateTime(null);
+            newRelas.add(rela);
+        }
+        policyWalletRelaService.saveBatch(newRelas);
+
+    }
+
+    /**
+     * 弃审
+     */
+    public void abandon(String policyId) {
+        Policy policy = policyService.getById(policyId);
+        policy.setExamineStatus(ExamineStatusEnum.SAVE.getKey());
+        policy.setStatus(StateEnum.OFF.getKey());
+        policy.updateById();
+    }
+
+    /**
+     * 政策的限定机型列表
+     *
+     * @param policyId
+     * @param saleTypeCode
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    public IPage<PolicyConditionMaterialBean> type1MaterialList(String policyId, String saleTypeCode, String specsName, Boolean status, Integer pageNum, Integer pageSize) {
+        IPage page = policyConditionMaterialService.lambdaQuery()
+                .eq(PolicyConditionMaterial::getPolicyId, policyId)
+                .eq(PolicyConditionMaterial::getPopType, 1)
+                .eq(PolicyConditionMaterial::getStatus, status)
+                .like(StringUtils.isNotEmpty(specsName), PolicyConditionMaterial::getSpecsName, specsName)
+                .eq(StringUtils.isNotEmpty(saleTypeCode), PolicyConditionMaterial::getSalesTypeCode, saleTypeCode)
+                .orderByDesc(PolicyConditionMaterial::getId)
+                .page(new Page<>(pageNum, pageSize));
+
+        List<PolicyConditionMaterialBean> list = new ArrayList<>();
+        for (Object o : page.getRecords()) {
+            PolicyConditionMaterial bean = (PolicyConditionMaterial) o;
+            PolicyConditionMaterialBean policyMaterialBean = new PolicyConditionMaterialBean();
+            BeanUtils.copyProperties(bean, policyMaterialBean);
+
+            list.add(policyMaterialBean);
+        }
+        page.setRecords(list);
+        return page;
+    }
+
+    /**
+     * 政策经销商列表
+     */
+    public IPage<PolicyCustomer> customerList(String policyId, Integer pageNum, Integer pageSize) {
+        return policyCustomerService.lambdaQuery()
+                .eq(PolicyCustomer::getPolicyId, policyId)
+                .orderByDesc(PolicyCustomer::getCreateTime, PolicyCustomer::getId)
+                .page(new Page<>(pageNum, pageSize));
+    }
+
+    /**
+     * 政策条件的机型
+     */
+    public IPage<PolicyConditionMaterialBean> conditionMaterialList(String policyConditionId, Integer popType, String specsName, String customerId,
+                                                                    Boolean status, Integer pageNum, Integer pageSize) {
+
+        IPage page = policyConditionMaterialService.lambdaQuery()
+                .eq(Objects.nonNull(popType), PolicyConditionMaterial::getPopType, popType)
+                .eq(PolicyConditionMaterial::getPolicyConditionId, policyConditionId)
+                .eq(Objects.nonNull(status), PolicyConditionMaterial::getStatus, status)
+                .like(StringUtils.isNotEmpty(specsName), PolicyConditionMaterial::getSpecsName, specsName)
+                .page(new Page<>(pageNum, pageSize));
+
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        List<CustomerWalletBean> customerWalletBeans = new ArrayList<>();
+        if (adminUser.getType() != 2) {
+            customerWalletBeans = companyWalletLogic.queryWalletByAdminCompanyId(adminUser.getCompanyWechatId());
+        } else {
+            if (StringUtils.isNotEmpty(customerId)) {
+                customerWalletBeans = companyWalletLogic.queryWalletByAdminCompanyId(customerId);
+            }
+        }
+
+        Map<String, CustomerWalletBean> commonlyCustomerWalletMap = customerWalletBeans.stream()
+                .collect(Collectors.toMap(CustomerWalletBean::getWalletId, v -> v));
+
+        List<PolicyConditionMaterialBean> list = new ArrayList<>();
+        for (Object o : page.getRecords()) {
+            PolicyConditionMaterial bean = (PolicyConditionMaterial) o;
+            PolicyConditionMaterialBean policyMaterialBean = new PolicyConditionMaterialBean();
+            BeanUtils.copyProperties(bean, policyMaterialBean);
+
+            // 政策物料与钱包关系
+            List<PolicyWalletRela> policyWalletRelas = policyWalletRelaService.lambdaQuery()
+                    .eq(PolicyWalletRela::getPolicyId, bean.getPolicyId())
+                    .eq(PolicyWalletRela::getPolicyMaterialId, bean.getPolicyMaterialId())
+                    .list();
+
+            List<CustomerWalletBean> walletBeanList = new ArrayList<>();
+            List<CustomerWalletBean> rebateWalletList = new ArrayList<>();
+
+            for (PolicyWalletRela policyWalletRela : policyWalletRelas) {
+                final CustomerWalletBean walletBean = commonlyCustomerWalletMap.get(policyWalletRela.getWalletId());
+                if (Objects.nonNull(walletBean)) {
+                    if (walletBean.getType().equals(BalanceTypeEnum.W.getKey())) {
+                        walletBeanList.add(walletBean);
+                    } else {
+                        rebateWalletList.add(walletBean);
+                    }
+                }
+            }
+
+            //现金钱包
+            policyMaterialBean.getWallets().addAll(walletBeanList);
+            //返利钱包
+            policyMaterialBean.getRebateWallets().addAll(rebateWalletList);
+
+            list.add(policyMaterialBean);
+        }
+        page.setRecords(list);
+        return page;
+    }
+
+    /**
+     * 政策条件
+     */
+    public List<PolicyCondition> conditionList(String policyId) {
+        List<PolicyCondition> list = policyConditionService.lambdaQuery()
+                .eq(PolicyCondition::getPolicyId, policyId)
+                .list();
+        return list;
+    }
+
+    /**
+     * 根据机型id和政策id反查政策条件
+     */
+    public PolicyCondition getCondition(String policyId, String materialId) {
+        PolicyConditionMaterial policyConditionMaterial = policyConditionMaterialService.lambdaQuery()
+                .eq(PolicyConditionMaterial::getPolicyId, policyId)
+                .eq(PolicyConditionMaterial::getGoodsMaterialId, materialId)
+                .eq(PolicyConditionMaterial::getPopType, 1)
+                .one();
+        PolicyCondition policyCondition = policyConditionService.getById(policyConditionMaterial.getPolicyConditionId());
+        return policyCondition;
+    }
+
+    /**
+     * 导入政策产品
+     */
+    @Transactional
+    public void importMaterial(String policyId, List<Object> rows) {
+        AdminUserCom adminUser = commonLogic.getAdminUser();
+        //检查是否可以编辑
+        this.checkPolicy(policyId);
+        //所有销售类型code
+        List<SalesType> salesTypes = salesTypeService.list();
+        Map<String, SalesType> saleTypeMap = salesTypes.stream().collect(Collectors.toMap(SalesType::getCode, v -> v));
+        //所有物料
+        List<GoodsMaterial> goodsMaterials = goodsMaterialService.lambdaQuery()
+                .eq(GoodsMaterial::getCompanyWechatId, "0")
+                .isNotNull(GoodsMaterial::getFactoryNo)
+                .list();
+        Map<String, GoodsMaterial> materialMap = goodsMaterials.stream().collect(Collectors.toMap(GoodsMaterial::getFactoryNo, v -> v));
+        //查询所有现金钱包
+        List<Wallet> wallets = walletService.list();
+        Map<String, Wallet> walletMap = wallets.stream().collect(Collectors.toMap(Wallet::getCode, v -> v));
+        //查询所有返利钱包
+        List<RebateType> walletRebates = rebateTypeService.list();
+        Map<String, RebateType> walletRebateMap = walletRebates.stream().collect(Collectors.toMap(RebateType::getCode, v -> v));
+
+        final List<RebateTypeUseRate> typeUseRateList = rebateTypeUseRateService.lambdaQuery()
+                .eq(RebateTypeUseRate::getStatus, StatusEnum.ONE.getValue())
+                .list();
+        Map<String, RebateTypeUseRate> typeUseRateMap = typeUseRateList.stream().collect(Collectors.toMap(v -> v.getSalesTypeId() + v.getRebateTypeId(), v -> v));
+
+
+        List<PolicyMaterial> list = new ArrayList<>();
+        List<PolicyWalletRela> relas = new ArrayList<>();
+        for (Object o : rows) {
+            String id = IdWorker.getIdStr();
+            List<Object> row = (List<Object>) o;
+
+            CommonUtils.initList2(row, row.size() + 10);
+
+            String factoryNo = (String) row.get(1);
+            if (StringUtils.isEmpty(factoryNo)) {
+                continue;
+            }
+            String saleTypeCode = (String) row.get(0);
+            BigDecimal price = new BigDecimal(row.get(2).toString());
+            String remark = (String) row.get(5);
+            String walletNames = (String) row.get(3);
+            String rebateWalletNames = (String) row.get(4);
+            String orgPrice = (String) row.get(6);
+            String[] walletName = walletNames.trim().replaceAll(",", ",").split(",");
+
+            if (StringUtils.isEmpty(factoryNo) || StringUtils.isEmpty(saleTypeCode) || Objects.isNull(price)
+                    || Objects.isNull(walletName) || walletName.length == 0) {
+                throw new RemoteServiceException("检测到厂物料编码/销售类型编码/单价/钱包编码有为空的情况");
+            }
+            if (!saleTypeMap.keySet().contains(saleTypeCode)) {
+                throw new RemoteServiceException("销售类型编码:" + saleTypeCode + "不存在");
+            }
+            if (!materialMap.keySet().contains(factoryNo)) {
+                throw new RemoteServiceException("物料编码:" + factoryNo + "不存在");
+            }
+            SalesType saleType = saleTypeMap.get(saleTypeCode);
+            GoodsMaterial goodsMaterial = materialMap.get(factoryNo);
+
+            //政策产品
+            PolicyMaterial policyMaterial = new PolicyMaterial();
+            policyMaterial.setId(id);
+            policyMaterial.setPolicyId(policyId);
+            policyMaterial.setMainId(goodsMaterial.getMainId());
+            policyMaterial.setMainName(goodsMaterial.getMainName());
+            policyMaterial.setGoodsMaterialId(goodsMaterial.getId());
+            policyMaterial.setGoodsMaterialName(goodsMaterial.getGoodsName());
+            policyMaterial.setFactoryNo(goodsMaterial.getFactoryNo());
+            policyMaterial.setSmallId(goodsMaterial.getSmallId());
+            policyMaterial.setSmallName(goodsMaterial.getSmallName());
+            policyMaterial.setSeriesName(goodsMaterial.getSeriesName());
+            policyMaterial.setSpecsName(goodsMaterial.getSpecsName());
+            policyMaterial.setSalesTypeId(saleType.getId());
+            policyMaterial.setSalesTypeCode(saleType.getCode());
+            policyMaterial.setSalesTypeName(saleType.getName());
+            policyMaterial.setPrice(price);
+            policyMaterial.setRemark(remark);
+            policyMaterial.setUnit(goodsMaterial.getUnit());
+            if (orgPrice != null) {
+                policyMaterial.setOrgPrice(new BigDecimal(orgPrice));
+            }
+            list.add(policyMaterial);
+
+            for (String name : walletName) {
+                Wallet wallet = walletMap.get(name);
+                if (wallet == null) {
+                    throw new RemoteServiceException("钱包编码:" + name + ",不存在");
+                }
+                //政策钱包
+                PolicyWalletRela policyWalletRela = new PolicyWalletRela();
+                policyWalletRela.setPolicyId(policyId);
+                policyWalletRela.setPolicyMaterialId(id);
+                policyWalletRela.setWalletName(wallet.getName());
+                policyWalletRela.setType(BalanceTypeEnum.W.getKey());
+                policyWalletRela.setWalletId(wallet.getId());
+                relas.add(policyWalletRela);
+            }
+
+            if (StringUtils.isNotEmpty(rebateWalletNames)) {
+                String[] rebateWalletName = rebateWalletNames.trim().replaceAll(",", ",").split(",");
+                for (String name : rebateWalletName) {
+                    RebateType walletRebate = walletRebateMap.get(name);
+                    if (walletRebate == null) {
+                        throw new RemoteServiceException("返利钱包编码:" + name + ",不存在");
+                    }
+
+                    boolean exist = typeUseRateMap.containsKey(saleType.getId() + walletRebate.getId());
+                    if (!exist) {
+                        throw new RemoteServiceException("返利钱包【" + walletRebate.getName() + "】与销售类型【" + saleType.getName() + "】对应关系不存在");
+                    }
+                    //政策钱包
+                    PolicyWalletRela policyWalletRela = new PolicyWalletRela();
+                    policyWalletRela.setPolicyId(policyId);
+                    policyWalletRela.setPolicyMaterialId(id);
+                    policyWalletRela.setWalletName(walletRebate.getName());
+                    policyWalletRela.setType(BalanceTypeEnum.R.getKey());
+                    policyWalletRela.setWalletId(walletRebate.getId());
+                    relas.add(policyWalletRela);
+                }
+            }
+
+        }
+
+        Set<String> distinct = new HashSet<>();
+        for (PolicyMaterial policyMaterial : list) {
+            distinct.add(policyMaterial.getSalesTypeCode() + policyMaterial.getGoodsMaterialId());
+        }
+        if (distinct.size() != list.size()) {
+            throw new RemoteServiceException("请检查是否存在同销售类型同物料编号的商品");
+        }
+
+        //覆盖,先删后增
+        policyMaterialService.lambdaUpdate().eq(PolicyMaterial::getPolicyId, policyId).remove();
+        policyMaterialService.saveBatch(list);
+        //覆盖,先删后增
+        policyWalletRelaService.lambdaUpdate().eq(PolicyWalletRela::getPolicyId, policyId).remove();
+        policyWalletRelaService.saveBatch(relas);
+    }
+
+    /**
+     * 导出政策商品
+     */
+    public ExcelData exportMaterial(List<PolicyMaterialBean> list) {
+        String[] titles = new String[]{"政策编号", "厂物料编码", "货品名称", "规格型号", "销售类型编码", "销售类型", "单价", "备注", "支付钱包", "返利类型", "原供价", "状态"};
+        List<List<Object>> rows = new ArrayList<>();
+        for (PolicyMaterialBean bean : list) {
+            List<Object> row = new ArrayList<>();
+            row.add(bean.getPolicyId());
+            row.add(bean.getFactoryNo());
+            row.add(bean.getGoodsMaterialName());
+            row.add(bean.getSpecsName());
+            row.add(bean.getSalesTypeCode());
+            row.add(bean.getSalesTypeName());
+            row.add(bean.getPrice());
+            row.add(bean.getRemark());
+            String rebateWallets = "";
+            List<PolicyWalletRela> rebateWalletLists = bean.getWalletRelaList().stream().filter(v -> v.getType().equals(BalanceTypeEnum.R.getKey())).collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(rebateWalletLists)) {
+                List<String> rebateNames = rebateWalletLists.stream().map(PolicyWalletRela::getWalletName).collect(Collectors.toList());
+                rebateWallets = StringUtils.join(rebateNames, ",");
+            }
+
+            String wallets = "";
+            List<PolicyWalletRela> walletRelas = bean.getWalletRelaList().stream().filter(v -> v.getType().equals(BalanceTypeEnum.W.getKey())).collect(Collectors.toList());
+            if (CollectionUtils.isNotEmpty(walletRelas)) {
+                List<String> walletNames = walletRelas.stream().map(PolicyWalletRela::getWalletName).collect(Collectors.toList());
+                wallets = StringUtils.join(walletNames, ",");
+            }
+            row.add(wallets);
+            row.add(rebateWallets);
+            row.add(bean.getOrgPrice());
+            row.add(bean.getStatus() ? "开启" : "关闭");
+            rows.add(row);
+        }
+        ExcelData excelData = new ExcelData();
+        excelData.setTitles(Arrays.asList(titles));
+        excelData.setRows(rows);
+        return excelData;
+    }
+}

+ 11 - 0
mall-server-api/src/main/resources/mapper/CommonMapper.xml

@@ -1464,4 +1464,15 @@
         ${ex.orderBy}
     </select>
 
+    <select id="policyList" resultType="com.gree.mall.manager.bean.supply.policy.PolicyVO">
+        SELECT
+        ${ex.selected}
+        FROM policy a
+        ${ex.query}
+        <if test="ex.orderBy == null or ex.orderBy ==''">
+            ORDER BY a.create_time DESC
+        </if>
+        ${ex.orderBy}
+    </select>
+
 </mapper>

二進制
mall-server-api/src/main/resources/template/policy_goods.xlsx