SyncStaffManageOSFService.java 12 KB

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