whycxzp
2021-09-28 7d64716cb0d406f21cde03976fd273bd07fdc06f
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.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.DeviceMaintainDTO;
import com.whyc.dto.Response;
import com.whyc.mapper.DeviceMaintainMapper;
import com.whyc.pojo.DeviceMaintain;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
@Service
public class DeviceMaintainService {
 
    @Resource
    private DeviceMaintainMapper mapper;
 
    public Response get(Integer deviceId) {
        /*QueryWrapper<DeviceMaintain> wrapper = Wrappers.query();
        wrapper.eq("status",1).eq("is_plan",1).eq("device_id",deviceId);
        DeviceMaintain deviceMaintain = mapper.selectOne(wrapper);*/
        DeviceMaintain deviceMaintain = mapper.get(deviceId);
        return new Response().set(1,deviceMaintain);
    }
 
    public Response add(DeviceMaintain deviceMaintain) {
        mapper.insert(deviceMaintain);
        return new Response().set(1,"创建成功");
    }
 
    public Response update(DeviceMaintain deviceMaintain) {
        mapper.updateById(deviceMaintain);
        return new Response().set(1,"修改成功");
    }
 
    public Response confirm(DeviceMaintain deviceMaintain) {
        //新增一条进记录,plan字段为0
        deviceMaintain.setPlan(0);
        mapper.insert(deviceMaintain);
        return new Response().set(1,"确认成功");
    }
 
    public Response getRecord(Integer deviceId) {
        QueryWrapper<DeviceMaintain> wrapper = Wrappers.query();
        wrapper.select("actual_time","actual_owner2","content").eq("is_plan",0).eq("device_id",deviceId);
        List<DeviceMaintain> deviceMaintains = mapper.selectList(wrapper);
        return new Response().set(1,deviceMaintains);
    }
 
    public Response getPageByCondition(Integer pageNum, Integer pageSize, DeviceMaintainDTO maintainDTO) {
        PageHelper.startPage(pageNum,pageSize);
        List<DeviceMaintain> deviceMaintainList = mapper.getPageByCondition(maintainDTO);
        PageInfo<DeviceMaintain> deviceMaintainPageInfo = new PageInfo<>(deviceMaintainList);
        return new Response().set(1,deviceMaintainPageInfo);
    }
 
    public Response getPageByCondition2(Integer pageNum, Integer pageSize, DeviceMaintainDTO maintainDTO) {
        //1.查询出所有的维保计划及对应的最后实际维保时间
        //2.如果没有维保时间的,按照首保时间+cycle得到预计的最后维保时间
        //  有实际维保时间的,按照最后实际维保时间+cycle得到预计的最后维保时间
        PageHelper.startPage(pageNum,pageSize);
        List<DeviceMaintain> deviceMaintainList = mapper.getPageByCondition2(maintainDTO);
 
        List<DeviceMaintain> newDeviceMaintainList =null;
        if(maintainDTO.getLastMaintainTime()!=null) {
            newDeviceMaintainList = deviceMaintainList.stream().filter(deviceMaintain -> deviceMaintain.getLastMaintainTime().equals(maintainDTO.getLastMaintainTime()))
                    .collect(Collectors.toList());
        }else{
            newDeviceMaintainList = deviceMaintainList;
        }
        PageInfo<DeviceMaintain> deviceMaintainPageInfo = new PageInfo<>(newDeviceMaintainList);
 
        return new Response().set(1,deviceMaintainPageInfo);
    }
}