新火炬后端单体项目初始化代码
src/main/java/org/jeecg/modules/andon/service/impl/AndonResponseConfigServiceImpl.java
@@ -1,10 +1,26 @@
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: 安灯响应配置
@@ -14,9 +30,175 @@
 */
@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("工单[{}]未找到对应响应人,无法发送通知");
        }
    }
}