diff --git a/basic-annotation/pom.xml b/basic-annotation/pom.xml new file mode 100644 index 00000000..bbc2cbf9 --- /dev/null +++ b/basic-annotation/pom.xml @@ -0,0 +1,14 @@ + + + + wg-basic + ink.wgink + 1.0-SNAPSHOT + + 4.0.0 + + basic-annotation + + \ No newline at end of file diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckBooleanAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckBooleanAnnotation.java new file mode 100644 index 00000000..0aca9fcd --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckBooleanAnnotation.java @@ -0,0 +1,18 @@ +package ink.wgink.annotation; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckBooleanAnnotation + * @Description: TODO + * @Author: WangGeng + * @Date: 2019/11/14 14:50 + * @Version: 1.0 + **/ +public @interface CheckBooleanAnnotation { + + String name(); + + String[] types() default {}; +} diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckEmptyAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckEmptyAnnotation.java new file mode 100644 index 00000000..cb2f3531 --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckEmptyAnnotation.java @@ -0,0 +1,28 @@ +package ink.wgink.annotation; + +import java.lang.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckEmptyAnnotation + * @Description: 校验空 + * @Author: WangGeng + * @Date: 2019/11/14 14:05 + * @Version: 1.0 + **/ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface CheckEmptyAnnotation { + + String name(); + + String[] types() default {}; + + String verifyType() default ""; + + String regex() default ""; + +} diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckListAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckListAnnotation.java new file mode 100644 index 00000000..dbbc96a8 --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckListAnnotation.java @@ -0,0 +1,22 @@ +package ink.wgink.annotation; + +import java.lang.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckListAnnotation + * @Description: 校验List + * @Author: WangGeng + * @Date: 2019/11/15 14:39 + * @Version: 1.0 + **/ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface CheckListAnnotation { + + String name(); + +} diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckNullAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckNullAnnotation.java new file mode 100644 index 00000000..dc89cb3b --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckNullAnnotation.java @@ -0,0 +1,23 @@ +package ink.wgink.annotation; + +import java.lang.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckNullAnno + * @Description: 字段为空校验 + * @Author: WangGeng + * @Date: 2019/11/14 11:31 + * @Version: 1.0 + **/ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface CheckNullAnnotation { + + String name(); + + String[] types() default {}; +} diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckNumberAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckNumberAnnotation.java new file mode 100644 index 00000000..d7b4ff78 --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckNumberAnnotation.java @@ -0,0 +1,28 @@ +package ink.wgink.annotation; + +import java.lang.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckNumberAnnotation + * @Description: 字段为数字校验 + * @Author: WangGeng + * @Date: 2019/11/14 11:31 + * @Version: 1.0 + **/ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD}) +public @interface CheckNumberAnnotation { + + String name(); + + String[] types() default {}; + + double max() default Integer.MAX_VALUE; + + double min() default Integer.MIN_VALUE; + +} diff --git a/basic-annotation/src/main/java/ink/wgink/annotation/CheckRequestBodyAnnotation.java b/basic-annotation/src/main/java/ink/wgink/annotation/CheckRequestBodyAnnotation.java new file mode 100644 index 00000000..5f96ac57 --- /dev/null +++ b/basic-annotation/src/main/java/ink/wgink/annotation/CheckRequestBodyAnnotation.java @@ -0,0 +1,19 @@ +package ink.wgink.annotation; + +import java.lang.annotation.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: CheckRequestBodyAnnotation + * @Description: 校验请求主体 + * @Author: WangGeng + * @Date: 2019/11/14 16:02 + * @Version: 1.0 + **/ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD}) +public @interface CheckRequestBodyAnnotation { +} diff --git a/basic-app/pom.xml b/basic-app/pom.xml index 678ae39d..b895e779 100644 --- a/basic-app/pom.xml +++ b/basic-app/pom.xml @@ -11,9 +11,22 @@ basic-app - - 8 - 8 - + + + ink.wgink + basic-exception + 1.0-SNAPSHOT + + + ink.wgink + basic-interface + 1.0-SNAPSHOT + + + ink.wgink + basic-util + 1.0-SNAPSHOT + + \ No newline at end of file diff --git a/basic-app/src/main/java/ink/wgink/app/AppTokenManager.java b/basic-app/src/main/java/ink/wgink/app/AppTokenManager.java index baab82a0..4afd5087 100644 --- a/basic-app/src/main/java/ink/wgink/app/AppTokenManager.java +++ b/basic-app/src/main/java/ink/wgink/app/AppTokenManager.java @@ -1,16 +1,16 @@ package ink.wgink.app; import com.alibaba.fastjson.JSONObject; -import com.cm.common.constants.ISystemConstant; -import com.cm.common.enums.AppTokenTypeEnum; -import com.cm.common.exception.TokenException; -import com.cm.common.token.app.entity.AppToken; -import com.cm.common.token.app.entity.AppTokenUser; -import com.cm.common.utils.AesUtil; +import ink.wgink.app.entity.AppToken; +import ink.wgink.app.entity.AppTokenUser; +import ink.wgink.app.enums.AppTokenTypeEnum; +import ink.wgink.exceptions.TokenException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.util.AesUtil; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Date; @@ -28,9 +28,9 @@ import java.util.concurrent.ConcurrentHashMap; * @Date: 2019-08-02 11:08 * @Version: 1.0 **/ +@Slf4j public class AppTokenManager { - private static final Logger LOG = LoggerFactory.getLogger(AppTokenManager.class); private static AppTokenManager appTokenManager = AppTokenManagerBuilder.appTokenManager; private static final Map tokens = new ConcurrentHashMap(); @@ -59,7 +59,7 @@ public class AppTokenManager { * 添加token * * @param token - * @param type + * @param appTokenTypeEnum * @param appTokenUser */ public synchronized void addToken(String token, AppTokenTypeEnum appTokenTypeEnum, AppTokenUser appTokenUser) { @@ -83,7 +83,7 @@ public class AppTokenManager { try { userInfo = AesUtil.aesCommonDecoder(ISystemConstant.APP_TOKEN_AES_KEY, new String(Base64.decodeBase64(token), "UTF-8")); } catch (Exception e) { - LOG.error(e.getMessage(), e); + log.error(e.getMessage(), e); throw new TokenException("Token解码异常"); } JSONObject userInfoObj = JSONObject.parseObject(userInfo); @@ -92,23 +92,23 @@ public class AppTokenManager { } String appTokenSign = userInfoObj.getString(ISystemConstant.APP_TOKEN_SIGN); if (StringUtils.isBlank(appTokenSign)) { - LOG.debug("Token标识为空"); + log.debug("Token标识为空"); throw new TokenException("Token非法"); } if (!StringUtils.startsWith(appTokenSign, ISystemConstant.APP_TOKEN_VERIFY)) { - LOG.debug("Token标识开头错误"); + log.debug("Token标识开头错误"); throw new TokenException("Token非法"); } String[] appTokenSignArray = appTokenSign.split("_"); if (appTokenSignArray.length != 3) { - LOG.debug("Token标识格式长度异常,应为3,这里为:{}", appTokenSignArray.length); + log.debug("Token标识格式长度异常,应为3,这里为:{}", appTokenSignArray.length); throw new TokenException("Token非法"); } try { new Date(Long.parseLong(appTokenSignArray[2])); } catch (NumberFormatException e) { e.printStackTrace(); - LOG.debug("Token时间戳异常"); + log.debug("Token时间戳异常"); throw new TokenException("Token非法"); } return JSONObject.toJavaObject(userInfoObj, AppTokenUser.class); @@ -144,7 +144,7 @@ public class AppTokenManager { for (String tokenKey : clearTokenKeys) { tokens.remove(tokenKey); } - LOG.debug("本次共清理超时Token:{}个", clearTokenKeys.size()); + log.debug("本次共清理超时Token:{}个", clearTokenKeys.size()); } private static class AppTokenManagerBuilder { diff --git a/basic-exception/pom.xml b/basic-exception/pom.xml index 8baa1f9d..72fee03a 100644 --- a/basic-exception/pom.xml +++ b/basic-exception/pom.xml @@ -11,9 +11,4 @@ basic-exception - - 8 - 8 - - \ No newline at end of file diff --git a/basic-interface/pom.xml b/basic-interface/pom.xml index 70a74a35..f90abb08 100644 --- a/basic-interface/pom.xml +++ b/basic-interface/pom.xml @@ -18,7 +18,6 @@ 1.0-SNAPSHOT - \ No newline at end of file diff --git a/basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentService.java b/basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentBaseService.java similarity index 87% rename from basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentService.java rename to basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentBaseService.java index 066119f1..f561c6ba 100644 --- a/basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentService.java +++ b/basic-interface/src/main/java/ink/wgink/interfaces/department/IDepartmentBaseService.java @@ -10,5 +10,5 @@ package ink.wgink.interfaces.department; * @Date: 2021/1/24 12:53 * @Version: 1.0 **/ -public interface IDepartmentService { +public interface IDepartmentBaseService { } diff --git a/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserBaseService.java b/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserBaseService.java new file mode 100644 index 00000000..37667b85 --- /dev/null +++ b/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserBaseService.java @@ -0,0 +1,54 @@ +package ink.wgink.interfaces.user; + +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.dtos.user.UserDTO; +import ink.wgink.pojo.result.SuccessResultList; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IUserService + * @Description: 用户 + * @Author: WangGeng + * @Date: 2021/1/24 12:52 + * @Version: 1.0 + **/ +public interface IUserBaseService { + + /** + * 用户详情 + * + * @param userId 用户ID + * @return + */ + UserDTO get(String userId); + + /** + * 用户详情 + * + * @param username 用户名 + * @return + */ + UserDTO getByUsername(String username); + + /** + * 用户列表 + * + * @param params + * @return + */ + List list(Map params); + + /** + * 用户分页列表 + * + * @param page + * @return + */ + SuccessResultList> listPage(ListPage page); + +} diff --git a/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserService.java b/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserService.java deleted file mode 100644 index 6531757e..00000000 --- a/basic-interface/src/main/java/ink/wgink/interfaces/user/IUserService.java +++ /dev/null @@ -1,14 +0,0 @@ -package ink.wgink.interfaces.user; - -/** - * When you feel like quitting. Think about why you started - * 当你想要放弃的时候,想想当初你为何开始 - * - * @ClassName: IUserService - * @Description: 用户 - * @Author: WangGeng - * @Date: 2021/1/24 12:52 - * @Version: 1.0 - **/ -public interface IUserService { -} diff --git a/basic-pojo/pom.xml b/basic-pojo/pom.xml index f9264f55..d1109b1f 100644 --- a/basic-pojo/pom.xml +++ b/basic-pojo/pom.xml @@ -12,6 +12,19 @@ basic-pojo + + + org.apache.tomcat.embed + tomcat-embed-core + compile + + + + + org.projectlombok + lombok + + org.springframework.security diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/bos/RoleGrantedAuthority.java b/basic-pojo/src/main/java/ink/wgink/pojo/bos/RoleGrantedAuthority.java index 522a0abb..b707f8c2 100644 --- a/basic-pojo/src/main/java/ink/wgink/pojo/bos/RoleGrantedAuthority.java +++ b/basic-pojo/src/main/java/ink/wgink/pojo/bos/RoleGrantedAuthority.java @@ -28,16 +28,16 @@ public class RoleGrantedAuthority implements GrantedAuthority { private List routeSaveMenu; private List routeUpdateMenu; private List routeQueryMenu; - private List permissionInsert; - private List permissionDelete; - private List permissionUpdate; - private List permissionQuery; + private List permissionInsert; + private List permissionDelete; + private List permissionUpdate; + private List permissionQuery; public RoleGrantedAuthority(String role) { this.role = role; } - public RoleGrantedAuthority(String role, com.cm.common.pojo.bos.RoleBO roleBO) { + public RoleGrantedAuthority(String role, RoleBO roleBO) { this.role = role; this.roleId = roleBO.getRoleId(); this.roleName = roleBO.getRoleName(); @@ -181,35 +181,35 @@ public class RoleGrantedAuthority implements GrantedAuthority { this.routeQueryMenu = routeQueryMenu; } - public List getPermissionInsert() { + public List getPermissionInsert() { return permissionInsert; } - public void setPermissionInsert(List permissionInsert) { + public void setPermissionInsert(List permissionInsert) { this.permissionInsert = permissionInsert; } - public List getPermissionDelete() { + public List getPermissionDelete() { return permissionDelete; } - public void setPermissionDelete(List permissionDelete) { + public void setPermissionDelete(List permissionDelete) { this.permissionDelete = permissionDelete; } - public List getPermissionUpdate() { + public List getPermissionUpdate() { return permissionUpdate; } - public void setPermissionUpdate(List permissionUpdate) { + public void setPermissionUpdate(List permissionUpdate) { this.permissionUpdate = permissionUpdate; } - public List getPermissionQuery() { + public List getPermissionQuery() { return permissionQuery; } - public void setPermissionQuery(List permissionQuery) { + public void setPermissionQuery(List permissionQuery) { this.permissionQuery = permissionQuery; } diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentDTO.java b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentDTO.java new file mode 100644 index 00000000..4a453eba --- /dev/null +++ b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentDTO.java @@ -0,0 +1,39 @@ +package ink.wgink.pojo.dtos.department; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName: DepartmentDTO + * @Description: 组织部门 + * @Author: wenc + * @Date: 2019/1/8 7:43 PM + * @Version: 1.0 + **/ +@ApiModel +public class DepartmentDTO extends DepartmentSimpleDTO { + + private static final long serialVersionUID = -6682276871851732246L; + @ApiModelProperty(name = "subDepartments", value = "组织部门子列表") + private List subDepartments; + + public List getSubDepartments() { + return subDepartments == null ? new ArrayList<>() : subDepartments; + } + + public void setSubDepartments(List subDepartments) { + this.subDepartments = subDepartments; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"subDepartments\":") + .append(subDepartments); + sb.append('}'); + return sb.toString(); + } +} diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentSimpleDTO.java b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentSimpleDTO.java new file mode 100644 index 00000000..610d2d21 --- /dev/null +++ b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/department/DepartmentSimpleDTO.java @@ -0,0 +1,471 @@ +package ink.wgink.pojo.dtos.department; + +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentSimpleDTO + * @Description: 组织机构(简单) + * @Author: WangGeng + * @Date: 2020/4/28 12:11 + * @Version: 1.0 + **/ +public class DepartmentSimpleDTO implements Serializable { + + private static final long serialVersionUID = 595737776232939256L; + @ApiModelProperty(name = "departmentIntId", value = "组织部门ID") + private Long departmentIntId; + @ApiModelProperty(name = "departmentId", value = "组织部门ID") + private String departmentId; + @ApiModelProperty(name = "departmentParentId", value = "组织部门上级ID") + private String departmentParentId; + @ApiModelProperty(name = "departmentParentName", value = "组织部门上级名称") + private String departmentParentName; + @ApiModelProperty(name = "departmentName", value = "组织部门名称") + private String departmentName; + @ApiModelProperty(name = "departmentNameEn", value = "组织部门名称(英文)") + private String departmentNameEn; + @ApiModelProperty(name = "departmentNameOther", value = "组织部门名称(其他类型)") + private String departmentNameOther; + @ApiModelProperty(name = "departmentCode", value = "组织部门编码") + private String departmentCode; + @ApiModelProperty(name = "departmentSummary", value = "组织部门说明") + private String departmentSummary; + @ApiModelProperty(name = "departmentLogo", value = "组织部门图标ID") + private Long departmentLogo; + @ApiModelProperty(name = "departmentLogoHover", value = "组织部门图标ID(选中)") + private Long departmentLogoHover; + @ApiModelProperty(name = "departmentType", value = "组织部门类别,1:机构,2:部门") + private Integer departmentType; + @ApiModelProperty(name = "departmentState", value = "组织部门状态,0:正常,1:锁定:2:冻结") + private Integer departmentState; + @ApiModelProperty(name = "departmentFax", value = "组织部门传真") + private String departmentFax; + @ApiModelProperty(name = "departmentTel", value = "组织部门电话") + private String departmentTel; + @ApiModelProperty(name = "departmentAddress", value = "组织部门地址") + private String departmentAddress; + @ApiModelProperty(name = "departmentMaster", value = "组织部门负责人") + private String departmentMaster; + @ApiModelProperty(name = "departmentMasterName", value = "组织部门负责人名称") + private String departmentMasterName; + @ApiModelProperty(name = "departmentDuty", value = "组织部门职责") + private String departmentDuty; + @ApiModelProperty(name = "departmentArea1Id", value = "1级区域ID") + private String departmentArea1Id; + @ApiModelProperty(name = "departmentArea1Code", value = "1级区域编码") + private String departmentArea1Code; + @ApiModelProperty(name = "departmentArea1Name", value = "1级区域名称") + private String departmentArea1Name; + @ApiModelProperty(name = "departmentArea2Id", value = "2级区域ID") + private String departmentArea2Id; + @ApiModelProperty(name = "departmentArea2Code", value = "2级区域编码") + private String departmentArea2Code; + @ApiModelProperty(name = "departmentArea2Name", value = "2级区域名称") + private String departmentArea2Name; + @ApiModelProperty(name = "departmentArea3Id", value = "3级区域ID") + private String departmentArea3Id; + @ApiModelProperty(name = "departmentArea3Code", value = "3级区域编码") + private String departmentArea3Code; + @ApiModelProperty(name = "departmentArea3Name", value = "3级区域名称") + private String departmentArea3Name; + @ApiModelProperty(name = "departmentArea4Id", value = "4级区域ID") + private String departmentArea4Id; + @ApiModelProperty(name = "departmentArea4Code", value = "4级区域编码") + private String departmentArea4Code; + @ApiModelProperty(name = "departmentArea4Name", value = "4级区域名称") + private String departmentArea4Name; + @ApiModelProperty(name = "departmentArea5Id", value = "5级区域ID") + private String departmentArea5Id; + @ApiModelProperty(name = "departmentArea5Code", value = "5级区域编码") + private String departmentArea5Code; + @ApiModelProperty(name = "departmentArea5Name", value = "5级区域名称") + private String departmentArea5Name; + @ApiModelProperty(name = "departmentLongitude", value = "组织部门经度") + private String departmentLongitude; + @ApiModelProperty(name = "departmentLatitude", value = "组织部门纬度") + private String departmentLatitude; + @ApiModelProperty(name = "departmentOrder", value = "组织部门排序,默认0") + private String departmentOrder; + + public Long getDepartmentIntId() { + return departmentIntId; + } + + public void setDepartmentIntId(Long departmentIntId) { + this.departmentIntId = departmentIntId; + } + + public String getDepartmentId() { + return departmentId == null ? "" : departmentId; + } + + public void setDepartmentId(String departmentId) { + this.departmentId = departmentId; + } + + public String getDepartmentParentId() { + return departmentParentId == null ? "" : departmentParentId; + } + + public void setDepartmentParentId(String departmentParentId) { + this.departmentParentId = departmentParentId; + } + + public String getDepartmentParentName() { + return departmentParentName == null ? "" : departmentParentName; + } + + public void setDepartmentParentName(String departmentParentName) { + this.departmentParentName = departmentParentName; + } + + public String getDepartmentName() { + return departmentName == null ? "" : departmentName; + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + public String getDepartmentNameEn() { + return departmentNameEn == null ? "" : departmentNameEn; + } + + public void setDepartmentNameEn(String departmentNameEn) { + this.departmentNameEn = departmentNameEn; + } + + public String getDepartmentNameOther() { + return departmentNameOther == null ? "" : departmentNameOther; + } + + public void setDepartmentNameOther(String departmentNameOther) { + this.departmentNameOther = departmentNameOther; + } + + public String getDepartmentCode() { + return departmentCode == null ? "" : departmentCode; + } + + public void setDepartmentCode(String departmentCode) { + this.departmentCode = departmentCode; + } + + public String getDepartmentSummary() { + return departmentSummary == null ? "" : departmentSummary; + } + + public void setDepartmentSummary(String departmentSummary) { + this.departmentSummary = departmentSummary; + } + + public Long getDepartmentLogo() { + return departmentLogo; + } + + public void setDepartmentLogo(Long departmentLogo) { + this.departmentLogo = departmentLogo; + } + + public Long getDepartmentLogoHover() { + return departmentLogoHover; + } + + public void setDepartmentLogoHover(Long departmentLogoHover) { + this.departmentLogoHover = departmentLogoHover; + } + + public Integer getDepartmentType() { + return departmentType; + } + + public void setDepartmentType(Integer departmentType) { + this.departmentType = departmentType; + } + + public Integer getDepartmentState() { + return departmentState; + } + + public void setDepartmentState(Integer departmentState) { + this.departmentState = departmentState; + } + + public String getDepartmentFax() { + return departmentFax == null ? "" : departmentFax; + } + + public void setDepartmentFax(String departmentFax) { + this.departmentFax = departmentFax; + } + + public String getDepartmentTel() { + return departmentTel == null ? "" : departmentTel; + } + + public void setDepartmentTel(String departmentTel) { + this.departmentTel = departmentTel; + } + + public String getDepartmentAddress() { + return departmentAddress == null ? "" : departmentAddress; + } + + public void setDepartmentAddress(String departmentAddress) { + this.departmentAddress = departmentAddress; + } + + public String getDepartmentMaster() { + return departmentMaster == null ? "" : departmentMaster; + } + + public void setDepartmentMaster(String departmentMaster) { + this.departmentMaster = departmentMaster; + } + + public String getDepartmentMasterName() { + return departmentMasterName == null ? "" : departmentMasterName; + } + + public void setDepartmentMasterName(String departmentMasterName) { + this.departmentMasterName = departmentMasterName; + } + + public String getDepartmentDuty() { + return departmentDuty == null ? "" : departmentDuty; + } + + public void setDepartmentDuty(String departmentDuty) { + this.departmentDuty = departmentDuty; + } + + public String getDepartmentArea1Id() { + return departmentArea1Id == null ? "" : departmentArea1Id; + } + + public void setDepartmentArea1Id(String departmentArea1Id) { + this.departmentArea1Id = departmentArea1Id; + } + + public String getDepartmentArea1Code() { + return departmentArea1Code == null ? "" : departmentArea1Code; + } + + public void setDepartmentArea1Code(String departmentArea1Code) { + this.departmentArea1Code = departmentArea1Code; + } + + public String getDepartmentArea1Name() { + return departmentArea1Name == null ? "" : departmentArea1Name; + } + + public void setDepartmentArea1Name(String departmentArea1Name) { + this.departmentArea1Name = departmentArea1Name; + } + + public String getDepartmentArea2Id() { + return departmentArea2Id == null ? "" : departmentArea2Id; + } + + public void setDepartmentArea2Id(String departmentArea2Id) { + this.departmentArea2Id = departmentArea2Id; + } + + public String getDepartmentArea2Code() { + return departmentArea2Code == null ? "" : departmentArea2Code; + } + + public void setDepartmentArea2Code(String departmentArea2Code) { + this.departmentArea2Code = departmentArea2Code; + } + + public String getDepartmentArea2Name() { + return departmentArea2Name == null ? "" : departmentArea2Name; + } + + public void setDepartmentArea2Name(String departmentArea2Name) { + this.departmentArea2Name = departmentArea2Name; + } + + public String getDepartmentArea3Id() { + return departmentArea3Id == null ? "" : departmentArea3Id; + } + + public void setDepartmentArea3Id(String departmentArea3Id) { + this.departmentArea3Id = departmentArea3Id; + } + + public String getDepartmentArea3Code() { + return departmentArea3Code == null ? "" : departmentArea3Code; + } + + public void setDepartmentArea3Code(String departmentArea3Code) { + this.departmentArea3Code = departmentArea3Code; + } + + public String getDepartmentArea3Name() { + return departmentArea3Name == null ? "" : departmentArea3Name; + } + + public void setDepartmentArea3Name(String departmentArea3Name) { + this.departmentArea3Name = departmentArea3Name; + } + + public String getDepartmentArea4Id() { + return departmentArea4Id == null ? "" : departmentArea4Id; + } + + public void setDepartmentArea4Id(String departmentArea4Id) { + this.departmentArea4Id = departmentArea4Id; + } + + public String getDepartmentArea4Code() { + return departmentArea4Code == null ? "" : departmentArea4Code; + } + + public void setDepartmentArea4Code(String departmentArea4Code) { + this.departmentArea4Code = departmentArea4Code; + } + + public String getDepartmentArea4Name() { + return departmentArea4Name == null ? "" : departmentArea4Name; + } + + public void setDepartmentArea4Name(String departmentArea4Name) { + this.departmentArea4Name = departmentArea4Name; + } + + public String getDepartmentArea5Id() { + return departmentArea5Id == null ? "" : departmentArea5Id; + } + + public void setDepartmentArea5Id(String departmentArea5Id) { + this.departmentArea5Id = departmentArea5Id; + } + + public String getDepartmentArea5Code() { + return departmentArea5Code == null ? "" : departmentArea5Code; + } + + public void setDepartmentArea5Code(String departmentArea5Code) { + this.departmentArea5Code = departmentArea5Code; + } + + public String getDepartmentArea5Name() { + return departmentArea5Name == null ? "" : departmentArea5Name; + } + + public void setDepartmentArea5Name(String departmentArea5Name) { + this.departmentArea5Name = departmentArea5Name; + } + + public String getDepartmentLongitude() { + return departmentLongitude == null ? "" : departmentLongitude; + } + + public void setDepartmentLongitude(String departmentLongitude) { + this.departmentLongitude = departmentLongitude; + } + + public String getDepartmentLatitude() { + return departmentLatitude == null ? "" : departmentLatitude; + } + + public void setDepartmentLatitude(String departmentLatitude) { + this.departmentLatitude = departmentLatitude; + } + + public String getDepartmentOrder() { + return departmentOrder == null ? "" : departmentOrder; + } + + public void setDepartmentOrder(String departmentOrder) { + this.departmentOrder = departmentOrder; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"departmentIntId\":") + .append(departmentIntId); + sb.append(",\"departmentId\":\"") + .append(departmentId).append('\"'); + sb.append(",\"departmentParentId\":\"") + .append(departmentParentId).append('\"'); + sb.append(",\"departmentParentName\":\"") + .append(departmentParentName).append('\"'); + sb.append(",\"departmentName\":\"") + .append(departmentName).append('\"'); + sb.append(",\"departmentNameEn\":\"") + .append(departmentNameEn).append('\"'); + sb.append(",\"departmentNameOther\":\"") + .append(departmentNameOther).append('\"'); + sb.append(",\"departmentCode\":\"") + .append(departmentCode).append('\"'); + sb.append(",\"departmentSummary\":\"") + .append(departmentSummary).append('\"'); + sb.append(",\"departmentLogo\":") + .append(departmentLogo); + sb.append(",\"departmentLogoHover\":") + .append(departmentLogoHover); + sb.append(",\"departmentType\":") + .append(departmentType); + sb.append(",\"departmentState\":") + .append(departmentState); + sb.append(",\"departmentFax\":\"") + .append(departmentFax).append('\"'); + sb.append(",\"departmentTel\":\"") + .append(departmentTel).append('\"'); + sb.append(",\"departmentAddress\":\"") + .append(departmentAddress).append('\"'); + sb.append(",\"departmentMaster\":\"") + .append(departmentMaster).append('\"'); + sb.append(",\"departmentMasterName\":\"") + .append(departmentMasterName).append('\"'); + sb.append(",\"departmentDuty\":\"") + .append(departmentDuty).append('\"'); + sb.append(",\"departmentArea1Id\":\"") + .append(departmentArea1Id).append('\"'); + sb.append(",\"departmentArea1Code\":\"") + .append(departmentArea1Code).append('\"'); + sb.append(",\"departmentArea1Name\":\"") + .append(departmentArea1Name).append('\"'); + sb.append(",\"departmentArea2Id\":\"") + .append(departmentArea2Id).append('\"'); + sb.append(",\"departmentArea2Code\":\"") + .append(departmentArea2Code).append('\"'); + sb.append(",\"departmentArea2Name\":\"") + .append(departmentArea2Name).append('\"'); + sb.append(",\"departmentArea3Id\":\"") + .append(departmentArea3Id).append('\"'); + sb.append(",\"departmentArea3Code\":\"") + .append(departmentArea3Code).append('\"'); + sb.append(",\"departmentArea3Name\":\"") + .append(departmentArea3Name).append('\"'); + sb.append(",\"departmentArea4Id\":\"") + .append(departmentArea4Id).append('\"'); + sb.append(",\"departmentArea4Code\":\"") + .append(departmentArea4Code).append('\"'); + sb.append(",\"departmentArea4Name\":\"") + .append(departmentArea4Name).append('\"'); + sb.append(",\"departmentArea5Id\":\"") + .append(departmentArea5Id).append('\"'); + sb.append(",\"departmentArea5Code\":\"") + .append(departmentArea5Code).append('\"'); + sb.append(",\"departmentArea5Name\":\"") + .append(departmentArea5Name).append('\"'); + sb.append(",\"departmentLongitude\":\"") + .append(departmentLongitude).append('\"'); + sb.append(",\"departmentLatitude\":\"") + .append(departmentLatitude).append('\"'); + sb.append(",\"departmentOrder\":\"") + .append(departmentOrder).append('\"'); + sb.append('}'); + return sb.toString(); + } +} diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/UserAttrInfoDTO.java b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserAttrInfoDTO.java similarity index 93% rename from basic-pojo/src/main/java/ink/wgink/pojo/dtos/UserAttrInfoDTO.java rename to basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserAttrInfoDTO.java index bee82704..849cfb26 100644 --- a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/UserAttrInfoDTO.java +++ b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserAttrInfoDTO.java @@ -1,9 +1,9 @@ -package ink.wgink.pojo.dtos; +package ink.wgink.pojo.dtos.user; -import com.cm.common.pojo.bos.DepartmentBO; -import com.cm.common.pojo.bos.GroupBO; -import com.cm.common.pojo.bos.PositionBO; -import com.cm.common.pojo.bos.RoleBO; +import ink.wgink.pojo.bos.DepartmentBO; +import ink.wgink.pojo.bos.GroupBO; +import ink.wgink.pojo.bos.PositionBO; +import ink.wgink.pojo.bos.RoleBO; import java.util.List; diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserDTO.java b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserDTO.java new file mode 100644 index 00000000..9e0554a4 --- /dev/null +++ b/basic-pojo/src/main/java/ink/wgink/pojo/dtos/user/UserDTO.java @@ -0,0 +1,274 @@ +package ink.wgink.pojo.dtos.user; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * @author WangGeng + */ +@ApiModel +public class UserDTO implements Serializable { + + private static final long serialVersionUID = -4381097524161926625L; + @ApiModelProperty(name = "userId", value = "用户ID") + private String userId; + @ApiModelProperty(name = "userUsername", value = "用户名") + private String userUsername; + @ApiModelProperty(name = "userName", value = "用户昵称") + private String userName; + @ApiModelProperty(name = "userPhone", value = "用户电话") + private String userPhone; + @ApiModelProperty(name = "userEmail", value = "用户邮件") + private String userEmail; + @ApiModelProperty(name = "userUKey", value = "UKey") + private String userUKey; + @ApiModelProperty(name = "userType", value = "用户类型,1:系统用户,2:普通用户") + private Integer userType; + @ApiModelProperty(name = "userState", value = "用户状态,0:正常,1:冻结") + private Integer userState; + @ApiModelProperty(name = "userAvatar", value = "用户头像ID") + private String userAvatar; + @ApiModelProperty(name = "lastLoginAddress", value = "最后登录IP") + private String lastLoginAddress; + @ApiModelProperty(name = "lastLoginTime", value = "最后登录时间") + private String lastLoginTime; + @ApiModelProperty(name = "userLongitude", value = "用户经度") + private String userLongitude; + @ApiModelProperty(name = "userLatitude", value = "用户纬度") + private String userLatitude; + @ApiModelProperty(name = "departmentIds", value = "组织部门ID") + private String departmentIds; + @ApiModelProperty(name = "departmentNames", value = "组织部门名称") + private String departmentNames; + @ApiModelProperty(name = "roleIds", value = "角色ID") + private String roleIds; + @ApiModelProperty(name = "roleNames", value = "角色名称") + private String roleNames; + @ApiModelProperty(name = "positionIds", value = "职位ID") + private String positionIds; + @ApiModelProperty(name = "positionNames", value = "职位名称") + private String positionNames; + @ApiModelProperty(name = "loginType", value = "登录类型") + private Integer loginType; + @ApiModelProperty(name = "gmtCreate", value = "创建时间") + private String gmtCreate; + + public String getUserId() { + return userId == null ? "" : userId.trim(); + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserUsername() { + return userUsername == null ? "" : userUsername.trim(); + } + + public void setUserUsername(String userUsername) { + this.userUsername = userUsername; + } + + public String getUserName() { + return userName == null ? "" : userName.trim(); + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserPhone() { + return userPhone == null ? "" : userPhone.trim(); + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public String getUserEmail() { + return userEmail == null ? "" : userEmail.trim(); + } + + public void setUserEmail(String userEmail) { + this.userEmail = userEmail; + } + + public String getUserUKey() { + return userUKey == null ? "" : userUKey; + } + + public void setUserUKey(String userUKey) { + this.userUKey = userUKey; + } + + public Integer getUserType() { + return userType; + } + + public void setUserType(Integer userType) { + this.userType = userType; + } + + public Integer getUserState() { + return userState; + } + + public void setUserState(Integer userState) { + this.userState = userState; + } + + public String getUserAvatar() { + return userAvatar == null ? "" : userAvatar.trim(); + } + + public void setUserAvatar(String userAvatar) { + this.userAvatar = userAvatar; + } + + public String getLastLoginAddress() { + return lastLoginAddress == null ? "" : lastLoginAddress.trim(); + } + + public void setLastLoginAddress(String lastLoginAddress) { + this.lastLoginAddress = lastLoginAddress; + } + + public String getLastLoginTime() { + return lastLoginTime == null ? "" : lastLoginTime.trim(); + } + + public void setLastLoginTime(String lastLoginTime) { + this.lastLoginTime = lastLoginTime; + } + + public String getUserLongitude() { + return userLongitude == null ? "" : userLongitude.trim(); + } + + public void setUserLongitude(String userLongitude) { + this.userLongitude = userLongitude; + } + + public String getUserLatitude() { + return userLatitude == null ? "" : userLatitude.trim(); + } + + public void setUserLatitude(String userLatitude) { + this.userLatitude = userLatitude; + } + + public String getDepartmentIds() { + return departmentIds == null ? "" : departmentIds.trim(); + } + + public void setDepartmentIds(String departmentIds) { + this.departmentIds = departmentIds; + } + + public String getDepartmentNames() { + return departmentNames == null ? "" : departmentNames.trim(); + } + + public void setDepartmentNames(String departmentNames) { + this.departmentNames = departmentNames; + } + + public String getRoleIds() { + return roleIds == null ? "" : roleIds.trim(); + } + + public void setRoleIds(String roleIds) { + this.roleIds = roleIds; + } + + public String getRoleNames() { + return roleNames == null ? "" : roleNames.trim(); + } + + public void setRoleNames(String roleNames) { + this.roleNames = roleNames; + } + + public String getPositionIds() { + return positionIds == null ? "" : positionIds.trim(); + } + + public void setPositionIds(String positionIds) { + this.positionIds = positionIds; + } + + public String getPositionNames() { + return positionNames == null ? "" : positionNames.trim(); + } + + public void setPositionNames(String positionNames) { + this.positionNames = positionNames; + } + + public Integer getLoginType() { + return loginType; + } + + public void setLoginType(Integer loginType) { + this.loginType = loginType; + } + + public String getGmtCreate() { + return gmtCreate == null ? "" : gmtCreate.trim(); + } + + public void setGmtCreate(String gmtCreate) { + this.gmtCreate = gmtCreate; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"userId\":") + .append("\"").append(userId).append("\""); + sb.append(",\"userUsername\":") + .append("\"").append(userUsername).append("\""); + sb.append(",\"userName\":") + .append("\"").append(userName).append("\""); + sb.append(",\"userPhone\":") + .append("\"").append(userPhone).append("\""); + sb.append(",\"userEmail\":") + .append("\"").append(userEmail).append("\""); + sb.append(",\"userUKey\":") + .append("\"").append(userUKey).append("\""); + sb.append(",\"userType\":") + .append(userType); + sb.append(",\"userState\":") + .append(userState); + sb.append(",\"userAvatar\":") + .append("\"").append(userAvatar).append("\""); + sb.append(",\"lastLoginAddress\":") + .append("\"").append(lastLoginAddress).append("\""); + sb.append(",\"lastLoginTime\":") + .append("\"").append(lastLoginTime).append("\""); + sb.append(",\"userLongitude\":") + .append("\"").append(userLongitude).append("\""); + sb.append(",\"userLatitude\":") + .append("\"").append(userLatitude).append("\""); + sb.append(",\"departmentIds\":") + .append("\"").append(departmentIds).append("\""); + sb.append(",\"departmentNames\":") + .append("\"").append(departmentNames).append("\""); + sb.append(",\"roleIds\":") + .append("\"").append(roleIds).append("\""); + sb.append(",\"roleNames\":") + .append("\"").append(roleNames).append("\""); + sb.append(",\"positionIds\":") + .append("\"").append(positionIds).append("\""); + sb.append(",\"positionNames\":") + .append("\"").append(positionNames).append("\""); + sb.append(",\"loginType\":") + .append(loginType); + sb.append(",\"gmtCreate\":") + .append("\"").append(gmtCreate).append("\""); + sb.append('}'); + return sb.toString(); + } +} diff --git a/basic-util/pom.xml b/basic-util/pom.xml index 8a7de1c1..c7bd64a4 100644 --- a/basic-util/pom.xml +++ b/basic-util/pom.xml @@ -106,7 +106,6 @@ com.alibaba fastjson - ${fastjson.version} diff --git a/basic-util/src/main/java/ink/wgink/util/AddressUtil.java b/basic-util/src/main/java/ink/wgink/util/AddressUtil.java new file mode 100644 index 00000000..268b08e2 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/AddressUtil.java @@ -0,0 +1,171 @@ +package ink.wgink.util; + +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; + +/** + * IP和MAC地址工具类 + */ +public class AddressUtil { + + /** + * 获取MAC地址,可能会为空 + * + * @return + * @throws Exception + */ + @Deprecated + public static final String getMacAddress() throws Exception { + InetAddress inetAddress = InetAddress.getLocalHost(); + byte[] mac = NetworkInterface.getByInetAddress(inetAddress).getHardwareAddress(); + StringBuilder macAddress = new StringBuilder(); + for (byte macByte : mac) { + if (macAddress.length() > 0) { + macAddress.append("-"); + } + int macInt = macByte & 0xff; + String str = Integer.toHexString(macInt); + macAddress.append(str.length() == 1 ? 0 + str : str); + } + return macAddress.toString().toUpperCase(); + } + + /** + * 此方法描述的是:获得服务器的IP地址 + */ + public static String getLocalIP() throws Exception { + String sIP = ""; + InetAddress ip = null; + boolean bFindIP = false; + Enumeration netInterfaces = (Enumeration) NetworkInterface + .getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + if (bFindIP) { + break; + } + NetworkInterface ni = (NetworkInterface) netInterfaces + .nextElement(); + + Enumeration ips = ni.getInetAddresses(); + while (ips.hasMoreElements()) { + ip = (InetAddress) ips.nextElement(); + if (!ip.isLoopbackAddress() + && ip.getHostAddress().matches( + "(\\d{1,3}\\.){3}\\d{1,3}")) { + bFindIP = true; + break; + } + } + } + if (null != ip) { + sIP = ip.getHostAddress(); + } + return sIP; + } + + /** + * 此方法描述的是:获得服务器的IP地址(多网卡) + */ + public static List getLocalIPS() throws Exception { + InetAddress ip = null; + List ipList = new ArrayList(); + Enumeration netInterfaces = (Enumeration) NetworkInterface + .getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + NetworkInterface ni = (NetworkInterface) netInterfaces + .nextElement(); + Enumeration ips = ni.getInetAddresses(); + while (ips.hasMoreElements()) { + ip = (InetAddress) ips.nextElement(); + if (!ip.isLoopbackAddress() + && ip.getHostAddress().matches( + "(\\d{1,3}\\.){3}\\d{1,3}")) { + ipList.add(ip.getHostAddress()); + } + } + } + return ipList; + } + + /** + * 获得服务器的MAC地址 + */ + public static String getMacId() throws Exception { + String macId = ""; + InetAddress ip = null; + NetworkInterface ni = null; + boolean bFindIP = false; + Enumeration netInterfaces = (Enumeration) NetworkInterface + .getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + if (bFindIP) { + break; + } + ni = (NetworkInterface) netInterfaces + .nextElement(); + Enumeration ips = ni.getInetAddresses(); + while (ips.hasMoreElements()) { + ip = (InetAddress) ips.nextElement(); + // 非127.0.0.1 + if (!ip.isLoopbackAddress() + && ip.getHostAddress().matches( + "(\\d{1,3}\\.){3}\\d{1,3}")) { + bFindIP = true; + break; + } + } + } + if (null != ip) { + macId = getMacFromBytes(ni.getHardwareAddress()); + } + return macId; + } + + /** + * 获得服务器的MAC地址(多网卡) + */ + public static List getMacIds() throws Exception { + InetAddress ip = null; + NetworkInterface ni = null; + List macList = new ArrayList(); + Enumeration netInterfaces = (Enumeration) NetworkInterface + .getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + ni = (NetworkInterface) netInterfaces + .nextElement(); + // ----------特定情况,可以考虑用ni.getName判断 + // 遍历所有ip + Enumeration ips = ni.getInetAddresses(); + while (ips.hasMoreElements()) { + ip = (InetAddress) ips.nextElement(); + if (!ip.isLoopbackAddress() // 非127.0.0.1 + && ip.getHostAddress().matches( + "(\\d{1,3}\\.){3}\\d{1,3}")) { + macList.add(getMacFromBytes(ni.getHardwareAddress())); + } + } + } + return macList; + } + + private static String getMacFromBytes(byte[] bytes) { + StringBuffer mac = new StringBuffer(); + byte currentByte; + boolean first = false; + for (byte b : bytes) { + if (first) { + mac.append("-"); + } + currentByte = (byte) ((b & 240) >> 4); + mac.append(Integer.toHexString(currentByte)); + currentByte = (byte) (b & 15); + mac.append(Integer.toHexString(currentByte)); + first = true; + } + return mac.toString().toUpperCase(); + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/AesUtil.java b/basic-util/src/main/java/ink/wgink/util/AesUtil.java new file mode 100644 index 00000000..199d5671 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/AesUtil.java @@ -0,0 +1,157 @@ +package ink.wgink.util; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.codec.binary.StringUtils; + +import javax.crypto.Cipher; +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import java.security.SecureRandom; +import java.security.Security; + +public class AesUtil { + + private static final String IV_STRING = "16-Bytes--String"; + /** + * PKCS#7 + */ + public static final String PKCS_7 = "PKCS7Padding"; + /** + * PKCS#5 + */ + public static final String PKCS_5 = "PKCS5Padding"; + + /** + * AES加密 + * + * @param encodeRule + * @param content + * @return + * @throws Exception + */ + public static String aesEncoder(String encodeRule, String content) throws Exception { + // 1.构造秘钥生成器 + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + // 2.根据编码规则构建秘钥生成器 + SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); + random.setSeed(encodeRule.getBytes()); + keyGenerator.init(128, random); + // 3.产生堆成秘钥 + SecretKey secretKey = keyGenerator.generateKey(); + // 4.对称秘钥原始数组 + byte[] secretKeyByte = secretKey.getEncoded(); + // 5.生成AES秘钥 + SecretKey key = new SecretKeySpec(secretKeyByte, "AES"); + // 6.初始化密码器 + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.ENCRYPT_MODE, key); + // 8.获取加密内容字节数组 + byte[] contentByte = content.getBytes("UTF-8"); + // 9.加密 + return new String(Base64.encodeBase64(cipher.doFinal(contentByte))); + } + + /** + * AES解密 + * + * @param encodeRule + * @param content + * @return + * @throws Exception + */ + public static String aesDecoder(String encodeRule, String content) throws Exception { + // 1.构建秘钥生成器 + KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); + // 2.根据编码规则构建秘钥生成器 + SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); + random.setSeed(encodeRule.getBytes()); + keyGenerator.init(128, random); + // 3.生成对称解密秘钥 + SecretKey secretKey = keyGenerator.generateKey(); + // 4.对称秘钥原始数组 + byte[] secretKeyByte = secretKey.getEncoded(); + // 5.生成AES秘钥 + SecretKey key = new SecretKeySpec(secretKeyByte, "AES"); + // 6.初始化密码器 + Cipher cipher = Cipher.getInstance("AES"); + cipher.init(Cipher.DECRYPT_MODE, key); + // 7.要解密内容的字节数组 + byte[] contentByte = Base64.decodeBase64(content); + // 8.解密 + return new String(cipher.doFinal(contentByte), "UTF-8"); + } + + /** + * 通用aes加密,兼容IOS + * + * @param key + * @param content + * @return + * @throws Exception + */ + public static String aesCommonEncoder(String key, String content) throws Exception { + byte[] encryptedBytes = aesCommonEncodeDetail(key, content, IV_STRING.getBytes(), PKCS_5); + return new String(Base64.encodeBase64(encryptedBytes), "UTF-8"); + } + + /** + * 通用aes加密,兼容IOS + * + * @param key + * @param content + * @param paddingType + * @return + * @throws Exception + */ + public static byte[] aesCommonEncodeDetail(String key, String content, byte[] ivBytes, String paddingType) throws Exception { + byte[] byteContent = content.getBytes("UTF-8"); + byte[] enCodeFormat = key.getBytes(); + SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); + if (StringUtils.equals(paddingType, PKCS_7)) { + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); + } + Cipher cipher = Cipher.getInstance("AES/CBC/" + paddingType); + cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); + return cipher.doFinal(byteContent); + } + + /** + * aes通用解密,兼容IOS + * + * @param key + * @param content + * @return + * @throws Exception + */ + public static String aesCommonDecoder(String key, String content) throws Exception { + byte[] encryptedBytes = Base64.decodeBase64(content); + byte[] keyBytes = key.getBytes(); + byte[] result = aesCommonDecoderDetail(keyBytes, encryptedBytes, IV_STRING.getBytes(), PKCS_5); + return new String(result, "UTF-8"); + } + + /** + * aes cbc 通用解密 + * + * @param keyBytes 秘钥字节数组 + * @param encryptedBytes 密文字节数组 + * @param ivBytes 向量字节数组 + * @param paddingType 填充类型 + * @return + * @throws Exception + */ + public static byte[] aesCommonDecoderDetail(byte[] keyBytes, byte[] encryptedBytes, byte[] ivBytes, String paddingType) throws Exception { + SecretKeySpec secretKey = new SecretKeySpec(keyBytes, "AES"); + IvParameterSpec ivParameterSpec = new IvParameterSpec(ivBytes); + Cipher cipher; + if (StringUtils.equals(paddingType, PKCS_7)) { + Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); + } + cipher = Cipher.getInstance("AES/CBC/" + paddingType); + cipher.init(Cipher.DECRYPT_MODE, secretKey, ivParameterSpec); + return cipher.doFinal(encryptedBytes); + } +} diff --git a/basic-util/src/main/java/ink/wgink/util/FolderUtil.java b/basic-util/src/main/java/ink/wgink/util/FolderUtil.java new file mode 100644 index 00000000..689fc378 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/FolderUtil.java @@ -0,0 +1,26 @@ +package ink.wgink.util; + +import java.io.File; + +/** + * @ClassName: FolderUtil + * @Description: 文件夹工具 + * @Author: WangGeng + * @Date: 2019-05-28 13:46 + * @Version: 1.0 + **/ +public class FolderUtil { + + /** + * 创建文件夹 + * + * @param folderPath + */ + public static void createFolder(String folderPath) { + File folder = new File(folderPath); + if (folder.exists()) { + return; + } + folder.mkdirs(); + } +} diff --git a/basic-util/src/main/java/ink/wgink/util/HtmlHelper.java b/basic-util/src/main/java/ink/wgink/util/HtmlHelper.java new file mode 100644 index 00000000..699bf9f2 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/HtmlHelper.java @@ -0,0 +1,59 @@ +package ink.wgink.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class HtmlHelper { + + /** + * 去除script + */ + private static final Pattern P_SCRIPT = Pattern.compile("]*?>[\\s\\S]*?<\\/script>", + Pattern.CASE_INSENSITIVE); + /** + * 去除style的正则表达式 + */ + private static final Pattern P_STYLE = Pattern.compile("]*?>[\\s\\S]*?<\\/style>", + Pattern.CASE_INSENSITIVE); + /** + * 定义HTML标签的正则表达式 + */ + private static final Pattern P_HTML = Pattern.compile("<[^>]+>", Pattern.CASE_INSENSITIVE); + /** + * 定义空格回车换行符 + */ + private static final Pattern P_SPACE = Pattern.compile("\\s*|\t|\r|\n", + Pattern.CASE_INSENSITIVE); + + /** + *

+ * title HtmlHelper + *

+ *

+ * description 获取纯文本 + *

+ * + * @param html + * @return + * @author WenG + * @date 2018年6月14日 下午2:31:32 + * @modifier WenG + * @date 2018年6月14日 下午2:31:32 + */ + public static String getText(String html) { + // 过滤script标签 + Matcher mScript = P_SCRIPT.matcher(html); + html = mScript.replaceAll(""); + // 过滤style标签 + Matcher mStyle = P_STYLE.matcher(html); + html = mStyle.replaceAll(""); + // 过滤html标签 + Matcher mHtml = P_HTML.matcher(html); + html = mHtml.replaceAll(""); + // 过滤空格回车标签 + Matcher mSpace = P_SPACE.matcher(html); + html = mSpace.replaceAll(""); + return html; + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/MD5Util.java b/basic-util/src/main/java/ink/wgink/util/MD5Util.java new file mode 100644 index 00000000..a41f78b6 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/MD5Util.java @@ -0,0 +1,36 @@ +package ink.wgink.util; + +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MD5Util + * @Description: MD5处理 + * @Author: WangGeng + * @Date: 2020/6/30 12:20 上午 + * @Version: 1.0 + **/ +public class MD5Util { + + public static String toMD5String(String str) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("MD5"); + if (md != null && str != null) { + byte[] byteData = md.digest(str.getBytes(Charset.forName("UTF-8"))); + StringBuilder sb = new StringBuilder(); + byte[] var4 = byteData; + int var5 = byteData.length; + + for (int var6 = 0; var6 < var5; ++var6) { + byte aByteData = var4[var6]; + sb.append(Integer.toString((aByteData & 255) + 256, 16).substring(1)); + } + return sb.toString(); + } else { + return null; + } + } +} diff --git a/basic-util/src/main/java/ink/wgink/util/QRCodeUtil.java b/basic-util/src/main/java/ink/wgink/util/QRCodeUtil.java new file mode 100644 index 00000000..97f3844a --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/QRCodeUtil.java @@ -0,0 +1,86 @@ +package ink.wgink.util; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.imageio.ImageIO; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +public class QRCodeUtil { + + public static BufferedImage createQrCode(int width, int height, String content, String logoPath) { + Map qrParams = new HashMap<>(3); + // 编码 + qrParams.put(EncodeHintType.CHARACTER_SET, "UTF-8"); + // 纠错等级 + qrParams.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); + // 边框 + qrParams.put(EncodeHintType.MARGIN, 1); + // 生成二维码 + BufferedImage bufferedImage = null; + try { + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, + width, height); + bufferedImage = getBufferImage(bitMatrix); + if (null != logoPath && !logoPath.isEmpty()) { + addLogo(bufferedImage, logoPath); + } + } catch (Exception e) { + e.printStackTrace(); + } + return bufferedImage; + } + + private static BufferedImage getBufferImage(BitMatrix bitMatrix) { + int bmWidth = bitMatrix.getWidth(); + int bmHeight = bitMatrix.getHeight(); + BufferedImage bufferedImage = new BufferedImage(bmWidth, bmHeight, + BufferedImage.TYPE_INT_ARGB); + for (int x = 0; x < bmWidth; x++) { + for (int y = 0; y < bmHeight; y++) { + bufferedImage.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); + } + } + return bufferedImage; + } + + private static void addLogo(BufferedImage bufferedImage, String logoPath) throws IOException { + Graphics2D graphics2d = bufferedImage.createGraphics(); + Image logo = ImageIO.read(new File(logoPath)); + // 设置比例 + int logoWidth = bufferedImage.getWidth() / 6; + int logoHeight = bufferedImage.getHeight() / 6; + + // 填充logo + int x = bufferedImage.getWidth() / 2 - logoWidth / 2; + int y = bufferedImage.getHeight() / 2 - logoHeight / 2; + // 设置抗锯齿 + graphics2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + // 填充填充背景 + graphics2d.setColor(Color.WHITE); + graphics2d.fillRoundRect(x, y, logoWidth, logoHeight, 10, 10); + + // 画边框 + graphics2d.setColor(new Color(220, 220, 220)); + graphics2d.drawRoundRect(x, y, logoWidth, logoHeight, 10, 10); + + // 画LOGO + graphics2d.drawImage(logo, x + 2, y + 2, logoWidth - 4, logoHeight - 4, null); + graphics2d.dispose(); + logo.flush(); + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/RegexUtil.java b/basic-util/src/main/java/ink/wgink/util/RegexUtil.java new file mode 100644 index 00000000..e2eefd3d --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/RegexUtil.java @@ -0,0 +1,223 @@ +package ink.wgink.util; + +import java.util.regex.Pattern; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: RegexUtil + * @Description: 正则校验工具类 + * @Author: WangGeng + * @Date: 2019/12/4 18:13 + * @Version: 1.0 + **/ +public class RegexUtil { + + /** + * 特殊字符 + */ + public static final String SPECIAL_CHARACTERS = "#?!@$%^&*-_"; + /** + * 密码最小长度 + */ + public static final int PASSWORD_LENGTH_MIN = 6; + /** + * 密码最大长度 + */ + public static final int PASSWORD_LENGTH_MAX = 16; + /** + * 手机 + */ + private static final Pattern PATTERN_PHONE = Pattern.compile("^1\\d{10}$"); + /** + * 邮箱 + */ + private static final Pattern PATTERN_EMAIL = Pattern.compile("^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+$"); + /** + * 邮箱 + */ + private static final Pattern PATTERN_URL = Pattern.compile("(^#)|(^http(s*):\\/\\/[^\\s]+)"); + /** + * 日期格式 + */ + private static final Pattern PATTERN_DATE = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*$"); + /** + * 时间戳格式 + */ + private static final Pattern PATTERN_DATETIME = Pattern.compile("^(\\d{4})[-\\/](\\d{1}|0\\d{1}|1[0-2])([-\\/](\\d{1}|0\\d{1}|[1-2][0-9]|3[0-1]))*(\\s+)([0-1][0-9]|(2[0-3])):([0-5][0-9])(:([0-5][0-9]))*$"); + /** + * 身份证 + */ + private static final Pattern PATTERN_IDENTITY = Pattern.compile("(^\\d{15}$)|(^\\d{17}(x|X|\\d)$)"); + /** + * 用户名 + */ + private static final Pattern PATTERN_USERNAME = Pattern.compile("^[a-zA-Z0-9_\\s]+$"); + /** + * 字母 + */ + private static final Pattern PATTERN_LETTER = Pattern.compile("[a-zA-Z]+"); + /** + * 中文 + */ + private static final Pattern PATTERN_CHINESE = Pattern.compile("[\\u4e00-\\u9fa5]+"); + /** + * 数字 + */ + private static final Pattern PATTERN_NUMBER = Pattern.compile("\\d+"); + /** + * 弱密码 + */ + private static final Pattern PASSWORD_WEEK = Pattern.compile(String.format("(?=.*[A-Za-z0-9%s]).{%d,%d}", SPECIAL_CHARACTERS, PASSWORD_LENGTH_MIN, PASSWORD_LENGTH_MAX)); + /** + * 中密码 + */ + private static final Pattern PASSWORD_MIDDLE = Pattern.compile(String.format("((?=.*[A-Za-z])(?=.*[0-9]))|((?=.*[A-Za-z])(?=.*[%s]))|((?=.*[0-9])(?=.*[%s])).{%d,%d}", SPECIAL_CHARACTERS, SPECIAL_CHARACTERS, PASSWORD_LENGTH_MIN, PASSWORD_LENGTH_MAX)); + /** + * 强密码 + */ + private static final Pattern PASSWORD_STRONG = Pattern.compile(String.format("(?=.*[A-Za-z])(?=.*[0-9])(?=.*[%s]).{%d,%d}", SPECIAL_CHARACTERS, PASSWORD_LENGTH_MIN, PASSWORD_LENGTH_MAX)); + + /** + * 判断弱密码强度 + * + * @param input + * @return + */ + public static boolean isPasswordWeek(String input) { + return PASSWORD_WEEK.matcher(input).matches(); + } + + /** + * 判断中密码强度 + * + * @param input + * @return + */ + public static boolean isPasswordMiddle(String input) { + return PASSWORD_MIDDLE.matcher(input).matches(); + } + + /** + * 判断强密码强度 + * + * @param input + * @return + */ + public static boolean isPasswordStrong(String input) { + return PASSWORD_STRONG.matcher(input).matches(); + } + + /** + * 判断电话 + * + * @param input + * @return + */ + public static boolean isPhone(String input) { + return PATTERN_PHONE.matcher(input).matches(); + } + + /** + * 判断邮箱 + * + * @param input + * @return + */ + public static boolean isEmail(String input) { + return PATTERN_EMAIL.matcher(input).matches(); + } + + /** + * 判断URL + * + * @param input + * @return + */ + public static boolean isUrl(String input) { + return PATTERN_URL.matcher(input).matches(); + } + + /** + * 判断日期 + * + * @param input + * @return + */ + public static boolean isDate(String input) { + return PATTERN_DATE.matcher(input).matches(); + } + + /** + * 判断时间戳 + * + * @param input + * @return + */ + public static boolean isDatetime(String input) { + return PATTERN_DATETIME.matcher(input).matches(); + } + + /** + * 判断身份证 + * + * @param input + * @return + */ + public static boolean isIdentity(String input) { + return PATTERN_IDENTITY.matcher(input).matches(); + } + + /** + * 判断用户名 + * + * @param input + * @return + */ + public static boolean isUsername(String input) { + return PATTERN_USERNAME.matcher(input).matches(); + } + + /** + * 判断是字母 + * + * @param input + * @return + */ + public static boolean isLetter(String input) { + return PATTERN_LETTER.matcher(input).matches(); + } + + /** + * 判断是中文 + * + * @param input + * @return + */ + public static boolean isChinese(String input) { + return PATTERN_CHINESE.matcher(input).matches(); + } + + /** + * 判断是数字 + * + * @param input + * @return + */ + public static boolean isNumber(String input) { + return PATTERN_NUMBER.matcher(input).matches(); + } + + /** + * 自定义判断 + * + * @param customPattern + * @param input + * @return + */ + public static boolean isMatch(Pattern customPattern, String input) { + return customPattern.matcher(input).matches(); + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/ResourceUtil.java b/basic-util/src/main/java/ink/wgink/util/ResourceUtil.java new file mode 100644 index 00000000..96b89954 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/ResourceUtil.java @@ -0,0 +1,58 @@ +package ink.wgink.util; + +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.ResourceLoader; + +import java.io.*; + +/** + * @ClassName: ResourceUtil + * @Description: 资源工具 + * @Author: WangGeng + * @Date: 2019-05-23 11:04 + * @Version: 1.0 + **/ +public class ResourceUtil { + + /** + * 资源输入流 + * + * @param resourcePath + * @return + * @throws IOException + */ + public static InputStream getResourceInputStream(String resourcePath) throws IOException { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + return resourceLoader.getResource(resourcePath).getInputStream(); + } + + /** + * 资源文件 + * + * @param resourcePath + * @return + * @throws IOException + */ + public static File getResourceFile(String resourcePath) throws IOException { + ResourceLoader resourceLoader = new DefaultResourceLoader(); + return resourceLoader.getResource(resourcePath).getFile(); + } + + /** + * 输入流输出文本 + * + * @param inputStream + * @return + * @throws IOException + */ + public static String inputStreamToText(InputStream inputStream) throws IOException { + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8")); + StringBuffer resultStr = new StringBuffer(); + for (String line; (line = bufferedReader.readLine()) != null; ) { + resultStr.append(line); + } + bufferedReader.close(); + return resultStr.toString(); + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/UUIDUtil.java b/basic-util/src/main/java/ink/wgink/util/UUIDUtil.java new file mode 100644 index 00000000..36406417 --- /dev/null +++ b/basic-util/src/main/java/ink/wgink/util/UUIDUtil.java @@ -0,0 +1,20 @@ +package ink.wgink.util; + +import java.util.UUID; + +/** + * UuidUtil + * + * @author WangGeng + */ +public class UUIDUtil { + + public static String getUUID() { + return UUID.randomUUID().toString().trim(); + } + + public static String get32UUID() { + return getUUID().replaceAll("-", ""); + } + +} diff --git a/basic-util/src/main/java/ink/wgink/util/map/HashMapUtil.java b/basic-util/src/main/java/ink/wgink/util/map/HashMapUtil.java index aeb7c4fd..8d45365c 100644 --- a/basic-util/src/main/java/ink/wgink/util/map/HashMapUtil.java +++ b/basic-util/src/main/java/ink/wgink/util/map/HashMapUtil.java @@ -7,6 +7,7 @@ import org.apache.commons.lang3.math.NumberUtils; import javax.servlet.http.HttpServletRequest; import java.beans.BeanInfo; +import java.beans.IntrospectionException; import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; @@ -32,7 +33,7 @@ public class HashMapUtil { */ public static Map requestParamsToMap(HttpServletRequest request) { Enumeration requestNames = request.getParameterNames(); - Map params = new HashMap<>(); + Map params = new HashMap<>(0); while (requestNames.hasMoreElements()) { String name = requestNames.nextElement(); String value = request.getParameter(name); @@ -91,7 +92,7 @@ public class HashMapUtil { * @return */ private static Map mapObjToMapString(Object object) { - Map result = new HashMap<>(); + Map result = new HashMap<>(0); Map map = (Map) object; for (Entry entry : map.entrySet()) { String key = entry.getKey().toString(); @@ -108,7 +109,7 @@ public class HashMapUtil { * @return */ public static Map mapObjToMap(Object object) { - Map result = new HashMap<>(); + Map result = new HashMap<>(0); Map map = (Map) object; for (Entry entry : map.entrySet()) { String key = entry.getKey().toString(); @@ -125,22 +126,27 @@ public class HashMapUtil { * @return * @throws Exception */ - public static Map beanToMap(Object object) throws Exception { - Map result = null; - BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); - PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); - for (PropertyDescriptor property : properties) { - if (null == result) { - result = new HashMap<>(); + public static Map beanToMap(Object object) { + try { + Map result = null; + BeanInfo beanInfo = null; + beanInfo = Introspector.getBeanInfo(object.getClass()); + PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); + for (PropertyDescriptor property : properties) { + if (null == result) { + result = new HashMap<>(0); + } + Method method = property.getReadMethod(); + String name = property.getName(); + if ("class".equals(name)) { + continue; + } + result.put(name, method.invoke(object)); } - Method method = property.getReadMethod(); - String name = property.getName(); - if ("class".equals(name)) { - continue; - } - result.put(name, method.invoke(object)); + return result; + } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { + throw new TypeConversionException(e.getMessage(), e); } - return result; } /** @@ -150,22 +156,26 @@ public class HashMapUtil { * @return * @throws Exception */ - public static Map beanToMapString(Object object) throws Exception { - Map result = null; - BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); - PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); - for (PropertyDescriptor property : properties) { - if (null == result) { - result = new HashMap<>(); + public static Map beanToMapString(Object object) { + try { + Map result = null; + BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); + PropertyDescriptor[] properties = beanInfo.getPropertyDescriptors(); + for (PropertyDescriptor property : properties) { + if (null == result) { + result = new HashMap<>(0); + } + Method method = property.getReadMethod(); + String name = property.getName(); + if ("class".equals(name)) { + continue; + } + result.put(name, method.invoke(object).toString()); } - Method method = property.getReadMethod(); - String name = property.getName(); - if ("class".equals(name)) { - continue; - } - result.put(name, method.invoke(object).toString()); + return result; + } catch (IntrospectionException | IllegalAccessException | InvocationTargetException e) { + throw new TypeConversionException(e.getMessage(), e); } - return result; } /** @@ -288,4 +298,29 @@ public class HashMapUtil { } } + /** + * 类型转换异常 + */ + public static class TypeConversionException extends RuntimeException { + + public TypeConversionException() { + } + + public TypeConversionException(String message) { + super(message); + } + + public TypeConversionException(String message, Throwable cause) { + super(message, cause); + } + + public TypeConversionException(Throwable cause) { + super(cause); + } + + public TypeConversionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } + } + } diff --git a/common/pom.xml b/common/pom.xml index 2680f7b3..3e52559e 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -27,6 +27,11 @@ basic-exception 1.0-SNAPSHOT
+ + ink.wgink + basic-annotation + 1.0-SNAPSHOT + @@ -36,6 +41,27 @@ + + + com.alibaba + druid + + + + + + com.github.pagehelper + pagehelper + + + + + + com.alibaba + easyexcel + + +
\ No newline at end of file diff --git a/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java b/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java new file mode 100644 index 00000000..886a2379 --- /dev/null +++ b/common/src/main/java/ink/wgink/common/advice/ResponseAdvice.java @@ -0,0 +1,88 @@ +package ink.wgink.common.advice; + +import com.alibaba.fastjson.JSON; +import ink.wgink.common.enums.ErrorResultCodeEnum; +import ink.wgink.exceptions.*; +import ink.wgink.exceptions.base.SystemException; +import ink.wgink.pojo.result.ErrorResult; +import ink.wgink.util.map.HashMapUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.security.authentication.InsufficientAuthenticationException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.sql.SQLSyntaxErrorException; + + +/** + * @ClassName: ResponseAdvice + * @Description: Response结果处理 + * @Author: WangGeng + * @Date: 2019/2/26 5:14 PM + * @Version: 1.0 + **/ +@ControllerAdvice +public class ResponseAdvice { + + private static final Logger LOG = LoggerFactory.getLogger(ResponseAdvice.class); + + @ResponseBody + @ExceptionHandler({SystemException.class, SQLSyntaxErrorException.class, Exception.class, HashMapUtil.TypeConversionException.class}) + public void responseException(HttpServletRequest request, HttpServletResponse response, Exception e) throws IOException { + if (e instanceof InsufficientAuthenticationException) { + throw new InsufficientAuthenticationException(e.getMessage()); + } + if (e instanceof FileException) { + LOG.error(e.getMessage()); + } else { + LOG.error(e.getMessage(), e); + } + ErrorResult result = new ErrorResult(ErrorResultCodeEnum.SYSTEM_ERROR.getValue(), "系统错误"); + if (e instanceof SaveException) { + result.setCode(ErrorResultCodeEnum.SAVE_ERROR.getValue()); + } else if (e instanceof RemoveException) { + result.setCode(ErrorResultCodeEnum.REMOVE_ERROR.getValue()); + } else if (e instanceof UpdateException) { + result.setCode(ErrorResultCodeEnum.UPDATE_ERROR.getValue()); + } else if (e instanceof SearchException) { + result.setCode(ErrorResultCodeEnum.QUERY_ERROR.getValue()); + } else if (e instanceof ParamsException) { + result.setCode(ErrorResultCodeEnum.PARAMS_ERROR.getValue()); + } else if (e instanceof FileException) { + result.setCode(ErrorResultCodeEnum.FILE_ERROR.getValue()); + } else if (e instanceof AppDeviceException) { + result.setCode(ErrorResultCodeEnum.DEVICE_ERROR.getValue()); + } else if (e instanceof AppVersionException) { + result.setCode(ErrorResultCodeEnum.DEVICE_VERSION_ERROR.getValue()); + } else if (e instanceof AccessTokenException) { + response.setStatus(HttpStatus.UNAUTHORIZED.value()); + } + // 自定义提示信息 + if (e instanceof SystemException) { + result.setMsg(e.getMessage()); + } else { + StringBuilder errorMessageSB = new StringBuilder(); + for (StackTraceElement stackTraceElement : e.getStackTrace()) { + errorMessageSB.append(stackTraceElement.toString()).append("\n"); + } + result.setDetail(errorMessageSB.toString()); + result.setDetail(e.getMessage()); + } + String contentType = request.getContentType(); + if (contentType != null && contentType.contains(MediaType.APPLICATION_JSON_VALUE)) { + response.setContentType(MediaType.APPLICATION_JSON_VALUE); + response.setStatus(HttpStatus.BAD_REQUEST.value()); + response.getWriter().write(JSON.toJSONString(result)); + } else { + request.getSession().setAttribute("errorMessage", JSON.toJSONString(result)); + } + } + +} diff --git a/common/src/main/java/ink/wgink/common/config/TransactionConfig.java b/common/src/main/java/ink/wgink/common/config/TransactionConfig.java index 01f5142c..5dd5fb15 100644 --- a/common/src/main/java/ink/wgink/common/config/TransactionConfig.java +++ b/common/src/main/java/ink/wgink/common/config/TransactionConfig.java @@ -43,7 +43,7 @@ public class TransactionConfig { /** * 默认其它事务 */ - private static String[] DEFAULT_OTHER_ARRAY = {"send*", "exec*", "set*", "login*"}; + private static String[] DEFAULT_OTHER_ARRAY = {"send*", "exec*", "set*", "login*", "register*", "sign*", "rest*", "upload*"}; /** * 默认查询事务 */ diff --git a/module-file/pom.xml b/module-file/pom.xml new file mode 100644 index 00000000..069a8905 --- /dev/null +++ b/module-file/pom.xml @@ -0,0 +1,42 @@ + + + + wg-basic + ink.wgink + 1.0-SNAPSHOT + + 4.0.0 + + module-file + 文件模块 + + + + ink.wgink + basic-app + 1.0-SNAPSHOT + + + ink.wgink + common + 1.0-SNAPSHOT + + + + + it.sauronsoftware + jave + + + + + + net.coobird + thumbnailator + + + + + \ No newline at end of file diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaAppMaxDurationProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaAppMaxDurationProperties.java new file mode 100644 index 00000000..bf14c4a4 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaAppMaxDurationProperties.java @@ -0,0 +1,14 @@ +package ink.wgink.module.file.config.properties; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileBackendMediaMaxDurationProperties + * @Description: APP媒体最大时长 + * @Author: WangGeng + * @Date: 2020/5/31 16:50 + * @Version: 1.0 + **/ +public class FileMediaAppMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties { +} diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBackendMaxDurationProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBackendMaxDurationProperties.java new file mode 100644 index 00000000..d8db4375 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBackendMaxDurationProperties.java @@ -0,0 +1,14 @@ +package ink.wgink.module.file.config.properties; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileBackendMediaMaxDurationProperties + * @Description: 后台媒体最大时长 + * @Author: WangGeng + * @Date: 2020/5/31 16:50 + * @Version: 1.0 + **/ +public class FileMediaBackendMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties { +} diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBaseMaxDurationProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBaseMaxDurationProperties.java new file mode 100644 index 00000000..85b57409 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaBaseMaxDurationProperties.java @@ -0,0 +1,44 @@ +package ink.wgink.module.file.config.properties; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileMaxDurationProperties + * @Description: 媒体最大长度 + * @Author: WangGeng + * @Date: 2020/5/31 16:49 + * @Version: 1.0 + **/ +public class FileMediaBaseMaxDurationProperties { + + private Long video; + private Long audio; + + public Long getVideo() { + return video == null ? 0 : video; + } + + public void setVideo(Long video) { + this.video = video; + } + + public Long getAudio() { + return audio == null ? 0 : audio; + } + + public void setAudio(Long audio) { + this.audio = audio; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"video\":") + .append(video); + sb.append(",\"audio\":") + .append(audio); + sb.append('}'); + return sb.toString(); + } +} diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaMaxDurationProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaMaxDurationProperties.java new file mode 100644 index 00000000..794546c3 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaMaxDurationProperties.java @@ -0,0 +1,55 @@ +package ink.wgink.module.file.config.properties; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MediaMaxDurationProperties + * @Description: 媒体最大长度 + * @Author: WangGeng + * @Date: 2020/5/31 16:54 + * @Version: 1.0 + **/ +public class FileMediaMaxDurationProperties { + + private FileMediaBackendMaxDurationProperties backend; + private com.cm.common.config.properties.FileMediaAppMaxDurationProperties app; + private FileMediaWechatMaxDurationProperties wechat; + + public FileMediaBackendMaxDurationProperties getBackend() { + return backend; + } + + public void setBackend(FileMediaBackendMaxDurationProperties backend) { + this.backend = backend; + } + + public com.cm.common.config.properties.FileMediaAppMaxDurationProperties getApp() { + return app; + } + + public void setApp(com.cm.common.config.properties.FileMediaAppMaxDurationProperties app) { + this.app = app; + } + + public FileMediaWechatMaxDurationProperties getWechat() { + return wechat; + } + + public void setWechat(FileMediaWechatMaxDurationProperties wechat) { + this.wechat = wechat; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"backend\":") + .append(backend); + sb.append(",\"app\":") + .append(app); + sb.append(",\"wechat\":") + .append(wechat); + sb.append('}'); + return sb.toString(); + } +} diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaWechatMaxDurationProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaWechatMaxDurationProperties.java new file mode 100644 index 00000000..7215f9e1 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileMediaWechatMaxDurationProperties.java @@ -0,0 +1,14 @@ +package ink.wgink.module.file.config.properties; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileBackendMediaMaxDurationProperties + * @Description: 微信媒体最大时长 + * @Author: WangGeng + * @Date: 2020/5/31 16:50 + * @Version: 1.0 + **/ +public class FileMediaWechatMaxDurationProperties extends com.cm.common.config.properties.FileMediaBaseMaxDurationProperties { +} diff --git a/module-file/src/main/java/ink/wgink/module/file/config/properties/FileProperties.java b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileProperties.java new file mode 100644 index 00000000..7fc46d09 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/config/properties/FileProperties.java @@ -0,0 +1,112 @@ +package ink.wgink.module.file.config.properties; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +/** + * @ClassName: FileConfig + * @Description: 文件配置 + * @Author: wenc + * @Date: 2019/1/3 3:12 PM + * @Version: 1.0 + **/ +@Component +@ConfigurationProperties(prefix = "file") +public class FileProperties { + + private String uploadPath; + private String imageTypes; + private String videoTypes; + private String audioTypes; + private String fileTypes; + private Integer maxFileCount; + private Double imageOutputQuality; + private FileMediaMaxDurationProperties mediaMaxDuration; + + public String getUploadPath() { + return uploadPath; + } + + public void setUploadPath(String uploadPath) { + this.uploadPath = uploadPath; + } + + public String getImageTypes() { + return imageTypes == null ? null : imageTypes.trim(); + } + + public void setImageTypes(String imageTypes) { + this.imageTypes = imageTypes; + } + + public String getVideoTypes() { + return videoTypes == null ? null : videoTypes.replaceAll("\\s", ""); + } + + public void setVideoTypes(String videoTypes) { + this.videoTypes = videoTypes; + } + + public String getAudioTypes() { + return audioTypes == null ? null : audioTypes.replaceAll("\\s", ""); + } + + public void setAudioTypes(String audioTypes) { + this.audioTypes = audioTypes; + } + + public String getFileTypes() { + return fileTypes == null ? null : fileTypes.replaceAll("\\s", ""); + } + + public void setFileTypes(String fileTypes) { + this.fileTypes = fileTypes; + } + + public Integer getMaxFileCount() { + return maxFileCount == null ? 1 : maxFileCount; + } + + public void setMaxFileCount(Integer maxFileCount) { + this.maxFileCount = maxFileCount; + } + + public Double getImageOutputQuality() { + return imageOutputQuality == null ? 0.4 : imageOutputQuality; + } + + public void setImageOutputQuality(Double imageOutputQuality) { + this.imageOutputQuality = imageOutputQuality; + } + + public FileMediaMaxDurationProperties getMediaMaxDuration() { + return mediaMaxDuration; + } + + public void setMediaMaxDuration(FileMediaMaxDurationProperties mediaMaxDuration) { + this.mediaMaxDuration = mediaMaxDuration; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"uploadPath\":\"") + .append(uploadPath).append('\"'); + sb.append(",\"imageTypes\":\"") + .append(imageTypes).append('\"'); + sb.append(",\"videoTypes\":\"") + .append(videoTypes).append('\"'); + sb.append(",\"audioTypes\":\"") + .append(audioTypes).append('\"'); + sb.append(",\"fileTypes\":\"") + .append(fileTypes).append('\"'); + sb.append(",\"maxFileCount\":") + .append(maxFileCount); + sb.append(",\"imageOutputQuality\":") + .append(imageOutputQuality); + sb.append(",\"mediaMaxDuration\":") + .append(mediaMaxDuration); + sb.append('}'); + return sb.toString(); + } +} diff --git a/module-file/src/main/java/ink/wgink/module/file/dao/IFileDao.java b/module-file/src/main/java/ink/wgink/module/file/dao/IFileDao.java new file mode 100644 index 00000000..e6ff0adf --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/dao/IFileDao.java @@ -0,0 +1,103 @@ +package ink.wgink.module.file.dao; + + +import ink.wgink.exceptions.RemoveException; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.module.file.pojo.dtos.FileDTO; +import ink.wgink.module.file.pojo.dtos.FileInfoDTO; +import ink.wgink.pojo.pos.FilePO; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName: IFileDao + * @Description: 文件 + * @Author: wenc + * @Date: 2019/1/3 4:36 PM + * @Version: 1.0 + **/ +@Repository +public interface IFileDao { + + /** + * 保存文件 + * + * @param params + * @throws SaveException + */ + void save(Map params) throws SaveException; + + /** + * 删除文件 + * + * @param params + * @throws RemoveException + */ + void remove(Map params) throws RemoveException; + + /** + * 删除文件(物理删除) + * + * @param params + * @throws RemoveException + */ + void delete(Map params) throws RemoveException; + + /** + * 更新文件描述 + * + * @param fileParams + * @throws SearchException + */ + void updateSummary(Map fileParams) throws SearchException; + + /** + * 获取文件详情 + * + * @param params + * @return + * @throws SearchException + */ + FilePO getPO(Map params) throws SearchException; + + /** + * 获取文件列表 + * + * @param params + * @return + * @throws SearchException + */ + List list(Map params) throws SearchException; + + /** + * 获取文件列表 + * + * @param params + * @return + * @throws SearchException + */ + List listInfo(Map params) throws SearchException; + + /** + * 获取文件列表(带路径) + * + * @param params + * @return + * @throws SearchException + */ + List listWithPath(Map params) throws SearchException; + + /** + * 文件列表 + * + * @param fileMd5 文件MD5值 + * @return + * @throws SearchException + */ + List listByMd5(String fileMd5) throws SearchException; + + +} diff --git a/module-file/src/main/java/ink/wgink/module/file/enums/UploadTypeEnum.java b/module-file/src/main/java/ink/wgink/module/file/enums/UploadTypeEnum.java new file mode 100644 index 00000000..561e476d --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/enums/UploadTypeEnum.java @@ -0,0 +1,22 @@ +package ink.wgink.module.file.enums; + +/** + * @ClassName: UploadTypeEnum + * @Description: 上传类型 + * @Author: WangGeng + * @Date: 2019/3/10 10:37 PM + * @Version: 1.0 + **/ +public enum UploadTypeEnum { + + FILE(1), IMAGE(2), VIDEO(3), AUDIO(4), ERROR_EXCEL(5); + private int value; + + UploadTypeEnum(int value) { + this.value = value; + } + + public int getValue() { + return value; + } +} diff --git a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/FileDTO.java b/module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileDTO.java similarity index 98% rename from basic-pojo/src/main/java/ink/wgink/pojo/dtos/FileDTO.java rename to module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileDTO.java index 8bb95582..266c2526 100644 --- a/basic-pojo/src/main/java/ink/wgink/pojo/dtos/FileDTO.java +++ b/module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileDTO.java @@ -1,4 +1,4 @@ -package ink.wgink.pojo.dtos; +package ink.wgink.module.file.pojo.dtos; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileInfoDTO.java b/module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileInfoDTO.java new file mode 100644 index 00000000..92d930d8 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/pojo/dtos/FileInfoDTO.java @@ -0,0 +1,76 @@ +package ink.wgink.module.file.pojo.dtos; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: FileDTO + * @Description: 文件 + * @Author: WangGeng + * @Date: 2020/9/12 17:28 + * @Version: 1.0 + **/ +@ApiModel +public class FileInfoDTO extends FileDTO { + + @ApiModelProperty(name = "filePath", value = "文件全路径") + private String filePath; + @ApiModelProperty(name = "fileUrl", value = "文件链接") + private String fileUrl; + @ApiModelProperty(name = "fileSummary", value = "文件说明") + private String fileSummary; + @ApiModelProperty(name = "isBack", value = "是否备份") + private Integer isBack; + + public String getFilePath() { + return filePath == null ? "" : filePath.trim(); + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + @Override + public String getFileUrl() { + return fileUrl == null ? "" : fileUrl.trim(); + } + + @Override + public void setFileUrl(String fileUrl) { + this.fileUrl = fileUrl; + } + + public String getFileSummary() { + return fileSummary == null ? "" : fileSummary.trim(); + } + + public void setFileSummary(String fileSummary) { + this.fileSummary = fileSummary; + } + + public Integer getIsBack() { + return isBack; + } + + public void setIsBack(Integer isBack) { + this.isBack = isBack; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"filePath\":\"") + .append(filePath).append('\"'); + sb.append(",\"fileUrl\":\"") + .append(fileUrl).append('\"'); + sb.append(",\"fileSummary\":\"") + .append(fileSummary).append('\"'); + sb.append(",\"isBack\":") + .append(isBack); + sb.append('}'); + return sb.toString(); + } +} diff --git a/module-file/src/main/java/ink/wgink/module/file/service/IFileService.java b/module-file/src/main/java/ink/wgink/module/file/service/IFileService.java new file mode 100644 index 00000000..fd82c030 --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/service/IFileService.java @@ -0,0 +1,229 @@ +package ink.wgink.module.file.service; + +import com.alibaba.fastjson.JSONObject; +import ink.wgink.module.file.enums.UploadTypeEnum; +import ink.wgink.module.file.pojo.dtos.FileDTO; +import ink.wgink.module.file.pojo.dtos.FileInfoDTO; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.pos.FilePO; +import ink.wgink.pojo.result.SuccessResultData; +import ink.wgink.pojo.result.SuccessResultList; +import org.springframework.web.multipart.MultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * @ClassName: IFileService + * @Description: 文件处理 + * @Author: WangGeng + * @Date: 2019/3/10 7:05 PM + * @Version: 1.0 + **/ +public interface IFileService { + + /** + * 文件类型 + */ + String UPLOAD_FILE_TYPE = "1"; + /** + * 图片类型 + */ + String UPLOAD_IMAGE_TYPE = "2"; + /** + * 视频类型 + */ + String UPLOAD_VIDEO_TYPE = "3"; + /** + * 音频类型 + */ + String UPLOAD_AUDIO_TYPE = "4"; + /** + * 读取流大小 1M + */ + int INPUT_STREAM_SIZE = 1048576; + + /** + * uEditor action + */ + String UEDITOR_ACTION = "action"; + /** + * uEditor config + */ + String UEDITOR_CONFIG = "config"; + /** + * uEditor 图片 + */ + String UEDITOR_UPLOAD_IMAGE = "uploadimage"; + /** + * uEditor 视频 + */ + String UEDITOR_UPLOAD_VIDEO = "uploadvideo"; + /** + * uEditor 文件 + */ + String UEDITOR_UPLOAD_FILE = "uploadfile"; + /** + * uEditor 图片列表 + */ + String UEDITOR_LIST_IMAGE = "listimage"; + /** + * uEditor 文件列表 + */ + String UEDITOR_LIST_FILE = "listfile"; + + /** + * 文件分页列表 + * + * @param page + * @return + */ + SuccessResultList> listPageInfo(ListPage page); + + /** + * 删除记录 + * + * @param ids + */ + void remove(String ids); + + /** + * 删除记录和文件 + * + * @param ids + */ + void delete(String ids); + + /** + * 文件上传 + * + * @param uploadFile + * @param uploadTypeEnum + * @param params + * @return + */ + SuccessResultData uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params); + + /** + * 文件上传 + * + * @param token + * @param uploadFile + * @param uploadTypeEnum + * @param params + * @return + * @throws IOException + */ + SuccessResultData uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params); + + /** + * 文件上传 + * + * @param token + * @param uploadFile + * @param uploadTypeEnum + * @param params + * @return + */ + FileDTO uploadSingleForFileDTO(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params); + + /** + * 文件下载 + * + * @param response + * @param params + */ + void downLoadFile(HttpServletResponse response, Map params); + + /** + * 文件下载 + * + * @param request + * @param response + * @param params + */ + void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map params); + + /** + * 文件下载 + * + * @param request + * @param response + * @param params + * @param canRange 开启断点续传 + */ + void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map params, boolean canRange); + + /** + * 百度富文本编辑器 + * + * @param file + * @param request + * @param params + * @return + * @throws IOException + */ + JSONObject uEditor(MultipartFile file, HttpServletRequest request, Map params) throws IOException; + + /** + * wangEditor上传文件 + * + * @param image + * @param image1 + * @param params + * @return + */ + JSONObject wangEditorImage(MultipartFile image, UploadTypeEnum image1, Map params); + + /** + * 获取文件详情 + * + * @param params + * @return + */ + FilePO getPO(Map params); + + /** + * 保存导入Excel异常文件信息 + * + * @param fileName + * @param uploadPath + * @param fileSize + * @param params + */ + void uploadErrorExcelFileInfo(String fileName, String uploadPath, long fileSize, Map params); + + /** + * 获取导入Excel异常文件路径 + * + * @return + */ + String getUploadExcelErrorPath(); + + /** + * 通过文件ID获取ID列表 + * + * @param idList + * @return + */ + List list(List idList); + + /** + * 校验视频长度是否符合 + * + * @param uploadFile + * @param maxDuration + */ + void checkVideoDurationAllow(MultipartFile uploadFile, long maxDuration); + + /** + * 校验音频长度是否符合 + * + * @param uploadFile + * @param maxDuration + */ + void checkAudioDurationAllow(MultipartFile uploadFile, long maxDuration); +} diff --git a/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java b/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java new file mode 100644 index 00000000..cdd7b8aa --- /dev/null +++ b/module-file/src/main/java/ink/wgink/module/file/service/impl/FileServiceImpl.java @@ -0,0 +1,853 @@ +package ink.wgink.module.file.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import ink.wgink.app.AppTokenManager; +import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.common.enums.ErrorResultCodeEnum; +import ink.wgink.exceptions.FileException; +import ink.wgink.exceptions.ParamsException; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.exceptions.base.SystemException; +import ink.wgink.module.file.config.properties.FileProperties; +import ink.wgink.module.file.dao.IFileDao; +import ink.wgink.module.file.enums.UploadTypeEnum; +import ink.wgink.module.file.pojo.dtos.FileDTO; +import ink.wgink.module.file.pojo.dtos.FileInfoDTO; +import ink.wgink.module.file.service.IFileService; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.pos.FilePO; +import ink.wgink.pojo.result.SuccessResultData; +import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.util.ResourceUtil; +import ink.wgink.util.UUIDUtil; +import ink.wgink.util.date.DateUtil; +import it.sauronsoftware.jave.Encoder; +import it.sauronsoftware.jave.EncoderException; +import it.sauronsoftware.jave.MultimediaInfo; +import net.coobird.thumbnailator.Thumbnails; +import org.apache.catalina.connector.ClientAbortException; +import org.apache.commons.fileupload.disk.DiskFileItem; +import org.apache.commons.lang3.StringUtils; +import org.joda.time.DateTime; +import org.joda.time.DateTimeZone; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.commons.CommonsMultipartFile; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.channels.WritableByteChannel; +import java.security.MessageDigest; +import java.util.*; + +/** + * @ClassName: FileServiceImpl + * @Description: 文件处理 + * @Author: WangGeng + * @Date: 2019/3/10 7:06 PM + * @Version: 1.0 + **/ +@Service +public class FileServiceImpl extends DefaultBaseService implements IFileService { + + private static final Logger LOG = LoggerFactory.getLogger(FileServiceImpl.class); + private static final char[] HEX_CODE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + /** + * 文件MD5值开头 + */ + public static final String FILE_MD5_PREFIX = "MD5:"; + /** + * 文件引用值开头 + */ + public static final String FILE_REF_PREFIX = "REF:"; + + @Autowired + private FileProperties fileProperties; + @Autowired + private IFileDao fileDao; + + private String[] imageTypes; + private String[] videoTypes; + private String[] audioTypes; + private String[] fileTypes; + + public List listFileInfo(Map params) { + return fileDao.listInfo(params); + } + + @Override + public SuccessResultList> listPageInfo(ListPage page) { + PageHelper.startPage(page.getPage(), page.getRows()); + List fileInfoDTOs = fileDao.listInfo(page.getParams()); + PageInfo pageInfo = new PageInfo<>(fileInfoDTOs); + return new SuccessResultList<>(fileInfoDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); + } + + @Override + public void remove(String ids) { + Map params = getHashMap(2); + params.put("fileIds", Arrays.asList(ids.split("_"))); + setUpdateInfo(params); + fileDao.remove(params); + } + + @Override + public void delete(String ids) { + Map params = getHashMap(2); + params.put("fileIds", Arrays.asList(ids.split("_"))); + Map fileParams = getHashMap(4); + List fileInfoWithPathDTOs = fileDao.listWithPath(params); + // 删除文件 + for (FileInfoDTO fileInfoDTO : fileInfoWithPathDTOs) { + // 如果文件描述为空,可以直接删除源文件 + if (StringUtils.isBlank(fileInfoDTO.getFileSummary())) { + deleteSourceFile(fileInfoDTO.getFilePath()); + continue; + } + // 文件描述不为空时,需要判断是否删除的是源文件,源文件在一个系统中只保留一份 + // 如果是引用文件的数据,不删除源文件 + if (fileInfoDTO.getFileSummary().startsWith(FILE_REF_PREFIX)) { + continue; + } + // 如果不是MD5源文件,略过 + if (!fileInfoDTO.getFileSummary().startsWith(FILE_MD5_PREFIX)) { + continue; + } + // 如果删除的是源文件,需要查询系统中是否还存在引用的数据 + List fileInfoDTOs = fileDao.listByMd5(FILE_REF_PREFIX + fileInfoDTO.getFileId()); + // 如果不存在对源文件引用的数据,则直接删除源文件 + if (fileInfoDTOs.size() == 0) { + deleteSourceFile(fileInfoDTO.getFilePath()); + continue; + } + fileParams.clear(); + // 如果存在引用数据,取出第一个修改为源文件,并将其他的引用更新为新的源文件ID + FileInfoDTO firstFileInfoDTO = fileInfoDTOs.get(0); + fileParams.put("fileSummary", firstFileInfoDTO.getFileSummary()); + fileParams.put("fileId", firstFileInfoDTO.getFileId()); + fileDao.updateSummary(fileParams); + // 获取其他的ID列表,更新文件引用关系 + List otherFileIds = new ArrayList<>(); + for (int i = 1; i < fileInfoDTOs.size(); i++) { + otherFileIds.add(fileInfoDTOs.get(i).getFileId()); + } + // 如果不存在其它的引用,略过 + if (otherFileIds.isEmpty()) { + continue; + } + fileParams.remove("fileId"); + fileParams.put("fileSummary", FILE_REF_PREFIX + firstFileInfoDTO.getFileId()); + fileParams.put("fileIds", otherFileIds); + fileDao.updateSummary(fileParams); + } + // 删除记录 + fileDao.delete(params); + } + + /** + * 删除源文件 + * + * @param sourceFilePath 源文件路径 + */ + private void deleteSourceFile(String sourceFilePath) { + File file = new File(sourceFilePath); + if (file.exists()) { + boolean isDelete = file.delete(); + if (isDelete) { + LOG.debug("文件删除成功"); + } else { + LOG.debug("文件删除失败"); + } + } + } + + @Override + public SuccessResultData uploadSingle(MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params) throws SystemException { + uploadFile(null, uploadFile, uploadTypeEnum, params); + return new SuccessResultData<>(params.get("fileId").toString()); + } + + @Override + public SuccessResultData uploadSingle(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params) throws SystemException { + uploadFile(token, uploadFile, uploadTypeEnum, params); + return new SuccessResultData<>(params.get("fileId").toString()); + } + + @Override + public FileDTO uploadSingleForFileDTO(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params) throws SystemException { + uploadFile(token, uploadFile, uploadTypeEnum, params); + FileDTO fileDTO = new FileDTO(); + fileDTO.setFileId(params.get("fileId").toString()); + fileDTO.setFileName(params.get("fileName").toString()); + fileDTO.setFileUrl(params.get("fileUrl").toString()); + fileDTO.setFileType(params.get("fileType").toString()); + return fileDTO; + } + + /** + * 上传文件 + * + * @param token + * @param uploadFile + * @param uploadTypeEnum + * @param params + * @throws SystemException + */ + private void uploadFile(String token, MultipartFile uploadFile, UploadTypeEnum uploadTypeEnum, Map params) throws SystemException { + String baseUploadPath = fileProperties.getUploadPath(); + if (StringUtils.isBlank(baseUploadPath)) { + throw new SystemException("上传路径未配置"); + } + String fileName = uploadFile.getOriginalFilename(); + // 文件大小 + long fileSize = uploadFile.getSize(); + // 文件类型 + String fileType = getFileType(fileName); + // 文件保存路径 + String uploadPath = getUploadPath(baseUploadPath, uploadTypeEnum, fileType); + // 文件保存名称 + String uploadFileName = getUploadFileName(fileType); + String fileMd5 = uploadFile(uploadFile, uploadPath, uploadFileName); + if (fileMd5 == null) { + throw new SaveException("文件上传失败"); + } + // 获取MD5相同的文件 + List fileInfoDTOs = fileDao.listByMd5(FILE_MD5_PREFIX + fileMd5); + if (fileInfoDTOs.size() > 0) { + // 删除新增的文件 + File uploadedFile = new File(uploadPath + File.separator + uploadFileName); + if (uploadedFile.exists()) { + uploadedFile.delete(); + } + // 保存记录,但文件信息都是原有的文件 + params.clear(); + FileInfoDTO fileInfoDTO = fileInfoDTOs.get(0); + params.put("fileSummary", "REF:" + fileInfoDTO.getFileId()); + saveFile(token, params, fileInfoDTO.getFileName(), fileInfoDTO.getFilePath(), fileInfoDTO.getFileUrl(), fileInfoDTO.getFileType(), fileInfoDTO.getFileSize()); + return; + } + params.put("fileSummary", "MD5:" + fileMd5); + saveUploadFileInfo(token, fileName, uploadPath, uploadFileName, fileType, fileSize, params); + } + + @Override + public void uploadErrorExcelFileInfo(String fileName, String uploadPath, long fileSize, Map params) { + saveUploadFileInfo(null, fileName, uploadPath, fileName, "xls", fileSize, params); + } + + @Override + public String getUploadExcelErrorPath() { + String baseUploadPath = fileProperties.getUploadPath(); + if (StringUtils.isBlank(baseUploadPath)) { + throw new SystemException("上传路径未配置"); + } + return getUploadPath(baseUploadPath, UploadTypeEnum.ERROR_EXCEL, null); + } + + @Override + public List list(List idList) throws SearchException { + Map params = getHashMap(1); + params.put("ids", idList); + return fileDao.list(params); + } + + /** + * 保存文件信息 + * + * @param token + * @param fileName + * @param uploadPath + * @param uploadFileName + * @param fileType + * @param fileSize + */ + private void saveUploadFileInfo(String token, String fileName, String uploadPath, String uploadFileName, String fileType, long fileSize, Map params) { + String fixPath = uploadPath.replace(fileProperties.getUploadPath(), ""); + if ("\\".equals(File.separator)) { + fixPath = fixPath.replace("\\", "/"); + } + if (fixPath.startsWith("/")) { + fixPath = fixPath.substring(1, fixPath.length() - 1); + } + String fileFullPath = String.format("%s%s%s", uploadPath, File.separator, uploadFileName); + // 压缩图片 + if (isImageFile(fileType)) { + compressImage(fileFullPath); + File photo = new File(fileFullPath); + fileSize = photo.length(); + } + saveFile(token, params, fileName, fileFullPath, String.format("files/%s/%s", fixPath, uploadFileName), fileType, fileSize); + } + + /** + * 保存文件 + * + * @param token token + * @param params 参数 + * @param fileName 文件名 + * @param fileFullPath 文件全路径 + * @param fileUrl 文件相对地址 + * @param fileType 文件类型 + * @param fileSize 文件大小 + */ + private void saveFile(String token, Map params, String fileName, String fileFullPath, String fileUrl, String fileType, long fileSize) { + params.put("fileId", UUIDUtil.getUUID()); + params.put("fileName", fileName); + params.put("filePath", fileFullPath); + params.put("fileUrl", fileUrl); + params.put("fileType", fileType); + params.put("fileSize", fileSize); + params.put("isBack", 0); + if (StringUtils.isBlank(token)) { + setSaveInfo(params); + } else { + setSaveInfoByUserId(params, AppTokenManager.getInstance().getToken(token).getAppTokenUser().getId()); + } + fileDao.save(params); + } + + @Override + public void downLoadFile(HttpServletResponse response, Map params) { + downLoadFile(null, response, params); + } + + @Override + public void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map params) { + downLoadFile(request, response, params, true); + } + + @Override + public void downLoadFile(HttpServletRequest request, HttpServletResponse response, Map params, boolean canRange) { + FilePO filePO = fileDao.getPO(params); + if (null == filePO) { + throw new SearchException("文件获取失败"); + } + try ( + RandomAccessFile randomAccessFile = new RandomAccessFile(filePO.getFilePath(), "r"); + FileChannel fileChannel = randomAccessFile.getChannel(); + OutputStream outputStream = response.getOutputStream(); + WritableByteChannel writableByteChannel = Channels.newChannel(outputStream); + ) { + boolean isOpen = Boolean.valueOf(params.get("isOpen").toString()); + response.setHeader("Content-Length", filePO.getFileSize()); + response.setContentType(getContentType(filePO.getFileType())); + if (!isOpen) { + response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(filePO.getFileName(), "UTF-8")); + } else { + response.setHeader("Content-Disposition", "inline;fileName=" + URLEncoder.encode(filePO.getFileName(), "UTF-8")); + // 如果是图片资源,开启缓存 + if (isImageFile(filePO.getFileType())) { + // 如果存在校验修改时间且未做修改,返回304,使用本地资源 + String ifModifiedSince = request.getHeader("If-Modified-Since"); + if (StringUtils.isNotBlank(ifModifiedSince) && StringUtils.equalsIgnoreCase(ifModifiedSince, filePO.getGmtModified())) { + response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); + return; + } + // 缓存有效时间为7天 + response.setHeader("Expires", DateTime.now().plusDays(7).toDateTime(DateTimeZone.forID("GMT")).toString()); + // 60秒之内不发送新请求 + response.setHeader("max-age", "60"); + response.setHeader("Last-Modified", filePO.getGmtModified()); + } + } + String rangeString = null; + if (canRange && request != null) { + rangeString = request.getHeader("Range"); + LOG.debug("range: {}", rangeString); + } + long contentLength = Long.valueOf(filePO.getFileSize()); + long startRange = 0; + long endRange = contentLength - 1; + if (!StringUtils.isBlank(rangeString)) { + if (!isOpen) { + response.setContentType("multipart/byteranges"); + } + String[] rangeArray = rangeString.substring(rangeString.indexOf("=") + 1).split("-"); + startRange = Long.valueOf(rangeArray[0]); + if (rangeArray.length > 1) { + endRange = Long.valueOf(rangeArray[1]); + } + setRangeHeader(startRange, endRange, response, filePO.getFileId(), contentLength); + randomAccessFile.seek(startRange); + } + LOG.debug("startRange: {}, endRange: {}", startRange, endRange); + long totalOutputLength = endRange - startRange + 1; + fileChannel.transferTo(startRange, totalOutputLength, writableByteChannel); + outputStream.flush(); + } catch (Exception e) { + if (e instanceof ClientAbortException) { + LOG.debug("客户端断开连接"); + } else { + throw new FileException("文件输出异常", e); + } + } + } + + /** + * 处理视频流问题 + * + * @param startRange + * @param endRange + * @param response + * @param fileId + * @param contentLength + */ + private void setRangeHeader(long startRange, long endRange, HttpServletResponse response, String fileId, long contentLength) { + // 这里不设置,会出现第一次加载很慢的情况 + response.setHeader("Content-Length", String.valueOf(endRange - startRange + 1)); + response.setHeader("Content-Range", String.format("bytes %d-%d/%d", startRange, endRange, contentLength)); + response.setHeader("Accept-Ranges", "bytes"); + response.setHeader("Etag", fileId); + response.setStatus(206); + } + + @Override + public JSONObject uEditor(MultipartFile file, HttpServletRequest request, Map params) throws SystemException, IOException { + if (params.get(UEDITOR_ACTION) == null || StringUtils.isBlank(params.get(UEDITOR_ACTION).toString())) { + throw new ParamsException("参数错误"); + } + String action = params.get(UEDITOR_ACTION).toString(); + JSONObject result = null; + if (UEDITOR_CONFIG.equals(action)) { + result = uEditorConfig(); + } + if (UEDITOR_UPLOAD_IMAGE.equals(action) || UEDITOR_UPLOAD_VIDEO.equals(action) || UEDITOR_UPLOAD_FILE.equals(action)) { + result = uEditorUpload(file, request, action, params); + } + if (UEDITOR_LIST_IMAGE.equals(action) || UEDITOR_LIST_FILE.equals(action)) { + result = uEditorFileList(request, action, params); + } + return result; + } + + @Override + public JSONObject wangEditorImage(MultipartFile image, UploadTypeEnum image1, Map params) { + JSONObject result = new JSONObject(); + try { + FileDTO fileDTO = uploadSingleForFileDTO(null, image, UploadTypeEnum.IMAGE, params); + result.put("errno", 0); + JSONArray fileArray = new JSONArray(); + fileArray.add(String.format("route/file/downloadfile/true/%s", fileDTO.getFileId())); + result.put("data", fileArray); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + result.put("errno", ErrorResultCodeEnum.FILE_ERROR.getValue()); + } + return result; + } + + @Override + public FilePO getPO(Map params) throws SearchException { + return fileDao.getPO(params); + } + + @Override + public void checkVideoDurationAllow(MultipartFile uploadFile, long maxDuration) { + if (maxDuration <= 0) { + return; + } + checkDurationAllow(uploadFile, maxDuration, "视频"); + } + + @Override + public void checkAudioDurationAllow(MultipartFile uploadFile, long maxDuration) { + if (maxDuration <= 0) { + return; + } + checkDurationAllow(uploadFile, maxDuration, "音频"); + } + + /** + * 校验音、视频长度是否符合 + * + * @param uploadFile + * @param maxDuration + */ + private void checkDurationAllow(MultipartFile uploadFile, long maxDuration, String name) { + CommonsMultipartFile commonsMultipartFile = (CommonsMultipartFile) uploadFile; + DiskFileItem diskFileItem = (DiskFileItem) commonsMultipartFile.getFileItem(); + File source = diskFileItem.getStoreLocation(); + Encoder encoder = new Encoder(); + MultimediaInfo multimediaInfo; + try { + multimediaInfo = encoder.getInfo(source); + } catch (EncoderException e) { + throw new SystemException("文件解析错误"); + } + long fileDuration = multimediaInfo.getDuration() / 1000; + if (fileDuration > maxDuration) { + throw new FileException(name + "时间超过 " + maxDuration + " 秒"); + } + } + + /** + * uEditor文件列表 + * + * @param action + * @param params + * @return + */ + private JSONObject uEditorFileList(HttpServletRequest request, String action, Map params) throws SearchException { + LOG.debug("uEditor文件列表"); + int start = Integer.parseInt(params.get("start").toString()); + int pageSize = Integer.parseInt(params.get("size").toString()); + int pageNum = start / pageSize + 1; + String downloadFile = "true"; + if (UEDITOR_LIST_IMAGE.equals(action)) { + params.put("fileUrl", "images"); + } else if (UEDITOR_LIST_FILE.equals(action)) { + params.put("fileUrl", "files"); + downloadFile = "false"; + } + PageHelper.startPage(pageNum, pageSize); + List listFileDTOs = fileDao.list(params); + PageInfo pageInfo = new PageInfo<>(listFileDTOs); + List> fileList = new ArrayList<>(); + for (FileDTO fileDTO : listFileDTOs) { + Map fileMap = new HashMap<>(0); + fileMap.put("url", String.format("%s/route/file/downloadfile/%s/%s.%s", request.getContextPath(), downloadFile, fileDTO.getFileId(), fileDTO.getFileType())); + fileList.add(fileMap); + } + JSONObject uEditorListResult = new JSONObject(); + uEditorListResult.put("state", "SUCCESS"); + uEditorListResult.put("start", start); + uEditorListResult.put("total", pageInfo.getTotal()); + uEditorListResult.put("list", fileList); + return uEditorListResult; + } + + /** + * uEditor上传文件 + * + * @param file + * @param request + * @param action + * @param params + * @return + * @throws SystemException + */ + private JSONObject uEditorUpload(MultipartFile file, HttpServletRequest request, String action, Map params) throws SystemException { + LOG.debug("UEditor上传文件"); + FileDTO fileDTO = null; + String downloadFile = "true"; + if (UEDITOR_UPLOAD_IMAGE.equals(action)) { + fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.IMAGE, params); + } else if (UEDITOR_UPLOAD_VIDEO.equals(action)) { + fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.VIDEO, params); + downloadFile = "true"; + } else if (UEDITOR_UPLOAD_FILE.equals(action)) { + fileDTO = uploadSingleForFileDTO(null, file, UploadTypeEnum.FILE, params); + downloadFile = "false"; + } + if (fileDTO == null) { + throw new SystemException("文件上传失败"); + } + String fileUrl = String.format("route/file/downloadfile/%s/%s.%s", downloadFile, fileDTO.getFileId(), fileDTO.getFileType()); + JSONObject fileUploadResult = new JSONObject(); + fileUploadResult.put("state", "SUCCESS"); + fileUploadResult.put("url", fileUrl); + fileUploadResult.put("title", fileDTO.getFileName()); + fileUploadResult.put("original", fileDTO.getFileName()); + return fileUploadResult; + } + + /** + * 获取ueditor配置文件 + * + * @return + * @throws IOException + */ + private JSONObject uEditorConfig() throws IOException { + LOG.debug("加载UEditor配置文件"); + String uEditorConfig = ResourceUtil.inputStreamToText(ResourceUtil.getResourceInputStream("classpath:ueditorconfig.json")); + return JSONObject.parseObject(uEditorConfig); + } + + + public String[] getImageTypes() { + return imageTypes == null ? fileProperties.getImageTypes().split(",") : imageTypes; + } + + public void setImageTypes(String[] imageTypes) { + this.imageTypes = imageTypes; + } + + public String[] getVideoTypes() { + return videoTypes == null ? fileProperties.getVideoTypes().split(",") : videoTypes; + } + + public void setVideoTypes(String[] videoTypes) { + this.videoTypes = videoTypes; + } + + public String[] getAudioTypes() { + return audioTypes == null ? fileProperties.getAudioTypes().split(",") : audioTypes; + } + + public void setAudioTypes(String[] audioTypes) { + this.audioTypes = audioTypes; + } + + public String[] getFileTypes() { + return fileTypes == null ? fileProperties.getFileTypes().split(",") : fileTypes; + } + + public void setFileTypes(String[] fileTypes) { + this.fileTypes = fileTypes; + } + + /** + * 校验类型 + * + * @param types + * @param fileType + * @return + */ + private boolean isTypeCorrect(String[] types, String fileType) { + for (String type : types) { + if (StringUtils.equalsIgnoreCase(fileType, type)) { + return true; + } + } + return false; + } + + /** + * 获取文件类型 + * + * @param fileName + * @return + */ + private String getFileType(String fileName) { + String[] names = fileName.split("\\."); + if (names != null) { + return names[names.length - 1].toLowerCase(); + } + return ""; + } + + /** + * 获取上传文件路径 + * + * @param baseUploadPath + * @param uploadTypeEnum + * @param fileType + * @return + * @throws FileException + */ + private String getUploadPath(String baseUploadPath, UploadTypeEnum uploadTypeEnum, String fileType) throws FileException { + StringBuilder filePath = new StringBuilder(); + if (!baseUploadPath.endsWith(File.separator)) { + filePath.append(baseUploadPath).append(File.separator); + } else { + filePath.append(baseUploadPath); + } + boolean hasFileType = !StringUtils.isBlank(fileType); + if (uploadTypeEnum.getValue() == UploadTypeEnum.IMAGE.getValue()) { + if (hasFileType && !isTypeCorrect(getImageTypes(), fileType)) { + throw new FileException("图片格式不支持上传"); + } + filePath.append("images"); + } else if (uploadTypeEnum.getValue() == UploadTypeEnum.VIDEO.getValue()) { + if (hasFileType && !isTypeCorrect(getVideoTypes(), fileType)) { + throw new FileException("视频格式不支持上传"); + } + filePath.append("videos"); + } else if (uploadTypeEnum.getValue() == UploadTypeEnum.AUDIO.getValue()) { + if (hasFileType && !isTypeCorrect(getAudioTypes(), fileType)) { + throw new FileException("音频格式不支持上传"); + } + filePath.append("audios"); + } else if (uploadTypeEnum.getValue() == UploadTypeEnum.ERROR_EXCEL.getValue()) { + filePath.append("errorexcels"); + } else { + if (hasFileType && !isTypeCorrect(getFileTypes(), fileType)) { + throw new FileException("文件格式不支持上传"); + } + filePath.append("files"); + } + filePath.append(File.separator).append(DateUtil.getDays()); + return filePath.toString(); + } + + /** + * 获取上传文件名称 + * + * @param fileType + * @return + */ + private String getUploadFileName(String fileType) { + String uploadFileName = UUIDUtil.get32UUID(); + if (!StringUtils.isEmpty(fileType)) { + uploadFileName += "." + fileType; + } + return uploadFileName; + } + + /** + * 保存文件到本地 + * + * @param uploadFile + * @param filePath + * @param uploadFileName + * @return + */ + private String uploadFile(MultipartFile uploadFile, String filePath, String uploadFileName) throws FileException { + String fileMd5; + File uploadFolder = new File(filePath); + if (!uploadFolder.exists()) { + uploadFolder.mkdirs(); + } + InputStream uploadFileInputStream = null; + FileOutputStream uploadFileOutputStream = null; + try { + uploadFileInputStream = uploadFile.getInputStream(); + uploadFileOutputStream = new FileOutputStream(new File(uploadFolder + "/" + uploadFileName)); + MessageDigest messageDigest = MessageDigest.getInstance("MD5"); + for (byte[] buf = new byte[INPUT_STREAM_SIZE]; uploadFileInputStream.read(buf) > -1; ) { + uploadFileOutputStream.write(buf, 0, buf.length); + messageDigest.update(buf, 0, buf.length); + } + uploadFileOutputStream.flush(); + // 计算文件的MD5 + byte[] data = messageDigest.digest(); + StringBuilder fileMd5SB = new StringBuilder(data.length * 2); + for (byte b : data) { + fileMd5SB.append(HEX_CODE[(b >> 4) & 0xF]); + fileMd5SB.append(HEX_CODE[(b & 0xF)]); + } + fileMd5 = fileMd5SB.toString(); + } catch (Exception e) { + LOG.error(e.getMessage(), e); + throw new FileException("文件上传失败"); + } finally { + try { + if (null != uploadFileOutputStream) { + uploadFileOutputStream.close(); + } + if (null != uploadFileInputStream) { + uploadFileInputStream.close(); + } + } catch (Exception e1) { + LOG.error(e1.getMessage()); + throw new FileException("文件上传失败"); + } + } + return fileMd5; + } + + /** + * 获取ContentType + * + * @param fileType + * @return + */ + private String getContentType(String fileType) { + String contentType; + switch (fileType) { + case "png": + contentType = "image/png"; + break; + case "blob": + case "jpg": + case "jpeg": + contentType = "image/jpeg"; + break; + case "gif": + contentType = "image/gif"; + break; + case "mp4": + contentType = "video/mp4"; + break; + case "rmvb": + contentType = "application/vnd.rn-realmedia-vbr"; + break; + case "mp3": + contentType = "audio/mp3"; + break; + case "wmv": + contentType = "video/x-ms-wmv"; + break; + case "wav": + contentType = "audio/wav"; + break; + case "doc": + contentType = "application/msword"; + break; + case "docx": + contentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; + break; + case "xls": + contentType = "application/vnd.ms-excel"; + break; + case "xlsx": + contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + break; + case "ppt": + contentType = "application/vnd.ms-powerpoint"; + break; + case "pptx": + contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; + break; + case "txt": + contentType = "text/plain"; + break; + case "apk": + contentType = "application/vnd.android.package-archive"; + break; + case "pdf": + contentType = "application/pdf"; + break; + default: + contentType = "application/octet-stream"; + } + return contentType; + } + + /** + * 是否是图片文件, GIF图片不压缩 + * + * @param fileType + * @return + */ + private boolean isImageFile(String fileType) { + if (StringUtils.equalsIgnoreCase("gif", fileType)) { + return false; + } + String imageTypes = fileProperties.getImageTypes(); + for (String imageType : imageTypes.split(",")) { + if (StringUtils.equalsIgnoreCase(fileType, imageType)) { + return true; + } + } + return false; + } + + /** + * 压缩图片 + * + * @param fileFullPath + */ + private void compressImage(String fileFullPath) { + if (fileFullPath.endsWith(".blob")) { + return; + } + try { + Thumbnails.of(fileFullPath).scale(1.0f).outputQuality(fileProperties.getImageOutputQuality()).toFile(fileFullPath); + } catch (IOException e) { + LOG.error(e.getMessage(), e); + } + } + +} diff --git a/pom.xml b/pom.xml index f3ba39e9..69c1ce48 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,10 @@ service-user basic-app basic-exception + basic-annotation + service-department + service-role + module-file pom @@ -55,6 +59,8 @@ 5.5.0 4.1.50.Final 1.56 + 9.0.14 + 1.18.16 @@ -353,6 +359,31 @@ + + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat-embed.version} + + + org.apache.tomcat.embed + tomcat-embed-el + ${tomcat-embed.version} + + + org.apache.tomcat.embed + tomcat-embed-websocket + ${tomcat-embed.version} + + + + + + org.projectlombok + lombok + ${lombok.version} + + diff --git a/service-department/pom.xml b/service-department/pom.xml new file mode 100644 index 00000000..f7e9a6da --- /dev/null +++ b/service-department/pom.xml @@ -0,0 +1,23 @@ + + + + wg-basic + ink.wgink + 1.0-SNAPSHOT + + 4.0.0 + + service-department + 组织机构业务 + + + + ink.wgink + service-user + 1.0-SNAPSHOT + + + + \ No newline at end of file diff --git a/service-department/src/main/java/ink/wgink/service/department/controller/api/DepartmentController.java b/service-department/src/main/java/ink/wgink/service/department/controller/api/DepartmentController.java new file mode 100644 index 00000000..eeaf6020 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/controller/api/DepartmentController.java @@ -0,0 +1,205 @@ +package ink.wgink.service.department.controller.api; + +import ink.wgink.annotation.CheckRequestBodyAnnotation; +import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.exceptions.ParamsException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.dtos.ZTreeDTO; +import ink.wgink.pojo.dtos.department.DepartmentDTO; +import ink.wgink.pojo.result.*; +import ink.wgink.service.department.pojo.vos.DepartmentVO; +import ink.wgink.service.department.pojo.vos.MergeDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.MergeNewDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.SplitDepartmentVO; +import ink.wgink.service.department.service.IDepartmentService; +import io.swagger.annotations.*; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.util.*; + +/** + * @ClassName: DepartmentController + * @Description: 组织部门 + * @Author: wenc + * @Date: 2019/1/8 7:23 PM + * @Version: 1.0 + **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "组织部门") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/department") +public class DepartmentController extends DefaultBaseController { + + @Autowired + private IDepartmentService departmentService; + + @ApiOperation(value = "组织部门新增", notes = "组织部门新增接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save") + @CheckRequestBodyAnnotation + public SuccessResult save(@RequestBody DepartmentVO departmentVO) throws Exception { + departmentService.save(departmentVO); + return new SuccessResult(); + } + + @ApiOperation(value = "组织部门删除", notes = "组织部门删除接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "组织部门ID列表,用下划线分隔", paramType = "path", example = "1_2_3") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @DeleteMapping("remove/{ids}") + public SuccessResult remove(@PathVariable("ids") String ids) { + departmentService.remove(Arrays.asList(ids.split("\\_"))); + return new SuccessResult(); + } + + @ApiOperation(value = "组织部门修改", notes = "组织部门修改接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentId", value = "组织部门ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update/{departmentId}") + @CheckRequestBodyAnnotation + public SuccessResult update(@PathVariable("departmentId") String departmentId, + @RequestBody DepartmentVO departmentVO) { + departmentService.update(departmentId, departmentVO); + return new SuccessResult(); + } + + @ApiOperation(value = "重置组织部门编码", notes = "重置组织部门编码接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("restcode") + public SuccessResult resetCode() { + departmentService.resetCode(); + return new SuccessResult(); + } + + + @ApiOperation(value = "更新合并到新增组织", notes = "更新合并到新增组织接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("updatemergenew") + @CheckRequestBodyAnnotation + public SuccessResult updateMergeNew(@RequestBody MergeNewDepartmentInfoVO mergeNewDepartmentInfoVO) throws Exception { + departmentService.updateMergeNew(mergeNewDepartmentInfoVO); + return new SuccessResult(); + } + + @ApiOperation(value = "更新合并到组织", notes = "更新合并到组织接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("updatemerge/{departmentId}") + @CheckRequestBodyAnnotation + public SuccessResult updateMerge(@PathVariable("departmentId") String departmentId, @RequestBody MergeDepartmentInfoVO mergeDepartmentInfoVO) { + departmentService.updateMerge(departmentId, mergeDepartmentInfoVO); + return new SuccessResult(); + } + + @ApiOperation(value = "更新分割部门", notes = "更新分割部门接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("updatesplit/{departmentId}") + @CheckRequestBodyAnnotation + public SuccessResult updateSplit(@PathVariable("departmentId") String departmentId, @RequestBody SplitDepartmentVO splitDepartmentVO) { + departmentService.updateSplit(departmentId, splitDepartmentVO); + return new SuccessResult(); + } + + @ApiOperation(value = "组织部门列表", notes = "组织部门列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentParentId", value = "组织部门上级ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list/{departmentParentId}") + public List list(@PathVariable("departmentParentId") String departmentParentId) { + Map params = new HashMap<>(0); + params.put("departmentParentId", departmentParentId); + return departmentService.listAll(params); + } + + @ApiOperation(value = "zTree列表", notes = "zTree列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "id", value = "父ID", paramType = "query", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listztree") + public List listZTree() { + Map params = requestParams(); + String departmentParentId = "0"; + if (!StringUtils.isBlank(params.get("id") == null ? null : params.get("id").toString())) { + departmentParentId = params.get("id").toString(); + } + return departmentService.listZTree(departmentParentId, params); + } + + @ApiOperation(value = "组织部门详情", notes = "组织部门详情接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentId", value = "部门ID", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("get/{departmentId}") + public DepartmentDTO get(@PathVariable("departmentId") String departmentId) { + return departmentService.get(departmentId); + } + + @ApiOperation(value = "easyui组织部门列表", notes = "easyui组织部门列表列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "parentId", value = "上级ID", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpagedepartment") + public SuccessResultList> listPageDepartment(ListPage page) { + Map params = requestParams(); + String departmentParentId = "0"; + if (!StringUtils.isBlank(params.get("parentId") == null ? null : params.get("parentId").toString())) { + departmentParentId = params.get("parentId").toString(); + } + page.setParams(params); + return departmentService.listPageByParentId(departmentParentId, page); + } + + @ApiOperation(value = "保存部门Excel(文件上传)", notes = "保存部门Excel接口(文件上传)") + @ApiImplicitParams({ + @ApiImplicitParam(name = "excel", value = "文件名称", paramType = "query"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("uploadexcel") + public UploadExcelResultDTO uploadExcel(MultipartFile excel) { + if (Objects.isNull(excel)) { + throw new ParamsException("Excel不能为空"); + } + if (!excel.getOriginalFilename().endsWith(".xls") && !excel.getOriginalFilename().endsWith(".xlsx")) { + throw new ParamsException("文件格式为Excel"); + } + return departmentService.uploadExcel(excel); + } + + @ApiOperation(value = "获得同一级部门数量(按部门名称)", notes = "获得同一级部门数量(按部门名称)接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "departmentParentId", value = "上级部门ID", paramType = "path"), + @ApiImplicitParam(name = "departmentName", value = "上级部门ID", paramType = "path"), + @ApiImplicitParam(name = "noDepartmentId", value = "不统计的部门ID", paramType = "query"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("countbyparentidandname/{departmentParentId}/{departmentName}") + public SuccessResultData countByParentIdAndName(@PathVariable("departmentParentId") String departmentParentId, + @PathVariable("departmentName") String departmentName, + @RequestParam(name = "noDepartmentId", required = false) String noDepartmentId) throws UnsupportedEncodingException { + Map params = getParams(); + params.put("departmentParentId", departmentParentId); + params.put("departmentName", URLDecoder.decode(departmentName, "UTF-8")); + params.put("noDepartmentId", noDepartmentId); + return new SuccessResultData<>(departmentService.count(params)); + } + +} diff --git a/service-department/src/main/java/ink/wgink/service/department/dao/IDepartmentDao.java b/service-department/src/main/java/ink/wgink/service/department/dao/IDepartmentDao.java new file mode 100644 index 00000000..d3ce88fe --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/dao/IDepartmentDao.java @@ -0,0 +1,167 @@ +package ink.wgink.service.department.dao; + +import ink.wgink.exceptions.RemoveException; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.exceptions.UpdateException; +import ink.wgink.pojo.dtos.ZTreeDTO; +import ink.wgink.pojo.dtos.department.DepartmentDTO; +import ink.wgink.pojo.dtos.department.DepartmentSimpleDTO; +import org.springframework.stereotype.Repository; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IUserDao + * @Description: 用户 + * @Author: WangGeng + * @Date: 2021/1/24 20:23 + * @Version: 1.0 + **/ +@Repository +public interface IDepartmentDao { + + /** + * 新增组织部门 + * + * @param params + * @throws SaveException + */ + void save(Map params) throws SaveException; + + /** + * 删除组织部门 + * + * @param params + * @throws RemoveException + */ + void remove(Map params) throws RemoveException; + + /** + * 更新组织部门 + * + * @param params + * @throws UpdateException + */ + void update(Map params) throws UpdateException; + + /** + * 组织部门编码更新 + * + * @param params + * @throws UpdateException + */ + void updateCode(Map params) throws UpdateException; + + /** + * 更新部门状态 + * + * @param params + * @throws UpdateException + */ + void updateState(Map params) throws UpdateException; + + /** + * 组织部门详情 + * + * @param params + * @return + * @throws SearchException + */ + DepartmentDTO get(Map params) throws SearchException; + + /** + * 组织部门列表 + * + * @param params + * @return + * @throws SearchException + */ + List list(Map params) throws SearchException; + + /** + * 统计部门数量 + * + * @param params + * @return + * @throws SearchException + */ + Integer count(Map params) throws SearchException; + + /** + * 部门ID + * + * @param params + * @return + * @throws SearchException + */ + List listId(Map params) throws SearchException; + + /** + * zTree组织部门列表 + * + * @param params + * @return + * @throws SearchException + */ + List listZTree(Map params) throws SearchException; + + /** + * zTree组织部门详情 + * + * @param params + * @return + * @throws SearchException + */ + ZTreeDTO getZTree(Map params) throws SearchException; + + /** + * 组织部门通过ID统计 + * + * @param id + * @return + * @throws SearchException + */ + Integer countByParentId(String id) throws SearchException; + + /** + * 最后一个子组织部门 + * + * @param parentId + * @return + * @throws SearchException + */ + DepartmentDTO getLastByParentId(String parentId) throws SearchException; + + /** + * 获取组织机构通过名称和上级名称 + * + * @param params + * @return + * @throws SearchException + */ + DepartmentDTO getByNameAndParentName(Map params) throws SearchException; + + /** + * 获取组织机构详情(简单类型) + * + * @param params + * @return + * @throws SearchException + */ + DepartmentSimpleDTO getSimple(Map params) throws SearchException; + + /** + * 获取组织机构列表(简单类型) + * + * @param params + * @return + * @throws SearchException + */ + List listSimple(Map params) throws SearchException; + +} diff --git a/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcel.java b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcel.java new file mode 100644 index 00000000..f010ea38 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcel.java @@ -0,0 +1,96 @@ +package ink.wgink.service.department.listener.excel; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentExcel + * @Description: 部门 + * @Author: WangGeng + * @Date: 2020/4/8 15:12 + * @Version: 1.0 + **/ +public class DepartmentExcel { + + @ExcelProperty(index = 0) + private Integer departmentId; + @ExcelProperty(index = 1) + private String departmentName; + @ExcelProperty(index = 2) + private Integer departmentParentId; + @ExcelProperty(index = 3) + private String departmentSummary; + @ExcelProperty(index = 4) + private String departmentTel; + @ExcelProperty(index = 5) + private Integer departmentType; + + public Integer getDepartmentId() { + return departmentId; + } + + public void setDepartmentId(Integer departmentId) { + this.departmentId = departmentId; + } + + public String getDepartmentName() { + return departmentName == null ? "" : departmentName.trim(); + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + public Integer getDepartmentParentId() { + return departmentParentId; + } + + public void setDepartmentParentId(Integer departmentParentId) { + this.departmentParentId = departmentParentId; + } + + public String getDepartmentSummary() { + return departmentSummary == null ? "" : departmentSummary.trim(); + } + + public void setDepartmentSummary(String departmentSummary) { + this.departmentSummary = departmentSummary; + } + + public String getDepartmentTel() { + return departmentTel == null ? "" : departmentTel.trim(); + } + + public void setDepartmentTel(String departmentTel) { + this.departmentTel = departmentTel; + } + + public Integer getDepartmentType() { + return departmentType; + } + + public void setDepartmentType(Integer departmentType) { + this.departmentType = departmentType; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"departmentId\":") + .append(departmentId); + sb.append(",\"departmentName\":") + .append("\"").append(departmentName).append("\""); + sb.append(",\"departmentParentId\":") + .append(departmentParentId); + sb.append(",\"departmentSummary\":") + .append("\"").append(departmentSummary).append("\""); + sb.append(",\"departmentTel\":") + .append("\"").append(departmentTel).append("\""); + sb.append(",\"departmentType\":") + .append(departmentType); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelError.java b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelError.java new file mode 100644 index 00000000..ddd8082d --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelError.java @@ -0,0 +1,108 @@ +package ink.wgink.service.department.listener.excel; + +import com.alibaba.excel.annotation.ExcelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentExcelError + * @Description: 部门Excel错误 + * @Author: WangGeng + * @Date: 2020/4/8 15:13 + * @Version: 1.0 + **/ +public class DepartmentExcelError { + + @ExcelProperty(index = 0) + private Integer departmentId; + @ExcelProperty(index = 1) + private String departmentName; + @ExcelProperty(index = 2) + private Integer departmentParentId; + @ExcelProperty(index = 3) + private String departmentSummary; + @ExcelProperty(index = 4) + private String departmentTel; + @ExcelProperty(index = 5) + private Integer departmentType; + @ExcelProperty(index = 6) + private String reason; + + public Integer getDepartmentId() { + return departmentId; + } + + public void setDepartmentId(Integer departmentId) { + this.departmentId = departmentId; + } + + public String getDepartmentName() { + return departmentName == null ? "" : departmentName.trim(); + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + public Integer getDepartmentParentId() { + return departmentParentId; + } + + public void setDepartmentParentId(Integer departmentParentId) { + this.departmentParentId = departmentParentId; + } + + public String getDepartmentSummary() { + return departmentSummary == null ? "" : departmentSummary.trim(); + } + + public void setDepartmentSummary(String departmentSummary) { + this.departmentSummary = departmentSummary; + } + + public String getDepartmentTel() { + return departmentTel == null ? "" : departmentTel.trim(); + } + + public void setDepartmentTel(String departmentTel) { + this.departmentTel = departmentTel; + } + + public Integer getDepartmentType() { + return departmentType; + } + + public void setDepartmentType(Integer departmentType) { + this.departmentType = departmentType; + } + + public String getReason() { + return reason == null ? "" : reason.trim(); + } + + public void setReason(String reason) { + this.reason = reason; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"departmentId\":") + .append(departmentId); + sb.append(",\"departmentName\":") + .append("\"").append(departmentName).append("\""); + sb.append(",\"departmentParentId\":") + .append(departmentParentId); + sb.append(",\"departmentSummary\":") + .append("\"").append(departmentSummary).append("\""); + sb.append(",\"departmentType\":") + .append(departmentType); + sb.append(",\"departmentTel\":") + .append("\"").append(departmentTel).append("\""); + sb.append(",\"reason\":") + .append("\"").append(reason).append("\""); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelListener.java b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelListener.java new file mode 100644 index 00000000..b3779fa0 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/listener/excel/DepartmentExcelListener.java @@ -0,0 +1,42 @@ +package ink.wgink.service.department.listener.excel; + +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentExcelListener + * @Description: 部门Excel监听 + * @Author: WangGeng + * @Date: 2020/4/8 15:13 + * @Version: 1.0 + **/ +public abstract class DepartmentExcelListener extends AnalysisEventListener { + + private static final Logger LOG = LoggerFactory.getLogger(DepartmentExcelListener.class); + private List departmentExcels = new ArrayList<>(0); + + @Override + public void invoke(DepartmentExcel departmentExcel, AnalysisContext analysisContext) { + departmentExcels.add(departmentExcel); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + try { + listDepartmentExcel(departmentExcels); + } catch (Exception e) { + LOG.error(e.getMessage()); + } + departmentExcels.clear(); + } + + public abstract void listDepartmentExcel(List departmentExcels) throws Exception; +} diff --git a/service-department/src/main/java/ink/wgink/service/department/pojo/vos/DepartmentVO.java b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/DepartmentVO.java new file mode 100644 index 00000000..6436ee99 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/DepartmentVO.java @@ -0,0 +1,270 @@ +package ink.wgink.service.department.pojo.vos; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import ink.wgink.annotation.CheckNumberAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @ClassName: DepartmentVO + * @Description: 组织部门视图 + * @Author: WangGeng + * @Date: 2019/3/4 4:20 PM + * @Version: 1.0 + **/ +@ApiModel +public class DepartmentVO { + + @ApiModelProperty(name = "departmentParentId", value = "组织部门上级ID") + @CheckEmptyAnnotation(name = "组织部门上级ID") + private String departmentParentId; + @ApiModelProperty(name = "departmentName", value = "组织部门名称") + @CheckEmptyAnnotation(name = "组织部门名称") + private String departmentName; + @ApiModelProperty(name = "departmentNameEn", value = "组织部门名称(英文)") + private String departmentNameEn; + @ApiModelProperty(name = "departmentNameOther", value = "组织部门名称(其他类型)") + private String departmentNameOther; + @ApiModelProperty(name = "departmentType", value = "组织部门类型,1:机构,2:部门") + @CheckNumberAnnotation(name = "组织部门类型", types = {"1", "2"}) + private Integer departmentType; + @ApiModelProperty(name = "departmentState", value = "组织部门状态,1:正常,2:异常,3:停用") + @CheckNumberAnnotation(name = "组织部门状态", types = {"1", "2", "3"}) + private Integer departmentState; + @ApiModelProperty(name = "departmentSummary", value = "组织部门说明") + private String departmentSummary; + @ApiModelProperty(name = "departmentFax", value = "组织部门传真") + private String departmentFax; + @ApiModelProperty(name = "departmentTel", value = "组织部门电话") + private String departmentTel; + @ApiModelProperty(name = "departmentAddress", value = "组织部门地址") + private String departmentAddress; + @ApiModelProperty(name = "departmentMaster", value = "组织部门负责人") + private String departmentMaster; + @ApiModelProperty(name = "departmentDuty", value = "组织部门职责") + private String departmentDuty; + @ApiModelProperty(name = "departmentArea1Id", value = "1级区域ID") + private Integer departmentArea1Id; + @ApiModelProperty(name = "departmentArea2Id", value = "2级区域ID") + private Integer departmentArea2Id; + @ApiModelProperty(name = "departmentArea3Id", value = "3级区域ID") + private Integer departmentArea3Id; + @ApiModelProperty(name = "departmentArea4Id", value = "4级区域ID") + private Integer departmentArea4Id; + @ApiModelProperty(name = "departmentArea5Id", value = "5级区域ID") + private Integer departmentArea5Id; + @ApiModelProperty(name = "departmentLongitude", value = "组织部门经度") + private String departmentLongitude; + @ApiModelProperty(name = "departmentLatitude", value = "组织部门纬度") + private String departmentLatitude; + @ApiModelProperty(name = "departmentOrder", value = "组织部门排序,默认0") + @CheckNumberAnnotation(name = "组织部门排序") + private Integer departmentOrder; + + public String getDepartmentParentId() { + return departmentParentId == null ? "" : departmentParentId.trim(); + } + + public void setDepartmentParentId(String departmentParentId) { + this.departmentParentId = departmentParentId; + } + + public String getDepartmentName() { + return departmentName == null ? "" : departmentName.trim(); + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } + + public String getDepartmentNameEn() { + return departmentNameEn == null ? "" : departmentNameEn.trim(); + } + + public void setDepartmentNameEn(String departmentNameEn) { + this.departmentNameEn = departmentNameEn; + } + + public String getDepartmentNameOther() { + return departmentNameOther == null ? "" : departmentNameOther.trim(); + } + + public void setDepartmentNameOther(String departmentNameOther) { + this.departmentNameOther = departmentNameOther; + } + + public Integer getDepartmentType() { + return departmentType; + } + + public void setDepartmentType(Integer departmentType) { + this.departmentType = departmentType; + } + + public Integer getDepartmentState() { + return departmentState; + } + + public void setDepartmentState(Integer departmentState) { + this.departmentState = departmentState; + } + + public String getDepartmentSummary() { + return departmentSummary == null ? "" : departmentSummary.trim(); + } + + public void setDepartmentSummary(String departmentSummary) { + this.departmentSummary = departmentSummary; + } + + public String getDepartmentFax() { + return departmentFax == null ? "" : departmentFax.trim(); + } + + public void setDepartmentFax(String departmentFax) { + this.departmentFax = departmentFax; + } + + public String getDepartmentTel() { + return departmentTel == null ? "" : departmentTel.trim(); + } + + public void setDepartmentTel(String departmentTel) { + this.departmentTel = departmentTel; + } + + public String getDepartmentAddress() { + return departmentAddress == null ? "" : departmentAddress.trim(); + } + + public void setDepartmentAddress(String departmentAddress) { + this.departmentAddress = departmentAddress; + } + + public String getDepartmentMaster() { + return departmentMaster == null ? "" : departmentMaster.trim(); + } + + public void setDepartmentMaster(String departmentMaster) { + this.departmentMaster = departmentMaster; + } + + public String getDepartmentDuty() { + return departmentDuty == null ? "" : departmentDuty.trim(); + } + + public void setDepartmentDuty(String departmentDuty) { + this.departmentDuty = departmentDuty; + } + + public Integer getDepartmentArea1Id() { + return departmentArea1Id; + } + + public void setDepartmentArea1Id(Integer departmentArea1Id) { + this.departmentArea1Id = departmentArea1Id; + } + + public Integer getDepartmentArea2Id() { + return departmentArea2Id; + } + + public void setDepartmentArea2Id(Integer departmentArea2Id) { + this.departmentArea2Id = departmentArea2Id; + } + + public Integer getDepartmentArea3Id() { + return departmentArea3Id; + } + + public void setDepartmentArea3Id(Integer departmentArea3Id) { + this.departmentArea3Id = departmentArea3Id; + } + + public Integer getDepartmentArea4Id() { + return departmentArea4Id; + } + + public void setDepartmentArea4Id(Integer departmentArea4Id) { + this.departmentArea4Id = departmentArea4Id; + } + + public Integer getDepartmentArea5Id() { + return departmentArea5Id; + } + + public void setDepartmentArea5Id(Integer departmentArea5Id) { + this.departmentArea5Id = departmentArea5Id; + } + + public String getDepartmentLongitude() { + return departmentLongitude == null ? "" : departmentLongitude.trim(); + } + + public void setDepartmentLongitude(String departmentLongitude) { + this.departmentLongitude = departmentLongitude; + } + + public String getDepartmentLatitude() { + return departmentLatitude == null ? "" : departmentLatitude.trim(); + } + + public void setDepartmentLatitude(String departmentLatitude) { + this.departmentLatitude = departmentLatitude; + } + + public Integer getDepartmentOrder() { + return departmentOrder; + } + + public void setDepartmentOrder(Integer departmentOrder) { + this.departmentOrder = departmentOrder; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"departmentParentId\":\"") + .append(departmentParentId).append('\"'); + sb.append(",\"departmentName\":\"") + .append(departmentName).append('\"'); + sb.append(",\"departmentNameEn\":\"") + .append(departmentNameEn).append('\"'); + sb.append(",\"departmentNameOther\":\"") + .append(departmentNameOther).append('\"'); + sb.append(",\"departmentType\":") + .append(departmentType); + sb.append(",\"departmentState\":") + .append(departmentState); + sb.append(",\"departmentSummary\":\"") + .append(departmentSummary).append('\"'); + sb.append(",\"departmentFax\":\"") + .append(departmentFax).append('\"'); + sb.append(",\"departmentTel\":\"") + .append(departmentTel).append('\"'); + sb.append(",\"departmentAddress\":\"") + .append(departmentAddress).append('\"'); + sb.append(",\"departmentMaster\":\"") + .append(departmentMaster).append('\"'); + sb.append(",\"departmentDuty\":\"") + .append(departmentDuty).append('\"'); + sb.append(",\"departmentArea1Id\":\"") + .append(departmentArea1Id).append('\"'); + sb.append(",\"departmentArea2Id\":\"") + .append(departmentArea2Id).append('\"'); + sb.append(",\"departmentArea3Id\":\"") + .append(departmentArea3Id).append('\"'); + sb.append(",\"departmentArea4Id\":\"") + .append(departmentArea4Id).append('\"'); + sb.append(",\"departmentArea5Id\":\"") + .append(departmentArea5Id).append('\"'); + sb.append(",\"departmentLongitude\":\"") + .append(departmentLongitude).append('\"'); + sb.append(",\"departmentLatitude\":\"") + .append(departmentLatitude).append('\"'); + sb.append(",\"departmentOrder\":") + .append(departmentOrder); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeDepartmentInfoVO.java b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeDepartmentInfoVO.java new file mode 100644 index 00000000..2073252e --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeDepartmentInfoVO.java @@ -0,0 +1,40 @@ +package ink.wgink.service.department.pojo.vos; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MergeDepartmentInfoVO + * @Description: 合并组织 + * @Author: WangGeng + * @Date: 2020/6/5 15:25 + * @Version: 1.0 + **/ +@ApiModel +public class MergeDepartmentInfoVO { + + @ApiModelProperty(name = "mergeDepartmentIds", value = "合并组织ID列表") + @CheckEmptyAnnotation(name = "合并组织ID列表") + private String mergeDepartmentIds; + + public String getMergeDepartmentIds() { + return mergeDepartmentIds == null ? "" : mergeDepartmentIds.trim(); + } + + public void setMergeDepartmentIds(String mergeDepartmentIds) { + this.mergeDepartmentIds = mergeDepartmentIds; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"mergeDepartmentIds\":\"") + .append(mergeDepartmentIds).append('\"'); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeNewDepartmentInfoVO.java b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeNewDepartmentInfoVO.java new file mode 100644 index 00000000..10d7de67 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/MergeNewDepartmentInfoVO.java @@ -0,0 +1,40 @@ +package ink.wgink.service.department.pojo.vos; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MergeNewDepartmentInfoVO + * @Description: 新增合并组织 + * @Author: WangGeng + * @Date: 2020/6/5 15:23 + * @Version: 1.0 + **/ +@ApiModel +public class MergeNewDepartmentInfoVO extends DepartmentVO { + + @ApiModelProperty(name = "mergeDepartmentIds", value = "合并组织ID列表") + @CheckEmptyAnnotation(name = "合并组织ID列表") + private String mergeDepartmentIds; + + public String getMergeDepartmentIds() { + return mergeDepartmentIds == null ? "" : mergeDepartmentIds.trim(); + } + + public void setMergeDepartmentIds(String mergeDepartmentIds) { + this.mergeDepartmentIds = mergeDepartmentIds; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"mergeDepartmentIds\":\"") + .append(mergeDepartmentIds).append('\"'); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentInfoVO.java b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentInfoVO.java new file mode 100644 index 00000000..24ace62f --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentInfoVO.java @@ -0,0 +1,38 @@ +package ink.wgink.service.department.pojo.vos; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: SplitDepartmentInfoVO + * @Description: 拆分部门信息 + * @Author: WangGeng + * @Date: 2020/6/4 11:52 下午 + * @Version: 1.0 + **/ +@ApiModel +public class SplitDepartmentInfoVO extends DepartmentVO { + + @ApiModelProperty(name = "userIds", value = "用户ID列表") + private String userIds; + + public String getUserIds() { + return userIds == null ? "" : userIds.trim(); + } + + public void setUserIds(String userIds) { + this.userIds = userIds; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"userIds\":") + .append("\"").append(userIds).append("\""); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentVO.java b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentVO.java new file mode 100644 index 00000000..07508aa9 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/pojo/vos/SplitDepartmentVO.java @@ -0,0 +1,43 @@ +package ink.wgink.service.department.pojo.vos; + +import ink.wgink.annotation.CheckListAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: SplitDepartmentVO + * @Description: 拆分机构部门 + * @Author: WangGeng + * @Date: 2020/6/4 11:19 下午 + * @Version: 1.0 + **/ +@ApiModel +public class SplitDepartmentVO { + + @ApiModelProperty(name = "splitDepartments", value = "拆分的部门列表") + @CheckListAnnotation(name = "拆分的部门列表") + private List splitDepartments; + + public List getSplitDepartments() { + return splitDepartments; + } + + public void setSplitDepartments(List splitDepartments) { + this.splitDepartments = splitDepartments; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"splitDepartments\":") + .append(splitDepartments); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-department/src/main/java/ink/wgink/service/department/service/IDepartmentService.java b/service-department/src/main/java/ink/wgink/service/department/service/IDepartmentService.java new file mode 100644 index 00000000..120839b6 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/service/IDepartmentService.java @@ -0,0 +1,223 @@ +package ink.wgink.service.department.service; + +import ink.wgink.interfaces.department.IDepartmentBaseService; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.bos.DepartmentBO; +import ink.wgink.pojo.dtos.ZTreeDTO; +import ink.wgink.pojo.dtos.department.DepartmentDTO; +import ink.wgink.pojo.dtos.department.DepartmentSimpleDTO; +import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.pojo.result.UploadExcelResultDTO; +import ink.wgink.service.department.pojo.vos.DepartmentVO; +import ink.wgink.service.department.pojo.vos.MergeDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.MergeNewDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.SplitDepartmentVO; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IDepartmentService + * @Description: 组织部门 + * @Author: wanggeng + * @Date: 2021/1/27 11:27 上午 + * @Version: 1.0 + */ +public interface IDepartmentService extends IDepartmentBaseService { + + /** + * 新增组织部门 + * + * @param departmentVO + * @return + */ + void save(DepartmentVO departmentVO); + + /** + * 保存部门返回ID + * + * @param departmentVO + * @return + */ + String saveReturnId(DepartmentVO departmentVO); + + /** + * 删除组织部门 + * + * @param ids + * @return + */ + void remove(List ids); + + /** + * 修改组织部门 + * + * @param departmentId + * @param departmentVO + * @return + */ + void update(String departmentId, DepartmentVO departmentVO); + + /** + * 更新合并到新增组织 + * + * @param mergeNewDepartmentInfoVO + * @return + * @throws Exception + */ + void updateMergeNew(MergeNewDepartmentInfoVO mergeNewDepartmentInfoVO); + + /** + * 更新合并到组织 + * + * @param departmentId + * @param mergeDepartmentInfoVO + * @return + */ + void updateMerge(String departmentId, MergeDepartmentInfoVO mergeDepartmentInfoVO); + + /** + * 更新分割部门 + * + * @param departmentId + * @param splitDepartmentVO + * @return + * @throws Exception + */ + void updateSplit(String departmentId, SplitDepartmentVO splitDepartmentVO); + + /** + * 重置组织部门编码 + * + * @return + */ + void resetCode(); + + /** + * 部门列表 + * + * @param params + * @return + */ + List list(Map params); + + /** + * 通过ID获取组织部门详情 + * + * @param departmentId + * @return + */ + DepartmentDTO get(String departmentId); + + /** + * easyui组织部门 + * + * @param page + * @return + */ + SuccessResultList> listPage(ListPage page); + + /** + * easyui组织部门列表 + * + * @param departmentParentId + * @param page + * @return + */ + SuccessResultList> listPageByParentId(String departmentParentId, ListPage page); + + /** + * 组织部门列表,递归获取全部内容 + * + * @param params + * @return + */ + List listAll(Map params); + + /** + * zTree组织部门 + * + * @param params + * @return + */ + List listZTree(Map params); + + /** + * zTree组织部门 + * + * @param departmentParentId + * @param params + * @return + */ + List listZTree(String departmentParentId, Map params); + + /** + * 部门ID列表 + * + * @param params + * @return + */ + List listId(Map params); + + /** + * 获取基础部门ID列表 + * + * @param departmentBOs + * @return + */ + List listId(List departmentBOs); + + /** + * 获取上级部门 + * + * @param departmentBO1 + * @param departmentBO2 + * @return + */ + DepartmentBO getHigherLevel(DepartmentBO departmentBO1, DepartmentBO departmentBO2); + + /** + * 保存部门Excel + * + * @param excel + * @return + */ + UploadExcelResultDTO uploadExcel(MultipartFile excel); + + /** + * 获得同一级部门数量(按部门名称) + * + * @param params + * @return + */ + Integer count(Map params); + + /** + * 通过ID获取组织部门详情(简单格式) + * + * @param departmentId + * @return + */ + DepartmentSimpleDTO getSimpleById(String departmentId); + + /** + * 部门列表 + * + * @param params + * @return + */ + List listSimple(Map params); + + /** + * 通过上级ID获取组织部门全部列表(简单格式) + * + * @param departmentParentId + * @return + */ + List listSimpleByParentId(String departmentParentId); + +} diff --git a/service-department/src/main/java/ink/wgink/service/department/service/impl/DepartmentServiceImpl.java b/service-department/src/main/java/ink/wgink/service/department/service/impl/DepartmentServiceImpl.java new file mode 100644 index 00000000..773c1fb8 --- /dev/null +++ b/service-department/src/main/java/ink/wgink/service/department/service/impl/DepartmentServiceImpl.java @@ -0,0 +1,451 @@ +package ink.wgink.service.department.service.impl; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.fastjson.JSONArray; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.interfaces.consts.ISystemConstant; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.bos.DepartmentBO; +import ink.wgink.pojo.dtos.ZTreeDTO; +import ink.wgink.pojo.dtos.department.DepartmentDTO; +import ink.wgink.pojo.dtos.department.DepartmentSimpleDTO; +import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.pojo.result.UploadExcelResultDTO; +import ink.wgink.service.department.dao.IDepartmentDao; +import ink.wgink.service.department.listener.excel.DepartmentExcel; +import ink.wgink.service.department.listener.excel.DepartmentExcelError; +import ink.wgink.service.department.listener.excel.DepartmentExcelListener; +import ink.wgink.service.department.pojo.vos.DepartmentVO; +import ink.wgink.service.department.pojo.vos.MergeDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.MergeNewDepartmentInfoVO; +import ink.wgink.service.department.pojo.vos.SplitDepartmentVO; +import ink.wgink.service.department.service.IDepartmentService; +import ink.wgink.util.UUIDUtil; +import ink.wgink.util.map.HashMapUtil; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.util.*; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: DepartmentServiceImpl + * @Description: 组织部门 + * @Author: wanggeng + * @Date: 2021/1/27 3:53 下午 + * @Version: 1.0 + */ +@Service +public class DepartmentServiceImpl extends DefaultBaseService implements IDepartmentService { + + @Autowired + private IDepartmentDao departmentDao; + + @Override + public void save(DepartmentVO departmentVO) { + saveReturnId(departmentVO); + } + + @Override + public String saveReturnId(DepartmentVO departmentVO) { + String parentCode = null; + String departmentParentId = departmentVO.getDepartmentParentId(); + if (!ISystemConstant.TREE_ROOT_ID.equals(departmentParentId)) { + DepartmentDTO departmentDTO = get(departmentParentId); + parentCode = departmentDTO.getDepartmentCode(); + } else { + if (!isAdmin()) { + throw new SaveException("非超级管理员无法在根节点添加组织"); + } + } + // 同级,同名组织不能添加 + if (isDepartmentExist(null, departmentVO.getDepartmentParentId(), departmentVO.getDepartmentName())) { + throw new SaveException("同级组织名称不能相同"); + } + String departmentId = UUIDUtil.getUUID(); + String departmentCode = getCode(parentCode, departmentParentId); + Map params = HashMapUtil.beanToMap(departmentVO); + setArea(departmentVO, params); + params.put("departmentCode", departmentCode); + params.put("departmentId", departmentId); + setSaveInfo(params); + departmentDao.save(params); + return departmentId; + } + + @Override + public void remove(List ids) { + // 清空组织所在人员组织信息 + for (String departmentId : ids) { + userService.deleteDepartmentUserByDepartmentId(departmentId); + } + Map params = getHashMap(2); + params.put("departmentIds", ids); + setUpdateInfo(params); + departmentDao.remove(params); + } + + @Override + public void update(String departmentId, DepartmentVO departmentVO) { + if (isDepartmentExist(departmentId, departmentVO.getDepartmentParentId(), departmentVO.getDepartmentName())) { + throw new SaveException("同级组织名称不能相同"); + } + Map params = HashMapUtil.beanToMap(departmentVO); + setArea(departmentVO, params); + params.put("departmentId", departmentId); + setUpdateInfo(params); + departmentDao.update(params); + } + + @Override + public void updateMergeNew(MergeNewDepartmentInfoVO mergeNewDepartmentInfoVO) { + String departmentId = saveReturnId(mergeNewDepartmentInfoVO); + String[] mergeDepartmentIdArray = mergeNewDepartmentInfoVO.getMergeDepartmentIds().split("_"); + mergeByDepartmentId(departmentId, mergeNewDepartmentInfoVO.getDepartmentName(), mergeDepartmentIdArray); + } + + @Override + public void updateMerge(String departmentId, MergeDepartmentInfoVO mergeDepartmentInfoVO) { + DepartmentSimpleDTO departmentSimpleDTO = getSimpleById(departmentId); + if (departmentSimpleDTO == null) { + throw new SearchException("部门不存在"); + } + String[] mergeDepartmentIdArray = mergeDepartmentInfoVO.getMergeDepartmentIds().split("_"); + mergeDepartmentByDepartmentId(departmentId, departmentSimpleDTO.getDepartmentName(), mergeDepartmentIdArray); + } + + @Override + public void updateSplit(String departmentId, SplitDepartmentVO splitDepartmentVO) { + + } + + @Override + public void resetCode() { + Map params = getHashMap(2); + resetCode("0", "", params); + } + + + @Override + public List list(Map params) { + return departmentDao.list(params); + } + + @Override + public SuccessResultList> listPage(ListPage page) { + PageHelper.startPage(page.getPage(), page.getRows()); + List departmentDTOs = list(page.getParams()); + PageInfo pageInfo = new PageInfo<>(departmentDTOs); + return new SuccessResultList<>(departmentDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); + } + + @Override + public SuccessResultList> listPageByParentId(String departmentParentId, ListPage page) { + if (StringUtils.equals(ISystemConstant.TREE_ROOT_ID, departmentParentId)) { + List listBaseDepartmentIds = listBaseDepartmentIds(); + if (!Objects.isNull(listBaseDepartmentIds)) { + page.getParams().put("departmentIds", listBaseDepartmentIds); + } else { + page.getParams().put("departmentParentId", departmentParentId); + } + return listPage(page); + } + page.getParams().put("departmentParentId", departmentParentId); + return listPage(page); + } + + @Override + public DepartmentDTO get(String departmentId) { + Map params = getHashMap(1); + params.put("departmentId", departmentId); + return departmentDao.get(params); + } + + @Override + public List listAll(Map params) { + List departmentDTOs = list(params); + listSub(departmentDTOs, params); + return departmentDTOs; + } + + @Override + public List listZTree(Map params) { + List zTreeDepartment = departmentDao.listZTree(params); + List zTreeDTOs = Arrays.asList(new ZTreeDTO[zTreeDepartment.size()]); + Collections.copy(zTreeDTOs, zTreeDepartment); + for (ZTreeDTO zTreeDTO : zTreeDTOs) { + Integer subCount = departmentDao.countByParentId(zTreeDTO.getId()); + setZTreeInfo(zTreeDTO, subCount); + } + return zTreeDTOs; + } + + @Override + public List listZTree(String departmentParentId, Map params) { + if (StringUtils.equals(ISystemConstant.TREE_ROOT_ID, departmentParentId)) { + List listBaseDepartmentIds = listBaseDepartmentIds(); + if (listBaseDepartmentIds != null && !listBaseDepartmentIds.isEmpty()) { + params.put("departmentIds", listBaseDepartmentIds); + return listZTree(params); + } + } + params.put("departmentParentId", departmentParentId); + return listZTree(params); + } + + @Override + public List listId(Map params) { + List departmentIds = new ArrayList<>(); + List departmentDTOs = list(params); + for (DepartmentDTO departmentDTO : departmentDTOs) { + departmentIds.add(departmentDTO.getDepartmentId()); + } + return departmentIds; + } + + @Override + public List listId(List departmentBOs) { + List departmentIds = new ArrayList<>(); + if (Objects.isNull(departmentBOs) || departmentBOs.isEmpty()) { + return departmentIds; + } + List departmentList = new ArrayList<>(departmentBOs); + List departmentTempList = new ArrayList<>(departmentBOs); + for (int i = 0; i < departmentList.size(); i++) { + DepartmentBO departmentBO = null; + // 找出CODE + for (DepartmentBO department : departmentList) { + DepartmentBO higherDepartmentBO = getHigherLevel(departmentList.get(i), department); + if (higherDepartmentBO != null) { + departmentBO = higherDepartmentBO; + } + } + departmentIds.add(departmentBO.getDepartmentId()); + // 删除包含关系的内容 + for (int j = 0; j < departmentList.size(); j++) { + if (StringUtils.startsWith(departmentList.get(j).getDepartmentCode(), departmentBO.getDepartmentCode())) { + departmentList.remove(j); + j--; + } + } + for (int j = 0; j < departmentTempList.size(); j++) { + if (StringUtils.startsWith(departmentTempList.get(j).getDepartmentCode(), departmentBO.getDepartmentCode())) { + departmentTempList.remove(j); + j--; + } + } + i = -1; + } + return departmentIds; + } + + @Override + public DepartmentBO getHigherLevel(DepartmentBO departmentBO1, DepartmentBO departmentBO2) { + if (StringUtils.startsWith(departmentBO1.getDepartmentCode(), departmentBO2.getDepartmentCode())) { + return departmentBO2; + } else if (StringUtils.startsWith(departmentBO2.getDepartmentCode(), departmentBO1.getDepartmentCode())) { + return departmentBO1; + } + return null; + } + + @Override + public UploadExcelResultDTO uploadExcel(MultipartFile excel) { + // 错误列表 + List departmentExcelErrors = new ArrayList<>(0); + long startTime = System.currentTimeMillis(); + EasyExcel.read(excel.getInputStream(), DepartmentExcel.class, new DepartmentExcelListener() { + @Override + public void listDepartmentExcel(List departmentExcels) throws Exception { + JSONArray listTreeDepartmentExcelJsonArray = listTreeDepartmentExcelJsonArray(0, departmentExcels, departmentExcelErrors); + saveExcel("0", null, listTreeDepartmentExcelJsonArray, departmentExcelErrors); + } + }).headRowNumber(2).sheet().doRead(); + long endTime = System.currentTimeMillis(); + String excelFileId = null; + if (departmentExcelErrors.size() > 0) { + excelFileId = new AbstractErrorExcelHandler(fileService) { + @Override + public List> excelHeaderNames() { + return simpleExcelHeader(new String[]{"ID", "组织名称", "上级ID", "组织说明", "组织电话", "类型", "错误原因"}); + } + }.saveErrorExcel(departmentExcelErrors); + } + return new UploadExcelResultDTO(departmentExcelErrors.size(), endTime - startTime, excelFileId); + } + + @Override + public Integer count(Map params) { + return null; + } + + @Override + public DepartmentSimpleDTO getSimpleById(String departmentId) { + return null; + } + + @Override + public List listSimple(Map params) { + return null; + } + + @Override + public List listSimpleByParentId(String departmentParentId) { + return null; + } + + /** + * 设置组织组织地区 + * + * @param departmentVO + * @param params + */ + private void setArea(DepartmentVO departmentVO, Map params) { + if (departmentVO.getDepartmentArea1Id() != null) { + DataAreaDTO dataAreaDTO = dataAreaService.getAreaById(departmentVO.getDepartmentArea1Id().toString()); + params.put("departmentArea1Code", dataAreaDTO.getAreaCode()); + params.put("departmentArea1Name", dataAreaDTO.getAreaName()); + } else { + params.put("departmentArea1Code", ""); + params.put("departmentArea1Name", ""); + } + if (departmentVO.getDepartmentArea2Id() != null) { + DataAreaDTO dataAreaDTO = dataAreaService.getAreaById(departmentVO.getDepartmentArea2Id().toString()); + params.put("departmentArea2Code", dataAreaDTO.getAreaCode()); + params.put("departmentArea2Name", dataAreaDTO.getAreaName()); + } else { + params.put("departmentArea2Code", ""); + params.put("departmentArea2Name", ""); + } + if (departmentVO.getDepartmentArea3Id() != null) { + DataAreaDTO dataAreaDTO = dataAreaService.getAreaById(departmentVO.getDepartmentArea3Id().toString()); + params.put("departmentArea3Code", dataAreaDTO.getAreaCode()); + params.put("departmentArea3Name", dataAreaDTO.getAreaName()); + } else { + params.put("departmentArea3Code", ""); + params.put("departmentArea3Name", ""); + } + if (departmentVO.getDepartmentArea4Id() != null) { + DataAreaDTO dataAreaDTO = dataAreaService.getAreaById(departmentVO.getDepartmentArea4Id().toString()); + params.put("departmentArea4Code", dataAreaDTO.getAreaCode()); + params.put("departmentArea4Name", dataAreaDTO.getAreaName()); + } else { + params.put("departmentArea4Code", ""); + params.put("departmentArea4Name", ""); + } + if (departmentVO.getDepartmentArea5Id() != null) { + DataAreaDTO dataAreaDTO = dataAreaService.getAreaById(departmentVO.getDepartmentArea5Id().toString()); + params.put("departmentArea5Code", dataAreaDTO.getAreaCode()); + params.put("departmentArea5Name", dataAreaDTO.getAreaName()); + } else { + params.put("departmentArea5Code", ""); + params.put("departmentArea5Name", ""); + } + } + + /** + * 重置编码 + * + * @param departmentParentId + * @param departmentParentCode + * @param params + */ + private void resetCode(String departmentParentId, String departmentParentCode, Map params) { + params.clear(); + params.put("departmentParentId", departmentParentId); + List departmentDTOs = list(params); + for (int i = 0; i < departmentDTOs.size(); i++) { + params.clear(); + int index = i + 1; + DepartmentDTO departmentDTO = departmentDTOs.get(i); + String departmentCode = String.format("%s%04d", departmentParentCode, index); + params.put("departmentId", departmentDTO.getDepartmentId()); + params.put("departmentCode", departmentCode); + departmentDao.updateCode(params); + resetCode(departmentDTO.getDepartmentId(), departmentCode, params); + } + } + + /** + * 递归查询子部门 + * + * @param departmentDTOs + * @param params + */ + private void listSub(List departmentDTOs, Map params) throws SearchException { + for (DepartmentDTO departmentDTO : departmentDTOs) { + params.put("departmentParentId", departmentDTO.getDepartmentId()); + List subDepartmentDTOs = list(params); + departmentDTO.setSubDepartments(subDepartmentDTOs); + listSub(subDepartmentDTOs, params); + } + } + + /** + * 合并组织到指定组织 + * + * @param departmentId + * @param mergeDepartmentIdArray + */ + private void mergeDepartmentByDepartmentId(String departmentId, String departmentName, String[] mergeDepartmentIdArray) { + DepartmentDTO departmentDTO = get(departmentId); + if (departmentDTO == null) { + throw new SearchException("并入部门不存在"); + } + List departmentUserIds = new ArrayList<>(); + for (String mergeDepartmentId : mergeDepartmentIdArray) { + DepartmentDTO mergeDepartmentDTO = get(mergeDepartmentId); + if (mergeDepartmentDTO == null) { + throw new SearchException("合并部门不存在"); + } + LOG.debug("新增合并日志"); + saveDepartmentAdjustment(mergeDepartmentId, mergeDepartmentDTO.getDepartmentName(), departmentId, departmentDTO.getDepartmentName(), DepartmentAdjustmentTypeEnum.MERGE); + LOG.debug("删除需要合并的组织人员"); + List oldDepartmentUserIds = removeDepartmentByDepartmentIdReturnDeletedDepartmentUserIds(mergeDepartmentId, mergeDepartmentDTO.getDepartmentName()); + departmentUserIds.addAll(oldDepartmentUserIds); + } + LOG.debug("将合并组织的人员添加到新组织"); + userService.saveDepartmentUserIdByDepartmentId(departmentId, departmentName, departmentUserIds); + } + + /** + * 组织是否存在 + * + * @param excludeDepartmentId + * @param departmentParentId + * @param departmentName + * @return + */ + private boolean isDepartmentExist(String excludeDepartmentId, String departmentParentId, String departmentName) { + Map params = getHashMap(3); + params.put("excludeDepartmentId", excludeDepartmentId); + params.put("departmentParentId", departmentParentId); + params.put("departmentName", departmentName.trim()); + DepartmentDTO departmentDTO = departmentDao.get(params); + if (departmentDTO == null) { + return false; + } + return false; + } + + /** + * 获取code + * + * @param parentCode + * @param parentId + * @return + */ + private String getCode(String parentCode, String parentId) { + DepartmentDTO departmentDTO = departmentDao.getLastByParentId(parentId); + String code = departmentDTO != null ? departmentDTO.getDepartmentCode() : "0000"; + return super.getNewCode(code, parentCode); + } +} diff --git a/service-department/src/main/resources/mybatis/mapper/department-mapper.xml b/service-department/src/main/resources/mybatis/mapper/department-mapper.xml new file mode 100644 index 00000000..b7c49174 --- /dev/null +++ b/service-department/src/main/resources/mybatis/mapper/department-mapper.xml @@ -0,0 +1,865 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO sys_department( + department_id, + department_parent_id, + department_name, + department_name_en, + department_name_other, + department_summary, + department_code, + department_logo, + department_logo_hover, + department_type, + department_state, + department_fax, + department_tel, + department_address, + department_master, + department_duty, + department_area1_id, + department_area1_code, + department_area1_name, + department_area2_id, + department_area2_code, + department_area2_name, + department_area3_id, + department_area3_code, + department_area3_name, + department_area4_id, + department_area4_code, + department_area4_name, + department_area5_id, + department_area5_code, + department_area5_name, + department_longitude, + department_latitude, + department_order, + creator, + gmt_create, + modifier, + gmt_modified, + is_delete + ) VALUES( + #{departmentId}, + #{departmentParentId}, + #{departmentName}, + #{departmentNameEn}, + #{departmentNameOther}, + #{departmentSummary}, + #{departmentCode}, + #{departmentLogo}, + #{departmentLogoHover}, + #{departmentType}, + #{departmentState}, + #{departmentFax}, + #{departmentTel}, + #{departmentAddress}, + #{departmentMaster}, + #{departmentDuty}, + #{departmentArea1Id}, + #{departmentArea1Code}, + #{departmentArea1Name}, + #{departmentArea2Id}, + #{departmentArea2Code}, + #{departmentArea2Name}, + #{departmentArea3Id}, + #{departmentArea3Code}, + #{departmentArea3Name}, + #{departmentArea4Id}, + #{departmentArea4Code}, + #{departmentArea4Name}, + #{departmentArea5Id}, + #{departmentArea5Code}, + #{departmentArea5Name}, + #{departmentLongitude}, + #{departmentLatitude}, + #{departmentOrder}, + #{creator}, + #{gmtCreate}, + #{modifier}, + #{gmtModified}, + #{isDelete} + ) + + + + + UPDATE + sys_department + SET + is_delete = 1, + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + department_id IN + + #{departmentIds[${index}]} + + + + + + UPDATE + sys_department + SET + + department_name = #{departmentName}, + + + department_name_en = #{departmentNameEn}, + + + department_name_other = #{departmentNameOther}, + + + department_summary = #{departmentSummary}, + + + department_code = #{departmentCode}, + + + department_logo = #{departmentLogo}, + + + department_logo_hover = #{departmentLogoHover}, + + + department_type = #{departmentType}, + + + department_state = #{departmentState}, + + + department_fax = #{departmentFax}, + + + department_tel = #{departmentTel}, + + + department_address = #{departmentAddress}, + + + department_master = #{departmentMaster}, + + + department_duty = #{departmentDuty}, + + department_area1_id = #{departmentArea1Id}, + + department_area1_code = #{departmentArea1Code}, + + + department_area1_name = #{departmentArea1Name}, + + department_area2_id = #{departmentArea2Id}, + + department_area2_code = #{departmentArea2Code}, + + + department_area2_name = #{departmentArea2Name}, + + department_area3_id = #{departmentArea3Id}, + + department_area3_code = #{departmentArea3Code}, + + + department_area3_name = #{departmentArea3Name}, + + department_area4_id = #{departmentArea4Id}, + + department_area4_code = #{departmentArea4Code}, + + + department_area4_name = #{departmentArea4Name}, + + department_area5_id = #{departmentArea5Id}, + + department_area5_code = #{departmentArea5Code}, + + + department_area5_name = #{departmentArea5Name}, + + + department_longitude = #{departmentLongitude}, + + + department_latitude = #{departmentLatitude}, + + + department_order = #{departmentOrder}, + + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + department_id = #{departmentId} + + + + + UPDATE + sys_department + SET + department_code = #{departmentCode} + WHERE + department_id = #{departmentId} + + + + + UPDATE + sys_department + SET + department_state = #{departmentState} + WHERE + department_id = #{departmentId} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/service-role/pom.xml b/service-role/pom.xml new file mode 100644 index 00000000..ed6baef3 --- /dev/null +++ b/service-role/pom.xml @@ -0,0 +1,24 @@ + + + + wg-basic + ink.wgink + 1.0-SNAPSHOT + + 4.0.0 + + service-role + 角色业务 + + + + ink.wgink + service-user + 1.0-SNAPSHOT + + + + + \ No newline at end of file diff --git a/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java b/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java new file mode 100644 index 00000000..355a8631 --- /dev/null +++ b/service-role/src/main/java/ink/wgink/service/role/controller/api/RoleController.java @@ -0,0 +1,22 @@ +package ink.wgink.service.role.controller.api; + +import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.interfaces.consts.ISystemConstant; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @ClassName: RoleController + * @Description: 角色 + * @Author: wenc + * @Date: 2019/1/6 3:03 PM + * @Version: 1.0 + * @MenuUrl: admin/role/goroles + **/ +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "角色信息管理接口") +@RestController +@RequestMapping(ISystemConstant.API_PREFIX + "/role") +public class RoleController extends DefaultBaseController { + +} diff --git a/service-user/pom.xml b/service-user/pom.xml index 5b9f9455..9ba6bc95 100644 --- a/service-user/pom.xml +++ b/service-user/pom.xml @@ -10,11 +10,12 @@ 4.0.0 service-user + 用户业务 ink.wgink - common + module-file 1.0-SNAPSHOT diff --git a/service-user/src/main/java/ink/wgink/service/user/controller/api/UserController.java b/service-user/src/main/java/ink/wgink/service/user/controller/api/UserController.java index 98531b9b..e70df64a 100644 --- a/service-user/src/main/java/ink/wgink/service/user/controller/api/UserController.java +++ b/service-user/src/main/java/ink/wgink/service/user/controller/api/UserController.java @@ -1,10 +1,24 @@ package ink.wgink.service.user.controller.api; import ink.wgink.common.base.DefaultBaseController; +import ink.wgink.exceptions.ParamsException; import ink.wgink.interfaces.consts.ISystemConstant; -import io.swagger.annotations.Api; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.dtos.user.UserDTO; +import ink.wgink.pojo.result.ErrorResult; +import ink.wgink.pojo.result.SuccessResult; +import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.service.user.pojo.vos.UserVO; +import ink.wgink.service.user.service.IUserService; +import ink.wgink.util.RegexUtil; +import io.swagger.annotations.*; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** * When you feel like quitting. Think about why you started @@ -16,11 +30,83 @@ import org.springframework.web.bind.annotation.RestController; * @Date: 2021/1/24 17:10 * @Version: 1.0 **/ -@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户信息管理") +@Api(tags = ISystemConstant.API_TAGS_SYSTEM_PREFIX + "用户") @RestController @RequestMapping(ISystemConstant.API_PREFIX + "/user") public class UserController extends DefaultBaseController { + @Autowired + private IUserService userService; + @ApiOperation(value = "用户新增", notes = "用户新增接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping("save") + public SuccessResult save(@RequestBody UserVO userVO) { + checkParams(userVO); + userService.save(userVO); + return new SuccessResult(); + } + + @ApiOperation(value = "用户删除", notes = "用户删除接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "ids", value = "用户ID列表,用下划线分隔", paramType = "path") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @DeleteMapping("remove/{ids}") + public SuccessResult remove(@PathVariable("ids") String ids) { + userService.remove(Arrays.asList(ids.split("\\_"))); + return new SuccessResult(); + } + + @ApiOperation(value = "用户修改", notes = "用户修改接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path"), + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PutMapping("update/{userId}") + public SuccessResult update(@PathVariable("userId") String userId, @RequestBody UserVO userVO) { + checkParams(userVO); + userService.update(userId, userVO); + return new SuccessResult(); + } + + /** + * 参数校验 + * + * @param userVO + * @throws ParamsException + */ + private void checkParams(UserVO userVO) throws ParamsException { + if (!StringUtils.isBlank(userVO.getUserPhone()) && !RegexUtil.isPhone(userVO.getUserPhone())) { + throw new ParamsException("手机号码格式错误"); + } + if (!StringUtils.isBlank(userVO.getUserEmail()) && !RegexUtil.isEmail(userVO.getUserEmail())) { + throw new ParamsException("用户邮箱格式错误"); + } + } + + @ApiOperation(value = "用户列表", notes = "用户列表接口") + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("list") + public List list() { + Map params = requestParams(); + return userService.list(params); + } + + @ApiOperation(value = "用户分页列表", notes = "用户分页列表接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "page", value = "当前页码", paramType = "query", dataType = "int", defaultValue = "1"), + @ApiImplicitParam(name = "rows", value = "显示数量", paramType = "query", dataType = "int", defaultValue = "20"), + @ApiImplicitParam(name = "keywords", value = "关键字", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "startTime", value = "开始时间", paramType = "query", dataType = "String"), + @ApiImplicitParam(name = "endTime", value = "结束时间", paramType = "query", dataType = "String") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @GetMapping("listpage") + public SuccessResultList> listPage(ListPage page) { + Map params = requestParams(); + page.setParams(params); + return userService.listPage(page); + } } diff --git a/service-user/src/main/java/ink/wgink/service/user/dao/IUserDao.java b/service-user/src/main/java/ink/wgink/service/user/dao/IUserDao.java index 4f043e83..ee17ad1e 100644 --- a/service-user/src/main/java/ink/wgink/service/user/dao/IUserDao.java +++ b/service-user/src/main/java/ink/wgink/service/user/dao/IUserDao.java @@ -1,7 +1,16 @@ package ink.wgink.service.user.dao; +import ink.wgink.exceptions.RemoveException; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.exceptions.UpdateException; +import ink.wgink.pojo.dtos.user.UserDTO; +import ink.wgink.service.user.pojo.pos.UserPO; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Map; + /** * When you feel like quitting. Think about why you started * 当你想要放弃的时候,想想当初你为何开始 @@ -14,4 +23,81 @@ import org.springframework.stereotype.Repository; **/ @Repository public interface IUserDao { + + /** + * 新增 + * + * @param params + * @throws SaveException + */ + void save(Map params) throws SaveException; + + /** + * 删除 + * + * @param params + * @throws RemoveException + */ + void remove(Map params) throws RemoveException; + + /** + * 修改 + * + * @param params + * @throws UpdateException + */ + void update(Map params) throws UpdateException; + + /** + * 修改密码 + * + * @param params + * @throws UpdateException + */ + void updatePassword(Map params) throws UpdateException; + + /** + * 修改用户名 + * + * @param params + * @throws UpdateException + */ + void updateUsername(Map params) throws UpdateException; + + /** + * 详情 + * + * @param params + * @return + * @throws SaveException + */ + UserPO getPO(Map params) throws SearchException; + + /** + * 详情 + * + * @param params + * @return + * @throws SearchException + */ + UserDTO get(Map params) throws SearchException; + + /** + * 列表 + * + * @param params + * @return + * @throws SearchException + */ + List list(Map params) throws SearchException; + + /** + * 总数 + * + * @param params + * @return + * @throws SearchException + */ + Integer count(Map params) throws SearchException; + } diff --git a/service-user/src/main/java/ink/wgink/service/user/pojo/pos/UserPO.java b/service-user/src/main/java/ink/wgink/service/user/pojo/pos/UserPO.java new file mode 100644 index 00000000..b4136246 --- /dev/null +++ b/service-user/src/main/java/ink/wgink/service/user/pojo/pos/UserPO.java @@ -0,0 +1,194 @@ +package ink.wgink.service.user.pojo.pos; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserPO + * @Description: 用户 + * @Author: wanggeng + * @Date: 2021/1/27 10:15 上午 + * @Version: 1.0 + */ +@ApiModel +public class UserPO implements Serializable { + + private static final long serialVersionUID = -9198716902763162718L; + private String userId; + private String userUsername; + private String userPassword; + private String userName; + private String userPhone; + private String userEmail; + private String userUKey; + private Integer userType; + private Integer userState; + private String userAvatar; + private String lastLoginAddress; + private String lastLoginTime; + private String userLongitude; + private String userLatitude; + private Integer loginType; + + public String getUserId() { + return userId == null ? "" : userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUserUsername() { + return userUsername == null ? "" : userUsername; + } + + public void setUserUsername(String userUsername) { + this.userUsername = userUsername; + } + + public String getUserPassword() { + return userPassword == null ? "" : userPassword; + } + + public void setUserPassword(String userPassword) { + this.userPassword = userPassword; + } + + public String getUserName() { + return userName == null ? "" : userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUserPhone() { + return userPhone == null ? "" : userPhone; + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public String getUserEmail() { + return userEmail == null ? "" : userEmail; + } + + public void setUserEmail(String userEmail) { + this.userEmail = userEmail; + } + + public String getUserUKey() { + return userUKey == null ? "" : userUKey; + } + + public void setUserUKey(String userUKey) { + this.userUKey = userUKey; + } + + public Integer getUserType() { + return userType == null ? 0 : userType; + } + + public void setUserType(Integer userType) { + this.userType = userType; + } + + public Integer getUserState() { + return userState == null ? 0 : userState; + } + + public void setUserState(Integer userState) { + this.userState = userState; + } + + public String getUserAvatar() { + return userAvatar == null ? "" : userAvatar; + } + + public void setUserAvatar(String userAvatar) { + this.userAvatar = userAvatar; + } + + public String getLastLoginAddress() { + return lastLoginAddress == null ? "" : lastLoginAddress; + } + + public void setLastLoginAddress(String lastLoginAddress) { + this.lastLoginAddress = lastLoginAddress; + } + + public String getLastLoginTime() { + return lastLoginTime == null ? "" : lastLoginTime; + } + + public void setLastLoginTime(String lastLoginTime) { + this.lastLoginTime = lastLoginTime; + } + + public String getUserLongitude() { + return userLongitude == null ? "" : userLongitude; + } + + public void setUserLongitude(String userLongitude) { + this.userLongitude = userLongitude; + } + + public String getUserLatitude() { + return userLatitude == null ? "" : userLatitude; + } + + public void setUserLatitude(String userLatitude) { + this.userLatitude = userLatitude; + } + + public Integer getLoginType() { + return loginType == null ? 0 : loginType; + } + + public void setLoginType(Integer loginType) { + this.loginType = loginType; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"userId\":\"") + .append(userId).append('\"'); + sb.append(",\"userUsername\":\"") + .append(userUsername).append('\"'); + sb.append(",\"userPassword\":\"") + .append(userPassword).append('\"'); + sb.append(",\"userName\":\"") + .append(userName).append('\"'); + sb.append(",\"userPhone\":\"") + .append(userPhone).append('\"'); + sb.append(",\"userEmail\":\"") + .append(userEmail).append('\"'); + sb.append(",\"userUKey\":\"") + .append(userUKey).append('\"'); + sb.append(",\"userType\":") + .append(userType); + sb.append(",\"userState\":") + .append(userState); + sb.append(",\"userAvatar\":\"") + .append(userAvatar).append('\"'); + sb.append(",\"lastLoginAddress\":\"") + .append(lastLoginAddress).append('\"'); + sb.append(",\"lastLoginTime\":\"") + .append(lastLoginTime).append('\"'); + sb.append(",\"userLongitude\":\"") + .append(userLongitude).append('\"'); + sb.append(",\"userLatitude\":\"") + .append(userLatitude).append('\"'); + sb.append(",\"loginType\":") + .append(loginType); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-user/src/main/java/ink/wgink/service/user/pojo/vos/UserVO.java b/service-user/src/main/java/ink/wgink/service/user/pojo/vos/UserVO.java new file mode 100644 index 00000000..90b0703d --- /dev/null +++ b/service-user/src/main/java/ink/wgink/service/user/pojo/vos/UserVO.java @@ -0,0 +1,126 @@ +package ink.wgink.service.user.pojo.vos; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import ink.wgink.annotation.CheckNumberAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @ClassName: UserVO + * @Description: 用户视图对象 + * @Author: WangGeng + * @Date: 2019/3/3 9:49 PM + * @Version: 1.0 + **/ +@ApiModel +public class UserVO { + + @ApiModelProperty(name = "userUsername", value = "用户名") + @CheckEmptyAnnotation(name = "用户名") + private String userUsername; + @ApiModelProperty(name = "userPassword", value = "密码") + @CheckEmptyAnnotation(name = "密码") + private String userPassword; + @ApiModelProperty(name = "userName", value = "昵称") + @CheckEmptyAnnotation(name = "昵称") + private String userName; + @ApiModelProperty(name = "userType", value = "用户类型,1:系统用户,2:普通该用户") + @CheckNumberAnnotation(name = "用户类型", types = {"1", "2"}) + private Integer userType; + @ApiModelProperty(name = "userState", value = "用户状态,0:正常,1:冻结,2:锁定") + @CheckNumberAnnotation(name = "用户状态", types = {"0", "1", "2"}) + private Integer userState; + @ApiModelProperty(name = "userPhone", value = "用户电话") + private String userPhone; + @ApiModelProperty(name = "userEmail", value = "用户邮件") + private String userEmail; + @ApiModelProperty(name = "userAvatar", value = "用户头像ID") + private String userAvatar; + + public String getUserUsername() { + return userUsername == null ? "" : userUsername.trim(); + } + + public void setUserUsername(String userUsername) { + this.userUsername = userUsername; + } + + public String getUserPassword() { + return userPassword; + } + + public void setUserPassword(String userPassword) { + this.userPassword = userPassword; + } + + public String getUserName() { + return userName == null ? "" : userName.trim(); + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Integer getUserType() { + return userType; + } + + public void setUserType(Integer userType) { + this.userType = userType; + } + + public Integer getUserState() { + return userState; + } + + public void setUserState(Integer userState) { + this.userState = userState; + } + + public String getUserPhone() { + return userPhone == null ? "" : userPhone.trim(); + } + + public void setUserPhone(String userPhone) { + this.userPhone = userPhone; + } + + public String getUserEmail() { + return userEmail == null ? "" : userEmail.trim(); + } + + public void setUserEmail(String userEmail) { + this.userEmail = userEmail; + } + + public String getUserAvatar() { + return userAvatar == null ? "" : userAvatar.trim(); + } + + public void setUserAvatar(String userAvatar) { + this.userAvatar = userAvatar; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"userUsername\":\"") + .append(userUsername).append('\"'); + sb.append(",\"userPassword\":\"") + .append(userPassword).append('\"'); + sb.append(",\"userName\":\"") + .append(userName).append('\"'); + sb.append(",\"userType\":") + .append(userType); + sb.append(",\"userState\":") + .append(userState); + sb.append(",\"userPhone\":\"") + .append(userPhone).append('\"'); + sb.append(",\"userEmail\":\"") + .append(userEmail).append('\"'); + sb.append(",\"userAvatar\":\"") + .append(userAvatar).append('\"'); + sb.append('}'); + return sb.toString(); + } +} diff --git a/service-user/src/main/java/ink/wgink/service/user/service/IUserService.java b/service-user/src/main/java/ink/wgink/service/user/service/IUserService.java new file mode 100644 index 00000000..91f718ea --- /dev/null +++ b/service-user/src/main/java/ink/wgink/service/user/service/IUserService.java @@ -0,0 +1,57 @@ +package ink.wgink.service.user.service; + +import ink.wgink.exceptions.RemoveException; +import ink.wgink.exceptions.SaveException; +import ink.wgink.exceptions.SearchException; +import ink.wgink.interfaces.user.IUserBaseService; +import ink.wgink.pojo.result.SuccessResult; +import ink.wgink.service.user.pojo.vos.UserVO; +import ink.wgink.util.map.HashMapUtil; + +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: IUserService + * @Description: 用户 + * @Author: wanggeng + * @Date: 2021/1/25 3:06 下午 + * @Version: 1.0 + */ +public interface IUserService extends IUserBaseService { + + /** + * 保存用户 + * + * @param userVO + * @return + */ + void save(UserVO userVO); + + /** + * 注册用户 + * + * @param userVO + * @return + */ + void register(UserVO userVO); + + /** + * 删除用户 + * + * @param ids id数组 + * @return + */ + void remove(List ids); + + /** + * 修改用户 + * + * @param userId + * @param userVO + * @return + */ + void update(String userId, UserVO userVO); +} diff --git a/service-user/src/main/java/ink/wgink/service/user/service/UserServiceImpl.java b/service-user/src/main/java/ink/wgink/service/user/service/UserServiceImpl.java deleted file mode 100644 index e823cb77..00000000 --- a/service-user/src/main/java/ink/wgink/service/user/service/UserServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package ink.wgink.service.user.service; - -import ink.wgink.common.base.DefaultBaseService; -import ink.wgink.interfaces.user.IUserService; -import org.springframework.stereotype.Service; - -/** - * When you feel like quitting. Think about why you started - * 当你想要放弃的时候,想想当初你为何开始 - * - * @ClassName: UserServiceImpl - * @Description: 用户 - * @Author: WangGeng - * @Date: 2021/1/24 20:25 - * @Version: 1.0 - **/ -@Service -public class UserServiceImpl extends DefaultBaseService implements IUserService { - - - -} diff --git a/service-user/src/main/java/ink/wgink/service/user/service/impl/UserServiceImpl.java b/service-user/src/main/java/ink/wgink/service/user/service/impl/UserServiceImpl.java new file mode 100644 index 00000000..ce8df086 --- /dev/null +++ b/service-user/src/main/java/ink/wgink/service/user/service/impl/UserServiceImpl.java @@ -0,0 +1,120 @@ +package ink.wgink.service.user.service.impl; + +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.exceptions.SearchException; +import ink.wgink.pojo.ListPage; +import ink.wgink.pojo.dtos.user.UserDTO; +import ink.wgink.pojo.result.SuccessResultList; +import ink.wgink.service.user.dao.IUserDao; +import ink.wgink.service.user.pojo.vos.UserVO; +import ink.wgink.service.user.service.IUserService; +import ink.wgink.util.UUIDUtil; +import ink.wgink.util.map.HashMapUtil; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: UserServiceImpl + * @Description: 用户 + * @Author: WangGeng + * @Date: 2021/1/24 20:25 + * @Version: 1.0 + **/ +@Service +public class UserServiceImpl extends DefaultBaseService implements IUserService { + + @Autowired + private IUserDao userDao; + @Autowired + private PasswordEncoder passwordEncoder; + + @Override + public synchronized void save(UserVO userVO) { + saveUser(userVO, false); + } + + @Override + public void register(UserVO userVO) { + saveUser(userVO, true); + } + + /** + * 保存用户 + * + * @param userVO + * @param isRegister 是否注册 + */ + private void saveUser(UserVO userVO, boolean isRegister) { + UserDTO userDTO = get(userVO.getUserUsername()); + if (userDTO != null) { + throw new SearchException("用户已经存在"); + } + userVO.setUserPassword(passwordEncoder.encode(DigestUtils.md5Hex(DigestUtils.md5Hex(DigestUtils.md5Hex(userVO.getUserPassword()))))); + String userId = UUIDUtil.getUUID(); + Map params = HashMapUtil.beanToMap(userVO); + params.put("userId", userId); + if (isRegister) { + setSaveInfoByUserId(params, userId); + } else { + setSaveInfo(params); + } + userDao.save(params); + } + + @Override + public void remove(List ids) { + Map params = getHashMap(2); + params.put("ids", ids); + setUpdateInfo(params); + userDao.remove(params); + } + + @Override + public void update(String userId, UserVO userVO) { + if (!StringUtils.isBlank(userVO.getUserPassword())) { + userVO.setUserPassword(passwordEncoder.encode(DigestUtils.md5Hex(DigestUtils.md5Hex(DigestUtils.md5Hex(userVO.getUserPassword()))))); + } + Map params = HashMapUtil.beanToMap(userVO); + setUpdateInfo(params); + userDao.update(params); + } + + @Override + public UserDTO get(String userId) { + Map params = getHashMap(2); + params.put("userId", userId); + return userDao.get(params); + } + + @Override + public UserDTO getByUsername(String username) { + Map params = getHashMap(2); + params.put("userUsername", username); + return userDao.get(params); + } + + @Override + public List list(Map params) { + return userDao.list(params); + } + + @Override + public SuccessResultList> listPage(ListPage page) { + PageHelper.startPage(page.getPage(), page.getRows()); + List userDTOs = list(page.getParams()); + PageInfo pageInfo = new PageInfo<>(userDTOs); + return new SuccessResultList<>(userDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); + } + +} diff --git a/service-user/src/main/resources/mybatis/mapper/user-mapper.xml b/service-user/src/main/resources/mybatis/mapper/user-mapper.xml new file mode 100644 index 00000000..d6d978c0 --- /dev/null +++ b/service-user/src/main/resources/mybatis/mapper/user-mapper.xml @@ -0,0 +1,366 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO sys_user( + user_id, + user_username, + user_password, + user_name, + user_phone, + user_email, + user_type, + user_state, + user_avatar, + creator, + gmt_create, + modifier, + gmt_modified, + is_delete + ) VALUES( + #{userId}, + #{userUsername}, + #{userPassword}, + #{userName}, + #{userPhone}, + #{userEmail}, + #{userType}, + #{userState}, + #{userAvatar}, + #{creator}, + #{gmtCreate}, + #{modifier}, + #{gmtModified}, + #{isDelete} + ) + + + + + UPDATE + sys_user + SET + is_delete = 1, + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + user_id IN + + #{userIds[${index}]} + + + + + + UPDATE + sys_user + SET + + user_password = #{userPassword}, + + + user_name = #{userName}, + + + user_phone = #{userPhone}, + + + user_email = #{userEmail}, + + + user_type = #{userType}, + + + user_state = #{userState}, + + + user_avatar = #{userAvatar}, + + + last_login_address = #{lastLoginAddress}, + + + last_login_time = #{lastLoginTime}, + + + gmt_password_modified = #{gmtPasswordModified}, + + + user_ukey = #{userUKey}, + + + user_ukey_electronic_secret_key = #{userUKeyElectronicSecretKey}, + + + login_type = #{loginType}, + + modifier = #{modifier}, + gmt_modified = #{gmtModified} + WHERE + user_id = #{userId} + + + + + UPDATE + sys_user + SET + user_password = #{userPassword} + WHERE + user_id = #{userId} + + + + + UPDATE + sys_user + SET + user_username = #{userUsername} + WHERE + user_id = #{userId} + + + + + + + + + + + + + + + \ No newline at end of file