|
|
|
@ -5,6 +5,7 @@ import cn.estsh.i3plus.core.api.iservice.base.ISystemInitService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.base.ISystemLoginStrategyService;
|
|
|
|
|
import cn.estsh.i3plus.core.api.iservice.busi.*;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.controller.busi.*;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.util.MailUtil;
|
|
|
|
|
import cn.estsh.i3plus.core.apiservice.util.SysUserPasswordUtil;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
@ -15,76 +16,66 @@ import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.annotation.AnnoIgnoreLog;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.BaseThreadLocal;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.ListPager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.common.Pager;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.common.CloudPagerModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.common.ImppEmail;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.common.ImppSmsContent;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.common.UserModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.license.ImppLicense;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.SysLoginModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.SysRoleModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.model.platform.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.sdk.dingtalk.cn.estsh.i3plus.sdk.service.IDingTalkService;
|
|
|
|
|
import cn.estsh.i3plus.sdk.dingtalk.dingrobot.DingRobotRequestBody;
|
|
|
|
|
import cn.estsh.i3plus.sdk.dingtalk.service.IDingTalkService;
|
|
|
|
|
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
|
|
|
|
|
import cn.estsh.impp.framework.boot.license.ImppLicenseTool;
|
|
|
|
|
import cn.estsh.impp.framework.boot.license.serviceimpl.ImppLicenseDecoder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ImppRedis;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.LocaleUtils;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.RedisCacheTool;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ResultBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.*;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest;
|
|
|
|
|
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
|
|
|
|
|
import com.aliyun.dingtalkrobot_1_0.models.BatchSendOTOHeaders;
|
|
|
|
|
import com.aliyun.dingtalkrobot_1_0.models.BatchSendOTORequest;
|
|
|
|
|
import com.aliyun.dingtalkrobot_1_0.models.BatchSendOTOResponse;
|
|
|
|
|
import com.aliyun.tea.TeaException;
|
|
|
|
|
import com.aliyun.teaopenapi.models.Config;
|
|
|
|
|
import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
|
|
import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
|
|
|
|
|
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
|
|
|
|
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
|
|
|
|
|
import com.google.common.cache.Cache;
|
|
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
|
|
import com.taobao.api.ApiException;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.shiro.authc.AuthenticationException;
|
|
|
|
|
import org.apache.shiro.authc.CredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.ExpiredCredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.IncorrectCredentialsException;
|
|
|
|
|
import org.apache.shiro.authc.LockedAccountException;
|
|
|
|
|
import org.apache.shiro.authc.UnknownAccountException;
|
|
|
|
|
import org.apache.shiro.authc.*;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.function.BiFunction;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Description :
|
|
|
|
@ -107,6 +98,9 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
private SysUserInfoController sysUserInfoController;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISysLocaleLanguageService sysLocaleLanguageService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@ -338,6 +332,7 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
return ResultBean.success("查询成功").setResultList(menuList);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping(value = "/auth/dingtalk/login")
|
|
|
|
|
@ApiOperation(value = "登录", notes = "登录")
|
|
|
|
|
public ResultBean loginByPhoneNumber(HttpServletRequest request, String dingTalkTmpAuthCode,
|
|
|
|
@ -440,7 +435,7 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
if (e.getCause() instanceof ImppBusiException) {
|
|
|
|
|
ImppBusiException imppBusiException = (ImppBusiException) e.getCause();
|
|
|
|
|
result.setErrorMsg(LocaleUtils.getLocaleRes(imppBusiException.getErrorDetail()));
|
|
|
|
|
}else {
|
|
|
|
|
} else {
|
|
|
|
|
result.setErrorMsg(e.getCause().getMessage());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -458,8 +453,8 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
|
|
|
|
|
LOGGER.warn("Impp业务异常Exception 登录失败 ", e);
|
|
|
|
|
} finally {
|
|
|
|
|
if (result != null && !result.isSuccess() ){
|
|
|
|
|
if(CommonEnumUtil.USER_LOGIN_STATUS.LOGIN_SUCCESS.getValue() == userLoginStatus.getValue()){
|
|
|
|
|
if (result != null && !result.isSuccess()) {
|
|
|
|
|
if (CommonEnumUtil.USER_LOGIN_STATUS.LOGIN_SUCCESS.getValue() == userLoginStatus.getValue()) {
|
|
|
|
|
userLoginStatus = CommonEnumUtil.USER_LOGIN_STATUS.SYSTEM_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -467,7 +462,7 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
recordSysUserLog(null, loginModel.getLoginName(), userLoginStatus.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOGGER.info("会员{}登陆登录完成,登录{},语言:{} , 登录耗时:{}", loginModel.getLoginName(),result.isSuccess()? "成功":"失败", BaseThreadLocal.getThreadLanguageCode(), (System.currentTimeMillis() - startTime));
|
|
|
|
|
LOGGER.info("会员{}登陆登录完成,登录{},语言:{} , 登录耗时:{}", loginModel.getLoginName(), result.isSuccess() ? "成功" : "失败", BaseThreadLocal.getThreadLanguageCode(), (System.currentTimeMillis() - startTime));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -727,6 +722,12 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
Arrays.asList(CommonEnumUtil.LOG_LOGIN_PLATFORM.values()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/sys-auth-platform")
|
|
|
|
|
@ApiOperation(value = "登录授权标识", notes = "登录授权标识")
|
|
|
|
|
public ResultBean getAuthPlatform() {
|
|
|
|
|
return new ResultBean(true, "操作成功",
|
|
|
|
|
Arrays.asList(CommonEnumUtil.AUTH_PLATFORM.values()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/sys-organize/list")
|
|
|
|
|
@ApiOperation(value = "获取全部组织", notes = "获取全部组织")
|
|
|
|
@ -966,10 +967,60 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
return sysUserInfoController.querySysUserInfo(cloudPagerModel.getObj(), cloudPagerModel.getPager());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据登录名,邮箱获取用户账号信息
|
|
|
|
|
*
|
|
|
|
|
* @param sysUser
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping(value = "/user/query-user")
|
|
|
|
|
@ApiOperation(value = "根据条件查询单个用户信息", notes = "根据条件查询单个用户信息")
|
|
|
|
|
public ResultBean querySysUser(@RequestBody SysUser sysUser) {
|
|
|
|
|
ValidatorBean.checkNotNull(sysUser.getUserLoginName(), "用户登录名不能为空!");
|
|
|
|
|
ValidatorBean.checkNotNull(sysUser.getUserEmail(), "用户email不能为空!");
|
|
|
|
|
SysUser user = null;
|
|
|
|
|
try {
|
|
|
|
|
user = sysUserService.getSysUserByLoginNameAndEmail(sysUser.getUserLoginName(), sysUser.getUserEmail());
|
|
|
|
|
} catch (ImppBusiException e) {
|
|
|
|
|
return ResultBean.fail(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success("查询成功!").setResultObject(user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/sendEmail")
|
|
|
|
|
@ApiOperation(value = "无需登录,发送邮件")
|
|
|
|
|
public ResultBean sendEmail(@RequestBody ImppEmail imppEmail) {
|
|
|
|
|
ValidatorBean.checkNotNull(imppEmail.getContent(), "消息内容不能为空");
|
|
|
|
|
ValidatorBean.checkNotNull(imppEmail.getEmail(), "email地址不能为空");
|
|
|
|
|
try {
|
|
|
|
|
MailUtil mailUtil = new MailUtil();
|
|
|
|
|
mailUtil.init();
|
|
|
|
|
mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.HTML.getDescription());
|
|
|
|
|
mailUtil.setNick(imppEmail.getNick());
|
|
|
|
|
mailUtil.setSubject(imppEmail.getSubject());
|
|
|
|
|
mailUtil.setTo(imppEmail.getEmail());
|
|
|
|
|
mailUtil.setBody(imppEmail.getContent());
|
|
|
|
|
mailUtil.send();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("发送邮件:{}失败:{}", imppEmail.getEmail(), e.getMessage());
|
|
|
|
|
return ResultBean.fail("发送失败,请检查邮箱是否输入正确!");
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success("验证码已发送!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "/update-vendor-pwd")
|
|
|
|
|
@ApiOperation(value = "忘记密码")
|
|
|
|
|
public ResultBean updateVendorPwd(@RequestBody UserModel userModel) {
|
|
|
|
|
ValidatorBean.checkNotNull(userModel.getLoginName(), "登录名不能为空!");
|
|
|
|
|
ValidatorBean.checkNotNull(userModel.getPassword(), "密码不能为空!");
|
|
|
|
|
sysUserService.updateSysUserPwdByLoginName(userModel.getLoginName(), userModel.getPassword());
|
|
|
|
|
return ResultBean.success("修改成功!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/sendSms")
|
|
|
|
|
@ApiOperation("无需登录 发送短信")
|
|
|
|
|
public ResultBean sendSms(@RequestBody ImppSmsContent imppSmsContent){
|
|
|
|
|
return smsSendRecordController.send(imppSmsContent);
|
|
|
|
|
public ResultBean sendSms(@RequestBody ImppSmsContent imppSmsContent) {
|
|
|
|
|
return smsSendRecordController.send(imppSmsContent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -989,8 +1040,8 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
}
|
|
|
|
|
//过滤SysRefUserRole
|
|
|
|
|
roleList = sysRoleService.findAllByRoleProperty(sysRole);
|
|
|
|
|
if (ObjectUtils.isEmpty(roleList)){
|
|
|
|
|
return ResultBean.success("操作成功");
|
|
|
|
|
if (ObjectUtils.isEmpty(roleList)) {
|
|
|
|
|
return ResultBean.success("操作成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> roleIdList = roleList.stream().map(el -> el.getId()).collect(Collectors.toList());
|
|
|
|
@ -1007,13 +1058,186 @@ public class WhiteController extends CoreBaseController {
|
|
|
|
|
* 根据登录的用户名批量修改账号状态
|
|
|
|
|
*
|
|
|
|
|
* @param userLoginNames 用户名数组
|
|
|
|
|
* @param status 状态
|
|
|
|
|
* @param status 状态
|
|
|
|
|
* @return 处理结果
|
|
|
|
|
*/
|
|
|
|
|
@PutMapping(value = "/batch-status/userLoginNames")
|
|
|
|
|
@ApiOperation(value = "根据用户名批量修改账号状态", notes = "根据用户名批量修改账号状态")
|
|
|
|
|
public ResultBean updateBatchStatusByUserLoginNames(String[] userLoginNames, Integer status) {
|
|
|
|
|
return sysUserController.updateBatchStatusByUserLoginNames(userLoginNames,status);
|
|
|
|
|
return sysUserController.updateBatchStatusByUserLoginNames(userLoginNames, status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Long ACCESS_TOKEN_EXPIRE_TIME = 7080L;
|
|
|
|
|
private static final String ACCESS_TOKEN_KEY = "ding_talk:access_token";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 钉钉单聊机器人批量发送消息
|
|
|
|
|
* @param dingSendBatchRequestModel
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@PostMapping(value = "/dingRobot/sendBatchRequest")
|
|
|
|
|
@ApiOperation(value = "根据手机号 钉钉单聊机器人批量发送消息", notes = "根据手机号 钉钉单聊机器人批量发送消息")
|
|
|
|
|
public ResultBean singleRobotsendBatchRequest(@RequestBody DingSendBatchRequestModel dingSendBatchRequestModel ) {
|
|
|
|
|
if(ObjectUtils.isEmpty(dingSendBatchRequestModel)){
|
|
|
|
|
return ResultBean.fail("消息内容不能为空");
|
|
|
|
|
}
|
|
|
|
|
List<String> phoneNumberList = dingSendBatchRequestModel.getPhoneNumberList();
|
|
|
|
|
String title = dingSendBatchRequestModel.getTitle();
|
|
|
|
|
String content = dingSendBatchRequestModel.getContent();
|
|
|
|
|
if (StringUtils.isBlank(content)) {
|
|
|
|
|
return ResultBean.fail("消息内容不能为空");
|
|
|
|
|
}
|
|
|
|
|
if (ObjectUtils.isEmpty(phoneNumberList)) {
|
|
|
|
|
return ResultBean.fail("手机号不能为空");
|
|
|
|
|
}
|
|
|
|
|
phoneNumberList = phoneNumberList.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
|
|
if (ObjectUtils.isEmpty(phoneNumberList)) {
|
|
|
|
|
return ResultBean.fail("手机号不能为空");
|
|
|
|
|
}
|
|
|
|
|
Config config = new Config();
|
|
|
|
|
config.protocol = "https";
|
|
|
|
|
config.regionId = "central";
|
|
|
|
|
com.aliyun.dingtalkrobot_1_0.Client client = null;
|
|
|
|
|
try {
|
|
|
|
|
client = new com.aliyun.dingtalkrobot_1_0.Client(config);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ResultBean.fail(e).setMsg("发送失败");
|
|
|
|
|
}
|
|
|
|
|
BatchSendOTOHeaders batchSendOTOHeaders = new BatchSendOTOHeaders();
|
|
|
|
|
batchSendOTOHeaders.xAcsDingtalkAccessToken = getAccessToken();
|
|
|
|
|
BatchSendOTORequest batchSendOTORequest = new BatchSendOTORequest();
|
|
|
|
|
List<String> userIdList = new ArrayList<String>();
|
|
|
|
|
phoneNumberList.forEach(el -> {
|
|
|
|
|
ResultBean result = getDingUserIdByPhoneNumber(el, batchSendOTOHeaders.xAcsDingtalkAccessToken);
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
|
userIdList.add((String) result.getResultObject());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
if (userIdList.isEmpty()) {
|
|
|
|
|
return ResultBean.fail("发送失败,无法根据手机号获取用户id");
|
|
|
|
|
}
|
|
|
|
|
// userIdList.add("27202755621041923");
|
|
|
|
|
// userIdList.add("070537336424114523");
|
|
|
|
|
|
|
|
|
|
String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
batchSendOTORequest.setRobotCode(dingTalkAppKey);
|
|
|
|
|
batchSendOTORequest.setUserIds(userIdList);
|
|
|
|
|
// markdown officialImageMsg
|
|
|
|
|
DingRobotRequestBody requestBody = generateMarkdown(title, content);
|
|
|
|
|
batchSendOTORequest.setMsgKey("sampleMarkdown");
|
|
|
|
|
batchSendOTORequest.setMsgParam(JSON.toJSONString(requestBody.getMarkdown()));
|
|
|
|
|
try {
|
|
|
|
|
BatchSendOTOResponse response = client.batchSendOTOWithOptions(batchSendOTORequest, batchSendOTOHeaders, new RuntimeOptions());
|
|
|
|
|
System.out.println(JSON.toJSONString(response));
|
|
|
|
|
} catch (TeaException err) {
|
|
|
|
|
err.printStackTrace();
|
|
|
|
|
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.fail(err).setMsg("发送失败");
|
|
|
|
|
|
|
|
|
|
} catch (Exception _err) {
|
|
|
|
|
_err.printStackTrace();
|
|
|
|
|
TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.fail(err).setMsg("发送失败");
|
|
|
|
|
}
|
|
|
|
|
return ResultBean.success("发送成功");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DingRobotRequestBody generateMarkdown(String title, String content) {
|
|
|
|
|
DingRobotRequestBody dingRobotRequestBody = new DingRobotRequestBody();
|
|
|
|
|
DingRobotRequestBody.MarkDown markDown = new DingRobotRequestBody.MarkDown();
|
|
|
|
|
markDown.setTitle(title);
|
|
|
|
|
dingRobotRequestBody.setMsgType("markdown");
|
|
|
|
|
// markDown.setText(" # Andon 通知" +
|
|
|
|
|
// "\n"+
|
|
|
|
|
// "\n"+
|
|
|
|
|
// " [](https://imgtu.com/i/qGTEi6) EP产线-01工位,物料缺料,请及时处理 "
|
|
|
|
|
// );
|
|
|
|
|
// markDown.setText(" # Andon 通知" +
|
|
|
|
|
// "\n"+
|
|
|
|
|
// "\n"+
|
|
|
|
|
// " [](https://imgtu.com/i/qGTEi6) EP产线-01工位,物料缺料,请及时处理 "
|
|
|
|
|
// );
|
|
|
|
|
// markDown.setText(" ## Andon 通知" +
|
|
|
|
|
// "\n"+
|
|
|
|
|
// "\n"+
|
|
|
|
|
// " [](https://imgtu.com/i/qGTEi6) EP产线-01工位,物料缺料,处理措施:联络供应商送货"
|
|
|
|
|
// );
|
|
|
|
|
markDown.setText(content);
|
|
|
|
|
dingRobotRequestBody.setMarkDown(markDown);
|
|
|
|
|
return dingRobotRequestBody;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据手机号获取钉钉的uid
|
|
|
|
|
*
|
|
|
|
|
* @param phoneNumber
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public ResultBean getDingUserIdByPhoneNumber(String phoneNumber, String accessToken) {
|
|
|
|
|
try {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getbymobile");
|
|
|
|
|
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
|
|
|
|
|
req.setMobile(phoneNumber);
|
|
|
|
|
// req.setMobile("13298408382");
|
|
|
|
|
OapiV2UserGetbymobileResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
return ResultBean.success("获取用户id成功").setResultObject(rsp.getResult().getUserid());
|
|
|
|
|
} catch (ApiException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取accessToken
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String getAccessToken() {
|
|
|
|
|
Object accessTokenCached = redisCore.getObject(ACCESS_TOKEN_KEY);
|
|
|
|
|
if (accessTokenCached != null) {
|
|
|
|
|
return String.valueOf(accessTokenCached);
|
|
|
|
|
}
|
|
|
|
|
Config config = new Config();
|
|
|
|
|
config.protocol = "https";
|
|
|
|
|
config.regionId = "central";
|
|
|
|
|
com.aliyun.dingtalkoauth2_1_0.Client client = null;
|
|
|
|
|
String dingTalkAppKey = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_KEY);
|
|
|
|
|
String dingTalkAppSecret = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.DINGTALK_APP_SECRET);
|
|
|
|
|
try {
|
|
|
|
|
client = new com.aliyun.dingtalkoauth2_1_0.Client(config);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
GetAccessTokenRequest getAccessTokenRequest = new GetAccessTokenRequest()
|
|
|
|
|
.setAppKey(dingTalkAppKey)
|
|
|
|
|
.setAppSecret(dingTalkAppSecret);
|
|
|
|
|
try {
|
|
|
|
|
GetAccessTokenResponse response = client.getAccessToken(getAccessTokenRequest);
|
|
|
|
|
if (!StringUtils.isEmpty(response.body.accessToken)) {
|
|
|
|
|
redisCore.putObject(ACCESS_TOKEN_KEY, response.body.accessToken, ACCESS_TOKEN_EXPIRE_TIME);
|
|
|
|
|
}
|
|
|
|
|
return response.body.accessToken;
|
|
|
|
|
} catch (TeaException err) {
|
|
|
|
|
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception _err) {
|
|
|
|
|
TeaException err = new TeaException(_err.getMessage(), _err);
|
|
|
|
|
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
|
|
|
|
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|