0627 ljc 测试用例管理模块代码编写
This commit is contained in:
parent
a5e2e070a0
commit
5213621a1e
@ -53,7 +53,7 @@ public class TestCaseInfoController {
|
|||||||
@PostMapping(path="/update")
|
@PostMapping(path="/update")
|
||||||
public CommonResult<Void> update(@RequestBody @NotNull @Valid TestCaseInfoReq req){
|
public CommonResult<Void> update(@RequestBody @NotNull @Valid TestCaseInfoReq req){
|
||||||
|
|
||||||
testCaseInfoService.updateTestCase(req);
|
testCaseInfoService.updateTestCaseInfo(req);
|
||||||
|
|
||||||
return CommonResult.success();
|
return CommonResult.success();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,88 @@
|
|||||||
|
package cd.casic.ci.api;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.testCase.TestCaseManagerResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.base.BaseIdReq;
|
||||||
|
import cd.casic.ci.process.process.service.testCase.TestCaseManagerService;
|
||||||
|
import cd.casic.framework.commons.pojo.CommonResult;
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import com.jcraft.jsch.JSchException;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ResourceController
|
||||||
|
* @Author hopeli
|
||||||
|
* @Date 2025/5/10 10:57
|
||||||
|
* @Version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/testCaseManager")
|
||||||
|
public class TestCaseManagerController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestCaseManagerService testCaseManagerService;
|
||||||
|
|
||||||
|
@PostMapping(path="/create")
|
||||||
|
public CommonResult<String> create(@RequestBody @Valid TestCaseManagerReq req){
|
||||||
|
|
||||||
|
String id = testCaseManagerService.create(req);
|
||||||
|
|
||||||
|
return CommonResult.success(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/delete")
|
||||||
|
public CommonResult<Void> delete(@RequestBody @Valid BaseIdReq req) throws JSchException, InterruptedException {
|
||||||
|
|
||||||
|
testCaseManagerService.delete(req.getId());
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/update")
|
||||||
|
public CommonResult<Void> update(@RequestBody @NotNull @Valid TestCaseManagerReq req){
|
||||||
|
|
||||||
|
testCaseManagerService.updateTestCaseManager(req);
|
||||||
|
|
||||||
|
return CommonResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findList")
|
||||||
|
public CommonResult<List<TestCaseManagerResp>> findList(@RequestBody @Valid TestCaseManagerQueryReq query){
|
||||||
|
|
||||||
|
List<TestCaseManagerResp> respList = testCaseManagerService.findList(query);
|
||||||
|
|
||||||
|
return CommonResult.success(respList);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findPage")
|
||||||
|
public CommonResult<PageResult<TestCaseManagerResp>> findResourcePage(@RequestBody @NotNull @Valid TestCaseManagerQueryReq query){
|
||||||
|
|
||||||
|
PageResult<TestCaseManagerResp> respPage = testCaseManagerService.findPage(query);
|
||||||
|
return CommonResult.success(respPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping(path="/findById")
|
||||||
|
public CommonResult<TestCaseManagerResp> findById(@RequestBody @Valid BaseIdReq req){
|
||||||
|
|
||||||
|
TestCaseManagerResp resp = testCaseManagerService.findById(req.getId());
|
||||||
|
|
||||||
|
return CommonResult.success(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -13,6 +13,8 @@ public class TestCaseInfoQueryReq extends PageParam {
|
|||||||
|
|
||||||
private List<String> idList;
|
private List<String> idList;
|
||||||
|
|
||||||
|
private String testCaseManagerId;
|
||||||
|
|
||||||
// 测试用例名称
|
// 测试用例名称
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import lombok.Data;
|
|||||||
public class TestCaseInfoReq {
|
public class TestCaseInfoReq {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
private String testCaseManagerId;
|
||||||
|
|
||||||
// 测试用例名称
|
// 测试用例名称
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.testCase;
|
||||||
|
|
||||||
|
import cd.casic.framework.commons.pojo.PageParam;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class TestCaseManagerQueryReq extends PageParam {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private List<String> idList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹路径,用于统一上传文件地址
|
||||||
|
*/
|
||||||
|
private String folderPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package cd.casic.ci.process.dto.req.testCase;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TestCaseManagerReq {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹路径,用于统一上传文件地址
|
||||||
|
*/
|
||||||
|
private String folderPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
}
|
@ -8,6 +8,8 @@ import java.time.LocalDateTime;
|
|||||||
public class TestCaseInfoResp {
|
public class TestCaseInfoResp {
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
|
private String testCaseManagerId;
|
||||||
|
|
||||||
// 测试用例名称
|
// 测试用例名称
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package cd.casic.ci.process.dto.resp.testCase;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TestCaseManagerResp {
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹路径,用于统一上传文件地址
|
||||||
|
*/
|
||||||
|
private String folderPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
//创建人id
|
||||||
|
private String creator;
|
||||||
|
|
||||||
|
//创建人姓名
|
||||||
|
private String creatorName;
|
||||||
|
|
||||||
|
//最后修改人id
|
||||||
|
private String updater;
|
||||||
|
|
||||||
|
//最后修改人姓名
|
||||||
|
private String updaterName;
|
||||||
|
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,8 @@ import cd.casic.ci.process.dto.req.testCase.TestCaseInfoReq;
|
|||||||
import cd.casic.ci.process.dto.resp.testCase.TestCaseInfoResp;
|
import cd.casic.ci.process.dto.resp.testCase.TestCaseInfoResp;
|
||||||
import cd.casic.ci.process.process.dataObject.testCase.TestCaseInfo;
|
import cd.casic.ci.process.process.dataObject.testCase.TestCaseInfo;
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.MappingTarget;
|
||||||
|
import org.mapstruct.NullValuePropertyMappingStrategy;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -15,7 +17,7 @@ import java.util.List;
|
|||||||
* @Date: 2025/5/13 14:39
|
* @Date: 2025/5/13 14:39
|
||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
@Mapper(componentModel = "spring")
|
@Mapper(componentModel = "spring",nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||||
public interface TestCaseInfoConverter {
|
public interface TestCaseInfoConverter {
|
||||||
TestCaseInfoConverter INSTANCE = Mappers.getMapper(TestCaseInfoConverter.class);
|
TestCaseInfoConverter INSTANCE = Mappers.getMapper(TestCaseInfoConverter.class);
|
||||||
|
|
||||||
@ -24,4 +26,6 @@ public interface TestCaseInfoConverter {
|
|||||||
List<TestCaseInfoResp> toRespList(List<TestCaseInfo> testCaseInfos);
|
List<TestCaseInfoResp> toRespList(List<TestCaseInfo> testCaseInfos);
|
||||||
|
|
||||||
TestCaseInfoResp toResp(TestCaseInfo testCaseInfo);
|
TestCaseInfoResp toResp(TestCaseInfo testCaseInfo);
|
||||||
|
|
||||||
|
void updateReqCopyToBean(TestCaseInfoReq req, @MappingTarget TestCaseInfo testCaseInfo);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package cd.casic.ci.process.process.converter;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.testCase.TestCaseManagerResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.testCase.TestCaseManager;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.MappingTarget;
|
||||||
|
import org.mapstruct.NullValuePropertyMappingStrategy;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName PipelineConverter
|
||||||
|
* @Date: 2025/5/13 14:39
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Mapper(componentModel = "spring",nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE)
|
||||||
|
public interface TestCaseManagerConverter {
|
||||||
|
TestCaseManagerConverter INSTANCE = Mappers.getMapper(TestCaseManagerConverter.class);
|
||||||
|
|
||||||
|
TestCaseManager toBean(TestCaseManagerReq req);
|
||||||
|
|
||||||
|
void updateReqCopyToBean(TestCaseManagerReq req, @MappingTarget TestCaseManager testCaseManager);
|
||||||
|
|
||||||
|
List<TestCaseManagerResp> toRespList(List<TestCaseManager> testCaseManagers);
|
||||||
|
|
||||||
|
TestCaseManagerResp toResp(TestCaseManager testCaseManager);
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package cd.casic.ci.process.process.dao.testCase;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.process.dataObject.testCase.TestCaseManager;
|
||||||
|
import cd.casic.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName PipelineDao
|
||||||
|
* @Date: 2025/5/13 14:39
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public interface TestCaseManagerDao extends BaseMapperX<TestCaseManager>, BaseMapper<TestCaseManager> {
|
||||||
|
}
|
@ -17,6 +17,8 @@ import lombok.EqualsAndHashCode;
|
|||||||
@TableName("test_case_info")
|
@TableName("test_case_info")
|
||||||
public class TestCaseInfo extends PipBaseElement {
|
public class TestCaseInfo extends PipBaseElement {
|
||||||
|
|
||||||
|
private String testCaseManagerId;
|
||||||
|
|
||||||
// 测试用例名称
|
// 测试用例名称
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package cd.casic.ci.process.process.dataObject.testCase;
|
||||||
|
|
||||||
|
import cd.casic.ci.process.process.dataObject.base.PipBaseElement;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName TestCaseInfo
|
||||||
|
* @Date: 2025/6/24 16:40
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("test_case_info")
|
||||||
|
public class TestCaseManager extends PipBaseElement {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理名称
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试用例管理类型
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文件夹路径,用于统一上传文件地址
|
||||||
|
*/
|
||||||
|
private String folderPath;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
}
|
@ -24,7 +24,7 @@ public interface TestCaseInfoService extends IService<TestCaseInfo> {
|
|||||||
|
|
||||||
void delete(String id);
|
void delete(String id);
|
||||||
|
|
||||||
void updateTestCase(@Valid TestCaseInfoReq req);
|
void updateTestCaseInfo(@Valid TestCaseInfoReq req);
|
||||||
|
|
||||||
List<TestCaseInfoResp> findList(@Valid TestCaseInfoQueryReq query);
|
List<TestCaseInfoResp> findList(@Valid TestCaseInfoQueryReq query);
|
||||||
|
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
package cd.casic.ci.process.process.service.testCase;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.testCase.TestCaseManagerResp;
|
||||||
|
import cd.casic.ci.process.process.dataObject.testCase.TestCaseManager;
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.jcraft.jsch.JSchException;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName PipelineService
|
||||||
|
* @Date: 2025/5/13 10:27
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
public interface TestCaseManagerService extends IService<TestCaseManager> {
|
||||||
|
|
||||||
|
String create(@Valid TestCaseManagerReq req);
|
||||||
|
|
||||||
|
void delete(String id) throws JSchException, InterruptedException;
|
||||||
|
|
||||||
|
void updateTestCaseManager(@Valid TestCaseManagerReq req);
|
||||||
|
|
||||||
|
List<TestCaseManagerResp> findList(@Valid TestCaseManagerQueryReq query);
|
||||||
|
|
||||||
|
PageResult<TestCaseManagerResp> findPage(@Valid TestCaseManagerQueryReq query);
|
||||||
|
|
||||||
|
TestCaseManagerResp findById(String id);
|
||||||
|
|
||||||
|
}
|
@ -52,20 +52,36 @@ public class TestCaseInfoServiceImpl extends ServiceImpl<TestCaseInfoDao, TestCa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(String id) {
|
public void delete(String id) {
|
||||||
|
TestCaseInfo testCaseInfo = testCaseInfoDao.selectById(id);
|
||||||
|
if (ObjectUtils.isEmpty(testCaseInfo)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"数据错误请联系管理员");
|
||||||
|
}
|
||||||
testCaseInfoDao.deleteById(id);
|
testCaseInfoDao.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTestCase(TestCaseInfoReq req) {
|
public void updateTestCaseInfo(TestCaseInfoReq req) {
|
||||||
TestCaseInfo testCaseInfo = TestCaseInfoConverter.INSTANCE.toBean(req);
|
TestCaseInfo testCaseInfo = testCaseInfoDao.selectById(req.getId());
|
||||||
|
if (ObjectUtils.isEmpty(testCaseInfo)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"数据错误请联系管理员");
|
||||||
|
}
|
||||||
|
|
||||||
|
TestCaseInfoConverter.INSTANCE.updateReqCopyToBean(req,testCaseInfo);
|
||||||
testCaseInfoDao.updateById(testCaseInfo);
|
testCaseInfoDao.updateById(testCaseInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TestCaseInfoResp> findList(TestCaseInfoQueryReq query) {
|
public List<TestCaseInfoResp> findList(TestCaseInfoQueryReq query) {
|
||||||
QueryWrapper<TestCaseInfo> wrapper = new QueryWrapper<>();
|
QueryWrapper<TestCaseInfo> wrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getTestFileType())){
|
||||||
|
wrapper.eq("test_file_type", query.getTestFileType());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(query.getTestCaseManagerId())){
|
||||||
|
wrapper.eq("test_case_manager_id", query.getTestCaseManagerId());
|
||||||
|
}
|
||||||
List<TestCaseInfo> testCaseInfos = testCaseInfoDao.selectList(wrapper);
|
List<TestCaseInfo> testCaseInfos = testCaseInfoDao.selectList(wrapper);
|
||||||
|
|
||||||
|
|
||||||
if (ObjectUtils.isEmpty(testCaseInfos)){
|
if (ObjectUtils.isEmpty(testCaseInfos)){
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
@ -82,6 +98,9 @@ public class TestCaseInfoServiceImpl extends ServiceImpl<TestCaseInfoDao, TestCa
|
|||||||
if (!StringUtils.isEmpty(query.getTestFileType())){
|
if (!StringUtils.isEmpty(query.getTestFileType())){
|
||||||
wrapper.eq("test_file_type", query.getTestFileType());
|
wrapper.eq("test_file_type", query.getTestFileType());
|
||||||
}
|
}
|
||||||
|
if (!StringUtils.isEmpty(query.getTestCaseManagerId())){
|
||||||
|
wrapper.eq("test_case_manager_id", query.getTestCaseManagerId());
|
||||||
|
}
|
||||||
Page<TestCaseInfo> testCaseInfoPage = testCaseInfoDao.selectPage(new Page<>(query.getPageNo(), query.getPageSize()), wrapper);
|
Page<TestCaseInfo> testCaseInfoPage = testCaseInfoDao.selectPage(new Page<>(query.getPageNo(), query.getPageSize()), wrapper);
|
||||||
if (ObjectUtils.isEmpty(testCaseInfoPage)){
|
if (ObjectUtils.isEmpty(testCaseInfoPage)){
|
||||||
return new PageResult<>();
|
return new PageResult<>();
|
||||||
|
@ -0,0 +1,185 @@
|
|||||||
|
package cd.casic.ci.process.process.service.testCase.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerQueryReq;
|
||||||
|
import cd.casic.ci.process.dto.req.testCase.TestCaseManagerReq;
|
||||||
|
import cd.casic.ci.process.dto.resp.testCase.TestCaseManagerResp;
|
||||||
|
import cd.casic.ci.process.process.converter.TestCaseManagerConverter;
|
||||||
|
import cd.casic.ci.process.process.dao.testCase.TestCaseManagerDao;
|
||||||
|
import cd.casic.ci.process.process.dataObject.testCase.TestCaseManager;
|
||||||
|
import cd.casic.ci.process.process.service.testCase.TestCaseManagerService;
|
||||||
|
import cd.casic.ci.process.properties.TargetFileUploadProperties;
|
||||||
|
import cd.casic.framework.commons.exception.ServiceException;
|
||||||
|
import cd.casic.framework.commons.exception.enums.GlobalErrorCodeConstants;
|
||||||
|
import cd.casic.framework.commons.pojo.PageResult;
|
||||||
|
import cd.casic.framework.security.dal.user.AdminUserDO;
|
||||||
|
import cd.casic.framework.tenant.core.service.AdminUserServiceImpl;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.jcraft.jsch.ChannelExec;
|
||||||
|
import com.jcraft.jsch.JSch;
|
||||||
|
import com.jcraft.jsch.JSchException;
|
||||||
|
import com.jcraft.jsch.Session;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author HopeLi
|
||||||
|
* @version v1.0
|
||||||
|
* @ClassName PipelineServiceImpl
|
||||||
|
* @Date: 2025/5/13 10:31
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class TestCaseManagerServiceImpl extends ServiceImpl<TestCaseManagerDao, TestCaseManager> implements TestCaseManagerService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TestCaseManagerDao testCaseManagerDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminUserServiceImpl adminUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TargetFileUploadProperties fileUploadProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String create(TestCaseManagerReq req) {
|
||||||
|
TestCaseManager testCaseManager = TestCaseManagerConverter.INSTANCE.toBean(req);
|
||||||
|
testCaseManagerDao.insert(testCaseManager);
|
||||||
|
return testCaseManager.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void delete(String id) throws JSchException, InterruptedException {
|
||||||
|
TestCaseManager testCaseManager = testCaseManagerDao.selectById(id);
|
||||||
|
if (ObjectUtils.isEmpty(testCaseManager)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"数据错误请联系管理员");
|
||||||
|
}
|
||||||
|
testCaseManagerDao.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTestCaseManager(TestCaseManagerReq req) {
|
||||||
|
TestCaseManager testCaseManager = testCaseManagerDao.selectById(req.getId());
|
||||||
|
if (ObjectUtils.isEmpty(testCaseManager)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"数据错误请联系管理员");
|
||||||
|
}
|
||||||
|
TestCaseManagerConverter.INSTANCE.updateReqCopyToBean(req,testCaseManager);
|
||||||
|
testCaseManagerDao.updateById(testCaseManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<TestCaseManagerResp> findList(TestCaseManagerQueryReq query) {
|
||||||
|
QueryWrapper<TestCaseManager> wrapper = new QueryWrapper<>();
|
||||||
|
List<TestCaseManager> testCaseManagers = testCaseManagerDao.selectList(wrapper);
|
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(testCaseManagers)){
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
List<TestCaseManagerResp> respList = TestCaseManagerConverter.INSTANCE.toRespList(testCaseManagers);
|
||||||
|
respList.forEach(this::setUserName);
|
||||||
|
return respList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<TestCaseManagerResp> findPage(TestCaseManagerQueryReq query) {
|
||||||
|
QueryWrapper<TestCaseManager> wrapper = new QueryWrapper<>();
|
||||||
|
if (!StringUtils.isEmpty(query.getName())){
|
||||||
|
wrapper.like("name", query.getName());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(query.getType())){
|
||||||
|
wrapper.eq("type", query.getType());
|
||||||
|
}
|
||||||
|
Page<TestCaseManager> testCaseManagerPage = testCaseManagerDao.selectPage(new Page<>(query.getPageNo(), query.getPageSize()), wrapper);
|
||||||
|
if (ObjectUtils.isEmpty(testCaseManagerPage)){
|
||||||
|
return new PageResult<>();
|
||||||
|
}
|
||||||
|
List<TestCaseManagerResp> respList = TestCaseManagerConverter.INSTANCE.toRespList(testCaseManagerPage.getRecords());
|
||||||
|
respList.forEach(this::setUserName);
|
||||||
|
return new PageResult<>(respList,testCaseManagerPage.getTotal(),testCaseManagerPage.getCurrent(),testCaseManagerPage.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TestCaseManagerResp findById(String id) {
|
||||||
|
TestCaseManager testCaseManager = testCaseManagerDao.selectById(id);
|
||||||
|
if (ObjectUtils.isEmpty(testCaseManager)){
|
||||||
|
throw new ServiceException(GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR.getCode(),"数据错误请联系管理员");
|
||||||
|
}
|
||||||
|
TestCaseManagerResp testCaseManagerResp = TestCaseManagerConverter.INSTANCE.toResp(testCaseManager);
|
||||||
|
setUserName(testCaseManagerResp);
|
||||||
|
return testCaseManagerResp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void setUserName(TestCaseManagerResp testCaseManagerResp) {
|
||||||
|
if (!StringUtils.isEmpty(testCaseManagerResp.getCreator())){
|
||||||
|
AdminUserDO user = adminUserService.getUser(Long.valueOf(testCaseManagerResp.getCreator()));
|
||||||
|
if (!ObjectUtils.isEmpty(user)){
|
||||||
|
testCaseManagerResp.setCreatorName(user.getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(testCaseManagerResp.getUpdater())){
|
||||||
|
AdminUserDO user = adminUserService.getUser(Long.valueOf(testCaseManagerResp.getUpdater()));
|
||||||
|
if (!ObjectUtils.isEmpty(user)){
|
||||||
|
testCaseManagerResp.setUpdaterName(user.getUsername());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void deleteRemoteFolder(String folderPath) throws JSchException, InterruptedException {
|
||||||
|
JSch jsch = new JSch();
|
||||||
|
Session session = null;
|
||||||
|
ChannelExec channel = null;
|
||||||
|
String username = fileUploadProperties.getUsername();
|
||||||
|
String host = fileUploadProperties.getRemoteHost();
|
||||||
|
Integer port = 22;
|
||||||
|
String password = fileUploadProperties.getPassword();
|
||||||
|
|
||||||
|
try {
|
||||||
|
session = jsch.getSession(username, host, port);
|
||||||
|
session.setPassword(password);
|
||||||
|
|
||||||
|
// 设置首次登录不自动添加密钥
|
||||||
|
session.setConfig("StrictHostKeyChecking", "no");
|
||||||
|
session.connect();
|
||||||
|
|
||||||
|
// 构建删除命令(递归删除)
|
||||||
|
String command = String.format("rm -rf %s", folderPath);
|
||||||
|
|
||||||
|
channel = (ChannelExec) session.openChannel("exec");
|
||||||
|
channel.setCommand(command);
|
||||||
|
channel.setErrStream(System.err);
|
||||||
|
channel.connect();
|
||||||
|
|
||||||
|
// 等待命令执行完成
|
||||||
|
while (!channel.isClosed()) {
|
||||||
|
Thread.sleep(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (channel != null) {
|
||||||
|
channel.disconnect();
|
||||||
|
}
|
||||||
|
if (session != null) {
|
||||||
|
session.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,8 @@
|
|||||||
package cd.casic.ci.process.properties;
|
package cd.casic.ci.process.properties;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties(prefix = "target.file-upload")
|
@ConfigurationProperties(prefix = "target.file-upload")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user