123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- 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.entity.PersonEntity;
- import com.kingdee.eas.hr.affair.EmpEnrollBizBillEntry;
- 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
- * @date 2024/10/24
- * @apiNote 员工信息维护扩展
- */
- 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);
- }
- /**
- * 同步组织
- * 1、当参数billIds不为空值时,增量同步参数中的部门数据到OA
- * 2、当参数billIds为空时,全量同步所有组织数据到OA
- * 3、当参数action不为空时,根据操作类型同步数据
- * 4、当参数action为空时,判断部门状态是否为失效,如果失效就执行删除同步,否则就执行编辑同步
- * 5、部门新增,调用部门同步方法增量同步,操作类型为新增
- *
- * @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);
- IPerson iPerson = PersonFactory.getLocalInstance(ctx);
- 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("id", 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());
- //人员名称
- 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
- person.setLocationid("");
- //移动电话
- person.setMobile(personInfo.getCell());
- //办公室电话
- person.setTelephone(personInfo.getOfficePhone());
- //电子邮件
- person.setEmail(personInfo.getEmail());
- //入职日期
- IEmpEnrollBizBillEntry iEmpEnrollBizBillEntry = EmpEnrollBizBillEntryFactory.getLocalInstance(ctx);
- EmpEnrollBizBillEntryInfo empEnrollBizBillEntryInfo = iEmpEnrollBizBillEntry.getEmpEnrollBizBillEntryInfo("person = '" + personInfo.getId() + "'");
- Date enrollDate = empEnrollBizBillEntryInfo.getEnrollDate();
- person.setCompanystartdate(originalFormat.format(enrollDate));
- //参加工作日期
- Date jobStartDate = empEnrollBizBillEntryInfo.getJobStartDate();
- person.setWorkstartdate(originalFormat.format(jobStartDate));
- UserInfo userInfo = iuser.getUserInfo("where person = '" + personInfo.getId() + "' ");
- //登录名称
- person.setLastname(userInfo.getName());
- //明文密码,会转密文
- person.setPassword(userInfo.getPassword());
- //安全级别
- 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();
- person.setJoblevel(Integer.parseInt(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);
- }
- }
|