| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.base.CaseFormat; |
| | | 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.EquipmentTemperatureDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquDepDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquProDto; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentMapper; |
| | | import org.jeecg.modules.mdc.mapper.XYZAliasesMapper; |
| | | import org.jeecg.modules.mdc.mapper.MdcTorqueConfigMapper; |
| | | import org.jeecg.modules.mdc.model.MdcEquipmentTree; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | |
| | | 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.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | |
| | | @Resource |
| | | private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService; |
| | | @Resource |
| | | private XYZAliasesMapper xyzAliasesMapper; |
| | | private MdcTorqueConfigMapper mdcTorqueConfigMapper; |
| | | |
| | | @Resource |
| | | private IEquipmentXYZService equipmentXYZService; |
| | | private IEquipmentLogService equipmentLogService; |
| | | |
| | | @Resource |
| | | private IEquipmentBaseInfoService equipmentBaseInfoService; |
| | | |
| | | @Resource |
| | | private IEquipmentTemperatureService equipmentTemperatureService; |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Resource |
| | | private ISysBaseAPI sysBaseApi; |
| | | |
| | | |
| | | @Override |
| | | public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) { |
| | |
| | | mdcEquipmentDto.setDevicePower(mdcEquipment.getDevicePower()); |
| | | mdcEquipmentDto.setDeviceType(mdcEquipment.getDriveType()); |
| | | mdcEquipmentDto.setRemark(mdcEquipment.getRemark()); |
| | | mdcEquipmentDto.setEquipmentID(mdcEquipment.getEquipmentId());//设备编号 |
| | | //设备编号 |
| | | mdcEquipmentDto.setEquipmentID(mdcEquipment.getEquipmentId()); |
| | | mdcEquipmentDto.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | mdcEquipmentDto.setEquipmentIP(mdcEquipment.getEquipmentIp()); |
| | | mdcEquipmentDto.setEquipmentModel(mdcEquipment.getEquipmentModel());//设备型号 |
| | | //设备型号 |
| | | mdcEquipmentDto.setEquipmentModel(mdcEquipment.getEquipmentModel()); |
| | | mdcEquipmentDto.setDriveType(mdcEquipment.getDriveType()); |
| | | mdcEquipmentDto.setDataPort(mdcEquipment.getDataPort()); |
| | | mdcEquipmentDto.setDataFlag(Integer.parseInt(CommonConstant.STATUS_1)); |
| | | ControlSystem controlSystem = controlSystemService.getByDriveType(mdcEquipmentDto.getDriveType()); |
| | | // 查询设备状态 |
| | | Integer oporation = equipmentLogService.selectEquipmentOporation(mdcEquipment.getEquipmentId()); |
| | | |
| | | if (controlSystem != null) { |
| | | //获取工作数据并初始化 |
| | | String saveTableName = mdcEquipment.getSaveTableName(); |
| | |
| | | mdcEquipmentDto.setSequencenumber(dto.getSequencenumber()); |
| | | mdcEquipmentDto.setExecutingcode(dto.getExecutingcode()); |
| | | mdcEquipmentDto.setProductName(dto.getProductName()); |
| | | if ("LSV2".equals(mdcEquipment.getDriveType())) { |
| | | mdcEquipmentDto.setSpindlebeilv(dto.getSFeed()); |
| | | mdcEquipmentDto.setFeedbeilv(dto.getFFeed()); |
| | | mdcEquipmentDto.setRapidfeed(dto.getRapidfeed()); |
| | | mdcEquipmentDto.setNCVersion(dto.getNCVersion()); |
| | | mdcEquipmentDto.setTNCVersion(dto.getTNCVersion()); |
| | | mdcEquipmentDto.setOPTVersion(dto.getOPTVersion()); |
| | | mdcEquipmentDto.setPLCVersion(dto.getPLCVersion()); |
| | | } |
| | | |
| | | //获取 MDC 驱动对应的展示参数 并根据key 拼装从 workData 查询的数据 |
| | | List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(mdcEquipment.getDriveType()); |
| | |
| | | if ("CollectTime".equals(englishName)) { |
| | | Date date = result == null ? null : (Date) result; |
| | | value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL); |
| | | } 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(); |
| | | } 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()); |
| | | if (StringUtils.isNotEmpty(devicePower) && oporation == 3) { |
| | | value = new BigDecimal(devicePower).divide(new BigDecimal("380"), 2, BigDecimal.ROUND_HALF_UP).add(load).toString(); |
| | | } else { |
| | | value = "0"; |
| | | } |
| | | } 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(); |
| | | } |
| | |
| | | } |
| | | mdcEquipmentDto.setMdcDriveTypeParamConfigList(mdcDriveTypeParamList); |
| | | } |
| | | EquipmentBaseInfo equipmentBaseInfo = equipmentBaseInfoService.getByEquipmentId(mdcEquipment.getEquipmentId()); |
| | | if (equipmentBaseInfo != null) { |
| | | mdcEquipmentDto.setMaxAxis(equipmentBaseInfo.getMaxAxis()); |
| | | mdcEquipmentDto.setValidAxis(equipmentBaseInfo.getValidAxis()); |
| | | } |
| | | } |
| | | // // 设备坐标数 获取设备需要采集的坐标信息 |
| | | // List<XYZAliases> equipmentCoordinateList = xyzAliasesMapper.getCoordinateByEquipmentId(mdcEquipment.getEquipmentId()); |
| | | // // 设备采集的坐标信息 |
| | | // EquipmentXYZ equipmentXYZ = equipmentXYZService.getByEquipmentId(mdcEquipment.getEquipmentId()); |
| | | // JSONObject jsonEquipmentXYZ = (JSONObject) JSONObject.toJSON(equipmentXYZ); |
| | | // if (equipmentCoordinateList != null && !equipmentCoordinateList.isEmpty()) { |
| | | // for (XYZAliases xyzAliases : equipmentCoordinateList) { |
| | | // String englishName = xyzAliases.getXYZFieldName().toLowerCase(); |
| | | // englishName = englishName.substring(0, 1) + "_" + englishName.substring(1, englishName.length()); |
| | | // englishName = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, englishName); |
| | | // Object orgValue = jsonEquipmentXYZ.get(englishName); |
| | | // String value = orgValue != null ? orgValue.toString() : null; |
| | | // // 坐标数据的title 来自 xyzAliases 表, 根据 是否包含 absolute 和 machine 判断是绝对坐标还是机床坐标 |
| | | // String title = englishName.substring(0, 1).toUpperCase(); |
| | | // title = englishName.contains("absolute") ? "绝对坐标" + title : "机床坐标" + title; |
| | | // xyzAliases.setTitle(title); |
| | | // xyzAliases.setValue(value); |
| | | // } |
| | | // mdcEquipmentDto.setXyzAliasesList(equipmentCoordinateList); |
| | | // } |
| | | |
| | | // if (equipmentXYZ != null) { |
| | | // mdcEquipmentDto.setXmachine(equipmentXYZ.getXMachine()); |
| | | // mdcEquipmentDto.setYmachine(equipmentXYZ.getYMachine()); |
| | | // mdcEquipmentDto.setZmachine(equipmentXYZ.getZMachine()); |
| | | // mdcEquipmentDto.setAmachine(equipmentXYZ.getAMachine()); |
| | | // mdcEquipmentDto.setBmachine(equipmentXYZ.getBMachine()); |
| | | // mdcEquipmentDto.setXabsolute(equipmentXYZ.getXAbsolute()); |
| | | // mdcEquipmentDto.setYabsolute(equipmentXYZ.getYAbsolute()); |
| | | // mdcEquipmentDto.setZabsolute(equipmentXYZ.getZAbsolute()); |
| | | // mdcEquipmentDto.setAabsolute(equipmentXYZ.getAAbsolute()); |
| | | // mdcEquipmentDto.setBabsolute(equipmentXYZ.getBAbsolute()); |
| | | // } |
| | | // EquipmentBaseInfo equipmentBaseInfo = equipmentBaseInfoService.getByEquipmentId(mdcEquipment.getEquipmentId()); |
| | | // if (equipmentBaseInfo != null) { |
| | | // mdcEquipmentDto.setMaxAxis(equipmentBaseInfo.getMaxAxis()); |
| | | // mdcEquipmentDto.setValidAxis(equipmentBaseInfo.getValidAxis()); |
| | | // } |
| | | // if (controlSystem.getDriveType().equals("SIEMENS840DSL")) { |
| | | // EquipmentTemperatureDto equipmentTemperature = equipmentTemperatureService.getEquipmentTemperature(mdcEquipment.getEquipmentId()); |
| | | // if (equipmentTemperature != null) { |
| | | // mdcEquipmentDto.setTemperatureX(equipmentTemperature.getX()); |
| | | // mdcEquipmentDto.setTemperatureY(equipmentTemperature.getY()); |
| | | // mdcEquipmentDto.setTemperatureZ(equipmentTemperature.getZ()); |
| | | // mdcEquipmentDto.setTemperatureA(equipmentTemperature.getA()); |
| | | // mdcEquipmentDto.setTemperatureB(equipmentTemperature.getB()); |
| | | // } |
| | | // EquipmentTemperatureDto equipmentLagError = equipmentTemperatureService.getEquipmentLagError(mdcEquipment.getEquipmentId()); |
| | | // if (equipmentLagError != null) { |
| | | // mdcEquipmentDto.setEquipmentLagErrorX(equipmentLagError.getX()); |
| | | // mdcEquipmentDto.setEquipmentLagErrorY(equipmentLagError.getY()); |
| | | // mdcEquipmentDto.setEquipmentLagErrorZ(equipmentLagError.getZ()); |
| | | // mdcEquipmentDto.setEquipmentLagErrorA(equipmentLagError.getA()); |
| | | // mdcEquipmentDto.setEquipmentLagErrorB(equipmentLagError.getB()); |
| | | // } |
| | | // } |
| | | // EquipmentTemperatureDto equipmentCurrent = equipmentTemperatureService.getEquipmentCurrent(mdcEquipment.getEquipmentId()); |
| | | // if (equipmentCurrent != null) { |
| | | // mdcEquipmentDto.setEquipmentCurrentX(equipmentCurrent.getX()); |
| | | // mdcEquipmentDto.setEquipmentCurrentY(equipmentCurrent.getY()); |
| | | // mdcEquipmentDto.setEquipmentCurrentZ(equipmentCurrent.getZ()); |
| | | // mdcEquipmentDto.setEquipmentCurrentA(equipmentCurrent.getA()); |
| | | // mdcEquipmentDto.setEquipmentCurrentB(equipmentCurrent.getB()); |
| | | // } |
| | | } |
| | | return mdcEquipmentDto; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 根据大屏车间id查询设备列表 |
| | | */ |
| | | @Override |
| | | public IPage<MdcEquipment> getEquipmentByWorkshopId(Page<MdcEquipment> page, WorkshopEquipmentVo workshopEquipmentVo) { |
| | | return this.baseMapper.getEquipmentByWorkshopId(page, workshopEquipmentVo); |
| | | } |
| | | |
| | | @Override |
| | | public List<String> listEquipmentId(String equipmentType, List<String> equipmentIdList) { |
| | | List<MdcEquipment> list = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentType, equipmentType).in(MdcEquipment::getEquipmentId, equipmentIdList)); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |