czt
2025-06-11 283da741b2429cf5a53786e5ee1b5528b757fdf6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;
    }
}