| | |
| | | package com.ruoyi.order.controller; |
| | | import cn.afterturn.easypoi.excel.ExcelExportUtil; |
| | | import cn.afterturn.easypoi.excel.entity.ExportParams; |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | |
| | | import com.ruoyi.order.dto.MyChargingOrderList; |
| | | import com.ruoyi.order.dto.OrderEvaluateVo; |
| | | import com.ruoyi.order.dto.*; |
| | | import com.ruoyi.order.export.PayOrderExport; |
| | | import com.ruoyi.order.export.EnterpriseChargingDetailExport; |
| | | import com.ruoyi.order.service.*; |
| | | import com.ruoyi.order.util.PreviousSixMonths; |
| | | import com.ruoyi.order.util.mongodb.service.UploadRealTimeMonitoringDataService; |
| | | import com.ruoyi.order.vo.EndOfChargePageInfo; |
| | | import com.ruoyi.order.vo.ChargingSimulationVO; |
| | | import com.ruoyi.order.vo.IcbcAdminSubOrderVO; |
| | | import com.ruoyi.order.vo.StatisticsOfBatteryVO; |
| | | import com.ruoyi.order.vo.UpdateOrderPaymentAmountDto; |
| | | import com.ruoyi.order.vo.WatchChargingOrderVo; |
| | |
| | | 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.IcbcPaymentResp; |
| | | import com.ruoyi.payment.api.vo.IcbcRefundResp; |
| | | import com.ruoyi.payment.api.vo.IcbcSubOrderRefundResp; |
| | | 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.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.net.URLEncoder; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.WebUtils; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | } |
| | | |
| | | |
| | | @RequiresPermissions(value = {"/chargingUserAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @PostMapping(value = "/enterprise/charging/analysis") |
| | | @ApiOperation(value = "企业用户充电分析", tags = {"管理后台-数据分析-企业用户充电分析"}) |
| | | public R<PageInfo<EnterpriseChargingAnalysisVO>> enterpriseChargingAnalysis(@RequestBody EnterpriseChargingAnalysisQuery query) { |
| | | return chargingOrderService.enterpriseChargingAnalysis(query); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingUserAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @PostMapping(value = "/enterprise/charging/detail") |
| | | @ApiOperation(value = "企业用户充电明细", tags = {"管理后台-数据分析-企业用户充电分析"}) |
| | | public R<PageInfo<EnterpriseChargingDetailVO>> enterpriseChargingDetail(@RequestBody EnterpriseChargingAnalysisQuery query) { |
| | | return chargingOrderService.enterpriseChargingDetail(query); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingUserAnalysis"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @PutMapping(value = "/enterprise/charging/detail/export") |
| | | @ApiOperation(value = "企业用户充电明细导出", tags = {"管理后台-数据分析-企业用户充电分析"}) |
| | | public void exportEnterpriseChargingDetail(@RequestBody EnterpriseChargingAnalysisQuery query) { |
| | | List<EnterpriseChargingDetailVO> records = chargingOrderService.enterpriseChargingDetailExport(query); |
| | | List<EnterpriseChargingDetailExport> exports = records.stream().map(this::buildEnterpriseChargingDetailExport).collect(Collectors.toList()); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), EnterpriseChargingDetailExport.class, exports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | try { |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("企业用户充电明细.xls", "utf-8")); |
| | | try (ServletOutputStream outputStream = response.getOutputStream()) { |
| | | workbook.write(outputStream); |
| | | } |
| | | workbook.close(); |
| | | } catch (IOException e) { |
| | | log.error("导出企业用户充电明细失败", e); |
| | | } |
| | | } |
| | | |
| | | private EnterpriseChargingDetailExport buildEnterpriseChargingDetailExport(EnterpriseChargingDetailVO dto) { |
| | | EnterpriseChargingDetailExport export = new EnterpriseChargingDetailExport(); |
| | | export.setCode(dto.getCode()); |
| | | export.setOrderType(formatEnterpriseOrderType(dto.getOrderType())); |
| | | export.setOrderClassification(formatOrderClassification(dto.getOrderClassification())); |
| | | export.setSiteName(dto.getSiteName()); |
| | | export.setTerminalName(dto.getTerminalName()); |
| | | export.setStatus(formatPayOrderStatus(1, dto.getStatus())); |
| | | export.setChargingSecond(dto.getChargingSecond()); |
| | | export.setTotalAmount(dto.getTotalAmount()); |
| | | export.setCouponDiscountAmount(dto.getCouponDiscountAmount()); |
| | | export.setVipDiscountAmount(dto.getVipDiscountAmount()); |
| | | export.setPaymentAmount(dto.getPaymentAmount()); |
| | | export.setRefundAmount(dto.getRefundAmount()); |
| | | export.setPartnerName(dto.getPartnerName()); |
| | | export.setPhone(dto.getPhone()); |
| | | export.setOrderSource(formatOrderSource(dto.getOrderSource())); |
| | | export.setStartTime(dto.getStartTime() == null ? null : DateUtils.localDateTimeToString(dto.getStartTime())); |
| | | export.setEndTime(dto.getEndTime() == null ? null : DateUtils.localDateTimeToString(dto.getEndTime())); |
| | | return export; |
| | | } |
| | | |
| | | private String formatEnterpriseOrderType(Integer type) { |
| | | if (type == null) { |
| | | return "-"; |
| | | } |
| | | if (type == 1) { |
| | | return "充电订单(小程序)"; |
| | | } |
| | | if (type == 2) { |
| | | return "充电订单(刷卡)"; |
| | | } |
| | | return "充电订单"; |
| | | } |
| | | |
| | | private String formatOrderClassification(Integer type) { |
| | | if (type == null) { |
| | | return "-"; |
| | | } |
| | | return type == 1 ? "线上订单" : "线下订单"; |
| | | } |
| | | |
| | | private String formatOrderSource(Integer source) { |
| | | if (source == null) { |
| | | return "-"; |
| | | } |
| | | if (source == 0) { |
| | | return "自有平台"; |
| | | } |
| | | if (source == 1) { |
| | | return "第三方平台"; |
| | | } |
| | | if (source == 2) { |
| | | return "引流平台"; |
| | | } |
| | | return "其他"; |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/invoiceManagement/select_order", "/paymentOrder/order"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @PostMapping(value = "/pay/order/list") |
| | | @ApiOperation(value = "列表", tags = {"管理后台-支付订单-订单信息"}) |
| | | public R<PageInfo<PayOrderDto>> payOrderList(@RequestBody PayOrderQueryDto payOrderQueryDto) { |
| | | return chargingOrderService.payOrderQuery(payOrderQueryDto); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/invoiceManagement/select_order", "/invoiceManagement/export", "/paymentOrder/order"}, logical = Logical.OR) |
| | | @ResponseBody |
| | | @PutMapping(value = "/pay/order/export") |
| | | @ApiOperation(value = "导出查看订单列表", tags = {"管理后台-支付订单-订单信息"}) |
| | | @Log(title = "发票管理查看订单导出", businessType = BusinessType.EXPORT) |
| | | public void exportPayOrder(@RequestBody PayOrderQueryDto payOrderQueryDto) { |
| | | payOrderQueryDto.setPageCurr(1); |
| | | payOrderQueryDto.setPageSize(10000); |
| | | R<PageInfo<PayOrderDto>> result = chargingOrderService.payOrderQuery(payOrderQueryDto); |
| | | List<PayOrderDto> records = result.getData() == null || result.getData().getRecords() == null |
| | | ? Collections.emptyList() : result.getData().getRecords(); |
| | | List<PayOrderExport> exports = records.stream().map(this::buildPayOrderExport).collect(Collectors.toList()); |
| | | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), PayOrderExport.class, exports); |
| | | HttpServletResponse response = WebUtils.response(); |
| | | response.setContentType("application/vnd.ms-excel;charset=UTF-8"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | response.setHeader("Pragma", "no-cache"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | try { |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("订单列表.xls", "utf-8")); |
| | | try (ServletOutputStream outputStream = response.getOutputStream()) { |
| | | workbook.write(outputStream); |
| | | } |
| | | workbook.close(); |
| | | } catch (IOException e) { |
| | | log.error("导出查看订单列表失败", e); |
| | | } |
| | | } |
| | | |
| | | private PayOrderExport buildPayOrderExport(PayOrderDto dto) { |
| | | PayOrderExport export = new PayOrderExport(); |
| | | export.setCode(dto.getCode()); |
| | | export.setType(formatPayOrderType(dto.getType())); |
| | | export.setTitle(dto.getTitle()); |
| | | export.setPhone(dto.getPhone()); |
| | | export.setOrderStatus(dto.getPayTime() != null ? "订单支付成功" : "订单完成"); |
| | | export.setStatus(formatPayOrderStatus(dto.getType(), dto.getStatus())); |
| | | export.setRefundStatus(dto.getRefundStatus() != null && dto.getRefundStatus() == 1 ? "有退款" : "无退款"); |
| | | export.setRechargeAmount(dto.getRechargeAmount()); |
| | | export.setPaymentAmount(dto.getPaymentAmount()); |
| | | export.setFinalAmount(dto.getFinalAmount()); |
| | | export.setCreateTime(dto.getCreateTime() == null ? null : DateUtils.localDateTimeToString(dto.getCreateTime())); |
| | | export.setEndTime(dto.getEndTime() == null ? null : DateUtils.localDateTimeToString(dto.getEndTime())); |
| | | export.setPayTime(dto.getPayTime() == null ? null : DateUtils.localDateTimeToString(dto.getPayTime())); |
| | | return export; |
| | | } |
| | | |
| | | private String formatPayOrderType(Integer type) { |
| | | if (type == null || type < 1 || type > 4) { |
| | | return "-"; |
| | | } |
| | | return new String[]{"充电订单", "购物订单", "vip订单", "停车订单"}[type - 1]; |
| | | } |
| | | |
| | | private String formatPayOrderStatus(Integer type, Integer status) { |
| | | if (type == null) { |
| | | return "-"; |
| | | } |
| | | if (type == 3) { |
| | | return "支付成功"; |
| | | } |
| | | if (status == null) { |
| | | return "-"; |
| | | } |
| | | if (type == 1 && status >= 0 && status <= 5) { |
| | | return new String[]{"未知", "等待中", "启动中", "充电中", "停止中", "已结束"}[status]; |
| | | } |
| | | if (type == 2 && status >= 1 && status <= 4) { |
| | | return new String[]{"待发货", "待收货", "已完成", "已取消"}[status - 1]; |
| | | } |
| | | if (type == 4 && status >= 1 && status <= 3) { |
| | | return new String[]{"已进场", "已出场", "已缴费出场"}[status - 1]; |
| | | } |
| | | return "-"; |
| | | } |
| | | |
| | | |
| | |
| | | @PostMapping(value = "/chargingOrder") |
| | | @ApiOperation(value = "充电桩订单列表", tags = {"管理后台-订单管理"}) |
| | | public AjaxResult<TCharingOrderVO> chargingOrder(@RequestBody ChargingOrderQuery dto) { |
| | | List<Long> data = appUserClient.getUserIdsByPhone(dto.getPhone()).getData(); |
| | | dto.setUserIds(data); |
| | | TCharingOrderVO res = chargingOrderService.chargingOrder(dto); |
| | | return AjaxResult.success(res); |
| | | } |
| | |
| | | public AjaxResult paymentChargingOrder(@RequestBody AddChargingOrder addChargingOrder) { |
| | | return chargingOrderService.paymentChargingOrder(addChargingOrder); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping(value = "/confirmIcbcPayment") |
| | | @ApiOperation(value = "主动确认工行充电支付结果", tags = {"小程序-扫一扫"}) |
| | | public AjaxResult confirmIcbcPayment(@RequestParam("orderCode") String orderCode) { |
| | | return chargingOrderService.confirmIcbcPayment(orderCode); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingPileOrder", "/paymentOrder/refund"}, logical = Logical.AND) |
| | | @PostMapping("/icbc/fund/payment-query") |
| | | @ApiOperation(value = "管理后台查询工行支付订单", tags = {"后台-充电桩订单"}) |
| | | public AjaxResult<IcbcPaymentResp> queryIcbcAdminPayment(@RequestBody IcbcAdminFundOperationReq request) { |
| | | return AjaxResult.success(chargingOrderService.queryIcbcAdminPayment(request == null ? null : request.getOrderCode())); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingPileOrder", "/paymentOrder/refund"}, logical = Logical.AND) |
| | | @PostMapping("/icbc/fund/refund") |
| | | @ApiOperation(value = "管理后台工行主订单退款", tags = {"后台-充电桩订单"}) |
| | | public AjaxResult<IcbcRefundResp> refundIcbcAdminPayment(@RequestBody IcbcAdminFundOperationReq request) { |
| | | return AjaxResult.success(chargingOrderService.refundIcbcAdminPayment(request)); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingPileOrder", "/paymentOrder/refund"}, logical = Logical.AND) |
| | | @PostMapping("/icbc/fund/sub-orders") |
| | | @ApiOperation(value = "管理后台查询工行分账子订单", tags = {"后台-充电桩订单"}) |
| | | public AjaxResult<List<IcbcAdminSubOrderVO>> queryIcbcAdminSubOrders(@RequestBody IcbcAdminFundOperationReq request) { |
| | | return AjaxResult.success(chargingOrderService.queryIcbcAdminSubOrders(request == null ? null : request.getOrderCode())); |
| | | } |
| | | |
| | | @RequiresPermissions(value = {"/chargingPileOrder", "/paymentOrder/refund"}, logical = Logical.AND) |
| | | @PostMapping("/icbc/fund/sub-order-refund") |
| | | @ApiOperation(value = "管理后台工行分账子订单退款", tags = {"后台-充电桩订单"}) |
| | | public AjaxResult<IcbcSubOrderRefundResp> refundIcbcAdminSubOrder(@RequestBody IcbcAdminFundOperationReq request) { |
| | | return AjaxResult.success(chargingOrderService.refundIcbcAdminSubOrder(request)); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @GetMapping("/simulation/current") |
| | | @ApiOperation(value = "查询当前枪可模拟结算的已支付订单", tags = {"小程序-模拟充电"}) |
| | | public AjaxResult<ChargingSimulationVO> getCurrentSimulationOrder(@RequestParam("gunId") Integer gunId) { |
| | | return AjaxResult.success(chargingOrderService.getCurrentSimulationOrder(gunId)); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @PostMapping("/simulation/complete") |
| | | @ApiOperation(value = "模拟完成充电并执行真实结算", tags = {"小程序-模拟充电"}) |
| | | public AjaxResult<ChargingSimulationVO> completeSimulation(@RequestBody ChargingSimulationReq request) { |
| | | return AjaxResult.success(chargingOrderService.completeSimulation(request)); |
| | | } |
| | | |
| | | /** |
| | | * 充电充值支付回调 |
| | |
| | | }) |
| | | 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); |
| | | } |
| | | |
| | |
| | | public R<List<SixChargingDto>> charge(Integer siteId) { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | boolean partnerView = isPartnerView(sysUser); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, siteId); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | //通过siteIds进行sql查询统计 |
| | | List<SixChargingDto> sixChargingDtos = generateLastSixMonths(); |
| | | List<SixChargingDto> chargingDtos = chargingOrderService.charge(sixBefore, siteIds); |
| | | List<SixChargingDto> chargingDtos = chargingOrderService.charge(sixBefore, siteIds, partnerView); |
| | | for (SixChargingDto sixChargingDto : sixChargingDtos) { |
| | | for (SixChargingDto chargingDto : chargingDtos) { |
| | | if (sixChargingDto.getMonth().equals(chargingDto.getMonth())){ |
| | |
| | | public R<List<SixCircleDto>> circle() { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | boolean partnerView = isPartnerView(sysUser); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | List<SixCircleDto> sixCircleDtos = chargingOrderService.circle(siteIds,sixBefore); |
| | | List<SixCircleDto> sixCircleDtos = chargingOrderService.circle(siteIds,sixBefore, partnerView); |
| | | for (SixCircleDto sixCircleDto : sixCircleDtos) { |
| | | Site site = siteClient.getSiteByIds(Arrays.asList(sixCircleDto.getSiteId())).getData().get(0); |
| | | sixCircleDto.setSiteName(site.getName()); |
| | |
| | | //count近6个月的数据 |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | boolean partnerView = isPartnerView(sysUser); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | Map<String,Object> map = chargingOrderService.countAll(siteIds); |
| | | boolean platformVisible = 1 == sysUser.getObjectId(); |
| | | Map<String,Object> map = chargingOrderService.countAll(siteIds, partnerView); |
| | | if (map == null) { |
| | | map = new HashMap<String,Object>(); |
| | | } |
| | | boolean platformVisible = !partnerView; |
| | | if(platformVisible){ |
| | | BigDecimal data = parkingLotClient.getRecordAmount().getData(); |
| | | if (map ==null){ |
| | | map = new HashMap<String,Object>(); |
| | | } |
| | | map.put("parkingAmount",data); |
| | | BigDecimal data1 = shoppingOrderService.getSumAmount(); |
| | | map.put("shopAmount",data1); |
| | |
| | | public R<List<SixIncomeCircleDto>> payTypeCircle() { |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | SysUser sysUser = sysUserClient.getSysUser(userId).getData(); |
| | | boolean partnerView = isPartnerView(sysUser); |
| | | List<Integer> siteIds = resolvePlatformRevenueSiteIds(userId, sysUser, null); |
| | | LocalDate sixBefore = PreviousSixMonths.get(); |
| | | return R.ok(chargingOrderService.payTypeCircle(sixBefore, siteIds)); |
| | | return R.ok(chargingOrderService.payTypeCircle(sixBefore, siteIds, partnerView)); |
| | | } |
| | | |
| | | private boolean isPartnerView(SysUser sysUser) { |
| | | return sysUser != null && Integer.valueOf(2).equals(sysUser.getRoleType()); |
| | | } |
| | | |
| | | /** |