Browse Source

完成excel模板导出

master
liuchen864 6 months ago
parent
commit
b58a19387a
  1. 2
      pom.xml
  2. 3
      win-admin/src/main/java/com/win/web/controller/base/CommandController.java
  3. 497
      win-admin/src/main/java/com/win/web/controller/base/ExcelController.java
  4. 3
      win-admin/src/main/java/com/win/web/controller/base/ShellController.java
  5. BIN
      win-admin/src/main/resources/changchun.xls
  6. BIN
      win-admin/src/main/resources/foshan_qingdao.xls
  7. BIN
      win-admin/src/main/resources/guowai1.xls
  8. BIN
      win-admin/src/main/resources/guowai2.xlsx
  9. 4
      win-admin/src/main/resources/logback-spring.xml
  10. 28
      win-system/src/main/java/com/win/system/service/LinuxAccessService.java
  11. 1
      win-system/src/main/java/com/win/system/service/QadAccessService.java

2
pom.xml

@ -23,7 +23,7 @@
<bitwalker.version>1.21</bitwalker.version>
<kaptcha.version>2.3.3</kaptcha.version>
<pagehelper.boot.version>1.4.6</pagehelper.boot.version>
<fastjson.version>2.0.34</fastjson.version>
<fastjson.version>2.0.50</fastjson.version>
<oshi.version>6.4.3</oshi.version>
<commons.io.version>2.11.0</commons.io.version>
<commons.fileupload.version>1.4</commons.fileupload.version>

3
win-admin/src/main/java/com/win/web/controller/base/CommandController.java

@ -11,7 +11,6 @@ import com.win.system.domain.LinuxAccess;
import com.win.system.domain.QadAccess;
import com.win.system.service.LinuxAccessService;
import com.win.system.service.QadAccessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -26,7 +25,6 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/command")
public class CommandController {
@ -108,7 +106,6 @@ public class CommandController {
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
return linuxAccessService.executeCommand(linuxAccess, qadAccess, traceid, inJson, domain);
}

497
win-admin/src/main/java/com/win/web/controller/base/ExcelController.java

File diff suppressed because one or more lines are too long

3
win-admin/src/main/java/com/win/web/controller/base/ShellController.java

@ -12,7 +12,6 @@ import com.win.system.domain.LinuxAccess;
import com.win.system.domain.QadAccess;
import com.win.system.service.LinuxAccessService;
import com.win.system.service.QadAccessService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,7 +26,6 @@ import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/shell")
public class ShellController {
@ -109,7 +107,6 @@ public class ShellController {
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
return linuxAccessService.executeShell(linuxAccess, qadAccess, traceid, inJson, domain);
}

BIN
win-admin/src/main/resources/changchun.xls

Binary file not shown.

BIN
win-admin/src/main/resources/foshan_qingdao.xls

Binary file not shown.

BIN
win-admin/src/main/resources/guowai1.xls

Binary file not shown.

BIN
win-admin/src/main/resources/guowai2.xlsx

Binary file not shown.

4
win-admin/src/main/resources/logback-spring.xml

@ -131,8 +131,6 @@
<!-- test环境 -->
<springProfile name="test">
<root level="ERROR">
<appender-ref ref="console"/>
<appender-ref ref="file_info"/>
<appender-ref ref="file_warn"/>
<appender-ref ref="file_error"/>
</root>
@ -140,7 +138,6 @@
<!-- prod环境 -->
<springProfile name="prod">
<root level="ERROR">
<appender-ref ref="file_info"/>
<appender-ref ref="file_warn"/>
<appender-ref ref="file_error"/>
</root>
@ -151,7 +148,6 @@
<logger name="com.baomidou" level="INFO" />
<logger name="org.mybatis" level="INFO" />
<logger name="org.hibernate" level="INFO" />
<logger name="com.win.module.eam.controller" level="INFO" />
<logger name="io.netty" level="WARN" />
<logger name="org.redisson" level="WARN" />
<logger name="org.mapstruct" level="WARN" />

28
win-system/src/main/java/com/win/system/service/LinuxAccessService.java

@ -12,7 +12,6 @@ import com.win.system.domain.LinuxAccess;
import com.win.system.domain.QadAccess;
import com.win.system.mapper.LinuxAccessMapper;
import com.win.system.mapper.QadAccessMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -27,7 +26,6 @@ import java.time.LocalDateTime;
* @author win
* @date 2024-03-12
*/
@Slf4j
@Service
public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAccess> implements IService<LinuxAccess> {
@ -70,27 +68,27 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce
Session session = shellUtil.getShellSession(linuxAccess.getUserName(), linuxAccess.getPassword(), linuxAccess.getIpAddress(), linuxAccess.getPort());
//写入json
String result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json");
log.info("write json result : {}", result);
//log.info("write json result : {}", result);
//写入dat.json
String datJson = "\"" + linuxAccess.getWorkPath() + traceid + ".json\" \"" + linuxAccess.getQadProgramCode() + "\" \"" + linuxAccess.getOutPath() + traceid+".out.log\" \"" + qadAccess.getUserName() + "\" \"" + qadAccess.getPassword() + "\"\r\n\"" + domain + "\"";
log.info("datJson: {}", datJson);
//log.info("datJson: {}", datJson);
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".dat && echo '" + datJson + "'>" + linuxAccess.getWorkPath() + traceid+".dat");
log.info("write dat json result : {}", result);
//log.info("write dat json result : {}", result);
//写入执行文件
String pJson = "output to " + linuxAccess.getOutPath() + traceid + ".run.log.\r\n" +
"input from " + linuxAccess.getWorkPath() + traceid + ".dat.\r\n" +
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" +
"input close.\r\n" +
"output close.";
log.info("pJson: {}", pJson);
//log.info("pJson: {}", pJson);
result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid+".p && echo '"+pJson+"'>" + linuxAccess.getWorkPath() + traceid + ".p");
log.info("write p result : {}", result);
//log.info("write p result : {}", result);
//执行QAD脚本
log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
//log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
result = shellUtil.execute(session, linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
//log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
result = shellUtil.execute(session, "cat " + linuxAccess.getOutPath() + traceid + ".run.out.json");
log.info("cat execute log : {}", result);
//log.info("cat execute log : {}", result);
if(result.indexOf("\"SUCCESS\"") > 0) {
//移动执行结果文件
shellUtil.execute(session, "mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json");
@ -126,17 +124,17 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce
"run " + linuxAccess.getScriptPath() + linuxAccess.getScriptProgram() + ".\r\n" +
"input close.\r\n" +
"output close.";
log.info("pJson: {}", pJson);
//log.info("pJson: {}", pJson);
fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".p");
fileOutputStream.write(pJson.getBytes());
fileOutputStream.close();
log.info("pJson: {}", pJson);
//log.info("pJson: {}", pJson);
//执行QAD脚本
log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
//log.info("command : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
String result = CommandUtil.exeCommand(linuxAccess.getScriptPath() + linuxAccess.getScriptName() + " " + linuxAccess.getWorkPath() + traceid + ".p");
log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
//log.info("execute {} result : {}", linuxAccess.getScriptPath() + linuxAccess.getScriptName(), result);
result = CommandUtil.exeCommand("cat " + linuxAccess.getOutPath() + traceid + ".run.out.json");
log.info("cat execute log : {}", result);
//log.info("cat execute log : {}", result);
if(result.indexOf("\"SUCCESS\"") > 0) {
//移动执行结果文件
CommandUtil.exeCommand("mv " + linuxAccess.getOutPath() + traceid + ".run.out.json " + linuxAccess.getSuccessPath() + traceid + ".run.out.json");

1
win-system/src/main/java/com/win/system/service/QadAccessService.java

@ -16,7 +16,6 @@ import java.time.LocalDateTime;
* @author win
* @date 2024-03-13
*/
@Slf4j
@Service
public class QadAccessService extends ServiceImpl<QadAccessMapper, QadAccess> implements IService<QadAccess> {

Loading…
Cancel
Save