| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.vo.LoginUser; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipmentOvertime; |
| | | import org.jeecg.modules.mdc.mapper.MdcEquipmentOvertimeMapper; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentOvertimeService; |
| | | import org.jeecg.modules.mdc.service.IMdcEquipmentService; |
| | | 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.stereotype.Service; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | |
| | | } |
| | | return this.baseMapper.pageList(page, mdcEquipmentOvertime); |
| | | } |
| | | |
| | | /** |
| | | * 导出 |
| | | * |
| | | * @param userId |
| | | * @param mdcEquipmentOvertime |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ModelAndView exportXls(String userId, MdcEquipmentOvertime mdcEquipmentOvertime) { |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(mdcEquipmentOvertime.getParentId()) && StringUtils.isEmpty(mdcEquipmentOvertime.getEquipmentId())) { |
| | | if ("2".equals(mdcEquipmentOvertime.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, mdcEquipmentOvertime.getParentId()); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcEquipmentOvertime.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(mdcEquipmentOvertime.getEquipmentId())) { |
| | | //单台设备信息 |
| | | mdcEquipmentOvertime.setMdcSectionIds(Collections.singletonList(mdcEquipmentOvertime.getEquipmentId())); |
| | | } else { |
| | | //查询用户拥有的所有设备信息 |
| | | if ("2".equals(mdcEquipmentOvertime.getTypeTree())) { |
| | | //部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | //产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | |
| | | if (mdcEquipmentOvertime.getMdcSectionIds() == null || mdcEquipmentOvertime.getMdcSectionIds().isEmpty()) { |
| | | mdcEquipmentOvertime.setMdcSectionIds(equipmentIds); |
| | | } |
| | | |
| | | if (mdcEquipmentOvertime.getMdcSectionIds() == null || mdcEquipmentOvertime.getMdcSectionIds().isEmpty()) { |
| | | return null; |
| | | } |
| | | // Step.2 AutoPoi 导出Excel |
| | | ModelAndView mv = new ModelAndView(new JeecgEntityExcelView()); |
| | | List<MdcEquipmentOvertime> mdcEquipmentOvertimes = this.baseMapper.list(mdcEquipmentOvertime); |
| | | // 导出文件名称 |
| | | mv.addObject(NormalExcelConstants.FILE_NAME, "加班管理列表"); |
| | | mv.addObject(NormalExcelConstants.CLASS, MdcEquipmentOvertime.class); |
| | | //获取当前登录用户 |
| | | //update-begin---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------ |
| | | LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
| | | mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("加班管理列表数据", "导出人:" + user.getRealname(), "加班管理")); |
| | | //update-end---author:wangshuai ---date:20211227 for:[JTC-116]导出人写死了------------ |
| | | mv.addObject(NormalExcelConstants.DATA_LIST, mdcEquipmentOvertimes); |
| | | return mv; |
| | | } |
| | | |
| | | /** |
| | | * 计算加班时间(分钟) |
| | | * |
| | | * @param equipmentId |
| | | * @param validDate |
| | | * @return |
| | | */ |
| | | @Override |
| | | public BigDecimal computeOvertime(String equipmentId, String validDate) { |
| | | List<MdcEquipmentOvertime> list = this.baseMapper.computeOvertime(equipmentId, validDate.replaceAll("-", "")); |
| | | BigDecimal result = new BigDecimal("0"); |
| | | if (list != null && !list.isEmpty()) { |
| | | for (MdcEquipmentOvertime equipmentOvertime : list) { |
| | | String date = DateUtils.format(DateUtils.toDate(validDate + "-01", DateUtils.STR_DATE), DateUtils.STR_DATE) + " "; |
| | | String startTime = date + equipmentOvertime.getStartTime(); |
| | | String endTime = date + equipmentOvertime.getEndTime(); |
| | | LocalDateTime localStartTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern(DateUtils.STR_DATE_TIME_SMALL)); |
| | | LocalDateTime localEndTime = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern(DateUtils.STR_DATE_TIME_SMALL)); |
| | | int minutes = Math.toIntExact(Duration.between(localStartTime, localEndTime).toMinutes()); |
| | | result = result.add(new BigDecimal(minutes)); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param mdcEquipmentOvertime |
| | | * @return |
| | | */ |
| | | @Override |
| | | public boolean addOvertime(MdcEquipmentOvertime mdcEquipmentOvertime) { |
| | | String[] equipmentIds = mdcEquipmentOvertime.getEquipmentIds().split(","); |
| | | List<MdcEquipmentOvertime> mdcEquipmentOvertimes = new ArrayList<>(); |
| | | // 计算时长(秒) |
| | | String startTime = mdcEquipmentOvertime.getStartTime(); |
| | | String endTime = mdcEquipmentOvertime.getEndTime(); |
| | | long duration = DateUtils.differentSecond(DateUtils.setTimeForDay(DateUtils.getNow(), startTime), DateUtils.setTimeForDay(DateUtils.getNow(), endTime)); |
| | | for (String equipmentId : equipmentIds) { |
| | | MdcEquipmentOvertime equipmentOvertime = new MdcEquipmentOvertime(); |
| | | equipmentOvertime.setEquipmentId(equipmentId); |
| | | equipmentOvertime.setTheDate(mdcEquipmentOvertime.getTheDate()); |
| | | equipmentOvertime.setAutoFlag(CommonConstant.AUTO_FLAG_N); |
| | | equipmentOvertime.setStartTime(mdcEquipmentOvertime.getStartTime()); |
| | | equipmentOvertime.setEndTime(mdcEquipmentOvertime.getEndTime()); |
| | | equipmentOvertime.setDuration(new BigDecimal(duration)); |
| | | mdcEquipmentOvertimes.add(equipmentOvertime); |
| | | } |
| | | return super.saveBatch(mdcEquipmentOvertimes); |
| | | } |
| | | } |