Explorar el Código

项目参与人自动修复

QuYueTing hace 3 días
padre
commit
abff85220c

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

@@ -1331,120 +1331,6 @@ public class ProjectController {
         return projectService.exportFTEData(monthStart,monthEnd,area,departmentId,request);
     }
 
-    @RequestMapping("/syncProjectWithFanwei")
-    public HttpRespMsg syncProjectWithFanwei(HttpServletRequest request){
-        User user = userMapper.selectById(request.getHeader("token"));
-        HttpRespMsg httpRespMsg=new HttpRespMsg();
-        String url="http://10.1.10.51:20175/api/cube/restful/interface/getModeDataPageList/getProejct";
-        JSONObject jsonObject=new JSONObject();
-        jsonObject.put("rybh","");
-        jsonObject.put("workDate","");
-        String jsonString = jsonObject.toJSONString();
-        HttpRespMsg result = DockWithMLD.getResult(url, null);
-        List<Map<String,Object>> dataList= (List<Map<String, Object>>) result.data;
-        List<Project> workTimeProjectList = projectService.list(new QueryWrapper<Project>().eq("company_id", 876).select("project_code","id"));
-//        List<Map<String, Object>> mapList = dataList.stream().filter(dl ->!dl.get("xmdm").equals("")&&
-//                !workTimeProjectList.stream().anyMatch(wl->wl.getProjectCode()!=null&&!wl.getProjectCode().equals("")&&wl.getProjectCode().equals(dl.get("xmdm")))).collect(Collectors.toList());
-        List<Map<String, Object>> mapList = dataList;
-        List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", 876).select("job_number", "id","name"));
-        int insert=0;
-        int update=0;
-        StringBuilder sb=new StringBuilder();
-        sb.append("更新的项目:");
-        for (Map<String, Object> map : mapList) {
-            List<Participation> participationList=new ArrayList<>();
-            Optional<User> first = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(map.get("xmfzrplxm"))).findFirst();
-            if(workTimeProjectList.stream().anyMatch(wl->wl.getProjectCode()!=null&&wl.getProjectCode().equals(map.get("xmdm")))){
-                Optional<Project> project = workTimeProjectList.stream().filter(wl -> wl.getProjectCode() != null && wl.getProjectCode().equals(map.get("xmdm"))).findFirst();
-                if(project.isPresent()){
-                    Project item = project.get();
-                    item.setFromOutside(1);
-                    item.setProjectName(String.valueOf(map.get("xmmc")));
-                    if(first.isPresent()){
-                        item.setInchargerId(first.get().getId())
-                                .setInchargerName(first.get().getName());
-                    }
-                    boolean isUpdate=false;
-                    if(!item.getInchargerId().equals(first.get().getId())){
-                        update++;
-                        isUpdate=true;
-                    }
-                    projectService.updateById(item);
-                    List<Participation> allParticipations = participationService.list(new QueryWrapper<Participation>().eq("project_id", item.getId()));
-                    if(map.get("xmcygs")!=null&&!map.get("xmcygs").equals("")){
-                        participationService.remove(new QueryWrapper<Participation>().eq("project_id",item.getId()));
-                        String participations = String.valueOf(map.get("xmcygs"));
-                        List<String> list = Arrays.asList(participations.split(","));
-                        for (String s : list) {
-                            Optional<User> participation = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(s)).findFirst();
-                            if(participation.isPresent()){
-                                Participation p=new Participation();
-                                p.setUserId(participation.get().getId()).setProjectId(item.getId());
-                                participationList.add(p);
-                            }
-                        }
-                        List<String> collect = allParticipations.stream().map(al -> al.getUserId()).distinct().collect(Collectors.toList());
-                        List<String> collect1 = participationList.stream().map(pl -> pl.getUserId()).distinct().collect(Collectors.toList());
-                        System.out.println("之前的数据:"+collect);
-                        System.out.println("之后的数据:"+collect1);
-                        if(collect.size()!=collect1.size()){
-                            sb.append("["+item.getProjectName()+"/"+item.getProjectCode()+"]"+"\n");
-                            if(!isUpdate){
-                                update++;
-                            }
-                        }else if(!collect.containsAll(collect1)){
-                            sb.append("["+item.getProjectName()+"/"+item.getProjectCode()+"]"+"\n");
-                            if(!isUpdate){
-                                update++;
-                            }
-                        }
-                    }
-                    if(participationList.size()>0){
-                        participationService.saveBatch(participationList);
-                    }
-                }
-            }else {
-                Project project=new Project();
-                project.setProjectName(String.valueOf(map.get("xmmc")))
-                        .setProjectCode(String.valueOf(map.get("xmdm")))
-                        .setCompanyId(876)
-                        .setCreateDate(LocalDate.now())
-                        .setFromOutside(1);
-                if(first.isPresent()){
-                    project.setInchargerId(first.get().getId())
-                            .setInchargerName(first.get().getName());
-                }
-                projectService.save(project);
-                insert++;
-                if(map.get("xmcygs")!=null&&!map.get("xmcygs").equals("")){
-                    String participations = String.valueOf(map.get("xmcygs"));
-                    List<String> list = Arrays.asList(participations.split(","));
-                    for (String s : list) {
-                        Optional<User> participation = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(s)).findFirst();
-                        if(participation.isPresent()){
-                            Participation p=new Participation();
-                            p.setUserId(participation.get().getId()).setProjectId(project.getId());
-                            participationList.add(p);
-                        }
-                    }
-                }
-                if(participationList.size()>0){
-                    participationService.saveBatch(participationList);
-                }
-            }
-        }
-        OperationRecord operationRecord=new OperationRecord();
-        operationRecord.setCompanyId(876)
-                       .setContent("同步新增来自泛微的项目数据,共"+insert+"条数据"+"\n"+"同步更新来自泛微的项目数据,共"+update+"条数据"+"\n"+sb.toString())
-                       .setModuleName("项目管理").setOperationTime(LocalDateTime.now())
-                       .setOperatorName(user.getName());
-        if(operationRecord.getContent().length()>1000){
-            operationRecord.setContent(operationRecord.getContent().substring(0,999));
-        }
-        operationRecordService.save(operationRecord);
-        httpRespMsg.setMsg("同步新增来自泛微的项目数据,共"+insert+"条数据"+"\n"+"同步更新来自泛微的项目数据,共"+update+"条数据");
-        return httpRespMsg;
-    }
 
     @LimitRequest(count = 60)
     @RequestMapping("/getProjectListByToken")

+ 6 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/mapper/TaskExecutorMapper.java

@@ -3,6 +3,7 @@ package com.management.platform.mapper;
 import com.management.platform.entity.TaskExecutor;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -17,4 +18,9 @@ import java.util.List;
 public interface TaskExecutorMapper extends BaseMapper<TaskExecutor> {
 
     List<TaskExecutor> getInfoWithFileCharge(@Param("taskId") Integer taskId);
+
+    @Select("SELECT task_executor.* FROM task_executor LEFT JOIN project ON project.`id` = task_executor.`project_id` LEFT JOIN `user` ON `user`.id = task_executor.`executor_id`\n" +
+            "         WHERE project.`company_id` = #{companyId}  AND executor_id IS NOT NULL AND project.`status` = 1 AND user.`is_active`=1\n" +
+            "AND NOT EXISTS (SELECT participation.`user_id` FROM participation WHERE participation.`project_id` = task_executor.`project_id` AND participation.`user_id` = task_executor.`executor_id`) ")
+    List<TaskExecutor> getMissedParticipation(Integer companyId);
 }

+ 23 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/ExcelParserService.java

@@ -23,7 +23,7 @@ public class ExcelParserService {
 
             // 获取表头行
             Row headerRow = sheet.getRow(0);
-
+            List<String> ignoreDates = new ArrayList<>();
             // 从第二行开始解析数据(假设第一行是表头)
             for (int i = 2; i <= sheet.getLastRowNum(); i++) {
                 Row row = sheet.getRow(i);
@@ -42,6 +42,7 @@ public class ExcelParserService {
 
                     // 解析日期(格式如:03-01\n周六)
                     String dateStr = getCellValue(dateCell);
+                    if (ignoreDates.contains(dateStr)) continue;
                     String[] dateParts = dateStr.split("\n");
                     if (dateParts.length < 1) continue;
 
@@ -58,6 +59,27 @@ public class ExcelParserService {
 
                     // 分割时间记录(可能有多个打卡时间)
                     String[] times = timeRecord.split("\n");
+
+                    if (times.length == 1) {
+                        //当前只有一次打卡,可能是晚班,要获取次日最晚打卡作为下班打卡。
+                        if (times[0].compareTo("18:00") > 0) {
+                            String sTime = times[0];
+                            //次日最晚打卡
+                            Cell nextDateCell = headerRow.getCell(col + 1);
+                            String nextDateStr = getCellValue(nextDateCell);
+                            Cell nextDayTime = row.getCell(col + 1);
+                            String nextDayTimeStr = getCellValue(nextDayTime);
+                            String[] nextDayTimes = nextDayTimeStr.split("\n");
+                            if (nextDayTimes[nextDayTimes.length -1].compareTo("12:00") < 0) {
+                                //次日上午打卡结束
+                                String nextDayEndTime = "次日"+nextDayTimes[nextDayTimes.length -1];
+                                times = new String[2];
+                                times[0] = sTime;
+                                times[1] = nextDayEndTime;
+                                ignoreDates.add(nextDateStr);
+                            }
+                        }
+                    }
                     if (times.length < 2) continue;
 
                     // 取第一个和最后一个时间作为上班和下班时间

+ 15 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/service/impl/ProjectServiceImpl.java

@@ -3847,16 +3847,30 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
 
     @Override
     public HttpRespMsg addMemb(Integer id, String[] userId) {
-        List<String> userIdList = new ArrayList<>();
         List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().eq("project_id", id));
+        StringBuilder stringBuilder = new StringBuilder();
         for (String uid: userId) {
             if (participationList.stream().filter(p->p.getUserId().equals(uid)).count() == 0) {
                 Participation item = new Participation();
                 item.setProjectId(id);
                 item.setUserId(uid);
                 participationMapper.insert(item);
+                stringBuilder.append(userMapper.selectById(uid).getName()).append(",");
             }
         }
+        //生成操作记录
+        User user = userMapper.selectById(request.getHeader("token"));
+        Project project = getById(id);
+        OperationRecord operationRecord=new OperationRecord();
+        operationRecord.setProjectName(project.getProjectName());
+        operationRecord.setOperationTime(LocalDateTime.now());
+        //operationRecord.setContent("添加了项目成员");
+        operationRecord.setContent(MessageUtils.message("Template.addMember")+":"+stringBuilder.substring(0,stringBuilder.length()-1));
+        //operationRecord.setModuleName("项目管理");
+        operationRecord.setModuleName(MessageUtils.message("Template.projectManage"));
+        operationRecord.setOperatorName(user.getName());
+        operationRecord.setCompanyId(user.getCompanyId());
+        operationRecordService.save(operationRecord);
         return new HttpRespMsg();
     }
 

+ 21 - 118
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -259,6 +259,27 @@ public class TimingTask {
         }
     }
 
+    //由于未知原因,任务加了参与人,但是项目会稍后丢失参与人,我们系统要自动修复一下
+    @Scheduled(cron = "0 20 1 ? * *")
+    private void autoFixProjectParticipation() {
+        if (isDev) return;
+        Integer companyId = 3092;
+        List<TaskExecutor> missedParticipation = taskExecutorMapper.getMissedParticipation(companyId);
+        List<Participation> addList = new ArrayList<>();
+        for (TaskExecutor executor : missedParticipation) {
+            Participation participation = new Participation();
+            participation.setProjectId(executor.getProjectId());
+            participation.setUserId(executor.getExecutorId());
+            if (addList.stream().noneMatch(p->p.getProjectId().equals(participation.getProjectId()) && p.getUserId().equals(participation.getUserId()))) {
+                addList.add(participation);
+            }
+        }
+        System.out.println("需要补参与人数据:"+addList.size());
+        if (addList.size() > 0) {
+            participationMapper.insertBatch(addList);
+        }
+    }
+
 
     //每天2:11 同步钉钉用户前2天到未来30天时间段的打卡,请假,出差数据
     @Scheduled(cron = "0 11 2 ? * *")
@@ -594,124 +615,6 @@ public class TimingTask {
             }
         }
     }
-    
-    @Scheduled(cron = "0 15 3 ? * *")
-    private void synFanWeiProjectDate() {
-        if (isDev) return;
-        if(!isPrivateDeploy) return;
-        List<TimeType> timeTypeList = timeTypeMapper.selectList(new QueryWrapper<TimeType>().eq("sync_fanwei", 1));
-        List<Integer> compIds = timeTypeList.stream().map(TimeType::getCompanyId).collect(Collectors.toList());
-        if(compIds.isEmpty()){
-            return;
-        }
-        for (Integer compId : compIds) {
-            String url="http://10.1.10.51:20175/api/cube/restful/interface/getModeDataPageList/getProejct";
-            JSONObject jsonObject=new JSONObject();
-            jsonObject.put("rybh","");
-            jsonObject.put("workDate","");
-            String jsonString = jsonObject.toJSONString();
-            HttpRespMsg result = DockWithMLD.getResult(url, null);
-            List<Map<String,Object>> dataList= (List<Map<String, Object>>) result.data;
-            List<Project> workTimeProjectList = projectService.list(new QueryWrapper<Project>().eq("company_id", compId).select("project_code","id"));
-//            List<Map<String, Object>> mapList = dataList.stream().filter(dl ->!dl.get("xmdm").equals("")&&
-//                    !workTimeProjectList.stream().anyMatch(wl->wl.getProjectCode()!=null&&!wl.getProjectCode().equals("")&&wl.getProjectCode().equals(dl.get("xmdm")))).collect(Collectors.toList());
-            List<Map<String, Object>> mapList = dataList;
-            List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", compId).select("job_number", "id","name"));
-            int insert=0;
-            int update=0;
-            StringBuilder sb=new StringBuilder();
-            sb.append("更新的项目:");
-            for (Map<String, Object> map : mapList) {
-                List<Participation> participationList=new ArrayList<>();
-                Optional<User> first = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(map.get("xmfzrplxm"))).findFirst();
-                if(workTimeProjectList.stream().anyMatch(wl->wl.getProjectCode()!=null&&wl.getProjectCode().equals(map.get("xmdm")))){
-                    Optional<Project> project = workTimeProjectList.stream().filter(wl -> wl.getProjectCode() != null && wl.getProjectCode().equals(map.get("xmdm"))).findFirst();
-                    if(project.isPresent()){
-                        Project item = project.get();
-                        item.setProjectName(String.valueOf(map.get("xmmc")));
-                        if(first.isPresent()){
-                            item.setInchargerId(first.get().getId())
-                                    .setInchargerName(first.get().getName());
-                        }
-                        boolean isUpdate=false;
-                        if(!item.getInchargerId().equals(first.get().getId())){
-                            update++;
-                            isUpdate=true;
-                        }
-                        projectService.updateById(item);
-                        List<Participation> allParticipations = participationService.list(new QueryWrapper<Participation>().eq("project_id", item.getId()));
-                        if(map.get("xmcygs")!=null&&!map.get("xmcygs").equals("")){
-                            participationService.remove(new QueryWrapper<Participation>().eq("project_id",item.getId()));
-                            String participations = String.valueOf(map.get("xmcygs"));
-                            List<String> list = Arrays.asList(participations.split(","));
-                            for (String s : list) {
-                                Optional<User> participation = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(s)).findFirst();
-                                if(participation.isPresent()){
-                                    Participation p=new Participation();
-                                    p.setUserId(participation.get().getId()).setProjectId(item.getId());
-                                    participationList.add(p);
-                                }
-                            }
-                            List<String> collect = allParticipations.stream().map(al -> al.getUserId()).distinct().collect(Collectors.toList());
-                            List<String> collect1 = participationList.stream().map(pl -> pl.getUserId()).distinct().collect(Collectors.toList());
-                            System.out.println("之前的数据:"+collect);
-                            System.out.println("之后的数据:"+collect1);
-                            if(collect.size()!=collect1.size()){
-                                sb.append("["+item.getProjectName()+"/"+item.getProjectCode()+"]"+"\n");
-                                if(!isUpdate){
-                                    update++;
-                                }
-
-                            }else if(!collect.containsAll(collect1)){
-                                sb.append("["+item.getProjectName()+"/"+item.getProjectCode()+"]"+"\n");
-                                if(!isUpdate){
-                                    update++;
-                                }
-                            }
-                        }
-                        if(participationList.size()>0){
-                            participationService.saveBatch(participationList);
-                        }
-                    }
-                }else {
-                    Project project=new Project();
-                    project.setProjectName(String.valueOf(map.get("xmmc")))
-                            .setProjectCode(String.valueOf(map.get("xmdm")))
-                            .setCompanyId(876)
-                            .setCreateDate(LocalDate.now());
-                    if(first.isPresent()){
-                        project.setInchargerId(first.get().getId())
-                                .setInchargerName(first.get().getName());
-                    }
-                    projectService.save(project);
-                    insert++;
-                    if(map.get("xmcygs")!=null&&!map.get("xmcygs").equals("")){
-                        String participations = String.valueOf(map.get("xmcygs"));
-                        List<String> list = Arrays.asList(participations.split(","));
-                        for (String s : list) {
-                            Optional<User> participation = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(s)).findFirst();
-                            if(participation.isPresent()){
-                                Participation p=new Participation();
-                                p.setUserId(participation.get().getId()).setProjectId(project.getId());
-                                participationList.add(p);
-                            }
-                        }
-                    }
-                    if(participationList.size()>0){
-                        participationService.saveBatch(participationList);
-                    }
-                }
-            }
-            OperationRecord operationRecord=new OperationRecord();
-            operationRecord.setCompanyId(compId)
-                    .setContent("同步来自泛微的项目数据,共"+insert+"条数据"+"\n"+"同步更新来自泛微的项目数据,共"+update+"条数据"+"\n"+sb.toString())
-                    .setModuleName("项目管理").setOperationTime(LocalDateTime.now());
-            if(operationRecord.getContent().length()>1000){
-                operationRecord.setContent(operationRecord.getContent().substring(0,999));
-            }
-            operationRecordService.save(operationRecord);
-        }
-    }
 
 
     //专门给明夷的定时任务

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/i18n/messages.properties

@@ -348,6 +348,7 @@ Template.lackDepartment=缺少部门列,请下载最新模板进行导入
 Template.lackJobNumber=缺少工号列,请下载最新模板导入
 Template.creatProject=创建了项目
 Template.projectManage=项目管理
+Template.addMember=添加了参与人
 Template.finishProject=完成了项目
 Template.revokeProject=撤销了项目
 Template.restart=重启了项目

+ 1 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/resources/i18n/messages_en_US.properties

@@ -348,6 +348,7 @@ Template.lackDepartment=The department column is missing. Please download the la
 Template.lackJobNumber=The job number column is missing. Please download the latest template to import.
 Template.creatProject=Created project
 Template.projectManage=project management
+Template.addMember=add participation
 Template.finishProject=completed the project
 Template.revokeProject=cancelled the project
 Template.restart=Restarted the project