| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- package com.kingdee.eas.custom.beisen.synchronouspos.osf;
- import com.alibaba.fastjson.JSONObject;
- import com.google.common.collect.Maps;
- import com.kingdee.bos.BOSException;
- import com.kingdee.bos.Context;
- import com.kingdee.bos.bsf.service.app.IHRMsfService;
- import com.kingdee.bos.rabbitmq.guava.Lists;
- import com.kingdee.eas.common.EASBizException;
- import com.kingdee.eas.custom.beisen.utils.BeiSenUtils;
- import com.kingdee.eas.custom.beisen.utils.BeisenParamByPropertiesUtil;
- import com.kingdee.eas.custom.beisen.utils.Helper;
- import com.kingdee.eas.util.app.DbUtil;
- import com.kingdee.jdbc.rowset.IRowSet;
- import java.sql.SQLException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class SyncStaffManageOSFService implements IHRMsfService {
- @Override
- public Object process(Context context, Map<String, Object> map) throws EASBizException, BOSException {
- Map<String,List<Map<String,Object>>> result = Maps.newHashMap();
- List<Map<String,Object>> list = Lists.newArrayList();
- List<Map<String,Object>> listMap = Lists.newArrayList();
- result.put("list",list);
- result.put("listMap",listMap);
- String posPath = (String) map.get("posPath");
- String orgPath = (String) map.get("orgPath");
- StringBuilder sql = new StringBuilder();
- sql.append(" ");
- sql.append(" select fid,FYear,FTableName from T_HR_StaffManageProject ");
- sql.append(" where FRule in ( ");
- sql.append(" select fid from T_HR_StaffManageRule where fid in ( ");
- sql.append(" select FStaffManageRuleId from T_HR_STAFFMANAGERULEFIELD where FColumn in ('FpositionID', 'FAdminOrgID') group by FStaffManageRuleId HAVING count(fid)>1 ");
- sql.append(" ) and FState = 1 ");
- sql.append(" ) ");
- sql.append(" and FState = 1 ");
- sql.append(" and FChannel = 1 ");
- IRowSet rs = DbUtil.executeQuery(context, sql.toString());
- try{
- BeiSenUtils b = new BeiSenUtils(context);
- Helper helper = b.helper;
- BeisenParamByPropertiesUtil posUtil = new BeisenParamByPropertiesUtil(posPath);
- Map<String,String> poskeyMap = posUtil.getConfig();
- BeisenParamByPropertiesUtil orgUtil = new BeisenParamByPropertiesUtil(orgPath);
- Map<String,String> orgkeyMap = orgUtil.getConfig();
- while (rs.next()) {
- String fid = rs.getString("fid");
- String FTableName = rs.getString("FTableName");
- String FYear = rs.getString("FYear");
- StringBuilder selSql = new StringBuilder();
- selSql.append(" select 'org' orgpos,org.fid posId,org.fname_l2 orgPosName,org.FDisplayName_L2 staffName, ");
- selSql.append(" org.CFOriginalId,(case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
- selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
- selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
- selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
- selSql.append(" (staff.FState+1) FState ");
- selSql.append(" from ");
- selSql.append(" "+FTableName+" staff ");
- selSql.append(" left join t_org_admin org on org.fid=staff.FAdminOrgID ");
- selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
- selSql.append(" where pos.fid is null and org.CFOriginalId is not null ");
- selSql.append(" UNION all ");
- selSql.append(" select 'pos' orgpos,org.fid posId,org.fname_l2 orgPosName,org.FDisplayName_L2 staffName,pos.CFOriginalId, ");
- selSql.append(" (case when staff.FControlWay=0 then 3 when staff.FControlWay=1 then 2 else 1 end) FControlWay, ");
- selSql.append(" staff.FPersonCount,staff.FStaffYear,staff.FYearActualStart, ");
- selSql.append(" staff.FOnWayAddCount,staff.FOnWaySubCount, ");
- selSql.append(" (staff.FStaffYear-staff.FOnWayAddCount+staff.FOnWaySubCount-staff.FPersonCount) FStaffYearUsable, ");
- selSql.append(" (staff.FState+1) FState ");
- selSql.append(" from ");
- selSql.append(" "+FTableName+" staff ");
- selSql.append(" left join t_org_admin org on org.fid=staff.FAdminOrgID ");
- selSql.append(" left join t_org_position pos on pos.fid = staff.FpositionID ");
- selSql.append(" where pos.fid is not null and pos.CFOriginalId is not null ");
- IRowSet rsSel = DbUtil.executeQuery(context, selSql.toString());
- // 获取访问令牌
- String token = b.getAccessToken();
- while (rsSel.next()){
- String orgpos= rsSel.getString("orgpos");
- if("org".equals(orgpos)){
- Map<String, Object> pos = this.getPostData(orgkeyMap,rsSel);
- if(null!=pos){
- // 若访问令牌不为空且开始时间和结束时间不为空
- if (!com.kingdee.util.StringUtils.isEmpty(token)) {
- // 创建请求头的 Map
- Map<String, String> header = new HashMap<String, String>();
- // 设置请求头的 Content-Type
- header.put("Content-Type", "application/json");
- // 设置请求头的 Authorization
- header.put("Authorization", "Bearer " + token);
- String url = "https://openapi.italent.cn/UserFrameworkApiV3/api/v1/departments/Put";
- JSONObject requestBody = new JSONObject(pos);
- System.out.println("url:"+url);
- System.out.println("requestBody:"+requestBody);
- JSONObject responseJson = helper.getURL(url,header, requestBody, "PUT",requestBody.getString("posId"),"更新","北森");
- System.out.println("responseJson:"+responseJson);
- listMap.add(responseJson);
- list.add(pos);
- }
- }
- }else if ("pos".equals(orgpos)){
- Map<String, Object> pos = this.getPostData(poskeyMap,rsSel);
- if(null!=pos){
- // 若访问令牌不为空且开始时间和结束时间不为空
- if (!com.kingdee.util.StringUtils.isEmpty(token)) {
- // 创建请求头的 Map
- Map<String, String> header = new HashMap<String, String>();
- // 设置请求头的 Content-Type
- header.put("Content-Type", "application/json");
- // 设置请求头的 Authorization
- header.put("Authorization", "Bearer " + token);
- String url = "https://openapi.italent.cn/RecruitV6/api/v1/RecruitOnBoarding/UpdatePost";
- JSONObject requestBody = new JSONObject(pos);
- System.out.println("url:"+url);
- System.out.println("requestBody:"+requestBody);
- JSONObject responseJson = helper.getURL(url,header, requestBody, "PUT",requestBody.getString("posId"),"更新","北森");
- System.out.println("responseJson:"+responseJson);
- listMap.add(responseJson);
- list.add(pos);
- }
- }
- }
- }
- }
- }catch (Exception e){
- e.printStackTrace();
- }finally {
- }
- return result;
- }
- /**
- * shr系统数据组装北森请求参数
- *
- * @param keyMap
- * @param rowSet
- * @return
- * @throws SQLException
- */
- protected Map<String, Object> getPostData(Map<String,String> keyMap, IRowSet rowSet) throws SQLException {
- Map<String, Object> pos = Maps.newHashMap();
- if (null!=rowSet){
- for(Map.Entry<String,String> entry : keyMap.entrySet()){
- String shrKey = entry.getKey();
- String beisenKey = entry.getValue();
- if(shrKey.indexOf(".")>0){
- String[] keys=shrKey.split("\\.");
- if(2==keys.length){
- Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
- if(null==map1){
- map1=Maps.newHashMap();
- pos.put(keys[0],map1);
- }
- String valueStr = rowSet.getString(keys[1]);
- if(beisenKey.indexOf(",")>0) {
- String[] beisenKeys = beisenKey.split(",");
- Object value = null;
- if("integer".equals(beisenKeys[1])){
- if(null!=valueStr){
- value=Integer.parseInt(valueStr);
- }
- }else {
- value = valueStr;
- }
- if(null!=value) {
- map1.put(beisenKeys[0], value);
- }
- }else {
- if(null!=valueStr) {
- map1.put(beisenKey, valueStr);
- }
- }
- }else if (3==keys.length){
- Map<String,Object> map1 = (Map<String, Object>) pos.get(keys[0]);
- if(null==map1){
- map1=Maps.newHashMap();
- pos.put(keys[0],map1);
- }
- Map<String,Object> map2 = (Map<String, Object>) map1.get(keys[1]);
- if(null==map2){
- map2=Maps.newHashMap();
- map1.put(keys[1],map1);
- }
- String valueStr = rowSet.getString(keys[2]);
- if(beisenKey.indexOf(",")>0) {
- String[] beisenKeys = beisenKey.split(",");
- Object value = null;
- if("integer".equals(beisenKeys[1])){
- if(null!=valueStr){
- value=Integer.parseInt(valueStr);
- }
- }else {
- value = valueStr;
- }
- if(null!=value) {
- map2.put(beisenKeys[0], value);
- }
- }else {
- if(null!=valueStr) {
- map2.put(beisenKey,valueStr);
- }
- }
- }
- }else {
- String valueStr = rowSet.getString(shrKey);
- if(beisenKey.indexOf(",")>0) {
- String[] beisenKeys = beisenKey.split(",");
- Object value = null;
- if("integer".equals(beisenKeys[1])){
- if(null!=valueStr){
- value=Integer.parseInt(valueStr);
- }
- }else {
- value = valueStr;
- }
- if(null!=value) {
- pos.put(beisenKeys[0],value);
- }
- }else {
- if(null!=valueStr) {
- pos.put(beisenKey,valueStr);
- }
- }
- }
- }
- }
- return pos;
- }
- }
|