From 73110d1170a1b0907cb8c5e50fdefcd6db85262c Mon Sep 17 00:00:00 2001
From: jishenghua <752718920@qq.com>
Date: Sat, 22 Feb 2025 15:33:29 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=A7=9F=E6=88=B7=E7=9A=84?=
=?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=88=86=E9=A1=B5=E6=96=B9=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
jshERP-boot/pom.xml | 5 +
.../java/com/jsh/erp/base/AjaxResult.java | 228 ++++++++
.../java/com/jsh/erp/base/BaseController.java | 158 ++++++
.../java/com/jsh/erp/base/PageDomain.java | 87 +++
.../java/com/jsh/erp/base/TableDataInfo.java | 70 +++
.../java/com/jsh/erp/base/TableSupport.java | 56 ++
.../jsh/erp/controller/TenantController.java | 28 +-
.../datasource/mappers/TenantMapperEx.java | 3 +-
.../com/jsh/erp/exception/UtilException.java | 26 +
.../jsh/erp/service/tenant/TenantService.java | 16 +-
.../main/java/com/jsh/erp/utils/Convert.java | 536 ++++++++++++++++++
.../java/com/jsh/erp/utils/PageUtils.java | 34 ++
.../java/com/jsh/erp/utils/ServletUtils.java | 123 ++++
.../main/java/com/jsh/erp/utils/SqlUtil.java | 50 ++
.../java/com/jsh/erp/utils/StringUtil.java | 75 +++
15 files changed, 1465 insertions(+), 30 deletions(-)
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/base/AjaxResult.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/base/BaseController.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/base/PageDomain.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/base/TableDataInfo.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/base/TableSupport.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/exception/UtilException.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/utils/Convert.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/utils/PageUtils.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/utils/ServletUtils.java
create mode 100644 jshERP-boot/src/main/java/com/jsh/erp/utils/SqlUtil.java
diff --git a/jshERP-boot/pom.xml b/jshERP-boot/pom.xml
index 61ce851e5..68cdf4ea1 100644
--- a/jshERP-boot/pom.xml
+++ b/jshERP-boot/pom.xml
@@ -123,6 +123,11 @@
pinyin4j
2.5.1
+
+ com.github.pagehelper
+ pagehelper-spring-boot-starter
+ 1.2.13
+
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/base/AjaxResult.java b/jshERP-boot/src/main/java/com/jsh/erp/base/AjaxResult.java
new file mode 100644
index 000000000..491ad943c
--- /dev/null
+++ b/jshERP-boot/src/main/java/com/jsh/erp/base/AjaxResult.java
@@ -0,0 +1,228 @@
+package com.jsh.erp.base;
+
+import com.jsh.erp.utils.StringUtil;
+
+import java.util.HashMap;
+import java.util.Objects;
+
+/**
+ * 操作消息提醒
+ *
+ * @author ji-sheng-hua
+ */
+public class AjaxResult extends HashMap
+{
+ private static final long serialVersionUID = 1L;
+
+ /** 状态码 */
+ public static final String CODE_TAG = "code";
+
+ /** 返回内容 */
+ public static final String MSG_TAG = "msg";
+
+ /** 数据对象 */
+ public static final String DATA_TAG = "data";
+
+ /**
+ * 状态类型
+ */
+ public enum Type
+ {
+ /** 成功 */
+ SUCCESS(0),
+ /** 警告 */
+ WARN(301),
+ /** 错误 */
+ ERROR(500);
+ private final int value;
+
+ Type(int value)
+ {
+ this.value = value;
+ }
+
+ public int value()
+ {
+ return this.value;
+ }
+ }
+
+ /**
+ * 初始化一个新创建的 AjaxResult 对象,使其表示一个空消息。
+ */
+ public AjaxResult()
+ {
+ }
+
+ /**
+ * 初始化一个新创建的 AjaxResult 对象
+ *
+ * @param type 状态类型
+ * @param msg 返回内容
+ */
+ public AjaxResult(Type type, String msg)
+ {
+ super.put(CODE_TAG, type.value);
+ super.put(MSG_TAG, msg);
+ }
+
+ /**
+ * 初始化一个新创建的 AjaxResult 对象
+ *
+ * @param type 状态类型
+ * @param msg 返回内容
+ * @param data 数据对象
+ */
+ public AjaxResult(Type type, String msg, Object data)
+ {
+ super.put(CODE_TAG, type.value);
+ super.put(MSG_TAG, msg);
+ if (StringUtil.isNotNull(data))
+ {
+ super.put(DATA_TAG, data);
+ }
+ }
+
+ /**
+ * 返回成功消息
+ *
+ * @return 成功消息
+ */
+ public static AjaxResult success()
+ {
+ return AjaxResult.success("操作成功");
+ }
+
+ /**
+ * 返回成功数据
+ *
+ * @return 成功消息
+ */
+ public static AjaxResult success(Object data)
+ {
+ return AjaxResult.success("操作成功", data);
+ }
+
+ /**
+ * 返回成功消息
+ *
+ * @param msg 返回内容
+ * @return 成功消息
+ */
+ public static AjaxResult success(String msg)
+ {
+ return AjaxResult.success(msg, null);
+ }
+
+ /**
+ * 返回成功消息
+ *
+ * @param msg 返回内容
+ * @param data 数据对象
+ * @return 成功消息
+ */
+ public static AjaxResult success(String msg, Object data)
+ {
+ return new AjaxResult(Type.SUCCESS, msg, data);
+ }
+
+ /**
+ * 返回警告消息
+ *
+ * @param msg 返回内容
+ * @return 警告消息
+ */
+ public static AjaxResult warn(String msg)
+ {
+ return AjaxResult.warn(msg, null);
+ }
+
+ /**
+ * 返回警告消息
+ *
+ * @param msg 返回内容
+ * @param data 数据对象
+ * @return 警告消息
+ */
+ public static AjaxResult warn(String msg, Object data)
+ {
+ return new AjaxResult(Type.WARN, msg, data);
+ }
+
+ /**
+ * 返回错误消息
+ *
+ * @return
+ */
+ public static AjaxResult error()
+ {
+ return AjaxResult.error("操作失败");
+ }
+
+ /**
+ * 返回错误消息
+ *
+ * @param msg 返回内容
+ * @return 警告消息
+ */
+ public static AjaxResult error(String msg)
+ {
+ return AjaxResult.error(msg, null);
+ }
+
+ /**
+ * 返回错误消息
+ *
+ * @param msg 返回内容
+ * @param data 数据对象
+ * @return 警告消息
+ */
+ public static AjaxResult error(String msg, Object data)
+ {
+ return new AjaxResult(Type.ERROR, msg, data);
+ }
+
+ /**
+ * 是否为成功消息
+ *
+ * @return 结果
+ */
+ public boolean isSuccess()
+ {
+ return Objects.equals(Type.SUCCESS.value, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为警告消息
+ *
+ * @return 结果
+ */
+ public boolean isWarn()
+ {
+ return Objects.equals(Type.WARN.value, this.get(CODE_TAG));
+ }
+
+ /**
+ * 是否为错误消息
+ *
+ * @return 结果
+ */
+ public boolean isError()
+ {
+ return Objects.equals(Type.ERROR.value, this.get(CODE_TAG));
+ }
+
+ /**
+ * 方便链式调用
+ *
+ * @param key 键
+ * @param value 值
+ * @return 数据对象
+ */
+ @Override
+ public AjaxResult put(String key, Object value)
+ {
+ super.put(key, value);
+ return this;
+ }
+}
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/base/BaseController.java b/jshERP-boot/src/main/java/com/jsh/erp/base/BaseController.java
new file mode 100644
index 000000000..bf9f01ce3
--- /dev/null
+++ b/jshERP-boot/src/main/java/com/jsh/erp/base/BaseController.java
@@ -0,0 +1,158 @@
+package com.jsh.erp.base;
+
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.jsh.erp.utils.PageUtils;
+import com.jsh.erp.utils.ServletUtils;
+import com.jsh.erp.utils.SqlUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * web层通用数据处理
+ *
+ * @author ji-sheng-hua
+ */
+public class BaseController
+{
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
+
+ /**
+ * 设置请求分页数据
+ */
+ protected void startPage()
+ {
+ PageUtils.startPage();
+ }
+
+ /**
+ * 设置请求排序数据
+ */
+ protected void startOrderBy()
+ {
+ PageDomain pageDomain = TableSupport.buildPageRequest();
+ if (StringUtils.isNotEmpty(pageDomain.getOrderBy()))
+ {
+ String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
+ PageHelper.orderBy(orderBy);
+ }
+ }
+
+ /**
+ * 清理分页的线程变量
+ */
+ protected void clearPage()
+ {
+ PageUtils.clearPage();
+ }
+
+ /**
+ * 获取request
+ */
+ public HttpServletRequest getRequest()
+ {
+ return ServletUtils.getRequest();
+ }
+
+ /**
+ * 获取response
+ */
+ public HttpServletResponse getResponse()
+ {
+ return ServletUtils.getResponse();
+ }
+
+ /**
+ * 获取session
+ */
+ public HttpSession getSession()
+ {
+ return getRequest().getSession();
+ }
+
+ /**
+ * 响应请求分页数据
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected TableDataInfo getDataTable(List> list)
+ {
+ Map data = new HashMap<>();
+ TableDataInfo rspData = new TableDataInfo();
+ rspData.setCode(200);
+ data.put("rows", list);
+ data.put("total", new PageInfo(list).getTotal());
+ rspData.setData(data);
+ return rspData;
+ }
+
+ /**
+ * 响应返回结果
+ *
+ * @param rows 影响行数
+ * @return 操作结果
+ */
+ protected AjaxResult toAjax(int rows)
+ {
+ return rows > 0 ? success() : error();
+ }
+
+ /**
+ * 响应返回结果
+ *
+ * @param result 结果
+ * @return 操作结果
+ */
+ protected AjaxResult toAjax(boolean result)
+ {
+ return result ? success() : error();
+ }
+
+ /**
+ * 返回成功
+ */
+ public AjaxResult success()
+ {
+ return AjaxResult.success();
+ }
+
+ /**
+ * 返回失败消息
+ */
+ public AjaxResult error()
+ {
+ return AjaxResult.error();
+ }
+
+ /**
+ * 返回成功消息
+ */
+ public AjaxResult success(String message)
+ {
+ return AjaxResult.success(message);
+ }
+
+ /**
+ * 返回成功数据
+ */
+ public static AjaxResult success(Object data)
+ {
+ return AjaxResult.success("操作成功", data);
+ }
+
+ /**
+ * 返回失败消息
+ */
+ public AjaxResult error(String message)
+ {
+ return AjaxResult.error(message);
+ }
+
+}
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/base/PageDomain.java b/jshERP-boot/src/main/java/com/jsh/erp/base/PageDomain.java
new file mode 100644
index 000000000..5c8de689f
--- /dev/null
+++ b/jshERP-boot/src/main/java/com/jsh/erp/base/PageDomain.java
@@ -0,0 +1,87 @@
+package com.jsh.erp.base;
+
+import com.jsh.erp.utils.StringUtil;
+
+/**
+ * 分页数据
+ *
+ * @author ji-sheng-hua
+ */
+public class PageDomain
+{
+ /** 当前记录起始索引 */
+ private Integer currentPage;
+
+ /** 每页显示记录数 */
+ private Integer pageSize;
+
+ /** 排序列 */
+ private String orderByColumn;
+
+ /** 排序的方向desc或者asc */
+ private String isAsc = "asc";
+
+ /** 分页参数合理化 */
+ private Boolean reasonable = true;
+
+ public String getOrderBy()
+ {
+ if (StringUtil.isEmpty(orderByColumn))
+ {
+ return "";
+ }
+ return StringUtil.toUnderScoreCase(orderByColumn) + " " + isAsc;
+ }
+
+ public Integer getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(Integer currentPage) {
+ this.currentPage = currentPage;
+ }
+
+ public Integer getPageSize()
+ {
+ return pageSize;
+ }
+
+ public void setPageSize(Integer pageSize)
+ {
+ this.pageSize = pageSize;
+ }
+
+ public String getOrderByColumn()
+ {
+ return orderByColumn;
+ }
+
+ public void setOrderByColumn(String orderByColumn)
+ {
+ this.orderByColumn = orderByColumn;
+ }
+
+ public String getIsAsc()
+ {
+ return isAsc;
+ }
+
+ public void setIsAsc(String isAsc)
+ {
+ this.isAsc = isAsc;
+ }
+
+ public Boolean getReasonable()
+ {
+ if (StringUtil.isNull(reasonable))
+ {
+ return Boolean.TRUE;
+ }
+ return reasonable;
+ }
+
+ public void setReasonable(Boolean reasonable)
+ {
+ this.reasonable = reasonable;
+ }
+}
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/base/TableDataInfo.java b/jshERP-boot/src/main/java/com/jsh/erp/base/TableDataInfo.java
new file mode 100644
index 000000000..54de48cbe
--- /dev/null
+++ b/jshERP-boot/src/main/java/com/jsh/erp/base/TableDataInfo.java
@@ -0,0 +1,70 @@
+package com.jsh.erp.base;
+
+import java.io.Serializable;
+
+/**
+ * 表格分页数据对象
+ *
+ * @author ji-sheng-hua
+ */
+public class TableDataInfo implements Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ /** 总记录数 */
+ private long total;
+
+ /** 消息状态码 */
+ private int code;
+
+ /** 消息状态码 */
+ private Object data;
+
+ /** 消息内容 */
+ private String msg;
+
+ /**
+ * 表格数据对象
+ */
+ public TableDataInfo()
+ {
+ }
+
+ public long getTotal()
+ {
+ return total;
+ }
+
+ public void setTotal(long total)
+ {
+ this.total = total;
+ }
+
+ public int getCode()
+ {
+ return code;
+ }
+
+ public void setCode(int code)
+ {
+ this.code = code;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public void setData(Object data) {
+ this.data = data;
+ }
+
+ public String getMsg()
+ {
+ return msg;
+ }
+
+ public void setMsg(String msg)
+ {
+ this.msg = msg;
+ }
+}
\ No newline at end of file
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/base/TableSupport.java b/jshERP-boot/src/main/java/com/jsh/erp/base/TableSupport.java
new file mode 100644
index 000000000..03c986aa2
--- /dev/null
+++ b/jshERP-boot/src/main/java/com/jsh/erp/base/TableSupport.java
@@ -0,0 +1,56 @@
+package com.jsh.erp.base;
+
+import com.jsh.erp.utils.Convert;
+import com.jsh.erp.utils.ServletUtils;
+
+/**
+ * 表格数据处理
+ *
+ * @author ji-sheng-hua
+ */
+public class TableSupport
+{
+ /**
+ * 当前记录起始索引
+ */
+ public static final String CURRENT_PAGE = "currentPage";
+
+ /**
+ * 每页显示记录数
+ */
+ public static final String PAGE_SIZE = "pageSize";
+
+ /**
+ * 排序列
+ */
+ public static final String ORDER_BY_COLUMN = "orderByColumn";
+
+ /**
+ * 排序的方向 "desc" 或者 "asc".
+ */
+ public static final String IS_ASC = "isAsc";
+
+ /**
+ * 分页参数合理化
+ */
+ public static final String REASONABLE = "reasonable";
+
+ /**
+ * 封装分页对象
+ */
+ public static PageDomain getPageDomain()
+ {
+ PageDomain pageDomain = new PageDomain();
+ pageDomain.setCurrentPage(Convert.toInt(ServletUtils.getParameter(CURRENT_PAGE), 1));
+ pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
+ pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
+ pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
+ pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
+ return pageDomain;
+ }
+
+ public static PageDomain buildPageRequest()
+ {
+ return getPageDomain();
+ }
+}
diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/TenantController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/TenantController.java
index dd0d8aeb7..9f2dfccae 100644
--- a/jshERP-boot/src/main/java/com/jsh/erp/controller/TenantController.java
+++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/TenantController.java
@@ -3,6 +3,8 @@ package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.jsh.erp.base.BaseController;
+import com.jsh.erp.base.TableDataInfo;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.TenantEx;
@@ -18,6 +20,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
@@ -29,7 +32,7 @@ import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
@RestController
@RequestMapping(value = "/tenant")
@Api(tags = {"租户管理"})
-public class TenantController {
+public class TenantController extends BaseController {
@Resource
private TenantService tenantService;
@@ -50,31 +53,14 @@ public class TenantController {
@GetMapping(value = "/list")
@ApiOperation(value = "获取信息列表")
- public String getList(@RequestParam(value = Constants.PAGE_SIZE, required = false) Integer pageSize,
- @RequestParam(value = Constants.CURRENT_PAGE, required = false) Integer currentPage,
- @RequestParam(value = Constants.SEARCH, required = false) String search,
+ public TableDataInfo getList(@RequestParam(value = Constants.SEARCH, required = false) String search,
HttpServletRequest request)throws Exception {
- Map objectMap = new HashMap<>();
- if (pageSize != null && pageSize <= 0) {
- pageSize = 10;
- }
String loginName = StringUtil.getInfo(search, "loginName");
String type = StringUtil.getInfo(search, "type");
String enabled = StringUtil.getInfo(search, "enabled");
String remark = StringUtil.getInfo(search, "remark");
- IPage page = new Page<>();
- page.setCurrent(currentPage);
- page.setSize(pageSize);
- IPage list = tenantService.select(page, loginName, type, enabled, remark);
- if (list != null) {
- objectMap.put("rows", list.getRecords());
- objectMap.put("total", list.getTotal());
- return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
- } else {
- objectMap.put("rows", new ArrayList