Commit ee55aab967306cb5bd2b68fa34d4c2d0b9731175
1 parent
5293b948
feat: 问题修复项
1、设计师权重导出
Showing
4 changed files
with
184 additions
and
10 deletions
src/main/java/com/order/erp/controller/OrderReportController.java
1 | 1 | package com.order.erp.controller; |
2 | 2 | |
3 | 3 | import com.order.erp.common.constant.ServerResult; |
4 | -import com.order.erp.domain.vo.OrderReportAnalysisVo; | |
4 | +import com.order.erp.common.excel4j.exceptions.Excel4JException; | |
5 | 5 | import com.order.erp.domain.vo.order.OrderBaseInfoQueryVO; |
6 | 6 | import com.order.erp.domain.vo.order.OrderProfitAnalysisVO; |
7 | 7 | import com.order.erp.service.order.OrderCompletionReportService; |
... | ... | @@ -12,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; |
12 | 12 | import org.springframework.web.bind.annotation.RestController; |
13 | 13 | |
14 | 14 | import javax.annotation.Resource; |
15 | +import javax.servlet.http.HttpServletResponse; | |
16 | +import java.io.IOException; | |
15 | 17 | |
16 | 18 | /** |
17 | 19 | * @author xms |
... | ... | @@ -31,4 +33,9 @@ public class OrderReportController { |
31 | 33 | public ServerResult<OrderProfitAnalysisVO> analysis(@RequestBody @Validated OrderBaseInfoQueryVO queryVO) { |
32 | 34 | return orderCompletionReportService.analysis(queryVO); |
33 | 35 | } |
36 | + | |
37 | + @PostMapping("/export") | |
38 | + public void export(HttpServletResponse response, @RequestBody @Validated OrderBaseInfoQueryVO queryVO) throws IOException, Excel4JException { | |
39 | + orderCompletionReportService.export(response, queryVO); | |
40 | + } | |
34 | 41 | } | ... | ... |
src/main/java/com/order/erp/domain/vo/OrderReportAnalysisExportVo.java
0 → 100644
1 | +package com.order.erp.domain.vo; | |
2 | + | |
3 | +import com.order.erp.common.excel4j.annotation.ExcelField; | |
4 | +import lombok.AllArgsConstructor; | |
5 | +import lombok.Data; | |
6 | +import lombok.NoArgsConstructor; | |
7 | +import lombok.ToString; | |
8 | +import lombok.experimental.SuperBuilder; | |
9 | + | |
10 | +import java.io.Serializable; | |
11 | +import java.math.BigDecimal; | |
12 | + | |
13 | +/** | |
14 | + * @author zhongnanhuang | |
15 | + * @version 1.0 | |
16 | + * @project order-erp | |
17 | + * @description 利润分析传参 | |
18 | + * @date 2023/10/30 10:19:26 | |
19 | + */ | |
20 | +@Data | |
21 | +@AllArgsConstructor | |
22 | +@NoArgsConstructor | |
23 | +@SuperBuilder | |
24 | +@ToString | |
25 | +public class OrderReportAnalysisExportVo implements Serializable { | |
26 | + | |
27 | + /** | |
28 | + * 设计师 | |
29 | + */ | |
30 | + @ExcelField(title = "设计师", order = 1) | |
31 | + private String designer; | |
32 | + | |
33 | + /** | |
34 | + * 想法来源占比 | |
35 | + */ | |
36 | + @ExcelField(title = "想法来源占比", order = 2) | |
37 | + private BigDecimal ideaSourceRate; | |
38 | + | |
39 | + /** | |
40 | + * 手工初型1占比 | |
41 | + */ | |
42 | + @ExcelField(title = "手工初型1占比", order = 3) | |
43 | + private BigDecimal manualPreform1Rate; | |
44 | + | |
45 | + /** | |
46 | + * 手工初型2占比 | |
47 | + */ | |
48 | + @ExcelField(title = "手工初型2占比", order = 4) | |
49 | + private BigDecimal manualPreform2Rate; | |
50 | +} | ... | ... |
src/main/java/com/order/erp/service/order/OrderCompletionReportService.java
... | ... | @@ -2,12 +2,15 @@ package com.order.erp.service.order; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | 4 | import com.order.erp.common.constant.ServerResult; |
5 | +import com.order.erp.common.excel4j.exceptions.Excel4JException; | |
5 | 6 | import com.order.erp.domain.dto.order.OrderCompletionReportDO; |
6 | 7 | import com.order.erp.domain.vo.OrderReportAnalysisVo; |
7 | 8 | import com.order.erp.domain.vo.order.OrderBaseInfoQueryVO; |
8 | 9 | import com.order.erp.domain.vo.order.OrderCompletionReportQueryVO; |
9 | 10 | import com.order.erp.domain.vo.order.OrderCompletionReportVO; |
10 | 11 | |
12 | +import javax.servlet.http.HttpServletResponse; | |
13 | +import java.io.IOException; | |
11 | 14 | import java.util.List; |
12 | 15 | |
13 | 16 | /** |
... | ... | @@ -36,12 +39,20 @@ public interface OrderCompletionReportService extends IService<OrderCompletionRe |
36 | 39 | |
37 | 40 | |
38 | 41 | /** |
39 | - * @param reportAnalysisVo | |
42 | + * @param queryVO | |
40 | 43 | * @return |
41 | 44 | */ |
42 | 45 | ServerResult analysis(OrderBaseInfoQueryVO queryVO); |
43 | 46 | |
44 | 47 | /** |
48 | + * | |
49 | + * @param response | |
50 | + * @param orderBaseInfoQueryVO | |
51 | + * @return | |
52 | + */ | |
53 | + ServerResult export(HttpServletResponse response, OrderBaseInfoQueryVO orderBaseInfoQueryVO) throws IOException, Excel4JException; | |
54 | + | |
55 | + /** | |
45 | 56 | * 新增数据 |
46 | 57 | * |
47 | 58 | * @param orderCompletionReportVO 数据VO | ... | ... |
src/main/java/com/order/erp/service/order/impl/OrderCompletionReportServiceImpl.java
... | ... | @@ -8,8 +8,11 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
8 | 8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
9 | 9 | import com.order.erp.common.constant.Constant; |
10 | 10 | import com.order.erp.common.constant.ServerResult; |
11 | +import com.order.erp.common.excel4j.ExcelUtils; | |
12 | +import com.order.erp.common.excel4j.exceptions.Excel4JException; | |
11 | 13 | import com.order.erp.domain.dto.order.OrderBaseInfoDO; |
12 | 14 | import com.order.erp.domain.dto.order.OrderCompletionReportDO; |
15 | +import com.order.erp.domain.vo.OrderReportAnalysisExportVo; | |
13 | 16 | import com.order.erp.domain.vo.OrderReportAnalysisResultVo; |
14 | 17 | import com.order.erp.domain.vo.order.OrderBaseInfoQueryVO; |
15 | 18 | import com.order.erp.domain.vo.order.OrderCompletionReportQueryVO; |
... | ... | @@ -21,11 +24,12 @@ import lombok.extern.slf4j.Slf4j; |
21 | 24 | import org.springframework.stereotype.Service; |
22 | 25 | |
23 | 26 | import javax.annotation.Resource; |
27 | +import javax.servlet.http.HttpServletResponse; | |
28 | +import java.io.IOException; | |
24 | 29 | import java.math.BigDecimal; |
25 | 30 | import java.math.RoundingMode; |
26 | -import java.util.List; | |
27 | -import java.util.Objects; | |
28 | -import java.util.Set; | |
31 | +import java.util.*; | |
32 | +import java.util.function.Function; | |
29 | 33 | import java.util.stream.Collectors; |
30 | 34 | |
31 | 35 | /** |
... | ... | @@ -74,23 +78,125 @@ public class OrderCompletionReportServiceImpl extends ServiceImpl<OrderCompletio |
74 | 78 | } |
75 | 79 | |
76 | 80 | @Override |
81 | + public ServerResult export(HttpServletResponse response, OrderBaseInfoQueryVO queryVO) throws IOException, Excel4JException { | |
82 | + LambdaQueryWrapper<OrderBaseInfoDO> queryWrapper = orderBaseInfoService.buildQueryByParam(queryVO); | |
83 | + List<OrderBaseInfoDO> orderBaseInfoDOList = orderBaseInfoService.list(queryWrapper); | |
84 | + if (CollectionUtils.isNotEmpty(orderBaseInfoDOList)) { | |
85 | + Set<Long> orderIds = orderBaseInfoDOList.stream().map(OrderBaseInfoDO::getId).collect(Collectors.toSet()); | |
86 | + List<OrderCompletionReportDO> reportDOS = list(new LambdaQueryWrapper<OrderCompletionReportDO>().in(OrderCompletionReportDO::getOrderId, orderIds)); | |
87 | + Map<String, OrderReportAnalysisExportVo> exportVoMap = new HashMap<>(); | |
88 | + if (CollectionUtils.isNotEmpty(reportDOS)) { | |
89 | + for (OrderCompletionReportDO reportDO : reportDOS) { | |
90 | + if (exportVoMap.containsKey(reportDO.getIdeaSource())) { | |
91 | + handlerExportMap(0, reportDO, exportVoMap); | |
92 | + } | |
93 | + if (exportVoMap.containsKey(reportDO.getManualPreform1())) { | |
94 | + handlerExportMap(1, reportDO, exportVoMap); | |
95 | + } | |
96 | + if (exportVoMap.containsKey(reportDO.getManualPreform2())) { | |
97 | + handlerExportMap(2, reportDO, exportVoMap); | |
98 | + } | |
99 | + if (!exportVoMap.containsKey(reportDO.getIdeaSource()) | |
100 | + && !exportVoMap.containsKey(reportDO.getManualPreform1()) | |
101 | + && !exportVoMap.containsKey(reportDO.getManualPreform2())) { | |
102 | + handlerExportMap(0, reportDO, exportVoMap); | |
103 | + handlerExportMap(1, reportDO, exportVoMap); | |
104 | + handlerExportMap(2, reportDO, exportVoMap); | |
105 | + } | |
106 | + } | |
107 | + } | |
108 | + List<OrderReportAnalysisExportVo> exportVos = exportMap2exportList(exportVoMap); | |
109 | + if (CollectionUtils.isNotEmpty(exportVos)) { | |
110 | + ExcelUtils.getInstance().exportObjects2Excel(exportVos, OrderReportAnalysisExportVo.class, response.getOutputStream()); | |
111 | + } | |
112 | + } | |
113 | + | |
114 | + return ServerResult.success(); | |
115 | + } | |
116 | + | |
117 | + /** | |
118 | + * @param exportVoMap | |
119 | + * @return | |
120 | + */ | |
121 | + private List<OrderReportAnalysisExportVo> exportMap2exportList(Map<String, OrderReportAnalysisExportVo> exportVoMap) { | |
122 | + List<OrderReportAnalysisExportVo> exportVos = new ArrayList<>(); | |
123 | + if (CollectionUtils.isEmpty(exportVoMap)) { | |
124 | + return exportVos; | |
125 | + } | |
126 | + for (Map.Entry<String, OrderReportAnalysisExportVo> exportVoEntry : exportVoMap.entrySet()) { | |
127 | + String key = exportVoEntry.getKey(); | |
128 | + OrderReportAnalysisExportVo exportVo = exportVoEntry.getValue(); | |
129 | + exportVo.setDesigner(key); | |
130 | + exportVos.add(exportVo); | |
131 | + } | |
132 | + return exportVos; | |
133 | + } | |
134 | + | |
135 | + /** | |
136 | + * @param reportDO | |
137 | + * @param exportVoMap | |
138 | + */ | |
139 | + private void handlerExportMap(Integer type, OrderCompletionReportDO reportDO, Map<String, OrderReportAnalysisExportVo> exportVoMap) { | |
140 | + OrderReportAnalysisExportVo exportVo = OrderReportAnalysisExportVo.builder() | |
141 | + .ideaSourceRate(new BigDecimal(0)) | |
142 | + .manualPreform1Rate(new BigDecimal(0)) | |
143 | + .manualPreform2Rate(new BigDecimal(0)).build(); | |
144 | + String key = null; | |
145 | + if (type == 0) { | |
146 | + key = reportDO.getIdeaSource(); | |
147 | + | |
148 | + } | |
149 | + if (type == 1) { | |
150 | + key = reportDO.getManualPreform1(); | |
151 | + } | |
152 | + if (type == 2) { | |
153 | + key = reportDO.getManualPreform2(); | |
154 | + } | |
155 | + exportVo = exportVoMap.get(key); | |
156 | + if (Objects.nonNull(reportDO.getIdeaSourceRate())) { | |
157 | + exportVo.setIdeaSourceRate(new BigDecimal(reportDO.getIdeaSourceRate()).add(exportVo.getIdeaSourceRate())); | |
158 | + } | |
159 | + if (Objects.nonNull(reportDO.getManualPreform1Rate())) { | |
160 | + exportVo.setManualPreform1Rate(new BigDecimal(reportDO.getManualPreform1Rate()).add(exportVo.getManualPreform1Rate())); | |
161 | + } | |
162 | + if (Objects.nonNull(reportDO.getManualPreform2Rate())) { | |
163 | + exportVo.setManualPreform2Rate(new BigDecimal(reportDO.getManualPreform2Rate()).add(exportVo.getManualPreform2Rate())); | |
164 | + } | |
165 | + exportVoMap.put(key, exportVo); | |
166 | + } | |
167 | + | |
168 | + @Override | |
77 | 169 | public ServerResult analysis(OrderBaseInfoQueryVO queryVO) { |
78 | 170 | LambdaQueryWrapper<OrderBaseInfoDO> queryWrapper = orderBaseInfoService.buildQueryByParam(queryVO); |
79 | 171 | List<OrderBaseInfoDO> orderBaseInfoDOList = orderBaseInfoService.list(queryWrapper); |
80 | 172 | OrderReportAnalysisResultVo resultVo = new OrderReportAnalysisResultVo(); |
173 | + Map<Long, OrderBaseInfoDO> orderBaseInfoDOMap = new HashMap<>(); | |
174 | + Set<String> innerNoSet = new HashSet<>(); | |
81 | 175 | if (CollectionUtils.isNotEmpty(orderBaseInfoDOList)) { |
176 | + | |
82 | 177 | Set<Long> orderIds = orderBaseInfoDOList.stream().map(OrderBaseInfoDO::getId).collect(Collectors.toSet()); |
83 | 178 | List<OrderCompletionReportDO> reportDOS = list(new LambdaQueryWrapper<OrderCompletionReportDO>().in(OrderCompletionReportDO::getOrderId, orderIds)); |
84 | 179 | BigDecimal sum = new BigDecimal(0); |
180 | + Map<Long, OrderCompletionReportDO> completionReportDOMap = new HashMap<>(); | |
85 | 181 | if (CollectionUtils.isNotEmpty(reportDOS)) { |
182 | + completionReportDOMap = reportDOS.stream().collect(Collectors.toMap(OrderCompletionReportDO::getOrderId, Function.identity(), (x, y) -> x)); | |
183 | + for (OrderBaseInfoDO orderBaseInfoDO : orderBaseInfoDOList) { | |
184 | + if (completionReportDOMap.containsKey(orderBaseInfoDO.getId())) { | |
185 | + if (!innerNoSet.contains(orderBaseInfoDO.getInnerNo())) { | |
186 | + orderBaseInfoDOMap.put(orderBaseInfoDO.getId(), orderBaseInfoDO); | |
187 | + } | |
188 | + innerNoSet.add(orderBaseInfoDO.getInnerNo()); | |
189 | + } | |
190 | + } | |
86 | 191 | for (OrderCompletionReportDO reportDO : reportDOS) { |
87 | - Double ideaSourceRate = queryVO.getDesigner().equals(reportDO.getIdeaSource()) && Objects.nonNull(reportDO.getIdeaSourceRate()) ? reportDO.getIdeaSourceRate() : 0; | |
88 | - Double manualPreform1Rate = queryVO.getDesigner().equals(reportDO.getManualPreform1()) && Objects.nonNull(reportDO.getManualPreform1Rate()) ? reportDO.getManualPreform1Rate() : 0; | |
89 | - Double manualPreform2Rate = queryVO.getDesigner().equals(reportDO.getManualPreform2()) && Objects.nonNull(reportDO.getManualPreform2Rate()) ? reportDO.getManualPreform2Rate() : 0; | |
90 | - sum = sum.add(new BigDecimal(ideaSourceRate)).add(new BigDecimal(manualPreform1Rate)).add(new BigDecimal(manualPreform2Rate)); | |
192 | + if (orderBaseInfoDOMap.containsKey(reportDO.getOrderId())) { | |
193 | + Double ideaSourceRate = queryVO.getDesigner().equals(reportDO.getIdeaSource()) && Objects.nonNull(reportDO.getIdeaSourceRate()) ? reportDO.getIdeaSourceRate() : 0; | |
194 | + Double manualPreform1Rate = queryVO.getDesigner().equals(reportDO.getManualPreform1()) && Objects.nonNull(reportDO.getManualPreform1Rate()) ? reportDO.getManualPreform1Rate() : 0; | |
195 | + Double manualPreform2Rate = queryVO.getDesigner().equals(reportDO.getManualPreform2()) && Objects.nonNull(reportDO.getManualPreform2Rate()) ? reportDO.getManualPreform2Rate() : 0; | |
196 | + sum = sum.add(new BigDecimal(ideaSourceRate)).add(new BigDecimal(manualPreform1Rate)).add(new BigDecimal(manualPreform2Rate)); | |
197 | + } | |
91 | 198 | } |
92 | 199 | } |
93 | - Set<String> innerNoSet = orderBaseInfoDOList.stream().map(OrderBaseInfoDO::getInnerNo).collect(Collectors.toSet()); | |
94 | 200 | resultVo.setRate(sum.divide(new BigDecimal(innerNoSet.size()), Constant.SIX, RoundingMode.HALF_UP).doubleValue()); |
95 | 201 | } |
96 | 202 | return ServerResult.success(resultVo); | ... | ... |