庞家镇
This commit is contained in:
@ -15,8 +15,13 @@
|
||||
web服务入口
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<geotools.version>20.5</geotools.version>
|
||||
<jts.version>1.16.1</jts.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- spring-boot-devtools -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -94,7 +99,170 @@
|
||||
<version>1.7.0-pdok2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 引入jsoup -->
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- AOP -->
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjrt</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
<artifactId>cglib</artifactId>
|
||||
<version>3.2.12</version>
|
||||
</dependency>
|
||||
<!-- geotools start -->
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-main</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-referencing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-api</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-opengis</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-metadata</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-geometry</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-coverage</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-cql</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-data</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-epsg-wkt</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-jdbc</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools.jdbc</groupId>
|
||||
<artifactId>gt-jdbc-postgis</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-shapefile</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-geojson</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-swing</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.locationtech.jts</groupId>
|
||||
<artifactId>jts-core</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.geotools</groupId>
|
||||
<artifactId>gt-wms</artifactId>
|
||||
<version>${geotools.version}</version>
|
||||
</dependency>
|
||||
<!-- geotools end -->
|
||||
|
||||
<!--geotools-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.geotools</groupId>-->
|
||||
<!-- <artifactId>gt-shapefile</artifactId>-->
|
||||
<!-- <version>${geotools.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.geotools</groupId>-->
|
||||
<!-- <artifactId>gt-swing</artifactId>-->
|
||||
<!-- <version>${geotools.version}</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– https://mvnrepository.com/artifact/org.locationtech.jts/jts-core –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.locationtech.jts</groupId>-->
|
||||
<!-- <artifactId>jts-core</artifactId>-->
|
||||
<!-- <version>1.16.1</version>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <!– https://mvnrepository.com/artifact/org.geotools/gt-main –>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.geotools</groupId>-->
|
||||
<!-- <artifactId>gt-main</artifactId>-->
|
||||
<!-- <version>22-RC</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.vividsolutions</groupId>-->
|
||||
<!-- <artifactId>jts</artifactId>-->
|
||||
<!-- <version>1.13</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>osgeo</id>
|
||||
<name>OSGeo Release Repository</name>
|
||||
<url>https://repo.osgeo.org/repository/release/</url>
|
||||
<snapshots><enabled>false</enabled></snapshots>
|
||||
<releases><enabled>true</enabled></releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>osgeo-snapshot</id>
|
||||
<name>OSGeo Snapshot Repository</name>
|
||||
<url>https://repo.osgeo.org/repository/snapshot/</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
<releases><enabled>false</enabled></releases>
|
||||
</repository>
|
||||
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
@ -126,4 +294,5 @@
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
|
@ -3,6 +3,7 @@ package com.ruoyi;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.EnableAspectJAutoProxy;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
/**
|
||||
|
113
ruoyi-admin/src/main/java/com/ruoyi/web/aop/ApiVisitHistory.java
Normal file
113
ruoyi-admin/src/main/java/com/ruoyi/web/aop/ApiVisitHistory.java
Normal file
@ -0,0 +1,113 @@
|
||||
package com.ruoyi.web.aop;
|
||||
|
||||
import com.ruoyi.common.utils.DateUtil;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.crops.domain.InterfaceStatistics;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import java.lang.reflect.Array;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* API访问历史统计
|
||||
* @author yangjunqiang
|
||||
*/
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class ApiVisitHistory {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(ApiVisitHistory.class);
|
||||
|
||||
private ThreadLocal<Long> startTime = new ThreadLocal<>();
|
||||
|
||||
private Set userIds = new HashSet();
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
/**
|
||||
* 定义切面
|
||||
* - 此处代表com.ruoyi.web.controller.crops包下的所有接口都会被统计
|
||||
*/
|
||||
@Pointcut("execution(* com.ruoyi.web.controller.crops..*.*(..))")
|
||||
public void pointCut(){
|
||||
|
||||
}
|
||||
|
||||
@Before("pointCut()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
startTime.set(System.currentTimeMillis());
|
||||
//计数
|
||||
AtomicCounter.getInstance().increase();
|
||||
}
|
||||
|
||||
@AfterReturning(returning = "returnVal", pointcut = "pointCut()")
|
||||
public void doAfterReturning(JoinPoint joinPoint, Object returnVal) {
|
||||
//判断访问接口的用户数
|
||||
try {
|
||||
userIds.add(SecurityUtils.getUserId());
|
||||
}catch (Exception e){}
|
||||
//从redis中获取数据
|
||||
InterfaceStatistics iS = (InterfaceStatistics) redisTemplate.opsForValue().get("interfaceStatistics");
|
||||
//当前时间和今天24点相差毫秒数
|
||||
long millis = DateUtil.dateDiff(new Date(), DateUtil.getDayEnd());
|
||||
//如果redis中有数据
|
||||
if (iS!=null){
|
||||
Integer visits = iS.getVisits();
|
||||
Integer dataEntries = iS.getDataEntries();
|
||||
dataEntries +=getLength(returnVal);
|
||||
Integer accessingUsers = iS.getAccessingUsers();
|
||||
// log.info("耗费时间:[{}] ms,访问次数:{},交换数据总量:{}", System.currentTimeMillis() - startTime.get(),AtomicCounter.getInstance().getValue(),dataEntries);
|
||||
InterfaceStatistics interfaceStatistics = new InterfaceStatistics();
|
||||
//访问次数进行自增
|
||||
interfaceStatistics.setVisits(++visits);
|
||||
//数据总量
|
||||
interfaceStatistics.setDataEntries(dataEntries);
|
||||
//用户访问数,只取最大
|
||||
interfaceStatistics.setAccessingUsers((userIds.size()>accessingUsers)?userIds.size():accessingUsers);
|
||||
redisTemplate.opsForValue().set("interfaceStatistics",interfaceStatistics, Duration.ofMillis(millis));
|
||||
}else {
|
||||
InterfaceStatistics interfaceStatistics = new InterfaceStatistics();
|
||||
interfaceStatistics.setVisits(1);
|
||||
interfaceStatistics.setDataEntries(1);
|
||||
interfaceStatistics.setAccessingUsers(1);
|
||||
redisTemplate.opsForValue().set("interfaceStatistics",interfaceStatistics, Duration.ofMillis(millis));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当接口报错时执行此方法
|
||||
*/
|
||||
@AfterThrowing(pointcut = "pointCut()")
|
||||
public void doAfterThrowing(JoinPoint joinPoint) {
|
||||
log.info("接口访问失败");
|
||||
}
|
||||
|
||||
|
||||
//判断Object 的类型(map,set,list,array),并返回长度
|
||||
private static int getLength(Object obj) {
|
||||
if (obj == null) {
|
||||
return 0;
|
||||
}
|
||||
if (obj.getClass().isArray()){
|
||||
int length = Array.getLength(obj);
|
||||
return length;
|
||||
}if (obj instanceof List) {
|
||||
return ((List) obj).size();
|
||||
}if (obj instanceof Set) {
|
||||
return ((Set) obj).size();
|
||||
}if (obj instanceof Map) {
|
||||
Object data = ((Map) obj).get("data");
|
||||
getLength(data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.ruoyi.web.aop;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 计数器,统计当前执行的任务数
|
||||
* @author yangjunqiang
|
||||
*
|
||||
*/
|
||||
public class AtomicCounter {
|
||||
|
||||
/**
|
||||
* 创建了一个私有静态的AtomicCounter对象,作为单例模式的实例。
|
||||
*/
|
||||
private static final AtomicCounter atomicCounter = new AtomicCounter();
|
||||
|
||||
/**
|
||||
* 私有的构造函数,用于限制类的实例化。其他类无法直接实例化该类,只能通过getInstance()方法获取单例对象
|
||||
*/
|
||||
private AtomicCounter() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共静态方法getInstance(),用于获取AtomicCounter类的单例对象。
|
||||
* @return 返回之前创建的静态atomicCounter对象
|
||||
*/
|
||||
public static AtomicCounter getInstance() {
|
||||
return atomicCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建了一个私有静态的AtomicInteger对象counter,用于存储计数器的值。
|
||||
*/
|
||||
private static AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
/**
|
||||
* 公共方法getValue(),用于获取计数器的当前值。
|
||||
* @return 通过调用counter.get()来获取counter的当前值,并返回。
|
||||
*/
|
||||
public int getValue() {
|
||||
return counter.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共方法increase(),用于递增计数器的值。
|
||||
* @return 通过调用counter.incrementAndGet()来递增counter的值,并返回递增后的新值。
|
||||
*/
|
||||
public int increase() {
|
||||
return counter.incrementAndGet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 公共方法decrease(),用于递减计数器的值。
|
||||
* 通过调用counter.decrementAndGet()来递减counter的值,并返回递减后的新值。
|
||||
* @return
|
||||
*/
|
||||
public int decrease() {
|
||||
return counter.decrementAndGet();
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.crops.domain.CropsComprehensiveData;
|
||||
import com.ruoyi.crops.service.ICropsComprehensiveDataService;
|
||||
@ -17,9 +15,6 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 作物综合数据Controller
|
||||
*
|
||||
* @author my
|
||||
* @date 2023-04-19
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/crops/data")
|
||||
@ -31,7 +26,7 @@ public class CropsComprehensiveDataController extends BaseController
|
||||
/**
|
||||
* 查询作物综合数据列表
|
||||
*/
|
||||
|
||||
@PreAuthorize("@ss.hasPermi('crops:data:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CropsComprehensiveData cropsComprehensiveData)
|
||||
{
|
||||
@ -44,7 +39,6 @@ public class CropsComprehensiveDataController extends BaseController
|
||||
* 导出作物综合数据列表
|
||||
*/
|
||||
|
||||
@Log(title = "作物综合数据", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, CropsComprehensiveData cropsComprehensiveData)
|
||||
{
|
||||
@ -67,7 +61,6 @@ public class CropsComprehensiveDataController extends BaseController
|
||||
* 新增作物综合数据
|
||||
*/
|
||||
|
||||
@Log(title = "作物综合数据", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody CropsComprehensiveData cropsComprehensiveData)
|
||||
{
|
||||
@ -78,7 +71,7 @@ public class CropsComprehensiveDataController extends BaseController
|
||||
* 修改作物综合数据
|
||||
*/
|
||||
|
||||
@Log(title = "作物综合数据", businessType = BusinessType.UPDATE)
|
||||
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody CropsComprehensiveData cropsComprehensiveData)
|
||||
{
|
||||
@ -89,7 +82,6 @@ public class CropsComprehensiveDataController extends BaseController
|
||||
* 删除作物综合数据
|
||||
*/
|
||||
|
||||
@Log(title = "作物综合数据", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids)
|
||||
{
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.CropsDrought;
|
||||
import com.ruoyi.crops.service.ICropsDroughtService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
@ -36,6 +38,7 @@ public class CropsDroughtController extends BaseController {
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:drought:list')")
|
||||
@GetMapping("/{time}")
|
||||
public List<CropsDrought> selectByTime(@PathVariable("time")Date time){
|
||||
return iCropsDroughtService.selectByTime(time);
|
||||
|
@ -6,6 +6,7 @@ import com.ruoyi.crops.domain.CropStructure;
|
||||
import com.ruoyi.crops.domain.CropsGrowth;
|
||||
import com.ruoyi.crops.service.ICropsGrowthService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
@ -22,7 +23,7 @@ public class CropsGrowthController extends BaseController {
|
||||
private ICropsGrowthService iCropsGrowthService;
|
||||
|
||||
/**
|
||||
* 批量新增
|
||||
* 批量新增作物长势数据
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@ -33,10 +34,11 @@ public class CropsGrowthController extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间查询
|
||||
* 根据时间查询作物长势数据
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:growth:list')")
|
||||
@GetMapping("/{time}")
|
||||
public List<CropsGrowth> selectByTime(@PathVariable("time") Date time){
|
||||
return iCropsGrowthService.selectByTime(time);
|
||||
|
@ -7,6 +7,7 @@ import com.ruoyi.crops.service.ICropsStructureService;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.aspectj.weaver.loadtime.Aj;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -48,6 +49,7 @@ public class CropsStructureController extends BaseController {
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:structure:list')")
|
||||
@GetMapping("/{time}")
|
||||
public List<CropStructure> selectByTime(@PathVariable Date time){
|
||||
return iCropsStructureService.selectByTime(time);
|
||||
|
@ -0,0 +1,112 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.CropsUser;
|
||||
import com.ruoyi.crops.service.ICropsUserService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 用户controller
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops/user")
|
||||
public class CropsUserController extends BaseController {
|
||||
@Autowired
|
||||
private ICropsUserService iCropsUserService;
|
||||
|
||||
/**
|
||||
* 根据id查询用户
|
||||
* @param phone
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{phone}")
|
||||
public CropsUser selectByPhone(@PathVariable String phone) {
|
||||
return iCropsUserService.selectByPhone(phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有用户列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:user:list')")
|
||||
@GetMapping()
|
||||
public List<CropsUser> list() {
|
||||
return iCropsUserService.list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:user:delete')")
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult delete(@PathVariable Integer id) {
|
||||
return toAjax(iCropsUserService.delete(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
*
|
||||
* @param cropsUser
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/register")
|
||||
public AjaxResult register(@Valid CropsUser cropsUser, Errors errors, String psw2) {
|
||||
if (errors.hasErrors()) {
|
||||
return AjaxResult.error(errors.getAllErrors().get(0).getDefaultMessage());
|
||||
} else if (!cropsUser.getPassword().equals(psw2)) {
|
||||
return AjaxResult.error("两次密码不同");
|
||||
} else {
|
||||
try {
|
||||
int ret = iCropsUserService.regist(cropsUser);
|
||||
if (ret > 0) {
|
||||
return AjaxResult.success(cropsUser);
|
||||
} else {
|
||||
return AjaxResult.error("注册失败");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
return AjaxResult.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public AjaxResult login(@Valid CropsUser cropsUser, Errors errors, HttpSession session) {
|
||||
if (errors.hasErrors()) {
|
||||
return AjaxResult.error(errors.getAllErrors().get(0).getDefaultMessage());
|
||||
} else {
|
||||
CropsUser user = iCropsUserService.login(cropsUser);
|
||||
if (user != null) {
|
||||
session.setAttribute("cropsUser", user);
|
||||
return AjaxResult.success("登录成功");
|
||||
} else {
|
||||
return AjaxResult.error("用户不存在/密码错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public AjaxResult update(@PathVariable Integer id) {
|
||||
return toAjax(iCropsUserService.update(id));
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.CropsYield;
|
||||
import com.ruoyi.crops.service.ICropsYieldService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
@ -12,7 +13,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 作物产量查询
|
||||
* 作物产量Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/crops/yield")
|
||||
@ -25,6 +26,7 @@ public class CropsYieldConeroller extends BaseController {
|
||||
* @param year
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:yield:list')")
|
||||
@GetMapping("/{year}")
|
||||
public List<CropsYield> selectByYear(@PathVariable Integer year){
|
||||
return iCropsYieldService.selectByYear(year);
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.crops.domain.DataAcquisition;
|
||||
import com.ruoyi.crops.service.IDataAcquisitionService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据采集Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/crops/acquisition")
|
||||
public class DataAcquisitionController extends BaseController {
|
||||
@Autowired
|
||||
private IDataAcquisitionService iDataAcquisitionService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataAcquisition.class);
|
||||
|
||||
@GetMapping
|
||||
@PreAuthorize("@ss.hasPermi('crops:acquisition:list')")
|
||||
public DataAcquisition getData() {
|
||||
return iDataAcquisitionService.getData();
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public DataAcquisition getdataAcquisition(){
|
||||
logger.info("每小时更新天空地一体化农业检测数据");
|
||||
return iDataAcquisitionService.getdataAcquisition();
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ 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.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.DeviceSense;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonDeviceSenseBean;
|
||||
@ -13,16 +14,20 @@ 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.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 设备状态信息Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/crops/device")
|
||||
public class DeviceSenseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
public class DeviceSenseController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeviceSenseController.class);
|
||||
|
||||
@Value("${url.deviceSense}")
|
||||
String url;//指定UR
|
||||
@ -40,71 +45,91 @@ public class DeviceSenseController {
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
@GetMapping
|
||||
public List<DeviceSense> selectBytime(@RequestParam String startTime, @RequestParam String endTime) {
|
||||
@PreAuthorize("@ss.hasPermi('crops:device:select')")
|
||||
@GetMapping()
|
||||
public List<DeviceSense> selectBytime(@RequestParam Date startTime, @RequestParam Date endTime) {
|
||||
return iDeviceSenseService.selectByTime(startTime, endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时任务调用接口获取数据插入数据库
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Scheduled(fixedDelay = 6 * 60 * 1000)
|
||||
public void getsense() throws Exception {
|
||||
public DeviceSense getsense(){
|
||||
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));
|
||||
try {
|
||||
//格式化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);
|
||||
//使用sql判断重复数据插入
|
||||
iDeviceSenseService.dedupInsert(deviceSense);
|
||||
|
||||
//判断设备预警信息 插入异常数据库
|
||||
iWarningService.insertWarning(deviceSense);
|
||||
logger.info("每6分钟更新一次设备传感数据");
|
||||
//判断设备预警信息 插入异常数据库
|
||||
iWarningService.judgeWarning(deviceSense);
|
||||
logger.info("每6分钟更新一次设备传感数据");
|
||||
return deviceSense;
|
||||
} catch (Exception e) {
|
||||
logger.info(e.toString());
|
||||
logger.info("获取传感设备数据失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小时,周,天,获取其平均值数据
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:device:sense')")
|
||||
@GetMapping("/sense")
|
||||
public AjaxResult averageList(@RequestParam String type) {
|
||||
return AjaxResult.success(iDeviceSenseService.averageList(type));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据时间查询设备状态
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/select")
|
||||
public List<DeviceSense> select(@RequestParam Date startTime, @RequestParam Date endTime) {
|
||||
return iDeviceSenseService.selectByTime(startTime, endTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,447 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.DateUtil;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ShapeUtil;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.crops.domain.*;
|
||||
import com.ruoyi.common.utils.MyPoint;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonFarmMachineryBean;
|
||||
import com.ruoyi.crops.domain.gsonBean.GsonMachineryPositionBean;
|
||||
import com.ruoyi.crops.domain.vo.FarmMachineryVo;
|
||||
import com.ruoyi.crops.domain.vo.MachineryJobDataVo;
|
||||
import com.ruoyi.crops.service.IFarmMachineryService;
|
||||
import com.ruoyi.crops.service.IGeoServer;
|
||||
import com.ruoyi.crops.service.IMapDrawPolygonService;
|
||||
|
||||
import com.ruoyi.crops.service.IWarningFarmService;
|
||||
import org.apache.commons.collections.map.HashedMap;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.geom.GeometryFactory;
|
||||
import org.locationtech.jts.geom.MultiPolygon;
|
||||
import org.locationtech.jts.geom.Polygon;
|
||||
import org.locationtech.jts.io.WKTReader;
|
||||
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.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/farm/machinery")
|
||||
public class FarmMachineryController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(FarmMachineryController.class);
|
||||
@Autowired
|
||||
private IFarmMachineryService iFarmMachineryService;
|
||||
@Autowired
|
||||
private IMapDrawPolygonService iMapDrawPolygonService;
|
||||
@Autowired
|
||||
private IWarningFarmService iWarningFarmService;
|
||||
@Autowired
|
||||
private IGeoServer iGeoServer;
|
||||
|
||||
@Value("${FarmMachinery.vehicleList}")
|
||||
private String vehicleListUrl;
|
||||
@Value("${FarmMachinery.vehiclePos}")
|
||||
private String vehiclePosUrl;
|
||||
@Value("${FarmMachinery.vehicleTrack}")
|
||||
private String vehicleTrackUrl;
|
||||
@Value("${FarmMachinery.vehicleJobData}")
|
||||
private String vehicleJobDataUrl;
|
||||
|
||||
@Value("${FarmMachinery.clienttoken}")
|
||||
private String clienttoken;
|
||||
|
||||
|
||||
/**
|
||||
* 农机设备信息查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("selectMachineryData")
|
||||
public TableDataInfo selectMachineryData() {
|
||||
startPage();
|
||||
List<FarmMachineryVo> list = iFarmMachineryService.selectMachineryData();
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 农机位置查询
|
||||
*
|
||||
* @param vehicleno
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/position")
|
||||
public JSONObject machineryPosition(@RequestParam(value = "vehicleno", required = false) String vehicleno) {
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("clienttoken", clienttoken);
|
||||
if (vehicleno != null) {
|
||||
map.put("vehicleno", vehicleno);
|
||||
}
|
||||
String result = HttpUtil.createPost(vehiclePosUrl).form(map).execute().body();
|
||||
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
|
||||
GsonMachineryPositionBean gsonMachineryPositionBean = gson.fromJson(result, GsonMachineryPositionBean.class);
|
||||
List<MachineryPosition> position = gsonMachineryPositionBean.getPosition();
|
||||
if (position.size()>0){
|
||||
iFarmMachineryService.insertPositions(position);
|
||||
WithinAndIntersects(position);
|
||||
}
|
||||
return JSONObject.parseObject(result);
|
||||
}
|
||||
//判断农机经纬度是否在范围内
|
||||
public void WithinAndIntersects(List<MachineryPosition> position) {
|
||||
List<Map<String, Object>> maps = null;
|
||||
try {
|
||||
//读取上传的shp文件
|
||||
maps = ShapeUtil.readShp(RuoYiConfig.getUploadPath() + "/shpFile/shapefile.shp");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Map<String, Object> map : maps) {
|
||||
String wkt = (String) map.get("wkt");
|
||||
//更改字符串格式 11,22|22,33|33,22|11,22
|
||||
String substring = wkt.substring(16, wkt.length() - 3);
|
||||
String replace = substring.replace(", ", "|").replace(" ", ",");
|
||||
for (MachineryPosition machineryPosition : position) {
|
||||
if (!iFarmMachineryService.withinAndIntersects(replace, machineryPosition.getLng(), machineryPosition.getLat())){
|
||||
WarningFarm warningFarm = new WarningFarm();
|
||||
String vehicleno = machineryPosition.getVehicleno();
|
||||
warningFarm.setVehicleno(vehicleno);
|
||||
FarmMachineryVo farmMachineryVos = iFarmMachineryService.selectMachineryData(vehicleno);
|
||||
warningFarm.setOwnername(farmMachineryVos.getOwnername());
|
||||
warningFarm.setTime(new Date());
|
||||
warningFarm.setWarningInfo("作业范围超出");
|
||||
iWarningFarmService.insertWarning(warningFarm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史作业信息查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectMachineryJobData")
|
||||
public TableDataInfo selectMachineryJobData(@RequestParam(required = false, name = "startTime") Date startTime,
|
||||
@RequestParam(required = false, name = "endTime") Date endTime,
|
||||
@RequestParam(required = false, name = "vehicleno") String vehicleno) {
|
||||
startPage();
|
||||
List<MachineryJobDataVo> list = iFarmMachineryService.selectMachineryJobData(startTime, endTime, vehicleno);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询全部农机编号
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectVehicleno")
|
||||
public AjaxResult selectVehicleno(){
|
||||
List<String> list = iFarmMachineryService.selectVehicleno();
|
||||
return AjaxResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 今日作业查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectTodayJobData")
|
||||
public AjaxResult selectTodayJobData() {
|
||||
MachineryJobDataVo data = iFarmMachineryService.selectTodayJobData();
|
||||
Map<String, Double> map = new HashedMap();
|
||||
map.put("area", data.getArea());
|
||||
map.put("workhours", data.getWorkhours());
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 农机作业信息导出
|
||||
*
|
||||
* @param
|
||||
*/
|
||||
// @Log(title = "农机作业信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public AjaxResult export(@RequestParam("startTime") Date startTime,
|
||||
@RequestParam("endTime") Date endTime,
|
||||
@RequestParam("vehicleno") String vehicleno) {
|
||||
List<MachineryJobDataVo> list = iFarmMachineryService.selectMachineryJobData(startTime, endTime, vehicleno);
|
||||
ExcelUtil<MachineryJobDataVo> util = new ExcelUtil<>(MachineryJobDataVo.class);
|
||||
// util.exportExcel(response, list, "农机作业信息");
|
||||
AjaxResult excelName = util.exportExcel(list, "农机作业信息");
|
||||
String msg = (String) excelName.get("msg");
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("path", RuoYiConfig.getDownloadPath() + msg);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询农机轨迹信息
|
||||
*
|
||||
* @param workplace
|
||||
* @param pttime
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/VehicleTrack")
|
||||
public List<MachineryTrajectory> selectVehicleTrack(String workplace, Date pttime) {
|
||||
return iFarmMachineryService.selectVehicleTrack(workplace, pttime);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 农机设备状态查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectFarmStatus")
|
||||
public FarmStatus selectFarmStatus() {
|
||||
FarmStatus farmStatus = new FarmStatus();
|
||||
//农机设备信息查询
|
||||
List<FarmMachineryVo> farmMachineryVos = iFarmMachineryService.selectMachineryData();
|
||||
int total = farmMachineryVos.size();
|
||||
farmStatus.setTotal(total);
|
||||
int working = iFarmMachineryService.selectWorkingMachinery();
|
||||
farmStatus.setWorking(working);
|
||||
farmStatus.setUnwork(total - working);
|
||||
int Online = iFarmMachineryService.selectMachineryOnline();
|
||||
farmStatus.setOnline(Online);
|
||||
farmStatus.setOffline(total - Online);
|
||||
return farmStatus;
|
||||
}
|
||||
|
||||
//定时获取数据库农机轨迹并发布服务
|
||||
@Scheduled(fixedDelay = 10* 60 * 1000)
|
||||
public AjaxResult Machinert() throws Exception {
|
||||
Map<String, Map<String, String>> areaWorkhoursMap = new HashMap<>();
|
||||
//查询作业地块
|
||||
List<String> workplaceList = iFarmMachineryService.distinctWorkplace();
|
||||
Map result = new HashMap<>();
|
||||
StringBuilder multiPolygon = new StringBuilder("MULTIPOLYGON((");
|
||||
List<String> userdata = new ArrayList<>();
|
||||
StringBuilder multiLineString = new StringBuilder("MULTILINESTRING(");
|
||||
for (String workplace : workplaceList) {
|
||||
List<MyPoint> pointList = new ArrayList<>();
|
||||
Date date = new Date(2023 - 1900, 3 - 1, 13);
|
||||
//根据作业地块和时间查询农机轨迹数据
|
||||
List<MachineryTrajectory> machineryTrajectories = iFarmMachineryService.selectVehicleTrack(workplace, date);
|
||||
for (MachineryTrajectory machineryTrajectory : machineryTrajectories) {
|
||||
pointList.add(new MyPoint(machineryTrajectory.getLng(), machineryTrajectory.getLat()));
|
||||
}
|
||||
//数据大于1000进行抽稀缩减
|
||||
if (pointList.size() > 1000) {
|
||||
for (int i = 0; i < pointList.size(); i += 3) {
|
||||
pointList.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
String polygon = ShapeUtil.point2WktPolygon(pointList);
|
||||
String line = ShapeUtil.point2WktLine(pointList);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("polygon", polygon);
|
||||
|
||||
//在经纬度数组后加入第一个点位,形成闭环
|
||||
pointList.add(pointList.size(), pointList.get(0));
|
||||
//使用凸包算法过滤出边界
|
||||
List<MyPoint> myPoints = iMapDrawPolygonService.DrawPolygon(pointList);
|
||||
//第二次过滤转换为wkt格式
|
||||
String drawPolygon = ShapeUtil.point2WktPolygon(iMapDrawPolygonService.DrawPolygon(myPoints));
|
||||
//userdata中添加农机编号
|
||||
MachineryTrajectory trajectory = machineryTrajectories.get(0);
|
||||
//查询农机编号
|
||||
String vehicleno = trajectory.getVehicleno();
|
||||
userdata.add(vehicleno);
|
||||
userdata.add(trajectory.getWorkplace());
|
||||
//通过农机编号查询作业类型
|
||||
userdata.add(String.valueOf(iFarmMachineryService.selectJobtype(vehicleno)));
|
||||
|
||||
//截取wkt格式字符串,改变为MULTIPOLYGON格式
|
||||
String substring = drawPolygon.substring(8, drawPolygon.length() - 1);
|
||||
String linestring = line.substring(10);
|
||||
multiPolygon.append(substring).append("),(");
|
||||
multiLineString.append(linestring).append(",");
|
||||
|
||||
//计算地块面积(亩)
|
||||
String area = String.format("%.2f", ShapeUtil.getAreaByWkt(polygon) / 666.67);
|
||||
map.put("area", area);
|
||||
//计算作业时间
|
||||
|
||||
float workingHours = Float.parseFloat(DateUtil.dateDiffHours(trajectory.getPttime(),
|
||||
machineryTrajectories.get(machineryTrajectories.size() - 1).getPttime()));
|
||||
String pttime = String.valueOf(workingHours);
|
||||
map.put("workHours", pttime);
|
||||
if (areaWorkhoursMap.containsKey(trajectory.getVehicleno())) {
|
||||
Map<String, String> sMap = areaWorkhoursMap.get(trajectory.getVehicleno());
|
||||
float va = Float.parseFloat(area);
|
||||
float fa = Float.parseFloat(sMap.get("area"));
|
||||
area = String.format("%.2f", (va + fa));
|
||||
|
||||
float vw = Float.parseFloat(pttime);
|
||||
float fw = Float.parseFloat(sMap.get("workHours"));
|
||||
pttime = String.format("%.2f", (vw + fw));
|
||||
}
|
||||
Map<String, String> mp = new HashMap<>();
|
||||
mp.put("area", area);
|
||||
mp.put("workHours", pttime);
|
||||
areaWorkhoursMap.put(trajectory.getVehicleno(), mp);
|
||||
|
||||
result.put(workplace, map);
|
||||
|
||||
}
|
||||
//统计作业时长和面积插入数据库
|
||||
for (Map.Entry<String, Map<String, String>> entry : areaWorkhoursMap.entrySet()) {
|
||||
String vehicleno = entry.getKey();
|
||||
Map<String, String> map = entry.getValue();
|
||||
double area = Float.parseFloat(map.get("area"));
|
||||
double workingHours = Float.parseFloat(map.get("workHours"));
|
||||
iFarmMachineryService.updateAreaWorkhours(vehicleno, area, workingHours);
|
||||
}
|
||||
|
||||
String mPolygon = multiPolygon.delete(multiPolygon.length() - 2,multiPolygon.length()).append(")").toString();
|
||||
|
||||
String mLineString = multiLineString.deleteCharAt(multiLineString.length() - 1).append(")").toString();
|
||||
|
||||
String polygonPath = RuoYiConfig.getUploadPath()+ "/shpFile/" + LocalDate.now() + "polygon.shp";
|
||||
String lineStringPath = RuoYiConfig.getUploadPath()+ "/shpFile/lineString.shp";
|
||||
// 生成shp文件
|
||||
ShapeUtil.writeShape(mPolygon,"MultiPolygon",polygonPath,userdata);
|
||||
ShapeUtil.writeShape(mLineString,"MultiLineString",lineStringPath,userdata) ;
|
||||
String fileName = LocalDate.now() + "polygon";
|
||||
String polygonZipPath = RuoYiConfig.getUploadPath()+ "/shpFile/" + LocalDate.now() + "polygon.zip";
|
||||
String lineStringZipPath = RuoYiConfig.getUploadPath()+ "/shpFile/lineString.zip";
|
||||
//发布shp服务
|
||||
String polygonShpResult = iGeoServer.publishShp("PJZ", fileName, fileName, polygonZipPath);
|
||||
String lineStringShpResult = iGeoServer.publishShp("PJZ", "lineString", "lineString", lineStringZipPath);
|
||||
result.put("publishPolygonShp", polygonShpResult);
|
||||
result.put("publishlineStringShp", lineStringShpResult);
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 物联网接口获取农机轨迹数据
|
||||
*
|
||||
* @param vehicleno
|
||||
* @param jobday
|
||||
* @param jobtype
|
||||
* @return
|
||||
*/
|
||||
public String gettrack(String vehicleno, Date jobday, String jobtype) {
|
||||
//格式化作业日期
|
||||
String formatjobday = new SimpleDateFormat("yyyy-MM-dd").format(jobday);
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("clienttoken", clienttoken);
|
||||
//农机编号
|
||||
map.put("vehicleno", vehicleno);
|
||||
//作业日期
|
||||
map.put("jobday", formatjobday);
|
||||
//作业类型码
|
||||
map.put("jobtype", jobtype);
|
||||
String result = HttpUtil.createPost(vehicleTrackUrl).form(map).execute().body();
|
||||
return result;
|
||||
}
|
||||
|
||||
//定时获取农机轨迹信息
|
||||
@Scheduled(fixedDelay = 10 * 1000)
|
||||
public void processPositions() {
|
||||
// List<MachineryJobDataVo> machineryJobDataVos = iFarmMachineryService.selectMachineryJobData(DateUtil.getDayBegin(), DateUtil.getBeginDayOfTomorrow(), null);
|
||||
//查询作业信息
|
||||
List<MachineryJobDataVo> machineryJobDataVos = iFarmMachineryService.selectMachineryJobData();
|
||||
iFarmMachineryService.updateworkplace();
|
||||
//根据农机作业信息进行轨迹查询
|
||||
for (MachineryJobDataVo machineryJobDataVo : machineryJobDataVos) {
|
||||
// String json = gettrack(machineryJobDataVo.getVehicleno(), DateUtil.getDayBegin(), machineryJobDataVo.getJobtype());
|
||||
String json = gettrack(machineryJobDataVo.getVehicleno(), machineryJobDataVo.getJobday(), machineryJobDataVo.getJobtype());
|
||||
JSONObject jsonObject = JSONObject. parseObject(json);
|
||||
String postions = jsonObject.getString("postions");
|
||||
String vehicleno = jsonObject.getString("vehicleno");
|
||||
List<MachineryTrajectory> list = JSON.parseArray(postions, MachineryTrajectory.class);
|
||||
iFarmMachineryService.insertProcessPositions(list, vehicleno);
|
||||
}
|
||||
}
|
||||
|
||||
//农机作业任务查询每天九点查询一次
|
||||
@Scheduled(cron = "0 0 9 * * ?")
|
||||
public void getMachineryJobData() throws ParseException {
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("clienttoken", clienttoken);
|
||||
//按要求格式化日期数据进行查询七天数据
|
||||
|
||||
Date beginDayOf7day = DateUtil.getBeginDayOf7day();
|
||||
Date dayBegin = DateUtil.getDayBegin();
|
||||
String startTime = DateUtils.parseDateToStr("yyyy/MM/dd", beginDayOf7day);
|
||||
String endTime = DateUtils.parseDateToStr("yyyy/MM/dd", dayBegin);
|
||||
map.put("jobday", "[\"" + startTime + "\",\"" + endTime + "\"]");
|
||||
String result = HttpUtil.createPost(vehicleJobDataUrl).form(map).execute().body();
|
||||
//解析json
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
JSONArray jobdata = jsonObject.getJSONArray("jobdata");
|
||||
//今日农机作业任务数据
|
||||
List<MachineryJobData> list = JSONArray.parseArray(jobdata.toJSONString(), MachineryJobData.class);
|
||||
//进行数据去重
|
||||
List<MachineryJobData> machineryJobData = iFarmMachineryService.selectJobDataByTime(beginDayOf7day, dayBegin);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
MachineryJobData mj = list.get(i);
|
||||
for (MachineryJobData md : machineryJobData) {
|
||||
if (mj.getJobday().equals(md.getJobday()) &&
|
||||
mj.getVehicleno().equals(md.getVehicleno()) &&
|
||||
mj.getJobarea().equals(md.getJobarea())) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
logger.info("更新农机作业任务");
|
||||
iFarmMachineryService.insertJobDataBatch(list);
|
||||
}
|
||||
}
|
||||
|
||||
//每周一九点获取农机数据
|
||||
@Scheduled(cron = " 0 0 9 ? * 2")
|
||||
public void getMachineryData() {
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
map.put("clienttoken", clienttoken);
|
||||
String result = HttpUtil.createPost(vehicleListUrl).form(map).execute().body();
|
||||
Gson gson = new Gson();
|
||||
GsonFarmMachineryBean vehicleList = gson.fromJson(result, GsonFarmMachineryBean.class);
|
||||
//创建一个空的list集合存放json解析的Meteorological实体数据
|
||||
List<FarmMachinery> list = vehicleList.getVehicle();
|
||||
//从数据库里查询出来的数据
|
||||
List<FarmMachineryVo> farmMachineryList = iFarmMachineryService.selectMachineryData();
|
||||
//剔除两个集合里面重复元素根据Vmeid和Vehicleno
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
FarmMachinery fm = list.get(i);
|
||||
for (FarmMachineryVo f : farmMachineryList) {
|
||||
if (fm.getOwnername().equals(f.getOwnername()) && fm.getVehicleno().equals(f.getVehicleno())) {
|
||||
list.remove(i);
|
||||
i--;//不进行i--会数组下标越界异常
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
logger.info("更新农机数据");
|
||||
iFarmMachineryService.insertBatch(list);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -16,66 +15,79 @@ 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;
|
||||
|
||||
/**
|
||||
* 水肥一体机设备传感数据Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class FertigationSenseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
private static final Logger logger = LoggerFactory.getLogger(FertigationSenseController.class);
|
||||
|
||||
@Value("${url.deviceSense}")
|
||||
String url;//指定UR
|
||||
String url;//指定URL
|
||||
|
||||
@Autowired
|
||||
private IFertigationSenseService iFertigationSenseService;
|
||||
|
||||
/**
|
||||
* 定时获取水肥一体机设备数据
|
||||
* @throws Exception
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public void getsense() throws Exception {
|
||||
public FertigationSense 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;
|
||||
try{
|
||||
//格式化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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iFertigationSenseService.insert(fertigationSense);
|
||||
logger.info("每小时更新一次水肥一体机设备传感数据");
|
||||
return fertigationSense;
|
||||
}catch (Exception e){
|
||||
logger.info(e.toString());
|
||||
logger.info("获取水肥一体机设备传感数据失败");
|
||||
return null;
|
||||
}
|
||||
//使用sql判断重复数据插入
|
||||
iFertigationSenseService.insert(fertigationSense);
|
||||
logger.info("每小时更新一次水肥一体机设备传感数据");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.InterfaceStatistics;
|
||||
import com.ruoyi.crops.domain.vo.InterfaceStatisticsVo;
|
||||
import com.ruoyi.crops.service.InterfaceStatisticsService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static com.ruoyi.common.utils.Threads.sleep;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/interface/statistics")
|
||||
public class InterfaceStatisticsController extends BaseController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(InterfaceStatisticsController.class);
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
@Autowired
|
||||
private InterfaceStatisticsService interfaceStatisticsService;
|
||||
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public AjaxResult getStatistics(){
|
||||
//启动时延时一秒,其他定时任务先执行
|
||||
sleep(1000);
|
||||
InterfaceStatistics interfaceStatistics = (InterfaceStatistics) redisTemplate.opsForValue().get("interfaceStatistics");
|
||||
logger.info("每小时更新接口访问数据");
|
||||
return toAjax(interfaceStatisticsService.insert(interfaceStatistics));
|
||||
}
|
||||
@PreAuthorize("@ss.hasPermi('interface:statistics:day')")
|
||||
@GetMapping("/day")
|
||||
public InterfaceStatistics day(){
|
||||
return interfaceStatisticsService.selectByDay();
|
||||
}
|
||||
@PreAuthorize("@ss.hasPermi('interface:statistics:total')")
|
||||
@GetMapping("/total")
|
||||
public InterfaceStatisticsVo total(){
|
||||
return interfaceStatisticsService.selectTotal();
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +1,152 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
|
||||
import com.ruoyi.crops.domain.MachineParameter;
|
||||
import com.ruoyi.crops.domain.OperationRecords;
|
||||
import com.ruoyi.crops.domain.vo.MachineParameterVo;
|
||||
import com.ruoyi.crops.service.IMachineParameterService;
|
||||
import com.ruoyi.crops.service.IOperationRecordsService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.assertj.core.util.DateUtil.now;
|
||||
|
||||
|
||||
/**
|
||||
* 水肥一体机参数controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/machine/parameter")
|
||||
public class MachineParameterController extends BaseController {
|
||||
public class MachineParameterController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IMachineParameterService machineParameterService;
|
||||
|
||||
/**
|
||||
* 根据大棚名称进行查询
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{name}")
|
||||
public List<MachineParameter> selectByName(@PathVariable String name) {
|
||||
return machineParameterService.selectByName(name);
|
||||
}
|
||||
@Autowired
|
||||
private IOperationRecordsService iOperationRecordsService;
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 新增单条数据
|
||||
* 获取水肥一体机状态进行两次对比,得到哪些参数被修改,存入操作记录
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping("/getcompare")
|
||||
public String getMachineParameter(Integer type) throws Exception {
|
||||
//判断是开启还是关闭界面
|
||||
if (type == 0) {
|
||||
//临时存入redis中和第二次做对比
|
||||
MachineParameter machineParameter = machineParameterService.getMachineParameter();
|
||||
redisTemplate.opsForValue().set("machineParameter", machineParameter, Duration.ofMinutes(10));
|
||||
return machineParameter.toString();
|
||||
} else if (type == 1) {
|
||||
//操作好关闭界面再次发送请求
|
||||
MachineParameter machineParameter = machineParameterService.getMachineParameter();
|
||||
MachineParameter parameter = (MachineParameter) redisTemplate.opsForValue().get("machineParameter");
|
||||
//记录修改了几个字段值
|
||||
int count = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
//反射获取类对象
|
||||
for (Field declaredField : MachineParameter.class.getDeclaredFields()) {
|
||||
try {
|
||||
//通过下面compareColumns里定义的字段名进行对比
|
||||
if (compareColumns.containsKey(declaredField.getName())) {
|
||||
declaredField.setAccessible(true);
|
||||
// 转成string 比较字符串内容
|
||||
Object obj1 = declaredField.get(parameter);
|
||||
Object obj2 = declaredField.get(machineParameter);
|
||||
if (Objects.nonNull(obj1) && !obj1.equals(obj2)) {
|
||||
OperationRecords operationRecords = new OperationRecords();
|
||||
//状态为0阀门关闭
|
||||
if (obj2.equals("0")) {
|
||||
operationRecords.setOperationContent(compareColumns.get(declaredField.getName()) + "关闭");
|
||||
} else if (obj2.equals("1")) {
|
||||
operationRecords.setOperationContent(compareColumns.get(declaredField.getName()) + "打开");
|
||||
}
|
||||
operationRecords.setUpdateTime(now());
|
||||
//插入操作记录
|
||||
iOperationRecordsService.insert(operationRecords);
|
||||
if (count == 2) {
|
||||
sb.append("等信息已更新");
|
||||
break;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(compareColumns.get(declaredField.getName()));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
// log.info("initCustomerDetailCount:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
return ("compare result:" + sb.toString());
|
||||
}
|
||||
return "参数错误";
|
||||
|
||||
}
|
||||
|
||||
Map<String, String> compareColumns = new HashMap<String, String>() {
|
||||
{
|
||||
put("Valve1", "阀门1");
|
||||
put("valve2", "阀门2");
|
||||
put("Valve3", "阀门3");
|
||||
put("Valve4", "阀门4");
|
||||
put("Valve5", "阀门5");
|
||||
put("Valve6", "阀门6");
|
||||
put("Valve7", "阀门7");
|
||||
put("Valve8", "阀门8");
|
||||
put("Valve9", "阀门9");
|
||||
put("Valve10", "阀门10");
|
||||
put("Valve11", "阀门11");
|
||||
put("Valve12", "阀门12");
|
||||
put("Valve13", "阀门13");
|
||||
put("Valve14", "阀门14");
|
||||
put("Valve15", "阀门15");
|
||||
put("Valve16", "阀门16");
|
||||
put("Valve17", "阀门17");
|
||||
put("Valve18", "阀门18");
|
||||
put("Valve19", "阀门19");
|
||||
put("Valve20", "阀门20");
|
||||
put("JiaoBan1", "搅拌1");
|
||||
put("JiaoBan2", "搅拌2");
|
||||
put("JiaoBan3", "搅拌3");
|
||||
put("JiaoBan4", "搅拌4");
|
||||
put("PowerMode", "功率模式");
|
||||
put("ControlMode", "控制模式");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 获取ph值,流量,压力值
|
||||
*
|
||||
* @param machineParameter
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult insert(@RequestBody MachineParameter machineParameter) {
|
||||
return toAjax(machineParameterService.insert(machineParameter));
|
||||
|
||||
@GetMapping("/select")
|
||||
public MachineParameterVo selectParameter() throws Exception {
|
||||
return machineParameterService.selectParameter();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,35 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.security.access.prepost.PreAuthorize;
|
||||
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");
|
||||
private static final Logger logger = LoggerFactory.getLogger(MeteorologicalController.class);
|
||||
|
||||
@Value("${Meteorological.url}")
|
||||
private String url;
|
||||
@ -33,6 +41,13 @@ public class MeteorologicalController {
|
||||
@Autowired
|
||||
private IMeteorologicalService iMeteorologicalService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询预警数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:meterological:select')")
|
||||
@GetMapping("/meterological")
|
||||
public AjaxResult selectByTime() {
|
||||
if (iMeteorologicalService.selectByTime().isEmpty()) {
|
||||
@ -41,40 +56,24 @@ public class MeteorologicalController {
|
||||
return AjaxResult.success(iMeteorologicalService.selectByTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时查询天气数据并去重保存
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public void MeteorologicalInfo() {
|
||||
public List<Meteorological> 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转换成对应实体类
|
||||
//将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> list = model.result;
|
||||
//从数据库查询出今日的预警信息
|
||||
List<Meteorological> meteorologicals = iMeteorologicalService.selectByTime();
|
||||
//剔除两个集合里面重复元素根据WarnId和Time
|
||||
@ -82,20 +81,26 @@ public class MeteorologicalController {
|
||||
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())) {
|
||||
if (me.getId() == Integer.parseInt(m.getWarnId()) && me.getTime().equals(m.getTime())) {
|
||||
list.remove(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
//遍历去重集合插入数据库
|
||||
for (Meteorological meteorological : list) {
|
||||
iMeteorologicalService.insert(meteorological);
|
||||
if (!list.isEmpty()) {
|
||||
//list顺序反转
|
||||
Collections.reverse(list);
|
||||
logger.info("每小时更新1次天气预警");
|
||||
iMeteorologicalService.insertBatch(list);
|
||||
} else {
|
||||
logger.info("本小时内无新预警");
|
||||
}
|
||||
logger.info("每小时更新1次天气预警");
|
||||
|
||||
return list;
|
||||
|
||||
} else {
|
||||
logger.info("今日暂无预警");
|
||||
}
|
||||
|
||||
return model.result;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.OperationRecords;
|
||||
import com.ruoyi.crops.service.IOperationRecordsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -23,6 +24,7 @@ public class OperationRecordsController extends BaseController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('operation:records:list')")
|
||||
@GetMapping("/list")
|
||||
public List<OperationRecords> listAll() {
|
||||
return iOperationRecordsService.selectAll();
|
||||
|
@ -5,12 +5,13 @@ import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.crops.domain.ServiceType;
|
||||
import com.ruoyi.crops.service.IServiceTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类型controller
|
||||
* 服务类型Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/service/type")
|
||||
@ -24,6 +25,7 @@ public class ServiceTypeController extends BaseController {
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:service:type')")
|
||||
@GetMapping("/{type}")
|
||||
public List<ServiceType> selectByType(@PathVariable String type) {
|
||||
return typeService.selectByType(type);
|
||||
@ -34,6 +36,7 @@ public class ServiceTypeController extends BaseController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('service:type:selectAll')")
|
||||
@GetMapping
|
||||
public List<ServiceType> selectAll() {
|
||||
return typeService.selectAll();
|
||||
@ -45,6 +48,7 @@ public class ServiceTypeController extends BaseController {
|
||||
* @param serviceType
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('service:type:insert')")
|
||||
@PostMapping("insert")
|
||||
public AjaxResult insert(@RequestBody ServiceType serviceType) {
|
||||
return toAjax(typeService.insert(serviceType));
|
||||
@ -56,6 +60,7 @@ public class ServiceTypeController extends BaseController {
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('service:type:delete')")
|
||||
@DeleteMapping("/{ids}")
|
||||
private AjaxResult remove(@PathVariable Long[] ids) {
|
||||
return toAjax(typeService.deleteByIds(ids));
|
||||
|
@ -1,17 +1,16 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.BashUtils;
|
||||
import com.ruoyi.common.utils.ShapeUtil;
|
||||
import com.ruoyi.crops.domain.ServiceType;
|
||||
import com.ruoyi.crops.service.IFarmMachineryService;
|
||||
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;
|
||||
@ -20,17 +19,15 @@ 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.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops")
|
||||
public class UploadController {
|
||||
@Value("${url.group1Upload}")
|
||||
private String url;
|
||||
|
||||
private String workSpace = "PJZ";
|
||||
@Value("${path.exepath}")
|
||||
@ -48,6 +45,9 @@ public class UploadController {
|
||||
@Autowired
|
||||
private IexeService iexeService;
|
||||
|
||||
@Autowired
|
||||
private IFarmMachineryService iFarmMachineryService;
|
||||
|
||||
/**
|
||||
* 上传TIFF文件
|
||||
*
|
||||
@ -57,19 +57,17 @@ public class UploadController {
|
||||
* @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);
|
||||
String uploadPath = RuoYiConfig.getUploadPath();
|
||||
//保存文件到本地并获得文件路径
|
||||
String filePath = iUploadService.upload(file, uploadPath+"/tifFile");
|
||||
|
||||
//调用接口上传文件到服务器
|
||||
Map<String, Object> map = new HashMap<>();//存放参数
|
||||
// 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();
|
||||
// map.put("file", targetFile);
|
||||
// map.put("path", "pjz/tif");
|
||||
// String result = HttpUtil.createPost(url).form(map).execute().body();
|
||||
|
||||
//获取文件信息
|
||||
String name = targetFile.getName();
|
||||
@ -87,10 +85,11 @@ public class UploadController {
|
||||
serviceType.setTime(date);
|
||||
serviceType.setServiceName(servieName);
|
||||
serviceType.setFileName(name);
|
||||
serviceType.setFilePath(result);
|
||||
serviceType.setFilePath(filePath);
|
||||
serviceType.setStyle(type);
|
||||
|
||||
//发送地图服务
|
||||
String pjz = iGeoServer.GeoServer(workSpace, fileName, filePath);
|
||||
String pjz = iGeoServer.publishTiff(workSpace, fileName, filePath, type);
|
||||
|
||||
//调用exe批量导入数据
|
||||
String res = iexeService.execCommand(type, targetFile.getAbsolutePath(), boundaryDataPath);
|
||||
@ -99,4 +98,26 @@ public class UploadController {
|
||||
return AjaxResult.success(pjz + res);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传shp.zip文件
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/uploadShp")
|
||||
public AjaxResult uploadShp(@RequestParam("file") MultipartFile file){
|
||||
String uploadPath = RuoYiConfig.getUploadPath();
|
||||
//保存文件到本地并获得文件路径
|
||||
String filePath = null;
|
||||
try {
|
||||
filePath = iUploadService.upload(file, uploadPath+"/shpFile");
|
||||
//解压上传的shp.zip文件
|
||||
String unzip = ShapeUtil.unzip(filePath, uploadPath + "/shpFile/");
|
||||
return AjaxResult.success(unzip);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ 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.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -18,9 +19,8 @@ import java.util.HashMap;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/info")
|
||||
|
||||
public class UserInfoController extends BaseController {
|
||||
private static final Logger logger = LoggerFactory.getLogger("scheduled");
|
||||
private static final Logger logger = LoggerFactory.getLogger(UserInfoController.class);
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
@ -2,18 +2,22 @@ package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.DateUtil;
|
||||
import com.ruoyi.crops.domain.DeviceSense;
|
||||
import com.ruoyi.crops.domain.WaringNumber;
|
||||
import com.ruoyi.crops.domain.WarningInformation;
|
||||
import com.ruoyi.crops.service.IDeviceSenseService;
|
||||
import com.ruoyi.crops.service.IWarningService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预警信息controller
|
||||
* 预警信息Controller
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/warning/information")
|
||||
@ -22,13 +26,17 @@ public class WarningController extends BaseController {
|
||||
private IWarningService iWarningService;
|
||||
|
||||
/**
|
||||
* 根据时间查询
|
||||
* 预警信息根据时间查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('warning:information:selectByTime')")
|
||||
@GetMapping("/selectByTime")
|
||||
public List<WarningInformation> selectBytTime(@RequestParam Date startTime, @RequestParam Date endTime) {
|
||||
return iWarningService.selectByTime(startTime, endTime);
|
||||
public TableDataInfo selectBytTime(@RequestParam(required = false) Date startTime,
|
||||
@RequestParam(required = false) Date endTime) {
|
||||
startPage();
|
||||
List<WarningInformation> list = iWarningService.selectByTime(startTime, endTime);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,6 +50,12 @@ public class WarningController extends BaseController {
|
||||
return toAjax(iWarningService.insert(warningInformation));
|
||||
}
|
||||
|
||||
/**
|
||||
* 大棚预警次数查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('warning:information:numberOfTimes')")
|
||||
@GetMapping("/numberOfTimes")
|
||||
public AjaxResult numberOfTimes() {
|
||||
List<WarningInformation> daylist = iWarningService.selectByTime(DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
@ -58,5 +72,6 @@ public class WarningController extends BaseController {
|
||||
waringNumber.setMonthNumber(monthNumber);
|
||||
return AjaxResult.success(waringNumber);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,111 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.utils.DateUtil;
|
||||
import com.ruoyi.crops.domain.MachineryTrajectory;
|
||||
import com.ruoyi.crops.domain.WaringNumber;
|
||||
import com.ruoyi.crops.domain.WarningFarm;
|
||||
import com.ruoyi.crops.domain.vo.FarmMachineryVo;
|
||||
import com.ruoyi.crops.service.IFarmMachineryService;
|
||||
import com.ruoyi.crops.service.IWarningFarmService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/warning/farm")
|
||||
public class WarningFarmController extends BaseController {
|
||||
@Autowired
|
||||
private IFarmMachineryService iFarmMachineryService;
|
||||
@Autowired
|
||||
private IWarningFarmService iWarningFarmService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WarningFarmController.class);
|
||||
|
||||
/**
|
||||
* 农机预警次数查询
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/numberOfTimes")
|
||||
public AjaxResult numberOfTimes() {
|
||||
List<WarningFarm> daylist = iWarningFarmService.selectByTime(DateUtil.getDayBegin(), DateUtil.getDayEnd());
|
||||
int dayNumber = daylist.size();
|
||||
|
||||
List<WarningFarm> weeklist = iWarningFarmService.selectByTime(DateUtil.getBeginDayOfWeek(), DateUtil.getEndDayOfWeek());
|
||||
int weekNumber = weeklist.size();
|
||||
|
||||
List<WarningFarm> monthlist = iWarningFarmService.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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 农机预警信息根据时间查询
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectByTime")
|
||||
public TableDataInfo selectBytTime(@RequestParam(required = false) Date startTime,
|
||||
@RequestParam(required = false) Date endTime) {
|
||||
startPage();
|
||||
List<WarningFarm> list = iWarningFarmService.selectByTime(startTime, endTime);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
//判断农机预警
|
||||
@Scheduled(fixedDelay = 5 * 60 * 1000)
|
||||
public void warning() {
|
||||
//查询今日作业农机编号
|
||||
List<String> vehiclenoList = iFarmMachineryService.distinctVehicleno();
|
||||
//根据编号查询作业地块
|
||||
for (String vehicleno : vehiclenoList) {
|
||||
List<String> workplaceList = iFarmMachineryService.distinctWorkplace(vehicleno);
|
||||
Date lastTime = null;
|
||||
//根据地块查询具体作业数据
|
||||
for (String workplace : workplaceList) {
|
||||
Date date = new Date(2023 - 1900, 3 - 1, 13);
|
||||
//根据作业地块和时间查询农机轨迹数据
|
||||
List<MachineryTrajectory> machineryTrajectories = iFarmMachineryService.selectVehicleTrack(workplace, date);
|
||||
MachineryTrajectory trajectory = machineryTrajectories.get(0);
|
||||
Date lastPttime = machineryTrajectories.get(machineryTrajectories.size() - 1).getPttime();
|
||||
//农机此次作业时长
|
||||
float workingHours = Float.parseFloat(DateUtil.dateDiffHours(trajectory.getPttime(), lastPttime));
|
||||
|
||||
WarningFarm warningFarm = new WarningFarm();
|
||||
warningFarm.setVehicleno(vehicleno);
|
||||
warningFarm.setTime(new Date());
|
||||
FarmMachineryVo farmMachineryVos = iFarmMachineryService.selectMachineryData(vehicleno);
|
||||
warningFarm.setOwnername(farmMachineryVos.getOwnername());
|
||||
if (lastTime != null) {
|
||||
float freeTime = Float.parseFloat(DateUtil.dateDiffHours(lastTime, trajectory.getPttime()));
|
||||
if (freeTime > 0.1) {
|
||||
//插入数据库预警
|
||||
warningFarm.setWarningInfo("闲置时间过长");
|
||||
iWarningFarmService.insertWarning(warningFarm);
|
||||
logger.info("农机闲置时间预警更新:" + vehicleno +"-"+ freeTime + "小时");
|
||||
}
|
||||
}
|
||||
lastTime = machineryTrajectories.get(machineryTrajectories.size() - 1).getPttime();
|
||||
if (workingHours > 0.5) {
|
||||
//预警
|
||||
warningFarm.setWarningInfo("作业时间过长");
|
||||
iWarningFarmService.insertWarning(warningFarm);
|
||||
logger.info("农机作业时间预警更新:" + vehicleno +"-"+ workingHours + "小时");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.ruoyi.web.controller.crops;
|
||||
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.crops.domain.WeatherPredictionEntity;
|
||||
import com.ruoyi.crops.domain.vo.WeatherPredoctionVo;
|
||||
import com.ruoyi.crops.service.IWeatherPredictionService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/crops/weather")
|
||||
public class WeatherPredictionController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private IWeatherPredictionService iWeatherPredictionService;
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(WeatherPredictionController.class);
|
||||
|
||||
/**
|
||||
* 查询一周的天气数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:weather:selectWeek')")
|
||||
@GetMapping("/selectWeek")
|
||||
public List<WeatherPredictionEntity> selectWeek() {
|
||||
return iWeatherPredictionService.selectWeek();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 气象数据对比查询
|
||||
*
|
||||
* @param time1
|
||||
* @param time2
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('crops:weather:compareTime')")
|
||||
@GetMapping("/compareTime")
|
||||
public List<WeatherPredoctionVo> compareTime(@RequestParam Date time1, @RequestParam Date time2) {
|
||||
List<WeatherPredoctionVo> weather1 = iWeatherPredictionService.selectByTime(time1);
|
||||
List<WeatherPredoctionVo> weather2 = iWeatherPredictionService.selectByTime(time2);
|
||||
for (WeatherPredoctionVo weatherPredoctopnVo : weather1) {
|
||||
if (weatherPredoctopnVo != null) {
|
||||
weatherPredoctopnVo.setWeatherTime(time1);
|
||||
String windSpeed = String.format("%.2f", Double.parseDouble(weatherPredoctopnVo.getWindSpeed()));
|
||||
String precipitation = String.format("%.2f", Double.parseDouble(weatherPredoctopnVo.getPrecipitation()));
|
||||
weatherPredoctopnVo.setWindSpeed(windSpeed);
|
||||
weatherPredoctopnVo.setPrecipitation(precipitation);
|
||||
}
|
||||
}
|
||||
for (WeatherPredoctionVo weatherPredoctopnVo : weather2) {
|
||||
if (weatherPredoctopnVo != null) {
|
||||
weatherPredoctopnVo.setWeatherTime(time2);
|
||||
String windSpeed = String.format("%.2f", Double.parseDouble(weatherPredoctopnVo.getWindSpeed()));
|
||||
String precipitation = String.format("%.2f", Double.parseDouble(weatherPredoctopnVo.getPrecipitation()));
|
||||
weatherPredoctopnVo.setWindSpeed(windSpeed);
|
||||
weatherPredoctopnVo.setPrecipitation(precipitation);
|
||||
}
|
||||
}
|
||||
List<WeatherPredoctionVo> list = new ArrayList<>();
|
||||
list.addAll(weather1);
|
||||
list.addAll(weather2);
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 定时查询更新天气数据
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
// @Scheduled(cron = "0 0 8,12,20 * * ?")
|
||||
@Scheduled(fixedDelay = 60 * 60 * 1000)
|
||||
public List<WeatherPredictionEntity> getWeather() throws IOException {
|
||||
List<WeatherPredictionEntity> weatherList = iWeatherPredictionService.getWeather();
|
||||
iWeatherPredictionService.insertBatch(weatherList);
|
||||
logger.info("每小时更新博兴天气数据");
|
||||
return weatherList;
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 生产厂家信息Controller
|
||||
*
|
||||
*
|
||||
* @author my
|
||||
* @date 2023-04-18
|
||||
*/
|
||||
|
@ -133,8 +133,9 @@ 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'
|
||||
# group1Upload: '192.168.2.20:4096/group1/upload'
|
||||
deviceSense: 'http://admin.nonghaiiot.com/app/queryDataByPropertyAll'
|
||||
machine: 'http://api.nonghaiiot.com/api/device/getFertigationProperty.zzdy'
|
||||
|
||||
geoserver:
|
||||
url: 'http://192.168.2.20:9080/geoserver'
|
||||
@ -148,6 +149,12 @@ path:
|
||||
|
||||
Meteorological:
|
||||
url: 'https://apis.juhe.cn/fapig/alarm/queryV2'
|
||||
# key: 'f072a23affd5551ecd9ae3a98d703b1c'
|
||||
key : '123'
|
||||
key: 'f072a23affd5551ecd9ae3a98d703b1c'
|
||||
code: '150700'
|
||||
|
||||
FarmMachinery:
|
||||
vehicleList: 'https://www.amtiot.cn/amapi/jzzy/VehicleList/query'
|
||||
vehiclePos: 'https://www.amtiot.cn/amapi/jzzy/VehiclePos/query'
|
||||
vehicleTrack: 'https://www.amtiot.cn/amapi/jzzy/VehicleTrack/query'
|
||||
vehicleJobData: 'https://www.amtiot.cn/amapi/jzzy/VehicleJobData/query'
|
||||
clienttoken: 'Ts7kePaCiWg+VRMrDkbdFnsY3TX0OaYckpC3eMV0Rvu01cuP9xeSBxbJYR5DnXUn1injVF36EopkBCiXYqteGpz1U/RpD2xs1vNoRenHE7tIPL0FK9gRTeLQCJm+d1AcH6uQBEmG+YiDrvanBSTnzdu2O61ZENEu4LZVQPZNsOENQfB8CRGvk1y9BKdf9uTj4d8Oaxwq4kpHegQSHReR9nylunAO1dN7NuX1mSzZ0sSyNcf43Nsrl/EMAJmA2V5lu2aSPZ455wmCbC7n2BSydRQp76thforrYM4SMKQ2i7u215e9S/A9Ll5syzyykwnkVlk2vfy9+U3fgG5ySeu6ITvkaLrk8tw3pI/sSWlajR9vyluJXmUlvgFeXfjSlcL6XfQcoSc5LaERZhn9e0GIczfpNDGrjvQgFgWB3E0y6WH5vU3Lr5AofbDnMceuY7wYefVcOtr+EOTB7f2p8aCPxZXWkSiN+WFWpuzLXCOkr1shAgMfGFARxHN/Zp8ABgc3aweVO29BFiv7PGgEc7mJ/w'
|
||||
|
@ -1,77 +1,100 @@
|
||||
package com.ruoyi.web;
|
||||
|
||||
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 com.ruoyi.common.utils.ShapeUtil;
|
||||
import com.ruoyi.crops.domain.WarningFarm;
|
||||
|
||||
import com.ruoyi.crops.service.*;
|
||||
|
||||
import org.geotools.geometry.jts.JTSFactoryFinder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.locationtech.jts.geom.Geometry;
|
||||
import org.locationtech.jts.io.ParseException;
|
||||
import org.locationtech.jts.io.WKTReader;
|
||||
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;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SpringBootTest
|
||||
public class PssTest {
|
||||
|
||||
@Value("${geoserver.url}")
|
||||
@Value("${url.machine}")
|
||||
private String url;
|
||||
@Value("${geoserver.username}")
|
||||
private String username;
|
||||
@Value("${geoserver.password}")
|
||||
private String password;
|
||||
@Autowired
|
||||
private IWeatherPredictionService iWeatherPredictionService;
|
||||
@Autowired
|
||||
private IDataAcquisitionService iDataAcquisitionService;
|
||||
|
||||
@Autowired
|
||||
private IWarningService iWarningService;
|
||||
private IMapDrawPolygonService iMapDrawPolygonService;
|
||||
@Autowired
|
||||
private IFarmMachineryService iFarmMachineryService;
|
||||
|
||||
@Autowired
|
||||
private IWarningFarmService iWarningFarmService;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
// publisherLayer("PJZ","zwhq_2023-05-11","zwhq","a","PJZ:zwcl_xm_2023-04-20","c",1);
|
||||
getDayBegin();
|
||||
// List<WeatherPredictionEntity> weatherPredictionEntities = weatherPredictionMapper.selectWeek();
|
||||
// WeatherPredictionEntity weatherPredictionEntity = weatherPredictionEntities.get(0);
|
||||
// String airTemperature = weatherPredictionEntity.getAirTemperature();
|
||||
|
||||
// for(int i = 0 ;i< arr.length -1; i++){
|
||||
// for(int j = 0; j<arr.length-1-i; j++){
|
||||
// if(arr[j]>arr[j+1]){
|
||||
// temp = arr[j];
|
||||
// arr[j] = arr[j+1];
|
||||
// arr[j+1] = temp;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
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();
|
||||
@Test
|
||||
public void test5() throws ParseException {
|
||||
|
||||
// List<WeatherPredictionEntity> weatherPredoction = iWeatherPredictionService.select(new SimpleDateFormat("yyyy-MM-dd").parse("2023-05-22"));
|
||||
|
||||
// weatherPredoction.sort(Comparator.comparing(WeatherPredictionEntity::getAirTemperature));
|
||||
// String maxAirTemperature = weatherPredoction.get(0).getAirTemperature();
|
||||
// String minAirTemperature = weatherPredoction.get(weatherPredoction.size()-1).getAirTemperature();
|
||||
|
||||
//比较器排序后的集合
|
||||
// Comparator<WeatherPredictionEntity> comparing = Comparator.comparing(WeatherPredictionEntity::getAirTemperature);
|
||||
// Comparator<WeatherPredictionEntity> humidity = Comparator.comparing(WeatherPredictionEntity::getHumidity);
|
||||
// Comparator<WeatherPredictionEntity> windSpeed = Comparator.comparing(WeatherPredictionEntity::getWindSpeed);
|
||||
// String maxAirTemperature = weatherPredoction.stream().max(comparing).get().getAirTemperature();
|
||||
// String minAirTemperature = weatherPredoction.stream().min(comparing).get().getAirTemperature();
|
||||
// String maxHumidity = weatherPredoction.stream().max(humidity).get().getHumidity();
|
||||
// String minHumidity = weatherPredoction.stream().min(humidity).get().getHumidity();
|
||||
// String awindSpeed = weatherPredoction.stream().(humidity).get().getWindSpeed();
|
||||
//
|
||||
// System.out.println(maxAirTemperature);
|
||||
// System.out.println(minAirTemperature);
|
||||
// System.out.println(maxHumidity);
|
||||
// System.out.println(minHumidity);
|
||||
}
|
||||
|
||||
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();
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
//图层设置
|
||||
GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
|
||||
gsFeatureTypeEncoder.setNativeName(tableName); //表名
|
||||
gsFeatureTypeEncoder.setName(layerName); // 图层名称
|
||||
gsFeatureTypeEncoder.setTitle(layerAlias);// 图层别名
|
||||
gsFeatureTypeEncoder.setSRS("EPSG:" + crsCode); //坐标系
|
||||
// String wkt = "MULTIPOLYGON ((30 20, 45 40, 10 40, 30 20), (15 5, 40 10, 10 20, 5 10, 15 5))";
|
||||
// ShapeUtil.writeShape(wkt,"MultiPolygon","D:\\ruoyi\\uploadPath\\upload\\shpFile\\lineString.shp");
|
||||
|
||||
GSLayerEncoder styleEncoder = new GSLayerEncoder(); //设置样式
|
||||
styleEncoder.setDefaultStyle(workspaceName,styleName);
|
||||
//读取shp文件
|
||||
//
|
||||
// List list = ShapeUtil.readShp("D:\\ruoyi\\uploadPath\\upload\\shpFile\\2023-06-25polygon.shp");
|
||||
// Map<String,String> map =(Map) list.get(0);
|
||||
// String wkt = map.get("wkt");
|
||||
// System.out.println(wkt);
|
||||
//
|
||||
// WKTReader wktReader = new WKTReader();
|
||||
// Geometry geometry = wktReader.read(wkt);
|
||||
// test(geometry);
|
||||
|
||||
boolean publishDBLayerResult = publisher.publishDBLayer(workspaceName, dataStoreName, gsFeatureTypeEncoder, styleEncoder);
|
||||
return publishDBLayerResult;
|
||||
// ShapeUtil.unzip("", "");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user