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(-1); 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 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> getAll(int pageNum,int pageSize){ QueryWrapper wrapper = Wrappers.query(); IPage page = mapper.selectPage(new Page<>(pageNum,pageSize),wrapper); return new Response>().set(1,page); } public Response> getPageByCondition(int pageNum, int pageSize, TestPlan testPlan){ QueryWrapper queryWrapper = new QueryWrapper<>(testPlan); //去除已废止的计划 queryWrapper.in("state",0,1,2); IPage page = mapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper); return new Response>().set(1,page); } public Response> getConclusion(int pageNum, int pageSize, TestPlan testPlan){ QueryWrapper queryWrapper = new QueryWrapper<>(testPlan); //6、8为结果审核状态,2:计划已结束,结论未审核 queryWrapper.in("state",2,6,8); IPage page = mapper.selectPage(new Page<>(pageNum,pageSize),queryWrapper); return new Response>().set(1,page); } }