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/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/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 @@ + + +