소스 검색

新增获取项目打卡月份数据表

anderx 1 년 전
부모
커밋
86e6b06532

+ 10 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ProjectTaskController.java

@@ -464,13 +464,7 @@ public class ProjectTaskController extends BaseController {
     }
 
 
-    /**
-     * 获取项目对应打卡月份
-     */
-    @GetMapping("/allProjectMonthData")
-    public AjaxResult getAllProjectMonth(){
-        return AjaxResult.success(projectStaffRecordService.getAllProjectMonth());
-    }
+
 
     /**
      * 获取项目月份打卡数据
@@ -482,4 +476,13 @@ public class ProjectTaskController extends BaseController {
     public void getMonthClockExport(@RequestParam("id") Integer id,@RequestParam("yearMonth") String yearMonth,HttpServletResponse response){
         projectStaffRecordService.getMonthClockExport(id,yearMonth,response);
     }
+
+
+    /**
+     * 获取项目对应打卡月份
+     */
+    @GetMapping("/allProjectMonthData")
+    public AjaxResult getAllProjectMonth(){
+        return AjaxResult.success(projectStaffRecordService.getAllProjectMonth());
+    }
 }

+ 55 - 0
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/OutMontClockBo.java

@@ -0,0 +1,55 @@
+package com.ruoyi.common.core.domain;
+
+import java.util.List;
+import java.util.Map;
+
+public class OutMontClockBo {
+
+    private String tableName;
+    private String projectName;
+    private String departmentName;
+    private String companyName;
+    private List<Map<String,Object>> list;
+
+
+
+    public String getTableName() {
+        return tableName;
+    }
+
+    public void setTableName(String tableName) {
+        this.tableName = tableName;
+    }
+
+    public String getProjectName() {
+        return projectName;
+    }
+
+    public void setProjectName(String projectName) {
+        this.projectName = projectName;
+    }
+
+    public String getDepartmentName() {
+        return departmentName;
+    }
+
+    public void setDepartmentName(String departmentName) {
+        this.departmentName = departmentName;
+    }
+
+    public String getCompanyName() {
+        return companyName;
+    }
+
+    public void setCompanyName(String companyName) {
+        this.companyName = companyName;
+    }
+
+    public List<Map<String, Object>> getList() {
+        return list;
+    }
+
+    public void setList(List<Map<String, Object>> list) {
+        this.list = list;
+    }
+}

+ 7 - 6
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java

@@ -24,6 +24,8 @@ import java.util.Set;
 import java.util.UUID;
 import java.util.stream.Collectors;
 import javax.servlet.http.HttpServletResponse;
+
+import com.ruoyi.common.core.domain.OutMontClockBo;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.RegExUtils;
 import org.apache.commons.lang3.reflect.FieldUtils;
@@ -1840,9 +1842,8 @@ public class ExcelUtil<T>
         return method;
     }
 
-    public void exportProjectMonthClockExcel(HttpServletResponse response,List<Map<String, Object>> listData, String projectName, String departmentName, String companyName,
-                                             Integer year,Integer month) {
-        title=StringUtils.format("{}年{}月工时记录表",year,month);
+    public void exportProjectMonthClockExcel(HttpServletResponse response, OutMontClockBo out) {
+        title=out.getTableName();
         sheetName="tab1";
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         response.setCharacterEncoding("utf-8");
@@ -1851,14 +1852,14 @@ public class ExcelUtil<T>
         wb.setSheetName(0, sheetName);
         this.styles = createProjectStyles(wb);
         sheet.setColumnWidth(0, 16*256);
-        Map<String, Object> stringObjectMap = listData.get(0);
+        Map<String, Object> stringObjectMap = out.getList().get(0);
         List<Map<String, Object>> map =  (List<Map<String, Object>>) stringObjectMap.get("data");
         try
         {
             addTitle(map.size());
-            addSubHead(map.size(),projectName,departmentName,companyName);
+            addSubHead(map.size(),out.getProjectName(),out.getDepartmentName(),out.getCompanyName());
             addTable(map);
-            addTableDuration(listData);
+            addTableDuration( out.getList());
             wb.write(response.getOutputStream());
         }
         catch (Exception e)

+ 2 - 2
ruoyi-system/src/main/java/com/ruoyi/project/service/ProjectStaffRecordService.java

@@ -1,6 +1,7 @@
 package com.ruoyi.project.service;
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.OutMontClockBo;
 import com.ruoyi.project.bo.ProjectStaffRecordInput;
 import com.ruoyi.project.bo.ProjectStaffRecordOut;
 import com.ruoyi.project.bo.batchExamineRecordInput;
@@ -9,7 +10,6 @@ import com.ruoyi.project.domain.ProjectStaffRecordLog;
 
 import javax.servlet.http.HttpServletResponse;
 import java.util.List;
-import java.util.Map;
 
 public interface ProjectStaffRecordService {
     AjaxResult add(ProjectStaffRecord in);
@@ -43,7 +43,7 @@ public interface ProjectStaffRecordService {
 
     void mateUserRecord(ProjectStaffRecordInput in);
 
-    List<Map<String,Object>> getMonthClock(Integer id, String yearMonth);
+    OutMontClockBo getMonthClock(Integer id, String yearMonth);
 
     void getMonthClockExport(Integer id, String yearMonth, HttpServletResponse response);
 

+ 26 - 24
ruoyi-system/src/main/java/com/ruoyi/project/service/impl/ProjectStaffRecordServiceImpl.java

@@ -1,8 +1,8 @@
 package com.ruoyi.project.service.impl;
 
-import com.mchange.v2.lang.SystemUtils;
 import com.ruoyi.common.config.RuoYiConfig;
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.domain.OutMontClockBo;
 import com.ruoyi.common.core.domain.entity.SysDept;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.core.domain.model.LoginUser;
@@ -14,10 +14,7 @@ import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanValidators;
 import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.project.bo.MyMonthDays;
-import com.ruoyi.project.bo.ProjectStaffRecordInput;
-import com.ruoyi.project.bo.ProjectStaffRecordOut;
-import com.ruoyi.project.bo.batchExamineRecordInput;
+import com.ruoyi.project.bo.*;
 import com.ruoyi.project.domain.ProjectStaffRecord;
 import com.ruoyi.project.domain.ProjectStaffRecordLog;
 import com.ruoyi.project.domain.ProjectTask;
@@ -35,7 +32,6 @@ import org.apache.commons.io.IOUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.core.parameters.P;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -776,12 +772,23 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
     }
 
     @Override
-    public List<Map<String,Object>> getMonthClock(Integer id, String yearMonth) {
-        yearMonth=yearMonth+"-01";
-        LocalDate startDate =  LocalDate.parse(yearMonth, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+    public OutMontClockBo getMonthClock(Integer id, String yearMonth) {
+        OutMontClockBo out = new OutMontClockBo();
+        ProjectTask projectTask = getProjectTask(id);
+        SysDept sysDept = deptService.selectDeptByPid(projectTask.getId());
+        out.setProjectName(projectTask.getName());
+        out.setDepartmentName(sysDept.getDeptName());
+        if (sysDept.getCompanyName()!=null){
+            out.setCompanyName(sysDept.getCompanyName());
+        }else {
+            out.setCompanyName(sysDept.getDeptName());
+        }
+        String dateYMD=yearMonth+"-01";
+        LocalDate startDate =  LocalDate.parse(dateYMD, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
         startDate=startDate.withDayOfMonth(1);
         int year=startDate.getYear();
         int month=startDate.getMonthValue();
+        out.setTableName(year+"年"+month+"月工时记录表");
         int lastMonth = month;
         if(startDate.getMonthValue()== Month.DECEMBER.getValue()){
             lastMonth=1;
@@ -794,6 +801,7 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
 //        monthClock = monthClock.stream().filter(e -> e.getAid() == 48).collect(Collectors.toList());
         LocalDate lastDay = startDate.with(TemporalAdjusters.lastDayOfMonth());
         List<Map<String,Object>> listData = new ArrayList<>();
+
         //将数据与表头匹配
         for (ProjectStaffRecord e : monthClock) {
             //先匹配是否存在这个人,不存证则需要新增
@@ -839,26 +847,20 @@ public class ProjectStaffRecordServiceImpl implements ProjectStaffRecordService
         }
         //将数据统计,计算出所有工时与分摊率
         pushDurationAndProportion(listData);
-        return listData;
+        out.setList(listData);
+        return out;
+    }
+
+    private ProjectTask getProjectTask(Integer id) {
+        ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(Long.valueOf(id));
+        return projectTask;
     }
 
     @Override
     public void getMonthClockExport(Integer id, String yearMonth, HttpServletResponse response) {
-        ProjectTask projectTask = projectTaskMapper.selectByPrimaryKey(Long.valueOf(id));
-        SysDept sysDept = deptService.selectDeptByPid(projectTask.getId());
-        String projectName=projectTask.getName();
-        String departmentName=sysDept.getDeptName();
-        String companyName=sysDept.getCompanyName();
-        if (sysDept.getCompanyId()==null){
-            companyName=sysDept.getDeptName();
-        }
-        LocalDate startDate =  LocalDate.parse(yearMonth, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-        startDate=startDate.withDayOfMonth(1);
-        int year=startDate.getYear();
-        int month=startDate.getMonthValue();
-        List<Map<String, Object>> listData = getMonthClock(id, yearMonth);
+        OutMontClockBo out = getMonthClock(id, yearMonth);
         ExcelUtil<Object> util = new ExcelUtil<>(Object.class);
-        util.exportProjectMonthClockExcel(response,listData, projectName, departmentName, companyName, year,month);
+        util.exportProjectMonthClockExcel(response,out);
     }
 
     @Override