Ver código fonte

加入登录

wangliang 1 ano atrás
pai
commit
70917b9bf3

+ 72 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/params/LoginParam.java

@@ -0,0 +1,72 @@
+package com.qmth.sop.business.bean.params;
+
+import com.qmth.sop.common.enums.LoginTypeEnum;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * @Description: 用户登录
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2021/4/23
+ */
+public class LoginParam {
+
+    @ApiModelProperty(value = "验证码")
+    private String code;
+
+    @ApiModelProperty(value = "用户手机号(优先给用户填的手机号发短信)")
+    private String mobileNumber;
+
+    @ApiModelProperty(value = "登录名")
+    private String loginName;
+
+    @ApiModelProperty(value = "密码")
+    private String password;
+
+    @ApiModelProperty(value = "登录类型")
+    @NotNull(message = "登录类型不能为空")
+    private LoginTypeEnum type;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMobileNumber() {
+        return mobileNumber;
+    }
+
+    public void setMobileNumber(String mobileNumber) {
+        this.mobileNumber = mobileNumber;
+    }
+
+    public String getLoginName() {
+        return loginName;
+    }
+
+    public void setLoginName(String loginName) {
+        this.loginName = loginName;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public LoginTypeEnum getType() {
+        return type;
+    }
+
+    public void setType(LoginTypeEnum type) {
+        this.type = type;
+    }
+}

+ 240 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/LoginResult.java

@@ -0,0 +1,240 @@
+package com.qmth.sop.business.bean.result;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+import com.qmth.sop.business.entity.SysOrg;
+import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.common.enums.AppSourceEnum;
+import com.qmth.sop.common.util.ServletUtil;
+import io.swagger.annotations.ApiModelProperty;
+
+import javax.management.relation.RoleResult;
+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 = "机构信息")
+    OrgNativeBean orgInfo;
+
+    @ApiModelProperty(name = "角色集合")
+    private Set<String> roleList;
+
+    @ApiModelProperty(name = "服务器时间戳")
+    private long time;
+
+    @ApiModelProperty(value = "应用来源")
+    AppSourceEnum appSource;
+
+    @ApiModelProperty(value = "密码修改次数")
+    Integer pwdCount;
+
+    @ApiModelProperty(name = "返回url")
+    String returnUrl;
+
+    @ApiModelProperty(name = "版本号")
+    String version;
+
+    public String getVersion() {
+        return version;
+    }
+
+    public void setVersion(String version) {
+        this.version = version;
+    }
+
+    public String getReturnUrl() {
+        return returnUrl;
+    }
+
+    public void setReturnUrl(String returnUrl) {
+        this.returnUrl = returnUrl;
+    }
+
+    public LoginResult() {
+
+    }
+
+    public LoginResult(SysUser sysUser, String sessionId, String accessToken, Set<String> roleList, AppSourceEnum appSource, String version) {
+        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;
+        this.appSource = appSource;
+        this.pwdCount = sysUser.getPwdCount();
+        this.version = version;
+    }
+
+    public LoginResult(SysUser sysUser, String sessionId, String accessToken, OrgNativeBean orgInfo, AppSourceEnum appSource, String version) {
+        this.loginName = sysUser.getLoginName();
+        this.realName = sysUser.getRealName();
+        this.sessionId = sessionId;
+        this.accessToken = accessToken;
+        this.orgInfo = orgInfo;
+        this.appSource = appSource;
+        this.version = version;
+    }
+
+    public AppSourceEnum getAppSource() {
+        return appSource;
+    }
+
+    public void setAppSource(AppSourceEnum appSource) {
+        this.appSource = appSource;
+    }
+
+    public Set<String> getRoleList() {
+        return roleList;
+    }
+
+    public void setRoleList(Set<String> 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 long getTime() {
+        return time;
+    }
+
+    public void setTime(long time) {
+        this.time = time;
+    }
+
+    public Integer getPwdCount() {
+        return pwdCount;
+    }
+
+    public void setPwdCount(Integer pwdCount) {
+        this.pwdCount = pwdCount;
+    }
+
+    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;
+        }
+    }
+}

+ 23 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/SmsResponseResult.java

@@ -0,0 +1,23 @@
+package com.qmth.sop.business.bean.result;
+
+public class SmsResponseResult {
+
+    private String code;
+    private String message;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

+ 14 - 0
sop-business/src/main/java/com/qmth/sop/business/service/SysUserService.java

@@ -1,7 +1,11 @@
 package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.sop.business.bean.result.LoginResult;
 import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.common.enums.AppSourceEnum;
+
+import java.security.NoSuchAlgorithmException;
 
 /**
  * <p>
@@ -13,4 +17,14 @@ import com.qmth.sop.business.entity.SysUser;
  */
 public interface SysUserService extends IService<SysUser> {
 
+    /**
+     * 登录公用
+     *
+     * @param password
+     * @param sysUser
+     * @param appSource
+     * @return
+     * @throws NoSuchAlgorithmException
+     */
+    public LoginResult login(String password, SysUser sysUser, AppSourceEnum appSource) throws NoSuchAlgorithmException;
 }

+ 58 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/SysUserServiceImpl.java

@@ -1,11 +1,28 @@
 package com.qmth.sop.business.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.boot.core.enums.Platform;
+import com.qmth.sop.business.bean.auth.AuthBean;
+import com.qmth.sop.business.bean.auth.ExpireTimeBean;
+import com.qmth.sop.business.bean.result.LoginResult;
+import com.qmth.sop.business.cache.CommonCacheService;
 import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.business.entity.TBSession;
 import com.qmth.sop.business.mapper.SysUserMapper;
 import com.qmth.sop.business.service.SysUserService;
+import com.qmth.sop.business.service.TBSessionService;
+import com.qmth.sop.business.util.AuthUtil;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.AppSourceEnum;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.util.ServletUtil;
+import com.qmth.sop.common.util.SessionUtil;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+
 /**
  * <p>
  * 用户表 服务实现类
@@ -17,4 +34,45 @@ import org.springframework.stereotype.Service;
 @Service
 public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
 
+    @Resource
+    CommonCacheService commonCacheService;
+
+    @Resource
+    TBSessionService tbSessionService;
+
+    @Override
+    public LoginResult login(String password, SysUser sysUser, AppSourceEnum appSource) throws NoSuchAlgorithmException {
+        //停用
+        if (!sysUser.getEnable()) {
+            throw ExceptionResultEnum.USER_ENABLE.exception();
+        }
+
+        Platform platform = ServletUtil.getRequestPlatform();
+        String deviceId = ServletUtil.getRequestDeviceId();
+        //添加用户鉴权缓存
+        AuthBean authBean = commonCacheService.userAuthCache(sysUser.getId());
+        Optional.ofNullable(authBean).orElseThrow(() -> ExceptionResultEnum.ROLE_ENABLE_AUTHORIZATION.exception());
+
+        //生成token
+        String token = SystemConstant.getNanoId();
+        commonCacheService.userCache(sysUser.getId());
+        //添加用户会话缓存
+        Set<String> roleNamesSet = new HashSet<>(), roleTypes = new HashSet<>();
+        List<String> roleNames = new ArrayList<>();
+        roleNames.addAll(roleNamesSet);
+        Collections.sort(roleNames);
+
+        String sessionId = SessionUtil.digest(sysUser.getId(), Math.abs(roleNames.toString().hashCode()), platform.name());
+        ExpireTimeBean expireTime = AuthUtil.getExpireTime(platform);
+        TBSession tbSession = new TBSession(sessionId, String.valueOf(sysUser.getId()), roleNames.toString(),
+                platform.name(), platform.name(), deviceId, ServletUtil.getRequest().getLocalAddr(), token,
+                expireTime.getDate().getTime(), appSource);
+        tbSessionService.saveOrUpdate(tbSession);
+        commonCacheService.setUserSession(sessionId, tbSession);
+
+        LoginResult loginResult = new LoginResult(sysUser, sessionId, token, Objects.nonNull(roleTypes) && roleTypes.size() > 0 ? roleTypes : roleNamesSet, appSource, SystemConstant.VERSION_VALUE);
+        loginResult.setOrgInfo(Objects.nonNull(authBean.getOrg()) ? loginResult.new OrgNativeBean(authBean.getOrg()) : null);
+        loginResult.setTime(System.currentTimeMillis());
+        return loginResult;
+    }
 }

+ 38 - 0
sop-business/src/main/java/com/qmth/sop/business/util/AuthUtil.java

@@ -0,0 +1,38 @@
+package com.qmth.sop.business.util;
+
+import com.qmth.boot.core.enums.Platform;
+import com.qmth.sop.business.bean.auth.ExpireTimeBean;
+import com.qmth.sop.common.contant.SystemConstant;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * @Description: 鉴权工具类util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/11/12
+ */
+public class AuthUtil {
+    private final static Logger log = LoggerFactory.getLogger(AuthUtil.class);
+
+    /**
+     * 获取过期时间
+     *
+     * @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.DEFAULT_EXPIRE_TIME);
+        return expireTimeBean;
+    }
+}

+ 85 - 0
sop-business/src/main/java/com/qmth/sop/business/util/SmsSendUtil.java

@@ -0,0 +1,85 @@
+package com.qmth.sop.business.util;
+
+import com.qmth.boot.api.exception.ApiException;
+import com.qmth.boot.core.sms.model.SmsSendRequest;
+import com.qmth.boot.core.sms.model.SmsSendResponse;
+import com.qmth.boot.core.sms.service.SmsService;
+import com.qmth.sop.business.bean.result.SmsResponseResult;
+import com.qmth.sop.business.cache.CommonCacheService;
+import com.qmth.sop.business.entity.SysConfig;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * 短信发送工具类
+ */
+@Component
+public class SmsSendUtil {
+
+    private static final Logger log = LoggerFactory.getLogger(SmsSendUtil.class);
+
+    public static final String OK = "OK";
+    private static final String ERROR = "ERROR";
+
+    @Resource
+    private SmsService smsService;
+
+    @Resource
+    CommonCacheService commonCacheService;
+
+
+    /**
+     * 短信发送接口
+     *
+     * @param phoneNumber   发送手机号
+     * @param configKey     参数key
+     * @param templateParam 模版变量
+     * @return bizId 本次操作业务标识
+     */
+    public SmsResponseResult sendSms(String phoneNumber, String configKey, Map<String, Object> templateParam) {
+        Optional.ofNullable(phoneNumber).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("手机号不能为空"));
+        if (phoneNumber.length() != 11) {
+            throw ExceptionResultEnum.ERROR.exception("手机号长度必须为11位");
+        }
+
+        SmsSendRequest smsSendRequest = new SmsSendRequest();
+        // 必填,发送手机号
+        smsSendRequest.setPhoneNumber(phoneNumber);
+        // 必填,短信签名
+        SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SMS_SIGN_NAME);
+        Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置短信签名模版"));
+
+        String signName = sysConfig.getConfigValue();
+        smsSendRequest.setSignName(signName);
+        // 必填,短信模版编号
+        SysConfig sysConfigKey = commonCacheService.addSysConfigCache(configKey);
+        Optional.ofNullable(sysConfigKey).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置" + configKey));
+
+        String templateCode = sysConfigKey.getConfigValue();
+        smsSendRequest.setTemplateCode(templateCode);
+        //模版变量,可选
+        if (Objects.nonNull(templateParam) && !CollectionUtils.isEmpty(templateParam)) {
+            smsSendRequest.setTemplateParam(templateParam);
+        }
+        SmsResponseResult smsResponseResult = new SmsResponseResult();
+        try {
+            SmsSendResponse smsSendResponse = smsService.sendSms(smsSendRequest);
+            Optional.ofNullable(smsSendResponse).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("短信发送失败"));
+            smsResponseResult.setCode(OK);
+            smsResponseResult.setMessage(smsSendResponse.getBizId());
+        } catch (ApiException e) {
+            smsResponseResult.setCode(OK);
+            smsResponseResult.setMessage(e.getMessage());
+        }
+        return smsResponseResult;
+    }
+}

+ 17 - 1
sop-common/src/main/java/com/qmth/sop/common/contant/SystemConstant.java

@@ -15,6 +15,9 @@ import java.nio.charset.Charset;
  */
 public class SystemConstant {
 
+    /**
+     * 系统常量
+     */
     public static final String CHARSET_NAME = "UTF-8";
     //    public static final String CHARSET_GB2312 = "gb2312";
     public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
@@ -34,6 +37,7 @@ public class SystemConstant {
     public static final String PATH_MATCH = "*";
     public static final String PATH_SUBSTR = "/#";
     public static final String METHOD = "post";
+    public static final String ERROR = "/error";
     public static final String PT = "PT";
     public static final String USER_DIR = "user.dir";
     public static final String OS_NAME = "os.name";
@@ -42,7 +46,13 @@ public class SystemConstant {
     public static final String SIZE = "size";
     public static final String WINDOWS = "Windows";
     public static final String ORG_SPLIT = "/";
+    public static final String HYPHEN = "-";
+    public static final String SYS_ADMIN = "sysadmin";
+    public static final String VERSION_VALUE = "1.0.0.1";
 
+    /**
+     * 系统配置
+     */
     public static final String SYS_CODE_ENABLE = "sys.code.enable";
     //    public static final String SYS_MESSAGE_ENABLE = "sys.message.enable";
 //    public static final String SYS_MESSAGE_RESEND_COUNT = "sys.message.resendCount";
@@ -57,11 +67,14 @@ public class SystemConstant {
     public static final String SMS_NORMAL_CODE = "sms.normal.code";
     public static final String CODE_EXPIRED_TIME = "code.expired.time";
     public static final String CODE_SEND_INTERVAL = "code.send.interval";
+    public static final String SMS_SIGN_NAME = "sms.sign.name";
 
     /**
      * api前缀
      */
     public static final String PREFIX_URL_WIDGET = "/admin/widget";
+    public static final String PREFIX_TEST_FLOW = "/test/flow";
+    public static final String PREFIX_URL_COMMON = "/admin/common";
 
     /**
      * 缓存配置
@@ -87,6 +100,10 @@ public class SystemConstant {
     public static final String SIGN = "sign";
     public static final String LOG_ERROR = "请求出错:{}";
 
+    public static final int DEFAULT_SESSION_EXPIRE = 1;//过期时间1天
+    public static final long DEFAULT_EXPIRE_TIME = 24 * 60L * 60L;//过期时间24小时
+    public static final long THIRD_USER_AUTH_EXPIRE_TIME = 2 * 60L;//过期时间2分钟
+
     /**
      * http设置
      */
@@ -118,7 +135,6 @@ public class SystemConstant {
     public static final String FLOW_DEPLOYMENT_ID = "flowDeploymentId";
     public static final String APPROVE = "approve";//流程审核变量
     public static final String DEFAULT_ASSIGNEE_LIST = "assigneeList";
-    public static final String ASSIGNEE = "assignee";
     public static final String NR_OF_COMPLETED_INSTANCES = "nrOfCompletedInstances";
     public static final String NR_OF_INSTANCES = "nrOfInstances";
 

+ 2 - 0
sop-common/src/main/java/com/qmth/sop/common/enums/ExceptionResultEnum.java

@@ -35,6 +35,8 @@ public enum ExceptionResultEnum {
      */
     USER_NO_DATA(HttpStatus.INTERNAL_SERVER_ERROR, 5000009, "用户或密码不正确"),
 
+    USER_ENABLE(HttpStatus.INTERNAL_SERVER_ERROR, 5000011, "用户已禁用"),
+
     NOT_LOGIN(HttpStatus.INTERNAL_SERVER_ERROR, 5000012, "请先登录"),
 
     MD5_EMPTY(HttpStatus.INTERNAL_SERVER_ERROR, 5000015, "md5为空"),

+ 42 - 0
sop-common/src/main/java/com/qmth/sop/common/enums/LoginTypeEnum.java

@@ -0,0 +1,42 @@
+package com.qmth.sop.common.enums;
+
+import java.util.Objects;
+
+/**
+ * @Description: 登录类型 enum
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2022/4/26
+ */
+public enum LoginTypeEnum {
+
+    ACCOUNT("账号登录"),
+
+    PHONE("手机验证码登录");
+
+    LoginTypeEnum(String title) {
+        this.title = title;
+    }
+
+    private String title;
+
+    public String getTitle() {
+        return title;
+    }
+
+    /**
+     * 状态转换 toName
+     *
+     * @param value
+     * @return
+     */
+    public static String convertToName(String value) {
+        for (LoginTypeEnum e : LoginTypeEnum.values()) {
+            if (Objects.equals(value.trim(), e.getTitle())) {
+                return e.name();
+            }
+        }
+        return null;
+    }
+}

+ 57 - 0
sop-common/src/main/java/com/qmth/sop/common/util/MD5Util.java

@@ -0,0 +1,57 @@
+package com.qmth.sop.common.util;
+
+import com.qmth.sop.common.contant.SystemConstant;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Optional;
+import java.util.StringJoiner;
+
+/**
+ * @Description: MD5加密工具类
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2019/10/11
+ */
+public class MD5Util {
+
+    /**
+     * MD5加密
+     *
+     * @param text
+     * @return
+     * @throws Exception
+     */
+    public static String encoder(String text) throws NoSuchAlgorithmException {
+        text = Optional.of(text).get();
+        MessageDigest digest = MessageDigest.getInstance(SystemConstant.MD5);
+        digest.update(text.getBytes(SystemConstant.CHARSET));
+        byte s[] = digest.digest();
+        StringJoiner result = new StringJoiner("");
+        for (int i = 0; i < s.length; i++) {
+            result.add(Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6));
+        }
+        return result.toString();
+    }
+
+    /**
+     * MD5校验
+     *
+     * @param text
+     * @param md5
+     * @return
+     * @throws Exception
+     */
+    public static boolean verify(String text, String md5) throws NoSuchAlgorithmException {
+        text = Optional.of(text).get();
+        md5 = Optional.of(md5).get();
+        //根据传入的密钥进行验证
+        String md5Text = encoder(text);
+        if (md5Text.equalsIgnoreCase(md5)) {
+            return true;
+        }
+        return false;
+    }
+}
+

+ 0 - 8
sop-common/src/main/java/com/qmth/sop/common/util/ServletUtil.java

@@ -235,12 +235,4 @@ public class ServletUtil {
         ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
         return servletRequestAttributes.getRequest().getSession();
     }
-
-    public static Long getRequestUserId() {
-        Object object = getRequest().getHeader("userId");
-        if (Objects.isNull(object)) {
-            throw ExceptionResultEnum.NOT_LOGIN.exception();
-        }
-        return Long.parseLong(object.toString());
-    }
 }

+ 33 - 0
sop-common/src/main/java/com/qmth/sop/common/util/SessionUtil.java

@@ -0,0 +1,33 @@
+package com.qmth.sop.common.util;
+
+import com.qmth.sop.common.contant.SystemConstant;
+
+import java.security.NoSuchAlgorithmException;
+import java.util.Objects;
+import java.util.StringJoiner;
+
+/**
+ * @Description: sessionId util
+ * @Param:
+ * @return:
+ * @Author: wangliang
+ * @Date: 2020/6/28
+ */
+public class SessionUtil {
+
+    /**
+     * 生成sessionId
+     *
+     * @param o
+     * @return
+     */
+    public static String digest(Object... o) throws NoSuchAlgorithmException {
+        StringJoiner stringJoiner = new StringJoiner("");
+        if (Objects.nonNull(o) && o.length > 0) {
+            for (int i = 0; i < o.length; i++) {
+                stringJoiner.add(String.valueOf(o[i])).add(SystemConstant.HYPHEN);
+            }
+        }
+        return MD5Util.encoder(stringJoiner.toString().substring(0, stringJoiner.length() - 1));
+    }
+}

+ 2 - 1
sop-server/src/main/java/com/qmth/sop/server/api/ActivitiFromHtmlController.java

@@ -2,6 +2,7 @@ package com.qmth.sop.server.api;
 
 import com.qmth.sop.business.activiti.service.ActivitiService;
 import com.qmth.sop.business.service.TFCustomFlowService;
+import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.FlowApprovePassEnum;
 import com.qmth.sop.common.enums.TFCustomTypeEnum;
 import com.qmth.sop.common.util.Result;
@@ -21,7 +22,7 @@ import java.util.*;
 
 @Api(tags = "测试流程表单htmlController")
 @RestController
-@RequestMapping("/test/flow")
+@RequestMapping(SystemConstant.PREFIX_TEST_FLOW)
 public class ActivitiFromHtmlController {
     private final static Logger log = LoggerFactory.getLogger(ActivitiFromHtmlController.class);
 

+ 108 - 0
sop-server/src/main/java/com/qmth/sop/server/api/SysController.java

@@ -0,0 +1,108 @@
+package com.qmth.sop.server.api;
+
+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.sop.business.bean.params.LoginParam;
+import com.qmth.sop.business.bean.result.LoginResult;
+import com.qmth.sop.business.cache.CommonCacheService;
+import com.qmth.sop.business.entity.SysConfig;
+import com.qmth.sop.business.entity.SysUser;
+import com.qmth.sop.business.service.SysUserService;
+import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.AppSourceEnum;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+import com.qmth.sop.common.enums.LoginTypeEnum;
+import com.qmth.sop.common.util.Result;
+import com.qmth.sop.common.util.ResultUtil;
+import io.swagger.annotations.*;
+import org.springframework.util.CollectionUtils;
+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.List;
+import java.util.Objects;
+import java.util.Optional;
+
+/**
+ * <p>
+ * 系统公用 前端控制器
+ * </p>
+ *
+ * @author wangliang
+ * @since 2023-07-17
+ */
+@Api(tags = "系统公用Controller")
+@RestController
+@RequestMapping(ApiConstant.DEFAULT_URI_PREFIX + SystemConstant.PREFIX_URL_COMMON)
+public class SysController {
+
+    @Resource
+    SysUserService sysUserService;
+
+    @Resource
+    CommonCacheService commonCacheService;
+
+    /**
+     * 登录
+     *
+     * @param login
+     * @return
+     */
+    @ApiOperation(value = "登录")
+    @RequestMapping(value = "/login", method = RequestMethod.POST)
+    @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());
+        }
+        SysUser sysUser = null;
+        List<SysUser> sysUserList = null;
+        if (login.getType() == LoginTypeEnum.ACCOUNT) {//账号登录
+            // 非空校验
+            Optional.ofNullable(login.getLoginName()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("用户名不能为空"));
+            Optional.ofNullable(login.getPassword()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("密码不能为空"));
+            sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getLoginName, login.getLoginName()));
+            if (CollectionUtils.isEmpty(sysUserList)) {
+                throw ExceptionResultEnum.ERROR.exception("用户不存在");
+            }
+            if (sysUserList.size() > 1) {
+                throw ExceptionResultEnum.ERROR.exception("查出多个用户");
+            }
+            sysUser = sysUserList.get(0);
+
+            if (!Objects.equals(sysUser.getPassword(), login.getPassword())) {
+                throw ExceptionResultEnum.ERROR.exception("用户名或密码错误");
+            }
+        } else {//验证码模式
+            Optional.ofNullable(login.getMobileNumber()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("手机号不能为空"));
+            Optional.ofNullable(login.getCode()).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("验证码不能为空"));
+
+            SysConfig sysConfig = commonCacheService.addSysConfigCache(SystemConstant.SMS_NORMAL_CODE);
+            Optional.ofNullable(sysConfig).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未配置万能短信验证码"));
+
+            if (Objects.equals(sysConfig.getConfigValue().trim(), login.getCode().trim())) {
+                sysUserList = sysUserService.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getMobileNumber, login.getMobileNumber()));
+                if (CollectionUtils.isEmpty(sysUserList)) {
+                    throw ExceptionResultEnum.ERROR.exception("用户不存在");
+                }
+                if (sysUserList.size() > 1) {
+                    throw ExceptionResultEnum.ERROR.exception("查出多个用户");
+                }
+                sysUser = sysUserList.get(0);
+            } else {//走发送验证码模式
+
+            }
+        }
+        Optional.ofNullable(sysUser).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("未查询到用户"));
+        return ResultUtil.ok(sysUserService.login(login.getPassword(), sysUser, AppSourceEnum.SYSTEM));
+    }
+}

+ 1 - 1
sop-server/src/main/resources/application.properties

@@ -74,7 +74,7 @@ com.qmth.auth.time-max-ahead=1m
 com.qmth.auth.time-max-delay=5m
 
 #\u7F13\u5B58\u65F6\u95F4
-com.qmth.cache.expire-after-write=8h
+com.qmth.cache.expire-after-write=24h
 
 #\u65E5\u671F\u683C\u5F0F\u5316
 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss