chen.lin
7 小时以前 9f724c61dfa4dc4c0eea66253ea0780b023622ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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<String, Object> 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<String, Object> 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("复制失败!");
        }
    }
}