| | |
| | | public int updateCustomer(Customer customer) { |
| | | LoginUser loginUser = SecurityUtils.getLoginUser(); |
| | | Long tenantId = loginUser.getTenantId(); |
| | | validateCustomerEditPermission(customer.getId()); |
| | | customer.setTenantId(tenantId); |
| | | return customerMapper.updateById(customer); |
| | | } |
| | |
| | | public void recycleCustomer(CustomerDto customerDto) { |
| | | Customer customer = customerMapper.selectById(customerDto.getId()); |
| | | if (customer.getType() == 1 && customer.getIsAssigned() == 1) { // 公海且已分配 |
| | | validatePublicSeaRecyclePermission(customer.getId()); |
| | | customer.setIsAssigned(0); |
| | | customer.setUsageStatus(0L); |
| | | customer.setUsageUser(0L); |
| | |
| | | return this.updateById(customer); |
| | | } |
| | | |
| | | private void validateCustomerEditPermission(Long customerId) { |
| | | Customer customer = customerMapper.selectById(customerId); |
| | | if (customer == null) { |
| | | throw new RuntimeException("客户档案不存在"); |
| | | } |
| | | if (!hasSalesModuleReference(customerId)) { |
| | | return; |
| | | } |
| | | if (Objects.equals(customer.getType(), 0)) { |
| | | throw new RuntimeException("已被销售模块引用的私海客户不能编辑"); |
| | | } |
| | | if (Objects.equals(customer.getType(), 1) && Objects.equals(customer.getIsAssigned(), 1)) { |
| | | throw new RuntimeException("已领用并且被销售模块引用的公海客户不能编辑"); |
| | | } |
| | | } |
| | | |
| | | private void validatePublicSeaRecyclePermission(Long customerId) { |
| | | if (hasSalesModuleReference(customerId)) { |
| | | throw new RuntimeException("已领用并且被销售模块引用的公海客户不能回收"); |
| | | } |
| | | } |
| | | |
| | | private boolean hasSalesModuleReference(Long customerId) { |
| | | Long salesLedgerCount = salesLedgerMapper.selectCount(new QueryWrapper<SalesLedger>().lambda() |
| | | .eq(SalesLedger::getCustomerId, customerId)); |
| | | if (salesLedgerCount != null && salesLedgerCount > 0) { |
| | | return true; |
| | | } |
| | | Long salesQuotationCount = salesQuotationMapper.selectCount(new QueryWrapper<SalesQuotation>().lambda() |
| | | .eq(SalesQuotation::getCustomerId, customerId)); |
| | | if (salesQuotationCount != null && salesQuotationCount > 0) { |
| | | return true; |
| | | } |
| | | Long returnManagementCount = returnManagementMapper.selectCount(new QueryWrapper<ReturnManagement>().lambda() |
| | | .eq(ReturnManagement::getCustomerId, customerId)); |
| | | return returnManagementCount != null && returnManagementCount > 0; |
| | | } |
| | | |
| | | @Override |
| | | public IPage<CustomerTransactionsVo> customewTransactions(Page page, String customerName) { |
| | | return customerMapper.customewTransactions(page, customerName); |