| | |
| | | package com.iailab.module.ansteel.coking.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void saveTraceDeviation(String relId, String process, String clock, JSONObject result, String chartcode, String row, String sugObj) { |
| | | List<ChartParamDTO> list = mcsApi.getChartParamList(chartcode); |
| | | Map<String, String> indexMaps = list.stream().collect(Collectors.toMap(ChartParamDTO::getParamCode, e -> e.getParamName())); |
| | | |
| | | List<String> rowKeys = new ArrayList<>(); |
| | | result.forEach((key, value) -> { |
| | | if (StringUtils.isNotBlank(key) && key.contains(row)) { |
| | | rowKeys.add(key); |
| | | } |
| | | |
| | | }); |
| | | public void saveTraceDeviation(String relId, String process, String clock, String jsonString, String sugObj) { |
| | | JSONArray jsonArray = JSON.parseArray(jsonString); |
| | | |
| | | List<CokingTraceDeviationEntity> entityList = new ArrayList<>(); |
| | | for (String key : rowKeys) { |
| | | JSONArray rowArr = JSON.parseArray(result.get(key).toString()); |
| | | if (CollectionUtils.isEmpty(rowArr)) { |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | JSONObject jsonObject = jsonArray.getJSONObject(i); |
| | | |
| | | Map<String,String> values = new HashMap<>(); |
| | | // 指标 |
| | | for (int index = 1; index <= 2; index++) { |
| | | String indexKey = "index" + index; |
| | | if (jsonObject.containsKey(indexKey)) { |
| | | String nameValue = jsonObject.getString(indexKey); |
| | | if (StringUtils.isBlank(nameValue)) { |
| | | continue; |
| | | } |
| | | String[] split = nameValue.split(" "); |
| | | String name = split[0]; |
| | | String value = split[1]; |
| | | |
| | | values.put("ind" + index + "Name",name); |
| | | values.put("ind" + index + "Value",value); |
| | | } |
| | | } |
| | | // 影响因素 |
| | | for (int index = 1; index <= 20; index++) { |
| | | String factorKey = "factor" + index; |
| | | if (jsonObject.containsKey(factorKey)) { |
| | | String nameValue = jsonObject.getString(factorKey); |
| | | if (StringUtils.isBlank(nameValue)) { |
| | | continue; |
| | | } |
| | | String[] split = nameValue.split(" "); |
| | | String name = split[0]; |
| | | String value = split[1]; |
| | | |
| | | values.put("fac" + index + "Name",name); |
| | | values.put("fac" + index + "Value",value); |
| | | } |
| | | } |
| | | |
| | | CokingTraceDeviationEntity entity = new CokingTraceDeviationEntity(); |
| | | BeanUtil.fillBeanWithMap(values,entity,true); |
| | | entity.setRelId(relId); |
| | | entity.setProcess(process); |
| | | entity.setClock(clock); |
| | | entity.setSugObj(sugObj); |
| | | |
| | | entity.setInd1Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(0).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setInd1Value(rowArr.getJSONArray(0).get(1).toString()); |
| | | entity.setInd1Unit(""); |
| | | |
| | | entity.setInd2Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(1).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setInd2Value(rowArr.getJSONArray(1).get(1).toString()); |
| | | entity.setInd2Unit(""); |
| | | |
| | | if (rowArr.size() > 2) { |
| | | entity.setFac1Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(2).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac1Value(rowArr.getJSONArray(2).get(1).toString()); |
| | | entity.setFac1Unit(""); |
| | | } |
| | | if (rowArr.size() > 3) { |
| | | entity.setFac2Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(3).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac2Value(rowArr.getJSONArray(3).get(1).toString()); |
| | | entity.setFac2Unit(""); |
| | | } |
| | | if (rowArr.size() > 4) { |
| | | entity.setFac3Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(4).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac3Value(rowArr.getJSONArray(4).get(1).toString()); |
| | | entity.setFac3Unit(""); |
| | | } |
| | | if (rowArr.size() > 5) { |
| | | entity.setFac4Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(5).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac4Value(rowArr.getJSONArray(5).get(1).toString()); |
| | | entity.setFac4Unit(""); |
| | | } |
| | | if (rowArr.size() > 6) { |
| | | entity.setFac5Name(indexMaps.get(new BigDecimal(rowArr.getJSONArray(6).get(0).toString()).setScale(0, BigDecimal.ROUND_HALF_UP).toString())); |
| | | entity.setFac5Value(rowArr.getJSONArray(6).get(1).toString()); |
| | | entity.setFac5Unit(""); |
| | | } |
| | | entity.setCreateDate(new Date()); |
| | | entityList.add(entity); |
| | | } |
| | | cokingTraceDeviationDao.insert(entityList); |