SyncStaffManageOSFService.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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.ExceptionUtil;
  14. import com.kingdee.eas.util.app.DbUtil;
  15. import com.kingdee.jdbc.rowset.IRowSet;
  16. import com.kingdee.shr.base.syssetting.IMSFServiceFacade;
  17. import com.kingdee.shr.base.syssetting.MSFServiceFacadeFactory;
  18. import java.io.IOException;
  19. import java.net.URISyntaxException;
  20. import java.net.URLEncoder;
  21. import java.sql.SQLException;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.concurrent.ExecutorService;
  26. import java.util.concurrent.Executors;
  27. /**
  28. * 编制同步
  29. * description: SynchronousPosOSFService <br>
  30. * date: 2025/7/11 17:46 <br>
  31. * author: lhbj <br>
  32. * version: 1.0 <br>
  33. */
  34. public class SyncStaffManageOSFService implements IHRMsfService {
  35. public Map<String, List<Map<String, Object>>> orgProcess(Context context, List<Map<String, Object>> orgListMap) throws IOException, URISyntaxException {
  36. return new StaffManageProcess().orgProcess(context, orgListMap);
  37. }
  38. public Map<String, List<Map<String, Object>>> posProcess(Context context, List<Map<String, Object>> posListMap) throws IOException, URISyntaxException {
  39. return new StaffManageProcess().posProcess(context, posListMap);
  40. }
  41. @Override
  42. public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
  43. String mack = (String) map.get("mack");
  44. Map<String, Object> result = Maps.newHashMap();
  45. List<Map<String, Object>> list = Lists.newArrayList();
  46. List<Map<String, Object>> listMap = Lists.newArrayList();
  47. List<Map<String, Object>> orgListMap = Lists.newArrayList();
  48. List<Map<String, Object>> posListMap = Lists.newArrayList();
  49. result.put("list", list);
  50. result.put("listMap", listMap);
  51. String posPath = (String) map.get("posPath");
  52. String orgPath = (String) map.get("orgPath");
  53. StringBuilder sql = new StringBuilder();
  54. sql.append(" ");
  55. sql.append(" select fid,FYear,FTableName from T_HR_StaffManageProject ");
  56. sql.append(" where FRule in ( ");
  57. sql.append(" select fid from T_HR_StaffManageRule where fid in ( ");
  58. sql.append(" select FStaffManageRuleId from T_HR_STAFFMANAGERULEFIELD where FColumn in ('FpositionID', 'FAdminOrgID') group by FStaffManageRuleId HAVING count(fid)>1 ");
  59. sql.append(" ) and FState = 1 ");
  60. sql.append(" ) ");
  61. sql.append(" and FState = 1 ");
  62. sql.append(" and FChannel = 1 ");
  63. IRowSet rs = DbUtil.executeQuery(context, sql.toString());
  64. try {
  65. BeisenParamByPropertiesUtil posUtil = new BeisenParamByPropertiesUtil(posPath);
  66. Map<String, String> poskeyMap = posUtil.getConfig();
  67. BeisenParamByPropertiesUtil orgUtil = new BeisenParamByPropertiesUtil(orgPath);
  68. Map<String, String> orgkeyMap = orgUtil.getConfig();
  69. while (rs.next()) {
  70. String fid = rs.getString("fid");
  71. String FTableName = rs.getString("FTableName");
  72. String FYear = rs.getString("FYear");
  73. StringBuilder selSql = new StringBuilder();
  74. selSql.append(" select * from ( ");
  75. selSql.append(" select 'org' orgpos,org.fid posId,org.Fnumber orgOriginalId,org.FParentID,org.fname_l2 orgPosName,org.FDisplayName_L2 staffName, ");
  76. //selSql.append(" org.Fid CFOriginalId, ");
  77. selSql.append(" org.Fnumber CFOriginalId, ");
  78. //selSql.append(" (case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
  79. selSql.append(" staff.FControlWay FControlWay, ");
  80. selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
  81. selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
  82. selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
  83. selSql.append(" (staff.FState) FState,staff.FContainSub, ");
  84. selSql.append(" 1 orgPosStatus ");
  85. selSql.append(" from ");
  86. selSql.append(" " + FTableName + " staff ");
  87. selSql.append(" left join t_org_admin org on org.fid=staff.FAdminOrgID ");
  88. selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
  89. selSql.append(" where pos.fid is null and org.FReserveFieldFirst is not null ");
  90. selSql.append(" UNION all ");
  91. selSql.append(" select 'pos' orgpos,pos.fid posId,org.FreserveFieldFirst orgOriginalId,pos.FParentID,pos.fname_l2 orgPosName,org.FDisplayName_L2 staffName,pos.CFOriginalId, ");
  92. //selSql.append(" (case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
  93. selSql.append(" staff.FControlWay FControlWay, ");
  94. selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
  95. selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
  96. selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
  97. selSql.append(" (staff.FState) FState,staff.FContainSub, ");
  98. selSql.append(" (case when pos.FDELETEDSTATUS=2 then 0 else 1 end) orgPosStatus ");
  99. selSql.append(" from ");
  100. selSql.append(" " + FTableName + " staff ");
  101. selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
  102. selSql.append(" left join t_org_admin org on org.fid=pos.FADMINORGUNITID ");
  103. selSql.append(" where pos.fid is not null and pos.CFOriginalId is not null ");
  104. selSql.append(" ) t order by t.FContainSub desc ");
  105. IRowSet rsSel = DbUtil.executeQuery(context, selSql.toString());
  106. // 获取访问令牌
  107. while (rsSel.next()) {
  108. String orgpos = rsSel.getString("orgpos");
  109. if ("org".equals(orgpos)) {
  110. Map<String, Object> pos = this.getPostData(orgkeyMap, rsSel);
  111. if (null != pos) {
  112. orgListMap.add(pos);
  113. }
  114. } else if ("pos".equals(orgpos)) {
  115. Map<String, Object> pos = this.getPostData(poskeyMap, rsSel);
  116. if (null != pos) {
  117. posListMap.add(pos);
  118. }
  119. }
  120. }
  121. result.put("orgListMap", orgListMap);
  122. result.put("posListMap", posListMap);
  123. }
  124. if ("org".equals(mack) || "pos".equals(mack)) {
  125. //Map<String,List<Map<String,Object>>> resultOrg = this.orgProcess(context,orgListMap);
  126. } else {
  127. ExecutorService executor = Executors.newFixedThreadPool(4);
  128. int orgLen = orgListMap.size();
  129. int batchSize = 50;
  130. for (int i = 0; i < orgLen; i += batchSize) {
  131. int end = Math.min(i + batchSize, orgLen);
  132. List<Map<String, Object>> orgSubListMap = orgListMap.subList(i, end);
  133. SyncOrgStaffManageRunnable syncOrg = new SyncOrgStaffManageRunnable(context, orgSubListMap);
  134. executor.submit(syncOrg);
  135. }
  136. int posLen = posListMap.size();
  137. for (int i = 0; i < posLen; i += batchSize) {
  138. int end = Math.min(i + batchSize, posLen);
  139. List<Map<String, Object>> posSubListMap = posListMap.subList(i, end);
  140. SyncPosStaffManageRunnable syncOrg = new SyncPosStaffManageRunnable(context, posSubListMap);
  141. executor.submit(syncOrg);
  142. }
  143. executor.shutdown();
  144. }
  145. } catch (Exception e) {
  146. e.printStackTrace();
  147. result.put("errMsg", ExceptionUtil.getExcLinkStackTrace(e));
  148. } finally {
  149. }
  150. return result;
  151. }
  152. /**
  153. * shr系统数据组装北森请求参数
  154. *
  155. * @param keyMap
  156. * @param rowSet
  157. * @return
  158. * @throws SQLException
  159. */
  160. protected Map<String, Object> getPostData(Map<String, String> keyMap, IRowSet rowSet) throws SQLException {
  161. Map<String, Object> pos = Maps.newHashMap();
  162. if (null != rowSet) {
  163. for (Map.Entry<String, String> entry : keyMap.entrySet()) {
  164. String shrKey = entry.getKey();
  165. String beisenKey = entry.getValue();
  166. if (shrKey.indexOf(".") > 0) {
  167. String[] keys = shrKey.split("\\.");
  168. if (2 == keys.length) {
  169. Map<String, Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  170. if (null == map1) {
  171. map1 = Maps.newHashMap();
  172. pos.put(keys[0], map1);
  173. }
  174. String valueStr = rowSet.getString(keys[1]);
  175. if (beisenKey.indexOf(",") > 0) {
  176. String[] beisenKeys = beisenKey.split(",");
  177. Object value = null;
  178. if ("integer".equals(beisenKeys[1])) {
  179. if (null != valueStr) {
  180. value = Integer.parseInt(valueStr);
  181. }
  182. } else {
  183. value = valueStr;
  184. }
  185. if (null != value) {
  186. map1.put(beisenKeys[0], value);
  187. }
  188. } else {
  189. if (null != valueStr) {
  190. map1.put(beisenKey, valueStr);
  191. }
  192. }
  193. } else if (3 == keys.length) {
  194. Map<String, Object> map1 = (Map<String, Object>) pos.get(keys[0]);
  195. if (null == map1) {
  196. map1 = Maps.newHashMap();
  197. pos.put(keys[0], map1);
  198. }
  199. Map<String, Object> map2 = (Map<String, Object>) map1.get(keys[1]);
  200. if (null == map2) {
  201. map2 = Maps.newHashMap();
  202. map1.put(keys[1], map1);
  203. }
  204. String valueStr = rowSet.getString(keys[2]);
  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. map2.put(beisenKeys[0], value);
  217. }
  218. } else {
  219. if (null != valueStr) {
  220. map2.put(beisenKey, valueStr);
  221. }
  222. }
  223. }
  224. } else {
  225. String valueStr = rowSet.getString(shrKey);
  226. if (beisenKey.indexOf(",") > 0) {
  227. String[] beisenKeys = beisenKey.split(",");
  228. Object value = null;
  229. if ("integer".equals(beisenKeys[1])) {
  230. if (null != valueStr) {
  231. value = Integer.parseInt(valueStr);
  232. }
  233. } else {
  234. value = valueStr;
  235. }
  236. if (null != value) {
  237. pos.put(beisenKeys[0], value);
  238. }
  239. } else {
  240. if (null != valueStr) {
  241. pos.put(beisenKey, valueStr);
  242. }
  243. }
  244. }
  245. }
  246. }
  247. return pos;
  248. }
  249. }