package com.fzzy.igds.dzhwk.v1.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.fzzy.igds.dzhwk.domain.Grain;
|
import com.fzzy.igds.grain.repository.GrainRepository;
|
import com.fzzy.igds.dzhwk.v1.ApiV1Service;
|
import com.fzzy.igds.dzhwk.v1.dto.ApiV1Data2001;
|
import com.fzzy.igds.dzhwk.v1.dto.ApiV1ReqDto;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.time.DateUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.stereotype.Service;
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
/**
|
* @Description 解析粮情信息
|
* @Author CZT
|
* @Date 2025/6/04 19:11
|
*/
|
@Slf4j
|
@Service
|
public class ApiV1ServiceImpl2001 implements ApiV1Service {
|
|
@Resource
|
private GrainRepository grainRepository;
|
|
@Override
|
public String getInterfaceId() {
|
return "2001";
|
}
|
|
@Override
|
public void analysis(String dataStr, ApiV1ReqDto configData) {
|
|
List<ApiV1Data2001> list = JSONObject.parseArray(dataStr, ApiV1Data2001.class);
|
if(null == list || list.isEmpty()){
|
log.error("-----未获取到粮情信息,不解析---------");
|
return;
|
}
|
try {
|
Grain grain;
|
for (ApiV1Data2001 apiData : list) {
|
grain = new Grain();
|
BeanUtils.copyProperties(apiData, grain);
|
|
grain.setBatchId(apiData.getJcdj());
|
grain.setCompanyId(configData.getSign());
|
grain.setDepotId(apiData.getHwdm());
|
grain.setTempMin(apiData.getLszdw());//粮情最低温
|
grain.setTempMax(apiData.getLszgw());//粮情最高温
|
grain.setTempIn(apiData.getCfnw());//仓内温度
|
grain.setTempOut(apiData.getCfww());//仓外温度
|
grain.setTempAve(apiData.getLspjw());//粮食平均温
|
grain.setHumidityOut(apiData.getCfws());//仓外湿度
|
grain.setHumidityIn(apiData.getCfww());//仓内湿度
|
|
grain = grainGbToGrain01(grain, apiData.getLswdzjh());
|
|
grain.setWeather(apiData.getWeather());
|
grain.setReceiveDate(DateUtils.parseDate(apiData.getJcsj(), "yyyy-MM-dd HH:mm:ss"));
|
grain.setCheckUser(apiData.getJcr());
|
grain.setRemark(apiData.getRemarks());
|
|
grainRepository.save(grain);
|
}
|
}catch (Exception e){
|
log.error("-----解析错误={}---------", e.toString());
|
}
|
|
}
|
|
/**
|
* 将温度信息转为系统内粮情点位信息
|
*
|
* @param lswdzjh
|
* @return
|
*/
|
public Grain grainGbToGrain01(Grain grain, String lswdzjh) {
|
String[] pointList = lswdzjh.split("\\|");
|
|
//获取最大层行列
|
String[] split;
|
Integer z = 0; //层
|
Integer y = 0; //行
|
Integer x = 0; //列
|
for (String s : pointList) {
|
if (s.startsWith(",")) {
|
s = s.substring(1);
|
}
|
split = s.split(",");
|
if (Integer.valueOf(split[1]) > z) {
|
z = Integer.valueOf(split[1]);
|
}
|
if (Integer.valueOf(split[2]) > y) {
|
y = Integer.valueOf(split[2]);
|
}
|
if (Integer.valueOf(split[3]) > x) {
|
x = Integer.valueOf(split[3]);
|
}
|
}
|
|
grain.setCable(z + "-" + y + "-" + x);
|
String points = "";
|
|
//将温湿度点转为系统使用格式
|
for (int a = 1; a <= x; a++) { //列
|
for (int b = 1; b <= y; b++) { //行
|
for (int c = 1; c <= z; c++) { //层
|
for (String s : pointList) {
|
if (s.startsWith(",")) {
|
s = s.substring(1);
|
}
|
split = s.split(",");
|
if (Integer.valueOf(split[1]) == c && Integer.valueOf(split[2]) == b && Integer.valueOf(split[3]) == a) {
|
points += split[0] + ",";
|
}
|
}
|
}
|
}
|
}
|
grain.setPoints(points);
|
return grain;
|
}
|
}
|