package com.gk.hotwork.Service.ServiceImpl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gk.hotwork.Domain.DepartmentInfo;
|
import com.gk.hotwork.Domain.Enum.ErrorCode;
|
import com.gk.hotwork.Domain.Exception.BusinessException;
|
import com.gk.hotwork.Domain.Reserve;
|
import com.gk.hotwork.Domain.UserInfo;
|
import com.gk.hotwork.Domain.Utils.Msg;
|
import com.gk.hotwork.Domain.Utils.PageInfo;
|
import com.gk.hotwork.Domain.Utils.StringUtils;
|
import com.gk.hotwork.Domain.Vo.PageInfoExtension;
|
import com.gk.hotwork.Mapper.ReserveMapper;
|
import com.gk.hotwork.Service.DepartmentService;
|
import com.gk.hotwork.Service.ReserveService;
|
import com.gk.hotwork.Service.UserService;
|
import org.omg.PortableInterceptor.INACTIVE;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.Calendar;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
@Service("reserveService")
|
public class ReserveServiceImpl extends ServiceImpl<ReserveMapper, Reserve> implements ReserveService {
|
|
@Autowired
|
private ReserveMapper reserveMapper;
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private DepartmentService departmentService;
|
|
|
/**
|
* @Description: 新增预约
|
* @date 2021/11/16 9:58
|
*/
|
@Override
|
public void addOne(Reserve reserve, UserInfo userInfo) {
|
|
//0.角色为部门负责人
|
UserInfo user = userService.getById(userInfo);
|
Byte isDepartment = user.getIsdepartment();
|
if ((byte) 1 != isDepartment)
|
throw new BusinessException("当前用户不是部门负责人,没有权限创建");
|
|
Date now = new Date();
|
Calendar instance = Calendar.getInstance();
|
instance.setTime(now);
|
instance.set(Calendar.HOUR_OF_DAY, 0);
|
instance.set(Calendar.MINUTE, 0);
|
instance.set(Calendar.SECOND, 0);
|
Date judgement = instance.getTime();
|
//1.预约时间
|
Date appointment = reserve.getAppointment();
|
if (appointment == null)
|
throw new BusinessException("预约时间为空");
|
if (appointment.before(judgement))
|
throw new BusinessException("预约时间为明日起");
|
|
//2.统计预约时间当日 该部门是否有单子
|
if (userInfo.getDepartment() == null) {
|
throw new BusinessException("用户未有部门");
|
}
|
DepartmentInfo dep = departmentService.getById(userInfo.getDepartment());
|
if (dep == null) {
|
throw new BusinessException("用户部门不存在");
|
}
|
if (this.isExistAtAppointment(appointment, dep.getDepartment()))
|
throw new BusinessException("预约当日已有预约单");
|
|
reserve.setCreateby(user.getId());
|
reserve.setCreatebyname(user.getRealname());
|
reserve.setUpdatebyname(user.getRealname());
|
reserve.setCreatetime(now);
|
reserve.setUpdatetime(now);
|
reserve.setCreatebydepartment(dep.getDepartment());
|
this.save(reserve);
|
}
|
|
/**
|
* @Description: 判断预约当日是否存在单子
|
* @date 2021/11/16 10:53
|
*/
|
@Override
|
public boolean isExistAtAppointment(Date appointment,String department) {
|
|
if (appointment == null)
|
throw new BusinessException("预约时间不能为空");
|
if (StringUtils.isBlank(department))
|
throw new BusinessException("部门不能为空");
|
|
Calendar instance = Calendar.getInstance();
|
instance.setTime(appointment);
|
instance.set(Calendar.HOUR_OF_DAY, 0);
|
instance.set(Calendar.MINUTE, 0);
|
instance.set(Calendar.SECOND, 0);
|
Date startTime = instance.getTime();
|
instance.set(Calendar.HOUR_OF_DAY, 23);
|
instance.set(Calendar.MINUTE, 59);
|
instance.set(Calendar.SECOND, 59);
|
Date endTime = instance.getTime();
|
|
LambdaQueryWrapper<Reserve> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.ge(Reserve::getAppointment, startTime)
|
.le(Reserve::getAppointment, endTime)
|
.eq(Reserve::getCreatebydepartment, department)
|
.eq(Reserve::getValidflag, true);
|
return reserveMapper.selectCount(queryWrapper) > 0;
|
|
|
}
|
|
/**
|
* @Description: 修改单子
|
* @date 2021/11/16 11:02
|
*/
|
@Override
|
public void modOne(Reserve reserve, UserInfo userInfo) {
|
|
if (reserve.getId() == null)
|
throw new BusinessException("参数传递有误");
|
Reserve old = this.getById(reserve);
|
|
//0.角色为部门负责人
|
UserInfo user = userService.getById(userInfo);
|
Byte isDepartment = user.getIsdepartment();
|
if ((byte) 1 != isDepartment)
|
throw new BusinessException("当前用户不是部门负责人,没有权限修改");
|
|
if (!old.getCreatebydepartment().equals(user.getDepartment()))
|
throw new BusinessException("当前用户不是当前单子的部门负责人");
|
|
Date now = new Date();
|
|
//更新 不修改预约时间
|
old.setSpace(reserve.getSpace());
|
old.setHoisting(reserve.getHoisting());
|
old.setSoild(reserve.getSoild());
|
old.setBreaks(reserve.getBreaks());
|
old.setHigh(reserve.getHigh());
|
old.setElectricity(reserve.getElectricity());
|
old.setBlindboard(reserve.getBlindboard());
|
old.setFire(reserve.getFire());
|
old.setUpdatebyname(user.getRealname());
|
old.setUpdatetime(now);
|
this.updateById(reserve);
|
}
|
|
/**
|
* @Description: 分页查询
|
* @date 2021/11/16 11:02
|
*/
|
@Override
|
public IPage selectPage(Page<Reserve> page, Map<String, Object> filter, UserInfo userInfo) {
|
|
LambdaQueryWrapper<Reserve> queryWrapper = new LambdaQueryWrapper<>();
|
UserInfo user = userService.getById(userInfo);
|
if (userInfo.getDepartment() == null) {
|
throw new BusinessException("用户未有部门");
|
}
|
DepartmentInfo dep = departmentService.getById(userInfo.getDepartment());
|
if (dep == null) {
|
throw new BusinessException("用户部门不存在");
|
}
|
queryWrapper.eq(Reserve::getCreatebydepartment, dep.getDepartment())
|
.eq(Reserve::getValidflag, true).orderByDesc(Reserve::getCreatetime);
|
if (StringUtils.isNotBlank((String) filter.get("starttime")))
|
queryWrapper.ge(Reserve::getAppointment, filter.get("starttime"));
|
if (StringUtils.isNotBlank((String) filter.get("endtime")))
|
queryWrapper.le(Reserve::getAppointment, filter.get("endtime"));
|
return reserveMapper.selectPage(page,queryWrapper);
|
}
|
|
|
/**
|
* @Description: 统计分页
|
* @date 2021/11/16 13:49
|
*/
|
@Override
|
public PageInfoExtension<Map> statistics(Page<Map> page, Map<String, Object> filter, UserInfo user) {
|
Map<String, Object> params = new HashMap<>();
|
params.put("appointment", filter.get("appointment"));
|
params.put("department", filter.get("department"));
|
Page pageInfo = reserveMapper.statistics(page,params);
|
PageInfoExtension<Map> extension = new PageInfoExtension<>(pageInfo);
|
Map totalNum = this.statisticsTotal(params);
|
extension.setExtension(totalNum);
|
return extension;
|
}
|
|
|
/**
|
* @Description: 统计分页 尾部 总计行
|
* @date 2021/11/16 14:14
|
*/
|
@Override
|
public Map statisticsTotal(Map<String, Object> params) {
|
return reserveMapper.selectStatisticsTotal(params);
|
}
|
}
|