package com.iailab.module.ansteel.api; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.iailab.framework.common.util.object.ConvertUtils; import com.iailab.module.ansteel.api.dao.PowerRunStateDao; import com.iailab.module.data.api.point.DataPointApi; import com.iailab.module.model.api.mcs.AnSteelApi; import com.iailab.module.sms.api.dto.PowerRunStateDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import java.math.BigDecimal; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Slf4j @Service public class McsServiceImpl implements AnSteelApi { @Autowired private DataPointApi dataPointApi; @Autowired private PowerRunStateDao powerRunStateDao; @Override public List getPowerRunState() { List list = ConvertUtils.sourceToTarget(powerRunStateDao.selectList(new QueryWrapper<>()), PowerRunStateDTO.class); if (!CollectionUtils.isEmpty(list)) { list.stream().map(item -> { StringBuffer sb = new StringBuffer(); sb.append(item.getQhRate()); sb.append(","); sb.append(item.getFhRate()); sb.append(","); sb.append(item.getGasTotal()); sb.append(","); sb.append(item.getGasCost()); sb.append(","); sb.append(item.getGasSurplus()); sb.append(","); sb.append(item.getBfg()); sb.append(","); sb.append(item.getLdg()); sb.append(","); sb.append(item.getCog()); String[] arr = sb.toString().split(","); Map adjValue = dataPointApi.queryPointsRealValue(Arrays.asList(arr)); item.setQhRate(ObjectUtils.isEmpty(adjValue.get(arr[0])) ? "0" : new BigDecimal(adjValue.get(arr[0]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setFhRate(ObjectUtils.isEmpty(adjValue.get(arr[1])) ? "0" : new BigDecimal(adjValue.get(arr[1]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setGasTotal(ObjectUtils.isEmpty(adjValue.get(arr[2])) ? "0" : new BigDecimal(adjValue.get(arr[2]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setGasCost(ObjectUtils.isEmpty(adjValue.get(arr[3])) ? "0" : new BigDecimal(adjValue.get(arr[3]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setGasSurplus(ObjectUtils.isEmpty(adjValue.get(arr[4])) ? "0" : new BigDecimal(adjValue.get(arr[4]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setBfg(ObjectUtils.isEmpty(adjValue.get(arr[5])) ? "0" : new BigDecimal(adjValue.get(arr[5]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setLdg(ObjectUtils.isEmpty(adjValue.get(arr[6])) ? "0" : new BigDecimal(adjValue.get(arr[6]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); item.setCog(ObjectUtils.isEmpty(adjValue.get(arr[7])) ? "0" : new BigDecimal(adjValue.get(arr[7]).toString()).setScale(2, BigDecimal.ROUND_HALF_UP).toString()); return item; }).collect(Collectors.toList()); } return list; } }