OutCommon.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.dk.mdm.service.ivt.outbound;
  2. import com.dk.common.exception.BaseBusinessException;
  3. import com.dk.common.infrastructure.constant.Constant;
  4. import com.dk.common.infrastructure.enums.ErrorCodeEnum;
  5. import com.dk.common.response.ResponseCodeEnum;
  6. import com.dk.mdm.mapper.mst.CustomerMapper;
  7. import com.dk.mdm.mapper.sale.MultiOwnerMapper;
  8. import com.dk.mdm.model.pojo.mst.Customer;
  9. import com.dk.mdm.model.pojo.sale.MultiOwner;
  10. import com.dk.mdm.model.vo.ivt.OutboundVO;
  11. import com.dk.mdm.service.common.CommonService;
  12. import com.dk.mdm.service.mst.CustomerService;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.math.BigDecimal;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * @desc : 新建客户,业务归属共通
  22. * @date : 2024/3/29 11:30
  23. * @author : 寇珊珊
  24. */
  25. @Service
  26. public class OutCommon {
  27. @Autowired
  28. private CommonService commonService;
  29. @Autowired
  30. private CustomerMapper customerMapper;
  31. @Autowired
  32. private CustomerService customerService;
  33. @Autowired
  34. private MultiOwnerMapper multiOwnerMapper;
  35. /**
  36. * @desc : 新建客户
  37. * @date : 2024/3/27 9:28
  38. * @author : 寇珊珊
  39. */
  40. @Transactional(rollbackFor = {Exception.class})
  41. public OutboundVO insertCustomer(OutboundVO outboundVO) {
  42. // 如果没有客户id,要新建
  43. if (outboundVO.getCusId() == null) {
  44. List<Customer> listCustomer = customerMapper.selectByCond(new Customer().setCpId(outboundVO.getCpId()).setCusPhone(outboundVO.getCusPhone()));
  45. // 如果客户电话已存在
  46. if (listCustomer.size() > 0) {
  47. throw new BaseBusinessException(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISEXISTS_CUSPHONE.getMessage());
  48. }
  49. // 创建客户,获取编码和主键UuId
  50. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.CUSTOMER.getName(), true);
  51. Customer customer = new Customer();
  52. // 增加跟进人,用于权限分配
  53. List<String> followStaffs = new ArrayList<>();
  54. followStaffs.add(outboundVO.getMakeStaff());
  55. customer.setCusId(codeMap.get("outId").toString()).setCusCode(codeMap.get("outNote").toString()).setCusName(outboundVO.getCusName())
  56. .setCusPhone(outboundVO.getCusPhone()).setAddressArea(outboundVO.getAddressArea()).setAddressName(outboundVO.getAddressName())
  57. .setAddressNo(outboundVO.getAddressNo()).setAddressGcj02(outboundVO.getAddressGcj02()).setAddressFull(outboundVO.getAddressFull())
  58. .setContactName(outboundVO.getContactName()).setContactPhone(outboundVO.getContactPhone()).setCusFrom(outboundVO.getCusFrom())
  59. .setChannelId(outboundVO.getSalesChannel()).setOrgId(outboundVO.getOrgId()).setStaffId(outboundVO.getStaffId())
  60. .setFollowStaffs(followStaffs).setCusFrom(outboundVO.getCusFrom())
  61. .setReportStaff(outboundVO.getMakeStaff()).setSaleStatus(Constant.SaleStatus.CHENGJIAO.getName()).setCpId(outboundVO.getCpId());
  62. customerMapper.insert(customer);
  63. outboundVO.setCusId(customer.getCusId());
  64. }else {
  65. // 如果当前跟进人
  66. Customer cus = customerMapper.selectByIdForUpdate(outboundVO.getCusId());
  67. List<String> followStaffs = cus.getFollowStaffs();
  68. if(followStaffs == null ){
  69. followStaffs.add(outboundVO.getMakeStaff());
  70. }else{
  71. if(!followStaffs.contains(outboundVO.getMakeStaff())){
  72. followStaffs.add(outboundVO.getMakeStaff());
  73. }
  74. }
  75. //编辑客户
  76. Customer customer = new Customer();
  77. customer.setCusName(outboundVO.getCusName()).setCusId(outboundVO.getCusId())
  78. .setCusPhone(outboundVO.getCusPhone()).setAddressArea(outboundVO.getAddressArea()).setAddressName(outboundVO.getAddressName())
  79. .setAddressNo(outboundVO.getAddressNo()).setAddressGcj02(outboundVO.getAddressGcj02()).setAddressFull(outboundVO.getAddressFull())
  80. .setContactName(outboundVO.getContactName()).setContactPhone(outboundVO.getContactPhone()).setCusFrom(outboundVO.getCusFrom())
  81. .setChannelId(outboundVO.getSalesChannel()).setOrgId(outboundVO.getOrgId()).setStaffId(outboundVO.getStaffId())
  82. .setFollowStaffs(followStaffs).setCusFrom(outboundVO.getCusFrom())
  83. .setSaleStatus(Constant.SaleStatus.CHENGJIAO.getName());
  84. customerService.updateByUuid(customer);
  85. }
  86. return outboundVO;
  87. }
  88. /**
  89. * @desc : 新建多业务归属
  90. * @date : 2024/3/27 9:33
  91. * @author : 寇珊珊
  92. */
  93. @Transactional(rollbackFor = {Exception.class})
  94. public void insertMultiOwner(OutboundVO outboundVO){
  95. // 业务部门业绩保存
  96. if (outboundVO.getOrgList() != null && outboundVO.getOrgList().size() > 0) {
  97. for (Map<String, Object> map : outboundVO.getOrgList()) {
  98. MultiOwner multiOwner = new MultiOwner();
  99. multiOwner.setOrderId(outboundVO.getOutId()).setOwnerId(map.get("orgId").toString())
  100. .setAllocationRatio(new BigDecimal(map.get("allocationRatio").toString())).setCpId(outboundVO.getCpId());
  101. if (Boolean.parseBoolean(map.get("ownerFlag").toString())) {
  102. multiOwner.setOwnerType(Constant.OwnerType.Z_ORG.getName());
  103. } else {
  104. multiOwner.setOwnerType(Constant.OwnerType.C_ORG.getName());
  105. }
  106. multiOwnerMapper.insert(multiOwner);
  107. }
  108. }
  109. // 业务员业绩保存
  110. if (outboundVO.getStaffList() != null && outboundVO.getStaffList().size() > 0) {
  111. for (Map<String, Object> map : outboundVO.getStaffList()) {
  112. MultiOwner multiOwner = new MultiOwner();
  113. multiOwner.setOrderId(outboundVO.getOutId()).setOwnerId(map.get("staffId").toString())
  114. .setAllocationRatio(new BigDecimal(map.get("allocationRatio").toString())).setCpId(outboundVO.getCpId());
  115. if (Boolean.parseBoolean(map.get("ownerFlag").toString())) {
  116. multiOwner.setOwnerType(Constant.OwnerType.Z_STAFF.getName());
  117. } else {
  118. multiOwner.setOwnerType(Constant.OwnerType.C_STAFF.getName());
  119. }
  120. multiOwnerMapper.insert(multiOwner);
  121. }
  122. }
  123. }
  124. }