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;
|
}
|
|
}
|