新火炬后端单体项目初始化代码
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package org.jeecg.modules.andon.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.jeecg.modules.andon.dto.AndonButtonDTO;
import org.jeecg.modules.andon.entity.AndonButtonConfig;
import org.jeecg.modules.andon.entity.AndonOrder;
import org.jeecg.modules.andon.entity.AndonResponseConfig;
import org.jeecg.modules.andon.mapper.AndonResponseConfigMapper;
import org.jeecg.modules.andon.service.IAndonButtonConfigService;
import org.jeecg.modules.andon.service.IAndonOrderService;
import org.jeecg.modules.andon.service.IAndonResponseConfigService;
import org.jeecg.modules.base.entity.Factory;
import org.jeecg.modules.base.service.IFactoryService;
import org.jeecg.modules.feishu.service.FeishuUserService;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.Collections;
import java.util.List;
 
/**
 * @Description: 安灯响应配置
 * @Author: jeecg-boot
 * @Date: 2025-07-10
 * @Version: V1.0
 */
@Service
public class AndonResponseConfigServiceImpl extends ServiceImpl<AndonResponseConfigMapper, AndonResponseConfig> implements IAndonResponseConfigService {
    @Autowired
    private IFactoryService factoryService;
 
    @Autowired
    private ISysUserService iSysUserService;
 
    @Autowired
    private FeishuUserService feishuUserService;
    @Autowired
    private IAndonButtonConfigService andonButtonConfigService;
 
    @Autowired
    private IAndonOrderService andonOrderService;
 
    @Override
    public AndonResponseConfig getAndonResponseConfigByFactoryIdAndButtonId(String factoryId, String buttonId) {
        return baseMapper.getAndonResponseConfigByFactoryIdAndButtonId(factoryId, buttonId);
    }
 
    @Override
    public List<AndonButtonDTO> queryAndonButtonList(String factoryId) {
        return Collections.emptyList();
    }
 
    @Override
    public void sendAndonNotification(AndonButtonDTO andonButtonDTO) {
        /**
         * 1. 验证工单状态
         */
        if (andonButtonDTO == null) {
            log.warn("请求参数为空");
            throw new IllegalArgumentException("请求参数不能为空");
        }
        /**
         * 2. 获取响应配置
         */
        AndonResponseConfig andonResponseConfig = this.getById(andonButtonDTO.getId());
 
        AndonOrder andonOrder = andonOrderService.getById(andonButtonDTO.getOrderIds());
        if (andonOrder == null) {
            log.warn("未找到ID为[{}]的安灯订单");
            throw new IllegalArgumentException("未找到对应的安灯订单");
        }
        String orderStatus = andonOrder.getOrderStatus();
        andonButtonDTO.setOrderStatus(orderStatus);
        if (andonResponseConfig == null) {
            log.warn("未找到ID为[{}]的响应配置");
            throw new IllegalArgumentException("未找到对应的响应配置");
        }
        /**
         * 3. 设置二级响应人
         */
        String secondResponder = andonResponseConfig.getSecondResponder();
        if (StringUtils.isNotBlank(secondResponder)) {
            andonButtonDTO.setSecondResponder(secondResponder);
        }
 
        /**
         * 4. 获取工厂信息
         */
 
        String factoryId = andonResponseConfig.getFactoryId();
        if (factoryId == null || factoryId.isEmpty()) {
            log.warn("响应配置[{}]未设置工厂ID");
            throw new IllegalArgumentException("响应配置未设置工厂信息");
        }
 
        Factory factory = factoryService.getOne(new QueryWrapper<Factory>()
                .eq("id", factoryId)
                .eq("del_flag", 0));
 
        if (factory == null) {
            log.warn("未找到ID为[{}]的工厂");
            throw new IllegalArgumentException("未找到对应的工厂信息");
        }
 
        /**
         * 获取产线名称
         */
        String factoryName = factory.getFactoryName();
        andonButtonDTO.setFactoryName(factoryName);
        /**
         * 6. 设置工厂名称
         */
        String parentId = factory.getParentId();
        if (parentId != null && !parentId.isEmpty()) {
            Factory parentFactory = factoryService.getOne(new QueryWrapper<Factory>()
                    .eq("id", parentId)
                    .eq("del_flag", 0));
            if (parentFactory != null) {
                andonButtonDTO.setParentFactoryName(parentFactory.getFactoryName());
            }
        }
        /**
         * 6. 获取安灯按钮配置
         */
        AndonButtonConfig andonButtonById = andonButtonConfigService.getAndonButtonById(andonButtonDTO.getButtonId());
        if (andonButtonById == null) {
            log.warn("未找到ID为[{}]的安灯按钮");
            throw new IllegalArgumentException("未找到对应的安灯按钮信息");
        }
        /**
         * 7. 设置响应时间
         */
        Integer upgradeResponseDuration = andonButtonById.getUpgradeResponseDuration();
        andonButtonDTO.setUpgradeResponseDuration(upgradeResponseDuration);
 
        Integer secondUpgradeResponseDuration = andonButtonById.getSecondUpgradeResponseDuration();
        andonButtonDTO.setSecondUpgradeResponseDuration(secondUpgradeResponseDuration);
 
        /**
         * 8. 获取响应人信息
         */
        String firstResponder = andonResponseConfig.getFirsterResponder();
        String threeResponder = andonResponseConfig.getThirdResponder();
        SysUser thirdUser = iSysUserService.getUserByName(threeResponder);
        SysUser userByName = iSysUserService.getUserByName(firstResponder);
        SysUser secondUser = null;
 
        if (StringUtils.isNotBlank(secondResponder)) {
            secondUser = iSysUserService.getUserByName(secondResponder);
        }
        /**
         * 9. 验证并设置响应人信息
         */
 
        if (userByName == null) {
            log.warn("用户[{}]未找到,无法发送通知");
            throw new IllegalArgumentException("用户[{}]未找到,无法发送通知");
        }
 
        if (secondUser == null && StringUtils.isNotBlank(secondResponder)) {
            log.warn("用户[{}]未找到,无法发送通知");
            throw new IllegalArgumentException("用户[{}]未找到,无法发送通知");
        }
 
        if (threeResponder == null) {
            StringUtils.isNotBlank(null);
        }
        //
        /**
         * 10. 设置响应人相关信息
         */
 
        andonButtonDTO.setResponderOpenId(userByName.getOpenId());
        andonButtonDTO.setResponder(userByName.getRealname());
        log.warn("用户[{}]已找到,开始发送通知");
 
        if (secondUser != null) {
            andonButtonDTO.setSecondResponderOpenId(secondUser.getOpenId());
            andonButtonDTO.setSecondResponder(secondUser.getRealname());
            log.warn("用户[{}]已找到,开始发送通知");
        }
        if (thirdUser != null) {
            andonButtonDTO.setThirdResponderOpenId(thirdUser.getOpenId());
            andonButtonDTO.setThirdResponder(thirdUser.getRealname());
            log.warn("用户[{}]已找到,开始发送通知");
        }
 
        /**
         *  11. 发送飞书通知
         */
        if (StringUtils.isNotBlank(firstResponder)) {
            String feishuAccessToken = feishuUserService.getFeishuAccessToken();
            feishuUserService.sendAndonNotification(feishuAccessToken, andonButtonDTO);
        } else {
            log.warn("工单[{}]未找到对应响应人,无法发送通知");
        }
    }
 
 
}