|
@@ -1,19 +1,21 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.management.platform.entity.FinanceMonthlyWorktime;
|
|
|
|
-import com.management.platform.entity.User;
|
|
|
|
|
|
+import com.management.platform.entity.*;
|
|
import com.management.platform.entity.vo.TisTimeVO;
|
|
import com.management.platform.entity.vo.TisTimeVO;
|
|
-import com.management.platform.mapper.FinanceMonthlyWorktimeMapper;
|
|
|
|
-import com.management.platform.mapper.FmwDetailMapper;
|
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
|
|
|
+import com.management.platform.mapper.*;
|
|
import com.management.platform.service.FinanceMonthlyWorktimeService;
|
|
import com.management.platform.service.FinanceMonthlyWorktimeService;
|
|
|
|
+import com.management.platform.service.FmwDetailService;
|
|
import com.management.platform.task.DataCollectTask;
|
|
import com.management.platform.task.DataCollectTask;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
import org.springframework.core.ParameterizedTypeReference;
|
|
import org.springframework.http.*;
|
|
import org.springframework.http.*;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
@@ -21,9 +23,7 @@ import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -45,6 +45,17 @@ public class FinanceMonthlyWorktimeServiceImpl extends ServiceImpl<FinanceMonthl
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private ReportMapper reportMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private DepartmentMapper departmentMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ private TaskGroupMapper taskGroupMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private FmwDetailService fmwDetailService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg send(String fmwId, String timesheetDate, HttpServletRequest request) {
|
|
public HttpRespMsg send(String fmwId, String timesheetDate, HttpServletRequest request) {
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
@@ -104,4 +115,106 @@ public class FinanceMonthlyWorktimeServiceImpl extends ServiceImpl<FinanceMonthl
|
|
|
|
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getByMonth(Integer companyId, String ymonth, HttpServletRequest request) {
|
|
|
|
+ //获取该月份的数据,如果没有自动生成
|
|
|
|
+ String token = request.getHeader("token");
|
|
|
|
+ User user = userMapper.selectById(token);
|
|
|
|
+ FinanceMonthlyWorktime financeMonthlyWorktime = financeMonthlyWorktimeMapper.selectOne(new LambdaQueryWrapper<FinanceMonthlyWorktime>().eq(FinanceMonthlyWorktime::getCompanyId, companyId).eq(FinanceMonthlyWorktime::getYmonth, ymonth));
|
|
|
|
+ if(null != financeMonthlyWorktime){
|
|
|
|
+ //生成数据
|
|
|
|
+ financeMonthlyWorktime = new FinanceMonthlyWorktime();
|
|
|
|
+ financeMonthlyWorktime.setCompanyId(companyId);
|
|
|
|
+ financeMonthlyWorktime.setYmonth(ymonth);
|
|
|
|
+ financeMonthlyWorktime.setStatus(0);
|
|
|
|
+ //数据日期就是当前日期
|
|
|
|
+ financeMonthlyWorktime.setTimesheetDate(LocalDate.now());
|
|
|
|
+ financeMonthlyWorktime.setUserId(user.getId());
|
|
|
|
+ financeMonthlyWorktimeMapper.insert(financeMonthlyWorktime);
|
|
|
|
+
|
|
|
|
+ //生成明细数据
|
|
|
|
+ //获取当月的第一天和最后一天
|
|
|
|
+ LocalDate firstDayOfMonth = LocalDate.parse(ymonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
+ LocalDate lastDayOfMonth = firstDayOfMonth.withDayOfMonth(firstDayOfMonth.lengthOfMonth());
|
|
|
|
+ //查询日报数据
|
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new LambdaQueryWrapper<Department>().eq(Department::getCompanyId, user.getCompanyId()));
|
|
|
|
+ List<Project> projectList = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getCompanyId, user.getCompanyId()));
|
|
|
|
+ List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().select(User::getId, User::getName, User::getDepartmentId).eq(User::getCompanyId, user.getCompanyId()));
|
|
|
|
+ List<String> groupNameList = new ArrayList<>();
|
|
|
|
+ groupNameList.add("组装/维修工时");
|
|
|
|
+ groupNameList.add("调试工时");
|
|
|
|
+ groupNameList.add("等料工时");
|
|
|
|
+ List<Report> reportList = reportMapper.getReportProjectGroupDetailList(user.getCompanyId(), firstDayOfMonth, lastDayOfMonth, groupNameList);
|
|
|
|
+ List<Report> assistList = reportMapper.getReportProjectAssistTime(user.getCompanyId(), firstDayOfMonth, lastDayOfMonth, groupNameList);
|
|
|
|
+
|
|
|
|
+ System.out.println("reportSize==="+reportList.size());
|
|
|
|
+ List<FmwDetail> insertDataList = new ArrayList<>();
|
|
|
|
+ for (Report report : reportList) {
|
|
|
|
+ //在insertDataList中按照projectId, extraField4,extraField5进行匹配查找,有的话取出来,没有的话插入
|
|
|
|
+ Optional<FmwDetail> optional = insertDataList.stream().filter(f -> f.getProjectId().equals(report.getProjectId()) && f.getExtraField4().equals(report.getExtraField4()) && f.getExtraField5().equals(report.getExtraField5())).findFirst();
|
|
|
|
+ if (optional.isPresent()) {
|
|
|
|
+ FmwDetail fmwDetail = optional.get();
|
|
|
|
+ setFmwTime(fmwDetail, report);
|
|
|
|
+ } else {
|
|
|
|
+ FmwDetail fmwDetail = new FmwDetail();
|
|
|
|
+ fmwDetail.setFmwId(financeMonthlyWorktime.getId());
|
|
|
|
+ fmwDetail.setProjectId(report.getProjectId());
|
|
|
|
+ projectList.stream().filter(p->p.getId().equals(report.getProjectId())).findFirst().ifPresent(project -> {
|
|
|
|
+ fmwDetail.setProjectCode(project.getProjectCode());
|
|
|
|
+ });
|
|
|
|
+ fmwDetail.setExtraField4(report.getExtraField4());
|
|
|
|
+ fmwDetail.setExtraField5(report.getExtraField5());
|
|
|
|
+ fmwDetail.setDeptId(report.getDeptId());
|
|
|
|
+ departmentList.stream().filter(d->d.getDepartmentId().equals(report.getDeptId())).findFirst().ifPresent(d->{
|
|
|
|
+ fmwDetail.setDeptCode(d.getDeptCode());
|
|
|
|
+ fmwDetail.setDeptName(d.getDepartmentName());
|
|
|
|
+ });
|
|
|
|
+ setFmwTime(fmwDetail, report);
|
|
|
|
+ //从assistList中获取协作工时
|
|
|
|
+ Optional<Report> assistItemOp = assistList.stream().filter(f -> f.getProjectId().equals(report.getProjectId()) && f.getExtraField4().equals(report.getExtraField4()) && f.getExtraField5().equals(report.getExtraField5())).findFirst();
|
|
|
|
+ if (assistItemOp.isPresent()) {
|
|
|
|
+ fmwDetail.setAssistTime(assistItemOp.get().getWorkingTime());
|
|
|
|
+ }
|
|
|
|
+ insertDataList.add(fmwDetail);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println("插入数据大小=="+insertDataList.size());
|
|
|
|
+ if (insertDataList.size() > 0) {
|
|
|
|
+ fmwDetailService.saveBatch(insertDataList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //查询数据
|
|
|
|
+ List<FmwDetail> details = fmwDetailMapper.selectList(new QueryWrapper<FmwDetail>().eq("fmw_id", financeMonthlyWorktime.getId()));
|
|
|
|
+ financeMonthlyWorktime.setDetailList(details);
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.data = financeMonthlyWorktime;
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void setFmwTime(FmwDetail fmwDetail, Report report) {
|
|
|
|
+ switch (report.getGroupName()) {
|
|
|
|
+ case "组装/维修工时":
|
|
|
|
+ fmwDetail.setMaintanceTime(report.getWorkingTime());
|
|
|
|
+ break;
|
|
|
|
+ case "调试工时":
|
|
|
|
+ fmwDetail.setDebugTime(report.getWorkingTime());
|
|
|
|
+ break;
|
|
|
|
+ case "等料工时":
|
|
|
|
+ fmwDetail.setWaitingTime(report.getWorkingTime());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg setTimesheetDate(Integer id, String timesheetDate, HttpServletRequest request) {
|
|
|
|
+ FinanceMonthlyWorktime financeMonthlyWorktime = new FinanceMonthlyWorktime();
|
|
|
|
+ financeMonthlyWorktime.setId(id);
|
|
|
|
+ financeMonthlyWorktime.setTimesheetDate(LocalDate.parse(timesheetDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
|
+ financeMonthlyWorktimeMapper.updateById(financeMonthlyWorktime);
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|