|
@@ -6,8 +6,10 @@ import com.dingtalk.api.response.OapiProcessinstanceGetResponse;
|
|
|
import com.dingtalk.api.response.OapiProcessinstanceListidsResponse;
|
|
|
import com.galaxis.manatee.constant.DingTalkConstant;
|
|
|
import com.galaxis.manatee.dao.ChuanyunAskForLeaveDao;
|
|
|
+import com.galaxis.manatee.dao.ChuanyunBusinessEntertainmentDao;
|
|
|
import com.galaxis.manatee.dao.DingTalkProcessInstanceDao;
|
|
|
import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunAskForLeaveDO;
|
|
|
+import com.galaxis.manatee.entity.chuanyun.data.object.ChuanyunBusinessEntertainmentDO;
|
|
|
import com.galaxis.manatee.entity.ding.DingTalkProcessInstance;
|
|
|
import com.taobao.api.ApiException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -49,12 +51,15 @@ public class DingTalkScheduledTask {
|
|
|
*/
|
|
|
private final ChuanyunAskForLeaveDao chuanyunAskForLeaveDao;
|
|
|
|
|
|
+ private final ChuanyunBusinessEntertainmentDao chuanyunBusinessEntertainmentDao;
|
|
|
+
|
|
|
public DingTalkScheduledTask(DingTalkClient processInstanceListIdsClient, DingTalkClient processInstanceClient,
|
|
|
- ChuanyunAskForLeaveDao chuanyunAskForLeaveDao,DingTalkProcessInstanceDao dingTalkProcessInstanceDao) {
|
|
|
+ ChuanyunAskForLeaveDao chuanyunAskForLeaveDao, DingTalkProcessInstanceDao dingTalkProcessInstanceDao, ChuanyunBusinessEntertainmentDao chuanyunBusinessEntertainmentDao) {
|
|
|
this.processInstanceListIdsClient = processInstanceListIdsClient;
|
|
|
this.processInstanceClient = processInstanceClient;
|
|
|
this.dingTalkProcessInstanceDao = dingTalkProcessInstanceDao;
|
|
|
this.chuanyunAskForLeaveDao = chuanyunAskForLeaveDao;
|
|
|
+ this.chuanyunBusinessEntertainmentDao = chuanyunBusinessEntertainmentDao;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -81,7 +86,7 @@ public class DingTalkScheduledTask {
|
|
|
* 业务招待申请更新
|
|
|
* @throws ApiException
|
|
|
*/
|
|
|
- @Scheduled(fixedDelay = 3600000L,initialDelay = 10000L)
|
|
|
+// @Scheduled(fixedDelay = 3600000L,initialDelay = 10000L)
|
|
|
void updateChuanyunBusinessEntertainmentProcessInstanceList() throws ApiException {
|
|
|
updateChuanyunBusinessEntertainment(DingTalkConstant.PROCESS_CODE_BUSINESSENTERTAINMENT);
|
|
|
}
|
|
@@ -96,47 +101,49 @@ public class DingTalkScheduledTask {
|
|
|
oApiProcessInstanceListIdsRequest.setEndTime(LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli());
|
|
|
oApiProcessInstanceListIdsRequest.setCursor(0L);
|
|
|
oApiProcessInstanceListIdsRequest.setSize(20L);
|
|
|
-// while(flag){
|
|
|
-// LocalDateTime start=LocalDateTime.now();
|
|
|
-// OapiProcessinstanceListidsResponse oapiProcessinstanceListidsResponse=processInstanceListIdsClient.execute(oApiProcessInstanceListIdsRequest,DingTalkConstant.DING_TALK_TOKEN);
|
|
|
-// List<ChuanyunAskForLeaveDO> chuanyunAskForLeaveDoList=new ArrayList<>();
|
|
|
-// if(oapiProcessinstanceListidsResponse.getErrcode()!=0){
|
|
|
-// log.info(oapiProcessinstanceListidsResponse.getErrmsg());
|
|
|
-// try {
|
|
|
-// Thread.sleep(5000);
|
|
|
-// } catch (InterruptedException e) {
|
|
|
-// log.error(e.getMessage());
|
|
|
-// }
|
|
|
-// continue;
|
|
|
-// }
|
|
|
-// //逐个请求
|
|
|
-// oapiProcessinstanceListidsResponse.getResult().getList().forEach(resultId->{
|
|
|
-// Optional<DingTalkProcessInstance> instance=dingTalkProcessInstanceDao.findById(resultId);
|
|
|
-// if(instance.isEmpty()){
|
|
|
-// OapiProcessinstanceGetRequest request=new OapiProcessinstanceGetRequest();
|
|
|
-// request.setProcessInstanceId(resultId);
|
|
|
-// try {
|
|
|
-// OapiProcessinstanceGetResponse oapiProcessinstanceGetResponse = processInstanceClient.execute(request, DingTalkConstant.DING_TALK_TOKEN);
|
|
|
-// ChuanyunAskForLeaveDO chuanyunAskForLeaveDo = ChuanyunAskForLeaveDO.fromAskForLeaveDTO(oapiProcessinstanceGetResponse.getProcessInstance());
|
|
|
-// List<ChuanyunAskForLeaveDO> existsAskForLeave = chuanyunAskForLeaveDao.findByTitleSQL(chuanyunAskForLeaveDo.getTitle());
|
|
|
-// if(existsAskForLeave != null && !existsAskForLeave.isEmpty()) {
|
|
|
-// chuanyunAskForLeaveDao.deleteById(existsAskForLeave.get(0).getObjectId());
|
|
|
-// }
|
|
|
-// chuanyunAskForLeaveDoList.add(chuanyunAskForLeaveDo);
|
|
|
-// } catch (ApiException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// });
|
|
|
-//
|
|
|
-// //保存id列表和实例列表,如果有更新的内容
|
|
|
-// chuanyunAskForLeaveDao.saveAll(chuanyunAskForLeaveDoList);
|
|
|
-// log.info(businessTripProcessCode+"下一个cursor为"+oapiProcessinstanceListidsResponse.getResult().getNextCursor()+"保存成功"+"耗时"+ ChronoUnit.SECONDS.between(start,LocalDateTime.now())+"秒");
|
|
|
-// flag=null!=oapiProcessinstanceListidsResponse.getResult().getNextCursor();
|
|
|
-// if (flag){
|
|
|
-// oApiProcessInstanceListIdsRequest.setCursor(oapiProcessinstanceListidsResponse.getResult().getNextCursor());
|
|
|
-// }
|
|
|
-// }
|
|
|
+ while(flag){
|
|
|
+ LocalDateTime start=LocalDateTime.now();
|
|
|
+ OapiProcessinstanceListidsResponse oapiProcessinstanceListidsResponse=processInstanceListIdsClient.execute(oApiProcessInstanceListIdsRequest,DingTalkConstant.DING_TALK_TOKEN);
|
|
|
+ List<ChuanyunBusinessEntertainmentDO> chuanyunBusinessEntertainmentDOS=new ArrayList<>();
|
|
|
+ if(oapiProcessinstanceListidsResponse.getErrcode()!=0){
|
|
|
+ log.info(oapiProcessinstanceListidsResponse.getErrmsg());
|
|
|
+ try {
|
|
|
+ Thread.sleep(5000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //逐个请求
|
|
|
+ oapiProcessinstanceListidsResponse.getResult().getList().forEach(resultId->{
|
|
|
+ Optional<DingTalkProcessInstance> instance=dingTalkProcessInstanceDao.findById(resultId);
|
|
|
+ if(instance.isEmpty()){
|
|
|
+ OapiProcessinstanceGetRequest request=new OapiProcessinstanceGetRequest();
|
|
|
+ request.setProcessInstanceId(resultId);
|
|
|
+ try {
|
|
|
+ OapiProcessinstanceGetResponse oapiProcessinstanceGetResponse = processInstanceClient.execute(request, DingTalkConstant.DING_TALK_TOKEN);
|
|
|
+ List<OapiProcessinstanceGetResponse.FormComponentValueVo> formComponentValueVoList = oapiProcessinstanceGetResponse.getProcessInstance().getFormComponentValues();
|
|
|
+ ChuanyunBusinessEntertainmentDO chuanyunBusinessEntertainmentDO = ChuanyunBusinessEntertainmentDO.formBusinessEntertainmentDTO(formComponentValueVoList);
|
|
|
+ chuanyunBusinessEntertainmentDO.setBusinessId(oapiProcessinstanceGetResponse.getProcessInstance().getBusinessId());
|
|
|
+ ChuanyunBusinessEntertainmentDO oldChuanyunBusinessEntertainmentDO = chuanyunBusinessEntertainmentDao.findByBusinessId(oapiProcessinstanceGetResponse.getProcessInstance().getBusinessId());
|
|
|
+ if(oldChuanyunBusinessEntertainmentDO != null ) {
|
|
|
+ chuanyunBusinessEntertainmentDao.deleteById(oldChuanyunBusinessEntertainmentDO.getObjectId());
|
|
|
+ }
|
|
|
+ chuanyunBusinessEntertainmentDOS.add(chuanyunBusinessEntertainmentDO);
|
|
|
+ } catch (ApiException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //保存id列表和实例列表,如果有更新的内容
|
|
|
+ chuanyunBusinessEntertainmentDao.saveAll(chuanyunBusinessEntertainmentDOS);
|
|
|
+ log.info(businessTripProcessCode+"下一个cursor为"+oapiProcessinstanceListidsResponse.getResult().getNextCursor()+"保存成功"+"耗时"+ ChronoUnit.SECONDS.between(start,LocalDateTime.now())+"秒");
|
|
|
+ flag=null!=oapiProcessinstanceListidsResponse.getResult().getNextCursor();
|
|
|
+ if (flag){
|
|
|
+ oApiProcessInstanceListIdsRequest.setCursor(oapiProcessinstanceListidsResponse.getResult().getNextCursor());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void updateChuanyunAskForLeave(String businessTripProcessCode) throws ApiException {
|