From 7a7dbbd34179b79caf3b74dedf2d5b84f30d0c05 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期五, 26 四月 2024 11:13:08 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 170 insertions(+), 0 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java new file mode 100644 index 0000000..99edde0 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CalculateReportServiceImpl.java @@ -0,0 +1,170 @@ +package com.ycl.platform.service.impl; + +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; +import com.ycl.platform.domain.entity.CalculateRecord; +import com.ycl.platform.domain.entity.CalculateReport; +import com.ycl.platform.domain.form.CalculateReportBackfillForm; +import com.ycl.platform.domain.vo.CalculateRecordVO; +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 org.springframework.beans.BeanUtils; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; +import java.util.ArrayList; +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; + +/** + * 鏍哥畻鎶ュ憡 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2024-04-23 + */ +@Service +@RequiredArgsConstructor +public class CalculateReportServiceImpl extends ServiceImpl<CalculateReportMapper, CalculateReport> implements CalculateReportService { + + private final CalculateReportMapper calculateReportMapper; + private final CalculateRecordMapper calculateRecordMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(CalculateReportForm form) { + CalculateReport entity = CalculateReportForm.getEntityByForm(form, null); + if(baseMapper.insert(entity) > 0) { + return Result.ok("娣诲姞鎴愬姛"); + } + return Result.error("娣诲姞澶辫触"); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(CalculateReportForm form) { + + CalculateReport entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + if (baseMapper.updateById(entity) > 0) { + return Result.ok("淇敼鎴愬姛"); + } + return Result.error("淇敼澶辫触"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + if(baseMapper.deleteBatchIds(ids) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + if(baseMapper.deleteById(id) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(CalculateReportQuery query) { + IPage<CalculateReportVO> page = PageUtil.getPage(query, CalculateReportVO.class); + baseMapper.page(query, page); + return Result.ok().data(page.getRecords()).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + CalculateReport entity = baseMapper.selectById(id); + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + CalculateReportVO vo = CalculateReportVO.getVoByEntity(entity, null); + // 鏄庣粏鍒楄〃 + List<CalculateRecordVO> recordList = calculateRecordMapper.getByContractId(entity.getContractId()); + vo.setRecordList(recordList); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<CalculateReport> entities = baseMapper.selectList(null); + List<CalculateReportVO> vos = entities.stream() + .map( + entity -> CalculateReportVO.getVoByEntity(entity, null) + ) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Result backfill(CalculateReportBackfillForm form) { + CalculateReport report = baseMapper.selectById(form.getId()); + if (Objects.isNull(report)) { + throw new RuntimeException("璇ユ牳绠楁姤鍛婁笉瀛樺湪"); + } + // 绱姞寰楀埌鎵f鎬婚 + BigDecimal totalDeduct = form.getRecordList().stream() + .map(CalculateReportBackfillForm.RecordForm::getDeductMoney) + .reduce(BigDecimal.ZERO, BigDecimal::add); + 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(); + }); + return Result.ok("鎿嶄綔鎴愬姛"); + } +} -- Gitblit v1.8.0