package com.vincent.rsf.server.manager.controller; import com.vincent.rsf.framework.common.R; import com.vincent.rsf.server.common.annotation.OperationLog; import com.vincent.rsf.server.manager.controller.params.RcsTestParams; import com.vincent.rsf.server.manager.entity.RcsTestConfig; import com.vincent.rsf.server.manager.entity.RcsTestPlan; import com.vincent.rsf.server.manager.service.RcsTestService; import com.vincent.rsf.server.manager.service.RcsTestPlanService; import com.vincent.rsf.server.system.controller.BaseController; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Map; import java.util.Objects; @RestController @RequestMapping("/rcs/test") @Api(tags = "RCS自动测试") public class RcsTestController extends BaseController { @Autowired private RcsTestService rcsTestService; @Autowired private RcsTestPlanService rcsTestPlanService; /** * 执行RCS全流程自动测试 */ @ApiOperation("执行RCS全流程自动测试") @OperationLog("执行RCS全流程自动测试") @PostMapping("/execute") public R executeTest(@RequestBody RcsTestParams params) { if (Objects.isNull(params)) { return R.error("参数不能为空!!"); } // 出库测试不需要物料编号,只有入库测试或全流程测试才需要物料编号 // 如果 autoOutbound 为 true 且没有物料编号,说明是纯出库测试,允许通过 if ((params.getMatnrCodes() == null || params.getMatnrCodes().isEmpty()) && (params.getAutoOutbound() == null || !params.getAutoOutbound())) { return R.error("物料编号组不能为空!!"); } Long userId = getLoginUserId(); if (userId == null) { userId = 1L; // 默认用户ID } return rcsTestService.executeRcsTest(params, userId); } /** * 保存测试配置 */ @ApiOperation("保存测试配置") @OperationLog("保存测试配置") @PostMapping("/config/save") public R saveConfig(@RequestBody RcsTestConfig config) { if (Objects.isNull(config)) { return R.error("参数不能为空!!"); } Long userId = getLoginUserId(); if (userId == null) { userId = 1L; // 默认用户ID } if (config.getId() == null) { config.setCreateBy(userId); } else { config.setUpdateBy(userId); } return rcsTestService.saveOrUpdate(config) ? R.ok() : R.error("保存失败!"); } /** * 查询测试配置列表 */ @ApiOperation("查询测试配置列表") @PostMapping("/config/list") public R listConfig(@RequestBody Map params) { return R.ok().add(rcsTestService.list()); } /** * 删除测试配置 */ @ApiOperation("删除测试配置") @OperationLog("删除测试配置") @PostMapping("/config/delete/{id}") public R deleteConfig(@PathVariable Long id) { return rcsTestService.removeById(id) ? R.ok() : R.error("删除失败!"); } /** * 保存测试计划(JMeter风格) */ @ApiOperation("保存测试计划") @OperationLog("保存测试计划") @PostMapping("/plan/save") public R savePlan(@RequestBody RcsTestPlan plan) { if (Objects.isNull(plan)) { return R.error("参数不能为空!!"); } if (Objects.isNull(plan.getPlanName()) || plan.getPlanName().trim().isEmpty()) { return R.error("测试计划名称不能为空!!"); } if (Objects.isNull(plan.getPlanData()) || plan.getPlanData().trim().isEmpty()) { return R.error("测试计划数据不能为空!!"); } Long userId = getLoginUserId(); if (userId == null) { userId = 1L; // 默认用户ID } Long tenantId = getTenantId(); if (plan.getId() == null) { plan.setCreateBy(userId); plan.setTenantId(tenantId); } else { plan.setUpdateBy(userId); } boolean result = rcsTestPlanService.saveOrUpdate(plan); if (result) { return R.ok("保存成功!").add(plan); } else { return R.error("保存失败!"); } } /** * 查询测试计划列表 */ @ApiOperation("查询测试计划列表") @PostMapping("/plan/list") public R listPlan(@RequestBody Map params) { return R.ok().add(rcsTestPlanService.list()); } /** * 根据ID查询测试计划详情 */ @ApiOperation("查询测试计划详情") @GetMapping("/plan/{id}") public R getPlan(@PathVariable Long id) { RcsTestPlan plan = rcsTestPlanService.getById(id); if (plan == null) { return R.error("测试计划不存在!"); } return R.ok().add(plan); } /** * 删除测试计划 */ @ApiOperation("删除测试计划") @OperationLog("删除测试计划") @PostMapping("/plan/delete/{id}") public R deletePlan(@PathVariable Long id) { return rcsTestPlanService.removeById(id) ? R.ok("删除成功!") : R.error("删除失败!"); } /** * 复制测试计划 */ @ApiOperation("复制测试计划") @OperationLog("复制测试计划") @PostMapping("/plan/copy/{id}") public R copyPlan(@PathVariable Long id) { RcsTestPlan sourcePlan = rcsTestPlanService.getById(id); if (sourcePlan == null) { return R.error("源测试计划不存在!"); } RcsTestPlan newPlan = new RcsTestPlan(); newPlan.setPlanName(sourcePlan.getPlanName() + "_副本"); newPlan.setPlanDescription(sourcePlan.getPlanDescription()); newPlan.setPlanData(sourcePlan.getPlanData()); newPlan.setVersion(sourcePlan.getVersion()); newPlan.setStatus(1); Long userId = getLoginUserId(); if (userId == null) { userId = 1L; } Long tenantId = getTenantId(); newPlan.setCreateBy(userId); newPlan.setTenantId(tenantId); boolean result = rcsTestPlanService.save(newPlan); if (result) { return R.ok("复制成功!").add(newPlan); } else { return R.error("复制失败!"); } } }