mirror of
https://gitee.com/likeadmin/likeadmin_java.git
synced 2026-06-25 06:30:48 +08:00
整体优化代码结构
This commit is contained in:
@@ -3,13 +3,10 @@ package com.mdd.common.core;
|
||||
import com.mdd.common.enums.HttpEnum;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Data
|
||||
public class AjaxResult implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public class AjaxResult<T> {
|
||||
|
||||
/** 状态码 **/
|
||||
private Integer code;
|
||||
@@ -18,12 +15,10 @@ public class AjaxResult implements Serializable {
|
||||
private String msg;
|
||||
|
||||
/** 响应数据 **/
|
||||
private Object data;
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 无参构造
|
||||
*/
|
||||
public AjaxResult() {}
|
||||
/** 无参构造 **/
|
||||
protected AjaxResult() {}
|
||||
|
||||
/**
|
||||
* 带参构造
|
||||
@@ -33,7 +28,7 @@ public class AjaxResult implements Serializable {
|
||||
* @param msg 提示信息
|
||||
* @param data 响应数据
|
||||
*/
|
||||
public AjaxResult(Integer code, String msg, Object data) {
|
||||
public AjaxResult(Integer code, String msg, T data) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
@@ -45,8 +40,8 @@ public class AjaxResult implements Serializable {
|
||||
* @author fzr
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success() {
|
||||
return new AjaxResult(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), new ArrayList<>());
|
||||
public static AjaxResult<Object> success() {
|
||||
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,8 +51,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param code 状态码
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(Integer code) {
|
||||
return new AjaxResult(code, HttpEnum.FAILED.getMsg(), new ArrayList<>());
|
||||
public static AjaxResult<Object> success(Integer code) {
|
||||
return new AjaxResult<>(code, HttpEnum.FAILED.getMsg(), new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,8 +62,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param msg 提示信息
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(String msg) {
|
||||
return new AjaxResult(HttpEnum.SUCCESS.getCode(), msg, new ArrayList<>());
|
||||
public static AjaxResult<Object> success(String msg) {
|
||||
return new AjaxResult<>(HttpEnum.SUCCESS.getCode(), msg, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,8 +73,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param data 响应数据
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(Object data) {
|
||||
return new AjaxResult(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), data);
|
||||
public static <T> AjaxResult<T> success(T data) {
|
||||
return new AjaxResult<T>(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,8 +85,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param msg 提示信息
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(Integer code, String msg) {
|
||||
return new AjaxResult(code, msg, new ArrayList<>());
|
||||
public static AjaxResult<Object> success(Integer code, String msg) {
|
||||
return new AjaxResult<>(code, msg, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,8 +97,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param data 响应数据
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(String msg, Object data) {
|
||||
return new AjaxResult(HttpEnum.SUCCESS.getCode(), msg, data);
|
||||
public static <T> AjaxResult <T> success(String msg, T data) {
|
||||
return new AjaxResult<T>(HttpEnum.SUCCESS.getCode(), msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,8 +110,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param data 响应数据
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult success(Integer code, String msg, Object data) {
|
||||
return new AjaxResult(code, msg, data);
|
||||
public static <T> AjaxResult<T> success(Integer code, String msg, T data) {
|
||||
return new AjaxResult<T>(code, msg, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +121,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param code 状态码
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult failed(Integer code) {
|
||||
return new AjaxResult(code, HttpEnum.FAILED.getMsg(), new ArrayList<>());
|
||||
public static AjaxResult<Object> failed(Integer code) {
|
||||
return new AjaxResult<>(code, HttpEnum.FAILED.getMsg(), new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,8 +132,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param msg 提示信息
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult failed(String msg) {
|
||||
return new AjaxResult(HttpEnum.FAILED.getCode(), msg, new ArrayList<>());
|
||||
public static AjaxResult<Object> failed(String msg) {
|
||||
return new AjaxResult<>(HttpEnum.FAILED.getCode(), msg, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,8 +143,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param data 响应数据
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult failed(Object data) {
|
||||
return new AjaxResult(HttpEnum.FAILED.getCode(), HttpEnum.FAILED.getMsg(), data);
|
||||
public static <T> AjaxResult<T> failed(T data) {
|
||||
return new AjaxResult<T>(HttpEnum.FAILED.getCode(), HttpEnum.FAILED.getMsg(), data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,8 +155,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param msg 提示信息
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult failed(Integer code, String msg) {
|
||||
return new AjaxResult(code, msg, new ArrayList<>());
|
||||
public static AjaxResult<Object> failed(Integer code, String msg) {
|
||||
return new AjaxResult<>(code, msg, new ArrayList<>());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,8 +168,8 @@ public class AjaxResult implements Serializable {
|
||||
* @param data 响应数据
|
||||
* @return AjaxResult
|
||||
*/
|
||||
public static AjaxResult failed(Integer code, String msg, Object data) {
|
||||
return new AjaxResult(code, msg, data);
|
||||
public static <T> AjaxResult<T> failed(Integer code, String msg, T data) {
|
||||
return new AjaxResult<T>(code, msg, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package com.mdd.common.core.basics;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.github.yulichang.query.MPJQueryWrapper;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mdd.common.utils.TimeUtil;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -41,10 +45,12 @@ public interface IBaseMapper<T> extends MPJBaseMapper<T> {
|
||||
*
|
||||
* @author fzr
|
||||
* @param queryWrapper 条件构造器
|
||||
* @param params 参数[条件:键@数据库字段:类型]
|
||||
* @param conditions 条件
|
||||
* @param param 参数[条件:键@数据库字段:类型]
|
||||
* @param conditions 条件[ new String[]{"like:username:str", "=:role:int"} ]
|
||||
*/
|
||||
default void setSearch(MPJQueryWrapper<T> queryWrapper, Map<String, String> params, String[] conditions) {
|
||||
default void setSearch(MPJQueryWrapper<T> queryWrapper, Object param, String[] conditions) {
|
||||
Type types = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> params = JSON.parseObject(JSONObject.toJSONString(param), types);
|
||||
|
||||
for (String condition : conditions) {
|
||||
String[] array = condition.split(":");
|
||||
@@ -160,7 +166,7 @@ public interface IBaseMapper<T> extends MPJBaseMapper<T> {
|
||||
|
||||
if (type.equals("long")) {
|
||||
if (!dateEnd.equals("")) { queryWrapper.le(field, Long.parseLong(dateEnd)); }
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, Long.parseLong(dateStart)); };
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, Long.parseLong(dateStart)); }
|
||||
} else {
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, TimeUtil.dateToTimestamp(dateStart)); }
|
||||
if (!dateEnd.equals("")) { queryWrapper.le(field, TimeUtil.dateToTimestamp(dateEnd)); }
|
||||
@@ -176,10 +182,12 @@ public interface IBaseMapper<T> extends MPJBaseMapper<T> {
|
||||
*
|
||||
* @author fzr
|
||||
* @param queryWrapper 条件构造器
|
||||
* @param params 参数[条件:键@数据库字段:类型]
|
||||
* @param conditions 条件
|
||||
* @param param 参数[条件:键@数据库字段:类型]
|
||||
* @param conditions 条件[ new String[]{"like:username:str", "=:role:int"} ]
|
||||
*/
|
||||
default void setSearch(QueryWrapper<T> queryWrapper, Map<String, String> params, String[] conditions) {
|
||||
default void setSearch(QueryWrapper<T> queryWrapper, Object param, String[] conditions) {
|
||||
Type types = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> params = JSON.parseObject(JSONObject.toJSONString(param), types);
|
||||
|
||||
for (String condition : conditions) {
|
||||
String[] array = condition.split(":");
|
||||
@@ -297,7 +305,7 @@ public interface IBaseMapper<T> extends MPJBaseMapper<T> {
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, Long.parseLong(dateStart)); }
|
||||
if (!dateEnd.equals("")) { queryWrapper.le(field, Long.parseLong(dateEnd)); }
|
||||
} else {
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, TimeUtil.dateToTimestamp(dateStart)); };
|
||||
if (!dateStart.equals("")) { queryWrapper.ge(field, TimeUtil.dateToTimestamp(dateStart)); }
|
||||
if (!dateEnd.equals("")) { queryWrapper.le(field, TimeUtil.dateToTimestamp(dateEnd)); }
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mdd.common.entity.decorate;
|
||||
package com.mdd.common.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.mdd.common.entity.decorate;
|
||||
package com.mdd.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mdd.common.mapper.decorate;
|
||||
package com.mdd.common.mapper;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.decorate.DecoratePage;
|
||||
import com.mdd.common.entity.DecoratePage;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mdd.common.mapper.decorate;
|
||||
package com.mdd.common.mapper;
|
||||
|
||||
import com.mdd.common.core.basics.IBaseMapper;
|
||||
import com.mdd.common.entity.decorate.DecorateTabbar;
|
||||
import com.mdd.common.entity.DecorateTabbar;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
@@ -1,20 +1,14 @@
|
||||
package com.mdd.common.plugin.sms;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.mdd.common.entity.system.SystemLogSms;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
import com.mdd.common.mapper.system.SystemLogSmsMapper;
|
||||
import com.mdd.common.plugin.sms.engine.AliSms;
|
||||
import com.mdd.common.plugin.sms.engine.TencentSms;
|
||||
import com.mdd.common.utils.ArrayUtil;
|
||||
import com.mdd.common.utils.ConfigUtil;
|
||||
import com.mdd.common.utils.SpringUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.management.openmbean.OpenDataException;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SmsDriver {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package com.mdd.common.plugin.sms.engine;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.aliyuncs.CommonRequest;
|
||||
import com.aliyuncs.CommonResponse;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.http.MethodType;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.mdd.common.exception.OperateException;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.mdd.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.mdd.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.mdd.common.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.mdd.common.config.GlobalConfig;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user