SynchronousPosOSFService.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. package com.kingdee.eas.custom.beisen.synchronouspos.osf;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.common.collect.Maps;
  5. import com.kingdee.bos.BOSException;
  6. import com.kingdee.bos.Context;
  7. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  8. import com.kingdee.bos.rabbitmq.guava.Lists;
  9. import com.kingdee.eas.common.EASBizException;
  10. import com.kingdee.eas.custom.beisen.utils.BeiSenUtils;
  11. import com.kingdee.eas.custom.beisen.utils.BeisenParamByPropertiesUtil;
  12. import com.kingdee.eas.custom.beisen.utils.Helper;
  13. import com.kingdee.eas.util.app.DbUtil;
  14. import com.kingdee.jdbc.rowset.IRowSet;
  15. import org.apache.commons.lang3.StringUtils;
  16. import java.io.IOException;
  17. import java.net.URISyntaxException;
  18. import java.net.URLEncoder;
  19. import java.sql.Date;
  20. import java.sql.SQLException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.Arrays;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 岗位同步
  28. * description: SynchronousPosOSFService <br>
  29. * date: 2025/7/11 17:46 <br>
  30. * author: lhbj <br>
  31. * version: 1.0 <br>
  32. */
  33. public class SynchronousPosOSFService implements IHRMsfService {
  34. @Override
  35. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  36. //例:/server/properties/beisen/posConfig.properties
  37. String path = (String) map.get("path");
  38. String posId = (String) map.get("posId");
  39. String syncStartTimeStr = (String) map.get("syncStartTimeStr");
  40. String syncEndTimeStr = (String) map.get("syncEndTimeStr");
  41. try {
  42. BeisenParamByPropertiesUtil util = new BeisenParamByPropertiesUtil(path);
  43. Map<String,String> keyMap = util.getConfig();
  44. return this._syncPosToBeiSen(context,keyMap,posId,syncStartTimeStr,syncEndTimeStr);
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. } catch (SQLException throwables) {
  48. throwables.printStackTrace();
  49. } catch (URISyntaxException e) {
  50. e.printStackTrace();
  51. }
  52. return null;
  53. }
  54. protected String _syncPosToBeiSen(Context ctx,Map<String,String> keyMap, String posId, String syncStartTimeStr, String syncEndTimeStr) throws BOSException, SQLException, IOException, URISyntaxException {
  55. List<JSONObject> responseList =Lists.newArrayList();
  56. List<JSONObject> addNewList = this._sendAddNewPosToBeisen(ctx,keyMap,posId,syncStartTimeStr,syncEndTimeStr);
  57. responseList.addAll(addNewList);
  58. List<JSONObject> editList = this._sendEditPosToBeisen(ctx,keyMap,posId,syncStartTimeStr,syncEndTimeStr);
  59. responseList.addAll(editList);
  60. return responseList.toString();
  61. }
  62. /**
  63. * shr系统数据组装北森请求参数
  64. *
  65. * @param ctx
  66. * @param keyMap
  67. * @param sql
  68. * @return
  69. * @throws BOSException
  70. * @throws SQLException
  71. */
  72. protected List<Map<String, Object>> getPostData(Context ctx,Map<String,String> keyMap,StringBuilder sql) throws BOSException, SQLException {
  73. IRowSet rowSet = DbUtil.executeQuery(ctx,sql.toString());
  74. List<Map<String, Object>> posList = Lists.newArrayList();
  75. while (rowSet.next()){
  76. Map<String, Object> pos = Maps.newHashMap();
  77. for(Map.Entry<String,String> entry : keyMap.entrySet()){
  78. String shrKey = entry.getKey();
  79. String beisenKey = entry.getValue();
  80. if(shrKey.indexOf(".")>0){
  81. String[] keys=shrKey.split("\\.");
  82. if(2==keys.length){
  83. Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  84. if(null==map1){
  85. map1=Maps.newHashMap();
  86. pos.put(keys[0],map1);
  87. }
  88. String valueStr = rowSet.getString(keys[1]);
  89. if(beisenKey.indexOf(",")>0) {
  90. String[] beisenKeys = beisenKey.split(",");
  91. Object value = null;
  92. if("integer".equals(beisenKeys[1])){
  93. if(null!=valueStr){
  94. value=Integer.parseInt(valueStr);
  95. }
  96. }else {
  97. value = valueStr;
  98. }
  99. if(null!=value) {
  100. map1.put(beisenKeys[0], value);
  101. }
  102. }else {
  103. if(null!=valueStr) {
  104. map1.put(beisenKey, valueStr);
  105. }
  106. }
  107. }else if (3==keys.length){
  108. Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  109. if(null==map1){
  110. map1=Maps.newHashMap();
  111. pos.put(keys[0],map1);
  112. }
  113. Map<String,Object> map2 = (Map<String, Object>) map1.get(keys[1]);
  114. if(null==map2){
  115. map2=Maps.newHashMap();
  116. map1.put(keys[1],map1);
  117. }
  118. String valueStr = rowSet.getString(keys[2]);
  119. if(beisenKey.indexOf(",")>0) {
  120. String[] beisenKeys = beisenKey.split(",");
  121. Object value = null;
  122. if("integer".equals(beisenKeys[1])){
  123. if(null!=valueStr){
  124. value=Integer.parseInt(valueStr);
  125. }
  126. }else {
  127. value = valueStr;
  128. }
  129. if(null!=value) {
  130. map2.put(beisenKeys[0], value);
  131. }
  132. }else {
  133. if(null!=valueStr) {
  134. map2.put(beisenKey,valueStr);
  135. }
  136. }
  137. }
  138. }else {
  139. String valueStr = rowSet.getString(shrKey);
  140. if(beisenKey.indexOf(",")>0) {
  141. String[] beisenKeys = beisenKey.split(",");
  142. Object value = null;
  143. if("integer".equals(beisenKeys[1])){
  144. if(null!=valueStr){
  145. value=Integer.parseInt(valueStr);
  146. }
  147. }else {
  148. value = valueStr;
  149. }
  150. if(null!=value) {
  151. pos.put(beisenKeys[0],value);
  152. }
  153. }else {
  154. if(null!=valueStr) {
  155. pos.put(beisenKey,valueStr);
  156. }
  157. }
  158. }
  159. }
  160. posList.add(pos);
  161. }
  162. return posList;
  163. }
  164. public StringBuilder getSql(String posId,String syncStartTimeStr, String syncEndTimeStr,Boolean isAddNew){
  165. StringBuilder sql = new StringBuilder();
  166. sql.append(" ");
  167. sql.append(" select ");
  168. sql.append(" pos.fid posId, ");
  169. sql.append(" pos.CFOriginalId posOriginalId, ");
  170. sql.append(" pos.fnumber posNumber, ");
  171. sql.append(" pos.fname_l2 posName, ");
  172. sql.append(" org.fid orgId, ");
  173. sql.append(" org.FreserveFieldFirst orgOriginalId, ");
  174. sql.append(" isnull(org.fnumber,'') orgNumber, ");
  175. sql.append(" isnull(org.fname_l2,'') orgName, ");
  176. sql.append(" (case when pos.FDELETEDSTATUS=2 then 0 else 1 end) posDeletedStatus, ");
  177. sql.append(" isnull(pos.cfzwjzygx,'') posZwjzygx, ");
  178. sql.append(" isnull(pos.cfzyzz,'') posZyzz, ");
  179. sql.append(" isnull(pos.cfgwdwsccg,'') posGwdwsccg, ");
  180. sql.append(" isnull(pos.cfcgzb,'') posCgzb, ");
  181. sql.append(" isnull(pos.cfzlzb,'') posZlzb, ");
  182. sql.append(" isnull(jobf.fname_l2,'') hrJobFamily, ");
  183. sql.append(" isnull(jobc.fname_l2,'') hrJobCategory, ");
  184. sql.append(" isnull(jobsc.fname_l2,'') jobscHrJobSubCategory, ");
  185. sql.append(" isnull(job.fnumber,'') jobNumber, ");
  186. sql.append(" isnull(job.fname_l2,'') jobName, ");
  187. sql.append(" isnull(lowjg.fname_l2,'') lowJobGrade, ");
  188. sql.append(" isnull(highjg.fname_l2,'') highJobGrade, ");
  189. sql.append(" isnull(lowjl.fname_l2,'') lowJobLevel, ");
  190. sql.append(" isnull(highjl.fname_l2,'') highJobLevel, ");
  191. sql.append(" isnull(pos.cfeducation,'') education, ");
  192. sql.append(" isnull(pos.cfrequirement,'') requirement, ");
  193. sql.append(" isnull(pos.cfcertification,'') certification, ");
  194. sql.append(" isnull(pos.cfforeignLang,'') foreignLang, ");
  195. sql.append(" isnull(pos.cfknowledge,'') knowledge, ");
  196. sql.append(" isnull(pos.cfskills,'') skills, ");
  197. sql.append(" isnull(pos.cfexperience,'') experience, ");
  198. sql.append(" isnull(pos.cfcoreCompe,'') coreCompe, ");
  199. sql.append(" isnull(pos.cfposition1,'') position1, ");
  200. sql.append(" isnull(pos.cfptime1,'') ptime1, ");
  201. sql.append(" isnull(pos.cfposition2,'') position2, ");
  202. sql.append(" isnull(pos.cfptime2,'') ptime2, ");
  203. sql.append(" isnull(workAdd.fnumber,'') workAdd, ");
  204. sql.append(" isnull(pos.CFFrequency,'') frequency, ");
  205. sql.append(" isnull(pos.cfjobRespon,'') jobRespon, ");
  206. sql.append(" isnull(pos.cfqualifications,'') qualifications, ");
  207. sql.append(" isnull(pos.cfreserved1,'') reserved1, ");
  208. sql.append(" isnull(pos.cfreserved2,'') reserved2, ");
  209. sql.append(" isnull(pos.cfreserved3,'') reserved3, ");
  210. sql.append(" isnull(pos.cfreserved4,'') reserved4, ");
  211. sql.append(" isnull(redf.FNumber,'') reserved5, ");
  212. sql.append(" posp.CFOriginalId pospOriginalId1, ");
  213. sql.append(" posp.CFOriginalId pospOriginalId2, ");
  214. sql.append(" '' ");
  215. sql.append(" from ");
  216. sql.append(" t_org_position pos ");
  217. sql.append(" left join t_org_admin org on pos.FADMINORGUNITID = org.fid ");
  218. sql.append(" left join CT_CUS_WorkAdd workAdd on workAdd.fid=pos.CFWorkAddID ");
  219. sql.append(" left join T_ORG_Job orgjob on orgjob.fid=pos.fjobid ");
  220. sql.append(" left join T_HR_HRJob job on job.FjobID = orgjob.fid ");
  221. sql.append(" left join T_HR_POSITIONEXTEND posex on posex.FPositionID=pos.fid ");
  222. sql.append(" left join T_HR_HRJobFamily jobf on jobf.fid = job.FHRJobFamilyID ");
  223. sql.append(" left join T_HR_HRJobCategory jobc on jobc.fid = job.FHRJobCategoryID ");
  224. sql.append(" left join T_HR_HRJobSubCategory jobsc on jobsc.fid=job.FHRJobSubCategoryID ");
  225. sql.append(" left join T_HR_JobGrade lowjg on lowjg.fid = pos.FLowJobGradeID ");
  226. sql.append(" left join T_HR_JobGrade highjg on highjg.fid = pos.FHighJobGradeID ");
  227. sql.append(" left join T_HR_JobLevel lowjl on lowjl.fid=posex.FLowJobLevel ");
  228. sql.append(" left join T_HR_JobLevel highjl on highjl.fid=posex.FHighJobLevel ");
  229. sql.append(" left join t_org_position posp on posp.fid=pos.FPARENTID ");
  230. sql.append(" left join CT_CUS_ReservedField redf on redf.fid=pos.CFReserved5ID ");
  231. sql.append(" where 1=1 ");
  232. if(StringUtils.isNotBlank(posId)){
  233. String[] posIds=posId.split(",");
  234. sql.append(" and pos.fid in('' ");
  235. for(String id : posIds){
  236. sql.append(",'");
  237. sql.append(id);
  238. sql.append("'");
  239. }
  240. sql.append(") ");
  241. }
  242. if(StringUtils.isNotBlank(syncStartTimeStr)){
  243. sql.append(" and pos.FLastUpdateTime >='"+syncStartTimeStr+"'");
  244. }
  245. if(StringUtils.isNotBlank(syncEndTimeStr)){
  246. sql.append(" and pos.FLastUpdateTime <='"+syncEndTimeStr+"'");
  247. }
  248. if(isAddNew){
  249. sql.append(" and (pos.CFOriginalId is null or pos.CFOriginalId ='')");
  250. }else {
  251. sql.append(" and (pos.CFOriginalId is not null and pos.CFOriginalId !='')");
  252. }
  253. return sql;
  254. }
  255. protected List<JSONObject> _sendAddNewPosToBeisen(Context ctx,Map<String,String> keyMap, String posId, String syncStartTimeStr, String syncEndTimeStr) throws BOSException, SQLException, IOException, URISyntaxException {
  256. BeiSenUtils b = new BeiSenUtils(ctx);
  257. Helper helper = b.helper;
  258. StringBuilder sql = this.getSql(posId, syncStartTimeStr, syncEndTimeStr, true);
  259. System.out.println("_sendAddNewPosToBeisen:"+sql);
  260. List<Map<String, Object>> list = this.getPostData(ctx, keyMap, sql);
  261. List<JSONObject> responseList = Lists.newArrayList();
  262. for (Map<String, Object> pos : list) {
  263. // 获取访问令牌
  264. String token = b.getAccessToken();
  265. // 若访问令牌不为空且开始时间和结束时间不为空
  266. if (!com.kingdee.util.StringUtils.isEmpty(token)) {
  267. // 创建请求头的 Map
  268. Map<String, String> header = new HashMap<String, String>();
  269. // 设置请求头的 Content-Type
  270. header.put("Content-Type", "application/json");
  271. // 设置请求头的 Authorization
  272. header.put("Authorization", "Bearer " + token);
  273. String url = "https://openapi.italent.cn/RecruitV6/api/v1/RecruitOnBoarding/CreatePost";
  274. JSONObject requestBody = new JSONObject(pos);
  275. System.out.println("url:" + url);
  276. System.out.println("requestBody:" + requestBody);
  277. JSONObject responseJson = helper.getURL(url, header, requestBody, "POST", requestBody.getString("posId"), "创建", "北森");
  278. System.out.println("responseJson:" + responseJson);
  279. Integer code = responseJson.getInteger("code");
  280. if(200==code){
  281. String data = responseJson.getString("data");
  282. String posId1 = requestBody.getString("posId");
  283. DbUtil.execute(ctx,"update t_org_position set CFOriginalId = ? where fid=?",new String[]{data,posId1});
  284. }
  285. responseList.add(responseJson);
  286. }
  287. }
  288. return responseList;
  289. }
  290. protected List<JSONObject> _sendEditPosToBeisen(Context ctx,Map<String,String> keyMap, String posId, String syncStartTimeStr, String syncEndTimeStr) throws BOSException, SQLException, IOException, URISyntaxException {
  291. BeiSenUtils b = new BeiSenUtils(ctx);
  292. Helper helper = b.helper;
  293. StringBuilder sql1 = this.getSql(posId,syncStartTimeStr,syncEndTimeStr,false);
  294. System.out.println("_sendAddNewPosToBeisen:"+sql1);
  295. List<Map<String,Object>> list1 = this.getPostData(ctx,keyMap,sql1);
  296. List<JSONObject> responseList = Lists.newArrayList();
  297. // 获取访问令牌
  298. String token = b.getAccessToken();
  299. for(Map<String,Object> pos : list1){
  300. // 若访问令牌不为空且开始时间和结束时间不为空
  301. if (!com.kingdee.util.StringUtils.isEmpty(token)) {
  302. // 创建请求头的 Map
  303. Map<String, String> header = new HashMap<String, String>();
  304. // 设置请求头的 Content-Type
  305. header.put("Content-Type", "application/json");
  306. // 设置请求头的 Authorization
  307. header.put("Authorization", "Bearer " + token);
  308. String url = "https://openapi.italent.cn/RecruitV6/api/v1/RecruitOnBoarding/UpdatePost";
  309. JSONObject requestBody = new JSONObject(pos);
  310. System.out.println("url:"+url);
  311. System.out.println("requestBody:"+requestBody);
  312. JSONObject responseJson = helper.getURL(url,header, requestBody, "PUT",requestBody.getString("posId"),"更新","北森");
  313. System.out.println("responseJson:"+responseJson);
  314. responseList.add(responseJson);
  315. }
  316. }
  317. return responseList;
  318. }
  319. }