package org.jeecg.modules.mdc.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
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;
|
import org.jeecg.modules.mdc.dto.MdcEquipmentDetailedDto;
|
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.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.util.FindsEquipmentDepartUtil;
|
import org.jeecg.modules.mdc.util.FindsEquipmentProductionUtil;
|
import org.jeecg.modules.mdc.vo.*;
|
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.*;
|
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;
|
|
/**
|
* @Description: 设备表
|
* @Author: liuS
|
* @Date: 2023-03-22
|
* @Version: V1.0
|
*/
|
@Service
|
public class MdcEquipmentServiceImpl extends ServiceImpl<MdcEquipmentMapper, MdcEquipment> implements IMdcEquipmentService {
|
|
@Resource
|
private MdcEquipmentDepartMapper mdcEquipmentDepartMapper;
|
@Resource
|
private MdcProductionEquipmentMapper mdcProductionEquipmentMapper;
|
@Resource
|
private ISysUserDepartService sysUserDepartService;
|
@Resource
|
private IMdcUserProductionService mdcUserProductionService;
|
@Resource
|
private ISysDepartService sysDepartService;
|
@Resource
|
private IMdcProductionService mdcProductionService;
|
@Resource
|
private IEquipmentWorkLineService equipmentWorkLineService;
|
@Resource
|
private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService;
|
@Resource
|
private MdcTorqueConfigMapper mdcTorqueConfigMapper;
|
|
@Resource
|
private IEquipmentLogService equipmentLogService;
|
|
@Resource
|
private ISysBaseAPI sysBaseApi;
|
|
@Resource
|
private IMdcAlarmInfoService mdcAlarmInfoService;
|
|
@Resource
|
private IMdcEquipmentThresholdService mdcEquipmentThresholdService;
|
|
@Resource
|
private IMdcOverrunAlarmService mdcOverrunAlarmService;
|
|
@Resource
|
private IEquipmentXYZService equipmentXYZService;
|
|
@Resource
|
private ISysDictService sysDictService;
|
|
@Override
|
public Map<String, String> getDepNamesByEquipmentIds(List<String> equipmentIds) {
|
List<MdcEquipmentDepVo> list = this.baseMapper.getDepNamesByEquipmentIds(equipmentIds);
|
Map<String, String> res = new HashMap(5);
|
list.forEach(item -> res.merge(item.getEquipmentId(), item.getDepartName(), (a, b) -> a + "," + b));
|
return res;
|
}
|
|
@Override
|
public Map<String, String> getProNamesByEquipmentIds(List<String> equipmentIds) {
|
List<MdcEquipmentProVo> list = this.baseMapper.getProNamesByEquipmentIds(equipmentIds);
|
Map<String, String> res = new HashMap(5);
|
list.forEach(item -> res.merge(item.getEquipmentId(), item.getProductionName(), (a, b) -> a + "," + b));
|
return res;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void saveMdcEquipment(MdcEquipment mdcEquipment, String selectedDeparts, String selectedProduction) {
|
//step.1 保存设备
|
this.save(mdcEquipment);
|
//step.2 保存所属部门
|
if (oConvertUtils.isNotEmpty(selectedDeparts)) {
|
String[] arr = selectedDeparts.split(",");
|
for (String departId : arr) {
|
MdcEquipmentDepart equipmentDepart = new MdcEquipmentDepart(mdcEquipment.getId(), departId);
|
mdcEquipmentDepartMapper.insert(equipmentDepart);
|
}
|
}
|
//step.3 保存所属产线
|
if (oConvertUtils.isNotEmpty(selectedProduction)) {
|
String[] arr = selectedProduction.split(",");
|
for (String productionId : arr) {
|
MdcProductionEquipment mdcProductionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId);
|
mdcProductionEquipmentMapper.insert(mdcProductionEquipment);
|
}
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
|
public void editMdcEquipment(MdcEquipment mdcEquipment) {
|
//step.1 修改设备基础信息
|
this.updateById(mdcEquipment);
|
//step.2 修改部门
|
String departs = mdcEquipment.getSelectedDeparts();
|
String[] arr = {};
|
if (oConvertUtils.isNotEmpty(departs)) {
|
arr = departs.split(",");
|
}
|
//先删后加
|
mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, mdcEquipment.getId()));
|
if (oConvertUtils.isNotEmpty(departs)) {
|
for (String departId : arr) {
|
MdcEquipmentDepart equipmentDepart = new MdcEquipmentDepart(mdcEquipment.getId(), departId);
|
mdcEquipmentDepartMapper.insert(equipmentDepart);
|
}
|
}
|
//step.3 修改产线
|
String productions = mdcEquipment.getSelectedProduction();
|
String[] array = {};
|
if (oConvertUtils.isNotEmpty(productions)) {
|
array = productions.split(",");
|
}
|
//先删后加
|
mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, mdcEquipment.getId()));
|
if (oConvertUtils.isNotEmpty(productions)) {
|
for (String productionId : array) {
|
MdcProductionEquipment productionEquipment = new MdcProductionEquipment(mdcEquipment.getId(), productionId);
|
mdcProductionEquipmentMapper.insert(productionEquipment);
|
}
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
|
public boolean deleteById(String id) {
|
// 1. 删除设备
|
int line = this.baseMapper.deleteById(id);
|
// 2. 删除设备部门关系
|
line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getEquipmentId, id));
|
// 3. 删除设备产线关系
|
line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getEquipmentId, id));
|
|
return line != 0;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
@CacheEvict(value = {"mdc:cache:encrypt:equipment"}, allEntries = true)
|
public boolean deleteByIds(List<String> equipmentIds) {
|
// 1. 删除设备
|
int line = this.baseMapper.deleteBatchIds(equipmentIds);
|
// 2. 删除设备部门关系
|
line += mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().in(MdcEquipmentDepart::getEquipmentId, equipmentIds));
|
// 3. 删除设备产线关系
|
line += mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().in(MdcProductionEquipment::getEquipmentId, equipmentIds));
|
|
return line != 0;
|
}
|
|
@Override
|
public IPage<MdcEquipment> pageListByDepId(Page<MdcEquipment> page, String departId, String equipmentId) {
|
return this.baseMapper.pageListByDepId(page, departId, equipmentId);
|
}
|
|
@Override
|
public IPage<MdcEquipment> pageListByProId(Page<MdcEquipment> page, String productionId, String equipmentId) {
|
return this.baseMapper.pageListByProId(page, productionId, equipmentId);
|
}
|
|
@Override
|
public void removeEquipmentForDepart(String departId, String equipmentId) {
|
mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getDepId, departId).eq(MdcEquipmentDepart::getEquipmentId, equipmentId));
|
}
|
|
@Override
|
public void removeEquipmentsForDepart(String departId, List<String> equipmentIdList) {
|
mdcEquipmentDepartMapper.delete(new LambdaQueryWrapper<MdcEquipmentDepart>().eq(MdcEquipmentDepart::getDepId, departId).in(MdcEquipmentDepart::getEquipmentId, equipmentIdList));
|
}
|
|
@Override
|
public void removeEquipmentForProduction(String productionId, String equipmentId) {
|
mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).eq(MdcProductionEquipment::getEquipmentId, equipmentId));
|
}
|
|
@Override
|
public void removeEquipmentsForProduction(String productionId, List<String> equipmentIdList) {
|
mdcProductionEquipmentMapper.delete(new LambdaQueryWrapper<MdcProductionEquipment>().eq(MdcProductionEquipment::getProductionId, productionId).in(MdcProductionEquipment::getEquipmentId, equipmentIdList));
|
}
|
|
@Override
|
public List<MdcEquipmentTree> loadTreeListByDepart(String userId) {
|
//获取所有部门数据
|
List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
|
//根据用户ID获取拥有的部门id集合
|
List<String> departIds = sysUserDepartService.queryDepartIdsByUserId(userId);
|
List<String> allDepartIds = new ArrayList<>();
|
//找到所有部门id的上级id
|
if (departIds != null && !departIds.isEmpty()) {
|
for (String departId : departIds) {
|
this.getAllDepartIds(departList, departId, allDepartIds);
|
}
|
}
|
//过滤部门数据
|
List<SysDepart> list = departList.stream().filter((SysDepart sysDepart) -> allDepartIds.contains(sysDepart.getId())).collect(Collectors.toList());
|
//组装部门设备树
|
List<MdcEquipmentTree> treeList = FindsEquipmentDepartUtil.wrapEquipmentDepartTreeList(list);
|
//填充设备数据
|
FillEquipmentByDepart(treeList);
|
return treeList;
|
}
|
|
/**
|
* 部门设备树填充设备数据
|
*
|
* @param treeList
|
*/
|
private void FillEquipmentByDepart(List<MdcEquipmentTree> treeList) {
|
for (MdcEquipmentTree mdcEquipmentTree : treeList) {
|
List<MdcEquipment> equipmentList = this.baseMapper.queryByDepartId(mdcEquipmentTree.getKey());
|
if (equipmentList != null && !equipmentList.isEmpty()) {
|
for (MdcEquipment mdcEquipment : equipmentList) {
|
MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
|
tree.setParentId(mdcEquipmentTree.getKey());
|
mdcEquipmentTree.getChildren().add(tree);
|
}
|
mdcEquipmentTree.setLeaf(false);
|
}
|
if (!mdcEquipmentTree.getChildren().isEmpty()) {
|
FillEquipmentByDepart(mdcEquipmentTree.getChildren());
|
}
|
}
|
}
|
|
/**
|
* 获取所有的部门id(包含所有上级)
|
*/
|
private void getAllDepartIds(List<SysDepart> departList, String departId, List<String> allDepartIds) {
|
if (!allDepartIds.contains(departId)) {
|
allDepartIds.add(departId);
|
}
|
for (SysDepart sysDepart : departList) {
|
if (StringUtils.isEmpty(sysDepart.getParentId())) {
|
continue;
|
}
|
if (departId.equals(sysDepart.getId())) {
|
if (!allDepartIds.contains(sysDepart.getParentId())) {
|
allDepartIds.add(sysDepart.getParentId());
|
getAllDepartIds(departList, sysDepart.getParentId(), allDepartIds);
|
}
|
}
|
}
|
}
|
|
|
@Override
|
public List<MdcEquipmentTree> loadTreeListByProduction(String userId) {
|
//获取所有产线数据
|
List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
|
//根据用户id获取拥有的产线信息集合
|
List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId);
|
List<String> allProductionIds = new ArrayList<>();
|
//找到所有产线id的上级id
|
if (productionIds != null && !productionIds.isEmpty()) {
|
for (String productionId : productionIds) {
|
this.getAllProductionIds(productionList, productionId, allProductionIds);
|
}
|
}
|
//过滤产线数据
|
List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList());
|
//组装产线设备树
|
List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
|
//填充设备数据
|
FillEquipmentByProduction(treeList);
|
return treeList;
|
}
|
|
/**
|
* 设备监控列表
|
*/
|
@Override
|
public List<MdcEquipmentMonitor> queryEquipmentMonitorList(String userId, String key) {
|
List<String> equipmentIds = this.getEquipmentIdsProduction(userId, key);
|
if (equipmentIds == null || equipmentIds.isEmpty()) {
|
return Collections.emptyList();
|
}
|
List<MdcEquipmentMonitor> result = this.baseMapper.checkStatusFromEquipmentIds(equipmentIds);
|
if (result != null && !result.isEmpty()) {
|
for (MdcEquipmentMonitor mdcEquipmentMonitor : result) {
|
if (mdcEquipmentMonitor.getEquipmentStatus() == 0) {
|
if (mdcEquipmentMonitor.getOporation() != null) {
|
switch (mdcEquipmentMonitor.getOporation()) {
|
case 1:
|
case 2:
|
mdcEquipmentMonitor.setOporationDict("待机");
|
break;
|
case 3:
|
mdcEquipmentMonitor.setOporationDict("运行");
|
break;
|
case 22:
|
mdcEquipmentMonitor.setOporationDict("报警");
|
break;
|
default:
|
mdcEquipmentMonitor.setOporationDict("关机");
|
break;
|
}
|
} else {
|
mdcEquipmentMonitor.setOporationDict("关机");
|
mdcEquipmentMonitor.setOporation(0);
|
}
|
} else {
|
List<DictModel> dictList = sysDictService.queryEnableDictItemsByCode(CommonConstant.DICT_EQUIPMENT_STATUS);
|
for (DictModel dictModel : dictList) {
|
if (Integer.valueOf(dictModel.getValue()).equals(mdcEquipmentMonitor.getEquipmentStatus())) {
|
mdcEquipmentMonitor.setOporationDict(dictModel.getLabel());
|
mdcEquipmentMonitor.setOporation(88);
|
}
|
}
|
}
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 设备监控 - 设备详细信息
|
*/
|
@Override
|
public Map<String, Object> mdcEquipmentDetailedInfo(String id) {
|
Map<String, Object> result = new HashMap<>();
|
MdcEquipmentDetailedDto mdcEquipmentDetailedDto = this.baseMapper.findById(id);
|
result.put("equipment", mdcEquipmentDetailedDto);
|
// 查询设备状态
|
EquipmentLog equipmentLog = equipmentLogService.selectEquipmentOporation(mdcEquipmentDetailedDto.getEquipmentId());
|
if (equipmentLog == null) {
|
return result;
|
}
|
Integer oporation = equipmentLog.getOporation();
|
//获取工作数据并初始化
|
String saveTableName = mdcEquipmentDetailedDto.getSaveTableName();
|
Map<String, Object> mapData = equipmentWorkLineService.getDataList(saveTableName);
|
if (mapData != null) {
|
// Map<String, Object> runData = new LinkedHashMap<>();
|
List<Map<String, Object>> runData = new ArrayList<>();
|
//获取 MDC 驱动对应的展示参数 并根据key 拼装从 workData 查询的数据
|
List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(mdcEquipmentDetailedDto.getDriveType());
|
if (mdcDriveTypeParamList != null && !mdcDriveTypeParamList.isEmpty()) {
|
for (MdcDriveTypeParamConfig mdcDriveTypeParamConfig : mdcDriveTypeParamList) {
|
Map<String, Object> map = new LinkedHashMap<>();
|
String englishName = mdcDriveTypeParamConfig.getEnglishName();
|
String chineseName = mdcDriveTypeParamConfig.getChineseName();
|
map.put("key", chineseName);
|
if (mapData.containsKey(englishName)) {
|
Object object = mapData.get(englishName);
|
String value = "";
|
if ("CollectTime".equals(englishName)) {
|
Date date = object == null ? null : (Date) object;
|
value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL);
|
} else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.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(mdcEquipmentDetailedDto.getDriveType()) && "spindlespeed".equals(englishName) && oporation == 3) {
|
// ZUOLAN设备主轴转速字段spindlespeed
|
value = String.valueOf(((new Random().nextInt(35)) + 1) * 100);
|
} else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "spindleload".equals(englishName) && oporation == 3) {
|
// ZUOLAN设备主轴负荷字段spindleload
|
value = String.valueOf(Integer.valueOf(new Random().nextInt(21)));
|
} else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "spindlebeilv".equals(englishName) && oporation == 3) {
|
// ZUOLAN设备主轴倍率字段spindlebeilv
|
value = String.valueOf((new Random().nextInt(13)) * 10);
|
} else if ("ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && "feedbeilv".equals(englishName) && oporation == 3) {
|
// ZUOLAN设备进给倍率字段feedbeilv
|
value = String.valueOf((new Random().nextInt(13)) * 10);
|
} else if ("spindle_current".equals(englishName)) {
|
// 其他设备电流字段
|
String devicePower = mdcEquipmentDetailedDto.getDevicePower();
|
Object spindleload = mapData.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(mdcEquipmentDetailedDto.getEquipmentId());
|
if (mdcTorqueConfig != null) {
|
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, mdcEquipmentDetailedDto.getDriveType()).eq(MdcAlarmInfo::getAlarmCode, equipmentLog.getAlarm()).eq(MdcAlarmInfo::getIsUse, 0));
|
if (mdcAlarmInfo != null && !mdcAlarmInfo.isEmpty()) {
|
value = mdcAlarmInfo.get(0).getAlarmContent();
|
}
|
} else {
|
value = "无";
|
}
|
} else {
|
value = object == null ? "" : object.toString();
|
}
|
map.put("value", value);
|
runData.add(map);
|
if ("spindlebeilv".equals(englishName) && !"".equals(value)) {
|
result.put("spindlebeilv", value);
|
}
|
if ("feedbeilv".equals(englishName) && !"".equals(value)) {
|
result.put("feedbeilv", value);
|
}
|
if ("spindleload".equals(englishName) && !"".equals(value)) {
|
result.put("spindleload", value);
|
}
|
if ("rapidfeed".equals(englishName) && !"".equals(value)) {
|
result.put("rapidfeed", value);
|
}
|
}
|
}
|
}
|
result.put("runData", runData);
|
|
// 查询坐标信息
|
if (!"ZUOLAN".equals(mdcEquipmentDetailedDto.getDriveType()) && !"CurrentState".equals(mdcEquipmentDetailedDto.getDriveType())) {
|
EquipmentXYZ equipmentXYZ = equipmentXYZService.getByEquipmentId(mdcEquipmentDetailedDto.getEquipmentId());
|
if (equipmentXYZ != null) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("xmachine", equipmentXYZ.getXMachine());
|
map.put("ymachine", equipmentXYZ.getYMachine());
|
map.put("zmachine", equipmentXYZ.getZMachine());
|
map.put("amachine", equipmentXYZ.getAMachine());
|
map.put("bmachine", equipmentXYZ.getBMachine());
|
|
map.put("xabsolute", equipmentXYZ.getXAbsolute());
|
map.put("yabsolute", equipmentXYZ.getYAbsolute());
|
map.put("zabsolute", equipmentXYZ.getZAbsolute());
|
map.put("aabsolute", equipmentXYZ.getAAbsolute());
|
map.put("babsolute", equipmentXYZ.getBAbsolute());
|
result.put("xyzList", map);
|
}
|
}
|
|
}
|
return result;
|
}
|
|
/**
|
* 通过用户部门关系获取设备id集合
|
*/
|
@Override
|
public List<String> getEquipmentIdsByDepart(String userId, String key) {
|
//获取所有部门数据
|
List<SysDepart> departList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(SysDepart::getDepartOrder));
|
//根据用户id获取拥有的部门信息集合
|
List<String> departIds = sysUserDepartService.queryDepartIdsByUserId(userId);
|
List<String> allDepartIds = new ArrayList<>();
|
if (departIds != null && !departIds.isEmpty()) {
|
for (String departId : departIds) {
|
this.getAllDepartIds(departList, departId, allDepartIds);
|
}
|
}
|
//根据产线集合查找所有设备id
|
if (allDepartIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIds = this.baseMapper.queryIdsByDeparts(allDepartIds);
|
if (StringUtils.isNotEmpty(key)) {
|
//key不为空,查询所有下级部门id
|
List<String> partDepart = this.findAllDeparts(key);
|
partDepart.add(key);
|
//过滤无权限部门id
|
List<String> allDepartIdsByKey = partDepart.stream().filter(allDepartIds::contains).collect(Collectors.toList());
|
equipmentIds = this.baseMapper.queryIdsByDeparts(allDepartIdsByKey);
|
}
|
return equipmentIds;
|
}
|
|
/**
|
* 根据父级id递归查询所有下级id集合
|
*/
|
private List<String> findAllDeparts(String key) {
|
List<String> departs = new ArrayList<>();
|
List<SysDepart> sysDeparts = sysDepartService.queryDeptByPid(key);
|
if (sysDeparts != null && !sysDeparts.isEmpty()) {
|
List<String> ids = sysDeparts.stream().map(SysDepart::getId).collect(Collectors.toList());
|
departs.addAll(ids);
|
for (SysDepart sysDepart : sysDeparts) {
|
List<String> allDeparts = findAllDeparts(sysDepart.getId());
|
departs.addAll(allDeparts);
|
}
|
}
|
return departs;
|
}
|
|
/**
|
* 通过用户产线关系获取设备id集合
|
*/
|
@Override
|
public List<String> getEquipmentIdsProduction(String userId, String key) {
|
//获取所有产线数据
|
List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
|
//根据用户id获取拥有的产线信息集合
|
List<String> productionIds = mdcUserProductionService.queryProductionIdsByUserId(userId);
|
List<String> allProductionIds = new ArrayList<>();
|
//找到所有产线id的上级id
|
if (productionIds != null && !productionIds.isEmpty()) {
|
for (String productionId : productionIds) {
|
this.getAllProductionIds(productionList, productionId, allProductionIds);
|
}
|
}
|
//根据产线集合查找所有设备id
|
if (allProductionIds.isEmpty()) {
|
return null;
|
}
|
List<String> equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIds);
|
if (StringUtils.isNotEmpty(key)) {
|
//key不为空,查询所有下级产线id
|
List<String> partProduction = this.findAllProductions(key);
|
partProduction.add(key);
|
//过滤无权限产线id
|
List<String> allProductionIdsByKey = partProduction.stream().filter(allProductionIds::contains).collect(Collectors.toList());
|
equipmentIds = this.baseMapper.queryIdsByProductions(allProductionIdsByKey);
|
}
|
return equipmentIds;
|
}
|
|
/**
|
* 根据设备id查询设备名称
|
*/
|
@Override
|
public MdcEquipment findEquipmentNameByEquipmentId(String equipmentId) {
|
return this.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, equipmentId));
|
}
|
|
/**
|
* 选择设备分页列表
|
*/
|
@Override
|
public IPage<MdcEquipment> findEquipmentList(Page<MdcEquipment> page, String userId, MdcEquipmentVo mdcEquipment) {
|
List<String> equipmentIdsByDepart = new ArrayList<>();
|
if (StringUtils.isNotEmpty(mdcEquipment.getDepartId())) {
|
equipmentIdsByDepart = getEquipmentIdsByDepart(userId, mdcEquipment.getDepartId());
|
}
|
List<String> equipmentIdsProduction = new ArrayList<>();
|
if (StringUtils.isNotEmpty(mdcEquipment.getProductionId())) {
|
equipmentIdsProduction = getEquipmentIdsProduction(userId, mdcEquipment.getProductionId());
|
}
|
List<String> allEquipments = new ArrayList<>();
|
if (StringUtils.isEmpty(mdcEquipment.getDepartId()) && StringUtils.isEmpty(mdcEquipment.getProductionId())) {
|
List<String> idsByDepart = getEquipmentIdsByDepart(userId, null);
|
List<String> idsProduction = getEquipmentIdsProduction(userId, null);
|
// 去重并集
|
allEquipments = Stream.of(idsByDepart, idsProduction).flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
}
|
if (StringUtils.isNotEmpty(mdcEquipment.getDepartId()) && StringUtils.isNotEmpty(mdcEquipment.getProductionId())) {
|
// 交集
|
allEquipments = equipmentIdsByDepart.stream().filter(equipmentIdsProduction::contains).collect(Collectors.toList());
|
}
|
LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.isNotNull(MdcEquipment::getEquipmentId);
|
if (StringUtils.isNotEmpty(mdcEquipment.getEquipmentId())) {
|
queryWrapper.like(MdcEquipment::getEquipmentId, mdcEquipment.getEquipmentId());
|
}
|
if (StringUtils.isNotEmpty(mdcEquipment.getEquipmentName())) {
|
queryWrapper.like(MdcEquipment::getEquipmentName, mdcEquipment.getEquipmentName());
|
}
|
if (mdcEquipment.getEquipmentStatus() != null) {
|
queryWrapper.eq(MdcEquipment::getEquipmentStatus, mdcEquipment.getEquipmentStatus());
|
}
|
if (!allEquipments.isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, allEquipments);
|
} else if (!equipmentIdsByDepart.isEmpty() && equipmentIdsProduction.isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, equipmentIdsByDepart);
|
} else if (equipmentIdsByDepart.isEmpty() && !equipmentIdsProduction.isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, equipmentIdsProduction);
|
}
|
queryWrapper.orderByAsc(MdcEquipment::getEquipmentName);
|
return this.baseMapper.selectPage(page, queryWrapper);
|
}
|
|
/**
|
* 根据父级id递归查询所有下级id集合
|
*/
|
private List<String> findAllProductions(String key) {
|
List<String> productions = new ArrayList<>();
|
List<MdcProduction> mdcProductions = mdcProductionService.queryProdByPid(key);
|
if (mdcProductions != null && !mdcProductions.isEmpty()) {
|
List<String> ids = mdcProductions.stream().map(MdcProduction::getId).collect(Collectors.toList());
|
productions.addAll(ids);
|
for (MdcProduction mdcProduction : mdcProductions) {
|
List<String> allProductions = findAllProductions(mdcProduction.getId());
|
productions.addAll(allProductions);
|
}
|
}
|
return productions;
|
}
|
|
/**
|
* 产线设备树填充设备数据
|
*/
|
private void FillEquipmentByProduction(List<MdcEquipmentTree> treeList) {
|
for (MdcEquipmentTree mdcEquipmentTree : treeList) {
|
List<MdcEquipment> equipmentList = this.baseMapper.queryByProductionId(mdcEquipmentTree.getKey());
|
if (equipmentList != null && !equipmentList.isEmpty()) {
|
for (MdcEquipment mdcEquipment : equipmentList) {
|
MdcEquipmentTree tree = new MdcEquipmentTree().convert(mdcEquipment);
|
tree.setParentId(mdcEquipmentTree.getKey());
|
mdcEquipmentTree.getChildren().add(tree);
|
}
|
mdcEquipmentTree.setLeaf(false);
|
}
|
if (!mdcEquipmentTree.getChildren().isEmpty()) {
|
FillEquipmentByProduction(mdcEquipmentTree.getChildren());
|
}
|
}
|
}
|
|
/**
|
* 获取所有的产线id(包含所有上级)
|
*/
|
private void getAllProductionIds(List<MdcProduction> productionList, String productionId, List<String> allProductionIds) {
|
if (!allProductionIds.contains(productionId)) {
|
allProductionIds.add(productionId);
|
}
|
for (MdcProduction mdcProduction : productionList) {
|
if (StringUtils.isEmpty(mdcProduction.getParentId())) {
|
continue;
|
}
|
if (productionId.equals(mdcProduction.getId())) {
|
if (!allProductionIds.contains(mdcProduction.getParentId())) {
|
allProductionIds.add(mdcProduction.getParentId());
|
getAllProductionIds(productionList, mdcProduction.getParentId(), allProductionIds);
|
}
|
}
|
}
|
}
|
|
/**
|
* 根据产线层级查询设备单个
|
*/
|
@Override
|
public MdcEquipment getEquipmentByPid(String pid, String userId) {
|
List<String> idsProduction = this.getEquipmentIdsProduction(userId, pid);
|
if (idsProduction != null && !idsProduction.isEmpty()) {
|
return super.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, idsProduction.get(0)));
|
}
|
return null;
|
}
|
|
/**
|
* 根据设备编号查询设备信息和部门信息
|
*
|
* @param equipmentIdList
|
* @return
|
*/
|
@Override
|
public List<MdcEquDepDto> findEquDepList(List<String> equipmentIdList) {
|
return this.baseMapper.findEquDepList(equipmentIdList);
|
}
|
|
/**
|
* 根据设备编号查询设备信息和产线信息
|
*
|
* @param equipmentIdList
|
* @return
|
*/
|
@Override
|
public List<MdcEquProDto> findEquProList(List<String> equipmentIdList) {
|
return this.baseMapper.findEquProList(equipmentIdList);
|
}
|
|
/**
|
* 根据部门层级查询设备单个
|
*/
|
@Override
|
public MdcEquipment getEquipmentByDepPid(String pid, String userId) {
|
List<String> idsByDepart = this.getEquipmentIdsByDepart(userId, pid);
|
if (idsByDepart != null && !idsByDepart.isEmpty()) {
|
return super.getOne(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, idsByDepart.get(0)));
|
}
|
return null;
|
}
|
|
/**
|
* 根据大屏车间id查询设备列表
|
*/
|
@Override
|
public IPage<MdcEquipment> getEquipmentByWorkshopId(Page<MdcEquipment> page, WorkshopEquipmentVo workshopEquipmentVo) {
|
return this.baseMapper.getEquipmentByWorkshopId(page, workshopEquipmentVo);
|
}
|
|
@Override
|
public List<String> listEquipmentId(MdcEfficiencyReportQueryVo vo) {
|
LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
|
if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
|
}
|
if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
|
queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
|
queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDriveType())) {
|
queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
|
queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
|
}
|
List<MdcEquipment> list = super.list(queryWrapper);
|
// 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) {
|
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();
|
//List<MdcEquipment> equipmentList = super.list(new LambdaQueryWrapper<MdcEquipment>().eq(MdcEquipment::getEquipmentId, "2140198"));
|
|
for (MdcEquipment mdcEquipment : equipmentList) {
|
List<MdcEquipmentThreshold> mdcEquipmentThresholdList = mdcEquipmentThresholdService.list(new LambdaQueryWrapper<MdcEquipmentThreshold>().eq(MdcEquipmentThreshold::getControlSystemType, mdcEquipment.getDriveType()));
|
if (mdcEquipmentThresholdList != null && !mdcEquipmentThresholdList.isEmpty()) {
|
String saveTableName = mdcEquipment.getSaveTableName();
|
StringBuilder builder = new StringBuilder();
|
for (MdcEquipmentThreshold mdcEquipmentThreshold : mdcEquipmentThresholdList) {
|
builder.append(",").append(mdcEquipmentThreshold.getEnglishName()).append(" as \"").append(mdcEquipmentThreshold.getEnglishName()).append("\" ");
|
}
|
Map<String, Object> param = new HashMap<>();
|
param.put("columns", builder.toString());
|
param.put("tableName", saveTableName);
|
Map<String, Object> map = new HashMap<>();
|
try {
|
map = this.baseMapper.getWorkLineLast(param);
|
} catch (Exception e) {
|
log.error("查询单表数据出差!", e);
|
}
|
if (!map.isEmpty()) {
|
for (MdcEquipmentThreshold mdcEquipmentThreshold : mdcEquipmentThresholdList) {
|
Integer actualValue = Integer.valueOf(map.get(mdcEquipmentThreshold.getEnglishName()).toString());
|
Integer max = mdcEquipmentThreshold.getMaxThreshold();
|
Integer min = mdcEquipmentThreshold.getMinThreshold();
|
MessageDTO messageDTO = new MessageDTO();
|
messageDTO.setTitle("设备" + mdcEquipmentThreshold.getChineseName() + "报警!");
|
messageDTO.setCategory("预警消息");
|
messageDTO.setFromUser("admin");
|
messageDTO.setToUser("admin");
|
MdcOverrunAlarm mdcOverrunAlarm = new MdcOverrunAlarm();
|
mdcOverrunAlarm.setEquipmentId(mdcEquipment.getEquipmentId());
|
mdcOverrunAlarm.setSetValue(min + "-" + max);
|
mdcOverrunAlarm.setRealValue(actualValue.toString());
|
if (actualValue > max) {
|
// 高
|
messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备" + mdcEquipmentThreshold.getChineseName() + "高报警!");
|
sysBaseApi.sendSysAnnouncement(messageDTO);
|
mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "高报警");
|
mdcOverrunAlarmService.save(mdcOverrunAlarm);
|
} else if (actualValue < min) {
|
// 低
|
messageDTO.setContent("设备编号为 [" + mdcEquipment.getEquipmentId() + "] 的设备" + mdcEquipmentThreshold.getChineseName() + "低报警!");
|
sysBaseApi.sendSysAnnouncement(messageDTO);
|
mdcOverrunAlarm.setAlarmContent(mdcEquipmentThreshold.getChineseName() + "低报警");
|
mdcOverrunAlarmService.save(mdcOverrunAlarm);
|
}
|
}
|
}
|
}
|
}
|
|
}
|
|
/**
|
* 导出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);
|
}
|
|
/**
|
* 通过车间ids获取设备树
|
*
|
* @param ids
|
* @return
|
*/
|
@Override
|
public List<MdcEquipmentTree> loadTreeListByProductionIds(String ids) {
|
List<String> productionIds = Arrays.asList(ids.split(","));
|
//获取所有产线数据
|
List<MdcProduction> productionList = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0.toString()).orderByAsc(MdcProduction::getProductionOrder));
|
List<String> allProductionIds = new ArrayList<>();
|
//找到所有产线id的上级id
|
if (!productionIds.isEmpty()) {
|
for (String productionId : productionIds) {
|
this.getAllProductionIds(productionList, productionId, allProductionIds);
|
}
|
}
|
//过滤产线数据
|
List<MdcProduction> list = productionList.stream().filter((MdcProduction mdcProduction) -> allProductionIds.contains(mdcProduction.getId())).collect(Collectors.toList());
|
//组装产线设备树
|
List<MdcEquipmentTree> treeList = FindsEquipmentProductionUtil.wrapEquipmentProductionTreeList(list);
|
//填充设备数据
|
FillEquipmentByProduction(treeList);
|
return treeList;
|
}
|
|
/**
|
* 查询单表数据
|
*
|
* @param tableName
|
* @return
|
*/
|
@Override
|
public MdcEquipmentDto getWorkLineLast(String tableName) {
|
try {
|
return this.baseMapper.findWorkLineLast(tableName);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
@Override
|
public List<String> listEquipmentIdShift(MdcEfficiencyReportShiftQueryVo vo) {
|
LambdaQueryWrapper<MdcEquipment> queryWrapper = new LambdaQueryWrapper<>();
|
if (vo.getEquipmentIdList() != null && !vo.getEquipmentIdList().isEmpty()) {
|
queryWrapper.in(MdcEquipment::getEquipmentId, vo.getEquipmentIdList());
|
}
|
if (StringUtils.isNotEmpty(vo.getEquipmentType())) {
|
queryWrapper.in(MdcEquipment::getEquipmentType, Arrays.asList(vo.getEquipmentType().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDeviceLevel())) {
|
queryWrapper.in(MdcEquipment::getDeviceLevel, Arrays.asList(vo.getDeviceLevel().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDriveType())) {
|
queryWrapper.in(MdcEquipment::getDriveType, Arrays.asList(vo.getDriveType().split(",")));
|
}
|
if (StringUtils.isNotEmpty(vo.getDeviceCategory())) {
|
queryWrapper.in(MdcEquipment::getDeviceCategory, Arrays.asList(vo.getDeviceCategory().split(",")));
|
}
|
List<MdcEquipment> list = super.list(queryWrapper);
|
// 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());
|
}
|
|
}
|