Commit 7c3e1335f0db6c78a2cb39f2a93b629aa89b04fe

Authored by 房远帅
1 parent f87eb8f5

楚江ERP:客户资质-限制一个客户只能有一条资信数据

... ... @@ -149,7 +149,14 @@ public class CustomerCreditController extends DefaultBaseController {
149 149 vo1.setSerialNumber(vo.getSerialNumber());
150 150 List<CustomerCredit> query = customerCreditService.query(vo1);
151 151 if (CollectionUtil.isNotEmpty(query)) {
152   - return InvokeResultBuilder.fail("资信编码已存在!");
  152 + throw new DefaultClientException("资信编码已存在!");
  153 + }
  154 + QueryCustomerCreditVo vo2 = new QueryCustomerCreditVo();
  155 + vo2.setCompanyId(vo.getCompanyId());
  156 + vo2.setStatusCancel("CANCEL");
  157 + List<CustomerCredit> query1 = customerCreditService.query(vo2);
  158 + if (CollectionUtil.isNotEmpty(query1)) {
  159 + throw new DefaultClientException("该单位名称资信已存在!");
153 160 }
154 161 customerCreditService.create(vo);
155 162
... ...
... ... @@ -13,6 +13,7 @@ import com.lframework.xingyun.sc.vo.customer.credit.*;
13 13 import lombok.extern.slf4j.Slf4j;
14 14 import org.apache.commons.collections.CollectionUtils;
15 15
  16 +import javax.annotation.Resource;
16 17 import java.util.ArrayList;
17 18 import java.util.Arrays;
18 19 import java.util.List;
... ... @@ -22,6 +23,10 @@ public class CustomerCreditImportListener extends ExcelImportListener<CustomerCr
22 23
23 24
24 25 private List<String> checkList = new ArrayList<>();
  26 + private List<String> checkNameList = new ArrayList<>();
  27 +
  28 + @Resource
  29 + private CustomerCreditService customerCreditService;
25 30
26 31 @Override
27 32 protected void doInvoke(CustomerCreditImportModel data, AnalysisContext context) {
... ... @@ -36,6 +41,10 @@ public class CustomerCreditImportListener extends ExcelImportListener<CustomerCr
36 41 "第" + context.readRowHolder().getRowIndex() + "行“编号”与第" + (checkList.indexOf(data.getCode()) + 1) + "行重复");
37 42 }
38 43 checkList.add(data.getCode());
  44 + if (checkNameList.contains(data.getName())) {
  45 + throw new DefaultClientException(
  46 + "第" + context.readRowHolder().getRowIndex() + "行“客户名称”与第" + (checkList.indexOf(data.getName()) + 1) + "行重复");
  47 + }
39 48 if (StringUtil.isBlank(data.getName())) {
40 49 throw new DefaultClientException(
41 50 "第" + context.readRowHolder().getRowIndex() + "行“客户名称”不能为空");
... ... @@ -45,9 +54,18 @@ public class CustomerCreditImportListener extends ExcelImportListener<CustomerCr
45 54 throw new DefaultClientException(
46 55 "第" + context.readRowHolder().getRowIndex() + "行“客户名称”不存在");
47 56 } else {
  57 + QueryCustomerCreditVo vo = new QueryCustomerCreditVo();
  58 + vo.setCompanyId(customer.getId());
  59 + vo.setStatusCancel("CANCEL");
  60 + List<CustomerCredit> query = customerCreditService.query(vo);
  61 + if (CollectionUtils.isNotEmpty(query) && query.size() > 0) {
  62 + throw new DefaultClientException(
  63 + "第" + context.readRowHolder().getRowIndex() + "行的客户资信已存在");
  64 + }
48 65 data.setCompanyId(customer.getId());
49 66 }
50 67 }
  68 + checkNameList.add(data.getName());
51 69 if (StringUtil.isBlank(data.getCompanySuggestedCategory())) {
52 70 throw new DefaultClientException(
53 71 "第" + context.readRowHolder().getRowIndex() + "行“客户分类”不能为空");
... ...
... ... @@ -1180,10 +1180,10 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
1180 1180 return sysUserService.findById(sysDept.getUserId());
1181 1181 }
1182 1182 } else {
1183   - throw new IllegalArgumentException("部门名称为空");
  1183 + throw new DefaultClientException("部门名称为空");
1184 1184 }
1185 1185 } else {
1186   - throw new IllegalArgumentException("人员不存在");
  1186 + throw new DefaultClientException("人员不存在");
1187 1187 }
1188 1188 return null;
1189 1189 }
... ... @@ -1210,10 +1210,10 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
1210 1210
1211 1211 return generateNextAvailableNumber(prefixPinyin, existingNumbers);
1212 1212 } else {
1213   - throw new IllegalArgumentException("部门名称为空");
  1213 + throw new DefaultClientException("部门名称为空");
1214 1214 }
1215 1215 } else {
1216   - throw new IllegalArgumentException("人员不存在");
  1216 + throw new DefaultClientException("人员不存在");
1217 1217 }
1218 1218 }
1219 1219
... ... @@ -1354,7 +1354,7 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
1354 1354 // 2. 从 classpath 加载模板
1355 1355 try (InputStream templateIs = getClass().getClassLoader().getResourceAsStream(templatePathInClasspath)) {
1356 1356 if (templateIs == null) {
1357   - throw new FileNotFoundException("模板文件未找到,请检查路径: " + templatePathInClasspath);
  1357 + throw new DefaultClientException("模板文件未找到,请检查路径: " + templatePathInClasspath);
1358 1358 }
1359 1359
1360 1360 // 3. 创建输出文件流
... ... @@ -1436,7 +1436,7 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
1436 1436 public static String generateNextAvailableNumber(String prefix, Set<String> existingNumbers) {
1437 1437 // 参数校验
1438 1438 if (prefix == null || prefix.isEmpty()) {
1439   - throw new IllegalArgumentException("办事处前缀不能为空");
  1439 + throw new DefaultClientException("办事处前缀不能为空");
1440 1440 }
1441 1441 if (existingNumbers == null) {
1442 1442 existingNumbers = new HashSet<>();
... ... @@ -1468,7 +1468,7 @@ public class CustomerCreditServiceImpl extends BaseMpServiceImpl<CustomerCreditM
1468 1468 .boxed()
1469 1469 .findFirst()
1470 1470 .map(n -> String.format("%s%03d", prefix.toUpperCase(), n))
1471   - .orElseThrow(() -> new RuntimeException("办事处 " + prefix + " 的编号已用尽 (001-999)"));
  1471 + .orElseThrow(() -> new DefaultClientException("办事处 " + prefix + " 的编号已用尽 (001-999)"));
1472 1472 }
1473 1473
1474 1474 @CacheEvict(value = CustomerCredit.CACHE_NAME, key = "@cacheVariables.tenantId() + #key")
... ...
... ... @@ -58,6 +58,19 @@ public class QueryCustomerCreditVo extends PageVo implements BaseVo, Serializabl
58 58 private String serialNumber;
59 59
60 60 /**
  61 + * 单位id
  62 + */
  63 + @ApiModelProperty("单位id")
  64 + private String companyId;
  65 +
  66 + /**
  67 + * 审核状态为取消
  68 + */
  69 + @ApiModelProperty("审核状态为取消")
  70 + private String statusCancel;
  71 +
  72 +
  73 + /**
61 74 * 导出类型
62 75 */
63 76 @ApiModelProperty("导出类型")
... ...
... ... @@ -168,6 +168,12 @@
168 168 <if test="vo.serialNumber != null and vo.serialNumber != ''">
169 169 AND tb.serial_number = #{vo.serialNumber}
170 170 </if>
  171 + <if test="vo.companyId != null and vo.companyId != ''">
  172 + AND tb.company_id = #{vo.companyId}
  173 + </if>
  174 + <if test="vo.statusCancel != null and vo.statusCancel != ''">
  175 + AND tb.status != #{vo.statusCancel}
  176 + </if>
171 177 </where>
172 178 </select>
173 179
... ...