| | |
| | | import com.ruoyi.account.api.model.*; |
| | | import com.ruoyi.account.api.vo.GetAppUserVipDetail; |
| | | import com.ruoyi.account.api.vo.GetInviteUser; |
| | | import com.ruoyi.chargingPile.api.dto.GetSiteListDTO; |
| | | import com.ruoyi.chargingPile.api.feignClient.*; |
| | | import com.ruoyi.chargingPile.api.model.*; |
| | | import com.ruoyi.chargingPile.api.vo.GetChargingGunByCode; |
| | |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.integration.api.feignClient.ChargingHandshakeClient; |
| | | import com.ruoyi.integration.api.feignClient.PlatformStartChargingReplyClient; |
| | | import com.ruoyi.integration.api.feignClient.SendMessageClient; |
| | |
| | | } |
| | | dto.setUserIds(data); |
| | | } |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (dto.getSiteId()==null){ |
| | | if (userId != null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | }else { |
| | | siteIds.add(dto.getSiteId()); |
| | | } |
| | | dto.setSiteIds(siteIds); |
| | | List<ChargingOrderVO> list = this.baseMapper.chargingOrder(pageInfo,dto,startTime1,startTime2,endTime1,endTime2); |
| | | List<ChargingOrderVO> list1 = this.baseMapper.chargingOrder(pageInfo1,dto,startTime1,startTime2,endTime1,endTime2); |
| | | BigDecimal total = new BigDecimal("0"); |
| | |
| | | dto.setCarIds(carIds); |
| | | } |
| | | } |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (dto.getSiteId()==null){ |
| | | if (userId != null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | }else { |
| | | siteIds.add(dto.getSiteId()); |
| | | } |
| | | dto.setSiteIds(siteIds); |
| | | PageInfo<ChargingOrderListVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | List<ChargingOrderListVO> list = this.baseMapper.chargingList(pageInfo,dto,startTime1,startTime2,endTime1,endTime2); |
| | | for (ChargingOrderListVO chargingOrderListVO : list) { |
| | |
| | | } |
| | | dto.setStartTime(startTime); |
| | | dto.setEndTime(endTime); |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (dto.getSiteIds()==null){ |
| | | if (userId != null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | }else { |
| | | siteIds.add(dto.getSiteIds()); |
| | | } |
| | | dto.setSiteIdss(siteIds); |
| | | PageInfo<TSettlementConfirm> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize()); |
| | | List<TSettlementConfirm> list = tSettlementConfirmMapper.settlementList(pageInfo,dto); |
| | | for (TSettlementConfirm tSettlementConfirm : list) { |
| | |
| | | |
| | | @Override |
| | | public SettlementTotalVO settlementTotal(String time) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (userId != null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | SettlementTotalVO res = new SettlementTotalVO(); |
| | | List<TSettlementConfirm> list1 = tSettlementConfirmMapper.settlementTotal(time); |
| | | List<TSettlementConfirm> list1 = tSettlementConfirmMapper.settlementTotal(time,siteIds); |
| | | LocalDateTime parse = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | // 减少一个月 |
| | | LocalDateTime minus = parse.minusMonths(1); |
| | | List<TSettlementConfirm> list2 = tSettlementConfirmMapper.settlementTotal(time); |
| | | List<TSettlementConfirm> list2 = tSettlementConfirmMapper.settlementTotal(time,siteIds); |
| | | // 合计 |
| | | List<TSettlementConfirm> total = new ArrayList<>(); |
| | | |
| | | TSettlementConfirm tSettlementConfirm1 = new TSettlementConfirm(); |
| | | BigDecimal meteringElectronic = new BigDecimal("0"); |
| | | BigDecimal chargingElectronic = new BigDecimal("0"); |
| | | BigDecimal lossElectronic = new BigDecimal("0"); |
| | | BigDecimal income = new BigDecimal("0"); |
| | | BigDecimal venue = new BigDecimal("0"); |
| | | BigDecimal metering = new BigDecimal("0"); |
| | | BigDecimal clean = new BigDecimal("0"); |
| | | BigDecimal maintain = new BigDecimal("0"); |
| | | BigDecimal cost = new BigDecimal("0"); |
| | | BigDecimal profitMoney = new BigDecimal("0"); |
| | | BigDecimal newMoney = new BigDecimal("0"); |
| | | BigDecimal newSettlement = new BigDecimal("0"); |
| | | BigDecimal supplyElectronic = new BigDecimal("0"); |
| | | BigDecimal proportionPartner = new BigDecimal("0"); |
| | | BigDecimal proportionMoney = new BigDecimal("0"); |
| | | BigDecimal totalElectronic = new BigDecimal("0"); |
| | | BigDecimal totalService = new BigDecimal("0"); |
| | | BigDecimal servicePartner = new BigDecimal("0"); |
| | | BigDecimal serviceMoney = new BigDecimal("0"); |
| | | BigDecimal sharingAmount = new BigDecimal("0"); |
| | | BigDecimal commissionAmount = new BigDecimal("0"); |
| | | BigDecimal electrovalence = new BigDecimal("0"); |
| | | BigDecimal serviceCharge = new BigDecimal("0"); |
| | | BigDecimal orderCommission = new BigDecimal("0"); |
| | | BigDecimal vipDiscount = new BigDecimal("0"); |
| | | BigDecimal couponDiscount = new BigDecimal("0"); |
| | | // tSettlementConfirm1.setIncomePercentage(); |
| | | // tSettlementConfirm1.setTotalPercentage(); |
| | | tSettlementConfirm1.setElectronicRefund(0); |
| | | // 上月成本合计 |
| | | BigDecimal beforeCost= new BigDecimal("0"); |
| | | // 上月利润合计 |
| | | BigDecimal beforeIncome= new BigDecimal("0"); |
| | | int i = 1; |
| | | for (TSettlementConfirm tSettlementConfirm : list1) { |
| | | tSettlementConfirm.setXuhao(i); |
| | | tSettlementConfirm.setMetering(tSettlementConfirm.getSupplyElectronic()); |
| | | List<Site> data1 = siteClient.getSiteByIds(Arrays.asList(tSettlementConfirm.getSiteId())).getData(); |
| | | if (!data1.isEmpty()){ |
| | | tSettlementConfirm.setSiteName(data1.get(0).getName()); |
| | | } |
| | | if (tSettlementConfirm.getMeteringElectronic()!=null){ |
| | | meteringElectronic = meteringElectronic.add(tSettlementConfirm.getMeteringElectronic()); |
| | | chargingElectronic = chargingElectronic.add(tSettlementConfirm.getChargingElectronic()); |
| | | } |
| | | if (tSettlementConfirm.getLossElectronic()!=null){ |
| | | lossElectronic = lossElectronic.add(tSettlementConfirm.getLossElectronic()); |
| | | } |
| | | income = income.add(tSettlementConfirm.getIncome()); |
| | | venue = venue.add(tSettlementConfirm.getVenue()); |
| | | metering = metering.add(tSettlementConfirm.getMetering()); |
| | | clean = clean.add(tSettlementConfirm.getClean()); |
| | | maintain = maintain.add(tSettlementConfirm.getMaintain()); |
| | | cost = cost.add(tSettlementConfirm.getCost()); |
| | | profitMoney = profitMoney.add(tSettlementConfirm.getProfitMoney()); |
| | | newMoney = newMoney.add(tSettlementConfirm.getNewMoney()); |
| | | newSettlement = newSettlement.add(tSettlementConfirm.getNewSettlement()); |
| | | supplyElectronic = supplyElectronic.add(tSettlementConfirm.getSupplyElectronic()); |
| | | proportionPartner = proportionPartner.add(tSettlementConfirm.getProportionPartner()); |
| | | proportionMoney = proportionMoney.add(tSettlementConfirm.getProportionMoney()); |
| | | totalElectronic = totalElectronic.add(tSettlementConfirm.getTotalElectronic()); |
| | | totalService = totalService.add(tSettlementConfirm.getTotalService()); |
| | | servicePartner = servicePartner.add(tSettlementConfirm.getServicePartner()); |
| | | serviceMoney = serviceMoney.add(tSettlementConfirm.getServiceMoney()); |
| | | sharingAmount = sharingAmount.add(tSettlementConfirm.getSharingAmount()); |
| | | commissionAmount = commissionAmount.add(tSettlementConfirm.getCommissionAmount()); |
| | | electrovalence = electrovalence.add(tSettlementConfirm.getElectrovalence()); |
| | | serviceCharge = serviceCharge.add(tSettlementConfirm.getServiceCharge()); |
| | | orderCommission = orderCommission.add(tSettlementConfirm.getOrderCommission()); |
| | | vipDiscount = vipDiscount.add(tSettlementConfirm.getVipDiscount()); |
| | | couponDiscount = couponDiscount.add(tSettlementConfirm.getCouponDiscount()); |
| | | |
| | | // 查询结算确认单开始时间和结束时间的单子 |
| | | QueryWrapper<TChargingOrder> eq = new QueryWrapper<TChargingOrder>() |
| | | .eq("site_id", tSettlementConfirm.getSiteId()) |
| | | .eq("recharge_payment_status",2); |
| | | switch (tSettlementConfirm.getType()){ |
| | | case 1: |
| | | eq.between("start_time", tSettlementConfirm.getStartTime(), tSettlementConfirm.getEndTime()); |
| | | break; |
| | | case 2: |
| | | eq.between("end_time", tSettlementConfirm.getStartTime(), tSettlementConfirm.getEndTime()); |
| | | break; |
| | | } |
| | | List<TChargingOrder> tChargingOrders = this.baseMapper.selectList(eq); |
| | | Map<String,TChargingOrder> map = new HashMap<>(); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | for (TChargingOrder tChargingOrder : tChargingOrders) { |
| | | stringBuilder.append(tChargingOrder.getCode()).append(","); |
| | | |
| | | } |
| | | // 充电总时长 |
| | | |
| | | Long temp = 1L; |
| | | if (StringUtils.hasLength(stringBuilder.toString())){ |
| | | String substring = stringBuilder.substring(0, stringBuilder.length() - 1); |
| | | for (String s : substring.split(",")) { |
| | | UploadRealTimeMonitoringData data6 = uploadRealTimeMonitoringDataClient.chargingOrderInfo(s).getData(); |
| | | if (data6!=null){ |
| | | temp+=(data6.getCumulative_charging_time()*60); |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | List<TChargingPile> data = siteClient.getPileListBySiteId(tSettlementConfirm.getSiteId()).getData(); |
| | | // 计算充电桩的功率平均值 |
| | | BigDecimal bigDecimal = new BigDecimal("0"); |
| | | for (TChargingPile datum : data) { |
| | | bigDecimal = bigDecimal.add(datum.getRatedPower()); |
| | | } |
| | | |
| | | |
| | | tSettlementConfirm.setIncome(tSettlementConfirm.getElectrovalence().add(tSettlementConfirm.getServiceCharge())); |
| | | //利用率=充电量/(桩数量*功率*时间) |
| | | List<TChargingPile> data2 = chargingPileClient.getChargingPileBySiteId(tSettlementConfirm.getSiteId()).getData(); |
| | | BigDecimal bigDecimal2 = new BigDecimal("0"); |
| | | |
| | | if (data2!=null && (!data2.isEmpty())){ |
| | | for (TChargingPile tChargingPile : data2) { |
| | | bigDecimal2 = bigDecimal2.add(tChargingPile.getRatedPower()); |
| | | } |
| | | BigDecimal bigDecimal1 = new BigDecimal(data2.size()+""); |
| | | // 平均功率 |
| | | BigDecimal divide = bigDecimal2.divide(bigDecimal1, 2, RoundingMode.HALF_DOWN); |
| | | // 充电量 |
| | | BigDecimal chargingElectronic1 = tSettlementConfirm.getChargingElectronic(); |
| | | // 桩数量 |
| | | BigDecimal bigDecimal3 = new BigDecimal(data2.size()); |
| | | BigDecimal multiply = chargingElectronic1.multiply(new BigDecimal("24")); |
| | | BigDecimal multiply1 = bigDecimal3.multiply(divide).multiply(new BigDecimal(temp)); |
| | | tSettlementConfirm.setRate(chargingElectronic1.divide(multiply1,2,RoundingMode.HALF_DOWN)+""); |
| | | }else{ |
| | | tSettlementConfirm.setRate(""); |
| | | } |
| | | |
| | | |
| | | for (TSettlementConfirm settlementConfirm : list2) { |
| | | int value = parse.getMonth().getValue(); |
| | | settlementConfirm.setMonth(value); |
| | | settlementConfirm.setIncome(settlementConfirm.getElectrovalence().add(settlementConfirm.getServiceCharge())); |
| | | tSettlementConfirm.setMetering(tSettlementConfirm.getSupplyElectronic()); |
| | | if (tSettlementConfirm.getSiteId().equals(settlementConfirm.getSiteId())){ |
| | | // 电站相同比较收入涨幅跌幅 |
| | | if (tSettlementConfirm.getIncome().compareTo(BigDecimal.ZERO)>0){ |
| | | BigDecimal subtract = tSettlementConfirm.getIncome().subtract(settlementConfirm.getIncome()).divide(tSettlementConfirm.getIncome(),2, RoundingMode.HALF_DOWN).multiply(new BigDecimal("100")); |
| | | tSettlementConfirm.setIncomePercentage(subtract+"%"); |
| | | }else { |
| | | tSettlementConfirm.setIncomePercentage("100"+"%"); |
| | | |
| | | } |
| | | |
| | | // 比较总利润 收入合计-成本合计 |
| | | BigDecimal subtract1 = tSettlementConfirm.getIncome().subtract(tSettlementConfirm.getCost()); |
| | | BigDecimal subtract2 = settlementConfirm.getIncome().subtract(settlementConfirm.getCost()); |
| | | BigDecimal bigDecimal1 = subtract1.subtract(subtract2) |
| | | .divide(subtract2, 2, RoundingMode.HALF_DOWN) |
| | | .multiply(new BigDecimal("100")) |
| | | .setScale(2, RoundingMode.HALF_DOWN); |
| | | tSettlementConfirm.setTotalPercentage(bigDecimal1+"%"); } |
| | | beforeCost = beforeCost.add(settlementConfirm.getCost()); |
| | | beforeIncome = beforeIncome.add(settlementConfirm.getIncome()); |
| | | } |
| | | i++; |
| | | } |
| | | TSettlementConfirm tSettlementConfirm = new TSettlementConfirm(); |
| | | tSettlementConfirm.setMonth(parse.getMonthValue()); |
| | | tSettlementConfirm.setMeteringElectronic(meteringElectronic); |
| | | tSettlementConfirm.setChargingElectronic(chargingElectronic); |
| | | tSettlementConfirm.setLossElectronic(lossElectronic); |
| | | tSettlementConfirm.setIncome(income); |
| | | tSettlementConfirm.setVenue(venue); |
| | | tSettlementConfirm.setMetering(metering); |
| | | tSettlementConfirm.setClean(clean); |
| | | tSettlementConfirm.setMaintain(maintain); |
| | | tSettlementConfirm.setCost(cost); |
| | | tSettlementConfirm.setProfitMoney(profitMoney); |
| | | tSettlementConfirm.setNewMoney(newMoney); |
| | | tSettlementConfirm.setNewSettlement(newSettlement); |
| | | tSettlementConfirm.setSupplyElectronic(supplyElectronic); |
| | | tSettlementConfirm.setProportionPartner(proportionPartner); |
| | | tSettlementConfirm.setProportionMoney(proportionMoney); |
| | | tSettlementConfirm.setTotalElectronic(totalElectronic); |
| | | tSettlementConfirm.setTotalService(totalService); |
| | | tSettlementConfirm.setServicePartner(servicePartner); |
| | | tSettlementConfirm.setServiceMoney(serviceMoney); |
| | | tSettlementConfirm.setSharingAmount(sharingAmount); |
| | | tSettlementConfirm.setCommissionAmount(commissionAmount); |
| | | tSettlementConfirm.setElectrovalence(electrovalence); |
| | | tSettlementConfirm.setServiceCharge(serviceCharge); |
| | | tSettlementConfirm.setOrderCommission(orderCommission); |
| | | tSettlementConfirm.setVipDiscount(vipDiscount); |
| | | tSettlementConfirm.setCouponDiscount(couponDiscount); |
| | | // 本月 |
| | | if (beforeIncome.compareTo(new BigDecimal("0")) == 0){ |
| | | tSettlementConfirm.setIncomePercentage(0+"%"); |
| | | tSettlementConfirm.setIncomePercentage(0+"%"); |
| | | }else{ |
| | | BigDecimal subtract = income.subtract(beforeIncome).divide(beforeIncome,2,RoundingMode.HALF_DOWN).multiply(new BigDecimal("100")); |
| | | tSettlementConfirm.setIncomePercentage(subtract+"%"); |
| | | tSettlementConfirm.setIncomePercentage(subtract+"%"); |
| | | |
| | | } |
| | | // 比较总利润 收入合计-成本合计 |
| | | BigDecimal subtract1 = income.subtract(cost); |
| | | BigDecimal subtract2 = beforeIncome.subtract(beforeCost); |
| | | if (subtract2.compareTo(new BigDecimal("0")) == 0){ |
| | | tSettlementConfirm.setTotalPercentage(0+"%"); |
| | | }else{ |
| | | tSettlementConfirm.setTotalPercentage(subtract1.subtract(subtract2).divide(subtract2,2, RoundingMode.HALF_DOWN).setScale(2, RoundingMode.HALF_DOWN).multiply(new BigDecimal("100"))+"%"); |
| | | } |
| | | tSettlementConfirm.setElectronicRefund(0); |
| | | // 查询上次汇报数据 进行比对涨幅跌幅 |
| | | total.add(tSettlementConfirm); |
| | | res.setList1(list1); |
| | | res.setList2(total); |
| | | return res; |
| | | } |
| | | @Override |
| | | public SettlementTotalVO settlementTotalR(String time,Long userId) { |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (userId != null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | SettlementTotalVO res = new SettlementTotalVO(); |
| | | List<TSettlementConfirm> list1 = tSettlementConfirmMapper.settlementTotal(time,siteIds); |
| | | LocalDateTime parse = LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | // 减少一个月 |
| | | LocalDateTime minus = parse.minusMonths(1); |
| | | List<TSettlementConfirm> list2 = tSettlementConfirmMapper.settlementTotal(time,siteIds); |
| | | // 合计 |
| | | List<TSettlementConfirm> total = new ArrayList<>(); |
| | | |