|
@@ -6,12 +6,14 @@ import com.aliyun.dingtalkoauth2_1_0.models.GetCorpAccessTokenResponse;
|
|
|
import com.aliyun.tea.TeaException;
|
|
|
import com.aliyun.teaopenapi.models.Config;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
import com.dingtalk.api.request.OapiGettokenRequest;
|
|
|
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
|
|
import com.dingtalk.api.request.OapiMessageCorpconversationSendbytemplateRequest;
|
|
|
import com.dingtalk.api.request.OapiServiceGetSuiteTokenRequest;
|
|
|
+import com.dingtalk.api.response.OapiGettokenResponse;
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationAsyncsendV2Response;
|
|
|
import com.dingtalk.api.response.OapiMessageCorpconversationSendbytemplateResponse;
|
|
|
import com.dingtalk.api.response.OapiServiceGetSuiteTokenResponse;
|
|
@@ -20,14 +22,16 @@ import com.management.platform.entity.SysConfig;
|
|
|
import com.management.platform.mapper.CompanyDingdingMapper;
|
|
|
import com.management.platform.mapper.SysConfigMapper;
|
|
|
import com.management.platform.service.CompanyDingdingService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.taobao.api.ApiException;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -58,203 +62,288 @@ public class CompanyDingdingServiceImpl extends ServiceImpl<CompanyDingdingMappe
|
|
|
|
|
|
@Resource
|
|
|
private SysConfigMapper sysConfigMapper;
|
|
|
+ @Resource
|
|
|
+ private CompanyDingdingMapper companyDingdingMapper;
|
|
|
@Value("${dingding.appId}")
|
|
|
private long appId;//钉钉第三方应用的appId
|
|
|
+ @Value("${configEnv.isPrivateDeploy}")
|
|
|
+ private boolean isPrivateDeploy;//是否是私有化部署,企业内部应用
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public void sendFillReportAlertMsg(Integer companyId, Long agentId, String msg, String useridList) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
- System.out.println("发送AlertMsg=="+msg+", agentId="+agentId);
|
|
|
CompanyDingding dingding = getOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
- req.setAgentId(agentId);
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ sendInnerLinkMsg(dingding,useridList,"日报漏填提醒",msg);
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("说明:");
|
|
|
+ item.setValue(msg);
|
|
|
+ form.add(item);
|
|
|
+ sendOAMsg(dingding,useridList,"日报漏填提醒","您有日报漏填,请及时填报",form,null);
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ System.out.println("发送AlertMsg=="+msg+", agentId="+agentId);
|
|
|
+ req.setAgentId(agentId);
|
|
|
// req.setDeptIdList("421897262");
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_ALERT_REPORT);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- json.put("msg", msg);
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_ALERT_REPORT);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("APPID", ""+appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ json.put("msg", msg);
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void sendRejectReportMsg(Integer companyId, String date, String projectNames, String reason, String auditorName, String useridList) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
CompanyDingding dingding = getOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
- req.setAgentId(dingding.getAgentId());
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_REJECT_REPORT);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("createDate", date);
|
|
|
- json.put("project", projectNames);
|
|
|
- json.put("reason", reason);
|
|
|
- json.put("auditUser", auditorName);
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("日报日期:");
|
|
|
+ item.setValue(date);
|
|
|
+ form.add(item);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item1=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item1.setKey("所属项目:");
|
|
|
+ item1.setValue(projectNames);
|
|
|
+ form.add(item1);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item2=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item2.setKey("驳回原因:");
|
|
|
+ item2.setValue(reason);
|
|
|
+ form.add(item2);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item3=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item3.setKey("审批人:");
|
|
|
+ item3.setValue(auditorName);
|
|
|
+ form.add(item3);
|
|
|
+ sendOAMsg(dingding,useridList,"日报驳回提醒","您的日报被驳回,请及时查看",form,null);
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ req.setAgentId(dingding.getAgentId());
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_REJECT_REPORT);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("createDate", date);
|
|
|
+ json.put("project", projectNames);
|
|
|
+ json.put("reason", reason);
|
|
|
+ json.put("auditUser", auditorName);
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void sendLeaveApplyAlertMsg(Integer companyId, Long agentId, String msg, String useridList) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
- System.out.println("发送 请假提交审批 =="+msg+", agentId="+agentId);
|
|
|
CompanyDingding dingding = getOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
- req.setAgentId(agentId);
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ sendInnerLinkMsg(dingding,useridList,"请假提交审批提醒",msg);
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("说明:");
|
|
|
+ item.setValue(msg);
|
|
|
+ form.add(item);
|
|
|
+ sendOAMsg(dingding,useridList,"请假提交审批提醒","您的请假还未提交审批,请及时提交",form,null);
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ System.out.println("发送 请假提交审批 ==" + msg + ", agentId=" + agentId);
|
|
|
+
|
|
|
+ req.setAgentId(agentId);
|
|
|
// req.setDeptIdList("421897262");
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_LEAVE_APPLY);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("employeeName", "张辉");
|
|
|
- json.put("deptName", "质量部");
|
|
|
- json.put("date", "2022-03-29");
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_LEAVE_APPLY);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("employeeName", "张辉");
|
|
|
+ json.put("deptName", "质量部");
|
|
|
+ json.put("date", "2022-03-29");
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void sendReportWaitingApplyMsg(Integer companyId, Long agentId, Long auditNum, String useridList) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
- System.out.println("发送 待审批日报数量 =="+auditNum+", agentId="+agentId);
|
|
|
CompanyDingding dingding = getOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
- req.setAgentId(agentId);
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_REPORT_WAITING_APPLY);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("auditNum", ""+auditNum);
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("待审核数量:");
|
|
|
+ item.setValue(String.valueOf(auditNum));
|
|
|
+ form.add(item);
|
|
|
+ sendOAMsg(dingding,useridList,"您还有日报暂未审核","请及时审核",form,null);
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ System.out.println("发送 待审批日报数量 ==" + auditNum + ", agentId=" + agentId);
|
|
|
+ req.setAgentId(agentId);
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_REPORT_WAITING_APPLY);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("auditNum", "" + auditNum);
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void sendBusinessTripSettingMsg(Integer companyId, Long agentId, String useridList) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
CompanyDingding dingding = getOne(new QueryWrapper<CompanyDingding>().eq("company_id", companyId));
|
|
|
- req.setAgentId(agentId);
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_BUSTRIP_SETTING);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ sendInnerLinkMsg(dingding,useridList,"关联出差提醒","您还有出差记录尚未关联到项目");
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ req.setAgentId(agentId);
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_BUSTRIP_SETTING);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
-
|
|
|
@Override
|
|
|
public void sendNewTaskMsg(CompanyDingding dingding, String ddUserid, String title, String endDate) {
|
|
|
- //异步发送
|
|
|
- new Thread(){
|
|
|
- public void run() {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
- req.setAgentId(dingding.getAgentId());
|
|
|
- req.setUseridList(ddUserid);
|
|
|
- req.setTemplateId(TEMPLATE_NEW_TASK);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("name", ""+title);
|
|
|
- json.put("endDate", ""+endDate);
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- req.setData(json.toJSONString());
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("任务标题:");
|
|
|
+ item.setValue(title);
|
|
|
+ form.add(item);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item1=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item1.setKey("截至日期:");
|
|
|
+ item1.setValue(endDate);
|
|
|
+ form.add(item1);
|
|
|
+ sendOAMsg(dingding,ddUserid,"新任务提醒","您有一条新的任务待执行,请关注",form,null);
|
|
|
+ } else {
|
|
|
+ //异步发送
|
|
|
+ new Thread() {
|
|
|
+ public void run() {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ req.setAgentId(dingding.getAgentId());
|
|
|
+ req.setUseridList(ddUserid);
|
|
|
+ req.setTemplateId(TEMPLATE_NEW_TASK);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("name", "" + title);
|
|
|
+ json.put("endDate", "" + endDate);
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ req.setData(json.toJSONString());
|
|
|
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
- }
|
|
|
- }.start();
|
|
|
+ }.start();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public void sendFinishMileStoneMsg(CompanyDingding dingding, String useridList, String taskName, Integer projectId, String project, String finishDate) {
|
|
|
- DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
- OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
- req.setAgentId(dingding.getAgentId());
|
|
|
- req.setUseridList(useridList);
|
|
|
- req.setTemplateId(TEMPLATE_FINISH_MILESTONE);
|
|
|
- JSONObject json = new JSONObject();
|
|
|
- json.put("taskName", taskName);
|
|
|
- json.put("project", project);
|
|
|
- json.put("PROJECTID", ""+projectId);
|
|
|
- json.put("APPID", ""+appId);
|
|
|
- json.put("CORPID", dingding.getCorpid());
|
|
|
- json.put("finishDate", finishDate);
|
|
|
- req.setData(json.toJSONString());
|
|
|
- OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
- try {
|
|
|
- rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
- } catch (ApiException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (Exception exception) {
|
|
|
- exception.printStackTrace();
|
|
|
+ if (isPrivateDeploy) {
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> form=new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item.setKey("里程碑:");
|
|
|
+ item.setValue(taskName);
|
|
|
+ form.add(item);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item1=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item1.setKey("所属项目:");
|
|
|
+ item1.setValue(project);
|
|
|
+ form.add(item1);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form item2=new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ item2.setKey("完成时间:");
|
|
|
+ item2.setValue(finishDate);
|
|
|
+ form.add(item2);
|
|
|
+ sendOAMsg(dingding,useridList,"里程碑完成提醒","我们刚刚完成了以下里程碑,感谢大家的努力!",form,projectId);
|
|
|
+ } else {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate");
|
|
|
+ OapiMessageCorpconversationSendbytemplateRequest req = new OapiMessageCorpconversationSendbytemplateRequest();
|
|
|
+ req.setAgentId(dingding.getAgentId());
|
|
|
+ req.setUseridList(useridList);
|
|
|
+ req.setTemplateId(TEMPLATE_FINISH_MILESTONE);
|
|
|
+ JSONObject json = new JSONObject();
|
|
|
+ json.put("taskName", taskName);
|
|
|
+ json.put("project", project);
|
|
|
+ json.put("PROJECTID", "" + projectId);
|
|
|
+ json.put("APPID", "" + appId);
|
|
|
+ json.put("CORPID", dingding.getCorpid());
|
|
|
+ json.put("finishDate", finishDate);
|
|
|
+ req.setData(json.toJSONString());
|
|
|
+ OapiMessageCorpconversationSendbytemplateResponse rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(req, getCorpAccessToken(dingding));
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
}
|
|
|
- System.out.println(rsp.getBody());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
- public void sendOAMsg(CompanyDingding dingding, String useridList, HashMap map) {
|
|
|
+ public void sendOAMsg(CompanyDingding dingding, String useridList,String titleText,String content,List<OapiMessageCorpconversationAsyncsendV2Request.Form> form,Integer projectId) {
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
|
|
|
OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
|
|
|
request.setAgentId(dingding.getAgentId());
|
|
|
request.setUseridList(useridList);
|
|
|
request.setToAllUser(false);
|
|
|
-
|
|
|
OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
|
|
|
// msg.setMsgtype("text");
|
|
|
// msg.setText(new OapiMessageCorpconversationAsyncsendV2Request.Text());
|
|
@@ -287,11 +376,19 @@ public class CompanyDingdingServiceImpl extends ServiceImpl<CompanyDingdingMappe
|
|
|
|
|
|
msg.setOa(new OapiMessageCorpconversationAsyncsendV2Request.OA());
|
|
|
msg.getOa().setHead(new OapiMessageCorpconversationAsyncsendV2Request.Head());
|
|
|
- msg.getOa().getHead().setText("这里是标题");
|
|
|
+ msg.getOa().getHead().setText(titleText);
|
|
|
msg.getOa().setBody(new OapiMessageCorpconversationAsyncsendV2Request.Body());
|
|
|
- msg.getOa().getBody().setContent("这里是内容");
|
|
|
+ msg.getOa().getBody().setContent(content);
|
|
|
+ msg.getOa().getBody().setForm(form);
|
|
|
msg.setMsgtype("oa");
|
|
|
- msg.getOa().setMessageUrl("dingtalk://dingtalkclient/action/openapp?corpid=="+dingding.getCorpid()+"&container_type=work_platform&app_id="+appId+"&redirect_type=jump&redirect_url=https%3A%2F%2Fworktime.ttkuaiban.com%2F%3Fcorpid%3D%24CORPID%24");
|
|
|
+ List<String> collect = form.stream().map(f -> f.getKey()).collect(Collectors.toList());
|
|
|
+ if(collect.contains("里程碑:")){
|
|
|
+ msg.getOa().setMessageUrl("dingtalk://dingtalkclient/action/openapp?corpid="+dingding.getCorpid()
|
|
|
+ +"&container_type=work_platform&app_id=0_"+dingding.getAgentId()+"&redirect_type=jump&redirect_url="+ URLEncoder.encode(dingding.getWebUrl()+"?corpid="+dingding.getCorpid())+"&jumpto=/info/"+projectId);
|
|
|
+ }else {
|
|
|
+ msg.getOa().setMessageUrl("dingtalk://dingtalkclient/action/openapp?corpid="+dingding.getCorpid()
|
|
|
+ +"&container_type=work_platform&app_id=0_"+dingding.getAgentId()+"&redirect_type=jump&redirect_url="+ URLEncoder.encode(dingding.getWebUrl()+"?corpid="+dingding.getCorpid()));
|
|
|
+ }
|
|
|
request.setMsg(msg);
|
|
|
|
|
|
// msg.setActionCard(new OapiMessageCorpconversationAsyncsendV2Request.ActionCard());
|
|
@@ -303,13 +400,59 @@ public class CompanyDingdingServiceImpl extends ServiceImpl<CompanyDingdingMappe
|
|
|
// request.setMsg(msg);
|
|
|
OapiMessageCorpconversationAsyncsendV2Response rsp = null;
|
|
|
try {
|
|
|
- rsp = client.execute(request, getCorpAccessToken(dingding));
|
|
|
+ rsp = client.execute(request, getInnerCorpToken(dingding));
|
|
|
} catch (Exception exception) {
|
|
|
exception.printStackTrace();
|
|
|
}
|
|
|
System.out.println(rsp.getBody());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void sendInnerLinkMsg(CompanyDingding dingding, String useridList, String title, String alertMsg) {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
|
|
|
+ request.setAgentId(dingding.getAgentId());
|
|
|
+ request.setUseridList(useridList);
|
|
|
+ request.setToAllUser(false);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
|
|
|
+
|
|
|
+ msg.setMsgtype("link");
|
|
|
+ msg.setLink(new OapiMessageCorpconversationAsyncsendV2Request.Link());
|
|
|
+ msg.getLink().setTitle(title);
|
|
|
+ msg.getLink().setText(alertMsg);
|
|
|
+ msg.getLink().setMessageUrl("dingtalk://dingtalkclient/action/openapp?corpid="+dingding.getCorpid()
|
|
|
+ +"&container_type=work_platform&app_id=0_"+dingding.getAgentId()+"&redirect_type=jump&redirect_url="+ URLEncoder.encode(dingding.getWebUrl()+"?corpid="+dingding.getCorpid()));
|
|
|
+ request.setMsg(msg);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Response rsp = null;
|
|
|
+ try {
|
|
|
+ rsp = client.execute(request, getInnerCorpToken(dingding));
|
|
|
+ } catch (Exception exception) {
|
|
|
+ exception.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println(rsp.getBody());
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取钉钉内部企业的token
|
|
|
+ */
|
|
|
+ private String getInnerCorpToken(CompanyDingding dingding) throws ApiException {
|
|
|
+ if (dingding.getInnerToken() == null || LocalDateTime.now().isAfter(dingding.getInnerExpireTime())) {
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
|
|
|
+ OapiGettokenRequest request = new OapiGettokenRequest();
|
|
|
+ request.setAppkey(dingding.getInnerAppkey());
|
|
|
+ request.setAppsecret(dingding.getInnerAppsecret());
|
|
|
+ request.setHttpMethod("GET");
|
|
|
+ OapiGettokenResponse response = client.execute(request);
|
|
|
+ if (!response.isSuccess()) {
|
|
|
+ System.err.println("获取企业内部token失败:"+response.getErrorCode()+":"+response.getErrmsg());
|
|
|
+ }
|
|
|
+ dingding.setInnerToken(response.getAccessToken());
|
|
|
+ dingding.setInnerExpireTime(LocalDateTime.now().plusSeconds(response.getExpiresIn()));
|
|
|
+ companyDingdingMapper.updateById(dingding);
|
|
|
+ }
|
|
|
+ return dingding.getInnerToken();
|
|
|
+ }
|
|
|
private String getDDSuiteAccessToken() throws ApiException {
|
|
|
if (DingDingServiceImpl.SUITE_ACCESS_TOKEN == null || DingDingServiceImpl.suiteTokenExpireTime < System.currentTimeMillis()) {
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/service/get_suite_token");
|