|
|
@@ -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;
|
|
|
+ }
|
|
|
+}
|