|
@@ -375,6 +375,110 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportZhengBeiTimeReport(String date, HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ String[] strings = date.split("-");
|
|
|
+ int year = Integer.parseInt(strings[0]);
|
|
|
+ int month = Integer.parseInt(strings[1]);
|
|
|
+ YearMonth yearMonth = YearMonth.of((year), month);
|
|
|
+ int daysInMonth = yearMonth.lengthOfMonth();
|
|
|
+ DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ // 获取该月份的第一天
|
|
|
+ LocalDate startDate = LocalDate.of(year, month, 1);
|
|
|
+ // 获取下个月的第一天
|
|
|
+ LocalDate lastDate = startDate.with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ try {
|
|
|
+ User targetUser = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = targetUser.getCompanyId();
|
|
|
+ CompanyDingding dingding = companyDingdingMapper.selectOne(new LambdaQueryWrapper<CompanyDingding>().eq(CompanyDingding::getCompanyId, companyId));
|
|
|
+ //查找该时间段内公司的所有日报数据
|
|
|
+ List<Report> monthlyReport = reportMapper.selectList(
|
|
|
+ new QueryWrapper<Report>().select("project_id", "sum(working_time) as working_time", "create_date", "creator_id").between("create_date", startDate, lastDate)
|
|
|
+ .eq("company_id", targetUser.getCompanyId()).eq("state", 1).groupBy()
|
|
|
+ .groupBy("project_id", "create_date", "creator_id"));
|
|
|
+ //构建表头: 项目编号,项目名称,项目计划日期,日期, 员工姓名
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().select("id", "project_code", "project_name", "plan_start_date", "plan_end_date").eq("company_id", targetUser.getCompanyId()));
|
|
|
+ List<String> header = new ArrayList<>();
|
|
|
+ header.add("项目编号");
|
|
|
+ header.add("项目名称");
|
|
|
+ header.add("项目计划日期");
|
|
|
+ header.add("日期");
|
|
|
+ List<User> users = userMapper.selectList(new QueryWrapper<User>().eq("company_id", targetUser.getCompanyId()));
|
|
|
+ for (User user : users) {
|
|
|
+ header.add(user.getName());
|
|
|
+ }
|
|
|
+ DecimalFormat df = new DecimalFormat("0.0");
|
|
|
+ //构建表体
|
|
|
+ List<List<String>> body = new ArrayList<>();
|
|
|
+ body.add(header);
|
|
|
+ //按项目进行分组
|
|
|
+ Map<Integer, List<Report>> groupByProjectList = monthlyReport.stream().collect(Collectors.groupingBy(Report::getProjectId));
|
|
|
+ Iterator<Integer> it = groupByProjectList.keySet().iterator();
|
|
|
+ while (it.hasNext()) {
|
|
|
+ Integer projectId = it.next();
|
|
|
+ Project project = projectList.stream().filter(p->p.getId().equals(projectId)).findFirst().orElse(null);
|
|
|
+ if (project == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<Report> curProjectReportList = groupByProjectList.get(projectId);
|
|
|
+ //构建日期,按自然日期填充
|
|
|
+ for (int i=0;i<daysInMonth;i++){
|
|
|
+ List<String> row = new ArrayList<>();
|
|
|
+ row.add(project.getProjectCode());
|
|
|
+ row.add(project.getProjectName());
|
|
|
+ row.add((project.getPlanStartDate() != null?dtf.format(project.getPlanStartDate()):"未设置")+"至"+(project.getPlanEndDate() != null?dtf.format(project.getPlanEndDate()):"未设置"));
|
|
|
+ LocalDate curDate = startDate.plusDays(i);
|
|
|
+ row.add(dtf.format(curDate));
|
|
|
+ boolean iWorkDay = WorkDayCalculateUtils.isWorkDay(curDate);
|
|
|
+ //根据人员进行填充
|
|
|
+ for (User user : users) {
|
|
|
+ Report report = curProjectReportList.stream().filter( r->r.getCreateDate().equals(curDate) && r.getCreatorId().equals(user.getId())).findFirst().orElse(null);
|
|
|
+ if (report != null && user.getId().equals(report.getCreatorId())) {
|
|
|
+ row.add(report.getWorkingTime().toString());
|
|
|
+ } else {
|
|
|
+ row.add(iWorkDay?"0":"休");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //项目+日期 组合为一行数据
|
|
|
+ body.add(row);
|
|
|
+ }
|
|
|
+ //按项目进行合计
|
|
|
+ List<String> projectSumRow = new ArrayList<>();
|
|
|
+ projectSumRow.add("");
|
|
|
+ projectSumRow.add("项目小合计");
|
|
|
+ projectSumRow.add("");
|
|
|
+ projectSumRow.add("");
|
|
|
+ for (User user : users) {
|
|
|
+ double sum = curProjectReportList.stream().filter(r->r.getCreatorId().equals(user.getId())).mapToDouble(Report::getWorkingTime).sum();
|
|
|
+ projectSumRow.add(df.format(sum));
|
|
|
+ }
|
|
|
+ body.add(projectSumRow);
|
|
|
+ }
|
|
|
+ //全部项目的个人合计
|
|
|
+ List<String> sumRow = new ArrayList<>();
|
|
|
+ sumRow.add("");
|
|
|
+ sumRow.add("总合计");
|
|
|
+ sumRow.add("");
|
|
|
+ sumRow.add("");
|
|
|
+ for (User user : users) {
|
|
|
+ double sum = monthlyReport.stream().filter(r->r.getCreatorId().equals(user.getId())).mapToDouble(Report::getWorkingTime).sum();
|
|
|
+ sumRow.add(df.format(sum));
|
|
|
+ }
|
|
|
+ body.add(sumRow);
|
|
|
+ String fileName = "月度工时明细表"+System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ return excelExportService.exportGeneralExcelByTitleAndList(null,dingding,fileName , body, path);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg exportTimeByProjectAndEmployee(String date, HttpServletRequest request) {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|