|
@@ -13,7 +13,9 @@ import com.usky.iot.service.PmWorkReportService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.iot.service.config.DingTalkAndMessage;
|
|
|
import com.usky.iot.service.vo.PmProjectWorkTimeVo;
|
|
|
+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.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -23,7 +25,6 @@ import java.math.RoundingMode;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.time.temporal.TemporalAdjusters;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -57,6 +58,9 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
@Autowired
|
|
|
private DingTalkAndMessage dingTalkAndMessage;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PmReceiveMapper pmReceiveMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 获取时间内工作报告
|
|
|
*
|
|
@@ -101,9 +105,7 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
}
|
|
|
//固定返回七条数据,没有内容也要设置时间给前端渲染
|
|
|
LambdaQueryWrapper<PmWorkReport> queryWrapperR = Wrappers.lambdaQuery();
|
|
|
- queryWrapperR.select(PmWorkReport::getId, PmWorkReport::getReportDate, PmWorkReport::getSubmitDate, PmWorkReport::getUpdateTime,
|
|
|
- PmWorkReport::getTomorrowPlan, PmWorkReport::getCoordinateWork, PmWorkReport::getCcTo, PmWorkReport::getSendDingTalk)
|
|
|
- .eq(PmWorkReport::getSubmitterId, SecurityUtils.getUserId())
|
|
|
+ queryWrapperR.eq(PmWorkReport::getSubmitterId, SecurityUtils.getUserId())
|
|
|
.between(PmWorkReport::getReportDate, startDate1, endDate1)
|
|
|
.orderByAsc(PmWorkReport::getReportDate)
|
|
|
.apply(reportId != 0, "id = " + reportId);
|
|
@@ -197,11 +199,10 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
String userName = SecurityUtils.getUsername();
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
Integer tenantId = SecurityUtils.getTenantId();
|
|
|
- LocalDateTime dateTime = LocalDateTime.now();
|
|
|
BigDecimal totalWorkTime = BigDecimal.ZERO; //计算总工时
|
|
|
- int minutesToAdd = 5;
|
|
|
+ LocalDateTime dateTime = LocalDateTime.now();
|
|
|
LocalDateTime timingTime = pmWorkReport.getTimingTime();
|
|
|
- LocalDateTime currentTimePlusMinutes = dateTime.plusMinutes(minutesToAdd);
|
|
|
+ LocalDateTime currentTimePlusMinutes = dateTime.plusMinutes(5);
|
|
|
|
|
|
if (pmWorkReport.getWorkContents() == null) {
|
|
|
throw new BusinessException("报告内容不能为空,请检查!");
|
|
@@ -244,13 +245,13 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
newReport.setTenantId(tenantId);
|
|
|
newReport.setTotalHours(totalWorkTime);
|
|
|
newReport.setSendDingTalk(pmWorkReport.getSendDingTalk());
|
|
|
- if (pmWorkReport.getIsRegularlySend() != 0) {
|
|
|
- if (timingTime != null && timingTime.isBefore(currentTimePlusMinutes)) {
|
|
|
+ if (pmWorkReport.getIsRegularlySend() == 1 && timingTime != null) {
|
|
|
+ if (timingTime.isAfter(currentTimePlusMinutes)) {
|
|
|
newReport.setIsRegularlySend(pmWorkReport.getIsRegularlySend());
|
|
|
newReport.setTimingTime(timingTime);
|
|
|
newReport.setReportStatus(0);
|
|
|
} else {
|
|
|
- throw new BusinessException("定时时间需大于五分钟!");
|
|
|
+ throw new BusinessException("定时时间需提前至少五分钟!");
|
|
|
}
|
|
|
}
|
|
|
try {
|
|
@@ -269,6 +270,7 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
//查出所有项目id对应项目名
|
|
|
List<PmProject> project = pmProjectService.projectName(projectIds);
|
|
|
//将项目名重新赋值
|
|
|
+ List<PmWorkContent> pmWorkContents = new ArrayList<>();
|
|
|
for (PmWorkContent b : pmWorkReport.getWorkContents()) {
|
|
|
for (int c = 0; c < project.size(); c++) {
|
|
|
if (b.getProjectId() == project.get(c).getId()) {
|
|
@@ -288,62 +290,99 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
newContent.setDeptId(deptId);
|
|
|
newContent.setTenantId(tenantId);
|
|
|
pmWorkContentMapper.insert(newContent);
|
|
|
+ pmWorkContents.add(newContent);
|
|
|
}
|
|
|
- //非定时发送
|
|
|
- if (timingTime == null) {
|
|
|
- //推送消息中心
|
|
|
- dingTalkAndMessage.sendAsyncMessage(newReport);
|
|
|
+ //抄送人不为空,非定时发送
|
|
|
+ if (StringUtils.isNotEmpty(pmWorkReport.getCcTo())) {
|
|
|
+ if (timingTime == null) {
|
|
|
+ //推送消息中心
|
|
|
+ dingTalkAndMessage.sendAsyncMessage(newReport);
|
|
|
|
|
|
- //是否同步钉钉
|
|
|
- if (pmWorkReport.getSendDingTalk() == 1) {
|
|
|
- dingTalkAndMessage.sendDingTalkDailyReport(newReport, pmWorkReport.getWorkContents());
|
|
|
+ //是否同步钉钉
|
|
|
+ if (pmWorkReport.getSendDingTalk() == 1) {
|
|
|
+ dingTalkAndMessage.sendDingTalkDailyReport(newReport, pmWorkContents);
|
|
|
+ }
|
|
|
}
|
|
|
+ //存入报告消息表
|
|
|
+ List<Long> longList = Arrays.stream(pmWorkReport.getCcTo().split(","))
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ receiveMessages(longList, newReport.getId());
|
|
|
}
|
|
|
-
|
|
|
} else if (repeat.size() > 0) {
|
|
|
PmWorkReport rp = new PmWorkReport();
|
|
|
rp.setId(pmWorkReport.getId());
|
|
|
- rp.setReportDate(pmWorkReport.getReportDate());
|
|
|
+ //rp.setReportDate(pmWorkReport.getReportDate());
|
|
|
rp.setSubmitterId(pmWorkReport.getSubmitterId());
|
|
|
- rp.setSubmitDate(pmWorkReport.getSubmitDate());
|
|
|
+ //rp.setSubmitDate(pmWorkReport.getSubmitDate());
|
|
|
rp.setCcTo(pmWorkReport.getCcTo());
|
|
|
rp.setCoordinateWork(pmWorkReport.getCoordinateWork());
|
|
|
rp.setTomorrowPlan(pmWorkReport.getTomorrowPlan());
|
|
|
rp.setCreateBy(pmWorkReport.getCreateBy());
|
|
|
- rp.setCreateTime(pmWorkReport.getCreateTime());
|
|
|
- rp.setUpdateTime(dateTime);
|
|
|
- rp.setDeptId(pmWorkReport.getDeptId());
|
|
|
- rp.setTenantId(pmWorkReport.getTenantId());
|
|
|
+ //rp.setCreateTime(pmWorkReport.getCreateTime());
|
|
|
+ //rp.setDeptId(pmWorkReport.getDeptId());
|
|
|
+ //rp.setTenantId(pmWorkReport.getTenantId());
|
|
|
rp.setUpdateBy(userName);
|
|
|
rp.setUpdateTime(dateTime);
|
|
|
rp.setTotalHours(totalWorkTime);
|
|
|
- if (pmWorkReport.getIsRegularlySend() != 0) {
|
|
|
- if (timingTime != null && timingTime.isBefore(currentTimePlusMinutes)) {
|
|
|
- rp.setIsRegularlySend(pmWorkReport.getIsRegularlySend());
|
|
|
+ if (pmWorkReport.getIsRegularlySend() == 1) {
|
|
|
+ if (timingTime != null && timingTime.isAfter(currentTimePlusMinutes)) {
|
|
|
rp.setTimingTime(timingTime);
|
|
|
- rp.setReportStatus(0);
|
|
|
} else {
|
|
|
throw new BusinessException("定时时间需大于五分钟!");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ rp.setIsRegularlySend(0);
|
|
|
+ }
|
|
|
+ //rp.setReportStatus(pmWorkReport.getReportStatus());
|
|
|
+ rp.setSendDingTalk(pmWorkReport.getSendDingTalk());
|
|
|
+ pmWorkReportMapper.updateById(rp);
|
|
|
+ LambdaQueryWrapper<PmWorkContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(PmWorkContent::getReportId, PmWorkContent::getSubmitterId, PmWorkContent::getCreateBy, PmWorkContent::getCreateTime, PmWorkContent::getDeptId, PmWorkContent::getTenantId)
|
|
|
+ .eq(PmWorkContent::getReportId, pmWorkReport.getId())
|
|
|
+ .last("LIMIT 1");
|
|
|
+ PmWorkContent f = pmWorkContentMapper.selectOne(queryWrapper);
|
|
|
+ pmWorkContentService.deleteContent(pmWorkReport.getId());
|
|
|
+ List<PmWorkContent> contents = pmWorkReport.getWorkContents();
|
|
|
+ List<PmWorkContent> contentsList = new ArrayList<>();
|
|
|
+ for (PmWorkContent e : contents) {
|
|
|
+ e.setReportId(f.getReportId());
|
|
|
+ e.setUpdateBy(userName);
|
|
|
+ e.setUpdateTime(dateTime);
|
|
|
+ e.setSubmitterId(f.getSubmitterId());
|
|
|
+ e.setCreateTime(f.getCreateTime());
|
|
|
+ e.setCreateBy(f.getCreateBy());
|
|
|
+ e.setDeptId(f.getDeptId());
|
|
|
+ e.setTenantId(f.getTenantId());
|
|
|
+ pmWorkContentMapper.insert(e);
|
|
|
+ contentsList.add(e);
|
|
|
+ }
|
|
|
+ if (pmWorkReport.getSendDingTalk().equals(1)) {
|
|
|
+ dingTalkAndMessage.sendDingTalkDailyReport(rp, contentsList);
|
|
|
+ rp.setReportStatus(1);
|
|
|
pmWorkReportMapper.updateById(rp);
|
|
|
- LambdaQueryWrapper<PmWorkContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.select(PmWorkContent::getReportId, PmWorkContent::getSubmitterId, PmWorkContent::getCreateBy, PmWorkContent::getCreateTime, PmWorkContent::getDeptId, PmWorkContent::getTenantId)
|
|
|
- .eq(PmWorkContent::getReportId, pmWorkReport.getId())
|
|
|
- .last("LIMIT 1");
|
|
|
- PmWorkContent f = pmWorkContentMapper.selectOne(queryWrapper);
|
|
|
- pmWorkContentService.deleteContent(pmWorkReport.getId());
|
|
|
- List<PmWorkContent> contents = pmWorkReport.getWorkContents();
|
|
|
- for (PmWorkContent e : contents) {
|
|
|
- e.setReportId(f.getReportId());
|
|
|
- e.setUpdateBy(userName);
|
|
|
- e.setUpdateTime(dateTime);
|
|
|
- e.setSubmitterId(f.getSubmitterId());
|
|
|
- e.setCreateTime(f.getCreateTime());
|
|
|
- e.setCreateBy(f.getCreateBy());
|
|
|
- e.setDeptId(f.getDeptId());
|
|
|
- e.setTenantId(f.getTenantId());
|
|
|
- pmWorkContentMapper.insert(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void receiveMessages(List<Long> ids, Integer reportId) {
|
|
|
+ List<SysUser> users = pmWorkContentService.nickNames(ids);
|
|
|
+ if (ids.size() > 0) {
|
|
|
+ for (Long id : ids) {
|
|
|
+ PmReceive pmReceive = new PmReceive();
|
|
|
+ pmReceive.setReceiverId(id);
|
|
|
+ pmReceive.setReportId(reportId);
|
|
|
+ pmReceive.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ pmReceive.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
|
|
+ pmReceive.setCreateBy(SecurityUtils.getUsername());
|
|
|
+ pmReceive.setCreateTime(LocalDateTime.now());
|
|
|
+ for (SysUser user : users) {
|
|
|
+ if (user.getUserId().equals(id)) {
|
|
|
+ pmReceive.setReceiverName(user.getUserName());
|
|
|
+ }
|
|
|
}
|
|
|
+ pmReceive.setReadFlag(0);
|
|
|
+ pmReceiveMapper.insert(pmReceive);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -435,9 +474,10 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void timedSending(LocalDateTime time) {
|
|
|
+ log.info("定时报告任务开始---------------------------");
|
|
|
LambdaQueryWrapper<PmWorkReport> reports = Wrappers.lambdaQuery();
|
|
|
- reports.eq(PmWorkReport::getIsRegularlySend, 1)
|
|
|
- .eq(PmWorkReport::getReportStatus, 0)
|
|
|
+ reports.eq(PmWorkReport::getReportStatus, 0)
|
|
|
+ .eq(PmWorkReport::getIsRegularlySend, 1)
|
|
|
.le(PmWorkReport::getTimingTime, time)
|
|
|
.orderByAsc(PmWorkReport::getTimingTime);
|
|
|
List<PmWorkReport> reportList = pmWorkReportMapper.selectList(reports);
|
|
@@ -454,16 +494,28 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
List<PmWorkContent> workContents = new ArrayList<>();
|
|
|
for (PmWorkContent content : pmWorkContentList) {
|
|
|
Integer reportId = content.getReportId();
|
|
|
- if (reportId == id) {
|
|
|
+ if (reportId.equals(id)) {
|
|
|
workContents.add(content);
|
|
|
}
|
|
|
}
|
|
|
- dingTalkAndMessage.sendDingTalkDailyReport(report, workContents);
|
|
|
- dingTalkAndMessage.sendAsyncMessage(report);
|
|
|
+ try {
|
|
|
+ dingTalkAndMessage.sendAsyncMessage(report);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("定时报告" + report.getId() + "调用消息中心异常" + e);
|
|
|
+ }
|
|
|
+ if (report.getSendDingTalk() == 1) {
|
|
|
+ try {
|
|
|
+ dingTalkAndMessage.sendDingTalkDailyReport(report, workContents);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("定时报告" + report.getId() + "发送钉钉异常" + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ report.setReportStatus(1);
|
|
|
+ pmWorkReportMapper.updateById(report);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ log.info("定时报告任务结束---------------------------");
|
|
|
}
|
|
|
|
|
|
|