lyfO_o
2021-06-11 8655d933a18c437f068659c91a84aaaaef7ad8bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.nanometer.smartlab.email;
 
import com.nanometer.smartlab.entity.EmailStatus;
import com.nanometer.smartlab.entity.OpeWarehouseReserve;
import com.nanometer.smartlab.entity.SysReagent;
import com.nanometer.smartlab.entity.enumtype.EmailSendStatus;
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.service.*;
import com.nanometer.smartlab.util.EmailSend;
import org.apache.log4j.Logger;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * Created by wjd on 18/6/18.
 */
@Component
public class EmailSendSchedule {
    @Lazy
    @Resource
    private OpeOrderService opeOrderService;
 
    private static Logger logger = Logger.getLogger(EmailSendSchedule.class);
 
    @Resource
    private SysReagentService sysReagentService;
    @Resource
    private OpeWarehouseReserveService opeWarehouseReserveService;
    @Resource
    private SysUserService userService;
 
    @Scheduled(fixedDelayString = "${emailSend.schedule.delay}")
    public void EmailSendSchedule(){
 
        List<EmailStatus> list = null;
        try {
            int count = this.opeOrderService.getUnsendEmailCount();
            if (count > 0) {
                list = opeOrderService.getUnsendEmailList();
            }
        } catch (Exception e) {
            logger.error(e);
        }
 
        if(list != null){
 
            for (EmailStatus email: list) {
                try {
                    EmailSend.send(email.getEmailAddress(), email.getApplyCode());
                    //  发送成功,更新邮件发送状态为:已发送
                    email.setStatus(EmailSendStatus.SEND_SUCCESS);
                    this.opeOrderService.updateEmailStatus(email);
                } catch (BusinessException e) {
                    //  发送失败,更新邮件发送状态为:发送失败
                    email.setStatus(EmailSendStatus.SEND_FAIL);
                    this.opeOrderService.updateEmailStatus(email);
                    logger.warn("操作失败。", e);
                } catch (Exception e) {
                    logger.error(e);
                }
            }
        }
    }
 
 
//        @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次
    @Scheduled(cron = "0 0 8 * * ?")//每天8点执行一次
    public void EmailSendStock(){
        //收件人为人员角色为库管员的邮箱
        List<String> revicerList = userService.getLibrarianEmail();
        //先查试剂表 安全库存大于0,然后去查库存,实际库存小于安全库存的列表
        List<SysReagent> sysReagentList = new ArrayList<>();
        //已经填写安全库存的试剂
        List<SysReagent> alreadyFillIn = sysReagentService.selectReagentSafetyNum();
        if (alreadyFillIn.size() > 0) {
            for (SysReagent reagent : alreadyFillIn) {
                int actualNum = opeWarehouseReserveService.countByReagentId(reagent.getId());
                if (reagent.getSafetynum() > actualNum) {
                    reagent.setActualnum(actualNum);
                    sysReagentList.add(reagent);
                }
            }
        }
        StringBuffer content = new StringBuffer("<html><body>");
        content.append("<div style=\"line-height:1.7;color:#000000;font-size:14px;font-family:Arial\">");
        content.append("<table border=\"1\">");
        content.append("<tbody>");
        content.append("<tr>");
        content.append("<th>试剂名称</th>");
        content.append("<th>产品编号</th>");
        content.append("<th>CAS</th>");
        content.append("<th>试剂类型</th>");
        content.append("<th>供应商</th>");
        content.append("<th>厂家</th>");
        content.append("<th>规格</th>");
        content.append("<th>包装</th>");
        content.append("<th>安全库存</th>");
        content.append("<th>实际库存</th>");
        content.append("</tr>");
        for (SysReagent sysReagent : sysReagentList){
            content.append("<tr>");
            content.append("<td>"+sysReagent.getName()+"</td>");
            content.append("<td>"+sysReagent.getProductSn()+"</td>");
            content.append("<td>"+sysReagent.getCas()+"</td>");
 
            content.append("<td>"+sysReagent.getReagentType()+"</td>");//
            content.append("<td>"+sysReagent.getSupplierName()+"</td>");
 
            content.append("<td>"+sysReagent.getProductHomeName()+"</td>");
 
            content.append("<td>"+sysReagent.getReagentFormat()+"</td>");//
 
            content.append("<td>"+sysReagent.getReagentUnit()+"</td>");//
            content.append("<td>"+sysReagent.getSafetynum()+"</td>");
            content.append("<td>"+sysReagent.getActualnum()+"</td>");
            content.append("</tr>");
        }
        content.append("</tbody></table></div>");
        content.append("</body></html>");
 
        try {
            EmailSend.sendArrivalEmail(revicerList,content.toString());
            //  发送成功,更新邮件发送状态为:已发送
        } catch (BusinessException e) {
            //  发送失败,更新邮件发送状态为:发送失败
            logger.warn("操作失败。", e);
        } catch (Exception e) {
            logger.error(e);
        }
    }
 
 
 
}