| | |
| | | package cn.gistack.sm.hk.service; |
| | | |
| | | import cn.gistack.sm.hk.constant.HkEventConstant; |
| | | import cn.gistack.sm.hk.entity.HkEvent; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import java.util.Date; |
| | | |
| | | @Component |
| | | @Slf4j |
| | | public class AsyncHkEventService { |
| | | |
| | | @Autowired |
| | |
| | | hkEvent.setEventLvl(eventsArray.getJSONObject(i).getInteger("eventLvl")); |
| | | hkEvent.setCreateTime(new Date()); |
| | | hkEvent.setSendTime(sendTime); |
| | | hkEvent.setImageUrl(setImageUrl(eventsArray,i)); |
| | | // 保存 |
| | | hkEventService.save(hkEvent); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置图片路径 |
| | | * @param eventsArray |
| | | * @param i |
| | | * @return |
| | | */ |
| | | private String setImageUrl(JSONArray eventsArray, int i) { |
| | | String eventType = eventsArray.getJSONObject(i).getLong("eventType").toString(); |
| | | // 如果是非算法事件处理 |
| | | if (HkEventConstant.videoList.contains(eventType)){ |
| | | String columns = HkEventConstant.videoMap.get(eventType); |
| | | if (!Strings.isBlank(columns)){ |
| | | String data = eventsArray.getJSONObject(i).getString("data"); |
| | | JSONObject parseObject = JSONObject.parseObject(data); |
| | | JSONArray columnsJSONArray = parseObject.getJSONArray(columns); |
| | | if (null!= columnsJSONArray && columnsJSONArray.size()>0) { |
| | | // log.info("img:" + columnsJSONArray.getJSONObject(0).getString("imageUrl")); |
| | | return columnsJSONArray.getJSONObject(0).getString("imageUrl"); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | // 算法事件处理 |
| | | if (HkEventConstant.artVideoList.contains(eventType)){ |
| | | // log.info("img:" + eventsArray.getJSONObject(i).getString("refrencePicUrl")); |
| | | return eventsArray.getJSONObject(i).getString("refrencePicUrl"); |
| | | } |
| | | return null; |
| | | } |
| | | } |