Quellcode durchsuchen

添加 cn.ele6.catalyzer.ruoyi.enhance 同名扩展类。

tom vor 5 Monaten
Ursprung
Commit
bab1d104c8

+ 0 - 8
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/Test2.java

@@ -1,8 +0,0 @@
-package cn.ele6.catalyzer.ruoyi;
-
-public class Test2 {
-
-    public String getTestString(){
-        return "test";
-    }
-}

+ 175 - 0
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/custom/BaseService.java

@@ -0,0 +1,175 @@
+package cn.ele6.catalyzer.ruoyi.custom;
+
+import cn.ele6.catalyzer.ruoyi.enhance.AjaxResult;
+import cn.ele6.catalyzer.ruoyi.enhance.TableDataInfo;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.ruoyi.common.constant.HttpStatus;
+import com.ruoyi.common.core.domain.model.LoginUser;
+import com.ruoyi.common.core.page.PageDomain;
+import com.ruoyi.common.core.page.TableSupport;
+import com.ruoyi.common.utils.PageUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.sql.SqlUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+public abstract class BaseService {
+
+    protected Logger l = LoggerFactory.getLogger(BaseService.class);
+
+    /**
+     * 设置请求分页数据
+     * copy from BaseController.
+     */
+    protected void startPage() {
+        PageUtils.startPage();
+    }
+
+    /**
+     * 设置请求排序数据
+     * copy from BaseController.
+     */
+    protected void startOrderBy() {
+        PageDomain pageDomain = TableSupport.buildPageRequest();
+        if (StringUtils.isNotEmpty(pageDomain.getOrderBy())) {
+            String orderBy = SqlUtil.escapeOrderBySql(pageDomain.getOrderBy());
+            PageHelper.orderBy(orderBy);
+        }
+    }
+
+    /**
+     * 清理分页的线程变量
+     * copy from BaseController.
+     */
+    protected void clearPage() {
+        PageUtils.clearPage();
+    }
+
+    /**
+     * 响应请求分页数据
+     * copy from BaseController.
+     */
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    protected TableDataInfo getDataTable(List<?> list) {
+        TableDataInfo rspData = new TableDataInfo();
+        rspData.setCode(HttpStatus.SUCCESS);
+        rspData.setMsg("查询成功");
+        rspData.setRows(list);
+        rspData.setTotal(new PageInfo(list).getTotal());
+        return rspData;
+    }
+
+    /**
+     * 返回成功
+     * copy from BaseController.
+     */
+    public AjaxResult success() {
+        return AjaxResult.success();
+    }
+
+    /**
+     * 返回失败消息
+     * copy from BaseController.
+     */
+    public AjaxResult error() {
+        return AjaxResult.error();
+    }
+
+    /**
+     * 返回成功消息
+     * copy from BaseController.
+     */
+    public AjaxResult success(String message) {
+        return AjaxResult.success(message);
+    }
+
+    /**
+     * 返回成功消息
+     * copy from BaseController.
+     */
+    public AjaxResult success(Object data) {
+        return AjaxResult.success(data);
+    }
+
+    /**
+     * 返回失败消息
+     * copy from BaseController.
+     */
+    public AjaxResult error(String message) {
+        return AjaxResult.error(message);
+    }
+
+    /**
+     * 返回警告消息
+     * copy from BaseController.
+     */
+    public AjaxResult warn(String message) {
+        return AjaxResult.warn(message);
+    }
+
+    /**
+     * 响应返回结果
+     * copy from BaseController.
+     *
+     * @param rows 影响行数
+     * @return 操作结果
+     */
+    protected AjaxResult toAjax(int rows) {
+        return rows > 0 ? AjaxResult.success() : AjaxResult.error();
+    }
+
+    /**
+     * 响应返回结果
+     * copy from BaseController.
+     *
+     * @param result 结果
+     * @return 操作结果
+     */
+    protected AjaxResult toAjax(boolean result) {
+        return result ? success() : error();
+    }
+
+    /**
+     * 页面跳转
+     * copy from BaseController.
+     */
+    public String redirect(String url) {
+        return StringUtils.format("redirect:{}", url);
+    }
+
+    /**
+     * 获取用户缓存信息
+     * copy from BaseController.
+     */
+    public LoginUser getLoginUser() {
+        return SecurityUtils.getLoginUser();
+    }
+
+    /**
+     * 获取登录用户id
+     * copy from BaseController.
+     */
+    public Long getUserId() {
+        return getLoginUser().getUserId();
+    }
+
+    /**
+     * 获取登录部门id
+     * copy from BaseController.
+     */
+    public Long getDeptId() {
+        return getLoginUser().getDeptId();
+    }
+
+    /**
+     * 获取登录用户名
+     * copy from BaseController.
+     */
+    public String getUsername() {
+        return getLoginUser().getUsername();
+    }
+}

+ 8 - 0
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/custom/RuoYiResponse.java

@@ -0,0 +1,8 @@
+package cn.ele6.catalyzer.ruoyi.custom;
+
+/**
+ * RuoYiResponse tag interface.
+ */
+public interface RuoYiResponse {
+
+}

+ 127 - 2
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/enhance/AjaxResult.java

@@ -1,11 +1,136 @@
 package cn.ele6.catalyzer.ruoyi.enhance;
 
+import cn.ele6.catalyzer.ruoyi.custom.RuoYiResponse;
+import com.ruoyi.common.constant.HttpStatus;
+import org.springframework.beans.BeanUtils;
+
 import java.io.Serializable;
 
 /**
- * 泛型改造。
+ * 改造。
  */
-public class AjaxResult extends com.ruoyi.common.core.domain.AjaxResult implements Serializable {
+public class AjaxResult extends com.ruoyi.common.core.domain.AjaxResult implements Serializable, RuoYiResponse {
+
+    /**
+     * 返回成功消息
+     * copy.
+     *
+     * @return 成功消息
+     */
+    public static AjaxResult success() {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.success("操作成功"));
+    }
+
+    /**
+     * 返回成功数据
+     * copy.
+     *
+     * @return 成功消息
+     */
+    public static AjaxResult success(Object data) {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.success("操作成功", data));
+    }
+
+    /**
+     * 返回成功消息
+     * copy.
+     *
+     * @param msg 返回内容
+     * @return 成功消息
+     */
+    public static AjaxResult success(String msg) {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.success(msg, null));
+    }
+
+    /**
+     * 返回成功消息
+     * copy.
+     *
+     * @param msg  返回内容
+     * @param data 数据对象
+     * @return 成功消息
+     */
+    public static AjaxResult success(String msg, Object data) {
+        return convert(new com.ruoyi.common.core.domain.AjaxResult(HttpStatus.SUCCESS, msg, data));
+    }
+
+    /**
+     * 返回警告消息
+     * copy.
+     *
+     * @param msg 返回内容
+     * @return 警告消息
+     */
+    public static AjaxResult warn(String msg) {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.warn(msg, null));
+    }
+
+    /**
+     * 返回警告消息
+     * copy.
+     *
+     * @param msg  返回内容
+     * @param data 数据对象
+     * @return 警告消息
+     */
+    public static AjaxResult warn(String msg, Object data) {
+        return convert(new com.ruoyi.common.core.domain.AjaxResult(HttpStatus.WARN, msg, data));
+    }
+
+    /**
+     * 返回错误消息
+     * copy.
+     *
+     * @return 错误消息
+     */
+    public static AjaxResult error() {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.error("操作失败"));
+    }
+
+    /**
+     * 返回错误消息
+     * copy.
+     *
+     * @param msg 返回内容
+     * @return 错误消息
+     */
+    public static AjaxResult error(String msg) {
+        return convert(com.ruoyi.common.core.domain.AjaxResult.error(msg, null));
+    }
+
+    /**
+     * 返回错误消息
+     * copy.
+     *
+     * @param msg  返回内容
+     * @param data 数据对象
+     * @return 错误消息
+     */
+    public static AjaxResult error(String msg, Object data) {
+        return convert(new com.ruoyi.common.core.domain.AjaxResult(HttpStatus.ERROR, msg, data));
+    }
 
+    /**
+     * 返回错误消息
+     * copy.
+     *
+     * @param code 状态码
+     * @param msg  返回内容
+     * @return 错误消息
+     */
+    public static AjaxResult error(int code, String msg) {
+        return convert(new com.ruoyi.common.core.domain.AjaxResult(code, msg, null));
+    }
 
+    /**
+     * copy obj and convert type.
+     *
+     * @param o
+     * @return
+     */
+    public static AjaxResult convert(com.ruoyi.common.core.domain.AjaxResult o) {
+        AjaxResult t = new AjaxResult();
+        BeanUtils.copyProperties(o, t);
+        return t;
+    }
 }

+ 9 - 0
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/enhance/BaseController.java

@@ -1,5 +1,14 @@
 package cn.ele6.catalyzer.ruoyi.enhance;
 
+/**
+ *
+ */
 public class BaseController extends com.ruoyi.common.core.controller.BaseController {
 
+
+
+
+    public static AjaxResult convert(com.ruoyi.common.core.domain.AjaxResult o) {
+        return AjaxResult.convert(o);
+    }
 }

+ 3 - 0
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/enhance/BaseEntity.java

@@ -1,5 +1,8 @@
 package cn.ele6.catalyzer.ruoyi.enhance;
 
+/**
+ *
+ */
 public class BaseEntity extends com.ruoyi.common.core.domain.BaseEntity {
 
 }

+ 3 - 0
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/enhance/BaseException.java

@@ -1,5 +1,8 @@
 package cn.ele6.catalyzer.ruoyi.enhance;
 
+/**
+ *
+ */
 public class BaseException extends com.ruoyi.common.exception.base.BaseException {
 
     public BaseException(String module, String code, Object[] args, String defaultMessage) {

+ 19 - 1
ele6-catalyzer-ruoyi-vue/src/main/java/cn/ele6/catalyzer/ruoyi/enhance/TableDataInfo.java

@@ -1,7 +1,25 @@
 package cn.ele6.catalyzer.ruoyi.enhance;
 
+import cn.ele6.catalyzer.ruoyi.custom.RuoYiResponse;
+import org.springframework.beans.BeanUtils;
+
 import java.io.Serializable;
 
-public class TableDataInfo extends com.ruoyi.common.core.page.TableDataInfo implements Serializable {
+/**
+ *
+ */
+public class TableDataInfo extends com.ruoyi.common.core.page.TableDataInfo implements Serializable, RuoYiResponse {
+
 
+    /**
+     * copy obj and convert type.
+     *
+     * @param o
+     * @return
+     */
+    public static TableDataInfo convert(com.ruoyi.common.core.page.TableDataInfo o) {
+        TableDataInfo t = new TableDataInfo();
+        BeanUtils.copyProperties(o, t);
+        return t;
+    }
 }