对比新文件 |
| | |
| | | package org.jeecg.modules.dnc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.jeecg.modules.dnc.entity.DeviceInfo; |
| | | import org.jeecg.modules.dnc.entity.DocFile; |
| | | import org.jeecg.modules.dnc.entity.DocInfo; |
| | | import org.jeecg.modules.dnc.exception.ExceptionCast; |
| | | import org.jeecg.modules.dnc.mapper.DocFileMapper; |
| | | import org.jeecg.modules.dnc.mapper.DocInfoMapper; |
| | | import org.jeecg.modules.dnc.response.CommonCode; |
| | | import org.jeecg.modules.dnc.utils.ValidateUtil; |
| | | import org.jeecg.modules.dnc.utils.file.DocVersionUtil; |
| | | import org.jeecg.modules.dnc.response.DocumentCode; |
| | | import org.jeecg.modules.dnc.service.IDocFileService; |
| | | import org.jeecg.modules.dnc.service.IDocInfoService; |
| | | import org.jeecg.modules.dnc.service.IDocRelativeService; |
| | | import org.jeecg.modules.mdc.entity.MdcEquipment; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class DocFileServiceImpl extends ServiceImpl<DocFileMapper, DocFile> implements IDocFileService { |
| | | @Autowired |
| | | private DocInfoMapper docInfoMapper; |
| | | @Autowired |
| | | @Lazy |
| | | private IDocRelativeService docRelativeService; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean addDocFile(DocFile docFile) { |
| | | if(docFile == null) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | if(!ValidateUtil.validateString(docFile.getDocId())) |
| | | ExceptionCast.cast(DocumentCode.DOC_FILE_DOC_ID_NONE); |
| | | if(!ValidateUtil.validateString(docFile.getFileName()) || !ValidateUtil.validateString(docFile.getFileEncodeName())) |
| | | ExceptionCast.cast(DocumentCode.DOCUMENT_NAME_NONE); |
| | | if(!ValidateUtil.validateLong(docFile.getFileSize())) |
| | | ExceptionCast.cast(DocumentCode.DOC_FILE_SIZE_NONE); |
| | | /*if(!ValidateUtil.validateString(docFile.getFileSuffix())) |
| | | ExceptionCast.cast(DocumentCode.DOC_SUFFIX_ERROR);*/ |
| | | if(!ValidateUtil.validateString(docFile.getFilePath())) |
| | | ExceptionCast.cast(DocumentCode.DOC_FILE_PATH_NONE); |
| | | DocFile nearestFile = getDocFileNearest(docFile.getDocId()); |
| | | if(nearestFile == null) { |
| | | docFile.setDocVersion(DocVersionUtil.generateNewVersion(null)); |
| | | }else { |
| | | docFile.setDocVersion(DocVersionUtil.generateNewVersion(nearestFile.getDocVersion())); |
| | | } |
| | | return super.save(docFile); |
| | | } |
| | | |
| | | @Override |
| | | public DocFile getDocFileNearest(String docId) { |
| | | if(!ValidateUtil.validateString(docId)) |
| | | return null; |
| | | LambdaQueryWrapper<DocFile> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(DocFile::getDocId, docId).orderByDesc(DocFile::getCreateTime).orderByDesc(DocFile::getFileId); |
| | | return super.getOne(lambdaQueryWrapper, false); |
| | | } |
| | | |
| | | @Override |
| | | public List<DocFile> findListByDocId(String docId) { |
| | | DocInfo docInfo = docInfoMapper.selectById(docId); |
| | | if(!ValidateUtil.validateString(docId)) |
| | | return null; |
| | | List<DocFile> fileList=super.lambdaQuery().eq(DocFile::getDocId, docId).orderByDesc(DocFile::getFileId).list(); |
| | | fileList.forEach(item->{ |
| | | //瀵规瘮鐗堟湰 |
| | | item.setPublishFlag(docInfo.getPublishVersion().equals(item.getDocVersion())); |
| | | }); |
| | | return fileList; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean assignFileVersion(String fileId) { |
| | | if(!ValidateUtil.validateString(fileId)) |
| | | ExceptionCast.cast(CommonCode.INVALID_PARAM); |
| | | DocFile docFile = super.getById(fileId); |
| | | if(docFile == null) { |
| | | ExceptionCast.cast(DocumentCode.DOC_FILE_ERROR); |
| | | } |
| | | List<MdcEquipment> deviceList = docRelativeService.findDeviceByDocId(docFile.getDocId()); |
| | | if(deviceList != null && !deviceList.isEmpty()) |
| | | ExceptionCast.cast(DocumentCode.DOC_DEVICE_EXIST); |
| | | DocInfo docInfo = new DocInfo(); |
| | | docInfo.setDocId(docFile.getDocId()); |
| | | docInfo.setPublishFileId(docFile.getFileId()); |
| | | docInfo.setPublishVersion(docFile.getDocVersion()); |
| | | return docInfoMapper.updateById(docInfo) >= 0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean deleteByDocAttr(Integer type, String id) { |
| | | return super.getBaseMapper().deleteByDocAttr(type, id) >= 0; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = {Exception.class}) |
| | | public boolean deleteByDocId(String docId) { |
| | | LambdaQueryWrapper<DocFile> lambdaQueryWrapper = Wrappers.lambdaQuery(); |
| | | lambdaQueryWrapper.eq(DocFile::getDocId, docId); |
| | | return super.remove(lambdaQueryWrapper); |
| | | } |
| | | } |