puzhibing
2026-08-31 e03b36815242709d0d4c640f068c8bedd6adf62b
feat: add card charging order export
2个文件已添加
3个文件已修改
190 ■■■■■ 已修改文件
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TCardChargingOrderController.java 67 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/export/CardChargingOrderExport.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/TCardChargingOrderService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TCardChargingOrderServiceImpl.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
sql/20260831_card_charging_order_export_menu.sql 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TCardChargingOrderController.java
@@ -1,18 +1,37 @@
package com.ruoyi.order.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.WebUtils;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.order.api.query.CardChargingOrderQuery;
import com.ruoyi.order.api.vo.ChargingOrderVO;
import com.ruoyi.order.export.CardChargingOrderExport;
import com.ruoyi.order.service.TCardChargingOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -31,6 +50,54 @@
        return R.ok(cardChargingOrderService.pageList(query));
    }
    @RequiresPermissions(value = {"/cardChargingOrder/export", "/cardChargingOrder"}, logical = Logical.OR)
    @PutMapping("/export")
    @ApiOperation("刷卡充电订单导出")
    @Log(title = "刷卡充电订单导出", businessType = BusinessType.EXPORT)
    public void export(@RequestBody CardChargingOrderQuery query) {
        List<ChargingOrderVO> list = cardChargingOrderService.exportList(query);
        List<CardChargingOrderExport> exports = new ArrayList<>();
        for (ChargingOrderVO order : list) {
            CardChargingOrderExport export = new CardChargingOrderExport();
            BeanUtils.copyProperties(order, export);
            export.setStartTime(formatTime(order.getStartTime()));
            export.setEndTime(formatTime(order.getEndTime()));
            exports.add(export);
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), CardChargingOrderExport.class, exports);
        writeWorkbook(workbook, "刷卡充电订单导出.xls");
    }
    private String formatTime(LocalDateTime time) {
        return time == null ? "" : DateUtils.localDateTimeToString(time);
    }
    private void writeWorkbook(Workbook workbook, String exportFileName) {
        HttpServletResponse response = WebUtils.response();
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode(exportFileName, "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                workbook.close();
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @GetMapping("/summary")
    @ApiOperation("刷卡充电订单汇总")
    public R<Map<String, Object>> summary(CardChargingOrderQuery query) {
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/export/CardChargingOrderExport.java
New file
@@ -0,0 +1,72 @@
package com.ruoyi.order.export;
import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@ApiModel(value = "刷卡充电订单导出")
public class CardChargingOrderExport implements Serializable {
    private static final long serialVersionUID = 1L;
    @Excel(name = "订单编号", width = 26)
    private String code;
    @Excel(name = "充电卡号", width = 20)
    private String cardNo;
    @Excel(name = "状态", width = 16, replace = {"未知_0", "等待中/已插枪_1", "启动中_2", "充电中_3", "停止中_4", "已结束_5"})
    private Integer status;
    @Excel(name = "订单分类", width = 12)
    private Integer orderClassification;
    @Excel(name = "站点名称", width = 24)
    private String siteName;
    @Excel(name = "充电终端名称", width = 24)
    private String terminalName;
    @Excel(name = "站点ID", width = 12)
    private Integer siteId;
    @Excel(name = "充电桩ID", width = 12)
    private Integer chargingPileId;
    @Excel(name = "充电枪ID", width = 12)
    private Integer chargingGunId;
    @Excel(name = "充电时长(秒)", width = 14)
    private Long chargingSecond;
    @Excel(name = "开始时间", width = 22)
    private String startTime;
    @Excel(name = "最后时间", width = 22)
    private String endTime;
    @Excel(name = "充电量", width = 12)
    private BigDecimal chargingCapacity;
    @Excel(name = "电费", width = 12)
    private BigDecimal electrovalence;
    @Excel(name = "服务费", width = 12)
    private BigDecimal serviceCharge;
    @Excel(name = "订单金额", width = 12)
    private BigDecimal orderAmount;
    @Excel(name = "实付", width = 12)
    private BigDecimal paymentAmount;
    @Excel(name = "平台收入", width = 12)
    private BigDecimal platformIncome;
    @Excel(name = "合作商收入", width = 12)
    private BigDecimal partnerIncome;
}
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/TCardChargingOrderService.java
@@ -13,6 +13,11 @@
    PageInfo<ChargingOrderVO> pageList(CardChargingOrderQuery query);
    /**
     * 按查询条件导出全部刷卡充电订单(不分页)
     */
    List<ChargingOrderVO> exportList(CardChargingOrderQuery query);
    Map<String, Object> summary(CardChargingOrderQuery query);
    List<Map<String, Object>> balanceIncomeDetail(CardChargingOrderQuery query);
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TCardChargingOrderServiceImpl.java
@@ -72,6 +72,27 @@
    }
    @Override
    public List<ChargingOrderVO> exportList(CardChargingOrderQuery query) {
        String[] timeRange = parseTimeRange(query);
        setAuthSiteIds(query);
        long total = baseMapper.count(query, timeRange[0], timeRange[1], timeRange[2], timeRange[3]);
        List<ChargingOrderVO> result = new ArrayList<>();
        if (total == 0) {
            return result;
        }
        int batchSize = 5000;
        for (long offset = 0; offset < total; offset += batchSize) {
            List<ChargingOrderVO> batch = baseMapper.pageList(query, timeRange[0], timeRange[1], timeRange[2], timeRange[3], offset, batchSize);
            if (batch == null || batch.isEmpty()) {
                break;
            }
            result.addAll(batch);
        }
        fillPageExtra(result);
        return result;
    }
    @Override
    public List<Map<String, Object>> balanceIncomeDetail(CardChargingOrderQuery query) {
        return baseMapper.balanceIncomeDetail(query);
    }
sql/20260831_card_charging_order_export_menu.sql
New file
@@ -0,0 +1,25 @@
-- =====================================================
-- 刷卡充电订单导出权限菜单(可选执行)
-- 说明:后端导出接口权限为 @RequiresPermissions({"/cardChargingOrder/export", "/cardChargingOrder"}, OR)
-- 拥有页面权限(/cardChargingOrder)的用户无需此脚本即可导出;
-- 如需对导出权限单独控制(如部分角色可看不可导出),执行本脚本并在角色管理中单独授权。
-- 执行库:charging_pile_other
-- =====================================================
USE charging_pile_other;
INSERT INTO `sys_menu`
(`menu_name`,`parent_id`,`order_num`,`path`,`component`,`query`,`is_frame`,`is_cache`,`menu_type`,`visible`,`status`,`perms`,`icon`,`create_by`,`create_time`,`update_by`,`update_time`,`remark`)
SELECT '刷卡订单导出', parent.menu_id, 2, '#', '', '', 1, 0, 'F', '0', '0', '/cardChargingOrder/export', '#', 'admin', NOW(), '', NULL, ''
FROM `sys_menu` parent
WHERE parent.perms = '/cardChargingOrder'
  AND NOT EXISTS (SELECT 1 FROM `sys_menu` WHERE `perms` = '/cardChargingOrder/export');
INSERT INTO `sys_role_menu` (`role_id`,`menu_id`)
SELECT 1, menu.menu_id
FROM `sys_menu` menu
WHERE menu.perms = '/cardChargingOrder/export'
  AND NOT EXISTS (
    SELECT 1 FROM `sys_role_menu` role_menu
    WHERE role_menu.role_id = 1 AND role_menu.menu_id = menu.menu_id
  );