Lius
2024-01-17 cf89583e4dd54632a0f11c06b859315c03958820
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,22 +22,23 @@
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;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
@@ -73,6 +77,16 @@
    @Resource
    private IEquipmentLogService equipmentLogService;
    @Resource
    private IEquipmentBaseInfoService equipmentBaseInfoService;
    @Resource
    private ISysDictService sysDictService;
    @Resource
    private ISysBaseAPI sysBaseApi;
    @Override
    public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
@@ -393,15 +407,23 @@
                        if ("CollectTime".equals(englishName)) {
                            Date date = result == null ? null : (Date) result;
                            value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL);
                        } else {
                            value = result == null ? null : result.toString();
                        }
                        // ZUOLAN设备电流字段AI01
                        if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "AI01".equals(englishName) && oporation == 3) {
                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "AI01".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备电流字段AI01
                            value = BigDecimal.valueOf(Math.random() * 15 + 0).setScale(1, RoundingMode.HALF_UP).toString();
                        }
                        // 其他设备电流字段
                        if ("spindle_current".equals(englishName)) {
                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备主轴转速字段spindlespeed
                            value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备主轴负荷字段spindleload
                            value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备主轴倍率字段spindlebeilv
                            value = String.valueOf((new Random().nextInt(13)) * 10);
                        } else if ("ZUOLAN".equals(mdcEquipment.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
                            // ZUOLAN设备进给倍率字段feedbeilv
                            value = String.valueOf((new Random().nextInt(13)) * 10);
                        } else if ("spindle_current".equals(englishName)) {
                            // 其他设备电流字段
                            String devicePower = mdcEquipment.getDevicePower();
                            Object spindleload = jsonObject.get("spindleload");
                            BigDecimal load = spindleload == null ? BigDecimal.ZERO : new BigDecimal(spindleload.toString());
@@ -410,19 +432,25 @@
                            } else {
                                value = "0";
                            }
                        }
                        // 扭矩字段
                        if ("torque".equals(englishName)) {
                        } else if ("torque".equals(englishName)) {
                            // 扭矩字段
                            MdcTorqueConfig mdcTorqueConfig = mdcTorqueConfigMapper.findLast(mdcEquipment.getEquipmentId());
                            if (mdcTorqueConfig != null) {
                                value = String.valueOf(mdcTorqueConfig.getTorqueValue());
                            } else {
                                value = "0";
                            }
                        } else {
                            value = result == null ? null : result.toString();
                        }
                        mdcDriveTypeParamConfig.setValue(value);
                    }
                    mdcEquipmentDto.setMdcDriveTypeParamConfigList(mdcDriveTypeParamList);
                }
                EquipmentBaseInfo equipmentBaseInfo = equipmentBaseInfoService.getByEquipmentId(mdcEquipment.getEquipmentId());
                if (equipmentBaseInfo != null) {
                    mdcEquipmentDto.setMaxAxis(equipmentBaseInfo.getMaxAxis());
                    mdcEquipmentDto.setValidAxis(equipmentBaseInfo.getValidAxis());
                }
            }
        }
@@ -677,4 +705,65 @@
        return list.stream().map(MdcEquipment::getEquipmentId).collect(Collectors.toList());
    }
    @Override
    public IPage<MdcEquipment> pageList(Page<MdcEquipment> page, MdcEquipmentVo mdcEquipment, HttpServletRequest req) {
        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);
                        }
                    }
                }
            }
        }
    }
}