|
|
|
|
@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
|
|
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.controller.admin.customer.vo.customer.*;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.dataobject.customer.CrmCustomerDO;
|
|
|
|
|
import cn.iocoder.yudao.module.mes.dal.mysql.customer.CrmCustomerMapper;
|
|
|
|
|
@ -30,10 +31,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
@Resource
|
|
|
|
|
private CrmCustomerMapper customerMapper;
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
private AutoCodeUtil autoCodeUtil;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Long createCustomer(CrmCustomerSaveReqVO createReqVO, Long userId) {
|
|
|
|
|
createReqVO.setId(null);
|
|
|
|
|
handleCustomerCodeForCreate(createReqVO);
|
|
|
|
|
validateCustomerForCreate(createReqVO.getName());
|
|
|
|
|
CrmCustomerDO customer = initCustomer(createReqVO, userId);
|
|
|
|
|
customerMapper.insert(customer);
|
|
|
|
|
@ -45,6 +50,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
public void updateCustomer(CrmCustomerSaveReqVO updateReqVO) {
|
|
|
|
|
validateCustomerExists(updateReqVO.getId());
|
|
|
|
|
validateCustomerNameUnique(updateReqVO.getName(), updateReqVO.getId());
|
|
|
|
|
validateCustomerCodeUnique(updateReqVO.getCustomerCode(), updateReqVO.getId());
|
|
|
|
|
CrmCustomerDO updateObj = BeanUtils.toBean(updateReqVO, CrmCustomerDO.class);
|
|
|
|
|
if (updateObj.getOwnerUserId() != null) {
|
|
|
|
|
updateObj.setOwnerTime(LocalDateTime.now());
|
|
|
|
|
@ -141,6 +147,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Long createCustomer(CrmCustomerCreateReqBO createReqBO, Long userId) {
|
|
|
|
|
handleCustomerCodeForCreate(createReqBO);
|
|
|
|
|
validateCustomerForCreate(createReqBO.getName());
|
|
|
|
|
CrmCustomerDO customer = initCustomer(createReqBO, userId);
|
|
|
|
|
customerMapper.insert(customer);
|
|
|
|
|
@ -161,6 +168,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
.build();
|
|
|
|
|
for (CrmCustomerImportExcelVO importCustomer : importCustomers) {
|
|
|
|
|
try {
|
|
|
|
|
handleCustomerCodeForCreate(importCustomer);
|
|
|
|
|
validateCustomerForCreate(importCustomer.getName());
|
|
|
|
|
} catch (ServiceException ex) {
|
|
|
|
|
CrmCustomerDO existCustomer = customerMapper.selectByCustomerName(importCustomer.getName());
|
|
|
|
|
@ -225,6 +233,30 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
return customer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleCustomerCodeForCreate(CrmCustomerSaveReqVO reqVO) {
|
|
|
|
|
if (StrUtil.isBlank(reqVO.getCustomerCode())) {
|
|
|
|
|
reqVO.setCustomerCode(autoCodeUtil.genSerialCode("CUSTOMER_CODE", null));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
validateCustomerCodeUnique(reqVO.getCustomerCode(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleCustomerCodeForCreate(CrmCustomerCreateReqBO reqBO) {
|
|
|
|
|
if (StrUtil.isBlank(reqBO.getCustomerCode())) {
|
|
|
|
|
reqBO.setCustomerCode(autoCodeUtil.genSerialCode("CUSTOMER_CODE", null));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
validateCustomerCodeUnique(reqBO.getCustomerCode(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void handleCustomerCodeForCreate(CrmCustomerImportExcelVO importVO) {
|
|
|
|
|
if (StrUtil.isBlank(importVO.getCustomerCode())) {
|
|
|
|
|
importVO.setCustomerCode(autoCodeUtil.genSerialCode("CUSTOMER_CODE", null));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
validateCustomerCodeUnique(importVO.getCustomerCode(), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CrmCustomerDO validateCustomerExists(Long id) {
|
|
|
|
|
CrmCustomerDO customer = customerMapper.selectById(id);
|
|
|
|
|
if (customer == null) {
|
|
|
|
|
@ -246,4 +278,14 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
|
|
|
|
|
throw exception(CUSTOMER_NAME_EXISTS, name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validateCustomerCodeUnique(String customerCode, Long id) {
|
|
|
|
|
if (StrUtil.isBlank(customerCode)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CrmCustomerDO customer = customerMapper.selectByCustomerCode(customerCode);
|
|
|
|
|
if (customer != null && !Objects.equals(customer.getId(), id)) {
|
|
|
|
|
throw exception(CUSTOMER_CODE_EXISTS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|