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 implements IAndonOrderService { @Autowired private FeishuUserService feishuService; @Autowired private ISysUserService sysUserService; @Autowired private AndonResponseConfigMapper andonResponseConfigMapper; @Override public List 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 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 handleAndonOrder(AndonOrder andonOrder) { // 设置工单状态为处理中 andonOrder.setOrderStatus("3"); // 获取响应者用户名 String responderUsername = andonOrder.getResponder(); // 验证响应者用户名不为空 if (StringUtils.isBlank(responderUsername)) { return Result.error("响应者信息不能为空"); } // 根据用户名查询用户信息 SysUser sysUser = sysUserService.getOne( new QueryWrapper().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("处理成功"); } }