From 5629dcfa3d4f57b63043d5ef64b5ec3bb7ac9123 Mon Sep 17 00:00:00 2001 From: Anayigeren <15659576701@163.com> Date: Wed, 9 Apr 2025 22:26:00 +0800 Subject: [PATCH] lzh --- .../module/report/model/ExpressReport.java | 22 ++ .../module/report/model/FinanceReport.java | 36 ++- .../report/model/OrderDeliveryReport.java | 16 ++ .../module/report/model/OrderReport.java | 22 ++ .../module/report/model/ReportQuery.java | 5 + .../module/report/model/StockDailyReport.java | 6 +- .../report/service/ReportOrderService.java | 4 + .../module/resource/api/DfsException.java | 38 ++- .../xmomen/module/resource/api/DfsFile.java | 59 +++- .../xmomen/module/resource/api/DfsPath.java | 41 ++- .../xmomen/module/resource/api/DfsSdk.java | 3 + .../module/resource/api/DfsService.java | 82 +++--- .../module/resource/api/FastDfsService.java | 259 +++++++++++++----- .../controller/ResourceController.java | 145 +++++++--- .../module/resource/entity/Resource.java | 2 +- .../resource/entity/mapper/ResourceMapper.xml | 189 +++++++++---- 16 files changed, 695 insertions(+), 234 deletions(-) diff --git a/src/main/java/com/xmomen/module/report/model/ExpressReport.java b/src/main/java/com/xmomen/module/report/model/ExpressReport.java index 9dbb2d4..a46aad0 100644 --- a/src/main/java/com/xmomen/module/report/model/ExpressReport.java +++ b/src/main/java/com/xmomen/module/report/model/ExpressReport.java @@ -17,22 +17,44 @@ public @Data class ExpressReport implements Serializable { + // 物流公司 + // 物流公司 @Excel(name = "物流公司") + // 订单号 private String expressName; + // 订单号 + // 总箱数 @Excel(name = "订单号", width = 20) private String orderNo; + // 出库时间 + // 总箱数 @Excel(name = "总箱数") + // 收货时间 private int totalBoxNum; + // 出库时间 + // 二次配送 @Excel(name = "出库时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss") + // 收货时间 + // 正常配送 private Date outDate; @Excel(name = "收货时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss") + // 异常配送 + // 二次配送 + // 正常配送 + // 物流代收款 private Date shouHuoDate; @Excel(name = "二次配送", type = 10) + // 损失承担 + // 异常配送 private int isTwoSend; + // 物流代收款 + // 是否拒收 @Excel(name = "正常配送", type = 10) + // 损失承担 private int isNormal; @Excel(name = "异常配送", type = 10) private int isNoNormal; + // 是否拒收 @Excel(name = "物流代收款", width = 15, type = 10) private double expressAmount; @Excel(name = "损失承担", type = 10) diff --git a/src/main/java/com/xmomen/module/report/model/FinanceReport.java b/src/main/java/com/xmomen/module/report/model/FinanceReport.java index 28d43d2..d7e326c 100644 --- a/src/main/java/com/xmomen/module/report/model/FinanceReport.java +++ b/src/main/java/com/xmomen/module/report/model/FinanceReport.java @@ -11,53 +11,57 @@ import java.io.Serializable; public @Data class FinanceReport implements Serializable { + //公司ID private int cdCompanyId; + //客户经理 @Excel(name = "客户经理") private String managerName; + //单位/个人 @Excel(name = "单位/个人") private String companyName; + //用户ID private int cdUserId; - //总张数 + //总张数(预付款) @Excel(name = "总张数(预付款)", type = 10) private int beforeCouponCount; - //总金额 + //总金额(预付款) @Excel(name = "总金额(预付款)", type = 10) private double beforeTotalValue; - //充值金额 + //充值金额(预付款) @Excel(name = "充值金额(预付款)", type = 10) private double beforeTotalRechargeValue; - //已付 + //已付(预付款) @Excel(name = "已付(预付款)", type = 10) private double beforeTotalYesValue; - // 未付 + // 未付(预付款) @Excel(name = "未付(预付款)", type = 10) private double beforeTotalNoValue; - // 余额 + // 余额(预付款) @Excel(name = "余额(预付款)", type = 10) private double beforeUserTotalValue; - // 回馈总金额 + // 回馈总金额(预付款) @Excel(name = "回馈总金额(预付款)", type = 10) private double beforeGiftTotalValue; - // 回馈剩余金额 + // 回馈剩余金额(预付款) @Excel(name = "回馈剩余金额(预付款)", type = 10) private double beforeGiftUserTotalValue; - // 总张数 + // 总张数(后付款) @Excel(name = "总张数(后付款)", type = 10) private int afterCouponCount; - // 总金额 + // 总金额(后付款) @Excel(name = "总金额(后付款)", type = 10) private double afterTotalValue; - // 充值金额 + // 充值金额(后付款) @Excel(name = "充值金额(后付款)", type = 10) private double afterTotalRechargeValue; - // 已付 + // 已付(后付款) @Excel(name = "已付(后付款)", type = 10) private double afterTotalYesValue; - // 未付 + // 未付(后付款) @Excel(name = "未付(后付款)", type = 10) private double afterTotalNoValue; - // 余额 + // 余额(后付款) @Excel(name = "余额(后付款)", type = 10) private double afterUserTotalValue; // 回馈总金额(后付款) @@ -78,12 +82,16 @@ class FinanceReport implements Serializable { //回馈总金额 @Excel(name = "回馈总金额", type = 10) private double giftOrderTotal; + //客户经理代收 @Excel(name = "客户经理代收", type = 10) private double managerAmount; + //POS @Excel(name = "POS", type = 10) private double posAmount; + //转账 @Excel(name = "转账", type = 10) private double zhuanAmount; + //物流代收 @Excel(name = "物流代收", type = 10) private double expressAmount; } diff --git a/src/main/java/com/xmomen/module/report/model/OrderDeliveryReport.java b/src/main/java/com/xmomen/module/report/model/OrderDeliveryReport.java index f8f0a34..26aab36 100644 --- a/src/main/java/com/xmomen/module/report/model/OrderDeliveryReport.java +++ b/src/main/java/com/xmomen/module/report/model/OrderDeliveryReport.java @@ -16,33 +16,49 @@ import java.util.Date; public @Data class OrderDeliveryReport implements Serializable { + // 下单日期 @Excel(name = "下单日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd") private Date createTime; + // 订单号 @Excel(name = "订单号",width = 20) private String orderNo; + // 快递商 @Excel(name="快递商") private String expressName; + // 收货人姓名 @Excel(name = "收货人姓名",width = 15) private String consigneeName; + // 收货人电话 @Excel(name = "收货人电话",width = 15) private String consigneePhone; + // 收货人地址 @Excel(name = "收货人地址",width = 30) private String consigneeAddress; + // 金额 @Excel(name = "金额") private double totalAmount; + // 付款方式 @Excel(name = "付款方式") private String paymentModeDesc; + // 付款金额 @Excel(name = "付款金额",type = 10) private double payAmount; + // 附加付款方式 @Excel(name = "附加付款方式") private String otherPaymentModeDesc; + // 附加付款金额 @Excel(name = "附加付款金额",type = 10) private double otherPayAmount; + // 送货日期 @Excel(name = "送货日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd") private Date appointmentTime; + // 备注 @Excel(name = "备注",width = 30) private String remark; + // 订单状态描述 private String orderStatusDesc; + // 总箱数 private int totalBoxNum; + // 快递扫描箱数 private int expressScanBoxNum; } diff --git a/src/main/java/com/xmomen/module/report/model/OrderReport.java b/src/main/java/com/xmomen/module/report/model/OrderReport.java index 6271e64..edfc72a 100644 --- a/src/main/java/com/xmomen/module/report/model/OrderReport.java +++ b/src/main/java/com/xmomen/module/report/model/OrderReport.java @@ -17,45 +17,67 @@ public @Data class OrderReport implements Serializable { + // 支付方式 private String paymentMode; + // 支付金额 private double payAmount; + // 其他支付方式 private String otherPaymentMode; + // 其他支付金额 private double otherPayAmount; + // 订单类型 @Excel(name = "订单类型") private String orderType; + // 订单号 @Excel(name = "订单号", width = 20) private String orderNo; + // 客户姓名 @Excel(name = "客户姓名") private String consigneeName; + // 电话 @Excel(name = "电话", width = 15) private String consigneePhone; + // 单位/个人 @Excel(name = "单位/个人") private String companyName; + // 客户经理 @Excel(name = "客户经理") private String managerName; + // 物流公司 @Excel(name = "物流公司") private String expressName; + // 总金额 @Excel(name = "总金额") private double totalAmount; + // 折扣金额 @Excel(name = "折扣金额") private double discountPrice; + // 客户经理代收 @Excel(name = "客户经理代收", width = 15, type = 10) private double managerAmount; + // 物流代收 @Excel(name = "物流代收", type = 10) private double expressAmount; + // 卡类扣款 @Excel(name = "卡类扣款", type = 10) private double couponAmount; + // 券类扣款 @Excel(name = "券类扣款", type = 10) private double quanAmount; + // 刷POS @Excel(name = "刷POS", type = 10) private double posAmount; + // 转账 @Excel(name = "转账", type = 10) private double zhuanZhanAmount; + // 其它 @Excel(name = "其它", type = 10) private double otherAmount; + // 回馈 @Excel(name = "回馈", type = 10) private double huiKuiAmount; + // 退货金额 @Excel(name = "退货金额", type = 10) private double returnTotalAmount; } diff --git a/src/main/java/com/xmomen/module/report/model/ReportQuery.java b/src/main/java/com/xmomen/module/report/model/ReportQuery.java index ab5a481..9b841c5 100644 --- a/src/main/java/com/xmomen/module/report/model/ReportQuery.java +++ b/src/main/java/com/xmomen/module/report/model/ReportQuery.java @@ -5,11 +5,16 @@ import lombok.Data; import java.io.Serializable; /** + * 报表查询模型 */ public @Data class ReportQuery implements Serializable { + // 开始时间 private String beginTime; + // 结束时间 private String endTime; + // 管理员ID private Integer managerId; + // 公司ID private Integer companyId; } diff --git a/src/main/java/com/xmomen/module/report/model/StockDailyReport.java b/src/main/java/com/xmomen/module/report/model/StockDailyReport.java index 8e65e0f..661ea9b 100644 --- a/src/main/java/com/xmomen/module/report/model/StockDailyReport.java +++ b/src/main/java/com/xmomen/module/report/model/StockDailyReport.java @@ -5,14 +5,14 @@ import org.jeecgframework.poi.excel.annotation.Excel; import java.io.Serializable; -/** - * 库存快照报表实体类 - */ + public @Data class StockDailyReport implements Serializable { + // 商品名称 @Excel(name = "商品名称") private String itemName; + // 商品编码 @Excel(name = "商品编码") private String itemCode; /** diff --git a/src/main/java/com/xmomen/module/report/service/ReportOrderService.java b/src/main/java/com/xmomen/module/report/service/ReportOrderService.java index 6594a6b..087a67d 100644 --- a/src/main/java/com/xmomen/module/report/service/ReportOrderService.java +++ b/src/main/java/com/xmomen/module/report/service/ReportOrderService.java @@ -41,9 +41,13 @@ public class ReportOrderService { * @return */ public List getOrderReportList(ReportQuery reportQuery) { + //查询订单报表 List orderReportList = mybatisDao.getSqlSessionTemplate().selectList(ReportOrderMapper.REPORT_ORDER_MAPPER_NAMESPACE + "getReportOrderList", reportQuery); + //遍历订单报表 for (OrderReport orderReport : orderReportList) { + //判断付款方式 if ("0".equals(orderReport.getPaymentMode())) { + //如果是汇款 orderReport.setHuiKuiAmount(orderReport.getPayAmount()); } if ("1".equals(orderReport.getPaymentMode())) { diff --git a/src/main/java/com/xmomen/module/resource/api/DfsException.java b/src/main/java/com/xmomen/module/resource/api/DfsException.java index 2c92a24..e4e7970 100644 --- a/src/main/java/com/xmomen/module/resource/api/DfsException.java +++ b/src/main/java/com/xmomen/module/resource/api/DfsException.java @@ -1,38 +1,66 @@ package com.xmomen.module.resource.api; +/** + * DfsException 类继承自 RuntimeException,用于表示在分布式文件系统(DFS)操作过程中出现的异常。 + */ public class DfsException extends RuntimeException { + // 序列化版本号,用于确保在反序列化时类的版本一致性 private static final long serialVersionUID = 1497374765949093902L; /** - * IOException 100 - * FileNotFoundException 200 - * Exception from DFS (example: from FastDFS, MyException) 300 - * OtherException 400 + * 异常代码,用于标识不同类型的异常。 + * 异常代码的具体含义如下: + * - IOException 对应代码 100 + * - FileNotFoundException 对应代码 200 + * - 来自 DFS 的异常(例如 FastDFS 抛出的异常、自定义异常 MyException)对应代码 300 + * - 其他异常对应代码 400 */ private String code; + // 异常的详细描述信息 private String message; + /** + * 构造函数,用于创建一个 DfsException 实例。 + * @param code 异常代码,用于标识异常类型 + * @param message 异常的详细描述信息 + */ public DfsException(String code, String message) { this.code = code; this.message = message; } + /** + * 获取异常代码。 + * @return 异常代码 + */ public String getCode() { return code; } + /** + * 设置异常代码。 + * @param code 要设置的异常代码 + */ public void setCode(String code) { this.code = code; } + /** + * 获取异常的详细描述信息。 + * @return 异常的详细描述信息 + */ public String getMessage() { return message; } + /** + * 设置异常的详细描述信息。 + * @param message 要设置的异常详细描述信息 + */ public void setMessage(String message) { this.message = message; } -} +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/api/DfsFile.java b/src/main/java/com/xmomen/module/resource/api/DfsFile.java index 0372790..4f5c405 100644 --- a/src/main/java/com/xmomen/module/resource/api/DfsFile.java +++ b/src/main/java/com/xmomen/module/resource/api/DfsFile.java @@ -2,32 +2,45 @@ package com.xmomen.module.resource.api; import java.util.Map; +/** + * DfsFile 类代表一个分布式文件系统(DFS)中的文件。 + * 该类封装了文件的数据、唯一标识以及元数据信息。 + */ public class DfsFile { /** - * file data + * 存储文件的二进制数据。 + * 它包含了文件的实际内容,以字节数组的形式存在。 */ private byte[] data; /** - * key,not used in FastDfs + * 文件的唯一标识。 + * 在 FastDFS 这种分布式文件系统中,此属性暂不使用。 */ private String key; /** - * metadata for file + * 文件的元数据信息。 + * 以键值对的形式存储与文件相关的额外信息, + * 例如文件的创建时间、作者、文件类型等。 */ private Map metadata; + /** + * 默认构造函数。 + * 用于创建一个空的 DfsFile 对象,各属性初始值为 null。 + */ public DfsFile() { } + /** - * constructor with data, key and metadata + * 带参数的构造函数,用于创建一个具有指定属性的 DfsFile 对象。 * - * @param key key,not used in FastDfs - * @param data file data - * @param metadata metadata for file + * @param key 文件的唯一标识,在 FastDFS 中暂不使用。 + * @param data 文件的二进制数据。 + * @param metadata 文件的元数据信息,以键值对形式存储。 */ public DfsFile(String key, byte[] data, Map metadata) { this.key = key; @@ -35,28 +48,58 @@ public class DfsFile { this.metadata = metadata; } + /** + * 获取文件的二进制数据。 + * + * @return 文件的二进制数据,以字节数组形式返回。 + */ public byte[] getData() { return data; } + /** + * 设置文件的二进制数据。 + * + * @param data 要设置的文件二进制数据。 + */ public void setData(byte[] data) { this.data = data; } + /** + * 获取文件的唯一标识。 + * + * @return 文件的唯一标识。 + */ public String getKey() { return key; } + /** + * 设置文件的唯一标识。 + * + * @param key 要设置的文件唯一标识。 + */ public void setKey(String key) { this.key = key; } + /** + * 获取文件的元数据信息。 + * + * @return 文件的元数据信息,以键值对形式返回。 + */ public Map getMetadata() { return metadata; } + /** + * 设置文件的元数据信息。 + * + * @param metadata 要设置的文件元数据信息,以键值对形式传入。 + */ public void setMetadata(Map metadata) { this.metadata = metadata; } -} +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/api/DfsPath.java b/src/main/java/com/xmomen/module/resource/api/DfsPath.java index 20ae18f..d91d7e5 100644 --- a/src/main/java/com/xmomen/module/resource/api/DfsPath.java +++ b/src/main/java/com/xmomen/module/resource/api/DfsPath.java @@ -1,45 +1,74 @@ package com.xmomen.module.resource.api; +/** + * DfsPath 类用于表示分布式文件系统(DFS)中文件的路径信息。 + * 它包含了文件的 HTTP 访问路径和存储服务器上的远程路径。 + */ public class DfsPath { /** - * whole url, just like http://.../bucketName/remotePath + * 完整的 HTTP 访问路径,格式类似于 http://.../bucketName/remotePath。 + * 该路径可用于在网络上直接访问文件。 */ private String httpPath; /** - * file path on storage server + * 文件在存储服务器上的路径。 + * 它表示文件在存储服务器的实际存储位置。 */ private String remotePath; + /** + * 默认构造函数,用于创建一个 DfsPath 对象,其属性初始值为 null。 + */ public DfsPath() { } /** - * Constructor with httpPath and remotePath + * 带参数的构造函数,用于创建一个具有指定 HTTP 路径和远程路径的 DfsPath 对象。 * - * @param httpPath - * @param remotePath + * @param httpPath 文件的完整 HTTP 访问路径 + * @param remotePath 文件在存储服务器上的路径 */ public DfsPath(String httpPath, String remotePath) { this.httpPath = httpPath; this.remotePath = remotePath; } + /** + * 获取文件的完整 HTTP 访问路径。 + * + * @return 文件的 HTTP 访问路径 + */ public String getHttpPath() { return httpPath; } + /** + * 设置文件的完整 HTTP 访问路径。 + * + * @param httpPath 要设置的 HTTP 访问路径 + */ public void setHttpPath(String httpPath) { this.httpPath = httpPath; } + /** + * 获取文件在存储服务器上的路径。 + * + * @return 文件在存储服务器上的路径 + */ public String getRemotePath() { return remotePath; } + /** + * 设置文件在存储服务器上的路径。 + * + * @param remotePath 要设置的存储服务器上的路径 + */ public void setRemotePath(String remotePath) { this.remotePath = remotePath; } -} +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/api/DfsSdk.java b/src/main/java/com/xmomen/module/resource/api/DfsSdk.java index 431a6f8..2d27023 100644 --- a/src/main/java/com/xmomen/module/resource/api/DfsSdk.java +++ b/src/main/java/com/xmomen/module/resource/api/DfsSdk.java @@ -4,7 +4,9 @@ import java.io.File; public class DfsSdk { + // 根据dfsType和bucketName获取DfsService实例 public static DfsService getDfsInstance(String dfsType, String bucketName) { + // 如果dfsType为FastDFS,则获取FastDfsService实例 if ("FastDFS".equalsIgnoreCase(dfsType)) { DfsService dfsService = FastDfsService.getInstance(bucketName); return dfsService; @@ -12,6 +14,7 @@ public class DfsSdk { return null; } + // 默认获取FastDFS的DfsService实例 public static DfsService getDfsInstance() { return getDfsInstance("FastDFS", "group1"); } diff --git a/src/main/java/com/xmomen/module/resource/api/DfsService.java b/src/main/java/com/xmomen/module/resource/api/DfsService.java index 3d8b68d..0cede84 100644 --- a/src/main/java/com/xmomen/module/resource/api/DfsService.java +++ b/src/main/java/com/xmomen/module/resource/api/DfsService.java @@ -4,73 +4,91 @@ import java.io.File; import java.util.List; import java.util.Map; +/** + * DfsService 接口定义了与分布式文件系统(DFS)进行交互的一系列操作。 + * 这些操作涵盖了文件的上传、下载、删除、列表获取以及路径获取等功能。 + */ public interface DfsService { /** - * Upload file to file system. + * 将本地文件上传到分布式文件系统。 * - * @param filePath local file path - * @param key Key - * @param metadata metadata for the file - * @return DfsPath object or null if fail + * @param filePath 文件在本地的路径,用于定位要上传的文件。 + * @param key 文件的唯一标识,可用于区分不同的文件。 + * @param metadata 文件的元数据,以键值对的形式存储额外信息。 + * @return 若上传成功,返回包含文件在 DFS 中路径信息的 DfsPath 对象;若失败则返回 null。 */ public DfsPath putObject(String filePath, String key, Map metadata); /** - * Upload file to file system + * 将 File 对象表示的文件上传到分布式文件系统。 * - * @param file file - * @param key Key - * @param metadata metadata for the file - * @return DfsPath object or null if fail + * @param file 要上传的文件对象。 + * @param key 文件的唯一标识,用于区分不同的文件。 + * @param metadata 文件的元数据,以键值对的形式存储额外信息。 + * @return 若上传成功,返回包含文件在 DFS 中路径信息的 DfsPath 对象;若失败则返回 null。 */ public DfsPath putObject(File file, String key, Map metadata); /** - * Upload file to file system + * 将字节数组形式的文件内容上传到分布式文件系统。 * - * @param bytes file - * @param key Key - * @param metadata metadata for the file - * @param extName ext name of file - * @return DfsPath object or null if fail + * @param bytes 文件的字节数据,代表文件的实际内容。 + * @param key 文件的唯一标识,用于区分不同的文件。 + * @param metadata 文件的元数据,以键值对的形式存储额外信息。 + * @param extName 文件的扩展名,用于标识文件类型。 + * @return 若上传成功,返回包含文件在 DFS 中路径信息的 DfsPath 对象;若失败则返回 null。 */ public DfsPath putObject(byte[] bytes, String key, Map metadata, String extName); /** - * Get file from file system with remotePath + * 从分布式文件系统中根据远程路径和键获取文件。 * - * @param remotePath remote file path on file system - * @param key Key - * @return DfsPath object or null if fail + * @param remotePath 文件在分布式文件系统中的远程路径,用于定位文件。 + * @param key 文件的唯一标识,用于验证文件的身份。 + * @return 若获取成功,返回包含文件数据和元信息的 DfsFile 对象;若失败则返回 null。 */ public DfsFile getObject(String remotePath, String key); /** - * Delete the file on file system + * 从分布式文件系统中删除指定远程路径和键对应的文件。 * - * @param remotePath remote file path on file system - * @param key Key - * @return true||false + * @param remotePath 文件在分布式文件系统中的远程路径,用于定位要删除的文件。 + * @param key 文件的唯一标识,用于验证要删除的文件。 + * @return 若删除成功,返回 true;若失败则返回 false。 */ public boolean deleteObject(String remotePath, String key); /** - * Get the list of the file on file system + * 获取分布式文件系统中的文件列表。 * - * @return List + * @return 返回一个包含 DfsFile 对象的列表,每个对象代表文件系统中的一个文件;若列表为空则返回空列表。 */ public List listObjects(); /** - * Get the whole url + * 根据文件在分布式文件系统中的远程路径获取其完整的 HTTP 访问路径。 * - * @param remotePath - * @return whole url + * @param remotePath 文件在分布式文件系统中的远程路径。 + * @return 返回文件的完整 HTTP 访问路径,可用于在网络上访问该文件。 */ public String getHttpPath(String remotePath); - + + /** + * 根据 DMS 文件路径获取其对应的完整 HTTP 访问路径。 + * DMS 可能是某种特定的文件管理系统。 + * + * @param dmsFilePath DMS 系统中的文件路径。 + * @return 返回该文件对应的完整 HTTP 访问路径。 + */ public String getDmsHttpPath(String dmsFilePath); - + + /** + * 根据指定的类型获取默认路径。 + * 这里的类型可能是文件的分类、用途等,具体含义取决于实现。 + * + * @param type 文件的类型标识。 + * @return 返回对应类型的默认路径。 + */ public String getDefaultPath(String type); -} +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/api/FastDfsService.java b/src/main/java/com/xmomen/module/resource/api/FastDfsService.java index cc7b3fc..fc86243 100644 --- a/src/main/java/com/xmomen/module/resource/api/FastDfsService.java +++ b/src/main/java/com/xmomen/module/resource/api/FastDfsService.java @@ -19,58 +19,77 @@ import org.csource.fastdfs.StorageServer; import org.csource.fastdfs.TrackerClient; import org.csource.fastdfs.TrackerServer; +/** + * FastDfsService 类实现了 DfsService 接口,用于与 FastDFS 分布式文件系统进行交互。 + * 该类采用单例模式,确保在整个应用中只有一个实例与 FastDFS 进行通信。 + */ public class FastDfsService implements DfsService { + // 单例实例 private static FastDfsService instance = null; + // 基础 URL,用于构建文件的完整 HTTP 访问路径 private String baseUrl = ""; + // DMS 基础 URL,用于构建 DMS 文件的完整 HTTP 访问路径 private String dmsBaseUrl = ""; + // 默认图片 URL private String defaultPicUrl = ""; - //private static Logger logger = Logger.getLogger(FastDfsService.class.getName()); - + // 配置文件中基础 URL 的键名 private static String BASE_URL = "httpBaseUrl"; - + // 配置文件中 DMS 基础 URL 的键名 private static String DMS_BASE_URL = "dmsBaseUrl"; - + // 配置文件中默认图片 URL 的键名 private static String DEFAULT_PIC_URL = "defaultPicUrl"; + // FastDFS 键名,用于元数据中存储文件的唯一标识 private static String FAST_DFS_KEY = "FastDfsKey"; /** - * bucket name + * 存储文件的桶名 */ private final String bucketName; /** - * constructor with bucketName + * 私有构造函数,用于初始化 FastDfsService 实例。 + * 该构造函数会读取 FastDFS 配置文件,并初始化客户端全局配置。 * - * @param bucketName bucket name + * @param bucketName 存储文件的桶名 */ private FastDfsService(String bucketName) { this.bucketName = bucketName; String configFilePath = null; - try { - configFilePath = FastDfsService.class.getResource("/").toURI().getPath() + "fdfs_client.conf"; - } catch (URISyntaxException e1) { - Exception e = new Exception("Cann't found fdfs_client.conf file under " + FastDfsService.class.getResource("/")); - handleException(e); - } try { + // 获取 FastDFS 配置文件的路径 + configFilePath = FastDfsService.class.getResource("/").toURI().getPath() + "fdfs_client.conf"; + } catch (URISyntaxException e1) { + // 若无法找到配置文件,抛出异常并处理 + Exception e = new Exception("Cann't found fdfs_client.conf file under " + FastDfsService.class.getResource("/")); + handleException(e); + } + try { + // 初始化 FastDFS 客户端全局配置 ClientGlobal.init(configFilePath); + // 读取配置文件 IniFileReader reader = new IniFileReader(configFilePath); + // 设置基础 URL setBaseUrl(reader.getStrValue(BASE_URL)); + // 设置 DMS 基础 URL setDmsBaseUrl(reader.getStrValue(DMS_BASE_URL)); + // 设置默认图片 URL setDefaultPicUrl(reader.getStrValue(DEFAULT_PIC_URL)); } catch (Exception e) { + // 处理初始化过程中出现的异常 handleException(e); } } /** - * Get instance of FastDfsService, for Singleton - * @param bucketName bucket name - * @return instance of FastDfsService + * 获取 FastDfsService 单例实例的方法。 + * 采用双重检查锁定机制确保线程安全。 + * + * @param bucketName 存储文件的桶名 + * @return FastDfsService 单例实例 */ public static synchronized FastDfsService getInstance(String bucketName) { if (null == instance) { @@ -80,11 +99,11 @@ public class FastDfsService implements DfsService { } /** - * Delete file on file system. + * 从文件系统中删除指定的文件。 * - * @param remotePath remote file path - * @param key Key, not used in FastDFS - * @return true|false + * @param remotePath 远程文件路径 + * @param key 文件的键,在 FastDFS 中未使用 + * @return 删除成功返回 true,失败返回 false */ @Override public boolean deleteObject(String remotePath, String key) { @@ -92,21 +111,28 @@ public class FastDfsService implements DfsService { TrackerClient trackerClient = new TrackerClient(); TrackerServer trackerServer = null; try { + // 获取 Tracker 服务器连接 trackerServer = trackerClient.getConnection(); + // 创建存储客户端 StorageClient storageClient = new StorageClient(trackerServer, null); + // 调用 FastDFS API 删除文件 result = storageClient.delete_file(bucketName, remotePath); - } catch(Exception e) { + } catch (Exception e) { + // 处理删除过程中出现的异常 handleException(e); } finally { if (null != trackerServer) { try { + // 关闭 Tracker 服务器连接 trackerServer.close(); } catch (Exception e) { + // 处理关闭连接时出现的异常 handleException(e); } } } if (0 != result) { + // 删除失败,记录日志并返回 false //logger.info("delete faild, the faild code is: " + result); return false; } @@ -114,26 +140,33 @@ public class FastDfsService implements DfsService { } /** - * Find the whole url + * 根据远程路径构建文件的完整 HTTP 访问路径。 * - * @param remotePath remote path - * @return the whole url + * @param remotePath 远程文件路径 + * @return 文件的完整 HTTP 访问路径 */ @Override public String getHttpPath(String remotePath) { return baseUrl + "/" + bucketName + "/" + remotePath; } + /** + * 根据 DMS 文件路径构建其完整的 HTTP 访问路径。 + * + * @param dmsFilePath DMS 文件路径 + * @return DMS 文件的完整 HTTP 访问路径 + */ @Override public String getDmsHttpPath(String dmsFilePath) { - return dmsBaseUrl + dmsFilePath; + return dmsBaseUrl + dmsFilePath; } + /** - * Get the file, and return DfsFile object + * 从文件系统中获取指定的文件。 * - * @param remotePath remote path - * @param key Key, not used in FastDFS, can be null - * @return DfsFile object or null if fail + * @param remotePath 远程文件路径 + * @param key 文件的键,在 FastDFS 中未使用,可以为 null + * @return 若获取成功,返回 DfsFile 对象;否则返回 null */ @Override public DfsFile getObject(String remotePath, String key) { @@ -141,59 +174,75 @@ public class FastDfsService implements DfsService { TrackerServer trackerServer = null; StorageServer storageServer = null; try { + // 获取 Tracker 服务器连接 trackerServer = trackerClient.getConnection(); + // 获取存储服务器 storageServer = trackerClient.getFetchStorage(trackerServer, bucketName, remotePath); + // 创建存储客户端 StorageClient storageClient = new StorageClient(trackerServer, storageServer); + // 下载文件 byte[] bytes = storageClient.download_file(this.bucketName, remotePath); if (null != bytes) { + // 获取文件的元数据 NameValuePair[] value_pairs = storageClient.get_metadata(bucketName, remotePath); Map metadata = new HashMap(); for (int i = 0; i < value_pairs.length; i++) { + // 将元数据存储到 Map 中 metadata.put(value_pairs[i].getName(), value_pairs[i].getValue()); } + // 创建 DfsFile 对象 DfsFile dfsFile = new DfsFile(metadata.get(FAST_DFS_KEY), bytes, metadata); return dfsFile; } - } catch (Exception e){ + } catch (Exception e) { + // 处理获取文件过程中出现的异常 handleException(e); } finally { if (null != storageServer) { try { + // 关闭存储服务器连接 storageServer.close(); } catch (Exception e) { + // 处理关闭连接时出现的异常 handleException(e); } } if (null != trackerServer) { try { + // 关闭 Tracker 服务器连接 trackerServer.close(); } catch (Exception e) { + // 处理关闭连接时出现的异常 handleException(e); } } } + // 获取文件失败,记录日志并返回 null //logger.info("Get object failed, get null object"); return null; } /** - * Get the file list of file system. - * Not implement at the moment, because FastDFS API not support. + * 获取文件系统中的文件列表。 + * 目前由于 FastDFS API 不支持,该方法未实现。 + * + * @return 始终返回 null */ @Override public List listObjects() { - //to do - //Because fastDFS api do not support list object method. + // 待实现 + // 因为 FastDFS API 不支持列出对象的方法 return null; } /** - * Upload the file to file system by file path + * 通过文件路径将文件上传到文件系统。 + * 该方法会将文件转换为 File 对象,然后调用 putObject(File file, String key, Map metadata) 方法进行上传。 * - * @param filePath local file path. - * @param key Key, not used in FastDFS, can be null - * @param metadata metadata for file, can be null - * @return DfsFile object or null if fail + * @param filePath 本地文件路径 + * @param key 文件的键,在 FastDFS 中未使用,可以为 null + * @param metadata 文件的元数据,可以为 null + * @return 若上传成功,返回 DfsPath 对象;否则返回 null */ @Override public DfsPath putObject(String filePath, String key, Map metadata) { @@ -202,13 +251,13 @@ public class FastDfsService implements DfsService { } /** - * Upload the file to file system by bytes + * 通过字节数组将文件上传到文件系统。 * - * @param bytes bytes - * @param key Key, not used in FastDFS - * @param metadata metadata for file, can be null - * @param extName extName for file, can be null - * @return DfsPath object or null if fail + * @param bytes 文件的字节数组 + * @param key 文件的键,在 FastDFS 中未使用 + * @param metadata 文件的元数据,可以为 null + * @param extName 文件的扩展名,可以为 null + * @return 若上传成功,返回 DfsPath 对象;否则返回 null */ @Override public DfsPath putObject(byte[] bytes, String key, Map metadata, String extName) { @@ -216,147 +265,215 @@ public class FastDfsService implements DfsService { TrackerServer trackerServer = null; StorageServer storageServer = null; try { + // 获取 Tracker 服务器连接 trackerServer = trackerClient.getConnection(); + // 获取存储服务器列表 StorageServer[] storageServers = trackerClient.getStoreStorages(trackerServer, bucketName); if (null != storageServers) { + // 选择第一个存储服务器 storageServer = storageServers[0]; + // 创建存储客户端 StorageClient storageClient = new StorageClient(trackerServer, storageServer); NameValuePair[] meta_list; int i = 0; if (null == metadata) { + // 若元数据为空,创建一个包含一个元素的元数据数组 meta_list = new NameValuePair[1]; } else { + // 若元数据不为空,创建一个包含元数据和 FastDFS 键的数组 meta_list = new NameValuePair[metadata.size() + 1]; for (Map.Entry entry : metadata.entrySet()) { meta_list[i++] = new NameValuePair(entry.getKey(), entry.getValue()); } } + // 添加 FastDFS 键到元数据数组 meta_list[i] = new NameValuePair(FAST_DFS_KEY, key); + // 调用 FastDFS API 上传文件 String[] results = storageClient.upload_file(bytes, extName, meta_list); if (null == results) { + // 上传失败,记录日志并返回 null //logger.info("upload file fail, error codes: " + storageClient.getErrorCode()); return null; } else { + // 获取远程文件名 String remote_fileName = results[1]; + // 构建文件的完整 HTTP 访问路径 String httpPath = this.getHttpPath(remote_fileName); + // 创建 DfsPath 对象 DfsPath dfsPath = new DfsPath(httpPath, remote_fileName); return dfsPath; } } } catch (Exception e) { + // 处理上传过程中出现的异常 handleException(e); } finally { if (null != storageServer) { try { + // 关闭存储服务器连接 storageServer.close(); } catch (Exception e) { + // 处理关闭连接时出现的异常 handleException(e); } } if (null != trackerServer) { try { + // 关闭 Tracker 服务器连接 trackerServer.close(); } catch (Exception e) { + // 处理关闭连接时出现的异常 handleException(e); } } } + // 上传失败,记录日志并返回 null //logger.info("Upload file faild, because can not get storage servers!"); return null; - } /** - * Upload the file to file system + * 将文件上传到文件系统。 + * 该方法会将文件转换为字节数组,然后调用 putObject(byte[] bytes, String key, Map metadata, String extName) 方法进行上传。 * - * @param file file - * @param key Key, not used in FastDFS, can be null - * @param metadata metadata for file , can be null - * @return DfsPath object or null if fail + * @param file 文件对象 + * @param key 文件的键,在 FastDFS 中未使用,可以为 null + * @param metadata 文件的元数据,可以为 null + * @return 若上传成功,返回 DfsPath 对象;否则返回 null */ @Override public DfsPath putObject(File file, String key, Map metadata) { FileInputStream in = null; byte[] file_buff = null; try { + // 打开文件输入流 in = new FileInputStream(file); if (null != in) { + // 获取文件长度 int len = in.available(); + // 创建字节数组 file_buff = new byte[len]; + // 读取文件内容到字节数组 in.read(file_buff); } } catch (Exception e) { + // 处理读取文件过程中出现的异常 handleException(e); } finally { if (null != in) { try { + // 关闭文件输入流 in.close(); } catch (Exception e) { + // 处理关闭流时出现的异常 handleException(e); } } } String file_ext_name = ""; if (file.getName().lastIndexOf(".") > 0) { + // 获取文件扩展名 file_ext_name = file.getName().substring(file.getName().lastIndexOf(".") + 1); } + // 调用 putObject(byte[] bytes, String key, Map metadata, String extName) 方法上传文件 return putObject(file_buff, key, metadata, file_ext_name); } + /** + * 获取基础 URL。 + * + * @return 基础 URL + */ public String getBaseUrl() { return baseUrl; } + /** + * 设置基础 URL。 + * + * @param baseUrl 要设置的基础 URL + */ private void setBaseUrl(String baseUrl) { this.baseUrl = baseUrl; } + /** + * 获取 DMS 基础 URL。 + * + * @return DMS 基础 URL + */ public String getDmsBaseUrl() { - return dmsBaseUrl; + return dmsBaseUrl; } + + /** + * 设置 DMS 基础 URL。 + * + * @param dmsBaseUrl 要设置的 DMS 基础 URL + */ public void setDmsBaseUrl(String dmsBaseUrl) { - this.dmsBaseUrl = dmsBaseUrl; + this.dmsBaseUrl = dmsBaseUrl; } - + + /** + * 获取默认图片 URL。 + * + * @return 默认图片 URL + */ public String getDefaultPicUrl() { - return defaultPicUrl; + return defaultPicUrl; } + + /** + * 设置默认图片 URL。 + * + * @param defaultPicUrl 要设置的默认图片 URL + */ public void setDefaultPicUrl(String defaultPicUrl) { - this.defaultPicUrl = defaultPicUrl; + this.defaultPicUrl = defaultPicUrl; } - + /** - * Handle Exception - * @param e exception + * 处理异常的方法。 + * 根据异常类型抛出不同的 DfsException 异常。 + * + * @param e 要处理的异常 */ private void handleException(Exception e) { if (e instanceof IOException) { + // 处理 IOException,抛出 DfsException,错误码为 100 //logger.error("Exception occured : DFSException code: 100," + " exception message :" + e.getMessage()); throw new DfsException("100", e.getMessage()); } else if (e instanceof FileNotFoundException) { + // 处理 FileNotFoundException,抛出 DfsException,错误码为 200 //logger.error("Exception occured : DFSException code: 200," + " exception message : file not found." + e.getMessage()); throw new DfsException("200", e.getMessage()); } else if (e instanceof MyException) { + // 处理 MyException,抛出 DfsException,错误码为 300 //logger.error("Exception occured : DFSException code: 300," + " exception message :" + e.getMessage()); throw new DfsException("300", e.getMessage()); } else if (e instanceof Exception) { + // 处理其他异常,抛出 DfsException,错误码为 400 //logger.error("Exception occured : DFSException code: 400," + " exception message :" + e.getMessage()); throw new DfsException("400", e.getMessage()); } } - @Override - public String getDefaultPath(String type) { - if("PICTURE".equalsIgnoreCase(type)) { - return defaultPicUrl; - } - return defaultPicUrl; - } - - - - -} + /** + * 根据类型获取默认路径。 + * 如果类型为 "PICTURE",则返回默认图片 URL;否则也返回默认图片 URL。 + * + * @param type 路径类型 + * @return 默认路径 + */ + @Override + public String getDefaultPath(String type) { + if ("PICTURE".equalsIgnoreCase(type)) { + return defaultPicUrl; + } + return defaultPicUrl; + } +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/controller/ResourceController.java b/src/main/java/com/xmomen/module/resource/controller/ResourceController.java index fcc48f5..50ca774 100644 --- a/src/main/java/com/xmomen/module/resource/controller/ResourceController.java +++ b/src/main/java/com/xmomen/module/resource/controller/ResourceController.java @@ -1,130 +1,203 @@ +// 声明该类所在的包,此包为资源控制器相关的包 package com.xmomen.module.resource.controller; +// 导入自定义框架中的业务异常类,用于处理业务逻辑中出现的异常 import com.xmomen.framework.exception.BusinessException; +// 导入自定义框架中 MyBatis 分页相关的 Page 类,用于处理分页查询结果 import com.xmomen.framework.mybatis.page.Page; +// 导入自定义模块中的日志注解,用于记录操作日志 import com.xmomen.module.logger.Log; +// 导入资源查询模型类,用于封装资源查询的条件 import com.xmomen.module.resource.model.ResourceQuery; +// 导入资源数据模型类,用于封装资源的相关数据 import com.xmomen.module.resource.model.ResourceModel; +// 导入资源服务类,该类包含资源相关的业务逻辑 import com.xmomen.module.resource.service.ResourceService; +// 导入 Apache Commons IO 工具类,用于处理输入输出流 import org.apache.commons.io.IOUtils; +// 导入 Jeecg 框架中 Excel 导入工具类,用于从 Excel 文件中导入数据 import org.jeecgframework.poi.excel.ExcelImportUtil; +// 导入 Jeecg 框架中 Excel 导出参数类,用于配置 Excel 导出的参数 import org.jeecgframework.poi.excel.entity.ExportParams; +// 导入 Jeecg 框架中 Excel 导入参数类,用于配置 Excel 导入的参数 import org.jeecgframework.poi.excel.entity.ImportParams; +// 导入 Jeecg 框架中 Excel 导入结果类,用于封装 Excel 导入的结果 import org.jeecgframework.poi.excel.entity.result.ExcelImportResult; +// 导入 Jeecg 框架中普通 Excel 常量类,包含一些 Excel 操作的常量 import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; +// 导入 Jeecg 框架中 Excel 导入异常类,用于处理 Excel 导入过程中出现的异常 import org.jeecgframework.poi.exception.excel.ExcelImportException; +// 导入 Spring 框架中的自动装配注解,用于自动注入依赖的 Bean import org.springframework.beans.factory.annotation.Autowired; +// 导入 Spring 框架中的模型映射类,用于在控制器和视图之间传递数据 import org.springframework.ui.ModelMap; +// 导入 Spring 框架中的数据绑定结果类,用于处理数据绑定过程中的错误信息 import org.springframework.validation.BindingResult; +// 导入 Spring 框架中的请求映射相关注解,用于处理 HTTP 请求 import org.springframework.web.bind.annotation.*; +// 导入 Spring 框架中用于处理多部分文件上传的类 import org.springframework.web.multipart.MultipartFile; +// 导入 Spring 框架中的模型和视图类,用于返回包含模型数据和视图名称的对象 import org.springframework.web.servlet.ModelAndView; +// 导入 JSR-303 验证框架中的有效注解,用于对请求参数进行验证 import javax.validation.Valid; +// 导入 Java 序列化接口,用于支持对象的序列化和反序列化 import java.io.Serializable; +// 导入 Java 输入输出异常类,用于处理输入输出操作中出现的异常 import java.io.IOException; +// 导入 Java 输入流类,用于读取数据 import java.io.InputStream; +// 导入 Java 列表接口,用于存储多个元素 import java.util.List; /** + * 资源控制器类,负责处理与资源目录相关的 HTTP 请求。 + * * @author tanxinzheng * @version 1.0.0 * @date 2017-4-10 23:26:20 */ +// 标记该类为 RESTful 风格的控制器,会自动将方法返回值转换为 JSON 格式 @RestController +// 定义该控制器处理的请求路径前缀为 /resource @RequestMapping(value = "/resource") public class ResourceController { + // 使用自动装配注解将 ResourceService 注入到当前类中,用于调用资源相关的业务逻辑 @Autowired ResourceService resourceService; /** - * 资源目录列表 + * 处理获取资源目录列表的请求。 * - * @param limit 每页结果数 - * @param offset 页码 - * @param id 主键 - * @param ids 主键数组 - * @param excludeIds 不包含主键数组 - * @return Page 资源目录领域分页对象 + * @param limit 每页显示的结果数量 + * @param offset 当前页码 + * @param id 资源的主键,可选参数 + * @param entityType 资源所属的实体类型,可选参数 + * @param entityId 资源所属的实体 ID,可选参数 + * @param ids 资源主键数组,可选参数 + * @param excludeIds 不包含的资源主键数组,可选参数 + * @return 包含资源目录数据的分页对象 */ + // 映射 HTTP GET 请求到该方法 @RequestMapping(method = RequestMethod.GET) + // 使用日志注解记录该操作的名称为查询资源目录列表 @Log(actionName = "查询资源目录列表") - public Page getResourceList(@RequestParam(value = "limit") Integer limit, - @RequestParam(value = "offset") Integer offset, - @RequestParam(value = "id", required = false) String id, - @RequestParam(value = "entityType", required = false) String entityType, - @RequestParam(value = "entityId", required = false) String entityId, - @RequestParam(value = "ids", required = false) String[] ids, - @RequestParam(value = "excludeIds", required = false) String[] excludeIds) { + public Page getResourceList( + // 从请求参数中获取每页结果数 + @RequestParam(value = "limit") Integer limit, + // 从请求参数中获取页码 + @RequestParam(value = "offset") Integer offset, + // 从请求参数中获取资源主键,该参数可选 + @RequestParam(value = "id", required = false) String id, + // 从请求参数中获取资源所属的实体类型,该参数可选 + @RequestParam(value = "entityType", required = false) String entityType, + // 从请求参数中获取资源所属的实体 ID,该参数可选 + @RequestParam(value = "entityId", required = false) String entityId, + // 从请求参数中获取资源主键数组,该参数可选 + @RequestParam(value = "ids", required = false) String[] ids, + // 从请求参数中获取不包含的资源主键数组,该参数可选 + @RequestParam(value = "excludeIds", required = false) String[] excludeIds) { + // 创建资源查询对象 ResourceQuery resourceQuery = new ResourceQuery(); + // 设置查询条件:资源主键 resourceQuery.setId(id); + // 设置查询条件:不包含的资源主键数组 resourceQuery.setExcludeIds(excludeIds); + // 设置查询条件:资源主键数组 resourceQuery.setIds(ids); + // 设置查询条件:资源所属的实体类型 resourceQuery.setEntityType(entityType); + // 设置查询条件:资源所属的实体 ID resourceQuery.setEntityId(entityId); + // 调用资源服务的方法,根据分页信息和查询条件获取资源目录分页数据 return resourceService.getResourceModelPage(limit, offset, resourceQuery); } /** - * 查询单个资源目录 + * 处理获取单个资源目录的请求。 * - * @param id 主键 - * @return ResourceModel 资源目录领域对象 + * @param id 资源的主键 + * @return 资源目录的数据模型对象 */ + // 映射形如 /resource/{id} 的 HTTP GET 请求到该方法 @RequestMapping(value = "/{id}", method = RequestMethod.GET) + // 使用日志注解记录该操作的名称为查询资源目录 @Log(actionName = "查询资源目录") - public ResourceModel getResourceById(@PathVariable(value = "id") String id) { + public ResourceModel getResourceById( + // 从路径中获取资源主键 + @PathVariable(value = "id") String id) { + // 调用资源服务的方法,根据主键获取单个资源目录的数据 return resourceService.getOneResourceModel(id); } /** - * 新增资源目录 + * 处理新增资源目录的请求。 * - * @param resourceModel 新增对象参数 - * @return ResourceModel 资源目录领域对象 + * @param resourceModel 包含新增资源目录信息的数据模型对象 + * @return 新增后的资源目录的数据模型对象 */ + // 映射 HTTP POST 请求到该方法 @RequestMapping(method = RequestMethod.POST) + // 使用日志注解记录该操作的名称为新增资源目录 @Log(actionName = "新增资源目录") - public ResourceModel createResource(@RequestBody @Valid ResourceModel resourceModel) { + public ResourceModel createResource( + // 从请求体中获取新增资源目录的数据,并进行数据验证 + @RequestBody @Valid ResourceModel resourceModel) { + // 调用资源服务的方法,创建新的资源目录 return resourceService.createResource(resourceModel); } /** - * 更新资源目录 + * 处理更新资源目录的请求。 * - * @param id 主键 - * @param resourceModel 更新对象参数 + * @param id 要更新的资源的主键 + * @param resourceModel 包含更新后资源目录信息的数据模型对象 */ + // 映射形如 /resource/{id} 的 HTTP PUT 请求到该方法 @RequestMapping(value = "/{id}", method = RequestMethod.PUT) + // 使用日志注解记录该操作的名称为更新资源目录 @Log(actionName = "更新资源目录") - public void updateResource(@PathVariable(value = "id") String id, - @RequestBody @Valid ResourceModel resourceModel) { + public void updateResource( + // 从路径中获取要更新的资源主键 + @PathVariable(value = "id") String id, + // 从请求体中获取更新后的资源目录数据,并进行数据验证 + @RequestBody @Valid ResourceModel resourceModel) { + // 调用资源服务的方法,更新资源目录信息 resourceService.updateResource(resourceModel); } /** - * 删除资源目录 + * 处理删除单个资源目录的请求。 * - * @param id 主键 + * @param id 要删除的资源的主键 */ + // 映射形如 /resource/{id} 的 HTTP DELETE 请求到该方法 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + // 使用日志注解记录该操作的名称为删除单个资源目录 @Log(actionName = "删除单个资源目录") - public void deleteResource(@PathVariable(value = "id") String id) { + public void deleteResource( + // 从路径中获取要删除的资源主键 + @PathVariable(value = "id") String id) { + // 调用资源服务的方法,删除指定主键的资源目录 resourceService.deleteResource(id); } /** - * 删除资源目录 + * 处理批量删除资源目录的请求。 * - * @param ids 主键 + * @param ids 要删除的资源的主键数组 */ + // 映射 HTTP DELETE 请求到该方法 @RequestMapping(method = RequestMethod.DELETE) + // 使用日志注解记录该操作的名称为批量删除资源目录 @Log(actionName = "批量删除资源目录") - public void deleteResources(@RequestParam(value = "ids") String[] ids) { + public void deleteResources( + // 从请求参数中获取要删除的资源主键数组 + @RequestParam(value = "ids") String[] ids) { + // 调用资源服务的方法,批量删除指定主键的资源目录 resourceService.deleteResource(ids); } - - -} +} \ No newline at end of file diff --git a/src/main/java/com/xmomen/module/resource/entity/Resource.java b/src/main/java/com/xmomen/module/resource/entity/Resource.java index aaddc97..7d6e44f 100644 --- a/src/main/java/com/xmomen/module/resource/entity/Resource.java +++ b/src/main/java/com/xmomen/module/resource/entity/Resource.java @@ -1,4 +1,4 @@ -package com.xmomen.module.resource.entity; +Xpackage com.xmomen.module.resource.entity; import com.xmomen.framework.mybatis.model.BaseMybatisModel; import javax.persistence.Column; diff --git a/src/main/java/com/xmomen/module/resource/entity/mapper/ResourceMapper.xml b/src/main/java/com/xmomen/module/resource/entity/mapper/ResourceMapper.xml index 8c4a34c..423fd53 100644 --- a/src/main/java/com/xmomen/module/resource/entity/mapper/ResourceMapper.xml +++ b/src/main/java/com/xmomen/module/resource/entity/mapper/ResourceMapper.xml @@ -1,7 +1,15 @@ - - + + + + + + @@ -9,25 +17,37 @@ - - - - - - - - + + + + + + + + + + + + + + and ${criterion.condition} - + + and ${criterion.condition} #{criterion.value} - + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - + + and ${criterion.condition} - + #{listItem} @@ -38,25 +58,30 @@ - - - - - - - - + + + + + + + + + + and ${criterion.condition} - + and ${criterion.condition} #{criterion.value} - + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - + and ${criterion.condition} - + #{listItem} @@ -67,100 +92,148 @@ - + + + ID, ENTITY_TYPE, ENTITY_ID, PATH, RESOURCE_TYPE, IS_DEFAULT - select - + + distinct + from cd_resource - + + - + + order by ${orderByClause} - + + + delete from cd_resource - + + - - + + + + + SELECT replace(UUID(),'-','') insert into cd_resource - + + ID, - + ENTITY_TYPE, - + ENTITY_ID, - + PATH, - + RESOURCE_TYPE, - + IS_DEFAULT, - + + #{id,jdbcType=VARCHAR}, - + #{entityType,jdbcType=VARCHAR}, - + #{entityId,jdbcType=VARCHAR}, - + #{path,jdbcType=VARCHAR}, - + #{resourceType,jdbcType=VARCHAR}, - + #{isDefault,jdbcType=INTEGER}, - select count(*) from cd_resource - + + - + + + update cd_resource - - + + + ID = #{record.id,jdbcType=VARCHAR}, - + ENTITY_TYPE = #{record.entityType,jdbcType=VARCHAR}, - + ENTITY_ID = #{record.entityId,jdbcType=VARCHAR}, - + PATH = #{record.path,jdbcType=VARCHAR}, - + RESOURCE_TYPE = #{record.resourceType,jdbcType=VARCHAR}, - + IS_DEFAULT = #{record.isDefault,jdbcType=INTEGER}, - + +