|
@@ -6,8 +6,10 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.usky.common.core.exception.BusinessException;
|
|
|
import com.usky.common.security.utils.SecurityUtils;
|
|
|
import com.usky.iot.domain.PmProject;
|
|
|
+import com.usky.iot.domain.PmReceive;
|
|
|
import com.usky.iot.domain.PmWorkContent;
|
|
|
import com.usky.iot.domain.PmWorkReport;
|
|
|
+import com.usky.iot.mapper.PmReceiveMapper;
|
|
|
import com.usky.iot.mapper.PmWorkContentMapper;
|
|
|
import com.usky.iot.mapper.PmWorkReportMapper;
|
|
|
import com.usky.iot.service.PmProjectService;
|
|
@@ -16,6 +18,7 @@ import com.usky.iot.service.PmWorkReportService;
|
|
|
import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
import com.usky.iot.service.vo.PmProjectWorkTimeVo;
|
|
|
import com.usky.system.RemoteMceService;
|
|
|
+import com.usky.system.domain.SysUser;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -42,6 +45,10 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMapper, PmWorkReport> implements PmWorkReportService {
|
|
|
|
|
|
+ private static final String INFO_TITLE = "报告提醒";
|
|
|
+ private static final String INFO_CONTENT = "的报告";
|
|
|
+ private static final int INFO_TYPE = 5;
|
|
|
+
|
|
|
@Autowired
|
|
|
private PmWorkContentMapper pmWorkContentMapper;
|
|
|
|
|
@@ -57,6 +64,9 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
@Autowired
|
|
|
private RemoteMceService remoteMceService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PmReceiveMapper pmReceiveMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 获取时间内工作报告
|
|
|
*
|
|
@@ -92,11 +102,13 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
.orderByDesc(PmWorkReport::getSubmitDate)
|
|
|
.last("LIMIT 1");
|
|
|
report = baseMapper.selectList(wrapper2);
|
|
|
- Integer pId = report.get(0).getId();
|
|
|
- LambdaQueryWrapper<PmWorkContent> wrapper = Wrappers.lambdaQuery();
|
|
|
- wrapper.eq(PmWorkContent::getReportId, pId);
|
|
|
- List<PmWorkContent> contents1 = pmWorkContentMapper.selectList(wrapper);
|
|
|
- report.get(0).setWorkContents(contents1);
|
|
|
+ if (!report.isEmpty()) {
|
|
|
+ Integer pId = report.get(0).getId();
|
|
|
+ LambdaQueryWrapper<PmWorkContent> wrapper = Wrappers.lambdaQuery();
|
|
|
+ wrapper.eq(PmWorkContent::getReportId, pId);
|
|
|
+ List<PmWorkContent> contents1 = pmWorkContentMapper.selectList(wrapper);
|
|
|
+ report.get(0).setWorkContents(contents1);
|
|
|
+ }
|
|
|
//固定返回七条数据,没有内容也要设置时间给前端渲染
|
|
|
LambdaQueryWrapper<PmWorkReport> queryWrapperR = Wrappers.lambdaQuery();
|
|
|
queryWrapperR.select(PmWorkReport::getId, PmWorkReport::getReportDate, PmWorkReport::getSubmitDate, PmWorkReport::getUpdateTime, PmWorkReport::getTomorrowPlan, PmWorkReport::getCoordinateWork, PmWorkReport::getCcTo)
|
|
@@ -190,25 +202,31 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void addReport(PmWorkReport pmWorkReport) {
|
|
|
+ Long deptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
|
|
|
+ String userName = SecurityUtils.getUsername();
|
|
|
+ Long userId = SecurityUtils.getUserId();
|
|
|
+ Integer tenantId = SecurityUtils.getTenantId();
|
|
|
+ LocalDateTime dateTime = LocalDateTime.now();
|
|
|
BigDecimal totalWorkTime = BigDecimal.ZERO; //计算总工时
|
|
|
- int size = pmWorkReport.getWorkContents().size();
|
|
|
- for (int p = 0; p < size; p++) {
|
|
|
- for (int q = p + 1; q < size; q++) {
|
|
|
- if (pmWorkReport.getWorkContents().get(p).getProjectId() == pmWorkReport.getWorkContents().get(q).getProjectId()) {
|
|
|
- throw new BusinessException("存在重复项目,请检查!");
|
|
|
- }
|
|
|
+ if (pmWorkReport.getWorkContents() == null) {
|
|
|
+ throw new BusinessException("报告内容不能为空,请检查!");
|
|
|
+ }
|
|
|
+ Set<Integer> projectIds2 = new HashSet<>();
|
|
|
+ for (PmWorkContent workContent : pmWorkReport.getWorkContents()) {
|
|
|
+ if (!projectIds2.add(workContent.getProjectId())) {
|
|
|
+ throw new BusinessException("存在重复项目,请检查!");
|
|
|
}
|
|
|
}
|
|
|
for (PmWorkContent a : pmWorkReport.getWorkContents()) {
|
|
|
totalWorkTime = totalWorkTime.add(a.getWorkTime());
|
|
|
}
|
|
|
//判断总工时是否超过24h
|
|
|
- BigDecimal noeDay = BigDecimal.valueOf(24);
|
|
|
- int compareResult = totalWorkTime.compareTo(noeDay);
|
|
|
- if (compareResult >= 0) {
|
|
|
+ BigDecimal maxWorkTimePerDay = BigDecimal.valueOf(24);
|
|
|
+ if (totalWorkTime.compareTo(maxWorkTimePerDay) >= 0) {
|
|
|
throw new BusinessException("一天24小时都不够你用,请检查当日总工时!");
|
|
|
- } else if (totalWorkTime == null || totalWorkTime.equals(BigDecimal.ZERO) || totalWorkTime.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- throw new BusinessException("工时不能为空!");
|
|
|
+ }
|
|
|
+ if (totalWorkTime.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ throw new BusinessException("工时必须大于零!");
|
|
|
}
|
|
|
LambdaQueryWrapper<PmWorkReport> reportWrapper = Wrappers.lambdaQuery();
|
|
|
reportWrapper.select(PmWorkReport::getId)
|
|
@@ -219,38 +237,24 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
if (pmWorkReport.getId() == null) {
|
|
|
PmWorkReport newReport = new PmWorkReport();
|
|
|
newReport.setReportDate(pmWorkReport.getReportDate());
|
|
|
- newReport.setSubmitterId(SecurityUtils.getUserId());
|
|
|
+ newReport.setSubmitterId(userId);
|
|
|
newReport.setSubmitDate(LocalDateTime.now());
|
|
|
newReport.setCcTo(pmWorkReport.getCcTo());
|
|
|
newReport.setCoordinateWork(pmWorkReport.getCoordinateWork());
|
|
|
newReport.setTomorrowPlan(pmWorkReport.getTomorrowPlan());
|
|
|
- newReport.setCreateBy(SecurityUtils.getUsername());
|
|
|
- newReport.setCreateTime(LocalDateTime.now());
|
|
|
- newReport.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
|
|
- newReport.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ newReport.setCreateBy(userName);
|
|
|
+ newReport.setCreateTime(dateTime);
|
|
|
+ newReport.setDeptId(deptId);
|
|
|
+ newReport.setTenantId(tenantId);
|
|
|
newReport.setTotalHours(totalWorkTime);
|
|
|
pmWorkReportMapper.insert(newReport);
|
|
|
//推送消息中心
|
|
|
- String nickName = SecurityUtils.getLoginUser().getSysUser().getNickName();
|
|
|
- String infoContent = nickName + "的报告";
|
|
|
- List<Long> ids = Arrays.stream(newReport.getCcTo().split(","))
|
|
|
- .map(Long::parseLong)
|
|
|
- .collect(Collectors.toList());
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.put("infoTitle", "报告提醒");
|
|
|
- jsonObject.put("infoContent", infoContent);
|
|
|
- jsonObject.put("infoType", 5);
|
|
|
- jsonObject.put("id", newReport.getId());
|
|
|
- jsonObject.put("userIds", ids);
|
|
|
- // 异步发送消息
|
|
|
- CompletableFuture.runAsync(() -> {
|
|
|
- try {
|
|
|
- // 推送消息中心
|
|
|
- remoteMceService.addMce(jsonObject.toString());
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- });
|
|
|
+ List<Long> ids = Optional.ofNullable(newReport.getCcTo())
|
|
|
+ .map(ccTo -> Arrays.stream(ccTo.split(","))
|
|
|
+ .map(Long::parseLong)
|
|
|
+ .collect(Collectors.toList()))
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
+ sendAsyncMessage(newReport, ids);
|
|
|
//获取报告中所有项目id
|
|
|
List<Integer> projectIds = new ArrayList<>();
|
|
|
for (PmWorkContent b1 : pmWorkReport.getWorkContents()) {
|
|
@@ -258,6 +262,8 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
}
|
|
|
//查出所有项目id对应项目名
|
|
|
List<PmProject> project = pmProjectService.projectName(projectIds);
|
|
|
+ //查username
|
|
|
+ List<SysUser> usersName = pmWorkContentService.nickNames(ids);
|
|
|
//将项目名重新赋值
|
|
|
for (PmWorkContent b : pmWorkReport.getWorkContents()) {
|
|
|
for (int c = 0; c < project.size(); c++) {
|
|
@@ -270,15 +276,32 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
newContent.setProjectId(b.getProjectId());
|
|
|
projectIds.add(b.getReportId());
|
|
|
newContent.setProjectName(b.getProjectName());
|
|
|
- newContent.setSubmitterId(SecurityUtils.getUserId());
|
|
|
+ newContent.setSubmitterId(userId);
|
|
|
newContent.setWorkContent(b.getWorkContent());
|
|
|
newContent.setWorkTime(b.getWorkTime());
|
|
|
- newContent.setCreateBy(SecurityUtils.getUsername());
|
|
|
- newContent.setCreateTime(LocalDateTime.now());
|
|
|
- newContent.setDeptId(SecurityUtils.getLoginUser().getSysUser().getDeptId());
|
|
|
- newContent.setTenantId(SecurityUtils.getTenantId());
|
|
|
+ newContent.setCreateBy(userName);
|
|
|
+ newContent.setCreateTime(dateTime);
|
|
|
+ newContent.setDeptId(deptId);
|
|
|
+ newContent.setTenantId(tenantId);
|
|
|
pmWorkContentMapper.insert(newContent);
|
|
|
}
|
|
|
+
|
|
|
+ for (Long id : ids) {
|
|
|
+ PmReceive pmReceive = new PmReceive();
|
|
|
+ pmReceive.setReceiverId(id);
|
|
|
+ for (SysUser user : usersName) {
|
|
|
+ if (id == user.getUserId()){
|
|
|
+ pmReceive.setReceiverName(user.getUserName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pmReceive.setReportId(newReport.getId());
|
|
|
+ pmReceive.setTenantId(tenantId);
|
|
|
+ pmReceive.setDeptId(deptId);
|
|
|
+ pmReceive.setCreateBy(userName);
|
|
|
+ pmReceive.setCreateTime(dateTime);
|
|
|
+ pmReceive.setReadFlag(0);
|
|
|
+ pmReceiveMapper.insert(pmReceive);
|
|
|
+ }
|
|
|
} else if (repeat.size() > 0) {
|
|
|
PmWorkReport rp = new PmWorkReport();
|
|
|
rp.setId(pmWorkReport.getId());
|
|
@@ -290,15 +313,13 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
rp.setTomorrowPlan(pmWorkReport.getTomorrowPlan());
|
|
|
rp.setCreateBy(pmWorkReport.getCreateBy());
|
|
|
rp.setCreateTime(pmWorkReport.getCreateTime());
|
|
|
- rp.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- rp.setUpdateTime(LocalDateTime.now());
|
|
|
+ rp.setUpdateTime(dateTime);
|
|
|
rp.setDeptId(pmWorkReport.getDeptId());
|
|
|
rp.setTenantId(pmWorkReport.getTenantId());
|
|
|
- rp.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- rp.setUpdateTime(LocalDateTime.now());
|
|
|
+ rp.setUpdateBy(userName);
|
|
|
+ rp.setUpdateTime(dateTime);
|
|
|
rp.setTotalHours(totalWorkTime);
|
|
|
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())
|
|
@@ -308,8 +329,8 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
List<PmWorkContent> contents = pmWorkReport.getWorkContents();
|
|
|
for (PmWorkContent e : contents) {
|
|
|
e.setReportId(f.getReportId());
|
|
|
- e.setUpdateBy(SecurityUtils.getUsername());
|
|
|
- e.setUpdateTime(LocalDateTime.now());
|
|
|
+ e.setUpdateBy(userName);
|
|
|
+ e.setUpdateTime(dateTime);
|
|
|
e.setSubmitterId(f.getSubmitterId());
|
|
|
e.setCreateTime(f.getCreateTime());
|
|
|
e.setCreateBy(f.getCreateBy());
|
|
@@ -320,6 +341,24 @@ public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMap
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void sendAsyncMessage(PmWorkReport newReport, List<Long> userId) {
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("infoTitle", INFO_TITLE);
|
|
|
+ jsonObject.put("infoContent", SecurityUtils.getLoginUser().getSysUser().getNickName() + INFO_CONTENT);
|
|
|
+ jsonObject.put("infoType", INFO_TYPE);
|
|
|
+ jsonObject.put("id", newReport.getId());
|
|
|
+ jsonObject.put("userIds", userId);
|
|
|
+ // 异步发送消息
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ // 推送消息中心
|
|
|
+ remoteMceService.addMce(jsonObject.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Map<String, Object>> countTime() {
|
|
|
int scale = 2;
|