package org.jeecg.modules.mdc.service.impl;
|
|
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 org.apache.commons.lang3.StringUtils;
|
import org.jeecg.modules.mdc.entity.MdcVacationManagement;
|
import org.jeecg.modules.mdc.mapper.MdcVacationManagementMappper;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
|
import org.jeecg.modules.mdc.service.IMdcVacationManagementService;
|
import org.jeecg.modules.mdc.util.DateUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDate;
|
import java.time.ZoneId;
|
import java.time.format.DateTimeFormatter;
|
import java.time.temporal.TemporalAdjusters;
|
import java.util.*;
|
|
/**
|
* @Description: 假期管理
|
* @Author: ym
|
* @Date: 2023-07-05
|
*/
|
@Service
|
public class MdcVacationManagementServiceImpl extends ServiceImpl<MdcVacationManagementMappper, MdcVacationManagement> implements IMdcVacationManagementService {
|
|
@Autowired
|
private IMdcEquipmentService equipmentService;
|
|
@Override
|
public MdcVacationManagement queryById(String id) {
|
return this.getById(id);
|
}
|
|
@Override
|
public Boolean addVacation(MdcVacationManagement mdcVacationManagement) {
|
return this.save(mdcVacationManagement);
|
}
|
|
@Override
|
public Boolean editVacation(MdcVacationManagement mdcVacationManagement) {
|
return this.updateById(mdcVacationManagement);
|
}
|
|
@Override
|
public Boolean deleteVacation(String id) {
|
return this.removeById(id);
|
}
|
|
@Override
|
public Boolean deleteBatchVacation(String ids) {
|
return this.removeBatchByIds(Arrays.asList(ids.split(",")));
|
}
|
|
@Override
|
public IPage<MdcVacationManagement> pageList(String userId, Page page, HttpServletRequest req, MdcVacationManagement mdcVacationManagement) {
|
//查询用户所拥有的设备信息
|
List<String> equipmentIds = new ArrayList<>();
|
if (StringUtils.isNotEmpty(mdcVacationManagement.getParentId()) && StringUtils.isEmpty(mdcVacationManagement.getEquipmentId())) {
|
if ("2".equals(mdcVacationManagement.getTypeTree())) {
|
//部门层级
|
equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, mdcVacationManagement.getParentId());
|
} else {
|
//产线层级
|
equipmentIds = equipmentService.getEquipmentIdsProduction(userId, mdcVacationManagement.getParentId());
|
}
|
} else if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())) {
|
//单台设备信息
|
mdcVacationManagement.setMdcSectionIds(Collections.singletonList(mdcVacationManagement.getEquipmentId()));
|
} else {
|
//查询用户所拥有的设备信息
|
if ("2".equals(mdcVacationManagement.getTypeTree())) {
|
//部门层级
|
equipmentIds = equipmentService.getEquipmentIdsByDepart(userId, null);
|
} else {
|
equipmentIds = equipmentService.getEquipmentIdsProduction(userId, null);
|
}
|
}
|
if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
|
mdcVacationManagement.setMdcSectionIds(equipmentIds);
|
}
|
if (mdcVacationManagement.getMdcSectionIds() == null || mdcVacationManagement.getMdcSectionIds().isEmpty()) {
|
return null;
|
}
|
return this.baseMapper.pageList(page, mdcVacationManagement);
|
}
|
|
/**
|
* 生成双休日
|
*/
|
@Override
|
public void generateWeekDays() {
|
MdcVacationManagement mdcVacationManagement = this.baseMapper.selectOne(new LambdaQueryWrapper<MdcVacationManagement>().eq(MdcVacationManagement::getType, "双休日").orderByDesc(MdcVacationManagement::getVacationDate).last("limit 1"));
|
// 获取生成开始时间和结束时间
|
LocalDate startDate;
|
LocalDate endDate;
|
if (mdcVacationManagement == null) {
|
startDate = LocalDate.now();
|
endDate = LocalDate.of(DateUtils.getYear(), DateUtils.getMonth(), DateUtils.getDayOfMonth());
|
} else {
|
LocalDate vacationDate = mdcVacationManagement.getVacationDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDate().plusMonths(1);
|
startDate = vacationDate.with(TemporalAdjusters.firstDayOfMonth());
|
endDate = vacationDate.with(TemporalAdjusters.lastDayOfMonth());
|
}
|
// 获取开始时间和结束时间的中间双休日集合
|
List<Date> dateList = DateUtils.getWeekDays(startDate, endDate);
|
}
|
}
|