无关风月
2024-11-01 f91bb885d680d3f30cbf1bcffdd6819b3b10e6b1
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/SiteController.java
@@ -1,10 +1,16 @@
package com.ruoyi.chargingPile.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.account.api.feignClient.AppUserClient;
import com.ruoyi.account.api.feignClient.AppUserVipDetailClient;
import com.ruoyi.account.api.model.TAppUser;
import com.ruoyi.account.api.model.TAppUserVipDetail;
import com.ruoyi.account.api.vo.GetAppUserVipDetail;
import com.ruoyi.chargingPile.api.dto.GetSiteListDTO;
import com.ruoyi.chargingPile.api.feignClient.ParkingLotClient;
import com.ruoyi.chargingPile.api.model.*;
@@ -18,6 +24,7 @@
import com.ruoyi.common.core.dto.ChargingPercentProvinceDto;
import com.ruoyi.chargingPile.service.*;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
@@ -40,6 +47,7 @@
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -99,7 +107,8 @@
   private TokenService tokenService;
   @Resource
   private AppUserClient appUserClient;
   @Resource
   private AppUserVipDetailClient vipDetailClient;
   /**
    * 根据站点id 查询所有充电桩
@@ -122,29 +131,37 @@
      SiteInfoVO siteInfoVO = new SiteInfoVO();
      TChargingGun chargingGun = chargingGunService.getOne(new LambdaQueryWrapper<TChargingGun>().eq(TChargingGun::getFullNumber, number));
      TChargingPile one = chargingPileService.getById(chargingGun.getChargingPileId());
      Site byId = siteService.getById(one.getSiteId());
      TAccountingStrategy byId1 = accountingStrategyService.getById(byId.getAccountingStrategyId());
      Site byId = siteService.getById(chargingGun.getSiteId());
      TAccountingStrategy byId1 = accountingStrategyService.getById(chargingGun.getAccountingStrategyId());
      List<TAccountingStrategyDetail> list = accountingStrategyDetailService.lambdaQuery().eq(TAccountingStrategyDetail::getAccountingStrategyId, byId1.getId()).list();
      list.stream().filter(item -> "00:00".equals(item.getEndTime())).forEach(item -> item.setEndTime("23:59:59"));
      for (TAccountingStrategyDetail tAccountingStrategyDetail : list) {
         // 当前时间属于那个阶段 取哪个阶段的电价
         if(LocalTime.now().isAfter(LocalTime.parse(tAccountingStrategyDetail.getStartTime())) && LocalTime.now().isBefore(LocalTime.parse(tAccountingStrategyDetail.getEndTime()))){
         if(DateUtils.string2LocalTime(tAccountingStrategyDetail.getStartTime() + ":00").compareTo(LocalTime.now()) <= 0
               && DateUtils.string2LocalTime(tAccountingStrategyDetail.getEndTime() + ("23:59:59".equals(tAccountingStrategyDetail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0){
            siteInfoVO.setElectrovalence(tAccountingStrategyDetail.getElectrovalence().add(tAccountingStrategyDetail.getServiceCharge()).setScale(4, BigDecimal.ROUND_HALF_UP));
            if(null != byId1.getDiscount()){
            // 获取当前登录用户id
            Long userId = tokenService.getLoginUserApplet().getUserId();
            // 根据id查询用户信息
            TAppUser appUser = appUserClient.getUserById(userId).getData();
            if(Objects.nonNull(byId1.getDiscount())){
               siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().multiply(byId1.getDiscount()).add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
            }else{
               // 获取当前登录用户id
               Long userId = tokenService.getLoginUserApplet().getUserId();
               // 根据id查询用户信息
               TAppUser appUser = appUserClient.getUserById(userId).getData();
               if(Objects.nonNull(appUser)){
                  TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
            }else {
               siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
            }
            if(Objects.nonNull(appUser)){
//               TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
               GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
               getAppUserVipDetail.setAppUserId(userId);
               getAppUserVipDetail.setVipId(appUser.getVipId());
               R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
               TAppUserVipDetail data1 = appUserVipDetail.getData();
               if(Objects.nonNull(data1)){
                  String vipJson = data1.getVipJson();
                  TVip vip = JSON.parseObject(vipJson, TVip.class);
                  if(Objects.nonNull(vip) && vip.getType() == 2){
                     siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
                  }else {
                     siteInfoVO.setVipElectrovalence(tAccountingStrategyDetail.getElectrovalence());
                  }
               }else {
                  siteInfoVO.setVipElectrovalence(tAccountingStrategyDetail.getElectrovalence());
               }
            }
         }
@@ -168,16 +185,49 @@
      Site byId = siteService.getById(one.getSiteId());
      TAccountingStrategy byId1 = accountingStrategyService.getById(byId.getAccountingStrategyId());
      List<TAccountingStrategyDetail> list = accountingStrategyDetailService.lambdaQuery().eq(TAccountingStrategyDetail::getAccountingStrategyId, byId1.getId()).list();
      list.stream().filter(item -> "00:00".equals(item.getEndTime())).forEach(item -> item.setEndTime("23:59:59"));
      for (TAccountingStrategyDetail tAccountingStrategyDetail : list) {
         // 当前时间属于那个阶段 取哪个阶段的电价
         if(LocalTime.now().isAfter(LocalTime.parse(tAccountingStrategyDetail.getStartTime())) && LocalTime.now().isBefore(LocalTime.parse(tAccountingStrategyDetail.getEndTime()))){
            siteInfoVO.setElectrovalence(tAccountingStrategyDetail.getElectrovalence());
            if(null != byId1.getDiscount()){
               siteInfoVO.setVipElectrovalence(tAccountingStrategyDetail.getElectrovalence().multiply(byId1.getDiscount()).setScale(4, BigDecimal.ROUND_HALF_UP));
            }else{
               siteInfoVO.setVipElectrovalence(tAccountingStrategyDetail.getElectrovalence());
         if(DateUtils.string2LocalTime(tAccountingStrategyDetail.getStartTime() + ":00").compareTo(LocalTime.now()) <= 0
               && DateUtils.string2LocalTime(tAccountingStrategyDetail.getEndTime() + ("23:59:59".equals(tAccountingStrategyDetail.getEndTime())?"":":00")).compareTo(LocalTime.now()) > 0){
            siteInfoVO.setElectrovalence(tAccountingStrategyDetail.getElectrovalence().add(tAccountingStrategyDetail.getServiceCharge()).setScale(4, BigDecimal.ROUND_HALF_UP));
            // 获取当前登录用户id
            Long userId = tokenService.getLoginUserApplet().getUserId();
            // 根据id查询用户信息
            TAppUser appUser = appUserClient.getUserById(userId).getData();
            if(Objects.nonNull(byId1.getDiscount())){
               siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().multiply(byId1.getDiscount()).add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
            }else {
               siteInfoVO.setVipElectrovalence((tAccountingStrategyDetail.getServiceCharge().add(tAccountingStrategyDetail.getElectrovalence())).setScale(4, BigDecimal.ROUND_HALF_UP));
            }
            if(Objects.nonNull(appUser)){
//               TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
               GetAppUserVipDetail getAppUserVipDetail = new GetAppUserVipDetail();
               getAppUserVipDetail.setAppUserId(userId);
               getAppUserVipDetail.setVipId(appUser.getVipId());
               R<TAppUserVipDetail> appUserVipDetail = vipDetailClient.getAppUserVipDetail(getAppUserVipDetail);
               TAppUserVipDetail data1 = appUserVipDetail.getData();
               if(Objects.nonNull(data1)){
                  String vipJson = data1.getVipJson();
                  TVip vip = JSON.parseObject(vipJson, TVip.class);
                  if(Objects.nonNull(vip) && vip.getType() == 2){
                     siteInfoVO.setVipElectrovalence(vip.getDiscount().divide(new BigDecimal(10)).multiply(tAccountingStrategyDetail.getServiceCharge()).add(tAccountingStrategyDetail.getElectrovalence()));
                  }
               }
            }
         }
      }
      List<TVip> vips = vipClient.getVipList().getData();
      if(!CollectionUtils.isEmpty(vips)){
         TVip tVip = vips.get(0);
         JSONArray objects = JSONArray.parseArray(tVip.getCoupon());
         Integer num = 0;
         for (Object object : objects) {
            JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(object));
            Integer number1 = jsonObject.getInteger("number");
            num += number1;
         }
         siteInfoVO.setCouponCount(num);
      }
      siteInfoVO.setChargingPileId(one.getId());
      siteInfoVO.setName(byId.getName());
@@ -211,17 +261,22 @@
      siteList.setPageSize(99999);
      PageInfo<GetSiteListDTO> list = siteService.getSiteList(siteList);
      for (GetSiteListDTO record : list.getRecords()) {
         Long count = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).eq(TChargingGun::getStatus, new int[]{3, 4, 5, 6}).count();
         List<Integer> c1 = new ArrayList<>();
         c1.add(3);
         c1.add(4);
         c1.add(5);
         c1.add(6);
         Long count = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).eq(TChargingGun::getStatus, 2).count();
         record.setC1(count);
         Long count1 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).eq(TChargingGun::getStatus, 2).count();
         Long count1 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 1).count();
         record.setC2(count1);
         Long count2 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).eq(TChargingGun::getStatus, new int[]{3, 4, 5, 6}).count();
         Long count2 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).eq(TChargingGun::getStatus, 2).count();
         record.setK1(count2);
         Long count3 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).eq(TChargingGun::getStatus, 2).count();
         Long count3 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 2).count();
         record.setK2(count3);
         Long count4 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).eq(TChargingGun::getStatus, new int[]{3, 4, 5, 6}).count();
         Long count4 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).eq(TChargingGun::getStatus, 2).count();
         record.setM1(count4);
         Long count5 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).eq(TChargingGun::getStatus, 2).count();
         Long count5 = chargingGunService.lambdaQuery().eq(TChargingGun::getSiteId, record.getId()).eq(TChargingGun::getChargeMode, 3).count();
         record.setM2(count5);
         //利用率
@@ -277,14 +332,7 @@
   @ApiOperation(value = "获取该充电站的利用率", tags = {"管理后台-数据分析-电站分析"})
   public R getPercentByCityCode(@RequestBody ChargingPercentProvinceDto chargingPercentProvinceDto){
      if (chargingPercentProvinceDto.getDate1()==null){
         LocalDate today = LocalDate.now();
         LocalDate lastMonth = today.minusMonths(1);
         LocalDate firstDayOfLastMonth = lastMonth.withDayOfMonth(1);
         LocalDate lastDayOfLastMonth =lastMonth.withDayOfMonth(lastMonth.lengthOfMonth());
         chargingPercentProvinceDto.setDate1(firstDayOfLastMonth);
         chargingPercentProvinceDto.setDate2(lastDayOfLastMonth);
      }
@@ -298,6 +346,9 @@
      List<GetSiteListDTO> records = siteService.getSiteList(siteList).getRecords();
      List<Integer> collect = records.stream().map(GetSiteListDTO::getId).collect(Collectors.toList());
      // 通过时间段获取和充电桩id获取各个充电站的充电订单
      if (chargingPercentProvinceDto.getDate1().equals(chargingPercentProvinceDto.getDate2())){
         chargingPercentProvinceDto.setDate2(chargingPercentProvinceDto.getDate1().plusDays(1));
      }
         List<ChargingOrderGroup> data = chargingOrderClient.getBySiteIdAndTime(chargingPercentProvinceDto).getData();
      // 计算利用率展示
      for (ChargingOrderGroup datum : data) {
@@ -307,7 +358,7 @@
            bigDecimal1 = bigDecimal1.add(chargingPile.getRatedPower());
         }
         long daysBetween = ChronoUnit.DAYS.between(chargingPercentProvinceDto.getDate1(), chargingPercentProvinceDto.getDate2()) + 1;
         long daysBetween = ChronoUnit.DAYS.between(chargingPercentProvinceDto.getDate1(), chargingPercentProvinceDto.getDate2());
         BigDecimal multiply = bigDecimal1.multiply(new BigDecimal("24")).multiply(BigDecimal.valueOf(daysBetween));
         //得到利用率
         BigDecimal divide = datum.getChargingCapacity().divide(multiply, 0, BigDecimal.ROUND_HALF_UP);
@@ -360,8 +411,9 @@
   @ApiOperation(value = "获取站点列表", tags = {"小程序-站点管理-地图导航站点"})
   @PostMapping("/getMapSiteList")
   public AjaxResult<List<SiteVO>> getMapSiteList(@Validated @RequestBody SiteQuery query){
      return AjaxResult.success(siteService.getMapSiteList(query));
   public AjaxResult<List<SiteVO>> getMapSiteList(@Validated @RequestBody SiteQuery query, HttpServletRequest request){
      int isLogin = StringUtils.isEmpty(SecurityUtils.getToken(request)) ? 0 : 1;
      return AjaxResult.success(siteService.getMapSiteList(query,isLogin));
   }
   @ApiOperation(value = "获取站点详细信息", tags = {"小程序-站点管理-站点详情"})
   @PostMapping("/getDetailById")