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.DncPassLog;
|
import org.jeecg.modules.dnc.entity.DocInfo;
|
import org.jeecg.modules.dnc.entity.DocRelative;
|
import org.jeecg.modules.dnc.exception.ExceptionCast;
|
import org.jeecg.modules.dnc.ext.NcTxtFilePathInfo;
|
import org.jeecg.modules.dnc.mapper.DocInfoMapper;
|
import org.jeecg.modules.dnc.mapper.DocRelativeMapper;
|
import org.jeecg.modules.dnc.response.CommonCode;
|
|
import org.jeecg.modules.dnc.service.*;
|
import org.jeecg.modules.dnc.utils.ValidateUtil;
|
import org.jeecg.modules.dnc.utils.date.DateUtil;
|
|
import org.jeecg.modules.dnc.utils.file.FileUtilS;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.List;
|
|
@Service
|
public class DocRelativeServiceImpl extends ServiceImpl<DocRelativeMapper, DocRelative> implements IDocRelativeService {
|
|
@Autowired
|
private DocInfoMapper docInfoMapper;
|
@Autowired
|
private IDeviceInfoService deviceInfoService;
|
@Autowired
|
private IDeviceGroupService deviceGroupService;
|
@Value("${securedoc.localFilePath}")
|
private String localFilePath;
|
@Autowired
|
private IDncPassLogService dncPassLogService;
|
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteByDocAttr(Integer attrType, String attrId) {
|
LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType).eq(DocRelative::getAttributionId, attrId);
|
return super.remove(lambdaQueryWrapper);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteByDocId(String id) {
|
LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(DocRelative::getDocId, id);
|
return super.remove(lambdaQueryWrapper);
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteDocByAttr(String docId, Integer attrType, String attrId) {
|
List<DocRelative> docRelatives = super.lambdaQuery().eq(DocRelative::getDocId, docId).
|
eq(DocRelative::getAttributionType, attrType).
|
eq(DocRelative::getAttributionId, attrId).list();
|
boolean docRel = false;
|
DocRelative docRelative = new DocRelative();
|
if (docRelatives != null && !docRelatives.isEmpty()) {
|
String classificationId = "1259647678577995778";
|
docRelative = docRelatives.get(0);
|
if (classificationId.equals(docRelative.getClassificationId())) {
|
docRel = true;
|
}
|
}
|
LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(DocRelative::getDocId, docId);
|
lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType);
|
lambdaQueryWrapper.eq(DocRelative::getAttributionId, attrId);
|
boolean b = super.remove(lambdaQueryWrapper);
|
|
if (b && docRel) {
|
DocInfo info = docInfoMapper.selectById(docId);
|
DeviceInfo deviceInfo = deviceInfoService.getById(attrId);
|
List<String> strings = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId());
|
if (strings != null && !strings.isEmpty()) {
|
String path = StringUtils.join(strings.toArray(), "/");
|
boolean deleteFile = FileUtilS.deleteFilePathZip(path + "/"+ deviceInfo.getDeviceNo(),
|
info.getDocName(), info.getDocSuffix());
|
if (!deleteFile) {
|
return false;
|
}
|
DncPassLog dncPassLog = dncPassLogService.findDayTime(DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY));
|
Integer fileTxt = 0, fileNc =0;
|
if (dncPassLog !=null) {
|
fileTxt = dncPassLog.getSequenceNumber() + 1;
|
fileNc = fileTxt + 1;
|
} else {
|
fileTxt = 1;
|
fileNc = fileTxt + 1;
|
}
|
String sequence = String.format("%06d",fileTxt);
|
DncPassLog passInfoNc = new DncPassLog();
|
passInfoNc.setSequenceNumber(fileNc);
|
passInfoNc.setSequenceOrder(sequence);
|
passInfoNc.setDayTime(DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY));
|
passInfoNc.setPassType("02");
|
passInfoNc.setPassName(info.getDocName()+"."+info.getDocSuffix());
|
passInfoNc.setCreateTime(DateUtil.getNow());
|
dncPassLogService.save(passInfoNc);
|
//处理文件名称 文件路径
|
|
NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
|
ncTxt.setEquipmentId(deviceInfo.getDeviceNo());
|
ncTxt.setFilePath(path + "/"+ deviceInfo.getDeviceNo() + "/" );
|
ncTxt.setFileTxtName("02A"+DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY)+sequence);
|
ncTxt.setOrigFileName(info.getDocName());
|
ncTxt.setOrigFileSuffix(info.getDocSuffix());
|
ncTxt.setFileAddOrDelete(2);
|
String loFilePath = localFilePath + "\\" + ncTxt.getFileTxtName() + ".nc";
|
try {
|
/* ObjectMapper mapper = new ObjectMapper();
|
String json = mapper.writeValueAsString(ncTxt);*/
|
String allList = new String();
|
allList=(ncTxt.getFileTxtName()+"\n");
|
allList+=(ncTxt.getFileNcName()+"\n");
|
allList+=(ncTxt.getOrigFileName()+"\n");
|
allList+=(ncTxt.getOrigFileSuffix()+"\n");
|
allList+=(ncTxt.getFilePath()+"\n");
|
allList+=(ncTxt.getEquipmentId()+"\n");
|
allList+=(ncTxt.getFileAddOrDelete().toString());
|
FileUtilS.fileWriterSql(loFilePath,allList);
|
}catch (Exception e) {
|
return true;
|
}
|
}
|
}
|
return b;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean deleteCopyDocByAttrNext(String docId, Integer attrType, String attrId) {
|
LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
lambdaQueryWrapper.eq(DocRelative::getDocId, docId);
|
lambdaQueryWrapper.eq(DocRelative::getAttributionType, attrType);
|
lambdaQueryWrapper.eq(DocRelative::getAttributionId, attrId);
|
boolean b = super.remove(lambdaQueryWrapper);
|
return b;
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public List<DeviceInfo> findDeviceByDocId(String docId) {
|
if(!ValidateUtil.validateString(docId))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
return super.getBaseMapper().findDeviceByDocId(docId);
|
}
|
}
|