新火炬后端单体项目初始化代码
zhangherong
2 天以前 182c04e399f5db26406234767f7ef34b5adc0015
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
package org.jeecg.modules.andon.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.andon.entity.AndonResponseConfig;
import org.jeecg.modules.andon.mapper.AndonResponseConfigMapper;
import org.jeecg.modules.andon.service.IAndonOrderService;
import org.jeecg.modules.andon.entity.AndonOrder;
import org.jeecg.modules.andon.mapper.AndonOrderMapper;
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.List;
 
/**
 * @Description: 安灯工单
 * @Author: jeecg-boot
 * @Date: 2025-07-10
 * @Version: V1.0
 */
@Service
public class AndonOrderServiceImpl extends ServiceImpl<AndonOrderMapper, AndonOrder> implements IAndonOrderService {
    @Autowired
    private FeishuUserService feishuService;
    @Autowired
    private ISysUserService sysUserService;
 
    @Autowired
    private AndonResponseConfigMapper andonResponseConfigMapper;
 
    @Override
    public List<AndonOrder> getAndonOrdersExceptYWC() {
        return baseMapper.getAndonOrdersExceptYWC();
    }
 
    @Override
    public String getPrimaryResponder(AndonOrder andonOrder) {
        // 1. 校验必要参数
        if (StringUtils.isBlank(andonOrder.getFactoryId()) || StringUtils.isBlank(andonOrder.getButtonId())) {
 
            return null;
        }
 
        // 2. 查询响应人配置(假设存在响应人配置实体和Mapper)
        // 构建查询条件:匹配产线ID、安灯类型ID,且配置为启用状态
        QueryWrapper<AndonResponseConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("factory_id", andonOrder.getFactoryId())
                .eq("button_id", andonOrder.getButtonId())
                .eq("status", 1) // 1表示启用状态
                .last("limit 1"); // 只取一条有效配置
 
        // 3. 执行查询
        AndonResponseConfig config = andonResponseConfigMapper.selectOne(queryWrapper);
        if (config == null) {
            return null;
        }
        return config.getFirsterResponder();
    }
 
    @Override
    public Result<String> handleAndonOrder(AndonOrder andonOrder) {
 
        // 设置工单状态为处理中
        andonOrder.setOrderStatus("3");
 
        // 获取响应者用户名
        String responderUsername = andonOrder.getResponder();
 
        // 验证响应者用户名不为空
        if (StringUtils.isBlank(responderUsername)) {
            return Result.error("响应者信息不能为空");
        }
 
        // 根据用户名查询用户信息
        SysUser sysUser = sysUserService.getOne(
                new QueryWrapper<SysUser>().eq("username", responderUsername)
        );
 
        // 验证用户是否存在
        if (sysUser == null) {
            return Result.error("找不到用户名为 " + responderUsername + " 的用户");
        }
        // 设置响应者ID
        andonOrder.setResponder(sysUser.getId());
        andonOrder.setProcessor(sysUser.getId());
        // 更新工单信息
        this.updateById(andonOrder);
 
        return Result.OK("处理成功");
    }
 
}