| | |
| | | import cn.iocoder.yudao.module.mes.dal.dataobject.pd.document.MesPdDocumentDO; |
| | | import cn.iocoder.yudao.module.mes.dal.mysql.pd.document.MesPdDocumentMapper; |
| | | import cn.iocoder.yudao.module.mes.service.pd.project.MesPdProjectService; |
| | | import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi; |
| | | import jakarta.annotation.Resource; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Resource |
| | | @Lazy |
| | | private MesPdProjectService projectService; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | |
| | | @Override |
| | | public Long createDocument(MesPdDocumentSaveReqVO createReqVO) { |
| | |
| | | // 插入 |
| | | MesPdDocumentDO document = BeanUtils.toBean(createReqVO, MesPdDocumentDO.class); |
| | | documentMapper.insert(document); |
| | | storageAttachmentApi.bindAttachments("file", "mes_pd_document", |
| | | document.getId(), createReqVO.getBlobIds()); |
| | | return document.getId(); |
| | | } |
| | | |
| | |
| | | // 更新 |
| | | MesPdDocumentDO updateObj = BeanUtils.toBean(updateReqVO, MesPdDocumentDO.class); |
| | | documentMapper.updateById(updateObj); |
| | | if (updateReqVO.getBlobIds() != null) { |
| | | storageAttachmentApi.deleteAttachmentsByRecord("mes_pd_document", updateReqVO.getId()); |
| | | storageAttachmentApi.bindAttachments("file", "mes_pd_document", |
| | | updateReqVO.getId(), updateReqVO.getBlobIds()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void deleteDocument(Long id) { |
| | | // 校验存在 |
| | | validateDocumentExists(id); |
| | | // 删除附件 |
| | | storageAttachmentApi.deleteAttachmentsByRecord("mes_pd_document", id); |
| | | // 删除 |
| | | documentMapper.deleteById(id); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void deleteByProjectId(Long projectId) { |
| | | List<MesPdDocumentDO> documents = documentMapper.selectListByProjectId(projectId); |
| | | for (MesPdDocumentDO document : documents) { |
| | | storageAttachmentApi.deleteAttachmentsByRecord("mes_pd_document", document.getId()); |
| | | } |
| | | documentMapper.deleteByProjectId(projectId); |
| | | } |
| | | |