Commit 8cb7dc88 authored by dqjdda's avatar dqjdda
Browse files

加入实体基类、DTO基类、修改部分实体继承基类

parent bf7c1eeb
......@@ -44,7 +44,7 @@ public class LimitAspect {
String key = limit.key();
if (StringUtils.isEmpty(key)) {
if (limitType == LimitType.IP) {
key = StringUtils.getIP(request);
key = StringUtils.getIp(request);
} else {
key = signatureMethod.getName();
}
......
package me.zhengjie.aspect;
/**
* 限流枚举
* @author /
*/
public enum LimitType {
// 默认
CUSTOMER,
// by ip addr
// by ip addr
IP;
}
package me.zhengjie.base;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author Zheng Jie
* @Date 2019年10月24日20:48:53
*/
@Getter
@Setter
public class BaseDTO implements Serializable {
private Boolean isDelete;
private Timestamp createTime;
private Timestamp updateTime;
}
package me.zhengjie.base;
import lombok.*;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.sql.Timestamp;
import java.lang.reflect.Field;
/**
* @author Zheng Jie
* @Date 2019年10月24日20:46:32
*/
@Getter
@Setter
@MappedSuperclass
public class BaseEntity implements Serializable {
// 删除标识
@Column(name = "is_delete", columnDefinition = "bit default 0")
private Boolean isDelete = false;
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
@Column(name = "update_time")
@UpdateTimestamp
private Timestamp updateTime;
public @interface New {}
public @interface Update {}
@Override
public String toString() {
ToStringBuilder builder = new ToStringBuilder(this);
Field[] fields = this.getClass().getDeclaredFields();
try {
for (Field f : fields) {
f.setAccessible(true);
builder.append(f.getName(), f.get(this)).append("\n");
}
} catch (Exception e) {
builder.append("toString builder encounter an error");
}
return builder.toString();
}
}
package me.zhengjie.mapper;
package me.zhengjie.base;
import java.util.List;
......@@ -6,7 +6,7 @@ import java.util.List;
* @author Zheng Jie
* @date 2018-11-23
*/
public interface EntityMapper<D, E> {
public interface BaseMapper<D, E> {
/**
* DTO转Entity
......
......@@ -145,7 +145,8 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
file.transferTo(dest);// 文件写入
// 文件写入
file.transferTo(dest);
return dest;
} catch (Exception e) {
e.printStackTrace();
......@@ -197,7 +198,9 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return "音乐";
} else if(video.contains(type)){
return "视频";
} else return "其他";
} else {
return "其他";
}
}
public static String getFileTypeByMimeType(String type) {
......@@ -215,8 +218,8 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
* 判断两个文件是否相同
*/
public static boolean check(File file1, File file2) {
String img1Md5 = getMD5(file1);
String img2Md5 = getMD5(file2);
String img1Md5 = getMd5(file1);
String img2Md5 = getMd5(file2);
return img1Md5.equals(img2Md5);
}
......@@ -244,7 +247,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return b;
}
private static String getMD5(byte[] bytes) {
private static String getMd5(byte[] bytes) {
// 16进制字符
char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
try {
......@@ -266,8 +269,8 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
return null;
}
public static String getMD5(File file) {
return getMD5(getByte(file));
public static String getMd5(File file) {
return getMd5(getByte(file));
}
}
......@@ -69,6 +69,7 @@ public class QueryHelp {
join = root.join(name, JoinType.RIGHT);
}
break;
default: break;
}
}
}
......@@ -105,6 +106,7 @@ public class QueryHelp {
list.add(getExpression(attributeName,join,root).in((Collection<Long>) val));
}
break;
default: break;
}
}
field.setAccessible(accessible);
......
......@@ -107,7 +107,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
/**
* 获取ip地址
*/
public static String getIP(HttpServletRequest request) {
public static String getIp(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
......
......@@ -38,6 +38,6 @@ public class StringUtilsTest {
@Test
public void testGetIP() {
assertEquals("127.0.0.1", getIP(new MockHttpServletRequest()));
assertEquals("127.0.0.1", getIp(new MockHttpServletRequest()));
}
}
\ No newline at end of file
......@@ -52,7 +52,7 @@ public class LogAspect {
currentTime = System.currentTimeMillis();
result = joinPoint.proceed();
Log log = new Log("INFO",System.currentTimeMillis() - currentTime);
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()),joinPoint, log);
logService.save(getUsername(), StringUtils.getIp(RequestHolder.getHttpServletRequest()),joinPoint, log);
return result;
}
......@@ -66,7 +66,7 @@ public class LogAspect {
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
Log log = new Log("ERROR",System.currentTimeMillis() - currentTime);
log.setExceptionDetail(ThrowableUtil.getStackTrace(e).getBytes());
logService.save(getUsername(), StringUtils.getIP(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
logService.save(getUsername(), StringUtils.getIp(RequestHolder.getHttpServletRequest()), (ProceedingJoinPoint)joinPoint, log);
}
public String getUsername() {
......
package me.zhengjie.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.domain.Log;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.service.dto.LogErrorDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-5-22
*/
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface LogErrorMapper extends EntityMapper<LogErrorDTO, Log> {
public interface LogErrorMapper extends BaseMapper<LogErrorDTO, Log> {
}
\ No newline at end of file
package me.zhengjie.service.mapper;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.domain.Log;
import me.zhengjie.mapper.EntityMapper;
import me.zhengjie.service.dto.LogSmallDTO;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
......@@ -11,6 +11,6 @@ import org.mapstruct.ReportingPolicy;
* @date 2019-5-22
*/
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface LogSmallMapper extends EntityMapper<LogSmallDTO, Log> {
public interface LogSmallMapper extends BaseMapper<LogSmallDTO, Log> {
}
\ No newline at end of file
package me.zhengjie.modules.quartz.domain;
import lombok.Data;
import org.hibernate.annotations.UpdateTimestamp;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author Zheng Jie
......@@ -16,7 +13,7 @@ import java.sql.Timestamp;
@Data
@Entity
@Table(name = "quartz_job")
public class QuartzJob implements Serializable {
public class QuartzJob extends BaseEntity {
public static final String JOB_KEY = "JOB_KEY";
......@@ -56,11 +53,4 @@ public class QuartzJob implements Serializable {
@Column(name = "remark")
@NotBlank
private String remark;
// 创建日期
@UpdateTimestamp
@Column(name = "update_time")
private Timestamp updateTime;
public interface Update{}
}
\ No newline at end of file
......@@ -2,12 +2,12 @@ package me.zhengjie.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.io.Serializable;
import java.util.Set;
/**
......@@ -15,9 +15,10 @@ import java.util.Set;
* @date 2019-03-25
*/
@Entity
@Data
@Getter
@Setter
@Table(name="dept")
public class Dept implements Serializable {
public class Dept extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -39,10 +40,4 @@ public class Dept implements Serializable {
@JsonIgnore
@ManyToMany(mappedBy = "depts")
private Set<Role> roles;
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
public @interface Update {}
}
\ No newline at end of file
package me.zhengjie.modules.system.domain;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
......@@ -12,9 +16,10 @@ import java.util.List;
* @date 2019-04-10
*/
@Entity
@Data
@Getter
@Setter
@Table(name="dict")
public class Dict implements Serializable {
public class Dict extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -31,6 +36,4 @@ public class Dict implements Serializable {
@OneToMany(mappedBy = "dict",cascade={CascadeType.PERSIST,CascadeType.REMOVE})
private List<DictDetail> dictDetails;
public @interface Update {}
}
\ No newline at end of file
package me.zhengjie.modules.system.domain;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
......@@ -10,9 +14,10 @@ import java.io.Serializable;
* @date 2019-04-10
*/
@Entity
@Data
@Getter
@Setter
@Table(name="dict_detail")
public class DictDetail implements Serializable {
public class DictDetail extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -36,6 +41,4 @@ public class DictDetail implements Serializable {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "dict_id")
private Dict dict;
public @interface Update {}
}
\ No newline at end of file
package me.zhengjie.modules.system.domain;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.*;
import javax.persistence.*;
import javax.persistence.Entity;
......@@ -15,9 +18,10 @@ import java.io.Serializable;
* @date 2019-03-29
*/
@Entity
@Data
@Getter
@Setter
@Table(name="job")
public class Job implements Serializable {
public class Job extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -40,10 +44,4 @@ public class Job implements Serializable {
@OneToOne
@JoinColumn(name = "dept_id")
private Dept dept;
@Column(name = "create_time")
@CreationTimestamp
private Timestamp createTime;
public @interface Update {}
}
\ No newline at end of file
......@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
......@@ -20,7 +21,7 @@ import java.util.Set;
@Getter
@Setter
@Table(name = "menu")
public class Menu implements Serializable {
public class Menu extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -63,12 +64,6 @@ public class Menu implements Serializable {
@JsonIgnore
private Set<Role> roles;
@CreationTimestamp
@Column(name = "create_time")
private Timestamp createTime;
public interface Update{}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
......@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
......@@ -19,7 +20,7 @@ import java.util.Set;
@Getter
@Setter
@Table(name = "permission")
public class Permission implements Serializable{
public class Permission extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -40,21 +41,4 @@ public class Permission implements Serializable{
@JsonIgnore
@ManyToMany(mappedBy = "permissions")
private Set<Role> roles;
@CreationTimestamp
@Column(name = "create_time")
private Timestamp createTime;
@Override
public String toString() {
return "Permission{" +
"id=" + id +
", name='" + name + '\'' +
", pid=" + pid +
", alias='" + alias + '\'' +
", createTime=" + createTime +
'}';
}
public interface Update{}
}
......@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import me.zhengjie.base.BaseEntity;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
......@@ -21,7 +22,7 @@ import java.util.Set;
@Table(name = "role")
@Getter
@Setter
public class Role implements Serializable {
public class Role extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
......@@ -59,20 +60,6 @@ public class Role implements Serializable {
@JoinTable(name = "roles_depts", joinColumns = {@JoinColumn(name = "role_id",referencedColumnName = "id")}, inverseJoinColumns = {@JoinColumn(name = "dept_id",referencedColumnName = "id")})
private Set<Dept> depts;
@CreationTimestamp
@Column(name = "create_time")
private Timestamp createTime;
@Override
public String toString() {
return "Role{" +
"id=" + id +
", name='" + name + '\'' +
", remark='" + remark + '\'' +
", createDateTime=" + createTime +
'}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment