陈裕财 4 years ago
parent
commit
698fc6db09
  1. 78
      xm-core/src/main/java/com/xm/core/ctrl/XmTestPlanCaseController.java
  2. 18
      xm-core/src/main/java/com/xm/core/entity/ImportFromTestCaseVo.java
  3. 13
      xm-core/src/main/java/com/xm/core/service/XmTestPlanCaseService.java
  4. 7
      xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmTestPlanCaseMapper.xml

78
xm-core/src/main/java/com/xm/core/ctrl/XmTestPlanCaseController.java

@ -3,15 +3,22 @@ package com.xm.core.ctrl;
import com.mdp.core.entity.Tips;
import com.mdp.core.err.BizException;
import com.mdp.core.utils.RequestUtils;
import com.mdp.core.utils.ResponseHelper;
import com.mdp.mybatis.PageUtils;
import com.mdp.safe.client.entity.User;
import com.mdp.safe.client.utils.LoginUtils;
import com.mdp.swagger.ApiEntityParams;
import com.xm.core.entity.ImportFromTestCaseVo;
import com.xm.core.entity.XmTestCase;
import com.xm.core.entity.XmTestPlan;
import com.xm.core.entity.XmTestPlanCase;
import com.xm.core.service.XmTestCaseService;
import com.xm.core.service.XmTestPlanCaseService;
import com.xm.core.service.XmTestPlanService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
@ -39,6 +46,13 @@ public class XmTestPlanCaseController {
private XmTestPlanCaseService xmTestPlanCaseService;
@Autowired
private XmTestPlanService xmTestPlanService;
@Autowired
XmTestCaseService xmTestCaseService;
Map<String,Object> fieldsMap = toMap(new XmTestPlanCase());
@ -107,6 +121,70 @@ public class XmTestPlanCaseController {
return m;
}
@ApiOperation( value = "从用例库导入用例列表到测试计划中",notes=" ")
@ApiResponses({
@ApiResponse(code = 200,response=XmTestPlanCase.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}")
})
@RequestMapping(value="/importFromTestCase",method=RequestMethod.POST)
public Map<String,Object> importFromTestCase(@RequestBody ImportFromTestCaseVo importFromTestCaseVo) {
Map<String,Object> m = new HashMap<>();
Tips tips=new Tips("成功新增一条数据");
try{
if(importFromTestCaseVo.getCaseIds()==null || importFromTestCaseVo.getCaseIds().size()==0){
return ResponseHelper.failed("caseIds-0","测试用例编号不能为空");
}
if(!StringUtils.hasText(importFromTestCaseVo.getPlanId())){
return ResponseHelper.failed("planId-0","测试计划编号不能为空");
}
List<XmTestCase> casesDb=xmTestCaseService.selectListByIds(importFromTestCaseVo.getCaseIds());
if(casesDb==null || casesDb.size()<=0){
return ResponseHelper.failed("cases-0","测试用例不存在");
}
XmTestPlan xmTestPlanDb=this.xmTestPlanService.selectOneById(importFromTestCaseVo.getPlanId());
if(xmTestPlanDb==null){
return ResponseHelper.failed("testPlan-0","测试计划不存在");
}
if("2".equals(xmTestPlanDb.getStatus())){
return ResponseHelper.failed("status-2","测试计划已结束");
}
//过滤掉已存在的测试用例 同一个用例不能重复添加到同一个计划中
List<XmTestPlanCase> planCasesDb=this.xmTestPlanCaseService.selectListByCaseIdsAndPlanId(importFromTestCaseVo.getPlanId(),importFromTestCaseVo.getCaseIds() );
if(planCasesDb!=null && planCasesDb.size()>0){
casesDb=casesDb.stream().filter(k->!planCasesDb.stream().filter(i->i.getCaseId().equals(k.getId())).findAny().isPresent()).collect(Collectors.toList());
}
if(casesDb.size()>0){
User user=LoginUtils.getCurrentUserInfo();
List<XmTestPlanCase> planCases=new ArrayList<>();
for (XmTestCase xmTestCase : casesDb) {
XmTestPlanCase xmTestPlanCase=new XmTestPlanCase();
BeanUtils.copyProperties(xmTestCase,xmTestPlanCase);
xmTestPlanCase.setPlanId(xmTestPlanDb.getId());
xmTestPlanCase.setBugs(0);
xmTestPlanCase.setExecStatus("0");
xmTestPlanCase.setCaseId(xmTestCase.getId());
xmTestPlanCase.setCaseName(xmTestCase.getCaseName());
xmTestPlanCase.setCtime(new Date());
xmTestPlanCase.setLtime(new Date());
xmTestPlanCase.setExecUserid(user.getUserid());
xmTestPlanCase.setExecUsername(user.getUsername());
xmTestPlanCase.setPriority("0");
planCases.add(xmTestPlanCase);
}
this.xmTestPlanCaseService.batchInsert(planCases);
}
}catch (BizException e) {
tips=e.getTips();
logger.error("",e);
}catch (Exception e) {
tips.setFailureMsg(e.getMessage());
logger.error("",e);
}
m.put("tips", tips);
return m;
}
@ApiOperation( value = "删除一条测试计划与用例关系表信息",notes=" ")
@ApiResponses({
@ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}")

18
xm-core/src/main/java/com/xm/core/entity/ImportFromTestCaseVo.java

@ -0,0 +1,18 @@
package com.xm.core.entity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
@ApiModel("从用例库导入测试用例到测试计划")
public class ImportFromTestCaseVo {
@ApiModelProperty(notes="需要导入的用例编号列表",allowEmptyValue=true,example="",allowableValues="")
List<String> caseIds;
@ApiModelProperty(notes="测试计划编号",allowEmptyValue=true,example="",allowableValues="")
String planId;
}

13
xm-core/src/main/java/com/xm/core/service/XmTestPlanCaseService.java

@ -1,16 +1,12 @@
package com.xm.core.service;
import com.mdp.core.service.BaseService;
import com.xm.core.entity.XmTestPlanCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.mdp.core.service.BaseService;
import static com.mdp.core.utils.BaseUtils.*;
import com.mdp.core.entity.Tips;
import com.mdp.core.err.BizException;
import com.xm.core.entity.XmTestPlanCase;
import java.util.List;
/**
* 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.<br>
* 组织 com 顶级模块 xm 大模块 core 小模块 <br>
@ -20,5 +16,8 @@ import com.xm.core.entity.XmTestPlanCase;
public class XmTestPlanCaseService extends BaseService {
static Logger logger =LoggerFactory.getLogger(XmTestPlanCaseService.class);
public List<XmTestPlanCase> selectListByCaseIdsAndPlanId(String planId, List<String> caseIds) {
return super.selectList("selectListByCaseIdsAndPlanId",map("planId",planId,"caseIds",caseIds));
}
}

7
xm-core/src/main/resources/mybatis/mapper/xm/core/dao/XmTestPlanCaseMapper.xml

@ -14,6 +14,13 @@
<if test="key != null and key !='' "> </if>
</sql>
<select id="selectListByCaseIdsAndPlanId" parameterType="HashMap">
select * from xm_test_plan_case res where res.plan_id=#{planId} and res.case_id in
<foreach collection="caseIds" item="item" index="index" open="(" separator="," close=")" >
#{item}
</foreach>
</select>
<!--结束 自定义sql函数区域-->

Loading…
Cancel
Save