Commit 0cac0506 authored by 赵啸非's avatar 赵啸非

添加钉钉接口相关

parent 99cc36d4
...@@ -9,18 +9,11 @@ public class RedisKey { ...@@ -9,18 +9,11 @@ public class RedisKey {
* 登录 key * 登录 key
*/ */
public static final String KEY_MENU_CACHE = "iot:base:MenuCacheKey:"; public static final String KEY_MENU_CACHE = "iot:base:MenuCacheKey:";
/**
* 设备心跳上报
*/
public static final String KEY_DEVICE_ONLINE_CACHE = "device:online:";
public static final String KEY_SITE_CACHE = "siteDict";
public static final String KEY_PLATFORM_CACHE = "platformDict"; /**
* 钉钉 访问token
public static final String KEY_PRODUCT_CACHE = "productDict"; */
public static final String KEY_DINGTALK_ACCESSTOKEN_CACHE = "dingtalk:token:";
public static final String KEY_TOKEN_API_CACHE = "token:api:";
} }
...@@ -83,9 +83,9 @@ public class CheckReviewRecordServiceImpl extends AbstractCRUDServiceImpl<CheckR ...@@ -83,9 +83,9 @@ public class CheckReviewRecordServiceImpl extends AbstractCRUDServiceImpl<CheckR
msg.setMsgtype("link"); msg.setMsgtype("link");
Link link = new Link(); Link link = new Link();
link.setPicUrl("测试图片链接"); link.setPicUrl("测试图片链接");
link.setMessageUrl("测试消息链接"); link.setMessageUrl("http://www.baidu.com");
link.setText("测试文本"); link.setText("你有一条绩效考核核查通知,请及时查看!");
link.setTitle("测试标题"); link.setTitle("绩效考核核查通知");
msg.setLink(link); msg.setLink(link);
workMsgReq.setUseridList(personRest.getMsg()); workMsgReq.setUseridList(personRest.getMsg());
......
...@@ -7,9 +7,12 @@ import com.dingtalk.api.response.OapiGettokenResponse; ...@@ -7,9 +7,12 @@ import com.dingtalk.api.response.OapiGettokenResponse;
import com.hikvision.artemis.sdk.config.ArtemisConfig; import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICacheService;
import com.mortals.xhx.common.key.RedisKey;
import com.mortals.xhx.common.pdu.ApiRespPdu; import com.mortals.xhx.common.pdu.ApiRespPdu;
import com.mortals.xhx.module.dingding.personal.service.IDingPersonService; import com.mortals.xhx.module.dingding.personal.service.IDingPersonService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -32,7 +35,7 @@ public abstract class AbstractDingTalkService implements IDingPersonService { ...@@ -32,7 +35,7 @@ public abstract class AbstractDingTalkService implements IDingPersonService {
protected Long agentId; protected Long agentId;
/** /**
* AgentId * domain
*/ */
@Value("${dingtalk.domain:https://oapi.dingtalk.com}") @Value("${dingtalk.domain:https://oapi.dingtalk.com}")
protected String domain; protected String domain;
...@@ -49,43 +52,38 @@ public abstract class AbstractDingTalkService implements IDingPersonService { ...@@ -49,43 +52,38 @@ public abstract class AbstractDingTalkService implements IDingPersonService {
@Value("${dingtalk.AppSecret:''}") @Value("${dingtalk.AppSecret:''}")
protected String appSecret; protected String appSecret;
/** @Autowired
* getToken private ICacheService cacheService;
*/
@Value("${dingtalk.gettoken:https://oapi.dingtalk.com/gettoken}")
protected String getTokneUrl;
protected String dingToken;
protected DingTalkClient getDingTalkClient(String path) { protected DingTalkClient getDingTalkClient(String path) {
DingTalkClient client = new DefaultDingTalkClient(domain + path); DingTalkClient client = new DefaultDingTalkClient(domain + path);
return client; return client;
} }
protected void checkToken() {
if (ObjectUtils.isEmpty(dingToken)) {
dingToken = getToken().getData();
}
}
@Override @Override
public Rest<String> getToken() { public String getToken() {
try { try {
DingTalkClient client = getDingTalkClient("/gettoken"); String dingToken = cacheService.get(RedisKey.KEY_DINGTALK_ACCESSTOKEN_CACHE);
OapiGettokenRequest req = new OapiGettokenRequest(); if (ObjectUtils.isEmpty(dingToken)) {
req.setAppkey(appKey); DingTalkClient client = getDingTalkClient("/gettoken");
req.setAppsecret(appSecret); OapiGettokenRequest req = new OapiGettokenRequest();
OapiGettokenResponse rsp = client.execute(req); req.setAppkey(appKey);
log.info("OapiGettokenResponse:{}",rsp.getBody()); req.setAppsecret(appSecret);
if (rsp.getErrcode() == 0) { OapiGettokenResponse rsp = client.execute(req);
return Rest.ok(rsp.getAccessToken()); log.info("OapiGettokenResponse:{}", rsp.getBody());
if (rsp.getErrcode() == 0) {
cacheService.setex(RedisKey.KEY_DINGTALK_ACCESSTOKEN_CACHE, rsp.getAccessToken(), 4800);
return rsp.getAccessToken();
} else {
throw new AppException(String.format("code:{},errorMsg:{}", rsp.getErrcode(), rsp.getErrmsg()));
}
} else { } else {
throw new AppException(rsp.getMessage()); return dingToken;
} }
} catch (Exception e) { } catch (Exception e) {
log.error("获取TOKEN异常", e); log.error("获取TOKEN异常", e);
return Rest.fail(e.getMessage()); throw new AppException(e.getMessage());
} }
} }
......
...@@ -3,5 +3,5 @@ package com.mortals.xhx.module.dingding; ...@@ -3,5 +3,5 @@ package com.mortals.xhx.module.dingding;
import com.mortals.framework.common.Rest; import com.mortals.framework.common.Rest;
public interface IDingTalkService { public interface IDingTalkService {
Rest<String> getToken(); String getToken();
} }
...@@ -24,11 +24,10 @@ public class DingPersonServiceImpl extends AbstractDingTalkService implements ID ...@@ -24,11 +24,10 @@ public class DingPersonServiceImpl extends AbstractDingTalkService implements ID
public Rest<String> getPersonByMobile(String mobile) { public Rest<String> getPersonByMobile(String mobile) {
try { try {
DingTalkClient client = getDingTalkClient("/topapi/v2/user/getbymobile"); DingTalkClient client = getDingTalkClient("/topapi/v2/user/getbymobile");
checkToken();
OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest(); OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
req.setMobile(mobile); req.setMobile(mobile);
log.info("getPersonByMobile:{}",mobile); log.info("getPersonByMobile:{}",mobile);
OapiV2UserGetbymobileResponse rsp = client.execute(req, dingToken); OapiV2UserGetbymobileResponse rsp = client.execute(req, getToken());
log.info("OapiV2UserGetbymobileResponse:{}",rsp.getBody()); log.info("OapiV2UserGetbymobileResponse:{}",rsp.getBody());
if (rsp.getErrcode() == 0) { if (rsp.getErrcode() == 0) {
return Rest.ok(rsp.getResult().getUserid()); return Rest.ok(rsp.getResult().getUserid());
...@@ -45,13 +44,13 @@ public class DingPersonServiceImpl extends AbstractDingTalkService implements ID ...@@ -45,13 +44,13 @@ public class DingPersonServiceImpl extends AbstractDingTalkService implements ID
public Rest<String> sendWorkMsg(WorkMsgReq workMsgReq) { public Rest<String> sendWorkMsg(WorkMsgReq workMsgReq) {
try { try {
DingTalkClient client = getDingTalkClient("/topapi/message/corpconversation/asyncsend_v2"); DingTalkClient client = getDingTalkClient("/topapi/message/corpconversation/asyncsend_v2");
checkToken();
OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request(); OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request();
req.setAgentId(agentId); req.setAgentId(agentId);
req.setUseridList(workMsgReq.getUseridList()); req.setUseridList(workMsgReq.getUseridList());
req.setMsg(JSON.toJSONString(workMsgReq.getMsg())); req.setMsg(JSON.toJSONString(workMsgReq.getMsg()));
log.info("sendWorkMsg:{}", JSON.toJSONString(workMsgReq)); log.info("sendWorkMsg:{}", JSON.toJSONString(workMsgReq));
OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, dingToken); OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, getToken());
log.info("OapiMessageResponse:{}",rsp.getBody()); log.info("OapiMessageResponse:{}",rsp.getBody());
if (rsp.getErrcode() == 0) { if (rsp.getErrcode() == 0) {
return Rest.ok(rsp.getMsg(), rsp.getRequestId()); return Rest.ok(rsp.getMsg(), rsp.getRequestId());
......
...@@ -641,3 +641,12 @@ CREATE TABLE mortals_xhx_staff_perform_summary( ...@@ -641,3 +641,12 @@ CREATE TABLE mortals_xhx_staff_perform_summary(
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='员工绩效统计'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='员工绩效统计';
-- ----------------------------
2023-7-15
-- ----------------------------
ALTER TABLE mortals_xhx_perform_attend_appeal ADD COLUMN `deductPerson` varchar(128) COMMENT '扣分人员' AFTER subMethod;
ALTER TABLE mortals_xhx_perform_attend_appeal ADD COLUMN `deductTime` datetime COMMENT '扣分时间' AFTER deductPerson;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment