|
@@ -8,19 +8,17 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
import com.dingtalk.api.request.OapiReportCreateRequest;
|
|
|
-import com.dingtalk.api.request.OapiReportSavecontentRequest;
|
|
|
import com.dingtalk.api.request.OapiV2UserGetbymobileRequest;
|
|
|
import com.dingtalk.api.response.OapiReportCreateResponse;
|
|
|
import com.dingtalk.api.response.OapiV2UserGetbymobileResponse;
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.taobao.api.ApiException;
|
|
|
+import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.iot.constant.dingTalkConstant;
|
|
|
import com.usky.iot.domain.*;
|
|
|
import com.usky.iot.mapper.*;
|
|
|
-import com.usky.iot.service.MceMbuserService;
|
|
|
import com.usky.iot.service.PmProjectService;
|
|
|
import com.usky.iot.service.PmWorkContentService;
|
|
|
import com.usky.iot.service.PmWorkReportService;
|
|
@@ -29,7 +27,6 @@ import com.usky.iot.service.vo.PmProjectWorkTimeVo;
|
|
|
import com.usky.system.RemoteMceService;
|
|
|
import com.usky.system.domain.SysUser;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -314,12 +311,17 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
.collect(Collectors.toList()))
|
|
|
.orElse(Collections.emptyList());
|
|
|
}
|
|
|
- sendAsyncMessage(newReport, ids);
|
|
|
- //存入消息接收
|
|
|
+ //sendAsyncMessage(newReport, ids);
|
|
|
+ List<Long> finalIds = ids;
|
|
|
+ CompletableFuture.runAsync(() -> {sendAsyncMessage(newReport, finalIds);});
|
|
|
+ //存入消息接收表
|
|
|
receiveMessages(ids, newReport.getId());
|
|
|
//是否同步钉钉
|
|
|
if (pmWorkReport.getSendDingTalk() == 1) {
|
|
|
- sendDingTalkDailyReport(pmWorkReport);
|
|
|
+ //sendDingTalkDailyReport(pmWorkReport);
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ sendDingTalkDailyReport(newReport, pmWorkReport.getWorkContents());
|
|
|
+ });
|
|
|
}
|
|
|
} else if (repeat.size() > 0) {
|
|
|
PmWorkReport rp = new PmWorkReport();
|
|
@@ -384,7 +386,6 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
|
|
|
@Async("asyncServiceExecutor")
|
|
|
public void sendAsyncMessage(PmWorkReport newReport, List<Long> userId) {
|
|
|
- log.info("start asyncServiceExecutor remoteMceService.addMce--------------------");
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("infoTitle", INFO_TITLE);
|
|
|
jsonObject.put("infoContent", SecurityUtils.getLoginUser().getSysUser().getNickName() + INFO_CONTENT);
|
|
@@ -396,9 +397,15 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
}
|
|
|
// 推送消息中心
|
|
|
try {
|
|
|
- remoteMceService.addMce(jsonObject.toString());
|
|
|
+ ApiResult<Void> voidApiResult = remoteMceService.addMce(jsonObject.toString());
|
|
|
+
|
|
|
+ if (voidApiResult.isSuccess()) {
|
|
|
+ log.info("报告消息发送成功!");
|
|
|
+ } else {
|
|
|
+ log.error("报告消息发送失败!");
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ log.error("发送消息时发生异常", e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -488,6 +495,7 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
|
|
|
/**
|
|
|
* 指定请求
|
|
|
+ *
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
@@ -501,12 +509,18 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
|
|
|
/**
|
|
|
* 获取钉钉企业内部AccessToken
|
|
|
+ *
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public String getDingTalkToken() throws Exception {
|
|
|
+ public String getDingTalkToken() {
|
|
|
GetAccessTokenResponse responseBody = new GetAccessTokenResponse();
|
|
|
- com.aliyun.dingtalkoauth2_1_0.Client client = createClient();
|
|
|
+ com.aliyun.dingtalkoauth2_1_0.Client client = null;
|
|
|
+ try {
|
|
|
+ client = createClient();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
|
|
|
.setAppKey(dingTalkConstant.DING_TALK_CLIENT_ID)
|
|
|
.setAppSecret(dingTalkConstant.DING_TALK_CLIENT_SECRET);
|
|
@@ -527,6 +541,7 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
|
|
|
/**
|
|
|
* 获取钉钉userId
|
|
|
+ *
|
|
|
* @param userId 平台userid
|
|
|
* @return
|
|
|
*/
|
|
@@ -542,44 +557,44 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
return mceMbuser.getDingTalkId();
|
|
|
}
|
|
|
}
|
|
|
- LambdaQueryWrapper<SysUser> phoneQuery = Wrappers.lambdaQuery();
|
|
|
- phoneQuery.select(SysUser::getPhonenumber, SysUser::getUserName)
|
|
|
- .eq(SysUser::getUserId, userId);
|
|
|
- SysUser user = sysUserMapper.selectOne(phoneQuery);
|
|
|
- String mobile = user.getPhonenumber();
|
|
|
- try {
|
|
|
- String accessToken = getDingTalkToken();
|
|
|
- DingTalkClient client = new DefaultDingTalkClient(dingTalkConstant.DING_TALK_USERID_URL);
|
|
|
- OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
|
|
|
- req.setMobile(mobile);
|
|
|
- OapiV2UserGetbymobileResponse rsp = client.execute(req, accessToken);
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
- JsonNode rootNode = objectMapper.readTree(rsp.getBody());
|
|
|
- JsonNode resultNode = rootNode.get("result");
|
|
|
- dingTalkId = resultNode.get("userid").asText();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (mceMbuser != null) {
|
|
|
- mceMbuser.setDingTalkId(dingTalkId);
|
|
|
- mceMbuser.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- mceMbuser.setUpdateTime(LocalDateTime.now());
|
|
|
- mceMbuserMapper.update(mceMbuser, dingTalkQuery);
|
|
|
- } else {
|
|
|
- MceMbuser mbuser = new MceMbuser();
|
|
|
- mbuser.setDingTalkId(dingTalkId);
|
|
|
- mbuser.setPhone(mobile);
|
|
|
- mbuser.setUserId(userId);
|
|
|
- mbuser.setCreateBy(user.getUserName());
|
|
|
- mbuser.setCreateTime(LocalDateTime.now());
|
|
|
- mceMbuserMapper.insert(mbuser);
|
|
|
- }
|
|
|
+ LambdaQueryWrapper<SysUser> phoneQuery = Wrappers.lambdaQuery();
|
|
|
+ phoneQuery.select(SysUser::getPhonenumber, SysUser::getUserName)
|
|
|
+ .eq(SysUser::getUserId, userId);
|
|
|
+ SysUser user = sysUserMapper.selectOne(phoneQuery);
|
|
|
+ String mobile = user.getPhonenumber();
|
|
|
+ try {
|
|
|
+ String accessToken = getDingTalkToken();
|
|
|
+ DingTalkClient client = new DefaultDingTalkClient(dingTalkConstant.DING_TALK_USERID_URL);
|
|
|
+ OapiV2UserGetbymobileRequest req = new OapiV2UserGetbymobileRequest();
|
|
|
+ req.setMobile(mobile);
|
|
|
+ OapiV2UserGetbymobileResponse rsp = client.execute(req, accessToken);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(rsp.getBody());
|
|
|
+ JsonNode resultNode = rootNode.get("result");
|
|
|
+ dingTalkId = resultNode.get("userid").asText();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (mceMbuser != null) {
|
|
|
+ mceMbuser.setDingTalkId(dingTalkId);
|
|
|
+ mceMbuser.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ mceMbuser.setUpdateTime(LocalDateTime.now());
|
|
|
+ mceMbuserMapper.update(mceMbuser, dingTalkQuery);
|
|
|
+ } else {
|
|
|
+ MceMbuser mbuser = new MceMbuser();
|
|
|
+ mbuser.setDingTalkId(dingTalkId);
|
|
|
+ mbuser.setPhone(mobile);
|
|
|
+ mbuser.setUserId(userId);
|
|
|
+ mbuser.setCreateBy(user.getUserName());
|
|
|
+ mbuser.setCreateTime(LocalDateTime.now());
|
|
|
+ mceMbuserMapper.insert(mbuser);
|
|
|
+ }
|
|
|
return dingTalkId;
|
|
|
}
|
|
|
|
|
|
@Async("asyncServiceExecutor")//异步发送
|
|
|
@Override
|
|
|
- public void sendDingTalkDailyReport(PmWorkReport workReport) {
|
|
|
+ public void sendDingTalkDailyReport(PmWorkReport workReport, List<PmWorkContent> workContents) {
|
|
|
String ccToStr = workReport.getCcTo();
|
|
|
String[] items = ccToStr.split(",");
|
|
|
List<Long> userIds = new ArrayList<>();
|
|
@@ -592,9 +607,17 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
String dingTalkUserId = getDingTalkUserId(userId);
|
|
|
ccTo.add(dingTalkUserId);
|
|
|
}
|
|
|
- String coordinateWork1 = workReport.getCoordinateWork();
|
|
|
- String tomorrowPlan1 = workReport.getTomorrowPlan();
|
|
|
- List<PmWorkContent> workContents = workReport.getWorkContents();
|
|
|
+ String reportCoordinateWork = workReport.getCoordinateWork();
|
|
|
+ String reportTomorrowPlan = workReport.getTomorrowPlan();
|
|
|
+ String coordinateWork1 = "-";
|
|
|
+ String tomorrowPlan1 = "-";
|
|
|
+ if (reportCoordinateWork != null && reportCoordinateWork != "") {
|
|
|
+ coordinateWork1 = reportCoordinateWork;
|
|
|
+ }
|
|
|
+ if (reportTomorrowPlan != null && reportTomorrowPlan != "") {
|
|
|
+ tomorrowPlan1 = reportTomorrowPlan;
|
|
|
+ }
|
|
|
+
|
|
|
StringBuilder contentBuilder = new StringBuilder();
|
|
|
for (PmWorkContent content : workContents) {
|
|
|
String projectName = content.getProjectName();
|
|
@@ -602,7 +625,7 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
String workContent = content.getWorkContent();
|
|
|
StringBuilder markdown = new StringBuilder();
|
|
|
markdown.append("#### ").append(projectName).append(" ").append(workTime).append("h\n\n");
|
|
|
- markdown.append(workContent).append("\n");
|
|
|
+ markdown.append("<span style=\"font-size: 18px;\">").append(workContent).append("\n").append("</span>");
|
|
|
contentBuilder.append(markdown);
|
|
|
}
|
|
|
String completedWork = contentBuilder.toString();
|
|
@@ -641,6 +664,11 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
//obj1.setToCids(dingTalkConstant.DING_TALK_DAILY_REPORT_TO_CIDS);//发送到群,群id
|
|
|
req.setCreateReportParam(obj1);
|
|
|
OapiReportCreateResponse rsp = client.execute(req, getDingTalkToken());
|
|
|
+ if (rsp.isSuccess()) {
|
|
|
+ log.info("钉钉报告发送成功");
|
|
|
+ } else {
|
|
|
+ log.error("钉钉报告发送失败: " + rsp.getErrmsg());
|
|
|
+ }
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|