|
|
@ -1,27 +1,32 @@ |
|
|
package com.thing.qingyuan.manageboard.service.impl; |
|
|
package com.thing.qingyuan.manageboard.service.impl; |
|
|
|
|
|
|
|
|
import cn.hutool.core.map.MapUtil; |
|
|
import cn.hutool.core.map.MapUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists; |
|
|
import com.mybatisflex.core.query.QueryColumn; |
|
|
import com.mybatisflex.core.query.QueryColumn; |
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
import com.mybatisflex.core.query.QueryWrapper; |
|
|
|
|
|
import com.thing.common.core.utils.ConvertUtils; |
|
|
|
|
|
import com.thing.common.data.tskv.TsKvDTO; |
|
|
|
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
|
|
|
import com.thing.common.tskv.service.TsKvService; |
|
|
import com.thing.qingyuan.manageboard.dto.MapParam; |
|
|
import com.thing.qingyuan.manageboard.dto.MapParam; |
|
|
import com.thing.qingyuan.manageboard.dto.PlantDTO; |
|
|
import com.thing.qingyuan.manageboard.dto.PlantDTO; |
|
|
import com.thing.qingyuan.manageboard.dto.PlantInfoReq; |
|
|
import com.thing.qingyuan.manageboard.dto.PlantInfoReq; |
|
|
import com.thing.qingyuan.manageboard.entity.PlantEntity; |
|
|
import com.thing.qingyuan.manageboard.entity.PlantEntity; |
|
|
import com.thing.qingyuan.manageboard.mapper.PlantMapper; |
|
|
import com.thing.qingyuan.manageboard.mapper.PlantMapper; |
|
|
import com.thing.qingyuan.manageboard.service.PlantService; |
|
|
import com.thing.qingyuan.manageboard.service.PlantService; |
|
|
import com.thing.common.core.utils.ConvertUtils; |
|
|
|
|
|
import com.thing.common.orm.service.impl.BaseServiceImpl; |
|
|
|
|
|
import com.thing.sys.security.context.UserContext; |
|
|
import com.thing.sys.security.context.UserContext; |
|
|
import com.thing.thing.entity.dto.IotThingEntityDTO; |
|
|
import com.thing.thing.entity.dto.IotThingEntityDTO; |
|
|
import com.thing.thing.entity.service.IotThingEntityService; |
|
|
import com.thing.thing.entity.service.IotThingEntityService; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.math.RoundingMode; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.Objects; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -34,12 +39,12 @@ import static com.mybatisflex.core.query.QueryMethods.column; |
|
|
* @since 3.0 2024-01-29 |
|
|
* @since 3.0 2024-01-29 |
|
|
*/ |
|
|
*/ |
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
|
|
|
public class PlantServiceImpl extends BaseServiceImpl<PlantMapper, PlantEntity> implements PlantService { |
|
|
public class PlantServiceImpl extends BaseServiceImpl<PlantMapper, PlantEntity> implements PlantService { |
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
|
@Resource |
|
|
IotThingEntityService iotThingEntityService; |
|
|
IotThingEntityService iotThingEntityService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
private TsKvService tsKvService; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
public QueryWrapper getWrapper(Map<String, Object> params){ |
|
|
@ -63,6 +68,54 @@ public class PlantServiceImpl extends BaseServiceImpl<PlantMapper, PlantEntity> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public List<PlantDTO> list(Map<String, Object> params) { |
|
|
|
|
|
List<PlantDTO> plantDTOS = listAs(params, PlantDTO.class); |
|
|
|
|
|
if(CollectionUtils.isEmpty(plantDTOS)){ |
|
|
|
|
|
return Lists.newArrayList(); |
|
|
|
|
|
} |
|
|
|
|
|
for (PlantDTO plantDTO : plantDTOS) { |
|
|
|
|
|
Long plantId = plantDTO.getPlantId(); |
|
|
|
|
|
//年发电量 |
|
|
|
|
|
TsKvDTO tsKvDTO29 = tsKvService.findLatestByCodeAndAttr(String.valueOf(plantId), "A29yy"); |
|
|
|
|
|
if(!Objects.isNull(tsKvDTO29)){ |
|
|
|
|
|
plantDTO.setAttrKey29(tsKvDTO29.getAttrKey()); |
|
|
|
|
|
plantDTO.setVal29(tsKvDTO29.getVal()); |
|
|
|
|
|
//减排量 |
|
|
|
|
|
if(!Objects.isNull(plantDTO.getProfitco())){ |
|
|
|
|
|
plantDTO.setReduction( |
|
|
|
|
|
new BigDecimal(tsKvDTO29.getVal()) |
|
|
|
|
|
.subtract(new BigDecimal(plantDTO.getProfitco())) |
|
|
|
|
|
.setScale(4, RoundingMode.HALF_UP) // 保留四位小数,四舍五入 |
|
|
|
|
|
.toPlainString() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//当前功率 |
|
|
|
|
|
TsKvDTO tsKvDTO16 = tsKvService.findLatestByCodeAndAttr(String.valueOf(plantId), "A16"); |
|
|
|
|
|
if(!Objects.isNull(tsKvDTO16)){ |
|
|
|
|
|
plantDTO.setAttrKey16(tsKvDTO16.getAttrKey()); |
|
|
|
|
|
plantDTO.setVal16(tsKvDTO16.getVal()); |
|
|
|
|
|
} |
|
|
|
|
|
//今日发电量 |
|
|
|
|
|
TsKvDTO tsKvDToday29 = tsKvService.findLatestByCodeAndAttr(String.valueOf(plantId), "A29dd"); |
|
|
|
|
|
if(!Objects.isNull(tsKvDToday29)){ |
|
|
|
|
|
plantDTO.setAttrKeyToday29(tsKvDToday29.getAttrKey()); |
|
|
|
|
|
plantDTO.setValToday29(tsKvDToday29.getVal()); |
|
|
|
|
|
//今日减排量 |
|
|
|
|
|
if(!Objects.isNull(plantDTO.getProfitco())){ |
|
|
|
|
|
plantDTO.setTodayReduction( |
|
|
|
|
|
new BigDecimal(tsKvDToday29.getVal()) |
|
|
|
|
|
.subtract(new BigDecimal(plantDTO.getProfitco())) |
|
|
|
|
|
.setScale(4, RoundingMode.HALF_UP) // 保留四位小数,四舍五入 |
|
|
|
|
|
.toPlainString() |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return plantDTOS; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Map<String,List<PlantDTO>> findByParam(MapParam mapParam) { |
|
|
public Map<String,List<PlantDTO>> findByParam(MapParam mapParam) { |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
QueryWrapper wrapper = new QueryWrapper(); |
|
|
|