CZT
2023-10-11 564295458c720206db9b5194b90481b711f4b010
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
package com.ld.igds.warn;
 
import com.bstek.bdf2.core.model.DefaultUser;
import com.ld.igds.common.CoreCommonService;
import com.ld.igds.common.mapper.CommonMapper;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.WarnLevel;
import com.ld.igds.constant.WarnStatus;
import com.ld.igds.constant.WarnType;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DepotConf;
import com.ld.igds.models.Grain;
import com.ld.igds.models.MWarnConf;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.warn.data.WarnData;
import com.ld.igds.warn.service.CoreWarnService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 警告工具类
 *
 * @author: chen
 * @description:
 * @version:
 * @data:2021年12月06日
 */
@Service(WarnUtils.BEAN_ID)
@Slf4j
public class WarnUtils {
 
    public static final String BEAN_ID = "core.warnUtils";
 
    //出入库推送微信接口编码
    public static final String WECHAT_WARN_1007 = "1007";
    //警告推送微信接口编码
    public static final String WECHAT_WARN_1008 = "1008";
    //工单推送微信接口
    public static final String WECHAT_WARN_1011 = "1011";
 
    @Autowired
    private CoreCommonService commonService;
    @Autowired
    private CoreWarnService coreWarnService;
    @Autowired
    private CommonMapper commonMapper;
 
    /**
     * 根据警告配置获取通知人
     *
     * @param conf
     * @return
     */
    public List<DefaultUser> getWarnUserByWarnConf(MWarnConf conf, String depotId) {
        if(null == conf){
            return null;
        }
 
        //获取仓库信息,用于下面获取保管员
        Depot depot = commonService.getCacheDepot(conf.getCompanyId(), depotId);
 
        // 根据警告配置获取通知人
        List<String> listUser = new ArrayList<>();
        if (StringUtils.isNotEmpty(conf.getUser1())) listUser.add(conf.getUser1());
        if (StringUtils.isNotEmpty(conf.getUser2())) listUser.add(conf.getUser2());
        if (StringUtils.isNotEmpty(conf.getUser3())) listUser.add(conf.getUser3());
        if (StringUtils.isNotEmpty(conf.getUser4())) listUser.add(conf.getUser4());
        if (StringUtils.isNotEmpty(conf.getUser5())) listUser.add(conf.getUser5());
        if (null !=depot && Constant.YN_Y.equals(conf.getKeeperTag())
                && StringUtils.isNotEmpty(depot.getStoreKeeper())){
            listUser.add(depot.getStoreKeeper());
        }
 
        return commonMapper.getUserByList(conf.getCompanyId(), listUser);
    }
 
    /**
     * 设置微信通知人等信息
     * @param warnData
     * @param users
     * @return
     */
    public WarnData setPhoneByWeChat(WarnData warnData, List<DefaultUser> users) {
        if (users.size() > 0) {
            warnData.setNoticeUser("");
            warnData.setPhone("");
            for (DefaultUser defaultUser : users) {
                if (StringUtils.isEmpty(defaultUser.getMobile())){
                    continue;
                }
                warnData.setNoticeUser(defaultUser.getUsername() + "," + warnData.getNoticeUser());
                warnData.setPhone(defaultUser.getMobile() + "," + warnData.getPhone());
            }
        }
        return warnData;
    }
 
    /**
     * 增加粮情高温记录
     * @param depotConf
     * @param grain
     */
    public void addGrainWarn(DepotConf depotConf, Grain grain){
        //获取仓库信息
        Depot depot = commonService.getCacheDepot(depotConf.getCompanyId(), depotConf.getDepotId());
        if(null == depot){
            log.error("-----未获取到仓库信息,不生成警告-----");
            return;
        }
        WarnData warn = new WarnData();
        warn.setId(ContextUtil.getUUID());
        warn.setCompanyId(depot.getCompanyId());
        warn.setDeptId(depot.getDeptId());
        warn.setDepotId(depot.getId());
        warn.setDepotName(depot.getName());
 
        warn.setName("粮情高温警告");
        warn.setType(WarnType.TYPE_01.getCode());
        warn.setLevel(WarnLevel.LEVEL_01.getCode());
        warn.setTime(grain.getReceiveDate());
        warn.setBizType(Constant.MODEL_GRAIN);
        warn.setStatus(WarnStatus.STATUS_10.getCode());
 
        String info = depot.getName() + "出现粮情高温警告,设定高温:" + depotConf.getTempMax()
                + ", 当前检测高温:" + grain.getTempMax() + ",检测时间:" +
                DateFormatUtils.format(grain.getReceiveDate(),"yyyy-MM-dd HH:mm:ss");
        warn.setInfo(info);
 
        coreWarnService.addWarnAndNotice(warn);
    }
}