package com.ipsplm.service.simulation.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ipsplm.dao.simulation.SimulationAnalysisMapper; import com.ipsplm.entity.simulation.*; import com.ipsplm.entity.simulation.dto.BufferNumDTO; import com.ipsplm.entity.simulation.vo.*; import com.ipsplm.service.simulation.ISimulationAnalysisService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; /** * @Description 仿真分析实现类 * @Author lulicheng * @Date 2024-07-31 10:20 * @Version 1.0 */ @Service public class SimulationAnalysisServiceImpl implements ISimulationAnalysisService { @Autowired private SimulationAnalysisMapper simulationAnalysisMapper; /** * 获取厂房设备利用率信息 * * @param flag * @return */ @Override public Map getPlantEquipmentUtilization(Long flag) { String simEndTime = simulationAnalysisMapper.getSimEndTime(); List plantEquipmentUtilization = simulationAnalysisMapper.getPlantEquipmentUtilization(flag); List oeeVOList = beanToKeyValue(plantEquipmentUtilization); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(null,1); Map result = new HashMap<>(); result.put("simEndTime",simEndTime); result.put("oeeList",fieldNameToChinese(fieldCnVOList,oeeVOList)); return result; } /** * 获取工序列表 * * @param tableCode * @return */ @Override public List getProcessList(String tableCode) { return simulationAnalysisMapper.getProcessList(tableCode); } /** * 获取缓存数量时间 * * @param process * @return */ @Override public Object getBufferNum(String process) { List bufferNameList = simulationAnalysisMapper.getBufferName(process); String tableCode = bufferNameList.get(0).getTableCode(); switch (tableCode) { case "buffernum_bxg": { List bufferNumBxgList = simulationAnalysisMapper.getBufferNumBxg(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(1,2); return beanToKeyValue(bufferNumBxgList,fieldCnVOList); } case "buffernum_dj": { List bufferNumDjList = simulationAnalysisMapper.getBufferNumDj(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(2,2); return beanToKeyValue(bufferNumDjList,fieldCnVOList); } case "buffernum_xe": { List bufferNumXeList = simulationAnalysisMapper.getBufferNumXe(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(3,2); return beanToKeyValue(bufferNumXeList,fieldCnVOList); } case "buffernum_xy": { List bufferNumXyList = simulationAnalysisMapper.getBufferNumXy(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(6,2); return beanToKeyValue(bufferNumXyList,fieldCnVOList); } case "buffernum_ze": { List bufferNumZeList = simulationAnalysisMapper.getBufferNumZe(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(5,2); return beanToKeyValue(bufferNumZeList,fieldCnVOList); } case "buffernum_zy": { List bufferNumZyList = simulationAnalysisMapper.getBufferNumZy(bufferNameList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(4,2); return beanToKeyValue(bufferNumZyList,fieldCnVOList); } default: break; } return null; } /** * 获取OEE数据 * * @param tableCode * @return */ @Override public Object getOee(String tableCode) { switch (tableCode) { case "oee_bxg": { List oeeBxgList = simulationAnalysisMapper.getOeeBxg(); List oeeVOList = beanToKeyValue(oeeBxgList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(7,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } case "oee_dj": { List oeeDjList = simulationAnalysisMapper.getOeeDj(); List oeeVOList = beanToKeyValue(oeeDjList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(12,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } case "oee_xe": { List oeeXeList = simulationAnalysisMapper.getOeeXe(); List oeeVOList = beanToKeyValue(oeeXeList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(9,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } case "oee_xy": { List oeeXyList = simulationAnalysisMapper.getOeeXy(); List oeeVOList = beanToKeyValue(oeeXyList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(8,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } case "oee_ze": { List oeeZeList = simulationAnalysisMapper.getOeeZe(); List oeeVOList = beanToKeyValue(oeeZeList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(11,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } case "oee_zy": { List oeeZyList = simulationAnalysisMapper.getOeeZy(); List oeeVOList = beanToKeyValue(oeeZyList); List fieldCnVOList = simulationAnalysisMapper.getFieldInfo(10,1); return fieldNameToChinese(fieldCnVOList,oeeVOList); } default: break; } return null; } /** * 获取对象的属性名和属性值并存入OeeVO对象的集合 * @param oeeList * @return */ public List beanToKeyValue(List oeeList) { List oeeVOList = new ArrayList<>(); for (Object object : oeeList) { JSONObject jsonObject = (JSONObject) JSON.toJSON(object); Object status = jsonObject.get("status"); for (Map.Entry entry : jsonObject.entrySet()) { OeeVO oeeVO = new OeeVO(); Object value = entry.getValue(); String key = entry.getKey(); if ("flag".equals(key) || "id".equals(key) || "status".equals(key)) { continue; } oeeVO.setName(key); oeeVO.setValue(value); oeeVO.setStatus(status); oeeVOList.add(oeeVO); } } return oeeVOList; } public List fieldNameToChinese(List fieldCnVOList,List oeeVOList) { for (OeeVO oeeVO : oeeVOList) { for (FieldCnVO fieldCnVO : fieldCnVOList) { if (oeeVO.getName().equals(fieldCnVO.getFieldCode())) { oeeVO.setName(fieldCnVO.getFieldName()); break; } } } return oeeVOList; } public List beanToKeyValue(List bufferNumList,List fieldCnVOList) { List bufferNumVOList = new ArrayList<>(); for (Object buffernum : bufferNumList) { JSONObject jsonObject = (JSONObject) JSON.toJSON(buffernum); String recordTime = jsonObject.getString("recordTime"); List bufferNumDTOList = new ArrayList<>(); for (Map.Entry entry : jsonObject.entrySet()) { BufferNumDTO bufferNumDTO = new BufferNumDTO(); Object value = entry.getValue(); String key = entry.getKey(); if(value == null || "recordTime".equals(key)){ continue; } for (FieldCnVO fieldCnVO : fieldCnVOList) { if(key.equals(fieldCnVO.getFieldCode())){ bufferNumDTO.setBufferName(fieldCnVO.getFieldName()); break; } } bufferNumDTO.setBufferNum((String) value); bufferNumDTOList.add(bufferNumDTO); } BufferNumVO bufferNumVO = new BufferNumVO(); bufferNumVO.setRecordTime(recordTime); bufferNumVO.setBufferNumVOList(bufferNumDTOList); bufferNumVOList.add(bufferNumVO); } return bufferNumVOList; } }