package com.gkhy.labRiskManage.domain.attachment.service.impl; import com.alibaba.druid.util.StringUtils; import com.gkhy.labRiskManage.application.attachment.service.dto.req.AttachmentAppReq; import com.gkhy.labRiskManage.commons.enums.ResultCode; import com.gkhy.labRiskManage.commons.exception.BusinessException; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.attachment.converter.AttachmentDomainConverter; import com.gkhy.labRiskManage.domain.attachment.dto.resp.AttachmentDomainDTO; import com.gkhy.labRiskManage.domain.attachment.entity.AttachmentInfo; import com.gkhy.labRiskManage.domain.attachment.repository.jpa.AttachmentReposity; import com.gkhy.labRiskManage.domain.attachment.service.AttachmentDomainService; import org.checkerframework.checker.units.qual.K; 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); } }