package com.ruoyi.jianguan.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.jianguan.service.TScreenContentService;
import com.ruoyi.jianguan.service.TSystemConfigurationService;
import com.ruoyi.jianguan.util.KsolarUtils;
import com.ruoyi.jianguan.vo.*;
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
import com.ruoyi.other.api.domain.TScreenContent;
import com.ruoyi.other.api.domain.TSystemConfiguration;
import com.ruoyi.other.api.feignClient.OtherClient;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
/**
*
* 前端控制器
*
*
* @author huliguo
* @since 2025/5/23
*/
@RestController
@RequestMapping("/t_screen_content")
public class TScreenContentController {
@Resource
private TScreenContentService screenContentService;
@Autowired
private OtherClient otherClient;
/**
* 顶部-累计电量
*/
@ApiOperation(tags = {"顶部-累计电量"},value = "充电桩数据大屏")
@GetMapping(value = "/top")
public AjaxResult top(@RequestParam("siteIds") List siteIds) {
return AjaxResult.success(screenContentService.top(siteIds));
}
/**
* 光伏发电和消纳 这里的绿电是调后台大屏内容管理的
*/
@ApiOperation(tags = {"光伏发电和消纳"},value = "充电桩数据大屏")
@GetMapping(value = "/photovoltaicAndConsumption")
public AjaxResult photovoltaicAndConsumption() {
//需调用接口 获取光伏发电量
PhotovoltaicAndConsumptionVO vo = new PhotovoltaicAndConsumptionVO();
vo.setTodayGenerateElectricity(new BigDecimal(KsolarUtils.getTodayEnergy(LocalDateTime.now().toString())));
vo.setGreenElectricityToday(vo.getTodayGenerateElectricity().multiply(new BigDecimal("0.94")).setScale(2, RoundingMode.HALF_UP));
return AjaxResult.success(vo);
}
/**
* 累计减排数据
*/
@ApiOperation(tags = {"减排数据"},value = "充电桩数据大屏")
@GetMapping(value = "/emissionReduction")
public AjaxResult emissionReduction (@RequestParam("siteIds") List siteIds) {
return AjaxResult.success( screenContentService.emissionReduction(siteIds));
}
/**
* 光伏发电实时情况
*/
@ApiOperation(tags = {"光伏发电实时情况"},value = "充电桩数据大屏")
@GetMapping(value = "/photovoltaicPowerGeneration")
public AjaxResult photovoltaicPowerGeneration (@RequestParam("siteIds") List siteIds) {
return AjaxResult.success( screenContentService.photovoltaicPowerGeneration(siteIds));
}
/**
* 储能放电情况
*/
@ApiOperation(tags = {"储能放电情况"},value = "充电桩数据大屏")
@GetMapping(value = "/energyStorageDischarge")
public AjaxResult energyStorageDischarge() {
String electricity = KsolarUtils.getElectricity();
R> systemConfiguration = otherClient.getTSystemConfiguration();
List list = systemConfiguration.getData();
// List list = systemConfigurationService.list(new LambdaQueryWrapper().in(TSystemConfiguration::getType, 4, 5));
// 昨日放能
TSystemConfiguration sysConfig = list.stream().filter(e -> e.getType() == 4).findFirst().orElse(null);
// 昨日储能
TSystemConfiguration sysConfig1 = list.stream().filter(e -> e.getType() == 5).findFirst().orElse(null);
// 总储能
String s = electricity.split("_")[0];
// 总放能
String s1 = electricity.split("_")[1];
EnergyStorageDischargeVO vo = new EnergyStorageDischargeVO();
BigDecimal subtract = new BigDecimal(s1).subtract(new BigDecimal(sysConfig.getContent()));
vo.setTodayDischarge(subtract);
BigDecimal subtract1 = new BigDecimal(s).subtract(new BigDecimal(sysConfig1.getContent()));
vo.setTodayStorage(subtract1);
return AjaxResult.success(vo);
}
/**
* 停车场共享情况及相关数据
*/
@ApiOperation(tags = {"停车场共享情况及相关数据"},value = "充电桩数据大屏")
@GetMapping(value = "/screen")
public AjaxResult screen(@RequestParam("siteIds") List siteIds) {
List list = screenContentService.list(new LambdaQueryWrapper().in(TScreenContent::getSiteId, siteIds));
TScreenContent tScreenContent = new TScreenContent();
if(list==null|| list.isEmpty()){
return AjaxResult.success(tScreenContent);
}
BeanUtils.copyProperties(list.get(0),tScreenContent);
list.remove(0);
list.forEach(x->{
tScreenContent.setCarDischarge(tScreenContent.getCarDischarge().add(x.getCarDischarge()));
tScreenContent.setGreenElectricity(tScreenContent.getGreenElectricity().add(x.getGreenElectricity()));
tScreenContent.setGreenElectricityToday(tScreenContent.getGreenElectricityToday().add(x.getGreenElectricityToday()));
tScreenContent.setValueOne(tScreenContent.getValueOne().add(x.getValueOne()));
tScreenContent.setValueTwo(tScreenContent.getValueTwo().add(x.getValueTwo()));
tScreenContent.setValueThree(tScreenContent.getValueThree().add(x.getValueThree()));
if(tScreenContent.getStatisticalDeadline().getTime()<(x.getStatisticalDeadline().getTime())) {
tScreenContent.setStatisticalDeadline(x.getStatisticalDeadline());
}
});
return AjaxResult.success(tScreenContent);
}
@ApiOperation(tags = {"车位数据传输"},value = "充电桩数据大屏")
@PostMapping(value = "/carportData")
public AjaxResult> carportData(Integer parkingPlace,Integer remainPlace) {
screenContentService.carportData(parkingPlace,remainPlace);
return AjaxResult.success();
}
@ApiOperation(tags = {"获取车位数据传输"},value = "充电桩数据大屏")
@GetMapping(value = "/getCarportData")
public AjaxResult> getCarportData() {
HashMap map = screenContentService.getCarportData();
return AjaxResult.success(map);
}
}