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.apache.commons.lang3.StringUtils;
|
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.IDeviceGroupService;
|
import org.jeecg.modules.dnc.service.IDeviceInfoService;
|
import org.jeecg.modules.dnc.service.IDocRelativeService;
|
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.jeecg.modules.mdc.entity.MdcEquipment;
|
import org.jeecg.modules.mdc.service.IMdcEquipmentService;
|
import org.jeecg.modules.system.service.IMdcProductionService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
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 IMdcEquipmentService iMdcEquipmentService;
|
@Autowired
|
private IMdcProductionService iMdcProductionService;
|
|
|
@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);
|
//todo 修改为mdc设备
|
MdcEquipment mdcEquipment=iMdcEquipmentService.getById(attrId);
|
List<String> strings = iMdcProductionService.findListParentTreeAll(mdcEquipment.getId());
|
if (strings != null && !strings.isEmpty()) {
|
String path = StringUtils.join(strings.toArray(), "/");
|
boolean deleteFile = FileUtilS.deleteFilePathZip(path + "/"+ mdcEquipment.getEquipmentId(),
|
info.getDocName(), info.getDocSuffix());
|
if (!deleteFile) {
|
return false;
|
}
|
//处理文件名称 文件路径
|
|
NcTxtFilePathInfo ncTxt = new NcTxtFilePathInfo();
|
ncTxt.setEquipmentId(mdcEquipment.getEquipmentId());
|
ncTxt.setFilePath(path + "/"+ mdcEquipment.getEquipmentId() + "/" );
|
ncTxt.setFileTxtName("02A"+DateUtil.format(DateUtil.getNow(),DateUtil.STR_YEARMONTHDAY));
|
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<MdcEquipment> findDeviceByDocId(String docId) {
|
if(!ValidateUtil.validateString(docId))
|
ExceptionCast.cast(CommonCode.INVALID_PARAM);
|
return super.getBaseMapper().findDeviceByDocId(docId);
|
}
|
}
|