EmployeeListHandlerEx.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. package com.kingdee.eas.custom.synctask.handler;
  2. import com.fasterxml.jackson.databind.ObjectMapper;
  3. import com.kingdee.bos.BOSException;
  4. import com.kingdee.bos.Context;
  5. import com.kingdee.bos.metadata.entity.*;
  6. import com.kingdee.bos.metadata.query.util.CompareType;
  7. import com.kingdee.eas.basedata.person.IPerson;
  8. import com.kingdee.eas.basedata.person.PersonCollection;
  9. import com.kingdee.eas.basedata.person.PersonFactory;
  10. import com.kingdee.eas.basedata.person.PersonInfo;
  11. import com.kingdee.eas.common.EASBizException;
  12. import com.kingdee.eas.cp.taskmng.util.StringUtil;
  13. import com.kingdee.eas.custom.synctask.SyncTranForIOTFacadeFactory;
  14. import com.kingdee.eas.custom.synctask.SyncTranForOAFacadeFactory;
  15. import com.kingdee.eas.hr.ats.AtsUtil;
  16. import com.kingdee.eas.hr.emp.web.handler.EmployeeListHandler;
  17. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsBody;
  18. import com.kingdee.shr.base.syssetting.api.bean.BatchMessageTipsHeader;
  19. import com.kingdee.shr.base.syssetting.context.SHRContext;
  20. import com.kingdee.shr.base.syssetting.exception.SHRWebException;
  21. import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
  22. import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
  23. import com.kingdee.util.StringUtils;
  24. import org.apache.log4j.Logger;
  25. import org.springframework.ui.ModelMap;
  26. import javax.servlet.http.HttpServletRequest;
  27. import javax.servlet.http.HttpServletResponse;
  28. import java.util.*;
  29. /**
  30. * @author qingwu
  31. * @date 2024/10/24
  32. * @apiNote 员工信息维护扩展
  33. */
  34. public class EmployeeListHandlerEx extends EmployeeListHandler {
  35. public Logger logger = Logger.getLogger(EmployeeListHandlerEx.class);
  36. public Context ctx = SHRContext.getInstance().getContext();
  37. public static Map<String, String> personStatusMap = new HashMap<String, String>();
  38. static {
  39. personStatusMap.put("001", "1");//试用员工
  40. personStatusMap.put("011", "1");//待岗
  41. personStatusMap.put("006", "1");//长期病假
  42. personStatusMap.put("007", "1");//停薪留职
  43. personStatusMap.put("005", "1");//出国
  44. personStatusMap.put("012", "1");//返聘员工
  45. personStatusMap.put("031", "1");//长学
  46. personStatusMap.put("S01", "1");//实习生
  47. personStatusMap.put("S02", "1");//劳务派遣
  48. personStatusMap.put("S05", "1");//待分配
  49. personStatusMap.put("S03", "1");//顾问
  50. personStatusMap.put("S20", "1");//临时工
  51. personStatusMap.put("002", "3");//辞退
  52. personStatusMap.put("010", "3");//辞职
  53. personStatusMap.put("009", "3");//退休
  54. personStatusMap.put("003", "3");//下岗
  55. personStatusMap.put("004", "3");//离休
  56. personStatusMap.put("013", "3");//开除
  57. personStatusMap.put("020", "3");//解聘
  58. personStatusMap.put("021", "3");//失踪
  59. personStatusMap.put("030", "3");//死亡
  60. personStatusMap.put("S04", "3");//返聘终止
  61. personStatusMap.put("S08", "3");//离职
  62. personStatusMap.put("S09", "3");//派遣终止
  63. personStatusMap.put("035", "3");//临时工终止
  64. personStatusMap.put("S07", "3");//实习终止
  65. }
  66. /**
  67. * 获取人员批处理信息
  68. *
  69. * @param request
  70. * @param response
  71. * @param modelMap
  72. * @return
  73. */
  74. public void getPersonBatchInfoAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, ShrWebBizException {
  75. try {
  76. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  77. PersonCollection personCollection = null;
  78. String ids = request.getParameter("ids");
  79. if (StringUtil.isEmpty(ids)) {
  80. personCollection = iPerson.getPersonCollection();
  81. } else {
  82. Set<String> adminOrgIds = AtsUtil.toSet(ids);
  83. FilterInfo filterInfo = new FilterInfo();
  84. FilterItemCollection filterItems = filterInfo.getFilterItems();
  85. filterItems.add(new FilterItemInfo("id", adminOrgIds, CompareType.INCLUDE));
  86. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  87. personCollection = iPerson.getPersonCollection(entityViewInfo);
  88. }
  89. List list = new ArrayList();
  90. for (int i = 0; i < personCollection.size(); i++) {
  91. PersonInfo personInfo = personCollection.get(i);
  92. Map personMap = new HashMap();
  93. personMap.put("person.name", personInfo.getName());
  94. personMap.put("person.number", personInfo.getNumber());
  95. personMap.put("person.id", personInfo.getId().toString());
  96. personMap.put("id", personInfo.getId().toString());
  97. list.add(personMap);
  98. }
  99. JSONUtils.SUCCESS(list);
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. throw new ShrWebBizException(e);
  103. }
  104. }
  105. /**
  106. * 同步IOT人员
  107. * 后续如需部署生产去掉Ex
  108. * @param request
  109. * @param response
  110. * @param modelMap
  111. * @throws BOSException
  112. * @throws EASBizException
  113. * @throws SHRWebException
  114. */
  115. public void syncPersonToIotAction(HttpServletRequest request,
  116. HttpServletResponse response,
  117. ModelMap modelMap) throws BOSException, ShrWebBizException {
  118. String billId = request.getParameter("billId");
  119. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  120. PersonCollection personCollection = null;
  121. Set personIds = null;
  122. Map<String, String> personNameAndNumberMap = new HashMap<String, String>();
  123. if (StringUtils.isEmpty(billId)) {
  124. personCollection = iPerson.getPersonCollection("select id,number");
  125. StringBuilder sb = new StringBuilder();
  126. for (int i = 0; i < personCollection.size(); i++) {
  127. PersonInfo personInfo = personCollection.get(i);
  128. String personId = personInfo.getId().toString();
  129. String personNumber = personInfo.getNumber().toString();
  130. sb.append(personId).append(",");
  131. personNameAndNumberMap.put(personNumber, personId);
  132. }
  133. sb.deleteCharAt(sb.lastIndexOf(","));
  134. billId = sb.toString();
  135. } else {
  136. personCollection = iPerson.getPersonCollection("select id,number where id in (" + AtsUtil.getStrFromString(billId) + ")");
  137. }
  138. personIds = AtsUtil.toSet(billId);
  139. //调用同步IOT人员
  140. try {
  141. Map<String, String> resultMap = SyncTranForIOTFacadeFactory.getLocalInstance(ctx).syncPersonToIot(billId);
  142. //Map<String, String> resultMap = syncPersonToIot(billId);
  143. int failure = 0;
  144. int success = personIds.size();
  145. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  146. for (int i = 0; i < personCollection.size(); i++) {
  147. BatchMessageTipsBody body = new BatchMessageTipsBody();
  148. PersonInfo personInfo = personCollection.get(i);
  149. body.setId(personInfo.getId().toString());
  150. String personNumber = personInfo.getNumber();
  151. if (resultMap.containsKey(personNumber)) {
  152. //失败
  153. body.setMuitTipsState(false);
  154. body.setMuitTipsMessage(resultMap.get(personNumber));
  155. failure++;
  156. } else {
  157. body.setMuitTipsState(true);
  158. }
  159. batchMessageTipsHeader.addResult(body);
  160. }
  161. success -= failure;
  162. //for (int i = 0; i < list.size(); i++) {
  163. // BatchMessageTipsBody body = new BatchMessageTipsBody();
  164. // Map<String, String> map = list.get(i);
  165. // //personNameAndNumberMap
  166. // String personId = personNameAndNumberMap.get(map.get("id"));
  167. // //body.setId(map.get("id"));
  168. // body.setId(personId);
  169. // body.setMuitTipsState(Boolean.FALSE);
  170. // logger.error("result--personId--" + personId);
  171. // logger.error("result--msg--" + map.get("msg"));
  172. // body.setMuitTipsMessage(map.get("msg"));
  173. // batchMessageTipsHeader.addResult(body);
  174. //}
  175. logger.error("handleEnableWithTips----- >> ");
  176. batchMessageTipsHeader.setBillId(billId);
  177. batchMessageTipsHeader.setFailureCount(failure);
  178. batchMessageTipsHeader.setSuccessCount(success);
  179. ObjectMapper mapper = new ObjectMapper();
  180. logger.error("handleEnableWithTips----- >> " + mapper.writeValueAsString(batchMessageTipsHeader));
  181. logger.error("handleEnableWithTips--size--- >> " + batchMessageTipsHeader.getResult().size());
  182. //logger.error("batchMessageTipsHeader " + batchMessageTipsHeader.getSuccessCount());
  183. request.setAttribute("res_method_data", batchMessageTipsHeader);
  184. this.writeSuccessData(batchMessageTipsHeader);
  185. logger.error("handleEnableWithTips----- end ");
  186. } catch (Exception e) {
  187. e.printStackTrace();
  188. throw new ShrWebBizException(e);
  189. }
  190. }
  191. /**
  192. * 同步OA人员
  193. *
  194. * @param request
  195. * @param response
  196. * @param modelMap
  197. * @throws BOSException
  198. * @throws EASBizException
  199. * @throws SHRWebException
  200. */
  201. public void syncPersonToOAAction(HttpServletRequest request,
  202. HttpServletResponse response,
  203. ModelMap modelMap) throws BOSException, EASBizException, SHRWebException {
  204. Enumeration<String> headerNames = request.getHeaderNames();
  205. while (headerNames.hasMoreElements()) {
  206. String headerName = headerNames.nextElement();
  207. String headerValue = request.getHeader(headerName);
  208. logger.error("----headerNames------key【" + headerName + "】-value【 " + headerValue + "】");
  209. }
  210. Enumeration enu = request.getParameterNames();
  211. while (enu.hasMoreElements()) {
  212. String paraName = (String) enu.nextElement();
  213. logger.error("----ParameterNames------key【" + paraName + "】-value【 " + request.getParameter(paraName) + "】");
  214. }
  215. //String billId = request.getParameter("billId[]");
  216. ////}
  217. //if (StringUtils.isEmpty(billId)) {
  218. // billId = (String) request.getAttribute("billId[]");
  219. //}
  220. //if (StringUtils.isEmpty(billId)) {
  221. // billId = request.getParameter("billIds[]");
  222. //}
  223. //if (StringUtils.isEmpty(billId)) {
  224. // billId = (String) request.getAttribute("billIds[]");
  225. //}
  226. //logger.error("----headerNames------billId----" + billId);
  227. this.handleEnableWithTips(request, "");
  228. }
  229. protected void handleEnableWithTips(HttpServletRequest request, String methodName) throws SHRWebException {
  230. //String billId = this.getBillId(request);
  231. String billId = request.getParameter("billId");
  232. //}
  233. if (StringUtils.isEmpty(billId)) {
  234. billId = (String) request.getAttribute("billId");
  235. }
  236. if (StringUtils.isEmpty(billId)) {
  237. billId = request.getParameter("billIds[]");
  238. }
  239. if (StringUtils.isEmpty(billId)) {
  240. billId = (String) request.getAttribute("billId[]");
  241. }
  242. try {
  243. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  244. if (StringUtils.isEmpty(billId)) {
  245. PersonCollection personCollection = iPerson.getPersonCollection("select id");
  246. StringBuilder sb = new StringBuilder();
  247. for (int i = 0; i < personCollection.size(); i++) {
  248. String personId = personCollection.get(i).getId().toString();
  249. sb.append(personId).append(",");
  250. }
  251. sb.deleteCharAt(sb.lastIndexOf(","));
  252. billId = sb.toString();
  253. }
  254. Map<String, Object> resultMap = SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncPersonToOA(billId, null);
  255. logger.error("handleEnableWithTips----- resultMap----" + resultMap);
  256. if (resultMap != null && !resultMap.isEmpty()) {
  257. logger.error("handleEnableWithTips----- start ");
  258. logger.error("handleEnableWithTips----- billId-- " + billId);
  259. PersonCollection personCollection = iPerson.getPersonCollection("select id,number where id in (" + AtsUtil.getStrFromString(billId) + ")");
  260. int sucess = 0;
  261. int failure = 0;
  262. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  263. for (int i = 0; i < personCollection.size(); i++) {
  264. BatchMessageTipsBody body = new BatchMessageTipsBody();
  265. PersonInfo personInfo = personCollection.get(i);
  266. body.setId(personInfo.getId().toString());
  267. String personNumber = personInfo.getNumber();
  268. Map<String, String> map = (Map<String, String>) resultMap.get(personNumber);
  269. logger.error("map----" + map);
  270. if (map == null) {
  271. ++failure;
  272. body.setMuitTipsState(Boolean.FALSE);
  273. body.setMuitTipsMessage("同步数据不能为空或检查是否同步OA字段是否等于否!");
  274. } else {
  275. if ("success".equals(map.get("state"))) {
  276. ++sucess;
  277. body.setMuitTipsState(Boolean.TRUE);
  278. body.setMuitTipsMessage(map.get("msg"));
  279. } else {
  280. ++failure;
  281. body.setMuitTipsState(Boolean.FALSE);
  282. body.setMuitTipsMessage(map.get("msg"));
  283. }
  284. }
  285. batchMessageTipsHeader.addResult(body);
  286. }
  287. //if (StringUtils.isEmpty(billId)) {
  288. // Set setPersonIds = (Set) resultMap.get("setPersonIds");
  289. // FilterInfo filterInfo = new FilterInfo();
  290. // filterInfo.getFilterItems().add(new FilterItemInfo("id", setPersonIds, CompareType.NOTINCLUDE));
  291. // EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  292. // PersonCollection personCollection2 = iPerson.getPersonCollection(entityViewInfo);
  293. // StringBuilder sb = new StringBuilder();
  294. // for (int i = 0; i < personCollection2.size(); i++) {
  295. // PersonInfo personInfo = personCollection2.get(i);
  296. // sb.append(personInfo.getId().toString()).append(",");
  297. // }
  298. // sb.deleteCharAt(sb.lastIndexOf(","));
  299. // billId = sb.toString();
  300. //}
  301. logger.error("handleEnableWithTips----- >> ");
  302. batchMessageTipsHeader.setBillId(billId);
  303. batchMessageTipsHeader.setFailureCount(failure);
  304. batchMessageTipsHeader.setSuccessCount(sucess);
  305. logger.error("batchMessageTipsHeader " + batchMessageTipsHeader.getSuccessCount());
  306. request.setAttribute("res_method_data", batchMessageTipsHeader);
  307. this.writeSuccessData(batchMessageTipsHeader);
  308. logger.error("handleEnableWithTips----- end ");
  309. }
  310. } catch (Exception e) {
  311. e.printStackTrace();
  312. throw new ShrWebBizException(e);
  313. }
  314. }
  315. }