Showing
1 changed file
with
30 additions
and
14 deletions
| @@ -8,7 +8,9 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; | @@ -8,7 +8,9 @@ import com.lframework.starter.common.exceptions.impl.DefaultClientException; | ||
| 8 | import com.lframework.starter.web.core.components.excel.ExcelImportListener; | 8 | import com.lframework.starter.web.core.components.excel.ExcelImportListener; |
| 9 | import com.lframework.starter.web.core.utils.ApplicationUtil; | 9 | import com.lframework.starter.web.core.utils.ApplicationUtil; |
| 10 | import com.lframework.starter.web.core.utils.JsonUtil; | 10 | import com.lframework.starter.web.core.utils.JsonUtil; |
| 11 | +import com.lframework.starter.web.inner.entity.SysDataDicItem; | ||
| 11 | import com.lframework.starter.web.inner.entity.SysDept; | 12 | import com.lframework.starter.web.inner.entity.SysDept; |
| 13 | +import com.lframework.starter.web.inner.service.system.SysDataDicItemService; | ||
| 12 | import com.lframework.starter.web.inner.service.system.SysDeptService; | 14 | import com.lframework.starter.web.inner.service.system.SysDeptService; |
| 13 | import com.lframework.xingyun.basedata.entity.Customer; | 15 | import com.lframework.xingyun.basedata.entity.Customer; |
| 14 | import com.lframework.xingyun.basedata.entity.CustomerShort; | 16 | import com.lframework.xingyun.basedata.entity.CustomerShort; |
| @@ -16,6 +18,7 @@ import com.lframework.xingyun.basedata.service.customer.CustomerService; | @@ -16,6 +18,7 @@ import com.lframework.xingyun.basedata.service.customer.CustomerService; | ||
| 16 | import com.lframework.xingyun.basedata.service.customer.CustomerShortService; | 18 | import com.lframework.xingyun.basedata.service.customer.CustomerShortService; |
| 17 | import lombok.extern.slf4j.Slf4j; | 19 | import lombok.extern.slf4j.Slf4j; |
| 18 | import org.apache.commons.collections4.CollectionUtils; | 20 | import org.apache.commons.collections4.CollectionUtils; |
| 21 | +import org.apache.commons.lang3.StringUtils; | ||
| 19 | 22 | ||
| 20 | import java.util.List; | 23 | import java.util.List; |
| 21 | import java.util.stream.Collectors; | 24 | import java.util.stream.Collectors; |
| @@ -31,7 +34,7 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | @@ -31,7 +34,7 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | ||
| 31 | .eq(Customer::getName, data.getCustomerName()); | 34 | .eq(Customer::getName, data.getCustomerName()); |
| 32 | Customer customer = customerService.getOne(customerWrapper); | 35 | Customer customer = customerService.getOne(customerWrapper); |
| 33 | if (customer == null) { | 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 | data.setCustomerId(customer.getId()); | 40 | data.setCustomerId(customer.getId()); |
| @@ -39,26 +42,39 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | @@ -39,26 +42,39 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | ||
| 39 | CustomerShortService customerShortService = ApplicationUtil.getBean(CustomerShortService.class); | 42 | CustomerShortService customerShortService = ApplicationUtil.getBean(CustomerShortService.class); |
| 40 | CustomerShort customerShort = customerShortService.getByCustomerId(customer.getId()); | 43 | CustomerShort customerShort = customerShortService.getByCustomerId(customer.getId()); |
| 41 | if (customerShort != null) { | 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 | SysDeptService sysDeptService = ApplicationUtil.getBean(SysDeptService.class); | 72 | SysDeptService sysDeptService = ApplicationUtil.getBean(SysDeptService.class); |
| 57 | LambdaQueryWrapper<SysDept> deptWrapper = Wrappers.lambdaQuery(SysDept.class); | 73 | LambdaQueryWrapper<SysDept> deptWrapper = Wrappers.lambdaQuery(SysDept.class); |
| 58 | deptWrapper.eq(SysDept::getName, data.getDeptName()); | 74 | deptWrapper.eq(SysDept::getName, data.getDeptName()); |
| 59 | SysDept office = sysDeptService.getOne(deptWrapper); | 75 | SysDept office = sysDeptService.getOne(deptWrapper); |
| 60 | if (office == null) { | 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 | data.setDeptId(office.getId()); | 80 | data.setDeptId(office.getId()); |
| @@ -67,17 +83,17 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | @@ -67,17 +83,17 @@ public class CustomerShortImportListener extends ExcelImportListener<CustomerSho | ||
| 67 | deptWrapper.eq(SysDept::getName, data.getRegionName()); | 83 | deptWrapper.eq(SysDept::getName, data.getRegionName()); |
| 68 | SysDept region = sysDeptService.getOne(deptWrapper); | 84 | SysDept region = sysDeptService.getOne(deptWrapper); |
| 69 | if (region == null) { | 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 | List<SysDept> regionList = sysDeptService.queryArea(null, office.getId()); | 89 | List<SysDept> regionList = sysDeptService.queryArea(null, office.getId()); |
| 74 | if (CollectionUtils.isEmpty(regionList)) { | 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 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); | 92 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); |
| 77 | } | 93 | } |
| 78 | List<String> regionNameList = regionList.stream().map(SysDept::getName).collect(Collectors.toList()); | 94 | List<String> regionNameList = regionList.stream().map(SysDept::getName).collect(Collectors.toList()); |
| 79 | if (!regionNameList.contains(region.getName())) { | 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 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); | 97 | + "]不属于[" + data.getDeptName() + "],请检查后再次导入!"); |
| 82 | } | 98 | } |
| 83 | data.setRegion(region.getId()); | 99 | data.setRegion(region.getId()); |