Commit f5690c4a2468b7cc0de4617ca30b31a2c68cdc09
Merge remote-tracking branch 'origin/master_0929' into master_0929
Showing
3 changed files
with
224 additions
and
5 deletions
xingyun-sc/src/main/java/com/lframework/xingyun/sc/controller/customer/CustomerCreditController.java
| ... | ... | @@ -3,6 +3,7 @@ package com.lframework.xingyun.sc.controller.customer; |
| 3 | 3 | import com.lframework.starter.common.utils.StringUtil; |
| 4 | 4 | import com.lframework.starter.web.core.annotations.security.HasPermission; |
| 5 | 5 | import com.lframework.starter.web.core.controller.DefaultBaseController; |
| 6 | +import com.lframework.starter.web.core.utils.ExcelUtil; | |
| 6 | 7 | import com.lframework.starter.web.inner.bo.system.user.QuerySysUserBo; |
| 7 | 8 | import com.lframework.starter.web.inner.entity.SysUser; |
| 8 | 9 | import com.lframework.starter.web.inner.service.system.SysUserService; |
| ... | ... | @@ -15,6 +16,8 @@ import com.lframework.starter.web.core.components.resp.PageResult; |
| 15 | 16 | import com.lframework.starter.web.core.components.resp.InvokeResult; |
| 16 | 17 | import javax.annotation.Resource; |
| 17 | 18 | import javax.validation.constraints.NotBlank; |
| 19 | +import com.lframework.xingyun.sc.excel.customerCredit.CustomerCreditImportListener; | |
| 20 | +import com.lframework.xingyun.sc.excel.customerCredit.CustomerCreditImportModel; | |
| 18 | 21 | import com.lframework.xingyun.sc.service.customer.CorePersonnelService; |
| 19 | 22 | import com.lframework.xingyun.sc.service.customer.CustomerCreditService; |
| 20 | 23 | import com.lframework.xingyun.sc.vo.customer.credit.CreateCustomerCreditVo; |
| ... | ... | @@ -30,8 +33,10 @@ import io.swagger.annotations.Api; |
| 30 | 33 | import org.springframework.beans.factory.annotation.Autowired; |
| 31 | 34 | import org.springframework.validation.annotation.Validated; |
| 32 | 35 | import org.springframework.web.bind.annotation.*; |
| 36 | +import org.springframework.web.multipart.MultipartFile; | |
| 33 | 37 | |
| 34 | 38 | import javax.validation.Valid; |
| 39 | +import javax.validation.constraints.NotNull; | |
| 35 | 40 | import java.util.List; |
| 36 | 41 | import java.util.stream.Collectors; |
| 37 | 42 | |
| ... | ... | @@ -58,7 +63,7 @@ public class CustomerCreditController extends DefaultBaseController { |
| 58 | 63 | * 查询列表 |
| 59 | 64 | */ |
| 60 | 65 | @ApiOperation("查询列表") |
| 61 | - @HasPermission({"customerCredit:customercredit:query"}) | |
| 66 | + @HasPermission({"customer-credit-manage:customer-credit-plan:query"}) | |
| 62 | 67 | @GetMapping("/query") |
| 63 | 68 | public InvokeResult<PageResult<GetCustomerCreditBo>> query(@Valid QueryCustomerCreditVo vo) { |
| 64 | 69 | |
| ... | ... | @@ -79,7 +84,7 @@ public class CustomerCreditController extends DefaultBaseController { |
| 79 | 84 | */ |
| 80 | 85 | @ApiOperation("根据ID查询") |
| 81 | 86 | @ApiImplicitParam(value = "id", name = "id", paramType = "query", required = true) |
| 82 | - @HasPermission({"customerCredit:customercredit:query"}) | |
| 87 | + @HasPermission({"customer-credit-manage:customer-credit-plan:query"}) | |
| 83 | 88 | @GetMapping("/getById") |
| 84 | 89 | public InvokeResult<GetCustomerCreditBo> get(@NotBlank(message = "id不能为空!") String id) { |
| 85 | 90 | |
| ... | ... | @@ -97,7 +102,7 @@ public class CustomerCreditController extends DefaultBaseController { |
| 97 | 102 | * 新增 |
| 98 | 103 | */ |
| 99 | 104 | @ApiOperation("新增") |
| 100 | - @HasPermission({"customerCredit:customercredit:add"}) | |
| 105 | + @HasPermission({"customer-credit-manage:customer-credit-plan:add"}) | |
| 101 | 106 | @PostMapping("/add") |
| 102 | 107 | public InvokeResult<Void> create(@Valid @RequestBody CreateCustomerCreditVo vo) { |
| 103 | 108 | QueryCustomerCreditVo vo1 = new QueryCustomerCreditVo(); |
| ... | ... | @@ -115,7 +120,7 @@ public class CustomerCreditController extends DefaultBaseController { |
| 115 | 120 | * 修改 |
| 116 | 121 | */ |
| 117 | 122 | @ApiOperation("修改") |
| 118 | - @HasPermission({"customerCredit:customercredit:modify"}) | |
| 123 | + @HasPermission({"customer-credit-manage:customer-credit-plan:modify"}) | |
| 119 | 124 | @PutMapping("/update") |
| 120 | 125 | public InvokeResult<Void> update(@Valid @RequestBody UpdateCustomerCreditVo vo) { |
| 121 | 126 | |
| ... | ... | @@ -131,7 +136,7 @@ public class CustomerCreditController extends DefaultBaseController { |
| 131 | 136 | */ |
| 132 | 137 | @ApiOperation("根据ID删除") |
| 133 | 138 | @ApiImplicitParam(value = "id", name = "id", paramType = "query", required = true) |
| 134 | - @HasPermission({"customerCredit:customercredit:delete"}) | |
| 139 | + @HasPermission({"customer-credit-manage:customer-credit-plan:delete"}) | |
| 135 | 140 | @DeleteMapping("/deleteById") |
| 136 | 141 | public InvokeResult<Void> deleteById(@NotBlank(message = "id不能为空!") String id) { |
| 137 | 142 | |
| ... | ... | @@ -183,6 +188,26 @@ public class CustomerCreditController extends DefaultBaseController { |
| 183 | 188 | return InvokeResultBuilder.success(results); |
| 184 | 189 | } |
| 185 | 190 | |
| 191 | + @ApiOperation("下载导入模板") | |
| 192 | + @HasPermission({"customer-credit-manage:customer-credit-plan:import"}) | |
| 193 | + @GetMapping("/import/template") | |
| 194 | + public void downloadImportTemplate() { | |
| 195 | + ExcelUtil.exportXls("客户资信导入模板", CustomerCreditImportModel.class); | |
| 196 | + } | |
| 197 | + | |
| 198 | + @ApiOperation("导入") | |
| 199 | + @HasPermission({"customer-credit-manage:customer-credit-plan:import"}) | |
| 200 | + @PostMapping("/import") | |
| 201 | + public InvokeResult<Void> importExcel(@NotBlank(message = "ID不能为空") String id, | |
| 202 | + @NotNull(message = "请上传文件") MultipartFile file) { | |
| 203 | + | |
| 204 | + CustomerCreditImportListener listener = new CustomerCreditImportListener(); | |
| 205 | + listener.setTaskId(id); | |
| 206 | + ExcelUtil.read(file, CustomerCreditImportModel.class, listener).sheet().doRead(); | |
| 207 | + | |
| 208 | + return InvokeResultBuilder.success(); | |
| 209 | + } | |
| 210 | + | |
| 186 | 211 | |
| 187 | 212 | /** |
| 188 | 213 | * 封装客户资信数据 | ... | ... |
| 1 | +package com.lframework.xingyun.sc.excel.customerCredit; | |
| 2 | + | |
| 3 | +import com.alibaba.excel.context.AnalysisContext; | |
| 4 | +import com.lframework.starter.common.exceptions.impl.DefaultClientException; | |
| 5 | +import com.lframework.starter.common.utils.StringUtil; | |
| 6 | +import com.lframework.starter.web.core.components.excel.ExcelImportListener; | |
| 7 | +import com.lframework.starter.web.core.utils.ApplicationUtil; | |
| 8 | +import com.lframework.xingyun.sc.entity.CorePersonnel; | |
| 9 | +import com.lframework.xingyun.sc.entity.CustomerCredit; | |
| 10 | +import com.lframework.xingyun.sc.service.customer.CorePersonnelService; | |
| 11 | +import com.lframework.xingyun.sc.service.customer.CustomerCreditService; | |
| 12 | +import com.lframework.xingyun.sc.vo.customer.credit.QueryCorePersonnelVo; | |
| 13 | +import com.lframework.xingyun.sc.vo.customer.credit.QueryCustomerCreditVo; | |
| 14 | +import com.lframework.xingyun.sc.vo.customer.credit.UpdateCorePersonnelVo; | |
| 15 | +import com.lframework.xingyun.sc.vo.customer.credit.UpdateCustomerCreditVo; | |
| 16 | +import lombok.extern.slf4j.Slf4j; | |
| 17 | +import org.springframework.beans.BeanUtils; | |
| 18 | +import org.apache.commons.collections.CollectionUtils; | |
| 19 | + | |
| 20 | +import java.util.ArrayList; | |
| 21 | +import java.util.Arrays; | |
| 22 | +import java.util.List; | |
| 23 | + | |
| 24 | +@Slf4j | |
| 25 | +public class CustomerCreditImportListener extends ExcelImportListener<CustomerCreditImportModel> { | |
| 26 | + | |
| 27 | + | |
| 28 | + private List<String> checkList = new ArrayList<>(); | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + protected void doInvoke(CustomerCreditImportModel data, AnalysisContext context) { | |
| 32 | + List<String> validValues = Arrays.asList("AAA", "AA", "A", "BBB", "BB", "B", "C", "D"); | |
| 33 | + if (StringUtil.isBlank(data.getCode())) { | |
| 34 | + throw new DefaultClientException( | |
| 35 | + "第" + context.readRowHolder().getRowIndex() + "行“编号”不能为空"); | |
| 36 | + } | |
| 37 | + if (checkList.contains(data.getCode())) { | |
| 38 | + throw new DefaultClientException( | |
| 39 | + "第" + context.readRowHolder().getRowIndex() + "行“编号”与第" + (checkList.indexOf(data.getCode()) + 1) + "行重复"); | |
| 40 | + } | |
| 41 | + checkList.add(data.getCode()); | |
| 42 | + QueryCustomerCreditVo vo = new QueryCustomerCreditVo(); | |
| 43 | + vo.setSerialNumber(data.getCode()); | |
| 44 | + CustomerCreditService customerCreditService = ApplicationUtil.getBean(CustomerCreditService.class); | |
| 45 | + List<CustomerCredit> query = customerCreditService.query(vo); | |
| 46 | + if (CollectionUtils.isEmpty(query)) { | |
| 47 | + throw new DefaultClientException( | |
| 48 | + "第" + context.readRowHolder().getRowIndex() + "行“编号”不存在"); | |
| 49 | + } | |
| 50 | + | |
| 51 | + if (StringUtil.isNotEmpty(data.getCompanySuggestedCategory()) && !validValues.contains(data.getCompanySuggestedCategory())) { | |
| 52 | + throw new DefaultClientException( | |
| 53 | + "第" + context.readRowHolder().getRowIndex() + "行“客户分类”只能为:AAA、AA、A、BBB、BB、B、C、D"); | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + protected void afterAllAnalysed(AnalysisContext context) { | |
| 59 | + CorePersonnelService corePersonnelService = ApplicationUtil.getBean(CorePersonnelService.class); | |
| 60 | + CustomerCreditService customerCreditService = ApplicationUtil.getBean(CustomerCreditService.class); | |
| 61 | + List<CustomerCreditImportModel> datas = this.getDatas(); | |
| 62 | + for (int i = 0; i < datas.size(); i++) { | |
| 63 | + CustomerCreditImportModel data = datas.get(i); | |
| 64 | + QueryCustomerCreditVo vo = new QueryCustomerCreditVo(); | |
| 65 | + vo.setSerialNumber(data.getCode()); | |
| 66 | + List<CustomerCredit> query = customerCreditService.query(vo); | |
| 67 | + if (CollectionUtils.isNotEmpty(query)) { | |
| 68 | + CustomerCredit customerCredit = query.get(0); | |
| 69 | + | |
| 70 | + UpdateCustomerCreditVo updateCustomerCreditVo = new UpdateCustomerCreditVo(); | |
| 71 | +// updateCustomerCreditVo.setId(customerCredit.getId()); | |
| 72 | + | |
| 73 | + BeanUtils.copyProperties(customerCredit, updateCustomerCreditVo); | |
| 74 | + //客户分类 | |
| 75 | + if (StringUtil.isNotEmpty(data.getCompanySuggestedCategory())) { | |
| 76 | + updateCustomerCreditVo.setCompanySuggestedCategory(data.getCompanySuggestedCategory()); | |
| 77 | + } | |
| 78 | + //授信额度 | |
| 79 | + if (StringUtil.isNotEmpty(data.getCompanyCreditLimit())) { | |
| 80 | + updateCustomerCreditVo.setCompanyCreditLimit(data.getCompanyCreditLimit()); | |
| 81 | + } | |
| 82 | + //加工操作方案 | |
| 83 | + if (StringUtil.isNotEmpty(data.getCompanyMaterialSupplyPlan())) { | |
| 84 | + updateCustomerCreditVo.setCompanyMaterialSupplyPlan(data.getCompanyMaterialSupplyPlan()); | |
| 85 | + } | |
| 86 | + //结算期限 | |
| 87 | + if (StringUtil.isNotEmpty(data.getCompanySettlementPeriod())) { | |
| 88 | + updateCustomerCreditVo.setCompanySettlementPeriod(data.getCompanySettlementPeriod()); | |
| 89 | + } | |
| 90 | + //核心人员(不填更新的时候会被删除) | |
| 91 | + QueryCorePersonnelVo queryCorePersonnelVo = new QueryCorePersonnelVo(); | |
| 92 | + queryCorePersonnelVo.setCreditId(customerCredit.getId()); | |
| 93 | + List<CorePersonnel> corePersonnelList = corePersonnelService.query(queryCorePersonnelVo); | |
| 94 | + if (CollectionUtils.isNotEmpty(corePersonnelList)) { | |
| 95 | + List<UpdateCorePersonnelVo> results = new ArrayList<>(); | |
| 96 | + for (CorePersonnel corePersonnel : corePersonnelList) { | |
| 97 | + UpdateCorePersonnelVo personnelVo = new UpdateCorePersonnelVo(); | |
| 98 | + personnelVo.setId(corePersonnel.getId()); | |
| 99 | + personnelVo.setCreditId(corePersonnel.getCreditId()); | |
| 100 | + if (!StringUtil.isBlank(corePersonnel.getPersonId())) { | |
| 101 | + personnelVo.setPersonId(corePersonnel.getPersonId()); | |
| 102 | + } | |
| 103 | + if (!StringUtil.isBlank(corePersonnel.getName())) { | |
| 104 | + personnelVo.setName(corePersonnel.getName()); | |
| 105 | + } | |
| 106 | + if (!StringUtil.isBlank(corePersonnel.getSex())) { | |
| 107 | + personnelVo.setSex(corePersonnel.getSex()); | |
| 108 | + } | |
| 109 | + if (!StringUtil.isBlank(corePersonnel.getNativePlace())) { | |
| 110 | + personnelVo.setNativePlace(corePersonnel.getNativePlace()); | |
| 111 | + } | |
| 112 | + if (!StringUtil.isBlank(corePersonnel.getAge())) { | |
| 113 | + personnelVo.setAge(corePersonnel.getAge()); | |
| 114 | + } | |
| 115 | + if (!StringUtil.isBlank(corePersonnel.getPosition())) { | |
| 116 | + personnelVo.setPosition(corePersonnel.getPosition()); | |
| 117 | + } | |
| 118 | + if (!StringUtil.isBlank(corePersonnel.getMobile())) { | |
| 119 | + personnelVo.setMobile(corePersonnel.getMobile()); | |
| 120 | + } | |
| 121 | + if (!StringUtil.isBlank(corePersonnel.getPhone())) { | |
| 122 | + personnelVo.setPhone(corePersonnel.getPhone()); | |
| 123 | + } | |
| 124 | + if (!StringUtil.isBlank(corePersonnel.getEmail())) { | |
| 125 | + personnelVo.setEmail(corePersonnel.getEmail()); | |
| 126 | + } | |
| 127 | + if (!StringUtil.isBlank(corePersonnel.getAddress())) { | |
| 128 | + personnelVo.setAddress(corePersonnel.getAddress()); | |
| 129 | + } | |
| 130 | + results.add(personnelVo); | |
| 131 | + } | |
| 132 | + updateCustomerCreditVo.setCorePersonnelList(results); | |
| 133 | + } | |
| 134 | + customerCreditService.update(updateCustomerCreditVo); | |
| 135 | + customerCreditService.cleanCacheByKey(customerCredit.getId()); | |
| 136 | + | |
| 137 | + this.setSuccessProcess(i); | |
| 138 | + } | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + @Override | |
| 143 | + protected void doComplete() { | |
| 144 | + } | |
| 145 | +} | ... | ... |
| 1 | +package com.lframework.xingyun.sc.excel.customerCredit; | |
| 2 | + | |
| 3 | +import com.alibaba.excel.annotation.ExcelIgnore; | |
| 4 | +import com.alibaba.excel.annotation.ExcelProperty; | |
| 5 | +import com.lframework.starter.web.core.annotations.excel.ExcelRequired; | |
| 6 | +import com.lframework.starter.web.core.components.excel.ExcelModel; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +@Data | |
| 10 | +public class CustomerCreditImportModel implements ExcelModel { | |
| 11 | + | |
| 12 | + /** | |
| 13 | + * ID | |
| 14 | + */ | |
| 15 | + @ExcelIgnore | |
| 16 | + private String id; | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 编号 | |
| 20 | + */ | |
| 21 | + @ExcelRequired | |
| 22 | + @ExcelProperty("编号") | |
| 23 | + private String code; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 客户分类 | |
| 27 | + */ | |
| 28 | + @ExcelProperty("客户分类") | |
| 29 | + private String companySuggestedCategory; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 授信额度 | |
| 33 | + */ | |
| 34 | + @ExcelProperty("授信额度") | |
| 35 | + private String companyCreditLimit; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * 加工操作方案 | |
| 39 | + */ | |
| 40 | + @ExcelProperty("加工操作方案") | |
| 41 | + private String companyMaterialSupplyPlan; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * 结算期限 | |
| 45 | + */ | |
| 46 | + @ExcelProperty("结算期限") | |
| 47 | + private String companySettlementPeriod; | |
| 48 | + | |
| 49 | +} | ... | ... |