|
@@ -1,5 +1,6 @@
|
|
|
package com.github.zuihou.business.productionResourceCenter.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -8,6 +9,7 @@ import com.github.zuihou.base.service.SuperServiceImpl;
|
|
|
import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
import com.github.zuihou.business.productionReadyCenter.entity.BBomProcedureTool;
|
|
|
import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureProductionresource;
|
|
|
import com.github.zuihou.business.productionReadyCenter.service.BomProcedureToolService;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ProgramMapper;
|
|
@@ -20,6 +22,7 @@ import com.github.zuihou.business.productionResourceCenter.entity.Tool;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.ProgramService;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.ProgramSuitProductionresourceService;
|
|
|
import com.github.zuihou.common.constant.UrlConfConstant;
|
|
|
+import com.github.zuihou.common.util.Scpclient;
|
|
|
import com.github.zuihou.context.BaseContextHandler;
|
|
|
import com.github.zuihou.database.mybatis.auth.DataScope;
|
|
|
import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
@@ -27,11 +30,14 @@ import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import com.github.zuihou.file.entity.Attachment;
|
|
|
import com.github.zuihou.file.properties.FileServerProperties;
|
|
|
import com.github.zuihou.file.service.AttachmentService;
|
|
|
+import com.github.zuihou.tenant.entity.Module;
|
|
|
import com.github.zuihou.tenant.service.CodeRuleService;
|
|
|
+import com.github.zuihou.tenant.service.ModuleService;
|
|
|
import com.github.zuihou.utils.BeanPlusUtil;
|
|
|
import com.xxl.job.core.util.FileUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
@@ -39,13 +45,13 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.github.zuihou.utils.DateUtils.DEFAULT_MONTH_FORMAT_SLASH;
|
|
|
|
|
@@ -61,6 +67,12 @@ import static com.github.zuihou.utils.DateUtils.DEFAULT_MONTH_FORMAT_SLASH;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program> implements ProgramService {
|
|
|
+ @Value("${zuihou.file.storage-path}")
|
|
|
+ private String uploadFolder;
|
|
|
+ @Value("${zuihou.nginx.ip}")
|
|
|
+ private String nginxIp;
|
|
|
+ @Value("${zuihou.nginx.port}")
|
|
|
+ private String nginxPort;
|
|
|
@Autowired
|
|
|
ProgramSuitProductionresourceService programSuitProductionresourceService;
|
|
|
@Autowired
|
|
@@ -78,6 +90,8 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
|
|
|
@Autowired
|
|
|
private BomProcedureToolService bomProcedureToolService;
|
|
|
+ @Autowired
|
|
|
+ private ModuleService moduleService;
|
|
|
|
|
|
@Override
|
|
|
public IPage<Program> pageList(IPage page, LbqWrapper<Program> wrapper) {
|
|
@@ -108,8 +122,7 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
headers.setContentType(MediaType.parseMediaType("application/json;charset=UTF-8"));
|
|
|
HttpEntity<String> formEntity = new HttpEntity<String>(jsonParam, headers);
|
|
|
//调用接口
|
|
|
- String returnData = restTemplate.postForObject(UrlConfConstant.plcURL, formEntity, String.class);
|
|
|
-
|
|
|
+// String returnData = restTemplate.postForObject(UrlConfConstant.plcURL, formEntity, String.class);
|
|
|
|
|
|
Program program = BeanPlusUtil.toBean(data, Program.class);
|
|
|
//根据编码规则
|
|
@@ -152,7 +165,17 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Boolean delete(Program model) {
|
|
|
|
|
|
- return removeById(model.getId());
|
|
|
+ Productionresource productionresource = productionresourceMapper.selectById(model.getResourceId());
|
|
|
+
|
|
|
+ removeById(model.getId());
|
|
|
+ //设置程序数量
|
|
|
+ List<Program>programList = baseMapper.selectList(Wraps.<Program>lbQ().eq(Program::getResourceId,model.getResourceId()));
|
|
|
+
|
|
|
+ if(productionresource!=null){
|
|
|
+ productionresource.setProgramNum(programList.size());
|
|
|
+ productionresourceMapper.updateById(productionresource);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -237,13 +260,65 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
@Override
|
|
|
public Boolean synchronousNumericalProgram(Program data){
|
|
|
if (data.getResourceList() != null && data.getResourceList().size() > 0){
|
|
|
- // 先查找设备ip,端口
|
|
|
- //
|
|
|
+ List<Productionresource> productionresources = productionresourceMapper.selectList(Wraps.<Productionresource>lbQ().in(Productionresource::getId,data.getResourceList()));
|
|
|
+ List<Long> moduldIds = productionresources.stream().map(p -> p.getModuleId()).collect(Collectors.toList());
|
|
|
+ List<Module> modules = moduleService.list(Wraps.<Module>lbQ().in(Module::getId,moduldIds));
|
|
|
+ Map<Long, List<Module>> moduleMap = new HashMap<Long, List<Module>>();
|
|
|
+ if(CollectionUtil.isNotEmpty(modules)){
|
|
|
+ moduleMap = modules.stream().collect(Collectors.groupingBy(Module::getId));
|
|
|
+ }
|
|
|
+ for(Productionresource productionresource : productionresources){
|
|
|
+ // 根据不同系统查找数控程序
|
|
|
+ // TODO 真实机床调试 Scpclient
|
|
|
+ List<String> fileNames = new ArrayList<>();
|
|
|
+ String ip = productionresource.getIp();
|
|
|
+ String port = productionresource.getPort();
|
|
|
+ String userName = "";
|
|
|
+ String password = "";
|
|
|
+ Scpclient scpclient = new Scpclient(ip,Integer.valueOf(port),userName,password);
|
|
|
+ List<Module> resourceModules = moduleMap.get(productionresource.getModuleId());
|
|
|
+ if(CollectionUtil.isNotEmpty(resourceModules)){
|
|
|
+ Module resourceModule = resourceModules.get(0);
|
|
|
+ String cncSystem = resourceModule.getCncSystem().getKey();
|
|
|
+ String cncFilePath = resourceModule.getCncFilePath();
|
|
|
+ // 模拟现在直接nginx下查找文件同步
|
|
|
+ fileNames = scpclient.getSubfolderName(cncFilePath);
|
|
|
+ }
|
|
|
+ if(CollectionUtil.isNotEmpty(fileNames)){
|
|
|
+ uploadFolder = uploadFolder + "0000/cncFile/";
|
|
|
+ for(String fileName : fileNames){
|
|
|
+ scpclient.getFile(fileName,uploadFolder);
|
|
|
+ // 入库设备程序表
|
|
|
+ Program program = new Program();
|
|
|
+ program.setResourceId(productionresource.getId());
|
|
|
+ program.setName(productionresource.getName());
|
|
|
+ program.setNo(productionresource.getCode());
|
|
|
+ String cncFilePath = "http://" + nginxIp + ":" + nginxPort + "/file/0000/cncFile/" + fileName;
|
|
|
+ program.setFilePath(cncFilePath);
|
|
|
+ program.setSource("2");
|
|
|
+ program.setSynTime(LocalDateTime.now());
|
|
|
+ //根据编码规则
|
|
|
+ save(program);
|
|
|
+ }
|
|
|
+
|
|
|
+ //设置程序数量
|
|
|
+ List<Program>programList = baseMapper.selectList(Wraps.<Program>lbQ().eq(Program::getResourceId,productionresource.getId()));
|
|
|
+
|
|
|
+ if(productionresource!=null){
|
|
|
+ productionresource.setProgramNum(programList.size());
|
|
|
+ productionresourceMapper.updateById(productionresource);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Boolean equipmentDelete(Program data){
|
|
|
if(1==1){//调用删除接口
|
|
|
baseMapper.deleteById(data.getId());
|
|
@@ -252,6 +327,7 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public Map implementProgram(Program data){
|
|
|
|
|
|
return null;
|