diff --git a/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobController.java b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobController.java new file mode 100644 index 00000000..735ed1b0 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobController.java @@ -0,0 +1,130 @@ +package com.zc.business.controller; + +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.exception.job.TaskException; +import com.zc.business.domain.DcBatchFunctionsJob; +import com.zc.business.service.IDcBatchFunctionsJobService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.quartz.SchedulerException; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +/** + * 定时任务Controller + * + * @author zhaoxianglong + */ +@Api(tags = {"定时任务"}) +@RestController +@RequestMapping("/business/dcBatchFunctionsJob") +public class DcBatchFunctionsJobController extends BaseController { + @Resource + private IDcBatchFunctionsJobService dcBatchFunctionsJobService; + + //*********************************调用功能记录增删改查****************************************** + + /** + * 分页查询列表 + * + * @param dcBatchFunctionsJob 请求参数 + * @return 分页查询结果 + */ + @ApiOperation("分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:list')") + @GetMapping("list") + public TableDataInfo listFacility(DcBatchFunctionsJob dcBatchFunctionsJob) { + return getDataTable(dcBatchFunctionsJobService.pageDcBatchFunctionsJob(dcBatchFunctionsJob)); + } + + /** + * 无分页查询列表 + * + * @param dcBatchFunctionsJob 请求参数 + * @return 查询结果 + */ + @ApiOperation("无分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("query") + public AjaxResult queryFacility(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException { + return AjaxResult.success(dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob)); + } + + /** + * 根据id查询信息 + * + * @param id id + * @return 查询结果 + */ + @ApiOperation("根据id查询信息") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("{id}") + public AjaxResult getFacility(@PathVariable String id) { + return AjaxResult.success(dcBatchFunctionsJobService.getById(id)); + } + + + /** + * 新增 + * + * @param dcBatchFunctionsJob 新增参数 + * @return 新增操作结果 + */ + @ApiOperation("新增") + @PreAuthorize("@ss.hasPermi('iot:facility:add')") + @Log(title = "新增", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult addFacility(@Valid @RequestBody DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { + return AjaxResult.success(dcBatchFunctionsJobService.addDcBatchFunctionsJob(dcBatchFunctionsJob)); + } + + /** + * 修改 + * + * @param dcBatchFunctionsJob 修改参数 + * @return 修改操作结果 + */ + @ApiOperation("修改") + @PreAuthorize("@ss.hasPermi('iot:facility:edit')") + @Log(title = "修改", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult editFacility(@Valid @RequestBody DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { + return toAjax(dcBatchFunctionsJobService.editDcBatchFunctionsJob(dcBatchFunctionsJob)); + } + + /** + * 删除 + * + * @param ids id集 + * @return 删除操作结果 + */ + @ApiOperation("删除") + @PreAuthorize("@ss.hasPermi('iot:facility:remove')") + @Log(title = "删除", businessType = BusinessType.DELETE) + @DeleteMapping("{ids}") + public AjaxResult removeFacility(@PathVariable List ids) throws SchedulerException, TaskException { + return toAjax(dcBatchFunctionsJobService.removeDcBatchFunctionsJob(ids)); + } + + /** + * 删除 + * + * @return 删除操作结果 + */ + @ApiOperation("删除") + @PreAuthorize("@ss.hasPermi('iot:facility:remove')") + @Log(title = "删除", businessType = BusinessType.DELETE) + @DeleteMapping("/time/{groupId}/{time}") + public AjaxResult deletesATaskByTime(@PathVariable String groupId, @PathVariable String time) { + return toAjax(dcBatchFunctionsJobService.deletesATaskByTime(groupId, time)); + } + +} diff --git a/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java new file mode 100644 index 00000000..a484ccd1 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/DcBatchFunctionsJobGroupController.java @@ -0,0 +1,135 @@ +package com.zc.business.controller; + +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.exception.job.TaskException; +import com.zc.business.domain.DcBatchFunctionsJobGroup; +import com.zc.business.service.IDcBatchFunctionsJobGroupService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.quartz.SchedulerException; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.List; + +/** + * 定时任务组Controller + * + * @author zhaoxianglong + */ +@Api(tags = {"定时任务组"}) +@RestController +@RequestMapping("/business/dcBatchFunctionsJobGroup") +public class DcBatchFunctionsJobGroupController extends BaseController { + @Resource + private IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService; + + //*********************************调用功能记录增删改查****************************************** + + /** + * 分页查询列表 + * + * @param dcBatchFunctionsJobGroup 请求参数 + * @return 分页查询结果 + */ + @ApiOperation("分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:list')") + @GetMapping("list") + public TableDataInfo listFacility(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + return getDataTable(dcBatchFunctionsJobGroupService.pageDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); + } + + /** + * 无分页查询列表 + * + * @param dcBatchFunctionsJobGroup 请求参数 + * @return 查询结果 + */ + @ApiOperation("无分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("query") + public AjaxResult queryFacility(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + return AjaxResult.success(dcBatchFunctionsJobGroupService.listDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); + } + + /** + * 根据id查询信息 + * + * @param id id + * @return 查询结果 + */ + @ApiOperation("根据id查询信息") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("{id}") + public AjaxResult getFacility(@PathVariable String id) { + return AjaxResult.success(dcBatchFunctionsJobGroupService.getById(id)); + } + + + /** + * 新增 + * + * @param dcBatchFunctionsJobGroup 新增参数 + * @return 新增操作结果 + */ + @ApiOperation("新增") + @PreAuthorize("@ss.hasPermi('iot:facility:add')") + @Log(title = "新增", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult addFacility(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + return AjaxResult.success(dcBatchFunctionsJobGroupService.addDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); + } + + /** + * 修改 + * + * @param dcBatchFunctionsJobGroup 修改参数 + * @return 修改操作结果 + */ + @ApiOperation("修改") + @PreAuthorize("@ss.hasPermi('iot:facility:edit')") + @Log(title = "修改", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult editFacility(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + return AjaxResult.success(dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup)); + } + + /** + * 删除 + * + * @param ids id集 + * @return 删除操作结果 + */ + @ApiOperation("删除") + @PreAuthorize("@ss.hasPermi('iot:facility:remove')") + @Log(title = "删除", businessType = BusinessType.DELETE) + @DeleteMapping("{ids}") + public AjaxResult removeFacility(@PathVariable List ids) { + return toAjax(dcBatchFunctionsJobGroupService.removeDcBatchFunctionsJobGroup(ids)); + } + + //*********************************定时任务组功能****************************************** + + + /** + * 改变状态 + * + * @param dcBatchFunctionsJobGroup 请求参数 + * @return 删除操作结果 + */ + @ApiOperation("改变状态") + @PreAuthorize("@ss.hasPermi('iot:facility:remove')") + @Log(title = "改变状态", businessType = BusinessType.DELETE) + @PostMapping("changeStatus") + public AjaxResult changeStatus(@Valid @RequestBody DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException { + return toAjax(dcBatchFunctionsJobGroupService.changeStatus(dcBatchFunctionsJobGroup)); + } + + +} diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index 5a8381f6..f18cefdd 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -12,6 +13,7 @@ import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.enums.BusinessType; import com.zc.business.constant.DeviceTypeConstants; import com.zc.business.domain.DcDevice; +import com.zc.business.interfaces.OperationLog; import com.zc.business.request.DeviceGetPropertiesOperateRequest; import com.zc.business.service.IDcDeviceService; import com.zc.common.core.httpclient.OkHttp; @@ -30,7 +32,6 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.io.IOException; -import java.lang.reflect.Field; import java.util.*; import java.util.stream.Collectors; @@ -267,12 +268,12 @@ public class DcDeviceController extends BaseController { JSONObject formatValue = JSON.parseObject(jsonObject.get("formatValue").toString()); map.put("1", formatValue.get("1")); map.put("3", formatValue.get("3")); - map.put("timestamp", formatValue.get("equipmentReportingTime") == null? "":Long.valueOf(formatValue.get("equipmentReportingTime").toString())); + map.put("timestamp", formatValue.get("equipmentReportingTime") == null ? "" : Long.valueOf(formatValue.get("equipmentReportingTime").toString())); list.add(map); }); List> newList = list.stream() - .filter(map-> !map.get("timestamp").equals("")) - .collect(Collectors.toList()); + .filter(map -> !map.get("timestamp").equals("")) + .collect(Collectors.toList()); Collections.sort(newList, new Comparator>() { @Override public int compare(Map map1, Map map2) { @@ -438,11 +439,17 @@ public class DcDeviceController extends BaseController { */ @ApiOperation("设备功能调用") @PostMapping("/functions/{deviceId}/{functionId}") + @OperationLog(operUrl = "/business/device/functions/{deviceId}/{functionId}") public AjaxResult invokedFunction( @PathVariable String deviceId, @PathVariable String functionId, @RequestBody HashMap props) throws HttpException, IOException { + return getAjaxResult(deviceId, functionId, props); + + } + + private AjaxResult getAjaxResult(String deviceId, String functionId, HashMap props) { if (!StringUtils.hasText(deviceId) || !StringUtils.hasText(functionId)) { return AjaxResult.error("设备未接入"); } @@ -463,7 +470,6 @@ public class DcDeviceController extends BaseController { } catch (Exception e) { return AjaxResult.error("请求失败"); } - } /** @@ -474,6 +480,7 @@ public class DcDeviceController extends BaseController { */ @ApiOperation("批量设备功能调用") @PostMapping("/batchFunctions") + @OperationLog(operUrl = "/business/device/batchFunctions") public AjaxResult batchInvokedFunction(@RequestBody Map props) throws HttpException, IOException, InterruptedException { ArrayList devices = (ArrayList) props.get("devices"); ArrayList functions = (ArrayList) props.get("functions"); @@ -487,7 +494,7 @@ public class DcDeviceController extends BaseController { JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; String functionId = functionJSONObject.getString("functionId"); - JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null?functionJSONObject.getJSONObject("params"):new JSONObject(); + JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); resultArray.add(getResult(device, iotDeviceId, functionId, jsonObject)); } } @@ -502,7 +509,7 @@ public class DcDeviceController extends BaseController { if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { result.put("result", broadcastController.nearCamListDistance(jsonObject)); } else { - result.put("result", invokedFunction(iotDeviceId, functionId, params)); + result.put("result", getAjaxResult(iotDeviceId, functionId, params)); } return result; } @@ -522,27 +529,14 @@ public class DcDeviceController extends BaseController { ArrayList params = (ArrayList) props.get("params"); JSONArray resultArray = new JSONArray(); for (Object param : params) { - resultArray.add(invokedFunction(deviceId, functionId, (HashMap) param)); + resultArray.add(getAjaxResult(deviceId, functionId, (HashMap) param)); } HashMap hashMap = new HashMap<>(); hashMap.put("SET", "7"); - invokedFunction(deviceId, "SETMD", hashMap); + getAjaxResult(deviceId, "SETMD", hashMap); return AjaxResult.success(resultArray); } - public HashMap objectToMap(Object obj) { - Map map = new HashMap<>(); - for (Field field : obj.getClass().getDeclaredFields()) { - try { - field.setAccessible(true); - map.put(field.getName(), field.get(obj)); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - } - return (HashMap) map; - } - /** * 查询物联设备事件数据 * @@ -610,4 +604,8 @@ public class DcDeviceController extends BaseController { @ApiParam(value="方向", name="direction", required=true) @RequestParam ("direction") String direction){ return dcDeviceService.selectNearBoard(stakeMark,direction); } + public void batchInvokedFunction(Object object) throws HttpException, IOException, InterruptedException { + Map map = new ObjectMapper().convertValue(object, Map.class); + batchInvokedFunction(map); + } } diff --git a/zc-business/src/main/java/com/zc/business/controller/DcOperLogController.java b/zc-business/src/main/java/com/zc/business/controller/DcOperLogController.java new file mode 100644 index 00000000..789580f5 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/controller/DcOperLogController.java @@ -0,0 +1,116 @@ +package com.zc.business.controller; + +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.zc.business.domain.DcOperLog; +import com.zc.business.service.IDcOperLogService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.validation.Valid; +import java.util.Date; +import java.util.List; + +/** + * 调用功能记录Controller + * + * @author zhaoxianglong + */ +@Api(tags = {"调用功能记录"}) +@RestController +@RequestMapping("/business/dcOperLog") +public class DcOperLogController extends BaseController { + @Resource + private IDcOperLogService dcOperLogService; + + //*********************************调用功能记录增删改查****************************************** + + /** + * 分页查询列表 + * + * @param dcOperLog 请求参数 + * @return 分页查询结果 + */ + @ApiOperation("分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:list')") + @GetMapping("list") + public TableDataInfo listFacility(DcOperLog dcOperLog,@RequestParam(value = "endTime", required = false)Date endTime,@RequestParam(value = "startTime", required = false)Date startTime) { + return getDataTable(dcOperLogService.pageDcOperLog(dcOperLog,endTime,startTime)); + } + + /** + * 无分页查询路网设施列表 + * + * @param dcOperLog 请求参数 + * @return 查询结果 + */ + @ApiOperation("无分页查询列表") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("query") + public AjaxResult queryFacility(DcOperLog dcOperLog, @RequestParam(value = "endTime", required = false) Date endTime, @RequestParam(value = "startTime", required = false)Date startTime) { + return AjaxResult.success(dcOperLogService.listDcOperLog(dcOperLog,endTime,startTime)); + } + + /** + * 根据id查询路网设施信息 + * + * @param id id + * @return 查询结果 + */ + @ApiOperation("根据id查询信息") + @PreAuthorize("@ss.hasPermi('iot:facility:query')") + @GetMapping("{id}") + public AjaxResult getFacility(@PathVariable String id) { + return AjaxResult.success(dcOperLogService.getById(id)); + } + + + /** + * 新增 + * + * @param dcOperLog 新增参数 + * @return 新增操作结果 + */ + @ApiOperation("新增") + @PreAuthorize("@ss.hasPermi('iot:facility:add')") + @Log(title = "新增", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult addFacility(@Valid @RequestBody DcOperLog dcOperLog) { + return toAjax(dcOperLogService.addDcOperLog(dcOperLog)); + } + + /** + * 修改 + * + * @param dcOperLog 修改参数 + * @return 修改操作结果 + */ + @ApiOperation("修改") + @PreAuthorize("@ss.hasPermi('iot:facility:edit')") + @Log(title = "修改", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult editFacility(@Valid @RequestBody DcOperLog dcOperLog) { + return toAjax(dcOperLogService.editDcOperLog(dcOperLog)); + } + + /** + * 删除 + * + * @param ids id集 + * @return 删除操作结果 + */ + @ApiOperation("删除") + @PreAuthorize("@ss.hasPermi('iot:facility:remove')") + @Log(title = "删除", businessType = BusinessType.DELETE) + @DeleteMapping("{ids}") + public AjaxResult removeFacility(@PathVariable List ids) { + return toAjax(dcOperLogService.removeDcOperLog(ids)); + } + +} diff --git a/zc-business/src/main/java/com/zc/business/controller/StatusController.java b/zc-business/src/main/java/com/zc/business/controller/StatusController.java index aab1f2c6..957be29a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/StatusController.java +++ b/zc-business/src/main/java/com/zc/business/controller/StatusController.java @@ -9,7 +9,9 @@ import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.zc.business.domain.DcDevice; +import com.zc.business.domain.DcRoadSection; import com.zc.business.domain.Status; +import com.zc.business.service.IDcRoadSectionService; import com.zc.business.service.impl.DcDeviceServiceImpl; import com.zc.business.service.impl.StatusService; import io.swagger.annotations.Api; @@ -36,6 +38,8 @@ public class StatusController extends BaseController { private DcDeviceServiceImpl dcDeviceService; @Resource private RedisCache redisCache; + @Resource + private IDcRoadSectionService dcRoadSectionService; private static final String ORDERRULE = "orderRule";//排序策略key @@ -362,8 +366,8 @@ public class StatusController extends BaseController { }else{ String[] rules = {"全部设备","高清网络枪型固定摄像机","高清网络球形摄像机","桥下高清网络球形摄像机","360°全景摄像机","180°全景摄像机", "门架式可变信息标志","雨棚可变信息标志","站前悬臂式可变信息标志","气象检测器","路段语音广播系统","护栏碰撞预警系统","毫米波雷达", - "合流区预警系统","激光疲劳唤醒","一类交通量调查站","智能行车诱导系统"}; - orderRule= Arrays.toString(rules); + "合流区预警系统","激光疲劳唤醒","一类交通量调查站","智能行车诱导系统","智能设备箱"}; + orderRule= Arrays.toString(rules).replace("[","").replace("]","").replace(" ",""); ruleMap.put("rule",orderRule); subMap.put("排序规则",ruleMap); } @@ -371,4 +375,71 @@ public class StatusController extends BaseController { } + //设备状态列表按路段 + @ApiOperation("设备状态列表按路段") + @GetMapping("/section") + public AjaxResult getSectionList() { + List> stringIntegerMap = dcDeviceService.countTheNumberOfEligibleItems(); + List dcRoadSections = dcRoadSectionService.selectDcRoadSectionList(new DcRoadSection()); + LocalDateTime todayStart = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS); + LocalDateTime currentTime = LocalDateTime.now(); + Status status = new Status(); + status.setStartTime(todayStart); + status.setTime(currentTime); + status.setUseState(1); + List listStatus = statusService.listStatusBySection(status); + //根据时间分组 + Map> map = listStatus.stream() + .collect(Collectors.groupingBy(Status -> Status.getTime().getHour())); + if (StringUtils.isEmpty(map)) { + return AjaxResult.success("暂无数据"); + } + Map> ipMap = new TreeMap<>(map); + Integer lastKey = Collections.max(ipMap.keySet()); + List lastEntry = ipMap.get(lastKey); + Map> typeMap = lastEntry.stream().filter(iteam -> iteam.getSectionId() != null).collect(Collectors.groupingBy(Status::getSectionId)); + Map> subMap = new HashMap<>(); + + dcRoadSections.forEach((key) -> { + + Map maps = new HashMap<>(); + List groupItems = typeMap.get(String.valueOf(key.getId())); + if (groupItems == null) { + //丢包率 + maps.put("lostRate", "0%"); + //在线率 + maps.put("sucessRate", "0%"); + //离线率 + maps.put("failRate", "0%"); + //已使用数量 + maps.put("sumUseState", "0"); + //总数 + maps.put("sum", stringIntegerMap.stream().filter(iteam -> Objects.equals(String.valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(0).get("number")); + subMap.put(key.getSectionName(), maps); + } else { + double lostRate = groupItems.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getLostRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + double sucessRate = groupItems.stream() + .mapToDouble(Status -> Double.parseDouble(Status.getSuccessRate().replace("%", ""))) // 去掉%,并转换为double + .average().getAsDouble(); + String failRate = String.format("%.2f", (100 - sucessRate)) + "%"; + //丢包率 + maps.put("lostRate", String.format("%.2f", lostRate) + "%"); + //在线率 + maps.put("sucessRate", String.format("%.2f", sucessRate) + "%"); + //离线率 + maps.put("failRate", failRate); + //已使用数量 + maps.put("sumUseState", String.valueOf(groupItems.size())); + //总数 + maps.put("sum", stringIntegerMap.stream().filter(iteam -> Objects.equals(String + .valueOf(iteam.get("id")), String.valueOf(key.getId()))).collect(Collectors.toList()).get(0).get("number")); + subMap.put(key.getSectionName(), maps); + } + }); + return AjaxResult.success(subMap); + } + + } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJob.java b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJob.java new file mode 100644 index 00000000..3bbb6d09 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJob.java @@ -0,0 +1,38 @@ +package com.zc.business.domain; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@ApiModel(value = "DcBatchFunctionsJob", description = "定时任务实体") +public class DcBatchFunctionsJob { + + //@TableId(value = "jobId", type = IdType.AUTO) + private Integer jobId; + @ApiModelProperty("任务组ID") + private String jobGroup; + @ApiModelProperty("调用目标字符串") + private String invokeTarget; + @ApiModelProperty("调用参数") + private String callParameter; + //@ApiModelProperty("cron执行表达式") + @TableField(exist = false) + private String cronExpression; + //@ApiModelProperty("状态") + @TableField(exist = false) + private String status; + @TableField(exist = false) + private String time; + @ApiModelProperty("创建者") + private String createBy; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("修改者") + private Date updateBy; + @ApiModelProperty("修改时间") + private Date updateTime; +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java new file mode 100644 index 00000000..1945506a --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcBatchFunctionsJobGroup.java @@ -0,0 +1,33 @@ +package com.zc.business.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@ApiModel(value = "DcBatchFunctionsJobGroup", description = "定时任务组实体") +public class DcBatchFunctionsJobGroup { + + @TableId(value = "id", type = IdType.AUTO) + private Long id; + @ApiModelProperty("任务组名称") + private String groupName; + @ApiModelProperty("状态") + private String status; + @ApiModelProperty("详细配置") + private String detailedConfiguration; + @ApiModelProperty("备注") + private String remark; + @ApiModelProperty("创建者") + private String createBy; + @ApiModelProperty("创建时间") + private Date createTime; + @ApiModelProperty("修改者") + private Date updateBy; + @ApiModelProperty("修改时间") + private Date updateTime; +} diff --git a/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java b/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java new file mode 100644 index 00000000..dfdc4397 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java @@ -0,0 +1,42 @@ +package com.zc.business.domain; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.Date; + +@Data +@ApiModel(value = "DcOperLog", description = "调用功能记录实体") +public class DcOperLog { + + @TableId(value = "id", type = IdType.AUTO) + private String id; + @ApiModelProperty("设备ID") + private String dcDeviceId; + @ApiModelProperty("设备类型") + private String dcDeviceType; + @ApiModelProperty("设备名称") + private String dcDeviceName; + @ApiModelProperty("操作人员") + private String operName; + @ApiModelProperty("部门名称") + private String deptName; + @ApiModelProperty("操作类型") + private String operType; + @ApiModelProperty("主机地址") + private String operIp; + @ApiModelProperty("操作地点") + private String operLocation; + @ApiModelProperty("请求参数") + private String operParam; + @ApiModelProperty("返回参数") + private String jsonResult; + @ApiModelProperty("操作状态") + private Integer status; + @ApiModelProperty("操作时间") + private Date operTime; + +} diff --git a/zc-business/src/main/java/com/zc/business/domain/Status.java b/zc-business/src/main/java/com/zc/business/domain/Status.java index 5e7c74e7..b1e8c7fe 100644 --- a/zc-business/src/main/java/com/zc/business/domain/Status.java +++ b/zc-business/src/main/java/com/zc/business/domain/Status.java @@ -22,11 +22,12 @@ public class Status { return startTime; } - public Status(long id, String deviceNo, String deviceName, String deviceStatus, LocalDateTime time, LocalDateTime startTime, String deviceIp, String successRate, String lostRate, String direction, String production, String model, String network, String content, String type) { + public Status(long id, String deviceNo, String deviceName, String deviceStatus, String sectionId, LocalDateTime time, LocalDateTime startTime, String deviceIp, String successRate, String lostRate, String direction, String production, String model, String network, String content, String type) { this.id = id; this.deviceNo = deviceNo; this.deviceName = deviceName; this.deviceStatus = deviceStatus; + this.sectionId = sectionId; this.time = time; this.startTime = startTime; this.deviceIp = deviceIp; @@ -123,6 +124,8 @@ public class Status { private Long deviceId; + + private String sectionId; @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern ="yyyy-MM-dd HH:mm:ss") @Excel(name = "监测时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") @@ -237,4 +240,12 @@ public class Status { public void setUseState(Integer useState) { this.useState = useState; } + + public String getSectionId() { + return sectionId; + } + + public void setSectionId(String sectionId) { + this.sectionId = sectionId; + } } diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLog.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLog.java new file mode 100644 index 00000000..4ab5a291 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/interfaces/OperationLog.java @@ -0,0 +1,15 @@ + +package com.zc.business.interfaces; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface OperationLog { + //String value() default ""; + + String operUrl(); +} diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java new file mode 100644 index 00000000..83e5ad1f --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java @@ -0,0 +1,136 @@ +package com.zc.business.interfaces; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.ip.IpUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.service.ISysDeptService; +import com.zc.business.domain.DcDevice; +import com.zc.business.domain.DcOperLog; +import com.zc.business.service.IDcDeviceService; +import com.zc.business.service.IDcOperLogService; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.*; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import java.util.*; + +@Aspect +@Component +public class OperationLogAspect { + + @AfterReturning(pointcut = "@annotation(operationLog)", returning = "jsonResult") + public void AfterReturning(JoinPoint joinPoint, OperationLog operationLog, Object jsonResult) throws Throwable { + System.out.println("运行成功"); + around((ProceedingJoinPoint) joinPoint, operationLog, "0", jsonResult, null); + } + + @AfterThrowing(value = "@annotation(operationLog)", throwing = "e") + public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable { + System.out.println("运行失败"); + around((ProceedingJoinPoint) joinPoint, operationLog, "1", null, e); + } + + public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable { + + ISysDeptService deptService = SpringUtils.getBean(ISysDeptService.class); + IDcOperLogService dcOperLogService = SpringUtils.getBean(IDcOperLogService.class); + IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); + + try { + DcOperLog dcOperLog = new DcOperLog(); + String operUrl = operationLog.operUrl(); + LoginUser loginUser; + try { + + loginUser = SecurityUtils.getLoginUser(); + }catch (Exception e){ + loginUser = null; + } + Object[] pointArgs = joinPoint.getArgs(); + + HttpServletRequest request; + try { + + request = ServletUtils.getRequest(); + }catch (Exception e){ + request = null; + } + if (operUrl.contains("batchFunctions")) { + if (loginUser != null) { + SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + + dcOperLog.setOperName(loginUser.getUsername()); + dcOperLog.setDeptName(sysDept.getDeptName()); + dcOperLog.setOperLocation(loginUser.getLoginLocation()); + } + dcOperLog.setOperType("2"); + dcOperLog.setOperIp(IpUtils.getIpAddr(request)); + dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs))); + dcOperLog.setOperTime(new Date()); + + + HashMap> pointArg = (HashMap>) pointArgs[0]; + ArrayList devices = pointArg.get("devices"); + ArrayList functions = pointArg.get("functions"); + for (Object dev : devices) { + JSONObject device = (JSONObject) JSON.toJSON(dev); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcDevice::getId, device.get("id")); + List list = dcDeviceService.list(lambdaQueryWrapper); + if (list.size() > 0) { + DcDevice dcDevice = list.get(0); + dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); + dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); + dcOperLog.setDcDeviceType(dcDevice.getDeviceType()); + } + for (Object fun : functions) { + JSONObject function = (JSONObject) JSON.toJSON(fun); + dcOperLog.setOperParam(function.getString("params")); + dcOperLogService.addDcOperLog(dcOperLog); + } + } + } else if (operUrl.contains("functions")) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]); + List list = dcDeviceService.list(lambdaQueryWrapper); + if (list.size() > 0) { + DcDevice dcDevice = list.get(0); + dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); + dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); + dcOperLog.setDcDeviceType(dcDevice.getDeviceType()); + } + if (loginUser != null) { + SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + + dcOperLog.setOperName(loginUser.getUsername()); + dcOperLog.setDeptName(sysDept.getDeptName()); + dcOperLog.setOperLocation(loginUser.getLoginLocation()); + dcOperLog.setOperType("0"); + } else { + dcOperLog.setOperType("1"); + } + dcOperLog.setOperIp(IpUtils.getIpAddr(request)); + dcOperLog.setOperParam(Arrays.toString(joinPoint.getArgs())); + dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs))); + if (Objects.equals(state, "0")) { + dcOperLog.setStatus(0); + } else { + dcOperLog.setStatus(1); + } + dcOperLog.setOperTime(new Date()); + dcOperLogService.addDcOperLog(dcOperLog); + } + + } catch (Exception e) { + throw e; + } + } +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobGroupMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobGroupMapper.java new file mode 100644 index 00000000..e8907d19 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobGroupMapper.java @@ -0,0 +1,14 @@ +package com.zc.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcBatchFunctionsJobGroup; +import org.apache.ibatis.annotations.Mapper; + +/** + * 定时任务组Mapper接口 + * + * @author zhaoxianglong + */ +@Mapper +public interface DcBatchFunctionsJobGroupMapper extends BaseMapper { +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobMapper.java new file mode 100644 index 00000000..b59e9ae5 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DcBatchFunctionsJobMapper.java @@ -0,0 +1,14 @@ +package com.zc.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcBatchFunctionsJob; +import org.apache.ibatis.annotations.Mapper; + +/** + * 定时任务Mapper接口 + * + * @author zhaoxianglong + */ +@Mapper +public interface DcBatchFunctionsJobMapper extends BaseMapper { +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java index 83ec034d..86c480c9 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcDeviceMapper.java @@ -23,4 +23,6 @@ public interface DcDeviceMapper extends BaseMapper { List selectNearCamPile(@Param("direction") String direction,@Param("startMileage") String startMileage,@Param("endMileage") String endMileage); List selectNearBoard(@Param("direction") String direction,@Param("startMileage") Integer startMileage,@Param("endMileage") Integer endMileage); + + List> countTheNumberOfEligibleItems(); } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcOperLogMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcOperLogMapper.java new file mode 100644 index 00000000..1e0fd980 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/mapper/DcOperLogMapper.java @@ -0,0 +1,14 @@ +package com.zc.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.zc.business.domain.DcOperLog; +import org.apache.ibatis.annotations.Mapper; + +/** + * 调用功能记录Mapper接口 + * + * @author zhaoxianglong + */ +@Mapper +public interface DcOperLogMapper extends BaseMapper { +} diff --git a/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java index 3f2a0d56..0c7838e1 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/StatusMapper.java @@ -17,6 +17,7 @@ public interface StatusMapper { int Add(@Param("status")Status status); List listStatus(@Param("status")Status status); + List listStatusBySection(@Param("status")Status status); List export(@Param("status")Status status); List deviceStatusListById(@Param("status")Status status); diff --git a/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java new file mode 100644 index 00000000..9dda4855 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobGroupService.java @@ -0,0 +1,53 @@ +package com.zc.business.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.common.exception.job.TaskException; +import com.zc.business.domain.DcBatchFunctionsJobGroup; +import org.quartz.SchedulerException; + +import java.util.List; + +/** + * 定时任务组Service接口 + * + * @author zhaoxianglong + */ +public interface IDcBatchFunctionsJobGroupService extends IService { + /** + * 添加信息 + * + * @return 操作结果 + */ + DcBatchFunctionsJobGroup addDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); + + /** + * 修改信息 + * + * @return 操作结果 + */ + DcBatchFunctionsJobGroup editDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); + + /** + * 删除 + * + * @return 操作结果 + */ + boolean removeDcBatchFunctionsJobGroup(List ids); + + /** + * 获取列表 + * + * @return 结果 + */ + List pageDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); + + /** + * 获取列表 + * + * @return 结果 + */ + List listDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup); + + boolean changeStatus(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws SchedulerException, TaskException; +} diff --git a/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobService.java b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobService.java new file mode 100644 index 00000000..38aade19 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IDcBatchFunctionsJobService.java @@ -0,0 +1,57 @@ +package com.zc.business.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.common.exception.job.TaskException; +import com.zc.business.domain.DcBatchFunctionsJob; +import org.quartz.SchedulerException; + +import java.util.List; + +/** + * 定时任务Service接口 + * + * @author zhaoxianglong + */ +public interface IDcBatchFunctionsJobService extends IService { + + + /** + * 添加信息 + * + * @return 操作结果 + */ + DcBatchFunctionsJob addDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws TaskException, SchedulerException; + + /** + * 修改信息 + * + * @return 操作结果 + */ + boolean editDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException; + + /** + * 删除 + * + * @return 操作结果 + */ + boolean removeDcBatchFunctionsJob(List ids) throws SchedulerException, TaskException; + + /** + * 获取列表 + * + * @return 结果 + */ + List pageDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob); + + /** + * 获取列表 + * + * @return 结果 + */ + List listDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException; + + boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException; + + boolean deletesATaskByTime(String groupId, String time); +} diff --git a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java index 8e975dbc..342c1510 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcDeviceService.java @@ -96,7 +96,9 @@ public interface IDcDeviceService extends IService { List numberOfDevicesByType(); - List selectNearCamPile(String direction,String startMileage,String endMileage); + List> countTheNumberOfEligibleItems(); + + List selectNearCamPile(String direction, String startMileage, String endMileage); /** * 查询上游10公里内的情报板 diff --git a/zc-business/src/main/java/com/zc/business/service/IDcOperLogService.java b/zc-business/src/main/java/com/zc/business/service/IDcOperLogService.java new file mode 100644 index 00000000..3be2ff5d --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/IDcOperLogService.java @@ -0,0 +1,52 @@ +package com.zc.business.service; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.zc.business.domain.DcOperLog; + +import java.util.List; +import java.util.Date; + +/** + * 调用功能记录Service接口 + * + * @author zhaoxianglong + */ +public interface IDcOperLogService extends IService { + + /** + * 添加信息 + * + * @return 操作结果 + */ + boolean addDcOperLog(DcOperLog dcOperLog); + + /** + * 修改信息 + * + * @return 操作结果 + */ + boolean editDcOperLog(DcOperLog dcOperLog); + + /** + * 删除 + * + * @return 操作结果 + */ + boolean removeDcOperLog(List ids); + + /** + * 获取列表 + * + * @return 结果 + */ + List pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime); + + /** + * 获取列表 + * + * @return 结果 + */ + List listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime); + +} diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java new file mode 100644 index 00000000..46f8bc39 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobGroupServiceImpl.java @@ -0,0 +1,125 @@ +package com.zc.business.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.exception.job.TaskException; +import com.ruoyi.common.utils.PageUtils; +import com.zc.business.domain.DcBatchFunctionsJob; +import com.zc.business.domain.DcBatchFunctionsJobGroup; +import com.zc.business.mapper.DcBatchFunctionsJobGroupMapper; +import com.zc.business.service.IDcBatchFunctionsJobGroupService; +import com.zc.business.service.IDcBatchFunctionsJobService; +import org.quartz.SchedulerException; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * 定时任务组Service业务层处理 + * + * @author zhaoxianglong + */ +@Service +public class DcBatchFunctionsJobGroupServiceImpl extends ServiceImpl implements IDcBatchFunctionsJobGroupService { + + @Resource + private IDcBatchFunctionsJobService dcBatchFunctionsJobService; + + + @Override + public DcBatchFunctionsJobGroup addDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + dcBatchFunctionsJobGroup.setCreateTime(new Date()); + boolean save = save(dcBatchFunctionsJobGroup); + if (save) { + return dcBatchFunctionsJobGroup; + } + return null; + } + + @Override + public DcBatchFunctionsJobGroup editDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getId, dcBatchFunctionsJobGroup.getId()); + dcBatchFunctionsJobGroup.setUpdateTime(new Date()); + boolean update = update(dcBatchFunctionsJobGroup, lambdaQueryWrapper); + if (update) { + return dcBatchFunctionsJobGroup; + } + return null; + } + + @Override + public boolean removeDcBatchFunctionsJobGroup(List ids) { + //LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + //lambdaQueryWrapper.in(DcBatchFunctionsJob::getJobGroup, ids); + //dcBatchFunctionsJobService.remove(lambdaQueryWrapper); + //List list = dcBatchFunctionsJobService.list(); + //List collect = list.stream().filter(item -> { + // String callParameter = item.getCallParameter(); + // return true; + //}).map(DcBatchFunctionsJob::getJobId).collect(Collectors.toList()); + //dcBatchFunctionsJobService.removeByIds(collect); + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(DcBatchFunctionsJobGroup::getId, ids); + List list = list(lambdaQueryWrapper); + ArrayList arrayList = new ArrayList<>(); + list.forEach(item -> { + JSONArray detailedConfiguration = JSONArray.parseArray(item.getDetailedConfiguration()); + detailedConfiguration.forEach(ite -> { + JSONObject jsonObject = (JSONObject) ite; + JSONArray tasks = jsonObject.getJSONArray("tasks"); + tasks.forEach(it -> { + arrayList.add(String.valueOf(it)); + }); + }); + }); + dcBatchFunctionsJobService.removeByIds(arrayList); + return removeByIds(ids); + } + + @Override + public List pageDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + PageUtils.startPage(); + return list(getDcBatchFunctionsJobGroupLambdaQueryWrapper(dcBatchFunctionsJobGroup)); + } + + @Override + public List listDcBatchFunctionsJobGroup(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + return list(getDcBatchFunctionsJobGroupLambdaQueryWrapper(dcBatchFunctionsJobGroup)); + } + + private static LambdaQueryWrapper getDcBatchFunctionsJobGroupLambdaQueryWrapper(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (dcBatchFunctionsJobGroup.getId() != null) { + lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getId, dcBatchFunctionsJobGroup.getId()); + } + if (dcBatchFunctionsJobGroup.getGroupName() != null) { + lambdaQueryWrapper.like(DcBatchFunctionsJobGroup::getGroupName, dcBatchFunctionsJobGroup.getGroupName()); + } + if (dcBatchFunctionsJobGroup.getStatus() != null) { + lambdaQueryWrapper.eq(DcBatchFunctionsJobGroup::getStatus, dcBatchFunctionsJobGroup.getStatus()); + } + return lambdaQueryWrapper; + } + + @Override + public boolean changeStatus(DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup) throws TaskException, SchedulerException { + DcBatchFunctionsJob dcBatchFunctionsJob = new DcBatchFunctionsJob(); + dcBatchFunctionsJob.setJobGroup(String.valueOf(dcBatchFunctionsJobGroup.getId())); + List dcBatchFunctionsJobs = dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob); + for (DcBatchFunctionsJob batchFunctionsJob : dcBatchFunctionsJobs) { + boolean changeStatus = dcBatchFunctionsJobService.changeStatus(batchFunctionsJob, dcBatchFunctionsJobGroup.getStatus()); + if (!changeStatus) { + return false; + } + } + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup1 = editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); + return dcBatchFunctionsJobGroup1 != null; + } +} + diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobServiceImpl.java new file mode 100644 index 00000000..4be890a1 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcBatchFunctionsJobServiceImpl.java @@ -0,0 +1,257 @@ +package com.zc.business.service.impl; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.exception.job.TaskException; +import com.ruoyi.common.utils.PageUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.zc.business.domain.DcBatchFunctionsJob; +import com.zc.business.domain.DcBatchFunctionsJobGroup; +import com.zc.business.mapper.DcBatchFunctionsJobMapper; +import com.zc.business.service.IDcBatchFunctionsJobGroupService; +import com.zc.business.service.IDcBatchFunctionsJobService; +import com.zc.business.utils.ScheduleUtils; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.ThreadLocalRandom; +import java.util.stream.Collectors; + +/** + * 定时任务Service业务层处理 + * + * @author zhaoxianglong + */ +@Service +public class DcBatchFunctionsJobServiceImpl extends ServiceImpl implements IDcBatchFunctionsJobService { + + @Resource + private Scheduler scheduler; + @Resource + private IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService; + + /** + * 项目启动时,初始化定时器 主要是防止手动修改数据库导致未同步到定时任务处理(注:不能手动修改数据库ID和任务组名,否则会导致脏数据) + */ + @PostConstruct + public void init() throws TaskException, SchedulerException { + List jobList = list(); + for (DcBatchFunctionsJob job : jobList) { + createScheduleJob(job); + } + } + + private void createScheduleJob(DcBatchFunctionsJob job) throws SchedulerException, TaskException { + IDcBatchFunctionsJobGroupService dcBatchFunctionsJobGroupService = SpringUtils.getBean(IDcBatchFunctionsJobGroupService.class); + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(job.getJobGroup()); + if (dcBatchFunctionsJobGroup != null) { + JSONArray jsonArray = JSONObject.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); + for (Object o : jsonArray) { + String time = ((JSONObject) o).getString("time"); + String[] times = time.split(":"); + String cron = times[2] + " " + times[1] + " " + times[0] + " " + " * * ?"; + JSONArray tasks = ((JSONObject) o).getJSONArray("tasks"); + for (Object task : tasks) { + if (Objects.equals(String.valueOf(job.getJobId()), String.valueOf(task))) { + job.setCronExpression(cron); + job.setStatus(dcBatchFunctionsJobGroup.getStatus()); + ScheduleUtils.createScheduleJob(scheduler, job); + } + } + } + } + } + + @Override + public DcBatchFunctionsJob addDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws TaskException, SchedulerException { + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup()); + if (dcBatchFunctionsJobGroup != null) { + JSONArray detailedConfigurations = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); + String time = dcBatchFunctionsJob.getTime(); + if (time == null) { + return null; + + } + List detaileds = detailedConfigurations.stream().filter(detailed -> + Objects.equals((String) ((JSONObject) detailed).get("time"), time) + ).collect(Collectors.toList()); + Integer id = ThreadLocalRandom.current().nextInt(0, 999999999); + if (detaileds.size() > 0) { + JSONObject detailed = (JSONObject) detaileds.get(0); + JSONArray tasks = detailed.getJSONArray("tasks"); + tasks.add(id); + detailed.put("tasks", tasks); + detailedConfigurations.stream().filter(detailedConfiguration -> Objects.equals((String) ((JSONObject) detailed).get("time"), time)).map(detadetailedConfiguration -> detailed); + } else { + JSONArray tasks = new JSONArray(); + tasks.add(id); + JSONObject detailedConfiguration = new JSONObject(); + detailedConfiguration.put("time", time); + detailedConfiguration.put("tasks", tasks); + detailedConfigurations.add(detailedConfiguration); + } + dcBatchFunctionsJobGroup.setDetailedConfiguration(String.valueOf(detailedConfigurations)); + dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); + dcBatchFunctionsJob.setJobId(id); + dcBatchFunctionsJob.setCreateTime(new Date()); + createScheduleJob(dcBatchFunctionsJob); + boolean save = save(dcBatchFunctionsJob); + if (save) { + return dcBatchFunctionsJob; + } else { + return null; + } + } + return null; + } + + @Override + public boolean editDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException, TaskException { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, dcBatchFunctionsJob.getJobId()); + dcBatchFunctionsJob.setUpdateTime(new Date()); + boolean update = updateSchedulerJob(dcBatchFunctionsJob, dcBatchFunctionsJob.getJobGroup()); + if (update) { + return update(dcBatchFunctionsJob, lambdaQueryWrapper); + } + return update; + } + + + /** + * 更新任务 + * + * @param job 任务对象 + * @param jobGroup 任务组名 + */ + public boolean updateSchedulerJob(DcBatchFunctionsJob job, String jobGroup) throws SchedulerException, TaskException { + Long jobId = Long.valueOf(job.getJobId()); + // 判断是否存在 + JobKey jobKey = ScheduleUtils.getJobKey(jobId, jobGroup); + if (scheduler.checkExists(jobKey)) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.deleteJob(jobKey); + } + + createScheduleJob(job); + + return true; + } + + + @Override + public boolean removeDcBatchFunctionsJob(List ids) throws SchedulerException, TaskException { + for (String id : ids) { + DcBatchFunctionsJob job = new DcBatchFunctionsJob(); + job.setJobId(Integer.valueOf(id)); + List dcBatchFunctionsJobs = listDcBatchFunctionsJob(job); + if (dcBatchFunctionsJobs.size() == 0) { + return false; + } + DcBatchFunctionsJob dcBatchFunctionsJob = dcBatchFunctionsJobs.get(0); + ScheduleUtils.deleteJob(scheduler, dcBatchFunctionsJob); + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(dcBatchFunctionsJob.getJobGroup()); + if (dcBatchFunctionsJobGroup == null) { + return false; + } + JSONArray detailedConfigurations = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); + List detaileds = detailedConfigurations.stream().filter(detailed -> { + boolean result = false; + boolean tasks = JSONArray.parseArray(String.valueOf(((JSONObject) detailed).get("tasks"))).contains(id); + JSONObject jsonObject = (JSONObject) detailed; + JSONArray jsonArray = jsonObject.getJSONArray("tasks"); + boolean contains = jsonArray.contains(id); + for (Object o : jsonArray) { + if (Objects.equals(String.valueOf(o), id)) { + result = true; + } + } + + return result; + }).collect(Collectors.toList()); + System.out.println(detaileds); + if (detaileds.size() > 0) { + JSONObject detailed = (JSONObject) detaileds.get(0); + JSONArray tasks = detailed.getJSONArray("tasks"); + + tasks = tasks.stream() + .filter(task -> !Objects.equals(String.valueOf(task), id)) + .collect(Collectors.toCollection(JSONArray::new)); + detailed.put("tasks", tasks); + detailedConfigurations.stream().filter(detailedConfiguration -> ((JSONObject) detailed).get("time") == dcBatchFunctionsJob.getTime()).map(detadetailedConfiguration -> detailed); + dcBatchFunctionsJobGroup.setDetailedConfiguration(String.valueOf(detailedConfigurations)); + dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); + } + } + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.in(DcBatchFunctionsJob::getJobId, ids); + return remove(lambdaQueryWrapper); + //return true; + } + + @Override + public List pageDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) { + PageUtils.startPage(); + return list(getDcBatchFunctionsJobLambdaQueryWrapper(dcBatchFunctionsJob)); + } + + @Override + public List listDcBatchFunctionsJob(DcBatchFunctionsJob dcBatchFunctionsJob) throws SchedulerException { + return list(getDcBatchFunctionsJobLambdaQueryWrapper(dcBatchFunctionsJob)); + } + + private static LambdaQueryWrapper getDcBatchFunctionsJobLambdaQueryWrapper(DcBatchFunctionsJob dcBatchFunctionsJob) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (dcBatchFunctionsJob.getJobId() != null) { + lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, dcBatchFunctionsJob.getJobId()); + } + //if (dcBatchFunctionsJob.getJobName() != null) { + // lambdaQueryWrapper.like(DcBatchFunctionsJob::getJobName, dcBatchFunctionsJob.getJobName()); + //} + if (dcBatchFunctionsJob.getJobGroup() != null) { + lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobGroup, dcBatchFunctionsJob.getJobGroup()); + } + return lambdaQueryWrapper; + } + + @Override + public boolean changeStatus(DcBatchFunctionsJob dcBatchFunctionsJob, String status) throws SchedulerException, TaskException { + if (Objects.equals(status, "0")) { + scheduler.resumeJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); + } else { + scheduler.pauseJob(ScheduleUtils.getJobKey(Long.valueOf(dcBatchFunctionsJob.getJobId()), String.valueOf(dcBatchFunctionsJob.getJobGroup()))); + } + return true; + } + + @Override + public boolean deletesATaskByTime(String groupId, String time) { + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup = dcBatchFunctionsJobGroupService.getById(groupId); + JSONArray detailedConfiguration = JSONArray.parseArray(dcBatchFunctionsJobGroup.getDetailedConfiguration()); + List filter = detailedConfiguration.stream().filter(item -> Objects.equals(((JSONObject) item).getString("time"), time)).collect(Collectors.toList()); + filter.forEach(item -> { + JSONArray tasks = ((JSONObject) item).getJSONArray("tasks"); + tasks.forEach(ite -> { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcBatchFunctionsJob::getJobId, ite); + remove(lambdaQueryWrapper); + }); + detailedConfiguration.remove(item); + }); + dcBatchFunctionsJobGroup.setDetailedConfiguration(detailedConfiguration.toString()); + DcBatchFunctionsJobGroup dcBatchFunctionsJobGroup1 = dcBatchFunctionsJobGroupService.editDcBatchFunctionsJobGroup(dcBatchFunctionsJobGroup); + if (dcBatchFunctionsJobGroup1 != null) { + return true; + } else { + return false; + } + } +} + diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java index f659096d..81b00640 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcDeviceServiceImpl.java @@ -487,6 +487,12 @@ public class DcDeviceServiceImpl extends ServiceImpl i return dcDeviceMapper.numberOfDevicesByType(); } + + @Override + public List> countTheNumberOfEligibleItems() { + return dcDeviceMapper.countTheNumberOfEligibleItems(); + } + public static List castList(Object obj, Class clazz) { List result = new ArrayList(); if (obj instanceof List) { diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java index 79dc17d4..3feebbaf 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcEventServiceImpl.java @@ -1,16 +1,13 @@ package com.zc.business.service.impl; import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.system.service.ISysDeptService; -import com.sun.xml.bind.v2.TODO; import com.zc.business.domain.*; import com.zc.business.enums.EventSubclassEnum; import com.zc.business.enums.ValueConverter; @@ -21,8 +18,6 @@ import com.zc.business.service.IMiddleDatabaseService; import com.zc.business.utils.diff.Diff; import com.zc.business.utils.diff.model.Result; import com.zc.common.core.websocket.WebSocketService; -import org.junit.Test; -import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -85,6 +80,7 @@ public class DcEventServiceImpl extends ServiceImpl impl private final String HAPPEN = "发生"; private final String EVENT = "事件"; private final String SUBEVENT = "0"; + /** * 查询事件信息 * @@ -138,8 +134,7 @@ public class DcEventServiceImpl extends ServiceImpl impl @Override public int insertDcEvent(DcEvent dcEvent) { - String dcEventId =dcEvent.getId(); - + String dcEventId = dcEvent.getId(); //获取事件类型 @@ -152,46 +147,46 @@ public class DcEventServiceImpl extends ServiceImpl impl //获取部门信息 dcEvent.setDeptId(SecurityUtils.getDeptId()); //用户 - dcEvent.setUserId(SecurityUtils.getUserId()); + dcEvent.setUserId(SecurityUtils.getUserId()); dcEvent.setCreateTime(DateUtils.getNowDate()); //处理无桩号事件 //交通事故 - if (eventType ==1&& dcEvent.getDcEventAccident().getFacilityId() != null) { + if (eventType == 1 && dcEvent.getDcEventAccident().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventAccident().getFacilityId()); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } //车辆事故 - if (eventType ==2 && dcEvent.getDcEventVehicleAccident().getFacilityId() != null) { + if (eventType == 2 && dcEvent.getDcEventVehicleAccident().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventVehicleAccident().getFacilityId()); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } //交通管制 - if (eventType ==3 && dcEvent.getDcEventTrafficControl().getFacilityIds() != null) { + if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityIds() != null) { String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } //交通拥堵 - if (eventType ==4 && dcEvent.getDcEventTrafficCongestion().getFacilityId() != null) { + if (eventType == 4 && dcEvent.getDcEventTrafficCongestion().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventTrafficCongestion().getFacilityId()); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } //施工建设 - if ( eventType ==7&& dcEvent.getDcEventConstruction().getFacilityId() != null) { + if (eventType == 7 && dcEvent.getDcEventConstruction().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventConstruction().getFacilityId()); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } //服务区异常 - if (eventType ==8 && dcEvent.getDcEventServiceArea().getFacilityId() != null) { + if (eventType == 8 && dcEvent.getDcEventServiceArea().getFacilityId() != null) { String facilityId = String.valueOf(dcEvent.getDcEventServiceArea().getFacilityId()); - dcEvent.setStakeMark( extracted(facilityId)); + dcEvent.setStakeMark(extracted(facilityId)); } int i7 = dcEventMapper.insertDcEvent(dcEvent); - if (i7>0 && eventType != 3){ + if (i7 > 0 && eventType != 3) { extracted(dcEvent);//事件推送到 首页 } if (i7 > 0) { @@ -222,137 +217,137 @@ public class DcEventServiceImpl extends ServiceImpl impl case 3: if (dcEvent.getDcEventTrafficControl() != null) { //TODO 插入多个收费站 - if (dcEvent.getDcEventTrafficControl().getFacilityIds().length==1){//facilityIds==1 说明只选择了一个收费站 - - if (dcEventId !=null){//不等于空 事件处置页面 修改 - dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 - DcEvent dcEvent1 = new DcEvent(); - dcEvent1.setId(dcEventId);//事件id - dcEvent1.setEventNature(1l);//首发事件 - dcEvent1.setLinkId(uuid);//关联管制事件id - dcEventMapper.updateDcEventLinkId(dcEvent1);//修改事件性质 - dcEvent.getDcEventTrafficControl().setId(uuid); - dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]);//取出数组字段赋值 设施id - int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl());// - }else { - extracted(dcEvent);//事件推送到 首页 - - dcEvent.getDcEventTrafficControl().setId(uuid); - dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]);//取出数组字段赋值 设施id - int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); - } - - }else if (dcEvent.getDcEventTrafficControl().getFacilityIds().length>1){//facilityIds1=1 说明只选择了多个收费站 - - if (dcEventId !=null){//不等于空 事件处置页面 修改 - dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 - DcEvent dcEvent1 = new DcEvent(); - dcEvent1.setId(dcEventId);//事件id - dcEvent1.setEventNature(1l);//首发事件 - Map map = new HashMap<>(); - for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { //设置事件Id UUID无下划线格式32 - String facilityUUID = IdUtils.fastSimpleUUID(); - map.put("facilityId"+i,facilityUUID);//每循环一次生成一个uuid - } - StringBuilder sb2 = new StringBuilder(); - // 遍历map, - int a = 0; - for (Map.Entry entry : map.entrySet()) { - sb2.append(entry.getValue()); - if (dcEvent.getDcEventTrafficControl().getFacilityIds().length-a !=1){ - sb2.append(","); - } - a++; - } - String linkId2 = sb2.toString(); - dcEvent1.setLinkId(linkId2);//关联管制事件id - dcEventMapper.updateDcEventLinkId(dcEvent1);//修改事件性质 - for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { - dcEvent.getDcEventTrafficControl().setId(map.get("facilityId"+i));//交通管制事件id - dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]);//取出数组字段赋值 设施id - // 使用StringBuilder来构建逗号分隔的字符串 - - //新增第一条数据 - dcEvent.setId(map.get("facilityId" + i)); - dcEvent.setEventState(0L); - dcEvent.setDeptId(SecurityUtils.getDeptId()); - dcEvent.setUserId(SecurityUtils.getUserId()); - dcEvent.setCreateTime(DateUtils.getNowDate()); - dcEvent.setEventNature(2L);//关联管制 - - StringBuilder sb = new StringBuilder(); - // 遍历map,排除与当前索引i对应的键 - for (Map.Entry entry : map.entrySet()) { - if (!entry.getKey().equals("facilityId" + i)) { - if (sb.length() > 0) { - sb.append(","); - } - sb.append(entry.getValue()); - } - } - String linkId = sb.toString(); - dcEvent.setLinkId(linkId); - - //交通管制 - if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityIds()[i] != null) { - String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]); - dcEvent.setStakeMark(extracted(facilityId)); - } - dcEventMapper.insertDcEvent(dcEvent); - - int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); - - } - }else { - - dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 - Map map = new HashMap<>(); - for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { //设置事件Id UUID无下划线格式32 - String facilityUUID = IdUtils.fastSimpleUUID(); - map.put("facilityId"+i,facilityUUID);//每循环一次生成一个uuid - } - for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { - - dcEvent.getDcEventTrafficControl().setId(map.get("facilityId" + i));//交通管制事件id - dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]);//取出数组字段赋值 设施id - - //新增第一条数据 - dcEvent.setId(map.get("facilityId" + i)); - dcEvent.setEventState(0L); - dcEvent.setDeptId(SecurityUtils.getDeptId()); - dcEvent.setUserId(SecurityUtils.getUserId()); - dcEvent.setCreateTime(DateUtils.getNowDate()); - dcEvent.setEventNature(2L);//关联管制 - - // 使用StringBuilder来构建逗号分隔的字符串 - StringBuilder sb = new StringBuilder(); - - // 遍历map,排除与当前索引i对应的键 - for (Map.Entry entry : map.entrySet()) { - if (!entry.getKey().equals("facilityId" + i)) { - if (sb.length() > 0) { - sb.append(","); - } - sb.append(entry.getValue()); - } - } - - String linkId = sb.toString(); - dcEvent.setLinkId(linkId); - System.out.println(linkId); - - //交通管制 - if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityIds()[i] != null) { - String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]); - dcEvent.setStakeMark(extracted(facilityId)); - } - - dcEventMapper.insertDcEvent(dcEvent); - extracted(dcEvent); - int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); - } - } - } + if (dcEvent.getDcEventTrafficControl().getFacilityIds().length == 1) {//facilityIds==1 说明只选择了一个收费站 + + if (dcEventId != null) {//不等于空 事件处置页面 修改 + dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 + DcEvent dcEvent1 = new DcEvent(); + dcEvent1.setId(dcEventId);//事件id + dcEvent1.setEventNature(1l);//首发事件 + dcEvent1.setLinkId(uuid);//关联管制事件id + dcEventMapper.updateDcEventLinkId(dcEvent1);//修改事件性质 + dcEvent.getDcEventTrafficControl().setId(uuid); + dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]);//取出数组字段赋值 设施id + int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl());// + } else { + extracted(dcEvent);//事件推送到 首页 + + dcEvent.getDcEventTrafficControl().setId(uuid); + dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[0]);//取出数组字段赋值 设施id + int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); + } + + } else if (dcEvent.getDcEventTrafficControl().getFacilityIds().length > 1) {//facilityIds1=1 说明只选择了多个收费站 + + if (dcEventId != null) {//不等于空 事件处置页面 修改 + dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 + DcEvent dcEvent1 = new DcEvent(); + dcEvent1.setId(dcEventId);//事件id + dcEvent1.setEventNature(1l);//首发事件 + Map map = new HashMap<>(); + for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { //设置事件Id UUID无下划线格式32 + String facilityUUID = IdUtils.fastSimpleUUID(); + map.put("facilityId" + i, facilityUUID);//每循环一次生成一个uuid + } + StringBuilder sb2 = new StringBuilder(); + // 遍历map, + int a = 0; + for (Map.Entry entry : map.entrySet()) { + sb2.append(entry.getValue()); + if (dcEvent.getDcEventTrafficControl().getFacilityIds().length - a != 1) { + sb2.append(","); + } + a++; + } + String linkId2 = sb2.toString(); + dcEvent1.setLinkId(linkId2);//关联管制事件id + dcEventMapper.updateDcEventLinkId(dcEvent1);//修改事件性质 + for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { + dcEvent.getDcEventTrafficControl().setId(map.get("facilityId" + i));//交通管制事件id + dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]);//取出数组字段赋值 设施id + // 使用StringBuilder来构建逗号分隔的字符串 + + //新增第一条数据 + dcEvent.setId(map.get("facilityId" + i)); + dcEvent.setEventState(0L); + dcEvent.setDeptId(SecurityUtils.getDeptId()); + dcEvent.setUserId(SecurityUtils.getUserId()); + dcEvent.setCreateTime(DateUtils.getNowDate()); + dcEvent.setEventNature(2L);//关联管制 + + StringBuilder sb = new StringBuilder(); + // 遍历map,排除与当前索引i对应的键 + for (Map.Entry entry : map.entrySet()) { + if (!entry.getKey().equals("facilityId" + i)) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(entry.getValue()); + } + } + String linkId = sb.toString(); + dcEvent.setLinkId(linkId); + + //交通管制 + if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityIds()[i] != null) { + String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]); + dcEvent.setStakeMark(extracted(facilityId)); + } + dcEventMapper.insertDcEvent(dcEvent); + + int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); + + } + } else { + + dcEventMapper.deleteDcEventById(uuid);//删除添加的事件主类 + Map map = new HashMap<>(); + for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { //设置事件Id UUID无下划线格式32 + String facilityUUID = IdUtils.fastSimpleUUID(); + map.put("facilityId" + i, facilityUUID);//每循环一次生成一个uuid + } + for (int i = 0; i < dcEvent.getDcEventTrafficControl().getFacilityIds().length; i++) { + + dcEvent.getDcEventTrafficControl().setId(map.get("facilityId" + i));//交通管制事件id + dcEvent.getDcEventTrafficControl().setFacilityId(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]);//取出数组字段赋值 设施id + + //新增第一条数据 + dcEvent.setId(map.get("facilityId" + i)); + dcEvent.setEventState(0L); + dcEvent.setDeptId(SecurityUtils.getDeptId()); + dcEvent.setUserId(SecurityUtils.getUserId()); + dcEvent.setCreateTime(DateUtils.getNowDate()); + dcEvent.setEventNature(2L);//关联管制 + + // 使用StringBuilder来构建逗号分隔的字符串 + StringBuilder sb = new StringBuilder(); + + // 遍历map,排除与当前索引i对应的键 + for (Map.Entry entry : map.entrySet()) { + if (!entry.getKey().equals("facilityId" + i)) { + if (sb.length() > 0) { + sb.append(","); + } + sb.append(entry.getValue()); + } + } + + String linkId = sb.toString(); + dcEvent.setLinkId(linkId); + System.out.println(linkId); + + //交通管制 + if (eventType == 3 && dcEvent.getDcEventTrafficControl().getFacilityIds()[i] != null) { + String facilityId = String.valueOf(dcEvent.getDcEventTrafficControl().getFacilityIds()[i]); + dcEvent.setStakeMark(extracted(facilityId)); + } + + dcEventMapper.insertDcEvent(dcEvent); + extracted(dcEvent); + int i6 = dcEventTrafficControlMapper.insertDcEventTrafficControl(dcEvent.getDcEventTrafficControl()); + } + } + } } break; @@ -411,26 +406,27 @@ public class DcEventServiceImpl extends ServiceImpl impl /** * 推送 事件信息 + * * @param dcEvent */ private void extracted(DcEvent dcEvent) { String direction = "";// 方向 String EventSubclass = "";// 事件类型 if (dcEvent.getDirection().equals("1")) { - direction="菏泽方向"; - }else { - direction="济南方向"; + direction = "菏泽方向"; + } else { + direction = "济南方向"; } for (EventSubclassEnum eventSubclass : EventSubclassEnum.values()) { if (eventSubclass.getCode().equals(dcEvent.getEventSubclass())) { - EventSubclass=eventSubclass.getInfo(); + EventSubclass = eventSubclass.getInfo(); break; } } - String content= direction+" " + dcEvent.getStakeMark()+" "+HAPPEN+EventSubclass+EVENT ; - Map contentMap = new HashMap<>(); - contentMap.put("content",content); - contentMap.put("event",dcEvent); + String content = direction + " " + dcEvent.getStakeMark() + " " + HAPPEN + EventSubclass + EVENT; + Map contentMap = new HashMap<>(); + contentMap.put("content", content); + contentMap.put("event", dcEvent); WebSocketService.broadcast(SUBEVENT, contentMap); //推送事件消息 0不是感知事件 } @@ -529,7 +525,7 @@ public class DcEventServiceImpl extends ServiceImpl impl dcEventProcess.setEventId(dcEvent.getId()); dcEventProcess.setSource(1); List processConfigList = dcProcessConfigMapper.selectDcProcessConfigByEventType(dcEvent.getEventType().intValue()); - if (processConfigList != null && processConfigList.size() > 0){ + if (processConfigList != null && processConfigList.size() > 0) { DcProcessConfig dcProcessConfig = processConfigList.get(0); dcEventProcess.setProcessType(1); dcEventProcess.setProcessId(Long.valueOf(dcProcessConfig.getNodeNode())); @@ -547,12 +543,11 @@ public class DcEventServiceImpl extends ServiceImpl impl } /** + * @param dcEventList + * @return int * @Description 批量添加事件 - * * @author liuwenge * @date 2024/3/18 8:42 - * @param dcEventList - * @return int */ @Override public boolean batchInsertDcEventWarning(List dcEventList) { @@ -639,7 +634,7 @@ public class DcEventServiceImpl extends ServiceImpl impl dcEventProcess.setEventId(dcEvent.getId()); dcEventProcess.setSource(1); List processConfigList = dcProcessConfigMapper.selectDcProcessConfigByEventType(dcEvent.getEventType().intValue()); - if (processConfigList != null && processConfigList.size() > 0){ + if (processConfigList != null && processConfigList.size() > 0) { DcProcessConfig dcProcessConfig = processConfigList.get(0); dcEventProcess.setProcessType(1); dcEventProcess.setProcessId(Long.valueOf(dcProcessConfig.getNodeNode())); @@ -667,11 +662,11 @@ public class DcEventServiceImpl extends ServiceImpl impl */ @Override public int updateDcEvent(DcEvent dcEvent) { - DcEvent oldEvent = selectEventSubclassById(dcEvent.getEventType().intValue(),dcEvent.getId()); + DcEvent oldEvent = selectEventSubclassById(dcEvent.getEventType().intValue(), dcEvent.getId()); dcEvent.setUpdateTime(DateUtils.getNowDate()); int i7 = dcEventMapper.updateDcEvent(dcEvent); if (i7 > 0) { - String context = comparisonInfo(oldEvent,dcEvent); + String context = comparisonInfo(oldEvent, dcEvent); //事件处置流程记录 DcEventProcess dcEventProcess = new DcEventProcess(); dcEventProcess.setEventId(dcEvent.getId()); @@ -739,7 +734,6 @@ public class DcEventServiceImpl extends ServiceImpl impl } - /** * 批量删除事件信息 * @@ -748,60 +742,60 @@ public class DcEventServiceImpl extends ServiceImpl impl */ @Override public int deleteDcEventByIds(String[] ids) { - int i7=-1; - for (String id : ids) { - DcEvent dcEvent = dcEventMapper.selectDcEventMainById(id); - int eventType = Math.toIntExact(dcEvent.getEventType()); - i7 = dcEventMapper.deleteDcEventById(id); + int i7 = -1; + for (String id : ids) { + DcEvent dcEvent = dcEventMapper.selectDcEventMainById(id); + int eventType = Math.toIntExact(dcEvent.getEventType()); + i7 = dcEventMapper.deleteDcEventById(id); - switch (eventType) { - //交通事故 - case 1: - int i1 = dcEventAccidentMapper.deleteDcEventAccidentById(id); - break; - //车辆事故 - case 2: - int i5 = dcEventVehicleAccidentMapper.deleteDcEventVehicleAccidentById(id); - break; - //交通管制 - case 3: - int i6 = dcEventTrafficControlMapper.deleteDcEventTrafficControlById(id); - break; - //交通拥堵 - case 4: - int i4 = dcEventTrafficCongestionMapper.deleteDcEventTrafficCongestionById(id); + switch (eventType) { + //交通事故 + case 1: + int i1 = dcEventAccidentMapper.deleteDcEventAccidentById(id); + break; + //车辆事故 + case 2: + int i5 = dcEventVehicleAccidentMapper.deleteDcEventVehicleAccidentById(id); + break; + //交通管制 + case 3: + int i6 = dcEventTrafficControlMapper.deleteDcEventTrafficControlById(id); + break; + //交通拥堵 + case 4: + int i4 = dcEventTrafficCongestionMapper.deleteDcEventTrafficCongestionById(id); - break; - //非法上路 - case 5: - break; - //路障清除 - case 6: - break; - //施工建设 - case 7: - int i2 = dcEventConstructionMapper.deleteDcEventConstructionById(id); - break; - //服务区异常 - case 8: - int i3 = dcEventServiceAreaMapper.deleteDcEventServiceAreaById(id); - break; - //设施设备隐患 - case 9: - break; - //异常天气 - case 10: - int i = dcEventAbnormalWeatherMapper.deleteDcEventAbnormalWeatherById(id); - break; - //其他事件 - case 11: - break; - // - default: - break; - } + break; + //非法上路 + case 5: + break; + //路障清除 + case 6: + break; + //施工建设 + case 7: + int i2 = dcEventConstructionMapper.deleteDcEventConstructionById(id); + break; + //服务区异常 + case 8: + int i3 = dcEventServiceAreaMapper.deleteDcEventServiceAreaById(id); + break; + //设施设备隐患 + case 9: + break; + //异常天气 + case 10: + int i = dcEventAbnormalWeatherMapper.deleteDcEventAbnormalWeatherById(id); + break; + //其他事件 + case 11: + break; + // + default: + break; } - return i7; + } + return i7; } @@ -958,9 +952,8 @@ public class DcEventServiceImpl extends ServiceImpl impl @Override public int updateDcEventState(String id, int state) { - - int i = dcEventMapper.updateDcEventState(id,state); - if (i > 0){ + int i = dcEventMapper.updateDcEventState(id, state); + if (i > 0) { DcEvent dcEvent = dcEventMapper.selectDcEventMainById(id); //中间库 @@ -972,7 +965,7 @@ public class DcEventServiceImpl extends ServiceImpl impl dcEventProcess.setEventId(dcEvent.getId()); dcEventProcess.setSource(1); List processConfigList = dcProcessConfigMapper.selectDcProcessConfigByEventType(dcEvent.getEventType().intValue()); - if (processConfigList != null && processConfigList.size() > 0){ + if (processConfigList != null && processConfigList.size() > 0) { DcProcessConfig dcProcessConfig = processConfigList.get(0); dcEventProcess.setProcessType(1); dcEventProcess.setProcessId(Long.valueOf(dcProcessConfig.getNodeNode())); @@ -998,147 +991,146 @@ public class DcEventServiceImpl extends ServiceImpl impl } /** - * @Description 事件信息比对 - * - * @author liuwenge - * @date 2024/4/10 16:24 * @param oldEvent 旧数据 * @param newEvent 新数据 * @return java.lang.String + * @Description 事件信息比对 + * @author liuwenge + * @date 2024/4/10 16:24 */ - public String comparisonInfo(DcEvent oldEvent,DcEvent newEvent){ + public String comparisonInfo(DcEvent oldEvent, DcEvent newEvent) { String context = ""; - if (oldEvent == null || newEvent == null){ + if (oldEvent == null || newEvent == null) { return context; } Diff diff = new Diff(); - List diffList = diff.diff(JSON.toJSON(oldEvent).toString(),JSON.toJSON(newEvent).toString()); + List diffList = diff.diff(JSON.toJSON(oldEvent).toString(), JSON.toJSON(newEvent).toString()); for (Result result : diffList) { - if ("ADD".equals(result.getDiffType()) || "MODIFY".equals(result.getDiffType())){ + if ("ADD".equals(result.getDiffType()) || "MODIFY".equals(result.getDiffType())) { if ("startTime".equals(result.getRightPath()) || "endTime".equals(result.getRightPath()) || "estimatedEndTime".equals(result.getRightPath()) - || "occurrenceTime".equals(result.getRightPath())){ + || "occurrenceTime".equals(result.getRightPath())) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date date = new Date(); date.setTime(Long.parseLong(result.getRight().toString())); result.setRight(df.format(date)); - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } - } else if ("direction".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("direction".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("上行"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("中"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("下行"); } - } else if ("eventState".equals(result.getRightPath())){ - if ("0".equals(result.getRight())){ + } else if ("eventState".equals(result.getRightPath())) { + if ("0".equals(result.getRight())) { result.setRight("待确认"); - } else if ("1".equals(result.getRight())){ + } else if ("1".equals(result.getRight())) { result.setRight("处理中"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("已完成"); } - } else if ("eventSource".equals(result.getRightPath())){ + } else if ("eventSource".equals(result.getRightPath())) { result.setRight(ValueConverter.eventSourceName(result.getRight().toString())); - } else if ("lang".equals(result.getRightPath())){ + } else if ("lang".equals(result.getRightPath())) { String langStr = ""; String langArr[] = result.getRight().toString().split(","); for (String lang : langArr) { - if ("1".equals(lang)){ + if ("1".equals(lang)) { langStr = langStr + "行1,"; - } else if ("2".equals(lang)){ + } else if ("2".equals(lang)) { langStr = langStr + "行2,"; - } else if ("3".equals(lang)){ + } else if ("3".equals(lang)) { langStr = langStr + "行3,"; - } else if ("4".equals(lang)){ + } else if ("4".equals(lang)) { langStr = langStr + "行4,"; - } else if ("0".equals(lang)){ + } else if ("0".equals(lang)) { langStr = langStr + "应急车道,"; } } - if (langStr.length() > 0){ - langStr = langStr.substring(0,langStr.length() -1); + if (langStr.length() > 0) { + langStr = langStr.substring(0, langStr.length() - 1); } result.setRight(langStr); - } else if ("dcEventAbnormalWeather.weatherSituation".equals(result.getRightPath())){ - if ("1-1".equals(result.getRight())){ + } else if ("dcEventAbnormalWeather.weatherSituation".equals(result.getRightPath())) { + if ("1-1".equals(result.getRight())) { result.setRight("雨雾"); - } else if ("1-2".equals(result.getRight())){ + } else if ("1-2".equals(result.getRight())) { result.setRight("雨雪"); - } else if ("1-3".equals(result.getRight())){ + } else if ("1-3".equals(result.getRight())) { result.setRight("中雨"); - } else if ("1-4".equals(result.getRight())){ + } else if ("1-4".equals(result.getRight())) { result.setRight("小雨"); - } else if ("1-5".equals(result.getRight())){ + } else if ("1-5".equals(result.getRight())) { result.setRight("大雨"); - } else if ("1-6".equals(result.getRight())){ + } else if ("1-6".equals(result.getRight())) { result.setRight("暴雨"); - } else if ("2-1".equals(result.getRight())){ + } else if ("2-1".equals(result.getRight())) { result.setRight("小雪"); - } else if ("2-2".equals(result.getRight())){ + } else if ("2-2".equals(result.getRight())) { result.setRight("中雪"); - } else if ("2-3".equals(result.getRight())){ + } else if ("2-3".equals(result.getRight())) { result.setRight("大雪"); - } else if ("2-4".equals(result.getRight())){ + } else if ("2-4".equals(result.getRight())) { result.setRight("暴雪"); - } else if ("2-5".equals(result.getRight())){ + } else if ("2-5".equals(result.getRight())) { result.setRight("大暴雪"); - } else if ("2-6".equals(result.getRight())){ + } else if ("2-6".equals(result.getRight())) { result.setRight("特大暴雪"); - } else if ("3-1".equals(result.getRight())){ + } else if ("3-1".equals(result.getRight())) { result.setRight("轻雾"); - } else if ("3-2".equals(result.getRight())){ + } else if ("3-2".equals(result.getRight())) { result.setRight("大雾"); - } else if ("3-3".equals(result.getRight())){ + } else if ("3-3".equals(result.getRight())) { result.setRight("浓雾"); - } else if ("3-4".equals(result.getRight())){ + } else if ("3-4".equals(result.getRight())) { result.setRight("强浓雾"); - } else if ("3-5".equals(result.getRight())){ + } else if ("3-5".equals(result.getRight())) { result.setRight("团雾"); } - } else if ("dcEventAbnormalWeather.emergencyLevel".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventAbnormalWeather.emergencyLevel".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("一般"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("紧急"); } - } else if ("dcEventAccident.locationType".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventAccident.locationType".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("高速主线"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("服务区"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("立交桥"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("收费站"); } - } else if ("dcEventAccident.weatherCondition".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventAccident.weatherCondition".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("晴"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("雨"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("雪"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("雾"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("其他"); } - } else if ("dcEventAccident.impactLevel".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventAccident.impactLevel".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("无"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("危化品泄漏"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("整车自燃"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("车辆复燃"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("散装人工倒货"); } } else if ("dcEventAccident.isReverseCargo".equals(result.getRightPath()) @@ -1150,199 +1142,199 @@ public class DcEventServiceImpl extends ServiceImpl impl || "dcEventVehicleAccident.congestionAhead".equals(result.getRightPath()) || "dcEventVehicleAccident.atIntersection".equals(result.getRightPath()) || "dcEventVehicleAccident.onCurve".equals(result.getRightPath()) - || "dcEventVehicleAccident.isPrivate".equals(result.getRightPath())){ - if ("0".equals(result.getRight())){ + || "dcEventVehicleAccident.isPrivate".equals(result.getRightPath())) { + if ("0".equals(result.getRight())) { result.setRight("否"); - } else if ("1".equals(result.getRight())){ + } else if ("1".equals(result.getRight())) { result.setRight("是"); } - } else if ("dcEventConstruction.controlMode".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventConstruction.controlMode".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("封闭"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("不封闭"); } - } else if ("dcEventConstruction.locationType".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventConstruction.locationType".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("单点"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("多点"); } - } else if ("dcEventConstruction.specialConstruction".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventConstruction.specialConstruction".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("专项工程施工"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("改扩建专项工程施工"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("桥梁专项工程施工"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("其他专项工程施工"); } - } else if ("dcEventConstruction.constructionMeasurement".equals(result.getRightPath())){ - if ("0".equals(result.getRight())){ + } else if ("dcEventConstruction.constructionMeasurement".equals(result.getRightPath())) { + if ("0".equals(result.getRight())) { result.setRight("无"); - } else if ("1".equals(result.getRight())){ + } else if ("1".equals(result.getRight())) { result.setRight("并道行驶"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("临时保通"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("借路侧服务区通行"); } } else if ("dcEventConstruction.exitsInlets".equals(result.getRightPath()) || "dcEventServiceArea.exitsInlets".equals(result.getRightPath()) - || "dcEventTrafficControl.exitsInlets".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + || "dcEventTrafficControl.exitsInlets".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("出口"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("入口"); } - } else if ("dcEventConstruction.trafficCondition".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventConstruction.trafficCondition".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("通行正常"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("通行受阻"); } - } else if ("dcEventServiceArea.disableFacility".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventServiceArea.disableFacility".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("卫生间"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("餐厅"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("停车场"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("加油站"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("充电桩"); } - } else if ("dcEventTrafficCongestion.congestionCause".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficCongestion.congestionCause".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("车流量大"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("交通事故"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("恶劣天气"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("施工"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("其他"); } - } else if ("dcEventTrafficCongestion.location".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficCongestion.location".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("入口"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("出口"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("入口内广场"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("出口内广场"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("外广场"); - } else if ("6".equals(result.getRight())){ + } else if ("6".equals(result.getRight())) { result.setRight("入口车道"); - } else if ("7".equals(result.getRight())){ + } else if ("7".equals(result.getRight())) { result.setRight("出口车道"); - } else if ("8".equals(result.getRight())){ + } else if ("8".equals(result.getRight())) { result.setRight("入口匝道"); - } else if ("9".equals(result.getRight())){ + } else if ("9".equals(result.getRight())) { result.setRight("出口匝道"); } } else if ("dcEventTrafficCongestion.locationType".equals(result.getRightPath()) - || "dcEventVehicleAccident.locationType".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + || "dcEventVehicleAccident.locationType".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("高速主线"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("服务区"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("立交桥"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("收费站"); } - } else if ("dcEventTrafficCongestion.weatherCondition".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficCongestion.weatherCondition".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("晴"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("雨"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("雪"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("雾"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("其他"); } - } else if ("dcEventTrafficControl.controlType".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.controlType".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("封闭"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("限行"); } - } else if ("dcEventTrafficControl.controlCause".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.controlCause".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("车流量大"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("交通事故"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("恶劣天气"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("施工"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("警备任务"); - } else if ("6".equals(result.getRight())){ + } else if ("6".equals(result.getRight())) { result.setRight("其他"); } - } else if ("dcEventTrafficControl.causeType".equals(result.getRightPath())){ - if ("3-1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.causeType".equals(result.getRightPath())) { + if ("3-1".equals(result.getRight())) { result.setRight("雨"); - } else if ("3-2".equals(result.getRight())){ + } else if ("3-2".equals(result.getRight())) { result.setRight("雪"); - } else if ("3-3".equals(result.getRight())){ + } else if ("3-3".equals(result.getRight())) { result.setRight("雾"); - } else if ("3-4".equals(result.getRight())){ + } else if ("3-4".equals(result.getRight())) { result.setRight("道路积水"); - } else if ("3-5".equals(result.getRight())){ + } else if ("3-5".equals(result.getRight())) { result.setRight("道路湿滑"); - } else if ("3-6".equals(result.getRight())){ + } else if ("3-6".equals(result.getRight())) { result.setRight("道路结冰"); - } else if ("3-7".equals(result.getRight())){ + } else if ("3-7".equals(result.getRight())) { result.setRight("沙尘暴"); - } else if ("4-1".equals(result.getRight())){ + } else if ("4-1".equals(result.getRight())) { result.setRight("专项工程施工"); - } else if ("4-2".equals(result.getRight())){ + } else if ("4-2".equals(result.getRight())) { result.setRight("改扩建工程施工"); - } else if ("4-3".equals(result.getRight())){ + } else if ("4-3".equals(result.getRight())) { result.setRight("其他施工"); } - } else if ("dcEventTrafficControl.measure".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.measure".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("临时关闭"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("限行车辆"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("限行车道"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("限行车道且限行车辆"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("间隔放行"); - } else if ("6".equals(result.getRight())){ + } else if ("6".equals(result.getRight())) { result.setRight("并道行驶"); - } else if ("7".equals(result.getRight())){ + } else if ("7".equals(result.getRight())) { result.setRight("限速"); } - } else if ("dcEventTrafficControl.classify".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.classify".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("主线关闭"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("主线限行"); - } else if ("3".equals(result.getRight())){ + } else if ("3".equals(result.getRight())) { result.setRight("主线间隔放行"); - } else if ("4".equals(result.getRight())){ + } else if ("4".equals(result.getRight())) { result.setRight("主线并道"); - } else if ("5".equals(result.getRight())){ + } else if ("5".equals(result.getRight())) { result.setRight("主线限速"); } - } else if ("dcEventTrafficControl.limitedType".equals(result.getRightPath())){ - if ("1".equals(result.getRight())){ + } else if ("dcEventTrafficControl.limitedType".equals(result.getRightPath())) { + if ("1".equals(result.getRight())) { result.setRight("只允许"); - } else if ("2".equals(result.getRight())){ + } else if ("2".equals(result.getRight())) { result.setRight("禁止"); } } @@ -1351,8 +1343,8 @@ public class DcEventServiceImpl extends ServiceImpl impl } } - if (context.length() > 0){ - context = context.substring(0,context.length() -1); + if (context.length() > 0) { + context = context.substring(0, context.length() - 1); } @@ -1361,37 +1353,35 @@ public class DcEventServiceImpl extends ServiceImpl impl /** + * @param eventId 事件id + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 查询事件流程状态 - * * @author liuwenge * @date 2024/4/11 11:19 - * @param eventId 事件id - * @return com.ruoyi.common.core.domain.AjaxResult */ @Override - public AjaxResult getProcessNode(String eventId){ - List> processNode = dcEventMapper.getProcessNode(eventId); + public AjaxResult getProcessNode(String eventId) { + List> processNode = dcEventMapper.getProcessNode(eventId); return AjaxResult.success(processNode); } /** + * @param eventId + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 解除事件 - * * @author liuwenge * @date 2024/4/11 14:13 - * @param eventId - * @return com.ruoyi.common.core.domain.AjaxResult */ @Override - public AjaxResult completeEvent(String eventId){ + public AjaxResult completeEvent(String eventId) { DcEvent dcEvent = dcEventMapper.selectDcEventById(eventId); - if (dcEvent.getEventState() != null && dcEvent.getEventState().equals(2L)){ + if (dcEvent.getEventState() != null && dcEvent.getEventState().equals(2L)) { return AjaxResult.error("事件已解除,无法进行操作!"); } boolean flag = dcEventMapper.completeEvent(eventId); - if (flag){ + if (flag) { //中间库 @@ -1400,7 +1390,7 @@ public class DcEventServiceImpl extends ServiceImpl impl mdEvent.setEventStatus(2L); middleDatabaseService.updateMiddleDatabaseEvent(mdEvent); - String datePoor = getDatePoor(new Date(),dcEvent.getStartTime()); + String datePoor = getDatePoor(new Date(), dcEvent.getStartTime()); //事件处置流程记录 DcEventProcess dcEventProcess = new DcEventProcess(); @@ -1415,18 +1405,17 @@ public class DcEventServiceImpl extends ServiceImpl impl } /** + * @param eventId + * @return com.ruoyi.common.core.domain.AjaxResult * @Description 无需清障 - * * @author liuwenge * @date 2024/4/11 14:13 - * @param eventId - * @return com.ruoyi.common.core.domain.AjaxResult */ @Override - public AjaxResult skipClear(String eventId){ + public AjaxResult skipClear(String eventId) { int i = dcEventMapper.selectClearInfo(eventId); - if (i > 0){ + if (i > 0) { return AjaxResult.error("已跳过清障,无法重复操作!"); } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java new file mode 100644 index 00000000..2bead588 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java @@ -0,0 +1,73 @@ +package com.zc.business.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.utils.PageUtils; +import com.zc.business.domain.*; +import com.zc.business.mapper.DcOperLogMapper; +import com.zc.business.service.*; +import org.springframework.stereotype.Service; + +import java.util.*; + +/** + * 调用功能记录Service业务层处理 + * + * @author zhaoxianglong + */ +@Service +public class DcOperLogServiceImpl extends ServiceImpl implements IDcOperLogService { + + @Override + public boolean addDcOperLog(DcOperLog dcOperLog) { + return save(dcOperLog); + } + + @Override + public boolean editDcOperLog(DcOperLog dcOperLog) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId()); + return update(dcOperLog, lambdaQueryWrapper); + } + + @Override + public boolean removeDcOperLog(List ids) { + return removeByIds(ids); + } + + @Override + public List pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) { + PageUtils.startPage(); + return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); + } + + @Override + public List listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime) { + return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); + } + + private static LambdaQueryWrapper getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog,Date endTime,Date startTime) { + LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); + if (dcOperLog.getId() != null) { + lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId()); + } + if (dcOperLog.getDcDeviceType() != null) { + lambdaQueryWrapper.like(DcOperLog::getDcDeviceType, dcOperLog.getDcDeviceType()); + } + if (dcOperLog.getDcDeviceName() != null) { + lambdaQueryWrapper.like(DcOperLog::getDcDeviceName, dcOperLog.getDcDeviceName()); + } + if (dcOperLog.getOperName() != null) { + lambdaQueryWrapper.like(DcOperLog::getOperName, dcOperLog.getOperName()); + } + if (dcOperLog.getDeptName() != null) { + lambdaQueryWrapper.like(DcOperLog::getDeptName, dcOperLog.getDeptName()); + } + if (endTime!=null&&startTime!=null) { + lambdaQueryWrapper.between(DcOperLog::getOperTime, startTime, endTime); + } + lambdaQueryWrapper.select(DcOperLog::getId, DcOperLog::getDcDeviceId, DcOperLog::getDcDeviceType, DcOperLog::getDcDeviceType, DcOperLog::getOperName,DcOperLog::getDeptName, DcOperLog::getOperType, DcOperLog::getOperIp, DcOperLog::getOperLocation,DcOperLog::getOperParam, DcOperLog::getJsonResult, DcOperLog::getStatus, DcOperLog::getOperTime); + return lambdaQueryWrapper; + } +} + diff --git a/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java index d490ba8f..41b01bf9 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/StatusService.java @@ -29,6 +29,10 @@ public class StatusService { List list = statusMapper.listStatus(status); return list; } + public List listStatusBySection(Status status) { + List list = statusMapper.listStatusBySection(status); + return list; + } public List export(Status status) { List list = statusMapper.export(status); return list; diff --git a/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java b/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java new file mode 100644 index 00000000..8c17d150 --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/task/ScheduledTaskSchedulingTask.java @@ -0,0 +1,36 @@ +package com.zc.business.task; + + +import com.alibaba.fastjson.JSONArray; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.zc.business.controller.DcDeviceController; +import com.zc.business.domain.DcBatchFunctionsJob; +import com.zc.business.service.impl.DcBatchFunctionsJobServiceImpl; +import com.zc.common.core.httpclient.exception.HttpException; +import org.quartz.SchedulerException; +import org.springframework.stereotype.Component; + +import java.io.IOException; + +/** + * 定时任务调度测试 + */ +@Component +public class ScheduledTaskSchedulingTask { + + + public void invokeTarget(DcBatchFunctionsJob dcBatchFunctionsJob) throws HttpException, IOException, InterruptedException, SchedulerException { + + DcBatchFunctionsJobServiceImpl dcBatchFunctionsJobService = SpringUtils.getBean(DcBatchFunctionsJobServiceImpl.class); + DcDeviceController deviceController = SpringUtils.getBean(DcDeviceController.class); + + DcBatchFunctionsJob job = dcBatchFunctionsJobService.listDcBatchFunctionsJob(dcBatchFunctionsJob).get(0); + if (job != null) { + JSONArray jsonArray = JSONArray.parseArray(job.getCallParameter()); + for (Object o : jsonArray) { + deviceController.batchInvokedFunction(o); + } + } + } + +} diff --git a/zc-business/src/main/java/com/zc/business/utils/ScheduleUtils.java b/zc-business/src/main/java/com/zc/business/utils/ScheduleUtils.java new file mode 100644 index 00000000..0db4234a --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/utils/ScheduleUtils.java @@ -0,0 +1,67 @@ +package com.zc.business.utils; + +import com.ruoyi.common.constant.ScheduleConstants; +import com.ruoyi.common.exception.job.TaskException; +import com.zc.business.domain.DcBatchFunctionsJob; +import org.quartz.*; + +/** + * 定时任务工具类 + * + * @author ruoyi + */ +public class ScheduleUtils { + + /** + * 构建任务键对象 + */ + public static JobKey getJobKey(Long jobId, String jobGroup) { + return JobKey.jobKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup); + } + + /** + * 创建定时任务 + */ + public static void createScheduleJob(Scheduler scheduler, DcBatchFunctionsJob job) throws SchedulerException, TaskException { + Class jobClass = ScheduledTaskScheduling.class; + // 构建job信息 + Long jobId = Long.valueOf(job.getJobId()); + String jobGroup = String.valueOf(job.getJobGroup()); + JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(getJobKey(jobId, jobGroup)).build(); + + // 表达式调度构建器 + CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); + cronScheduleBuilder = cronScheduleBuilder.withMisfireHandlingInstructionIgnoreMisfires(); + + // 按新的cronExpression表达式构建一个新的trigger + CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(TriggerKey.triggerKey(ScheduleConstants.TASK_CLASS_NAME + jobId, jobGroup)) + .withSchedule(cronScheduleBuilder).build(); + + // 放入参数,运行时的方法可以获取 + jobDetail.getJobDataMap().put(ScheduleConstants.TASK_PROPERTIES, job); + + // 判断是否存在 + if (scheduler.checkExists(ScheduleUtils.getJobKey(jobId, jobGroup))) { + // 防止创建时存在数据问题 先移除,然后在执行创建操作 + scheduler.deleteJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + + scheduler.scheduleJob(jobDetail, trigger); + + // 暂停任务 + if (job.getStatus().equals(ScheduleConstants.Status.PAUSE.getValue())) + { + scheduler.pauseJob(ScheduleUtils.getJobKey(jobId, jobGroup)); + } + } + + /** + * 删除定时任务 + */ + public static void deleteJob(Scheduler scheduler, DcBatchFunctionsJob job) throws SchedulerException, TaskException { + if (scheduler.checkExists(ScheduleUtils.getJobKey(Long.valueOf(job.getJobId()), String.valueOf(job.getJobGroup())))) { + scheduler.deleteJob(getJobKey(Long.valueOf(job.getJobId()), String.valueOf(job.getJobGroup()))); + } + } + +} diff --git a/zc-business/src/main/java/com/zc/business/utils/ScheduledTaskScheduling.java b/zc-business/src/main/java/com/zc/business/utils/ScheduledTaskScheduling.java new file mode 100644 index 00000000..c6c293db --- /dev/null +++ b/zc-business/src/main/java/com/zc/business/utils/ScheduledTaskScheduling.java @@ -0,0 +1,20 @@ +package com.zc.business.utils; + +import com.ruoyi.quartz.domain.SysJob; +import com.ruoyi.quartz.util.AbstractQuartzJob; +import com.zc.business.domain.DcBatchFunctionsJob; +import com.zc.business.task.ScheduledTaskSchedulingTask; +import org.quartz.JobExecutionContext; + +public class ScheduledTaskScheduling extends AbstractQuartzJob { + + + + @Override + protected void doExecute(JobExecutionContext context, SysJob sysJob) throws Exception { + ScheduledTaskSchedulingTask scheduledTaskSchedulingTask = new ScheduledTaskSchedulingTask(); + DcBatchFunctionsJob dcBatchFunctionsJob = new DcBatchFunctionsJob(); + dcBatchFunctionsJob.setJobId(Math.toIntExact(sysJob.getJobId())); + scheduledTaskSchedulingTask.invokeTarget(dcBatchFunctionsJob); + } +} diff --git a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml index 809f0bb2..a98fa87e 100644 --- a/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcDeviceMapper.xml @@ -141,5 +141,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where t1.device_type = '2' and t1.direction = #{direction} and t2.mileage >= #{startMileage} and t2.mileage <= #{endMileage} + diff --git a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml index 05c738ed..0da925e1 100644 --- a/zc-business/src/main/resources/mapper/business/DcEventMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcEventMapper.xml @@ -771,7 +771,8 @@ update dc_event event_state = #{state}, - start_time = NOW(), + start_time = NOW(), + end_time = NOW(), where id = #{id} diff --git a/zc-business/src/main/resources/mapper/business/StatusMapper.xml b/zc-business/src/main/resources/mapper/business/StatusMapper.xml index 388f6b57..d76b633f 100644 --- a/zc-business/src/main/resources/mapper/business/StatusMapper.xml +++ b/zc-business/src/main/resources/mapper/business/StatusMapper.xml @@ -147,6 +147,35 @@ + + +