package com.ruoyi.sales.service.impl; import cn.hutool.core.bean.BeanUtil; 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.basic.enums.ApplicationTypeEnum; import com.ruoyi.basic.enums.RecordTypeEnum; import com.ruoyi.basic.dto.StorageBlobDTO; import com.ruoyi.basic.dto.StorageBlobVO; import com.ruoyi.basic.utils.FileUtil; import com.ruoyi.framework.web.domain.AjaxResult; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.sales.dto.SalesLawsuitDTO; import com.ruoyi.sales.mapper.SalesLawsuitMapper; import com.ruoyi.sales.pojo.SalesLawsuit; import com.ruoyi.sales.service.ISalesLawsuitService; import com.ruoyi.sales.vo.SalesLawsuitVO; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * 诉讼管理 Service 实现 */ @Slf4j @Service public class SalesLawsuitServiceImpl extends ServiceImpl implements ISalesLawsuitService { @Resource private FileUtil fileUtil; @Override public IPage listPage(Page page, SalesLawsuitDTO dto) { LambdaQueryWrapper queryWrapper = buildQueryWrapper(dto); IPage iPage = this.page(page, queryWrapper); IPage voPage = iPage.convert(item -> { SalesLawsuitVO vo = BeanUtil.copyProperties(item, SalesLawsuitVO.class); return vo; }); return voPage; } @Override public AjaxResult getDetail(Long id) { SalesLawsuit lawsuit = this.getById(id); if (lawsuit == null) { return AjaxResult.error("数据不存在"); } SalesLawsuitVO vo = BeanUtil.copyProperties(lawsuit, SalesLawsuitVO.class); // 组装附件 List storageBlobVOs = fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId( ApplicationTypeEnum.FILE, RecordTypeEnum.SALES_LAWSUIT, id ); vo.setStorageBlobVOs(storageBlobVOs != null ? storageBlobVOs : new ArrayList<>()); return AjaxResult.success(vo); } @Override @Transactional(rollbackFor = Exception.class) public AjaxResult addOrUpdate(SalesLawsuitDTO dto) { SalesLawsuit lawsuit = BeanUtil.copyProperties(dto, SalesLawsuit.class); boolean isUpdate = lawsuit.getId() != null; if (isUpdate) { this.updateById(lawsuit); log.info("TODO: 同步更新项目时间轴中对应的诉讼事件节点 (projectId: {}, lawsuitId: {})", lawsuit.getProjectId(), lawsuit.getId()); } else { this.save(lawsuit); log.info("TODO: 在项目时间轴中追加一条诉讼节点 (projectId: {}, lawsuitId: {})", lawsuit.getProjectId(), lawsuit.getId()); } // 处理附件 List storageBlobDTOs = dto.getStorageBlobDTOs(); if (storageBlobDTOs == null) { storageBlobDTOs = new ArrayList<>(); } fileUtil.saveStorageAttachment( ApplicationTypeEnum.FILE, RecordTypeEnum.SALES_LAWSUIT, lawsuit.getId(), storageBlobDTOs ); return AjaxResult.success(); } @Override @Transactional(rollbackFor = Exception.class) public AjaxResult del(List ids) { if (CollectionUtils.isEmpty(ids)) { return AjaxResult.error("参数不能为空"); } List lawsuits = this.listByIds(ids); this.removeByIds(ids); for (SalesLawsuit lawsuit : lawsuits) { log.info("TODO: 同步移除项目时间轴中对应的诉讼事件节点 (projectId: {}, lawsuitId: {})", lawsuit.getProjectId(), lawsuit.getId()); } return AjaxResult.success(); } @Override public List selectList(SalesLawsuitDTO dto) { return this.list(buildQueryWrapper(dto)); } /** * 构建查询条件 */ private LambdaQueryWrapper buildQueryWrapper(SalesLawsuitDTO dto) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); if (dto == null) { return queryWrapper; } queryWrapper.like(StringUtils.isNotBlank(dto.getCaseNo()), SalesLawsuit::getCaseNo, dto.getCaseNo()); queryWrapper.eq(dto.getProjectId() != null, SalesLawsuit::getProjectId, dto.getProjectId()); queryWrapper.like(StringUtils.isNotBlank(dto.getProjectName()), SalesLawsuit::getProjectName, dto.getProjectName()); queryWrapper.eq(dto.getContractId() != null, SalesLawsuit::getContractId, dto.getContractId()); queryWrapper.like(StringUtils.isNotBlank(dto.getContractNo()), SalesLawsuit::getContractNo, dto.getContractNo()); queryWrapper.eq(StringUtils.isNotBlank(dto.getLawsuitStatus()), SalesLawsuit::getLawsuitStatus, dto.getLawsuitStatus()); queryWrapper.like(StringUtils.isNotBlank(dto.getLawyer()), SalesLawsuit::getLawyer, dto.getLawyer()); queryWrapper.ge(dto.getFilingDateStart() != null, SalesLawsuit::getFilingDate, dto.getFilingDateStart()); queryWrapper.le(dto.getFilingDateEnd() != null, SalesLawsuit::getFilingDate, dto.getFilingDateEnd()); queryWrapper.orderByDesc(SalesLawsuit::getCreateTime); return queryWrapper; } }