EmployeeListHandlerEx.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. //部署测试环境需要注释此行
  142. Map<String, String> resultMap = SyncTranForIOTFacadeFactory.getLocalInstance(ctx).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. logger.error("handleEnableWithTips----- >> ");
  163. batchMessageTipsHeader.setBillId(billId);
  164. batchMessageTipsHeader.setFailureCount(failure);
  165. batchMessageTipsHeader.setSuccessCount(success);
  166. ObjectMapper mapper = new ObjectMapper();
  167. logger.error("handleEnableWithTips----- >> " + mapper.writeValueAsString(batchMessageTipsHeader));
  168. logger.error("handleEnableWithTips--size--- >> " + batchMessageTipsHeader.getResult().size());
  169. //logger.error("batchMessageTipsHeader " + batchMessageTipsHeader.getSuccessCount());
  170. request.setAttribute("res_method_data", batchMessageTipsHeader);
  171. this.writeSuccessData(batchMessageTipsHeader);
  172. logger.error("handleEnableWithTips----- end ");
  173. } catch (Exception e) {
  174. e.printStackTrace();
  175. throw new ShrWebBizException(e);
  176. }
  177. }
  178. /**
  179. * 同步OA人员
  180. *
  181. * @param request
  182. * @param response
  183. * @param modelMap
  184. * @throws BOSException
  185. * @throws EASBizException
  186. * @throws SHRWebException
  187. */
  188. public void syncPersonToOAAction(HttpServletRequest request,
  189. HttpServletResponse response,
  190. ModelMap modelMap) throws BOSException, EASBizException, SHRWebException {
  191. Enumeration<String> headerNames = request.getHeaderNames();
  192. while (headerNames.hasMoreElements()) {
  193. String headerName = headerNames.nextElement();
  194. String headerValue = request.getHeader(headerName);
  195. logger.error("----headerNames------key【" + headerName + "】-value【 " + headerValue + "】");
  196. }
  197. Enumeration enu = request.getParameterNames();
  198. while (enu.hasMoreElements()) {
  199. String paraName = (String) enu.nextElement();
  200. logger.error("----ParameterNames------key【" + paraName + "】-value【 " + request.getParameter(paraName) + "】");
  201. }
  202. //String billId = request.getParameter("billId[]");
  203. ////}
  204. //if (StringUtils.isEmpty(billId)) {
  205. // billId = (String) request.getAttribute("billId[]");
  206. //}
  207. //if (StringUtils.isEmpty(billId)) {
  208. // billId = request.getParameter("billIds[]");
  209. //}
  210. //if (StringUtils.isEmpty(billId)) {
  211. // billId = (String) request.getAttribute("billIds[]");
  212. //}
  213. //logger.error("----headerNames------billId----" + billId);
  214. this.handleEnableWithTips(request, "");
  215. }
  216. protected void handleEnableWithTips(HttpServletRequest request, String methodName) throws SHRWebException {
  217. //String billId = this.getBillId(request);
  218. String billId = request.getParameter("billId");
  219. //}
  220. if (StringUtils.isEmpty(billId)) {
  221. billId = (String) request.getAttribute("billId");
  222. }
  223. if (StringUtils.isEmpty(billId)) {
  224. billId = request.getParameter("billIds[]");
  225. }
  226. if (StringUtils.isEmpty(billId)) {
  227. billId = (String) request.getAttribute("billId[]");
  228. }
  229. try {
  230. IPerson iPerson = PersonFactory.getLocalInstance(ctx);
  231. if (StringUtils.isEmpty(billId)) {
  232. PersonCollection personCollection = iPerson.getPersonCollection("select id");
  233. StringBuilder sb = new StringBuilder();
  234. for (int i = 0; i < personCollection.size(); i++) {
  235. String personId = personCollection.get(i).getId().toString();
  236. sb.append(personId).append(",");
  237. }
  238. sb.deleteCharAt(sb.lastIndexOf(","));
  239. billId = sb.toString();
  240. }
  241. Map<String, Object> resultMap = SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncPersonToOA(billId, null);
  242. logger.error("handleEnableWithTips----- resultMap----" + resultMap);
  243. if (resultMap != null && !resultMap.isEmpty()) {
  244. logger.error("handleEnableWithTips----- start ");
  245. logger.error("handleEnableWithTips----- billId-- " + billId);
  246. PersonCollection personCollection = iPerson.getPersonCollection("select id,number where id in (" + AtsUtil.getStrFromString(billId) + ")");
  247. int sucess = 0;
  248. int failure = 0;
  249. BatchMessageTipsHeader batchMessageTipsHeader = new BatchMessageTipsHeader();
  250. for (int i = 0; i < personCollection.size(); i++) {
  251. BatchMessageTipsBody body = new BatchMessageTipsBody();
  252. PersonInfo personInfo = personCollection.get(i);
  253. body.setId(personInfo.getId().toString());
  254. String personNumber = personInfo.getNumber();
  255. Map<String, String> map = (Map<String, String>) resultMap.get(personNumber);
  256. logger.error("map----" + map);
  257. if (map == null) {
  258. ++failure;
  259. body.setMuitTipsState(Boolean.FALSE);
  260. body.setMuitTipsMessage("同步数据不能为空或检查是否同步OA字段是否等于否!");
  261. } else {
  262. if ("success".equals(map.get("state"))) {
  263. ++sucess;
  264. body.setMuitTipsState(Boolean.TRUE);
  265. body.setMuitTipsMessage(map.get("msg"));
  266. } else {
  267. ++failure;
  268. body.setMuitTipsState(Boolean.FALSE);
  269. body.setMuitTipsMessage(map.get("msg"));
  270. }
  271. }
  272. batchMessageTipsHeader.addResult(body);
  273. }
  274. //if (StringUtils.isEmpty(billId)) {
  275. // Set setPersonIds = (Set) resultMap.get("setPersonIds");
  276. // FilterInfo filterInfo = new FilterInfo();
  277. // filterInfo.getFilterItems().add(new FilterItemInfo("id", setPersonIds, CompareType.NOTINCLUDE));
  278. // EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, null, null);
  279. // PersonCollection personCollection2 = iPerson.getPersonCollection(entityViewInfo);
  280. // StringBuilder sb = new StringBuilder();
  281. // for (int i = 0; i < personCollection2.size(); i++) {
  282. // PersonInfo personInfo = personCollection2.get(i);
  283. // sb.append(personInfo.getId().toString()).append(",");
  284. // }
  285. // sb.deleteCharAt(sb.lastIndexOf(","));
  286. // billId = sb.toString();
  287. //}
  288. logger.error("handleEnableWithTips----- >> ");
  289. batchMessageTipsHeader.setBillId(billId);
  290. batchMessageTipsHeader.setFailureCount(failure);
  291. batchMessageTipsHeader.setSuccessCount(sucess);
  292. logger.error("batchMessageTipsHeader " + batchMessageTipsHeader.getSuccessCount());
  293. request.setAttribute("res_method_data", batchMessageTipsHeader);
  294. this.writeSuccessData(batchMessageTipsHeader);
  295. logger.error("handleEnableWithTips----- end ");
  296. }
  297. } catch (Exception e) {
  298. e.printStackTrace();
  299. throw new ShrWebBizException(e);
  300. }
  301. }
  302. }