“djh”
2024-12-04 d1549b8445c65a6775cf1ba093f5040ace0f87e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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);
    }
}