| | |
| | | package com.ruoyi.lavorissue.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 com.ruoyi.approve.utils.StartAndEndDateDto; |
| | | import com.ruoyi.common.utils.excel.ExcelUtils; |
| | | 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.SysDictData; |
| | | import com.ruoyi.project.system.domain.SysDictType; |
| | | import com.ruoyi.project.system.mapper.SysDictDataMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author :yys |
| | |
| | | |
| | | @Override |
| | | public IPage<LaborIssue> listPage(Page page, LaborIssue laborIssue) { |
| | | IPage<LaborIssue> listPage = lavorIssueMapper.listPage(page, laborIssue); |
| | | return listPage; |
| | | StartAndEndDateDto startAndEndDateDto = getStartAndEndDateDto(laborIssue.getSeason(), laborIssue.getIssueDate()); |
| | | laborIssue.setStartDate(startAndEndDateDto.getStartDate()); |
| | | laborIssue.setEndDate(startAndEndDateDto.getEndDate()); |
| | | IPage<LaborIssue> laborIssueIPage = lavorIssueMapper.listPage(page, laborIssue); |
| | | return laborIssueIPage; |
| | | } |
| | | |
| | | public StartAndEndDateDto getStartAndEndDateDto(Integer season,Date payDate){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | StartAndEndDateDto startAndEndDateDto = new StartAndEndDateDto(); |
| | | if(season != null){ |
| | | Calendar calendar = Calendar.getInstance(); |
| | | int currentYear = calendar.get(Calendar.YEAR); |
| | | switch (season){ |
| | | case 1: |
| | | startAndEndDateDto.setStartDate(currentYear + "-01-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-03-31"); |
| | | break; |
| | | case 2: |
| | | startAndEndDateDto.setStartDate(currentYear + "-04-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-06-30"); |
| | | break; |
| | | case 3: |
| | | startAndEndDateDto.setStartDate(currentYear + "-07-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-09-30"); |
| | | break; |
| | | case 4: |
| | | startAndEndDateDto.setStartDate(currentYear + "-10-01"); |
| | | startAndEndDateDto.setEndDate(currentYear + "-12-31"); |
| | | break; |
| | | } |
| | | } |
| | | if(payDate != null){ |
| | | Date lastDayOfMonth = getLastDayOfMonth(payDate); |
| | | startAndEndDateDto.setStartDate(sdf.format(payDate)); |
| | | startAndEndDateDto.setEndDate(sdf.format(lastDayOfMonth)); |
| | | } |
| | | 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) { |
| | | List<SysDictData> sys_lavor_issue = sysDictDataMapper.selectDictDataByType("sys_lavor_issue"); |
| | | if(CollectionUtils.isEmpty(sys_lavor_issue)){ |
| | | throw new RuntimeException("字典数据为空"); |
| | | } |
| | | List<Object> head = new ArrayList<>(); |
| | | head.add("部门"); |
| | | head.add(ExcelUtils.COLUMN_MERGE); |
| | | head.add("企业管理科"); |
| | | head.add(ExcelUtils.COLUMN_MERGE); |
| | | head.add("企业管理科2025年1月-2025年3月劳保发放计划表"); |
| | | for (int i = 0; i < sys_lavor_issue.size(); i++) { |
| | | if (i == 0) { |
| | | head.add(ExcelUtils.COLUMN_MERGE); |
| | | } else { |
| | | head.add(ExcelUtils.COLUMN_MERGE); |
| | | } |
| | | } |
| | | List<Object> head1 = new ArrayList<>(); |
| | | head1.add("开始年/月"); |
| | | head1.add(ExcelUtils.COLUMN_MERGE); |
| | | head1.add("结束年/月"); |
| | | head1.add(ExcelUtils.COLUMN_MERGE); |
| | | for (int i = 0; i < sys_lavor_issue.size(); i++) { |
| | | head1.add(""); |
| | | } |
| | | |
| | | List<Object> head2 = new ArrayList<>(); |
| | | head2.add("2025"); |
| | | head2.add("1"); |
| | | head2.add("2025"); |
| | | head2.add("3"); |
| | | for (int i = 0; i < sys_lavor_issue.size(); i++) { |
| | | head2.add(""); |
| | | } |
| | | List<Object> head3 = new ArrayList<>(); |
| | | head3.add("部门名称"); |
| | | head3.add(ExcelUtils.COLUMN_MERGE); |
| | | head3.add("姓名"); |
| | | head3.add("工号"); |
| | | for (SysDictData sysDictData : sys_lavor_issue) { |
| | | head3.add(sysDictData.getDictLabel()); |
| | | } |
| | | |
| | | List<List<Object>> sheetDataList = new ArrayList<>(); |
| | | sheetDataList.add(head); |
| | | sheetDataList.add(head1); |
| | | sheetDataList.add(head2); |
| | | sheetDataList.add(head3); |
| | | ExcelUtils.export(response, "劳保发放计划表", sheetDataList); |
| | | } |
| | | |
| | | 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对象 |
| | | } |
| | | } |