|
@@ -5,6 +5,7 @@ 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;
|
|
@@ -15,6 +16,7 @@ import com.kingdee.eas.basedata.org.AdminOrgUnitCollection;
|
|
|
import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
|
|
|
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
|
|
|
import com.kingdee.eas.basedata.org.IAdminOrgUnit;
|
|
|
+import com.kingdee.eas.basedata.person.PersonInfo;
|
|
|
import com.kingdee.eas.common.EASBizException;
|
|
|
import com.kingdee.eas.custom.log.ISyncLog;
|
|
|
import com.kingdee.eas.custom.log.SyncLogFactory;
|
|
@@ -24,8 +26,19 @@ import com.kingdee.eas.custom.log.app.DockingSystemEnum;
|
|
|
import com.kingdee.eas.custom.log.app.SyncEntityNameEnum;
|
|
|
import com.kingdee.eas.custom.log.app.SyncStatusEnum;
|
|
|
import com.kingdee.eas.custom.synctask.entity.AdminOrg;
|
|
|
+import com.kingdee.eas.custom.synctask.entity.PersonEntity;
|
|
|
import com.kingdee.eas.custom.synctask.entity.PositionEntity;
|
|
|
+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.IPersonPosition;
|
|
|
+import com.kingdee.eas.hr.emp.PersonPositionCollection;
|
|
|
+import com.kingdee.eas.hr.emp.PersonPositionFactory;
|
|
|
+import com.kingdee.eas.hr.emp.PersonPositionInfo;
|
|
|
+import com.kingdee.eas.hr.org.JobLevelInfo;
|
|
|
import com.kingdee.eas.util.app.DbUtil;
|
|
|
import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
import com.kingdee.util.StringUtils;
|
|
@@ -35,9 +48,8 @@ import org.apache.log4j.Logger;
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.nio.charset.Charset;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
import java.sql.SQLException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -90,6 +102,8 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
SelectorItemCollection sic = new SelectorItemCollection();
|
|
|
sic.add("*");
|
|
|
sic.add("parent.number");
|
|
|
+ sic.add("responPosition.name");
|
|
|
+ sic.add("responPosition.number");
|
|
|
EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
|
|
|
AdminOrgUnitCollection adminOrgUnitCollection = iAdminOrgUnit.getAdminOrgUnitCollection(entityViewInfo);
|
|
|
for (int i = 0; i < adminOrgUnitCollection.size(); i++) {
|
|
@@ -109,6 +123,37 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
//adminOrg.setParent_code("ITCS");
|
|
|
adminOrg.setOrg_code("0");
|
|
|
adminOrg.setParent_code(adminOrgUnitInfo.getParent().getNumber());
|
|
|
+ Map map = new HashMap();
|
|
|
+ //部门负责人
|
|
|
+ PositionInfo responPosition = adminOrgUnitInfo.getResponPosition();
|
|
|
+ String responPositionId = responPosition.getId().toString();
|
|
|
+ PersonPositionInfo personPositionInfo = getOAIDbyPostitonId(ctx, responPositionId);
|
|
|
+ map.put("bmfzr", personPositionInfo.getPerson().getName());
|
|
|
+ //经理 总监 副总
|
|
|
+ IPosition iPosition = PositionFactory.getLocalInstance(ctx);
|
|
|
+ PositionCollection positionCollection = iPosition.getPositionCollection("where adminOrgUnit = '" + adminOrgUnitInfo.getId() + "'");
|
|
|
+ for (int j = 0; j < positionCollection.size(); j++) {
|
|
|
+ PositionInfo positionInfo = positionCollection.get(j);
|
|
|
+ String positionName = positionInfo.getName();
|
|
|
+ logger.error("_syncOrgUnitToOA---positionName---" + positionName);
|
|
|
+ if ("经理".equals(positionName)) {
|
|
|
+ PersonPositionInfo oaiDbyPostitonId = getOAIDbyPostitonId(ctx, positionInfo.getId().toString());
|
|
|
+ //String oaid = oaiDbyPostitonId.getPerson().get("oAid").toString();
|
|
|
+ String personName = oaiDbyPostitonId.getPerson().getName();
|
|
|
+ map.put("bmjl", personName);
|
|
|
+ }
|
|
|
+ if ("总监".equals(positionName)) {
|
|
|
+ PersonPositionInfo oaiDbyPostitonId = getOAIDbyPostitonId(ctx, positionInfo.getId().toString());
|
|
|
+ String personName = oaiDbyPostitonId.getPerson().getName();
|
|
|
+ map.put("jl", personName);
|
|
|
+ }
|
|
|
+ if ("副总经理".equals(positionName)) {
|
|
|
+ PersonPositionInfo oaiDbyPostitonId = getOAIDbyPostitonId(ctx, positionInfo.getId().toString());
|
|
|
+ String personName = oaiDbyPostitonId.getPerson().getName();
|
|
|
+ map.put("fz", personName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ adminOrg.setCustomData(map);
|
|
|
//adminOrg.setOrder((String.valueOf(adminOrgUnitInfo.getIndex())));
|
|
|
dataList.add(adminOrg);
|
|
|
}
|
|
@@ -123,6 +168,21 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 通过职位获取人员OAID
|
|
|
+ *
|
|
|
+ * @param ctx
|
|
|
+ * @param postitonId
|
|
|
+ * @return
|
|
|
+ * @throws BOSException
|
|
|
+ */
|
|
|
+ public PersonPositionInfo getOAIDbyPostitonId(Context ctx, String postitonId) throws BOSException {
|
|
|
+ IPersonPosition iPersonPosition = PersonPositionFactory.getLocalInstance(ctx);
|
|
|
+ PersonPositionCollection personPositionCollection = iPersonPosition.getPersonPositionCollection("select * ,person.name where primaryPosition = '" + postitonId + "'");
|
|
|
+ PersonPositionInfo personPositionInfo = personPositionCollection.get(0);
|
|
|
+ return personPositionInfo;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 执行同步组织到OA
|
|
@@ -356,9 +416,216 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
@Override
|
|
|
protected void _syncPersonToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, EASBizException {
|
|
|
super._syncPersonToOA(ctx, billds, action);
|
|
|
- _syncPersonFromOAById(ctx, billds);
|
|
|
+ logger.error("_syncpersonToOA----------------------start");
|
|
|
+ logger.error("_syncpersonToOA----------------------billds: " + billds);
|
|
|
+ ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
|
|
|
+ SyncLogInfo syncLogInfo = new SyncLogInfo();
|
|
|
+ syncLogInfo.setEntityName(SyncEntityNameEnum.person);
|
|
|
+ syncLogInfo.setDataDirection(DataDirectionEnum.outflow);
|
|
|
+ syncLogInfo.setDockingSystem(DockingSystemEnum.OA);
|
|
|
+ try {
|
|
|
+ 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.workPlace.name");
|
|
|
+ sic.add("person.personnelCa.name");
|
|
|
+ sic.add("person.immediateSu.oAid");
|
|
|
+ sic.add("person.immediateSu.name");
|
|
|
+ sic.add("person.immediateSu.number");
|
|
|
+ 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(ctx, personPositionInfo);
|
|
|
+ dataList.add(person);
|
|
|
+ }
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ logger.error("_syncpersonToOA------------------dataList----- " + mapper.writeValueAsString(dataList));
|
|
|
+ //调用执行人员组织到OA
|
|
|
+ executeSyncPersonToOA(ctx, dataList, syncLogInfo);
|
|
|
+ _syncPersonFromOAById(ctx, billds);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
+ syncLogInfo.setSyncResult(e.getMessage());
|
|
|
+ iSyncLog.save(syncLogInfo);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 执行同步人员到OA
|
|
|
+ *
|
|
|
+ * @param dataList
|
|
|
+ */
|
|
|
+ public void executeSyncPersonToOA(Context ctx, List dataList, SyncLogInfo syncLogInfo) throws IOException, BOSException, EASBizException {
|
|
|
+ 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("executeSyncPersonToOA----------------------params----" + params);
|
|
|
+ //封装请求参数
|
|
|
+ String syncPersonApiUrl = this.propt.getProperty("syncPersonApiUrl");
|
|
|
+ logger.error("executeSyncPersonToOA----------------------syncPersonApiUrl----" + syncPersonApiUrl);
|
|
|
+ if (StringUtils.isEmpty(syncPersonApiUrl)) {
|
|
|
+ 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(syncPersonApiUrl)
|
|
|
+ .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();
|
|
|
+ //处理响应结果,写入日志
|
|
|
+ handlerResponse(ctx, response, syncLogInfo);
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 封装人员对象
|
|
|
+ *
|
|
|
+ * @param personPositionInfo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public PersonEntity packagingPerson(Context ctx, PersonPositionInfo personPositionInfo) throws BOSException, EASBizException {
|
|
|
+ SimpleDateFormat originalFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ //人员
|
|
|
+ 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.getNumber());
|
|
|
+ //岗位
|
|
|
+ PositionInfo primaryPosition = personPositionInfo.getPrimaryPosition();
|
|
|
+ person.setJobtitle(primaryPosition.getNumber());
|
|
|
+ //直接上级 @todo
|
|
|
+ IObjectValue immediateSu = (IObjectValue) personInfo.get("immediateSu");
|
|
|
+ if (immediateSu != null) {
|
|
|
+ person.setManagerid((String) immediateSu.get("number"));
|
|
|
+ }
|
|
|
+ //助理 @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();
|
|
|
+ if (jobStartDate != null) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ //职务
|
|
|
+ person.setJobactivityid("费用会计");
|
|
|
+ //职务类型
|
|
|
+ person.setJobactivityid("专业类");
|
|
|
+
|
|
|
+ return person;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 根据id从OA系统同步人员信息
|
|
|
*
|