From 63a52cf972551e04546d3f41fbaddd26014afa29 Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Fri, 28 Jun 2024 09:48:10 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 2 +- .../business/controller/ApplyController.java | 51 ++- .../controller/ApplyPlanController.java | 26 +- .../controller/ApplyPlanLogController.java | 13 + .../controller/ResourceLibraryController.java | 11 +- .../com/ruoyi/business/domain/ApplyPlan.java | 5 + .../ruoyi/business/domain/ApplyPlanLog.java | 100 +---- .../ruoyi/business/domain/vo/ListApplyVO.java | 10 + .../ruoyi/business/mapper/ApplyMapper.java | 3 +- .../business/service/IApplyPlanService.java | 12 +- .../ruoyi/business/service/IApplyService.java | 11 +- .../service/IResourceLibraryService.java | 7 + .../service/impl/ApplyPlanServiceImpl.java | 385 ++++++++++++------ .../service/impl/ApplyServiceImpl.java | 98 ++++- .../impl/ResourceLibraryServiceImpl.java | 19 + .../ruoyi/business/util/YinDaoHttpUtils.java | 2 + .../resources/mapper/business/ApplyMapper.xml | 6 +- .../mapper/business/ApplyPlanLogMapper.xml | 57 +-- .../mapper/business/ApplyPlanMapper.xml | 3 + .../ruoyi/quartz/util/AbstractQuartzJob.java | 2 +- 20 files changed, 543 insertions(+), 280 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index c832852..908e9db 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -43,7 +43,7 @@ user: # 密码最大错误次数 maxRetryCount: 5 # 密码锁定时间(默认10分钟) - lockTime: 10 + lockTime: 5 # Spring配置 spring: diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java index 5ba5797..eb1906a 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java @@ -1,10 +1,19 @@ package com.ruoyi.business.controller; +import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletResponse; import java.util.Arrays; +import java.util.stream.Collectors; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.ruoyi.business.domain.ApplyPlan; +import com.ruoyi.business.domain.ApplyPlanLog; import com.ruoyi.business.domain.Rebot; +import com.ruoyi.business.domain.vo.ListApplyVO; +import com.ruoyi.business.service.IApplyPlanLogService; +import com.ruoyi.business.service.IApplyPlanService; +import com.ruoyi.common.enums.PlanRunStatus; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -41,6 +50,22 @@ public class ApplyController extends BaseController { @Autowired private IApplyService applyService; + @Autowired + private IApplyPlanService applyPlanService; + + @Autowired + private IApplyPlanLogService applyPlanLogService; + + /** + * 同步应用数据 + */ + @ApiOperation(value = "修改应用实际执行时间", httpMethod = "POST", response = Rebot.class) + @PostMapping("/updateRunDate") + public AjaxResult updateRunDate(@RequestBody Apply apply) throws IllegalAccessException { + return toAjax(applyService.updateRunDate(apply)); + } + + /** * 同步应用数据 */ @@ -68,8 +93,24 @@ public class ApplyController extends BaseController { @ApiOperation(value = "查询应用信息管理列表", httpMethod = "GET", response = Apply.class) @GetMapping("/list") public TableDataInfo list(Apply apply) { + // 获取所有计划 + List planList = applyPlanService.lambdaQuery().isNotNull(ApplyPlan::getManualTime) + .and(e -> e.in(ApplyPlan::getExcType, "0", "1") + .eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).or().eq(ApplyPlan::getExcType, "2")) + + .list(); + // 只过滤执行计划的id + List planIdList = planList.stream().filter(e -> "2".equals(e.getExcType())).map(ApplyPlan::getId).collect(Collectors.toList()); + // 获取所有 设置了时间并且是完成状态的计划记录 + LambdaQueryChainWrapper qw = applyPlanLogService.lambdaQuery(); + List planLogList = null; + if (planIdList.isEmpty()) { + planLogList = new ArrayList<>(); + } else { + planLogList = qw.in(ApplyPlanLog::getPlanId, planIdList).isNotNull(ApplyPlanLog::getUpdateTime).list(); + } startPage(); - List list = applyService.list(apply); + List list = applyService.list(planList, planLogList, apply); return getDataTable(list); } @@ -80,8 +121,12 @@ public class ApplyController extends BaseController { @Log(title = "应用信息管理", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, Apply apply) { - List list = applyService.list(apply); - ExcelUtil util = new ExcelUtil(Apply.class); + // 获取所有执行成功的计划 + List planList = applyPlanService.lambdaQuery().eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).list(); + // 获取所有计划记录 + List planLogList = applyPlanLogService.list(); + List list = applyService.list(planList, planLogList, apply); + ExcelUtil util = new ExcelUtil(ListApplyVO.class); util.exportExcel(response, list, "应用信息管理数据"); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java index a63dffc..cb6b2fa 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanController.java @@ -1,5 +1,6 @@ package com.ruoyi.business.controller; +import java.text.ParseException; import java.util.List; import javax.servlet.http.HttpServletResponse; import java.util.Arrays; @@ -45,10 +46,7 @@ public class ApplyPlanController extends BaseController { @PostMapping("/callBack/updatePlanStatus") public void updatePlanStatus(@RequestParam(required = false) String bodyMd5, @RequestParam(required = false) Long timestamp, @RequestParam(required = false) String sign, @RequestBody String body) { - log.info("fake callback: bodyMd5:{}", bodyMd5); - log.info("fake callback: sign:{}", sign); - log.info("fake callback: timestamp:{}", timestamp); - log.info("fake callback: body:{}", body); + log.info("影刀回调成功:bodyMd5:{},sign:{},timestamp:{},body:{}", bodyMd5,sign,timestamp,body); YinDaoCallBackBO yinDaoCallBackBO = JSONObject.parseObject(body, YinDaoCallBackBO.class); // 获取应用名称 task_uuid @@ -63,6 +61,24 @@ public class ApplyPlanController extends BaseController { // } } + /** + * 修改运行时间 + */ + @ApiOperation(value = "修改运行时间", httpMethod = "POST", response = ApplyPlan.class) + @PostMapping("/updateRunTime") + public AjaxResult updateRunTime(@RequestBody ApplyPlan applyPlan) throws ParseException { + return toAjax(applyPlanService.updateRunTime(applyPlan)); + } + + /** + * 重新运行 + */ + @ApiOperation(value = "启用或禁用", httpMethod = "POST", response = ApplyPlan.class) + @PostMapping("/stopOrStart") + public AjaxResult appRetry(@RequestBody ApplyPlan applyPlan) throws IllegalAccessException { + return toAjax(applyPlanService.updateById(applyPlan)); + } + /** * 重新运行 */ @@ -120,7 +136,7 @@ public class ApplyPlanController extends BaseController { @ApiOperation(value = "新增应用执行计划管理", httpMethod = "POST") @Log(title = "应用执行计划管理", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody AddApplyPlanBO addApplyPlanBO) { + public AjaxResult add(@RequestBody AddApplyPlanBO addApplyPlanBO) throws ParseException { // 随机分配 addApplyPlanBO.setPlanType("1"); addApplyPlanBO.setWaitTimeout("10m"); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanLogController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanLogController.java index d793d3c..95ffb72 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanLogController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyPlanLogController.java @@ -40,6 +40,19 @@ public class ApplyPlanLogController extends BaseController @Autowired private IApplyPlanLogService applyPlanLogService; + /** + * 根据计划查询所有执行日志 + */ + @ApiOperation(value="根据计划查询所有执行日志", httpMethod = "GET", response = ApplyPlanLog.class) + @GetMapping("/listAll") + public AjaxResult listAll(String planId) + { + ApplyPlanLog applyPlanLog = new ApplyPlanLog(); + applyPlanLog.setPlanId(planId); + List list = applyPlanLogService.list(applyPlanLog); + return AjaxResult.success(list); + } + /** * 查询应用执行结果记录管理列表 */ diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java index 631bf09..fb01d71 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java @@ -80,7 +80,6 @@ public class ResourceLibraryController extends BaseController { List list = resourceLibraryService.list(resourceLibrary, null); return getDataTable(list); } - } /** @@ -114,6 +113,16 @@ public class ResourceLibraryController extends BaseController { return success(resourceLibraryService.getById(id)); } + /** + * 批量修改资源信息 + */ + @ApiOperation(value = "批量修改资源信息", httpMethod = "POST") + @Log(title = "批量修改资源信息", businessType = BusinessType.INSERT) + @PostMapping("/updateBatch") + public AjaxResult updateBatch(@RequestBody AddBatchResourceLibraryBO addBatchResourceLibraryBO) { + return toAjax(resourceLibraryService.updateBatch(addBatchResourceLibraryBO)); + } + /** * 批量新增资源信息 */ diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java index c40a396..9ddd617 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlan.java @@ -179,6 +179,11 @@ public class ApplyPlan extends BaseEntity @ApiModelProperty(name="deptName",value = "部门名称") private String deptName; + /** 是否启用 */ + @Excel(name = "是否启用") + @ApiModelProperty(name="enabled",value = "是否启用(0启用 1禁用)") + private String enabled; + @Override public String toString() { diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java index e0f38ad..7a8c2c8 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java @@ -37,100 +37,32 @@ public class ApplyPlanLog extends BaseEntity - /** 启动的任务的uuid */ - @Excel(name = "启动的任务的uuid") - @ApiModelProperty(name="jobUuid",value = "启动的任务的uuid") - private String jobUuid; - - /** 计划名称 */ - @Excel(name = "计划名称") - @ApiModelProperty(name="planName",value = "计划名称") - private String planName; - - - /** 执行类型(0指定机器人 1随机分配空闲) */ - @Excel(name = "执行类型", readConverterExp = "0=指定机器人,1=随机分配空闲") - @ApiModelProperty(name="planType",value = "执行类型") - private String planType; - - /** 计划执行的机器人名称 */ - @Excel(name = "计划执行的机器人名称") - @ApiModelProperty(name="robotName",value = "计划执行的机器人名称") - private String robotName; - - /** 应用类型名称 */ - @Excel(name = "应用类型名称") - @ApiModelProperty(name="appTypeName",value = "应用类型名称") - private String appTypeName; - - /** 应用名称 */ - @Excel(name = "应用名称") - @ApiModelProperty(name="appName",value = "应用名称") - private String appName; - - /** appid */ - @Excel(name = "appid") - @ApiModelProperty(name="appId",value = "appid") + /** 计划id */ + @Excel(name = "计划id") + @ApiModelProperty(name="planId",value = "计划id") + private String planId; + + /** 所属应用id */ + @Excel(name = "所属应用id") + @ApiModelProperty(name="appId",value = "所属应用id") private String appId; - /** 任务状态 */ - @Excel(name = "任务状态") - @ApiModelProperty(name="status",value = "任务状态") - private String status; - - /** 任务状态名称 */ - @Excel(name = "任务状态名称") - @ApiModelProperty(name="statusName",value = "任务状态名称") - private String statusName; - - - /** 任务开始运行的时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "任务开始运行的时间", width = 30, dateFormat = "yyyy-MM-dd") - @ApiModelProperty(name="startTime",value = "任务开始运行的时间") - private Date startTime; - - - /** 任务结束运行的时间 */ - @JsonFormat(pattern = "yyyy-MM-dd") - @Excel(name = "任务结束运行的时间", width = 30, dateFormat = "yyyy-MM-dd") - @ApiModelProperty(name="endTime",value = "任务结束运行的时间") - private Date endTime; - - /** 预计人工耗时 */ - @Excel(name = "预计人工耗时") - @ApiModelProperty(name="manualTime",value = "预计人工耗时") - private String manualTime; + /** 计划job_uuid */ + @Excel(name = "计划job_uuid") + @ApiModelProperty(name="jobUuid",value = "计划job_uuid") + private String jobUuid; - /** 实际耗时 */ - @Excel(name = "实际耗时") - @ApiModelProperty(name="planTime",value = "实际耗时") - private String planTime; - /** 节约时间 */ - @Excel(name = "节约时间") - @ApiModelProperty(name="timeSaving",value = "节约时间") - private String timeSaving; + /** 输出内容 */ + @Excel(name = "输出内容") + @ApiModelProperty(name="outParam",value = "输出内容") + private String outParam; @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) .append("id", getId()) - .append("jobUuid", getJobUuid()) - .append("planName", getPlanName()) - .append("planType", getPlanType()) - .append("robotName", getRobotName()) - .append("appTypeName", getAppTypeName()) - .append("appName", getAppName()) - .append("appId", getAppId()) - .append("status", getStatus()) - .append("statusName", getStatusName()) - .append("startTime", getStartTime()) - .append("endTime", getEndTime()) - .append("manualTime", getManualTime()) - .append("planTime", getPlanTime()) - .append("timeSaving", getTimeSaving()) .append("createBy", getCreateBy()) .append("createTime", getCreateTime()) .append("updateBy", getUpdateBy()) diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/ListApplyVO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/ListApplyVO.java index f4acf15..5a0bd30 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/ListApplyVO.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/vo/ListApplyVO.java @@ -84,10 +84,20 @@ public class ListApplyVO extends BaseEntity @Excel(name = "预计人工耗时") @ApiModelProperty(name="manualTime",value = "预计人工耗时") private String manualTime; + /** 总计节约时间 */ + @Excel(name = "总计节约时间") + @ApiModelProperty(name="timeSaving",value = "总计节约时间") + private String timeSaving; /** 所属公司 */ @Excel(name = "所属公司") @ApiModelProperty(name="deptId",value = "所属公司") private Long deptId; + + /** 部门名称 */ + @Excel(name = "部门名称") + @ApiModelProperty(name="deptName",value = "部门名称") + private String deptName; + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyMapper.java index 9047a80..bf6ad8c 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyMapper.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyMapper.java @@ -3,6 +3,7 @@ package com.ruoyi.business.mapper; import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.ruoyi.business.domain.Apply; +import com.ruoyi.business.domain.vo.ListApplyVO; /** * 应用信息管理Mapper接口 @@ -19,7 +20,7 @@ public interface ApplyMapper extends BaseMapper * @param apply 应用信息管理 * @return 应用信息管理集合 */ - List selectApplyList(Apply apply); + List selectApplyList(Apply apply); /** * 查询所有应用信息列表 diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java index 8f97fbb..515c5c1 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyPlanService.java @@ -1,5 +1,6 @@ package com.ruoyi.business.service; +import java.text.ParseException; import java.util.List; import com.ruoyi.business.domain.ApplyPlan; @@ -17,6 +18,15 @@ import com.ruoyi.business.domain.vo.JobQueryVO; * @date 2024-06-14 */ public interface IApplyPlanService extends IService { + + + /** + * 修改运行时间 + * @param applyPlan + * @return + */ + boolean updateRunTime(ApplyPlan applyPlan) throws ParseException; + /** * 影刀回调逻辑 * @@ -76,7 +86,7 @@ public interface IApplyPlanService extends IService { * @param addApplyPlanBO * @return */ - boolean save(AddApplyPlanBO addApplyPlanBO); + boolean save(AddApplyPlanBO addApplyPlanBO) throws ParseException; /** * 修改计划 diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java index e4f0929..276dcc7 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java @@ -3,11 +3,14 @@ package com.ruoyi.business.service; import java.util.List; import com.ruoyi.business.domain.Apply; import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.business.domain.ApplyPlan; +import com.ruoyi.business.domain.ApplyPlanLog; import com.ruoyi.business.domain.Rebot; import com.ruoyi.business.domain.bo.ApplyStartBO; import com.ruoyi.business.domain.bo.JobQueryBO; import com.ruoyi.business.domain.vo.JobQueryVO; import com.ruoyi.business.domain.vo.JobStartVO; +import com.ruoyi.business.domain.vo.ListApplyVO; import com.ruoyi.common.annotation.DataScope; /** @@ -39,7 +42,7 @@ public interface IApplyService extends IService * @param apply 应用信息管理 * @return 应用信息管理集合 */ - List list(Apply apply); + List list(List planList, List planLogList, Apply apply); /** * 查询所有应用信息列表 @@ -49,4 +52,10 @@ public interface IApplyService extends IService */ List listAll(Apply apply); + /** + * 修改应用实际执行时间 + * @param apply + * @return + */ + boolean updateRunDate(Apply apply); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IResourceLibraryService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IResourceLibraryService.java index aa0c62b..a59fca4 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IResourceLibraryService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IResourceLibraryService.java @@ -14,6 +14,13 @@ import com.ruoyi.business.domain.bo.AddBatchResourceLibraryBO; */ public interface IResourceLibraryService extends IService { + /** + * 批量修改参数 + * @param addBatchResourceLibraryBO + * @return + */ + boolean updateBatch(AddBatchResourceLibraryBO addBatchResourceLibraryBO); + /** * 批量添加参数 * diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 9cfe8a8..62d512b 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -1,5 +1,7 @@ package com.ruoyi.business.service.impl; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.ParseException; import java.time.ZoneId; import java.time.ZonedDateTime; @@ -11,17 +13,13 @@ import java.util.stream.Collectors; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; -import com.ruoyi.business.domain.Apply; -import com.ruoyi.business.domain.Rebot; -import com.ruoyi.business.domain.ResourceLibrary; +import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.bo.*; import com.ruoyi.business.domain.vo.JobQueryLogVO; import com.ruoyi.business.domain.vo.JobQueryVO; import com.ruoyi.business.domain.vo.JobStartVO; import com.ruoyi.business.domain.vo.ListRebotVO; -import com.ruoyi.business.service.IApplyService; -import com.ruoyi.business.service.IRebotService; -import com.ruoyi.business.service.IResourceLibraryService; +import com.ruoyi.business.service.*; import com.ruoyi.business.util.YinDaoHttpUtils; import com.ruoyi.business.yddoman.BaseDTO; import com.ruoyi.common.annotation.DataScope; @@ -42,8 +40,6 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.support.CronSequenceGenerator; import org.springframework.stereotype.Service; import com.ruoyi.business.mapper.ApplyPlanMapper; -import com.ruoyi.business.domain.ApplyPlan; -import com.ruoyi.business.service.IApplyPlanService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.transaction.annotation.Transactional; @@ -67,6 +63,47 @@ public class ApplyPlanServiceImpl extends ServiceImpl 0) { + nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 + applyPlan.setNextExecTime(nextDate); + } else { + nextDate = cron.getNextValidTimeAfter(applyPlan.getLastExecTime());//下次执行时间 + applyPlan.setNextExecTime(nextDate); + } + } + return this.updateById(applyPlan); + } + /** * 影刀回调 * @@ -74,28 +111,68 @@ public class ApplyPlanServiceImpl extends ServiceImpl finalState = new ArrayList<>(); - finalState.add(PlanRunStatus.FINISH.getKey()); - finalState.add(PlanRunStatus.STOPPED.getKey()); - finalState.add(PlanRunStatus.ERROR.getKey()); - finalState.add(PlanRunStatus.SKIPPED.getKey()); - finalState.add(PlanRunStatus.CANCEL.getKey()); - // 如果是终态 - if (StringUtils.isNotEmpty(yinDaoCallBackBO.getRobotClientName()) && finalState.contains(yinDaoCallBackBO.getStatus())) { - Rebot rebot = new Rebot(); - rebot.setStatus(RebotStatus.IDLE.getKey()); - return rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, yinDaoCallBackBO.getRobotClientName()).update(rebot); - } else { - return isUpdate; + RLock lock = redissonClient.getLock("updateResult"); + try { + // 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 + boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); + if (isLocked) { + ApplyPlan applyPlan = this.lambdaQuery().eq(ApplyPlan::getTaskUuid, yinDaoCallBackBO.getJobUuid()).one(); + applyPlan.setStartTime(DateUtils.parseDate(yinDaoCallBackBO.getStartTime())); + applyPlan.setEndTime(DateUtils.parseDate(yinDaoCallBackBO.getEndTime())); + + BigDecimal planTime = new BigDecimal((double) (Long.parseLong(yinDaoCallBackBO.getEndTime()) - Long.parseLong(yinDaoCallBackBO.getStartTime())) / (60 * 1000)).setScale(2, RoundingMode.HALF_UP); + applyPlan.setPlanTime(planTime + ""); + applyPlan.setTaskStatus(yinDaoCallBackBO.getStatus()); + if (!yinDaoCallBackBO.getResult().isEmpty()) { + applyPlan.setOutParam(yinDaoCallBackBO.getResult().get(0).getValue()); + + // 记录响应参数 + ApplyPlanLog applyPlanLog = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getJobUuid, yinDaoCallBackBO.getJobUuid()).one(); + if (null == applyPlanLog) { + applyPlanLog = new ApplyPlanLog(); + applyPlanLog.setCreateBy("系统创建"); + applyPlanLog.setCreateTime(new Date()); + } else { + applyPlanLog.setUpdateBy("系统创建"); + applyPlanLog.setUpdateTime(new Date()); + } + applyPlanLog.setJobUuid(yinDaoCallBackBO.getJobUuid()); + applyPlanLog.setAppId(applyPlan.getAppId()); + applyPlanLog.setOutParam(applyPlan.getOutParam()); + applyPlanLogService.saveOrUpdate(applyPlanLog); + } + applyPlan.setUpdateBy("系统修改"); + applyPlan.setUpdateTime(new Date()); + boolean isUpdate = this.updateById(applyPlan); + // 终态 + List finalState = new ArrayList<>(); + finalState.add(PlanRunStatus.FINISH.getKey()); + finalState.add(PlanRunStatus.STOPPED.getKey()); + finalState.add(PlanRunStatus.ERROR.getKey()); + finalState.add(PlanRunStatus.SKIPPED.getKey()); + finalState.add(PlanRunStatus.CANCEL.getKey()); + // 如果是终态 + if (StringUtils.isNotEmpty(yinDaoCallBackBO.getRobotClientName()) && finalState.contains(yinDaoCallBackBO.getStatus())) { + Rebot rebot = new Rebot(); + rebot.setStatus(RebotStatus.IDLE.getKey()); + rebot.setUpdateBy("系统修改"); + rebot.setUpdateTime(new Date()); + return rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, yinDaoCallBackBO.getRobotClientName()).update(rebot); + } else { + return isUpdate; + } + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + if (lock.isHeldByCurrentThread()) { + // 释放锁 + lock.unlock(); + } } - + return true; } /** @@ -139,7 +216,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()).isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime).list(); + List applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TWO.getKey()) + .isNull(ApplyPlan::getTaskUuid).orderByAsc(ApplyPlan::getExcTime) + .eq(ApplyPlan::getEnabled, "0") + .list(); if (applyPlanList.isEmpty()) { return false; } @@ -224,28 +304,22 @@ public class ApplyPlanServiceImpl extends ServiceImpl applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()).ne(ApplyPlan::getTaskStatus, PlanRunStatus.RUNNING.getKey()).ne(ApplyPlan::getTaskStatus, PlanRunStatus.CREATED.getKey()).list(); + List applyPlanList = this.lambdaQuery().eq(ApplyPlan::getExcType, ExcTypeStatus.TREE.getKey()) + .ne(ApplyPlan::getTaskStatus, PlanRunStatus.RUNNING.getKey()) + .ne(ApplyPlan::getTaskStatus, PlanRunStatus.CREATED.getKey()) + .eq(ApplyPlan::getEnabled, "0") + .list(); if (applyPlanList.isEmpty()) { return false; } // 需要执行的计划 List execApplyPlan = new ArrayList<>(); applyPlanList.forEach(e -> { - try { - CronExpression cron = new CronExpression(e.getCronExpression()); - // 如果该计划没有执行过 - if (Objects.isNull(e.getLastExecTime())) { - // 执行一次 - execApplyPlan.add(e); - } else { - // 根据表达式返回下一个执行时间 - if (new Date().compareTo(e.getNextExecTime()) > -1) { - execApplyPlan.add(e); - } - } - } catch (ParseException ex) { - log.error(e.getPlanName() + "的时间表达式错误!"); - throw new RuntimeException(ex); + Date date = new Date(); + // 当前时间大于下次时间 + if (date.compareTo(e.getNextExecTime()) > -1) { + // 执行一次 + execApplyPlan.add(e); } }); if (execApplyPlan.isEmpty()) { @@ -288,11 +362,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); - applyStartBO.setParams(paramList); + List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, e.getAppId()).list(); + if (!list.isEmpty()) { + List robotParamList = list.stream().map(param -> { + ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); + robotParam.setType(param.getResourceType()); + robotParam.setName(param.getResourceName()); + robotParam.setValue(param.getResourceValue()); + return robotParam; + }).collect(Collectors.toList()); + applyStartBO.setParams(robotParamList); + // 记录已经执行的参数 + String jsonString = JSON.toJSONString(robotParamList); + applyStartBO.setPlanParams(jsonString); } } @@ -304,20 +386,21 @@ public class ApplyPlanServiceImpl extends ServiceImpl noStatus = new ArrayList<>(); - noStatus.add(PlanRunStatus.FINISH.getKey()); - noStatus.add(PlanRunStatus.STOPPED.getKey()); - noStatus.add(PlanRunStatus.ERROR.getKey()); - noStatus.add(PlanRunStatus.SKIPPED.getKey()); - noStatus.add(PlanRunStatus.CANCEL.getKey()); - // 查询任务运行状态非空非终态并且已经创建的任务 - List list = this.lambdaQuery().notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskUuid).isNotNull(ApplyPlan::getTaskStatus).orderByAsc(ApplyPlan::getPriority).list(); - if (list.isEmpty()) { - log.debug("没有需要更新状态的计划任务"); - return; - } - for (ApplyPlan applyPlan : list) { - JobQueryBO jobQueryBO = new JobQueryBO(); - jobQueryBO.setJobUuid(applyPlan.getTaskUuid()); - JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO); - // 如果状态不一致,更新最新状态 - if (jobQueryVO != null && !applyPlan.getTaskStatus().equals(jobQueryVO.getStatus())) { - // 修改的任务计划 - ApplyPlan updateApplyPlan = new ApplyPlan(); - updateApplyPlan.setTaskStatus(jobQueryVO.getStatus()); - if (null != jobQueryVO.getEndTime()) { - updateApplyPlan.setEndTime(jobQueryVO.getEndTime()); - updateApplyPlan.setStartTime(jobQueryVO.getStartTime()); - if (!Objects.isNull(updateApplyPlan.getEndTime()) && !Objects.isNull(updateApplyPlan.getStartTime())) { - long diff = updateApplyPlan.getEndTime().getTime() - updateApplyPlan.getStartTime().getTime(); - long planTime = diff / (60 * 1000); - updateApplyPlan.setPlanTime(planTime + ""); - if (!Objects.isNull(applyPlan.getManualTime())) { - updateApplyPlan.setTimeSaving((Long.parseLong(applyPlan.getManualTime()) - planTime) + ""); + RLock lock = redissonClient.getLock("updateResult"); + try { + // 尝试获取锁,最多等待100秒,锁定之后最多持有锁10秒 + boolean isLocked = lock.tryLock(2, 10, TimeUnit.SECONDS); + if (isLocked) { + // 不查询的状态 + List noStatus = new ArrayList<>(); + noStatus.add(PlanRunStatus.FINISH.getKey()); + noStatus.add(PlanRunStatus.STOPPED.getKey()); + noStatus.add(PlanRunStatus.ERROR.getKey()); + noStatus.add(PlanRunStatus.SKIPPED.getKey()); + noStatus.add(PlanRunStatus.CANCEL.getKey()); + // 查询任务运行状态非空非终态并且已经创建的任务 + List list = this.lambdaQuery().notIn(ApplyPlan::getTaskStatus, noStatus).isNotNull(ApplyPlan::getTaskUuid).isNotNull(ApplyPlan::getTaskStatus).orderByAsc(ApplyPlan::getPriority).list(); + if (list.isEmpty()) { + log.debug("没有需要更新状态的计划任务"); + return; + } + for (ApplyPlan applyPlan : list) { + JobQueryBO jobQueryBO = new JobQueryBO(); + jobQueryBO.setJobUuid(applyPlan.getTaskUuid()); + JobQueryVO jobQueryVO = YinDaoHttpUtils.queryAppStartResult(jobQueryBO); + // 如果状态不一致,更新最新状态 + if (jobQueryVO != null && !applyPlan.getTaskStatus().equals(jobQueryVO.getStatus())) { + // 修改的任务计划 + ApplyPlan updateApplyPlan = new ApplyPlan(); + updateApplyPlan.setTaskStatus(jobQueryVO.getStatus()); + if (null != jobQueryVO.getEndTime()) { + updateApplyPlan.setEndTime(jobQueryVO.getEndTime()); + updateApplyPlan.setStartTime(jobQueryVO.getStartTime()); + if (!Objects.isNull(updateApplyPlan.getEndTime()) && !Objects.isNull(updateApplyPlan.getStartTime())) { + long diff = updateApplyPlan.getEndTime().getTime() - updateApplyPlan.getStartTime().getTime(); + BigDecimal planTime = new BigDecimal((double) diff / (60 * 1000)).setScale(2, RoundingMode.HALF_UP); + updateApplyPlan.setPlanTime(planTime + ""); + if (!Objects.isNull(applyPlan.getManualTime())) { + updateApplyPlan.setTimeSaving((new BigDecimal(applyPlan.getManualTime()).subtract(planTime)) + ""); + } + } + } + updateApplyPlan.setId(applyPlan.getId()); + updateApplyPlan.setUpdateBy("系统修改"); + updateApplyPlan.setUpdateTime(new Date()); + + // 如果是终态并且有响应参数 获取返回值 + List finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); + if (finishStatus.contains(jobQueryVO.getStatus())) { + List outputs = jobQueryVO.getRobotParams().getOutputs(); + if (null != outputs && !outputs.isEmpty()) { + JobQueryVO.RobotParam robotParam = outputs.get(0); + updateApplyPlan.setOutParam(robotParam.getValue()); + } + } + updateApplyPlan.setRemark(jobQueryVO.getRemark()); + + this.updateById(updateApplyPlan); + if ("2".equals(applyPlan.getExcType())) { + ApplyPlanLog applyPlanLog = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getJobUuid, applyPlan.getTaskUuid()).one(); + // 记录响应参数 + if (applyPlanLog == null) { + applyPlanLog = new ApplyPlanLog(); + applyPlanLog.setCreateBy("系统创建"); + applyPlanLog.setCreateTime(new Date()); + } else { + applyPlanLog.setUpdateBy("系统创建"); + applyPlanLog.setUpdateTime(new Date()); + } + applyPlanLog.setJobUuid(jobQueryVO.getJobUuid()); + applyPlanLog.setAppId(applyPlan.getAppId()); + applyPlanLog.setOutParam(updateApplyPlan.getOutParam()); + applyPlanLogService.saveOrUpdate(applyPlanLog); } } - } - updateApplyPlan.setId(applyPlan.getId()); - updateApplyPlan.setUpdateBy("系统修改"); - updateApplyPlan.setUpdateTime(new Date()); - - // 如果是终态并且有响应参数 获取返回值 - List finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); - if (finishStatus.contains(jobQueryVO.getStatus())) { - List outputs = jobQueryVO.getRobotParams().getOutputs(); - if (null != outputs && !outputs.isEmpty()) { - JobQueryVO.RobotParam robotParam = outputs.get(0); - updateApplyPlan.setOutParam(robotParam.getValue()); + // 如果是终态改变机器人状态 + List finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); + if (finishStatus.contains(jobQueryVO.getStatus())) { + Rebot rebot = new Rebot(); + rebot.setStatus(RebotStatus.IDLE.getKey()); + rebot.setUpdateBy("系统修改"); + rebot.setUpdateTime(new Date()); + rebot.setStatus(RebotStatus.IDLE.getKey()); + rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); + } else if (PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())) { + Rebot rebot = new Rebot(); + rebot.setStatus(RebotStatus.RUNNING.getKey()); + rebot.setUpdateBy("系统修改"); + rebot.setUpdateTime(new Date()); + rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); } } - updateApplyPlan.setRemark(jobQueryVO.getRemark()); - this.updateById(updateApplyPlan); } - // 如果是终态改变机器人状态 - List finishStatus = Arrays.asList(PlanRunStatus.FINISH.getKey(), PlanRunStatus.STOPPED.getKey(), PlanRunStatus.ERROR.getKey(), PlanRunStatus.SKIPPED.getKey(), PlanRunStatus.CANCEL.getKey()); - if (finishStatus.contains(jobQueryVO.getStatus())) { - Rebot rebot = new Rebot(); - rebot.setStatus(RebotStatus.IDLE.getKey()); - rebot.setUpdateBy("系统修改"); - rebot.setUpdateTime(new Date()); - rebot.setStatus(RebotStatus.IDLE.getKey()); - rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); - } else if (PlanRunStatus.RUNNING.getKey().equals(jobQueryVO.getStatus())) { - Rebot rebot = new Rebot(); - rebot.setStatus(RebotStatus.RUNNING.getKey()); - rebot.setUpdateBy("系统修改"); - rebot.setUpdateTime(new Date()); - rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, jobQueryVO.getRobotClientName()).update(rebot); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + if (lock.isHeldByCurrentThread()) { + // 释放锁 + lock.unlock(); } } } @@ -491,10 +619,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl paramList = JSON.parseArray(applyPlan.getPlanParams(), ApplyStartBO.RobotParam.class); - applyStartBO.setParams(paramList); + List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyPlan.getAppId()).list(); + if (!list.isEmpty()) { + List robotParamList = list.stream().map(e -> { + ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); + robotParam.setType(e.getResourceType()); + robotParam.setName(e.getResourceName()); + robotParam.setValue(e.getResourceValue()); + return robotParam; + }).collect(Collectors.toList()); + applyStartBO.setParams(robotParamList); + // 记录已经执行的参数 + String jsonString = JSON.toJSONString(robotParamList); + applyStartBO.setPlanParams(jsonString); } } JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); @@ -511,8 +648,10 @@ public class ApplyPlanServiceImpl extends ServiceImpl implements listApplyBO.setPage(1); // 影刀最大限制 listApplyBO.setSize(100); - List applyList = baseMapper.selectApplyList(new Apply()); - Map> applyMap = applyList.stream().collect(Collectors.groupingBy(Apply::getAppId)); + List applyList = baseMapper.selectApplyList(new Apply()); + Map> applyMap = applyList.stream().collect(Collectors.groupingBy(ListApplyVO::getAppId)); List listApplyVOList = YinDaoHttpUtils.listApp(listApplyBO); // 获取客户端名称集合 List appIdList = listApplyVOList.stream().map(ListApplyVO::getAppId).collect(Collectors.toList()); - // 只能移除当前用户部门的 - this.remove(new LambdaUpdateWrapper().notIn(Apply::getAppId, appIdList).eq(Apply::getDeptId, SecurityUtils.getDeptId())); - + // 是否管理员 + long count = SecurityUtils.getLoginUser().getUser().getRoles().stream().filter(e -> e.getRoleId() == 1).count(); + if (count > 0) { + this.remove(new LambdaUpdateWrapper().notIn(Apply::getAppId, appIdList)); + } else { + // 只能移除当前用户部门的 + this.remove(new LambdaUpdateWrapper().notIn(Apply::getAppId, appIdList).eq(Apply::getDeptId, SecurityUtils.getDeptId())); + } Map> deptMap = sysDeptService.selectDeptAllList(new SysDept()).stream().collect(Collectors.groupingBy(SysDept::getDeptName)); listApplyVOList.forEach(listRebotVO -> { // 数据库里是否存在 - List applys = applyMap.get(listRebotVO.getAppId()); + List applys = applyMap.get(listRebotVO.getAppId()); String[] deptName = listRebotVO.getAppName().split("-"); List sysDepts = deptMap.get(deptName[0]); @@ -115,7 +119,7 @@ public class ApplyServiceImpl extends ServiceImpl implements } save(newApply); } else { - Apply apply = applys.get(0); + ListApplyVO apply = applys.get(0); Apply newApply = new Apply(); BeanUtils.copyBeanProp(newApply, listRebotVO); newApply.setAppCreateTime(listRebotVO.getCreateTime()); @@ -148,8 +152,46 @@ public class ApplyServiceImpl extends ServiceImpl implements */ @Override @DataScope(deptAlias = "apply") - public List list(Apply apply) { - return baseMapper.selectApplyList(apply); + public List list(List planList, List planLogList, Apply apply) { + // 按照appId分组 + Map> planMap = planList.stream().collect(Collectors.groupingBy(ApplyPlan::getAppId)); + // 日志按照app分组 + Map> planLogMap = planLogList.stream().collect(Collectors.groupingBy(ApplyPlanLog::getAppId)); + + List listApplyVOS = baseMapper.selectApplyList(apply); + List newList = listApplyVOS.stream().map(e -> { + // 根据appId获取执行计划 + List applyPlans = planMap.get(e.getAppId()); + // 应用没有设置时间 + if (null == applyPlans) { + return e; + } + // 总计节约时间 (分钟) + AtomicReference planTime = new AtomicReference<>(BigDecimal.ZERO); + applyPlans.forEach(plan -> { + // 如果是周期执行 + if ("2".equals(plan.getExcType())) { + // 获取执行日志 + List applyPlanLogs = planLogMap.get(e.getAppId()); + // 日志总计节约时间 + AtomicReference logPlanTime = new AtomicReference<>(BigDecimal.ZERO); + applyPlanLogs.forEach(log -> { + // 实际运行时间 + long runDate = log.getUpdateTime().getTime() - log.getCreateTime().getTime(); + // 转为分钟 + BigDecimal min = new BigDecimal((double) runDate / (1000 * 60)).setScale(2, RoundingMode.HALF_UP); + logPlanTime.set(logPlanTime.get().add(min)); + }); + planTime.set(planTime.get().add(logPlanTime.get())); +// planTime.set(planTime.get() + logPlanTime.get()); + } else { + planTime.set(planTime.get().add(new BigDecimal(Long.parseLong(plan.getTimeSaving())))); + } + }); + e.setTimeSaving(planTime.get() + ""); + return e; + }).collect(Collectors.toList()); + return newList; } /** @@ -163,4 +205,28 @@ public class ApplyServiceImpl extends ServiceImpl implements public List listAll(Apply apply) { return baseMapper.selectApplyAllList(apply); } + + /** + * 修改应用实际执行时间 + * + * @param apply + * @return + */ + @Override + public boolean updateRunDate(Apply apply) { + // 根据appId获取计划 + List appList = applyPlanService.lambdaQuery().eq(ApplyPlan::getAppId, apply.getAppId()).list(); + appList.forEach(e -> { + e.setManualTime(apply.getManualTime()); + if (PlanRunStatus.FINISH.getKey().equals(e.getTaskStatus())) { + // 计算节约时间 + long diff = Long.parseLong(e.getManualTime()) - Long.parseLong(Optional.ofNullable(e.getPlanTime()).orElse("0")); + e.setTimeSaving(diff + ""); + } + applyPlanService.updateById(e); + }); + return super.updateById(apply); + } + + } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java index 401b3d3..65e933c 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ResourceLibraryServiceImpl.java @@ -30,6 +30,25 @@ public class ResourceLibraryServiceImpl extends ServiceImpl resourceLibraries = new ArrayList<>(); + addBatchResourceLibraryBO.getList().forEach(e -> { + ResourceLibrary resourceLibrary = new ResourceLibrary(); + resourceLibrary.setId(e.getId()); + resourceLibrary.setResourceValue(e.getResourceValue()); + resourceLibraries.add(resourceLibrary); + }); + + return super.updateBatchById(resourceLibraries); + } + /** * 批量添加参数 * diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java b/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java index 86f87fb..3a7ceb7 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/util/YinDaoHttpUtils.java @@ -55,6 +55,8 @@ public class YinDaoHttpUtils { List robotParams = JSON.parseArray(applyStartBO.getPlanParams(), ApplyStartBO.RobotParam.class); List newParamList = robotParams.stream().peek(e -> { if ("file".equals(e.getType())) { +// e.setValue(SERVER_URL + e.getValue()); + e.setType("str"); e.setValue(SERVER_URL + e.getValue()); } }).collect(Collectors.toList()); diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml index 84b1305..5edced3 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml @@ -51,6 +51,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + select apply.id, @@ -77,7 +81,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" apply.deleted - from ct_apply apply diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml index 1701b2c..31e2c60 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanLogMapper.xml @@ -9,32 +9,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - - - - - - - - - + - - - - - - - - - - - - - - + + + + @@ -52,20 +32,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select id, - job_uuid, - plan_name, - plan_type, - robot_name, - app_type_name, - app_name, - app_id, - status, - status_name, - start_time, - end_time, - manual_time, - plan_time, - time_saving, + job_uuid, + app_id, + plan_id, + out_param, create_by, create_time, update_by, @@ -79,13 +49,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" deleted = 0 and job_uuid = #{jobUuid} - and plan_name like concat(#{planName}, '%') - and robot_name like concat(#{robotName}, '%') - and app_type_name like concat(#{appTypeName}, '%') - and app_name like concat(#{appName}, '%') - and app_id = #{appId} - and status = #{status} - and status_name like concat(#{statusName}, '%') + and plan_id = #{planId} + ORDER BY create_time desc \ No newline at end of file diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml index b59902a..509110f 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml @@ -57,6 +57,8 @@ + + @@ -100,6 +102,7 @@ plan.time_saving, plan.dept_id, plan.dept_name, + plan.enabled, plan.create_by, plan.create_time, plan.update_by, diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java index f241c54..aad4183 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/util/AbstractQuartzJob.java @@ -93,7 +93,7 @@ public abstract class AbstractQuartzJob implements Job } // 写入数据库当中 - SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); +// SpringUtils.getBean(ISysJobLogService.class).addJobLog(sysJobLog); } /** -- 2.24.1 From a7f2d48e1bb21a47b5a6bbef6eb79d07a6988406 Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Thu, 25 Jul 2024 14:19:15 +0800 Subject: [PATCH 2/8] 123 --- .../src/main/resources/application.yml | 4 ++-- .../business/controller/ApplyController.java | 4 ++-- .../ruoyi/business/service/IApplyService.java | 2 +- .../service/impl/ApplyPlanServiceImpl.java | 13 +++++++++---- .../service/impl/ApplyServiceImpl.java | 19 ++++++++++++------- .../mapper/business/ApplyPlanMapper.xml | 4 +--- .../core/controller/BaseController.java | 3 ++- .../common/utils/file/FileUploadUtils.java | 4 ++-- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 908e9db..6e78cb6 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -57,9 +57,9 @@ spring: servlet: multipart: # 单个文件大小 - max-file-size: 10MB + max-file-size: 200MB # 设置总上传的文件大小 - max-request-size: 20MB + max-request-size: 200MB # 服务模块 devtools: restart: diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java index eb1906a..bf9815c 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java @@ -110,7 +110,7 @@ public class ApplyController extends BaseController { planLogList = qw.in(ApplyPlanLog::getPlanId, planIdList).isNotNull(ApplyPlanLog::getUpdateTime).list(); } startPage(); - List list = applyService.list(planList, planLogList, apply); + List list = applyService.list(apply,planList, planLogList ); return getDataTable(list); } @@ -125,7 +125,7 @@ public class ApplyController extends BaseController { List planList = applyPlanService.lambdaQuery().eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).list(); // 获取所有计划记录 List planLogList = applyPlanLogService.list(); - List list = applyService.list(planList, planLogList, apply); + List list = applyService.list(apply,planList, planLogList); ExcelUtil util = new ExcelUtil(ListApplyVO.class); util.exportExcel(response, list, "应用信息管理数据"); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java index 276dcc7..43db47d 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyService.java @@ -42,7 +42,7 @@ public interface IApplyService extends IService * @param apply 应用信息管理 * @return 应用信息管理集合 */ - List list(List planList, List planLogList, Apply apply); + List list(Apply apply,List planList, List planLogList); /** * 查询所有应用信息列表 diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 62d512b..0d02947 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -121,10 +121,15 @@ public class ApplyPlanServiceImpl extends ServiceImpl list(ApplyPlan applyPlan) { return baseMapper.selectApplyPlanList(applyPlan); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java index d85234b..0ab1270 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java @@ -9,6 +9,9 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import com.ruoyi.business.domain.*; import com.ruoyi.business.domain.bo.ApplyStartBO; import com.ruoyi.business.domain.bo.JobQueryBO; @@ -21,9 +24,12 @@ import com.ruoyi.business.service.IResourceLibraryService; import com.ruoyi.business.util.YinDaoHttpUtils; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.page.PageDomain; +import com.ruoyi.common.core.page.TableSupport; import com.ruoyi.common.enums.PlanRunStatus; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.bean.BeanUtils; +import com.ruoyi.common.utils.sql.SqlUtil; import com.ruoyi.system.service.ISysDeptService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -152,19 +158,19 @@ public class ApplyServiceImpl extends ServiceImpl implements */ @Override @DataScope(deptAlias = "apply") - public List list(List planList, List planLogList, Apply apply) { + public List list(Apply apply,List planList, List planLogList) { // 按照appId分组 Map> planMap = planList.stream().collect(Collectors.groupingBy(ApplyPlan::getAppId)); // 日志按照app分组 Map> planLogMap = planLogList.stream().collect(Collectors.groupingBy(ApplyPlanLog::getAppId)); List listApplyVOS = baseMapper.selectApplyList(apply); - List newList = listApplyVOS.stream().map(e -> { + listApplyVOS.forEach(e -> { // 根据appId获取执行计划 List applyPlans = planMap.get(e.getAppId()); // 应用没有设置时间 if (null == applyPlans) { - return e; + return; } // 总计节约时间 (分钟) AtomicReference planTime = new AtomicReference<>(BigDecimal.ZERO); @@ -189,9 +195,8 @@ public class ApplyServiceImpl extends ServiceImpl implements } }); e.setTimeSaving(planTime.get() + ""); - return e; - }).collect(Collectors.toList()); - return newList; + }); + return listApplyVOS; } /** @@ -220,7 +225,7 @@ public class ApplyServiceImpl extends ServiceImpl implements e.setManualTime(apply.getManualTime()); if (PlanRunStatus.FINISH.getKey().equals(e.getTaskStatus())) { // 计算节约时间 - long diff = Long.parseLong(e.getManualTime()) - Long.parseLong(Optional.ofNullable(e.getPlanTime()).orElse("0")); + double diff = Double.parseDouble(e.getManualTime()) - Double.parseDouble(Optional.ofNullable(e.getPlanTime()).orElse("0")); e.setTimeSaving(diff + ""); } applyPlanService.updateById(e); diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml index 509110f..744a301 100644 --- a/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/ApplyPlanMapper.xml @@ -103,7 +103,7 @@ plan.dept_id, plan.dept_name, plan.enabled, - plan.create_by, + ifnull((select nick_name from sys_user where user_name = plan.create_by),plan.create_by) as create_by, plan.create_time, plan.update_by, plan.update_time, @@ -114,8 +114,6 @@ + + from ct_apply_rebot ar + + deleted = 0 + and version = #{applyId} + and rebot_name = #{rebotName} + + + + \ No newline at end of file -- 2.24.1 From 403b8e75ed7a15c8e7812e2a04412b54128820d3 Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Mon, 5 Aug 2024 15:10:52 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=88=87=E6=8D=A2=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-prod.yml | 12 +- .../src/main/resources/application.yml | 22 -- .../business/controller/ApplyController.java | 3 +- .../controller/ApplyRebotController.java | 2 +- .../ruoyi/business/domain/ApplyPlanLog.java | 56 ++-- .../ruoyi/business/domain/bo/JobQueryBO.java | 5 + .../service/impl/ApplyPlanServiceImpl.java | 275 +++++++++++------- .../service/impl/ApplyServiceImpl.java | 3 + 8 files changed, 224 insertions(+), 154 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 191d629..a7083fe 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -3,13 +3,13 @@ spring: # redis 配置 redis: # 地址 - host: 192.168.10.136 + host: 192.168.10.214 # 端口,默认为6379 port: 6379 # 数据库索引 - database: 13 + database: 0 # 密码 - password: wjcy@123456 + password: Aa@123456 # 连接超时时间 timeout: 10s lettuce: @@ -28,9 +28,9 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://192.168.10.136:3306/wjcy_new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: wjcy@123456 + url: jdbc:mysql://192.168.10.214:3306/wjcy_new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: wjcy_new + password: PHPKL3p3ME2pGT4j # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 6e78cb6..7340ef2 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -65,28 +65,6 @@ spring: restart: # 热部署开关 enabled: true - # redis 配置 - redis: - # 地址 - host: 192.168.10.136 - # 端口,默认为6379 - port: 6379 - # 数据库索引 - database: 13 - # 密码 - password: wjcy@123456 - # 连接超时时间 - timeout: 10s - lettuce: - pool: - # 连接池中的最小空闲连接 - min-idle: 0 - # 连接池中的最大空闲连接 - max-idle: 8 - # 连接池的最大数据库连接数 - max-active: 8 - # #连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms # token配置 token: diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java index bf9815c..a3a28f9 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyController.java @@ -97,12 +97,11 @@ public class ApplyController extends BaseController { List planList = applyPlanService.lambdaQuery().isNotNull(ApplyPlan::getManualTime) .and(e -> e.in(ApplyPlan::getExcType, "0", "1") .eq(ApplyPlan::getTaskStatus, PlanRunStatus.FINISH.getKey()).or().eq(ApplyPlan::getExcType, "2")) - .list(); // 只过滤执行计划的id List planIdList = planList.stream().filter(e -> "2".equals(e.getExcType())).map(ApplyPlan::getId).collect(Collectors.toList()); // 获取所有 设置了时间并且是完成状态的计划记录 - LambdaQueryChainWrapper qw = applyPlanLogService.lambdaQuery(); + LambdaQueryChainWrapper qw = applyPlanLogService.lambdaQuery().eq(ApplyPlanLog::getStatus,"0"); List planLogList = null; if (planIdList.isEmpty()) { planLogList = new ArrayList<>(); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java index fd3c9bc..f9cc0f7 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java @@ -56,7 +56,7 @@ public class ApplyRebotController extends BaseController { @ApiOperation(value = "查询所有应用和机器人绑定列表", httpMethod = "GET", response = Apply.class) @GetMapping("/listAll") public AjaxResult listAll(ApplyRebot applyRebot) { - List applyRebotList = applyRebotService.list(applyRebot); + List applyRebotList = applyRebotService.list(applyRebot).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); return AjaxResult.success(applyRebotList); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java index 7a8c2c8..7f4fb58 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyPlanLog.java @@ -1,6 +1,7 @@ package com.ruoyi.business.domain; import java.util.Date; + import com.fasterxml.jackson.annotation.JsonFormat; import com.baomidou.mybatisplus.annotation.*; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -28,47 +29,60 @@ import com.ruoyi.common.core.domain.BaseEntity; @Builder(toBuilder = true) @NoArgsConstructor @AllArgsConstructor -@ApiModel(value="ApplyPlanLog",description = "应用执行结果记录管理") +@ApiModel(value = "ApplyPlanLog", description = "应用执行结果记录管理") @TableName(value = "ct_apply_plan_log") -public class ApplyPlanLog extends BaseEntity -{ +public class ApplyPlanLog extends BaseEntity { @TableField(exist = false) private static final long serialVersionUID = 1L; - - /** 计划id */ + /** + * 计划id + */ @Excel(name = "计划id") - @ApiModelProperty(name="planId",value = "计划id") + @ApiModelProperty(name = "planId", value = "计划id") private String planId; - /** 所属应用id */ + /** + * 所属应用id + */ @Excel(name = "所属应用id") - @ApiModelProperty(name="appId",value = "所属应用id") + @ApiModelProperty(name = "appId", value = "所属应用id") private String appId; - /** 计划job_uuid */ + /** + * 计划job_uuid + */ @Excel(name = "计划job_uuid") - @ApiModelProperty(name="jobUuid",value = "计划job_uuid") + @ApiModelProperty(name = "jobUuid", value = "计划job_uuid") private String jobUuid; - /** 输出内容 */ + /** + * 输出内容 + */ @Excel(name = "输出内容") - @ApiModelProperty(name="outParam",value = "输出内容") + @ApiModelProperty(name = "outParam", value = "输出内容") private String outParam; + /** + * 执行结果(0成功 1失败) + */ + @Excel(name = "执行结果(0成功 1失败)") + @ApiModelProperty(name = "status", value = "执行结果(0成功 1失败)") + private String status; + @Override public String toString() { - return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("createBy", getCreateBy()) - .append("createTime", getCreateTime()) - .append("updateBy", getUpdateBy()) - .append("updateTime", getUpdateTime()) - .append("remark", getRemark()) - .append("deleted", getDeleted()) - .toString(); + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .append("deleted", getDeleted()) + .toString(); } } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java index ed79165..307964e 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/JobQueryBO.java @@ -15,5 +15,10 @@ public class JobQueryBO { * 应用运行的uuid, 由job/start接口返回 */ private String jobUuid; + + /** + * 是否应用新参数 + */ + private Boolean newData; } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 6c9a7a4..9ba7f84 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -98,6 +98,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl 0; + // 状态异常重新创建任务 删除原任务,如果是周期则有任务日志,改变原日志关联id,重新创建的任务绑定新的参数 + // 已停止状态重新运行,获取的是旧参数 + ApplyPlan plan = applyPlanService.lambdaQuery().eq(ApplyPlan::getTaskUuid, jobQueryBO.getJobUuid()).one(); + // 获取应用信息 + Apply apply = applyService.lambdaQuery().eq(Apply::getAppId, plan.getAppId()).one(); + + try { + // 周期,将日志绑定到新计划 + if ("2".equals(plan.getExcType())) { + ApplyPlan newApplyPlan = new ApplyPlan(); + createApplyPlan(jobQueryBO, plan, apply, newApplyPlan); + // 换绑日志 + ApplyPlanLog applyPlanLog = new ApplyPlanLog(); + applyPlanLog.setPlanId(newApplyPlan.getId()); + applyPlanLogService.lambdaUpdate().eq(ApplyPlanLog::getPlanId, plan.getId()).update(applyPlanLog); + } else { + createApplyPlan(jobQueryBO, plan, apply, new ApplyPlan()); + } + } catch (Exception ex) { + ex.printStackTrace(); + throw ex; + } + return true; + } + + /** + * 创建一个计划 + * + * @return + */ + private boolean createApplyPlan(JobQueryBO jobQueryBO, ApplyPlan plan, Apply apply, ApplyPlan newApplyPlan) { + // 创建一个新计划 + BeanUtils.copyBeanProp(newApplyPlan, plan); + newApplyPlan.setId(null); + newApplyPlan.setTaskStatus(PlanRunStatus.AWAIT_CREATE.getKey()); + newApplyPlan.setNextExecTime(newApplyPlan.getLastExecTime()); + if (jobQueryBO.getNewData()) { + if (null != apply.getSupportParam() && apply.getSupportParam() == 1) { + newApplyPlan.setSupportParam(apply.getSupportParam()); + // 获取参数列表 + List resourceLibraryList = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, plan.getAppId()).list(); + // 获取参数 每一次执行计划的参数都是独立的 + List paramList = resourceLibraryList.stream() + .map(item -> { + ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); + robotParam.setName(item.getResourceName()); + robotParam.setValue(item.getResourceValue()); + robotParam.setType(item.getResourceType()); + return robotParam; + }).collect(Collectors.toList()); + if (paramList.isEmpty()) { + throw new ServiceException("该应用需要参数,没有检测到参数!"); + } else { + // json集合转字符串 + newApplyPlan.setPlanParams(JSONArray.toJSONString(paramList)); + } + } } else { - return false; + if (null != apply.getSupportParam() && apply.getSupportParam() == 1) { + newApplyPlan.setSupportParam(apply.getSupportParam()); + newApplyPlan.setPlanParams(plan.getPlanParams()); + } } + // 先删除 在新增 + applyPlanService.removeById(plan.getId()); + return applyPlanService.save(newApplyPlan); } /** @@ -239,56 +307,54 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } - List ids = new ArrayList<>(); - runRebotList.forEach(rebot -> { - applyPlanList.forEach(e -> { - log.debug("指定时间执行 执行时间:" + e.getExcTime()); - if (ids.contains(e.getId())) { - return; - } - if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { - ApplyStartBO applyStartBO = new ApplyStartBO(); - applyStartBO.setRobotUuid(e.getAppId()); - applyStartBO.setAccountName(rebot.getRobotClientName()); - applyStartBO.setManualTime(e.getManualTime()); - //high 高 middle 中 low 低 - applyStartBO.setPriority("high"); - // 如果应用支持参数 - if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { - if (StringUtils.isNotEmpty(e.getPlanParams())) { - applyStartBO.setPlanParams(e.getPlanParams()); - List paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); - applyStartBO.setParams(paramList); - } + applyPlanList.forEach(e -> { + List runRebotList = getRunRebot(listRebotVos, e.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return; + } + ListRebotVO rebot = runRebotList.get(0); + log.debug("指定时间执行 执行时间:" + e.getExcTime()); + if (ids.contains(e.getId())) { + return; + } + if (e.getExcTime().getTime() <= System.currentTimeMillis() && PlanRunStatus.AWAIT_CREATE.getKey().equals(e.getTaskStatus())) { + ApplyStartBO applyStartBO = new ApplyStartBO(); + applyStartBO.setRobotUuid(e.getAppId()); + applyStartBO.setAccountName(rebot.getRobotClientName()); + applyStartBO.setManualTime(e.getManualTime()); + //high 高 middle 中 low 低 + applyStartBO.setPriority("high"); + // 如果应用支持参数 + if (!Objects.isNull(e.getSupportParam()) && e.getSupportParam() == 1) { + if (StringUtils.isNotEmpty(e.getPlanParams())) { + applyStartBO.setPlanParams(e.getPlanParams()); + List paramList = JSON.parseArray(e.getPlanParams(), ApplyStartBO.RobotParam.class); + applyStartBO.setParams(paramList); } - try { - JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); - ApplyPlan applyPlan = new ApplyPlan(); - applyPlan.setId(e.getId()); - applyPlan.setUpdateBy("系统修改"); - applyPlan.setUpdateTime(new Date()); - applyPlan.setTaskUuid(jobStartVO.getJobUuid()); - applyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); - this.updateById(applyPlan); - Rebot updateRebot = new Rebot(); - updateRebot.setUpdateBy("系统修改"); - updateRebot.setUpdateTime(new Date()); - updateRebot.setStatus(RebotStatus.RUNNING.getKey()); - if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { - log.debug("applyPlanList:" + applyPlanList.size()); - ids.add(e.getId()); - } - } catch (IllegalAccessException ex) { - throw new RuntimeException(ex); + } + try { + JobStartVO jobStartVO = YinDaoHttpUtils.appStart(applyStartBO); + ApplyPlan applyPlan = new ApplyPlan(); + applyPlan.setId(e.getId()); + applyPlan.setUpdateBy("系统修改"); + applyPlan.setUpdateTime(new Date()); + applyPlan.setTaskUuid(jobStartVO.getJobUuid()); + applyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); + this.updateById(applyPlan); + Rebot updateRebot = new Rebot(); + updateRebot.setUpdateBy("系统修改"); + updateRebot.setUpdateTime(new Date()); + updateRebot.setStatus(RebotStatus.RUNNING.getKey()); + if (rebotService.lambdaUpdate().eq(Rebot::getRobotClientName, rebot.getRobotClientName()).update(updateRebot)) { + log.debug("applyPlanList:" + applyPlanList.size()); + ids.add(e.getId()); } + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); } - }); + } }); } } catch (InterruptedException e) { @@ -348,17 +414,19 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } List ids = new ArrayList<>(); execApplyPlan.forEach(e -> { if (listRebotVos.isEmpty()) { return; } + + List runRebotList = getRunRebot(listRebotVos, e.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return; + } + ListRebotVO rebot = runRebotList.get(0); log.debug("机器人表达式执行调度日志" + rebot.getRobotClientName() + "调度" + e.getAppName() + "应用,排除的应用id为" + ids.toString()); if (ids.contains(e.getId())) { @@ -540,6 +608,13 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos); - if(null == runRebotList){ - log.debug("暂无可用空闲机器人"); - return false; - } - // 获取每个部门优先级最高的计划 List applyPlans = new ArrayList<>(); applyPlanMap.forEach((k, v) -> { @@ -625,20 +694,22 @@ public class ApplyPlanServiceImpl extends ServiceImpl runRebotList = getRunRebot(listRebotVos, runApplyPlan.getAppId()); + if (null == runRebotList) { + log.debug("暂无可用空闲机器人"); + return false; } - applyPlan = applyPlans.get(0); + applyStartBO = new ApplyStartBO(); - applyStartBO.setRobotUuid(applyPlan.getAppId()); + applyStartBO.setRobotUuid(runApplyPlan.getAppId()); //high 高 middle 中 low 低 applyStartBO.setPriority("high"); - applyStartBO.setAccountName(listRebotVO.getRobotClientName()); + applyStartBO.setAccountName(runRebotList.get(0).getRobotClientName()); // 如果应用支持参数 - if (!Objects.isNull(applyPlan.getSupportParam()) && applyPlan.getSupportParam() == 1) { - List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, applyPlan.getAppId()).list(); + if (!Objects.isNull(runApplyPlan.getSupportParam()) && runApplyPlan.getSupportParam() == 1) { + List list = resourceLibraryService.lambdaQuery().eq(ResourceLibrary::getAppId, runApplyPlan.getAppId()).list(); if (!list.isEmpty()) { List robotParamList = list.stream().map(e -> { ApplyStartBO.RobotParam robotParam = new ApplyStartBO.RobotParam(); @@ -655,23 +726,23 @@ public class ApplyPlanServiceImpl extends ServiceImpl getRunRebot(List listRebotVos){ - // 查询应用是否有指定机器人,没有则随机指派 - List rebotList = applyRebotService.list(new LambdaQueryWrapper().eq(ApplyRebot::getApplyId, applyStartBO.getRobotUuid())).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); - // 是否继续执行 - List runRebotList = new ArrayList<>(); - // 如果查到关系,则该应用指定了机器人 - if(!rebotList.isEmpty()){ - // 遍历可用机器人 - listRebotVos.forEach(e->{ - // 如果有指定可用 - if(rebotList.contains(e.getRobotClientName())){ - runRebotList.add(e); - } - }); - }else{ - runRebotList.addAll(listRebotVos); - } - if(runRebotList.isEmpty()){ - return runRebotList; - }else{ - return null; - } - } - + private List getRunRebot(List listRebotVos, String appId) { + // 查询应用是否有指定机器人,没有则随机指派 + List rebotList = applyRebotService.list(new LambdaQueryWrapper().eq(ApplyRebot::getApplyId, appId)).stream().map(ApplyRebot::getRebotName).collect(Collectors.toList()); + // 是否继续执行 + List runRebotList = new ArrayList<>(); + // 如果查到关系,则该应用指定了机器人 + if (!rebotList.isEmpty()) { + // 遍历可用机器人 + listRebotVos.forEach(e -> { + // 如果有指定可用 + if (rebotList.contains(e.getRobotClientName())) { + runRebotList.add(e); + } + }); + } else { + runRebotList.addAll(listRebotVos); + } + if (!runRebotList.isEmpty()) { + return runRebotList; + } else { + return null; + } + } @Override diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java index f3df1e7..05f9810 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyServiceImpl.java @@ -183,6 +183,9 @@ public class ApplyServiceImpl extends ServiceImpl implements if ("2".equals(plan.getExcType())) { // 获取执行日志 List applyPlanLogs = planLogMap.get(e.getAppId()); + if(null == applyPlanLogs){ + return; + } // 日志总计节约时间 AtomicReference logPlanTime = new AtomicReference<>(BigDecimal.ZERO); applyPlanLogs.forEach(log -> { -- 2.24.1 From f7cbff887e91450f9ac79e1d4fd391b2ecb7d35b Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Mon, 5 Aug 2024 15:19:12 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BD=AC?= =?UTF-8?q?=E7=94=9F=E4=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-admin/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 7340ef2..c0b9062 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -52,7 +52,7 @@ spring: # 国际化资源文件路径 basename: i18n/messages profiles: - active: test + active: prod # 文件上传 servlet: multipart: -- 2.24.1 From 1a62768a6b26b3edf4e126d01c3b337852e122e7 Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Sat, 24 Aug 2024 13:59:38 +0800 Subject: [PATCH 6/8] 1 --- ruoyi-admin/src/main/resources/application-prod.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ruoyi-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index a7083fe..637d76c 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -1,3 +1,7 @@ +# 项目相关配置 +ruoyi: + # 文件路径 示例( Windows配置D:/poject,Linux配置 /home/poject) + profile: /home/pojectFile/ # Spring配置 数据源配置 spring: # redis 配置 -- 2.24.1 From 6e3906d6cdd6859a1af9f271b101446f60992d6b Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Mon, 26 Aug 2024 16:03:52 +0800 Subject: [PATCH 7/8] 123 --- ruoyi-admin/src/main/resources/application-dev.yml | 12 ++++++------ .../business/service/impl/ApplyPlanServiceImpl.java | 11 +++++++++-- .../service/impl/ResourceLibraryServiceImpl.java | 8 ++++---- .../com/ruoyi/business/util/YinDaoHttpUtils.java | 6 +++++- .../main/resources/mapper/business/ApplyMapper.xml | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ruoyi-admin/src/main/resources/application-dev.yml b/ruoyi-admin/src/main/resources/application-dev.yml index 86a1122..b168741 100644 --- a/ruoyi-admin/src/main/resources/application-dev.yml +++ b/ruoyi-admin/src/main/resources/application-dev.yml @@ -7,13 +7,13 @@ spring: # redis 配置 redis: # 地址 - host: 192.168.10.136 + host: 192.168.10.214 # 端口,默认为6379 port: 6379 # 数据库索引 - database: 13 + database: 2 # 密码 - password: wjcy@123456 + password: Aa@123456 # 连接超时时间 timeout: 10s lettuce: @@ -32,9 +32,9 @@ spring: druid: # 主库数据源 master: - url: jdbc:mysql://192.168.10.136:3306/wjcy_new?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 - username: root - password: wjcy@123456 + url: jdbc:mysql://192.168.10.214:3306/wjcy_test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + username: wjcy_test + password: 5EyKjNcW28MTJGHe # 从库数据源 slave: # 从数据源开关/默认关闭 diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 9ba7f84..7e6d5f6 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -229,6 +229,7 @@ public class ApplyPlanServiceImpl extends ServiceImpl and owner_name like concat(#{ownerName}, '%') and owner_account like concat(#{ownerAccount}, '%') - and app_name like concat(#{appName}, '%') + and app_name like concat('%',#{appName}, '%') and version = #{version} and app_type_name like concat(#{appTypeName}, '%') and app_type = #{appType} -- 2.24.1 From 7c5e1e9769b688b938895adc5e3f19f87f1fea07 Mon Sep 17 00:00:00 2001 From: lcr <977192391@qq.com> Date: Mon, 26 Aug 2024 17:56:33 +0800 Subject: [PATCH 8/8] 123 --- .../business/controller/ResourceLibraryController.java | 2 +- .../ruoyi/business/service/impl/ApplyPlanServiceImpl.java | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java index fb01d71..dee88bf 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ResourceLibraryController.java @@ -68,7 +68,7 @@ public class ResourceLibraryController extends BaseController { public TableDataInfo list(ResourceLibrary resourceLibrary) { // 是否管理员 SysUser user = SecurityUtils.getLoginUser().getUser(); - boolean isRole = user.getRoles().stream().filter(e -> e.getRoleId() == 1).count() > 0; + boolean isRole = user.getRoles().stream().anyMatch(e -> e.getRoleId() == 1); if (!isRole) { List appIdList = applyService.lambdaQuery().eq(Apply::getDeptId, SecurityUtils.getDeptId()).list().stream().map(Apply::getAppId).collect(Collectors.toList()); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java index 7e6d5f6..b7d8145 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyPlanServiceImpl.java @@ -728,13 +728,6 @@ public class ApplyPlanServiceImpl extends ServiceImpl