|
@@ -1,46 +1,17 @@
|
|
|
package com.kingdee.eas.custom.synctask.handler;
|
|
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.kingdee.bos.BOSException;
|
|
|
import com.kingdee.bos.Context;
|
|
|
-import com.kingdee.bos.dao.IObjectValue;
|
|
|
-import com.kingdee.bos.metadata.entity.EntityViewInfo;
|
|
|
-import com.kingdee.bos.metadata.entity.FilterInfo;
|
|
|
-import com.kingdee.bos.metadata.entity.FilterItemInfo;
|
|
|
-import com.kingdee.bos.metadata.entity.SelectorItemCollection;
|
|
|
-import com.kingdee.bos.metadata.query.util.CompareType;
|
|
|
-import com.kingdee.eas.base.permission.IUser;
|
|
|
-import com.kingdee.eas.base.permission.UserFactory;
|
|
|
-import com.kingdee.eas.base.permission.UserInfo;
|
|
|
-import com.kingdee.eas.basedata.org.*;
|
|
|
-import com.kingdee.eas.basedata.person.*;
|
|
|
import com.kingdee.eas.common.EASBizException;
|
|
|
-import com.kingdee.eas.custom.synctask.ActionTypeEnum;
|
|
|
import com.kingdee.eas.custom.synctask.SyncTranForOAFacadeFactory;
|
|
|
-import com.kingdee.eas.custom.synctask.entity.PersonEntity;
|
|
|
-import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryCollection;
|
|
|
-import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryFactory;
|
|
|
-import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntryInfo;
|
|
|
-import com.kingdee.eas.hr.affair.IEmpEnrollBizBillEntry;
|
|
|
-import com.kingdee.eas.hr.ats.AtsUtil;
|
|
|
-import com.kingdee.eas.hr.base.EmployeeTypeInfo;
|
|
|
-import com.kingdee.eas.hr.emp.*;
|
|
|
import com.kingdee.eas.hr.emp.web.handler.EmployeeListHandler;
|
|
|
-import com.kingdee.eas.hr.org.JobLevelInfo;
|
|
|
import com.kingdee.shr.base.syssetting.context.SHRContext;
|
|
|
-import com.kingdee.util.StringUtils;
|
|
|
-import okhttp3.*;
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.log4j.Logger;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author qingwu
|
|
@@ -49,242 +20,13 @@ import java.util.*;
|
|
|
*/
|
|
|
public class EmployeeListHandlerEx extends EmployeeListHandler {
|
|
|
public static Logger logger = Logger.getLogger(EmployeeListHandlerEx.class);
|
|
|
-
|
|
|
private Context ctx = SHRContext.getInstance().getContext();
|
|
|
- private Properties propt = new Properties();
|
|
|
-
|
|
|
- public EmployeeListHandlerEx() {
|
|
|
- try {
|
|
|
- //this.propt.load(new FileInputStream("E:\\Kingdee\\eas\\server\\properties\\scy\\syncOAConfig.properties"));
|
|
|
- propt.load(new FileInputStream(System.getProperty("EAS_HOME") + "/server/properties/scy/syncOAConfig.properties"));
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
public void syncPersonToOAAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, IOException, EASBizException {
|
|
|
String billIds = request.getParameter("billIds");
|
|
|
- //同步组织到OA
|
|
|
- //SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncOrgUnitToOA(billIds, null);
|
|
|
- _syncpersonToOA(billIds, null);
|
|
|
- }
|
|
|
-
|
|
|
- public void syncPersonFromAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws BOSException, IOException, EASBizException {
|
|
|
- String billIds = request.getParameter("billIds");
|
|
|
+ //同步人员到OA
|
|
|
SyncTranForOAFacadeFactory.getLocalInstance(ctx).syncPersonToOA(billIds, null);
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 同步人员
|
|
|
- *
|
|
|
- * @param billds
|
|
|
- * @param action
|
|
|
- * @throws BOSException
|
|
|
- */
|
|
|
- public void _syncpersonToOA(String billds, ActionTypeEnum action) throws BOSException, IOException, EASBizException {
|
|
|
- logger.error("_syncpersonToOA----------------------start");
|
|
|
- logger.error("_syncpersonToOA----------------------billds: " + billds);
|
|
|
- IPersonPosition iPersonPosition = PersonPositionFactory.getLocalInstance(ctx);
|
|
|
- List<PersonEntity> dataList = new ArrayList();
|
|
|
- //当参数billIds不为空值时,增量同步参数中的部门数据到OA
|
|
|
- FilterInfo filterInfo = null;
|
|
|
- if (!StringUtils.isEmpty(billds)) {
|
|
|
- Set<String> personIds = AtsUtil.toSet(billds);
|
|
|
- filterInfo = new FilterInfo();
|
|
|
- filterInfo.getFilterItems().add(new FilterItemInfo("person", personIds, CompareType.INCLUDE));
|
|
|
- }
|
|
|
- SelectorItemCollection sic = new SelectorItemCollection();
|
|
|
- sic.add("*");
|
|
|
- sic.add("person.number");
|
|
|
- sic.add("person.name");
|
|
|
- sic.add("person.id");
|
|
|
- sic.add("person.employeeType.number");
|
|
|
- sic.add("personDep.name");
|
|
|
- sic.add("personDep.number");
|
|
|
- sic.add("personDep.id");
|
|
|
- sic.add("jobLevel.name");
|
|
|
- sic.add("jobLevel.number");
|
|
|
- sic.add("primaryPosition.id");
|
|
|
- sic.add("primaryPosition.name");
|
|
|
- sic.add("primaryPosition.number");
|
|
|
- sic.add("primaryPosition.job.name");
|
|
|
- sic.add("primaryPosition.job.number");
|
|
|
- sic.add("primaryPosition.job.jobType.name");
|
|
|
- sic.add("primaryPosition.job.jobType.number");
|
|
|
- EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
|
|
|
- PersonPositionCollection personPositionCollection = iPersonPosition.getPersonPositionCollection(entityViewInfo);
|
|
|
- for (int i = 0; i < personPositionCollection.size(); i++) {
|
|
|
- //职业信息
|
|
|
- PersonPositionInfo personPositionInfo = personPositionCollection.get(i);
|
|
|
- PersonEntity person = packagingPerson(personPositionInfo);
|
|
|
- dataList.add(person);
|
|
|
- }
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- logger.error("_syncpersonToOA------------------dataList----- " + mapper.writeValueAsString(dataList));
|
|
|
- //调用执行同步组织到OA
|
|
|
- //executeSyncOrgUnitToOA(dataList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 封装人员对象
|
|
|
- *
|
|
|
- * @param personPositionInfo
|
|
|
- * @return
|
|
|
- */
|
|
|
- public PersonEntity packagingPerson(PersonPositionInfo personPositionInfo) throws BOSException, EASBizException {
|
|
|
- SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
-
|
|
|
- IUser iuser = UserFactory.getLocalInstance(ctx);
|
|
|
- //人员
|
|
|
- PersonInfo personInfo = personPositionInfo.getPerson();
|
|
|
- //自定义人员实体
|
|
|
- PersonEntity person = new PersonEntity();
|
|
|
- //编码
|
|
|
- person.setWorkcode(personInfo.getNumber());
|
|
|
- //人员名称
|
|
|
- logger.error("personInfo.getName------------" + personInfo.getName());
|
|
|
- person.setLastname(personInfo.getName());
|
|
|
- //分部
|
|
|
- //person.setSubcompany("0");
|
|
|
- //部门
|
|
|
- AdminOrgUnitInfo personDep = personPositionInfo.getPersonDep();
|
|
|
- person.setDepartment(personDep.getName());
|
|
|
- //直接上级 @todo
|
|
|
- person.setManagerid("");
|
|
|
- //助理 @todo
|
|
|
- person.setAssistantid("");
|
|
|
- //状态
|
|
|
- EmployeeTypeInfo employeeType = personInfo.getEmployeeType();
|
|
|
- String number = employeeType.getNumber();
|
|
|
- String personStatus = "";
|
|
|
- switch (number) {
|
|
|
- case "001": //正式员工
|
|
|
- personStatus = "正式";
|
|
|
- break;
|
|
|
- case "002": //试用员工
|
|
|
- personStatus = "试用";
|
|
|
- break;
|
|
|
- case "S06": //临时工
|
|
|
- personStatus = "临时";
|
|
|
- break;
|
|
|
- case "021": //解聘
|
|
|
- personStatus = "解聘";
|
|
|
- break;
|
|
|
- case "S09": //离职
|
|
|
- personStatus = "离职";
|
|
|
- break;
|
|
|
- case "011": //退休
|
|
|
- personStatus = "退休";
|
|
|
- break;
|
|
|
- default:
|
|
|
- personStatus = "无效";
|
|
|
- break;
|
|
|
- }
|
|
|
- person.setStatus(personStatus);
|
|
|
- //办公地点 @todo
|
|
|
- IObjectValue workPlace = (IObjectValue) personInfo.get("workPlace");
|
|
|
- if (workPlace != null) {
|
|
|
- person.setLocationid((String) workPlace.get("name"));
|
|
|
- }
|
|
|
- //移动电话
|
|
|
- person.setMobile(personInfo.getCell());
|
|
|
- //办公室电话
|
|
|
- person.setTelephone(personInfo.getOfficePhone());
|
|
|
- //电子邮件
|
|
|
- person.setEmail(personInfo.getEmail());
|
|
|
- //入职日期
|
|
|
- IEmpEnrollBizBillEntry iEmpEnrollBizBillEntry = EmpEnrollBizBillEntryFactory.getLocalInstance(ctx);
|
|
|
- EmpEnrollBizBillEntryCollection empEnrollBizBillEntryCollection = iEmpEnrollBizBillEntry.getEmpEnrollBizBillEntryCollection("where person = '" + personInfo.getId() + "'");
|
|
|
- if (empEnrollBizBillEntryCollection.size() > 0) {
|
|
|
-
|
|
|
- EmpEnrollBizBillEntryInfo empEnrollBizBillEntryInfo = empEnrollBizBillEntryCollection.get(0);
|
|
|
- Date enrollDate = empEnrollBizBillEntryInfo.getEnrollDate();
|
|
|
- person.setCompanystartdate(originalFormat.format(enrollDate));
|
|
|
- //参加工作日期
|
|
|
- Date jobStartDate = empEnrollBizBillEntryInfo.getJobStartDate();
|
|
|
- person.setWorkstartdate(originalFormat.format(jobStartDate));
|
|
|
- }
|
|
|
- //登录名称
|
|
|
- person.setLoginid(personInfo.getNumber());
|
|
|
- //明文密码,会转密文 默认:Scy$1234
|
|
|
- person.setPassword("Scy$1234");
|
|
|
- //安全级别
|
|
|
- person.setSeclevel("3");
|
|
|
- //人员类别
|
|
|
- IObjectValue personnelCa = (IObjectValue) personInfo.get("personnelCa");
|
|
|
- if (personnelCa != null) {
|
|
|
- Map customMap = new HashMap();
|
|
|
- customMap.put("field", personnelCa.get("name"));
|
|
|
- person.setWorkCustomData(customMap);
|
|
|
- }
|
|
|
- //职级
|
|
|
- JobLevelInfo jobLevel = personPositionInfo.getJobLevel();
|
|
|
- if (jobLevel != null) {
|
|
|
- person.setJoblevel(jobLevel.getName());
|
|
|
- }
|
|
|
-
|
|
|
- return person;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行同步组织到OA
|
|
|
- *
|
|
|
- * @param dataList
|
|
|
- */
|
|
|
- public void executeSyncOrgUnitToOA(List dataList) throws IOException, BOSException {
|
|
|
- if (dataList != null && dataList.size() > 0) {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- //封装请求参数
|
|
|
- String data = mapper.writeValueAsString(dataList);
|
|
|
- String params = String.format("token = %s &data = %s", getToken(), data);
|
|
|
- logger.error("executeSyncOrgUnitToOA----------------------params" + params);
|
|
|
- //封装请求参数
|
|
|
- //String syncOrgUnitApiUrl = "/api/hrm/resful/synDepartment";
|
|
|
- String syncOrgUnitApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|
|
|
- String url = this.propt.getProperty("url");
|
|
|
- logger.error("executeSyncOrgUnitToOA----------------------syncOrgUnitApiUrl" + syncOrgUnitApiUrl);
|
|
|
- if (StringUtils.isEmpty(syncOrgUnitApiUrl)) {
|
|
|
- throw new BOSException("同步组织到OA接口地址不能为空!");
|
|
|
- }
|
|
|
- OkHttpClient client = new OkHttpClient();
|
|
|
- MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
- RequestBody body = RequestBody.create(mediaType, params);
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(url + syncOrgUnitApiUrl)
|
|
|
- .post(body)
|
|
|
- .addHeader("Content-Type", "application/json")
|
|
|
- .addHeader("Accept", "*/*")
|
|
|
- .addHeader("Accept-Encoding", "gzip, deflate, br")
|
|
|
- .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
|
|
|
- .addHeader("Connection", "keep-alive")
|
|
|
- .build();
|
|
|
- Response response = client.newCall(request).execute();
|
|
|
- String respBody = response.body().string();
|
|
|
- if (response.isSuccessful()) {
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取token
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public String getToken() {
|
|
|
- String key = this.propt.getProperty("key");
|
|
|
- long l = System.currentTimeMillis();//时间戳毫秒数
|
|
|
- String code = key.concat(Long.toString(l));
|
|
|
- //String s = DigestUtils.md5Hex(code).toUpperCase();
|
|
|
- String s = DigestUtils.md5Hex(code).toUpperCase();
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("key", s);
|
|
|
- map.put("ts", Long.toString(l));
|
|
|
- logger.error("getToken" + JSONObject.toJSONString(map));
|
|
|
- return JSONObject.toJSONString(map);
|
|
|
- }
|
|
|
}
|