Browse Source

审核模式为2,先分组后项目经理审核的模式下,变更项目经理时把待审核日报的审核人也变过来。

seyason 2 years ago
parent
commit
2a6dcbb523

+ 105 - 68
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -538,6 +538,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                 }
             }
         }
+        boolean inchargerChanged = false;
+        String oldInchargerId = null;
         if (id == null) {
             //新增项目
             if (name == null) {
@@ -683,6 +685,10 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                 httpRespMsg.setError(MessageUtils.message("project.submitFailByNoRepeat"));
             } else {
                 Project project = projectMapper.selectById(id);
+                if (inchargerId != null && !inchargerId.equals(project.getInchargerId())) {
+                    inchargerChanged = true;
+                    oldInchargerId = project.getInchargerId();
+                }
                 Project p = new Project();
                 p.setProjectName(name).setId(id).setCompanyId(companyId).setProjectCode(code).setInchargerId(inchargerId)
                         .setLevel(level)
@@ -930,59 +936,73 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
                     }
                 }
             } else {
-                //提取变化的部分
-                List<ProjectAuditor> oldAuditorList = projectAuditorMapper.selectList(new QueryWrapper<ProjectAuditor>().eq("project_id", id));
-                List<ProjectAuditor> newList = new ArrayList<>();
-                String firstAuditorId = null;
-                if (auditorIds.size() > 0) {
-                    firstAuditorId = auditorIds.get(0);
-                    List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", auditorIds));
-                    System.out.println("有auditor===");
-                    List<User> newUserList = userList.stream()
-                                .filter(u->!oldAuditorList.stream().anyMatch(old->old.getAuditorId().equals(u.getId())))
-                                .collect(Collectors.toList());
-                    if (newUserList.size() > 0) {
-                        for (User u : newUserList) {
-                            ProjectAuditor a = new ProjectAuditor();
-                            a.setProjectId(id);
-                            a.setAuditorId(u.getId());
-                            a.setAuditorName(u.getName());
-                            newList.add(a);
-                        }
-                        projectAuditorService.saveBatch(newList);
-                    }
-                    //检查有没有需要删除的
-                    List<ProjectAuditor> deleteList = oldAuditorList.stream()
-                            .filter(old->!userList.stream().anyMatch(u->u.getId().equals(old.getAuditorId())))
-                            .collect(Collectors.toList());
-
-                    if (deleteList.size() > 0) {
-                        projectAuditorService.removeByIds(deleteList.stream().map(ProjectAuditor::getId).collect(Collectors.toList()));
-                    }
-                    if (newList.size() == 0 && deleteList.size() == oldAuditorList.size()) {
-                        //全部被删除了的情况,保留项目负责人
-                        if (!StringUtils.isEmpty(inchargerId)) {
-                            ProjectAuditor auditor = new ProjectAuditor();
-                            auditor.setProjectId(id);
-                            auditor.setAuditorId(inchargerId);
-                            auditor.setAuditorName(userMapper.selectById(inchargerId).getName());
-                            projectAuditorMapper.insert(auditor);
-                        }
-                    }
-                    //检查日报,如果有删除的审核人的正在审核的日报,要更新审核人为当前的第一个人
-                    Report updateItem = new Report();
-                    if (deleteList.size() > 0 && firstAuditorId != null) {
-                        updateItem.setProjectAuditorId(firstAuditorId);
-                        List<String> collect = deleteList.stream().map(ProjectAuditor::getAuditorId).collect(Collectors.toList());
+                //针对reportAuditType=2(先任务分组负责人审核再项目经理审核的情况),如果项目经理变更,需要把老项目经理负责的日报变成新项目经理负责
+                if (timeType.getReportAuditType() == 2) {
+                    if (inchargerChanged && oldInchargerId != null) {
+                        Report updateItem = new Report();
+                        updateItem.setProjectAuditorId(inchargerId);
                         reportMapper.update(updateItem, new QueryWrapper<Report>()
                                 .eq("company_id", companyId)
-                                .in("project_auditor_id", collect)
+                                .eq("project_auditor_id", oldInchargerId)
                                 .eq("state", 0)
+                                .eq("group_audit_state", 1)//任务分组已审核,当前是项目经理审核
                                 .eq("project_id", id));
                     }
                 } else {
-                    //清空
-                    projectAuditorMapper.delete(new QueryWrapper<ProjectAuditor>().eq("project_id", id));
+                    //其他审核情况,提取变化的部分
+                    List<ProjectAuditor> oldAuditorList = projectAuditorMapper.selectList(new QueryWrapper<ProjectAuditor>().eq("project_id", id));
+                    List<ProjectAuditor> newList = new ArrayList<>();
+                    String firstAuditorId = null;
+                    if (auditorIds.size() > 0) {
+                        firstAuditorId = auditorIds.get(0);
+                        List<User> userList = userMapper.selectList(new QueryWrapper<User>().in("id", auditorIds));
+                        System.out.println("有auditor===");
+                        List<User> newUserList = userList.stream()
+                                .filter(u->!oldAuditorList.stream().anyMatch(old->old.getAuditorId().equals(u.getId())))
+                                .collect(Collectors.toList());
+                        if (newUserList.size() > 0) {
+                            for (User u : newUserList) {
+                                ProjectAuditor a = new ProjectAuditor();
+                                a.setProjectId(id);
+                                a.setAuditorId(u.getId());
+                                a.setAuditorName(u.getName());
+                                newList.add(a);
+                            }
+                            projectAuditorService.saveBatch(newList);
+                        }
+                        //检查有没有需要删除的
+                        List<ProjectAuditor> deleteList = oldAuditorList.stream()
+                                .filter(old->!userList.stream().anyMatch(u->u.getId().equals(old.getAuditorId())))
+                                .collect(Collectors.toList());
+
+                        if (deleteList.size() > 0) {
+                            projectAuditorService.removeByIds(deleteList.stream().map(ProjectAuditor::getId).collect(Collectors.toList()));
+                        }
+                        if (newList.size() == 0 && deleteList.size() == oldAuditorList.size()) {
+                            //全部被删除了的情况,保留项目负责人
+                            if (!StringUtils.isEmpty(inchargerId)) {
+                                ProjectAuditor auditor = new ProjectAuditor();
+                                auditor.setProjectId(id);
+                                auditor.setAuditorId(inchargerId);
+                                auditor.setAuditorName(userMapper.selectById(inchargerId).getName());
+                                projectAuditorMapper.insert(auditor);
+                            }
+                        }
+                        //检查日报,如果有删除的审核人的正在审核的日报,要更新审核人为当前的第一个人
+                        Report updateItem = new Report();
+                        if (deleteList.size() > 0 && firstAuditorId != null) {
+                            updateItem.setProjectAuditorId(firstAuditorId);
+                            List<String> collect = deleteList.stream().map(ProjectAuditor::getAuditorId).collect(Collectors.toList());
+                            reportMapper.update(updateItem, new QueryWrapper<Report>()
+                                    .eq("company_id", companyId)
+                                    .in("project_auditor_id", collect)
+                                    .eq("state", 0)
+                                    .eq("project_id", id));
+                        }
+                    } else {
+                        //清空
+                        projectAuditorMapper.delete(new QueryWrapper<ProjectAuditor>().eq("project_id", id));
+                    }
                 }
             }
         }
@@ -7988,6 +8008,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
     public HttpRespMsg batchExchangeIncharger(String projectIds, String inchargerId, HttpServletRequest request) {
         HttpRespMsg httpRespMsg=new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("token"));
+        TimeType timeType = timeTypeMapper.selectById(user.getCompanyId());
         String[] split = projectIds.split(",");
         List<String> stringlist = Arrays.asList(split);
         List<Integer> list=new ArrayList<>();
@@ -7997,28 +8018,44 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
         List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().in("id", list));
         List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().in("project_id", list));
         for (Project project : projectList) {
-            project.setInchargerId(inchargerId);
-            if(projectMapper.updateById(project)<=0){
-                //httpRespMsg.setError("操作失败");
-                httpRespMsg.setError(MessageUtils.message("other.operationFail"));
-                return httpRespMsg;
-            }
-            boolean b = participationList.stream().anyMatch(pl -> pl.getProjectId().equals(project.getId()) && pl.getUserId().equals(inchargerId));
-            //项目经理不在参与人当中时 要添加
-            if(!b){
-                Participation participation=new Participation();
-                participation.setProjectId(project.getId());
-                participation.setUserId(inchargerId);
-                participationMapper.insert(participation);
+            String oldInchargerId = project.getInchargerId();
+            if (!inchargerId.equals(oldInchargerId)) {
+                project.setInchargerId(inchargerId);
+                if(projectMapper.updateById(project)<=0){
+                    //httpRespMsg.setError("操作失败");
+                    httpRespMsg.setError(MessageUtils.message("other.operationFail"));
+                    return httpRespMsg;
+                }
+                boolean b = participationList.stream().anyMatch(pl -> pl.getProjectId().equals(project.getId()) && pl.getUserId().equals(inchargerId));
+                //项目经理不在参与人当中时 要添加
+                if(!b){
+                    Participation participation=new Participation();
+                    participation.setProjectId(project.getId());
+                    participation.setUserId(inchargerId);
+                    participationMapper.insert(participation);
+                }
+                OperationRecord operationRecord=new OperationRecord();
+                operationRecord.setOperatorName(user.getName());
+                operationRecord.setProjectName(project.getProjectName());
+                operationRecord.setCompanyId(project.getCompanyId());
+                operationRecord.setOperationTime(LocalDateTime.now());
+                operationRecord.setContent("批量操作:[设置项目负责人为:"+inchargerId+"]");
+                operationRecord.setModuleName("项目管理");
+                operationRecordService.save(operationRecord);
+                //针对reportAuditType=2(先任务分组负责人审核再项目经理审核的情况),如果项目经理变更,需要把老项目经理负责的日报变成新项目经理负责
+                if (timeType.getReportAuditType() == 2) {
+                    if (oldInchargerId != null) {
+                        Report updateItem = new Report();
+                        updateItem.setProjectAuditorId(inchargerId);
+                        reportMapper.update(updateItem, new QueryWrapper<Report>()
+                                .eq("company_id", timeType.getCompanyId())
+                                .eq("project_auditor_id", oldInchargerId)
+                                .eq("state", 0)
+                                .eq("group_audit_state", 1)//任务分组已审核,当前是项目经理审核
+                                .eq("project_id", project.getId()));
+                    }
+                }
             }
-            OperationRecord operationRecord=new OperationRecord();
-            operationRecord.setOperatorName(user.getName());
-            operationRecord.setProjectName(project.getProjectName());
-            operationRecord.setCompanyId(project.getCompanyId());
-            operationRecord.setOperationTime(LocalDateTime.now());
-            operationRecord.setContent("批量操作:[设置项目负责人为:"+inchargerId+"]");
-            operationRecord.setModuleName("项目管理");
-            operationRecordService.save(operationRecord);
         }
         return httpRespMsg;
     }

+ 1 - 2
fhKeeper/formulahousekeeper/timesheet/src/views/project/list.vue

@@ -395,10 +395,9 @@
             </template>
             <template v-if="(showColumnWidth != '0' || permissions.projectManagement)">
                 <el-button size="small" type="primary" @click="addProPreson()">{{ $t('projectparticipantsinbatches') }}</el-button>
-                <el-button size="small" type="primary" @click="batchIncharger()">{{ $t('projectmanagersinbatches') }}</el-button>
+                <el-button size="small" type="primary" v-if="permissions.projectManagement" @click="batchIncharger()">{{ $t('projectmanagersinbatches') }}</el-button>
                 <!-- <el-button size="small" type="primary" @click="batchDelete()">批量删除</el-button> -->
             </template>
-                
             
             <el-pagination
                 @size-change="handleSizeChange"