| | |
| | | package com.ruoyi.order.controller; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | import com.ruoyi.common.core.dto.ChargingOrderGroup; |
| | | import com.ruoyi.common.core.dto.ChargingPercentProvinceDto; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.web.domain.BasePojo; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.log.enums.OperatorType; |
| | |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.integration.api.model.PageChargingOrderAndUploadRealTimeMonitoringDataDto; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringData; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.integration.api.feignClient.UploadRealTimeMonitoringDataClient; |
| | | import com.ruoyi.integration.api.model.ChargingOrderAndUploadRealTimeMonitoringDataDto; |
| | | import com.ruoyi.integration.api.model.UploadRealTimeMonitoringPageData; |
| | | import com.ruoyi.order.api.dto.ChargingStatisticeDTO; |
| | | import com.ruoyi.order.api.model.*; |
| | | import com.ruoyi.order.api.query.ChargingOrderQuery; |
| | |
| | | import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService; |
| | | import com.ruoyi.order.vo.EndOfChargePageInfo; |
| | | import com.ruoyi.order.vo.StatisticsOfBatteryVO; |
| | | import com.ruoyi.order.vo.UpdateOrderPaymentAmountDto; |
| | | import com.ruoyi.order.vo.WatchChargingOrderVo; |
| | | import com.ruoyi.other.api.feignClient.RoleSiteClient; |
| | | import com.ruoyi.other.api.feignClient.UserSiteClient; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.vo.AliQueryOrder; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.feignClient.SysUserRoleClient; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | |
| | | @ResponseBody |
| | | @PostMapping(value = "/refund") |
| | | public R refund(@RequestParam(value = "code") String code){ |
| | | List<UploadRealTimeMonitoringData> dataByOrderCode = uploadRealTimeMonitoringDataService.getDataByOrderCode(code); |
| | | if(!dataByOrderCode.isEmpty()){ |
| | | return R.fail("订单有充电数据,无法全额退款"); |
| | | } |
| | | chargingOrderService.refund(code); |
| | | return R.ok(); |
| | | } |
| | |
| | | }) |
| | | public AjaxResult<PreChargeCheck> preChargeCheck(@PathVariable Integer id) { |
| | | String key = "AQJC_" + id; |
| | | Object cacheObject = redisService.getCacheObject(key); |
| | | PreChargeCheck cacheObject = redisService.getCacheObject(key); |
| | | if(null != cacheObject){ |
| | | if(LocalDateTime.now().minusMinutes(1).isAfter(cacheObject.getAddTime())){ |
| | | redisService.deleteObject(key); |
| | | cacheObject = null; |
| | | } |
| | | } |
| | | return AjaxResult.success(cacheObject); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "电站收入分析", tags = {"后台-数据分析-平台收入分析"}) |
| | | public R<List<SixChargingDto>> charge(Integer siteId) { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | //如果没传siteId,获取当前登陆人所有的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (siteId==null){ |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | }else { |
| | | siteIds.add(siteId); |
| | | } |
| | | if (siteIds.isEmpty()){ |
| | | siteIds.add(-1); |
| | | } |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, siteId); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | //通过siteIds进行sql查询统计 |
| | | List<SixChargingDto> sixChargingDtos = generateLastSixMonths(); |
| | |
| | | @ApiOperation(value = "电站收入占比", tags = {"后台-数据分析-平台收入分析"}) |
| | | public R<List<SixCircleDto>> circle() { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | //获取当前登录的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | //进行统计groupBySiteId |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | if (siteIds.isEmpty()){ |
| | | siteIds.add(-1); |
| | | } |
| | | List<SixCircleDto> sixCircleDtos = chargingOrderService.circle(siteIds,sixBefore); |
| | | for (SixCircleDto sixCircleDto : sixCircleDtos) { |
| | | Site site = siteClient.getSiteByIds(Arrays.asList(sixCircleDto.getSiteId())).getData().get(0); |
| | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询平台收入分析底部数据分类,充电订单金额由数据库聚合,避免全量订单和计费明细加载超时。 |
| | | */ |
| | | @RequiresPermissions(value = {"/platformRevenueAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @GetMapping(value = "/six/total") |
| | |
| | | //count近6个月的数据 |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | //获取当前登录的siteIds |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | List<GetSiteListDTO> data9 = siteClient.getSiteListByUserId(userId).getData(); |
| | | for (GetSiteListDTO datum : data9) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | //进行统计groupBySiteId |
| | | if (siteIds.isEmpty()){ |
| | | siteIds.add(-1); |
| | | } |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | Map<String,Object> map = chargingOrderService.countAll(siteIds); |
| | | if(1 == sysUser.getObjectId()){ |
| | | boolean platformVisible = 1 == sysUser.getObjectId(); |
| | | if(platformVisible){ |
| | | BigDecimal data = parkingLotClient.getRecordAmount().getData(); |
| | | if (map ==null){ |
| | | map = new HashMap<String,Object>(); |
| | |
| | | map.put("shopAmount",0); |
| | | map.put("vipAmount",0); |
| | | } |
| | | List<TChargingOrder> list = chargingOrderService.lambdaQuery().eq(TChargingOrder::getStatus, 5).eq(TChargingOrder::getDelFlag, 0) |
| | | .eq(TChargingOrder::getRechargePaymentStatus, 2).in(TChargingOrder::getSiteId, siteIds).list(); |
| | | BigDecimal sharingAmount = BigDecimal.ZERO; |
| | | BigDecimal commissionAmount = BigDecimal.ZERO; |
| | | //计算list中electrovalence的总和 |
| | | BigDecimal totalElectrovalence = BigDecimal.ZERO; |
| | | //计算list中serviceCharge的总和 |
| | | BigDecimal totalServiceCharge = BigDecimal.ZERO; |
| | | List<TChargingOrderAccountingStrategy> accountingStrategyList = chargingOrderAccountingStrategyService.list(); |
| | | for (TChargingOrder order : list) { |
| | | List<TChargingOrderAccountingStrategy> collect = accountingStrategyList.stream().filter(s -> s.getChargingOrderId().equals(order.getId())).collect(Collectors.toList()); |
| | | BigDecimal periodElectricPrice = collect.stream().map(TChargingOrderAccountingStrategy::getPeriodElectricPrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | BigDecimal periodServicePrice = collect.stream().map(TChargingOrderAccountingStrategy::getPeriodServicePrice).reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | totalElectrovalence = totalElectrovalence.add(periodElectricPrice); |
| | | if(2 != order.getOrderSource()){ |
| | | totalServiceCharge = totalServiceCharge.add(periodServicePrice); |
| | | commissionAmount = commissionAmount.add((periodElectricPrice.add(periodServicePrice)).multiply(new BigDecimal("0.006"))); |
| | | }else{ |
| | | totalServiceCharge = totalServiceCharge.add(periodServicePrice.multiply(new BigDecimal("0.8"))); |
| | | sharingAmount = sharingAmount.add(periodServicePrice.multiply(new BigDecimal("0.2"))); |
| | | map.put("platformIncomeVisible", platformVisible); |
| | | return R.ok(map); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/platformRevenueAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @GetMapping(value = "/six/pay-type-circle") |
| | | @ApiOperation(value = "收入类型占比", tags = {"后台-数据分析-平台收入分析"}) |
| | | public R<List<SixIncomeCircleDto>> payTypeCircle() { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | return R.ok(chargingOrderService.payTypeCircle(sixBefore, siteIds)); |
| | | } |
| | | |
| | | /** |
| | | * 解析平台收入分析页面允许查看的站点范围。 |
| | | * 合作商使用授权站点,其他后台账号沿用用户站点列表;传入站点时需做授权校验。 |
| | | */ |
| | | private List<Integer> resolvePlatformRevenueSiteIds(Long userId, SysUser sysUser, Integer siteId) { |
| | | List<Integer> siteIds = new ArrayList<>(); |
| | | if (sysUser != null && Integer.valueOf(2).equals(sysUser.getRoleType())) { |
| | | Set<Integer> authSiteIds = partnerClient.authSite(sysUser.getObjectId(), SiteMenu.SITE_LIST.getValue()).getData(); |
| | | if (authSiteIds != null) { |
| | | siteIds.addAll(authSiteIds); |
| | | } |
| | | } else { |
| | | List<GetSiteListDTO> data = siteClient.getSiteListByUserId(userId).getData(); |
| | | if (data != null) { |
| | | for (GetSiteListDTO datum : data) { |
| | | siteIds.add(datum.getId()); |
| | | } |
| | | } |
| | | } |
| | | map.put("service_charge",totalServiceCharge.setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | map.put("electrovalence",totalElectrovalence.setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | map.put("commission_amount",commissionAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | map.put("sharing_amount",sharingAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN)); |
| | | return R.ok(map); |
| | | if (siteId != null) { |
| | | return siteIds.contains(siteId) ? Collections.singletonList(siteId) : Collections.singletonList(-1); |
| | | } |
| | | if (siteIds.isEmpty()) { |
| | | siteIds.add(-1); |
| | | } |
| | | return siteIds; |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 手动查询订单和退款数据,完善退款记录 |
| | | * @param orderId |
| | | * @param refund_out_trade_no |
| | | * @return |
| | | */ |
| | | @PostMapping("/orderQueryRefund") |
| | | public R<?> orderQueryRefund(@RequestParam("orderId") Long orderId, @RequestParam("refund_out_trade_no") String refund_out_trade_no){ |
| | | chargingOrderService.orderQueryRefund(orderId, refund_out_trade_no); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 手动查询订单和退款数据,批量完善退款记录 |
| | | * @return |
| | | */ |
| | | @PostMapping("/orderQueryRefundList") |
| | | public R<?> orderQueryRefundList(@RequestBody List<String> dto){ |
| | | for (String s : dto) { |
| | | String[] split = s.split(","); |
| | | chargingOrderService.orderQueryRefund(Long.valueOf(split[0]), split[1]); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 手动添加完善订单费用明细 |
| | | * @param orderId |
| | | * @return |
| | | */ |
| | | @PostMapping("/addOrderExpenseBreakdown") |
| | | public R<?> addOrderExpenseBreakdown(@RequestParam("orderId") Long orderId){ |
| | | chargingOrderService.addOrderExpenseBreakdown(orderId); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 手动批量修改订单支付金额 |
| | | * @param dtos |
| | | * @return |
| | | */ |
| | | @PostMapping("/updateOrderPaymentAmount") |
| | | public R<?> updateOrderPaymentAmount(@RequestBody List<UpdateOrderPaymentAmountDto> dtos){ |
| | | for (UpdateOrderPaymentAmountDto dto : dtos) { |
| | | chargingOrderService.update(new UpdateWrapper<TChargingOrder>().eq("id", dto.getOrderId()) |
| | | .set("payment_amount", dto.getPaymentAmount())); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | } |