| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import net.sf.saxon.expr.Component; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.jeecg.modules.mdc.entity.MdcStandardProcessDuration; |
| | | 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.jeecgframework.poi.excel.def.NormalExcelConstants; |
| | | import org.jeecgframework.poi.excel.entity.ExportParams; |
| | | import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.text.ParseException; |
| | |
| | | |
| | | @Override |
| | | public Boolean addVacation(MdcVacationManagement mdcVacationManagement) { |
| | | return this.save(mdcVacationManagement); |
| | | boolean result = false; |
| | | String[] equipmentIds = mdcVacationManagement.getEquipmentIds().split(","); |
| | | for (String equipmentId : equipmentIds) { |
| | | MdcEquipment mdcEquipment = equipmentService.findEquipmentNameByEquipmentId(equipmentId); |
| | | MdcVacationManagement vacationManagement = new MdcVacationManagement(); |
| | | BeanUtils.copyProperties(mdcVacationManagement, vacationManagement); |
| | | vacationManagement.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | vacationManagement.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | boolean b = super.save(vacationManagement); |
| | | if (b) { |
| | | result = true; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | */ |
| | | @Override |
| | | public void generateWeekDays() { |
| | | MdcVacationManagement mdcVacationManagement = this.baseMapper.selectOne(new LambdaQueryWrapper<MdcVacationManagement>().eq(MdcVacationManagement::getType, "双休日").orderByDesc(MdcVacationManagement::getVacationDate).last("limit 1")); |
| | | MdcVacationManagement mdcVacationManagement = this.baseMapper.selectLastWeekDays(); |
| | | // 获取生成开始时间和结束时间 |
| | | LocalDate startDate; |
| | | LocalDate endDate; |
| | |
| | | startDate = vacationDate.with(TemporalAdjusters.firstDayOfMonth()); |
| | | endDate = vacationDate.with(TemporalAdjusters.lastDayOfMonth()); |
| | | } |
| | | List<MdcVacationManagement> list = new ArrayList<>(); |
| | | // 获取开始时间和结束时间的中间双休日集合 |
| | | List<Date> dateList = DateUtils.getWeekDays(startDate, endDate); |
| | | if (!dateList.isEmpty()) { |
| | | // 获取所有设备 |
| | | List<MdcEquipment> equipmentList = equipmentService.list(); |
| | | for (Date date : dateList) { |
| | | for (MdcEquipment mdcEquipment : equipmentList) { |
| | | MdcVacationManagement management = new MdcVacationManagement(); |
| | | management.setEquipmentId(mdcEquipment.getEquipmentId()); |
| | | management.setEquipmentName(mdcEquipment.getEquipmentName()); |
| | | management.setVacationDate(date); |
| | | management.setVacationType("双休日"); |
| | | management.setCreateBy("root"); |
| | | list.add(management); |
| | | } |
| | | } |
| | | super.saveBatch(list); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ModelAndView exportXls(String userId, MdcVacationManagement mdcVacationManagement) { |
| | | LambdaQueryWrapper<MdcVacationManagement> queryWrapper = new LambdaQueryWrapper<>(); |
| | | //查询用户所拥有的设备信息 |
| | | 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; |
| | | } else { |
| | | queryWrapper.in(MdcVacationManagement::getEquipmentId, mdcVacationManagement.getMdcSectionIds()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentId())) { |
| | | queryWrapper.like(MdcVacationManagement::getEquipmentId, mdcVacationManagement.getEquipmentId()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcVacationManagement.getEquipmentName())) { |
| | | queryWrapper.like(MdcVacationManagement::getEquipmentName, mdcVacationManagement.getEquipmentName()); |
| | | } |
| | | if (StringUtils.isNotEmpty(mdcVacationManagement.getStartTime()) && StringUtils.isNotEmpty(mdcVacationManagement.getEndTime())) { |
| | | queryWrapper.between(MdcVacationManagement::getVacationDate, mdcVacationManagement.getStartTime(), mdcVacationManagement.getEndTime()); |
| | | } |
| | | queryWrapper.orderByAsc(MdcVacationManagement::getVacationDate); |
| | | // Step.2 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | List<MdcVacationManagement> mdcStandardProcessDurations = this.baseMapper.selectList(queryWrapper); |
| | | // 导出文件名称 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, "假期管理列表"); |
| | | mv.addObject(NormalExcelConstants.CLASS, MdcVacationManagement.class); |
| | | //获取当前登录用户 |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("假期管理列表数据", "导出人:" + user.getRealname(), "假期管理")); |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, mdcStandardProcessDurations); |
| | | return mv; |
| | | } |
| | | } |