Browse Source

工时报告性能优化

seyason 1 year ago
parent
commit
da4110b56c

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

@@ -92,12 +92,12 @@ public interface ReportMapper extends BaseMapper<Report> {
     List<Map<String, Object>> getReportNameByDateAndDept(@Param("date") String date,
                                                          @Param("deptIds") List<Integer> deptIds,
                                                          @Param("userId") String userId,
-                                                         @Param("companyId") Integer companyId, Integer pageStart, Integer pageSize);
+                                                         @Param("companyId") Integer companyId, String leaderId, Integer pageStart, Integer pageSize);
 
     Integer getReportNameByDateAndDeptCount(@Param("date") String date,
                                                          @Param("deptIds") List<Integer> deptIds,
                                                          @Param("userId") String userId,
-                                                         @Param("companyId") Integer companyId);
+                                                         @Param("companyId") Integer companyId, String leaderId);
     List<Map<String, Object>> getDetailByStateInMyProfession(@Param("state") Integer state,
                                                @Param("companyId") Integer companyId,
                                                @Param("leaderId") String leaderId);

+ 164 - 131
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ReportServiceImpl.java

@@ -289,151 +289,154 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                     }
                 }
 
+                String reportLeaderId = null;
+                if(deptId==null&&targetUid==null){
+                    //没有指定部门和人员,按照自己所管辖范围来查看
+                    reportLeaderId = leaderId;
+                }
                 List<Integer> allVisibleDeptIdList = getAllVisibleDeptIdList(user, null);
                 //需要看可见部门(部门主要负责人和其他负责人以及查看本部门工时权限)所有人员的日报
-                if (allVisibleDeptIdList.size() > 0) {
-                    if (nameList.size() > 0) {
-                        //自己填写的日报
-                        List<Map<String, Object>> deptNameList = reportMapper.getReportNameByDateAndDept(date,
-                                allVisibleDeptIdList, targetUid, null, pageStart, pageSize);
-                        totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, allVisibleDeptIdList, targetUid, null);
-                        for (Map<String, Object> deptNameItem : deptNameList) {
-                            if (!deptNameItem.get("id").equals(user.getId())) {
-                                nameList.add(deptNameItem);
-                            }
-                        }
-                    } else {
-                        nameList = reportMapper.getReportNameByDateAndDept(date,
-                                allVisibleDeptIdList, targetUid, null, pageStart, pageSize);
-                        totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, allVisibleDeptIdList, targetUid, null);
-                    }
-                    if (nameList.size() > 0) {
-                        List<String> userIds = new ArrayList<>();
-                        nameList.forEach(n->{
-                            String id = (String) n.get("id");
-                            userIds.add(id);
-                        });
-                        List<Map<String, Object>> reportList = reportMapper.getUserReportByDateOrId(date, userIds, null);
-                        for (Map<String, Object> memb : nameList) {
-                            //再根据人分别获取当天的报告
-                            List<Map<String, Object>> rList = new ArrayList<Map<String, Object>>();
-                            BigDecimal total = new BigDecimal(0);
-                            for (Map<String, Object> report : reportList) {
-                                if (((String)report.get("creatorId")).equals((String)memb.get("id"))) {
-                                    rList.add(report);
-                                    total = total.add((BigDecimal) report.get("cost"));
-                                }
-                            }
-                            memb.put("data", rList);
-                            memb.put("cost", total);
-                            double reportTime = 0;
-                            if (rList.size() > 0) {
-                                int state = 1;
-                                for (Map<String, Object> m : rList) {
-                                    double t = (double) m.get("time");
-                                    reportTime += t;
-
-                                    //取最低的状态
-                                    if (state == 2) {
-                                        continue;
-                                    }
-                                    if (state == 0) {
-                                        if ((int)m.get("state") == 2) {
-                                            state = 2;
-                                        } else {
-                                            continue;
-                                        }
-                                    } else {
-                                        state = (int)m.get("state");
-                                    }
-                                }
-                                memb.put("state", state);
-                            }
-                            DecimalFormat df = new DecimalFormat("0.00");
-                            memb.put("reportTime", df.format(reportTime));
+                if (nameList.size() > 0) {
+                    //自己填写的日报
+                    List<Map<String, Object>> deptNameList = reportMapper.getReportNameByDateAndDept(date,
+                            allVisibleDeptIdList.size() > 0?allVisibleDeptIdList:null, targetUid, null, reportLeaderId, pageStart, pageSize);
+                    totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, allVisibleDeptIdList.size() > 0?allVisibleDeptIdList:null, targetUid, null, reportLeaderId);
+                    for (Map<String, Object> deptNameItem : deptNameList) {
+                        if (!deptNameItem.get("id").equals(user.getId())) {
+                            nameList.add(deptNameItem);
                         }
                     }
+                } else {
+                    nameList = reportMapper.getReportNameByDateAndDept(date,
+                            allVisibleDeptIdList.size() > 0?allVisibleDeptIdList:null, targetUid, null, reportLeaderId, pageStart, pageSize);
+                    totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, allVisibleDeptIdList.size() > 0?allVisibleDeptIdList:null, targetUid, null, reportLeaderId);
                 }
-                if(deptId==null&&targetUid==null){
-                    //担任项目经理或者日报审核人,查找相关的人员的日报
-                    List<Map<String, Object>> puserNames = reportMapper.getReportNameByDate(date, user.getCompanyId(), leaderId);
-                    List<Map<String, Object>> inchargeReportList= reportMapper.getInchargeReportByDate(date, leaderId, null);
-
-                    if ((timeType.getReportAuditType() == 5 || timeType.getReportAuditType() == 6)&& timeType.getReportCc() == 1) {
-                        //存在抄送人的设置,需要把抄送人的项目相关日报也加上
-                        List<Map<String, Object>> viewUserNames = reportMapper.getCcReportNameByDate(date, user.getCompanyId(),leaderId);
-                        for (Map<String, Object> viewItem : viewUserNames) {
-                            boolean exists = false;
-                            for (Map<String, Object> u : puserNames) {
-                                if (u.get("id").equals(viewItem.get("id"))) {
-                                    exists = true;
-                                    break;
-                                }
-                            }
-                            if (!exists) {
-                                puserNames.add(viewItem);
+                if (nameList.size() > 0) {
+                    List<String> userIds = new ArrayList<>();
+                    nameList.forEach(n->{
+                        String id = (String) n.get("id");
+                        userIds.add(id);
+                    });
+                    List<Map<String, Object>> reportList = reportMapper.getUserReportByDateOrId(date, userIds, null);
+                    for (Map<String, Object> memb : nameList) {
+                        //再根据人分别获取当天的报告
+                        List<Map<String, Object>> rList = new ArrayList<Map<String, Object>>();
+                        BigDecimal total = new BigDecimal(0);
+                        for (Map<String, Object> report : reportList) {
+                            if (((String)report.get("creatorId")).equals((String)memb.get("id"))) {
+                                rList.add(report);
+                                total = total.add((BigDecimal) report.get("cost"));
                             }
                         }
+                        memb.put("data", rList);
+                        memb.put("cost", total);
+                        double reportTime = 0;
+                        if (rList.size() > 0) {
+                            int state = 1;
+                            for (Map<String, Object> m : rList) {
+                                double t = (double) m.get("time");
+                                reportTime += t;
 
-                        List<Map<String, Object>> viewReportList = reportMapper.getCcReportByDate(date, leaderId, null);
-                        for (Map<String, Object> viewItem : viewReportList) {
-                            boolean exists = false;
-                            for (Map<String, Object> u : inchargeReportList) {
-                                if (u.get("id").equals(viewItem.get("id"))) {
-                                    exists = true;
-                                    break;
+                                //取最低的状态
+                                if (state == 2) {
+                                    continue;
                                 }
-                            }
-                            if (!exists) {
-                                inchargeReportList.add(viewItem);
-                            }
-                        }
-                    }
-                    for (Map<String, Object> map2 : puserNames) {
-
-                        if (nameList.size() > 0) {
-                            String myUserId = (String)nameList.get(0).get("id");
-                            if (myUserId.equals(map2.get("id"))) {
-                                //自己的报告,之前已经添加过了,排重
-                                continue;
-                            }
-                        }
-                        List<Object> collect = nameList.stream().map(nl -> nl.get("")).collect(Collectors.toList());
-                        if(!collect.contains(map2.get("id"))){
-                            nameList.add(map2);
-                        }
-                        //再根据人分别获取当天的报告
-                        List<Map<String, Object>> list2 =
-                                inchargeReportList.stream().filter(i->i.get("creatorId").equals(map2.get("id"))).collect(Collectors.toList());
-                        map2.put("data", list2);
-
-                        double reportTime = 0;
-                        BigDecimal total = new BigDecimal(0);
-                        int state = 1;
-                        for (Map<String, Object> m : list2) {
-                            double t = (double) m.get("time");
-                            reportTime += t;
-                            total = total.add((BigDecimal)m.get("cost"));
-                            //取最低的状态
-                            if (state == 2) {
-                                continue;
-                            }
-                            if (state == 0) {
-                                if ((int)m.get("state") == 2) {
-                                    state = 2;
+                                if (state == 0) {
+                                    if ((int)m.get("state") == 2) {
+                                        state = 2;
+                                    } else {
+                                        continue;
+                                    }
                                 } else {
-                                    continue;
+                                    state = (int)m.get("state");
                                 }
-                            } else {
-                                state = (int)m.get("state");
                             }
+                            memb.put("state", state);
                         }
                         DecimalFormat df = new DecimalFormat("0.00");
-                        map2.put("reportTime", df.format(reportTime));
-                        map2.put("cost", total);
-                        map2.put("state", state);
+                        memb.put("reportTime", df.format(reportTime));
                     }
                 }
+//                if(deptId==null&&targetUid==null){
+//                    //担任项目经理或者日报审核人,查找相关的人员的日报
+//                    List<Map<String, Object>> puserNames = reportMapper.getReportNameByDate(date, user.getCompanyId(), leaderId);
+//                    List<Map<String, Object>> inchargeReportList= reportMapper.getInchargeReportByDate(date, leaderId, null);
+//
+//                    if ((timeType.getReportAuditType() == 5 || timeType.getReportAuditType() == 6)&& timeType.getReportCc() == 1) {
+//                        //存在抄送人的设置,需要把抄送人的项目相关日报也加上
+//                        List<Map<String, Object>> viewUserNames = reportMapper.getCcReportNameByDate(date, user.getCompanyId(),leaderId);
+//                        for (Map<String, Object> viewItem : viewUserNames) {
+//                            boolean exists = false;
+//                            for (Map<String, Object> u : puserNames) {
+//                                if (u.get("id").equals(viewItem.get("id"))) {
+//                                    exists = true;
+//                                    break;
+//                                }
+//                            }
+//                            if (!exists) {
+//                                puserNames.add(viewItem);
+//                            }
+//                        }
+//
+//                        List<Map<String, Object>> viewReportList = reportMapper.getCcReportByDate(date, leaderId, null);
+//                        for (Map<String, Object> viewItem : viewReportList) {
+//                            boolean exists = false;
+//                            for (Map<String, Object> u : inchargeReportList) {
+//                                if (u.get("id").equals(viewItem.get("id"))) {
+//                                    exists = true;
+//                                    break;
+//                                }
+//                            }
+//                            if (!exists) {
+//                                inchargeReportList.add(viewItem);
+//                            }
+//                        }
+//                    }
+//                    for (Map<String, Object> map2 : puserNames) {
+//
+//                        if (nameList.size() > 0) {
+//                            String myUserId = (String)nameList.get(0).get("id");
+//                            if (myUserId.equals(map2.get("id"))) {
+//                                //自己的报告,之前已经添加过了,排重
+//                                continue;
+//                            }
+//                        }
+//                        List<Object> collect = nameList.stream().map(nl -> nl.get("")).collect(Collectors.toList());
+//                        if(!collect.contains(map2.get("id"))){
+//                            nameList.add(map2);
+//                        }
+//                        //再根据人分别获取当天的报告
+//                        List<Map<String, Object>> list2 =
+//                                inchargeReportList.stream().filter(i->i.get("creatorId").equals(map2.get("id"))).collect(Collectors.toList());
+//                        map2.put("data", list2);
+//
+//                        double reportTime = 0;
+//                        BigDecimal total = new BigDecimal(0);
+//                        int state = 1;
+//                        for (Map<String, Object> m : list2) {
+//                            double t = (double) m.get("time");
+//                            reportTime += t;
+//                            total = total.add((BigDecimal)m.get("cost"));
+//                            //取最低的状态
+//                            if (state == 2) {
+//                                continue;
+//                            }
+//                            if (state == 0) {
+//                                if ((int)m.get("state") == 2) {
+//                                    state = 2;
+//                                } else {
+//                                    continue;
+//                                }
+//                            } else {
+//                                state = (int)m.get("state");
+//                            }
+//                        }
+//                        DecimalFormat df = new DecimalFormat("0.00");
+//                        map2.put("reportTime", df.format(reportTime));
+//                        map2.put("cost", total);
+//                        map2.put("state", state);
+//                    }
+//                }
             } else {
                 Integer companyId = userMapper.selectById(request.getHeader("Token")).getCompanyId();
                 List<Integer> ids = null;
@@ -456,8 +459,8 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
                     }
                 }
                 nameList = reportMapper.getReportNameByDateAndDept(date,
-                        ids, targetUid, companyId, pageStart, pageSize);
-                totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, ids, targetUid, companyId);
+                        ids, targetUid, companyId, null, pageStart, pageSize);
+                totalMembCount = reportMapper.getReportNameByDateAndDeptCount(date, ids, targetUid, companyId, null);
                 if (nameList.size() > 0) {
                     List<String> userIds = new ArrayList<>();
                     nameList.forEach(n->{
@@ -7029,6 +7032,36 @@ public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> impleme
         if (defaultDegree!=null && "-1".equals(defaultDegree.get("id").toString())){
             defaultDegree = null;
         }
+        //如果该项目已经没有绑定该维度,则取消
+        if (defaultDegree != null) {
+            Integer degreeId = (Integer) defaultDegree.get("id");
+            Integer companyId = user.getCompanyId();
+            TimeType timeType = timeTypeMapper.selectById(companyId);
+            List<ReportExtraDegree> extraDegreeList = reportExtraDegreeMapper.selectList(new QueryWrapper<ReportExtraDegree>().eq("company_id", companyId));
+            String associateDegrees = "";
+            List<String> associateDegreeList = new ArrayList<>();
+            if(timeType.getCustomDegreeWithPro()==0){
+                associateDegrees=extraDegreeList.stream().map(a->String.valueOf(a.getId())).collect(Collectors.joining(","));
+            }else {
+                Project project = projectMapper.selectById(projectId);
+                associateDegrees = project.getAssociateDegrees();
+            }
+            boolean find = false;
+            if (!StringUtils.isEmpty(associateDegrees)) {
+                String[] id = associateDegrees.split("\\,");
+                for (int i=0;i<id.length; i++) {
+                    if (id[i].equals(degreeId.toString())) {
+                        find = true;
+                        break;
+                    }
+                }
+            }
+            if (!find) {
+                //该维度已不存在,或者从项目上解绑了
+                defaultDegree = null;
+            }
+        }
+
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         httpRespMsg.data = defaultDegree;
         return httpRespMsg;

+ 21 - 6
fhKeeper/formulahousekeeper/management-platform/src/main/resources/mapper/ReportMapper.xml

@@ -670,16 +670,31 @@
         SELECT DISTINCT b.id, b.name ,a.evaluate as evaluate
         FROM report AS a
         JOIN user AS b ON a.creator_id=b.id
+        left join project on project.id = a.project_id
+        LEFT JOIN project_ccuser ON a.project_id = project_ccuser.project_id
         WHERE 1=1
         <if test="date != null and date != ''">
             AND a.create_date=#{date}
         </if>
-        <if test="deptIds != null">
-            AND b.department_id in
-            <foreach item="item" collection="deptIds" separator="," open="(" close=")" index="">
-                #{item, jdbcType=INTEGER}
-            </foreach>
-        </if>
+        <choose>
+            <when test="deptIds != null and leaderId == null">
+                AND b.department_id in
+                <foreach item="item" collection="deptIds" separator="," open="(" close=")" index="">
+                    #{item, jdbcType=INTEGER}
+                </foreach>
+            </when>
+            <!--项目负责人,日报审核人,抄送人 -->
+           <when test="deptIds != null and leaderId != null">
+               AND (b.department_id in
+               <foreach item="item" collection="deptIds" separator="," open="(" close=")" index="">
+                   #{item, jdbcType=INTEGER}
+               </foreach>
+                    OR (a.project_auditor_id = #{leaderId} or project.incharger_id = #{leaderId}) or project_ccuser.`user_id` = #{leaderId})
+           </when>
+          <when test="deptIds == null and leaderId != null">
+              and (a.project_auditor_id = #{leaderId} or project.incharger_id = #{leaderId} or project_ccuser.`user_id` = #{leaderId})
+          </when>
+        </choose>
         <if test="companyId != null">
             AND b.company_id = #{companyId}
         </if>