whyczh
2021-04-07 284c3e1a5474eddec29f6c2debdab4253269cdf8
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whyc.dto.Response;
import com.whyc.mapper.TestPlanMapper;
import com.whyc.pojo.TestPlan;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
 
@Service
@Slf4j
public class TestPlanService {
    @Resource
    private TestPlanMapper mapper;
 
    public Response add(TestPlan testPlan){
        testPlan.setCreator("admin");
        testPlan.setCreateTime(new Date());
        testPlan.setState(0);//试验状态:未开始
        mapper.insert(testPlan);
        return new Response().setMsg(1,"添加成功");
    }
 
    public Response update(TestPlan testPlan){
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"修改成功");
    }
 
    public Response getOne(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        return new Response().set(1,testPlan);
    }
    public TestPlan getOneById(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        return testPlan;
    }
 
    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){
        QueryWrapper<TestPlan> wrapper = Wrappers.query();
        IPage<TestPlan> page = mapper.selectPage(new Page<>(pageNum,pageSize),wrapper);
        return new Response<IPage<TestPlan>>().set(1,page);
    }
 
    public Response<IPage<TestPlan>> getPageByCondition(int pageNum, int pageSize, TestPlan testPlan){
        QueryWrapper<TestPlan> queryWrapper = new QueryWrapper<>(testPlan);
        //去除已废止的计划
        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);
 
    }
}