whycxzp
2021-03-25 61cb431c730137fca0e68203993df14bf6d2cc15
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
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.DeviceManageMapper;
import com.whyc.pojo.DeviceManage;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class DeviceManageService {
 
    @Resource
    private DeviceManageMapper mapper;
 
    public Response add(DeviceManage deviceManage) {
        //新增入库
        deviceManage.setStatus((byte) 1);
        mapper.insert(deviceManage);
        return new Response().setMsg(1,"添加成功");
    }
 
    public Response delete(Integer deviceId) {
        //逻辑删除,更改状态为0
        UpdateWrapper<DeviceManage> wrapper = Wrappers.update();
        wrapper.set("status",0).eq("device_id",deviceId);
        int update = mapper.update(null, wrapper);
        return new Response().setMsg(1,"出库报废成功");
    }
 
    public Response update(DeviceManage deviceManage) {
        mapper.updateById(deviceManage);
        return new Response().setMsg(1,"修改成功");
    }
 
    public Response<IPage<DeviceManage>> getAll(int pageNum,int pageSize) {
        QueryWrapper<DeviceManage> wrapper = Wrappers.query();
        wrapper.eq("status",1);
        IPage<DeviceManage> page1 = mapper.selectPage(new Page<>(pageNum,pageSize), wrapper);
        return new Response<IPage<DeviceManage>>().set(1,page1);
    }
}