|
@@ -0,0 +1,229 @@
|
|
|
+package com.zjugis.module.adm.service.report;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
|
|
+import com.zjugis.framework.common.pojo.CommonResult;
|
|
|
+import com.zjugis.framework.common.util.date.LocalDateTimeUtils;
|
|
|
+
|
|
|
+import com.zjugis.module.adm.controller.admin.report.vo.base.ReportCreateReqVO;
|
|
|
+import com.zjugis.module.adm.controller.admin.report.vo.comment.ReportCommentCreateReqVO;
|
|
|
+import com.zjugis.module.adm.controller.admin.report.vo.workload.ReportWorkloadCreateReqVO;
|
|
|
+import com.zjugis.module.adm.dal.dataobject.report.ReportDO;
|
|
|
+import com.zjugis.module.adm.dal.mysql.report.ReportMapper;
|
|
|
+import com.zjugis.module.adm.remote.ProjectClient;
|
|
|
+import com.zjugis.module.adm.remote.dto.ProjectDto;
|
|
|
+import com.zjugis.module.adm.remote.vo.ProjectVO;
|
|
|
+import com.zjugis.module.infra.api.ding.DingApi;
|
|
|
+import com.zjugis.module.infra.api.ding.dto.DingMessageDto;
|
|
|
+import com.zjugis.module.infra.api.ding.enums.DingMsg;
|
|
|
+import com.zjugis.module.system.api.user.AdminUserApi;
|
|
|
+import com.zjugis.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 行政管理_工作报告 Service 实现类
|
|
|
+ *
|
|
|
+ * @author 管理员
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Validated
|
|
|
+public class ReportDingServiceImpl {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProjectClient projectClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DingApi dingApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ReportMapper reportMapper;
|
|
|
+
|
|
|
+ private static final String URL = "http://10.10.10.7:18080/html_h5";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送报告钉钉消息
|
|
|
+ * @param reportRequestVO
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void sendReportDingMessage(ReportCreateReqVO reportRequestVO) {
|
|
|
+ //用户map
|
|
|
+ Map<String, AdminUserRespDTO> userMap = adminUserApi.getUserMap();
|
|
|
+ //项目map
|
|
|
+ Map<String, String> projectMap = getProjectMap();
|
|
|
+ //发送钉钉消息
|
|
|
+ List<String> receiveUserIds = reportRequestVO.getReceiveUserIds();
|
|
|
+
|
|
|
+ String url = "/logsDetail?id= " + reportRequestVO.getReportId();
|
|
|
+ for (String receiveUserId : receiveUserIds) {
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA();
|
|
|
+ oa.setMessageUrl(URL + url);
|
|
|
+ oa.setPcMessageUrl(URL + url);
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Head head = new OapiMessageCorpconversationAsyncsendV2Request.Head();
|
|
|
+ head.setBgcolor("FFBBBBBB");
|
|
|
+ head.setText("浙江万维OA");
|
|
|
+ oa.setHead(head);
|
|
|
+
|
|
|
+ //消息实体
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Body body = new OapiMessageCorpconversationAsyncsendV2Request.Body();
|
|
|
+
|
|
|
+ //消息标题
|
|
|
+ String userNickName = userMap.get(reportRequestVO.getUserId()) != null ? userMap.get(reportRequestVO.getUserId()).getNickname() : "(异常人员)";
|
|
|
+ String reportType = "daily".equals(reportRequestVO.getReportType()) ? "日报" : "周报";
|
|
|
+ body.setTitle(userNickName + "的" + reportType);
|
|
|
+
|
|
|
+ //消息内容
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formStartDate = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formStartDate.setKey("开始日期:");
|
|
|
+ formStartDate.setValue(LocalDateTimeUtils.format(reportRequestVO.getReportStartDate(), "yyyy-MM-dd"));
|
|
|
+ formList.add(formStartDate);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formEndDate = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formEndDate.setKey("结束日期:");
|
|
|
+ formEndDate.setValue(LocalDateTimeUtils.format(reportRequestVO.getReportEndDate(), "yyyy-MM-dd"));
|
|
|
+ formList.add(formEndDate);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formContent = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formContent.setKey("本周完成工作:\n");
|
|
|
+ formContent.setValue(reportRequestVO.getReportContent());
|
|
|
+ formList.add(formContent);
|
|
|
+
|
|
|
+ StringBuffer formWorkTimeValue = new StringBuffer();
|
|
|
+ List<ReportWorkloadCreateReqVO> weeklyWorkloadList = reportRequestVO.getWeeklyWorkloadList();
|
|
|
+ for (ReportWorkloadCreateReqVO workLoad : weeklyWorkloadList) {
|
|
|
+ String projectName = projectMap.get(workLoad.getProjectId());
|
|
|
+ if (StrUtil.isNotBlank(projectName)) {
|
|
|
+ formWorkTimeValue.append("(").append(workLoad.getWorkTime()).append("小时)").append(projectName).append("\n");
|
|
|
+ } else {
|
|
|
+ formWorkTimeValue.append("(").append(workLoad.getWorkTime()).append("小时)").append("(异常项目)").append("\n");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formWorkTime = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formWorkTime.setKey("工作量分配:\n");
|
|
|
+ formWorkTime.setValue(formWorkTimeValue.toString());
|
|
|
+ formList.add(formWorkTime);
|
|
|
+
|
|
|
+ body.setForm(formList);
|
|
|
+ oa.setBody(body);
|
|
|
+
|
|
|
+ DingMessageDto message = new DingMessageDto(receiveUserId);
|
|
|
+ message.setMsgType(DingMsg.OA);
|
|
|
+ message.setOa(oa);
|
|
|
+ dingApi.sendMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送评论及回复评论钉钉消息
|
|
|
+ * @param reportCommentCreateReqVO
|
|
|
+ */
|
|
|
+ @Async
|
|
|
+ public void sendCommentDingMessage(ReportCommentCreateReqVO reportCommentCreateReqVO) {
|
|
|
+ //用户map
|
|
|
+ Map<String, AdminUserRespDTO> userMap = adminUserApi.getUserMap();
|
|
|
+ //报告map
|
|
|
+ ReportDO reportDO = reportMapper.selectById(reportCommentCreateReqVO.getReportId());
|
|
|
+ String url = "/logsDetail?id= " + reportDO.getId();
|
|
|
+ //发送钉钉消息
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA();
|
|
|
+ oa.setMessageUrl(URL + url);
|
|
|
+ oa.setPcMessageUrl(URL + url);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Head head = new OapiMessageCorpconversationAsyncsendV2Request.Head();
|
|
|
+ head.setBgcolor("FFBBBBBB");
|
|
|
+ head.setText("浙江万维OA");
|
|
|
+ oa.setHead(head);
|
|
|
+
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Body body = new OapiMessageCorpconversationAsyncsendV2Request.Body();
|
|
|
+
|
|
|
+ String commentUserNickName = userMap.get(reportCommentCreateReqVO.getCommentUserId()) != null ? userMap.get(reportCommentCreateReqVO.getCommentUserId()).getNickname() : "(异常人员)";
|
|
|
+ String reportAuthor = userMap.get(reportDO.getUserId()) != null ? userMap.get(reportDO.getUserId()).getNickname() : "(异常人员)";
|
|
|
+ String reportType = "daily".equals(reportDO.getReportType()) ? "日报" : "周报";
|
|
|
+ String messageUserId = reportDO.getUserId();//默认为报告作者
|
|
|
+
|
|
|
+ //发送评论
|
|
|
+ if(!reportCommentCreateReqVO.getCommentUserId().equals(reportDO.getUserId())){
|
|
|
+ //消息标题
|
|
|
+ body.setTitle(commentUserNickName + "评论了你「" + LocalDateTimeUtils.format(reportDO.getReportStartDate(), "yyyy-MM-dd")
|
|
|
+ + "~" + LocalDateTimeUtils.format(reportDO.getReportStartDate(), "yyyy-MM-dd") + "」的" + reportType);
|
|
|
+
|
|
|
+ //消息内容
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formContent = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formContent.setKey("评论内容:\n");
|
|
|
+ formContent.setValue(reportCommentCreateReqVO.getCommentContent());
|
|
|
+ formList.add(formContent);
|
|
|
+ body.setForm(formList);
|
|
|
+
|
|
|
+ oa.setBody(body);
|
|
|
+
|
|
|
+ DingMessageDto message = new DingMessageDto(messageUserId);
|
|
|
+ message.setMsgType(DingMsg.OA);
|
|
|
+ message.setOa(oa);
|
|
|
+ dingApi.sendMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+ //回复评论
|
|
|
+ if (StrUtil.isNotBlank(reportCommentCreateReqVO.getReplyToUserid()) && !reportCommentCreateReqVO.getCommentUserId().equals(reportCommentCreateReqVO.getReplyToUserid())) {
|
|
|
+ messageUserId = reportCommentCreateReqVO.getReplyToUserid();
|
|
|
+ //消息标题
|
|
|
+ body.setTitle(commentUserNickName + "回复了你在" + reportAuthor + "「" + LocalDateTimeUtils.format(reportDO.getReportStartDate(), "yyyy-MM-dd")
|
|
|
+ + "~" + LocalDateTimeUtils.format(reportDO.getReportStartDate(), "yyyy-MM-dd") + "」" + reportType + "下的评论");
|
|
|
+
|
|
|
+ //消息内容
|
|
|
+ List<OapiMessageCorpconversationAsyncsendV2Request.Form> formList = new ArrayList<>();
|
|
|
+ OapiMessageCorpconversationAsyncsendV2Request.Form formContent = new OapiMessageCorpconversationAsyncsendV2Request.Form();
|
|
|
+ formContent.setKey("回复内容:\n");
|
|
|
+
|
|
|
+ int index = reportCommentCreateReqVO.getCommentContent().indexOf(":");
|
|
|
+ String replyCommentContent = reportCommentCreateReqVO.getCommentContent().substring(index + 1);
|
|
|
+ formContent.setValue(replyCommentContent);
|
|
|
+ formList.add(formContent);
|
|
|
+ body.setForm(formList);
|
|
|
+ oa.setBody(body);
|
|
|
+
|
|
|
+ DingMessageDto message = new DingMessageDto(messageUserId);
|
|
|
+ message.setMsgType(DingMsg.OA);
|
|
|
+ message.setOa(oa);
|
|
|
+ dingApi.sendMessage(message);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取项目map
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map<String, String> getProjectMap() {
|
|
|
+ Map<String, String> projectMap = new HashMap<>();
|
|
|
+ ProjectDto projectDto = new ProjectDto();
|
|
|
+ projectDto.setPageNo(1);
|
|
|
+ projectDto.setPageSize(-1);
|
|
|
+ CommonResult<Page<ProjectVO>> projectPage = projectClient.getProjectPage(projectDto);
|
|
|
+ if (projectPage.isSuccess()) {
|
|
|
+ List<ProjectVO> projectList = projectPage.getData().getRecords();
|
|
|
+ projectMap = projectList.stream().collect(Collectors.toMap(ProjectVO::getId, ProjectVO::getXmmc));
|
|
|
+ }
|
|
|
+ return projectMap;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|