Browse Source

1、销售合同关联客户

dongpo 6 months ago
parent
commit
1fea4f2268

+ 8 - 0
yudao-module-customer/yudao-module-customer-api/src/main/java/cn/iocoder/yudao/module/customer/api/info/CustomerInfoApi.java

@@ -20,4 +20,12 @@ public interface CustomerInfoApi {
      * @return 客户信息列表
      */
     List<CustomerInfoDTO> getCustomerInfoList(Collection<Long> ids);
+
+    /**
+     * 获得客户信息
+     *
+     * @param id 客户信息id
+     * @return 客户信息
+     */
+    CustomerInfoDTO getCustomerInfo(Long id);
 }

+ 6 - 0
yudao-module-customer/yudao-module-customer-biz/src/main/java/cn/iocoder/yudao/module/customer/api/info/CustomerInfoApiImpl.java

@@ -31,4 +31,10 @@ public class CustomerInfoApiImpl implements CustomerInfoApi {
         List<CustomerInfoDO> customerInfoDOList = customerInfoService.getCustomerInfoList(ids);
         return BeanUtils.toBean(customerInfoDOList, CustomerInfoDTO.class);
     }
+
+    @Override
+    public CustomerInfoDTO getCustomerInfo(Long id) {
+        CustomerInfoDO customerInfoDO = customerInfoService.getInfo(id);
+        return BeanUtils.toBean(customerInfoDO, CustomerInfoDTO.class);
+    }
 }

+ 2 - 0
yudao-module-finance/yudao-module-contract-api/src/main/java/cn/iocoder/yudao/module/contract/enums/ErrorCodeConstants.java

@@ -6,12 +6,14 @@ public interface ErrorCodeConstants {
     // ========== 采购合同信息 1_052_000_001 ==========
     ErrorCode SUPPLIER_CONTRACT_NOT_EXISTS = new ErrorCode(1_052_000_001, "采购合同信息不存在");
     ErrorCode SUPPLIER_CONTRACT_NOT_CLOSED = new ErrorCode(1_052_000_002, "采购合同已经是开启状态");
+    ErrorCode SUPPLIER_CONTRACT_CODE_EXISTS = new ErrorCode(1_052_000_003, "采购合同编号已存在");
     // ========== 采购合同历史信息 1_052_001_001 ==========
     ErrorCode SUPPLIER_CONTRACT_HISTORY_NOT_EXISTS = new ErrorCode(1_052_001_001, "采购合同历史信息不存在");
 
     // ========== 销售合同信息 1_052_002_001 ==========
     ErrorCode CUSTOMER_CONTRACT_NOT_EXISTS = new ErrorCode(1_052_002_001, "销售合同信息不存在");
     ErrorCode CUSTOMER_CONTRACT_NOT_CLOSED = new ErrorCode(1_052_002_002, "销售合同已经是开启状态");
+    ErrorCode CUSTOMER_CONTRACT_CODE_EXISTS = new ErrorCode(1_052_002_003, "销售合同编号已存在");
     // ========== 销售合同历史信息 1_052_003_001 ==========
     ErrorCode CUSTOMER_CONTRACT_HISTORY_NOT_EXISTS = new ErrorCode(1_052_003_001, "销售合同历史信息不存在");
 

+ 5 - 0
yudao-module-finance/yudao-module-contract-biz/pom.xml

@@ -38,6 +38,11 @@
             <artifactId>yudao-module-employee-api</artifactId>
             <version>${revision}</version>
         </dependency>
+        <dependency>
+            <groupId>cn.iocoder.boot</groupId>
+            <artifactId>yudao-module-customer-api</artifactId>
+            <version>${revision}</version>
+        </dependency>
 
         <!-- 业务组件 -->
         <dependency>

+ 14 - 0
yudao-module-finance/yudao-module-contract-biz/src/main/java/cn/iocoder/yudao/module/contract/controller/admin/customercontract/CustomerContractController.java

@@ -12,6 +12,8 @@ import cn.iocoder.yudao.module.contract.dal.dataobject.customercontract.Customer
 import cn.iocoder.yudao.module.contract.dal.dataobject.customercontract.CustomerContractHistoryDO;
 import cn.iocoder.yudao.module.contract.enums.ContractStatusEnum;
 import cn.iocoder.yudao.module.contract.service.customercontract.CustomerContractService;
+import cn.iocoder.yudao.module.customer.api.info.CustomerInfoApi;
+import cn.iocoder.yudao.module.customer.api.info.dto.CustomerInfoDTO;
 import cn.iocoder.yudao.module.employee.api.EmployeeApi;
 import cn.iocoder.yudao.module.employee.api.dto.EmployeeRespDTO;
 import cn.iocoder.yudao.module.infra.api.file.FileApi;
@@ -57,6 +59,9 @@ public class CustomerContractController {
     @Resource
     private FileApi fileApi;
 
+    @Resource
+    private CustomerInfoApi customerInfoApi;
+
 
     @GetMapping("/getCustomerContractCode")
     @Operation(summary = "获取销售合同编号")
@@ -120,6 +125,15 @@ public class CustomerContractController {
         if (Objects.nonNull(ownerDept)) {
             customerContractRespVO.setDeptName(ownerDept.getName());
         }
+        // 客户名称
+        Long customerId = customerContract.getCustomerId();
+        if (customerId != null) {
+            CustomerInfoDTO customerInfo = customerInfoApi.getCustomerInfo(customerId);
+            if (customerInfo != null) {
+                customerContractRespVO.setCustomerName(customerInfo.getCustomerName());
+            }
+        }
+
         // 合同状态描述
         Map<String, String> contractStatusMap = Arrays.stream(ContractStatusEnum.values())
                 .collect(Collectors.toMap(ContractStatusEnum::getStatus, ContractStatusEnum::getDesc));

+ 13 - 0
yudao-module-finance/yudao-module-contract-biz/src/main/java/cn/iocoder/yudao/module/contract/service/customercontract/CustomerContractServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.contract.service.customercontract;
 
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.enums.GeneralStatusEnum;
 import cn.iocoder.yudao.framework.common.exception.ErrorCode;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -24,6 +25,7 @@ import org.springframework.validation.annotation.Validated;
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.util.ConcurrentModificationException;
 import java.util.List;
 import java.util.Objects;
 
@@ -68,6 +70,10 @@ public class CustomerContractServiceImpl implements CustomerContractService {
         if (Objects.isNull(loginEmployee)) {
             throw exception(new ErrorCode(EMPLOYEE_INFO_NOT_EXISTS.getCode(), "登录用户员工信息不存在"));
         }
+        String customerContractCode = createReqVO.getCustomerContractCode();
+        if (StrUtil.isNotBlank(customerContractCode)) {
+            validateCustomerContractCode(customerContractCode);
+        }
         // 插入
         CustomerContractDO customerContract = BeanUtils.toBean(createReqVO, CustomerContractDO.class);
         // uuid
@@ -105,6 +111,13 @@ public class CustomerContractServiceImpl implements CustomerContractService {
         return customerContract.getId();
     }
 
+    private void validateCustomerContractCode(String customerContractCode) {
+        Long aLong = customerContractMapper.selectCount(CustomerContractDO::getCustomerContractCode, customerContractCode);
+        if (aLong > 0) {
+            throw exception(CUSTOMER_CONTRACT_CODE_EXISTS);
+        }
+    }
+
     @Override
     public void updateCustomerContract(CustomerContractSaveReqVO updateReqVO) {
         // 校验存在

+ 12 - 0
yudao-module-finance/yudao-module-contract-biz/src/main/java/cn/iocoder/yudao/module/contract/service/suppliercontract/SupplierContractServiceImpl.java

@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.contract.service.suppliercontract;
 
 import cn.hutool.core.util.IdUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.enums.GeneralStatusEnum;
 import cn.iocoder.yudao.framework.common.exception.ErrorCode;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -68,6 +69,10 @@ public class SupplierContractServiceImpl implements SupplierContractService {
         if (Objects.isNull(loginEmployee)) {
             throw exception(new ErrorCode(EMPLOYEE_INFO_NOT_EXISTS.getCode(), "登录用户员工信息不存在"));
         }
+        String supplierContractCode = createReqVO.getSupplierContractCode();
+        if (StrUtil.isNotBlank(supplierContractCode)) {
+            validateSupplierContractCode(supplierContractCode);
+        }
         // 插入
         SupplierContractDO supplierContract = BeanUtils.toBean(createReqVO, SupplierContractDO.class);
         // uuid
@@ -105,6 +110,13 @@ public class SupplierContractServiceImpl implements SupplierContractService {
         return supplierContract.getId();
     }
 
+    private void validateSupplierContractCode(String supplierContractCode) {
+        Long aLong = supplierContractMapper.selectCount(SupplierContractDO::getSupplierContractCode, supplierContractCode);
+        if (aLong > 0) {
+            throw exception(SUPPLIER_CONTRACT_CODE_EXISTS);
+        }
+    }
+
     @Override
     public void updateSupplierContract(SupplierContractSaveReqVO updateReqVO) {
         // 校验存在

+ 2 - 1
yudao-module-finance/yudao-module-contract-biz/src/main/resources/mapper/customercontract/CustomerContractMapper.xml

@@ -67,7 +67,7 @@
         ELSE '未知'
         END AS isFrameContractDesc,
         fcc.customer_id,
-        fcc.customer_name,
+        ci.customer_name,
         fcc.start_date,
         fcc.end_date,
         fcc.money,
@@ -107,6 +107,7 @@
         LEFT JOIN employee_info ei ON ei.id = fcc.owner_employee_id AND ei.deleted = 0
         LEFT JOIN system_dept sd ON sd.id = fcc.dept_id AND sd.deleted = 0
         LEFT JOIN employee_info ei2 ON ei2.id = fcc.creator AND ei2.deleted = 0
+        LEFT JOIN customer_info ci ON ci.id = fcc.customer_id AND ci.deleted = 0
         WHERE
         fcc.deleted = 0
         <if test="page.customerContractCode != null and page.customerContractCode != ''">

+ 0 - 1
yudao-module-personnel/yudao-module-employee-biz/src/main/java/cn/iocoder/yudao/module/employee/service/info/EmployeeInfoServiceImpl.java

@@ -242,7 +242,6 @@ public class EmployeeInfoServiceImpl implements EmployeeInfoService {
 
     @Override
     public EmployeeInfoDO getInfo(Long id) {
-        validateInfoExists(id);
         return infoMapper.selectById(id);
     }