SyncStaffManageOSFService.java 12 KB

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