Commit 43458e11aeceaeee29e671c513a8ba1e608fcd0d
1 parent
589b0cdc
定时检测超时任务
Showing
6 changed files
with
252 additions
and
302 deletions
src/main/java/com/order/erp/common/utils/EmailSendUtils.java
... | ... | @@ -2,6 +2,7 @@ package com.order.erp.common.utils; |
2 | 2 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
3 | 3 | import com.order.erp.domain.EmailTemplateEnum; |
4 | 4 | import com.order.erp.domain.email.OrderProductEmailVO; |
5 | +import com.order.erp.domain.vo.order.OrderEventJobVO; | |
5 | 6 | import freemarker.template.Template; |
6 | 7 | import freemarker.template.TemplateException; |
7 | 8 | import org.springframework.beans.factory.annotation.Value; |
... | ... | @@ -37,12 +38,12 @@ public class EmailSendUtils { |
37 | 38 | * @Description: 发送邮件 |
38 | 39 | * @param emailTemplateEnum 邮件事件类型 |
39 | 40 | * @param receiveemailList 收件人邮箱 |
40 | - * @param orderProductEmailVO 订单基本信息,订单-质检信息。 | |
41 | + * @param orderEventJobVO 订单基本信息,订单-质检信息,等。 | |
41 | 42 | * @throws MessagingException |
42 | 43 | * @throws IOException |
43 | 44 | */ |
44 | 45 | |
45 | - public void sendEmail(EmailTemplateEnum emailTemplateEnum, List<String> receiveemailList, OrderProductEmailVO orderProductEmailVO) throws MessagingException, IOException, TemplateException { | |
46 | + public void sendEmail(EmailTemplateEnum emailTemplateEnum, List<String> receiveemailList, OrderEventJobVO orderEventJobVO) throws MessagingException, IOException, TemplateException { | |
46 | 47 | MimeMessage mimeMessage = javaMailSender.createMimeMessage(); |
47 | 48 | if(CollectionUtils.isNotEmpty(receiveemailList)){ |
48 | 49 | MimeMessageHelper helper=new MimeMessageHelper(mimeMessage,true); |
... | ... | @@ -57,7 +58,7 @@ public class EmailSendUtils { |
57 | 58 | Map<String, Object> map = new HashMap<>(); |
58 | 59 | map.put("context",emailTemplateEnum.getContent()); |
59 | 60 | map.put("title",emailTemplateEnum.getTitle()); |
60 | - map.put("data",orderProductEmailVO); | |
61 | + map.put("data",orderEventJobVO); | |
61 | 62 | Template template = freeMarkerConfigurer.getConfiguration().getTemplate("mail.ftl"); |
62 | 63 | StringWriter stringWriter = new StringWriter(); |
63 | 64 | template.process(map,stringWriter); | ... | ... |
src/main/java/com/order/erp/domain/EmailTemplateEnum.java
... | ... | @@ -43,5 +43,13 @@ public enum EmailTemplateEnum { |
43 | 43 | * 邮件模块id |
44 | 44 | */ |
45 | 45 | private Long templateId; |
46 | + public static EmailTemplateEnum byTemplate(Long templateId) { | |
47 | + for (EmailTemplateEnum emailTemplateEnum : EmailTemplateEnum.values()) { | |
48 | + if (emailTemplateEnum.getTemplateId().equals(templateId)) { | |
49 | + return emailTemplateEnum; | |
50 | + } | |
51 | + } | |
52 | + return null; | |
53 | + } | |
46 | 54 | |
47 | 55 | } | ... | ... |
src/main/java/com/order/erp/job/OrderOverTimeEventJob.java
1 | 1 | package com.order.erp.job; |
2 | - | |
2 | +import cn.hutool.core.bean.BeanUtil; | |
3 | 3 | import com.alibaba.fastjson.JSON; |
4 | +import com.alibaba.fastjson.TypeReference; | |
4 | 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
5 | 6 | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
6 | 7 | import com.order.erp.common.constant.Constant; |
7 | 8 | import com.order.erp.common.utils.EmailSendUtils; |
9 | +import com.order.erp.common.utils.RedisUtils; | |
8 | 10 | import com.order.erp.common.utils.StringUtils; |
9 | 11 | import com.order.erp.common.utils.TransactionHelper; |
10 | 12 | import com.order.erp.domain.EmailTemplateEnum; |
11 | 13 | import com.order.erp.domain.OrderEventEnum; |
12 | -import com.order.erp.domain.OrderStatusEnum; | |
13 | -import com.order.erp.domain.dto.BaseDO; | |
14 | 14 | import com.order.erp.domain.dto.order.OrderBaseInfoDO; |
15 | 15 | import com.order.erp.domain.dto.order.OrderInspectionStageDO; |
16 | 16 | import com.order.erp.domain.dto.order.OrderTrackStageDO; |
17 | 17 | import com.order.erp.domain.dto.order.ReceiveEmailMappingDO; |
18 | -import com.order.erp.domain.email.OrderProductEmailVO; | |
19 | -import com.order.erp.domain.vo.order.OrderEventJobVO; | |
20 | -import com.order.erp.domain.vo.order.ReceiveEmailConfigItemVO; | |
18 | +import com.order.erp.domain.vo.order.*; | |
21 | 19 | import com.order.erp.service.order.*; |
22 | 20 | import freemarker.template.TemplateException; |
23 | 21 | import lombok.extern.slf4j.Slf4j; |
24 | 22 | import org.springframework.scheduling.annotation.Scheduled; |
25 | 23 | import org.springframework.stereotype.Component; |
26 | - | |
27 | 24 | import javax.annotation.Resource; |
28 | 25 | import javax.mail.MessagingException; |
29 | -import java.io.File; | |
30 | 26 | import java.io.IOException; |
31 | 27 | import java.time.LocalDate; |
32 | 28 | import java.time.format.DateTimeFormatter; |
... | ... | @@ -35,7 +31,6 @@ import java.util.*; |
35 | 31 | import java.util.function.Function; |
36 | 32 | import java.util.stream.Collectors; |
37 | 33 | |
38 | -import static com.order.erp.domain.EmailTemplateEnum.BIG_SAMPLE_TEMPLATE; | |
39 | 34 | |
40 | 35 | |
41 | 36 | /** |
... | ... | @@ -72,291 +67,23 @@ public class OrderOverTimeEventJob { |
72 | 67 | @Resource |
73 | 68 | private ReceiveEmailMappingService receiveEmailMappingService; |
74 | 69 | |
70 | + @Resource | |
71 | + private RedisUtils redisUtils; | |
72 | + | |
75 | 73 | /** |
76 | 74 | * 凌晨1点执行,一天一次 |
77 | 75 | */ |
78 | - @Scheduled(cron = "0 0 1 * * ?") | |
79 | - public void checkOverTimeExecute() { | |
80 | - /*首先判断字符串。如果没有ok并且次数达到了三次(统计fail是否存在三次),就提醒。 | |
81 | - * 如果有ok,取出ok前的日期,得到日期,那这个日期与HOD日期进行判断*/ | |
82 | - List<OrderBaseInfoDO> orderBaseInfoList = orderBaseInfoService.list(new LambdaQueryWrapper<OrderBaseInfoDO>() | |
83 | - .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | |
84 | - .ne(OrderBaseInfoDO::getOrderStatus, OrderStatusEnum.ORDER_FINISH.getStatus())); | |
85 | - Set<Long> orderList = orderBaseInfoList.stream().map(OrderBaseInfoDO::getId).collect(Collectors.toSet()); | |
86 | - Map<Long, OrderBaseInfoDO> baseInfoDOMap = orderBaseInfoList.stream().collect(Collectors.toMap(OrderBaseInfoDO::getId, Function.identity(), (x, y) -> x)); | |
87 | - List<OrderInspectionStageDO> orderInspectionStageList = inspectionStageService.listByIds(orderList); | |
88 | - Map<Long, OrderInspectionStageDO> inspectionStageDOMap = orderInspectionStageList.stream().collect(Collectors.toMap(OrderInspectionStageDO::getOrderId, Function.identity(), (x, y) -> x)); | |
89 | - List<OrderTrackStageDO> orderTrackStageList = trackStageService.listByIds(orderList); | |
90 | - OrderProductEmailVO orderProductEmailVO = new OrderProductEmailVO(); | |
91 | - System.out.println("1111111111111111111111111"); | |
92 | - //只有跟单信息不为空时,才会有时间和状态。 | |
93 | - if (CollectionUtils.isNotEmpty(orderTrackStageList)) { | |
94 | - System.out.println("orderId" + baseInfoDOMap); | |
95 | - System.out.println("order Base Info" + inspectionStageDOMap); | |
96 | - orderTrackStageList.stream().forEach(x -> { | |
97 | - System.out.println("orderId" + x.getOrderId()); | |
98 | - System.out.println("order Base Info" + baseInfoDOMap.get(x.getOrderId())); | |
99 | - if (StringUtils.isBlank(baseInfoDOMap.get(x.getOrderId()).getOrderHodTime())) { | |
100 | -// return ServerResult.fail("HODTime不能为空"); | |
101 | - } | |
102 | - if (baseInfoDOMap.get(x.getOrderId()).getId() == x.getOrderId()) { | |
103 | - orderProductEmailVO.setBaseInfo(baseInfoDOMap.get(x.getOrderId())); | |
104 | - try { | |
105 | - System.out.println("222222222222222222222"); | |
106 | - test(EmailTemplateEnum.AITEX_SGS_TEST_TEMPLATE, x.getPpConfirmResult(), orderProductEmailVO); | |
107 | - System.out.println("2333333333333333333333"); | |
108 | - } catch (MessagingException e) { | |
109 | - throw new RuntimeException(e); | |
110 | - } catch (TemplateException e) { | |
111 | - throw new RuntimeException(e); | |
112 | - } catch (IOException e) { | |
113 | - throw new RuntimeException(e); | |
114 | - } | |
115 | - try { | |
116 | - test(EmailTemplateEnum.CONFIRM_SAMPLE_TEMPLATE, x.getShippmentSampleConfirmResult(), orderProductEmailVO); | |
117 | - } catch (MessagingException e) { | |
118 | - throw new RuntimeException(e); | |
119 | - } catch (TemplateException e) { | |
120 | - throw new RuntimeException(e); | |
121 | - } catch (IOException e) { | |
122 | - throw new RuntimeException(e); | |
123 | - } | |
124 | - try { | |
125 | - test(EmailTemplateEnum.AITEX_SGS_TEST_TEMPLATE, x.getAitexTestFinishResult(), orderProductEmailVO); | |
126 | - } catch (MessagingException e) { | |
127 | - throw new RuntimeException(e); | |
128 | - } catch (TemplateException e) { | |
129 | - throw new RuntimeException(e); | |
130 | - } catch (IOException e) { | |
131 | - throw new RuntimeException(e); | |
132 | - } | |
133 | - try { | |
134 | - test(EmailTemplateEnum.AITEX_SGS_TEST_TEMPLATE, x.getSgsTestFinishResult(), orderProductEmailVO); | |
135 | - } catch (MessagingException e) { | |
136 | - throw new RuntimeException(e); | |
137 | - } catch (TemplateException e) { | |
138 | - throw new RuntimeException(e); | |
139 | - } catch (IOException e) { | |
140 | - throw new RuntimeException(e); | |
141 | - } | |
142 | - try { | |
143 | - test(EmailTemplateEnum.OTHER_SAMPLE_TEMPLATE, x.getEsoSampleSendTime(), orderProductEmailVO); | |
144 | - } catch (MessagingException e) { | |
145 | - throw new RuntimeException(e); | |
146 | - } catch (TemplateException e) { | |
147 | - throw new RuntimeException(e); | |
148 | - } catch (IOException e) { | |
149 | - throw new RuntimeException(e); | |
150 | - } | |
151 | - try { | |
152 | - test(EmailTemplateEnum.BARCODE_ARRIVAL_TEMPLATE, x.getLatestArrivalTime(), orderProductEmailVO); | |
153 | - } catch (MessagingException e) { | |
154 | - throw new RuntimeException(e); | |
155 | - } catch (TemplateException e) { | |
156 | - throw new RuntimeException(e); | |
157 | - } catch (IOException e) { | |
158 | - throw new RuntimeException(e); | |
159 | - } | |
160 | - try { | |
161 | - test(EmailTemplateEnum.LATEST_DC_TEMPLATE, x.getLatestBkTime(), orderProductEmailVO); | |
162 | - } catch (MessagingException e) { | |
163 | - throw new RuntimeException(e); | |
164 | - } catch (TemplateException e) { | |
165 | - throw new RuntimeException(e); | |
166 | - } catch (IOException e) { | |
167 | - throw new RuntimeException(e); | |
168 | - } | |
169 | - } | |
170 | - if (baseInfoDOMap.get(x.getOrderId()).getId() == x.getOrderId() && | |
171 | - baseInfoDOMap.get(x.getOrderId()).getId() == inspectionStageDOMap.get(x.getOrderId()).getOrderId()) { | |
172 | - orderProductEmailVO.setInspectionStageInfo(inspectionStageDOMap.get(x.getOrderId())); | |
173 | - orderProductEmailVO.setBaseInfo(baseInfoDOMap.get(x.getOrderId())); | |
174 | - //尾期验货日期。尾期放这里写是因为尾期验货日期需要从inspectionStageDOMap中获取。 | |
175 | - try { | |
176 | - test(EmailTemplateEnum.END_CHECK_DATE_TEMPLATE, inspectionStageDOMap.get(x.getOrderId()).getEndCheckApplyTime(), orderProductEmailVO); | |
177 | - } catch (MessagingException e) { | |
178 | - throw new RuntimeException(e); | |
179 | - } catch (TemplateException e) { | |
180 | - throw new RuntimeException(e); | |
181 | - } catch (IOException e) { | |
182 | - throw new RuntimeException(e); | |
183 | - } | |
184 | - /*加上中期验货报告和尾期验货报告的发送,因为他需要发送inspectionStageDOMap实体类中的数据*/ | |
185 | - //todo | |
186 | - } | |
187 | - | |
188 | - } | |
189 | - ); | |
190 | - } | |
191 | - | |
192 | - } | |
193 | - | |
194 | - // 写一下检测方法。 | |
195 | - /*@param event 代表的含义,这个是对应的枚举类型。 | |
196 | - *@param str 代表的含义,这个是状态日期。 | |
197 | - *@param orderProductEmailVO 代表的含义,这个邮件要发送的内容。 | |
198 | - * */ | |
199 | - //todo 还需要判断其他时间,不能单独只判断po时间。 | |
200 | - public void test(EmailTemplateEnum eventEnum, String str, OrderProductEmailVO orderProductEmailVO) throws MessagingException, TemplateException, IOException { | |
201 | - //获取邮件收件人。 | |
202 | - System.out.println("22222222222222222222--1111111111111"); | |
203 | - List<List<String>> emails = getEmails(eventEnum, orderProductEmailVO); | |
204 | - if (StringUtils.isNotBlank(str)) { | |
205 | - //如果为确认样确认,或者AITEX/SGS测试判断是否存在ok。 | |
206 | - if (eventEnum.getTitle().equals(EmailTemplateEnum.CONFIRM_SAMPLE_TEMPLATE.getTitle()) || | |
207 | - eventEnum.getTitle().equals(EmailTemplateEnum.AITEX_SGS_TEST_TEMPLATE.getTitle()) || | |
208 | - eventEnum.getTitle().equals(BIG_SAMPLE_TEMPLATE.getTitle())) { | |
209 | - System.out.println("2222222222-22222222222222"); | |
210 | - //不包含ok并且三次输入机会都为fail了 | |
211 | - if (!str.contains("ok") && org.apache.commons.lang3.StringUtils.countMatches(str, "fail") == 3) { | |
212 | - //直接发邮件。 | |
213 | - for (List email : emails) { | |
214 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
215 | - } | |
216 | - //设置状态为1,下次不扫描。 | |
217 | - } else if (str.contains("ok") || org.apache.commons.lang3.StringUtils.countMatches(str, "fail") < 3) { | |
218 | - //只会有几种种情况,一种是fail,一种是fail+fail。一种是fail+ok,一种是ok,得到最后状态前的值就可以了,前面的不用管。 | |
219 | - String[] parats = str.split("\\+"); | |
220 | - //获取最后状态前的时间。 | |
221 | - String time = parats[str.length() - 3]; | |
222 | - LocalDate parse1 = LocalDate.parse(time, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
223 | - //得到订单的截止时间。 | |
224 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
225 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
226 | - //计算两个时间之间的天数间隔。parse2-parse1 | |
227 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
228 | - if (eventEnum.getTitle().equals(EmailTemplateEnum.CONFIRM_SAMPLE_TEMPLATE.getTitle())) { | |
229 | - if (daysBetween == 21) { | |
230 | - //直接发邮件。 | |
231 | - for (List email : emails) { | |
232 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
233 | - } | |
234 | - } | |
235 | - } else if (eventEnum.getTitle().equals(EmailTemplateEnum.AITEX_SGS_TEST_TEMPLATE.getTitle())) { | |
236 | - if (daysBetween == 3) { | |
237 | - //直接发邮件。 | |
238 | - for (List email : emails) { | |
239 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
240 | - } | |
241 | - } | |
242 | - } else { | |
243 | - if (daysBetween == 7) { | |
244 | - //直接发邮件。 | |
245 | - for (List email : emails) { | |
246 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
247 | - } | |
248 | - } | |
249 | - } | |
250 | - } | |
251 | - } | |
252 | - //没有ok或者fail状态,只通过时间来判断。 | |
253 | - if (eventEnum.getTitle().equals(EmailTemplateEnum.OTHER_SAMPLE_TEMPLATE.getTitle())) { | |
254 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
255 | - LocalDate parse1 = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
256 | - //订单的HOD截止时间。 | |
257 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
258 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
259 | - if (daysBetween == 14) { | |
260 | - for (List email : emails) { | |
261 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
262 | - } | |
263 | - } | |
264 | - | |
265 | - } else if (eventEnum.getTitle().equals(EmailTemplateEnum.BARCODE_ARRIVAL_TEMPLATE.getTitle())) { | |
266 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
267 | - LocalDate parse1 = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
268 | - //订单的HOD截止时间。 | |
269 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
270 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
271 | - if (daysBetween == 7) { | |
272 | - for (List email : emails) { | |
273 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
274 | - } | |
275 | - } | |
276 | - | |
277 | - } else if (eventEnum.getTitle().equals(EmailTemplateEnum.LATEST_DC_TEMPLATE.getTitle())) { | |
278 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
279 | - LocalDate parse1 = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
280 | - //订单的HOD截止时间。 | |
281 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
282 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
283 | - if (daysBetween == 10) { | |
284 | - for (List email : emails) { | |
285 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
286 | - } | |
287 | - } | |
288 | - | |
289 | - } else if (eventEnum.getTitle().equals(EmailTemplateEnum.END_CHECK_DATE_TEMPLATE.getTitle())) { | |
290 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
291 | - LocalDate parse1 = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
292 | - //订单的HOD截止时间。 | |
293 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
294 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
295 | - if (daysBetween == 2) { | |
296 | - for (List email : emails) { | |
297 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
298 | - } | |
299 | - } | |
300 | - } | |
301 | - } | |
302 | - } | |
303 | - | |
304 | - /*发送中期验货报告和尾期验货报告,疑问,是什么时候发送,质检信息中有中期验货字段,是否是填写了中期验货字段就发送还是说填写了跟单信息发送*/ | |
305 | - public void send() { | |
306 | - | |
307 | - } | |
308 | - | |
309 | - /*发送生产指示书*/ | |
310 | - public void sende(File file) { | |
311 | - | |
312 | - } | |
313 | - | |
314 | - /*返回邮箱 | |
315 | - * 解释:根据订单的客户编码和事件类型,得到这个客户编码配置好的邮箱配置,返回邮箱*/ | |
316 | - public List<List<String>> getEmails(EmailTemplateEnum eventEnum, OrderProductEmailVO orderProductEmailVO) { | |
317 | - String customerCode = orderProductEmailVO.getBaseInfo().getCustomerCode(); | |
318 | - List<ReceiveEmailMappingDO> receiveEmailMappingDOList = receiveEmailMappingService.list(new LambdaQueryWrapper<ReceiveEmailMappingDO>() | |
319 | - .eq(BaseDO::getEnableFlag, Constant.ENABLE_TEN) | |
320 | - .eq(ReceiveEmailMappingDO::getTypeValue, customerCode)); | |
321 | - Set<List<String>> emailList = receiveEmailMappingDOList.stream().map(x -> { | |
322 | - ReceiveEmailConfigItemVO receiveEmailConfigItemVO = JSON.parseObject(x.getConfigInfos(), ReceiveEmailConfigItemVO.class); | |
323 | - if (eventEnum.getTemplateId() == OrderEventEnum.getEvent(receiveEmailConfigItemVO.getEvent()).getTemplateId()) { | |
324 | - List<String> emailsList = receiveEmailConfigItemVO.getEmails(); | |
325 | - return emailsList; | |
326 | - } | |
327 | - return null; | |
328 | - }).collect(Collectors.toSet()); | |
329 | - return new ArrayList<>(emailList); | |
330 | - } | |
331 | - | |
332 | - | |
333 | - /* public void a(String str, OrderProductEmailVO orderProductEmailVO) { | |
334 | - //包含ok。 | |
335 | - String[] parats = str.split("\\+"); | |
336 | - //获取ok前的时间。 | |
337 | - String time = parats[str.length() - 3]; | |
338 | - LocalDate parse1 = LocalDate.parse(time, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
339 | - //得到订单的截止时间。 | |
340 | - String orderHodTime = orderProductEmailVO.getBaseInfo().getOrderHodTime(); | |
341 | - LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
342 | - //计算两个时间之间的天数间隔。parse2-parse1 | |
343 | - long daysBetween = ChronoUnit.DAYS.between(parse2, parse1); | |
344 | - if (daysBetween == 21) { | |
345 | - //直接发邮件。 | |
346 | - for (List email : emails) { | |
347 | - emailSendUtils.sendEmail(eventEnum, email, orderProductEmailVO); | |
348 | - } | |
349 | - } | |
350 | - }*/ | |
351 | - | |
352 | - @Scheduled(cron = "0 0 2 * * ?") | |
353 | - public void checkOverTimeExecuteV2() { | |
354 | - List<OrderEventJobVO> jobVOList = transfer2OrderEventList(null, null, null); | |
355 | - | |
76 | + @Scheduled(cron = "0 0 2 * * ?") | |
77 | + public void checkOverTimeExecuteV2() throws MessagingException, TemplateException, IOException { | |
78 | + List<OrderBaseInfoDO> orderBaseInfoDOList = orderBaseInfoService.getEventList(); | |
79 | + Set<Long> orderIds = orderBaseInfoDOList.stream().map(OrderBaseInfoDO::getId).collect(Collectors.toSet()); | |
80 | + List<OrderInspectionStageDO> orderInspectionStageDOList = inspectionStageService.list(new LambdaQueryWrapper<OrderInspectionStageDO>() | |
81 | + .in(OrderInspectionStageDO::getOrderId, orderIds)); | |
82 | + List<OrderTrackStageDO> orderTrackStageDOList = trackStageService.list(new LambdaQueryWrapper<OrderTrackStageDO>() | |
83 | + .in(OrderTrackStageDO::getOrderId, orderIds)); | |
84 | + List<OrderEventJobVO> jobVOList = transfer2OrderEventList(orderBaseInfoDOList, orderInspectionStageDOList, orderTrackStageDOList); | |
356 | 85 | Map<String, List<OrderEventJobVO>> map = handlerOrderEvent(jobVOList); |
357 | - | |
358 | 86 | for (Map.Entry<String, List<OrderEventJobVO>> entry : map.entrySet()) { |
359 | - | |
360 | 87 | sendEmail4OrderEvent(OrderEventEnum.getEvent(entry.getKey()), entry.getValue()); |
361 | 88 | } |
362 | 89 | } |
... | ... | @@ -365,20 +92,90 @@ public class OrderOverTimeEventJob { |
365 | 92 | * @param eventEnum |
366 | 93 | * @param eventJobVOS |
367 | 94 | */ |
368 | - private void sendEmail4OrderEvent(OrderEventEnum eventEnum, List<OrderEventJobVO> eventJobVOS) { | |
369 | - // todo | |
95 | + //发送邮件。 | |
96 | + private void sendEmail4OrderEvent(OrderEventEnum eventEnum, List<OrderEventJobVO> eventJobVOS) throws MessagingException, TemplateException, IOException { | |
97 | + HashSet<String> strings = new HashSet<>(); | |
98 | + for (OrderEventJobVO orderEventJob : eventJobVOS) { | |
99 | + if (!redisUtils.hasKey(EmailTemplateEnum.byTemplate( | |
100 | + eventEnum.getTemplateId()) + Constant.POINT_BAR_CHARACTER + orderEventJob.getBaseInfo().getId())){ | |
101 | + strings.add(orderEventJob.getBaseInfo().getCustomerCode()); | |
102 | + } | |
103 | + } | |
104 | + LambdaQueryWrapper<ReceiveEmailMappingDO> queryWrapper = new LambdaQueryWrapper<>(); | |
105 | + queryWrapper.eq(ReceiveEmailMappingDO::getEnableFlag, Constant.ENABLE_TEN); | |
106 | + if (strings == null || strings.isEmpty()) { | |
107 | + queryWrapper.eq(ReceiveEmailMappingDO::getTypeValue, " "); | |
108 | + } else { | |
109 | + queryWrapper.in(ReceiveEmailMappingDO::getTypeValue, strings); | |
110 | + } | |
111 | + queryWrapper.apply("JSON_CONTAINS(JSON_EXTRACT(config_infos, '$[*].event'), JSON_QUOTE({0}), '$')", eventEnum.getEvent()); | |
112 | + List<ReceiveEmailMappingDO> receiveEmailMappingDOList = receiveEmailMappingService.list(queryWrapper); | |
113 | + | |
114 | + /* List<ReceiveEmailMappingDO> receiveEmailMappingDOList = receiveEmailMappingService.list( | |
115 | + new LambdaQueryWrapper<ReceiveEmailMappingDO>() | |
116 | + .eq(ReceiveEmailMappingDO::getEnableFlag, Constant.ENABLE_TEN) | |
117 | + .in(CollectionUtils.isNotEmpty(strings),ReceiveEmailMappingDO::getTypeValue, strings) | |
118 | + .apply("JSON_CONTAINS(JSON_EXTRACT(config_infos, '$[*].event'), JSON_QUOTE({0}), '$')", eventEnum.getEvent()));*/ | |
119 | + | |
120 | + Set<Map<String, List<String>>> set = receiveEmailMappingDOList.stream().map(x -> { | |
121 | + Map<String, List<String>> map = new HashMap<>(); | |
122 | + String customerCode = x.getTypeValue(); | |
123 | +// ReceiveEmailConfigItemVO receiveEmailConfigItemVO = JSON.parseObject(x.getConfigInfos(), ReceiveEmailConfigItemVO.class); | |
124 | + List<ReceiveEmailConfigItemVO> receiveEmailConfigItemVOList = JSON.parseObject( | |
125 | + x.getConfigInfos(), new TypeReference<List<ReceiveEmailConfigItemVO>>() { | |
126 | + }); | |
127 | + List<String> strings1 = new ArrayList<>(); | |
128 | + for (ReceiveEmailConfigItemVO item : receiveEmailConfigItemVOList) { | |
129 | + strings1 = item.getEmails(); | |
130 | + } | |
131 | + List<String> emails = strings1; | |
132 | + map.put(customerCode, emails); | |
133 | + return map; | |
134 | + }).collect(Collectors.toSet()); | |
135 | + for (OrderEventJobVO orderEventJob : eventJobVOS) { | |
136 | + for (Map<String, List<String>> map : set) { | |
137 | + if (orderEventJob.getBaseInfo().getCustomerCode().equals(map.keySet().iterator().next())) { | |
138 | + emailSendUtils.sendEmail(EmailTemplateEnum.byTemplate(eventEnum.getTemplateId()), | |
139 | + map.get(map.keySet().iterator().next()), orderEventJob); | |
140 | + redisUtils.set(EmailTemplateEnum.byTemplate( | |
141 | + eventEnum.getTemplateId()) + Constant.POINT_BAR_CHARACTER + orderEventJob.getBaseInfo().getId(), | |
142 | + orderEventJob); | |
143 | + } | |
144 | + } | |
145 | + | |
146 | + } | |
370 | 147 | } |
371 | 148 | |
372 | 149 | /** |
373 | - * @param orderBaseInfoList | |
374 | - * @param orderInspectionStageList | |
375 | - * @param orderTrackStageList | |
376 | - * @return | |
150 | + * @param orderBaseInfoList 订单基础信息集合。 | |
151 | + * @param orderInspectionStageList 订单质检信息集合。 (需要尾期验货申请时间,判断尾期验货日期到期时间)/(还需要尾期验货报告和中期验货报告) | |
152 | + * @param orderTrackStageList 订单跟单信息集合。 (需要各个属性,判断其他各种事件) | |
153 | + * @return 0rderEventJobVO 订单数据整合集合 | |
377 | 154 | */ |
155 | + //这个方法的作用应该是筛选出订单数据。 | |
378 | 156 | private List<OrderEventJobVO> transfer2OrderEventList(List<OrderBaseInfoDO> orderBaseInfoList, List<OrderInspectionStageDO> orderInspectionStageList, List<OrderTrackStageDO> orderTrackStageList) { |
379 | - | |
380 | 157 | // todo |
381 | - return null; | |
158 | + Map<Long, OrderInspectionStageDO> OrderInspectionStageMap = orderInspectionStageList.stream().collect(Collectors.toMap(OrderInspectionStageDO::getOrderId, Function.identity(), (x, y) -> x)); | |
159 | + Map<Long, OrderTrackStageDO> OrderTrackStageMap = orderTrackStageList.stream().collect(Collectors.toMap(OrderTrackStageDO::getOrderId, Function.identity(), (x, y) -> x)); | |
160 | + List<OrderEventJobVO> orderEventJobVOList = orderBaseInfoList.stream().map(x -> { | |
161 | + OrderEventJobVO orderEventJobVO = new OrderEventJobVO(); | |
162 | + if (x.getId() == OrderInspectionStageMap.get(x.getId()).getOrderId() && | |
163 | + x.getId() == OrderTrackStageMap.get(x.getId()).getOrderId()) { | |
164 | + OrderBaseInfoVO orderBaseInfoVO = new OrderBaseInfoVO(); | |
165 | + OrderTrackStageVO orderTrackStageVO = new OrderTrackStageVO(); | |
166 | + OrderInspectionStageVO orderInspectionStageVO = new OrderInspectionStageVO(); | |
167 | + BeanUtil.copyProperties(x, orderBaseInfoVO); | |
168 | + BeanUtil.copyProperties(OrderInspectionStageMap.get(x.getId()), orderInspectionStageVO); | |
169 | + BeanUtil.copyProperties(OrderTrackStageMap.get(x.getId()), orderTrackStageVO); | |
170 | + orderEventJobVO.setOrderId(orderBaseInfoVO.getId()); | |
171 | + orderEventJobVO.setInspectionStageInfo(orderInspectionStageVO); | |
172 | + orderEventJobVO.setBaseInfo(orderBaseInfoVO); | |
173 | + orderEventJobVO.setTrackStageInfo(orderTrackStageVO); | |
174 | + } | |
175 | + return orderEventJobVO; | |
176 | + }).filter(Objects::nonNull) | |
177 | + .collect(Collectors.toList()); | |
178 | + return orderEventJobVOList; | |
382 | 179 | } |
383 | 180 | |
384 | 181 | /** |
... | ... | @@ -416,7 +213,25 @@ public class OrderOverTimeEventJob { |
416 | 213 | if (filterConfirmSampleOrderEvent(eventJobVO)) { |
417 | 214 | map.put(OrderEventEnum.CONFIRM_SAMPLE_EVENT.getEvent(), eventJobVO); |
418 | 215 | } |
419 | - // todo 其他订单超期事件判断 | |
216 | + if (filterOtherSampleEvent(eventJobVO)) { | |
217 | + map.put(OrderEventEnum.OTHER_SAMPLE_EVENT.getEvent(), eventJobVO); | |
218 | + } | |
219 | + if (filterBigSampleEvent(eventJobVO)) { | |
220 | + map.put(OrderEventEnum.BIG_SAMPLE_EVENT.getEvent(), eventJobVO); | |
221 | + } | |
222 | + if (filterAITEXSGSTestEvent(eventJobVO)) { | |
223 | + map.put(OrderEventEnum.AITEX_SGS_TEST_EVENT.getEvent(), eventJobVO); | |
224 | + } | |
225 | + if (filterBarcodeArrivalEvent(eventJobVO)) { | |
226 | + map.put(OrderEventEnum.BARCODE_ARRIVAL_EVENT.getEvent(), eventJobVO); | |
227 | + } | |
228 | + if (filterLatestDCEvent(eventJobVO)) { | |
229 | + map.put(OrderEventEnum.LATEST_DC_EVENT.getEvent(), eventJobVO); | |
230 | + } | |
231 | + if (filterEndCheckDateEvent(eventJobVO)) { | |
232 | + map.put(OrderEventEnum.END_CHECK_DATE_EVENT.getEvent(), eventJobVO); | |
233 | + } | |
234 | + // todo 其他订单超期事件判断 中期验货报告和尾期验货报告。 | |
420 | 235 | return map; |
421 | 236 | } |
422 | 237 | |
... | ... | @@ -427,8 +242,124 @@ public class OrderOverTimeEventJob { |
427 | 242 | private Boolean filterConfirmSampleOrderEvent(OrderEventJobVO eventJobVO) { |
428 | 243 | |
429 | 244 | // todo 判断是否未能在规定的期限内完成以下货号的确认样确认 |
245 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
246 | + String ppConfirmResult = eventJobVO.getTrackStageInfo().getPpConfirmResult(); | |
247 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(ppConfirmResult)) { | |
248 | + if (!ppConfirmResult.contains("ok") && org.apache.commons.lang3.StringUtils.countMatches(ppConfirmResult, "fail") == 3) { | |
249 | + return true; | |
250 | + } else if (ppConfirmResult.contains("ok") || org.apache.commons.lang3.StringUtils.countMatches(ppConfirmResult, "fail") < 3) { | |
251 | + String[] parats = ppConfirmResult.split("\\+"); | |
252 | + String lastTime = parats[parats.length - 3]; | |
253 | + LocalDate parse1 = LocalDate.parse(lastTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
254 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
255 | + long daysBetween = ChronoUnit.DAYS.between(parse1, parse2); | |
256 | + if (daysBetween == 21) { | |
257 | + return true; | |
258 | + } | |
259 | + } | |
260 | + } | |
261 | + return false; | |
262 | + } | |
263 | + | |
264 | + private Boolean filterOtherSampleEvent(OrderEventJobVO eventJobVO) { | |
265 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
266 | + String esoSampleSendTime = eventJobVO.getTrackStageInfo().getEsoSampleSendTime(); | |
267 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(esoSampleSendTime)) { | |
268 | + LocalDate parse1 = LocalDate.parse(esoSampleSendTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
269 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
270 | + if (ChronoUnit.DAYS.between(parse1, parse2) == 7) { | |
271 | + return true; | |
272 | + } | |
273 | + } | |
274 | + return false; | |
275 | + } | |
276 | + | |
277 | + private Boolean filterBigSampleEvent(OrderEventJobVO eventJobVO) { | |
278 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
279 | + String shippmentSampleConfirmResult = eventJobVO.getTrackStageInfo().getShippmentSampleConfirmResult(); | |
280 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(shippmentSampleConfirmResult)) { | |
281 | + if (!shippmentSampleConfirmResult.contains("ok") && org.apache.commons.lang3.StringUtils.countMatches(shippmentSampleConfirmResult, "fail") == 3) { | |
282 | + return true; | |
283 | + } else if (shippmentSampleConfirmResult.contains("ok") || org.apache.commons.lang3.StringUtils.countMatches(shippmentSampleConfirmResult, "fail") < 3) { | |
284 | + String[] parats = shippmentSampleConfirmResult.split("\\+"); | |
285 | + String lastTime = parats[parats.length - 3]; | |
286 | + LocalDate parse1 = LocalDate.parse(lastTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
287 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
288 | + long daysBetween = ChronoUnit.DAYS.between(parse1, parse2); | |
289 | + if (daysBetween == 7) { | |
290 | + return true; | |
291 | + } | |
292 | + } | |
293 | + } | |
294 | + return false; | |
295 | + } | |
296 | + | |
297 | + | |
298 | + private Boolean filterAITEXSGSTestEvent(OrderEventJobVO eventJobVO) { | |
299 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
300 | + String shippmentSampleConfirmResult = eventJobVO.getTrackStageInfo().getAitexTestFinishResult(); | |
301 | + String sgsTestFinishResult = eventJobVO.getTrackStageInfo().getSgsTestFinishResult(); | |
302 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(shippmentSampleConfirmResult) || | |
303 | + StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(sgsTestFinishResult)) { | |
304 | + if (!shippmentSampleConfirmResult.contains("ok") && org.apache.commons.lang3.StringUtils.countMatches(shippmentSampleConfirmResult, "fail") == 3 || | |
305 | + !shippmentSampleConfirmResult.contains("ok") && org.apache.commons.lang3.StringUtils.countMatches(sgsTestFinishResult, "fail") == 3) { | |
306 | + return true; | |
307 | + } else if ((shippmentSampleConfirmResult.contains("ok") || org.apache.commons.lang3.StringUtils.countMatches(shippmentSampleConfirmResult, "fail") < 3) || | |
308 | + (sgsTestFinishResult.contains("ok") || org.apache.commons.lang3.StringUtils.countMatches(sgsTestFinishResult, "fail") < 3)) { | |
309 | + String[] parats = shippmentSampleConfirmResult.split("\\+"); | |
310 | + String lastTime = parats[parats.length - 3]; | |
311 | + String[] parats1 = sgsTestFinishResult.split("\\+"); | |
312 | + String lastTime1 = parats1[parats1.length - 3]; | |
313 | + LocalDate parse1 = LocalDate.parse(lastTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
314 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
315 | + LocalDate parse3 = LocalDate.parse(lastTime1, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
316 | + long daysBetween = ChronoUnit.DAYS.between(parse1, parse2); | |
317 | + long daysBetween1 = ChronoUnit.DAYS.between(parse3, parse2); | |
318 | + if (daysBetween == 3 || daysBetween1 == 3) { | |
319 | + return true; | |
320 | + } | |
321 | + } | |
322 | + } | |
323 | + return false; | |
324 | + } | |
325 | + | |
430 | 326 | |
431 | - return true; | |
327 | + private Boolean filterBarcodeArrivalEvent(OrderEventJobVO eventJobVO) { | |
328 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
329 | + String lastArrivalTime = eventJobVO.getTrackStageInfo().getLatestArrivalTime(); | |
330 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(lastArrivalTime)) { | |
331 | + LocalDate parse1 = LocalDate.parse(lastArrivalTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
332 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
333 | + if (ChronoUnit.DAYS.between(parse1, parse2) == 7) { | |
334 | + return true; | |
335 | + } | |
336 | + } | |
337 | + return false; | |
432 | 338 | } |
433 | 339 | |
340 | + private Boolean filterLatestDCEvent(OrderEventJobVO eventJobVO) { | |
341 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
342 | + String latestBkTime = eventJobVO.getTrackStageInfo().getLatestBkTime(); | |
343 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(latestBkTime)) { | |
344 | + LocalDate parse1 = LocalDate.parse(latestBkTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
345 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
346 | + if (ChronoUnit.DAYS.between(parse1, parse2) == 10) { | |
347 | + return true; | |
348 | + } | |
349 | + } | |
350 | + return false; | |
351 | + } | |
352 | + | |
353 | + private Boolean filterEndCheckDateEvent(OrderEventJobVO eventJobVO) { | |
354 | + String orderHodTime = eventJobVO.getBaseInfo().getOrderHodTime(); | |
355 | + String endCheckApplyTime = eventJobVO.getInspectionStageInfo().getEndCheckApplyTime(); | |
356 | + if (StringUtils.isNotBlank(orderHodTime) && StringUtils.isNotBlank(endCheckApplyTime)) { | |
357 | + LocalDate parse1 = LocalDate.parse(endCheckApplyTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
358 | + LocalDate parse2 = LocalDate.parse(orderHodTime, DateTimeFormatter.ofPattern("yyyy-M-d")); | |
359 | + if (ChronoUnit.DAYS.between(parse1, parse2) == 2) { | |
360 | + return true; | |
361 | + } | |
362 | + } | |
363 | + return false; | |
364 | + } | |
434 | 365 | } | ... | ... |
src/main/java/com/order/erp/mapper/order/OrderBaseInfoMapper.java
... | ... | @@ -31,5 +31,7 @@ public interface OrderBaseInfoMapper extends BaseMapper<OrderBaseInfoDO> { |
31 | 31 | |
32 | 32 | List<QueryProjectNoAndInnerNoDto> queryProjectNoAndInnerNoDto(@Param("flag") Boolean flag, |
33 | 33 | @Param("dto") QueryProjectNoAndInnerNoDto dto); |
34 | + @Select("SELECT * FROM order_base_info WHERE order_status!=50 and enable_flag=10 and DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(create_time);") | |
35 | + List<OrderBaseInfoDO> getEventList(); | |
34 | 36 | } |
35 | 37 | ... | ... |
src/main/java/com/order/erp/service/order/OrderBaseInfoService.java
src/main/java/com/order/erp/service/order/impl/OrderBaseInfoServiceImpl.java
... | ... | @@ -1970,4 +1970,10 @@ public class OrderBaseInfoServiceImpl extends ServiceImpl<OrderBaseInfoMapper, O |
1970 | 1970 | } |
1971 | 1971 | return ServerResult.success(); |
1972 | 1972 | } |
1973 | + | |
1974 | + @Override | |
1975 | + public List<OrderBaseInfoDO> getEventList() { | |
1976 | + List<OrderBaseInfoDO> orderBaseInfoDOList= baseMapper.getEventList(); | |
1977 | + return orderBaseInfoDOList; | |
1978 | + } | |
1973 | 1979 | } | ... | ... |