瀏覽代碼

加入鉴权

wangliang 4 年之前
父節點
當前提交
3f424c2f77
共有 37 個文件被更改,包括 3368 次插入79 次删除
  1. 31 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/annotation/ExcelProperty.java
  2. 85 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/auth/AuthBean.java
  3. 33 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/auth/ExpireTimeBean.java
  4. 132 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PrivilegeCacheDto.java
  5. 16 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/query/LoginParam.java
  6. 89 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/EditResult.java
  7. 247 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/LoginResult.java
  8. 138 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/PrivilegeResult.java
  9. 70 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/RolePrivilegeResult.java
  10. 34 12
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/SysUserRole.java
  11. 190 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TBSession.java
  12. 44 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/PrivilegePropertyEnum.java
  13. 50 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/UploadFileEnum.java
  14. 16 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/TBSessionMapper.java
  15. 149 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CacheService.java
  16. 93 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CommonService.java
  17. 16 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TBSessionService.java
  18. 239 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CacheServiceImpl.java
  19. 322 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CommonServiceImpl.java
  20. 20 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBSessionServiceImpl.java
  21. 186 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/AuthUtil.java
  22. 53 8
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ExcelUtil.java
  23. 34 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/OssUtil.java
  24. 236 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/RedisUtil.java
  25. 171 3
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ServletUtil.java
  26. 60 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ColumnSetting.java
  27. 79 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ExcelExport.java
  28. 92 0
      distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ExcelWriter.java
  29. 5 0
      distributed-print-business/src/main/resources/mapper/TBSessionMapper.xml
  30. 228 0
      distributed-print-common/src/main/java/com/qmth/distributed/print/common/SignatureEntityTest.java
  31. 39 1
      distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java
  32. 56 8
      distributed-print-common/src/main/java/com/qmth/distributed/print/common/enums/ExceptionResultEnum.java
  33. 92 25
      distributed-print/src/main/java/com/qmth/distributed/print/api/SysController.java
  34. 7 12
      distributed-print/src/main/java/com/qmth/distributed/print/aspect/ApiControllerAspect.java
  35. 12 7
      distributed-print/src/main/java/com/qmth/distributed/print/config/SwaggerConfig.java
  36. 2 1
      distributed-print/src/main/java/com/qmth/distributed/print/interceptor/AuthInterceptor.java
  37. 2 2
      distributed-print/src/main/resources/application.properties

+ 31 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/annotation/ExcelProperty.java

@@ -0,0 +1,31 @@
+package com.qmth.distributed.print.business.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.FIELD)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface ExcelProperty {
+	/**
+	 * 导出时列名
+	 */
+    String name() default "";
+    
+	/**
+	 * 导出时列宽
+	 */
+    int width() default 0;
+	/**
+	 * 排序
+	 */
+    int index();
+    /**
+     * 类型
+     * 0:导入(读excel)
+     * 1:导出(写excel)
+     * 2:导入&导出
+     */
+    int type() default 2;
+}

+ 85 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/auth/AuthBean.java

@@ -0,0 +1,85 @@
+package com.qmth.distributed.print.business.bean.auth;
+
+import com.qmth.distributed.print.business.entity.BasicSchool;
+import com.qmth.distributed.print.business.entity.SysOrg;
+import com.qmth.distributed.print.business.entity.SysRole;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Description: 鉴权 bean
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/26
+ */
+public class AuthBean implements Serializable {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(name = "角色集合")
+    private List<SysRole> roleList;
+
+    @ApiModelProperty(name = "url集合")
+    private Set<String> urls;
+
+    @ApiModelProperty(name = "学校信息")
+    private BasicSchool school;
+
+    @ApiModelProperty(name = "机构信息")
+    private SysOrg org;
+
+    public BasicSchool getSchool() {
+        return school;
+    }
+
+    public void setSchool(BasicSchool school) {
+        this.school = school;
+    }
+
+    public AuthBean() {
+
+    }
+
+    public AuthBean(List<SysRole> roleList, Set<String> urls) {
+        this.roleList = roleList;
+        this.urls = urls;
+    }
+
+    public AuthBean(List<SysRole> roleList, Set<String> urls, BasicSchool school, SysOrg org) {
+        this.roleList = roleList;
+        this.urls = urls;
+        this.school = school;
+        this.org = org;
+    }
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public List<SysRole> getRoleList() {
+        return roleList;
+    }
+
+    public void setRoleList(List<SysRole> roleList) {
+        this.roleList = roleList;
+    }
+
+    public Set<String> getUrls() {
+        return urls;
+    }
+
+    public void setUrls(Set<String> urls) {
+        this.urls = urls;
+    }
+
+    public SysOrg getOrg() {
+        return org;
+    }
+
+    public void setOrg(SysOrg org) {
+        this.org = org;
+    }
+}

+ 33 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/auth/ExpireTimeBean.java

@@ -0,0 +1,33 @@
+package com.qmth.distributed.print.business.bean.auth;
+
+import java.util.Date;
+
+/**
+ * @Description: 过期时间bean
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/25
+ */
+public class ExpireTimeBean {
+
+    private Date date;
+
+    private long expireSeconds;
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public long getExpireSeconds() {
+        return expireSeconds;
+    }
+
+    public void setExpireSeconds(long expireSeconds) {
+        this.expireSeconds = expireSeconds;
+    }
+}

+ 132 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PrivilegeCacheDto.java

@@ -0,0 +1,132 @@
+package com.qmth.distributed.print.business.bean.dto;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.enums.PrivilegeEnum;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * @Description: 权限临时dto
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/27
+ */
+public class PrivilegeCacheDto implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "角色id")
+    Long id;
+
+    @ApiModelProperty(value = "角色名称")
+    String name;
+
+    @ApiModelProperty(value = "角色类别")
+    RoleTypeEnum type;
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "权限id")
+    Long privilegeId;
+
+    @ApiModelProperty(value = "权限名称")
+    String privilegeName;
+
+    @ApiModelProperty(value = "权限地址")
+    String url;
+
+    @ApiModelProperty(value = "权限类别")
+    PrivilegeEnum privilegeType;
+
+    @ApiModelProperty(value = "父id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    Long parentId;
+
+    @ApiModelProperty(value = "序号")
+    Integer sequence;
+
+    @ApiModelProperty(value = "是否启用,false:停用,true:启用")
+    Boolean enable;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public RoleTypeEnum getType() {
+        return type;
+    }
+
+    public void setType(RoleTypeEnum type) {
+        this.type = type;
+    }
+
+    public Long getPrivilegeId() {
+        return privilegeId;
+    }
+
+    public void setPrivilegeId(Long privilegeId) {
+        this.privilegeId = privilegeId;
+    }
+
+    public String getPrivilegeName() {
+        return privilegeName;
+    }
+
+    public void setPrivilegeName(String privilegeName) {
+        this.privilegeName = privilegeName;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public PrivilegeEnum getPrivilegeType() {
+        return privilegeType;
+    }
+
+    public void setPrivilegeType(PrivilegeEnum privilegeType) {
+        this.privilegeType = privilegeType;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public Integer getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(Integer sequence) {
+        this.sequence = sequence;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+}

+ 16 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/query/LoginParam.java

@@ -1,12 +1,28 @@
 package com.qmth.distributed.print.business.bean.query;
 
+import io.swagger.annotations.ApiModelProperty;
+import org.hibernate.validator.constraints.Length;
+
+import javax.validation.constraints.NotBlank;
+
 /**
  * @Date: 2021/3/30.
  */
 public class LoginParam {
 
+    @ApiModelProperty(value = "登录名")
+    @NotBlank(message = "请输入登录名")
+    @Length(message = "登录名不能超过{max}个字符", max = 25)
     private String loginName;
+
+    @ApiModelProperty(value = "密码")
+    @NotBlank(message = "请输入密码")
+    @Length(message = "密码不能少于{min}位", min = 6)
+    @Length(message = "密码不能超过{max}位", max = 30)
     private String password;
+
+    @ApiModelProperty(value = "验证码")
+    @NotBlank(message = "请输入验证码")
     private String code;
 
     public String getLoginName() {

+ 89 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/EditResult.java

@@ -0,0 +1,89 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.util.ServletUtil;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.Arrays;
+import java.util.Objects;
+
+/**
+ * @Description: 新增/更新返回值
+ * @Author: CaoZixuan
+ * @Date: 2021-03-22
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class EditResult {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    private Long id;
+
+    @ApiModelProperty(value = "更新时间")
+    Long updateTime;
+
+    @ApiModelProperty(value = "成功状态")
+    Boolean success;
+
+    @ApiModelProperty(value = "附件url")
+    String url;
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public Boolean getSuccess() {
+        return success;
+    }
+
+    public void setSuccess(Boolean success) {
+        this.success = success;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getUpdateTime() {
+        if (Objects.isNull(updateTime)) {
+            return System.currentTimeMillis();
+        } else {
+            return updateTime;
+        }
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public EditResult(Long id) {
+        this.id = id;
+        ServletUtil.setRequestId(Arrays.asList(id));
+    }
+
+    public EditResult(Boolean success) {
+        this.success = success;
+    }
+
+    public EditResult(Long id, String url) {
+        this.id = id;
+        this.url = url;
+    }
+
+    public EditResult(String url) {
+        this.url = url;
+    }
+
+    public EditResult() {
+    }
+}

+ 247 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/LoginResult.java

@@ -0,0 +1,247 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.entity.BasicSchool;
+import com.qmth.distributed.print.business.entity.SysOrg;
+import com.qmth.distributed.print.business.entity.SysUser;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import com.qmth.distributed.print.business.util.ServletUtil;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @Description: 登录返回result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/25
+ */
+public class LoginResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    Long id;
+
+    @ApiModelProperty(value = "登录名")
+    String loginName;
+
+    @ApiModelProperty(value = "姓名")
+    String realName;
+
+    @ApiModelProperty(value = "会话id")
+    String sessionId;
+
+    @ApiModelProperty(value = "访问令牌")
+    String accessToken;
+
+    @ApiModelProperty(value = "学校信息")
+    SchoolNativeBean schoolInfo;
+
+    @ApiModelProperty(value = "机构信息")
+    OrgNativeBean orgInfo;
+
+    @ApiModelProperty(name = "角色集合")
+    private Set<RoleTypeEnum> roleList;
+
+    public LoginResult() {
+
+    }
+
+    public LoginResult(SysUser sysUser, String sessionId, String accessToken, Set<RoleTypeEnum> roleList) {
+        this.id = sysUser.getId();
+        ServletUtil.setRequestId(Arrays.asList(id));
+        this.loginName = sysUser.getLoginName();
+        this.realName = sysUser.getRealName();
+        this.sessionId = sessionId;
+        this.accessToken = accessToken;
+        this.roleList = roleList;
+    }
+
+    public LoginResult(SysUser sysUser, String sessionId, String accessToken, SchoolNativeBean schoolInfo, OrgNativeBean orgInfo) {
+        this.loginName = sysUser.getLoginName();
+        this.realName = sysUser.getRealName();
+        this.sessionId = sessionId;
+        this.accessToken = accessToken;
+        this.schoolInfo = schoolInfo;
+        this.orgInfo = orgInfo;
+    }
+
+    public Set<RoleTypeEnum> getRoleList() {
+        return roleList;
+    }
+
+    public void setRoleList(Set<RoleTypeEnum> roleList) {
+        this.roleList = roleList;
+    }
+
+    public OrgNativeBean getOrgInfo() {
+        return orgInfo;
+    }
+
+    public void setOrgInfo(OrgNativeBean orgInfo) {
+        this.orgInfo = orgInfo;
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getLoginName() {
+        return loginName;
+    }
+
+    public void setLoginName(String loginName) {
+        this.loginName = loginName;
+    }
+
+    public String getRealName() {
+        return realName;
+    }
+
+    public void setRealName(String realName) {
+        this.realName = realName;
+    }
+
+    public String getSessionId() {
+        return sessionId;
+    }
+
+    public void setSessionId(String sessionId) {
+        this.sessionId = sessionId;
+    }
+
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+    public void setAccessToken(String accessToken) {
+        this.accessToken = accessToken;
+    }
+
+    public SchoolNativeBean getSchoolInfo() {
+        return schoolInfo;
+    }
+
+    public void setSchoolInfo(SchoolNativeBean schoolInfo) {
+        this.schoolInfo = schoolInfo;
+    }
+
+    public class SchoolNativeBean implements Serializable {
+
+        @ApiModelProperty(value = "id")
+        @JsonSerialize(using = ToStringSerializer.class)
+        Long id;
+
+        @ApiModelProperty(value = "代码")
+        String code;
+
+        @ApiModelProperty(value = "名称")
+        String name;
+
+        public SchoolNativeBean() {
+
+        }
+
+        public SchoolNativeBean(BasicSchool tbSchool) {
+            this.id = tbSchool.getId();
+            this.code = tbSchool.getCode();
+            this.name = tbSchool.getName();
+            schoolInfo = this;
+        }
+
+        public SchoolNativeBean(Long id, String code, String name) {
+            this.id = id;
+            this.code = code;
+            this.name = name;
+            schoolInfo = this;
+        }
+
+        public Long getId() {
+            return id;
+        }
+
+        public void setId(Long id) {
+            this.id = id;
+        }
+
+        public String getCode() {
+            return code;
+        }
+
+        public void setCode(String code) {
+            this.code = code;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+
+    public class OrgNativeBean implements Serializable {
+
+        @ApiModelProperty(value = "id")
+        @JsonSerialize(using = ToStringSerializer.class)
+        Long id;
+
+        @ApiModelProperty(value = "代码")
+        String code;
+
+        @ApiModelProperty(value = "名称")
+        String name;
+
+        public OrgNativeBean() {
+
+        }
+
+        public OrgNativeBean(SysOrg org) {
+            this.id = org.getId();
+            this.code = org.getCode();
+            this.name = org.getName();
+            orgInfo = this;
+        }
+
+        public OrgNativeBean(Long id, String code, String name) {
+            this.id = id;
+            this.code = code;
+            this.name = name;
+            orgInfo = this;
+        }
+
+        public Long getId() {
+            return id;
+        }
+
+        public void setId(Long id) {
+            this.id = id;
+        }
+
+        public String getCode() {
+            return code;
+        }
+
+        public void setCode(String code) {
+            this.code = code;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+    }
+}

+ 138 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/PrivilegeResult.java

@@ -0,0 +1,138 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.bean.dto.PrivilegeCacheDto;
+import com.qmth.distributed.print.business.bean.dto.PrivilegeDto;
+import com.qmth.distributed.print.business.enums.PrivilegeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description: 权限result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/27
+ */
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class PrivilegeResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    Long id;
+
+    @ApiModelProperty(value = "权限名称")
+    String name;
+
+    @ApiModelProperty(value = "权限地址")
+    String url;
+
+    @ApiModelProperty(value = "权限类别")
+    PrivilegeEnum type;
+
+    @ApiModelProperty(value = "父id")
+    @JsonSerialize(using = ToStringSerializer.class)
+    Long parentId;
+
+    @ApiModelProperty(value = "序号")
+    Integer sequence;
+
+    @ApiModelProperty(value = "是否启用,false:停用,true:启用")
+    Boolean enable;
+
+    @ApiModelProperty(value = "按钮")
+    List<PrivilegeResult> buttons;
+
+    @ApiModelProperty(value = "操作栏地址")
+    List<PrivilegeResult> links;
+
+    public PrivilegeResult() {
+
+    }
+
+    public PrivilegeResult(PrivilegeCacheDto privilegeCacheDto) {
+        this.id = privilegeCacheDto.getPrivilegeId();
+        this.name = privilegeCacheDto.getPrivilegeName();
+        this.url = privilegeCacheDto.getUrl();
+        this.type = privilegeCacheDto.getPrivilegeType();
+        this.parentId = privilegeCacheDto.getParentId();
+        this.sequence = privilegeCacheDto.getSequence();
+        this.enable = privilegeCacheDto.getEnable();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getUrl() {
+        return url;
+    }
+
+    public void setUrl(String url) {
+        this.url = url;
+    }
+
+    public PrivilegeEnum getType() {
+        return type;
+    }
+
+    public void setType(PrivilegeEnum type) {
+        this.type = type;
+    }
+
+    public Long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(Long parentId) {
+        this.parentId = parentId;
+    }
+
+    public Integer getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(Integer sequence) {
+        this.sequence = sequence;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public List<PrivilegeResult> getButtons() {
+        return buttons;
+    }
+
+    public void setButtons(List<PrivilegeResult> buttons) {
+        this.buttons = buttons;
+    }
+
+    public List<PrivilegeResult> getLinks() {
+        return links;
+    }
+
+    public void setLinks(List<PrivilegeResult> links) {
+        this.links = links;
+    }
+}

+ 70 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/result/RolePrivilegeResult.java

@@ -0,0 +1,70 @@
+package com.qmth.distributed.print.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.distributed.print.business.bean.dto.PrivilegeCacheDto;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @Description: 角色权限result
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/27
+ */
+
+public class RolePrivilegeResult implements Serializable {
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "角色id")
+    Long id;
+
+    @ApiModelProperty(value = "角色名称")
+    String name;
+
+    @ApiModelProperty(value = "角色类别")
+    String type;
+
+    List<PrivilegeResult> privileges;
+
+    public void setInfo(PrivilegeCacheDto privilegeCacheDto) {
+        this.id = privilegeCacheDto.getId();
+        this.name = privilegeCacheDto.getName();
+        this.type = privilegeCacheDto.getType().getDesc();
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public List<PrivilegeResult> getPrivileges() {
+        return privileges;
+    }
+
+    public void setPrivileges(List<PrivilegeResult> privileges) {
+        this.privileges = privileges;
+    }
+}

+ 34 - 12
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/SysUserRole.java

@@ -5,7 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
-import com.qmth.distributed.print.business.base.BaseEntity;
+import com.qmth.distributed.print.common.contant.SystemConstant;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -19,7 +19,7 @@ import java.io.Serializable;
  * @since 2021-03-23
  */
 @TableName("sys_user_role")
-public class SysUserRole extends BaseEntity implements Serializable {
+public class SysUserRole implements Serializable {
 
     private static final long serialVersionUID = 1L;
 
@@ -42,32 +42,38 @@ public class SysUserRole extends BaseEntity implements Serializable {
     @TableField("role_id")
     private Long roleId;
 
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "权限id")
+    @TableField(value = "privilege_id")
+    private Long privilegeId;
+
     @ApiModelProperty(value = "是否启用,false:停用,true:启用")
     @TableField(value = "enable")
     private Boolean enable;
 
+    public SysUserRole() {
+
+    }
+
+    public SysUserRole(Long userId, Long roleId, Long privilegeId) {
+        this.id = SystemConstant.getDbUuid();
+        this.userId = userId;
+        this.roleId = roleId;
+        this.privilegeId = privilegeId;
+    }
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }
 
-    @Override
     public Long getId() {
         return id;
     }
 
-    @Override
     public void setId(Long id) {
         this.id = id;
     }
 
-    public Boolean getEnable() {
-        return enable;
-    }
-
-    public void setEnable(Boolean enable) {
-        this.enable = enable;
-    }
-
     public Long getUserId() {
         return userId;
     }
@@ -83,4 +89,20 @@ public class SysUserRole extends BaseEntity implements Serializable {
     public void setRoleId(Long roleId) {
         this.roleId = roleId;
     }
+
+    public Long getPrivilegeId() {
+        return privilegeId;
+    }
+
+    public void setPrivilegeId(Long privilegeId) {
+        this.privilegeId = privilegeId;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
 }

+ 190 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/entity/TBSession.java

@@ -0,0 +1,190 @@
+package com.qmth.distributed.print.business.entity;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 会话表
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-03-19
+ */
+@ApiModel(value = "TBSession对象", description = "会话表")
+public class TBSession implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @JsonSerialize(using = ToStringSerializer.class)
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "id")
+    private String id;
+
+    @ApiModelProperty(value = "用户标识")
+    @TableField(value = "identity")
+    private String identity;
+
+    @ApiModelProperty(value = "用户类型")
+    @TableField(value = "type")
+    private String type;
+
+    @ApiModelProperty(value = "访问来源")
+    @TableField(value = "source")
+    private String source;
+
+    @ApiModelProperty(value = "设备分类")
+    @TableField(value = "platform")
+    private String platform;
+
+    @ApiModelProperty(value = "设备标识")
+    @TableField(value = "device_id")
+    private String deviceId;
+
+    @ApiModelProperty(value = "登录IP地址")
+    @TableField(value = "address")
+    private String address;
+
+    @ApiModelProperty(value = "访问令牌")
+    @TableField(value = "access_token")
+    private String accessToken;
+
+    @ApiModelProperty(value = "最近访问时间")
+    @TableField(value = "last_access_time")
+    private Long lastAccessTime;
+
+    @ApiModelProperty(value = "最近访问IP地址")
+    @TableField(value = "last_access_ip")
+    private String lastAccessIp;
+
+    @ApiModelProperty(value = "令牌更新时间")
+    @TableField(value = "update_time")
+    private Long updateTime;
+
+    @ApiModelProperty(value = "令牌强制失效时间")
+    @TableField(value = "expire_time")
+    private Long expireTime;
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+
+    public TBSession() {
+
+    }
+
+    public TBSession(String id, String identity, String type, String source, String platform, String deviceId, String address, String accessToken, Long expireTime) {
+        this.id = id;
+        this.identity = identity;
+        this.type = type;
+        this.source = source;
+        this.platform = platform;
+        this.deviceId = deviceId;
+        this.address = address;
+        this.accessToken = accessToken;
+        this.expireTime = expireTime;
+        this.lastAccessTime = System.currentTimeMillis();
+    }
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getIdentity() {
+        return identity;
+    }
+
+    public void setIdentity(String identity) {
+        this.identity = identity;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
+
+    public String getPlatform() {
+        return platform;
+    }
+
+    public void setPlatform(String platform) {
+        this.platform = platform;
+    }
+
+    public String getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(String deviceId) {
+        this.deviceId = deviceId;
+    }
+
+    public String getAddress() {
+        return address;
+    }
+
+    public void setAddress(String address) {
+        this.address = address;
+    }
+
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+    public void setAccessToken(String accessToken) {
+        this.accessToken = accessToken;
+    }
+
+    public Long getLastAccessTime() {
+        return lastAccessTime;
+    }
+
+    public void setLastAccessTime(Long lastAccessTime) {
+        this.lastAccessTime = lastAccessTime;
+    }
+
+    public String getLastAccessIp() {
+        return lastAccessIp;
+    }
+
+    public void setLastAccessIp(String lastAccessIp) {
+        this.lastAccessIp = lastAccessIp;
+    }
+
+    public Long getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Long updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public Long getExpireTime() {
+        return expireTime;
+    }
+
+    public void setExpireTime(Long expireTime) {
+        this.expireTime = expireTime;
+    }
+}

+ 44 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/PrivilegePropertyEnum.java

@@ -0,0 +1,44 @@
+package com.qmth.distributed.print.business.enums;
+
+import java.util.Objects;
+
+/**
+ * @Description: 系统鉴权属性 enum
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/25
+ */
+public enum PrivilegePropertyEnum {
+
+    NO_AUTH("无需鉴权"),
+
+    AUTH("鉴权"),
+
+    SYS("系统公用");
+
+    private String title;
+
+    private PrivilegePropertyEnum(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param title
+     * @return
+     */
+    public static String convertToName(String title) {
+        for (PrivilegePropertyEnum e : PrivilegePropertyEnum.values()) {
+            if (Objects.equals(title, e.getTitle())) {
+                return e.name();
+            }
+        }
+        return null;
+    }
+}

+ 50 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/enums/UploadFileEnum.java

@@ -0,0 +1,50 @@
+package com.qmth.distributed.print.business.enums;
+
+import java.util.Objects;
+
+/**
+ * @Description: 上传文件类型
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/7/15
+ */
+public enum UploadFileEnum {
+    /**
+     * 客户端
+     */
+    PAPER("paper"),
+    /**
+     * 系统相关
+     */
+    UPLOAD("upload"),
+    /**
+     * 导入导出
+     */
+    FILE("file");
+
+    private String title;
+
+    private UploadFileEnum(String title) {
+        this.title = title;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param title
+     * @return
+     */
+    public static String convertToName(String title) {
+        for (UploadFileEnum e : UploadFileEnum.values()) {
+            if (Objects.equals(title, e.getTitle())) {
+                return e.name();
+            }
+        }
+        return null;
+    }
+}

+ 16 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/mapper/TBSessionMapper.java

@@ -0,0 +1,16 @@
+package com.qmth.distributed.print.business.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qmth.distributed.print.business.entity.TBSession;
+
+/**
+ * <p>
+ * 会话表 Mapper 接口
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-03-19
+ */
+public interface TBSessionMapper extends BaseMapper<TBSession> {
+
+}

+ 149 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CacheService.java

@@ -0,0 +1,149 @@
+package com.qmth.distributed.print.business.service;
+
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.PrivilegePropertyEnum;
+
+import java.util.List;
+
+/**
+ * @Description: 缓存操作service
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/25
+ */
+public interface CacheService {
+
+    /**
+     * 添加用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    public SysUser userCache(Long userId);
+
+    /**
+     * 修改用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    public SysUser updateUserCache(Long userId);
+
+    /**
+     * 删除用户缓存
+     *
+     * @param userId
+     */
+    public void removeUserCache(Long userId);
+
+    /**
+     * 添加用户鉴权缓存
+     *
+     * @param userId
+     * @return
+     */
+    public AuthBean userAuthCache(Long userId);
+
+    /**
+     * 修改用户鉴权缓存
+     *
+     * @param userId
+     * @return
+     */
+    public AuthBean updateUserAuthCache(Long userId);
+
+    /**
+     * 删除用户鉴权缓存
+     *
+     * @param userId
+     */
+    public void removeUserAuthCache(Long userId);
+
+    /**
+     * 添加学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    public BasicSchool schoolCache(Long schoolId);
+
+    /**
+     * 添加机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    public SysOrg orgCache(Long orgId);
+
+    /**
+     * 获取鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    public List<String> privilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum);
+
+    /**
+     * 修改鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    public List<String> updatePrivilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum);
+
+
+    /**
+     * 删除鉴权url
+     *
+     * @param privilegePropertyEnum
+     */
+    public void removePrivilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum);
+
+    /**
+     * 添加角色权限缓存
+     *
+     * @param roleId
+     * @return
+     */
+    public List<SysRolePrivilege> rolePrivilegeCache(Long roleId);
+
+    /**
+     * 修改角色权限缓存
+     *
+     * @param roleId
+     * @return
+     */
+    public List<SysRolePrivilege> updateRolePrivilegeCache(Long roleId);
+
+    /**
+     * 删除角色权限缓存
+     *
+     * @param roleId
+     */
+    public void removeRolePrivilegeCache(Long roleId);
+
+    /**
+     * 添加用户角色权限缓存
+     *
+     * @param userId
+     * @return
+     */
+    public List<SysUserRole> userRolePrivilegeCache(Long userId);
+
+    /**
+     * 修改用户角色权限缓存
+     *
+     * @param userId
+     * @return
+     */
+    public List<SysUserRole> updateUserRolePrivilegeCache(Long userId);
+
+    /**
+     * 删除用户角色权限缓存
+     *
+     * @param userId
+     */
+    public void removeUserRolePrivilegeCache(Long userId);
+}

+ 93 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/CommonService.java

@@ -0,0 +1,93 @@
+package com.qmth.distributed.print.business.service;
+
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.bean.dto.PrivilegeCacheDto;
+import com.qmth.distributed.print.business.bean.result.RolePrivilegeResult;
+import com.qmth.distributed.print.business.entity.SysRolePrivilege;
+import com.qmth.distributed.print.business.entity.SysUser;
+import com.qmth.distributed.print.business.entity.SysUserRole;
+import com.qmth.distributed.print.business.enums.PrivilegePropertyEnum;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.List;
+
+/**
+ * @Description: 公共服务service
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/26
+ */
+public interface CommonService {
+
+    /**
+     * 新增用户权限
+     *
+     * @param sysUser
+     * @param roleId
+     */
+    public void addUserRolePrivilege(SysUser sysUser, Long roleId);
+
+    /**
+     * 获取用户角色
+     *
+     * @param userId
+     * @return
+     */
+    public List<SysUserRole> getUserRolePrivilege(Long userId);
+
+    /**
+     * 获取角色权限
+     *
+     * @param roleId
+     * @return
+     */
+    public List<SysRolePrivilege> getRolePrivilege(Long roleId);
+
+    /**
+     * 获取用户权限
+     *
+     * @param userId
+     * @return
+     */
+    public AuthBean getUserAuth(Long userId);
+
+    /**
+     * 获取鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    public List<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum);
+
+    /**
+     * 删除用户信息
+     *
+     * @param userId
+     */
+    public void removeUserInfo(Long userId) throws NoSuchAlgorithmException;
+
+    /**
+     * 修改角色状态
+     *
+     * @param roleIds
+     * @param enable
+     */
+    public void updateRoleEnable(Long[] roleIds, Boolean enable);
+
+    /**
+     * 查询用户或角色权限信息
+     *
+     * @param privilegeCacheDtoList
+     * @return
+     */
+    public RolePrivilegeResult getUserOrRolePrivilege(List<PrivilegeCacheDto> privilegeCacheDtoList);
+
+    /**
+     * 文件预览
+     *
+     * @param path
+     * @return
+     */
+    public String filePreview(String path);
+}

+ 16 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/TBSessionService.java

@@ -0,0 +1,16 @@
+package com.qmth.distributed.print.business.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.distributed.print.business.entity.TBSession;
+
+/**
+ * <p>
+ * 会话表 服务类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-03-19
+ */
+public interface TBSessionService extends IService<TBSession> {
+
+}

+ 239 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CacheServiceImpl.java

@@ -0,0 +1,239 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.PrivilegePropertyEnum;
+import com.qmth.distributed.print.business.service.*;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @Description: 缓存操作serviceImpl 实现类
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/25
+ */
+@Service(value = "applicationCacheService")
+public class CacheServiceImpl implements CacheService {
+    private final static Logger log = LoggerFactory.getLogger(CacheServiceImpl.class);
+
+    @Resource
+    SysUserService sysUserService;
+
+    @Resource
+    BasicSchoolService basicSchoolService;
+
+    @Resource
+    CommonService commonService;
+
+    @Resource
+    SysOrgService sysOrgService;
+
+    /**
+     * 添加用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0")
+    public SysUser userCache(Long userId) {
+        return sysUserService.getById(userId);
+    }
+
+    /**
+     * 修改用户缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0")
+    public SysUser updateUserCache(Long userId) {
+        return sysUserService.getById(userId);
+    }
+
+    /**
+     * 删除用户缓存
+     *
+     * @param userId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.USER_ACCOUNT_CACHE, key = "#p0")
+    public void removeUserCache(Long userId) {
+
+    }
+
+    /**
+     * 添加用户鉴权缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0")
+    public AuthBean userAuthCache(Long userId) {
+        return commonService.getUserAuth(userId);
+    }
+
+    /**
+     * 修改用户鉴权缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0")
+    public AuthBean updateUserAuthCache(Long userId) {
+        return commonService.getUserAuth(userId);
+    }
+
+    /**
+     * 删除用户鉴权缓存
+     *
+     * @param userId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.USER_OAUTH_CACHE, key = "#p0")
+    public void removeUserAuthCache(Long userId) {
+
+    }
+
+    /**
+     * 添加学校缓存
+     *
+     * @param schoolId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.SCHOOL_CACHE, key = "#p0")
+    public BasicSchool schoolCache(Long schoolId) {
+        return basicSchoolService.getById(schoolId);
+    }
+
+    /**
+     * 添加机构缓存
+     *
+     * @param orgId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.ORG_CACHE, key = "#p0")
+    public SysOrg orgCache(Long orgId) {
+        return sysOrgService.getById(orgId);
+    }
+
+    /**
+     * 获取鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.PRIVILEGE_URL_CACHE, key = "#p0")
+    public List<String> privilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum) {
+        return commonService.getPrivilegeUrl(privilegePropertyEnum);
+    }
+
+    /**
+     * 修改鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.PRIVILEGE_URL_CACHE, key = "#p0")
+    public List<String> updatePrivilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum) {
+        return commonService.getPrivilegeUrl(privilegePropertyEnum);
+    }
+
+    /**
+     * 删除鉴权url
+     *
+     * @param privilegePropertyEnum
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.PRIVILEGE_URL_CACHE, key = "#p0")
+    public void removePrivilegeUrlCache(PrivilegePropertyEnum privilegePropertyEnum) {
+
+    }
+
+    /**
+     * 获取角色权限缓存
+     *
+     * @param roleId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public List<SysRolePrivilege> rolePrivilegeCache(Long roleId) {
+        return commonService.getRolePrivilege(roleId);
+    }
+
+    /**
+     * 修改角色权限缓存
+     *
+     * @param roleId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public List<SysRolePrivilege> updateRolePrivilegeCache(Long roleId) {
+        return commonService.getRolePrivilege(roleId);
+    }
+
+    /**
+     * 删除角色权限缓存
+     *
+     * @param roleId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public void removeRolePrivilegeCache(Long roleId) {
+
+    }
+
+    /**
+     * 添加用户角色权限缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @Cacheable(value = SystemConstant.USER_ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public List<SysUserRole> userRolePrivilegeCache(Long userId) {
+        return commonService.getUserRolePrivilege(userId);
+    }
+
+    /**
+     * 修改用户角色权限缓存
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    @CachePut(value = SystemConstant.USER_ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public List<SysUserRole> updateUserRolePrivilegeCache(Long userId) {
+        return commonService.getUserRolePrivilege(userId);
+    }
+
+    /**
+     * 删除用户角色权限缓存
+     *
+     * @param userId
+     */
+    @Override
+    @CacheEvict(value = SystemConstant.USER_ROLE_PRIVILEGE_CACHE, key = "#p0")
+    public void removeUserRolePrivilegeCache(Long userId) {
+
+    }
+}

+ 322 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/CommonServiceImpl.java

@@ -0,0 +1,322 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.qmth.boot.core.enums.Platform;
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.bean.dto.PrivilegeCacheDto;
+import com.qmth.distributed.print.business.bean.result.PrivilegeResult;
+import com.qmth.distributed.print.business.bean.result.RolePrivilegeResult;
+import com.qmth.distributed.print.business.config.DictionaryConfig;
+import com.qmth.distributed.print.business.entity.*;
+import com.qmth.distributed.print.business.enums.PrivilegeEnum;
+import com.qmth.distributed.print.business.enums.PrivilegePropertyEnum;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import com.qmth.distributed.print.business.enums.UploadFileEnum;
+import com.qmth.distributed.print.business.service.*;
+import com.qmth.distributed.print.business.util.OssUtil;
+import com.qmth.distributed.print.business.util.RedisUtil;
+import com.qmth.distributed.print.business.util.ServletUtil;
+import com.qmth.distributed.print.common.contant.SpringContextHolder;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import com.qmth.distributed.print.common.util.SessionUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedMultiValueMap;
+
+import javax.annotation.Resource;
+import java.io.File;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @Description: 公共服务service impl
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/3/26
+ */
+@Service
+public class CommonServiceImpl implements CommonService {
+    private final static Logger log = LoggerFactory.getLogger(CommonServiceImpl.class);
+
+    @Resource
+    CacheService cacheService;
+
+    @Resource
+    SysUserRoleService sysUserRoleService;
+
+    @Resource
+    SysPrivilegeService sysPrivilegeService;
+
+    @Resource
+    SysRolePrivilegeService sysRolePrivilegeService;
+
+    @Resource
+    SysRoleService sysRoleService;
+
+    @Resource
+    TBSessionService tbSessionService;
+
+    @Resource
+    RedisUtil redisUtil;
+
+    @Resource
+    DictionaryConfig dictionaryConfig;
+
+    @Resource
+    OssUtil ossUtil;
+
+    /**
+     * 新增用户权限
+     *
+     * @param sysUser
+     * @param roleId
+     */
+    @Override
+    public void addUserRolePrivilege(SysUser sysUser, Long roleId) {
+        List<SysRolePrivilege> sysRolePrivilegeList = cacheService.rolePrivilegeCache(roleId);
+        List<SysUserRole> sysUserRoleList = new ArrayList<>();
+        sysRolePrivilegeList.forEach(s -> {
+            sysUserRoleList.add(new SysUserRole(sysUser.getId(), s.getRoleId(), s.getPrivilegeId()));
+        });
+        sysUserRoleService.saveBatch(sysUserRoleList);
+    }
+
+    /**
+     * 获取用户角色权限
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    public List<SysUserRole> getUserRolePrivilege(Long userId) {
+        QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
+        sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, userId)
+                .eq(SysUserRole::getEnable, true);
+        return sysUserRoleService.list(sysUserRoleQueryWrapper);
+    }
+
+    /**
+     * 获取角色权限
+     *
+     * @param roleId
+     * @return
+     */
+    @Override
+    public List<SysRolePrivilege> getRolePrivilege(Long roleId) {
+        QueryWrapper<SysRolePrivilege> sysRolePrivilegeQueryWrapper = new QueryWrapper<>();
+        sysRolePrivilegeQueryWrapper.lambda().eq(SysRolePrivilege::getRoleId, roleId);
+        return sysRolePrivilegeService.list(sysRolePrivilegeQueryWrapper);
+    }
+
+    /**
+     * 获取用户权限
+     *
+     * @param userId
+     * @return
+     */
+    @Override
+    public AuthBean getUserAuth(Long userId) {
+        AuthBean authBean = null;
+        try {
+            CacheService cacheService = SpringContextHolder.getBean(CacheService.class);
+            SysUser user = cacheService.userCache(userId);
+            if (Objects.isNull(user)) {
+                throw ExceptionResultEnum.USER_NO_DATA.exception();
+            }
+            //查询用户角色和权限
+            List<SysUserRole> sysUserRoleList = cacheService.userRolePrivilegeCache(user.getId());
+            if (Objects.nonNull(sysUserRoleList) && sysUserRoleList.size() > 0) {
+                Set<Long> roleIds = new HashSet<>();
+                Set<Long> privilegeIds = new HashSet<>();
+                sysUserRoleList.forEach(s -> {
+                    roleIds.add(s.getRoleId());
+                    privilegeIds.add(s.getPrivilegeId());
+                });
+                QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
+                sysRoleQueryWrapper.lambda().in(SysRole::getId, roleIds)
+                        .eq(SysRole::getEnable, true);
+                List<SysRole> sysRoleList = sysRoleService.list(sysRoleQueryWrapper);
+                long count = 0;
+                if (Objects.nonNull(sysRoleList) && sysRoleList.size() > 0) {
+                    count = sysRoleList.stream().filter(s -> s.getType() == RoleTypeEnum.ADMIN).count();
+                }
+                QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
+                if (count > 0) {//超级系统管理员
+                    sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL)
+                            .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
+                    List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
+                    authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()));
+                } else {
+                    BasicSchool tbSchool = cacheService.schoolCache(user.getSchoolId());
+                    SysOrg org = cacheService.orgCache(user.getOrgId());
+                    sysPrivilegeQueryWrapper.lambda().in(SysPrivilege::getId, privilegeIds)
+                            .eq(SysPrivilege::getProperty, PrivilegePropertyEnum.AUTH);
+                    List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
+                    authBean = new AuthBean(sysRoleList, sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toSet()), tbSchool, org);
+                }
+            }
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.ERROR.exception("添加用户鉴权缓存失败");
+        }
+        return authBean;
+    }
+
+    /**
+     * 获取鉴权url
+     *
+     * @param privilegePropertyEnum
+     * @return
+     */
+    @Override
+    public List<String> getPrivilegeUrl(PrivilegePropertyEnum privilegePropertyEnum) {
+        QueryWrapper<SysPrivilege> sysPrivilegeQueryWrapper = new QueryWrapper<>();
+        sysPrivilegeQueryWrapper.lambda().eq(SysPrivilege::getType, PrivilegeEnum.URL)
+                .eq(SysPrivilege::getProperty, privilegePropertyEnum)
+                .eq(SysPrivilege::getEnable, true);
+        List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(sysPrivilegeQueryWrapper);
+        return Objects.nonNull(sysPrivilegeList) && sysPrivilegeList.size() > 0 ? sysPrivilegeList.stream().map(s -> s.getUrl()).collect(Collectors.toList()) : null;
+    }
+
+    /**
+     * 删除用户信息
+     *
+     * @param userId
+     */
+    @Override
+    public void removeUserInfo(Long userId) throws NoSuchAlgorithmException {
+        AuthBean authBean = cacheService.userAuthCache(userId);
+        if (Objects.isNull(authBean)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        for (Platform p : Platform.values()) {
+            String sessionId = SessionUtil.digest(userId, Math.abs(authBean.getRoleList().stream().map(s -> s.getType()).collect(Collectors.toSet()).hashCode()), p.name());
+            tbSessionService.removeById(sessionId);
+            redisUtil.deleteUserSession(sessionId);
+        }
+        cacheService.removeUserCache(userId);
+        cacheService.removeUserAuthCache(userId);
+    }
+
+    /**
+     * 修改角色状态
+     *
+     * @param roleIds
+     * @param enable
+     */
+    @Override
+    public void updateRoleEnable(Long[] roleIds, Boolean enable) {
+        SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
+        List<SysRole> dbRoleList = sysRoleService.listByIds(Arrays.asList(roleIds));
+        if (Objects.isNull(dbRoleList) || dbRoleList.size() == 0) {
+            throw ExceptionResultEnum.ROLE_NO_DATA.exception();
+        }
+
+        //修改角色
+        UpdateWrapper<SysRole> sysRoleUpdateWrapper = new UpdateWrapper<>();
+        sysRoleUpdateWrapper.lambda().in(SysRole::getId, roleIds)
+                .set(SysRole::getEnable, enable)
+                .set(SysRole::getUpdateId, requestUser.getId())
+                .set(SysRole::getUpdateTime, System.currentTimeMillis());
+        sysRoleService.update(sysRoleUpdateWrapper);
+
+        //修改角色权限
+        UpdateWrapper<SysRolePrivilege> sysRolePrivilegeUpdateWrapper = new UpdateWrapper<>();
+        sysRolePrivilegeUpdateWrapper.lambda().in(SysRolePrivilege::getRoleId, roleIds)
+                .set(SysRolePrivilege::getEnable, enable);
+        sysRolePrivilegeService.update(sysRolePrivilegeUpdateWrapper);
+
+        //修改用户角色权限
+        UpdateWrapper<SysUserRole> sysUserRoleUpdateWrapper = new UpdateWrapper<>();
+        sysUserRoleUpdateWrapper.lambda().in(SysUserRole::getRoleId, roleIds)
+                .set(SysUserRole::getEnable, enable);
+        sysUserRoleService.update(sysUserRoleUpdateWrapper);
+
+        List<Long> updateRoleIds = new ArrayList<>();
+        for (SysRole dbRole : dbRoleList) {
+            //如果数据库的状态和修改的状态不同
+            if (Objects.nonNull(dbRole.getEnable()) && dbRole.getEnable().booleanValue() != enable.booleanValue()) {
+                //更新角色权限
+                cacheService.updateRolePrivilegeCache(dbRole.getId());
+                updateRoleIds.add(dbRole.getId());
+            }
+        }
+        //更新用户权限状态
+        QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
+        sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getRoleId, updateRoleIds);
+        List<SysUserRole> sysUserRoleList = sysUserRoleService.list(sysUserRoleQueryWrapper);
+        Set<Long> userIds = sysUserRoleList.stream().map(s -> s.getUserId()).collect(Collectors.toSet());
+        for (Long l : userIds) {
+            cacheService.updateUserRolePrivilegeCache(l);
+            cacheService.updateUserAuthCache(l);
+        }
+    }
+
+    /**
+     * 查询用户或者角色权限信息
+     *
+     * @param privilegeCacheDtoList
+     * @return
+     */
+    @Override
+    public RolePrivilegeResult getUserOrRolePrivilege(List<PrivilegeCacheDto> privilegeCacheDtoList) {
+        LinkedMultiValueMap<Long, PrivilegeResult> buttonsLinkedMultiValueMap = new LinkedMultiValueMap<>(), linksLinkedMultiValueMap = new LinkedMultiValueMap<>();
+        List<PrivilegeCacheDto> buttonsFilterList = new ArrayList<>(), linksFilterList = new ArrayList<>();
+
+        for (PrivilegeCacheDto privilegeCacheDto : privilegeCacheDtoList) {
+            if (privilegeCacheDto.getPrivilegeType() == PrivilegeEnum.BUTTON) {
+                buttonsFilterList.add(privilegeCacheDto);
+                buttonsLinkedMultiValueMap.add(privilegeCacheDto.getParentId(), new PrivilegeResult(privilegeCacheDto));
+            } else if (privilegeCacheDto.getPrivilegeType() == PrivilegeEnum.LINK) {
+                linksFilterList.add(privilegeCacheDto);
+                linksLinkedMultiValueMap.add(privilegeCacheDto.getParentId(), new PrivilegeResult(privilegeCacheDto));
+            }
+        }
+
+        privilegeCacheDtoList.removeAll(buttonsFilterList);
+        privilegeCacheDtoList.removeAll(linksFilterList);
+
+        RolePrivilegeResult rolePrivilegeResult = new RolePrivilegeResult();
+        List<PrivilegeResult> privilegeResultList = new ArrayList<>();
+        for (PrivilegeCacheDto privilegeCacheDto : privilegeCacheDtoList) {
+            rolePrivilegeResult.setInfo(privilegeCacheDto);
+            PrivilegeResult privilegeResult = new PrivilegeResult(privilegeCacheDto);
+            privilegeResult.setButtons(buttonsLinkedMultiValueMap.get(privilegeResult.getId()));
+            privilegeResult.setLinks(linksLinkedMultiValueMap.get(privilegeResult.getId()));
+            privilegeResultList.add(privilegeResult);
+        }
+        rolePrivilegeResult.setPrivileges(privilegeResultList);
+        return rolePrivilegeResult;
+    }
+
+    /**
+     * 文件预览
+     *
+     * @param path
+     * @return
+     */
+    @Override
+    public String filePreview(String path) {
+        String url = null;
+        JSONObject jsonObject = JSONObject.parseObject(path);
+        String attachmentType = (String) jsonObject.get(SystemConstant.TYPE);
+        String filePath = (String) jsonObject.get(SystemConstant.PATH);
+        UploadFileEnum uploadFileEnum = UploadFileEnum.valueOf((String) jsonObject.get(SystemConstant.UPLOAD_TYPE));
+        if (Objects.equals(attachmentType, SystemConstant.LOCAL)) {
+            url = SystemConstant.HTTP + dictionaryConfig.sysDomain().getFileHost() + File.separator + filePath;
+        } else {
+            if (uploadFileEnum == UploadFileEnum.PAPER) {
+                url = ossUtil.getPrivateUrl(filePath);
+            } else {
+                url = dictionaryConfig.aliYunOssDomain().getUrl() + File.separator + filePath;
+            }
+        }
+        return url;
+    }
+}

+ 20 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBSessionServiceImpl.java

@@ -0,0 +1,20 @@
+package com.qmth.distributed.print.business.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.distributed.print.business.entity.TBSession;
+import com.qmth.distributed.print.business.mapper.TBSessionMapper;
+import com.qmth.distributed.print.business.service.TBSessionService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 会话表 服务实现类
+ * </p>
+ *
+ * @author wangliang
+ * @since 2021-03-19
+ */
+@Service
+public class TBSessionServiceImpl extends ServiceImpl<TBSessionMapper, TBSession> implements TBSessionService {
+
+}

+ 186 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/AuthUtil.java

@@ -0,0 +1,186 @@
+package com.qmth.distributed.print.business.util;
+
+import com.qmth.boot.core.enums.Platform;
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.bean.auth.ExpireTimeBean;
+import com.qmth.distributed.print.business.entity.SysUser;
+import com.qmth.distributed.print.business.entity.TBSession;
+import com.qmth.distributed.print.business.enums.PrivilegePropertyEnum;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import com.qmth.distributed.print.business.service.CacheService;
+import com.qmth.distributed.print.common.SignatureEntityTest;
+import com.qmth.distributed.print.common.contant.SpringContextHolder;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+
+/**
+ * @Description: 鉴权工具类util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/11/12
+ */
+public class AuthUtil {
+    private final static Logger log = LoggerFactory.getLogger(AuthUtil.class);
+
+    static CacheService cacheService = null;
+
+    /**
+     * admin鉴权
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    public static boolean adminAuthInterceptor(HttpServletRequest request, HttpServletResponse response) {
+        String url = request.getServletPath();
+        cacheService = SpringContextHolder.getBean(CacheService.class);
+        List<String> privilegeUrl = cacheService.privilegeUrlCache(PrivilegePropertyEnum.NO_AUTH);
+        //无需鉴权的url
+        int noAuthCount = (int) privilegeUrl.stream().filter(s -> s.equalsIgnoreCase(url)).count();
+        if (noAuthCount > 0) {
+            return true;
+        }
+        String method = request.getMethod();
+        if (url.equalsIgnoreCase(SystemConstant.ERROR)) {
+            throw ExceptionResultEnum.NOT_FOUND.exception();
+        }
+        Platform platform = ServletUtil.getRequestPlatform();
+        String deviceId = ServletUtil.getRequestDeviceId();
+        String authorization = ServletUtil.getRequestAuthorization();
+        Long time = ServletUtil.getRequestTime();
+        log.info("Start authorization: url:{}, method:{}, platform:{}, deviceId:{}, authorization:{}, time:{}", url,
+                method, platform, deviceId, authorization, time);
+
+        TBSession tbSession = authHeadCommon(platform, deviceId, authorization, time, method, url);
+        Long userId = Long.parseLong(tbSession.getIdentity());
+        SysUser sysUser = cacheService.userCache(userId);
+        request.setAttribute(SystemConstant.SESSION, tbSession);
+        request.setAttribute(SystemConstant.USER, sysUser);
+        return authFootCommon(userId, SystemConstant.USER_OAUTH_CACHE, request, response);
+    }
+
+    /**
+     * 鉴权头公用
+     *
+     * @param platform
+     * @param deviceId
+     * @param authorization
+     * @param time
+     * @return
+     */
+    static TBSession authHeadCommon(Platform platform,
+                                    String deviceId,
+                                    String authorization,
+                                    long time,
+                                    String method,
+                                    String url) {
+        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
+//        if (SystemConstant.expire(time)) {
+//            log.warn("Authorization faile: time expired, server time=" + System.currentTimeMillis());
+//            throw new BusinessException(ExceptionResultEnum.AUTHORIZATION_ERROR);
+//        }
+        //测试
+        final SignatureEntityTest info = SignatureEntityTest.parse(authorization);
+        //校验签名信息
+//        final SignatureInfo info = SignatureInfo.parse(method.toLowerCase(), url, time, authorization);
+        if (info == null) {
+            log.warn("Authorization faile: signature decode error");
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        if (SignatureType.TOKEN != info.getType()) {
+            log.warn("Authorization faile: signature type is not Token");
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        //校验session
+        String sessionId = info.getInvoker();
+        TBSession tbSession = (TBSession) redisUtil.getUserSession(sessionId);
+        if (Objects.isNull(tbSession)) {
+            log.warn("Authorization faile: session id not exists: " + sessionId);
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        if (tbSession.getExpireTime() <= System.currentTimeMillis() || info.getTimestamp() > tbSession.getExpireTime()) {
+            log.warn("Authorization faile: session has expired, expire time=" + tbSession.getExpireTime());
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        if (!info.validate(tbSession.getAccessToken())) {
+            log.warn("Authorization faile: access token invalid, session token is " + tbSession.getAccessToken());
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        if (!tbSession.getPlatform().equalsIgnoreCase(platform.name())) {
+            log.warn("Authorization faile: platform invalid, session platform is " + tbSession.getPlatform());
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        if (!tbSession.getDeviceId().equalsIgnoreCase(deviceId)) {
+            log.warn("Authorization faile: deviceId invalid, session deviceId is " + tbSession.getDeviceId());
+            throw ExceptionResultEnum.AUTHORIZATION_ERROR.exception();
+        }
+        return tbSession;
+    }
+
+    /**
+     * 鉴权尾公用
+     *
+     * @param userId
+     * @param type
+     * @param request
+     * @param response
+     * @return
+     */
+    static boolean authFootCommon(long userId,
+                                  String type,
+                                  HttpServletRequest request,
+                                  HttpServletResponse response) {
+        String url = request.getServletPath();
+        //验证权限
+        AuthBean authBean = type.contains(SystemConstant.USER_OAUTH_CACHE) ? authBean = cacheService.userAuthCache(userId) : null;
+        if (Objects.isNull(authBean)) {
+            throw ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception();
+        }
+        request.setAttribute(SystemConstant.SCHOOL, authBean.getSchool());
+
+        //超级系统管理员拥有所有权限
+        long count = authBean.getRoleList().stream().filter(s -> s.getType() == RoleTypeEnum.ADMIN).count();
+        if (count > 0) {
+            return true;
+        }
+        //系统公用接口不拦截
+        List<String> sysUrls = cacheService.privilegeUrlCache(PrivilegePropertyEnum.SYS);
+        int sysCount = (int) sysUrls.stream().filter(s -> s.equalsIgnoreCase(url)).count();
+        if (sysCount > 0) {
+            return true;
+        }
+        Set<String> urls = authBean.getUrls();
+        int privilegeCount = (int) urls.stream().filter(s -> s.equalsIgnoreCase(url)).count();
+        if (privilegeCount == 0) {
+            log.warn("Authorization faile: url cannot access");
+            throw ExceptionResultEnum.UN_AUTHORIZATION.exception();
+        }
+        response.setStatus(ExceptionResultEnum.SUCCESS.getCode());
+        return true;
+    }
+
+    /**
+     * 获取过期时间
+     *
+     * @param platform
+     * @return
+     */
+    public static ExpireTimeBean getExpireTime(Platform platform) {
+        ExpireTimeBean expireTimeBean = new ExpireTimeBean();
+        Date now = new Date();
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(now);
+        calendar.add(Calendar.DAY_OF_YEAR, SystemConstant.DEFAULT_SESSION_EXPIRE);
+        expireTimeBean.setDate(calendar.getTime());
+        expireTimeBean.setExpireSeconds(SystemConstant.REDIS_DEFAULT_EXPIRE_TIME);
+        return expireTimeBean;
+    }
+}

+ 53 - 8
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ExcelUtil.java

@@ -3,6 +3,7 @@ package com.qmth.distributed.print.business.util;
 import com.qmth.distributed.print.business.annotation.ExcelNote;
 import com.qmth.distributed.print.business.util.excel.ExcelCallback;
 import com.qmth.distributed.print.business.util.excel.ExcelError;
+import com.qmth.distributed.print.business.util.excel.ExcelWriter;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import org.apache.poi.ss.usermodel.Cell;
@@ -13,11 +14,15 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.LinkedMultiValueMap;
 
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.constraints.NotNull;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
+import java.net.URLEncoder;
 import java.util.*;
 
 /**
@@ -29,6 +34,46 @@ import java.util.*;
  */
 public class ExcelUtil {
     private final static Logger log = LoggerFactory.getLogger(ExcelUtil.class);
+    private static final String DEFALUT_CONTENT_TYPE = "application/vnd.ms-excel";
+    private static final String DEFALUT_EXT = ".xlsx";
+
+    /**
+     * 导出excel
+     *
+     * @param fileName
+     * @param dataClass
+     * @param dataset
+     * @param response
+     * @throws Exception
+     */
+    public static void excelExport(String fileName, Class<?> dataClass,
+                                   Collection<?> dataset, HttpServletResponse response) throws Exception {
+        log.debug("导出Excel开始...");
+        response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME) + DEFALUT_EXT);
+        response.setContentType(DEFALUT_CONTENT_TYPE);
+        ServletOutputStream outputStream = response.getOutputStream();
+
+        ExcelWriter excelExporter = new ExcelWriter(dataClass, "sheet1");
+        excelExporter.write(dataset, outputStream);
+        outputStream.flush();
+        outputStream.close();
+        log.debug("导出Excel结束");
+    }
+
+    /**
+     * 生成excel
+     *
+     * @param dataClass
+     * @param dataset
+     * @param outputStream
+     * @throws Exception
+     */
+    public static void excelMake(Class<?> dataClass, Collection<?> dataset, OutputStream outputStream) throws Exception {
+        log.debug("生成Excel开始...");
+        ExcelWriter excelExporter = new ExcelWriter(dataClass, "sheet1");
+        excelExporter.write(dataset, outputStream);
+        log.debug("生成Excel结束");
+    }
 
     /**
      * excel读取
@@ -49,18 +94,18 @@ public class ExcelUtil {
             //获取整个excel
             XSSFWorkbook xb = new XSSFWorkbook(inputStream);
             int sheets = xb.getNumberOfSheets();
-            List<LinkedMultiValueMap<Integer, Object>> finalOList = new ArrayList();
-            List<LinkedMultiValueMap<Integer, String>> finalColumnNameList = new ArrayList();
-            List<LinkedMultiValueMap<Integer, ExcelError>> finalExcelErrorList = new ArrayList();
+            List<LinkedMultiValueMap<Integer, Object>> finalOList = new ArrayList<>();
+            List<LinkedMultiValueMap<Integer, String>> finalColumnNameList = new ArrayList<>();
+            List<LinkedMultiValueMap<Integer, ExcelError>> finalExcelErrorList = new ArrayList<>();
             for (int y = 0; y < sheets; y++) {
                 //获取第一个表单sheet
                 XSSFSheet sheet = xb.getSheetAt(y);
                 //获取最后一行
                 int lastrow = sheet.getLastRowNum();
                 //循环行数依次获取列数
-                LinkedMultiValueMap<Integer, Object> oList = new LinkedMultiValueMap();
-                LinkedMultiValueMap<Integer, String> columnNameList = new LinkedMultiValueMap();
-                LinkedMultiValueMap<Integer, ExcelError> excelErrorList = new LinkedMultiValueMap();
+                LinkedMultiValueMap<Integer, Object> oList = new LinkedMultiValueMap<>();
+                LinkedMultiValueMap<Integer, String> columnNameList = new LinkedMultiValueMap<>();
+                LinkedMultiValueMap<Integer, ExcelError> excelErrorList = new LinkedMultiValueMap<>();
                 for (int i = 0; i < lastrow + 1; i++) {
                     //获取哪一行i
                     Row row = sheet.getRow(i);
@@ -99,7 +144,7 @@ public class ExcelUtil {
                                             field.setAccessible(true);
                                             Map map = (Map) field.get(o);
                                             if (Objects.isNull(map)) {
-                                                map = new LinkedHashMap();
+                                                map = new LinkedHashMap<>();
                                             }
                                             map.put(columnNameList.get(y).get(j), obj);
                                             field.set(o, map);
@@ -122,7 +167,7 @@ public class ExcelUtil {
                     }
                 }
                 if (oList.size() == 0 && finalOList.size() == 0) {
-                    throw ExceptionResultEnum.EXCEL_NO.exception();
+                    throw ExceptionResultEnum.EXCEL_NO_DATA.exception();
                 }
                 if (oList.size() > 0) {
                     finalOList.add(oList);

+ 34 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/OssUtil.java

@@ -4,6 +4,8 @@ import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClientBuilder;
 import com.aliyun.oss.model.*;
 import com.qmth.distributed.print.business.domain.AliYunOssDomain;
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Bean;
@@ -13,6 +15,8 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 import java.util.Objects;
 
@@ -99,6 +103,20 @@ public class OssUtil {
         return localFile;
     }
 
+    /**
+     * 从oss上下载文件到byte[]
+     *
+     * @param objectName
+     * @throws IOException
+     */
+    public byte[] ossDownload(String objectName) throws IOException {
+        log.info("oss Download is come in");
+        OSSObject obj = ossClient.getObject(new GetObjectRequest(this.aliYunOssDomain.getBucket(), objectName));
+        byte[] data = IOUtils.toByteArray(obj.getObjectContent());
+        obj.close();
+        return data;
+    }
+
     /**
      * oss删除文件
      *
@@ -118,4 +136,20 @@ public class OssUtil {
         DeleteObjectsResult deleteObjectsResult = ossClient.deleteObjects(new DeleteObjectsRequest(this.aliYunOssDomain.getBucket()).withKeys(paths));
         deleteObjectsResult.getDeletedObjects();
     }
+
+    /**
+     * 获取私有bucket文件访问url
+     *
+     * @param objectPath
+     * @return
+     */
+    public String getPrivateUrl(String objectPath) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(new Date());
+        calendar.add(Calendar.MILLISECOND, SystemConstant.OSS_URL_EXPIRE);
+        GeneratePresignedUrlRequest generatePresignedUrlRequest;
+        generatePresignedUrlRequest = new GeneratePresignedUrlRequest(this.aliYunOssDomain.getBucket(), objectPath);
+        generatePresignedUrlRequest.setExpiration(calendar.getTime());
+        return ossClient.generatePresignedUrl(generatePresignedUrlRequest).toString();
+    }
 }

+ 236 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/RedisUtil.java

@@ -0,0 +1,236 @@
+package com.qmth.distributed.print.business.util;
+
+import com.qmth.distributed.print.common.contant.SystemConstant;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @Description: redis util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/4/15
+ */
+@Component
+public class RedisUtil {
+
+    @Resource
+    RedisTemplate<String, Object> redisTemplate;
+
+    /**
+     * 获取用户会话信息
+     *
+     * @param sessionId
+     * @return
+     */
+    public Object getUserSession(String sessionId) {
+        return redisTemplate.opsForValue().get(SystemConstant.SESSION + sessionId);
+    }
+
+    /**
+     * 删除用户会话缓存
+     *
+     * @param sessionId
+     */
+    public void deleteUserSession(String sessionId) {
+        redisTemplate.delete(SystemConstant.SESSION + sessionId);
+    }
+
+    /**
+     * 设置用户session信息
+     *
+     * @param sessionId
+     * @param o
+     * @param time
+     */
+    public void setUserSession(String sessionId, Object o, long time) {
+        redisTemplate.opsForValue().set(SystemConstant.SESSION + sessionId, o, time, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 批量获取key的value
+     *
+     * @param keys
+     * @return
+     */
+    public List<?> multiGet(Set keys) {
+        return redisTemplate.opsForValue().multiGet(keys);
+    }
+
+    /**
+     * 获取key like
+     *
+     * @param key
+     * @return
+     */
+    public Set<?> getKeyPatterns(String key) {
+        if (null != key) {
+            return redisTemplate.keys(key);
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * 设置hash
+     *
+     * @param key
+     * @param hashKey
+     * @param hashValue
+     */
+    public void set(String key, String hashKey, Object hashValue) {
+        redisTemplate.opsForHash().put(key, hashKey, hashValue);
+    }
+
+    /**
+     * 获取hash
+     *
+     * @param key
+     * @param hashKey
+     * @return
+     */
+    public Object get(String key, String hashKey) {
+        return redisTemplate.opsForHash().get(key, hashKey);
+    }
+
+    /**
+     * hash删除
+     *
+     * @param key
+     * @param hashKey
+     */
+    public void delete(String key, String hashKey) {
+        redisTemplate.opsForHash().delete(key, hashKey);
+    }
+
+    /**
+     * 获取hash大小
+     *
+     * @param key
+     * @return
+     */
+    public Long getHashSize(String key) {
+        return redisTemplate.opsForHash().size(key);
+    }
+
+    /**
+     * 获取hash map
+     *
+     * @param key
+     * @return
+     */
+    public Map getHashEntries(String key) {
+        return redisTemplate.opsForHash().entries(key);
+    }
+
+    /**
+     * 分布式锁
+     *
+     * @param key
+     * @param timeout SECONDS
+     * @return
+     */
+    public boolean lock(String key, long timeout) {
+        long expireAt = System.currentTimeMillis() + (timeout * 1000) + 1;
+        return redisTemplate.opsForValue().setIfAbsent(key, expireAt, timeout, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 删除锁
+     *
+     * @param key
+     * @return
+     */
+    public void releaseLock(String key) {
+        redisTemplate.expire(key, 100, TimeUnit.MILLISECONDS);
+    }
+
+    /**
+     * 设置缓存
+     *
+     * @param key
+     * @param o
+     */
+    public void set(String key, Object o) {
+        redisTemplate.opsForValue().set(key, o);
+    }
+
+    /**
+     * 设置缓存
+     *
+     * @param key
+     * @param o
+     * @param time
+     * @param timeUnit
+     */
+    public void set(String key, Object o, long time, TimeUnit timeUnit) {
+        redisTemplate.opsForValue().set(key, o, time, timeUnit);
+    }
+
+    /**
+     * 设置缓存
+     *
+     * @param key
+     * @param o
+     * @param time SECONDS
+     */
+    public void set(String key, Object o, long time) {
+        set(key, o, time, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 获取缓存
+     *
+     * @param key
+     * @return
+     */
+    public Object get(String key) {
+        return redisTemplate.opsForValue().get(key);
+    }
+
+    /**
+     * 删除缓存
+     *
+     * @param key
+     * @return
+     */
+    public void delete(String key) {
+        redisTemplate.expire(key, 0, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 保存hash结构
+     *
+     * @param key
+     * @param map
+     */
+    public void setForHash(String key, Map<String, Object> map) {
+        redisTemplate.opsForHash().putAll(key, map);
+    }
+
+    /**
+     * 设置过期时间(秒)
+     *
+     * @param key
+     * @param timeOutSecond
+     */
+    public void expire(String key, int timeOutSecond) {
+        redisTemplate.expire(key, timeOutSecond, TimeUnit.SECONDS);
+    }
+
+    /**
+     * 设置过期时间
+     *
+     * @param key
+     * @param timeOut
+     */
+    public void expire(String key, long timeOut, TimeUnit timeUnit) {
+        redisTemplate.expire(key, timeOut, timeUnit);
+    }
+}

+ 171 - 3
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/ServletUtil.java

@@ -1,9 +1,13 @@
 package com.qmth.distributed.print.business.util;
 
 import com.alibaba.fastjson.JSONObject;
+import com.qmth.boot.core.enums.Platform;
 import com.qmth.distributed.print.common.contant.SystemConstant;
+import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
@@ -11,6 +15,7 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -21,6 +26,7 @@ import java.util.Objects;
  * @Date: 2020/4/10
  */
 public class ServletUtil {
+    private final static Logger log = LoggerFactory.getLogger(ServletUtil.class);
 
     /**
      * 输出错误
@@ -40,11 +46,163 @@ public class ServletUtil {
     /**
      * 获取请求的token
      *
-     * @param httpRequest
      * @return
      */
-    public static String getRequestToken(HttpServletRequest httpRequest) {
-        return Objects.isNull(httpRequest.getHeader(SystemConstant.TOKEN)) ? httpRequest.getParameter(SystemConstant.TOKEN) : null;
+    public static String getRequestToken() {
+        try {
+            HttpServletRequest request = getRequest();
+            return Objects.isNull(request.getHeader(SystemConstant.TOKEN)) ? request.getParameter(SystemConstant.TOKEN) : request.getHeader(SystemConstant.TOKEN);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.TOKEN_INVALID.exception();
+        }
+    }
+
+    /**
+     * 获取请求的platform
+     *
+     * @return
+     */
+    public static Platform getRequestPlatform() {
+        try {
+            HttpServletRequest request = getRequest();
+            String value = Objects.isNull(request.getHeader(SystemConstant.HEADER_PLATFORM)) ? request.getParameter(SystemConstant.HEADER_PLATFORM) : request.getHeader(SystemConstant.HEADER_PLATFORM);
+            return Platform.valueOf(value);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.PLATFORM_INVALID.exception();
+        }
+    }
+
+    /**
+     * 获取请求的deviceId
+     *
+     * @return
+     */
+    public static String getRequestDeviceId() {
+        try {
+            HttpServletRequest request = getRequest();
+            return Objects.isNull(request.getHeader(SystemConstant.HEADER_DEVICE_ID)) ? request.getParameter(SystemConstant.HEADER_DEVICE_ID) : request.getHeader(SystemConstant.HEADER_DEVICE_ID);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.DEVICE_ID_INVALID.exception();
+        }
+    }
+
+    /**
+     * 获取请求的Authorization
+     *
+     * @return
+     */
+    public static String getRequestAuthorization() {
+        try {
+            HttpServletRequest request = getRequest();
+            return Objects.isNull(request.getHeader(SystemConstant.HEADER_AUTHORIZATION)) ? request.getParameter(SystemConstant.HEADER_AUTHORIZATION) : request.getHeader(SystemConstant.HEADER_AUTHORIZATION);
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.AUTHORIZATION_INVALID.exception();
+        }
+    }
+
+    /**
+     * 获取请求的Authorization
+     *
+     * @return
+     */
+    public static Long getRequestTime() {
+        try {
+            HttpServletRequest request = getRequest();
+            String time = Objects.isNull(request.getHeader(SystemConstant.HEADER_TIME)) ? request.getParameter(SystemConstant.HEADER_TIME) : request.getHeader(SystemConstant.HEADER_TIME);
+            return Objects.nonNull(time) ? Long.parseLong(time) : null;
+        } catch (Exception e) {
+            log.error("请求出错", e);
+            throw ExceptionResultEnum.TIME_INVALID.exception();
+        }
+    }
+
+    /**
+     * 获取请求的Session
+     *
+     * @return
+     */
+    public static Object getRequestSession() {
+        Object object = getRequest().getAttribute(SystemConstant.SESSION);
+        if (Objects.isNull(object)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        return object;
+    }
+
+    /**
+     * 获取请求的用户
+     *
+     * @return
+     */
+    public static Object getRequestUser() {
+        Object object = getRequest().getAttribute(SystemConstant.USER);
+        if (Objects.isNull(object)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        return object;
+    }
+
+    /**
+     * 获取请求的学校
+     *
+     * @return
+     */
+    public static Object getRequestSchool() {
+        Object object = getRequest().getAttribute(SystemConstant.SCHOOL);
+        if (Objects.isNull(object)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        return object;
+    }
+
+    /**
+     * 获取请求的合作方
+     *
+     * @return
+     */
+    public static Object getRequestPartner() {
+        Object object = getRequest().getAttribute(SystemConstant.PARTNER);
+        if (Objects.isNull(object)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        return object;
+    }
+
+    /**
+     * 获取请求的md5
+     *
+     * @return
+     */
+    public static String getRequestMd5() {
+        String md5 = getRequest().getHeader(SystemConstant.MD5.toLowerCase());
+        if (Objects.isNull(md5)) {
+            throw ExceptionResultEnum.MD5_EMPTY.exception();
+        }
+        return md5;
+    }
+
+    /**
+     * 设置id
+     *
+     * @param ids
+     * @return
+     */
+    public static void setRequestId(List<Long> ids) {
+        HttpServletRequest request = getRequest();
+        request.setAttribute(SystemConstant.ID, ids);
+    }
+
+    /**
+     * 获取id
+     *
+     * @return
+     */
+    public static List<Long> getRequestId() {
+        return Objects.nonNull(getRequest().getAttribute(SystemConstant.ID)) ? (List<Long>) getRequest().getAttribute(SystemConstant.ID) : null;
     }
 
     /**
@@ -56,4 +214,14 @@ public class ServletUtil {
         ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         return servletRequestAttributes.getRequest();
     }
+
+    /**
+     * 获取HttpServletResponse
+     *
+     * @return
+     */
+    public static HttpServletResponse getResponse() {
+        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+        return servletRequestAttributes.getResponse();
+    }
 }

+ 60 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ColumnSetting.java

@@ -0,0 +1,60 @@
+package com.qmth.distributed.print.business.util.excel;
+
+public class ColumnSetting implements Comparable<ColumnSetting> {
+
+    private String header;
+    private String getMethodName;
+    private int width;
+    private int index;
+
+    public ColumnSetting(String header, String getMethodName, int width, int index) {
+        this.header = header;
+        this.getMethodName = getMethodName;
+        this.width = width;
+        this.index = index;
+    }
+
+    public String getHeader() {
+        return header;
+    }
+
+    public void setHeader(String header) {
+        this.header = header;
+    }
+
+    public String getGetMethodName() {
+        return getMethodName;
+    }
+
+    public void setGetMethodName(String getMethodName) {
+        this.getMethodName = getMethodName;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setWidth(int width) {
+        this.width = width;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+
+    @Override
+    public int compareTo(ColumnSetting columnSetting) {
+        if (index < columnSetting.getIndex()) {
+            return -1;
+        }
+        if (index > columnSetting.getIndex()) {
+            return 1;
+        }
+        return 0;
+    }
+}

+ 79 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ExcelExport.java

@@ -0,0 +1,79 @@
+package com.qmth.distributed.print.business.util.excel;
+
+import com.qmth.distributed.print.business.annotation.ExcelProperty;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public abstract class ExcelExport {
+
+    private Class<?> dataClass;
+    private List<ColumnSetting> columnSettings;
+
+    public ExcelExport(Class<?> dataClass) {
+        this.dataClass = dataClass;
+        this.columnSettings = getColumnSettings(dataClass);
+    }
+
+    public Class<?> getDataClass() {
+        return dataClass;
+    }
+
+    public void setDataClass(Class<?> dataClass) {
+        this.dataClass = dataClass;
+    }
+
+    public List<ColumnSetting> getColumnSettings() {
+        return columnSettings;
+    }
+
+    public void setColumnSettings(List<ColumnSetting> columnSettings) {
+        this.columnSettings = columnSettings;
+    }
+
+    /**
+     * 提取ExcelProperty注解类的字段信息
+     *
+     * @param dataClass 需要解析 写入excel的数据类型
+     * @return
+     */
+    protected List<ColumnSetting> getColumnSettings(Class<?> dataClass) {
+        List<ColumnSetting> columnSettings = new ArrayList<>();
+        // 先在方法上找ExcelProperty注解
+        Method[] methods = dataClass.getDeclaredMethods();
+        for (Method method : methods) {
+            ExcelProperty exportProperty = method.getAnnotation(ExcelProperty.class);
+            if (exportProperty != null && exportProperty.name().trim().length() > 0) {
+                ColumnSetting columnSetting = new ColumnSetting(exportProperty.name(), method.getName(),
+                        exportProperty.width(), exportProperty.index());
+                columnSettings.add(columnSetting);
+            }
+        }
+        // 如果方法上找不到注解,再到属性上找
+        if (columnSettings.size() == 0) {
+            Field[] fields = dataClass.getDeclaredFields();
+            for (Field field : fields) {
+                ExcelProperty exportProperty = field.getAnnotation(ExcelProperty.class);
+                if (exportProperty != null && exportProperty.name().trim().length() > 0) {
+                    ColumnSetting columnSetting = new ColumnSetting(exportProperty.name(),
+                            "get" + toUpperCaseFirstOne(field.getName()), exportProperty.width(),
+                            exportProperty.index());
+                    columnSettings.add(columnSetting);
+                }
+            }
+        }
+        Collections.sort(columnSettings);
+        return columnSettings;
+    }
+
+    private static String toUpperCaseFirstOne(String s) {
+        if (Character.isUpperCase(s.charAt(0))) {
+            return s;
+        } else {
+            return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString();
+        }
+    }
+}

+ 92 - 0
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/excel/ExcelWriter.java

@@ -0,0 +1,92 @@
+package com.qmth.distributed.print.business.util.excel;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.FillPatternType;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
+import org.apache.poi.xssf.usermodel.XSSFColor;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.awt.*;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+
+public class ExcelWriter extends ExcelExport {
+
+    private XSSFWorkbook workbook;// 工作簿
+
+    private Sheet sheet; // 工作表
+
+    private Row row = null;// 创建一行
+
+    private Cell cell = null;
+
+    private XSSFCellStyle style;
+
+    private XSSFCellStyle style2;
+
+    public ExcelWriter(Class<?> dataClass, String sheetName) {
+        super(dataClass);
+        // 声明一个工作薄
+        // workbook = new SXSSFWorkbook(100);//使用该方法会有权限问题
+        workbook = new XSSFWorkbook();
+        // 生成一个表格
+        sheet = workbook.createSheet(sheetName);
+        // 设置表格默认列宽度为15个字节
+        sheet.setDefaultColumnWidth((short) 15);
+    }
+
+    private List<ColumnSetting> createColumnSettings() {
+        List<ColumnSetting> columnSettings = this.getColumnSettings();
+        // 产生表格标题行
+        row = sheet.createRow(0);
+        for (short i = 0; i < columnSettings.size(); i++) {
+            cell = row.createCell(i);
+            style = workbook.createCellStyle();
+            style.setFillForegroundColor(new XSSFColor(new Color(227, 239, 217)));
+            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+            cell.setCellStyle(style);
+            XSSFRichTextString text = new XSSFRichTextString(columnSettings.get(i).getHeader());
+            cell.setCellValue(text);
+            if (columnSettings.get(i).getWidth() > 0) {
+                sheet.setColumnWidth(i, columnSettings.get(i).getWidth() * 256);
+            }
+        }
+        return columnSettings;
+    }
+
+    /**
+     * 写入excel
+     *
+     * @param dataset 数据集合
+     * @param out     输出流
+     * @throws SecurityException
+     * @throws NoSuchMethodException
+     * @throws InvocationTargetException
+     * @throws IllegalArgumentException
+     * @throws IllegalAccessException
+     */
+    public void write(Collection<?> dataset, OutputStream out) throws Exception {
+        List<ColumnSetting> columnSettings = this.createColumnSettings();
+        int index = 0;
+        for (Object obj : dataset) {
+            index++;
+            row = sheet.createRow(index);// 创建行
+            // 利用反射,根据javabean属性的先后顺序,动态调用getXxx()方法得到属性值
+            for (short i = 0; i < columnSettings.size(); i++) {
+                cell = row.createCell(i);// 创建列
+                cell.setCellStyle(style2);
+                String methodName = columnSettings.get(i).getGetMethodName();
+                Method method = this.getDataClass().getMethod(methodName, new Class[]{});
+                Object value = method.invoke(obj, new Object[]{});
+                cell.setCellValue(value == null ? "" : value.toString());
+            }
+        }
+        workbook.write(out);
+    }
+}

+ 5 - 0
distributed-print-business/src/main/resources/mapper/TBSessionMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.qmth.distributed.print.business.mapper.TBSessionMapper">
+
+</mapper>

+ 228 - 0
distributed-print-common/src/main/java/com/qmth/distributed/print/common/SignatureEntityTest.java

@@ -0,0 +1,228 @@
+package com.qmth.distributed.print.common;
+
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.distributed.print.common.util.Base64Util;
+import com.qmth.distributed.print.common.util.ShaUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SignatureEntityTest {
+
+    private static final String PATTERN = "{0} {1}{2}{3}";
+
+    private static final String FIELD_JOINER = ":";
+
+    private static final String PARAM_JOINER = "&";
+
+    private static Map<String, SignatureType> typeMap = new HashMap<>();
+
+    static {
+        for (SignatureType type : SignatureType.values()) {
+            typeMap.put(type.getName(), type);
+        }
+    }
+
+    private SignatureType type;
+
+    private String method;
+
+    private String uri;
+
+    private long timestamp;
+
+    private String ciphertext;
+
+    private String invoker;
+
+    private String secret;
+
+    private SignatureEntityTest() {
+    }
+
+    public SignatureType getType() {
+        return type;
+    }
+
+    private void setType(SignatureType type) {
+        this.type = type;
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    private void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String getUri() {
+        return uri;
+    }
+
+    private void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public long getTimestamp() {
+        return timestamp;
+    }
+
+    private void setTimestamp(long timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    private String getCiphertext() {
+        return ciphertext;
+    }
+
+    private void setCiphertext(String ciphertext) {
+        this.ciphertext = ciphertext;
+    }
+
+    public String getInvoker() {
+        return invoker;
+    }
+
+    private void setInvoker(String invoker) {
+        this.invoker = invoker;
+    }
+
+    public String getSecret() {
+        return secret;
+    }
+
+    private void setSecret(String secret) {
+        this.secret = secret;
+    }
+
+    private static String encrypt(String... values) {
+        return Base64Util.encode(ShaUtils.sha1(StringUtils.join(values, PARAM_JOINER)));
+    }
+
+//    /**
+//     * 基于解析好的签名对象,使用传入的保密信息进行签名内容验证
+//     *
+//     * @param secret
+//     * @return
+//     */
+//    public boolean validate(String secret) {
+//        if (method != null && uri != null && timestamp >= 0 && secret != null && ciphertext != null) {
+//            return encrypt(method, uri, String.valueOf(timestamp), secret).equals(ciphertext);
+//        }
+//        return false;
+//    }
+
+    /**
+     * 基于解析好的签名对象,使用传入的保密信息进行签名内容验证(测试用)
+     *
+     * @param secret
+     * @return
+     */
+    public boolean validate(String secret) {
+        if (secret != null && ciphertext != null) {
+            return encrypt(secret).equals(ciphertext);
+        }
+        return false;
+    }
+
+    /**
+     * 根据标准参数构造最终的签名字符串
+     *
+     * @param type
+     * @param method
+     * @param uri
+     * @param timestamp
+     * @param invoker
+     * @param secret
+     * @return
+     */
+    public static String build(SignatureType type, String method, String uri, long timestamp, String invoker, String secret) {
+        if (type == null || method == null || uri == null || timestamp <= 0 || invoker == null || secret == null) {
+            return "";
+        }
+        return MessageFormat.format(PATTERN, type.getName(), invoker, FIELD_JOINER,
+                encrypt(method.toLowerCase(), uri, String.valueOf(timestamp), secret));
+    }
+
+    /**
+     * 根据标准参数构造最终的签名字符串(测试用)
+     *
+     * @param type
+     * @param invoker
+     * @param secret
+     * @return
+     */
+    public static String build(SignatureType type, String invoker, String secret) {
+        if (type == null || invoker == null || secret == null) {
+            return "";
+        }
+        return MessageFormat.format(PATTERN, type.getName(), invoker, FIELD_JOINER,
+                encrypt(secret));
+    }
+
+    /**
+     * 根据当前接口的的基本信息、header中的时间戳与签名字符串,尝试解析并构造签名数据对象
+     *
+     * @param method
+     * @param uri
+     * @param timestamp
+     * @param signature
+     * @return
+     */
+    public static SignatureEntityTest parse(String method, String uri, long timestamp, String signature) {
+        if (method == null || uri == null || timestamp <= 0 || signature == null) {
+            return null;
+        }
+        String[] values = StringUtils.split(signature);
+        if (values != null && values.length == 2) {
+            SignatureType type = typeMap.get(values[0]);
+            if (type != null) {
+                String[] array = StringUtils.split(values[1], FIELD_JOINER);
+                if (array != null && array.length == 2) {
+                    SignatureEntityTest info = new SignatureEntityTest();
+                    info.setType(type);
+                    info.setMethod(method.toLowerCase());
+                    info.setUri(uri);
+                    info.setTimestamp(timestamp);
+                    info.setInvoker(array[0]);
+                    info.setCiphertext(array[1]);
+                    return info;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
+     * 根据当前接口的的基本信息、header中的时间戳与签名字符串,尝试解析并构造签名数据对象(测试用)
+     *
+     * @param signature
+     * @return
+     */
+    public static SignatureEntityTest parse(String signature) {
+        if (signature == null) {
+            return null;
+        }
+        String[] values = StringUtils.split(signature);
+        if (values != null && values.length == 2) {
+            SignatureType type = typeMap.get(values[0]);
+            if (type != null) {
+                String[] array = StringUtils.split(values[1], FIELD_JOINER);
+                if (array != null && array.length == 2) {
+                    SignatureEntityTest info = new SignatureEntityTest();
+                    info.setType(type);
+//                    info.setMethod(method.toLowerCase());
+//                    info.setUri(uri);
+//                    info.setTimestamp(timestamp);
+                    info.setInvoker(array[0]);
+                    info.setCiphertext(array[1]);
+                    return info;
+                }
+            }
+        }
+        return null;
+    }
+}

+ 39 - 1
distributed-print-common/src/main/java/com/qmth/distributed/print/common/contant/SystemConstant.java

@@ -25,10 +25,47 @@ public class SystemConstant {
     public static final String MD5 = "MD5";
     public static final String SUCCESS = "success";
     public static final String EXTEND_COLUMN = "extendColumn";
-    public static final String METHOD = "post";
     public static final String USER_DIR = "user.dir";
     public static final String PDF_TEMP = "pdf-temp";
     public static final String FILE_TEMP = "file-temp";
+    public static final String SESSION = "session:";
+    public static final String USER = "account";
+    public static final String SCHOOL = "school";
+    public static final String PARTNER = "partner";
+    public static final String ERROR = "/error";
+    public static final String METHOD = "post";
+    public static final String DEFAULT_PASSWORD = "MTIzNDU2";
+    public static final String UPDATE_TIME = "updateTime";
+    public static final String PATH = "path";
+    public static final String TYPE = "type";
+    public static final String LOCAL = "local";
+    public static final String OSS = "oss";
+    public static final String UPLOAD_TYPE = "uploadType";
+    public static final String FILE = "file";
+    public static final String TASK = "task";
+    public static final String SIZE = "size";
+    public static final String SUMMARY = "summary";
+    public static final String HTTP = "http://";
+    public static final String ID = "id";
+    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
+    public static final int PAGE_NUMBER = 0;
+    public static final int PAGE_SIZE = 10000000;
+
+    /**
+     * oss url过期时间
+     */
+    public static final int OSS_URL_EXPIRE = 5 * 60 * 1000;//过期时间5分钟
+
+    /**
+     * 缓存配置
+     */
+    public static final String USER_OAUTH_CACHE = "user:oauth:cache";
+    public static final String USER_ACCOUNT_CACHE = "user:account:cache";
+    public static final String SCHOOL_CACHE = "school:cache";
+    public static final String ORG_CACHE = "org:cache";
+    public static final String PRIVILEGE_URL_CACHE = "privilege:url:cache";
+    public static final String ROLE_PRIVILEGE_CACHE = "role:privilege:cache";
+    public static final String USER_ROLE_PRIVILEGE_CACHE = "user:role:privilege:cache";
 
     /**
      * 鉴权
@@ -42,6 +79,7 @@ public class SystemConstant {
     /**
      * redis
      */
+    public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
     public static final long REDIS_DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
 
     /**

+ 56 - 8
distributed-print-common/src/main/java/com/qmth/distributed/print/common/enums/ExceptionResultEnum.java

@@ -16,22 +16,70 @@ public enum ExceptionResultEnum {
      */
     SUCCESS(HttpStatus.OK, 200, "成功"),
 
-    ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 500, "失败"),
+    ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000001, "失败"),
 
-    SQL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 503, "sql异常:"),
+    PARAMS_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000002, "参数错误"),
 
-    INVOCATIONTARGET_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 501, "反射异常:"),
+    SQL_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000003, "sql异常:"),
 
-    SERVICE_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, 502, "服务器错误"),
+    INVOCATIONTARGET_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000004, "反射异常:"),
 
-    UNKONW_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 504, "未知错误:请联系管理员"),
+    SERVICE_NOT_FOUND(HttpStatus.INTERNAL_SERVER_ERROR, 5000005, "服务器错误"),
 
-    EXCEPTION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 505, "系统异常:请联系管理员"),
+    UNKONW_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000006, "未知错误:请联系管理员"),
+
+    EXCEPTION_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000007, "系统异常:请联系管理员"),
+
+    /**
+     * 500
+     */
+    EXCEL_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000008, "excel没有数据"),
+
+    USER_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000009, "用户或密码不正确"),
+
+    PASSWORD_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000010, "密码不正确"),
+
+    USER_ENABLE(HttpStatus.INTERNAL_SERVER_ERROR, 5000011, "用户已停用"),
+
+    NOT_LOGIN(HttpStatus.INTERNAL_SERVER_ERROR, 5000012, "请先登录"),
+
+    ROLE_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000013, "没有角色数据"),
+
+    ATTACHMENT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 5000014, "上传文件失败"),
+
+    MD5_EMPTY(HttpStatus.INTERNAL_SERVER_ERROR, 5000015, "md5为空"),
+
+    MD5_EQUALS_FALSE(HttpStatus.INTERNAL_SERVER_ERROR, 5000016, "md5不一致"),
+
+    ATTACHMENT_TYPE_EMPTY(HttpStatus.INTERNAL_SERVER_ERROR, 5000017, "请上传文件类型"),
+
+    TASK_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000018, "任务不存在"),
+
+    PATH_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000019, "文件地址不存在"),
+
+    /**
+     * 401
+     */
+    PLATFORM_INVALID(HttpStatus.UNAUTHORIZED, 4010001, "platform无效"),
+
+    DEVICE_ID_INVALID(HttpStatus.UNAUTHORIZED, 4010002, "deviceId无效"),
+
+    TOKEN_INVALID(HttpStatus.UNAUTHORIZED, 4010003, "token无效"),
+
+    TIME_INVALID(HttpStatus.UNAUTHORIZED, 4010004, "time无效"),
+
+    AUTHORIZATION_INVALID(HttpStatus.UNAUTHORIZED, 4010005, "authorization无效"),
+
+    AUTHORIZATION_ERROR(HttpStatus.UNAUTHORIZED, 4010006, "签名验证失败"),
+
+    UN_AUTHORIZATION(HttpStatus.UNAUTHORIZED, 4010007, "没有权限"),
+
+    ROLE_ENABLE_AUTHORIZATION(HttpStatus.UNAUTHORIZED, 4010008, "角色被禁用或没有权限"),
 
     /**
-     * 400
+     * 404
      */
-    EXCEL_NO(HttpStatus.BAD_REQUEST, 4000001, "excel没有数据");
+    NOT_FOUND(HttpStatus.NOT_FOUND, 4040003, "请求地址错误");
 
     private HttpStatus status;
     private int code;

+ 92 - 25
distributed-print/src/main/java/com/qmth/distributed/print/api/SysController.java

@@ -1,32 +1,47 @@
 package com.qmth.distributed.print.api;
 
-import cn.hutool.core.lang.UUID;
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.annotation.BOOL;
 import com.qmth.boot.api.constant.ApiConstant;
+import com.qmth.boot.core.enums.Platform;
+import com.qmth.boot.tools.signature.SignatureType;
+import com.qmth.distributed.print.business.bean.auth.AuthBean;
+import com.qmth.distributed.print.business.bean.auth.ExpireTimeBean;
 import com.qmth.distributed.print.business.bean.query.LoginParam;
+import com.qmth.distributed.print.business.bean.result.EditResult;
+import com.qmth.distributed.print.business.bean.result.LoginResult;
 import com.qmth.distributed.print.business.config.DictionaryConfig;
 import com.qmth.distributed.print.business.entity.BasicVerifyCode;
 import com.qmth.distributed.print.business.entity.SysUser;
-import com.qmth.distributed.print.business.service.BasicVerifyCodeService;
-import com.qmth.distributed.print.business.service.SysConfigService;
-import com.qmth.distributed.print.business.service.SysUserService;
+import com.qmth.distributed.print.business.entity.TBSession;
+import com.qmth.distributed.print.business.enums.RoleTypeEnum;
+import com.qmth.distributed.print.business.service.*;
+import com.qmth.distributed.print.business.util.AuthUtil;
+import com.qmth.distributed.print.business.util.RedisUtil;
+import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.business.util.security.Md5Utils;
+import com.qmth.distributed.print.common.SignatureEntityTest;
+import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
+import com.qmth.distributed.print.common.util.SessionUtil;
+import io.swagger.annotations.*;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.annotation.Resource;
+import javax.validation.Valid;
+import java.security.NoSuchAlgorithmException;
 import java.util.Date;
 import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 /**
  * @Date: 2021/3/30.
@@ -34,7 +49,7 @@ import java.util.Objects;
 @Api(tags = "系统Controller")
 @RestController
 @RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + "/${prefix.url.common}")
-@Aac(auth = BOOL.FALSE)
+@Aac(strict = BOOL.TRUE, platform = Platform.WEB)
 public class SysController {
 
     @Autowired
@@ -49,6 +64,15 @@ public class SysController {
     @Autowired
     private DictionaryConfig dictionaryConfig;
 
+    @Resource
+    CacheService cacheService;
+
+    @Resource
+    TBSessionService tbSessionService;
+
+    @Resource
+    RedisUtil redisUtil;
+
     /**
      * 登录
      *
@@ -57,20 +81,30 @@ public class SysController {
      */
     @ApiOperation(value = "登录")
     @RequestMapping(value = "/login", method = RequestMethod.POST)
-    public Result login(@RequestBody LoginParam login) {
+    @ApiResponses({@ApiResponse(code = 200, message = "用户信息", response = LoginResult.class)})
+    @Aac(auth = BOOL.FALSE)
+    public Result login(@ApiParam(value = "用户信息", required = true) @Valid @RequestBody LoginParam login, BindingResult bindingResult) throws NoSuchAlgorithmException {
+        if (bindingResult.hasErrors()) {
+            return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
+        }
         QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
         queryWrapper.lambda().eq(SysUser::getLoginName, login.getLoginName());
         SysUser sysUser = sysUserService.getOne(queryWrapper);
-        if (sysUser == null) {
-            throw ExceptionResultEnum.ERROR.exception("用户不存在");
+        //用户不存在
+        if (Objects.isNull(sysUser)) {
+            throw ExceptionResultEnum.USER_NO_DATA.exception();
         }
-        String password = Md5Utils.toMd5Hex(login.getPassword());
-        if (!password.equals(sysUser.getPassword())) {
-            throw ExceptionResultEnum.ERROR.exception("密码错误");
+        //密码不正确
+        if (!Objects.equals(login.getPassword(), sysUser.getPassword())) {
+            throw ExceptionResultEnum.PASSWORD_ERROR.exception();
+        }
+        //停用
+        if (!sysUser.getEnable()) {
+            throw ExceptionResultEnum.USER_ENABLE.exception();
         }
         //校验验证码
         String value = sysConfigService.getByKey("sys.code.enable");
-        if (value.equals("true")) {
+        if (Objects.nonNull(value) && value.equals("true")) {
             String code = login.getCode();
             if (Objects.isNull(code)) {
                 throw ExceptionResultEnum.ERROR.exception("验证码为空");
@@ -89,25 +123,58 @@ public class SysController {
             }
         }
 
-        //停用
-        if (!sysUser.getEnable()) {
-            throw ExceptionResultEnum.ERROR.exception("用户已禁用");
+        Platform platform = ServletUtil.getRequestPlatform();
+        String deviceId = ServletUtil.getRequestDeviceId();
+        //添加用户鉴权缓存
+        AuthBean authBean = cacheService.userAuthCache(sysUser.getId());
+        if (Objects.isNull(authBean)) {
+            throw ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception();
         }
-        JSONObject jsonObject = new JSONObject();
-        jsonObject.put("user", sysUserService.getUserRoles(sysUser));
-        jsonObject.put("token", UUID.fastUUID().toString());
-        return ResultUtil.ok(jsonObject);
+        //生成token
+        String token = SystemConstant.getUuid();
+        cacheService.userCache(sysUser.getId());
+        //添加用户会话缓存
+        Set<RoleTypeEnum> roleType = authBean.getRoleList().stream().map(s -> s.getType()).collect(Collectors.toSet());
+        String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleType.toString().hashCode()), platform.name());
+        //TODO 测试用
+        String test = SignatureEntityTest.build(SignatureType.TOKEN, sessionId, token);
+        ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
+        TBSession tbSession = new TBSession(sessionId, String.valueOf(sysUser.getId()), roleType.toString(),
+                platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
+                expireTime.getDate().getTime());
+        tbSessionService.saveOrUpdate(tbSession);
+        redisUtil.setUserSession(sessionId, tbSession, expireTime.getExpireSeconds());
+
+//        JSONObject jsonObject = new JSONObject();
+//        jsonObject.put("user", sysUserService.getUserRoles(sysUser));
+//        jsonObject.put("token", UUID.fastUUID().toString());
+
+        LoginResult loginResult = new LoginResult(sysUser, sessionId, test, roleType);
+        loginResult.setSchoolInfo(Objects.nonNull(authBean.getSchool()) ? loginResult.new SchoolNativeBean(authBean.getSchool()) : null);
+        loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
+        return ResultUtil.ok(loginResult);
     }
 
     /**
      * 登出
-     * @param id
+     *
      * @return
      */
     @ApiOperation(value = "登出")
     @RequestMapping(value = "/logout", method = RequestMethod.POST)
-    public Result logout(Long id) {
-        return ResultUtil.ok(true);
+    @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
+    public Result logout() {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
+        AuthBean authBean = cacheService.userAuthCache(sysUser.getId());
+        if (Objects.isNull(authBean)) {
+            throw ExceptionResultEnum.NOT_LOGIN.exception();
+        }
+        tbSessionService.removeById(tbSession.getId());
+        redisUtil.deleteUserSession(tbSession.getId());
+        cacheService.removeUserCache(sysUser.getId());
+        cacheService.removeUserAuthCache(sysUser.getId());
+        return ResultUtil.ok(new EditResult(sysUser.getId()));
     }
 
     /**

+ 7 - 12
distributed-print/src/main/java/com/qmth/distributed/print/aspect/ApiControllerAspect.java

@@ -2,6 +2,7 @@ package com.qmth.distributed.print.aspect;
 
 import com.qmth.boot.api.exception.ApiException;
 import com.qmth.distributed.print.business.util.ServletUtil;
+import com.qmth.distributed.print.common.util.JacksonUtil;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
@@ -11,6 +12,7 @@ import org.aspectj.lang.reflect.MethodSignature;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
+import org.springframework.validation.BeanPropertyBindingResult;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
@@ -57,18 +59,11 @@ public class ApiControllerAspect {
             log.info("============类=============:{}", className);
             log.info("============方法===========:{}", methodName);
             if (Objects.nonNull(args) && args.length > 0) {
-                boolean jsonOut = true;
-                for (Object o : args) {
-                    if (o instanceof CommonsMultipartFile || o instanceof MultipartFile) {
-                        jsonOut = false;
-                        break;
-                    }
-                }
-                if (jsonOut) {
-//                    log.info("============参数key:{},参数value===========:{}", JacksonUtil.parseJson(paramsName), JacksonUtil.parseJson(args));
-                } else {
-                    for (int i = 0; i < args.length; i++) {
-                        log.info("============参数key:{},参数value===========:{}", paramsName[i], args[i]);
+                for (int i = 0; i < args.length; i++) {
+                    if (args[i] instanceof CommonsMultipartFile || args[i] instanceof MultipartFile || args[i] instanceof BeanPropertyBindingResult) {
+                        continue;
+                    } else {
+                        log.info("============参数key:{},参数value===========:{}", JacksonUtil.parseJson(paramsName[i]), JacksonUtil.parseJson(args[i]));
                     }
                 }
             }

+ 12 - 7
distributed-print/src/main/java/com/qmth/distributed/print/config/SwaggerConfig.java

@@ -1,15 +1,22 @@
 package com.qmth.distributed.print.config;
 
 import com.google.common.base.Predicates;
+import com.qmth.distributed.print.common.contant.SystemConstant;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import springfox.documentation.builders.ParameterBuilder;
 import springfox.documentation.builders.PathSelectors;
 import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.schema.ModelRef;
 import springfox.documentation.service.ApiInfo;
+import springfox.documentation.service.Parameter;
 import springfox.documentation.spi.DocumentationType;
 import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @Description: swagger配置类
  * @Param:
@@ -23,11 +30,11 @@ public class SwaggerConfig {
 
     @Bean
     public Docket createRestApi() {
-        /*ParameterBuilder tokenPar = new ParameterBuilder();
+        ParameterBuilder tokenPar = new ParameterBuilder();
         ParameterBuilder tokenPar1 = new ParameterBuilder();
         ParameterBuilder tokenPar2 = new ParameterBuilder();
         ParameterBuilder tokenPar3 = new ParameterBuilder();
-        List<Parameter> pars = new ArrayList();
+        List<Parameter> pars = new ArrayList<>();
         tokenPar.name(SystemConstant.HEADER_PLATFORM).description("平台").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
         tokenPar1.name(SystemConstant.HEADER_DEVICE_ID).description("设备id").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
         tokenPar2.name(SystemConstant.HEADER_AUTHORIZATION).description("鉴权token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
@@ -35,7 +42,7 @@ public class SwaggerConfig {
         pars.add(tokenPar.build());
         pars.add(tokenPar1.build());
         pars.add(tokenPar2.build());
-        pars.add(tokenPar3.build());*/
+        pars.add(tokenPar3.build());
 
         return new Docket(DocumentationType.SWAGGER_2)
                 .groupName("distributed-print")
@@ -46,7 +53,7 @@ public class SwaggerConfig {
                 // 不显示错误的接口地址
                 .paths(Predicates.not(PathSelectors.regex("/error.*")))// 错误路径不监控
                 .build()
-//                .globalOperationParameters(pars)
+                .globalOperationParameters(pars)
                 .apiInfo(apiInfo());
     }
 
@@ -61,6 +68,4 @@ public class SwaggerConfig {
                 "API license URL");
         return apiInfo;
     }
-}
- 
-
+}

+ 2 - 1
distributed-print/src/main/java/com/qmth/distributed/print/interceptor/AuthInterceptor.java

@@ -1,6 +1,7 @@
 package com.qmth.distributed.print.interceptor;
 
 import com.qmth.boot.api.interceptor.ExtendInterceptor;
+import com.qmth.distributed.print.business.util.AuthUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.lang.Nullable;
@@ -17,7 +18,7 @@ public class AuthInterceptor extends ExtendInterceptor {
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
         log.info("preHandle is come in");
-        return true;
+        return AuthUtil.adminAuthInterceptor(request, response);
     }
 
     @Override

+ 2 - 2
distributed-print/src/main/resources/application.properties

@@ -12,9 +12,9 @@ spring.application.name=distributed-print
 #\u6570\u636E\u6E90\u914D\u7F6E
 db.host=localhost
 db.port=3306
-db.name=tc_print_2
+db.name=distributed_print
 db.username=root
-db.password=root
+db.password=123456789
 
 #redis\u6570\u636E\u6E90\u914D\u7F6E
 com.qmth.redis.host=${db.host}