pull/3/head
Anayigeren 1 month ago
parent 894d6e99a9
commit 5629dcfa3d

@ -17,22 +17,44 @@ public
@Data @Data
class ExpressReport implements Serializable { class ExpressReport implements Serializable {
// 物流公司
// 物流公司
@Excel(name = "物流公司") @Excel(name = "物流公司")
// 订单号
private String expressName; private String expressName;
// 订单号
// 总箱数
@Excel(name = "订单号", width = 20) @Excel(name = "订单号", width = 20)
private String orderNo; private String orderNo;
// 出库时间
// 总箱数
@Excel(name = "总箱数") @Excel(name = "总箱数")
// 收货时间
private int totalBoxNum; private int totalBoxNum;
// 出库时间
// 二次配送
@Excel(name = "出库时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss") @Excel(name = "出库时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss")
// 收货时间
// 正常配送
private Date outDate; private Date outDate;
@Excel(name = "收货时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss") @Excel(name = "收货时间", width = 20, exportFormat = "yyyy-MM-dd HH:mm:ss")
// 异常配送
// 二次配送
// 正常配送
// 物流代收款
private Date shouHuoDate; private Date shouHuoDate;
@Excel(name = "二次配送", type = 10) @Excel(name = "二次配送", type = 10)
// 损失承担
// 异常配送
private int isTwoSend; private int isTwoSend;
// 物流代收款
// 是否拒收
@Excel(name = "正常配送", type = 10) @Excel(name = "正常配送", type = 10)
// 损失承担
private int isNormal; private int isNormal;
@Excel(name = "异常配送", type = 10) @Excel(name = "异常配送", type = 10)
private int isNoNormal; private int isNoNormal;
// 是否拒收
@Excel(name = "物流代收款", width = 15, type = 10) @Excel(name = "物流代收款", width = 15, type = 10)
private double expressAmount; private double expressAmount;
@Excel(name = "损失承担", type = 10) @Excel(name = "损失承担", type = 10)

@ -11,53 +11,57 @@ import java.io.Serializable;
public public
@Data @Data
class FinanceReport implements Serializable { class FinanceReport implements Serializable {
//公司ID
private int cdCompanyId; private int cdCompanyId;
//客户经理
@Excel(name = "客户经理") @Excel(name = "客户经理")
private String managerName; private String managerName;
//单位/个人
@Excel(name = "单位/个人") @Excel(name = "单位/个人")
private String companyName; private String companyName;
//用户ID
private int cdUserId; private int cdUserId;
//总张数 //总张数(预付款)
@Excel(name = "总张数(预付款)", type = 10) @Excel(name = "总张数(预付款)", type = 10)
private int beforeCouponCount; private int beforeCouponCount;
//总金额 //总金额(预付款)
@Excel(name = "总金额(预付款)", type = 10) @Excel(name = "总金额(预付款)", type = 10)
private double beforeTotalValue; private double beforeTotalValue;
//充值金额 //充值金额(预付款)
@Excel(name = "充值金额(预付款)", type = 10) @Excel(name = "充值金额(预付款)", type = 10)
private double beforeTotalRechargeValue; private double beforeTotalRechargeValue;
//已付 //已付(预付款)
@Excel(name = "已付(预付款)", type = 10) @Excel(name = "已付(预付款)", type = 10)
private double beforeTotalYesValue; private double beforeTotalYesValue;
// 未付 // 未付(预付款)
@Excel(name = "未付(预付款)", type = 10) @Excel(name = "未付(预付款)", type = 10)
private double beforeTotalNoValue; private double beforeTotalNoValue;
// 余额 // 余额(预付款)
@Excel(name = "余额(预付款)", type = 10) @Excel(name = "余额(预付款)", type = 10)
private double beforeUserTotalValue; private double beforeUserTotalValue;
// 回馈总金额 // 回馈总金额(预付款)
@Excel(name = "回馈总金额(预付款)", type = 10) @Excel(name = "回馈总金额(预付款)", type = 10)
private double beforeGiftTotalValue; private double beforeGiftTotalValue;
// 回馈剩余金额 // 回馈剩余金额(预付款)
@Excel(name = "回馈剩余金额(预付款)", type = 10) @Excel(name = "回馈剩余金额(预付款)", type = 10)
private double beforeGiftUserTotalValue; private double beforeGiftUserTotalValue;
// 总张数 // 总张数(后付款)
@Excel(name = "总张数(后付款)", type = 10) @Excel(name = "总张数(后付款)", type = 10)
private int afterCouponCount; private int afterCouponCount;
// 总金额 // 总金额(后付款)
@Excel(name = "总金额(后付款)", type = 10) @Excel(name = "总金额(后付款)", type = 10)
private double afterTotalValue; private double afterTotalValue;
// 充值金额 // 充值金额(后付款)
@Excel(name = "充值金额(后付款)", type = 10) @Excel(name = "充值金额(后付款)", type = 10)
private double afterTotalRechargeValue; private double afterTotalRechargeValue;
// 已付 // 已付(后付款)
@Excel(name = "已付(后付款)", type = 10) @Excel(name = "已付(后付款)", type = 10)
private double afterTotalYesValue; private double afterTotalYesValue;
// 未付 // 未付(后付款)
@Excel(name = "未付(后付款)", type = 10) @Excel(name = "未付(后付款)", type = 10)
private double afterTotalNoValue; private double afterTotalNoValue;
// 余额 // 余额(后付款)
@Excel(name = "余额(后付款)", type = 10) @Excel(name = "余额(后付款)", type = 10)
private double afterUserTotalValue; private double afterUserTotalValue;
// 回馈总金额(后付款) // 回馈总金额(后付款)
@ -78,12 +82,16 @@ class FinanceReport implements Serializable {
//回馈总金额 //回馈总金额
@Excel(name = "回馈总金额", type = 10) @Excel(name = "回馈总金额", type = 10)
private double giftOrderTotal; private double giftOrderTotal;
//客户经理代收
@Excel(name = "客户经理代收", type = 10) @Excel(name = "客户经理代收", type = 10)
private double managerAmount; private double managerAmount;
//POS
@Excel(name = "POS", type = 10) @Excel(name = "POS", type = 10)
private double posAmount; private double posAmount;
//转账
@Excel(name = "转账", type = 10) @Excel(name = "转账", type = 10)
private double zhuanAmount; private double zhuanAmount;
//物流代收
@Excel(name = "物流代收", type = 10) @Excel(name = "物流代收", type = 10)
private double expressAmount; private double expressAmount;
} }

@ -16,33 +16,49 @@ import java.util.Date;
public @Data public @Data
class OrderDeliveryReport implements Serializable { class OrderDeliveryReport implements Serializable {
// 下单日期
@Excel(name = "下单日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd") @Excel(name = "下单日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd")
private Date createTime; private Date createTime;
// 订单号
@Excel(name = "订单号",width = 20) @Excel(name = "订单号",width = 20)
private String orderNo; private String orderNo;
// 快递商
@Excel(name="快递商") @Excel(name="快递商")
private String expressName; private String expressName;
// 收货人姓名
@Excel(name = "收货人姓名",width = 15) @Excel(name = "收货人姓名",width = 15)
private String consigneeName; private String consigneeName;
// 收货人电话
@Excel(name = "收货人电话",width = 15) @Excel(name = "收货人电话",width = 15)
private String consigneePhone; private String consigneePhone;
// 收货人地址
@Excel(name = "收货人地址",width = 30) @Excel(name = "收货人地址",width = 30)
private String consigneeAddress; private String consigneeAddress;
// 金额
@Excel(name = "金额") @Excel(name = "金额")
private double totalAmount; private double totalAmount;
// 付款方式
@Excel(name = "付款方式") @Excel(name = "付款方式")
private String paymentModeDesc; private String paymentModeDesc;
// 付款金额
@Excel(name = "付款金额",type = 10) @Excel(name = "付款金额",type = 10)
private double payAmount; private double payAmount;
// 附加付款方式
@Excel(name = "附加付款方式") @Excel(name = "附加付款方式")
private String otherPaymentModeDesc; private String otherPaymentModeDesc;
// 附加付款金额
@Excel(name = "附加付款金额",type = 10) @Excel(name = "附加付款金额",type = 10)
private double otherPayAmount; private double otherPayAmount;
// 送货日期
@Excel(name = "送货日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd") @Excel(name = "送货日期" , exportFormat="yyyy-MM-dd", importFormat = "yyyy-MM-dd")
private Date appointmentTime; private Date appointmentTime;
// 备注
@Excel(name = "备注",width = 30) @Excel(name = "备注",width = 30)
private String remark; private String remark;
// 订单状态描述
private String orderStatusDesc; private String orderStatusDesc;
// 总箱数
private int totalBoxNum; private int totalBoxNum;
// 快递扫描箱数
private int expressScanBoxNum; private int expressScanBoxNum;
} }

@ -17,45 +17,67 @@ public
@Data @Data
class OrderReport implements Serializable { class OrderReport implements Serializable {
// 支付方式
private String paymentMode; private String paymentMode;
// 支付金额
private double payAmount; private double payAmount;
// 其他支付方式
private String otherPaymentMode; private String otherPaymentMode;
// 其他支付金额
private double otherPayAmount; private double otherPayAmount;
// 订单类型
@Excel(name = "订单类型") @Excel(name = "订单类型")
private String orderType; private String orderType;
// 订单号
@Excel(name = "订单号", width = 20) @Excel(name = "订单号", width = 20)
private String orderNo; private String orderNo;
// 客户姓名
@Excel(name = "客户姓名") @Excel(name = "客户姓名")
private String consigneeName; private String consigneeName;
// 电话
@Excel(name = "电话", width = 15) @Excel(name = "电话", width = 15)
private String consigneePhone; private String consigneePhone;
// 单位/个人
@Excel(name = "单位/个人") @Excel(name = "单位/个人")
private String companyName; private String companyName;
// 客户经理
@Excel(name = "客户经理") @Excel(name = "客户经理")
private String managerName; private String managerName;
// 物流公司
@Excel(name = "物流公司") @Excel(name = "物流公司")
private String expressName; private String expressName;
// 总金额
@Excel(name = "总金额") @Excel(name = "总金额")
private double totalAmount; private double totalAmount;
// 折扣金额
@Excel(name = "折扣金额") @Excel(name = "折扣金额")
private double discountPrice; private double discountPrice;
// 客户经理代收
@Excel(name = "客户经理代收", width = 15, type = 10) @Excel(name = "客户经理代收", width = 15, type = 10)
private double managerAmount; private double managerAmount;
// 物流代收
@Excel(name = "物流代收", type = 10) @Excel(name = "物流代收", type = 10)
private double expressAmount; private double expressAmount;
// 卡类扣款
@Excel(name = "卡类扣款", type = 10) @Excel(name = "卡类扣款", type = 10)
private double couponAmount; private double couponAmount;
// 券类扣款
@Excel(name = "券类扣款", type = 10) @Excel(name = "券类扣款", type = 10)
private double quanAmount; private double quanAmount;
// 刷POS
@Excel(name = "刷POS", type = 10) @Excel(name = "刷POS", type = 10)
private double posAmount; private double posAmount;
// 转账
@Excel(name = "转账", type = 10) @Excel(name = "转账", type = 10)
private double zhuanZhanAmount; private double zhuanZhanAmount;
// 其它
@Excel(name = "其它", type = 10) @Excel(name = "其它", type = 10)
private double otherAmount; private double otherAmount;
// 回馈
@Excel(name = "回馈", type = 10) @Excel(name = "回馈", type = 10)
private double huiKuiAmount; private double huiKuiAmount;
// 退货金额
@Excel(name = "退货金额", type = 10) @Excel(name = "退货金额", type = 10)
private double returnTotalAmount; private double returnTotalAmount;
} }

@ -5,11 +5,16 @@ import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/** /**
*
*/ */
public @Data public @Data
class ReportQuery implements Serializable { class ReportQuery implements Serializable {
// 开始时间
private String beginTime; private String beginTime;
// 结束时间
private String endTime; private String endTime;
// 管理员ID
private Integer managerId; private Integer managerId;
// 公司ID
private Integer companyId; private Integer companyId;
} }

@ -5,14 +5,14 @@ import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable; import java.io.Serializable;
/**
*
*/
public public
@Data @Data
class StockDailyReport implements Serializable { class StockDailyReport implements Serializable {
// 商品名称
@Excel(name = "商品名称") @Excel(name = "商品名称")
private String itemName; private String itemName;
// 商品编码
@Excel(name = "商品编码") @Excel(name = "商品编码")
private String itemCode; private String itemCode;
/** /**

@ -41,9 +41,13 @@ public class ReportOrderService {
* @return * @return
*/ */
public List<OrderReport> getOrderReportList(ReportQuery reportQuery) { public List<OrderReport> getOrderReportList(ReportQuery reportQuery) {
//查询订单报表
List<OrderReport> orderReportList = mybatisDao.getSqlSessionTemplate().selectList(ReportOrderMapper.REPORT_ORDER_MAPPER_NAMESPACE + "getReportOrderList", reportQuery); List<OrderReport> orderReportList = mybatisDao.getSqlSessionTemplate().selectList(ReportOrderMapper.REPORT_ORDER_MAPPER_NAMESPACE + "getReportOrderList", reportQuery);
//遍历订单报表
for (OrderReport orderReport : orderReportList) { for (OrderReport orderReport : orderReportList) {
//判断付款方式
if ("0".equals(orderReport.getPaymentMode())) { if ("0".equals(orderReport.getPaymentMode())) {
//如果是汇款
orderReport.setHuiKuiAmount(orderReport.getPayAmount()); orderReport.setHuiKuiAmount(orderReport.getPayAmount());
} }
if ("1".equals(orderReport.getPaymentMode())) { if ("1".equals(orderReport.getPaymentMode())) {

@ -1,38 +1,66 @@
package com.xmomen.module.resource.api; package com.xmomen.module.resource.api;
/**
* DfsException RuntimeExceptionDFS
*/
public class DfsException extends RuntimeException { public class DfsException extends RuntimeException {
// 序列化版本号,用于确保在反序列化时类的版本一致性
private static final long serialVersionUID = 1497374765949093902L; private static final long serialVersionUID = 1497374765949093902L;
/** /**
* IOException 100 *
* FileNotFoundException 200 *
* Exception from DFS (example: from FastDFS, MyException) 300 * - IOException 100
* OtherException 400 * - FileNotFoundException 200
* - DFS FastDFS MyException 300
* - 400
*/ */
private String code; private String code;
// 异常的详细描述信息
private String message; private String message;
/**
* DfsException
* @param code
* @param message
*/
public DfsException(String code, String message) { public DfsException(String code, String message) {
this.code = code; this.code = code;
this.message = message; this.message = message;
} }
/**
*
* @return
*/
public String getCode() { public String getCode() {
return code; return code;
} }
/**
*
* @param code
*/
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
/**
*
* @return
*/
public String getMessage() { public String getMessage() {
return message; return message;
} }
/**
*
* @param message
*/
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
} }

@ -2,32 +2,45 @@ package com.xmomen.module.resource.api;
import java.util.Map; import java.util.Map;
/**
* DfsFile DFS
*
*/
public class DfsFile { public class DfsFile {
/** /**
* file data *
*
*/ */
private byte[] data; private byte[] data;
/** /**
* key,not used in FastDfs *
* FastDFS 使
*/ */
private String key; private String key;
/** /**
* metadata for file *
*
*
*/ */
private Map<String, String> metadata; private Map<String, String> metadata;
/**
*
* DfsFile null
*/
public DfsFile() { public DfsFile() {
} }
/** /**
* constructor with data, key and metadata * DfsFile
* *
* @param key key,not used in FastDfs * @param key FastDFS 使
* @param data file data * @param data
* @param metadata metadata for file * @param metadata
*/ */
public DfsFile(String key, byte[] data, Map<String, String> metadata) { public DfsFile(String key, byte[] data, Map<String, String> metadata) {
this.key = key; this.key = key;
@ -35,28 +48,58 @@ public class DfsFile {
this.metadata = metadata; this.metadata = metadata;
} }
/**
*
*
* @return
*/
public byte[] getData() { public byte[] getData() {
return data; return data;
} }
/**
*
*
* @param data
*/
public void setData(byte[] data) { public void setData(byte[] data) {
this.data = data; this.data = data;
} }
/**
*
*
* @return
*/
public String getKey() { public String getKey() {
return key; return key;
} }
/**
*
*
* @param key
*/
public void setKey(String key) { public void setKey(String key) {
this.key = key; this.key = key;
} }
/**
*
*
* @return
*/
public Map<String, String> getMetadata() { public Map<String, String> getMetadata() {
return metadata; return metadata;
} }
/**
*
*
* @param metadata
*/
public void setMetadata(Map<String, String> metadata) { public void setMetadata(Map<String, String> metadata) {
this.metadata = metadata; this.metadata = metadata;
} }
} }

@ -1,45 +1,74 @@
package com.xmomen.module.resource.api; package com.xmomen.module.resource.api;
/**
* DfsPath DFS
* HTTP 访
*/
public class DfsPath { public class DfsPath {
/** /**
* whole url, just like http://.../bucketName/remotePath * HTTP 访 http://.../bucketName/remotePath。
* 访
*/ */
private String httpPath; private String httpPath;
/** /**
* file path on storage server *
*
*/ */
private String remotePath; private String remotePath;
/**
* DfsPath null
*/
public DfsPath() { public DfsPath() {
} }
/** /**
* Constructor with httpPath and remotePath * HTTP DfsPath
* *
* @param httpPath * @param httpPath HTTP 访
* @param remotePath * @param remotePath
*/ */
public DfsPath(String httpPath, String remotePath) { public DfsPath(String httpPath, String remotePath) {
this.httpPath = httpPath; this.httpPath = httpPath;
this.remotePath = remotePath; this.remotePath = remotePath;
} }
/**
* HTTP 访
*
* @return HTTP 访
*/
public String getHttpPath() { public String getHttpPath() {
return httpPath; return httpPath;
} }
/**
* HTTP 访
*
* @param httpPath HTTP 访
*/
public void setHttpPath(String httpPath) { public void setHttpPath(String httpPath) {
this.httpPath = httpPath; this.httpPath = httpPath;
} }
/**
*
*
* @return
*/
public String getRemotePath() { public String getRemotePath() {
return remotePath; return remotePath;
} }
/**
*
*
* @param remotePath
*/
public void setRemotePath(String remotePath) { public void setRemotePath(String remotePath) {
this.remotePath = remotePath; this.remotePath = remotePath;
} }
} }

@ -4,7 +4,9 @@ import java.io.File;
public class DfsSdk { public class DfsSdk {
// 根据dfsType和bucketName获取DfsService实例
public static DfsService getDfsInstance(String dfsType, String bucketName) { public static DfsService getDfsInstance(String dfsType, String bucketName) {
// 如果dfsType为FastDFS则获取FastDfsService实例
if ("FastDFS".equalsIgnoreCase(dfsType)) { if ("FastDFS".equalsIgnoreCase(dfsType)) {
DfsService dfsService = FastDfsService.getInstance(bucketName); DfsService dfsService = FastDfsService.getInstance(bucketName);
return dfsService; return dfsService;
@ -12,6 +14,7 @@ public class DfsSdk {
return null; return null;
} }
// 默认获取FastDFS的DfsService实例
public static DfsService getDfsInstance() { public static DfsService getDfsInstance() {
return getDfsInstance("FastDFS", "group1"); return getDfsInstance("FastDFS", "group1");
} }

@ -4,73 +4,91 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* DfsService DFS
*
*/
public interface DfsService { public interface DfsService {
/** /**
* Upload file to file system. *
* *
* @param filePath local file path * @param filePath
* @param key Key * @param key
* @param metadata metadata for the file * @param metadata
* @return DfsPath object or null if fail * @return DFS DfsPath null
*/ */
public DfsPath putObject(String filePath, String key, Map<String, String> metadata); public DfsPath putObject(String filePath, String key, Map<String, String> metadata);
/** /**
* Upload file to file system * File
* *
* @param file file * @param file
* @param key Key * @param key
* @param metadata metadata for the file * @param metadata
* @return DfsPath object or null if fail * @return DFS DfsPath null
*/ */
public DfsPath putObject(File file, String key, Map<String, String> metadata); public DfsPath putObject(File file, String key, Map<String, String> metadata);
/** /**
* Upload file to file system *
* *
* @param bytes file * @param bytes
* @param key Key * @param key
* @param metadata metadata for the file * @param metadata
* @param extName ext name of file * @param extName
* @return DfsPath object or null if fail * @return DFS DfsPath null
*/ */
public DfsPath putObject(byte[] bytes, String key, Map<String, String> metadata, String extName); public DfsPath putObject(byte[] bytes, String key, Map<String, String> metadata, String extName);
/** /**
* Get file from file system with remotePath *
* *
* @param remotePath remote file path on file system * @param remotePath
* @param key Key * @param key
* @return DfsPath object or null if fail * @return DfsFile null
*/ */
public DfsFile getObject(String remotePath, String key); public DfsFile getObject(String remotePath, String key);
/** /**
* Delete the file on file system *
* *
* @param remotePath remote file path on file system * @param remotePath
* @param key Key * @param key
* @return true||false * @return true false
*/ */
public boolean deleteObject(String remotePath, String key); public boolean deleteObject(String remotePath, String key);
/** /**
* Get the list of the file on file system *
* *
* @return List<DfsFile> * @return DfsFile
*/ */
public List<DfsFile> listObjects(); public List<DfsFile> listObjects();
/** /**
* Get the whole url * HTTP 访
* *
* @param remotePath * @param remotePath
* @return whole url * @return HTTP 访访
*/ */
public String getHttpPath(String remotePath); public String getHttpPath(String remotePath);
/**
* DMS HTTP 访
* DMS
*
* @param dmsFilePath DMS
* @return HTTP 访
*/
public String getDmsHttpPath(String dmsFilePath); public String getDmsHttpPath(String dmsFilePath);
/**
*
*
*
* @param type
* @return
*/
public String getDefaultPath(String type); public String getDefaultPath(String type);
} }

@ -19,58 +19,77 @@ import org.csource.fastdfs.StorageServer;
import org.csource.fastdfs.TrackerClient; import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer; import org.csource.fastdfs.TrackerServer;
/**
* FastDfsService DfsService FastDFS
* FastDFS
*/
public class FastDfsService implements DfsService { public class FastDfsService implements DfsService {
// 单例实例
private static FastDfsService instance = null; private static FastDfsService instance = null;
// 基础 URL用于构建文件的完整 HTTP 访问路径
private String baseUrl = ""; private String baseUrl = "";
// DMS 基础 URL用于构建 DMS 文件的完整 HTTP 访问路径
private String dmsBaseUrl = ""; private String dmsBaseUrl = "";
// 默认图片 URL
private String defaultPicUrl = ""; private String defaultPicUrl = "";
//private static Logger logger = Logger.getLogger(FastDfsService.class.getName()); // 配置文件中基础 URL 的键名
private static String BASE_URL = "httpBaseUrl"; private static String BASE_URL = "httpBaseUrl";
// 配置文件中 DMS 基础 URL 的键名
private static String DMS_BASE_URL = "dmsBaseUrl"; private static String DMS_BASE_URL = "dmsBaseUrl";
// 配置文件中默认图片 URL 的键名
private static String DEFAULT_PIC_URL = "defaultPicUrl"; private static String DEFAULT_PIC_URL = "defaultPicUrl";
// FastDFS 键名,用于元数据中存储文件的唯一标识
private static String FAST_DFS_KEY = "FastDfsKey"; private static String FAST_DFS_KEY = "FastDfsKey";
/** /**
* bucket name *
*/ */
private final String bucketName; private final String bucketName;
/** /**
* constructor with bucketName * FastDfsService
* FastDFS
* *
* @param bucketName bucket name * @param bucketName
*/ */
private FastDfsService(String bucketName) { private FastDfsService(String bucketName) {
this.bucketName = bucketName; this.bucketName = bucketName;
String configFilePath = null; 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 { 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); ClientGlobal.init(configFilePath);
// 读取配置文件
IniFileReader reader = new IniFileReader(configFilePath); IniFileReader reader = new IniFileReader(configFilePath);
// 设置基础 URL
setBaseUrl(reader.getStrValue(BASE_URL)); setBaseUrl(reader.getStrValue(BASE_URL));
// 设置 DMS 基础 URL
setDmsBaseUrl(reader.getStrValue(DMS_BASE_URL)); setDmsBaseUrl(reader.getStrValue(DMS_BASE_URL));
// 设置默认图片 URL
setDefaultPicUrl(reader.getStrValue(DEFAULT_PIC_URL)); setDefaultPicUrl(reader.getStrValue(DEFAULT_PIC_URL));
} catch (Exception e) { } catch (Exception e) {
// 处理初始化过程中出现的异常
handleException(e); handleException(e);
} }
} }
/** /**
* Get instance of FastDfsService, for Singleton * FastDfsService
* @param bucketName bucket name * 线
* @return instance of FastDfsService *
* @param bucketName
* @return FastDfsService
*/ */
public static synchronized FastDfsService getInstance(String bucketName) { public static synchronized FastDfsService getInstance(String bucketName) {
if (null == instance) { if (null == instance) {
@ -80,11 +99,11 @@ public class FastDfsService implements DfsService {
} }
/** /**
* Delete file on file system. *
* *
* @param remotePath remote file path * @param remotePath
* @param key Key, not used in FastDFS * @param key FastDFS 使
* @return true|false * @return true false
*/ */
@Override @Override
public boolean deleteObject(String remotePath, String key) { public boolean deleteObject(String remotePath, String key) {
@ -92,21 +111,28 @@ public class FastDfsService implements DfsService {
TrackerClient trackerClient = new TrackerClient(); TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = null; TrackerServer trackerServer = null;
try { try {
// 获取 Tracker 服务器连接
trackerServer = trackerClient.getConnection(); trackerServer = trackerClient.getConnection();
// 创建存储客户端
StorageClient storageClient = new StorageClient(trackerServer, null); StorageClient storageClient = new StorageClient(trackerServer, null);
// 调用 FastDFS API 删除文件
result = storageClient.delete_file(bucketName, remotePath); result = storageClient.delete_file(bucketName, remotePath);
} catch(Exception e) { } catch (Exception e) {
// 处理删除过程中出现的异常
handleException(e); handleException(e);
} finally { } finally {
if (null != trackerServer) { if (null != trackerServer) {
try { try {
// 关闭 Tracker 服务器连接
trackerServer.close(); trackerServer.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭连接时出现的异常
handleException(e); handleException(e);
} }
} }
} }
if (0 != result) { if (0 != result) {
// 删除失败,记录日志并返回 false
//logger.info("delete faild, the faild code is: " + result); //logger.info("delete faild, the faild code is: " + result);
return false; return false;
} }
@ -114,26 +140,33 @@ public class FastDfsService implements DfsService {
} }
/** /**
* Find the whole url * HTTP 访
* *
* @param remotePath remote path * @param remotePath
* @return the whole url * @return HTTP 访
*/ */
@Override @Override
public String getHttpPath(String remotePath) { public String getHttpPath(String remotePath) {
return baseUrl + "/" + bucketName + "/" + remotePath; return baseUrl + "/" + bucketName + "/" + remotePath;
} }
/**
* DMS HTTP 访
*
* @param dmsFilePath DMS
* @return DMS HTTP 访
*/
@Override @Override
public String getDmsHttpPath(String dmsFilePath) { public String getDmsHttpPath(String dmsFilePath) {
return dmsBaseUrl + dmsFilePath; return dmsBaseUrl + dmsFilePath;
} }
/** /**
* Get the file, and return DfsFile object *
* *
* @param remotePath remote path * @param remotePath
* @param key Key, not used in FastDFS, can be null * @param key FastDFS 使 null
* @return DfsFile object or null if fail * @return DfsFile null
*/ */
@Override @Override
public DfsFile getObject(String remotePath, String key) { public DfsFile getObject(String remotePath, String key) {
@ -141,59 +174,75 @@ public class FastDfsService implements DfsService {
TrackerServer trackerServer = null; TrackerServer trackerServer = null;
StorageServer storageServer = null; StorageServer storageServer = null;
try { try {
// 获取 Tracker 服务器连接
trackerServer = trackerClient.getConnection(); trackerServer = trackerClient.getConnection();
// 获取存储服务器
storageServer = trackerClient.getFetchStorage(trackerServer, bucketName, remotePath); storageServer = trackerClient.getFetchStorage(trackerServer, bucketName, remotePath);
// 创建存储客户端
StorageClient storageClient = new StorageClient(trackerServer, storageServer); StorageClient storageClient = new StorageClient(trackerServer, storageServer);
// 下载文件
byte[] bytes = storageClient.download_file(this.bucketName, remotePath); byte[] bytes = storageClient.download_file(this.bucketName, remotePath);
if (null != bytes) { if (null != bytes) {
// 获取文件的元数据
NameValuePair[] value_pairs = storageClient.get_metadata(bucketName, remotePath); NameValuePair[] value_pairs = storageClient.get_metadata(bucketName, remotePath);
Map<String, String> metadata = new HashMap<String, String>(); Map<String, String> metadata = new HashMap<String, String>();
for (int i = 0; i < value_pairs.length; i++) { for (int i = 0; i < value_pairs.length; i++) {
// 将元数据存储到 Map 中
metadata.put(value_pairs[i].getName(), value_pairs[i].getValue()); metadata.put(value_pairs[i].getName(), value_pairs[i].getValue());
} }
// 创建 DfsFile 对象
DfsFile dfsFile = new DfsFile(metadata.get(FAST_DFS_KEY), bytes, metadata); DfsFile dfsFile = new DfsFile(metadata.get(FAST_DFS_KEY), bytes, metadata);
return dfsFile; return dfsFile;
} }
} catch (Exception e){ } catch (Exception e) {
// 处理获取文件过程中出现的异常
handleException(e); handleException(e);
} finally { } finally {
if (null != storageServer) { if (null != storageServer) {
try { try {
// 关闭存储服务器连接
storageServer.close(); storageServer.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭连接时出现的异常
handleException(e); handleException(e);
} }
} }
if (null != trackerServer) { if (null != trackerServer) {
try { try {
// 关闭 Tracker 服务器连接
trackerServer.close(); trackerServer.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭连接时出现的异常
handleException(e); handleException(e);
} }
} }
} }
// 获取文件失败,记录日志并返回 null
//logger.info("Get object failed, get null object"); //logger.info("Get object failed, get null object");
return null; return null;
} }
/** /**
* Get the file list of file system. *
* Not implement at the moment, because FastDFS API not support. * FastDFS API
*
* @return null
*/ */
@Override @Override
public List<DfsFile> listObjects() { public List<DfsFile> listObjects() {
//to do // 待实现
//Because fastDFS api do not support list object method. // 因为 FastDFS API 不支持列出对象的方法
return null; return null;
} }
/** /**
* Upload the file to file system by file path *
* File putObject(File file, String key, Map<String, String> metadata)
* *
* @param filePath local file path. * @param filePath
* @param key Key, not used in FastDFS, can be null * @param key FastDFS 使 null
* @param metadata metadata for file, can be null * @param metadata null
* @return DfsFile object or null if fail * @return DfsPath null
*/ */
@Override @Override
public DfsPath putObject(String filePath, String key, Map<String, String> metadata) { public DfsPath putObject(String filePath, String key, Map<String, String> metadata) {
@ -202,13 +251,13 @@ public class FastDfsService implements DfsService {
} }
/** /**
* Upload the file to file system by bytes *
* *
* @param bytes bytes * @param bytes
* @param key Key, not used in FastDFS * @param key FastDFS 使
* @param metadata metadata for file, can be null * @param metadata null
* @param extName extName for file, can be null * @param extName null
* @return DfsPath object or null if fail * @return DfsPath null
*/ */
@Override @Override
public DfsPath putObject(byte[] bytes, String key, Map<String, String> metadata, String extName) { public DfsPath putObject(byte[] bytes, String key, Map<String, String> metadata, String extName) {
@ -216,147 +265,215 @@ public class FastDfsService implements DfsService {
TrackerServer trackerServer = null; TrackerServer trackerServer = null;
StorageServer storageServer = null; StorageServer storageServer = null;
try { try {
// 获取 Tracker 服务器连接
trackerServer = trackerClient.getConnection(); trackerServer = trackerClient.getConnection();
// 获取存储服务器列表
StorageServer[] storageServers = trackerClient.getStoreStorages(trackerServer, bucketName); StorageServer[] storageServers = trackerClient.getStoreStorages(trackerServer, bucketName);
if (null != storageServers) { if (null != storageServers) {
// 选择第一个存储服务器
storageServer = storageServers[0]; storageServer = storageServers[0];
// 创建存储客户端
StorageClient storageClient = new StorageClient(trackerServer, storageServer); StorageClient storageClient = new StorageClient(trackerServer, storageServer);
NameValuePair[] meta_list; NameValuePair[] meta_list;
int i = 0; int i = 0;
if (null == metadata) { if (null == metadata) {
// 若元数据为空,创建一个包含一个元素的元数据数组
meta_list = new NameValuePair[1]; meta_list = new NameValuePair[1];
} else { } else {
// 若元数据不为空,创建一个包含元数据和 FastDFS 键的数组
meta_list = new NameValuePair[metadata.size() + 1]; meta_list = new NameValuePair[metadata.size() + 1];
for (Map.Entry<String, String> entry : metadata.entrySet()) { for (Map.Entry<String, String> entry : metadata.entrySet()) {
meta_list[i++] = new NameValuePair(entry.getKey(), entry.getValue()); meta_list[i++] = new NameValuePair(entry.getKey(), entry.getValue());
} }
} }
// 添加 FastDFS 键到元数据数组
meta_list[i] = new NameValuePair(FAST_DFS_KEY, key); meta_list[i] = new NameValuePair(FAST_DFS_KEY, key);
// 调用 FastDFS API 上传文件
String[] results = storageClient.upload_file(bytes, extName, meta_list); String[] results = storageClient.upload_file(bytes, extName, meta_list);
if (null == results) { if (null == results) {
// 上传失败,记录日志并返回 null
//logger.info("upload file fail, error codes: " + storageClient.getErrorCode()); //logger.info("upload file fail, error codes: " + storageClient.getErrorCode());
return null; return null;
} else { } else {
// 获取远程文件名
String remote_fileName = results[1]; String remote_fileName = results[1];
// 构建文件的完整 HTTP 访问路径
String httpPath = this.getHttpPath(remote_fileName); String httpPath = this.getHttpPath(remote_fileName);
// 创建 DfsPath 对象
DfsPath dfsPath = new DfsPath(httpPath, remote_fileName); DfsPath dfsPath = new DfsPath(httpPath, remote_fileName);
return dfsPath; return dfsPath;
} }
} }
} catch (Exception e) { } catch (Exception e) {
// 处理上传过程中出现的异常
handleException(e); handleException(e);
} finally { } finally {
if (null != storageServer) { if (null != storageServer) {
try { try {
// 关闭存储服务器连接
storageServer.close(); storageServer.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭连接时出现的异常
handleException(e); handleException(e);
} }
} }
if (null != trackerServer) { if (null != trackerServer) {
try { try {
// 关闭 Tracker 服务器连接
trackerServer.close(); trackerServer.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭连接时出现的异常
handleException(e); handleException(e);
} }
} }
} }
// 上传失败,记录日志并返回 null
//logger.info("Upload file faild, because can not get storage servers!"); //logger.info("Upload file faild, because can not get storage servers!");
return null; return null;
} }
/** /**
* Upload the file to file system *
* putObject(byte[] bytes, String key, Map<String, String> metadata, String extName)
* *
* @param file file * @param file
* @param key Key, not used in FastDFS, can be null * @param key FastDFS 使 null
* @param metadata metadata for file , can be null * @param metadata null
* @return DfsPath object or null if fail * @return DfsPath null
*/ */
@Override @Override
public DfsPath putObject(File file, String key, Map<String, String> metadata) { public DfsPath putObject(File file, String key, Map<String, String> metadata) {
FileInputStream in = null; FileInputStream in = null;
byte[] file_buff = null; byte[] file_buff = null;
try { try {
// 打开文件输入流
in = new FileInputStream(file); in = new FileInputStream(file);
if (null != in) { if (null != in) {
// 获取文件长度
int len = in.available(); int len = in.available();
// 创建字节数组
file_buff = new byte[len]; file_buff = new byte[len];
// 读取文件内容到字节数组
in.read(file_buff); in.read(file_buff);
} }
} catch (Exception e) { } catch (Exception e) {
// 处理读取文件过程中出现的异常
handleException(e); handleException(e);
} finally { } finally {
if (null != in) { if (null != in) {
try { try {
// 关闭文件输入流
in.close(); in.close();
} catch (Exception e) { } catch (Exception e) {
// 处理关闭流时出现的异常
handleException(e); handleException(e);
} }
} }
} }
String file_ext_name = ""; String file_ext_name = "";
if (file.getName().lastIndexOf(".") > 0) { if (file.getName().lastIndexOf(".") > 0) {
// 获取文件扩展名
file_ext_name = file.getName().substring(file.getName().lastIndexOf(".") + 1); file_ext_name = file.getName().substring(file.getName().lastIndexOf(".") + 1);
} }
// 调用 putObject(byte[] bytes, String key, Map<String, String> metadata, String extName) 方法上传文件
return putObject(file_buff, key, metadata, file_ext_name); return putObject(file_buff, key, metadata, file_ext_name);
} }
/**
* URL
*
* @return URL
*/
public String getBaseUrl() { public String getBaseUrl() {
return baseUrl; return baseUrl;
} }
/**
* URL
*
* @param baseUrl URL
*/
private void setBaseUrl(String baseUrl) { private void setBaseUrl(String baseUrl) {
this.baseUrl = baseUrl; this.baseUrl = baseUrl;
} }
/**
* DMS URL
*
* @return DMS URL
*/
public String getDmsBaseUrl() { public String getDmsBaseUrl() {
return dmsBaseUrl; return dmsBaseUrl;
} }
/**
* DMS URL
*
* @param dmsBaseUrl DMS URL
*/
public void setDmsBaseUrl(String dmsBaseUrl) { public void setDmsBaseUrl(String dmsBaseUrl) {
this.dmsBaseUrl = dmsBaseUrl; this.dmsBaseUrl = dmsBaseUrl;
} }
/**
* URL
*
* @return URL
*/
public String getDefaultPicUrl() { public String getDefaultPicUrl() {
return defaultPicUrl; return defaultPicUrl;
} }
/**
* URL
*
* @param defaultPicUrl URL
*/
public void setDefaultPicUrl(String defaultPicUrl) { public void setDefaultPicUrl(String defaultPicUrl) {
this.defaultPicUrl = defaultPicUrl; this.defaultPicUrl = defaultPicUrl;
} }
/** /**
* Handle Exception *
* @param e exception * DfsException
*
* @param e
*/ */
private void handleException(Exception e) { private void handleException(Exception e) {
if (e instanceof IOException) { if (e instanceof IOException) {
// 处理 IOException抛出 DfsException错误码为 100
//logger.error("Exception occured : DFSException code: 100," + " exception message :" + e.getMessage()); //logger.error("Exception occured : DFSException code: 100," + " exception message :" + e.getMessage());
throw new DfsException("100", e.getMessage()); throw new DfsException("100", e.getMessage());
} else if (e instanceof FileNotFoundException) { } else if (e instanceof FileNotFoundException) {
// 处理 FileNotFoundException抛出 DfsException错误码为 200
//logger.error("Exception occured : DFSException code: 200," + " exception message : file not found." + e.getMessage()); //logger.error("Exception occured : DFSException code: 200," + " exception message : file not found." + e.getMessage());
throw new DfsException("200", e.getMessage()); throw new DfsException("200", e.getMessage());
} else if (e instanceof MyException) { } else if (e instanceof MyException) {
// 处理 MyException抛出 DfsException错误码为 300
//logger.error("Exception occured : DFSException code: 300," + " exception message :" + e.getMessage()); //logger.error("Exception occured : DFSException code: 300," + " exception message :" + e.getMessage());
throw new DfsException("300", e.getMessage()); throw new DfsException("300", e.getMessage());
} else if (e instanceof Exception) { } else if (e instanceof Exception) {
// 处理其他异常,抛出 DfsException错误码为 400
//logger.error("Exception occured : DFSException code: 400," + " exception message :" + e.getMessage()); //logger.error("Exception occured : DFSException code: 400," + " exception message :" + e.getMessage());
throw new DfsException("400", e.getMessage()); throw new DfsException("400", e.getMessage());
} }
} }
@Override /**
public String getDefaultPath(String type) { *
if("PICTURE".equalsIgnoreCase(type)) { * "PICTURE" URL URL
return defaultPicUrl; *
} * @param type
return defaultPicUrl; * @return
} */
@Override
public String getDefaultPath(String type) {
if ("PICTURE".equalsIgnoreCase(type)) {
return defaultPicUrl;
} }
return defaultPicUrl;
}
}

@ -1,130 +1,203 @@
// 声明该类所在的包,此包为资源控制器相关的包
package com.xmomen.module.resource.controller; package com.xmomen.module.resource.controller;
// 导入自定义框架中的业务异常类,用于处理业务逻辑中出现的异常
import com.xmomen.framework.exception.BusinessException; import com.xmomen.framework.exception.BusinessException;
// 导入自定义框架中 MyBatis 分页相关的 Page 类,用于处理分页查询结果
import com.xmomen.framework.mybatis.page.Page; import com.xmomen.framework.mybatis.page.Page;
// 导入自定义模块中的日志注解,用于记录操作日志
import com.xmomen.module.logger.Log; import com.xmomen.module.logger.Log;
// 导入资源查询模型类,用于封装资源查询的条件
import com.xmomen.module.resource.model.ResourceQuery; import com.xmomen.module.resource.model.ResourceQuery;
// 导入资源数据模型类,用于封装资源的相关数据
import com.xmomen.module.resource.model.ResourceModel; import com.xmomen.module.resource.model.ResourceModel;
// 导入资源服务类,该类包含资源相关的业务逻辑
import com.xmomen.module.resource.service.ResourceService; import com.xmomen.module.resource.service.ResourceService;
// 导入 Apache Commons IO 工具类,用于处理输入输出流
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
// 导入 Jeecg 框架中 Excel 导入工具类,用于从 Excel 文件中导入数据
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
// 导入 Jeecg 框架中 Excel 导出参数类,用于配置 Excel 导出的参数
import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.entity.ExportParams;
// 导入 Jeecg 框架中 Excel 导入参数类,用于配置 Excel 导入的参数
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
// 导入 Jeecg 框架中 Excel 导入结果类,用于封装 Excel 导入的结果
import org.jeecgframework.poi.excel.entity.result.ExcelImportResult; import org.jeecgframework.poi.excel.entity.result.ExcelImportResult;
// 导入 Jeecg 框架中普通 Excel 常量类,包含一些 Excel 操作的常量
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;
// 导入 Jeecg 框架中 Excel 导入异常类,用于处理 Excel 导入过程中出现的异常
import org.jeecgframework.poi.exception.excel.ExcelImportException; import org.jeecgframework.poi.exception.excel.ExcelImportException;
// 导入 Spring 框架中的自动装配注解,用于自动注入依赖的 Bean
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
// 导入 Spring 框架中的模型映射类,用于在控制器和视图之间传递数据
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
// 导入 Spring 框架中的数据绑定结果类,用于处理数据绑定过程中的错误信息
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
// 导入 Spring 框架中的请求映射相关注解,用于处理 HTTP 请求
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
// 导入 Spring 框架中用于处理多部分文件上传的类
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
// 导入 Spring 框架中的模型和视图类,用于返回包含模型数据和视图名称的对象
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
// 导入 JSR-303 验证框架中的有效注解,用于对请求参数进行验证
import javax.validation.Valid; import javax.validation.Valid;
// 导入 Java 序列化接口,用于支持对象的序列化和反序列化
import java.io.Serializable; import java.io.Serializable;
// 导入 Java 输入输出异常类,用于处理输入输出操作中出现的异常
import java.io.IOException; import java.io.IOException;
// 导入 Java 输入流类,用于读取数据
import java.io.InputStream; import java.io.InputStream;
// 导入 Java 列表接口,用于存储多个元素
import java.util.List; import java.util.List;
/** /**
* HTTP
*
* @author tanxinzheng * @author tanxinzheng
* @version 1.0.0 * @version 1.0.0
* @date 2017-4-10 23:26:20 * @date 2017-4-10 23:26:20
*/ */
// 标记该类为 RESTful 风格的控制器,会自动将方法返回值转换为 JSON 格式
@RestController @RestController
// 定义该控制器处理的请求路径前缀为 /resource
@RequestMapping(value = "/resource") @RequestMapping(value = "/resource")
public class ResourceController { public class ResourceController {
// 使用自动装配注解将 ResourceService 注入到当前类中,用于调用资源相关的业务逻辑
@Autowired @Autowired
ResourceService resourceService; ResourceService resourceService;
/** /**
* *
* *
* @param limit * @param limit
* @param offset * @param offset
* @param id * @param id
* @param ids * @param entityType
* @param excludeIds * @param entityId ID
* @return Page<ResourceModel> * @param ids
* @param excludeIds
* @return
*/ */
// 映射 HTTP GET 请求到该方法
@RequestMapping(method = RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
// 使用日志注解记录该操作的名称为查询资源目录列表
@Log(actionName = "查询资源目录列表") @Log(actionName = "查询资源目录列表")
public Page<ResourceModel> getResourceList(@RequestParam(value = "limit") Integer limit, public Page<ResourceModel> getResourceList(
@RequestParam(value = "offset") Integer offset, // 从请求参数中获取每页结果数
@RequestParam(value = "id", required = false) String id, @RequestParam(value = "limit") Integer limit,
@RequestParam(value = "entityType", required = false) String entityType, // 从请求参数中获取页码
@RequestParam(value = "entityId", required = false) String entityId, @RequestParam(value = "offset") Integer offset,
@RequestParam(value = "ids", required = false) String[] ids, // 从请求参数中获取资源主键,该参数可选
@RequestParam(value = "excludeIds", required = false) String[] excludeIds) { @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 resourceQuery = new ResourceQuery();
// 设置查询条件:资源主键
resourceQuery.setId(id); resourceQuery.setId(id);
// 设置查询条件:不包含的资源主键数组
resourceQuery.setExcludeIds(excludeIds); resourceQuery.setExcludeIds(excludeIds);
// 设置查询条件:资源主键数组
resourceQuery.setIds(ids); resourceQuery.setIds(ids);
// 设置查询条件:资源所属的实体类型
resourceQuery.setEntityType(entityType); resourceQuery.setEntityType(entityType);
// 设置查询条件:资源所属的实体 ID
resourceQuery.setEntityId(entityId); resourceQuery.setEntityId(entityId);
// 调用资源服务的方法,根据分页信息和查询条件获取资源目录分页数据
return resourceService.getResourceModelPage(limit, offset, resourceQuery); return resourceService.getResourceModelPage(limit, offset, resourceQuery);
} }
/** /**
* *
* *
* @param id * @param id
* @return ResourceModel * @return
*/ */
// 映射形如 /resource/{id} 的 HTTP GET 请求到该方法
@RequestMapping(value = "/{id}", method = RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
// 使用日志注解记录该操作的名称为查询资源目录
@Log(actionName = "查询资源目录") @Log(actionName = "查询资源目录")
public ResourceModel getResourceById(@PathVariable(value = "id") String id) { public ResourceModel getResourceById(
// 从路径中获取资源主键
@PathVariable(value = "id") String id) {
// 调用资源服务的方法,根据主键获取单个资源目录的数据
return resourceService.getOneResourceModel(id); return resourceService.getOneResourceModel(id);
} }
/** /**
* *
* *
* @param resourceModel * @param resourceModel
* @return ResourceModel * @return
*/ */
// 映射 HTTP POST 请求到该方法
@RequestMapping(method = RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
// 使用日志注解记录该操作的名称为新增资源目录
@Log(actionName = "新增资源目录") @Log(actionName = "新增资源目录")
public ResourceModel createResource(@RequestBody @Valid ResourceModel resourceModel) { public ResourceModel createResource(
// 从请求体中获取新增资源目录的数据,并进行数据验证
@RequestBody @Valid ResourceModel resourceModel) {
// 调用资源服务的方法,创建新的资源目录
return resourceService.createResource(resourceModel); return resourceService.createResource(resourceModel);
} }
/** /**
* *
* *
* @param id * @param id
* @param resourceModel * @param resourceModel
*/ */
// 映射形如 /resource/{id} 的 HTTP PUT 请求到该方法
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
// 使用日志注解记录该操作的名称为更新资源目录
@Log(actionName = "更新资源目录") @Log(actionName = "更新资源目录")
public void updateResource(@PathVariable(value = "id") String id, public void updateResource(
@RequestBody @Valid ResourceModel resourceModel) { // 从路径中获取要更新的资源主键
@PathVariable(value = "id") String id,
// 从请求体中获取更新后的资源目录数据,并进行数据验证
@RequestBody @Valid ResourceModel resourceModel) {
// 调用资源服务的方法,更新资源目录信息
resourceService.updateResource(resourceModel); resourceService.updateResource(resourceModel);
} }
/** /**
* *
* *
* @param id * @param id
*/ */
// 映射形如 /resource/{id} 的 HTTP DELETE 请求到该方法
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
// 使用日志注解记录该操作的名称为删除单个资源目录
@Log(actionName = "删除单个资源目录") @Log(actionName = "删除单个资源目录")
public void deleteResource(@PathVariable(value = "id") String id) { public void deleteResource(
// 从路径中获取要删除的资源主键
@PathVariable(value = "id") String id) {
// 调用资源服务的方法,删除指定主键的资源目录
resourceService.deleteResource(id); resourceService.deleteResource(id);
} }
/** /**
* *
* *
* @param ids * @param ids
*/ */
// 映射 HTTP DELETE 请求到该方法
@RequestMapping(method = RequestMethod.DELETE) @RequestMapping(method = RequestMethod.DELETE)
// 使用日志注解记录该操作的名称为批量删除资源目录
@Log(actionName = "批量删除资源目录") @Log(actionName = "批量删除资源目录")
public void deleteResources(@RequestParam(value = "ids") String[] ids) { public void deleteResources(
// 从请求参数中获取要删除的资源主键数组
@RequestParam(value = "ids") String[] ids) {
// 调用资源服务的方法,批量删除指定主键的资源目录
resourceService.deleteResource(ids); resourceService.deleteResource(ids);
} }
}
}

@ -1,4 +1,4 @@
package com.xmomen.module.resource.entity; Xpackage com.xmomen.module.resource.entity;
import com.xmomen.framework.mybatis.model.BaseMybatisModel; import com.xmomen.framework.mybatis.model.BaseMybatisModel;
import javax.persistence.Column; import javax.persistence.Column;

@ -1,7 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.xmomen.module.resource.entity.mapper.ResourceMapper" > <?xml version="1.0" encoding="UTF-8"?>
<resultMap id="BaseResultMap" type="com.xmomen.module.resource.entity.Resource" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xmomen.module.resource.entity.mapper.ResourceMapper">
<!--
定义结果映射,将数据库查询结果映射到 Java 对象。
id: 结果映射的唯一标识。
type: 要映射的 Java 实体类的全限定名。
-->
<resultMap id="BaseResultMap" type="com.xmomen.module.resource.entity.Resource">
<!-- 映射数据库表中的主键列到实体类的属性 -->
<id column="ID" property="id" jdbcType="VARCHAR" /> <id column="ID" property="id" jdbcType="VARCHAR" />
<result column="ENTITY_TYPE" property="entityType" jdbcType="VARCHAR" /> <result column="ENTITY_TYPE" property="entityType" jdbcType="VARCHAR" />
<result column="ENTITY_ID" property="entityId" jdbcType="VARCHAR" /> <result column="ENTITY_ID" property="entityId" jdbcType="VARCHAR" />
@ -9,25 +17,37 @@
<result column="RESOURCE_TYPE" property="resourceType" jdbcType="VARCHAR" /> <result column="RESOURCE_TYPE" property="resourceType" jdbcType="VARCHAR" />
<result column="IS_DEFAULT" property="isDefault" jdbcType="INTEGER" /> <result column="IS_DEFAULT" property="isDefault" jdbcType="INTEGER" />
</resultMap> </resultMap>
<sql id="Example_Where_Clause" >
<where > <!--
<foreach collection="oredCriteria" item="criteria" separator="or" > 定义 SQL 片段,用于生成 WHERE 子句。
<if test="criteria.valid" > 此片段根据传入的查询条件动态生成 WHERE 子句,支持多种条件类型(无值、单值、范围值、列表值)。
<trim prefix="(" suffix=")" prefixOverrides="and" > -->
<foreach collection="criteria.criteria" item="criterion" > <sql id="Example_Where_Clause">
<choose > <where>
<when test="criterion.noValue" > <!-- 遍历所有的查询条件组 -->
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<!-- 去除开头多余的 "and" -->
<trim prefix="(" suffix=")" prefixOverrides="and">
<!-- 遍历每个查询条件组中的具体条件 -->
<foreach collection="criteria.criteria" item="criterion">
<choose>
<!-- 处理无值条件 -->
<when test="criterion.noValue">
and ${criterion.condition} and ${criterion.condition}
</when> </when>
<when test="criterion.singleValue" > <!-- 处理单值条件 -->
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.betweenValue" > <!-- 处理范围值条件 -->
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.listValue" > <!-- 处理列表值条件 -->
<when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > <foreach collection="criterion.value" item="listItem" open="(" close=")" separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -38,25 +58,30 @@
</foreach> </foreach>
</where> </where>
</sql> </sql>
<sql id="Update_By_Example_Where_Clause" >
<where > <!--
<foreach collection="example.oredCriteria" item="criteria" separator="or" > 定义 SQL 片段,用于生成 UPDATE 语句的 WHERE 子句。
<if test="criteria.valid" > 逻辑与 Example_Where_Clause 类似,用于根据条件更新数据。
<trim prefix="(" suffix=")" prefixOverrides="and" > -->
<foreach collection="criteria.criteria" item="criterion" > <sql id="Update_By_Example_Where_Clause">
<choose > <where>
<when test="criterion.noValue" > <foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" suffix=")" prefixOverrides="and">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition} and ${criterion.condition}
</when> </when>
<when test="criterion.singleValue" > <when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value} and ${criterion.condition} #{criterion.value}
</when> </when>
<when test="criterion.betweenValue" > <when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when> </when>
<when test="criterion.listValue" > <when test="criterion.listValue">
and ${criterion.condition} and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," > <foreach collection="criterion.value" item="listItem" open="(" close=")" separator=",">
#{listItem} #{listItem}
</foreach> </foreach>
</when> </when>
@ -67,100 +92,148 @@
</foreach> </foreach>
</where> </where>
</sql> </sql>
<sql id="Base_Column_List" >
<!-- 定义 SQL 片段,列出表中的基本列名 -->
<sql id="Base_Column_List">
ID, ENTITY_TYPE, ENTITY_ID, PATH, RESOURCE_TYPE, IS_DEFAULT ID, ENTITY_TYPE, ENTITY_ID, PATH, RESOURCE_TYPE, IS_DEFAULT
</sql> </sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.xmomen.module.resource.entity.ResourceExample" >
<!--
定义查询语句,根据条件查询资源数据。
id: 语句的唯一标识。
resultMap: 引用前面定义的结果映射,用于将查询结果映射到实体类。
parameterType: 传入的参数类型,这里是查询条件对象。
-->
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.xmomen.module.resource.entity.ResourceExample">
select select
<if test="distinct" > <!-- 如果需要去重,添加 distinct 关键字 -->
<if test="distinct">
distinct distinct
</if> </if>
<!-- 引入基本列名片段 -->
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from cd_resource from cd_resource
<if test="_parameter != null" > <!-- 如果传入了查询参数,引入 WHERE 子句片段 -->
<if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
<if test="orderByClause != null" > <!-- 如果有排序条件,添加排序子句 -->
<if test="orderByClause != null">
order by ${orderByClause} order by ${orderByClause}
</if> </if>
</select> </select>
<delete id="deleteByExample" parameterType="com.xmomen.module.resource.entity.ResourceExample" >
<!--
定义删除语句,根据条件删除资源数据。
id: 语句的唯一标识。
parameterType: 传入的参数类型,这里是查询条件对象。
-->
<delete id="deleteByExample" parameterType="com.xmomen.module.resource.entity.ResourceExample">
delete from cd_resource delete from cd_resource
<if test="_parameter != null" > <!-- 如果传入了查询参数,引入 WHERE 子句片段 -->
<if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</delete> </delete>
<insert id="insertSelective" parameterType="com.xmomen.module.resource.entity.Resource" useGeneratedKeys="true" keyProperty="id" keyColumn="ID" >
<selectKey resultType="java.lang.String" keyProperty="id" order="BEFORE" > <!--
定义插入语句,选择性插入资源数据(只插入非空字段)。
id: 语句的唯一标识。
parameterType: 传入的参数类型,这里是要插入的实体类对象。
useGeneratedKeys: 是否使用数据库生成的主键。
keyProperty: 实体类中表示主键的属性名。
keyColumn: 数据库表中主键列的名称。
-->
<insert id="insertSelective" parameterType="com.xmomen.module.resource.entity.Resource" useGeneratedKeys="true" keyProperty="id" keyColumn="ID">
<!-- 在插入前生成主键值,这里使用 UUID 并去除连字符 -->
<selectKey resultType="java.lang.String" keyProperty="id" order="BEFORE">
SELECT replace(UUID(),'-','') SELECT replace(UUID(),'-','')
</selectKey> </selectKey>
insert into cd_resource insert into cd_resource
<trim prefix="(" suffix=")" suffixOverrides="," > <!-- 动态生成插入的列名,只包含非空字段 -->
<trim prefix="(" suffix=")" suffixOverrides=",">
ID, ID,
<if test="entityType != null" > <if test="entityType != null">
ENTITY_TYPE, ENTITY_TYPE,
</if> </if>
<if test="entityId != null" > <if test="entityId != null">
ENTITY_ID, ENTITY_ID,
</if> </if>
<if test="path != null" > <if test="path != null">
PATH, PATH,
</if> </if>
<if test="resourceType != null" > <if test="resourceType != null">
RESOURCE_TYPE, RESOURCE_TYPE,
</if> </if>
<if test="isDefault != null" > <if test="isDefault != null">
IS_DEFAULT, IS_DEFAULT,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides="," > <!-- 动态生成插入的值,只包含非空字段 -->
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{id,jdbcType=VARCHAR}, #{id,jdbcType=VARCHAR},
<if test="entityType != null" > <if test="entityType != null">
#{entityType,jdbcType=VARCHAR}, #{entityType,jdbcType=VARCHAR},
</if> </if>
<if test="entityId != null" > <if test="entityId != null">
#{entityId,jdbcType=VARCHAR}, #{entityId,jdbcType=VARCHAR},
</if> </if>
<if test="path != null" > <if test="path != null">
#{path,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR},
</if> </if>
<if test="resourceType != null" > <if test="resourceType != null">
#{resourceType,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR},
</if> </if>
<if test="isDefault != null" > <if test="isDefault != null">
#{isDefault,jdbcType=INTEGER}, #{isDefault,jdbcType=INTEGER},
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.xmomen.module.resource.entity.ResourceExample" resultType="java.lang.Integer" >
<!--
定义统计语句,根据条件统计资源数据的数量。
id: 语句的唯一标识。
parameterType: 传入的参数类型,这里是查询条件对象。
resultType: 返回的结果类型,这里是整数类型。
-->
<select id="countByExample" parameterType="com.xmomen.module.resource.entity.ResourceExample" resultType="java.lang.Integer">
select count(*) from cd_resource select count(*) from cd_resource
<if test="_parameter != null" > <!-- 如果传入了查询参数,引入 WHERE 子句片段 -->
<if test="_parameter != null">
<include refid="Example_Where_Clause" /> <include refid="Example_Where_Clause" />
</if> </if>
</select> </select>
<update id="updateByExampleSelective" parameterType="map" >
<!--
定义更新语句,根据条件选择性更新资源数据(只更新非空字段)。
id: 语句的唯一标识。
parameterType: 传入的参数类型,这里是一个包含实体类对象和查询条件的 Map。
-->
<update id="updateByExampleSelective" parameterType="map">
update cd_resource update cd_resource
<set > <!-- 动态生成 SET 子句,只包含非空字段 -->
<if test="record.id != null" > <set>
<if test="record.id != null">
ID = #{record.id,jdbcType=VARCHAR}, ID = #{record.id,jdbcType=VARCHAR},
</if> </if>
<if test="record.entityType != null" > <if test="record.entityType != null">
ENTITY_TYPE = #{record.entityType,jdbcType=VARCHAR}, ENTITY_TYPE = #{record.entityType,jdbcType=VARCHAR},
</if> </if>
<if test="record.entityId != null" > <if test="record.entityId != null">
ENTITY_ID = #{record.entityId,jdbcType=VARCHAR}, ENTITY_ID = #{record.entityId,jdbcType=VARCHAR},
</if> </if>
<if test="record.path != null" > <if test="record.path != null">
PATH = #{record.path,jdbcType=VARCHAR}, PATH = #{record.path,jdbcType=VARCHAR},
</if> </if>
<if test="record.resourceType != null" > <if test="record.resourceType != null">
RESOURCE_TYPE = #{record.resourceType,jdbcType=VARCHAR}, RESOURCE_TYPE = #{record.resourceType,jdbcType=VARCHAR},
</if> </if>
<if test="record.isDefault != null" > <if test="record.isDefault != null">
IS_DEFAULT = #{record.isDefault,jdbcType=INTEGER}, IS_DEFAULT = #{record.isDefault,jdbcType=INTEGER},
</if> </if>
</set> </set>
<if test="_parameter != null" > <!-- 如果传入了查询参数,引入 UPDATE 的 WHERE 子句片段 -->
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>

Loading…
Cancel
Save