package cn.huge.module.file.service;
|
|
import cn.huge.base.common.exception.ServiceException;
|
import cn.huge.base.common.utils.DateUtils;
|
import cn.huge.base.common.utils.IdUtils;
|
import cn.huge.base.common.utils.ObjectUtils;
|
import cn.huge.module.client.api.impl.UtilsClientImpl;
|
import cn.huge.module.file.dao.mapper.FileRelateMapper;
|
import cn.huge.module.file.domain.po.FileInfo;
|
import cn.huge.module.file.domain.dto.UploaderDTO;
|
import cn.huge.module.file.domain.po.FileInfo;
|
import cn.huge.module.file.domain.po.FileRelate;
|
import cn.huge.module.sys.constant.FileOwnerTypeBaseEnum;
|
import cn.huge.module.sys.dto.FileInfoBaseDTO;
|
import cn.huge.module.sys.dto.FileTypeInfoBaseDTO;
|
import cn.huge.module.sys.dto.FileTypeTermsDTO;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.PageImpl;
|
import org.springframework.data.domain.PageRequest;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.PostConstruct;
|
import java.util.*;
|
|
/**
|
* @title: 附件关系表业务逻辑处理
|
* @Description 附件关系表业务逻辑处理
|
* @company hugeinfo
|
* @author liyj
|
* @Time 2024-08-28 20:06:19
|
* @version 1.0.0
|
*/
|
@Slf4j
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class FileRelateService extends ServiceImpl<FileRelateMapper, FileRelate>{
|
|
@Autowired
|
private FileRelateMapper mapper;
|
|
@Autowired
|
private UtilsClientImpl utilsClient;
|
|
/**
|
* 更新对象
|
* @param entity 对象
|
*/
|
public void updateFileRelate(FileRelate entity){
|
try{
|
mapper.updateFileRelate(entity);
|
}catch (Exception e){
|
log.error("[FileRelateService.updateFileRelate]调用失败,异常信息:"+e, e);
|
throw new ServiceException("FileRelateService.updateFileRelate", e);
|
}
|
}
|
|
/**
|
* 条件更新对象
|
* @param entity 对象
|
* @param terms 条件
|
*/
|
public void updateFileRelateTerms(FileRelate entity, Map<String, Object> terms){
|
try{
|
mapper.updateFileRelateTerms(entity, terms);
|
}catch (Exception e){
|
log.error("[FileRelateService.updateFileRelateTerms]调用失败,异常信息:"+e, e);
|
throw new ServiceException("FileRelateService.updateFileRelateTerms", e);
|
}
|
}
|
|
/**
|
* 根据编号物理删除
|
* @param id 查询条件集合
|
*/
|
public void deleteFileRelate(String id){
|
try{
|
mapper.deleteFileRelate(id);
|
}catch (Exception e){
|
log.error("[FileRelateService.deleteFileRelate]调用失败,异常信息:"+e, e);
|
throw new ServiceException("FileRelateService.deleteFileRelate", e);
|
}
|
}
|
|
/**
|
* 按条件查询
|
* @param terms 条件
|
* @return List
|
*/
|
public List<FileRelate> listTerms(Map<String, Object> terms){
|
return mapper.listTerms(terms);
|
}
|
|
/**
|
* 按条件统计
|
* @param terms 条件
|
* @return long
|
*/
|
public long countTerms(Map<String, Object> terms){
|
return mapper.countTerms(terms);
|
}
|
|
/**
|
* 按条件分页查询
|
* @param page 分页对象
|
* @param terms 条件
|
* @return Page
|
*/
|
public Page<FileRelate> pageQuery(PageRequest page, Map<String, Object> terms){
|
long total = mapper.countTerms(terms);
|
List<FileRelate> content = mapper.pageTerms(page, terms);
|
return new PageImpl<FileRelate>(content, page, total);
|
}
|
|
/**
|
* 新增或更新对象
|
* @param fileRelate 实体对象
|
*/
|
public void saveFileRelate(FileRelate fileRelate){
|
try{
|
Date nowDate = DateUtils.getNowDate();
|
// 判断是否新增
|
if (IdUtils.checkNewId(fileRelate.getId())){
|
fileRelate.setId(utilsClient.getNewTimeId());
|
fileRelate.setCreateTime(nowDate);
|
}
|
fileRelate.setUpdateTime(nowDate);
|
this.saveOrUpdate(fileRelate);
|
}catch (Exception e){
|
log.error("[FileRelateService.saveFileRelate]调用失败,异常信息:"+e, e);
|
throw new ServiceException("FileRelateService.saveFileRelate", e);
|
}
|
}
|
|
/**
|
* 根据所属业务编号和类型统计
|
* @param ownerId 所属业务编号
|
* @param ownerType 所属业务类型
|
* @return int 统计数
|
*/
|
public int countByOwnerIdAndType(String ownerId, String ownerType){
|
QueryWrapper<FileRelate> fileRelateQueryWrapper = new QueryWrapper<>();
|
fileRelateQueryWrapper.eq("owner_id", ownerId).eq("owner_type", ownerType);
|
return mapper.selectCount(fileRelateQueryWrapper);
|
}
|
|
/**
|
* 根据附件信息新增附件业务关系
|
* @param fileInfo 附件信息
|
*/
|
public void saveByFileInfo(FileInfo fileInfo) {
|
try {
|
// 保存业务关系
|
FileRelate fileRelate = new FileRelate();
|
fileRelate.setId(utilsClient.getNewTimeId());
|
fileRelate.setFileId(fileInfo.getId());
|
fileRelate.setMainId(fileInfo.getMainId());
|
fileRelate.setOwnerId(fileInfo.getOwnerId());
|
fileRelate.setOwnerCat(fileInfo.getOwnerCat());
|
fileRelate.setOwnerType(fileInfo.getOwnerType());
|
fileRelate.setUploaderId(fileInfo.getUploaderId());
|
fileRelate.setUploaderName(fileInfo.getUploaderName());
|
fileRelate.setUploaderType(fileInfo.getUploaderType());
|
fileRelate.setCustId(fileInfo.getCustId());
|
Date nowDate = DateUtils.getNowDate();
|
fileRelate.setCreateTime(nowDate);
|
fileRelate.setUpdateTime(nowDate);
|
mapper.insert(fileRelate);
|
} catch (Exception e) {
|
log.error("service方法[FileRelateService.uploadFile]调用失败,异常信息:"+e, e);
|
throw new ServiceException("FileRelateService.uploadFile", e);
|
}
|
}
|
|
/**
|
* 根据条件删除
|
* @param fileTypeTermsDTO 条件
|
*/
|
public void removeOne(FileTypeTermsDTO fileTypeTermsDTO){
|
try{
|
if (StringUtils.isNotEmpty(fileTypeTermsDTO.getOwnerId())) {
|
QueryWrapper<FileRelate> fileRelateQueryWrapper = new QueryWrapper<>();
|
fileRelateQueryWrapper.eq("owner_id", fileTypeTermsDTO.getOwnerId());
|
if (StringUtils.isNotEmpty(fileTypeTermsDTO.getOwnerType())) {
|
fileRelateQueryWrapper.eq("owner_type", fileTypeTermsDTO.getOwnerType());
|
}
|
if (CollectionUtils.isNotEmpty(fileTypeTermsDTO.getOwnerTypeList())) {
|
fileRelateQueryWrapper.in("owner_type", fileTypeTermsDTO.getOwnerTypeList());
|
}
|
mapper.delete(fileRelateQueryWrapper);
|
}
|
}catch (Exception e){
|
log.error("service方法[FileRelateService.removeOne]调用异常:"+e, e);
|
throw new ServiceException("FileRelateService.removeOne", e);
|
}
|
}
|
|
/**
|
* 根据条件删除
|
* @param fileTypeTermsDTO 条件
|
*/
|
public void removeAll(FileTypeTermsDTO fileTypeTermsDTO){
|
try{
|
if (CollectionUtils.isNotEmpty(fileTypeTermsDTO.getOwnerIdList())) {
|
QueryWrapper<FileRelate> fileRelateQueryWrapper = new QueryWrapper<>();
|
fileRelateQueryWrapper.in("owner_id", fileTypeTermsDTO.getOwnerIdList());
|
if (StringUtils.isNotEmpty(fileTypeTermsDTO.getOwnerType())) {
|
fileRelateQueryWrapper.eq("owner_type", fileTypeTermsDTO.getOwnerType());
|
}
|
if (CollectionUtils.isNotEmpty(fileTypeTermsDTO.getOwnerTypeList())) {
|
fileRelateQueryWrapper.in("owner_type", fileTypeTermsDTO.getOwnerTypeList());
|
}
|
mapper.delete(fileRelateQueryWrapper);
|
}
|
}catch (Exception e){
|
log.error("service方法[FileRelateService.removeAll]调用异常:"+e, e);
|
throw new ServiceException("FileRelateService.removeAll", e);
|
}
|
}
|
}
|