소스 검색

更新代码

Heyuan 9 달 전
부모
커밋
c8f41ed2d3
1개의 변경된 파일93개의 추가작업 그리고 3개의 파일을 삭제
  1. 93 3
      src/com/kingdee/eas/custom/synctask/SyncTranForOAFacadeControllerBean.java

+ 93 - 3
src/com/kingdee/eas/custom/synctask/SyncTranForOAFacadeControllerBean.java

@@ -10,12 +10,11 @@ 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.basedata.org.*;
 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.PersonCollection;
-import com.kingdee.eas.basedata.person.PersonFactory;
 import com.kingdee.eas.common.EASBizException;
 import com.kingdee.eas.custom.log.ISyncLog;
 import com.kingdee.eas.custom.log.SyncLogFactory;
@@ -25,6 +24,7 @@ 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.PositionEntity;
 import com.kingdee.eas.hr.ats.AtsUtil;
 import com.kingdee.eas.util.app.DbUtil;
 import com.kingdee.jdbc.rowset.IRowSet;
@@ -249,9 +249,99 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
      */
     @Override
     protected void _syncPositionToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, EASBizException {
-        super._syncPositionToOA(ctx, billds, action);
+        ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
+        SyncLogInfo syncLogInfo = new SyncLogInfo();
+        syncLogInfo.setEntityName(SyncEntityNameEnum.postiton);
+        syncLogInfo.setDataDirection(DataDirectionEnum.outflow);
+        syncLogInfo.setDockingSystem(DockingSystemEnum.OA);
+        try {
+            super._syncPositionToOA(ctx, billds, action);
+            logger.error("_syncPositionToOA---billds: " + billds);
+            String data = getPositionColData(ctx, billds);
+            String syncPositionApiUrl = this.propt.getProperty("syncPositionApiUrl");
+            synScyRequest(ctx,data, syncPositionApiUrl,syncLogInfo);
+        } catch (Exception e) {
+            e.printStackTrace();
+            syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
+            syncLogInfo.setSyncResult(e.getMessage());
+            iSyncLog.save(syncLogInfo);
+            throw new BOSException(e.getMessage());
+        }
+
+
+    }
+
+    /**
+     * 获取岗位信息
+     * @param ctx
+     * @param billIds
+     * @return
+     * @throws IOException
+     * @throws BOSException
+     */
+    protected String getPositionColData(Context ctx,String billIds) throws IOException, BOSException {
+        List list = new ArrayList();
+        ObjectMapper mapper = new ObjectMapper();
+        Set positionIds = new HashSet();
+        PositionCollection positionCollection = new PositionCollection();
+        IPosition localInstance = PositionFactory.getLocalInstance(ctx);
+        if (org.apache.commons.lang.StringUtils.isNotBlank(billIds)){
+            String[] split = billIds.split(",");
+            for (int i = 0; i < split.length; i++) {
+                positionIds.add(split[i]);
+            }
+            positionCollection = localInstance.getPositionCollection("where id in( " + AtsUtil.convertSetToString(positionIds) + ")");
+        }else {
+            positionCollection = localInstance.getPositionCollection();
+        }
+        for (int i = 0; i < positionCollection.size(); i++) {
+            PositionEntity positionEntity = new PositionEntity();
+            PositionInfo positionInfo = positionCollection.get(i);
+            DeletedStatusEnum deletedStatus = positionInfo.getDeletedStatus();
+            if ("2".equals(deletedStatus.getValue())){ // 失效
+                positionEntity.setAction("delete");
+            }else {
+                positionEntity.setAction("add");
+            }
+            positionEntity.setJobtitlecode(positionInfo.getNumber());
+            positionEntity.setJobtitlename(positionInfo.getName());
+            positionEntity.setJobtitleremark(positionInfo.getName());
+            list.add(positionEntity);
+        }
+        //封装请求参数
+        String data = mapper.writeValueAsString(list);
+        logger.error("_syncPositionToOA----------------------data" + data);
+        return data;
+    }
+
+    /**
+     * 同步请求方法
+     * @param param
+     * @param aipUrl
+     * @return
+     * @throws IOException
+     */
+    public void synScyRequest(Context ctx,String param, String aipUrl, SyncLogInfo syncLogInfo) throws IOException, BOSException, EASBizException {
+        OkHttpClient client = new OkHttpClient();
+        MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
+        String data = String.format("token = %s &data = %s", getToken(), param);
+        //logger.error("synAdminOrgRequest----------------------date" + data);
+        RequestBody body = RequestBody.create(mediaType, data);
+        Request request = new Request.Builder()
+                .url(aipUrl)
+                .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);
     }
 
+
     /**
      * 同步员工信息
      *