package com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.service.impl;
|
|
import com.alibaba.druid.util.StringUtils;
|
import com.gkhy.huataiFourierSpecialGasMonitor.application.attachment.service.dto.req.AttachmentAppReq;
|
import com.gkhy.huataiFourierSpecialGasMonitor.commons.enums.ResultCode;
|
import com.gkhy.huataiFourierSpecialGasMonitor.commons.exception.BusinessException;
|
import com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.converter.AttachmentDomainConverter;
|
import com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.dto.resp.AttachmentDomainDTO;
|
import com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.entity.AttachmentInfo;
|
import com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.repository.jpa.AttachmentReposity;
|
import com.gkhy.huataiFourierSpecialGasMonitor.domain.attachment.service.AttachmentDomainService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.ObjectUtils;
|
|
/**
|
* @email 1603559716@qq.com
|
* @author: zf
|
* @date: 2023/5/6
|
* @time: 14:50
|
*/
|
@Service
|
public class AttachmentDomainServiceImpl implements AttachmentDomainService {
|
@Autowired
|
private AttachmentReposity reposity;
|
|
@Autowired
|
private AttachmentDomainConverter converter;
|
|
@Override
|
public AttachmentDomainDTO save(AttachmentAppReq attachmentAppReq) {
|
if(ObjectUtils.isEmpty(attachmentAppReq)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL);
|
}
|
AttachmentInfo attachmentInfo = new AttachmentInfo();
|
BeanUtils.copyProperties(attachmentAppReq,attachmentInfo);
|
AttachmentInfo save = reposity.save(attachmentInfo);
|
return converter.getDomainDTO(save);
|
}
|
|
@Override
|
public AttachmentDomainDTO findByKey(String key) {
|
if (StringUtils.isEmpty(key)){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL);
|
}
|
AttachmentInfo attachmentInfo = reposity.findByFileKey(key);
|
return converter.getDomainDTO(attachmentInfo);
|
}
|
@Override
|
public AttachmentDomainDTO findById(Long id) {
|
if (id == null){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL);
|
}
|
AttachmentInfo attachmentInfo = reposity.getById(id);
|
return converter.getDomainDTO(attachmentInfo);
|
}
|
|
@Override
|
public int delete(Long id) {
|
if (id == null){
|
throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL);
|
}
|
return reposity.deleteAttachment(id);
|
}
|
}
|