Procházet zdrojové kódy

广以写的更新到本地

yuanzhi_kuang před 7 měsíci
rodič
revize
6ea5e28a39

+ 60 - 0
src/main/java/com/gtiit/shr/controller/NewShrOrgPosPerController.java

@@ -0,0 +1,60 @@
+package com.gtiit.shr.controller;
+
+import com.gtiit.shr.common.Result;
+import com.gtiit.shr.service.NewSynOrgPosPerService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.SimpleDateFormat;
+
+/**
+ * @author ramon.wang
+ * @date Created in 17/07/2025 16:46
+ * @description shr同步组织岗位人员到oa系统
+ */
+
+@RestController
+@RequestMapping("/new")
+public class NewShrOrgPosPerController {
+
+    @Autowired
+    NewSynOrgPosPerService newsynOrgAndDeptService;
+
+
+    @GetMapping({"/admin"})
+    public Result admin(@RequestParam String statrTime, @RequestParam String endTime) {
+        Result result = new Result();
+
+        try {
+            result = this.newsynOrgAndDeptService.SynOrg(statrTime, endTime);
+            return result;
+        } catch (Exception var5) {
+            result.setMessage("系统异常,请联系管理员分析日志:" + var5.getMessage());
+            result.setCode(0);
+            return result;
+        }
+    }
+
+    @GetMapping({"/position"})
+    public Result position(@RequestParam String statrTime, @RequestParam String endTime) {
+        SimpleDateFormat dat = new SimpleDateFormat("yyyy-MM-dd");
+        Result result = new Result();
+
+        try {
+            result = this.newsynOrgAndDeptService.SynPosition(dat.parse(statrTime), dat.parse(endTime));
+            return result;
+        } catch (Exception var6) {
+            result.setMessage("系统异常,请联系管理员分析日志:" + var6.getMessage());
+            result.setCode(0);
+            return result;
+        }
+    }
+
+    @GetMapping({"/person"})
+    public Result admin(@RequestParam String startDate, @RequestParam String endDate, @RequestParam String personNumber) throws Exception {
+        return this.newsynOrgAndDeptService.synPerson(startDate, endDate, personNumber);
+    }
+}

+ 14 - 0
src/main/java/com/gtiit/shr/service/NewSynOrgPosPerService.java

@@ -0,0 +1,14 @@
+package com.gtiit.shr.service;
+
+import com.gtiit.shr.common.Result;
+
+import java.util.Date;
+
+public interface NewSynOrgPosPerService {
+
+    Result SynOrg(String startTime, String endTime) throws Exception;
+
+    Result SynPosition(Date startTime, Date endTime) throws Exception;
+
+    Result synPerson(String startDate, String endDate, String personNumber) throws Exception;
+}

+ 629 - 0
src/main/java/com/gtiit/shr/service/impl/NewSynOrgPosPerServiceImpl.java

@@ -0,0 +1,629 @@
+package com.gtiit.shr.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.gtiit.shr.common.Result;
+import com.gtiit.shr.entity.enums.TaskNameEnum;
+import com.gtiit.shr.entity.enums.TaskStatusEnum;
+import com.gtiit.shr.entity.enums.TypeEnum;
+import com.gtiit.shr.entity.vo.ExceptionRequestVo;
+import com.gtiit.shr.service.ExceptionService;
+import com.gtiit.shr.service.NewSynOrgPosPerService;
+import com.gtiit.shr.utils.FinalParamUtil;
+import com.gtiit.shr.utils.NewOaApiUtil;
+import com.kingdee.shr.api.Response;
+import com.kingdee.shr.api.SHRClient;
+import com.kingdee.shr.api.Token;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * @author ramon.wang
+ * @date Created in 17/07/2025 16:59
+ * @description shr同步组织岗位人员到oa系统业务实现类
+ */
+@Service
+@Transactional
+public class NewSynOrgPosPerServiceImpl implements NewSynOrgPosPerService {
+
+    @Autowired
+    private FinalParamUtil finalParamUtil;
+
+    @Autowired
+    private NewOaApiUtil newOaApiUtil;
+
+    @Autowired
+    ExceptionService exceptionService;
+
+    Token token = null;
+
+    @Value("${scheduled.org.new.able}")
+    private String deptcronStatus;
+
+    @Value("${scheduled.position.new.able}")
+    private String positioncronStatus;
+
+    @Value("${scheduled.person.new.able}")
+    private String cronStatus;
+
+    private static String shrurl = "https://gtiit.kdeascloud.com/shr";
+
+    private static Map<String, String> statusmap = new HashMap<>();
+
+    static {
+//        '{"On Probation":"试用","Employee":"正式","Permanent Employee":"正式","Temporary Worker":"临时",
+//        "试用延期":"试用延期","Dismiss":"解聘","Termination":"解聘","Dimission":"离职","Resignation":"离职","Retirement":"退休","无效":"无效"}'
+        //key为shr,value为oa
+        statusmap.put("On Probation", "1");
+        statusmap.put("试用延期", "2");
+        statusmap.put("Employee", "3");
+        statusmap.put("Permanent Employee", "3");
+        statusmap.put("Temporary Worker", "4");
+        statusmap.put("Labor Dispatching","4");
+        statusmap.put("Practice","5");
+        statusmap.put("Dimission", "6");
+        statusmap.put("Resignation", "6");
+        statusmap.put("Dismiss","6");
+        statusmap.put("Termination","6");
+        statusmap.put("Retirement with Honors","6");
+        statusmap.put("Fired","6");
+        statusmap.put("Retirement", "7");
+    }
+
+
+    @Scheduled(
+            cron = "${scheduled.org.cron}"
+    )
+    @Transactional
+    public void SynOrg() throws Exception {
+        //TODO 这里记得要删除旧接口的定时同步任务,把旧定时任务设置为禁用
+        if (TaskStatusEnum.ABLE.getValue().equals(this.deptcronStatus)) {
+            String var1 = FinalParamUtil.getBeforeOneDay(new Date());
+            this.synOrgToType(var1, FinalParamUtil.formatDate(new Date()), TypeEnum.AUTO.getValue());
+        }
+
+    }
+
+    @Override
+    public Result SynOrg(String startTime, String endTime) throws Exception {
+        return this.synOrgToType(startTime, endTime, TypeEnum.MANUAL.getValue());
+    }
+
+    private Result synOrgToType(String startTime, String endTime, String type) throws Exception {
+        SHRClient sHRClient = new SHRClient();
+        //TODO 这里先把shr生产环境数据同步到oa测试环境。为了不影响同步程序生产环境的日志等配置,这里不能在application.yml中spring.profiles.active:uat改为prod。所以先写死生产shr的url
+        this.token = sHRClient.loginShrByUser(this.finalParamUtil.getShrUrl());
+//        this.token = sHRClient.loginShrByUser(shrurl);
+        Result result = new Result();
+        result.setCode(1);
+        JSONArray jsonAdmArr = null;
+        Map<String, String> param = new HashMap();
+        param.put("startDate", startTime);
+        param.put("endDate", endTime);
+
+        try {
+            jsonAdmArr = JSONObject.parseArray(this.getOSFData(this.finalParamUtil.getInteOAGetAdminOrgDataService(), param).getData().toString());
+        } catch (Exception var31) {
+            return new Result(false, 0, "SHR系统请求报错,报错信息为--new:" + var31.getMessage());
+        }
+
+        Map<String, Object> mapBody = new HashMap();
+        ArrayList<Map<String, String>> dataList = new ArrayList();
+        Map<String, Object> paramMap = new HashMap();
+        //shr返回的组织数据不为空
+        if (jsonAdmArr != null && jsonAdmArr.size() > 0) {
+            for (int i = 0; i < jsonAdmArr.size(); ++i) {
+                JSONObject jsonObject = JSONObject.parseObject(jsonAdmArr.get(i).toString());
+                String shortname = jsonObject.getString("simpleName");
+                if (StrUtil.isEmpty(shortname)) {
+                    shortname = jsonObject.getString("name");
+                }
+
+                HashMap mpBody = new HashMap();
+                mpBody.put("name", shortname);
+                mpBody.put("code", jsonObject.getString("fnumber"));
+//            mpBody.put("fullname", jsonObject.getString("name"));
+                //其中 7 表示中文,8 表示英文
+                JSONObject fullname = new JSONObject();
+                fullname.put("7", jsonObject.getString("name"));
+                fullname.put("8", jsonObject.getString("name_L1"));
+                JSONObject multiObj = new JSONObject();
+                multiObj.put("fullname", fullname);
+                mpBody.put("multiObj", multiObj);
+
+                mpBody.put("parent", jsonObject.getString("supFnumber"));
+                mpBody.put("description", jsonObject.getString("name_L1"));
+
+                //组装自定义的部门负责人和部门分管领导
+                JSONObject result1 = new JSONObject();
+                result1.put("bmfzr", jsonObject.getString("pnumber") == null ? "" : jsonObject.getString("pnumber"));
+                result1.put("bmfgld", jsonObject.getString("pvc_number") == null ? "" : jsonObject.getString("pvc_number"));
+                mpBody.put("departmentExtend", result1);
+
+                dataList.add(mpBody);
+                paramMap.put(jsonObject.getString("fnumber"), mpBody);
+            }
+
+            if (dataList.size() == 0) {
+                return new Result(false, 0, "当前时间范围内未找到组织的变动记录--new");
+            } else {
+                mapBody.put("data", dataList);
+                Map<String, String> dataRuleMap = new HashMap();
+                dataRuleMap.put("department", "code");
+                dataRuleMap.put("employee", "job_num");
+                mapBody.put("dataRule", dataRuleMap);
+                String sendAPIByAddAdmin = "";
+
+                try {
+                    sendAPIByAddAdmin = this.newOaApiUtil.restful("/papi/openapi/api/hrm/restful/syncDepartment", mapBody, "sendAPIByAddAdmin");
+                } catch (Exception var30) {
+                    return new Result(false, 0, "OA系统请求报错,报错信息为--new:" + var30.getMessage());
+                }
+
+                System.out.println("日志打印--admin--new:" + sendAPIByAddAdmin);
+                Integer sucessCount = 0;
+                Integer failCount = 0;
+                JSONObject jsonObject = JSONObject.parseObject(sendAPIByAddAdmin);
+                //同步失败
+                if (StrUtil.isNotEmpty(jsonObject.getString("errcode"))) {
+                    String errmsg = "";
+                    if (StrUtil.isNotEmpty(jsonObject.getString("errmsg"))) {
+                        errmsg = jsonObject.getString("errmsg");
+                    }
+                    return new Result(false, 0, "OA系统请求报错,报错信息为--new:" + errmsg);
+                } else {
+                    List<ExceptionRequestVo> exceptionRequestVoList = new ArrayList();
+                    JSONArray dataResult = jsonObject.getJSONArray("data");
+                    int batchSize = 100;
+                    int totalSize = dataResult.size();
+                    int batchCount = (totalSize + batchSize - 1) / batchSize;
+
+                    for (int i = 0; i < batchCount; ++i) {
+                        int startIndex = i * batchSize;
+                        int endIndex = Math.min(startIndex + batchSize, totalSize);
+                        List<Object> subObjects = dataResult.subList(startIndex, endIndex);
+                        for (Object object : subObjects) {
+                            JSONObject jsonObject1 = (JSONObject) object;
+//                        JSONObject jsonObject1 = dataResult.getJSONObject(i);
+                            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+                            exceptionRequestVo.setTaskName("OA部门同步-new-" + jsonObject1.getString("keyValue") + "-" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
+                            exceptionRequestVo.setTaskType(TaskNameEnum.OADEPT.getValue());
+                            exceptionRequestVo.setType(type);
+                            exceptionRequestVo.setExcuteDate(new Date());
+                            exceptionRequestVo.setErrorReason(jsonObject1.getString("errcode"));
+                            exceptionRequestVo.setIsSucess("否");
+                            if ("SUCCESS".equals(jsonObject1.getString("status"))) {
+                                exceptionRequestVo.setIsSucess("是");
+                                sucessCount = sucessCount + 1;
+                            } else {
+                                failCount++;
+                            }
+
+                            exceptionRequestVo.setRequestParam(JSON.toJSONString(paramMap.get(jsonObject1.getString("keyValue"))));
+                            exceptionRequestVo.setResponeParam(jsonObject1.toString());
+                            exceptionRequestVoList.add(exceptionRequestVo);
+                        }
+                        if (exceptionRequestVoList != null && exceptionRequestVoList.size() > 0) {
+                            int resultConut = this.exceptionService.insertBatchException(exceptionRequestVoList);
+                            if (resultConut > 0) {
+                                exceptionRequestVoList.clear();
+                            }
+                        }
+                    }
+
+                    result.setMessage("操作成功--new,同步成功" + sucessCount + ",失败" + failCount + "条");
+                    return result;
+                }
+            }
+        } else {
+            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+            exceptionRequestVo.setTaskName("OA部门同步-new");
+            exceptionRequestVo.setTaskType(TaskNameEnum.OADEPT.getValue());
+            exceptionRequestVo.setType(type);
+            exceptionRequestVo.setExcuteDate(new Date());
+            exceptionRequestVo.setErrorReason("当前时间范围内未找到组织的变动记录");
+            exceptionRequestVo.setIsSucess("否");
+            exceptionRequestVo.setResponeParam(jsonAdmArr.toJSONString());
+            this.exceptionService.insertException(exceptionRequestVo);
+            return new Result(false, 0, "当前时间范围内未找到组织的变动记录--new");
+        }
+    }
+
+    @Scheduled(
+            cron = "${scheduled.position.cron}"
+    )
+    @Transactional
+    public void SynPosition() throws Exception {
+        if (TaskStatusEnum.ABLE.getValue().equals(this.positioncronStatus)) {
+            this.synPositionToType(FinalParamUtil.parse(FinalParamUtil.getBeforeOneDay(new Date())), new Date(), TypeEnum.AUTO.getValue());
+        }
+
+    }
+
+    public Result SynPosition(Date startTime, Date endTime) throws Exception {
+        return this.synPositionToType(startTime, endTime, TypeEnum.MANUAL.getValue());
+    }
+
+    private Result synPositionToType(Date startTime, Date endTime, String type) throws Exception {
+        SHRClient sHRClient = new SHRClient();
+        //TODO
+        this.token = sHRClient.loginShrByUser(this.finalParamUtil.getShrUrl());
+//        this.token = sHRClient.loginShrByUser(shrurl);
+        Result result = new Result();
+        result.setCode(1);
+        JSONArray jsonAdmArr = null;
+
+        try {
+            jsonAdmArr = JSONObject.parseArray(this.getOSFData(this.finalParamUtil.getInteOAGetPositionDataService(), (Map) null).getData().toString());
+        } catch (Exception var29) {
+            return new Result(false, 0, "SHR系统请求报错,报错信息为--new:" + var29.getMessage());
+        }
+
+        Map<String, Object> mapBody = new HashMap();
+        ArrayList<Map<String, String>> listBody = new ArrayList();
+        Map<String, Object> paramMap = new HashMap();
+        //shr返回的岗位数据不为空
+        if (jsonAdmArr != null && jsonAdmArr.size() > 0) {
+            for (int i = 0; i < jsonAdmArr.size(); ++i) {
+                JSONObject jsonObject = JSONObject.parseObject(jsonAdmArr.get(i).toString());
+                String fLastUpdateTime = jsonObject.getString("fLastUpdateTime");
+                Boolean flag = FinalParamUtil.getLastDateTime(fLastUpdateTime);
+                if (startTime != null && endTime != null) {
+                    flag = false;
+                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                    if (startTime.getTime() <= sdf.parse(fLastUpdateTime).getTime() && sdf.parse(fLastUpdateTime).getTime() <= endTime.getTime()) {
+                        flag = true;
+                    }
+                }
+
+                if (flag) {
+                    String longNamel1 = jsonObject.getString("longNamel1");
+                    String longNamel2 = jsonObject.getString("longNamel2");
+                    String name = jsonObject.getString("Name");
+                    String namel1 = jsonObject.getString("Namel1");
+                    String orgName = jsonObject.getString("orgName");
+                    String posName_CN = "";
+                    String posName_EN = "";
+                    if (!StrUtil.isEmpty(orgName) && "true".equals(this.finalParamUtil.getIsJobTitlePrefixed())) {
+                        posName_CN = orgName + "-" + name;
+                        posName_EN = orgName + "-" + namel1;
+                    } else {
+                        posName_CN = name;
+                        posName_EN = namel1;
+                    }
+
+                    String parent = jsonObject.getString("supFnumber");
+                    HashMap mpBody = new HashMap();
+                    mpBody.put("code", jsonObject.getString("fnumber"));
+                    mpBody.put("name", posName_EN);
+                    mpBody.put("parent", parent);
+                    mpBody.put("department", jsonObject.getString("fOrgNumber"));
+                    JSONObject multiname = new JSONObject();
+                    multiname.put("7", posName_CN);
+                    multiname.put("8", posName_EN);
+                    JSONObject multiObj = new JSONObject();
+                    multiObj.put("name", multiname);
+                    mpBody.put("multiObj", multiObj);
+
+                    listBody.add(mpBody);
+                    paramMap.put(jsonObject.getString("fnumber"), mpBody);
+                }
+            }
+
+            if (listBody.size() == 0) {
+                return new Result(false, 0, "当前时间范围内未找到岗位的变动记录--new");
+            } else {
+                mapBody.put("data", listBody);
+                Map<String, String> dataRuleMap = new HashMap();
+                dataRuleMap.put("position", "code");
+                dataRuleMap.put("department", "code");
+                mapBody.put("dataRule", dataRuleMap);
+                String sendAPIByAddPosition = "";
+
+                try {
+                    sendAPIByAddPosition = this.newOaApiUtil.restful("/papi/openapi/api/hrm/restful/syncPosition", mapBody, "sendAPIByAddPosition");
+                } catch (Exception var28) {
+                    return new Result(false, 0, "OA系统请求报错,报错信息为--new:" + var28.getMessage());
+                }
+
+                System.out.println("日志打印--position--new:" + sendAPIByAddPosition);
+                Integer sucessCount = 0;
+                Integer failCount = 0;
+                JSONObject jsonObject = JSONObject.parseObject(sendAPIByAddPosition);
+                //同步失败
+                if (StrUtil.isNotEmpty(jsonObject.getString("errcode"))) {
+                    String errmsg = "";
+                    if (StrUtil.isNotEmpty(jsonObject.getString("errmsg"))) {
+                        errmsg = jsonObject.getString("errmsg");
+                    }
+                    return new Result(false, 0, "OA系统请求报错,报错信息为--new:" + errmsg);
+                } else {
+                    List<ExceptionRequestVo> exceptionRequestVoList = new ArrayList();
+                    JSONArray dataResult = jsonObject.getJSONArray("data");
+                    int batchSize = 100;
+                    int totalSize = dataResult.size();
+                    int batchCount = (totalSize + batchSize - 1) / batchSize;
+
+                    for (int i = 0; i < batchCount; ++i) {
+                        int startIndex = i * batchSize;
+                        int endIndex = Math.min(startIndex + batchSize, totalSize);
+                        List<Object> subObjects = dataResult.subList(startIndex, endIndex);
+                        for (Object object : subObjects) {
+                            JSONObject jsonObject1 = (JSONObject) object;
+//                        JSONObject jsonObject1 = dataResult.getJSONObject(i);
+                            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+                            exceptionRequestVo.setTaskName("OA岗位同步-new-" + jsonObject1.getString("keyValue") + "-" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
+                            exceptionRequestVo.setTaskType(TaskNameEnum.OAPOST.getValue());
+                            exceptionRequestVo.setType(type);
+                            exceptionRequestVo.setExcuteDate(new Date());
+                            exceptionRequestVo.setErrorReason(jsonObject1.getString("errcode"));
+                            exceptionRequestVo.setIsSucess("否");
+                            if ("SUCCESS".equals(jsonObject1.getString("status"))) {
+                                exceptionRequestVo.setIsSucess("是");
+                                sucessCount = sucessCount + 1;
+                            } else {
+                                failCount++;
+                            }
+
+                            exceptionRequestVo.setRequestParam(JSON.toJSONString(paramMap.get(jsonObject1.getString("keyValue"))));
+                            exceptionRequestVo.setResponeParam(jsonObject1.toString());
+                            exceptionRequestVoList.add(exceptionRequestVo);
+                        }
+                        if (exceptionRequestVoList != null && exceptionRequestVoList.size() > 0) {
+                            int resultConut = this.exceptionService.insertBatchException(exceptionRequestVoList);
+                            if (resultConut > 0) {
+                                exceptionRequestVoList.clear();
+                            }
+                        }
+                    }
+
+                    result.setMessage("操作成功--new,同步成功" + sucessCount + ",失败" + failCount + "条");
+                    return result;
+                }
+            }
+        } else {
+            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+            exceptionRequestVo.setTaskName("OA岗位同步-new");
+            exceptionRequestVo.setTaskType(TaskNameEnum.OAPOST.getValue());
+            exceptionRequestVo.setType(type);
+            exceptionRequestVo.setExcuteDate(new Date());
+            exceptionRequestVo.setErrorReason("当前时间范围内未找到岗位的变动记录");
+            exceptionRequestVo.setIsSucess("否");
+            exceptionRequestVo.setResponeParam(jsonAdmArr.toJSONString());
+            this.exceptionService.insertException(exceptionRequestVo);
+            return new Result(false, 0, "当前时间范围内未找到岗位的变动记录--new");
+        }
+    }
+
+    @Scheduled(
+            cron = "${scheduled.person.cron}"
+    )
+    @Transactional
+    public void scheduledSynPerson() throws IOException {
+        if (TaskStatusEnum.ABLE.getValue().equals(this.cronStatus)) {
+            Map<String, String> param = new HashMap();
+            param.put("startDate", FinalParamUtil.getBeforeOneDay(new Date()));
+            param.put("endDate", FinalParamUtil.formatDate(new Date()));
+            param.put("personNumber", "");
+            SHRClient sHRClient = new SHRClient();
+            //TODO
+            this.token = sHRClient.loginShrByUser(this.finalParamUtil.getShrUrl());
+//            this.token = sHRClient.loginShrByUser(shrurl);
+            String resultString = this.getOSFData(this.finalParamUtil.getSynPersonService(), param).getData().toString();
+            JSONObject shrResultJson = JSONObject.parseObject(resultString);
+            if (!org.springframework.util.StringUtils.isEmpty(shrResultJson) && "error".equals(shrResultJson.getString("result"))) {
+                ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+                exceptionRequestVo.setTaskName("OA员工同步-new");
+                exceptionRequestVo.setTaskType(TaskNameEnum.OASTAFF.getValue());
+                exceptionRequestVo.setType(TypeEnum.AUTO.getValue());
+                exceptionRequestVo.setExcuteDate(new Date());
+                exceptionRequestVo.setErrorReason(shrResultJson.getString("summary"));
+                exceptionRequestVo.setIsSucess("否");
+                exceptionRequestVo.setResponeParam(resultString);
+                this.exceptionService.insertException(exceptionRequestVo);
+            } else if (shrResultJson.getString("code").equals("1") && shrResultJson.getJSONArray("data").size() > 0) {
+                this.synPersonToType(shrResultJson, TypeEnum.AUTO.getValue());
+            } else {
+                ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+                exceptionRequestVo.setTaskName("OA员工同步-new");
+                exceptionRequestVo.setTaskType(TaskNameEnum.OASTAFF.getValue());
+                exceptionRequestVo.setType(TypeEnum.AUTO.getValue());
+                exceptionRequestVo.setExcuteDate(new Date());
+                exceptionRequestVo.setErrorReason("当前时间范围内暂无变更的人员信息");
+                exceptionRequestVo.setIsSucess("否");
+                exceptionRequestVo.setResponeParam(resultString);
+                this.exceptionService.insertException(exceptionRequestVo);
+            }
+        }
+    }
+
+    public Result synPerson(String startDate, String endDate, String personNumber) throws Exception {
+        SHRClient sHRClient = new SHRClient();
+        this.token = sHRClient.loginShrByUser(this.finalParamUtil.getShrUrl());
+        Map<String, String> param = new HashMap();
+        param.put("startDate", startDate);
+        param.put("endDate", endDate);
+        param.put("personNumber", personNumber);
+        String resultString = "";
+
+        try {
+            resultString = this.getOSFData(this.finalParamUtil.getSynPersonService(), param).getData().toString();
+        } catch (Exception var8) {
+            return new Result(false, 0, "SHR系统请求报错,报错信息为--new:" + var8.getMessage());
+        }
+
+        JSONObject shrResultJson = JSONObject.parseObject(resultString);
+        if (!org.springframework.util.StringUtils.isEmpty(shrResultJson) && "error".equals(shrResultJson.getString("result"))) {
+            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+            exceptionRequestVo.setTaskName("OA员工同步-new");
+            exceptionRequestVo.setTaskType(TaskNameEnum.OASTAFF.getValue());
+            exceptionRequestVo.setType(TypeEnum.MANUAL.getValue());
+            exceptionRequestVo.setExcuteDate(new Date());
+            exceptionRequestVo.setErrorReason(shrResultJson.getString("summary"));
+            exceptionRequestVo.setIsSucess("否");
+            exceptionRequestVo.setResponeParam(resultString);
+            this.exceptionService.insertException(exceptionRequestVo);
+            return new Result(false, 0, shrResultJson.getString("summary"));
+        } else if (shrResultJson.getString("code").equals("1") && shrResultJson.getJSONArray("data").size() > 0) {
+            return this.synPersonToType(shrResultJson, TypeEnum.MANUAL.getValue());
+        } else {
+            ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+            exceptionRequestVo.setTaskName("OA员工同步-new");
+            exceptionRequestVo.setTaskType(TaskNameEnum.OASTAFF.getValue());
+            exceptionRequestVo.setType(TypeEnum.MANUAL.getValue());
+            exceptionRequestVo.setExcuteDate(new Date());
+            exceptionRequestVo.setErrorReason("当前时间范围内暂无变更的人员信息");
+            exceptionRequestVo.setIsSucess("否");
+            exceptionRequestVo.setResponeParam(resultString);
+            this.exceptionService.insertException(exceptionRequestVo);
+            Result result = new Result();
+            result.setMessage("shr端暂无变更的人员信息!--new");
+            return result;
+        }
+    }
+
+    private Result synPersonToType(JSONObject shrResultJson, String type) {
+        JSONArray dataJsonArray = (JSONArray) shrResultJson.get("data");
+        Map<String, Object> mapBody = new HashMap();
+        ArrayList<Map<String, String>> listBody = new ArrayList();
+        Map<String, Object> paramMap = new HashMap();
+
+        //组装e10需要的参数格式
+//        JSONArray newJsonArray = new JSONArray();
+        for (int i = 0; i < dataJsonArray.size(); i++) {
+            HashMap mpBody = new HashMap();
+//            JSONObject newObj = new JSONObject();
+            JSONObject requestJson = dataJsonArray.getJSONObject(i);
+            mpBody.put("loginid", requestJson.getString("loginid"));
+            mpBody.put("job_num", requestJson.getString("workcode"));
+            //处理岗位
+            String jobtitle = requestJson.getString("jobtitle");
+            String validJson = jobtitle.replaceFirst("^\\{JSON\\}", "");
+            JSONObject jsonObj = JSONObject.parseObject(validJson);
+            mpBody.put("position", jsonObj.getString("jobtitlecode"));
+
+            mpBody.put("hiredate", requestJson.getString("companystartdate"));
+            //判断性别
+            String sex = null;
+            if (StrUtil.isNotEmpty(requestJson.getString("sex"))) {
+                if ("男".equals(requestJson.getString("sex"))) {
+                    sex = "male";
+                } else if ("女".equals(requestJson.getString("sex"))) {
+                    sex = "female";
+                } else {
+                    sex = "";
+                }
+            }
+            mpBody.put("sex", sex);
+            mpBody.put("mobile", requestJson.getString("mobile"));
+            mpBody.put("telephone", requestJson.getString("telephone"));
+            mpBody.put("grade", requestJson.getString("joblevel"));
+            mpBody.put("superior", requestJson.getString("managerid"));
+            mpBody.put("username", requestJson.getString("lastname"));
+            mpBody.put("password", requestJson.getString("password"));
+            //处理部门
+            String department = requestJson.getString("department");
+            validJson = department.replaceFirst("^\\{JSON\\}", "");
+            jsonObj = JSONObject.parseObject(validJson);
+            mpBody.put("department", jsonObj.getString("departmentcode"));
+
+            mpBody.put("sec_level", requestJson.getString("seclevel"));
+            mpBody.put("email", requestJson.getString("email"));
+            mpBody.put("personnel_status", StrUtil.isEmpty(statusmap.get(requestJson.getString("status")))?"":statusmap.get(requestJson.getString("status")));
+            mpBody.put("resp_desc",requestJson.getString("jobactivitydesc"));
+
+            listBody.add(mpBody);
+//            newJsonArray.add(newObj);
+            paramMap.put(requestJson.getString("workcode"), mpBody);
+        }
+
+//        mapBody.put("data", listBody);
+        Map<String, String> dataRuleMap = new HashMap();
+        dataRuleMap.put("employee", "job_num");
+        dataRuleMap.put("department", "code");
+        dataRuleMap.put("position", "code");
+        dataRuleMap.put("grade", "name");
+        mapBody.put("dataRule", dataRuleMap);
+
+//        JSONArray dataArray = shrResultJson.getJSONArray("data");
+        int arraySize = listBody.size();
+        int arrayNum = arraySize % 100 == 0 ? arraySize / 100 : arraySize / 100 + 1;
+
+        int errorSize = 0;
+        int successSize = 0;
+        TaskNameEnum oaStaff = TaskNameEnum.OASTAFF;
+        List<ExceptionRequestVo> exceptionRequestVoList = new ArrayList();
+
+        for (int i = 1; i <= arrayNum; ++i) {
+            int jSONArrayEnd = Math.min(i * 100, arraySize);
+            int jSONArrayStart = (i - 1) * 100;
+            List<Map<String, String>> objects = listBody.subList(jSONArrayStart, jSONArrayEnd);
+            mapBody.put("data", objects);
+            String sendAPIByAddPerson = "";
+
+            try {
+                sendAPIByAddPerson = this.newOaApiUtil.restful("/papi/openapi/api/hrm/restful/syncEmployee", mapBody, "sendAPIByAddPerson");
+            } catch (Exception var27) {
+                return new Result(false, 0, "OA系统请求报错,报错信息为:" + var27.getMessage());
+            }
+
+            JSONObject oaResultJson = JSON.parseObject(sendAPIByAddPerson);
+            if (StrUtil.isNotEmpty(oaResultJson.getString("errcode"))) {
+                String errmsg = "";
+                if (StrUtil.isNotEmpty(oaResultJson.getString("errmsg"))) {
+                    errmsg = oaResultJson.getString("errmsg");
+                }
+                return new Result(false, 0, "OA系统请求报错,报错信息为--new:" + errmsg);
+            } else {
+                JSONArray dataResult = oaResultJson.getJSONArray("data");
+                if (dataResult != null && dataResult.size() > 0) {
+                    for (int index = 0; index < dataResult.size(); ++index) {
+                        JSONObject jsonObject1 = dataResult.getJSONObject(index);
+                        ExceptionRequestVo exceptionRequestVo = new ExceptionRequestVo();
+                        exceptionRequestVo.setTaskName("OA员工同步-new-" + jsonObject1.getString("keyValue") + "-" + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(new Date()));
+                        exceptionRequestVo.setTaskType(oaStaff.getValue());
+                        exceptionRequestVo.setType(type);
+                        exceptionRequestVo.setExcuteDate(new Date());
+                        exceptionRequestVo.setErrorReason(jsonObject1.getString("errcode"));
+                        exceptionRequestVo.setIsSucess("否");
+                        if ("SUCCESS".equals(jsonObject1.getString("status"))) {
+                            exceptionRequestVo.setIsSucess("是");
+                            successSize = successSize + 1;
+                        } else {
+                            errorSize++;
+                        }
+
+                        exceptionRequestVo.setRequestParam(JSON.toJSONString(paramMap.get(jsonObject1.getString("keyValue"))));
+                        exceptionRequestVo.setResponeParam(jsonObject1.toString());
+                        exceptionRequestVoList.add(exceptionRequestVo);
+                    }
+                    if (exceptionRequestVoList != null && exceptionRequestVoList.size() > 0) {
+                        int resultConut = this.exceptionService.insertBatchException(exceptionRequestVoList);
+                        if (resultConut > 0) {
+                            exceptionRequestVoList.clear();
+                        }
+                    }
+                }
+            }
+
+        }
+
+        return new Result(true, successSize - errorSize > 0 ? 1 : 0, "同步成功:" + successSize + ";同步失败:" + errorSize);
+    }
+
+    public Response getOSFData(String OsfName, Map map) throws IOException {
+        SHRClient client = new SHRClient();
+        //TODO 这里先把shr生产环境数据同步到oa测试环境,为了不影响生产环境同步程序的日志等配置。这里不能在application.yml中spring.profiles.active:uat改为prod。所以先写死生产shr的url
+        return client.executeOSFService(this.finalParamUtil.getShrUrl(), this.token, OsfName, map);
+//        return client.executeOSFService(shrurl, this.token, OsfName, map);
+    }
+}

+ 60 - 0
src/main/java/com/gtiit/shr/utils/FinalParamUtil.java

@@ -47,6 +47,18 @@ public  class FinalParamUtil {
     private String IsJobTitlePrefixed;
     @Value("${api.oa.subcompanycode}")
     private String subcompanycode;
+    @Value("${api.oa.new.url}")
+    private String newoaUrl;
+    @Value("${api.oa.new.app_key}")
+    private String appKey;
+    @Value("${api.oa.new.app_secret}")
+    private String appSecret;
+    @Value("${api.oa.new.grant_type}")
+    private String grantType;
+    @Value("${api.oa.new.corpid}")
+    private String corpid;
+    @Value("${api.oa.new.response_type}")
+    private String responseType;
 
     public static Boolean getLastDateTime(String fLastUpdateTime) throws ParseException {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -188,6 +200,30 @@ public  class FinalParamUtil {
         return this.subcompanycode;
     }
 
+    public String getNewoaUrl() {
+        return this.newoaUrl;
+    }
+
+    public String getAppKey() {
+        return this.appKey;
+    }
+
+    public String getAppSecret() {
+        return this.appSecret;
+    }
+
+    public String getGrantType() {
+        return this.grantType;
+    }
+
+    public String getCorpid() {
+        return this.corpid;
+    }
+
+    public String getResponseType() {
+        return this.responseType;
+    }
+
     public void setShrUrl(final String shrUrl) {
         this.shrUrl = shrUrl;
     }
@@ -264,6 +300,30 @@ public  class FinalParamUtil {
         this.subcompanycode = subcompanycode;
     }
 
+    public void setNewoaUrl(String newoaUrl) {
+        this.newoaUrl = newoaUrl;
+    }
+
+    public void setAppKey(String appKey) {
+        this.appKey = appKey;
+    }
+
+    public void setAppSecret(String appSecret) {
+        this.appSecret = appSecret;
+    }
+
+    public void setGrantType(String grantType) {
+        this.grantType = grantType;
+    }
+
+    public void setCorpid(String corpid) {
+        this.corpid = corpid;
+    }
+
+    public void setResponseType(String responseType) {
+        this.responseType = responseType;
+    }
+
     public boolean equals(final Object o) {
         if (o == this) {
             return true;

+ 113 - 0
src/main/java/com/gtiit/shr/utils/NewOaApiUtil.java

@@ -0,0 +1,113 @@
+package com.gtiit.shr.utils;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author ramon.wang
+ * @date Created in 18/07/2025 14:56
+ * @description
+ */
+@Component
+public class NewOaApiUtil {
+
+    private static final HashMap<String, String> NEWSYSTEM_CACHE = new HashMap();
+
+    @Autowired
+    FinalParamUtil finalParamUtil;
+
+    //TODO 后面这些参数需要写入到yml文件中,然后进行调用
+//    private static final String OAURL = "https://sites.gtiit.edu.cn/oatest";
+
+//    private static final String app_key = "b9693deee1dba5f70134e81161d7b31";
+
+//    private static final String app_secret = "550856d7234a759b333a93aeb09739d3";
+
+//    private static final String grant_type = "authorization_code";
+
+//    private static final String corpid = "4bfaa311d6ac47f4822020e1ff3f2bf8";
+
+//    private static final String response_type = "code";
+
+
+    private Map<String, Object> getCode(String address) {
+        Map<String, Object> codeBody = new HashMap();
+        codeBody.put("corpid", this.finalParamUtil.getCorpid());
+        codeBody.put("response_type", this.finalParamUtil.getResponseType());
+        codeBody.put("state", "");
+        String jsonString = JSONObject.toJSONString(codeBody);
+        String data = HttpRequest.post(address + "/papi/openapi/oauth2/authorize").body(jsonString).execute().body();
+        System.out.println("getCode()--new:" + data);
+        Map<String, Object> datas = JSONUtil.parseObj(data);
+        return datas;
+    }
+
+    public Map<String, Object> getoken(String address) {
+        Map<String, Object> codeMap = this.getCode(address);
+        String code = (String) codeMap.get("code");
+        Map<String, Object> tokenBody = new HashMap();
+        tokenBody.put("app_key", this.finalParamUtil.getAppKey());
+        tokenBody.put("app_secret", this.finalParamUtil.getAppSecret());
+        tokenBody.put("grant_type", this.finalParamUtil.getGrantType());
+        tokenBody.put("code", code);
+        String jsonString = JSONObject.toJSONString(tokenBody);
+        //access_token过期时间
+        NEWSYSTEM_CACHE.put("EXPIRE_TIME", String.valueOf(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(2)));
+        String data = HttpRequest.post(address + "/papi/openapi/oauth2/access_token").header("Content-Type", "application/json").body(jsonString).execute().body();
+        System.out.println("getoken()--new:" + data);
+        Map<String, Object> datas = JSONUtil.parseObj(data);
+        NEWSYSTEM_CACHE.put("ACCESS_TOKEN", StrUtil.nullToEmpty((String) datas.get("accessToken")));
+        return datas;
+    }
+
+    public String restful(String api, Map jsonParams, String menthType) {
+        //获取accesstoken
+        String accessToken = (String) NEWSYSTEM_CACHE.get("ACCESS_TOKEN");
+        //判断accesstoken是否过期,2小时过期
+        Boolean isExpire = Boolean.FALSE;
+        if (!StrUtil.isEmpty(NEWSYSTEM_CACHE.get("EXPIRE_TIME"))) {
+            long expireTime = Long.valueOf(NEWSYSTEM_CACHE.get("EXPIRE_TIME"));
+            if (System.currentTimeMillis() > expireTime) {
+                isExpire = Boolean.TRUE;
+            }
+        }
+        if (StrUtil.isEmpty(accessToken) || isExpire) {
+            accessToken = (String) this.getoken(this.finalParamUtil.getNewoaUrl()).get("accessToken");
+        }
+        jsonParams.put("access_token", accessToken);
+        String jsonString = JSONObject.toJSONString(jsonParams);
+        if ("sendAPIByAddAdmin".equals(menthType)) {
+            return this.newSendAPIByAddAdmin(this.finalParamUtil.getNewoaUrl() + api, jsonString);
+        } else if ("sendAPIByAddPosition".equals(menthType)) {
+            return this.newSendAPIByAddPosition(this.finalParamUtil.getNewoaUrl() + api, jsonString);
+        } else {
+            return "sendAPIByAddPerson".equals(menthType) ? this.newsendAPIByAddPerson(this.finalParamUtil.getNewoaUrl() + api, jsonString) : "未找到相关调用代码";
+        }
+    }
+
+    private String newSendAPIByAddAdmin(String api, String jsonParams) {
+        String data = HttpRequest.post(api).header("Content-Type", "application/json").body(jsonParams).execute().body();
+        System.out.println("Restful()--new--admin:" + data);
+        return data;
+    }
+
+    private String newSendAPIByAddPosition(String api, String jsonParams) {
+        String data = HttpRequest.post(api).header("Content-Type", "application/json").body(jsonParams).execute().body();
+        System.out.println("Restful()--new--position:" + data);
+        return data;
+    }
+
+    private String newsendAPIByAddPerson(String api, String jsonParams) {
+        String data = HttpRequest.post(api).header("Content-Type", "application/json").body(jsonParams).execute().body();
+        System.out.println("Restful()--new--person:" + data);
+        return data;
+    }
+}

+ 17 - 3
src/main/resources/application-prod.yml

@@ -46,6 +46,14 @@ api:
     #人员状态映射 key为SHR端的状态 value为OA端的状态
     statusmap: '{"On Probation":"试用","Employee":"正式","Permanent Employee":"正式","Temporary Worker":"临时",
     "试用延期":"试用延期","Dismiss":"解聘","Termination":"解聘","Dimission":"离职","Resignation":"离职","Retirement":"退休","无效":"无效"}'
+    new:
+      #e10系统OA相关
+      url: https://sites.gtiit.edu.cn/oa
+      app_key: 255609d931748ab7e94b8c9ebd3cda4a
+      app_secret: aebfac1e820af1d38bc9aa295df20e0b
+      grant_type: authorization_code
+      corpid: 55d8e2e21120eb4d0ee019386e19589b
+      response_type: code
 #AD域服务器地址相关
   ad:
     address: ldap://10.103.4.45:389
@@ -64,15 +72,21 @@ scheduled:
   #OA岗位 每天凌晨03:30:10和04:30:10  able为1是可用  2是禁用
   position:
     cron: 10 30 3,4 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA组织  每天凌晨01:30:10和02:30:10 able为1是可用  2是禁用
   org:
     cron: 10 30 1,2 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA员工  通过定时任务每天 8点、13点、18点 执行 进行同步 able为1是可用  2是禁用
   person:
     cron: 0 0 8,13,18 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #AD用户 通过定时任务每天 8点05、13点05、18点05 执行 进行同步 able为1是可用  2是禁用
   ad:
     person:

+ 16 - 3
src/main/resources/application-sit.yml

@@ -48,7 +48,14 @@ api:
     #人员状态映射 key为SHR端的状态 value为OA端的状态
     statusmap: '{"On Probation":"试用","Employee":"正式","Permanent Employee":"正式","Temporary Worker":"临时",
     "试用延期":"试用延期","Dismiss":"解聘","Termination":"解聘","Dimission":"离职","Resignation":"离职","Retirement":"退休","无效":"无效"}'
-
+    new:
+      #e10系统OA相关
+      url: https://sites.gtiit.edu.cn/oatest
+      app_key: b9693deee1dba5f70134e81161d7b31
+      app_secret: 550856d7234a759b333a93aeb09739d3
+      grant_type: authorization_code
+      corpid: 4bfaa311d6ac47f4822020e1ff3f2bf8
+      response_type: code
 
 
   #AD域服务器地址相关
@@ -70,15 +77,21 @@ scheduled:
   #OA岗位 每天凌晨03:30:10和04:30:10  able为1是可用  2是禁用
   position:
     cron: 10 30 3,4 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA组织  每天凌晨01:30:10和02:30:10 able为1是可用  2是禁用
   org:
     cron: 10 30 1,2 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA员工  通过定时任务每天 8点、13点、18点 执行 进行同步 able为1是可用  2是禁用
   person:
     cron: 0 0 8,13,18 * * ?
     able: 2
+    new:
+      able: 1
   #AD用户 通过定时任务每天 8点、13点、18点 执行 进行同步 able为1是可用  2是禁用
   ad:
     person:

+ 17 - 3
src/main/resources/application-uat.yml

@@ -50,6 +50,14 @@ api:
     #人员状态映射 key为SHR端的状态 value为OA端的状态
     statusmap: '{"On Probation":"试用","Employee":"正式","Permanent Employee":"正式","Temporary Worker":"临时",
     "试用延期":"试用延期","Dismiss":"解聘","Termination":"解聘","Dimission":"离职","Resignation":"离职","Retirement":"退休","无效":"无效"}'
+    new:
+      #e10系统OA相关
+      url: https://sites.gtiit.edu.cn/oatest
+      app_key: b9693deee1dba5f70134e81161d7b31
+      app_secret: 550856d7234a759b333a93aeb09739d3
+      grant_type: authorization_code
+      corpid: 4bfaa311d6ac47f4822020e1ff3f2bf8
+      response_type: code
 #AD域服务器地址相关
   ad:
     #服务器地址
@@ -73,15 +81,21 @@ scheduled:
   #OA岗位 每天凌晨03:30:10和04:30:10  able为1是可用  2是禁用
   position:
     cron: 10 30 3,4 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA组织  每天凌晨01:30:10和02:30:10 able为1是可用  2是禁用
   org:
     cron: 10 30 1,2 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #OA员工  通过定时任务每天 8点、13点、18点 执行 进行同步 able为1是可用  2是禁用
   person:
     cron: 0 0 8,13,18 * * ?
-    able: 1
+    able: 2
+    new:
+      able: 1
   #AD用户 通过定时任务每天 8点、13点、18点 执行 进行同步 able为1是可用  2是禁用
   ad:
     person:

+ 6 - 3
src/main/resources/templates/detail.html

@@ -129,7 +129,8 @@
                 })
               if(this.activeName==='OA员工同步'){
                 res = await axios({
-                  url: `${apiUrl}/OA/synPerson`,
+                  // url: `${apiUrl}/OA/synPerson`,
+                  url: `${apiUrl}/new/person`,
                   method: 'get',
                   params:{
                       startDate:dayjs(this.form.startDate).format("YYYY-MM-DD"),
@@ -200,7 +201,8 @@
 
                 if(this.activeName==='OA组织同步'){
                     res = await axios({
-                        url: `${apiUrl}/admin`,
+                        // url: `${apiUrl}/admin`,
+                        url: `${apiUrl}/new/admin`,
                         method: 'get',
                         params:{
                             statrTime:dayjs(this.form.startDate).format("YYYY-MM-DD HH:mm:ss"),
@@ -223,7 +225,8 @@
 
                 if(this.activeName==='OA岗位同步'){
                     res = await axios({
-                        url: `${apiUrl}/position`,
+                        // url: `${apiUrl}/position`,
+                        url: `${apiUrl}/new/position`,
                         method: 'get',
                         params:{
                             statrTime:dayjs(this.form.startDate).format("YYYY-MM-DD"),