whycxzp
2021-09-28 7d64716cb0d406f21cde03976fd273bd07fdc06f
src/main/java/com/whyc/service/TestPlanService.java
@@ -2,21 +2,16 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.TestPlanMapper;
import com.whyc.pojo.DeviceManage;
import com.whyc.pojo.TestPlan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
@Slf4j
@@ -28,6 +23,7 @@
        testPlan.setCreator("admin");
        testPlan.setCreateTime(new Date());
        testPlan.setState(0);//试验状态:未开始
        testPlan.setTestCount(0);//测试测试默认为0
        mapper.insert(testPlan);
        return new Response().setMsg(1,"添加成功");
    }
@@ -48,12 +44,57 @@
    public Response startPlan(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        //获取计划重复次数
        int planCount = 0;
        int testCount = 0;
        if (testPlan.getPlanCount()!=null){
            planCount = testPlan.getPlanCount();
        }
        if (testPlan.getTestCount()!=null){
            testCount= testPlan.getTestCount();
        }
        if (planCount!=0 && testCount==planCount){
            return new Response().setMsg(0,"已达到计划重复次数最大值");
        }
        testPlan.setState(1);
        testPlan.setTestCount(++testCount);
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"启动成功");
    }
    public Response deletePlan(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        testPlan.setState(-1);
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"删除作废成功");
    }
    public Response stopPlan(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        //获取计划重复次数
        int planCount = testPlan.getPlanCount();
        int testCount = testPlan.getTestCount();
        if (planCount!=0 && testCount==planCount){
            testPlan.setState(3);//已结束
            int k = (int)(Math.random()*2);
            if (k==1){
                testPlan.setConclusion("合格");
            }else{
                testPlan.setConclusion("不合格");
            }
        }else {
            testPlan.setState(2);//已停止
        }
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"停止成功");
    }
    public Response verifiedPlan(Integer num,String verifier){
        TestPlan testPlan = mapper.selectById(num);
        testPlan.setState(6);
        testPlan.setVerifier(verifier);
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"审核成功");
    }
    public Response<IPage<TestPlan>> getAll(int pageNum,int pageSize){
@@ -64,7 +105,17 @@
    public Response<IPage<TestPlan>> getPageByCondition(int pageNum, int pageSize, TestPlan testPlan){
        QueryWrapper<TestPlan> queryWrapper = new QueryWrapper<>(testPlan);
        List<TestPlan> testPlanList = mapper.selectList(queryWrapper);
        //去除已废止的计划
        queryWrapper.in("state",0,1,2,3,6,8);
        IPage<TestPlan> page = mapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper);
        return new Response<IPage<TestPlan>>().set(1,page);
    }
    public Response<IPage<TestPlan>> getConclusion(int pageNum, int pageSize, TestPlan testPlan){
        QueryWrapper<TestPlan> queryWrapper = new QueryWrapper<>(testPlan);
        //6、8为结果审核状态,2:计划已结束,结论未审核
        queryWrapper.in("state",3,6,8);
        IPage<TestPlan> page = mapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper);
        return new Response<IPage<TestPlan>>().set(1,page);