| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.entity.CalculateRecord; |
| | | import com.ycl.platform.domain.entity.CalculateReport; |
| | | import com.ycl.platform.domain.excel.CalculateExport; |
| | | import com.ycl.platform.domain.form.CalculateReportBackfillForm; |
| | | import com.ycl.platform.domain.vo.CalculateRecordVO; |
| | | import com.ycl.platform.domain.form.CalculateReportForm; |
| | | import com.ycl.platform.domain.query.CalculateReportQuery; |
| | | import com.ycl.platform.domain.vo.CalculateReportDetailVO; |
| | | import com.ycl.platform.domain.vo.CalculateReportVO; |
| | | import com.ycl.platform.mapper.CalculateRecordMapper; |
| | | import com.ycl.platform.mapper.CalculateReportMapper; |
| | | import com.ycl.platform.service.CalculateReportService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.CalculateReportForm; |
| | | import com.ycl.platform.domain.vo.CalculateReportVO; |
| | | import com.ycl.platform.domain.query.CalculateReportQuery; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.system.page.PageUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import enumeration.general.CalculateReportStatusEnum; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import java.util.ArrayList; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | |
| | | /** |
| | | * 核算报告 服务实现类 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | public Result remove(List<Long> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | public Result removeById(Long id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | |
| | | public Result page(CalculateReportQuery query) { |
| | | IPage<CalculateReportVO> page = PageUtil.getPage(query, CalculateReportVO.class); |
| | | baseMapper.page(query, page); |
| | | page.getRecords().stream().forEach(item -> { |
| | | if (Objects.isNull(item)) { |
| | | item.setCanPublish(Boolean.FALSE); |
| | | } else { |
| | | item.setCanPublish(Boolean.TRUE); |
| | | } |
| | | }); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result detail(String id) { |
| | | CalculateReport entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | CalculateReportVO vo = CalculateReportVO.getVoByEntity(entity, null); |
| | | public Result detail(Long id) { |
| | | // 明细列表 |
| | | List<CalculateRecordVO> recordList = calculateRecordMapper.getByContractId(entity.getContractId()); |
| | | vo.setRecordList(recordList); |
| | | return Result.ok().data(vo); |
| | | CalculateReportDetailVO detail = baseMapper.getById(id); |
| | | if (Objects.nonNull(detail) && ! CollectionUtils.isEmpty(detail.getRecordList())) { |
| | | if (CalculateReportStatusEnum.NOT_PUBLISH.equals(detail.getStatus())) { |
| | | detail.getRecordList().get(0).setLatest(Boolean.TRUE); |
| | | } else { |
| | | detail.getRecordList().get(0).setLatest(Boolean.FALSE); |
| | | } |
| | | } |
| | | return Result.ok().data(detail); |
| | | } |
| | | |
| | | /** |
| | |
| | | public Result all() { |
| | | List<CalculateReport> entities = baseMapper.selectList(null); |
| | | List<CalculateReportVO> vos = entities.stream() |
| | | .map( |
| | | entity -> CalculateReportVO.getVoByEntity(entity, null) |
| | | ) |
| | | .map(entity -> CalculateReportVO.getVoByEntity(entity, null)) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | |
| | | if (Objects.isNull(report)) { |
| | | throw new RuntimeException("该核算报告不存在"); |
| | | } |
| | | // 累加得到扣款总额 |
| | | BigDecimal totalDeduct = form.getRecordList().stream() |
| | | .map(CalculateReportBackfillForm.RecordForm::getDeductMoney) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | if (CalculateReportStatusEnum.PUBLISHED.equals(report.getStatus())) { |
| | | throw new RuntimeException("最新一次核算报告已经发布,无法修改"); |
| | | } |
| | | CalculateReportBackfillForm.RecordForm latestRecord = form.getRecordList().get(0); |
| | | CalculateRecord beforeRecord = calculateRecordMapper.selectById(latestRecord.getId()); |
| | | if (Objects.isNull(beforeRecord)) { |
| | | throw new RuntimeException("最近一次核算记录不存在"); |
| | | } |
| | | // 计算得到扣款总额(只算最近一条) |
| | | BigDecimal totalDeduct = report.getDeductMoney().subtract(latestRecord.getDeductMoney()).add(latestRecord.getDeductMoney()); |
| | | report.setDeductMoney(totalDeduct); |
| | | baseMapper.updateById(report); |
| | | form.getRecordList().stream().forEach(item -> { |
| | | new LambdaUpdateChainWrapper<>(calculateRecordMapper) |
| | | .eq(CalculateRecord::getId, item.getId()) |
| | | .set(CalculateRecord::getDeductMoney, item.getDeductMoney()) |
| | | .update(); |
| | | }); |
| | | |
| | | beforeRecord.setDeductMoney(latestRecord.getDeductMoney()); |
| | | calculateRecordMapper.updateById(beforeRecord); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result updatePublishStatus(Long reportId) { |
| | | CalculateReport report = baseMapper.selectById(reportId); |
| | | if (Objects.isNull(report)) { |
| | | throw new RuntimeException("该核算报告不存在"); |
| | | } |
| | | if (CalculateReportStatusEnum.NOT_PUBLISH.equals(report.getStatus())) { |
| | | report.setStatus(CalculateReportStatusEnum.PUBLISHED); |
| | | } else if (CalculateReportStatusEnum.PUBLISHED.equals(report.getStatus())) { |
| | | report.setStatus(CalculateReportStatusEnum.NOT_PUBLISH); |
| | | } |
| | | baseMapper.updateById(report); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void export(Integer contractId, HttpServletResponse response) { |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | String fileName = URLEncoder.encode("核算报告", StandardCharsets.UTF_8).replace("\\+", "%20"); |
| | | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); |
| | | EasyExcel.write(response.getOutputStream(), CalculateExport.class) |
| | | .sheet("核算报告") |
| | | .doWrite(baseMapper.exportData(contractId)); |
| | | } |
| | | } |