@@ -73,12 +73,14 @@ import java.math.BigDecimal;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Comparator ;
import java.util.HashMap ;
import java.util.LinkedHashMap ;
import java.util.List ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Set ;
import java.util.stream.Collectors ;
/**
@@ -99,6 +101,8 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
private static final String APPROVAL_APPROVED = " approved " ;
private static final String APPROVAL_REJECTED = " rejected " ;
private static final String CUSTOMER_CODE_PREFIX = " KS " ;
private static final Set < String > CUSTOMER_NATURES = Set . of ( " 有限公司 " , " 个体工商户 " ) ;
private static final Set < String > CUSTOMER_TYPES = Set . of ( " 客户 " , " 承运商 " ) ;
private final CustomerContactMapper contactMapper ;
private final CustomerReceiptAccountMapper receiptAccountMapper ;
@@ -146,6 +150,7 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
}
CustomerArchive entity = Objects . requireNonNull ( BeanUtil . copyProperties ( customer , CustomerArchive . class ) ) ;
boolean result = saveOrUpdate ( entity ) ;
customer . setId ( entity . getId ( ) ) ;
replaceDetail ( entity . getId ( ) , customer ) ;
addChangeRecord ( entity . getId ( ) , created ? " 新增客商档案 " : " 修改客商档案 " ) ;
return result ;
@@ -274,6 +279,9 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
if ( Func . isEmpty ( customer . getCustomerNature ( ) ) ) {
throw new ServiceException ( " 客商性质不能为空 " ) ;
}
if ( ! CUSTOMER_NATURES . contains ( customer . getCustomerNature ( ) ) ) {
throw new ServiceException ( " 客商性质只能选择有限公司或个体工商户 " ) ;
}
if ( Func . isEmpty ( customer . getUnifiedCreditCode ( ) ) ) {
throw new ServiceException ( " 统一社会信用代码不能为空 " ) ;
}
@@ -283,6 +291,7 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
if ( Func . isEmpty ( customer . getCustomerType ( ) ) ) {
throw new ServiceException ( " 客商类型不能为空 " ) ;
}
validateCustomerType ( customer . getCustomerType ( ) ) ;
if ( Func . isEmpty ( customer . getLegalPerson ( ) ) ) {
throw new ServiceException ( " 法人/负责人不能为空 " ) ;
}
@@ -295,8 +304,13 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
if ( Func . isEmpty ( customer . getDeptName ( ) ) ) {
throw new ServiceException ( " 所属组织不能为空 " ) ;
}
if ( Objects . equals ( customer . getBusinessTermType ( ) , " 固定期限 " ) & & Func . isEmpty ( customer . getBusinessEndDate ( ) ) ) {
throw new ServiceException ( " 固定营业期限必须填写营业期限截止日 " ) ;
}
validateLength ( customer . getShortName ( ) , 20 , " 客商简称最多20个汉字 " ) ;
validateLength ( customer . getFullName ( ) , 100 , " 客商全称最多100个字符 " ) ;
validateLength ( customer . getLegalPerson ( ) , 10 , " 法人/负责人最多10个汉字 " ) ;
validateLength ( customer . getContactPhone ( ) , 11 , " 联系电话必须为11位手机号 " ) ;
validateLength ( customer . getRegisteredAddress ( ) , 200 , " 地址最多200个字符 " ) ;
validateLength ( customer . getBusinessScope ( ) , 500 , " 经营范围最多500个字符 " ) ;
validateLength ( customer . getRemark ( ) , 500 , " 备注最多500个字符 " ) ;
@@ -307,6 +321,21 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
validateUnique ( customer ) ;
}
private void validateCustomerType ( String customerType ) {
List < String > typeList = Arrays . stream ( customerType . replace ( " , " , " , " ) . split ( " , " ) )
. map ( String : : trim )
. filter ( Func : : isNotEmpty )
. toList ( ) ;
if ( Func . isEmpty ( typeList ) ) {
throw new ServiceException ( " 客商类型不能为空 " ) ;
}
for ( String type : typeList ) {
if ( ! CUSTOMER_TYPES . contains ( type ) ) {
throw new ServiceException ( " 客商类型只能选择客户或承运商 " ) ;
}
}
}
private void validateApproval ( CustomerArchiveVO customer ) {
if ( Objects . equals ( customer . getAccessType ( ) , ACCESS_FORMAL ) ) {
if ( Func . isEmpty ( customer . getQualificationAttachments ( ) ) ) {