| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.approve.utils.StartAndEndDateDto; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.excel.ConfigurableMergeStrategy; |
| | | import com.ruoyi.common.utils.excel.CustomCellStyleHandler; |
| | | import com.ruoyi.lavorissue.dto.StatisticsLaborIssue; |
| | |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(laborIssue.getSeason(), laborIssue.getIssueDate()); |
| | | laborIssue.setStartDate(startAndEndDateDto.getStartDate()); |
| | | laborIssue.setEndDate(startAndEndDateDto.getEndDate()); |
| | | IPage<LaborIssue> laborIssueIPage = lavorIssueMapper.listPage(page, laborIssue); |
| | | return laborIssueIPage; |
| | | return lavorIssueMapper.listPage(page, laborIssue); |
| | | } |
| | | |
| | | @Override |
| | | public List<Map<String, Object>> statisticsList(LaborIssue laborIssue){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(laborIssue.getSeason(), laborIssue.getIssueDate()); |
| | | laborIssue.setStartDate(startAndEndDateDto.getStartDate()); |
| | | laborIssue.setEndDate(startAndEndDateDto.getEndDate()); |
| | | List<LaborIssue> laborIssueIPage = lavorIssueMapper.list(laborIssue); |
| | | |
| | | // 使用可变的ArrayList替换默认的不可变列表 |
| | | List<Map<String, Object>> records = new ArrayList<>(); |
| | | |
| | | Map<String, List<LaborIssue>> collect = laborIssueIPage.stream().collect(Collectors.groupingBy(LaborIssue::getStaffNo)); |
| | | collect.forEach((k, v) -> { |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | LaborIssue laborIssue1 = v.get(0); |
| | | hashMap.put("id", v.stream().map(LaborIssue::getId)); |
| | | hashMap.put("deptName", laborIssue1.getDeptName()); |
| | | hashMap.put("orderNo", laborIssue1.getOrderNo()); |
| | | hashMap.put("staffId", laborIssue1.getStaffId()); |
| | | hashMap.put("staffName", laborIssue1.getStaffName()); |
| | | hashMap.put("staffNo", laborIssue1.getStaffNo()); |
| | | hashMap.put("dictType", laborIssue1.getDictType()); |
| | | hashMap.put("dictTypeName", laborIssue1.getDictTypeName()); |
| | | hashMap.put("factoryDate", laborIssue1.getFactoryDate() == null ? "" : sdf.format(laborIssue1.getFactoryDate())); |
| | | hashMap.put("issueDate", laborIssue1.getIssueDate() == null ? "" : sdf.format(laborIssue1.getIssueDate())); |
| | | hashMap.put("adoptedDate", laborIssue1.getAdoptedDate() == null ? "" : sdf.format(laborIssue1.getAdoptedDate())); |
| | | hashMap.put("tenantId", laborIssue1.getTenantId()); |
| | | Map<String, List<LaborIssue>> collect1 = v.stream().collect(Collectors.groupingBy(LaborIssue::getDictId)); |
| | | collect1.forEach((k1, v1) -> { |
| | | hashMap.put(k1, v1.stream() |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum()); |
| | | }); |
| | | records.add(hashMap); |
| | | }); |
| | | return records; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> progressTotal(LaborIssue req) { |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(req.getSeason(), req.getIssueDate()); |
| | | req.setStartDate(startAndEndDateDto.getStartDate()); |
| | | req.setEndDate(startAndEndDateDto.getEndDate()); |
| | | List<LaborIssue> laborIssueIPage = lavorIssueMapper.list(req); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("total", 0); // 发放总数量 |
| | | // 领取数量 |
| | | map.put("adopted", 0); |
| | | // 未领取数量 |
| | | map.put("notAdopted", 0); |
| | | // 领取完成率 |
| | | map.put("adoptedPercent", 0); |
| | | if(!CollectionUtils.isEmpty(laborIssueIPage)){ |
| | | long sum = laborIssueIPage.stream().mapToLong(LaborIssue::getNum).sum(); |
| | | map.put("total", sum); |
| | | long sum1 = laborIssueIPage |
| | | .stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() != null) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | map.put("adopted", sum1); |
| | | map.put("notAdopted", sum - sum1); |
| | | map.put("adoptedPercent", sum1 * 100.0 / sum); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> progressPercent(LaborIssue req) { |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(req.getSeason(), req.getIssueDate()); |
| | | req.setStartDate(startAndEndDateDto.getStartDate()); |
| | | req.setEndDate(startAndEndDateDto.getEndDate()); |
| | | List<LaborIssue> laborIssueIPage = lavorIssueMapper.list(req); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | // 领取数量 |
| | | map.put("adopted", 0); |
| | | // 未领取数量 |
| | | map.put("notAdopted", 0); |
| | | if(!CollectionUtils.isEmpty(laborIssueIPage)){ |
| | | long sum = laborIssueIPage.stream().mapToLong(LaborIssue::getNum).sum(); |
| | | long sum1 = laborIssueIPage |
| | | .stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() != null) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | map.put("adopted", sum1); |
| | | map.put("notAdopted", sum - sum1); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> progressDistribution(LaborIssue req) { |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(req.getSeason(), req.getIssueDate()); |
| | | req.setStartDate(startAndEndDateDto.getStartDate()); |
| | | req.setEndDate(startAndEndDateDto.getEndDate()); |
| | | List<LaborIssue> laborIssueIPage = lavorIssueMapper.list(req); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | if(!CollectionUtils.isEmpty(laborIssueIPage)){ |
| | | // 根据发放日期,领用日期计算及时已领取,及时未领取,超时已领取,超时未领取数据 |
| | | // 及时已领取 |
| | | List<List<Long>> list = new ArrayList<>(); |
| | | List<Long> sumList = new ArrayList<>(); |
| | | long sum = laborIssueIPage.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() != null && laborIssue.getAdoptedDate().getTime() <= laborIssue.getIssueDate().getTime()) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | // 及时未领取 |
| | | long sum1 = laborIssueIPage.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() == null && laborIssue.getIssueDate().getTime() <= new Date().getTime()) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | sumList.add(sum); |
| | | sumList.add(sum1); |
| | | list.add(sumList); |
| | | List<Long> sumList1 = new ArrayList<>(); |
| | | // 超时已领取 |
| | | long sum2 = laborIssueIPage.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() != null && laborIssue.getAdoptedDate().getTime() > laborIssue.getIssueDate().getTime()) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | // 超时未领取 |
| | | long sum3 = laborIssueIPage.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() == null && laborIssue.getIssueDate().getTime() > new Date().getTime()) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | sumList1.add(sum2); |
| | | sumList1.add(sum3); |
| | | list.add(sumList1); |
| | | map.put("series", list); |
| | | } |
| | | return map; |
| | | } |
| | | |
| | | public StartAndEndDateDto getStartAndEndDateDto(Integer season,Date payDate){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | StartAndEndDateDto startAndEndDateDto = new StartAndEndDateDto(); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int currentYear = calendar.get(Calendar.YEAR); |
| | | startAndEndDateDto.setYear(currentYear); |
| | | if(season != null){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int currentYear = calendar.get(Calendar.YEAR); |
| | | startAndEndDateDto.setYear(currentYear); |
| | | switch (season){ |
| | | case 1: |
| | | startAndEndDateDto.setStartDate(currentYear + "-01-01"); |
| | |
| | | } |
| | | if(payDate != null){ |
| | | Date lastDayOfMonth = getLastDayOfMonth(payDate); |
| | | startAndEndDateDto.setStartDate(sdf.format(payDate)); |
| | | Date firstDayOfMonth = getFirstDayOfMonth(payDate); |
| | | startAndEndDateDto.setStartDate(sdf.format(firstDayOfMonth)); |
| | | startAndEndDateDto.setEndDate(sdf.format(lastDayOfMonth)); |
| | | startAndEndDateDto.setStartMonth(payDate.getMonth() + 1); |
| | | startAndEndDateDto.setEndMonth(payDate.getMonth() + 1); |
| | | } |
| | | return startAndEndDateDto; |
| | | } |
| | |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系 |
| | | String fileName = URLEncoder.encode("外部装箱单", "UTF-8"); |
| | | String fileName = URLEncoder.encode("劳保台账", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | try { |
| | |
| | | List<List<String>> list = data.get(i); |
| | | |
| | | //获取sheet0对象 |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(i, "外部装箱单" + i).build(); |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(i, "劳保台账" + i).build(); |
| | | //向sheet0写入数据 传入空list这样只导出表头 |
| | | excelWriter.write(list, mainSheet); |
| | | } |
| | |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH)); // 设置为当月最后一天 |
| | | return calendar.getTime(); // 返回Date对象 |
| | | } |
| | | |
| | | /** |
| | | * 获取当月第一天 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public Date getFirstDayOfMonth(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); // 设置传入的Date |
| | | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH)); // 设置为当月第一天 |
| | | return calendar.getTime(); // 返回Date对象 |
| | | } |
| | | |
| | | } |