|
@@ -0,0 +1,242 @@
|
|
|
+package com.usky.iot.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+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.PmWorkContent;
|
|
|
+import com.usky.iot.domain.PmWorkReport;
|
|
|
+import com.usky.iot.mapper.PmProjectMapper;
|
|
|
+import com.usky.iot.mapper.PmWorkContentMapper;
|
|
|
+import com.usky.iot.mapper.PmWorkReportMapper;
|
|
|
+import com.usky.iot.service.PmProjectService;
|
|
|
+import com.usky.iot.service.PmWorkContentService;
|
|
|
+import com.usky.iot.service.PmWorkReportService;
|
|
|
+import com.usky.common.mybatis.core.AbstractCrudService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.DayOfWeek;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 工作报告表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author fu
|
|
|
+ * @since 2024-05-20
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class PmWorkReportServiceImpl extends AbstractCrudService<PmWorkReportMapper, PmWorkReport> implements PmWorkReportService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmWorkContentMapper pmWorkContentMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmWorkReportMapper pmWorkReportMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmProjectMapper pmProjectMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmProjectService pmProjectService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PmWorkContentService pmWorkContentService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取时间内工作报告
|
|
|
+ *
|
|
|
+ * @param startDate 开始时间
|
|
|
+ * @param endDate 结束时间
|
|
|
+ * @param reportId 报告id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<PmWorkReport> weekWork(String startDate, String endDate, Integer reportId) {
|
|
|
+ LocalDate startDate1 = null;
|
|
|
+ LocalDate endDate1 = null;
|
|
|
+ if (startDate == null && endDate == null) {
|
|
|
+ startDate1 = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
+ endDate1 = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
+ } else {
|
|
|
+ startDate1 = LocalDate.parse(startDate);
|
|
|
+ endDate1 = LocalDate.parse(endDate);
|
|
|
+ }
|
|
|
+ //固定返回七条数据,没有内容也要设置时间给前端渲染
|
|
|
+ List<LocalDate> dates = new ArrayList<>();
|
|
|
+ while (!startDate1.isAfter(endDate1)) {
|
|
|
+ dates.add(startDate1);
|
|
|
+ startDate1 = startDate1.plusDays(1);
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PmWorkReport> queryWrapperR = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperR.select(PmWorkReport::getId, PmWorkReport::getReportDate, PmWorkReport::getTomorrowPlan, PmWorkReport::getCoordinateWork, PmWorkReport::getCcTo)
|
|
|
+ .eq(PmWorkReport::getSubmitterId, SecurityUtils.getUserId())
|
|
|
+ .between(PmWorkReport::getReportDate, startDate, endDate)
|
|
|
+ .orderByAsc(PmWorkReport::getReportDate)
|
|
|
+ .apply(reportId != 0, "id = " + reportId);
|
|
|
+ List<PmWorkReport> reports = this.list(queryWrapperR);
|
|
|
+ if (reports.isEmpty()) {
|
|
|
+ List<PmWorkReport> reports1 = new ArrayList<>();
|
|
|
+ for (int f = 0; f < dates.size(); f++) {
|
|
|
+ List<PmWorkContent> content = new ArrayList<>();
|
|
|
+ PmWorkReport report1 = new PmWorkReport();
|
|
|
+ report1.setReportDate(dates.get(f));
|
|
|
+ report1.setWorkContents(content);
|
|
|
+ reports1.add(report1);
|
|
|
+ }
|
|
|
+ return reports1;
|
|
|
+ }
|
|
|
+ List<Integer> ids = new ArrayList<>();
|
|
|
+ for (PmWorkReport pwr : reports) {
|
|
|
+ ids.add(pwr.getId());
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<PmWorkContent> queryWrapperC = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperC.select(PmWorkContent::getId, PmWorkContent::getWorkContent, PmWorkContent::getWorkTime, PmWorkContent::getProjectId, PmWorkContent::getProjectName, PmWorkContent::getReportId)
|
|
|
+ .in(PmWorkContent::getReportId, ids)
|
|
|
+ .orderByDesc(PmWorkContent::getWorkTime);
|
|
|
+ List<PmWorkContent> contents = pmWorkContentMapper.selectList(queryWrapperC);
|
|
|
+ int a, b;
|
|
|
+ for (int i = 0; i < reports.size(); i++) {
|
|
|
+ a = reports.get(i).getId();
|
|
|
+ List<PmWorkContent> contentList = new ArrayList<>();
|
|
|
+ for (int j = 0; j < contents.size(); j++) {
|
|
|
+ b = contents.get(j).getReportId();
|
|
|
+ if (b == a) {
|
|
|
+ contentList.add(contents.get(j));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reports.get(i).setWorkContents(contentList);
|
|
|
+ }
|
|
|
+ if (reports.size() == 7 || reportId != 0) {
|
|
|
+ return reports;
|
|
|
+ }
|
|
|
+ List<PmWorkReport> reportList = new ArrayList<>();
|
|
|
+ for (int d = 0; d < dates.size(); d++) {
|
|
|
+ boolean matchFound = false;
|
|
|
+ for (int c = 0; c < reports.size(); c++) {
|
|
|
+ if (dates.get(d).isEqual(reports.get(c).getReportDate())) {
|
|
|
+ reportList.add(reports.get(c));
|
|
|
+ matchFound = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!matchFound) {
|
|
|
+ PmWorkReport newReport = new PmWorkReport();
|
|
|
+ List<PmWorkContent> newContent = new ArrayList<>();
|
|
|
+ newReport.setReportDate(dates.get(d));
|
|
|
+ newReport.setWorkContents(newContent);
|
|
|
+ reportList.add(newReport);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return reportList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增、编辑工作报告
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void addReport(PmWorkReport pmWorkReport) {
|
|
|
+ //计算总工时
|
|
|
+ BigDecimal totalWorkTime = BigDecimal.ZERO;
|
|
|
+ for (PmWorkContent a : pmWorkReport.getWorkContents()) {
|
|
|
+ totalWorkTime = totalWorkTime.add(a.getWorkTime());
|
|
|
+ }
|
|
|
+ //判断总工时是否超过24h
|
|
|
+ BigDecimal noeDay = BigDecimal.valueOf(24);
|
|
|
+ int compareResult = totalWorkTime.compareTo(noeDay);
|
|
|
+ if (compareResult >= 0) {
|
|
|
+ throw new BusinessException("一天24小时都不够你用,请检查当日总工时!");
|
|
|
+ } else if (totalWorkTime == null || totalWorkTime.equals(BigDecimal.ZERO) || totalWorkTime.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new BusinessException("工时不能为空!");
|
|
|
+ }
|
|
|
+ //判断是否携带reportId,不写带则为新增报告,携带则为编辑(更新)项目
|
|
|
+ if (pmWorkReport.getId() == null) {
|
|
|
+ PmWorkReport newReport = new PmWorkReport();
|
|
|
+ newReport.setReportDate(pmWorkReport.getReportDate());
|
|
|
+ newReport.setSubmitterId(SecurityUtils.getUserId());
|
|
|
+ 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.setTotalHours(totalWorkTime);
|
|
|
+ pmWorkReportMapper.insert(newReport);
|
|
|
+ //获取报告中所有项目id
|
|
|
+ List<Integer> projectIds = new ArrayList<>();
|
|
|
+ for (PmWorkContent b1 : pmWorkReport.getWorkContents()) {
|
|
|
+ projectIds.add(b1.getProjectId());
|
|
|
+ }
|
|
|
+ //查出所有项目id对应项目名
|
|
|
+ List<PmProject> project = pmProjectService.projectName(projectIds);
|
|
|
+ //将项目名重新赋值
|
|
|
+ for (PmWorkContent b : pmWorkReport.getWorkContents()) {
|
|
|
+ for (int c = 0; c < project.size(); c++) {
|
|
|
+ if (b.getProjectId() == project.get(c).getId()) {
|
|
|
+ b.setProjectName(project.get(c).getProjectName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PmWorkContent newContent = new PmWorkContent();
|
|
|
+ newContent.setReportId(newReport.getId());
|
|
|
+ newContent.setProjectId(b.getProjectId());
|
|
|
+ projectIds.add(b.getReportId());
|
|
|
+ newContent.setProjectName(b.getProjectName());
|
|
|
+ newContent.setSubmitterId(SecurityUtils.getUserId());
|
|
|
+ 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());
|
|
|
+ pmWorkContentMapper.insert(newContent);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PmWorkReport rp = new PmWorkReport();
|
|
|
+ rp.setId(pmWorkReport.getId());
|
|
|
+ rp.setReportDate(pmWorkReport.getReportDate());
|
|
|
+ rp.setSubmitterId(pmWorkReport.getSubmitterId());
|
|
|
+ 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.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ rp.setUpdateTime(LocalDateTime.now());
|
|
|
+ rp.setDeptId(pmWorkReport.getDeptId());
|
|
|
+ rp.setTenantId(pmWorkReport.getTenantId());
|
|
|
+ rp.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ rp.setUpdateTime(LocalDateTime.now());
|
|
|
+ pmWorkReportMapper.updateById(rp);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<PmWorkContent> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.select(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.setUpdateBy(SecurityUtils.getUsername());
|
|
|
+ e.setUpdateTime(LocalDateTime.now());
|
|
|
+ e.setSubmitterId(f.getSubmitterId());
|
|
|
+ e.setCreateTime(f.getCreateTime());
|
|
|
+ e.setCreateBy(f.getCreateBy());
|
|
|
+ e.setDeptId(f.getDeptId());
|
|
|
+ e.setTenantId(f.getTenantId());
|
|
|
+ pmWorkContentMapper.insert(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|