|
@@ -45,7 +45,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.io.File;
|
|
|
+import java.io.*;
|
|
|
+import java.net.URL;
|
|
|
+import java.net.URLConnection;
|
|
|
+import java.nio.channels.Channels;
|
|
|
+import java.nio.channels.ReadableByteChannel;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
@@ -126,7 +130,7 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
// String returnData = restTemplate.postForObject(UrlConfConstant.plcURL, formEntity, String.class);
|
|
|
String localFolder = uploadFolder + "0000/cncFile/" + productionresource.getId();
|
|
|
String fileName = data.getFilePath().substring(data.getFilePath().lastIndexOf("/") + 1);
|
|
|
- String localFilePathName = localFolder + "/" + fileName;
|
|
|
+ String localFilePathName = uploadFolder + "/" + data.getFilePath().substring(data.getFilePath().indexOf("0000"));
|
|
|
// TODO 西门子程序scp上传
|
|
|
String ip = productionresource.getIp();
|
|
|
String port = "22";
|
|
@@ -206,6 +210,43 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
return getFileContent(fileName,model);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查看程序
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map getProgramContent(Program data){
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ Program program = baseMapper.selectById(data.getId());
|
|
|
+ BufferedReader br = null;
|
|
|
+ try {
|
|
|
+ URL url = new URL(program.getFilePath());
|
|
|
+ URLConnection con = url.openConnection();
|
|
|
+
|
|
|
+ br = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
|
+ String inputLine = null;
|
|
|
+ while((inputLine = br.readLine()) != null){
|
|
|
+ if (inputLine != null && inputLine.trim().length() > 0) {
|
|
|
+ sb.append(inputLine);
|
|
|
+ sb.append("\n\r");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("content",sb.toString());
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(null != br){
|
|
|
+ try{
|
|
|
+ br.close();
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//文件内容
|
|
|
public Map getFileContent(String fileName,Program model){
|
|
|
Map map = new HashMap<>();
|
|
@@ -305,7 +346,7 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
// 入库设备程序表
|
|
|
Program program = new Program();
|
|
|
program.setResourceId(productionresource.getId());
|
|
|
- program.setName(productionresource.getName());
|
|
|
+ program.setName(fileName);
|
|
|
program.setNo(productionresource.getCode());
|
|
|
String programFilePath = "http://" + nginxIp + ":" + nginxPort + "/file/0000/cncFile/"+ productionresource.getId() + "/" + fileName;
|
|
|
program.setFilePath(programFilePath);
|
|
@@ -322,6 +363,7 @@ public class ProgramServiceImpl extends SuperServiceImpl<ProgramMapper, Program>
|
|
|
|
|
|
if(productionresource!=null){
|
|
|
productionresource.setProgramNum(programList.size());
|
|
|
+ productionresource.setProgramSynTime(LocalDateTime.now());
|
|
|
productionresourceMapper.updateById(productionresource);
|
|
|
}
|
|
|
}
|