Showing
1 changed file
with
30 additions
and
14 deletions
| ... | ... | @@ -8,7 +8,9 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; |
| 8 | 8 | import com.lframework.starter.web.core.components.excel.ExcelImportListener; |
| 9 | 9 | import com.lframework.starter.web.core.utils.ApplicationUtil; |
| 10 | 10 | import com.lframework.starter.web.core.utils.JsonUtil; |
| 11 | +import com.lframework.starter.web.inner.entity.SysDataDicItem; | |
| 11 | 12 | import com.lframework.starter.web.inner.entity.SysDept; |
| 13 | +import com.lframework.starter.web.inner.service.system.SysDataDicItemService; | |
| 12 | 14 | import com.lframework.starter.web.inner.service.system.SysDeptService; |
| 13 | 15 | import com.lframework.xingyun.basedata.entity.Customer; |
| 14 | 16 | import com.lframework.xingyun.basedata.entity.CustomerShort; |
| ... | ... | @@ -16,6 +18,7 @@ import com.lframework.xingyun.basedata.service.customer.CustomerService; |
| 16 | 18 | import com.lframework.xingyun.basedata.service.customer.CustomerShortService; |
| 17 | 19 | import lombok.extern.slf4j.Slf4j; |
| 18 | 20 | import org.apache.commons.collections4.CollectionUtils; |
| 21 | +import org.apache.commons.lang3.StringUtils; | |
| 19 | 22 | |
| 20 | 23 | import java.util.List; |
| 21 | 24 | import java.util.stream.Collectors; |
| ... | ... | @@ -31,7 +34,7 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho |
| 31 | 34 | .eq(Customer::getName, data.getCustomerName()); |
| 32 | 35 | Customer customer = customerService.getOne(customerWrapper); |
| 33 | 36 | if (customer == null) { |
| 34 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,客户[" + data.getCustomerName() | |
| 37 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,客户[" + data.getCustomerName() | |
| 35 | 38 | + "]不存在,请检查后再次导入!"); |
| 36 | 39 | } |
| 37 | 40 | data.setCustomerId(customer.getId()); |
| ... | ... | @@ -39,26 +42,39 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho |
| 39 | 42 | CustomerShortService customerShortService = ApplicationUtil.getBean(CustomerShortService.class); |
| 40 | 43 | CustomerShort customerShort = customerShortService.getByCustomerId(customer.getId()); |
| 41 | 44 | if (customerShort != null) { |
| 42 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,客户[" + data.getCustomerName() | |
| 45 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,客户[" + data.getCustomerName() | |
| 43 | 46 | + "]简称已存在,请检查后再次导入!"); |
| 44 | 47 | } |
| 45 | 48 | // 客户类型 |
| 46 | - String type = data.getType(); | |
| 47 | - if ("终端".equals(type)) { | |
| 48 | - type = "TERMINAL"; | |
| 49 | - } else if ("经销".equals(type)) { | |
| 50 | - type = "DEALER"; | |
| 51 | - } else { | |
| 52 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,客户类型只能填写“终端”或“经销”,请检查后再次导入!"); | |
| 49 | + String customerType = ""; | |
| 50 | + SysDataDicItemService sysDataDicItemService = ApplicationUtil.getBean(SysDataDicItemService.class); | |
| 51 | + List<SysDataDicItem> enterpriseTypes = sysDataDicItemService.findByDicCode("ENTERPRISE_TYPE"); | |
| 52 | + StringBuilder enterpriseTypesBuilder = new StringBuilder(); | |
| 53 | + for (SysDataDicItem dicItem : enterpriseTypes) { | |
| 54 | + String name = dicItem.getName(); | |
| 55 | + enterpriseTypesBuilder.append("“").append(name).append("”"); | |
| 56 | + enterpriseTypesBuilder.append("或"); | |
| 57 | + | |
| 58 | + String type = data.getType(); | |
| 59 | + if (name.equals(type)) { | |
| 60 | + customerType = dicItem.getCode(); | |
| 61 | + } | |
| 62 | + } | |
| 63 | + if (enterpriseTypesBuilder.length() > 0) { | |
| 64 | + enterpriseTypesBuilder.deleteCharAt(enterpriseTypesBuilder.length() - 1); | |
| 65 | + } | |
| 66 | + if (StringUtils.isBlank(customerType)) { | |
| 67 | + throw new DefaultClientException("第" + ((context.readRowHolder().getRowIndex() + 1)) + "行,客户类型只能填写" + enterpriseTypesBuilder | |
| 68 | + + ",请检查后再次导入!"); | |
| 53 | 69 | } |
| 54 | - data.setType(type); | |
| 70 | + data.setType(customerType); | |
| 55 | 71 | // 办事处 |
| 56 | 72 | SysDeptService sysDeptService = ApplicationUtil.getBean(SysDeptService.class); |
| 57 | 73 | LambdaQueryWrapper<SysDept> deptWrapper = Wrappers.lambdaQuery(SysDept.class); |
| 58 | 74 | deptWrapper.eq(SysDept::getName, data.getDeptName()); |
| 59 | 75 | SysDept office = sysDeptService.getOne(deptWrapper); |
| 60 | 76 | if (office == null) { |
| 61 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,[" + data.getDeptName() | |
| 77 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,[" + data.getDeptName() | |
| 62 | 78 | + "]不存在,请检查后再次导入!"); |
| 63 | 79 | } |
| 64 | 80 | data.setDeptId(office.getId()); |
| ... | ... | @@ -67,17 +83,17 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho |
| 67 | 83 | deptWrapper.eq(SysDept::getName, data.getRegionName()); |
| 68 | 84 | SysDept region = sysDeptService.getOne(deptWrapper); |
| 69 | 85 | if (region == null) { |
| 70 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,[" + data.getRegionName() | |
| 86 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,[" + data.getRegionName() | |
| 71 | 87 | + "]不存在,请检查后再次导入!"); |
| 72 | 88 | } |
| 73 | 89 | List<SysDept> regionList = sysDeptService.queryArea(null, office.getId()); |
| 74 | 90 | if (CollectionUtils.isEmpty(regionList)) { |
| 75 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,[" + data.getRegionName() | |
| 91 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,[" + data.getRegionName() | |
| 76 | 92 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); |
| 77 | 93 | } |
| 78 | 94 | List<String> regionNameList = regionList.stream().map(SysDept::getName).collect(Collectors.toList()); |
| 79 | 95 | if (!regionNameList.contains(region.getName())) { |
| 80 | - throw new DefaultClientException("第" + context.readRowHolder().getRowIndex() + "行,[" + data.getRegionName() | |
| 96 | + throw new DefaultClientException("第" + (context.readRowHolder().getRowIndex() + 1) + "行,[" + data.getRegionName() | |
| 81 | 97 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); |
| 82 | 98 | } |
| 83 | 99 | data.setRegion(region.getId()); | ... | ... |