PushLgLogUtils.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package com.ydtech.modules.lg;
  2. import cn.hutool.extra.spring.SpringUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ydtech.modules.lg.dao.PushLgEntityMapper;
  5. import com.ydtech.modules.lg.model.PushLgEntity;
  6. import com.ydtech.modules.ttqf.QuartzManager;
  7. import com.ydtech.utils.StringUtils;
  8. import org.springframework.scheduling.annotation.Async;
  9. import org.springframework.stereotype.Component;
  10. import java.util.Date;
  11. import java.util.HashMap;
  12. @Component
  13. public class PushLgLogUtils {
  14. @Async
  15. public void pushLg(PushLgEntity lgEntity){
  16. int insert = SpringUtil.getBean(PushLgEntityMapper.class).insert(lgEntity);
  17. if (insert > 0){
  18. lgEntity.setZgUuid(lgEntity.getId());
  19. lgEntity.setId(null);
  20. JSONObject jsonObject = JSONObject.parseObject(SendUtils.send(JSONObject.toJSONString(lgEntity)));
  21. if (null != jsonObject && String.valueOf(jsonObject.getInteger("code")).equals("200")){
  22. lgEntity.setPushStatus(String.valueOf(jsonObject.getInteger("code")));
  23. lgEntity.setMsg(jsonObject.getString("msg"));
  24. lgEntity.setSuccessPushTime(new Date());
  25. }else {
  26. lgEntity.setPushStatus("");
  27. lgEntity.setMsg("推送失败");
  28. }
  29. if (!StringUtils.equals(lgEntity.getPushStatus(),"200")){
  30. pushLgRetry(lgEntity);
  31. }
  32. }
  33. }
  34. public void pushLgRetry(PushLgEntity lgEntity){
  35. try {
  36. HashMap<String, Object> map = new HashMap<>();
  37. map.put("lgEntity", lgEntity);
  38. QuartzManager manager = QuartzManager.getInstance();
  39. manager.getContext().put("executionFrequency",1);
  40. manager.addJob(String.valueOf(lgEntity.getId()),"jobGroup" + lgEntity.getId(), PushRetry.class,"*/5 * * * * ?",map);
  41. manager.start();
  42. }catch (Exception e){
  43. e.printStackTrace();
  44. }
  45. }
  46. }