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-admin/src/main/resources/application-prod.yml b/ruoyi-admin/src/main/resources/application-prod.yml index 191d629..637d76c 100644 --- a/ruoyi-admin/src/main/resources/application-prod.yml +++ b/ruoyi-admin/src/main/resources/application-prod.yml @@ -1,15 +1,19 @@ +# 项目相关配置 +ruoyi: + # 文件路径 示例( Windows配置D:/poject,Linux配置 /home/poject) + profile: /home/pojectFile/ # Spring配置 数据源配置 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 +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_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 c832852..c0b9062 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: @@ -52,41 +52,19 @@ spring: # 国际化资源文件路径 basename: i18n/messages profiles: - active: test + active: prod # 文件上传 servlet: multipart: # 单个文件大小 - max-file-size: 10MB + max-file-size: 200MB # 设置总上传的文件大小 - max-request-size: 20MB + max-request-size: 200MB # 服务模块 devtools: 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/pom.xml b/ruoyi-business/pom.xml index 7d201be..e5bbc9b 100644 --- a/ruoyi-business/pom.xml +++ b/ruoyi-business/pom.xml @@ -50,6 +50,10 @@ org.quartz-scheduler quartz + + javax.validation + validation-api + 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..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 @@ -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,23 @@ 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().eq(ApplyPlanLog::getStatus,"0"); + 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(apply,planList, planLogList ); return getDataTable(list); } @@ -80,8 +120,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(apply,planList, planLogList); + 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/ApplyRebotController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java new file mode 100644 index 0000000..f9cc0f7 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/ApplyRebotController.java @@ -0,0 +1,64 @@ +package com.ruoyi.business.controller; + +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.ruoyi.business.domain.*; +import com.ruoyi.business.domain.bo.UpdateApplyRebotBO; +import com.ruoyi.business.domain.vo.ListApplyVO; +import com.ruoyi.business.service.IApplyPlanLogService; +import com.ruoyi.business.service.IApplyPlanService; +import com.ruoyi.business.service.IApplyRebotService; +import com.ruoyi.business.service.IApplyService; +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.enums.PlanRunStatus; +import com.ruoyi.common.utils.poi.ExcelUtil; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 应用信息管理Controller + * + * @author LiuChengRan + * @date 2024-06-13 + */ +@Api(tags = "应用和机器人关系管理接口") +@RestController +@RequestMapping("/business/ctApplyRebot") +public class ApplyRebotController extends BaseController { + @Autowired + private IApplyRebotService applyRebotService; + + + /** + * 查询应用信息管理列表 + */ + @ApiOperation(value = "配置应用机器人绑定关系", httpMethod = "GET", response = Apply.class) + @PostMapping("/updateApplyRebot") + public AjaxResult updateApplyRebot(@RequestBody UpdateApplyRebotBO updateApplyRebotBO) { + + return toAjax(applyRebotService.updateApplyRebot( updateApplyRebotBO)); + } + + /** + * 查询应用信息管理列表 + */ + @ApiOperation(value = "查询所有应用和机器人绑定列表", httpMethod = "GET", response = Apply.class) + @GetMapping("/listAll") + public AjaxResult listAll(ApplyRebot 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/controller/RebotController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/RebotController.java index 3c96968..345cf0b 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/RebotController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/RebotController.java @@ -62,6 +62,15 @@ public class RebotController extends BaseController { List list = rebotService.list(rebot); return AjaxResult.success(list); } + /** + * 查询所有机器人 + */ + @ApiOperation(value = "查询所有机器人", httpMethod = "GET", response = Rebot.class) + @GetMapping("/listRebotAll") + public AjaxResult listRebotAll(Rebot rebot) { + List list = rebotService.list(rebot); + 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..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()); @@ -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..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,115 +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 + */ + @Excel(name = "计划id") + @ApiModelProperty(name = "planId", value = "计划id") + private String planId; - /** 启动的任务的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 = "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; + /** + * 计划job_uuid + */ + @Excel(name = "计划job_uuid") + @ApiModelProperty(name = "jobUuid", value = "计划job_uuid") + private String jobUuid; - /** 预计人工耗时 */ - @Excel(name = "预计人工耗时") - @ApiModelProperty(name="manualTime",value = "预计人工耗时") - private String manualTime; - /** 实际耗时 */ - @Excel(name = "实际耗时") - @ApiModelProperty(name="planTime",value = "实际耗时") - private String planTime; + /** + * 输出内容 + */ + @Excel(name = "输出内容") + @ApiModelProperty(name = "outParam", value = "输出内容") + private String outParam; - /** 节约时间 */ - @Excel(name = "节约时间") - @ApiModelProperty(name="timeSaving",value = "节约时间") - private String timeSaving; + /** + * 执行结果(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("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()) - .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/ApplyRebot.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyRebot.java new file mode 100644 index 0000000..83d6793 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/ApplyRebot.java @@ -0,0 +1,56 @@ +package com.ruoyi.business.domain; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 应用信息管理对象 ct_apply + * + * @author LiuChengRan + * @date 2024-06-13 + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value="ApplyRebot",description = "应用和机器人关系绑定") +@TableName(value = "ct_apply_rebot") +public class ApplyRebot extends BaseEntity +{ + @TableField(exist = false) + private static final long serialVersionUID = 1L; + /** 应用id */ + @Excel(name = "应用id") + @ApiModelProperty(name="applyId",value = "应用id") + private String applyId; + /** 机器人名称 */ + @Excel(name = "机器人名称") + @ApiModelProperty(name="rebotName",value = "机器人名称") + private String rebotName; + + @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(); + } +} 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/domain/bo/UpdateApplyRebotBO.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/UpdateApplyRebotBO.java new file mode 100644 index 0000000..28b348b --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/bo/UpdateApplyRebotBO.java @@ -0,0 +1,54 @@ +package com.ruoyi.business.domain.bo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.List; + +/** + * 应用信息管理对象 ct_apply + * + * @author LiuChengRan + * @date 2024-06-13 + */ +@Data +@Builder(toBuilder = true) +@NoArgsConstructor +@AllArgsConstructor +@ApiModel(value="UpdateApplyRebotBO",description = "应用和机器人关系绑定") +public class UpdateApplyRebotBO extends BaseEntity +{ + @TableField(exist = false) + private static final long serialVersionUID = 1L; + /** 应用id */ + @Excel(name = "应用id") + @ApiModelProperty(name="applyId",value = "应用id") + private String applyId; + /** 机器人名称 */ + @Excel(name = "机器人名称列表") + @ApiModelProperty(name="optRebot",value = "机器人名称列表") + private List optRebot; + + @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(); + } +} 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/mapper/ApplyRebotMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyRebotMapper.java new file mode 100644 index 0000000..aec6718 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/ApplyRebotMapper.java @@ -0,0 +1,29 @@ +package com.ruoyi.business.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.business.domain.Apply; +import com.ruoyi.business.domain.ApplyRebot; +import com.ruoyi.business.domain.vo.ListApplyVO; + +import java.util.List; + +/** + * 应用机器人关联关系 + * + * @author LiuChengRan + * @date 2024-06-13 + */ +public interface ApplyRebotMapper extends BaseMapper +{ + + /** + * 查询应用信息管理列表 + * + * @param applyRebot 应用信息管理 + * @return 应用信息管理集合 + */ + List selectApplyRebotList(ApplyRebot applyRebot); + + + +} 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/IApplyRebotService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyRebotService.java new file mode 100644 index 0000000..8d34ccd --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IApplyRebotService.java @@ -0,0 +1,40 @@ +package com.ruoyi.business.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.ruoyi.business.domain.Apply; +import com.ruoyi.business.domain.ApplyPlan; +import com.ruoyi.business.domain.ApplyPlanLog; +import com.ruoyi.business.domain.ApplyRebot; +import com.ruoyi.business.domain.bo.ApplyStartBO; +import com.ruoyi.business.domain.bo.JobQueryBO; +import com.ruoyi.business.domain.bo.UpdateApplyRebotBO; +import com.ruoyi.business.domain.vo.JobQueryVO; +import com.ruoyi.business.domain.vo.JobStartVO; +import com.ruoyi.business.domain.vo.ListApplyVO; + +import java.util.List; + +/** + * 应用信息管理Service接口 + * + * @author LiuChengRan + * @date 2024-06-13 + */ +public interface IApplyRebotService extends IService +{ + + /** + * 查询应用机器人关系列表 + * + * @param applyRebot 应用机器人关系 + * @return 应用信息管理集合 + */ + List list(ApplyRebot applyRebot); + + /** + * 绑定机器人关系 + * @param updateApplyRebotBO + * @return + */ + boolean updateApplyRebot(UpdateApplyRebotBO updateApplyRebotBO); +} 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..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 @@ -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(Apply apply,List planList, List planLogList); /** * 查询所有应用信息列表 @@ -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..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 @@ -1,8 +1,8 @@ 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; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -10,22 +10,16 @@ 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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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; -import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.ExcTypeStatus; import com.ruoyi.common.enums.PlanRunStatus; import com.ruoyi.common.enums.RebotStatus; @@ -38,12 +32,8 @@ import org.quartz.*; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import org.springframework.beans.factory.annotation.Autowired; -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 +57,51 @@ public class ApplyPlanServiceImpl extends ServiceImpl 0) { + nextDate = cron.getNextValidTimeAfter(date);//下次执行时间 + applyPlan.setNextExecTime(nextDate); + } else { + nextDate = cron.getNextValidTimeAfter(applyPlan.getLastExecTime());//下次执行时间 + applyPlan.setNextExecTime(nextDate); + } + } + applyPlan.setCronExpression(entity.getCronExpression()); + return this.updateById(applyPlan); + } + /** * 影刀回调 * @@ -74,28 +109,80 @@ 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())); + if (null != yinDaoCallBackBO.getEndTime()) { + log.debug("endTime:" + yinDaoCallBackBO.getEndTime()); + Date endDate = DateUtils.parseDate(yinDaoCallBackBO.getEndTime()); + Date startDate = DateUtils.parseDate(yinDaoCallBackBO.getStartTime()); + BigDecimal planTime = new BigDecimal((double) (endDate.getTime() - startDate.getTime()) / (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()); + if (PlanRunStatus.FINISH.getKey().equals(yinDaoCallBackBO.getStatus())) { + // 成功 + applyPlanLog.setStatus("0"); + } else { + // 失败 + applyPlanLog.setStatus("1"); + } + 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; } /** @@ -107,12 +194,73 @@ 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.setTaskUuid(null); + 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); } /** @@ -139,7 +287,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; } @@ -156,50 +307,55 @@ public class ApplyPlanServiceImpl extends ServiceImpl ids = new ArrayList<>(); - listRebotVos.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) { @@ -224,28 +380,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()) { @@ -262,17 +412,23 @@ public class ApplyPlanServiceImpl extends ServiceImpl ids = new ArrayList<>(); execApplyPlan.forEach(e -> { if (listRebotVos.isEmpty()) { - // 刷新机器人数据 -// rebotService.syn(new Rebot()); return; } - ListRebotVO rebot = listRebotVos.get(0); + + 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())) { return; @@ -288,11 +444,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 +468,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()); + if (PlanRunStatus.FINISH.getKey().equals(jobQueryVO.getStatus())) { + // 成功 + applyPlanLog.setStatus("0"); + } else { + // 失败 + applyPlanLog.setStatus("1"); + } + 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(); } } } @@ -478,42 +695,53 @@ 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) { - if (StringUtils.isNotEmpty(applyPlan.getPlanParams())) { - applyStartBO.setPlanParams(applyPlan.getPlanParams()); - List paramList = JSON.parseArray(applyPlan.getPlanParams(), ApplyStartBO.RobotParam.class); - applyStartBO.setParams(paramList); + 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(); + 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); ApplyPlan updateApplyPlan = new ApplyPlan(); - updateApplyPlan.setId(applyPlan.getId()); - updateApplyPlan.setCreateBy("系统创建"); - updateApplyPlan.setCreateTime(new Date()); + updateApplyPlan.setId(runApplyPlan.getId()); updateApplyPlan.setUpdateBy("系统修改"); updateApplyPlan.setUpdateTime(new Date()); updateApplyPlan.setStartTime(new Date()); updateApplyPlan.setTaskUuid(jobStartVO.getJobUuid()); - updateApplyPlan.setPlanName(applyPlan.getPlanName()); + updateApplyPlan.setPlanName(runApplyPlan.getPlanName()); updateApplyPlan.setTaskStatus(PlanRunStatus.CREATED.getKey()); - updateApplyPlan.setRobotName(listRebotVO.getRobotClientName()); - updateApplyPlan.setManualTime(applyPlan.getManualTime()); + updateApplyPlan.setRobotName(runRebotList.get(0).getRobotClientName()); + updateApplyPlan.setManualTime(runApplyPlan.getManualTime()); updateApplyPlan.setDeptId(applyStartBO.getDeptId()); - applyPlan.setTaskUuid(jobStartVO.getJobUuid()); + updateApplyPlan.setPlanParams(applyStartBO.getPlanParams()); + runApplyPlan.setTaskUuid(jobStartVO.getJobUuid()); if (this.saveOrUpdate(updateApplyPlan)) { - applyPlans.remove(0); + // 当前机器人已用,移除 + runRebotList.remove(0); i++; } } @@ -529,10 +757,39 @@ public class ApplyPlanServiceImpl extends ServiceImpl 0; } + /** + * 获取可执行机器人 + * + * @return list 返回可执行的机器人列表 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 @Transactional - public boolean save(AddApplyPlanBO addApplyPlanBO) { + public boolean save(AddApplyPlanBO addApplyPlanBO) throws ParseException { // 指定时间执行 if (addApplyPlanBO.getExcType().equals("1") && null == addApplyPlanBO.getExcTime()) { throw new ServiceException("指定时间执行时间不能为空"); @@ -557,6 +814,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/ApplyRebotServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyRebotServiceImpl.java new file mode 100644 index 0000000..b0caee8 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/ApplyRebotServiceImpl.java @@ -0,0 +1,87 @@ +package com.ruoyi.business.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.business.domain.*; +import com.ruoyi.business.domain.bo.ApplyStartBO; +import com.ruoyi.business.domain.bo.JobQueryBO; +import com.ruoyi.business.domain.bo.ListApplyBO; +import com.ruoyi.business.domain.bo.UpdateApplyRebotBO; +import com.ruoyi.business.domain.vo.JobQueryVO; +import com.ruoyi.business.domain.vo.JobStartVO; +import com.ruoyi.business.domain.vo.ListApplyVO; +import com.ruoyi.business.mapper.ApplyMapper; +import com.ruoyi.business.mapper.ApplyRebotMapper; +import com.ruoyi.business.service.IApplyPlanService; +import com.ruoyi.business.service.IApplyRebotService; +import com.ruoyi.business.service.IApplyService; +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.enums.PlanRunStatus; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.bean.BeanUtils; +import com.ruoyi.system.service.ISysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; + +/** + * 应用信息管理Service业务层处理 + * + * @author LiuChengRan + * @date 2024-06-13 + */ +@Service +public class ApplyRebotServiceImpl extends ServiceImpl implements IApplyRebotService { + + + + + /** + * 查询应用信息管理列表 + * + * @param applyRebot 应用信息管理 + * @return 应用信息管理 + */ + @Override + public List list(ApplyRebot applyRebot) { + LambdaQueryWrapper eq = new LambdaQueryWrapper().eq(ApplyRebot::getApplyId, applyRebot.getApplyId()); + return super.list(eq); + } + + /** + * 绑定机器人 + * @param updateApplyRebotBO + * @return + */ + @Override + @Transactional + public boolean updateApplyRebot(UpdateApplyRebotBO updateApplyRebotBO) { + this.remove(new LambdaQueryWrapper().eq(ApplyRebot::getApplyId,updateApplyRebotBO.getApplyId())); + if(updateApplyRebotBO.getOptRebot().isEmpty()){ + return true; + } + List applyRebots = new ArrayList<>(); + updateApplyRebotBO.getOptRebot().forEach(e->{ + ApplyRebot applyRebot = new ApplyRebot(); + applyRebot.setRebotName(e); + applyRebot.setApplyId(updateApplyRebotBO.getApplyId()); + applyRebots.add(applyRebot); + }); + return this.saveBatch(applyRebots); + } + + +} 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 318b45e..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 @@ -1,34 +1,39 @@ package com.ruoyi.business.service.impl; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.List; import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; -import com.ruoyi.business.domain.ApplyPlan; -import com.ruoyi.business.domain.Rebot; -import com.ruoyi.business.domain.ResourceLibrary; +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; import com.ruoyi.business.domain.bo.ListApplyBO; -import com.ruoyi.business.domain.bo.ListRebotBO; import com.ruoyi.business.domain.vo.JobQueryVO; import com.ruoyi.business.domain.vo.JobStartVO; import com.ruoyi.business.domain.vo.ListApplyVO; -import com.ruoyi.business.domain.vo.ListRebotVO; import com.ruoyi.business.service.IApplyPlanService; 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.utils.DateUtils; +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; import com.ruoyi.business.mapper.ApplyMapper; -import com.ruoyi.business.domain.Apply; import com.ruoyi.business.service.IApplyService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.transaction.annotation.Transactional; @@ -88,19 +93,24 @@ public class ApplyServiceImpl 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 +125,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 +158,52 @@ public class ApplyServiceImpl extends ServiceImpl implements */ @Override @DataScope(deptAlias = "apply") - public List list(Apply apply) { - return baseMapper.selectApplyList(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); + listApplyVOS.forEach(e -> { + // 根据appId获取执行计划 + List applyPlans = planMap.get(e.getAppId()); + // 应用没有设置时间 + if (null == applyPlans) { + return; + } + // 未设置人工用时则不统计节约时间 + if (null == e.getManualTime()) { + return; + } + // 总计节约时间 (分钟) + AtomicReference planTime = new AtomicReference<>(BigDecimal.ZERO); + applyPlans.forEach(plan -> { + // 如果是周期执行 + if ("2".equals(plan.getExcType())) { + // 获取执行日志 + List applyPlanLogs = planLogMap.get(e.getAppId()); + if(null == applyPlanLogs){ + return; + } + // 日志总计节约时间 + 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(new BigDecimal(e.getManualTime()).subtract(min))); + }); + planTime.set(planTime.get().add(logPlanTime.get())); + } else { + planTime.set(planTime.get().add(new BigDecimal(e.getManualTime()).subtract(new BigDecimal(plan.getPlanTime())))); + } + }); + e.setTimeSaving(planTime.get() + ""); + }); + return listApplyVOS; } /** @@ -163,4 +217,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())) { + // 计算节约时间 + double diff = Double.parseDouble(e.getManualTime()) - Double.parseDouble(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..f7c7b96 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 @@ -1,9 +1,6 @@ package com.ruoyi.business.service.impl; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; import com.ruoyi.business.domain.Apply; @@ -11,6 +8,7 @@ import com.ruoyi.business.domain.bo.AddBatchResourceLibraryBO; import com.ruoyi.business.service.IApplyService; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.business.mapper.ResourceLibraryMapper; @@ -30,6 +28,27 @@ public class ResourceLibraryServiceImpl extends ServiceImpl resourceLibraries = new ArrayList<>(); + addBatchResourceLibraryBO.getList().forEach(e -> { + ResourceLibrary resourceLibrary = new ResourceLibrary(); + resourceLibrary.setId(e.getId()); + resourceLibrary.setResourceValue(e.getResourceValue()); + resourceLibrary.setUpdateBy(SecurityUtils.getUsername()); + resourceLibrary.setUpdateTime(new Date()); + 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..834078e 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,7 +55,13 @@ 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.setValue(SERVER_URL + e.getValue()); + e.setType("str"); + if (StringUtils.isNull(e.getValue()) || StringUtils.isBlank(e.getValue())) { + e.setValue(null); + }else{ + e.setValue(SERVER_URL + e.getValue()); + } } }).collect(Collectors.toList()); applyStartBO.setParams(newParamList); diff --git a/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml b/ruoyi-business/src/main/resources/mapper/business/ApplyMapper.xml index 84b1305..0ec0005 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,14 +81,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" apply.deleted - from ct_apply apply deleted = 0 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} 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..744a301 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,7 +102,8 @@ plan.time_saving, plan.dept_id, plan.dept_name, - plan.create_by, + plan.enabled, + 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, @@ -111,8 +114,6 @@ + + from ct_apply_rebot ar + + deleted = 0 + and version = #{applyId} + and rebot_name = #{rebotName} + + + + \ No newline at end of file diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java index 6854a2b..dd5b7ab 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/controller/BaseController.java @@ -86,7 +86,8 @@ public class BaseController rspData.setCode(HttpStatus.SUCCESS); rspData.setMsg("查询成功"); rspData.setRows(list); - rspData.setTotal(new PageInfo(list).getTotal()); + PageInfo pageInfo = new PageInfo(list); + rspData.setTotal(pageInfo.getTotal()); return rspData; } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java index 831bb83..e656e71 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java @@ -23,9 +23,9 @@ import com.ruoyi.common.utils.uuid.Seq; public class FileUploadUtils { /** - * 默认大小 50M + * 默认大小 200M */ - public static final long DEFAULT_MAX_SIZE = 50 * 1024 * 1024; + public static final long DEFAULT_MAX_SIZE = 200 * 1024 * 1024; /** * 默认的文件名最大长度 100 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); } /**