Commit bc2be8b143b2e58e190a524e10d97b9df7395891

Authored by yeqianyong
1 parent a44c716a

楚江ERP-客户开发异步导出功能开发

1 1 package com.lframework.xingyun.sc.bo.customer.develop;
2 2
3 3 import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.web.core.dto.BaseDto;
4 5 import com.lframework.xingyun.basedata.entity.*;
5 6 import com.lframework.xingyun.sc.entity.CustomerDevelopPlan;
6 7 import com.lframework.starter.common.constants.StringPool;
... ... @@ -18,7 +19,7 @@ import lombok.Data;
18 19 *
19 20 */
20 21 @Data
21   -public class GetCustomerDevelopPlanBo extends BaseBo<CustomerDevelopPlan> {
  22 +public class GetCustomerDevelopPlanBo extends BaseBo<CustomerDevelopPlan> implements BaseDto {
22 23
23 24 /**
24 25 * ID
... ...
... ... @@ -3,6 +3,7 @@ package com.lframework.xingyun.sc.controller.customer;
3 3 import com.lframework.starter.bpm.dto.FlowTaskDto;
4 4 import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
5 5 import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
  6 +import com.lframework.starter.mq.core.utils.ExportTaskUtil;
6 7 import com.lframework.starter.web.core.annotations.security.HasPermission;
7 8 import com.lframework.starter.web.core.components.security.SecurityUtil;
8 9 import com.lframework.starter.web.core.controller.DefaultBaseController;
... ... @@ -12,9 +13,9 @@ import com.lframework.xingyun.basedata.entity.*;
12 13 import com.lframework.xingyun.basedata.service.customer.CustomerService;
13 14 import com.lframework.xingyun.basedata.service.office.OfficeService;
14 15 import com.lframework.xingyun.basedata.service.product.ProductVarietyService;
15   -import com.lframework.xingyun.basedata.service.type.TypeInfoService;
16 16 import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
17 17 import com.lframework.xingyun.sc.bo.customer.develop.GetCustomerDevelopPlanBo;
  18 +import com.lframework.xingyun.sc.excel.customer.CustomerDevelopExportTaskWorker;
18 19 import com.lframework.xingyun.sc.vo.customer.develop.QueryCustomerDevelopPlanVo;
19 20 import com.lframework.xingyun.sc.service.customer.CustomerDevelopPlanService;
20 21 import com.lframework.xingyun.sc.vo.customer.develop.CreateCustomerDevelopPlanVo;
... ... @@ -152,6 +153,17 @@ public class CustomerDevelopPlanController extends DefaultBaseController {
152 153 return InvokeResultBuilder.success();
153 154 }
154 155
  156 + /**
  157 + * 导出
  158 + */
  159 + @ApiOperation("导出")
  160 + @HasPermission({"customer:develop:export"})
  161 + @PostMapping("/export")
  162 + public InvokeResult<Void> export(@Valid QueryCustomerDevelopPlanVo vo) {
  163 + ExportTaskUtil.exportTask("客户开发信息", CustomerDevelopExportTaskWorker.class, vo);
  164 + return InvokeResultBuilder.success();
  165 + }
  166 +
155 167
156 168 /**
157 169 * 封装客户开发数据
... ...
... ... @@ -26,4 +26,19 @@ public enum CustomerDevelopStatus implements BaseEnum<Integer> {
26 26 public String getDesc() {
27 27 return this.desc;
28 28 }
  29 +
  30 +
  31 + /**
  32 + * 通过code获取desc
  33 + * @param code 状态码
  34 + * @return 描述信息
  35 + */
  36 + public static String getDescByCode(Integer code) {
  37 + for (CustomerDevelopStatus status : CustomerDevelopStatus.values()) {
  38 + if (status.getCode().equals(code)) {
  39 + return status.getDesc();
  40 + }
  41 + }
  42 + return null;
  43 + }
29 44 }
... ...
  1 +package com.lframework.xingyun.sc.excel.customer;
  2 +
  3 +import com.alibaba.excel.annotation.ExcelProperty;
  4 +import com.alibaba.excel.annotation.format.DateTimeFormat;
  5 +import com.lframework.starter.common.constants.StringPool;
  6 +import com.lframework.starter.web.core.bo.BaseBo;
  7 +import com.lframework.starter.web.core.components.excel.ExcelModel;
  8 +import com.lframework.xingyun.sc.bo.customer.develop.GetCustomerDevelopPlanBo;
  9 +import com.lframework.xingyun.sc.enums.CustomerDevelopStatus;
  10 +import lombok.Data;
  11 +
  12 +
  13 +@Data
  14 +public class CustomerDevelopExportModel extends BaseBo<GetCustomerDevelopPlanBo> implements ExcelModel {
  15 +
  16 +
  17 + /**
  18 + * 客户基本信息
  19 + */
  20 + @ExcelProperty("客户名称")
  21 + private String customerName;
  22 +
  23 + /**
  24 + * 生产厂
  25 + */
  26 + @ExcelProperty("生产厂")
  27 + private String workshopName;
  28 +
  29 + /**
  30 + * 科办
  31 + */
  32 + @ExcelProperty("科办")
  33 + private String officeName;
  34 +
  35 + /**
  36 + * 客户类型
  37 + */
  38 + @ExcelProperty("客户类型")
  39 + private String customerTypeName;
  40 +
  41 + /**
  42 + * 产品品种
  43 + */
  44 + @ExcelProperty("产品品种")
  45 + private String productVarietyName;
  46 +
  47 + /**
  48 + * 月用量
  49 + */
  50 + @ExcelProperty("月用量")
  51 + private Double monthlyUsage;
  52 +
  53 + /**
  54 + * 目标量
  55 + */
  56 + @ExcelProperty("目标量")
  57 + private Double targetQuantity;
  58 +
  59 + /**
  60 + * 行业
  61 + */
  62 + @ExcelProperty("行业")
  63 + private String industry;
  64 +
  65 + /**
  66 + * 牌号
  67 + */
  68 + @ExcelProperty("牌号")
  69 + private String mark;
  70 +
  71 + /**
  72 + * 厚度
  73 + */
  74 + @ExcelProperty("厚度")
  75 + private Double thickness;
  76 +
  77 + /**
  78 + * 宽度
  79 + */
  80 + @ExcelProperty("宽度")
  81 + private Double width;
  82 +
  83 + /**
  84 + * 材质要求
  85 + */
  86 + @ExcelProperty("材质要求")
  87 + private String materialRequire;
  88 +
  89 + /**
  90 + * 品质要求
  91 + */
  92 + @ExcelProperty("品质要求")
  93 + private String qualityRequire;
  94 +
  95 + /**
  96 + * 同行
  97 + */
  98 + @ExcelProperty("同行")
  99 + private String peer;
  100 +
  101 + /**
  102 + * 核价模式
  103 + */
  104 + @ExcelProperty("核价模式")
  105 + private String pricingMode;
  106 +
  107 + /**
  108 + * 结算天数
  109 + */
  110 + @ExcelProperty("结算天数")
  111 + private Double settleDays;
  112 +
  113 + /**
  114 + * 责任人
  115 + */
  116 + @ExcelProperty("责任人")
  117 + private String chargeUserName;
  118 +
  119 + /**
  120 + * 状态
  121 + */
  122 + @ExcelProperty("状态")
  123 + private String statusName;
  124 +
  125 + /**
  126 + * 创建人
  127 + */
  128 + @ExcelProperty("创建人")
  129 + private String createBy;
  130 +
  131 + /**
  132 + * 更新人
  133 + */
  134 + @ExcelProperty("更新人")
  135 + private String updateBy;
  136 +
  137 + /**
  138 + * 创建时间
  139 + */
  140 + @ExcelProperty("创建时间")
  141 + @DateTimeFormat(StringPool.DATE_TIME_PATTERN)
  142 + private String createTime;
  143 +
  144 + /**
  145 + * 更新时间
  146 + */
  147 + @ExcelProperty("更新时间")
  148 + @DateTimeFormat(StringPool.DATE_TIME_PATTERN)
  149 + private String updateTime;
  150 +
  151 +
  152 + public CustomerDevelopExportModel() {
  153 +
  154 + }
  155 +
  156 + public CustomerDevelopExportModel(GetCustomerDevelopPlanBo dto) {
  157 + super(dto);
  158 + }
  159 +
  160 + @Override
  161 + public BaseBo<GetCustomerDevelopPlanBo> convert(GetCustomerDevelopPlanBo dto) {
  162 + return super.convert(dto);
  163 + }
  164 +
  165 + @Override
  166 + protected void afterInit(GetCustomerDevelopPlanBo dto) {
  167 + if (dto.getCustomer() != null) {
  168 + this.customerName = dto.getCustomer().getName();
  169 + }
  170 + if (dto.getWorkshop() != null) {
  171 + this.workshopName = dto.getWorkshop().getName();
  172 + }
  173 + if (dto.getOffice() != null) {
  174 + this.officeName = dto.getOffice().getName();
  175 + }
  176 + if (dto.getProductVariety() != null) {
  177 + this.productVarietyName = dto.getProductVariety().getName();
  178 + }
  179 + if (dto.getStatus() != null) {
  180 + this.statusName = CustomerDevelopStatus.getDescByCode(dto.getStatus());
  181 + }
  182 + if (dto.getCustomerType() != null) {
  183 + switch (dto.getCustomerType()) {
  184 + case "DEALER":
  185 + this.customerTypeName = "经销商";
  186 + break;
  187 + case "TERMINAL":
  188 + this.customerTypeName = "终端";
  189 + break;
  190 + default:
  191 + break;
  192 + }
  193 + }
  194 + }
  195 +}
... ...
  1 +package com.lframework.xingyun.sc.excel.customer;
  2 +
  3 +import com.lframework.starter.common.utils.CollectionUtil;
  4 +import com.lframework.starter.web.core.components.resp.PageResult;
  5 +import com.lframework.starter.web.core.utils.ApplicationUtil;
  6 +import com.lframework.starter.web.core.utils.JsonUtil;
  7 +import com.lframework.starter.mq.core.components.export.ExportTaskWorker;
  8 +import com.lframework.starter.web.core.utils.PageResultUtil;
  9 +import com.lframework.starter.web.inner.entity.SysUser;
  10 +import com.lframework.starter.web.inner.service.system.SysUserService;
  11 +import com.lframework.xingyun.basedata.entity.Customer;
  12 +import com.lframework.xingyun.basedata.entity.Office;
  13 +import com.lframework.xingyun.basedata.entity.ProductVariety;
  14 +import com.lframework.xingyun.basedata.entity.Workshop;
  15 +import com.lframework.xingyun.basedata.service.customer.CustomerService;
  16 +import com.lframework.xingyun.basedata.service.office.OfficeService;
  17 +import com.lframework.xingyun.basedata.service.product.ProductVarietyService;
  18 +import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
  19 +import com.lframework.xingyun.sc.bo.customer.develop.GetCustomerDevelopPlanBo;
  20 +import com.lframework.xingyun.sc.entity.CustomerDevelopPlan;
  21 +import com.lframework.xingyun.sc.service.customer.CustomerDevelopPlanService;
  22 +import com.lframework.xingyun.sc.vo.customer.develop.QueryCustomerDevelopPlanVo;
  23 +import org.apache.commons.collections4.CollectionUtils;
  24 +import org.apache.commons.lang3.StringUtils;
  25 +
  26 +import java.util.ArrayList;
  27 +import java.util.HashMap;
  28 +import java.util.List;
  29 +import java.util.Map;
  30 +import java.util.function.Function;
  31 +import java.util.stream.Collectors;
  32 +
  33 +public class CustomerDevelopExportTaskWorker implements
  34 + ExportTaskWorker<QueryCustomerDevelopPlanVo, GetCustomerDevelopPlanBo, CustomerDevelopExportModel> {
  35 +
  36 +
  37 + @Override
  38 + public QueryCustomerDevelopPlanVo parseParams(String json) {
  39 + return JsonUtil.parseObject(json, QueryCustomerDevelopPlanVo.class);
  40 + }
  41 +
  42 + @Override
  43 + public PageResult<GetCustomerDevelopPlanBo> getDataList(int pageIndex, int pageSize, QueryCustomerDevelopPlanVo params) {
  44 + CustomerDevelopPlanService customerDevelopPlanService = ApplicationUtil.getBean(CustomerDevelopPlanService.class);
  45 + PageResult<CustomerDevelopPlan> pageResult = customerDevelopPlanService.query(pageIndex, pageSize, params);
  46 + List<CustomerDevelopPlan> dataList = pageResult.getDatas();
  47 + List<GetCustomerDevelopPlanBo> results = null;
  48 + if (!CollectionUtil.isEmpty(dataList)) {
  49 + results = this.packCustomerDevelopData(dataList);
  50 + }
  51 + return PageResultUtil.rebuild(pageResult, results);
  52 + }
  53 +
  54 + @Override
  55 + public CustomerDevelopExportModel exportData(GetCustomerDevelopPlanBo data) {
  56 + return new CustomerDevelopExportModel(data);
  57 + }
  58 +
  59 + @Override
  60 + public Class<CustomerDevelopExportModel> getModelClass() {
  61 + return CustomerDevelopExportModel.class;
  62 + }
  63 +
  64 +
  65 + /**
  66 + * 封装客户开发数据
  67 + *
  68 + * @param dataList 数据集
  69 + * @return List<GetCustomerDevelopPlanBo>
  70 + */
  71 + private List<GetCustomerDevelopPlanBo> packCustomerDevelopData(List<CustomerDevelopPlan> dataList) {
  72 + // 处理关联数据
  73 + List<String> customerIds = new ArrayList<>();
  74 + List<String> workshopIds = new ArrayList<>();
  75 + List<String> officeIds = new ArrayList<>();
  76 + List<String> productVarietyIds = new ArrayList<>();
  77 + List<String> chargeUserIds = new ArrayList<>();
  78 + for (CustomerDevelopPlan plan : dataList) {
  79 + String customerId = plan.getCustomerId();
  80 + String workshopId = plan.getWorkshopId();
  81 + String officeId = plan.getOfficeId();
  82 + String productVarietyId = plan.getProductVarietyId();
  83 + String chargeUserId = plan.getChargeUserId();
  84 + if (StringUtils.isNotBlank(customerId) && !customerIds.contains(customerId)) {
  85 + customerIds.add(customerId);
  86 + }
  87 + if (StringUtils.isNotBlank(workshopId) && !workshopIds.contains(workshopId)) {
  88 + workshopIds.add(workshopId);
  89 + }
  90 + if (StringUtils.isNotBlank(officeId) && !officeIds.contains(officeId)) {
  91 + officeIds.add(officeId);
  92 + }
  93 + if (StringUtils.isNotBlank(productVarietyId) && !productVarietyIds.contains(productVarietyId)) {
  94 + productVarietyIds.add(productVarietyId);
  95 + }
  96 + if (StringUtils.isNotBlank(chargeUserId) && !chargeUserIds.contains(chargeUserId)) {
  97 + chargeUserIds.add(chargeUserId);
  98 + }
  99 + }
  100 + // 获取客户基本信息
  101 + CustomerService customerService = ApplicationUtil.getBean(CustomerService.class);
  102 + List<Customer> customerList = customerService.listByIds(customerIds);
  103 + Map<String, Customer> customerMap = new HashMap<>();
  104 + if (CollectionUtils.isNotEmpty(customerList)) {
  105 + customerMap = customerList.stream().collect(Collectors.toMap(Customer::getId, Function.identity()));
  106 + }
  107 + // 获取厂房信息
  108 + WorkshopService workshopService = ApplicationUtil.getBean(WorkshopService.class);
  109 + List<Workshop> workshopList = workshopService.listByIds(workshopIds);
  110 + Map<String, Workshop> workshopMap = new HashMap<>();
  111 + if (CollectionUtils.isNotEmpty(workshopList)) {
  112 + workshopMap = workshopList.stream().collect(Collectors.toMap(Workshop::getId, Function.identity()));
  113 + }
  114 + // 获取办事处/科办信息
  115 + OfficeService officeService = ApplicationUtil.getBean(OfficeService.class);
  116 + List<Office> officeList = officeService.listByIds(officeIds);
  117 + Map<String, Office> officeMap = new HashMap<>();
  118 + if (CollectionUtils.isNotEmpty(officeList)) {
  119 + officeMap = officeList.stream().collect(Collectors.toMap(Office::getId, Function.identity()));
  120 + }
  121 + // 获取产品品种信息
  122 + ProductVarietyService productVarietyService = ApplicationUtil.getBean(ProductVarietyService.class);
  123 + List<ProductVariety> productVarietyList = productVarietyService.listByIds(productVarietyIds);
  124 + Map<String, ProductVariety> productVarietyMap = new HashMap<>();
  125 + if (CollectionUtils.isNotEmpty(productVarietyList)) {
  126 + productVarietyMap = productVarietyList.stream().collect(Collectors.toMap(ProductVariety::getId, Function.identity()));
  127 + }
  128 + // 获取责任人数据
  129 + SysUserService sysUserService = ApplicationUtil.getBean(SysUserService.class);
  130 + List<SysUser> userList = sysUserService.listByIds(chargeUserIds);
  131 + Map<String, SysUser> userMap = new HashMap<>();
  132 + if (CollectionUtils.isNotEmpty(userList)) {
  133 + userMap = userList.stream().collect(Collectors.toMap(SysUser::getId, Function.identity()));
  134 + }
  135 + List<GetCustomerDevelopPlanBo> result = new ArrayList<>();
  136 + for (CustomerDevelopPlan plan : dataList) {
  137 + GetCustomerDevelopPlanBo data = new GetCustomerDevelopPlanBo(plan);
  138 + // 客户信息
  139 + Customer customer = customerMap.get(plan.getCustomerId());
  140 + data.setCustomer(customer);
  141 + // 厂房信息
  142 + Workshop workshop = workshopMap.get(plan.getWorkshopId());
  143 + data.setWorkshop(workshop);
  144 + // 办事处/科办
  145 + Office office = officeMap.get(plan.getOfficeId());
  146 + data.setOffice(office);
  147 + // 产品品种
  148 + ProductVariety productVariety = productVarietyMap.get(plan.getProductVarietyId());
  149 + data.setProductVariety(productVariety);
  150 + // 责任人
  151 + SysUser user = userMap.get(plan.getChargeUserId());
  152 + data.setChargeUserName(user == null ? null : user.getName());
  153 +
  154 + result.add(data);
  155 + }
  156 + return result;
  157 + }
  158 +}
... ...
... ... @@ -72,4 +72,10 @@ public class QueryCustomerDevelopPlanVo extends SortPageVo implements BaseVo, Se
72 72 */
73 73 @ApiModelProperty("待办类型")
74 74 private String todoType;
  75 +
  76 + /**
  77 + * 导出类型
  78 + */
  79 + @ApiModelProperty("导出类型")
  80 + private String exportType = "CUSTOMER_DEVELOP";
75 81 }
... ...