mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-02-05 01:55:29 +08:00
v3.7.2 版本代码合并
This commit is contained in:
@ -5,12 +5,15 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.jeecg.common.api.dto.message.MessageDTO;
|
||||
import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.enums.MessageTypeEnum;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.config.StaticConfig;
|
||||
import org.jeecg.modules.message.entity.SysMessage;
|
||||
import org.jeecg.modules.message.handle.ISendMsgHandle;
|
||||
import org.jeecg.modules.message.mapper.SysMessageMapper;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.mapper.SysUserMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -43,6 +46,9 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@Autowired
|
||||
private SysMessageMapper sysMessageMapper;
|
||||
|
||||
/**
|
||||
* 真实姓名变量
|
||||
@ -78,6 +84,23 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
@Override
|
||||
public void sendMessage(MessageDTO messageDTO) {
|
||||
String content = messageDTO.getContent();
|
||||
String title = messageDTO.getTitle();
|
||||
//update-begin---author:wangshuai---date:2024-11-20---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
boolean timeJobSendEmail = this.isTimeJobSendEmail(messageDTO.getToUser(), title, content);
|
||||
if(timeJobSendEmail){
|
||||
return;
|
||||
}
|
||||
//update-end---author:wangshuai---date:2024-11-20---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
this.sendEmailMessage(messageDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接发送邮件
|
||||
*
|
||||
* @param messageDTO
|
||||
*/
|
||||
public void sendEmailMessage(MessageDTO messageDTO) {
|
||||
String[] arr = messageDTO.getToUser().split(",");
|
||||
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<SysUser>().in(SysUser::getUsername, arr);
|
||||
List<SysUser> list = sysUserMapper.selectList(query);
|
||||
@ -213,4 +236,35 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 1 / 1000);
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否定时发送邮箱
|
||||
* @param toUser
|
||||
* @param title
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
private boolean isTimeJobSendEmail(String toUser, String title, String content) {
|
||||
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
|
||||
Boolean timeJobSend = staticConfig.getTimeJobSend();
|
||||
if(null != timeJobSend && timeJobSend){
|
||||
this.addSysSmsSend(toUser,title,content);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到短信发送表
|
||||
*/
|
||||
private void addSysSmsSend(String toUser, String title, String content) {
|
||||
SysMessage sysMessage = new SysMessage();
|
||||
sysMessage.setEsTitle(title);
|
||||
sysMessage.setEsContent(content);
|
||||
sysMessage.setEsReceiver(toUser);
|
||||
sysMessage.setEsSendStatus("0");
|
||||
sysMessage.setEsSendNum(0);
|
||||
sysMessage.setEsType(MessageTypeEnum.YJ.getType());
|
||||
sysMessageMapper.insert(sysMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,6 +51,9 @@ public class SendMsgJob implements Job {
|
||||
md.setToUser(sysMessage.getEsReceiver());
|
||||
md.setType(sysMessage.getEsType());
|
||||
md.setToAll(false);
|
||||
//update-begin---author:wangshuai---date:2024-11-12---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
md.setIsTimeJob(true);
|
||||
//update-end---author:wangshuai---date:2024-11-12---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
sysBaseAPI.sendTemplateMessage(md);
|
||||
//发送消息成功
|
||||
sysMessage.setEsSendStatus(SendMsgStatusEnum.SUCCESS.getCode());
|
||||
|
||||
@ -18,7 +18,7 @@ import static org.springframework.boot.actuate.endpoint.annotation.Selector.Matc
|
||||
* @Date: 2024/5/13 17:02
|
||||
*/
|
||||
@Component
|
||||
@Endpoint(id = "httptrace-new")
|
||||
@Endpoint(id = "jeecghttptrace")
|
||||
public class CustomHttpTraceEndpoint{
|
||||
private final CustomInMemoryHttpTraceRepository repository;
|
||||
|
||||
|
||||
@ -1276,12 +1276,6 @@ public class SysUserController {
|
||||
updateUser.setUpdateBy(JwtUtil.getUserNameByToken(request));
|
||||
updateUser.setUpdateTime(new Date());
|
||||
sysUserService.revertLogicDeleted(Arrays.asList(userIds.split(",")), updateUser);
|
||||
// 用户变更,触发同步工作流
|
||||
List<String> userNameList = sysUserService.userIdToUsername(Arrays.asList(userIds.split(",")));
|
||||
if (!userNameList.isEmpty()) {
|
||||
String joinedString = String.join(",", userNameList);
|
||||
}
|
||||
|
||||
}
|
||||
return Result.ok("还原成功");
|
||||
}
|
||||
|
||||
@ -557,4 +557,64 @@ public class ThirdLoginController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新版钉钉登录
|
||||
*
|
||||
* @param authCode
|
||||
* @param state
|
||||
* @param tenantId
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/oauth2/dingding/login")
|
||||
public String OauthDingDingLogin(@RequestParam(value = "authCode", required = false) String authCode,
|
||||
@RequestParam("state") String state,
|
||||
@RequestParam(name = "tenantId",defaultValue = "0") String tenantId,
|
||||
HttpServletResponse response) {
|
||||
SysUser loginUser = thirdAppDingtalkService.oauthDingDingLogin(authCode,Integer.valueOf(tenantId));
|
||||
try {
|
||||
String redirect = "";
|
||||
if (state.indexOf("?") > 0) {
|
||||
String[] arr = state.split("\\?");
|
||||
state = arr[0];
|
||||
if(arr.length>1){
|
||||
redirect = arr[1];
|
||||
}
|
||||
}
|
||||
String token = saveToken(loginUser);
|
||||
state += "/oauth2-app/login?oauth2LoginToken=" + URLEncoder.encode(token, "UTF-8") + "&tenantId=" + URLEncoder.encode(tenantId, "UTF-8");
|
||||
state += "&thirdType=DINGTALK";
|
||||
if (redirect != null && redirect.length() > 0) {
|
||||
state += "&" + redirect;
|
||||
}
|
||||
log.info("OAuth2登录重定向地址: " + state);
|
||||
try {
|
||||
response.sendRedirect(state);
|
||||
return "ok";
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return "重定向失败";
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return "解码失败";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业id和应用id
|
||||
* @param tenantId
|
||||
* @return
|
||||
*/
|
||||
@ResponseBody
|
||||
@GetMapping("/get/corpId/clientId")
|
||||
public Result<SysThirdAppConfig> getCorpIdClientId(@RequestParam(value = "tenantId", defaultValue = "0") String tenantId){
|
||||
Result<SysThirdAppConfig> result = new Result<>();
|
||||
SysThirdAppConfig sysThirdAppConfig = thirdAppDingtalkService.getCorpIdClientId(Integer.valueOf(tenantId));
|
||||
result.setSuccess(true);
|
||||
result.setResult(sysThirdAppConfig);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -51,10 +51,10 @@ public class SysThirdAppConfig {
|
||||
@ApiModelProperty(value = "钉钉/企业微信应用id对应的秘钥")
|
||||
private String clientSecret;
|
||||
|
||||
/**企业微信自建应用Secret*/
|
||||
@Excel(name = "企业微信自建应用Secret", width = 15)
|
||||
@ApiModelProperty(value = "企业微信自建应用Secret")
|
||||
private String agentAppSecret;
|
||||
/**钉钉企业id*/
|
||||
@Excel(name = "钉钉企业id", width = 15)
|
||||
@ApiModelProperty(value = "钉钉企业id")
|
||||
private String corpId;
|
||||
|
||||
/**第三方类别(dingtalk 钉钉 wechat_enterprise 企业微信)*/
|
||||
@Excel(name = "第三方类别(dingtalk 钉钉 wechat_enterprise 企业微信)", width = 15)
|
||||
|
||||
@ -443,4 +443,19 @@ public interface ISysUserService extends IService<SysUser> {
|
||||
* @param ipAddress ip地址
|
||||
*/
|
||||
void sendChangePhoneSms(JSONObject jsonObject, String username, String ipAddress);
|
||||
|
||||
/**
|
||||
* 发送注销用户手机号验证密码[敲敲云专用]
|
||||
* @param jsonObject
|
||||
* @param username
|
||||
* @param ipAddress
|
||||
*/
|
||||
void sendLogOffPhoneSms(JSONObject jsonObject, String username, String ipAddress);
|
||||
|
||||
/**
|
||||
* 用户注销[敲敲云专用]
|
||||
* @param jsonObject
|
||||
* @param username
|
||||
*/
|
||||
void userLogOff(JSONObject jsonObject, String username);
|
||||
}
|
||||
|
||||
@ -1597,7 +1597,13 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
// 邮件消息要解析Markdown
|
||||
message.setContent(HTMLUtils.parseMarkdown(message.getContent()));
|
||||
}
|
||||
emailSendMsgHandle.sendMessage(message);
|
||||
//update-begin---author:wangshuai---date:2024-11-20---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
if(message.getIsTimeJob() != null && message.getIsTimeJob()){
|
||||
emailSendMsgHandle.sendEmailMessage(message);
|
||||
}else{
|
||||
emailSendMsgHandle.sendMessage(message);
|
||||
}
|
||||
//update-end---author:wangshuai---date:2024-11-20---for:【QQYUN-8523】敲敲云发邮件通知,不稳定---
|
||||
}else if(MessageTypeEnum.DD.getType().equals(messageType)){
|
||||
ddSendMsgHandle.sendMessage(message);
|
||||
}else if(MessageTypeEnum.QYWX.getType().equals(messageType)){
|
||||
|
||||
@ -1978,15 +1978,50 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
}
|
||||
}
|
||||
//step4 发送短信验证码
|
||||
this.sendPhoneSms(phone, ipAddress);
|
||||
String redisKey = CommonConstant.CHANGE_PHONE_REDIS_KEY_PRE+phone;
|
||||
this.sendPhoneSms(phone, ipAddress,redisKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendLogOffPhoneSms(JSONObject jsonObject, String username, String ipAddress) {
|
||||
String phone = jsonObject.getString("phone");
|
||||
//通过用户名查询数据库中的手机号
|
||||
SysUser userByNameAndPhone = userMapper.getUserByNameAndPhone(phone, username);
|
||||
if (null == userByNameAndPhone) {
|
||||
throw new JeecgBootException("当前用户手机号不匹配,无法修改!");
|
||||
}
|
||||
String code = CommonConstant.LOG_OFF_PHONE_REDIS_KEY_PRE + phone;
|
||||
this.sendPhoneSms(phone, ipAddress, code);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void userLogOff(JSONObject jsonObject, String username) {
|
||||
String phone = jsonObject.getString("phone");
|
||||
String smsCode = jsonObject.getString("smscode");
|
||||
//通过用户名查询数据库中的手机号
|
||||
SysUser userByNameAndPhone = userMapper.getUserByNameAndPhone(phone, username);
|
||||
if (null == userByNameAndPhone) {
|
||||
throw new JeecgBootException("当前用户手机号不匹配,无法注销!");
|
||||
}
|
||||
String code = CommonConstant.LOG_OFF_PHONE_REDIS_KEY_PRE + phone;
|
||||
Object redisSmdCode = redisUtil.get(code);
|
||||
if (null == redisSmdCode) {
|
||||
throw new JeecgBootException("验证码失效,无法注销!");
|
||||
}
|
||||
if (!redisSmdCode.toString().equals(smsCode)) {
|
||||
throw new JeecgBootException("验证码不匹配,无法注销!");
|
||||
}
|
||||
this.deleteUser(userByNameAndPhone.getId());
|
||||
redisUtil.removeAll(code);
|
||||
redisUtil.removeAll(CacheConstant.SYS_USERS_CACHE + phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送短信验证码
|
||||
* @param phone
|
||||
*/
|
||||
private void sendPhoneSms(String phone, String clientIp) {
|
||||
String redisKey = CommonConstant.CHANGE_PHONE_REDIS_KEY_PRE+phone;
|
||||
private void sendPhoneSms(String phone, String clientIp,String redisKey) {
|
||||
Object object = redisUtil.get(redisKey);
|
||||
|
||||
if (object != null) {
|
||||
|
||||
@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.jeecg.dingtalk.api.base.JdtBaseAPI;
|
||||
import com.jeecg.dingtalk.api.core.response.Response;
|
||||
import com.jeecg.dingtalk.api.core.util.HttpUtil;
|
||||
import com.jeecg.dingtalk.api.core.vo.AccessToken;
|
||||
import com.jeecg.dingtalk.api.core.vo.PageResult;
|
||||
import com.jeecg.dingtalk.api.department.JdtDepartmentAPI;
|
||||
@ -46,10 +47,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@ -1254,4 +1252,57 @@ public class ThirdAppDingtalkServiceImpl implements IThirdAppService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//=================================== begin 新版钉钉登录 ============================================
|
||||
/**
|
||||
* 钉钉登录获取用户信息
|
||||
* 【QQYUN-9421】钉钉登录后打开了敲敲云,换其他账号登录后,再打开敲敲云显示的是原来账号的应用
|
||||
* @param authCode
|
||||
* @param tenantId
|
||||
* @return
|
||||
*/
|
||||
public SysUser oauthDingDingLogin(String authCode, Integer tenantId) {
|
||||
Long count = tenantMapper.tenantIzExist(tenantId);
|
||||
if(ObjectUtil.isEmpty(count) || 0 == count){
|
||||
throw new JeecgBootException("租户不存在!");
|
||||
}
|
||||
SysThirdAppConfig config = configMapper.getThirdConfigByThirdType(tenantId, MessageTypeEnum.DD.getType());
|
||||
String accessToken = this.getTenantAccessToken(config);
|
||||
if(StringUtils.isEmpty(accessToken)){
|
||||
throw new JeecgBootBizTipException("accessToken获取失败");
|
||||
}
|
||||
String getUserInfoUrl = "https://oapi.dingtalk.com/topapi/v2/user/getuserinfo?access_token=" + accessToken;
|
||||
Map<String,String> params = new HashMap<>();
|
||||
params.put("code",authCode);
|
||||
Response<JSONObject> userInfoResponse = HttpUtil.post(getUserInfoUrl, JSON.toJSONString(params));
|
||||
if (userInfoResponse.isSuccess()) {
|
||||
String userId = userInfoResponse.getResult().getString("userid");
|
||||
// 判断第三方用户表有没有这个人
|
||||
LambdaQueryWrapper<SysThirdAccount> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysThirdAccount::getThirdType, THIRD_TYPE);
|
||||
queryWrapper.eq(SysThirdAccount::getTenantId, tenantId);
|
||||
queryWrapper.and((wrapper)->wrapper.eq(SysThirdAccount::getThirdUserUuid,userId).or().eq(SysThirdAccount::getThirdUserId,userId));
|
||||
SysThirdAccount thirdAccount = sysThirdAccountService.getOne(queryWrapper);
|
||||
if (thirdAccount != null) {
|
||||
return this.getSysUserByThird(thirdAccount, null, userId, accessToken, tenantId);
|
||||
}else{
|
||||
throw new JeecgBootException("该用户没有同步,请先同步!");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户id获取企业id和应用id
|
||||
* 【QQYUN-9421】钉钉登录后打开了敲敲云,换其他账号登录后,再打开敲敲云显示的是原来账号的应用
|
||||
* @param tenantId
|
||||
*/
|
||||
public SysThirdAppConfig getCorpIdClientId(Integer tenantId) {
|
||||
LambdaQueryWrapper<SysThirdAppConfig> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysThirdAppConfig::getThirdType, THIRD_TYPE);
|
||||
queryWrapper.eq(SysThirdAppConfig::getTenantId, tenantId);
|
||||
queryWrapper.select(SysThirdAppConfig::getCorpId,SysThirdAppConfig::getClientId);
|
||||
return configMapper.selectOne(queryWrapper);
|
||||
}
|
||||
//=================================== end 新版钉钉登录 ============================================
|
||||
}
|
||||
@ -119,12 +119,9 @@ public class ThirdAppWechatEnterpriseServiceImpl implements IThirdAppService {
|
||||
public String getAppAccessToken(SysThirdAppConfig config) {
|
||||
//update-begin---author:wangshuai ---date:20230224 for:[QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
||||
String corpId = config.getClientId();
|
||||
String secret = config.getAgentAppSecret();
|
||||
// 如果没有配置APP秘钥,就说明是老企业,可以通用秘钥
|
||||
if (oConvertUtils.isEmpty(secret)) {
|
||||
secret = config.getClientSecret();
|
||||
String secret = config.getClientSecret();
|
||||
//update-end---author:wangshuai ---date:20230224 for:[QQYUN-3440]新建企业微信和钉钉配置表,通过租户模式隔离------------
|
||||
}
|
||||
|
||||
AccessToken accessToken = JwAccessTokenAPI.getAccessToken(corpId, secret);
|
||||
if (accessToken != null) {
|
||||
|
||||
Reference in New Issue
Block a user