ScheduleTask.java 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.malk.zhiwei.schedule;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.malk.server.aliwork.YDConf;
  5. import com.malk.server.aliwork.YDParam;
  6. import com.malk.service.aliwork.YDClient;
  7. import com.malk.utils.PublicUtil;
  8. import com.malk.utils.UtilMap;
  9. import com.malk.zhiwei.service.ZwService;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  13. import org.springframework.context.annotation.Configuration;
  14. import org.springframework.scheduling.annotation.EnableScheduling;
  15. import org.springframework.scheduling.annotation.Scheduled;
  16. import org.springframework.web.bind.annotation.PostMapping;
  17. import java.util.HashMap;
  18. import java.util.List;
  19. import java.util.Map;
  20. /**
  21. * @EnableScheduling 开启定时任务 [配置参考McScheduleTask]
  22. */
  23. @Slf4j
  24. @Configuration
  25. @EnableScheduling
  26. @ConditionalOnProperty(name = {"enable.scheduling"})
  27. public class ScheduleTask {
  28. @Autowired
  29. private YDClient ydClient;
  30. @Autowired
  31. private ZwService zwService;
  32. /**
  33. */
  34. // @Scheduled(cron = "0 0/5 * * * ?")
  35. public void sync() {
  36. List<Map> list=(List<Map>) ydClient.queryData(YDParam.builder().formUuid("FORM-3A89370AC94B429B9180ED98260BAF680JYM").pageSize(1)
  37. .searchFieldJson(JSONObject.toJSONString(UtilMap.map("selectField_mcefftmv","待处理"))).build(), YDConf.FORM_QUERY.retrieve_list_all).getData();
  38. log.info("手动同步查询-结果,{}",list.size());
  39. if(list==null||list.size()<1){
  40. return;
  41. }
  42. Map data=list.get(0);
  43. log.info("{}",data);
  44. String formInstanceId=String.valueOf(data.get("formInstanceId"));
  45. processing(formInstanceId);
  46. Map formData=UtilMap.getMap(data,"formData");
  47. try {
  48. String type=UtilMap.getString(formData,"selectField_mcefftmu");
  49. if("销售订单".equals(type)){
  50. JSONObject jsonObject=zwService.saveSaleOrder(formData);
  51. comp(formInstanceId,"同步完成!",JSONObject.toJSONString(jsonObject.getJSONObject("result")),jsonObject);
  52. }else if("发货单".equals(type)){
  53. JSONObject jsonObject=zwService.saveDeliveryOrder(formData);
  54. comp(formInstanceId,"同步完成!",JSONObject.toJSONString(jsonObject.getJSONObject("result")),jsonObject);
  55. }else if("产品同步".equals(type)){
  56. zwService.syncProduct(UtilMap.getString(formData,"textField_mcefftng"),UtilMap.getString(formData,"textField_mdr1v1di"));
  57. comp(formInstanceId,"同步完成!","",null);
  58. }else{
  59. comp(formInstanceId,"同步完成!","",null);
  60. }
  61. }catch (Exception e){
  62. e.printStackTrace();
  63. comp(formInstanceId,"异常",e.getMessage(),null);
  64. }
  65. }
  66. // @Scheduled(cron = "0 0 1 * * ?")
  67. public void syncProd() {
  68. zwService.syncProduct("","PILOT2024");
  69. zwService.syncProduct("","PILOT2023");
  70. }
  71. private void processing(String id){
  72. ydClient.operateData(YDParam.builder().formInstanceId(id)
  73. .updateFormDataJson(JSON.toJSONString(UtilMap.map("selectField_mcefftmv", "处理中")))
  74. .build(), YDConf.FORM_OPERATION.update);
  75. }
  76. private void comp(String id,String result,String msg,Map data){
  77. if(data==null){
  78. data=new HashMap<>();
  79. }
  80. data.putAll(UtilMap.map("selectField_mcefftmv, textField_mcefftnw, textareaField_mcefftn0", "已完成",result,msg));
  81. ydClient.operateData(YDParam.builder().formInstanceId(id)
  82. .updateFormDataJson(JSON.toJSONString(data))
  83. .build(), YDConf.FORM_OPERATION.update);
  84. }
  85. }