| | |
| | | import cn.gistack.sm.sjztmd.vo.StBdDataVO; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.ArrayList; |
| | |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | @DS("zt") |
| | | public class StBdDataServiceImpl extends ServiceImpl<StBdDataMapper, StBdData> implements IStBdDataService { |
| | | |
| | | private static final ObjectMapper objectMapper = new ObjectMapper(); |
| | | private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); |
| | | |
| | | @Override |
| | | public Boolean insertData(String stBdDataStr) { |
| | | StBdDataVO stBdDataVO; |
| | | try { |
| | | stBdDataVO = objectMapper.readValue(stBdDataStr, StBdDataVO.class); |
| | | } catch (JsonProcessingException e) { |
| | | throw new ServiceException("转换北斗平台监测数据失败,详情:" + e.getMessage()); |
| | | } |
| | | public Boolean insertData(StBdDataVO stBdDataVO) throws Exception { |
| | | List<StBdDataVO.CommInfo> commInfos = stBdDataVO.getCommInfos(); |
| | | if (null == commInfos || commInfos.isEmpty()) { |
| | | throw new ServiceException("获取北斗平台数据失败,无效的commInfos"); |
| | | } |
| | | List<StBdData> stBdDataList = new ArrayList<>(); |
| | | for (StBdDataVO.CommInfo commInfo : commInfos) { |
| | | log.info("StBdDataVO zk " + commInfo.toString()); |
| | | StBdData stBdData = new StBdData(); |
| | | stBdData.setId(UUID.randomUUID().toString().replaceAll("-", "")); |
| | | stBdData.setTm(commInfo.getTime()); |
| | | stBdData.setTm(formatter.parse(commInfo.getTime())); |
| | | stBdData.setCreateTime(new Date()); |
| | | stBdData.setFromAddr(commInfo.getFromAddr()); |
| | | stBdData.setToAddr(commInfo.getToAddr()); |
| | | String content = commInfo.getContent(); |
| | | String content = commInfo.getContent(); |
| | | log.info("content zk " + content); |
| | | stBdData.setContent(content); |
| | | boolean isContainsChinese = contentIsContainChinese(content); |
| | | stBdData.setCodeType(isContainsChinese? RainfallConstant.CONTAINS_CHINESE : RainfallConstant.NOT_CONTAINS_CHINESE); |
| | | log.info("stBdData zk " + stBdData.toString()); |
| | | stBdDataList.add(stBdData); |
| | | } |
| | | this.saveBatch(stBdDataList); |