| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.lavorissue.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | 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.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; |
| | | import com.ruoyi.lavorissue.mapper.LavorIssueMapper; |
| | | import com.ruoyi.lavorissue.pojo.LaborIssue; |
| | | import com.ruoyi.lavorissue.service.LavorIssueService; |
| | | import com.ruoyi.project.system.domain.SysDept; |
| | | import com.ruoyi.project.system.domain.SysDictData; |
| | | import com.ruoyi.project.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.project.system.mapper.SysDictDataMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.util.CellRangeAddress; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author :yys |
| | | * @date : 2025/8/13 11:18 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class LavorIssueServiceImpl extends ServiceImpl<LavorIssueMapper, LaborIssue> implements LavorIssueService { |
| | | |
| | | @Autowired |
| | | private LavorIssueMapper lavorIssueMapper; |
| | | |
| | | @Override |
| | | public IPage<LaborIssue> listPage(Page page, LaborIssue laborIssue) { |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(laborIssue.getSeason(), laborIssue.getIssueDate()); |
| | | laborIssue.setStartDate(startAndEndDateDto.getStartDate()); |
| | | laborIssue.setEndDate(startAndEndDateDto.getEndDate()); |
| | | 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; |
| | | } |
| | | |
| | | 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){ |
| | | switch (season){ |
| | | case 1: |
| | | startAndEndDateDto.setStartDate(currentYear + "-01-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-03-31"); |
| | | startAndEndDateDto.setStartMonth(1); |
| | | startAndEndDateDto.setEndMonth(3); |
| | | break; |
| | | case 2: |
| | | startAndEndDateDto.setStartDate(currentYear + "-04-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-06-30"); |
| | | startAndEndDateDto.setStartMonth(4); |
| | | startAndEndDateDto.setEndMonth(6); |
| | | break; |
| | | case 3: |
| | | startAndEndDateDto.setStartDate(currentYear + "-07-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-09-30"); |
| | | startAndEndDateDto.setStartMonth(7); |
| | | startAndEndDateDto.setEndMonth(9); |
| | | break; |
| | | case 4: |
| | | startAndEndDateDto.setStartDate(currentYear + "-10-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-12-31"); |
| | | startAndEndDateDto.setStartMonth(10); |
| | | startAndEndDateDto.setEndMonth(12); |
| | | break; |
| | | } |
| | | } |
| | | if(payDate != null){ |
| | | Date lastDayOfMonth = getLastDayOfMonth(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; |
| | | } |
| | | |
| | | @Override |
| | | public StatisticsLaborIssue statistics(StatisticsLaborIssue req) throws Exception{ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | StatisticsLaborIssue statisticsLaborIssue = new StatisticsLaborIssue(); |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(req.getSeason(), req.getIssueDate()); |
| | | LambdaQueryWrapper<LaborIssue> laborIssueLambdaQueryWrapper = new LambdaQueryWrapper<>(); |
| | | if(req.getSeason() != null || req.getIssueDate() != null){ |
| | | laborIssueLambdaQueryWrapper.ge(LaborIssue::getIssueDate, startAndEndDateDto.getStartDate()) |
| | | .le(LaborIssue::getIssueDate, startAndEndDateDto.getEndDate()); |
| | | } |
| | | List<LaborIssue> laborIssues = lavorIssueMapper.selectList(laborIssueLambdaQueryWrapper); |
| | | if(!CollectionUtils.isEmpty(laborIssues)){ |
| | | Long sum = laborIssues.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() != null) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum(); |
| | | statisticsLaborIssue.setYlqNum(sum); |
| | | statisticsLaborIssue.setWlqNum(laborIssues.stream() |
| | | .filter(laborIssue -> laborIssue.getAdoptedDate() == null) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum()); |
| | | Date currentDate = new Date(); |
| | | Date parse = sdf.parse(sdf.format(currentDate)); |
| | | statisticsLaborIssue.setCsylqNum(laborIssues.stream() |
| | | .filter(laborIssue -> laborIssue.getIssueDate() != null |
| | | && laborIssue.getAdoptedDate() != null |
| | | && (laborIssue.getIssueDate().before(laborIssue.getAdoptedDate()))) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum()); |
| | | statisticsLaborIssue.setCswlqNum(laborIssues.stream() |
| | | .filter(laborIssue -> laborIssue.getIssueDate() != null |
| | | && laborIssue.getIssueDate().before(parse) |
| | | && laborIssue.getAdoptedDate() == null) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum()); |
| | | } |
| | | return statisticsLaborIssue; |
| | | } |
| | | |
| | | @Autowired |
| | | private SysDictDataMapper sysDictDataMapper; |
| | | |
| | | @Override |
| | | public void exportCopy(HttpServletResponse response, LaborIssue laborIssue) throws UnsupportedEncodingException { |
| | | List<SysDictData> sys_lavor_issue = sysDictDataMapper.selectDictDataByType("sys_lavor_issue"); |
| | | if(CollectionUtils.isEmpty(sys_lavor_issue)){ |
| | | throw new RuntimeException("åå
¸æ°æ®ä¸ºç©º"); |
| | | } |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(laborIssue.getSeason(), laborIssue.getIssueDate()); |
| | | BeanUtils.copyProperties(startAndEndDateDto, laborIssue); |
| | | List<LaborIssue> laborIssues = lavorIssueMapper.list(laborIssue); |
| | | if (CollectionUtils.isEmpty(laborIssues)) { |
| | | throw new RuntimeException("æ°æ®ä¸ºç©º"); |
| | | } |
| | | Map<String, List<LaborIssue>> laborIssueMap = laborIssues.stream() |
| | | .collect(Collectors.groupingBy(LaborIssue::getStaffNo)); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setCharacterEncoding("UTF-8"); |
| | | // è¿éURLEncoder.encodeå¯ä»¥é²æ¢ä¸æä¹±ç å½ç¶åeasyexcel没æå
³ç³» |
| | | String fileName = URLEncoder.encode("å³ä¿å°è´¦", "UTF-8"); |
| | | response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | try { |
| | | //æ°å»ºExcelWriter |
| | | ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()) |
| | | .registerWriteHandler(new CustomCellStyleHandler()) |
| | | .registerWriteHandler(new ConfigurableMergeStrategy(exportExternalPackingListGetMerge(4,sys_lavor_issue.size(),laborIssueMap.size()))) |
| | | .build(); |
| | | |
| | | List<List<List<String>>> data = completeExternalPackingList(laborIssueMap, sys_lavor_issue,laborIssue); |
| | | |
| | | for (int i = 0; i < data.size(); i++) { |
| | | List<List<String>> list = data.get(i); |
| | | |
| | | //è·åsheet0对象 |
| | | WriteSheet mainSheet = EasyExcel.writerSheet(i, "å³ä¿å°è´¦" + i).build(); |
| | | //åsheet0åå
¥æ°æ® ä¼ å
¥ç©ºlistè¿æ ·åªå¯¼åºè¡¨å¤´ |
| | | excelWriter.write(list, mainSheet); |
| | | } |
| | | |
| | | //å
³éæµ |
| | | excelWriter.finish(); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导åºå¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | |
| | | // å¤çå¤é¨è£
ç®±åæ°æ® |
| | | private List<List<List<String>>> completeExternalPackingList(Map<String, List<LaborIssue>> listMap,List<SysDictData> sys_lavor_issue,LaborIssue obj) { |
| | | List<List<List<String>>> data = new ArrayList<>(); |
| | | int num = sys_lavor_issue.size(); |
| | | |
| | | List<List<String>> item = new ArrayList<>(); |
| | | List<String> list = new ArrayList<>(); |
| | | list.add("é¨é¨"); |
| | | list.add(""); |
| | | list.add("ä¼ä¸ç®¡çç§"); |
| | | list.add(""); |
| | | list.add("ä¼ä¸ç®¡çç§" + obj.getYear() + "å¹´" + obj.getStartMonth() + "æ-" + obj.getYear() + "å¹´" + obj.getEndMonth() +"æå³ä¿åæ¾è®¡å表"); |
| | | for (int i = 1; i <= num; i++){ |
| | | list.add(""); |
| | | } |
| | | item.add(list); |
| | | |
| | | List<String> list1 = new ArrayList<>(); |
| | | list1.add("å¼å§å¹´/æ"); |
| | | list1.add(""); |
| | | list1.add("ç»æå¹´/æ"); |
| | | list1.add(""); |
| | | for (int i = 0; i <= num; i++){ |
| | | list1.add(""); |
| | | } |
| | | item.add(list1); |
| | | |
| | | List<String> list2 = new ArrayList<>(); |
| | | list2.add(obj.getYear().toString()); |
| | | list2.add(obj.getStartMonth().toString()); |
| | | list2.add(obj.getYear().toString()); |
| | | list2.add(obj.getEndMonth().toString()); |
| | | for (int i = 0; i <= num; i++){ |
| | | list.add(""); |
| | | } |
| | | item.add(list2); |
| | | |
| | | List<String> list3 = new ArrayList<>(); |
| | | list3.add("é¨é¨åç§°"); |
| | | list3.add(""); |
| | | list3.add("å§å"); |
| | | list3.add("å·¥å·"); |
| | | for (SysDictData sysDictData : sys_lavor_issue) { |
| | | list3.add(sysDictData.getDictLabel()); |
| | | } |
| | | list3.add("ç¾å"); |
| | | item.add(list3); |
| | | |
| | | // å¡«å¼ |
| | | SysDept sysDept = sysDeptMapper.selectDeptById(SecurityUtils.getLoginUser().getTenantId()); |
| | | List<String> sumList = new ArrayList<>(); |
| | | AtomicInteger i = new AtomicInteger(); |
| | | listMap.forEach((key, value) -> { |
| | | List<String> list4 = new ArrayList<>(); |
| | | list4.add(sysDept.getDeptName()); |
| | | list4.add(""); |
| | | list4.add(value.get(0).getStaffName()); |
| | | list4.add(value.get(0).getStaffNo()); |
| | | int j = 0; |
| | | for (SysDictData sysDictData : sys_lavor_issue) { |
| | | list4.add(value.stream().filter(laborIssue -> laborIssue.getDictId().equals(sysDictData.getDictValue())) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum() |
| | | + ""); |
| | | if(i.get() == 0){ |
| | | sumList.add(value.stream().filter(laborIssue -> laborIssue.getDictId().equals(sysDictData.getDictValue())) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum() |
| | | + ""); |
| | | }else { |
| | | sumList.set(j,(Long.parseLong(sumList.get(j)) + value.stream().filter(laborIssue -> laborIssue.getDictId().equals(sysDictData.getDictValue())) |
| | | .mapToLong(LaborIssue::getNum) |
| | | .sum()) |
| | | + ""); |
| | | } |
| | | j++; |
| | | } |
| | | i.getAndIncrement(); |
| | | item.add(list4); |
| | | }); |
| | | List<String> list5 = new ArrayList<>(); |
| | | list5.add("å计"); |
| | | list5.add(""); |
| | | list5.add(""); |
| | | list5.add(""); |
| | | for (int h = 0; h < sumList.size(); h++){ |
| | | list5.add(sumList.get(h)); |
| | | } |
| | | item.add(list5); |
| | | data.add(item); |
| | | return data; |
| | | } |
| | | |
| | | /** |
| | | * å¤é¨è£
ç®±ååå¹¶åå
æ ¼ |
| | | * |
| | | * @return |
| | | */ |
| | | private List<CellRangeAddress> exportExternalPackingListGetMerge(Integer rowNum,Integer num,Integer listSize) { |
| | | List<CellRangeAddress> mergeRegions = new ArrayList<>(); |
| | | mergeRegions.add(new CellRangeAddress(0, 0, 0, 1)); // åå¹¶A1:Q2 |
| | | mergeRegions.add(new CellRangeAddress(0, 0, 2, 3)); // åå¹¶A4:Q4 |
| | | |
| | | mergeRegions.add(new CellRangeAddress(0, 2, rowNum, rowNum + num)); // åå¹¶A5:B6 |
| | | mergeRegions.add(new CellRangeAddress(1, 1, 0, 1)); // åå¹¶C5:E6 |
| | | mergeRegions.add(new CellRangeAddress(1, 1, 2, 3)); // åå¹¶F5:G6 |
| | | mergeRegions.add(new CellRangeAddress(3, 3, 0, 1)); // åå¹¶H5:I6 |
| | | for (int i = 1; i <= listSize; i++) { |
| | | mergeRegions.add(new CellRangeAddress(3 + i, 3 + i, 0, 1)); |
| | | } |
| | | mergeRegions.add(new CellRangeAddress(rowNum + listSize, rowNum + listSize, 0, 3)); |
| | | return mergeRegions; |
| | | } |
| | | |
| | | public Date getLastDayOfMonth(Date date) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(date); // è®¾ç½®ä¼ å
¥çDate |
| | | 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对象 |
| | | } |
| | | |
| | | } |