EmployeeListHandlerEx.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. package com.kingdee.eas.custom.synctask.handler;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.kingdee.bos.BOSException;
  5. import com.kingdee.bos.Context;
  6. import com.kingdee.bos.dao.IObjectValue;
  7. import com.kingdee.bos.metadata.entity.EntityViewInfo;
  8. import com.kingdee.bos.metadata.entity.FilterInfo;
  9. import com.kingdee.bos.metadata.entity.FilterItemInfo;
  10. import com.kingdee.bos.metadata.entity.SelectorItemCollection;
  11. import com.kingdee.bos.metadata.query.util.CompareType;
  12. import com.kingdee.eas.base.permission.IUser;
  13. import com.kingdee.eas.base.permission.UserFactory;
  14. import com.kingdee.eas.base.permission.UserInfo;
  15. import com.kingdee.eas.basedata.org.*;
  16. import com.kingdee.eas.basedata.person.*;
  17. import com.kingdee.eas.common.EASBizException;
  18. import com.kingdee.eas.custom.synctask.ActionTypeEnum;
  19. import com.kingdee.eas.custom.synctask.SyncTranForOAFacadeFactory;
  20. import com.kingdee.eas.custom.synctask.entity.PersonEntity;
  21. import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryCollection;
  22. import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryFactory;
  23. import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryInfo;
  24. import com.kingdee.eas.hr.affair.IEmpEnrollBizBillEntry;
  25. import com.kingdee.eas.hr.ats.AtsUtil;
  26. import com.kingdee.eas.hr.base.EmployeeTypeInfo;
  27. import com.kingdee.eas.hr.emp.*;
  28. import com.kingdee.eas.hr.emp.web.handler.EmployeeListHandler;
  29. import com.kingdee.eas.hr.org.JobLevelInfo;
  30. import com.kingdee.shr.base.syssetting.context.SHRContext;
  31. import com.kingdee.util.StringUtils;
  32. import okhttp3.*;
  33. import org.apache.commons.codec.digest.DigestUtils;
  34. import org.apache.log4j.Logger;
  35. import org.springframework.ui.ModelMap;
  36. import javax.servlet.http.HttpServletRequest;
  37. import javax.servlet.http.HttpServletResponse;
  38. import java.io.FileInputStream;
  39. import java.io.IOException;
  40. import java.text.SimpleDateFormat;
  41. import java.util.*;
  42. /**
  43. * @author qingwu
  44. * @date 2024/10/24
  45. * @apiNote 员工信息维护扩展
  46. */
  47. public class EmployeeListHandlerEx extends EmployeeListHandler {
  48. public static Logger logger = Logger.getLogger(EmployeeListHandlerEx.class);
  49. private Context ctx = SHRContext.getInstance().getContext();
  50. private Properties propt = new Properties();
  51. public EmployeeListHandlerEx() {
  52. try {
  53. //this.propt.load(new FileInputStream("E:\\Kingdee\\eas\\server\\properties\\scy\\syncOAConfig.properties"));
  54. propt.load(new FileInputStream(System.getProperty("EAS_HOME") + "/server/properties/scy/syncOAConfig.properties"));
  55. } catch (IOException e) {
  56. e.printStackTrace();
  57. }
  58. }
  59. public void syncPersonToOAAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, IOException, EASBizException {
  60. String billIds = request.getParameter("billIds");
  61. //同步组织到OA
  62. //SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncOrgUnitToOA(billIds, null);
  63. _syncpersonToOA(billIds, null);
  64. }
  65. public void syncPersonFromAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, IOException, EASBizException {
  66. String billIds = request.getParameter("billIds");
  67. SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncPersonToOA(billIds, null);
  68. }
  69. /**
  70. * 同步人员
  71. *
  72. * @param billds
  73. * @param action
  74. * @throws BOSException
  75. */
  76. public void _syncpersonToOA(String billds, ActionTypeEnum action) throws BOSException, IOException, EASBizException {
  77. logger.error("_syncpersonToOA----------------------start");
  78. logger.error("_syncpersonToOA----------------------billds: " + billds);
  79. IPersonPosition iPersonPosition = PersonPositionFactory.getLocalInstance(ctx);
  80. List<PersonEntity> dataList = new ArrayList();
  81. //当参数billIds不为空值时,增量同步参数中的部门数据到OA
  82. FilterInfo filterInfo = null;
  83. if (!StringUtils.isEmpty(billds)) {
  84. Set<String> personIds = AtsUtil.toSet(billds);
  85. filterInfo = new FilterInfo();
  86. filterInfo.getFilterItems().add(new FilterItemInfo("person", personIds, CompareType.INCLUDE));
  87. }
  88. SelectorItemCollection sic = new SelectorItemCollection();
  89. sic.add("*");
  90. sic.add("person.number");
  91. sic.add("person.name");
  92. sic.add("person.id");
  93. sic.add("person.employeeType.number");
  94. sic.add("personDep.name");
  95. sic.add("personDep.number");
  96. sic.add("personDep.id");
  97. sic.add("jobLevel.name");
  98. sic.add("jobLevel.number");
  99. sic.add("primaryPosition.id");
  100. sic.add("primaryPosition.name");
  101. sic.add("primaryPosition.number");
  102. sic.add("primaryPosition.job.name");
  103. sic.add("primaryPosition.job.number");
  104. sic.add("primaryPosition.job.jobType.name");
  105. sic.add("primaryPosition.job.jobType.number");
  106. EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
  107. PersonPositionCollection personPositionCollection = iPersonPosition.getPersonPositionCollection(entityViewInfo);
  108. for (int i = 0; i < personPositionCollection.size(); i++) {
  109. //职业信息
  110. PersonPositionInfo personPositionInfo = personPositionCollection.get(i);
  111. PersonEntity person = packagingPerson(personPositionInfo);
  112. dataList.add(person);
  113. }
  114. ObjectMapper mapper = new ObjectMapper();
  115. logger.error("_syncpersonToOA------------------dataList----- " + mapper.writeValueAsString(dataList));
  116. //调用执行同步组织到OA
  117. //executeSyncOrgUnitToOA(dataList);
  118. }
  119. /**
  120. * 封装人员对象
  121. *
  122. * @param personPositionInfo
  123. * @return
  124. */
  125. public PersonEntity packagingPerson(PersonPositionInfo personPositionInfo) throws BOSException, EASBizException {
  126. SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd");
  127. IUser iuser = UserFactory.getLocalInstance(ctx);
  128. //人员
  129. PersonInfo personInfo = personPositionInfo.getPerson();
  130. //自定义人员实体
  131. PersonEntity person = new PersonEntity();
  132. //编码
  133. person.setWorkcode(personInfo.getNumber());
  134. //人员名称
  135. logger.error("personInfo.getName------------" + personInfo.getName());
  136. person.setLastname(personInfo.getName());
  137. //分部
  138. //person.setSubcompany("0");
  139. //部门
  140. AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
  141. person.setDepartment(personDep.getName());
  142. //直接上级 @todo
  143. person.setManagerid("");
  144. //助理 @todo
  145. person.setAssistantid("");
  146. //状态
  147. EmployeeTypeInfo employeeType = personInfo.getEmployeeType();
  148. String number = employeeType.getNumber();
  149. String personStatus = "";
  150. switch (number) {
  151. case "001": //正式员工
  152. personStatus = "正式";
  153. break;
  154. case "002": //试用员工
  155. personStatus = "试用";
  156. break;
  157. case "S06": //临时工
  158. personStatus = "临时";
  159. break;
  160. case "021": //解聘
  161. personStatus = "解聘";
  162. break;
  163. case "S09": //离职
  164. personStatus = "离职";
  165. break;
  166. case "011": //退休
  167. personStatus = "退休";
  168. break;
  169. default:
  170. personStatus = "无效";
  171. break;
  172. }
  173. person.setStatus(personStatus);
  174. //办公地点 @todo
  175. IObjectValue workPlace = (IObjectValue) personInfo.get("workPlace");
  176. if (workPlace != null) {
  177. person.setLocationid((String) workPlace.get("name"));
  178. }
  179. //移动电话
  180. person.setMobile(personInfo.getCell());
  181. //办公室电话
  182. person.setTelephone(personInfo.getOfficePhone());
  183. //电子邮件
  184. person.setEmail(personInfo.getEmail());
  185. //入职日期
  186. IEmpEnrollBizBillEntry iEmpEnrollBizBillEntry = EmpEnrollBizBillEntryFactory.getLocalInstance(ctx);
  187. EmpEnrollBizBillEntryCollection empEnrollBizBillEntryCollection = iEmpEnrollBizBillEntry.getEmpEnrollBizBillEntryCollection("where person = '" + personInfo.getId() + "'");
  188. if (empEnrollBizBillEntryCollection.size() > 0) {
  189. EmpEnrollBizBillEntryInfo empEnrollBizBillEntryInfo = empEnrollBizBillEntryCollection.get(0);
  190. Date enrollDate = empEnrollBizBillEntryInfo.getEnrollDate();
  191. person.setCompanystartdate(originalFormat.format(enrollDate));
  192. //参加工作日期
  193. Date jobStartDate = empEnrollBizBillEntryInfo.getJobStartDate();
  194. person.setWorkstartdate(originalFormat.format(jobStartDate));
  195. }
  196. //登录名称
  197. person.setLoginid(personInfo.getNumber());
  198. //明文密码,会转密文 默认:Scy$1234
  199. person.setPassword("Scy$1234");
  200. //安全级别
  201. person.setSeclevel("3");
  202. //人员类别
  203. IObjectValue personnelCa = (IObjectValue) personInfo.get("personnelCa");
  204. if (personnelCa != null) {
  205. Map customMap = new HashMap();
  206. customMap.put("field", personnelCa.get("name"));
  207. person.setWorkCustomData(customMap);
  208. }
  209. //职级
  210. JobLevelInfo jobLevel = personPositionInfo.getJobLevel();
  211. if (jobLevel != null) {
  212. person.setJoblevel(jobLevel.getName());
  213. }
  214. return person;
  215. }
  216. /**
  217. * 执行同步组织到OA
  218. *
  219. * @param dataList
  220. */
  221. public void executeSyncOrgUnitToOA(List dataList) throws IOException, BOSException {
  222. if (dataList != null && dataList.size() > 0) {
  223. ObjectMapper mapper = new ObjectMapper();
  224. //封装请求参数
  225. String data = mapper.writeValueAsString(dataList);
  226. String params = String.format("token = %s &data = %s", getToken(), data);
  227. logger.error("executeSyncOrgUnitToOA----------------------params" + params);
  228. //封装请求参数
  229. //String syncOrgUnitApiUrl = "/api/hrm/resful/synDepartment";
  230. String syncOrgUnitApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
  231. String url = this.propt.getProperty("url");
  232. logger.error("executeSyncOrgUnitToOA----------------------syncOrgUnitApiUrl" + syncOrgUnitApiUrl);
  233. if (StringUtils.isEmpty(syncOrgUnitApiUrl)) {
  234. throw new BOSException("同步组织到OA接口地址不能为空!");
  235. }
  236. OkHttpClient client = new OkHttpClient();
  237. MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
  238. RequestBody body = RequestBody.create(mediaType, params);
  239. Request request = new Request.Builder()
  240. .url(url + syncOrgUnitApiUrl)
  241. .post(body)
  242. .addHeader("Content-Type", "application/json")
  243. .addHeader("Accept", "*/*")
  244. .addHeader("Accept-Encoding", "gzip, deflate, br")
  245. .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
  246. .addHeader("Connection", "keep-alive")
  247. .build();
  248. Response response = client.newCall(request).execute();
  249. String respBody = response.body().string();
  250. if (response.isSuccessful()) {
  251. } else {
  252. }
  253. }
  254. }
  255. /**
  256. * 获取token
  257. *
  258. * @return
  259. */
  260. public String getToken() {
  261. String key = this.propt.getProperty("key");
  262. long l = System.currentTimeMillis();//时间戳毫秒数
  263. String code = key.concat(Long.toString(l));
  264. //String s = DigestUtils.md5Hex(code).toUpperCase();
  265. String s = DigestUtils.md5Hex(code).toUpperCase();
  266. Map<String, String> map = new HashMap<>();
  267. map.put("key", s);
  268. map.put("ts", Long.toString(l));
  269. logger.error("getToken" + JSONObject.toJSONString(map));
  270. return JSONObject.toJSONString(map);
  271. }
  272. }