CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.ld.igds;
 
import com.alibaba.fastjson.JSONObject;
import com.bstek.bdf2.core.controller.IController;
import com.ld.igds.constant.RedisConst;
import com.ld.igds.gas.CoreGasService;
import com.ld.igds.gas.dto.GasData;
import com.ld.igds.gas.dto.GasParam;
import com.ld.igds.grain.dto.GrainData;
import com.ld.igds.grain.dto.GrainParam;
import com.ld.igds.grain.service.CoreGrainService;
import com.ld.igds.models.WeatherConf;
import com.ld.igds.models.WeatherInfo;
import com.ld.igds.timer.WeatherScheduled;
import com.ld.igds.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
 
/**
 * 测试Action接口,支持匿名访问 方位路径:http://127.0.0.1:8080/igds/test.action?t=timer
 */
@Slf4j
@Component
public class TestAction implements IController {
 
    @Autowired
    private CoreGasService gasService;
    @Autowired
    private CoreGrainService grainService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private WeatherScheduled weatherScheduled;
 
    @Override
    public String getUrl() {
        return "/test";
    }
 
    /**
     * 测试调用
     */
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) {
        String companyId = request.getParameter("companyId");
        String t = request.getParameter("t");
        String p1 = request.getParameter("p1");
        String p2 = request.getParameter("p2");
        log.debug("p1={},p2={}", p1, p2);
 
        if (StringUtils.isEmpty(t)) {
            return;
        }
 
        if ("weather".equals(t)) {
            doTestWeather(companyId, p1, p2, response);
            return;
        }
 
        // 重新更新缓存中气体信息
        if (t.equals("cache-gas")) {
            GasParam param = new GasParam();
            param.setCompanyId(companyId);
            List<GasData> list = gasService.pageQueryList(param);
 
            if (null == list)
                return;
 
            for (GasData data : list) {
 
                String key = RedisConst.buildKey(param.getCompanyId(),
                        RedisConst.KEY_GAS_DATA, data.getDepotId());
 
                redisUtil.set(key, data);
            }
 
            log.info("手动执行了刷新气体缓存");
        }
 
        if (t.equals("cache-grain")) {
 
            GrainParam param = new GrainParam();
            param.setCompanyId(companyId);
            param.setLimit(100);
            param.setTagUpdate(false);
 
            List<GrainData> list = grainService.listGrainData(param);
            if (null == list || list.isEmpty())
                return;
 
            String key;
            GrainData grainData;
            for (int i = list.size() - 1; i >= 0; i--) {
 
                grainData = list.get(i);
                grainData.setListRows(null);
                grainData.setListLays(null);
                grainData.setListPoints(null);
 
                key = RedisConst.buildKey(param.getCompanyId(),
                        RedisConst.KEY_GRAIN, grainData.getDepotId());
 
                redisUtil.set(key, grainData);
            }
 
            log.info("手动执行了刷新粮情缓存");
        }
        if (t.equals("pressure")) {
            // DeviceSer ser = serService.getCacheSer(companyId, p1);
            // pressureManager.checkPressureBySer(ser);
        }
 
        if (t.equals("reset-out-storage")) {
            if (null == p1) {// 仓库编码
                return;
            }
            if (null == p2) {// 开始时间
                return;
            }
            log.info("------initRecordCurStorageOUT--------");
        }
 
        if (t.equals("reset-in-storage")) {
            if (null == p1) {// 仓库编码
                return;
            }
            if (null == p2) {// 开始时间
                return;
            }
        }
 
        if (t.equals("weather11")) {
            weatherScheduled.scheduled();
        }
    }
 
 
    /**
     * 测试气象信息
     *
     * @param companyId
     * @param deptId
     * @param response
     * @throws IOException
     */
    private void doTestWeather(String companyId, String deptId, String cityId, HttpServletResponse response) {
        try {
 
            if (StringUtils.isEmpty(companyId)) {
                response.getWriter().print("MSG:ERROR,param {companyId} is null");
            }
            if (StringUtils.isEmpty(deptId)) {
                response.getWriter().print("MSG:ERROR,param {deptId} is null");
            }
            if (StringUtils.isEmpty(cityId)) {
                response.getWriter().print("MSG:ERROR,param {cityId} is null");
            }
 
            WeatherConf conf = new WeatherConf(companyId, deptId, cityId);
 
            log.info("-----测试调用气象----deptId={},cityId={}", deptId, cityId);
 
            Date date = new Date();
            WeatherInfo info = weatherScheduled.getWeatherByWeb(date, conf);
            if (null == info) {
                response.getWriter().print("MSG:ERROR");
            } else {
                response.getWriter().print("MSG:SUCCESS:" + JSONObject.toJSONString(info));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
 
    @Override
    public boolean anonymousAccess() {
        return false;
    }
 
    @Override
    public boolean isDisabled() {
        return false;
    }
 
}