Reiskuchen 5 лет назад
Родитель
Сommit
79b6f77181

+ 5 - 9
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ReportController.java

@@ -106,16 +106,12 @@ public class ReportController {
     }
 
     /**
-     * 根据审核状态分页获取报告
-     * pageIndex 分页索引
-     * pageSize 分页大小
-     * state 筛选状态 -1-全部 0-未审核 1-已通过 2-未通过
-     * date 日期 可传 不传即全部
+     * 根据审核状态获取报告
+     * state 筛选状态 0-未审核 1-已通过 2-未通过
      */
-    @RequestMapping("/listByType")
-    public HttpRespMsg getListByState(@RequestParam Integer pageIndex, @RequestParam Integer pageSize,
-                                      @RequestParam Integer state, String date, HttpServletRequest request) {
-        return reportService.getListByState(pageIndex, pageSize, state, date, request);
+    @RequestMapping("/listByState")
+    public HttpRespMsg getListByState(@RequestParam Integer state, HttpServletRequest request) {
+        return reportService.getListByState(state, request);
     }
 
     /**

+ 2 - 9
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/ReportMapper.java

@@ -1,7 +1,6 @@
 package com.management.platform.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.management.platform.entity.Report;
 import org.apache.ibatis.annotations.Param;
 
@@ -23,12 +22,6 @@ public interface ReportMapper extends BaseMapper<Report> {
 
     List<Map<String, Object>> getReportNameByDate(@Param("date") String date, @Param("companyId") Integer companyId);
 
-    List<Map<String, Object>> getListByState(Page page,
-                                             @Param("state") Integer state,
-                                             @Param("companyId") Integer companyId,
-                                             @Param("date") String date);
-
-    Integer countByState(@Param("state") Integer state,
-                         @Param("companyId") Integer companyId,
-                         @Param("date") String date);
+    List<Map<String, Object>> getDetailByState(@Param("state") Integer state,
+                                               @Param("companyId") Integer companyId);
 }

+ 1 - 2
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ReportService.java

@@ -26,8 +26,7 @@ public interface ReportService extends IService<Report> {
 
     HttpRespMsg deleteReport(Integer reportId);
 
-    HttpRespMsg getListByState(Integer pageIndex, Integer pageSize, Integer state, String date,
-                               HttpServletRequest request);
+    HttpRespMsg getListByState(Integer state, HttpServletRequest request);
 
     HttpRespMsg approveReport(String id, String date, HttpServletRequest request);
 

+ 39 - 11
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -1,7 +1,6 @@
 package com.management.platform.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
@@ -219,20 +218,49 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
         return httpRespMsg;
     }
 
-    //获取报告列表
+    //按状态获取报告列表
     @Override
-    public HttpRespMsg getListByState(Integer pageIndex, Integer pageSize, Integer state, String date,
-                                      HttpServletRequest request) {
+    public HttpRespMsg getListByState(Integer state, HttpServletRequest request) {
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         try {
-            if (state == -1) {
-                state = null;
-            }
             Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
-            Map<String, Object> map = new HashMap<>();
-            map.put("records", reportMapper.getListByState(new Page<>(pageIndex, pageSize), state, companyId, date));
-            map.put("total", reportMapper.countByState(state, companyId, date));
-            httpRespMsg.data = map;
+            String userId = request.getHeader("Token");
+            User user = userMapper.selectById(userId);
+            List<Map<String, Object>> nameList = reportMapper.getDetailByState(state, companyId);
+            for (Map<String, Object> map : nameList) {
+                //再根据人分别获取当天的报告
+                List<Map<String, Object>> list = reportMapper.getReportByDate(
+                        map.get("date").toString(),
+                        (String) map.get("id"));
+                map.put("data", list);
+                double reportTime = 0;
+                if (list.size() > 0) {
+                    for (Map<String, Object> m : list) {
+                        double t = (double) m.get("time");
+                        reportTime += t;
+                    }
+                    map.put("state", list.get(0).get("state"));
+                }
+                DecimalFormat df = new DecimalFormat("0.00");
+                map.put("reportTime", df.format(reportTime));
+                //顺便再获取一下可分配时间
+                Integer calculateTime = 0;
+                //以下区间被认为是工作时间
+                Integer[] workType = {-1, 0, 1, 2, 3, 4, 5};
+                //工作时间筛选
+                List<TimeCalculation> timeCalculations = timeCalculationMapper.selectList(new QueryWrapper<TimeCalculation>()
+                        .eq("date", map.get("date").toString())
+                        .eq("user_id", map.get("id"))
+                        .in("action_type", workType));
+                if (timeCalculations != null) {
+                    for (TimeCalculation timeCalculation : timeCalculations) {
+                        calculateTime += timeCalculation.getDuration();
+                    }
+                }
+                //把总秒数转为double后换算为小时并保留两位小数
+                map.put("calculateTime", df.format((double) calculateTime / 3600));
+            }
+            httpRespMsg.data = nameList;
         } catch (NullPointerException e) {
             httpRespMsg.setError("验证失败");
             return httpRespMsg;

+ 4 - 27
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -60,34 +60,11 @@
     </select>
 
     <!--报告列表-->
-    <select id="getListByState" resultType="java.util.Map">
-        SELECT a.id, b.name AS user, c.project_name AS project, a.create_date AS date, a.working_time AS time, a.content
+    <select id="getDetailByState" resultType="java.util.Map">
+        SELECT DISTINCT b.id, b.name, a.create_date AS date
         FROM report AS a
-        LEFT JOIN user AS b ON a.creator_id=b.id
-        JOIN project AS c ON a.project_id = c.id
-        WHERE c.company_id = #{companyId}
-        <if test="state != null and state != ''">
-            AND a.state = #{state}
-        </if>
-        <if test="date != null and date != ''">
-            AND a.create_date = #{date}
-        </if>
-        ORDER BY a.id DESC
-    </select>
-
-    <!--报告列表数据-->
-    <select id="countByState" resultType="java.lang.Integer">
-        SELECT COUNT(a.id)
-        FROM report AS a
-        LEFT JOIN user AS b ON a.creator_id=b.id
-        JOIN project AS c ON a.project_id = c.id
-        WHERE c.company_id = #{companyId}
-        <if test="state != null and state != ''">
-            AND a.state = #{state}
-        </if>
-        <if test="date != null and date != ''">
-            AND a.create_date = #{date}
-        </if>
+        JOIN user AS b ON a.creator_id=b.id
+        WHERE a.state = #{state} AND b.company_id=#{companyId}
     </select>
 
 </mapper>