浏览代码

泛微项目数据同步定时任务 以及mapping接口开发

Min 2 年之前
父节点
当前提交
ce33667699

+ 46 - 9
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/controller/ProjectController.java

@@ -8,6 +8,7 @@ import com.management.platform.entity.vo.OvertimeListVO;
 import com.management.platform.mapper.*;
 import com.management.platform.service.OperationRecordService;
 import com.management.platform.service.ProjectService;
+import com.management.platform.util.DockWithMLD;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
 import org.apache.poi.hssf.usermodel.*;
@@ -20,12 +21,9 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+import sun.util.resources.LocaleData;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -33,10 +31,7 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -1231,5 +1226,47 @@ public class ProjectController {
     public HttpRespMsg exportFTEData(String month,String area,HttpServletRequest request){
         return projectService.exportFTEData(month,area,request);
     }
+
+    @RequestMapping("/syncProjectWithFanwei")
+    public HttpRespMsg syncProjectWithFanwei(){
+        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"));
+        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<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", 876).select("job_number", "id","name"));
+        List<Project> needInsert=new ArrayList<>();
+        for (Map<String, Object> map : mapList) {
+            Optional<User> first = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(map.get("xmfzrplxm"))).findFirst();
+            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());
+            }
+            needInsert.add(project);
+        }
+        httpRespMsg.setData(dataList);
+        if(!projectService.saveBatch(needInsert)){
+           httpRespMsg.setError("操作失败");
+           return httpRespMsg;
+        }
+        OperationRecord operationRecord=new OperationRecord();
+        operationRecord.setCompanyId(876)
+                       .setContent("同步来自泛微的项目数据,共"+needInsert.size()+"条数据")
+                       .setModuleName("项目管理").setOperationTime(LocalDateTime.now());
+        operationRecordService.save(operationRecord);
+        return httpRespMsg;
+    }
+
 }
 

+ 51 - 0
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/task/TimingTask.java

@@ -102,6 +102,10 @@ public class TimingTask {
     private WxCorpInfoMapper wxCorpInfoMapper;
     @Resource
     private ReportLogMapper reportLogMapper;
+    @Resource
+    private ProjectService projectService;
+    @Resource
+    private OperationRecordService operationRecordService;
     @Value(value = "${upload.path}")
     private String path;
 
@@ -542,6 +546,53 @@ public class TimingTask {
         }
     }
 
+    //每天2:11 同步泛微用户前2天到未来30天时间段的打卡,请假,出差数据
+    @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"));
+            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<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", compId).select("job_number", "id","name"));
+            List<Project> needInsert=new ArrayList<>();
+            for (Map<String, Object> map : mapList) {
+                Optional<User> first = userList.stream().filter(ul ->ul.getJobNumber()!=null&&ul.getJobNumber().equals(map.get("xmfzrplxm"))).findFirst();
+                Project project=new Project();
+                project.setProjectName(String.valueOf(map.get("xmmc")))
+                        .setProjectCode(String.valueOf(map.get("xmdm")))
+                        .setCompanyId(compId)
+                        .setCreateDate(LocalDate.now());
+                if(first.isPresent()){
+                    project.setInchargerId(first.get().getId())
+                            .setInchargerName(first.get().getName());
+                }
+                needInsert.add(project);
+            }
+            if(needInsert.size()>0){
+                projectService.saveBatch(needInsert);
+            }
+            OperationRecord operationRecord=new OperationRecord();
+            operationRecord.setCompanyId(compId)
+                    .setContent("同步来自泛微的项目数据,共"+needInsert.size()+"条数据")
+                    .setModuleName("项目管理").setOperationTime(LocalDateTime.now());
+            operationRecordService.save(operationRecord);
+        }
+    }
+
     private  List<LocalDateTime> getDays(LocalDateTime start, LocalDateTime end) {
         List<LocalDateTime> result = new ArrayList();
         while (start.isBefore(end)) {

+ 1 - 1
fhKeeper/formulahousekeeper/management-platform/src/main/java/com/management/platform/util/DockWithMLD.java

@@ -82,7 +82,7 @@ public class DockWithMLD {
         pageInfo.put("pageSize",99999);
         paramDatajson.put("pageInfo",pageInfo);
         //封装 mainTable 参数
-        JSONObject mainTable  = JSON.parseObject(screenString);
+        JSONObject mainTable  = JSON.parseObject(screenString==null?"{}":screenString);
         paramDatajson.put("mainTable",mainTable);
         //封装 operationinfo 参数
         JSONObject operationinfo = new JSONObject();