Commit 5e12e993f2ec128e144eabc71c5964f320856e40

Authored by 房远帅
1 parent 7b044e95

合同编码:按办事处生成每个都从办事处编码+日期+00001开始递增;WZ260500001 ZT260500001

... ... @@ -17,7 +17,6 @@ import com.lframework.starter.web.inner.entity.SysDataDicItem;
17 17 import com.lframework.starter.web.inner.entity.SysDept;
18 18 import com.lframework.starter.web.inner.entity.SysUser;
19 19 import com.lframework.starter.web.inner.service.DicCityService;
20   -import com.lframework.starter.web.inner.service.GenerateCodeService;
21 20 import com.lframework.starter.web.inner.service.system.SysDataDicItemService;
22 21 import com.lframework.starter.web.inner.service.system.SysDeptService;
23 22 import com.lframework.starter.web.inner.service.system.SysUserService;
... ... @@ -30,7 +29,6 @@ import com.lframework.xingyun.sc.bo.contract.GetContractDistributorLineBo;
30 29 import com.lframework.xingyun.sc.bo.contract.GetContractDistributorStandardBo;
31 30 import com.lframework.xingyun.sc.bo.contract.GetContractStdProcessingLineBo;
32 31 import com.lframework.xingyun.sc.bo.contract.QueryContractDistributorStandardBo;
33   -import com.lframework.xingyun.sc.components.code.GenerateCodeTypePool;
34 32 import com.lframework.xingyun.sc.entity.*;
35 33 import com.lframework.xingyun.sc.service.contract.ContractDistributorLineService;
36 34 import com.lframework.xingyun.sc.service.contract.ContractDistributorStandardService;
... ... @@ -105,8 +103,6 @@ public class ContractDistributorStandardController extends DefaultBaseController
105 103 @Autowired
106 104 private SysDataDicItemService sysDataDicItemService;
107 105 @Autowired
108   - private GenerateCodeService generateCodeService;
109   - @Autowired
110 106 private DicCityService dicCityService;
111 107 @Autowired
112 108 private WorkshopService workshopService;
... ... @@ -474,10 +470,9 @@ public class ContractDistributorStandardController extends DefaultBaseController
474 470 }
475 471
476 472 Wrapper<ContractDistributorStandard> checkWrapper = Wrappers.lambdaQuery(ContractDistributorStandard.class)
477   - .eq(ContractDistributorStandard::getCode, vo.getCode())
478   - .eq(ContractDistributorStandard::getType, vo.getType());
  473 + .eq(ContractDistributorStandard::getCode, vo.getCode());
479 474 if (contractDistributorStandardService.count(checkWrapper) > 0) {
480   - throw new DefaultClientException("编号重复,请重新输入!");
  475 + throw new DefaultClientException("编号重复,请重新获取!");
481 476 }
482 477
483 478
... ... @@ -524,40 +519,28 @@ public class ContractDistributorStandardController extends DefaultBaseController
524 519 @ApiOperation("获取code")
525 520 @GetMapping("/code")
526 521 public InvokeResult<String> code() {
527   - StringBuilder stringBuilder = new StringBuilder();
528   - // 获取当前人员及所在部门
529 522 String currentUserId = SecurityUtil.getCurrentUser().getId();
530 523 SysUser sysUser = sysUserService.findById(currentUserId);
531   - if (sysUser != null) {
532   - GetSysUserBo getSysUserBo = new GetSysUserBo(sysUser);
533   - //部门
534   - List<String> depts = getSysUserBo.getDepts();
535   - if (CollectionUtils.isNotEmpty(depts)) {
536   - String deptId = depts.get(0);
537   - SysDept sysDept = sysDeptService.findById(deptId);
538   - if (sysDept.getCode().equals("BF") || sysDept.getCode().equals("CZ")
539   - || sysDept.getCode().equals("DG") || sysDept.getCode().equals("FS")
540   - || sysDept.getCode().equals("NB") || sysDept.getCode().equals("SZ")
541   - || sysDept.getCode().equals("WM") || sysDept.getCode().equals("WZ")
542   - || sysDept.getCode().equals("ZT")) { //获取办事处code
543   - stringBuilder.append(sysDept.getCode());
544   - } else {
545   - SysDept parentSysDept = sysDeptService.findById(sysDept.getParentId());
546   - if (parentSysDept != null && (parentSysDept.getCode().equals("BF") || parentSysDept.getCode().equals("CZ")
547   - || parentSysDept.getCode().equals("DG") || parentSysDept.getCode().equals("FS")
548   - || parentSysDept.getCode().equals("NB") || parentSysDept.getCode().equals("SZ")
549   - || parentSysDept.getCode().equals("WM") || parentSysDept.getCode().equals("WZ")
550   - || parentSysDept.getCode().equals("ZT"))) {
551   - stringBuilder.append(parentSysDept.getCode());
552   - } else {
553   - stringBuilder.append(sysDept.getCode());
554   - }
555   - }
556   - }
  524 + String officeCode = resolveOfficeCodeByUser(sysUser);
  525 + if (StringUtils.isBlank(officeCode)) {
  526 + throw new DefaultClientException("当前用不属于九大办事处,无法生成合同编号!");
557 527 }
558 528
559   - stringBuilder.append(generateCodeService.generate(GenerateCodeTypePool.CONTRACT));
560   - return InvokeResultBuilder.success(stringBuilder.toString());
  529 + String monthCode = LocalDate.now().format(DateTimeFormatter.ofPattern("yyMM"));
  530 + String prefix = officeCode + monthCode;
  531 +
  532 + Wrapper<ContractDistributorStandard> wrapper = Wrappers.lambdaQuery(ContractDistributorStandard.class)
  533 + .select(ContractDistributorStandard::getCode)
  534 + .likeRight(ContractDistributorStandard::getCode, prefix);
  535 + List<ContractDistributorStandard> contractList = contractDistributorStandardService.list(wrapper);
  536 + int nextSeq = contractList.stream()
  537 + .map(ContractDistributorStandard::getCode)
  538 + .map(code -> extractContractSequence(code, prefix))
  539 + .filter(Objects::nonNull)
  540 + .max(Integer::compareTo)
  541 + .orElse(0) + 1;
  542 +
  543 + return InvokeResultBuilder.success(prefix + String.format("%05d", nextSeq));
561 544 }
562 545
563 546 /**
... ... @@ -1475,6 +1458,19 @@ public class ContractDistributorStandardController extends DefaultBaseController
1475 1458 return landlineDicItem == null || StringUtils.isBlank(landlineDicItem.getName()) ? "" : landlineDicItem.getName();
1476 1459 }
1477 1460
  1461 + private String resolveOfficeCodeByUser(SysUser user) {
  1462 + if (user == null) {
  1463 + return "";
  1464 + }
  1465 +
  1466 + GetSysUserBo getSysUserBo = new GetSysUserBo(user);
  1467 + List<String> depts = getSysUserBo.getDepts();
  1468 + if (CollectionUtils.isEmpty(depts)) {
  1469 + return "";
  1470 + }
  1471 + return resolveOfficeCode(depts.get(0));
  1472 + }
  1473 +
1478 1474 private String resolveOfficeCode(String deptId) {
1479 1475 if (StringUtils.isBlank(deptId)) {
1480 1476 return "";
... ... @@ -1504,6 +1500,18 @@ public class ContractDistributorStandardController extends DefaultBaseController
1504 1500 return StringUtils.defaultString(officeLandline);
1505 1501 }
1506 1502
  1503 + private Integer extractContractSequence(String code, String prefix) {
  1504 + if (StringUtils.isBlank(code) || !StringUtils.startsWith(code, prefix)) {
  1505 + return null;
  1506 + }
  1507 +
  1508 + String suffix = StringUtils.substring(code, prefix.length());
  1509 + if (StringUtils.length(suffix) != 5 || !StringUtils.isNumeric(suffix)) {
  1510 + return null;
  1511 + }
  1512 + return Integer.parseInt(suffix);
  1513 + }
  1514 +
1507 1515 private File convertExcelToPdf(File excelFile) throws IOException, InterruptedException {
1508 1516 if (!excelFile.exists()) {
1509 1517 throw new IllegalArgumentException("Excel 文件不存在: " + excelFile.getAbsolutePath());
... ...