whyczh
2021-03-30 82406b9bd125fea5265e8334841e7122a701e214
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
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.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
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);
        testPlan.setState(1);
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"启动成功");
    }
 
    public Response deletePlan(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        testPlan.setState(3);
        mapper.updateById(testPlan);
        return new Response().setMsg(1,"删除作废成功");
    }
    public Response stopPlan(Integer num){
        TestPlan testPlan = mapper.selectById(num);
        testPlan.setState(2);
        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);
        List<TestPlan> testPlanList = mapper.selectList(queryWrapper);
        IPage<TestPlan> page = mapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper);
        return new Response<IPage<TestPlan>>().set(1,page);
 
    }
}