package com.ydtech.modules.lg; import cn.hutool.extra.spring.SpringUtil; import com.alibaba.fastjson.JSONObject; import com.ydtech.modules.lg.dao.PushLgEntityMapper; import com.ydtech.modules.lg.model.PushLgEntity; import com.ydtech.modules.ttqf.QuartzManager; import com.ydtech.utils.StringUtils; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.util.Date; import java.util.HashMap; @Component public class PushLgLogUtils { @Async public void pushLg(PushLgEntity lgEntity){ int insert = SpringUtil.getBean(PushLgEntityMapper.class).insert(lgEntity); if (insert > 0){ lgEntity.setZgUuid(lgEntity.getId()); lgEntity.setId(null); JSONObject jsonObject = JSONObject.parseObject(SendUtils.send(JSONObject.toJSONString(lgEntity))); if (null != jsonObject && String.valueOf(jsonObject.getInteger("code")).equals("200")){ lgEntity.setPushStatus(String.valueOf(jsonObject.getInteger("code"))); lgEntity.setMsg(jsonObject.getString("msg")); lgEntity.setSuccessPushTime(new Date()); }else { lgEntity.setPushStatus(""); lgEntity.setMsg("推送失败"); } if (!StringUtils.equals(lgEntity.getPushStatus(),"200")){ pushLgRetry(lgEntity); } } } public void pushLgRetry(PushLgEntity lgEntity){ try { HashMap map = new HashMap<>(); map.put("lgEntity", lgEntity); QuartzManager manager = QuartzManager.getInstance(); manager.getContext().put("executionFrequency",1); manager.addJob(String.valueOf(lgEntity.getId()),"jobGroup" + lgEntity.getId(), PushRetry.class,"*/5 * * * * ?",map); manager.start(); }catch (Exception e){ e.printStackTrace(); } } }