Pārlūkot izejas kodu

优化-数据管理-客户管理

zhouxin 1 gadu atpakaļ
vecāks
revīzija
0edbc71f05

+ 6 - 0
superdesk-uniorder-dao/src/main/java/cn/superdesk/uniorder/dao/mapper/unified/settlement/UnifiedSettlementProgrammeMapperEx.java

@@ -3,9 +3,15 @@ package cn.superdesk.uniorder.dao.mapper.unified.settlement;
 import cn.superdesk.uniorder.dto.param.operationCenter.customer.OperationCenterCustomerParam;
 import cn.superdesk.uniorder.dto.vo.operationCenter.customer.OperationCenterCustomerVo;
 import cn.superdesk.uniorder.dto.vo.operationCenter.customer.settlement.UnifiedSettlementVo;
+import org.apache.ibatis.annotations.Update;
 
 import java.util.List;
 
 public interface UnifiedSettlementProgrammeMapperEx {
     List<UnifiedSettlementVo> list(OperationCenterCustomerParam param);
+
+    @Update("update unified_settlement_programme set " +
+            "update_time =NOW(), update_user_id= #{userId},is_default=#{isDefault}  " +
+            "where customer_id =#{customerId}")
+    int updateIsDefaultByCustomerId(Long customerId, Integer isDefault, Long userId);
 }

+ 2 - 2
superdesk-uniorder-dao/src/main/resources/mappers/unified/settlement/UnifiedSettlementProgrammeMapperEx.xml

@@ -21,7 +21,7 @@
              on t.update_user_id= t1.id
         WHERE
             t.deleted=0
-        <if test="status !=null and status !=''">
+        <if test="status !=null ">
             and t.enabled=#{status}
         </if>
         <if test="programmeName !=null and programmeName !=''">
@@ -35,7 +35,7 @@
         </if>
 
 
-        ORDER BY t.update_time
+        ORDER BY t.update_time desc
 
     </select>
 </mapper>

+ 3 - 0
superdesk-uniorder-dubbo-provider/src/main/java/cn/superdesk/uniorder/dubbo/provider/operationCenter/customer/DubboOperationCenterCustomerServiceImpl.java

@@ -93,6 +93,9 @@ public class DubboOperationCenterCustomerServiceImpl implements DubboOperationCe
 
         if (null != param.getBusinessId()) {
             OperationCenterBusiness entity = operationCenterBusinessService.findById(param.getBusinessId());
+            if (null == entity) {
+                return new R("500", "所关联的业务人员不存在或已删除,请重新选择!", false);
+            }
             param.setBusinessName(entity.getUserName());
         }
 

+ 2 - 2
superdesk-uniorder-dubbo-provider/src/main/java/cn/superdesk/uniorder/dubbo/provider/unified/settlement/DubboUnifiedSettlementProgrammeServiceImpl.java

@@ -64,8 +64,8 @@ public class DubboUnifiedSettlementProgrammeServiceImpl implements DubboUnifiedS
         //unifiedSettlementProgrammeService.deleteObj(ids);
 
         List<Long> idsList = Arrays.stream(ids.split(",")).map(x -> Long.parseLong(x)).collect(Collectors.toList());
-        unifiedSettlementProgrammeService.deleteByIds(idsList,userId);
-        return new R<>("删除成功!");
+
+        return  unifiedSettlementProgrammeService.deleteByIds(idsList,userId);
     }
 
     @Override

+ 1 - 1
superdesk-uniorder-service/src/main/java/cn/superdesk/uniorder/service/unified/settlement/UnifiedSettlementProgrammeService.java

@@ -21,5 +21,5 @@ public interface UnifiedSettlementProgrammeService extends BaseService<UnifiedSe
 
     R<String> setDefault(Long id,Long userId);
 
-    void deleteByIds(List<Long> idsList,Long userId);
+    R<String> deleteByIds(List<Long> idsList,Long userId);
 }

+ 58 - 16
superdesk-uniorder-service/src/main/java/cn/superdesk/uniorder/service/unified/settlement/impl/UnifiedSettlementProgrammeServiceImpl.java

@@ -90,7 +90,6 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
     }
 
 
-
     @Transactional(rollbackFor = Exception.class)
     @Override
     public R<String> saveUnifiedSettlement(UnifiedSettlementParam param, Long sysUserId) {
@@ -107,14 +106,14 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         entity.setUpdateTime(new Date());
         entity.setUpdateUserId(sysUserId);
 
-        entity.setProgrammeNo("PR"+ DateUtil.format(new Date(), "yyyyMM")+  GenRandomHelper.genRandomNum(6) );
+        entity.setProgrammeNo("PR" + DateUtil.format(new Date(), "yyyyMM") + GenRandomHelper.genRandomNum(6));
         SettlementExportFieldVo vo = new SettlementExportFieldVo();
         BeanUtils.copyProperties(param, vo);
         entity.setExportField(JSON.toJSONString(vo));
         unifiedSettlementProgrammeMapper.insertSelective(entity);
 
         if (param.getSettlementScope().intValue() == SettlementScopeEnum.部分订单不参与结算.getKey().intValue()
-            && CollectionUtils.isNotEmpty(param.getUnifiedSettlementRangeRuleParam1List())) {
+                && CollectionUtils.isNotEmpty(param.getUnifiedSettlementRangeRuleParam1List())) {
 
             //结算范围 部分订单不参与结算
             for (UnifiedSettlementRangeRuleParam unifiedSettlementRangeRuleParam : param.getUnifiedSettlementRangeRuleParam1List()) {
@@ -138,7 +137,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
             for (UnifiedSettlementAmountRuleParam amountRuleParam : param.getUnifiedSettlementAmountRuleParamList()) {
                 UnifiedSettlementProgrammeAmountRule rule = new UnifiedSettlementProgrammeAmountRule();
 
-                BeanUtils.copyProperties(amountRuleParam,rule);
+                BeanUtils.copyProperties(amountRuleParam, rule);
                 rule.setCreateUserId(sysUserId);
                 rule.setCreateTime(new Date());
                 rule.setProgrammeId(entity.getId());
@@ -170,7 +169,9 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
 
         UnifiedCenterCustomer customer = new UnifiedCenterCustomer();
         customer.setId(param.getCustomerId());
-        customer.setIsSettlementMethod((byte)1);
+        customer.setIsSettlementMethod((byte) 1);
+        customer.setUpdateUserId(sysUserId);
+        customer.setUpdateTime(new Date());
         unifiedCenterCustomerMapper.updateByPrimaryKeySelective(customer);
 
         //更改客户主体 结算方案已配置
@@ -202,7 +203,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
                 && CollectionUtils.isNotEmpty(param.getUnifiedSettlementRangeRuleParam1List())) {
 
             //先删除
-            UnifiedSettlementProgrammeRangeRuleExample example =new UnifiedSettlementProgrammeRangeRuleExample();
+            UnifiedSettlementProgrammeRangeRuleExample example = new UnifiedSettlementProgrammeRangeRuleExample();
             example.createCriteria().andProgrammeIdEqualTo(param.getId());
             unifiedSettlementProgrammeRangeRuleMapper.deleteByExample(example);
 
@@ -235,7 +236,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
             for (UnifiedSettlementAmountRuleParam amountRuleParam : param.getUnifiedSettlementAmountRuleParamList()) {
                 UnifiedSettlementProgrammeAmountRule rule = new UnifiedSettlementProgrammeAmountRule();
 
-                BeanUtils.copyProperties(amountRuleParam,rule);
+                BeanUtils.copyProperties(amountRuleParam, rule);
                 rule.setCreateUserId(sysUserId);
                 rule.setCreateTime(new Date());
                 rule.setProgrammeId(entity.getId());
@@ -248,7 +249,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
 
         if (param.getSupnameDisplayRule().intValue() == SupnameDisplayRuleEnum.部分按原供应商名称导出.getKey().intValue()
                 && CollectionUtils.isNotEmpty(param.getUnifiedSettlementRangeRuleParam1List())) {
-            UnifiedSettlementProgrammeRangeRuleExample example =new UnifiedSettlementProgrammeRangeRuleExample();
+            UnifiedSettlementProgrammeRangeRuleExample example = new UnifiedSettlementProgrammeRangeRuleExample();
             example.createCriteria().andProgrammeIdEqualTo(param.getId());
             unifiedSettlementProgrammeRangeRuleMapper.deleteByExample(example);
 
@@ -286,7 +287,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         //主体
         UnifiedCenterCustomer customer = unifiedCenterCustomerMapper.selectByPrimaryKey(programme.getCustomerId());
         vo.setCustomerName(customer.getCustomerName());
-        vo.setTypeDesc(SettlementProgrammeTypeEnum.getDescByKey((int)customer.getType()));
+        vo.setTypeDesc(SettlementProgrammeTypeEnum.getDescByKey((int) customer.getType()));
 
         List<UnifiedSettlementRangeRuleParam> unifiedSettlementRangeRuleParam1List = new ArrayList<>();
 
@@ -295,14 +296,13 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         List<UnifiedSettlementRangeRuleParam> unifiedSettlementRangeRuleParam2List = new ArrayList<>();
 
 
-
-        UnifiedSettlementProgrammeRangeRuleExample example1 =new UnifiedSettlementProgrammeRangeRuleExample();
+        UnifiedSettlementProgrammeRangeRuleExample example1 = new UnifiedSettlementProgrammeRangeRuleExample();
         example1.createCriteria().andProgrammeIdEqualTo(id).andTypeEqualTo((byte) 1);
         List<UnifiedSettlementProgrammeRangeRule> rangeRules1 = unifiedSettlementProgrammeRangeRuleMapper.selectByExampleWithBLOBs(example1);
 
         for (UnifiedSettlementProgrammeRangeRule voRangeRule : rangeRules1) {
             UnifiedSettlementRangeRuleParam RangeRuleParam = new UnifiedSettlementRangeRuleParam();
-            BeanUtils.copyProperties(voRangeRule,RangeRuleParam);
+            BeanUtils.copyProperties(voRangeRule, RangeRuleParam);
             if (StringUtils.isNotBlank(voRangeRule.getNotJoiningRangeJson())) {
 
                 RangeRuleParam.setSysSelectVoList(JSON.parseArray(voRangeRule.getNotJoiningRangeJson(), OperationCenterVo.class));
@@ -311,13 +311,13 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         }
 
 
-        UnifiedSettlementProgrammeRangeRuleExample example2 =new UnifiedSettlementProgrammeRangeRuleExample();
+        UnifiedSettlementProgrammeRangeRuleExample example2 = new UnifiedSettlementProgrammeRangeRuleExample();
         example2.createCriteria().andProgrammeIdEqualTo(id).andTypeEqualTo((byte) 2);
         List<UnifiedSettlementProgrammeRangeRule> rangeRules2 = unifiedSettlementProgrammeRangeRuleMapper.selectByExampleWithBLOBs(example2);
 
         for (UnifiedSettlementProgrammeRangeRule voRangeRule : rangeRules2) {
             UnifiedSettlementRangeRuleParam RangeRuleParam = new UnifiedSettlementRangeRuleParam();
-            BeanUtils.copyProperties(voRangeRule,RangeRuleParam);
+            BeanUtils.copyProperties(voRangeRule, RangeRuleParam);
             if (StringUtils.isNotBlank(voRangeRule.getNotJoiningRangeJson())) {
                 List<OperationCenterVo> operationCenterVos = JSON.parseArray(voRangeRule.getNotJoiningRangeJson(), OperationCenterVo.class);
                 RangeRuleParam.setSysSelectVoList(operationCenterVos);
@@ -342,7 +342,7 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
     }
 
     @Override
-    public R<String> setDefault(Long id,Long userId) {
+    public R<String> setDefault(Long id, Long userId) {
         UnifiedSettlementProgrammeExample example = new UnifiedSettlementProgrammeExample();
         example.createCriteria().andDeletedEqualTo((byte) 0)
                 .andIdEqualTo(id);
@@ -352,6 +352,13 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         }
         Integer isDefault = unifiedSettlementProgrammes.get(0).getIsDefault();
 
+        //设置该结算方案为默认
+        if (0 == isDefault) {
+            //将该客户下的所有 设为非默认
+            Long customerId = unifiedSettlementProgrammes.get(0).getCustomerId();
+            unifiedSettlementProgrammeMapperEx.updateIsDefaultByCustomerId(customerId, 0, userId);
+        }
+
         UnifiedSettlementProgramme entity = new UnifiedSettlementProgramme();
         entity.setId(id);
         entity.setIsDefault(isDefault == 1 ? 0 : 1);
@@ -363,7 +370,26 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
     }
 
     @Override
-    public void deleteByIds(List<Long> idsList,Long userId) {
+    public R<String> deleteByIds(List<Long> idsList, Long userId) {
+        //删除前 检查 要删除的 有没有开启状态的
+        UnifiedSettlementProgrammeExample example1 = new UnifiedSettlementProgrammeExample();
+        example1.createCriteria().andIdIn(idsList)
+                .andEnabledEqualTo((byte)1);
+        List<UnifiedSettlementProgramme> unifiedSettlementProgrammes = unifiedSettlementProgrammeMapper.selectByExample(example1);
+        if (CollectionUtils.isNotEmpty(unifiedSettlementProgrammes)) {
+            return new R<>("500", "不允许删除启用状态的结算方案,请先停用", false);
+        }
+
+        example1 = new UnifiedSettlementProgrammeExample();
+        example1.createCriteria().andIdIn(idsList)
+                .andIsDefaultEqualTo((byte) 1);
+        List<UnifiedSettlementProgramme> unifiedSettlementProgrammes1 = unifiedSettlementProgrammeMapper.selectByExample(example1);
+        if (CollectionUtils.isNotEmpty(unifiedSettlementProgrammes1)) {
+            return new R<>("500", "不允许删除默认结算方案,请先取消默认", false);
+        }
+
+        //TODO 该结算方案已被账单关联使用,不允许删除,停用方案即可
+
         UnifiedSettlementProgrammeExample example = new UnifiedSettlementProgrammeExample();
         example.createCriteria().andIdIn(idsList);
         UnifiedSettlementProgramme record = new UnifiedSettlementProgramme();
@@ -371,5 +397,21 @@ public class UnifiedSettlementProgrammeServiceImpl implements UnifiedSettlementP
         record.setUpdateUserId(userId);
         record.setUpdateTime(new Date());
         unifiedSettlementProgrammeMapper.updateByExampleSelective(record, example);
+
+        //判断该客户所关联的“未删除”结算方案数量=0时,即为“未配置”;
+        UnifiedSettlementProgramme unifiedSettlementProgramme = unifiedSettlementProgrammeMapper.selectByPrimaryKey(idsList.get(0));
+        OperationCenterCustomerParam param = new OperationCenterCustomerParam();
+        param.setCustomerId(unifiedSettlementProgramme.getCustomerId());
+        List<UnifiedSettlementVo> list = unifiedSettlementProgrammeMapperEx.list(param);
+        if (CollectionUtils.isEmpty(list)) {
+            UnifiedCenterCustomer customer = new UnifiedCenterCustomer();
+            customer.setId(param.getCustomerId());
+            customer.setIsSettlementMethod((byte) 0);
+            customer.setUpdateTime(new Date());
+            customer.setUpdateUserId(userId);
+            unifiedCenterCustomerMapper.updateByPrimaryKeySelective(customer);
+        }
+
+        return new R<>("删除成功");
     }
 }