SyncStaffManageOSFService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package com.kingdee.eas.custom.beisen.synchronouspos.osf;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.google.common.collect.Maps;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.Context;
  6. import com.kingdee.bos.bsf.service.app.IHRMsfService;
  7. import com.kingdee.bos.rabbitmq.guava.Lists;
  8. import com.kingdee.eas.common.EASBizException;
  9. import com.kingdee.eas.custom.beisen.utils.BeiSenUtils;
  10. import com.kingdee.eas.custom.beisen.utils.BeisenParamByPropertiesUtil;
  11. import com.kingdee.eas.custom.beisen.utils.Helper;
  12. import com.kingdee.eas.util.app.DbUtil;
  13. import com.kingdee.jdbc.rowset.IRowSet;
  14. import java.sql.SQLException;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. public class SyncStaffManageOSFService implements IHRMsfService {
  19. @Override
  20. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  21. Map<String,List<Map<String,Object>>> result = Maps.newHashMap();
  22. List<Map<String,Object>> list = Lists.newArrayList();
  23. List<Map<String,Object>> listMap = Lists.newArrayList();
  24. result.put("list",list);
  25. result.put("listMap",listMap);
  26. String posPath = (String) map.get("posPath");
  27. String orgPath = (String) map.get("orgPath");
  28. StringBuilder sql = new StringBuilder();
  29. sql.append(" ");
  30. sql.append(" select fid,FYear,FTableName from T_HR_StaffManageProject ");
  31. sql.append(" where FRule in ( ");
  32. sql.append(" select fid from T_HR_StaffManageRule where fid in ( ");
  33. sql.append(" select FStaffManageRuleId from T_HR_STAFFMANAGERULEFIELD where FColumn in ('FpositionID', 'FAdminOrgID') group by FStaffManageRuleId HAVING count(fid)>1 ");
  34. sql.append(" ) and FState = 1 ");
  35. sql.append(" ) ");
  36. sql.append(" and FState = 1 ");
  37. sql.append(" and FChannel = 1 ");
  38. IRowSet rs = DbUtil.executeQuery(context, sql.toString());
  39. try{
  40. BeiSenUtils b = new BeiSenUtils(context);
  41. Helper helper = b.helper;
  42. BeisenParamByPropertiesUtil posUtil = new BeisenParamByPropertiesUtil(posPath);
  43. Map<String,String> poskeyMap = posUtil.getConfig();
  44. BeisenParamByPropertiesUtil orgUtil = new BeisenParamByPropertiesUtil(orgPath);
  45. Map<String,String> orgkeyMap = orgUtil.getConfig();
  46. while (rs.next()) {
  47. String fid = rs.getString("fid");
  48. String FTableName = rs.getString("FTableName");
  49. String FYear = rs.getString("FYear");
  50. StringBuilder selSql = new StringBuilder();
  51. selSql.append(" select 'org' orgpos,org.fid posId,org.fname_l2 orgPosName,org.FDisplayName_L2 staffName, ");
  52. selSql.append(" org.CFOriginalId,(case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
  53. selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
  54. selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
  55. selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
  56. selSql.append(" (staff.FState+1) FState ");
  57. selSql.append(" from ");
  58. selSql.append(" "+FTableName+" staff ");
  59. selSql.append(" left join t_org_admin org on org.fid=staff.FAdminOrgID ");
  60. selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
  61. selSql.append(" where pos.fid is null and org.CFOriginalId is not null ");
  62. selSql.append(" UNION all ");
  63. selSql.append(" select 'pos' orgpos,org.fid posId,org.fname_l2 orgPosName,org.FDisplayName_L2 staffName,pos.CFOriginalId, ");
  64. selSql.append(" (case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
  65. selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
  66. selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
  67. selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
  68. selSql.append(" (staff.FState+1) FState ");
  69. selSql.append(" from ");
  70. selSql.append(" "+FTableName+" staff ");
  71. selSql.append(" left join t_org_admin org on org.fid=staff.FAdminOrgID ");
  72. selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
  73. selSql.append(" where pos.fid is not null and pos.CFOriginalId is not null ");
  74. IRowSet rsSel = DbUtil.executeQuery(context, selSql.toString());
  75. // 获取访问令牌
  76. String token = b.getAccessToken();
  77. while (rsSel.next()){
  78. String orgpos= rsSel.getString("orgpos");
  79. if("org".equals(orgpos)){
  80. Map<String, Object> pos = this.getPostData(orgkeyMap,rsSel);
  81. if(null!=pos){
  82. // 若访问令牌不为空且开始时间和结束时间不为空
  83. if (!com.kingdee.util.StringUtils.isEmpty(token)) {
  84. // 创建请求头的 Map
  85. Map<String, String> header = new HashMap<String, String>();
  86. // 设置请求头的 Content-Type
  87. header.put("Content-Type", "application/json");
  88. // 设置请求头的 Authorization
  89. header.put("Authorization", "Bearer " + token);
  90. String url = "https://openapi.italent.cn/UserFrameworkApiV3/api/v1/departments/Put";
  91. JSONObject requestBody = new JSONObject(pos);
  92. System.out.println("url:"+url);
  93. System.out.println("requestBody:"+requestBody);
  94. JSONObject responseJson = helper.getURL(url,header, requestBody, "PUT",requestBody.getString("posId"),"更新","北森");
  95. System.out.println("responseJson:"+responseJson);
  96. listMap.add(responseJson);
  97. list.add(pos);
  98. }
  99. }
  100. }else if ("pos".equals(orgpos)){
  101. Map<String, Object> pos = this.getPostData(poskeyMap,rsSel);
  102. if(null!=pos){
  103. // 若访问令牌不为空且开始时间和结束时间不为空
  104. if (!com.kingdee.util.StringUtils.isEmpty(token)) {
  105. // 创建请求头的 Map
  106. Map<String, String> header = new HashMap<String, String>();
  107. // 设置请求头的 Content-Type
  108. header.put("Content-Type", "application/json");
  109. // 设置请求头的 Authorization
  110. header.put("Authorization", "Bearer " + token);
  111. String url = "https://openapi.italent.cn/RecruitV6/api/v1/RecruitOnBoarding/UpdatePost";
  112. JSONObject requestBody = new JSONObject(pos);
  113. System.out.println("url:"+url);
  114. System.out.println("requestBody:"+requestBody);
  115. JSONObject responseJson = helper.getURL(url,header, requestBody, "PUT",requestBody.getString("posId"),"更新","北森");
  116. System.out.println("responseJson:"+responseJson);
  117. listMap.add(responseJson);
  118. list.add(pos);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }catch (Exception e){
  125. e.printStackTrace();
  126. }finally {
  127. }
  128. return result;
  129. }
  130. /**
  131. * shr系统数据组装北森请求参数
  132. *
  133. * @param keyMap
  134. * @param rowSet
  135. * @return
  136. * @throws SQLException
  137. */
  138. protected Map<String, Object> getPostData(Map<String,String> keyMap, IRowSet rowSet) throws SQLException {
  139. Map<String, Object> pos = Maps.newHashMap();
  140. if (null!=rowSet){
  141. for(Map.Entry<String,String> entry : keyMap.entrySet()){
  142. String shrKey = entry.getKey();
  143. String beisenKey = entry.getValue();
  144. if(shrKey.indexOf(".")>0){
  145. String[] keys=shrKey.split("\\.");
  146. if(2==keys.length){
  147. Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  148. if(null==map1){
  149. map1=Maps.newHashMap();
  150. pos.put(keys[0],map1);
  151. }
  152. String valueStr = rowSet.getString(keys[1]);
  153. if(beisenKey.indexOf(",")>0) {
  154. String[] beisenKeys = beisenKey.split(",");
  155. Object value = null;
  156. if("integer".equals(beisenKeys[1])){
  157. if(null!=valueStr){
  158. value=Integer.parseInt(valueStr);
  159. }
  160. }else {
  161. value = valueStr;
  162. }
  163. if(null!=value) {
  164. map1.put(beisenKeys[0], value);
  165. }
  166. }else {
  167. if(null!=valueStr) {
  168. map1.put(beisenKey, valueStr);
  169. }
  170. }
  171. }else if (3==keys.length){
  172. Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  173. if(null==map1){
  174. map1=Maps.newHashMap();
  175. pos.put(keys[0],map1);
  176. }
  177. Map<String,Object> map2 = (Map<String, Object>) map1.get(keys[1]);
  178. if(null==map2){
  179. map2=Maps.newHashMap();
  180. map1.put(keys[1],map1);
  181. }
  182. String valueStr = rowSet.getString(keys[2]);
  183. if(beisenKey.indexOf(",")>0) {
  184. String[] beisenKeys = beisenKey.split(",");
  185. Object value = null;
  186. if("integer".equals(beisenKeys[1])){
  187. if(null!=valueStr){
  188. value=Integer.parseInt(valueStr);
  189. }
  190. }else {
  191. value = valueStr;
  192. }
  193. if(null!=value) {
  194. map2.put(beisenKeys[0], value);
  195. }
  196. }else {
  197. if(null!=valueStr) {
  198. map2.put(beisenKey,valueStr);
  199. }
  200. }
  201. }
  202. }else {
  203. String valueStr = rowSet.getString(shrKey);
  204. if(beisenKey.indexOf(",")>0) {
  205. String[] beisenKeys = beisenKey.split(",");
  206. Object value = null;
  207. if("integer".equals(beisenKeys[1])){
  208. if(null!=valueStr){
  209. value=Integer.parseInt(valueStr);
  210. }
  211. }else {
  212. value = valueStr;
  213. }
  214. if(null!=value) {
  215. pos.put(beisenKeys[0],value);
  216. }
  217. }else {
  218. if(null!=valueStr) {
  219. pos.put(beisenKey,valueStr);
  220. }
  221. }
  222. }
  223. }
  224. }
  225. return pos;
  226. }
  227. }