Bladeren bron

预估工时导出修改2

yusm 1 jaar geleden
bovenliggende
commit
f617efefc6

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ReportMapper.java

@@ -201,4 +201,5 @@ public interface ReportMapper extends BaseMapper<Report> {
 
     List<Map<String, Object>> getUserWorkTimeByCategory(Integer categoryId, String userId,Integer companyId,@Param("list")List<Integer> deptIds, Integer deptId, String startDate, String endDate);
 
+    List<Map<String, Object>> selectReallyTimeWithMap(Integer companyId,Integer projectId);
 }

+ 5 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/TaskGroupMapper.java

@@ -4,6 +4,9 @@ import com.management.platform.entity.TaskGroup;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Update;
 
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  *  Mapper 接口
@@ -16,4 +19,6 @@ public interface TaskGroupMapper extends BaseMapper<TaskGroup> {
 
     @Update("update task_group set incharger_id = null where id = #{id}")
     void removeInchargerId(Integer id);
+
+    List<Map<String, Object>> selectReallyTimeWithMap(Integer companyId, Integer projectId);
 }

+ 27 - 22
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -316,8 +316,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
             project.setReallyWorkTime(rWorkTime);
             String pEstimatedWork=project.getManDay()==null ? 0*allday+"": project.getManDay()*allday+"";
             project.setEstimatedWorkTime(pEstimatedWork);
-            List<TaskGroup> taskGroupCollect = taskGroups.stream().filter(t -> t.getProjectId() == project.getId())
-                    .collect(Collectors.toList());
+            List<TaskGroup> taskGroupCollect = taskGroups.stream().filter(t -> t.getProjectId().equals(project.getId())).collect(Collectors.toList());
 
             ArrayList<GroupEstimatedWorkVO> groupEstimatedWorkVOS = new ArrayList<>();
 
@@ -2910,42 +2909,48 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         List<Integer> collectIds = selectProjects.stream().map(Project::getId).collect(Collectors.toList());
 
         //根据查询道德project列表查询总的reporeList
-        List<Report> reportList = reportMapper.selectList(new QueryWrapper<Report>()
-                .in("project_id", collectIds));
+//        List<Report> reportList = reportMapper.selectList(new QueryWrapper<Report>()
+//                .in("project_id", collectIds));
+
+        List<Map<String,Object>> reportList=reportMapper.selectReallyTimeWithMap(companyId,projectId);
         //根据查询道德project列表查询总的task_groupList
-        List<TaskGroup> taskGroups = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>()
-                .in("project_id", collectIds));
+//        List<TaskGroup> taskGroups = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>()
+//                .in("project_id", collectIds));
+        List<Map<String,Object>> taskGroups= taskGroupMapper.selectReallyTimeWithMap(companyId,projectId);
 
         DecimalFormat df = new DecimalFormat("0.00");
 
         for (Project project : selectProjects) {
-            Double reallWorkTime = reportList.stream().filter(r -> r.getProjectId() .equals( project.getId()))
-                    .mapToDouble(r->r.getWorkingTime()).sum();
-            String rWorkTime=reallWorkTime==null ? "0":df.format(reallWorkTime);
+            /*Double reallWorkTime = reportList.stream().filter(r -> r.getProjectId() .equals( project.getId()))
+                    .mapToDouble(r->r.getWorkingTime()).sum();*/
+            List<Map<String, Object>> projectIdCollect = reportList.stream().filter(l -> l.get("projectId").toString().equals(project.getId().toString())).collect(Collectors.toList());
+            if (projectIdCollect.size()<=0){
+                continue;
+            }
+            String rWorkTime= String.valueOf(projectIdCollect.get(0).get("total_working_time")) ;
             project.setReallyWorkTime(rWorkTime);
             String pEstimatedWork=project.getManDay()==null ? 0*allday+"": project.getManDay()*allday+"";
             project.setEstimatedWorkTime(pEstimatedWork);
-            List<TaskGroup> taskGroupCollect = taskGroups.stream().filter(t -> t.getProjectId() == project.getId())
-                    .collect(Collectors.toList());
+            List<Map<String, Object>> taskGroupCollect = taskGroups.stream().filter(t -> t.get("projectId").equals(project.getId())).collect(Collectors.toList());
 
             ArrayList<GroupEstimatedWorkVO> groupEstimatedWorkVOS = new ArrayList<>();
 
             if (taskGroupCollect.size()>0){
-                List<Integer> groupIds = taskGroupCollect.stream().map(TaskGroup::getId).collect(Collectors.toList());
+                List<Integer> groupIds = taskGroupCollect.stream().map(t->Integer.valueOf(t.get("taskGroupId").toString())).collect(Collectors.toList());
                 List<Report> getByProjectAndGroup = reportMapper.selectList(new QueryWrapper<Report>()
                         .eq("project_id", project.getId())
                         .in("group_id", groupIds));
-                for (TaskGroup taskGroup : taskGroupCollect) {
-                    Double gReallWorkTime = getByProjectAndGroup.stream().filter(r -> r.getGroupId().equals( taskGroup.getId()))
+                for (Map<String, Object> taskGroup : taskGroupCollect) {
+                    Double gReallWorkTime = getByProjectAndGroup.stream().filter(r -> r.getGroupId().toString().equals( taskGroup.get("taskGroupId").toString()))
                             .mapToDouble(r->r.getWorkingTime()).sum();
                     GroupEstimatedWorkVO groupEstimatedWorkVO = new GroupEstimatedWorkVO();
                     String grWorkTime=gReallWorkTime==null ? "0":gReallWorkTime+"";
-                    String gEstimatedWork=taskGroup.getManDay()==null ? 0*allday+"": taskGroup.getManDay()*allday+"";
+                    String gEstimatedWork=taskGroup.get("manDay")==null ? 0*allday+"": Double.valueOf(taskGroup.get("manDay").toString())*allday+"";
 
                     groupEstimatedWorkVO.setWorkTime(grWorkTime);
                     groupEstimatedWorkVO.setEstimatedWorkTime(gEstimatedWork);
-                    groupEstimatedWorkVO.setId(taskGroup.getId());
-                    groupEstimatedWorkVO.setGroupName(taskGroup.getName());
+                    groupEstimatedWorkVO.setId(Integer.valueOf( taskGroup.get("taskGroupId").toString()));
+                    groupEstimatedWorkVO.setGroupName(taskGroup.get("taskGroupName").toString());
 
                     groupEstimatedWorkVOS.add(groupEstimatedWorkVO);
                 }
@@ -2966,18 +2971,18 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
 
             data.add(project.getProjectName() == null?"":project.getProjectName());
             data.add(project.getGroupName() == null?"":project.getGroupName());
-            data.add(project.getEstimatedWorkTime() != null?project.getEstimatedWorkTime().toString():"");
-            data.add(project.getReallyWorkTime() != null?project.getReallyWorkTime().toString():"");
+            data.add(StringUtils.isEmpty(project.getEstimatedWorkTime()) ? "0.0":project.getEstimatedWorkTime().toString());
+            data.add(StringUtils.isEmpty(project.getReallyWorkTime())?"0.0": project.getReallyWorkTime().toString());
             exportList.add(data);
 
-            if (project.getGroupEstimatedWorkVOList().size()>0){
+            if (project.getGroupEstimatedWorkVOList()!=null&&project.getGroupEstimatedWorkVOList().size()>0){
                 List<GroupEstimatedWorkVO> groupEstimatedWorkVOList = project.getGroupEstimatedWorkVOList();
                 for (GroupEstimatedWorkVO groupEstimatedWorkVO : groupEstimatedWorkVOList) {
                     List<String> data1 = new ArrayList<>();
                     data1.add(groupEstimatedWorkVO.getProjectName() == null?"":groupEstimatedWorkVO.getProjectName());
                     data1.add(groupEstimatedWorkVO.getGroupName() == null?"":groupEstimatedWorkVO.getGroupName());
-                    data1.add(groupEstimatedWorkVO.getEstimatedWorkTime() != null?groupEstimatedWorkVO.getEstimatedWorkTime().toString():"");
-                    data1.add(groupEstimatedWorkVO.getWorkTime() != null?groupEstimatedWorkVO.getWorkTime().toString():"");
+                    data1.add(StringUtils.isEmpty(groupEstimatedWorkVO.getEstimatedWorkTime()) ? "0.0":groupEstimatedWorkVO.getEstimatedWorkTime().toString());
+                    data1.add(StringUtils.isEmpty(groupEstimatedWorkVO.getWorkTime())?"0.0": groupEstimatedWorkVO.getWorkTime().toString());
                     exportList.add(data1);
                 }
             }

+ 12 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -1146,4 +1146,16 @@
         </if>
         group by p.id,r.create_date,u.id
     </select>
+
+    <select id="selectReallyTimeWithMap" resultType="java.util.Map">
+        SELECT p.id as projectId, SUM(IFNULL(r.working_time, 0)) AS total_working_time
+        FROM report r LEFT JOIN project p ON r.project_id = p.id
+        WHERE p.company_id = #{companyId}
+              AND p.status in(1,2)
+              AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
+        <if test="projectId!=null">
+            and p.id=#{projectId}
+        </if>
+        group by p.id
+    </select>
 </mapper>

+ 13 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/TaskGroupMapper.xml

@@ -18,4 +18,17 @@
         id, project_id, task_group_code, name, incharger_id, wbs_code, man_day
     </sql>
 
+    <select id="selectReallyTimeWithMap" resultType="java.util.Map">
+        SELECT t.id as taskGroupId,p.id as projectId  ,IFNULL(t.man_day, 0) as manDay ,t.name as taskGroupName
+        FROM task_group t
+        LEFT JOIN project p
+        ON t.project_id = p.id
+        WHERE p.company_id = #{companyId}
+              AND p.status in (1,2)
+              AND (p.finish_date IS NULL OR p.finish_date >= '2023-11-08')
+              <if test="projectId!=null">
+                and p.id=#{projectId}
+              </if>
+    </select>
+
 </mapper>