package com.lxzn.plm.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.additional.query.impl.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.lxzn.activiti.service.IAssignFileStreamService;
|
import com.lxzn.base.service.IDncLogService;
|
import com.lxzn.base.service.IEquipmentClassService;
|
import com.lxzn.framework.domain.base.DncLog;
|
import com.lxzn.framework.domain.base.EquipmentClass;
|
import com.lxzn.framework.domain.filesystem.response.FileUploadResult;
|
import com.lxzn.framework.domain.nc.*;
|
import com.lxzn.framework.domain.nc.response.DocumentCode;
|
import com.lxzn.framework.domain.plm.PdmProgramSource;
|
import com.lxzn.framework.domain.plm.QueryNcProgramLog;
|
import com.lxzn.framework.domain.plm.ext.PdmProgramResult;
|
import com.lxzn.framework.domain.plm.ext.PdmProgramReturn;
|
import com.lxzn.framework.domain.plm.ext.PdmProgramSourceExt;
|
import com.lxzn.framework.domain.plm.request.PdmProgramSourceRequest;
|
import com.lxzn.framework.exception.ExceptionCast;
|
import com.lxzn.framework.model.response.CommonCode;
|
import com.lxzn.framework.model.response.QueryPageResponseResult;
|
import com.lxzn.framework.utils.*;
|
import com.lxzn.framework.utils.date.DateUtil;
|
import com.lxzn.framework.utils.file.FileUtil;
|
import com.lxzn.nc.service.*;
|
import com.lxzn.plm.dao.PdmProgramSourceMapper;
|
import com.lxzn.plm.service.IPdmProgramSourceService;
|
import com.lxzn.plm.service.IQueryNcProgramLogService;
|
import com.lxzn.plm.service.PdmWebClientApi;
|
import lombok.extern.slf4j.Slf4j;
|
import net.lingala.zip4j.io.ZipInputStream;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author clown
|
* * @date 2022/9/19
|
*/
|
@Service
|
@Slf4j
|
@PropertySource("classpath:/scheduled.properties")
|
public class PdmProgramSourceServiceImpl extends ServiceImpl<PdmProgramSourceMapper,PdmProgramSource> implements IPdmProgramSourceService {
|
|
@Autowired
|
private IQueryNcProgramLogService queryNcProgramLogService;
|
@Autowired
|
private IProductInfoService productInfoService;
|
@Autowired
|
private PdmWebClientApi pdmWebClientApi;
|
@Autowired
|
private IComponentInfoService componentInfoService;
|
@Autowired
|
private IPermissionStreamService permissionStreamService;
|
@Autowired
|
private IComponentDepartmentService componentDepartmentService;
|
@Autowired
|
private IComponentPermissionService componentPermissionService;
|
@Autowired
|
private IPartsInfoService partsInfoService;
|
@Autowired
|
private IPartsDepartmentService partsDepartmentService;
|
@Autowired
|
private IPartsPermissionService partsPermissionService;
|
@Autowired
|
private IProcessStreamService processStreamService;
|
@Autowired
|
private IDocInfoService docInfoService;
|
@Autowired
|
private IDocRelativeService docRelativeService;
|
@Autowired
|
private IDocFileService docFileService;
|
@Autowired
|
private IDocClassificationService docClassificationService;
|
@Autowired
|
private IDncLogService dncLogService;
|
@Autowired
|
private IEquipmentClassService equipmentClassService;
|
@Autowired
|
private IAssignFileStreamService assignFileStreamService;
|
|
|
@Value("${ncPdm.file_path}")
|
private String filePath;
|
|
@Value("${ncPdm.product.root}")
|
private String ncPdmProduct;
|
|
|
@Override
|
/* @Scheduled(cron = "${plmCron}")*/
|
public void pdmProgramSourceList() {
|
List<QueryNcProgramLog> logList = queryNcProgramLogService.findListNcLog();
|
if (logList == null || logList.isEmpty()) {
|
log.error("======= 无日志新增记录=======");
|
return;
|
}
|
List<PdmProgramSource> sourceList = new ArrayList<>();
|
for (QueryNcProgramLog ncLog : logList ) {
|
DncLog dncLog = new DncLog();
|
dncLog.setNcType(LogCodeUtil.plm_code);
|
PdmProgramReturn pro = new PdmProgramReturn();
|
pro.setSkgxId(ncLog.getSkgxId());
|
pro.setPartRevId(ncLog.getSkgxRevId());
|
pro.setSqzt(ncLog.getSqzt());
|
JsonMapper mapper = new JsonMapper();
|
try {
|
Object[] objects = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"",""};
|
//String program = "{\"code\":1,\"message\":\"\",\"response\":[{\"skgx_id\":\"CX信息中心10000070\",\"skgx_rev_id\":\"1\",\"skgx_name\":\"焊接数控程序\",\"sqzt\":\"S状态\",\"ae8nc_cxno\":\"CX信息中心10000070\",\"ae8nc_gfrev\":\"1\",\"ae8nc_sbno\":\"2240080\",\"ae8nc_jcid\":\"QJK006\",\"ae8nc_os\":\"华中数控-HNC848C\",\"ae8nc_filename\":\"107052PA5\",\"ae8nc_cxfz\":\"计算机仿真\",\"ae8nc_operator\":\"\",\"ae8nc_inspect\":\"\",\"ae8nc_acceptview\":\"\",\"ae8nc_cxno_unit\":\"信息中心\",\"ae8nc_filename_unit\":\"PA\",\"ae8gallery\":\"\",\"ae8nc_plant\":\"信息中心\",\"ae8nc_modelno\":\"jx\",\"ae8nc_batchno\":\"\",\"meop_id\":\"OPHJ000000000049108\",\"meop_rev_id\":\"A\",\"meop_name\":\"焊接\",\"meop_type\":\"AE8Operation Revision\",\"ae8gx_no\":\"5\",\"process_id\":\"JZG2022008107653\",\"process_rev_id\":\"1\",\"process_name\":\"107052\",\"ae8part_no\":\"107052\",\"ae8stageidentifying\":\"L\",\"ae8gy_type\":\"机加工艺设计\",\"ae8plant\":\"信息中心\",\"part_id\":\"1047051\",\"part_rev_id\":\"01\",\"part_name\":\"集成测试件\",\"create_by\":\"用户2(user2)\",\"create_date\":\"02-9月-22 17:15:14\",\"filename\":\"DNC-CX信息中心10000070-1.zip\",\"filepath\":\"http://localhost:9099/resources/images/login/bj_bak.png\"}]}\n";
|
String program =pdmWebClientApi.queryNcProgramAttrInfo(objects);
|
if (StringUtils.isEmpty(program)) {
|
log.error("======= 无 "+ ncLog.getSkgxId() +" 新增记录=======");
|
continue;
|
}
|
PdmProgramResult result = mapper.fromJson(program, new TypeReference<PdmProgramResult>() {
|
});
|
if (result == null ) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
continue;
|
}
|
if (result.getResponse() == null) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
continue;
|
}
|
dncLog.setContentName(program);
|
List<PdmProgramSourceExt> pdmExt = result.getResponse();
|
PdmProgramSource source = new PdmProgramSource();
|
if(pdmExt == null || pdmExt.isEmpty()) {
|
log.error("======= pdmExt =======");
|
continue;
|
}
|
BeanMapper.copy(pdmExt.get(0),source);
|
//处理字段位空的问题 不进行数据保存 直接返回
|
if(StringUtils.isEmpty(source.getFilePath() )) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"无程序","失败",null};
|
ncProgramReceived(receivedObject);
|
continue;
|
}
|
if (StringUtils.isEmpty(source.getAe8ncSbno())
|
|| StringUtils.isEmpty(source.getProcessRevId())
|
|| StringUtils.isEmpty(source.getAe8ncPlant())
|
|| StringUtils.isEmpty(source.getAe8partNo())
|
|| StringUtils.isEmpty(source.getAe8gxNo())) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"数据缺失内容","失败",null};
|
ncProgramReceived(receivedObject);
|
continue;
|
}
|
sourceList.add(source);
|
//权限分配
|
boolean b = saveProductInfo(source);
|
if (!b) {
|
log.error("======= 权限分配,请联系开发人员=======");
|
continue;
|
}
|
super.save(source);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"","成功",null};
|
try {
|
String programReceived = ncProgramReceived(receivedObject);
|
dncLog.setIsSuccess(LogCodeUtil.success_is_true);
|
dncLog.setRemarks("数据生成成功");
|
dncLogService.save(dncLog);
|
log.info(programReceived);
|
}catch (Exception e) {
|
continue;
|
}
|
|
}catch (Exception e) {
|
e.printStackTrace();
|
continue;
|
}
|
}
|
queryNcProgramLogService.saveBatch(logList);
|
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean pdmProgramSyncSave(QueryNcProgramLog ncLog) {
|
if (ncLog == null ) {
|
log.error("======= 无日志新增记录=======");
|
return false;
|
}
|
//queryNcProgramLogService.save(ncLog);
|
DncLog dncLog = new DncLog();
|
dncLog.setNcType(LogCodeUtil.plm_code);
|
PdmProgramReturn pro = new PdmProgramReturn();
|
pro.setSkgxId(ncLog.getSkgxId());
|
pro.setPartRevId(ncLog.getSkgxRevId());
|
pro.setSqzt(ncLog.getSqzt());
|
JsonMapper mapper = new JsonMapper();
|
PdmProgramSource source = new PdmProgramSource();
|
try {
|
Object[] objects = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"",""};
|
//String program = "{\"code\":1,\"message\":\"\",\"response\":[{\"skgx_id\":\"CX信息中心10000070\",\"skgx_rev_id\":\"1\",\"skgx_name\":\"焊接数控程序\",\"sqzt\":\"S状态\",\"ae8nc_cxno\":\"CX信息中心10000070\",\"ae8nc_gfrev\":\"1\",\"ae8nc_sbno\":\"2240080\",\"ae8nc_jcid\":\"QJK006\",\"ae8nc_os\":\"华中数控-HNC848C\",\"ae8nc_filename\":\"107052PA5\",\"ae8nc_cxfz\":\"计算机仿真\",\"ae8nc_operator\":\"\",\"ae8nc_inspect\":\"\",\"ae8nc_acceptview\":\"\",\"ae8nc_cxno_unit\":\"信息中心\",\"ae8nc_filename_unit\":\"PA\",\"ae8gallery\":\"\",\"ae8nc_plant\":\"信息中心\",\"ae8nc_modelno\":\"jx\",\"ae8nc_batchno\":\"\",\"meop_id\":\"OPHJ000000000049108\",\"meop_rev_id\":\"A\",\"meop_name\":\"焊接\",\"meop_type\":\"AE8Operation Revision\",\"ae8gx_no\":\"5\",\"process_id\":\"JZG2022008107653\",\"process_rev_id\":\"1\",\"process_name\":\"107052\",\"ae8part_no\":\"107052\",\"ae8stageidentifying\":\"L\",\"ae8gy_type\":\"机加工艺设计\",\"ae8plant\":\"信息中心\",\"part_id\":\"1047051\",\"part_rev_id\":\"01\",\"part_name\":\"集成测试件\",\"create_by\":\"用户2(user2)\",\"create_date\":\"02-9月-22 17:15:14\",\"filename\":\"DNC-CX信息中心10000070-1.zip\",\"filepath\":\"http://192.168.2.234:8081/ncprogram/202209/DNC-CX信息中心10000070-1.zip\"}]}\n";
|
String program =pdmWebClientApi.queryNcProgramAttrInfo(objects);
|
if (StringUtils.isEmpty(program)) {
|
log.error("======= 无 "+ ncLog.getSkgxId() +" 新增记录=======");
|
return false;
|
}
|
PdmProgramResult result = mapper.fromJson(program, new TypeReference<PdmProgramResult>() {
|
});
|
if (result == null ) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
return false;
|
}
|
if (result.getResponse() == null) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
return false;
|
}
|
dncLog.setContentName(program);
|
List<PdmProgramSourceExt> pdmExt = result.getResponse();
|
|
if(pdmExt == null || pdmExt.isEmpty()) {
|
log.error("======= pdmExt =======");
|
return false;
|
}
|
BeanMapper.copy(pdmExt.get(0),source);
|
//处理字段位空的问题 不进行数据保存 直接返回
|
if(StringUtils.isEmpty(source.getFilePath() )) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"失败","无程序",null};
|
ncProgramReceived(receivedObject);
|
return false;
|
}
|
if (StringUtils.isEmpty(source.getAe8ncSbno())
|
|| StringUtils.isEmpty(source.getProcessRevId())
|
|| StringUtils.isEmpty(source.getAe8ncPlant())
|
|| StringUtils.isEmpty(source.getAe8partNo())
|
|| StringUtils.isEmpty(source.getAe8gxNo())) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"失败","数据缺失内容",null};
|
ncProgramReceived(receivedObject);
|
return true;
|
}
|
//权限分配
|
boolean b = saveProductInfo(source);
|
if (!b) {
|
log.error("======= 权限分配,请联系开发人员=======");
|
return false;
|
}
|
super.save(source);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"成功","",null};
|
try {
|
String programReceived = ncProgramReceived(receivedObject);
|
dncLog.setIsSuccess(LogCodeUtil.success_is_true);
|
dncLog.setRemarks("数据生成成功");
|
dncLogService.save(dncLog);
|
log.info(programReceived);
|
}catch (Exception e) {
|
return false;
|
}
|
|
}catch (Exception e) {
|
e.printStackTrace();
|
return false;
|
}
|
return true;
|
}
|
|
@Override
|
@Scheduled(cron = "${plmCron}")
|
public boolean pdmSaveSyncNew() {
|
List<QueryNcProgramLog> logNcs = queryNcProgramLogService.findLogNewLogOneDate();
|
if (logNcs == null || logNcs.isEmpty()) {
|
return false;
|
}
|
QueryNcProgramLog ncLog = logNcs.get(0);
|
if (ncLog == null ) {
|
log.error("======= 无日志新增记录=======");
|
return false;
|
}
|
//queryNcProgramLogService.save(ncLog);
|
DncLog dncLog = new DncLog();
|
dncLog.setNcType(LogCodeUtil.plm_code);
|
|
PdmProgramReturn pro = new PdmProgramReturn();
|
pro.setSkgxId(ncLog.getSkgxId());
|
pro.setPartRevId(ncLog.getSkgxRevId());
|
pro.setSqzt(ncLog.getSqzt());
|
JsonMapper mapper = new JsonMapper();
|
PdmProgramSource source = new PdmProgramSource();
|
try {
|
Object[] objects = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"",""};
|
String program = "{\"code\":1,\"message\":\"\",\"response\":[{\"skgx_id\":\"CX信息中心10000070\",\"skgx_rev_id\":\"1\",\"skgx_name\":\"焊接数控程序\",\"sqzt\":\"S状态\",\"ae8nc_cxno\":\"CX信息中心10000070\",\"ae8nc_gfrev\":\"1\",\"ae8nc_sbno\":\"2240080\",\"ae8nc_jcid\":\"QJK006\",\"ae8nc_os\":\"华中数控-HNC848C\",\"ae8nc_filename\":\"107052PA5\",\"ae8nc_cxfz\":\"计算机仿真\",\"ae8nc_operator\":\"\",\"ae8nc_inspect\":\"\",\"ae8nc_acceptview\":\"\",\"ae8nc_cxno_unit\":\"信息中心\",\"ae8nc_filename_unit\":\"PA\",\"ae8gallery\":\"\",\"ae8nc_plant\":\"信息中心\",\"ae8nc_modelno\":\"jx\",\"ae8nc_batchno\":\"\",\"meop_id\":\"OPHJ000000000049108\",\"meop_rev_id\":\"A\",\"meop_name\":\"焊接\",\"meop_type\":\"AE8Operation Revision\",\"ae8gx_no\":\"5\",\"process_id\":\"JZG2022008107653\",\"process_rev_id\":\"1\",\"process_name\":\"107052\",\"ae8part_no\":\"107052\",\"ae8stageidentifying\":\"L\",\"ae8gy_type\":\"机加工艺设计\",\"ae8plant\":\"信息中心\",\"part_id\":\"1047051\",\"part_rev_id\":\"01\",\"part_name\":\"集成测试件\",\"create_by\":\"用户2(user2)\",\"create_date\":\"02-9月-22 17:15:14\",\"filename\":\"DNC-CX信息中心10000070-1.zip\",\"filepath\":\"http://localhost:9099/outer/test/download.xhtml\"}]}\n";
|
//String program =pdmWebClientApi.queryNcProgramAttrInfo(objects);
|
if (StringUtils.isEmpty(program)) {
|
log.error("======= 无 "+ ncLog.getSkgxId() +" 新增记录=======");
|
return false;
|
}
|
ncLog.setUpdateSave("1");
|
queryNcProgramLogService.saveOrUpdate(ncLog);
|
PdmProgramResult result = mapper.fromJson(program, new TypeReference<PdmProgramResult>() {
|
});
|
if (result == null ) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
return false;
|
}
|
if (result.getResponse() == null) {
|
log.error("======= 解析失败,请联系开发人员=======");
|
return false;
|
}
|
|
dncLog.setContentName(program);
|
List<PdmProgramSourceExt> pdmExt = result.getResponse();
|
|
if(pdmExt == null || pdmExt.isEmpty()) {
|
log.error("======= pdmExt =======");
|
return false;
|
}
|
BeanMapper.copy(pdmExt.get(0),source);
|
//处理字段位空的问题 不进行数据保存 直接返回
|
if(StringUtils.isEmpty(source.getFilePath() )) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"失败","无程序",null};
|
ncProgramReceived(receivedObject);
|
return false;
|
}
|
if (StringUtils.isEmpty(source.getAe8ncSbno())
|
|| StringUtils.isEmpty(source.getProcessRevId())
|
|| StringUtils.isEmpty(source.getAe8ncPlant())
|
|| StringUtils.isEmpty(source.getAe8partNo())
|
|| StringUtils.isEmpty(source.getAe8gxNo())) {
|
dncLog.setIsSuccess(LogCodeUtil.success_is_false);
|
dncLog.setRemarks("无NC程序文件,数据不生成");
|
dncLogService.save(dncLog);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"失败","数据缺失内容",null};
|
ncProgramReceived(receivedObject);
|
return true;
|
}
|
dncLog.setEquipmentId(source.getAe8ncSbno());
|
dncLog.setWorkshopNo(source.getAe8ncPlant());
|
//权限分配
|
boolean b = saveProductInfo(source);
|
if (!b) {
|
log.error("======= 权限分配,请联系开发人员=======");
|
return false;
|
}
|
super.save(source);
|
Object[] receivedObject = new Object[]{ncLog.getSkgxId(),ncLog.getSkgxRevId(),ncLog.getSqzt(),"成功","",null};
|
try {
|
String programReceived = ncProgramReceived(receivedObject);
|
dncLog.setIsSuccess(LogCodeUtil.success_is_true);
|
dncLog.setRemarks("数据生成成功");
|
dncLogService.save(dncLog);
|
log.info(programReceived);
|
}catch (Exception e) {
|
return false;
|
}
|
|
}catch (Exception e) {
|
e.printStackTrace();
|
return false;
|
}
|
return true;
|
}
|
|
public String ncProgramReceived( Object[] receivedObject){
|
try {
|
String programReceived = pdmWebClientApi.setNcProgramReceived(receivedObject);
|
return programReceived;
|
}catch (Exception e) {
|
return null;
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public boolean saveProductInfo(PdmProgramSource source) {
|
ProductInfo processInfo = productInfoService.getById(ncPdmProduct);
|
if (processInfo == null) {
|
log.error("======= 产品层级异常,请联系开发人员=======");
|
return false;
|
}
|
/**
|
* 1、部件总 按照部门(车间 ae8nc_plant )维度建立
|
* 2、子部件 型别
|
* 3、零件 图号(零件号) ae8part_no
|
* 4、工序 工艺ID(工艺规程编号/临规编号)
|
*/
|
//1、部件总
|
ComponentInfo compTotal = componentInfoService.getByCode(source.getAe8ncPlant());
|
if (compTotal == null) {
|
compTotal = new ComponentInfo();
|
compTotal.setComponentCode(source.getAe8ncPlant());
|
compTotal.setProductId(ncPdmProduct);
|
compTotal.setComponentName(source.getAe8ncPlant());
|
compTotal.setComponentStatus(1);
|
compTotal.setRankLevel(1);
|
compTotal.setComponentId(IdWorker.getIdStr());
|
boolean b = componentInfoService.save(compTotal);
|
if(!b) {
|
return false;
|
}
|
boolean c = savePermissionList(compTotal,processInfo.getProductId());
|
if (!c) {
|
return false;
|
}
|
}
|
ComponentInfo compTotalF = componentInfoService.getByCode(source.getAe8ncModelNo() +"_" + source.getAe8ncPlant());
|
if (compTotalF == null) {
|
compTotalF = new ComponentInfo();
|
compTotalF.setComponentCode(source.getAe8ncModelNo() +"_" + source.getAe8ncPlant());
|
compTotalF.setProductId(ncPdmProduct);
|
compTotalF.setComponentName(source.getAe8ncModelNo());
|
compTotalF.setComponentStatus(1);
|
compTotalF.setRankLevel(2);
|
compTotalF.setParentId(compTotal.getComponentId());
|
compTotalF.setComponentId(IdWorker.getIdStr());
|
boolean b = componentInfoService.save(compTotalF);
|
if(!b) {
|
return false;
|
}
|
boolean c = savePermissionList(compTotalF,processInfo.getProductId());
|
if (!c) {
|
return false;
|
}
|
}
|
|
//3、零件 图号(零件号) ae8part_no
|
PartsInfo part = partsInfoService.getByCode(source.getAe8partNo());
|
if(part == null) {
|
List<PartsDepartment> partsDepartPermList = new ArrayList<>();
|
List<PermissionStream> partsPermList = new ArrayList<>();
|
List<PartsPermission> partsUserPermList = new ArrayList<>();
|
PartsDepartment department;
|
PartsPermission permission;
|
PermissionStream stream;
|
part = new PartsInfo();
|
part.setPartsId(IdWorker.getIdStr());
|
part.setComponentId(compTotalF.getComponentId());
|
part.setProductId(compTotalF.getProductId());
|
part.setPartsStatus(1);
|
part.setPartsCode(source.getAe8partNo());
|
part.setPartsName(source.getAe8partNo());
|
part.setPartsModel(source.getAe8partNo());
|
/* part.setMaterielCode(source.getAe8partNo());
|
part.setMaterielDesp(source.getAe8partNo());*/
|
|
boolean b = partsInfoService.save(part);
|
if(!b) {
|
return false;
|
}
|
//权限
|
List<PermissionStream> oldPermissionList = permissionStreamService.getAllByProductId(ncPdmProduct);
|
if(oldPermissionList != null && !oldPermissionList.isEmpty()) {
|
for(PermissionStream p : oldPermissionList) {
|
if(ValidateUtil.validateString(p.getUserId())) {
|
//用户权限
|
permission = new PartsPermission();
|
permission.setPartsId(part.getPartsId());
|
permission.setUserId(p.getUserId());
|
partsUserPermList.add(permission);
|
|
stream = new PermissionStream();
|
stream.setUserId(p.getUserId());
|
stream.setProductId(part.getProductId());
|
stream.setComponentId(part.getComponentId());
|
stream.setPartsId(part.getPartsId());
|
partsPermList.add(stream);
|
}
|
if(ValidateUtil.validateString(p.getDepartId())) {
|
//部门权限
|
department = new PartsDepartment();
|
department.setPartsId(part.getPartsId());
|
department.setDepartId(p.getDepartId());
|
partsDepartPermList.add(department);
|
stream = new PermissionStream();
|
stream.setProductId(part.getProductId());
|
stream.setComponentId(part.getComponentId());
|
stream.setPartsId(part.getPartsId());
|
stream.setDepartId(p.getDepartId());
|
partsPermList.add(stream);
|
}
|
}
|
if(!partsUserPermList.isEmpty()) {
|
b = partsPermissionService.saveBatch(partsUserPermList);
|
if(!b) {
|
return false;
|
}
|
}
|
if(!partsDepartPermList.isEmpty()) {
|
b = partsDepartmentService.saveBatch(partsDepartPermList);
|
if(!b) {
|
return false;
|
}
|
}
|
if(!partsPermList.isEmpty()) {
|
b = permissionStreamService.saveBatch(partsPermList);
|
if(!b) {
|
return false;
|
}
|
}
|
}
|
|
}
|
//4、工序 工艺ID(工艺规程编号/临规编号)
|
List<ProcessStream> addProcessList = new ArrayList<>();
|
|
List<ProcessStream> updateProcessList = new ArrayList<>();
|
ProcessStream stream; //ae8gx_no
|
String processCode = source.getAe8gxNo();
|
if (!StringUtils.isEmpty(source.getAe8ncSbno())) {
|
processCode = processCode + "_" + source.getAe8ncSbno();
|
}
|
stream = processStreamService.findByProcessNoAndPartsId(processCode, part.getPartsId());
|
if(stream == null) {
|
stream = new ProcessStream();
|
stream.setProcessId(IdWorker.getIdStr());
|
stream.setProductId(part.getProductId());
|
stream.setComponentId(part.getComponentId());
|
stream.setPartsId(part.getPartsId());
|
stream.setProcessCode(processCode);
|
stream.setProcessName(source.getSkgxName());
|
/*数控工序号*/
|
stream.setCraftNo(source.getSkgxId());
|
stream.setCraftVersion(source.getProcessRevId());
|
|
stream.setDescription(source.getSqzt());
|
//stream.set
|
/*机床操作系统 ae8nc_os*/
|
EquipmentClass classE = equipmentClassService.findEquipmentIdsFromEqId(source.getAe8ncPlant(),source.getAe8ncSbno());
|
if (classE != null && StringUtils.isNotEmpty(classE.getEquipmentIds())) {
|
stream.setProcessingEquipmentCode(classE.getEquipmentIds());
|
} else {
|
stream.setProcessingEquipmentCode(source.getAe8ncSbno());
|
}
|
stream.setProcessingEquipmentOs(source.getAe8ncOs());
|
stream.setProcessingEquipmentModel(source.getAe8ncJcId());
|
addProcessList.add(stream);
|
}else {
|
stream.setProcessName(source.getSkgxName());
|
stream.setDescription(source.getSqzt());
|
updateProcessList.add(stream);
|
}
|
|
if(!addProcessList.isEmpty()) {
|
boolean b = processStreamService.saveBatch(addProcessList);
|
if(!b) {
|
return false;
|
}
|
}
|
if(!updateProcessList.isEmpty()){
|
boolean b = processStreamService.updateBatchById(updateProcessList);
|
if(!b) {
|
return false;
|
}
|
}
|
//下载数据并解压
|
if(stream == null) {
|
return false;
|
}
|
String itemCode = stream.getProcessCode();
|
DocClassification docClass = docClassificationService.getByCode("NC");
|
if(docClass == null) {
|
return false;
|
}
|
try {
|
String fileName = readFileName(itemCode);
|
boolean b = HttpRequest.downLoadFromUrl(source.getFilePath(),fileName,filePath);
|
if(b){
|
String localPath = filePath;
|
File file = new File(localPath + File.separator + fileName);
|
if(file.exists() && file.isFile() && file.length() > 0) {
|
Map<String, ZipInputStream> map = ZipUtil.readZipFileStream(file);
|
if(map == null || map.isEmpty()) {
|
ExceptionCast.cast(CommonCode.FAIL);
|
}
|
for(Map.Entry<String, ZipInputStream> entry : map.entrySet()) {
|
String suffix = FileUtil.getFileSuffix(entry.getKey());
|
if (suffix.contentEquals("docx") || suffix.contentEquals("pdf") ) {
|
continue;
|
}
|
source.setFileName(entry.getKey());
|
DocInfo docInfo = docInfoService.findByAttrAndDocName(FileUtil.getFilenameNonSuffix(entry.getKey()), 5,
|
stream.getProcessId(),suffix);
|
//新增
|
FileUploadResult fileUploadResult = FileUtil.uploadFile(entry.getKey(),
|
entry.getValue());
|
if(fileUploadResult == null) {
|
ExceptionCast.cast(DocumentCode.DOC_UPLOAD_ERROR);
|
}
|
if(docInfo == null) {
|
//代码逻辑调整
|
//TODO
|
docInfo = new DocInfo();
|
String docId = IdWorker.getIdStr();
|
docInfo.setDocId(docId);
|
docInfo.setDocName(fileUploadResult.getFileName());
|
docInfo.setDocSuffix(fileUploadResult.getFileSuffix());
|
docInfo.setDocStatus(1);
|
DocRelative docRelative = new DocRelative();
|
docRelative.setAttributionId(stream.getProcessId());
|
docRelative.setDocId(docInfo.getDocId());
|
docRelative.setAttributionType(5);
|
docRelative.setClassificationId(docClass.getClassificationId());
|
b = docRelativeService.save(docRelative);
|
if(!b) {
|
return false;
|
}
|
DocFile docFile = new DocFile();
|
docFile.setDocId(docInfo.getDocId());
|
docFile.setFileName(fileUploadResult.getFileName());
|
docFile.setFileEncodeName(fileUploadResult.getEncodeFileName());
|
docFile.setFilePath(fileUploadResult.getFilePath());
|
docFile.setFileSize(fileUploadResult.getFileSize());
|
docFile.setFileSuffix(fileUploadResult.getFileSuffix());
|
b = docFileService.addDocFile(docFile);
|
if(!b) {
|
return false;
|
}
|
docInfo.setPublishVersion(docFile.getDocVersion());
|
docInfo.setPublishFileId(docFile.getFileId());
|
b = docInfoService.save(docInfo);
|
boolean pdm = assignFileStreamService.saveListNcFromPdm(docInfo,source);
|
if(!b){
|
return false;
|
}
|
}else {
|
//升版
|
DocFile docFile = new DocFile();
|
docFile.setDocId(docInfo.getDocId());
|
docFile.setFileName(fileUploadResult.getFileName());
|
docFile.setFileEncodeName(fileUploadResult.getEncodeFileName());
|
docFile.setFilePath(fileUploadResult.getFilePath());
|
docFile.setFileSize(fileUploadResult.getFileSize());
|
docFile.setFileSuffix(fileUploadResult.getFileSuffix());
|
b = docFileService.addDocFile(docFile);
|
if(!b){
|
return false;
|
}
|
docInfo.setPublishVersion(docFile.getDocVersion());
|
docInfo.setPublishFileId(docFile.getFileId());
|
b = docInfoService.updateById(docInfo);
|
//
|
boolean pdm = assignFileStreamService.saveListNcFromPdm(docInfo,source);
|
if(!b) {
|
return false;
|
}
|
}
|
}
|
return true;
|
}
|
}
|
} catch (Exception e) {
|
log.error(e.getMessage());
|
return false;
|
}
|
return false;
|
}
|
|
|
private boolean savePermissionList(ComponentInfo comp, String totalOrSonId) {
|
boolean b;
|
List<PermissionStream> oldPermissionList = permissionStreamService.getAllByProductId(totalOrSonId);
|
//权限
|
List<ComponentDepartment> componentDepartmentList = new ArrayList<>();
|
List<PermissionStream> componentDepartPermList = new ArrayList<>();
|
List<ComponentPermission> componentPermissionList = new ArrayList<>();
|
ComponentDepartment department;
|
ComponentPermission permission;
|
PermissionStream stream;
|
if(oldPermissionList != null && !oldPermissionList.isEmpty()) {
|
for (PermissionStream p : oldPermissionList) {
|
if (ValidateUtil.validateString(p.getUserId())) {
|
//部门权限
|
permission = new ComponentPermission();
|
permission.setComponentId(comp.getComponentId());
|
permission.setUserId(p.getUserId());
|
componentPermissionList.add(permission);
|
|
stream = new PermissionStream();
|
stream.setUserId(p.getUserId());
|
stream.setProductId(comp.getProductId());
|
stream.setComponentId(comp.getComponentId());
|
componentDepartPermList.add(stream);
|
}
|
if (ValidateUtil.validateString(p.getDepartId())) {
|
//用户权限
|
department = new ComponentDepartment(comp.getComponentId(), p.getDepartId());
|
componentDepartmentList.add(department);
|
stream = new PermissionStream(comp.getProductId(), comp.getComponentId());
|
stream.setDepartId(p.getDepartId());
|
componentDepartPermList.add(stream);
|
}
|
|
}
|
}
|
if(!componentDepartmentList.isEmpty()) {
|
b = componentDepartmentService.saveBatch(componentDepartmentList);
|
if(!b) {
|
return false;
|
}
|
}
|
if(!componentPermissionList.isEmpty()) {
|
b = componentPermissionService.saveBatch(componentPermissionList);
|
if(!b) {
|
return false;
|
}
|
}
|
if(!componentDepartPermList.isEmpty()) {
|
b = permissionStreamService.saveBatch(componentDepartPermList);
|
if(!b) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
@Override
|
public String readFileName(String itemCode){
|
return "pdm_" + itemCode + ".zip";
|
}
|
|
@Override
|
public QueryPageResponseResult<PdmProgramSource> findPageList(int page, int size, PdmProgramSourceRequest requestParams) {
|
if(page < 1 || size < 1) {
|
ExceptionCast.cast(CommonCode.INVALID_PAGE);
|
}
|
IPage<PdmProgramSource> pageData = new Page<>(page, size);
|
LambdaQueryChainWrapper<PdmProgramSource> lambdaQuery = super.lambdaQuery();
|
if(requestParams != null) {
|
if(ValidateUtil.validateString(requestParams.getAe8gxNo())) {
|
lambdaQuery.eq(PdmProgramSource::getAe8gxNo, requestParams.getAe8gxNo());
|
}
|
if(ValidateUtil.validateString(requestParams.getAe8ncSbno())) {
|
lambdaQuery.eq(PdmProgramSource::getAe8ncSbno, requestParams.getAe8ncSbno());
|
}
|
if(ValidateUtil.validateString(requestParams.getPartName())) {
|
lambdaQuery.like(PdmProgramSource::getPartName, requestParams.getPartName());
|
}
|
if(ValidateUtil.validateString(requestParams.getProcessId())) {
|
lambdaQuery.like(PdmProgramSource::getProcessId, requestParams.getProcessId());
|
}
|
if(ValidateUtil.validateString(requestParams.getProcessRevId())) {
|
lambdaQuery.like(PdmProgramSource::getProcessRevId, requestParams.getProcessRevId());
|
}
|
if(ValidateUtil.validateString(requestParams.getEndTime())) {
|
String date = DateUtil.format(DateUtil.plusTime(DateUtil.toDate(requestParams.getEndTime(),DateUtil.STR_DATE),1),DateUtil.STR_DATE);
|
lambdaQuery.lt(PdmProgramSource::getCreateTime,date);
|
}
|
if(ValidateUtil.validateString(requestParams.getStartTime())) {
|
lambdaQuery.ge(PdmProgramSource::getCreateTime,requestParams.getStartTime());
|
}
|
if(ValidateUtil.validateString(requestParams.getWorkshopNo())) {
|
lambdaQuery.like(PdmProgramSource::getAe8ncPlant, requestParams.getWorkshopNo());
|
}
|
if(ValidateUtil.validateString(requestParams.getCreateTime())) {
|
if (requestParams.getCreateTime().equals("asc")) {
|
lambdaQuery.orderByAsc(true,PdmProgramSource::getCreateTime);
|
} else if (requestParams.getCreateTime().equals("desc")) {
|
lambdaQuery.orderByDesc(true,PdmProgramSource::getCreateTime);
|
}
|
}
|
}
|
IPage<PdmProgramSource> userIPage = lambdaQuery.page(pageData);
|
return new QueryPageResponseResult<>(CommonCode.SUCCESS, userIPage);
|
}
|
}
|