Merge branch 'SingleSignOn' into branch2022-1-4
# Conflicts: # db/2022-1-4变更.sql
This commit is contained in:
+1
-6
@@ -47,12 +47,7 @@ update tb_certificate_payment set charge_use = 20 where 1 = 1;
|
||||
|
||||
update pay_meeting set meeting_type = 5 ,case_committee_id = '1486586847797346305' ,case_committee_name = '全国汽车标准化技术委员会电动车辆分技术委员会' WHERE id = '1478574801809993729';
|
||||
update pay_working_group_subitem set make_invoice = 1 where id = '1484760196725768194';
|
||||
--合同变更
|
||||
alter TABLE pay_spending_contract ADD (phone VARCHAR(22) COMMENT '联系电话',address VARCHAR(255) COMMENT '邮寄地址',post_code VARCHAR(50) COMMENT '邮编');
|
||||
alter TABLE pay_mail_contract ADD (contract_type TINYINT(2) COMMENT '合同类型:1 支出合同,2 收入合同');
|
||||
INSERT INTO `sys_dict` VALUES ('1509830472616779778', '合同类型', 'contract_type', '(1:支出合同,2:收入合同)', 0, 'LKGLZ', '2022-04-01 17:50:11', 'LKGLZ', '2022-04-01 17:51:38', 0);
|
||||
INSERT INTO `sys_dict_item` VALUES ('1509830576870400001', '1509830472616779778', '支出合同', '1', '', 1.00, 1, 'LKGLZ', '2022-04-01 17:50:35', NULL, NULL);
|
||||
INSERT INTO `sys_dict_item` VALUES ('1509830618775691265', '1509830472616779778', '收入合同', '2', '', 1.00, 1, 'LKGLZ', '2022-04-01 17:50:45', NULL, NULL);
|
||||
|
||||
|
||||
-- 2022-4-8 导入工号
|
||||
|
||||
|
||||
+1
@@ -79,6 +79,7 @@ public class ShiroConfig {
|
||||
filterChainDefinitionMap.put("/sys/mLogin", "anon"); //登录接口排除
|
||||
filterChainDefinitionMap.put("/sys/logout", "anon"); //登出接口排除
|
||||
filterChainDefinitionMap.put("/sys/thirdLogin/**", "anon"); //第三方登录
|
||||
filterChainDefinitionMap.put("/sys/singleSignOn", "anon"); //单点登录
|
||||
filterChainDefinitionMap.put("/sys/getEncryptedString", "anon"); //获取加密串
|
||||
filterChainDefinitionMap.put("/sys/sms", "anon");//短信验证码
|
||||
filterChainDefinitionMap.put("/sys/phoneLogin", "anon");//手机登录
|
||||
|
||||
+9
-47
@@ -56,8 +56,6 @@ public class LoginController {
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Resource
|
||||
private BaseCommonService baseCommonService;
|
||||
@Resource
|
||||
@@ -160,7 +158,7 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
//用户登录信息
|
||||
userInfo(sysUser, result);
|
||||
sysUserService.userInfo(sysUser, result);
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
@@ -413,7 +411,7 @@ public class LoginController {
|
||||
return result;
|
||||
}
|
||||
//用户信息
|
||||
userInfo(sysUser, result);
|
||||
sysUserService.userInfo(sysUser, result);
|
||||
//添加日志
|
||||
baseCommonService.addLog("账号: " + sysUser.getUsername() + ",登录成功!", CommonConstant.LOG_TYPE_1, null);
|
||||
|
||||
@@ -421,50 +419,7 @@ public class LoginController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @param sysUser
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
|
||||
String syspassword = sysUser.getPassword();
|
||||
String username = sysUser.getUsername();
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(username, syspassword);
|
||||
// 设置token缓存有效时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
||||
|
||||
// 获取用户部门信息
|
||||
JSONObject obj = new JSONObject();
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
obj.put("departs", departs);
|
||||
if (departs == null || departs.size() == 0) {
|
||||
obj.put("multi_depart", 0);
|
||||
} else if (departs.size() == 1) {
|
||||
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
obj.put("multi_depart", 1);
|
||||
} else {
|
||||
//查询当前是否有登录部门
|
||||
// update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
SysUser sysUserById = sysUserService.getById(sysUser.getId());
|
||||
if (oConvertUtils.isEmpty(sysUserById.getOrgCode())) {
|
||||
sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
}
|
||||
// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
obj.put("multi_depart", 2);
|
||||
}
|
||||
sysUser.setPhone(PasswordUtil.decrypt(sysUser.getPhone()));
|
||||
sysUser.setEmail(PasswordUtil.decrypt(sysUser.getEmail()));
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", sysUser);
|
||||
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
|
||||
result.setResult(obj);
|
||||
result.success("登录成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加密字符串
|
||||
@@ -643,4 +598,11 @@ public class LoginController {
|
||||
//String string = redisUtil.get("_verification:_phone:" + phone).toString();
|
||||
return Result.OK();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "单点登录")
|
||||
@PostMapping(value = "/singleSignOn")
|
||||
public Result<?> singleSignOn(@RequestParam(name="code") String code) {
|
||||
return sysUserService.singleSignOn(code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-1
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
@@ -20,6 +21,7 @@ import com.jero.modules.system.model.SysLoginVO;
|
||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||
import com.jero.modules.system.vo.SysUserVo;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -263,6 +265,15 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
*/
|
||||
PayContactsManagement getPayContactsManagementByPhone(String phone);
|
||||
|
||||
//单点登录
|
||||
Result<JSONObject> singleSignOn(String code);
|
||||
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @param sysUser
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result);
|
||||
}
|
||||
|
||||
+138
-1
@@ -1,14 +1,19 @@
|
||||
package com.jero.modules.system.service.impl;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.util.JwtUtil;
|
||||
import com.jero.common.util.*;
|
||||
import com.jero.modules.pay.company.entity.PayContactsManagement;
|
||||
import com.jero.modules.system.model.SysLoginModel;
|
||||
import com.jero.modules.system.model.SysLoginVO;
|
||||
import com.jero.modules.system.service.*;
|
||||
import com.jero.modules.system.vo.SysUserVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.jero.common.api.vo.Result;
|
||||
@@ -21,7 +26,6 @@ import com.jero.common.system.vo.SysUserCacheInfo;
|
||||
import com.jero.modules.system.entity.*;
|
||||
import com.jero.modules.system.mapper.*;
|
||||
import com.jero.modules.system.model.SysUserSysDepartModel;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.system.vo.SysUserDepVo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -32,11 +36,14 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jero.modules.system.controller.LoginController.RETRY_LOGIN_PREFIX;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户表 服务实现类
|
||||
@@ -71,8 +78,20 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
private BaseCommonService baseCommonService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ISysDictService sysDictService;
|
||||
@Autowired
|
||||
private ISysDepartService sysDepartService;
|
||||
@Resource
|
||||
private ISysRoleService sysRoleService;
|
||||
@Resource
|
||||
private ISysUserRoleService sysUserRoleService;
|
||||
@Value("${defaultPassword}")
|
||||
private String defaultPassword;
|
||||
@Value("${singleSignON.client_id}")
|
||||
private String client_id;
|
||||
@Value("${singleSignON.client_secret}")
|
||||
private String client_secret;
|
||||
|
||||
@Override
|
||||
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
|
||||
@@ -620,6 +639,124 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
if(ObjectUtils.isEmpty(user.getVerifyPassword())){
|
||||
throw new JeroBootException("确认密码为必填");
|
||||
}
|
||||
}
|
||||
|
||||
//单点登录
|
||||
public Result<JSONObject> singleSignOn(String code){
|
||||
//根据授权码获取access_token
|
||||
HashMap<String, Object> tokenParam = new HashMap<>();
|
||||
tokenParam.put("client_id", client_id);
|
||||
tokenParam.put("client_secret", client_secret);
|
||||
tokenParam.put("code", code);
|
||||
tokenParam.put("grant_type", "authorization_code");
|
||||
|
||||
String tokenRes= HttpUtil.post("https://idmtest.catarc.ac.cn/bam-protocol-service/oauth2/getToken", tokenParam);
|
||||
JSONObject tokenJson = JSONObject.parseObject(tokenRes);
|
||||
String access_token = tokenJson.getString("access_token");
|
||||
|
||||
//根据access_token获取用户信息
|
||||
HashMap<String, Object> userInfoParam = new HashMap<>();
|
||||
userInfoParam.put("access_token", access_token);
|
||||
userInfoParam.put("client_id", client_id);
|
||||
|
||||
String userInfoRes= HttpUtil.get("https://idmtest.catarc.ac.cn/bam-protocol-service/oauth2/getUserInfo", userInfoParam);
|
||||
JSONObject userInfoJson = JSONObject.parseObject(userInfoRes);
|
||||
String loginName = userInfoJson.getString("loginName");
|
||||
|
||||
//根据工号登录
|
||||
return loginByUserNo(loginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据工号登录
|
||||
* @return
|
||||
*/
|
||||
public Result<JSONObject> loginByUserNo(String workNo) {
|
||||
Result<JSONObject> result = new Result<>();
|
||||
|
||||
//1. 校验用户是否有效
|
||||
//update-begin-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
LambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUser::getWorkNo, workNo);
|
||||
SysUser sysUser = getOne(queryWrapper);
|
||||
//update-end-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为false
|
||||
result= (Result<JSONObject>) checkUserIsEffective(sysUser);
|
||||
if (!result.isSuccess()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//用户登录信息
|
||||
userInfo(sysUser, result);
|
||||
//update-begin--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtils.copyProperties(sysUser, loginUser);
|
||||
// 新增用户角色code
|
||||
LambdaQueryWrapper<SysUserRole> querySysUserRole = new LambdaQueryWrapper();
|
||||
querySysUserRole.eq(SysUserRole::getUserId,sysUser.getId());
|
||||
List<SysUserRole> listSysUserRole = sysUserRoleService.list(querySysUserRole);
|
||||
if(!org.apache.commons.collections.CollectionUtils.isEmpty(listSysUserRole)){
|
||||
List<String> listStr = listSysUserRole.stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
|
||||
LambdaQueryWrapper<SysRole> querySysRole = new LambdaQueryWrapper();
|
||||
querySysRole.in(SysRole::getId,listStr);
|
||||
List<SysRole> listSysRole = sysRoleService.list(querySysRole);
|
||||
if(!org.apache.commons.collections.CollectionUtils.isEmpty(listSysRole)){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
listSysRole.forEach(p->{
|
||||
sb.append(p.getRoleCode());
|
||||
if(listSysRole.indexOf(p) != (listSysRole.size() - 1)){
|
||||
sb.append(",");
|
||||
}
|
||||
});
|
||||
loginUser.setRoleCode(sb.toString());
|
||||
}
|
||||
}
|
||||
baseCommonService.addLog("账号: " + sysUser.getUsername() + ",第三方登录成功!", CommonConstant.LOG_TYPE_1, null, loginUser);
|
||||
//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
*
|
||||
* @param sysUser
|
||||
* @param result
|
||||
* @return
|
||||
*/
|
||||
public Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
|
||||
String syspassword = sysUser.getPassword();
|
||||
String username = sysUser.getUsername();
|
||||
// 生成token
|
||||
String token = JwtUtil.sign(username, syspassword);
|
||||
// 设置token缓存有效时间
|
||||
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);
|
||||
|
||||
// 获取用户部门信息
|
||||
JSONObject obj = new JSONObject();
|
||||
List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
||||
obj.put("departs", departs);
|
||||
if (departs == null || departs.size() == 0) {
|
||||
obj.put("multi_depart", 0);
|
||||
} else if (departs.size() == 1) {
|
||||
updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
obj.put("multi_depart", 1);
|
||||
} else {
|
||||
//查询当前是否有登录部门
|
||||
// update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
SysUser sysUserById = getById(sysUser.getId());
|
||||
if (oConvertUtils.isEmpty(sysUserById.getOrgCode())) {
|
||||
updateUserDepart(username, departs.get(0).getOrgCode());
|
||||
}
|
||||
// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去
|
||||
obj.put("multi_depart", 2);
|
||||
}
|
||||
sysUser.setPhone(PasswordUtil.decrypt(sysUser.getPhone()));
|
||||
sysUser.setEmail(PasswordUtil.decrypt(sysUser.getEmail()));
|
||||
obj.put("token", token);
|
||||
obj.put("userInfo", sysUser);
|
||||
obj.put("sysAllDictItems", sysDictService.queryAllDictItems());
|
||||
result.setResult(obj);
|
||||
result.success("登录成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,3 +332,8 @@ message:
|
||||
wxName: '小程序名称'
|
||||
# 消息模板替换,报名url
|
||||
openPage: http://localhost:3000/signUpEntrance?id
|
||||
|
||||
#单点登录
|
||||
singleSignON:
|
||||
client_id: cwp
|
||||
client_secret: f9dfaeb910f247608f771e2418478
|
||||
|
||||
Reference in New Issue
Block a user