Parcourir la source

人员工时分配统计与导出

yurk il y a 2 ans
Parent
commit
bac0107ea9

+ 21 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -5,6 +5,7 @@ import com.management.platform.entity.Project;
 import com.management.platform.service.ProjectService;
 import com.management.platform.util.HttpRespMsg;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -31,6 +32,8 @@ import java.util.List;
 public class ProjectController {
     @Autowired
     private ProjectService projectService;
+    @Value(value = "${upload.path}")
+    private String path;
     @Resource
     private HttpServletRequest request;
 
@@ -392,6 +395,24 @@ public class ProjectController {
         return projectService.exportOvertimeList(userId, projectId, startDate, endDate, request);
     }
 
+    /**
+     * 查看人员工时详情
+     * @param userId
+     * @param projectId
+     * @param startDate
+     * @param endDate
+     * @return
+     */
+    @RequestMapping("/getUserWorkingTimeList")
+    public HttpRespMsg getUserWorkingTimeList(String userId,Integer projectId,String startDate, String endDate,Integer pageIndex,Integer pageSize){
+        return projectService.getUserWorkingTimeList(userId,projectId,startDate,endDate,pageIndex,pageSize,request);
+    }
+
+    @RequestMapping("/exportUserWorkingTimeList")
+    public HttpRespMsg exportUserWorkingTimeList(String userId,Integer projectId,String startDate, String endDate){
+        return projectService.exportUserWorkingTimeList(userId,projectId,startDate,endDate,request);
+    }
+
     /**
      * 获取项目相关的维度数据列表
      * @param projectId

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ProjectMapper.java

@@ -92,4 +92,8 @@ public interface ProjectMapper extends BaseMapper<Project> {
     List<Map<String, Object>> getProjectCostGroupByCategory(Integer companyId, String startDate, String endDate, Integer projectCategoryId,String userId);
 
     List<Map<String, Object>> getProjectCostByCategory(Integer companyId, String startDate, String endDate, Integer curProjectCategoryId, String userId);
+
+    List<Map<String, Object>> getUserWorkingTimeList(String userId, Integer companyId, String startDate, String endDate, Integer projectId, Integer start, Integer size);
+
+    long findCountWithUser(String userId, Integer companyId, String startDate, String endDate, Integer projectId, Integer start,Integer size);
 }

+ 4 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ProjectService.java

@@ -131,4 +131,8 @@ public interface ProjectService extends IService<Project> {
     HttpRespMsg getTimeCostByCategory(String startDate, String endDate, String userId, HttpServletRequest request);
 
     HttpRespMsg exportTimeCostByCategory(String startDate, String endDate, Integer projectCategoryId, String userId, Boolean projectSum, Integer type, HttpServletRequest request);
+
+    HttpRespMsg getUserWorkingTimeList(String userId, Integer projectId, String startDate, String endDate, Integer pageIndex, Integer pageSize,HttpServletRequest request);
+
+    HttpRespMsg exportUserWorkingTimeList(String userId, Integer projectId, String startDate, String endDate,HttpServletRequest request);
 }

+ 56 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -34,6 +34,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.math.BigDecimal;
 import java.text.DecimalFormat;
+import java.text.NumberFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.format.DateTimeFormatter;
@@ -3025,6 +3026,61 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         return httpRespMsg;
     }
 
+    @Override
+    public HttpRespMsg getUserWorkingTimeList(String userId, Integer projectId, String startDate, String endDate, Integer pageIndex, Integer pageSize,HttpServletRequest request) {
+        //1.获取分页结果
+        Integer size=pageSize;//查询条数
+        Integer start =(pageIndex-1)*size;//limit开始
+        HttpRespMsg msg = new HttpRespMsg();
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        List<Map<String, Object>> list = projectMapper.getUserWorkingTimeList(userId, user.getCompanyId(), startDate, endDate, projectId,start,size);
+        long total=projectMapper.findCountWithUser(userId, user.getCompanyId(), startDate, endDate, projectId,null,null);
+        list.forEach(li->{
+            double isPublic = (double) li.get("isPublic");
+            double workingTime = (double) li.get("workingTime");
+            BigDecimal bdIsPublic=new BigDecimal(isPublic);
+            BigDecimal divide = bdIsPublic.divide(BigDecimal.valueOf(workingTime),2,BigDecimal.ROUND_HALF_UP);
+            NumberFormat nf = NumberFormat.getPercentInstance();
+            li.put("proportion",nf.format(divide));
+        });
+        HashMap map=new HashMap();
+        map.put("total",total);
+        map.put("result",list);
+        msg.data = map;
+        return msg;
+    }
+
+    @Override
+    public HttpRespMsg exportUserWorkingTimeList(String userId, Integer projectId, String startDate, String endDate,HttpServletRequest request) {
+        HttpRespMsg msg = new HttpRespMsg();
+        String token = request.getHeader("TOKEN");
+        User user = userMapper.selectById(token);
+        List<Map<String, Object>> list = projectMapper.getUserWorkingTimeList(userId, user.getCompanyId(), startDate, endDate, projectId,null,null);
+        String[] string={"人员","普通项目工时","公共项目工时","总工时","公共项目工时占比"};
+        List<List<String>> dataList=new ArrayList<>();
+        dataList.add(Arrays.asList(string));
+        for(Map<String,Object> item:list){
+            List<String> subList=new ArrayList<>();
+            double isPublic = (double) item.get("isPublic");
+            double workingTime = (double) item.get("workingTime");
+            BigDecimal bdIsPublic=new BigDecimal(isPublic);
+            BigDecimal divide = bdIsPublic.divide(BigDecimal.valueOf(workingTime),2,BigDecimal.ROUND_HALF_UP);
+            NumberFormat nf = NumberFormat.getPercentInstance();
+            subList.add(String.valueOf(item.get("username")));
+            subList.add(String.valueOf(item.get("unPublic")));
+            subList.add(String.valueOf(item.get("isPublic")));
+            subList.add(String.valueOf(item.get("workingTime")));
+            subList.add(String.valueOf(nf.format(divide)));
+            dataList.add(subList);
+        }
+        //生成excel文件导出
+        String fileName = "人员工时分配统计_"+System.currentTimeMillis();
+        String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , dataList, path);
+        msg.data = resp;
+        return msg;
+    }
+
 
     private List<Department> getSubDepts(Department dp, List<Department> list) {
         List<Department> collect = list.stream().filter(l -> dp.getDepartmentId().equals(l.getSuperiorId())).collect(Collectors.toList());;

+ 49 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ProjectMapper.xml

@@ -525,6 +525,55 @@
         </if>
         order by user.create_time asc, report.create_date desc
     </select>
+
+    <!--获取人员工时-->
+    <select id="getUserWorkingTimeList" resultType="java.util.Map">
+    SELECT  report.`creator_id` AS userId, user.`name` AS username,
+	ifnull(SUM(if(project.is_public=0,report.working_time,null)),0) as unPublic,
+	ifnull(SUM(if(project.is_public=1,report.working_time,null)),0) as isPublic,
+	ifnull(SUM(report.`working_time`),0) AS workingTime
+	FROM report LEFT JOIN user ON user.id = report.`creator_id`
+    left join project on project.id = report.project_id
+    WHERE
+    report.`state` = 1
+    AND report.`create_date` BETWEEN #{startDate} and #{endDate}
+    AND user.`company_id` =#{companyId}
+    <if test="userId!=null">
+        and user.id=#{userId}
+    </if>
+    <if test="projectId!=null">
+        and project.id=#{projectId}
+    </if>
+    group by user.id
+    order by user.create_time asc, report.create_date desc
+    <if test="start!=null and size!=null">
+        limit #{start},#{size}
+    </if>
+    </select>
+    <select id="findCountWithUser" resultType="java.lang.Long">
+        select count(*)
+        from (SELECT  report.`creator_id` AS userId, user.`name` AS username,
+        SUM(if(project.is_public=0,report.working_time,null)) as unPublic,
+        SUM(if(project.is_public=1,report.working_time,null)) as isPublic,
+        SUM(report.`working_time`) AS workingTime
+        FROM report LEFT JOIN user ON user.id = report.`creator_id`
+        left join project on project.id = report.project_id
+        WHERE
+        report.`state` = 1
+        AND report.`create_date` BETWEEN #{startDate} and #{endDate}
+        AND user.`company_id` =#{companyId}
+        <if test="userId!=null">
+            and user.id=#{userId}
+        </if>
+        <if test="projectId!=null">
+            and project.id=#{projectId}
+        </if>
+        group by user.id
+        order by user.create_time asc, report.create_date desc
+        <if test="start!=null and size!=null">
+            limit #{start},#{size}
+        </if>) as total
+    </select>
     <!--按照项目内的阶段名称分组统计工时-->
     <select id="getDegreeCost" resultType="java.util.Map">
         SELECT IFNULL(b.name, "未分配") as name, SUM(a.working_time) AS cost, SUM(a.cost) AS costMoney