| | |
| | | package com.iailab.module.ansteel.api.controller.admin; |
| | | |
| | | import com.iailab.framework.common.exception.enums.GlobalErrorCodeConstants; |
| | | import com.iailab.framework.common.pojo.CommonResult; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.ansteel.api.dto.PowerCapacitorStatusDTO; |
| | | import com.iailab.module.ansteel.api.dto.PowerControlDetDTO; |
| | | import com.iailab.module.ansteel.api.dto.PowerControlMainDTO; |
| | | import com.iailab.module.ansteel.api.dto.PowerNetFactorDTO; |
| | | import com.iailab.module.ansteel.api.entity.*; |
| | | import com.iailab.module.ansteel.api.service.*; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | import static com.iailab.framework.common.pojo.CommonResult.success; |
| | | |
| | | /** |
| | | * 电力接口 |
| | |
| | | @RestController |
| | | @RequestMapping("/ansteel/api/power") |
| | | public class PowerController { |
| | | |
| | | @Autowired |
| | | private PowerNetFactorService powerNetFactorService; |
| | | |
| | | @Autowired |
| | | private PowerCapacitorStatusService powerCapacitorStatusService; |
| | | |
| | | @Autowired |
| | | private PowerControlMainService powerControlMainService; |
| | | |
| | | @Autowired |
| | | private PowerControlDetService powerControlDetService; |
| | | |
| | | @Resource |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @GetMapping("/net-factor/list") |
| | | @Operation(summary = "功率因数-电网拓扑") |
| | | public CommonResult<List<PowerNetFactorDTO>> getPowerNetFactorList(@RequestParam Map<String, Object> params) { |
| | | List<PowerNetFactorEntity> list = powerNetFactorService.list(params); |
| | | List<PowerNetFactorDTO> result = ConvertUtils.sourceToTarget(list, PowerNetFactorDTO.class); |
| | | if (CollectionUtils.isEmpty(result)) { |
| | | return success(result); |
| | | } |
| | | for(PowerNetFactorDTO dto : result) { |
| | | List<String> points = new ArrayList<>(); |
| | | if (StringUtils.isNotBlank(dto.getCurP())) { |
| | | points.add(dto.getCurP()); |
| | | } |
| | | if (StringUtils.isNotBlank(dto.getCurQ())) { |
| | | points.add(dto.getCurQ()); |
| | | } |
| | | if (!CollectionUtils.isEmpty(points)) { |
| | | Map<String, Object> pointsRealValue = dataPointApi.queryPointsRealValue(points); |
| | | if (pointsRealValue.get(dto.getCurP()) != null) { |
| | | dto.setCurP(pointsRealValue.get(dto.getCurP()).toString()); |
| | | } |
| | | if (pointsRealValue.get(dto.getCurQ()) != null) { |
| | | dto.setCurQ(pointsRealValue.get(dto.getCurQ()).toString()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return success(result); |
| | | } |
| | | |
| | | @GetMapping("/capacitor-status/list") |
| | | @Operation(summary = "功率因数-电容器投运状态") |
| | | public CommonResult<List<PowerCapacitorStatusDTO>> getPowerCapacitorStatusList(@RequestParam Map<String, Object> params) { |
| | | List<PowerCapacitorStatusEntity> list = powerCapacitorStatusService.list(params); |
| | | return success(ConvertUtils.sourceToTarget(list, PowerCapacitorStatusDTO.class)); |
| | | } |
| | | |
| | | @GetMapping("/control-main/list") |
| | | @Operation(summary = "功率因数-管控变电站列表") |
| | | public CommonResult<List<PowerControlMainDTO>> getPowerControlMainList(@RequestParam Map<String, Object> params) { |
| | | List<PowerControlMainEntity> list = powerControlMainService.list(params); |
| | | return success(ConvertUtils.sourceToTarget(list, PowerControlMainDTO.class)); |
| | | } |
| | | |
| | | @GetMapping("/control-det/list") |
| | | @Operation(summary = "功率因数-管控功率因数详情") |
| | | public CommonResult<List<PowerControlDetDTO>> getPowerControlDetList(@RequestParam Map<String, Object> params) { |
| | | List<PowerControlDetDTO> result = new ArrayList<>(); |
| | | String name = (String)params.get("name"); |
| | | if (StringUtils.isBlank(name)) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.BAD_REQUEST); |
| | | } |
| | | PowerControlMainEntity main = powerControlMainService.getByName(name); |
| | | if (main == null) { |
| | | return CommonResult.error(GlobalErrorCodeConstants.NOT_FOUND); |
| | | } |
| | | List<PowerControlDetEntity> list = powerControlDetService.list(main.getId()); |
| | | result = ConvertUtils.sourceToTarget(list, PowerControlDetDTO.class); |
| | | |
| | | result.forEach(item -> { |
| | | // 设置随机数据,0.8左右 |
| | | Random rand = new Random(); |
| | | int min = 700; |
| | | int max = 900; |
| | | int randomNumber = rand.nextInt(max - min + 1) + min; |
| | | BigDecimal rv = new BigDecimal(randomNumber * 0.001).setScale(4, BigDecimal.ROUND_HALF_UP); |
| | | item.setValue(rv); |
| | | if (item.getLimitL() != null && rv.compareTo(item.getLimitL()) < 0) { |
| | | item.setStatus(1); |
| | | } else { |
| | | item.setStatus(0); |
| | | } |
| | | }); |
| | | return success(result); |
| | | } |
| | | } |