设备信息定时查询
天气预警数据定时查询
This commit is contained in:
@ -87,6 +87,12 @@
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
<!-- geoserver-->
|
||||
<dependency>
|
||||
<groupId>nl.pdok</groupId>
|
||||
<artifactId>geoserver-manager</artifactId>
|
||||
<version>1.7.0-pdok2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
@ -0,0 +1,110 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.DeviceSense;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonDeviceSenseBean;
|
||||
import com.ruoyi.crops.service.IDeviceSenseService;
|
||||
import com.ruoyi.crops.service.IWarningService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops/device")
|
||||
public class DeviceSenseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
|
||||
@Value("${url.deviceSense}")
|
||||
String url;//指定UR
|
||||
|
||||
@Autowired
|
||||
private IDeviceSenseService iDeviceSenseService;
|
||||
|
||||
@Autowired
|
||||
private IWarningService iWarningService;
|
||||
|
||||
/**
|
||||
* 根据时间查询设备传感数据
|
||||
*
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public List<DeviceSense> selectBytime(@RequestParam String startTime, @RequestParam String endTime) {
|
||||
return iDeviceSenseService.selectByTime(startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务调用接口获取数据插入数据库
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Scheduled(fixedDelay = 6 * 60 * 1000)
|
||||
public void getsense() throws Exception {
|
||||
String deviceId = "863070042491174-1-1";
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("deviceId", deviceId);
|
||||
//发送get请求
|
||||
String result = HttpUtil.createGet(url).form(map).execute().body();
|
||||
//格式化json时间类型数据
|
||||
Gson gson = new GsonBuilder().setDateFormat("yyyy/MM/dd HH:mm:ss").create();
|
||||
//格式化json,封装到GsonDeviceSenseBean类型
|
||||
GsonDeviceSenseBean model = gson.fromJson(result, GsonDeviceSenseBean.class);
|
||||
//创建DeviceSense对象,设置deviceId
|
||||
DeviceSense deviceSense = new DeviceSense();
|
||||
deviceSense.setDeviceId(deviceId);
|
||||
//通过反射获取成员变量name与json字段匹配入库
|
||||
Class clazz = Class.forName("com.ruoyi.crops.domain.DeviceSense");
|
||||
for (GsonDeviceSenseBean.AttDataList attDataList : model.data.attDataList) {
|
||||
//2.获取成员变量
|
||||
String attributeValue = attDataList.attributeValue;
|
||||
Field field = clazz.getDeclaredField(attDataList.attributeName);
|
||||
//设置私有变量也可访问
|
||||
field.setAccessible(true);
|
||||
//判断数据类型进行相应转换
|
||||
if (attributeValue != null) {
|
||||
switch (field.getType().getName()) {
|
||||
case "java.lang.Double":
|
||||
field.set(deviceSense, Double.valueOf(attributeValue));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
field.set(deviceSense, Integer.valueOf(attributeValue));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
field.set(deviceSense, attributeValue);
|
||||
break;
|
||||
case "java.util.Date":
|
||||
field.set(deviceSense, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(attributeValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
//使用sql判断重复数据插入
|
||||
iDeviceSenseService.dedupInsert(deviceSense);
|
||||
|
||||
//判断设备预警信息 插入异常数据库
|
||||
iWarningService.insertWarning(deviceSense);
|
||||
logger.info("每6分钟更新一次设备传感数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小时,周,天,获取其平均值数据
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/sense")
|
||||
public AjaxResult averageList(@RequestParam String type) {
|
||||
return AjaxResult.success(iDeviceSenseService.averageList(type));
|
||||
}
|
||||
|
||||
}
|
@ -21,21 +21,23 @@ public class EnvironmentalController extends BaseController {
|
||||
|
||||
/**
|
||||
* 根据大棚编号查询
|
||||
*
|
||||
* @param number
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{number}")
|
||||
private List<EnvironmentalData> selectByNumber(@PathVariable Integer number){
|
||||
private List<EnvironmentalData> selectByNumber(@PathVariable Integer number) {
|
||||
return iEnvironmentalService.selectByNumber(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param environmentalData
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
private AjaxResult insert(@RequestBody EnvironmentalData environmentalData){
|
||||
private AjaxResult insert(@RequestBody EnvironmentalData environmentalData) {
|
||||
return toAjax(iEnvironmentalService.insert(environmentalData));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,81 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ruoyi.crops.domain.DeviceSense;
|
||||
import com.ruoyi.crops.domain.FertigationSense;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonDeviceSenseBean;
|
||||
import com.ruoyi.crops.service.IFertigationSenseService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.util.DateUtil.now;
|
||||
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class FertigationSenseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
|
||||
@Value("${url.deviceSense}")
|
||||
String url;//指定UR
|
||||
|
||||
@Autowired
|
||||
private IFertigationSenseService iFertigationSenseService;
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public void getsense() throws Exception {
|
||||
String deviceId = "645281df92edbc7ee9427230_NHWL-MengLiangGu-Fertigation";
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("deviceId", deviceId);
|
||||
//发送get请求
|
||||
String result = HttpUtil.createGet(url).form(map).execute().body();
|
||||
//格式化json时间类型数据
|
||||
Gson gson = new GsonBuilder().setDateFormat("yyyy/MM/dd HH:mm:ss").create();
|
||||
//格式化json,封装到GsonDeviceSenseBean类型
|
||||
GsonDeviceSenseBean model = gson.fromJson(result, GsonDeviceSenseBean.class);
|
||||
//创建DeviceSense对象,设置deviceId
|
||||
FertigationSense fertigationSense = new FertigationSense();
|
||||
fertigationSense.setDeviceId(deviceId);
|
||||
fertigationSense.setTime(now());
|
||||
//通过反射获取成员变量name与json字段匹配入库
|
||||
Class clazz = Class.forName("com.ruoyi.crops.domain.FertigationSense");
|
||||
for (GsonDeviceSenseBean.AttDataList attDataList : model.data.attDataList) {
|
||||
//2.获取成员变量
|
||||
String attributeValue = attDataList.attributeValue;
|
||||
Field field = clazz.getDeclaredField(attDataList.attributeName);
|
||||
//设置私有变量也可访问
|
||||
field.setAccessible(true);
|
||||
//判断数据类型进行相应转换
|
||||
if (attributeValue != null) {
|
||||
switch (field.getType().getName()) {
|
||||
case "java.lang.Double":
|
||||
field.set(fertigationSense, Double.valueOf(attributeValue));
|
||||
break;
|
||||
case "java.lang.Integer":
|
||||
field.set(fertigationSense, Integer.valueOf(attributeValue));
|
||||
break;
|
||||
case "java.lang.String":
|
||||
field.set(fertigationSense, attributeValue);
|
||||
break;
|
||||
// case "java.util.Date":
|
||||
// field.set(fertigationSense, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(attributeValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
//使用sql判断重复数据插入
|
||||
iFertigationSenseService.insert(fertigationSense);
|
||||
logger.info("每小时更新一次水肥一体机设备传感数据");
|
||||
}
|
||||
}
|
@ -1,22 +1,12 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.ruoyi.crops.domain.GsonParseFoundationBean;
|
||||
import com.ruoyi.crops.service.IFoundationService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/foundation")
|
||||
public class FoundationController {
|
||||
@ -24,7 +14,7 @@ public class FoundationController {
|
||||
private IFoundationService foundationService;
|
||||
|
||||
@PostMapping("/{id}")
|
||||
public String Foundation(@PathVariable String id){
|
||||
public String Foundation(@PathVariable String id) {
|
||||
return foundationService.getFoundation(id);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("/workspaces/PJZ/coveragestores/")
|
||||
@RequestMapping
|
||||
public class Geoservercontroller {
|
||||
// @PutMapping("/{store}/{method}.{format}")
|
||||
|
||||
}
|
@ -20,12 +20,12 @@ public class GreenhouseController extends BaseController {
|
||||
private IGreenhouseService iGreenhouseService;
|
||||
|
||||
@GetMapping("/{name}")
|
||||
public List<GreenhouseInformation> selectByName(@PathVariable String name){
|
||||
public List<GreenhouseInformation> selectByName(@PathVariable String name) {
|
||||
return iGreenhouseService.selectByName(name);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody GreenhouseInformation greenhouseInformation){
|
||||
public AjaxResult insert(@RequestBody GreenhouseInformation greenhouseInformation) {
|
||||
return toAjax(iGreenhouseService.insert(greenhouseInformation));
|
||||
}
|
||||
}
|
||||
|
@ -21,25 +21,27 @@ public class IntelligentController extends BaseController {
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param intelligentControl
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody IntelligentControl intelligentControl){
|
||||
public AjaxResult insert(@RequestBody IntelligentControl intelligentControl) {
|
||||
return toAjax(iIntelligentControlService.insert(intelligentControl));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public List<IntelligentControl> selectAll(){
|
||||
public List<IntelligentControl> selectAll() {
|
||||
return iIntelligentControlService.selectAll();
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody IntelligentControl intelligentControl){
|
||||
public AjaxResult edit(@RequestBody IntelligentControl intelligentControl) {
|
||||
return toAjax(iIntelligentControlService.edit(intelligentControl));
|
||||
}
|
||||
}
|
||||
|
@ -21,21 +21,23 @@ public class MachineParameterController extends BaseController {
|
||||
|
||||
/**
|
||||
* 根据大棚名称进行查询
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{name}")
|
||||
public List<MachineParameter> selectByName(@PathVariable String name){
|
||||
public List<MachineParameter> selectByName(@PathVariable String name) {
|
||||
return machineParameterService.selectByName(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param machineParameter
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody MachineParameter machineParameter){
|
||||
public AjaxResult insert(@RequestBody MachineParameter machineParameter) {
|
||||
return toAjax(machineParameterService.insert(machineParameter));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,101 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonMeteorologicalBean;
|
||||
import com.ruoyi.crops.domain.Meteorological;
|
||||
import com.ruoyi.crops.service.IMeteorologicalService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops")
|
||||
public class MeteorologicalController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
|
||||
@Value("${Meteorological.url}")
|
||||
private String url;
|
||||
@Value("${Meteorological.key}")
|
||||
private String key;
|
||||
@Value("${Meteorological.code}")
|
||||
private String code;
|
||||
|
||||
@Autowired
|
||||
private IMeteorologicalService iMeteorologicalService;
|
||||
|
||||
@GetMapping("/meterological")
|
||||
public AjaxResult selectByTime() {
|
||||
if (iMeteorologicalService.selectByTime().isEmpty()) {
|
||||
return AjaxResult.warn("今日暂无数据");
|
||||
}
|
||||
return AjaxResult.success(iMeteorologicalService.selectByTime());
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public void MeteorologicalInfo() {
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("city_code", code);
|
||||
map.put("key", key);
|
||||
// HashMap<String, String> headers = new HashMap<>();//存放请求头,可以存放多个请求头
|
||||
// headers.put("xxx", xxx);
|
||||
//发送get请求并接收响应数据
|
||||
String result = HttpUtil.createGet(url).form(map).execute().body();
|
||||
|
||||
//格式化Json时间类型
|
||||
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
|
||||
//讲json转换成对应实体类
|
||||
GsonMeteorologicalBean model = gson.fromJson(result, GsonMeteorologicalBean.class);
|
||||
//判断json是否有数据
|
||||
if (model.result != null) {
|
||||
ArrayList<GsonMeteorologicalBean.Meteorological> meteorologicalArrayList = model.result;
|
||||
//创建一个空的list集合存放json解析的Meteorological实体数据
|
||||
List<Meteorological> list = new ArrayList<>();
|
||||
//遍历json数组里的参数,存入实体类
|
||||
for (GsonMeteorologicalBean.Meteorological meteorological : meteorologicalArrayList) {
|
||||
//新建实体类
|
||||
Meteorological ml = new Meteorological();
|
||||
ml.setWarnId(meteorological.id);
|
||||
ml.setTitle(meteorological.title);
|
||||
ml.setLevel(meteorological.level);
|
||||
ml.setType(meteorological.type);
|
||||
ml.setTime(meteorological.time);
|
||||
ml.setProvince(meteorological.province);
|
||||
ml.setCity(meteorological.city);
|
||||
ml.setDistrict(meteorological.district);
|
||||
ml.setContent(meteorological.content);
|
||||
list.add(ml);
|
||||
}
|
||||
//从数据库查询出今日的预警信息
|
||||
List<Meteorological> meteorologicals = iMeteorologicalService.selectByTime();
|
||||
//剔除两个集合里面重复元素根据WarnId和Time
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
Meteorological me = list.get(i);
|
||||
for (int j = 0; j < meteorologicals.size(); j++) {
|
||||
Meteorological m = meteorologicals.get(j);
|
||||
if (me.getWarnId().equals(m.getWarnId()) && me.getTime().equals(m.getTime())) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
//遍历去重集合插入数据库
|
||||
for (Meteorological meteorological : list) {
|
||||
iMeteorologicalService.insert(meteorological);
|
||||
}
|
||||
logger.info("每小时更新1次天气预警");
|
||||
} else {
|
||||
logger.info("今日暂无预警");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -20,20 +20,22 @@ public class OperationRecordsController extends BaseController {
|
||||
|
||||
/**
|
||||
* 查询全部记录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public List<OperationRecords> listAll (){
|
||||
public List<OperationRecords> listAll() {
|
||||
return iOperationRecordsService.selectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param operationRecords
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody OperationRecords operationRecords){
|
||||
public AjaxResult insert(@RequestBody OperationRecords operationRecords) {
|
||||
return toAjax(iOperationRecordsService.insert(operationRecords));
|
||||
}
|
||||
|
||||
|
@ -20,40 +20,44 @@ public class ServiceTypeController extends BaseController {
|
||||
|
||||
/**
|
||||
* 根据类型查询(有参)
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{type}")
|
||||
public List<ServiceType> selectByType(@PathVariable String type){
|
||||
return typeService.selectByType(type);
|
||||
public List<ServiceType> selectByType(@PathVariable String type) {
|
||||
return typeService.selectByType(type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 无参查询全部展示
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public List<ServiceType> selectAll(){
|
||||
public List<ServiceType> selectAll() {
|
||||
return typeService.selectAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param serviceType
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("insert")
|
||||
public AjaxResult insert(@RequestBody ServiceType serviceType){
|
||||
public AjaxResult insert(@RequestBody ServiceType serviceType) {
|
||||
return toAjax(typeService.insert(serviceType));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数组批量删除数据
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/{ids}")
|
||||
private AjaxResult remove(@PathVariable Long[] ids){
|
||||
private AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(typeService.deleteByIds(ids));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,102 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.BashUtils;
|
||||
import com.ruoyi.crops.domain.ServiceType;
|
||||
import com.ruoyi.crops.service.IGeoServer;
|
||||
import com.ruoyi.crops.service.IUploadService;
|
||||
import com.ruoyi.crops.service.IexeService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops")
|
||||
public class UploadController {
|
||||
@Value("${url.group1Upload}")
|
||||
private String url;
|
||||
|
||||
private String workSpace = "PJZ";
|
||||
@Value("${path.exepath}")
|
||||
private String exePath;
|
||||
|
||||
private String imgDataPath;
|
||||
@Value("${path.boundaryDataPath}")
|
||||
private String boundaryDataPath;
|
||||
@Autowired
|
||||
private IUploadService iUploadService;
|
||||
|
||||
@Autowired
|
||||
private IGeoServer iGeoServer;
|
||||
|
||||
@Autowired
|
||||
private IexeService iexeService;
|
||||
|
||||
/**
|
||||
* 上传TIFF文件
|
||||
*
|
||||
* @param type 服务类型
|
||||
* @param file Tiff文件
|
||||
* @return 文件状态
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AjaxResult upload(@RequestParam("type") String type, @RequestParam("file") MultipartFile file) throws Exception {
|
||||
//获得项目的static路径
|
||||
String realPath = ResourceUtils.getURL("classpath:").getPath() + "static";
|
||||
//获得文件路径
|
||||
String filePath = iUploadService.upload(type, file, realPath);
|
||||
|
||||
//调用接口上传文件到服务器
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
File targetFile = new File(filePath);
|
||||
map.put("file", targetFile);
|
||||
map.put("path", "pjz/tif");
|
||||
String result = HttpUtil.createPost(url).form(map).execute().body();
|
||||
|
||||
//获取文件信息
|
||||
String name = targetFile.getName();
|
||||
String[] n = name.split("\\.");
|
||||
|
||||
String time = n[0].substring(n[0].length() - 10);
|
||||
String fileName = n[0];
|
||||
String servieName = workSpace + ":" + fileName;
|
||||
|
||||
//封装成serviceType对象
|
||||
ServiceType serviceType = new ServiceType();
|
||||
|
||||
serviceType.setServiceType(type);
|
||||
Date date = new SimpleDateFormat("yyyy-MM-dd").parse(time);
|
||||
serviceType.setTime(date);
|
||||
serviceType.setServiceName(servieName);
|
||||
serviceType.setFileName(name);
|
||||
serviceType.setFilePath(result);
|
||||
|
||||
//发送地图服务
|
||||
String pjz = iGeoServer.GeoServer(workSpace, fileName, filePath);
|
||||
|
||||
//调用exe批量导入数据
|
||||
String res = iexeService.execCommand(type, targetFile.getAbsolutePath(), boundaryDataPath);
|
||||
//插入数据库
|
||||
iGeoServer.insert(serviceType);
|
||||
return AjaxResult.success(pjz + res);
|
||||
|
||||
}
|
||||
}
|
@ -3,35 +3,40 @@ package com.ruoyi.web.controller.crops;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.User;
|
||||
import com.ruoyi.crops.domain.UserInfo;
|
||||
import com.ruoyi.crops.service.IUserInfoService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/info")
|
||||
|
||||
|
||||
public class UserInfoController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
|
||||
@Autowired
|
||||
private IUserInfoService userInfoService;
|
||||
// @Scheduled(fixedDelay = 30*1000)
|
||||
@PostMapping
|
||||
public String userInfo(@RequestBody User user){
|
||||
return userInfoService.login(user);
|
||||
// System.out.println("执行1次");
|
||||
private RedisTemplate redisTemplate;
|
||||
@Value("${url.userInfo}")
|
||||
private String url;
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000 * 10)
|
||||
public void userInfo() {
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("username", "18954905838");
|
||||
paramMap.put("password", "112233");
|
||||
String result = HttpUtil.post(url, paramMap);
|
||||
UserInfo userInfo = JSONObject.parseObject(result, UserInfo.class);
|
||||
redisTemplate.opsForValue().set("cropsUserInfo", userInfo, Duration.ofSeconds(userInfo.getExpire()));
|
||||
|
||||
logger.info("更新redis中session信息");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,40 +2,61 @@ package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.DateUtil;
|
||||
import com.ruoyi.crops.domain.WaringNumber;
|
||||
import com.ruoyi.crops.domain.WarningInformation;
|
||||
import com.ruoyi.crops.service.IWarningService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预警信息controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("warning/information")
|
||||
@RequestMapping("/warning/information")
|
||||
public class WarningController extends BaseController {
|
||||
@Autowired
|
||||
private IWarningService iWarningService;
|
||||
|
||||
/**
|
||||
* 根据大棚编号查询
|
||||
* @param number
|
||||
* 根据时间查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{number}")
|
||||
public List<WarningInformation> selectByNumber(@PathVariable Integer number){
|
||||
return iWarningService.selectByNumber(number);
|
||||
@GetMapping("/selectByTime")
|
||||
public List<WarningInformation> selectBytTime(@RequestParam Date startTime, @RequestParam Date endTime) {
|
||||
return iWarningService.selectByTime(startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
*
|
||||
* @param warningInformation
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody WarningInformation warningInformation){
|
||||
public AjaxResult insert(@RequestBody WarningInformation warningInformation) {
|
||||
return toAjax(iWarningService.insert(warningInformation));
|
||||
}
|
||||
|
||||
@GetMapping("/numberOfTimes")
|
||||
public AjaxResult numberOfTimes() {
|
||||
List<WarningInformation> daylist = iWarningService.selectByTime(DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
int dayNumber = daylist.size();
|
||||
|
||||
List<WarningInformation> weeklist = iWarningService.selectByTime(DateUtil.getBeginDayOfWeek(), DateUtil.getEndDayOfWeek());
|
||||
int weekNumber = weeklist.size();
|
||||
|
||||
List<WarningInformation> monthlist = iWarningService.selectByTime(DateUtil.getBeginDayOfMonth(), DateUtil.getEndDayOfMonth());
|
||||
int monthNumber = monthlist.size();
|
||||
WaringNumber waringNumber = new WaringNumber();
|
||||
waringNumber.setDayNumber(dayNumber);
|
||||
waringNumber.setWeekNumber(weekNumber);
|
||||
waringNumber.setMonthNumber(monthNumber);
|
||||
return AjaxResult.success(waringNumber);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -57,11 +57,11 @@ spring:
|
||||
active: druid
|
||||
# 文件上传
|
||||
servlet:
|
||||
multipart:
|
||||
# 单个文件大小
|
||||
max-file-size: 10MB
|
||||
# 设置总上传的文件大小
|
||||
max-request-size: 20MB
|
||||
multipart:
|
||||
# 单个文件大小
|
||||
max-file-size: 1024MB
|
||||
# 设置总上传的文件大小
|
||||
max-request-size: 2048MB
|
||||
# 服务模块
|
||||
devtools:
|
||||
restart:
|
||||
@ -92,21 +92,21 @@ spring:
|
||||
|
||||
# token配置
|
||||
token:
|
||||
# 令牌自定义标识
|
||||
header: Authorization
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
# 令牌自定义标识
|
||||
header: Authorization
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
|
||||
# MyBatis配置
|
||||
mybatis:
|
||||
# 搜索指定包别名
|
||||
typeAliasesPackage: com.ruoyi.**.domain
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
# 加载全局的配置文件
|
||||
configLocation: classpath:mybatis/mybatis-config.xml
|
||||
# 搜索指定包别名
|
||||
typeAliasesPackage: com.ruoyi.**.domain
|
||||
# 配置mapper的扫描,找到所有的mapper.xml映射文件
|
||||
mapperLocations: classpath*:mapper/**/*Mapper.xml
|
||||
# 加载全局的配置文件
|
||||
configLocation: classpath:mybatis/mybatis-config.xml
|
||||
|
||||
# PageHelper分页插件
|
||||
pagehelper:
|
||||
@ -133,3 +133,21 @@ xss:
|
||||
url:
|
||||
foundation: 'http://api.nonghaiiot.com/api/foundation/getFoundationByUserId.zzdy'
|
||||
userInfo: 'http://api.nonghaiiot.com/admin/sys/login'
|
||||
group1Upload: '192.168.2.20:4096/group1/upload'
|
||||
deviceSense : 'http://admin.nonghaiiot.com/app/queryDataByPropertyAll'
|
||||
|
||||
geoserver:
|
||||
url: 'http://192.168.2.20:9080/geoserver'
|
||||
username: 'admin'
|
||||
password: 'geoserver'
|
||||
|
||||
path:
|
||||
exepath: 'E:/庞家镇农情统计分析脚本/'
|
||||
imgDataPath:
|
||||
boundaryDataPath: 'E:/庞家镇农情统计分析脚本/庞家镇村边界.tif'
|
||||
|
||||
Meteorological:
|
||||
url: 'https://apis.juhe.cn/fapig/alarm/queryV2'
|
||||
# key: 'f072a23affd5551ecd9ae3a98d703b1c'
|
||||
key : '123'
|
||||
code: '150700'
|
||||
|
@ -11,7 +11,7 @@
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 系统日志输出 -->
|
||||
<appender name="file_info" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/sys-info.log</file>
|
||||
@ -34,7 +34,7 @@
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
<appender name="file_error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/sys-error.log</file>
|
||||
<!-- 循环政策:基于时间创建日志文件 -->
|
||||
@ -56,7 +56,7 @@
|
||||
<onMismatch>DENY</onMismatch>
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 用户访问日志输出 -->
|
||||
<appender name="sys-user" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/sys-user.log</file>
|
||||
@ -70,7 +70,7 @@
|
||||
<pattern>${log.pattern}</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
|
||||
<!-- 系统模块日志级别控制 -->
|
||||
<logger name="com.ruoyi" level="info" />
|
||||
<!-- Spring日志级别控制 -->
|
||||
@ -79,15 +79,19 @@
|
||||
<root level="info">
|
||||
<appender-ref ref="console" />
|
||||
</root>
|
||||
|
||||
|
||||
<!--系统操作日志-->
|
||||
<root level="info">
|
||||
<appender-ref ref="file_info" />
|
||||
<appender-ref ref="file_error" />
|
||||
</root>
|
||||
|
||||
|
||||
<!--系统用户操作日志-->
|
||||
<logger name="sys-user" level="info">
|
||||
<appender-ref ref="sys-user"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
<!--定时任务日志-->
|
||||
<logger name="scheduled" level="info">
|
||||
<appender-ref ref="sys-user"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
@ -1,21 +1,77 @@
|
||||
package com.ruoyi.web;
|
||||
|
||||
import com.ruoyi.pill.domain.PillFactory;
|
||||
import com.ruoyi.pill.service.IPillFactoryService;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ruoyi.crops.domain.DeviceSense;
|
||||
import com.ruoyi.crops.domain.FertigationSense;
|
||||
import com.ruoyi.crops.domain.WarningInformation;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonDeviceSenseBean;
|
||||
import com.ruoyi.crops.service.IFertigationSenseService;
|
||||
import com.ruoyi.crops.service.IWarningService;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.util.DateUtil.now;
|
||||
|
||||
@SpringBootTest
|
||||
public class PssTest {
|
||||
|
||||
@Value("${geoserver.url}")
|
||||
private String url;
|
||||
@Value("${geoserver.username}")
|
||||
private String username;
|
||||
@Value("${geoserver.password}")
|
||||
private String password;
|
||||
|
||||
@Autowired
|
||||
private IPillFactoryService IpillFactoryService;
|
||||
|
||||
private IWarningService iWarningService;
|
||||
@Test
|
||||
public void testSelectFactory(){
|
||||
PillFactory pillFactory = new PillFactory();
|
||||
pillFactory.setFactoryName("云南");
|
||||
IpillFactoryService.selectPillFactoryList(pillFactory);
|
||||
public void test() throws Exception {
|
||||
// publisherLayer("PJZ","zwhq_2023-05-11","zwhq","a","PJZ:zwcl_xm_2023-04-20","c",1);
|
||||
getDayBegin();
|
||||
}
|
||||
|
||||
public static java.util.Date getDayBegin() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
System.out.println(cal.getTime());
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public boolean publisherLayer(String workspaceName,String dataStoreName,String styleName, String tableName,String layerName, String layerAlias, int crsCode) throws Exception {
|
||||
URL u = new URL(url);
|
||||
GeoServerRESTManager manager = new GeoServerRESTManager(u, username, password);
|
||||
GeoServerRESTPublisher publisher = manager.getPublisher();
|
||||
|
||||
//图层设置
|
||||
GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
|
||||
gsFeatureTypeEncoder.setNativeName(tableName); //表名
|
||||
gsFeatureTypeEncoder.setName(layerName); // 图层名称
|
||||
gsFeatureTypeEncoder.setTitle(layerAlias);// 图层别名
|
||||
gsFeatureTypeEncoder.setSRS("EPSG:" + crsCode); //坐标系
|
||||
|
||||
GSLayerEncoder styleEncoder = new GSLayerEncoder(); //设置样式
|
||||
styleEncoder.setDefaultStyle(workspaceName,styleName);
|
||||
|
||||
boolean publishDBLayerResult = publisher.publishDBLayer(workspaceName, dataStoreName, gsFeatureTypeEncoder, styleEncoder);
|
||||
return publishDBLayerResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user