From 0c82398dad95f536e22b5e1966f79aa29b2cf1c9 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期四, 03 七月 2025 19:34:39 +0800 Subject: [PATCH] 修改bug --- ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/qianyuntong/EmployeeUtil.java | 116 ++++++++++++++++++++++++++++++++++------------------------ 1 files changed, 68 insertions(+), 48 deletions(-) diff --git a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/qianyuntong/EmployeeUtil.java b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/qianyuntong/EmployeeUtil.java index b9ec866..f8c8724 100644 --- a/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/qianyuntong/EmployeeUtil.java +++ b/ManagementQYTTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/util/qianyuntong/EmployeeUtil.java @@ -2,6 +2,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.google.gson.Gson; import com.open.common.util.OpenApiClient; import com.open.common.util.SystemParameterNames; import com.stylefeng.guns.modular.system.util.qianyuntong.model.*; @@ -22,48 +23,22 @@ public class EmployeeUtil { - /** - * 企业增加员工 - * @param request - * @return - */ - public static Boolean saveStaffNode(SaveStaffNodeRequest request){ - //请求路径 - String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/saveStaffNode"; - //私钥文件 - String skprivateKeyFile = QianYunTongProperties.privateKeyPath; - //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密 - String appKey = QianYunTongProperties.appkey;//appkey - Map<String, String> headers = new HashMap<>(); - headers.put("Content-Type", "application/json"); - Map<String, Object> contentMap = new HashMap<String, Object>(); - Date nowdate = new Date(); - SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss"); - - String timeStamp = date.format(nowdate); - String messageId = UUID.randomUUID().toString().replaceAll("-", ""); - contentMap.put(SystemParameterNames.getAppKey(), appKey); - contentMap.put(SystemParameterNames.getMessage_id(), messageId); - contentMap.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName); - contentMap.put(SystemParameterNames.getStatus(), QianYunTongProperties.status); - contentMap.put("content", JSON.toJSONString(request)); - log.info("【企业增加员工】请求地址:" + url); - log.info("【企业增加员工】请求参数:" + JSON.toJSONString(contentMap)); - String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, contentMap); - log.info("【企业增加员工】请求结果:" + result); - JSONObject jsonObject = JSON.parseObject(result); - String retCode = jsonObject.getString("retCode"); - if (!"0".equals(retCode)) { - log.error("【企业增加员工】请求失败:" + result); - throw new RuntimeException("【企业增加员工】请求失败:" + result); - } - JSONObject object = jsonObject.getJSONObject("object"); - String status = object.getString("status"); - if (!"0".equals(status)) { - log.error("【企业增加员工】失败:" + object.toJSONString()); - throw new RuntimeException("【企业增加员工】失败:" + object.toJSONString()); - } - return true; + public static void main(String[] args) { + SaveStaffNodeRequest request = new SaveStaffNodeRequest(); + request.setMobile("18798410042"); + request.setEntercode("9811000039358999"); + request.setEmpName("莫萍"); + request.setEmpNickname("莫萍"); + request.setLoginNo("15180824124"); + request.setEmpSex("女"); + request.setMphone("15180824124"); + request.setEmail("15180824124" + "@qyt.com"); + request.setDeptId(0); + request.setPositionId(1); + request.setSuperLevel(0); + request.setHideMobile(0); + SaveStaffNode saveStaffNode = EmployeeUtil.saveStaffNode(request); + System.out.println(saveStaffNode); } @@ -91,7 +66,7 @@ contentMap.put(SystemParameterNames.getMessage_id(), messageId); contentMap.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName); contentMap.put(SystemParameterNames.getStatus(), QianYunTongProperties.status); - contentMap.put("content", JSON.toJSONString(request)); + contentMap.put("content", new Gson().toJson(request)); log.info("【企业修改员工信息】请求地址:" + url); log.info("【企业修改员工信息】请求参数:" + JSON.toJSONString(contentMap)); String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, contentMap); @@ -137,7 +112,7 @@ contentMap.put(SystemParameterNames.getMessage_id(), messageId); contentMap.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName); contentMap.put(SystemParameterNames.getStatus(), QianYunTongProperties.status); - contentMap.put("content", JSON.toJSONString(request)); + contentMap.put("content", new Gson().toJson(request)); log.info("【企业删除人员】请求地址:" + url); log.info("【企业删除人员】请求参数:" + JSON.toJSONString(contentMap)); String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, contentMap); @@ -182,7 +157,7 @@ contentMap.put(SystemParameterNames.getMessage_id(), messageId); contentMap.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName); contentMap.put(SystemParameterNames.getStatus(), QianYunTongProperties.status); - contentMap.put("content", JSON.toJSONString(request)); + contentMap.put("content", new Gson().toJson(request)); log.info("【根据员工ID获取人员信息】请求地址:" + url); log.info("【根据员工ID获取人员信息】请求参数:" + JSON.toJSONString(contentMap)); String result = OpenApiClient.sendCommonHttpRequst(url, headers, "GET", skprivateKeyFile, timeStamp, contentMap); @@ -191,15 +166,60 @@ String retCode = jsonObject.getString("retCode"); if (!"0".equals(retCode)) { log.error("【根据员工ID获取人员信息】请求失败:" + result); - throw new RuntimeException("【根据员工ID获取人员信息】请求失败:" + result); + return null; } JSONObject object = jsonObject.getJSONObject("object"); String status = object.getString("status"); if (!"0".equals(status)) { log.error("【根据员工ID获取人员信息】失败:" + object.toJSONString()); - throw new RuntimeException("【根据员工ID获取人员信息】失败:" + object.toJSONString()); + return null; } - StaffNodeInfo staffNodeInfo = jsonObject.getObject("object", StaffNodeInfo.class); + StaffNodeInfo staffNodeInfo = object.getObject("data", StaffNodeInfo.class); return staffNodeInfo; } + + /** + * 企业增加员工 + * @param request + * @return + */ + public static SaveStaffNode saveStaffNode(SaveStaffNodeRequest request){ + //请求路径 + String url = QianYunTongProperties.apiUrl + "/openapi/rest/1.0/saveStaffNode"; + //私钥文件 + String skprivateKeyFile = QianYunTongProperties.privateKeyPath; + //注意:私钥文件需要开发者手动新建.pem文件,将委办局提供的私钥串复制进文件里用于sign加密 + String appKey = QianYunTongProperties.appkey;//appkey + Map<String, String> headers = new HashMap<>(); + headers.put("Content-Type", "application/json"); + Map<String, Object> contentMap = new HashMap<String, Object>(); + Date nowdate = new Date(); + SimpleDateFormat date = new SimpleDateFormat("yyyyMMddHHmmss"); + + String timeStamp = date.format(nowdate); + String messageId = UUID.randomUUID().toString().replaceAll("-", ""); + contentMap.put(SystemParameterNames.getAppKey(), appKey); + contentMap.put(SystemParameterNames.getMessage_id(), messageId); + contentMap.put(SystemParameterNames.getUserName(), QianYunTongProperties.userName); + contentMap.put(SystemParameterNames.getStatus(), QianYunTongProperties.status); + contentMap.put("content", new Gson().toJson(request)); + log.info("【企业增加员工】请求地址:" + url); + log.info("【企业增加员工】请求参数:" + JSON.toJSONString(contentMap)); + String result = OpenApiClient.sendCommonHttpRequst(url, headers, "POST", skprivateKeyFile, timeStamp, contentMap); + log.info("【企业增加员工】请求结果:" + result); + JSONObject jsonObject = JSON.parseObject(result); + String retCode = jsonObject.getString("retCode"); + if (!"0".equals(retCode)) { + log.error("【企业增加员工】请求失败:" + result); + throw new RuntimeException("【企业增加员工】请求失败:" + result); + } + JSONObject object = jsonObject.getJSONObject("object"); + String status = object.getString("status"); + if (!"0".equals(status)) { + log.error("【企业增加员工】失败:" + object.toJSONString()); + throw new RuntimeException("【企业增加员工】失败:" + object.toJSONString()); + } + SaveStaffNode saveStaffNode = object.getObject("data", SaveStaffNode.class); + return saveStaffNode; + } } -- Gitblit v1.7.1