|
@@ -1,18 +1,25 @@
|
|
|
package com.sooka.sponest.lawenforcement.device.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.common.core.web.controller.BaseController;
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
|
|
import com.sooka.sponest.lawenforcement.device.domain.DeviceBO;
|
|
|
import com.sooka.sponest.lawenforcement.device.service.IDeviceService;
|
|
|
import com.sooka.sponest.lawenforcement.record.service.ILawenforcementRecordService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @author LG
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/device")
|
|
|
+@Slf4j
|
|
|
public class DeviceController extends BaseController {
|
|
|
|
|
|
@Autowired
|
|
@@ -21,43 +28,91 @@ public class DeviceController extends BaseController {
|
|
|
@Autowired
|
|
|
private IDeviceService deviceService;
|
|
|
|
|
|
+ private final String OPEN = "1";
|
|
|
+ private final String CLOSE = "0";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 实时接受设备开关机状态集合
|
|
|
+ * @param arr
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@PostMapping("/deviceOpenOrClose")
|
|
|
- public AjaxResult deviceOpenOrClose(@RequestBody DeviceBO bo){
|
|
|
- if("0".equals(bo.getStatus())){
|
|
|
- close(bo);
|
|
|
- }else if("1".equals(bo.getStatus())){
|
|
|
- open(bo);
|
|
|
- }else{
|
|
|
- return AjaxResult.error("状态异常");
|
|
|
+ public AjaxResult deviceOpenOrClose(@RequestBody String arr){
|
|
|
+ log.info("接受的执法设备参数:{}",arr);
|
|
|
+ if(StringUtils.isEmpty(arr)){
|
|
|
+ return AjaxResult.error("数据为空");
|
|
|
}
|
|
|
+ //将参数转为实体类集合
|
|
|
+ List<DeviceBO> deviceList = JSON.parseObject(arr, new TypeReference<List<DeviceBO>>(){});
|
|
|
+
|
|
|
+ //遍历设备集合,判断设备是否开机
|
|
|
+ deviceList.forEach(bo->{
|
|
|
+ //设备关机状态执行:调用单设备关机信号
|
|
|
+ if(CLOSE.equals(bo.getStatus())){
|
|
|
+ close(bo);
|
|
|
+ }
|
|
|
+ //设备开机状态执行:调用单设备开机信号
|
|
|
+ if(OPEN.equals(bo.getStatus())){
|
|
|
+ open(bo);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //返回信息
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 单设备开机信号
|
|
|
+ * @param bo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@PostMapping("/open")
|
|
|
public AjaxResult open(@RequestBody DeviceBO bo) {
|
|
|
deviceService.open(bo);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
- // 可以添加其他方法来停止定时任务,例如:
|
|
|
+ /**
|
|
|
+ * 单设备关机信号
|
|
|
+ * @param bo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("/close")
|
|
|
+ public AjaxResult close(@RequestBody DeviceBO bo){
|
|
|
+ //设备关机先尝试删除定时任务
|
|
|
+ deviceService.cancelTask(bo.getCode());
|
|
|
+ //设置任务结束时间和任务状态为完成
|
|
|
+ recordService.updateRecordLogEndTime(bo);
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动停止定时任务接口
|
|
|
+ * @param deviceCode
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@PostMapping("/stop/{deviceCode}")
|
|
|
public AjaxResult stopDevice(@PathVariable String deviceCode) {
|
|
|
deviceService.cancelTask(deviceCode);
|
|
|
return AjaxResult.success();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取已开启定时任务的设备列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@GetMapping("/getTaskList")
|
|
|
public AjaxResult getTaskList(){
|
|
|
return AjaxResult.success(deviceService.getTaskList());
|
|
|
}
|
|
|
|
|
|
- @PostMapping("/close")
|
|
|
- public AjaxResult close(@RequestBody DeviceBO bo){
|
|
|
- System.out.println(" 设备关闭 ");
|
|
|
- //设备关机先尝试删除定时任务
|
|
|
- deviceService.cancelTask(bo.getDeviceCode());
|
|
|
- //设置任务结束时间和任务状态为完成
|
|
|
- recordService.updateRecordLogEndTime(bo);
|
|
|
- return AjaxResult.success();
|
|
|
+ /**
|
|
|
+ * 获取正在执行工单任务的设备列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/getOpenedDeviceList")
|
|
|
+ public AjaxResult getOpenedDeviceList(){
|
|
|
+ return AjaxResult.success(deviceService.getTaskOpenedDevice());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|