Commit d9b6f3cbc7a34d37183047af2f26b45b7601d62b

Authored by 房远帅
1 parent 313b397a

合同:外贸、加工合同目的地历史数据处理

... ... @@ -738,6 +738,74 @@ public class ContractDistributorStandardController extends DefaultBaseController
738 738 return InvokeResultBuilder.success();
739 739 }
740 740
  741 + @ApiOperation("历史数据目的地迁移")
  742 + @PostMapping("/migrateForeignDestination")
  743 + public InvokeResult<Integer> migrateForeignDestination() {
  744 + List<String> contractTypes = Arrays.asList(
  745 + "INTL_STD_CONTRACT",
  746 + "INTL_INVENTORY_AGMT",
  747 + "INTL_OPEN_SPEC_AGMT",
  748 + "PROCESS_STD_AGMT"
  749 + );
  750 + Wrapper<ContractDistributorStandard> wrapper = Wrappers.lambdaQuery(ContractDistributorStandard.class)
  751 + .in(ContractDistributorStandard::getType, contractTypes)
  752 + .and(w -> w.isNull(ContractDistributorStandard::getForeignDestination)
  753 + .or()
  754 + .eq(ContractDistributorStandard::getForeignDestination, ""))
  755 + .isNotNull(ContractDistributorStandard::getDestination)
  756 + .ne(ContractDistributorStandard::getDestination, "");
  757 + List<ContractDistributorStandard> contractList = contractDistributorStandardService.list(wrapper);
  758 + if (CollectionUtils.isEmpty(contractList)) {
  759 + return InvokeResultBuilder.success(0);
  760 + }
  761 +
  762 + List<DicCityDto> allCity = dicCityService.getAll();
  763 + int updated = 0;
  764 + for (ContractDistributorStandard contract : contractList) {
  765 + if (contract == null || StringUtils.isBlank(contract.getId())) {
  766 + continue;
  767 + }
  768 + String destination = contract.getDestination();
  769 + if (StringUtils.isBlank(destination)) {
  770 + continue;
  771 + }
  772 + String foreignDestination = buildDestinationText(destination, allCity);
  773 + if (StringUtils.isBlank(foreignDestination)) {
  774 + continue;
  775 + }
  776 + Wrapper<ContractDistributorStandard> updateWrapper = Wrappers.lambdaUpdate(ContractDistributorStandard.class)
  777 + .set(ContractDistributorStandard::getForeignDestination, foreignDestination)
  778 + .eq(ContractDistributorStandard::getId, contract.getId());
  779 + if (contractDistributorStandardService.update(updateWrapper)) {
  780 + updated++;
  781 + contractDistributorStandardService.cleanCacheByKey(contract.getId());
  782 + }
  783 + }
  784 +
  785 + return InvokeResultBuilder.success(updated);
  786 + }
  787 +
  788 + private String buildDestinationText(String destination, List<DicCityDto> allCity) {
  789 + if (StringUtils.isBlank(destination) || CollectionUtils.isEmpty(allCity)) {
  790 + return "";
  791 + }
  792 + List<DicCityDto> fullPath = dicCityService.getFullPath(destination, allCity);
  793 + if (CollectionUtils.isEmpty(fullPath)) {
  794 + return "";
  795 + }
  796 + StringBuilder destinationBuilder = new StringBuilder();
  797 + for (DicCityDto cityDto : fullPath) {
  798 + if (cityDto == null || StringUtils.isBlank(cityDto.getName())) {
  799 + continue;
  800 + }
  801 + destinationBuilder.append(cityDto.getName()).append(",");
  802 + }
  803 + if (destinationBuilder.length() > 0) {
  804 + destinationBuilder.setLength(destinationBuilder.length() - 1);
  805 + }
  806 + return destinationBuilder.toString();
  807 + }
  808 +
741 809 /**
742 810 * 标准合同模版打印
743 811 */
... ...