Lius
2024-02-29 abf0df941bc5e1b77420234b0b3a33e515e390a3
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcEquipmentServiceImpl.java
@@ -6,7 +6,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.dto.message.MessageDTO;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.mdc.dto.MdcEquDepDto;
import org.jeecg.modules.mdc.dto.MdcEquProDto;
@@ -19,17 +22,17 @@
import org.jeecg.modules.mdc.util.DateUtils;
import org.jeecg.modules.mdc.util.FindsEquipmentDepartUtil;
import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
import org.jeecg.modules.mdc.vo.*;
import org.jeecg.modules.mdc.vo.MdcEquipmentDepVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentProVo;
import org.jeecg.modules.mdc.vo.MdcEquipmentVo;
import org.jeecg.modules.mdc.vo.WorkshopEquipmentVo;
import org.jeecg.modules.system.entity.MdcEquipmentDepart;
import org.jeecg.modules.system.entity.MdcProduction;
import org.jeecg.modules.system.entity.MdcProductionEquipment;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.mapper.MdcEquipmentDepartMapper;
import org.jeecg.modules.system.mapper.MdcProductionEquipmentMapper;
import org.jeecg.modules.system.service.IMdcProductionService;
import org.jeecg.modules.system.service.IMdcUserProductionService;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserDepartService;
import org.jeecg.modules.system.service.*;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -77,6 +80,16 @@
    @Resource
    private IEquipmentBaseInfoService equipmentBaseInfoService;
    @Resource
    private ISysDictService sysDictService;
    @Resource
    private ISysBaseAPI sysBaseApi;
    @Resource
    private IMdcAlarmInfoService mdcAlarmInfoService;
    @Override
    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -359,7 +372,8 @@
        mdcEquipmentDto.setDataFlag(Integer.parseInt(CommonConstant.STATUS_1));
        ControlSystem controlSystem = controlSystemService.getByDriveType(mdcEquipmentDto.getDriveType());
        // 查询设备状态
        Integer oporation = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
        EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId());
        Integer oporation = equipmentLog.getOporation();
        if (controlSystem != null) {
            //获取工作数据并初始化
@@ -429,6 +443,21 @@
                                value = String.valueOf(mdcTorqueConfig.getTorqueValue());
                            } else {
                                value = "0";
                            }
                        } else if ("alarm".equals(englishName)) {
                            if (oporation == 22) {
                                value = equipmentLog.getAlarm();
                            } else {
                                value = "无";
                            }
                        }  else if ("alarmContent".equals(englishName)) {
                            if (oporation == 22) {
                                List<MdcAlarmInfo> mdcAlarmInfo = mdcAlarmInfoService.list(new LambdaQueryWrapper<MdcAlarmInfo>().eq(MdcAlarmInfo::getDriveType, mdcEquipment.getDriveType()).eq(MdcAlarmInfo::getAlarmCode, equipmentLog.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0));
                                if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) {
                                    value = mdcAlarmInfo.get(0).getAlarmContent();
                                }
                            } else {
                                value = "无";
                            }
                        } else {
                            value = result == null ? null : result.toString();
@@ -697,7 +726,84 @@
    @Override
    public IPage<MdcEquipment> pageList(Page<MdcEquipment> page, MdcEquipmentVo mdcEquipment, HttpServletRequest req) {
        if (StringUtils.isNotBlank(mdcEquipment.getProductionName())) {
            // 递归查询所有子节点
            List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
            mdcEquipment.setProductionIds(productionIds);
        }
        return this.baseMapper.pageList(page, mdcEquipment);
    }
    /**
     * 监控设备转速任务
     */
    @Override
    public void monitoringSpeedProcess() {
        List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getDriveType, "FANUC"));
        //List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
        // 获取字典数据
        List<DictModel> dictModelList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_OPERATING_SPEED_RANGE);
        Integer range = 0;
        if (dictModelList != null && !dictModelList.isEmpty()) {
            range = Integer.valueOf(dictModelList.get(0).getValue());
        }
        for (MdcEquipment mdcEquipment : equipmentList) {
            String saveTableName = mdcEquipment.getSaveTableName();
            //查询单表数据
            MdcEquipmentDto mdcEquipmentDto = this.baseMapper.getWorkLineLast(saveTableName);
            if (mdcEquipmentDto != null) {
                MessageDTO messageDTO = new MessageDTO();
                messageDTO.setTitle("设备运行转速报警!");
                messageDTO.setCategory("预警消息");
                messageDTO.setFromUser("admin");
                messageDTO.setToUser("admin");
                Integer spindlespeed = Integer.valueOf(mdcEquipmentDto.getSpindlespeed());
                Integer actualspindlespeed = Integer.valueOf(mdcEquipmentDto.getActualspindlespeed());
                if (range.equals(0)) {
                    if (spindlespeed > actualspindlespeed) {
                        // 实际值大于设定值   高
                        messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速高报警!");
                        sysBaseApi.sendSysAnnouncement(messageDTO);
                    } else if (spindlespeed < actualspindlespeed) {
                        // 实际值小于设定值   低
                        messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速低报警!");
                        sysBaseApi.sendSysAnnouncement(messageDTO);
                    }
                } else {
                    int max = actualspindlespeed + actualspindlespeed * (range / 100);
                    int min = actualspindlespeed - actualspindlespeed * (range / 100);
                    if (spindlespeed > max || spindlespeed < min) {
                        if (spindlespeed > actualspindlespeed) {
                            // 实际值大于设定值   高
                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速高报警!");
                            sysBaseApi.sendSysAnnouncement(messageDTO);
                        } else if (spindlespeed < actualspindlespeed) {
                            // 实际值小于设定值   低
                            messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备运行转速低报警!");
                            sysBaseApi.sendSysAnnouncement(messageDTO);
                        }
                    }
                }
            }
        }
    }
    /**
     * 导出list
     *
     * @param mdcEquipment
     * @return
     */
    @Override
    public List<MdcEquipment> exportXlsList(MdcEquipmentVo mdcEquipment) {
        if (StringUtils.isNotBlank(mdcEquipment.getProductionName())) {
            // 递归查询所有子节点
            List<String> productionIds = mdcProductionService.recursionChildren(mdcEquipment.getProductionName());
            mdcEquipment.setProductionIds(productionIds);
        }
        return this.baseMapper.exportXlsList(mdcEquipment);
    }
}