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);
|
}
|
}
|