package com.lxzn.nc.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 com.lxzn.base.service.IDncPassLogService;
|
import com.lxzn.framework.domain.activiti.response.ActivitiCode;
|
import com.lxzn.framework.domain.base.DncPassLog;
|
import com.lxzn.framework.domain.base.ext.NcTxtFilePathInfo;
|
import com.lxzn.framework.domain.nc.DeviceInfo;
|
import com.lxzn.framework.domain.nc.DocInfo;
|
import com.lxzn.framework.domain.nc.DocRelative;
|
import com.lxzn.framework.domain.ucenter.ButtonPermission;
|
import com.lxzn.framework.exception.ExceptionCast;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.utils.ValidateUtil;
|
import com.lxzn.framework.utils.date.DateUtil;
|
import com.lxzn.framework.utils.file.FileUtil;
|
import com.lxzn.nc.dao.DocRelativeMapper;
|
import com.lxzn.nc.service.IDeviceGroupService;
|
import com.lxzn.nc.service.IDeviceInfoService;
|
import com.lxzn.nc.service.IDocInfoService;
|
import com.lxzn.nc.service.IDocRelativeService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.codehaus.jackson.map.ObjectMapper;
|
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 IDocInfoService docInfoService;
|
@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) {
|
return this.baseMapper.deleteById(id);
|
}
|
|
@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 = docInfoService.getBaseMapper().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 = FileUtil.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("10A"+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());
|
FileUtil.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);
|
}
|
}
|