新增:erp、erp-spi
This commit is contained in:
@@ -0,0 +1,224 @@
|
||||
package com.zsw.base;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.zsw.exception.BizException;
|
||||
import com.zsw.exception.code.BaseExceptionCode;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuppressWarnings("ALL")
|
||||
@Accessors(chain = true)
|
||||
public class R<T> implements Serializable {
|
||||
private static final long serialversionUID = 1L;
|
||||
public static final String DEF_ERROR_MESSAGE = "系统繁忙,请稍候再试";
|
||||
public static final String HYSTRIX_ERROR_MESSAGE = "请求超时,请稍候再试";
|
||||
public static final int SUCCESS_CODE = 200;
|
||||
public static final int FAIL_CODE = -1;
|
||||
public static final int TIMEOUT_CODE = -2;
|
||||
/**
|
||||
* 统一参数验证异常
|
||||
*/
|
||||
public static final int VALID_EX_CODE = -9;
|
||||
public static final int OPERATION_EX_CODE = -10;
|
||||
/**
|
||||
* 调用是否成功标识,0:成功,-1:系统繁忙,此时请开发者稍候再试 详情见[ExceptionCode]
|
||||
*/
|
||||
@ApiModelProperty(value = "响应编码:0/200-请求处理成功")
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 是否执行默认操作
|
||||
*/
|
||||
@JsonIgnore
|
||||
private Boolean defExec = true;
|
||||
|
||||
/**
|
||||
* 调用结果
|
||||
*/
|
||||
@ApiModelProperty(value = "响应数据")
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 结果消息,如果调用成功,消息通常为空T
|
||||
*/
|
||||
@ApiModelProperty(value = "提示消息")
|
||||
private String msg = "ok";
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModelProperty(value = "请求路径")
|
||||
private String path;
|
||||
/**
|
||||
* 附加数据
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModelProperty(value = "附加数据")
|
||||
private Map<String, Object> extra;
|
||||
|
||||
/**
|
||||
* 响应时间
|
||||
*/
|
||||
@ApiModelProperty(value = "响应时间戳")
|
||||
private LocalDateTime time = LocalDateTime.now();
|
||||
|
||||
private R() {
|
||||
super();
|
||||
}
|
||||
|
||||
public R(int code, T data, String msg) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
this.msg = msg;
|
||||
this.defExec = false;
|
||||
}
|
||||
|
||||
public R(int code, T data, String msg, boolean defExec) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
this.msg = msg;
|
||||
this.defExec = defExec;
|
||||
}
|
||||
|
||||
public static <E> R<E> result(int code, E data, String msg) {
|
||||
return new R<E>(code, data, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求成功消息
|
||||
*
|
||||
* @param data 结果
|
||||
* @return RPC调用结果
|
||||
*/
|
||||
public static <E> R<E> success(E data) {
|
||||
return new R<E>(SUCCESS_CODE, data, "ok");
|
||||
}
|
||||
|
||||
public static R<Boolean> success() {
|
||||
return new R<Boolean>(SUCCESS_CODE, true, "ok");
|
||||
}
|
||||
|
||||
|
||||
public static <E> R<E> successDef(E data) {
|
||||
return new R<E>(SUCCESS_CODE, data, "ok", true);
|
||||
}
|
||||
|
||||
public static <E> R<E> successDef() {
|
||||
return new R<E>(SUCCESS_CODE, null, "ok", true);
|
||||
}
|
||||
|
||||
public static <E> R<E> successDef(E data, String msg) {
|
||||
return new R<E>(SUCCESS_CODE, data, msg, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求成功方法 ,data返回值,msg提示信息
|
||||
*
|
||||
* @param data 结果
|
||||
* @param msg 消息
|
||||
* @return RPC调用结果
|
||||
*/
|
||||
public static <E> R<E> success(E data, String msg) {
|
||||
return new R<E>(SUCCESS_CODE, data, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求失败消息
|
||||
*
|
||||
* @param msg
|
||||
* @return
|
||||
*/
|
||||
public static <E> R<E> fail(int code, String msg) {
|
||||
return new R<E>(code, null, (msg == null || msg.isEmpty()) ? DEF_ERROR_MESSAGE : msg);
|
||||
}
|
||||
|
||||
public static <E> R<E> fail(String msg) {
|
||||
return fail(OPERATION_EX_CODE, msg);
|
||||
}
|
||||
|
||||
public static <E> R<E> fail(String msg, Object... args) {
|
||||
String message = (msg == null || msg.isEmpty()) ? DEF_ERROR_MESSAGE : msg;
|
||||
return new R<E>(OPERATION_EX_CODE, null, String.format(message, args));
|
||||
}
|
||||
|
||||
public static <E> R<E> fail(BaseExceptionCode exceptionCode) {
|
||||
return validFail(exceptionCode);
|
||||
}
|
||||
|
||||
public static <E> R<E> fail(BizException exception) {
|
||||
if (exception == null) {
|
||||
return fail(DEF_ERROR_MESSAGE);
|
||||
}
|
||||
return new R<E>(exception.getCode(), null, exception.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求失败消息,根据异常类型,获取不同的提供消息
|
||||
*
|
||||
* @param throwable 异常
|
||||
* @return RPC调用结果
|
||||
*/
|
||||
public static <E> R<E> fail(Throwable throwable) {
|
||||
return fail(FAIL_CODE, throwable != null ? throwable.getMessage() : DEF_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
public static <E> R<E> validFail(String msg) {
|
||||
return new R<E>(VALID_EX_CODE, null, (msg == null || msg.isEmpty()) ? DEF_ERROR_MESSAGE : msg);
|
||||
}
|
||||
|
||||
public static <E> R<E> validFail(String msg, Object... args) {
|
||||
String message = (msg == null || msg.isEmpty()) ? DEF_ERROR_MESSAGE : msg;
|
||||
return new R<E>(VALID_EX_CODE, null, String.format(message, args));
|
||||
}
|
||||
|
||||
public static <E> R<E> validFail(BaseExceptionCode exceptionCode) {
|
||||
return new R<E>(exceptionCode.getCode(), null,
|
||||
(exceptionCode.getMsg() == null || exceptionCode.getMsg().isEmpty()) ? DEF_ERROR_MESSAGE : exceptionCode.getMsg());
|
||||
}
|
||||
|
||||
public static <E> R<E> timeout() {
|
||||
return fail(TIMEOUT_CODE, HYSTRIX_ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
public R<T> put(String key, Object value) {
|
||||
if (this.extra == null) {
|
||||
this.extra = new HashMap<String, Object>(10);
|
||||
}
|
||||
this.extra.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑处理是否成功
|
||||
*
|
||||
* @return 是否成功
|
||||
*/
|
||||
public Boolean getIsSuccess() {
|
||||
return this.code == SUCCESS_CODE || this.code == 200 || this.code == 0 || this.msg.equals("ok");
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑处理是否失败
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Boolean getIsError() {
|
||||
return !getIsSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JSONUtil.toJsonStr(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.zsw.base.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* 基础实体
|
||||
*
|
||||
* @author 云久
|
||||
* @date 2019/05/05
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public class Entity<T> extends SuperEntity<T> {
|
||||
|
||||
public static final String UPDATE_TIME = "updateTime";
|
||||
public static final String UPDATE_USER = "updateUser";
|
||||
private static final long serialVersionUID = 5169873634279173683L;
|
||||
|
||||
@ApiModelProperty(value = "最后修改时间",hidden = true)
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
|
||||
protected LocalDateTime updateTime;
|
||||
|
||||
@ApiModelProperty(value = "最后修改人ID",hidden = true)
|
||||
@TableField(value = "update_user", fill = FieldFill.INSERT_UPDATE)
|
||||
protected T updateUser;
|
||||
|
||||
public Entity(T id, LocalDateTime createTime, T createUser, LocalDateTime updateTime, T updateUser) {
|
||||
super(id, createTime, createUser);
|
||||
this.updateTime = updateTime;
|
||||
this.updateUser = updateUser;
|
||||
}
|
||||
|
||||
public Entity() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.zsw.base.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import jdk.nashorn.internal.objects.annotations.Getter;
|
||||
import jdk.nashorn.internal.objects.annotations.Setter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Null;
|
||||
import javax.validation.groups.Default;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 基础实体
|
||||
*
|
||||
* @author 云久
|
||||
* @date 2019/05/05
|
||||
*/
|
||||
@Accessors(chain = true)
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public class SuperEntity<T> implements Serializable {
|
||||
public static final String FIELD_ID = "id";
|
||||
public static final String CREATE_TIME = "createTime";
|
||||
public static final String CREATE_TIME_COLUMN = "create_time";
|
||||
public static final String CREATE_USER = "createUser";
|
||||
public static final String CREATE_USER_COLUMN = "create_user";
|
||||
|
||||
private static final long serialVersionUID = -4603650115461757622L;
|
||||
|
||||
@TableId(value = "id", type = IdType.INPUT)
|
||||
@ApiModelProperty(value = "主键|新增请删除")
|
||||
@NotNull(message = "id不能为空", groups = Update.class)
|
||||
@Null(message = "id错误", groups = Save.class)
|
||||
protected T id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间",hidden = true)
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
protected LocalDateTime createTime;
|
||||
|
||||
@ApiModelProperty(value = "创建人ID",hidden = true)
|
||||
@TableField(value = "create_user", fill = FieldFill.INSERT)
|
||||
protected T createUser;
|
||||
|
||||
/**
|
||||
* 保存和缺省验证组
|
||||
*/
|
||||
public interface Save extends Default {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新和缺省验证组
|
||||
*/
|
||||
public interface Update extends Default {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.zsw.base.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 树形实体
|
||||
*
|
||||
* @author 云久
|
||||
* @date 2019/05/05
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Accessors(chain = true)
|
||||
@ToString(callSuper = true)
|
||||
public class TreeEntity<E, T> extends Entity<T> {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@ApiModelProperty(value = "名称")
|
||||
@NotEmpty(message = "名称不能为空")
|
||||
@Length(max = 255, message = "名称长度不能超过255")
|
||||
@TableField(value = "label")
|
||||
protected String label;
|
||||
|
||||
/**
|
||||
* 父ID
|
||||
*/
|
||||
@ApiModelProperty(value = "父ID")
|
||||
@TableField(value = "parent_id")
|
||||
protected T parentId;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@ApiModelProperty(value = "排序号")
|
||||
@TableField(value = "sort_value")
|
||||
protected Integer sortValue;
|
||||
|
||||
|
||||
@ApiModelProperty(value = "子节点", hidden = true)
|
||||
@TableField(exist = false)
|
||||
protected List<E> children;
|
||||
|
||||
|
||||
/**
|
||||
* 初始化子类
|
||||
*/
|
||||
public void initChildren() {
|
||||
if (getChildren() == null) {
|
||||
this.setChildren(new ArrayList<E>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.zsw.base.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于MP的 BaseMapper 新增了2个方法: insertBatchSomeColumn、updateAllById
|
||||
*
|
||||
* @param <T> 实体
|
||||
* @author 云久
|
||||
* @date 2020年03月06日11:06:46
|
||||
*/
|
||||
public interface SuperMapper<T> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 全量修改所有字段
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
int updateAllById(@Param(Constants.ENTITY) T entity);
|
||||
|
||||
/**
|
||||
* 批量插入所有字段
|
||||
* <p>
|
||||
* 只测试过MySQL!只测试过MySQL!只测试过MySQL!
|
||||
*
|
||||
* @param entityList
|
||||
* @return
|
||||
*/
|
||||
int insertBatchSomeColumn(List<T> entityList);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.zsw.base.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
|
||||
import com.zsw.base.mapper.SuperMapper;
|
||||
import com.zsw.exception.BizException;
|
||||
import com.zsw.exception.code.ExceptionCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 基于MP的 IService 新增了2个方法: saveBatchSomeColumn、updateAllById
|
||||
* 其中:
|
||||
* 1,updateAllById 执行后,会清除缓存
|
||||
* 2,saveBatchSomeColumn 批量插入
|
||||
*
|
||||
* @param <T> 实体
|
||||
* @author 云久
|
||||
* @date 2020年03月03日20:49:03
|
||||
*/
|
||||
public interface SuperService<T> extends IService<T> {
|
||||
|
||||
/**
|
||||
* 批量保存数据
|
||||
* <p>
|
||||
* 注意:该方法仅仅测试过mysql
|
||||
*
|
||||
* @param entityList
|
||||
* @return
|
||||
*/
|
||||
default boolean saveBatchSomeColumn(List<T> entityList) {
|
||||
if (entityList.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
if (entityList.size() > 5000) {
|
||||
throw BizException.wrap(ExceptionCode.TOO_MUCH_DATA_ERROR);
|
||||
}
|
||||
return SqlHelper.retBool(((SuperMapper) getBaseMapper()).insertBatchSomeColumn(entityList));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id修改 entity 的所有字段
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
boolean updateAllById(T entity);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user