Browse Source

更改为一个接口

master
liuchen864 8 months ago
parent
commit
5f5e1a55d3
  1. 150
      win-admin/src/main/java/com/win/web/controller/base/CommandController.java
  2. 150
      win-admin/src/main/java/com/win/web/controller/base/ShellController.java
  3. 86
      win-system/src/main/java/com/win/system/service/LinuxAccessService.java

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

@ -1,11 +1,16 @@
package com.win.web.controller.base;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.win.common.annotation.Log;
import com.win.common.constant.HttpStatus;
import com.win.common.core.domain.AjaxResult;
import com.win.common.enums.BusinessType;
import com.win.common.utils.ProfileUtil;
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;
@ -19,8 +24,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
@Slf4j
@ -32,6 +35,8 @@ public class CommandController {
@Autowired
private LinuxAccessService linuxAccessService;
@Autowired
private QadAccessService qadAccessService;
/**
* 对外提供一个接口通过header中的interfaceName反射机制调用方法方法必须写到这个controller中并且不用加PostMapping注解
@ -42,7 +47,7 @@ public class CommandController {
*/
@PostMapping("/api")
@Log(title = "命令行对接qad", businessType = BusinessType.INSERT, isManager = false)
public AjaxResult api(HttpServletRequest request, @RequestBody String body) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
public AjaxResult api(HttpServletRequest request, @RequestBody String body) throws IOException {
String interfaceName = request.getHeader("interface");
String sign = request.getHeader("sign");
String timeStr = request.getHeader("timestamp");
@ -68,108 +73,43 @@ public class CommandController {
if(/*!activeProfile.contains("dev") && */!StringUtils.equals(sign, computeSign.toUpperCase())) {
return AjaxResult.error(HttpStatus.SIGN_ERROR, "签名不正确");
}
Method method = this.getClass().getMethod(interfaceName, String.class);
return (AjaxResult) method.invoke(this, body);
}
public AjaxResult poreceipt(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "purchaseorder/poreceipt/", "dsPoreceiver");
}
public AjaxResult projectdetail(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "project/projectdetail/", "dsSearchCondition");
}
public AjaxResult itemmaster(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "items/itemmaster/", "dsItemmaster");
}
public AjaxResult inventorydetail(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "inventory/inventorydetail/", "dsSearchCondition");
}
public AjaxResult podetexport(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "puchaseorder/podetexport/", "dsSearchCondition");
}
public AjaxResult exportsupplier(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "supplier/exportsupplier/", "dsSearchCondition");
}
public AjaxResult discretepo(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "purchaseorder/discretepo/", "dsDescreteOrder");
}
public AjaxResult custrequiredschedule(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "customer/custrequiredschedule/", "dsSearchCondition");
}
public AjaxResult qadgrirexport(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "qadgrir/qadgrirexport/", "dsSearchCondition");
}
public AjaxResult Unplannedissue(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "transactions/Unplannedissue/", "dsUnplanISRC");
}
public AjaxResult supplierschedule(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "supplier/supplierschedule/", "dsSearchCondition");
}
public AjaxResult bommastr(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "bom/bommastr/", "dsBommaster");
}
public AjaxResult backflush(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "workorder/backflush/", "dsBackflushMaster");
}
public AjaxResult supplierasn(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "supplier/supplierasn/", "dsttsupplierasn");
}
public AjaxResult supplierinvoicebalance(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "supplier/supplierinvoicebalance/", "dsSearchCondition");
}
public AjaxResult createsupplierinvoice(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "supplierinvoice/createsupplierinvoice/", "dsSupplierInvoice");
}
public AjaxResult loadbommstr(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "bommstr/loadbommstr/", "dsBommaster");
}
public AjaxResult costcenterdetail(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "costcenter/costcenterdetail/", "dsSearchCondition");
}
public AjaxResult salesorderexport(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "salesorder/salesorderexport/", "dsSearchCondition");
}
public AjaxResult costdetail(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "cost/costdetail/", "dsSearchCondition");
}
public AjaxResult exportcustomer(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "customer/exportcustomer/", "dsSearchCondition");
}
public AjaxResult routingdetail(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "routing/routingdetail/", "dsRouting");
}
public AjaxResult productionschedule(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "production/productionschedule/", "dsSearchCondition");
}
public AjaxResult intransfer(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "transactions/intransfer/", "dsinvtransfer");
}
public AjaxResult loadbommastr(String body) throws IOException, InterruptedException {
return linuxAccessService.executeCommand(body, "bom/loadbommastr/", "dsBommaster");
JSONObject jsonObject = JSONObject.parseObject(body);
String key = "";
for(String keyTemp : jsonObject.keySet()) {
jsonObject = JSONObject.parseObject(jsonObject.getString(keyTemp));
key = keyTemp;
}
String domain = jsonObject.getString("domain");
if(domain == null || domain.isEmpty()) {
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空");
}
String companyCode = jsonObject.getString("company_code");
if(companyCode == null || companyCode.isEmpty()) {
return AjaxResult.error(HttpStatus.COMPANY_CODE_ERROR, "公司编码不能为空");
}
QueryWrapper<LinuxAccess> linuxAccessQueryWrapper = new QueryWrapper<>();
linuxAccessQueryWrapper.eq("company_code", companyCode);
linuxAccessQueryWrapper.eq("uri", interfaceName);
LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper);
if(linuxAccess == null) {
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在");
}
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>();
qadAccessQueryWrapper.eq("company_code", companyCode);
qadAccessQueryWrapper.eq("domain", domain);
QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper);
if(qadAccess == null) {
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR");
}
//生成traceid
String traceid = jsonObject.getString("traceid");
jsonObject.remove("traceid");
jsonObject.remove("dataid");
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
return linuxAccessService.executeCommand(linuxAccess, qadAccess, traceid, inJson, domain);
}
}

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

@ -1,12 +1,17 @@
package com.win.web.controller.base;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jcraft.jsch.JSchException;
import com.win.common.annotation.Log;
import com.win.common.constant.HttpStatus;
import com.win.common.core.domain.AjaxResult;
import com.win.common.enums.BusinessType;
import com.win.common.utils.ProfileUtil;
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;
@ -20,8 +25,6 @@ import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
@Slf4j
@ -33,6 +36,8 @@ public class ShellController {
@Autowired
private LinuxAccessService linuxAccessService;
@Autowired
private QadAccessService qadAccessService;
/**
* 对外提供一个接口通过header中的interfaceName反射机制调用方法方法必须写到这个controller中并且不用加PostMapping注解
@ -43,7 +48,7 @@ public class ShellController {
*/
@PostMapping("/api")
@Log(title = "远程行对接qad", businessType = BusinessType.INSERT, isManager = false)
public AjaxResult api(HttpServletRequest request, @RequestBody String body) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
public AjaxResult api(HttpServletRequest request, @RequestBody String body) throws IOException, JSchException {
String interfaceName = request.getHeader("interface");
String sign = request.getHeader("sign");
String timeStr = request.getHeader("timestamp");
@ -69,108 +74,43 @@ public class ShellController {
if(/*!activeProfile.contains("dev") && */!StringUtils.equals(sign, computeSign)) {
return AjaxResult.error(HttpStatus.SIGN_ERROR, "签名不正确");
}
Method method = this.getClass().getMethod(interfaceName, String.class);
return (AjaxResult) method.invoke(this, body);
}
public AjaxResult poreceipt(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "purchaseorder/poreceipt/", "dsPoreceiver");
}
public AjaxResult projectdetail(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "project/projectdetail/", "dsSearchCondition");
}
public AjaxResult itemmaster(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "items/itemmaster/", "dsItemmaster");
}
public AjaxResult inventorydetail(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "inventory/inventorydetail/", "dsSearchCondition");
}
public AjaxResult podetexport(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "puchaseorder/podetexport/", "dsSearchCondition");
}
public AjaxResult exportsupplier(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "supplier/exportsupplier/", "dsSearchCondition");
}
public AjaxResult discretepo(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "purchaseorder/discretepo/", "dsDescreteOrder");
}
public AjaxResult custrequiredschedule(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "customer/custrequiredschedule/", "dsSearchCondition");
}
public AjaxResult qadgrirexport(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "qadgrir/qadgrirexport/", "dsSearchCondition");
}
public AjaxResult Unplannedissue(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "transactions/Unplannedissue/", "dsUnplanISRC");
}
public AjaxResult supplierschedule(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "supplier/supplierschedule/", "dsSearchCondition");
}
public AjaxResult bommastr(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "bom/bommastr/", "dsBommaster");
}
public AjaxResult backflush(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "workorder/backflush/", "dsBackflushMaster");
}
public AjaxResult supplierasn(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "supplier/supplierasn/", "dsttsupplierasn");
}
public AjaxResult supplierinvoicebalance(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "supplier/supplierinvoicebalance/", "dsSearchCondition");
}
public AjaxResult createsupplierinvoice(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "supplierinvoice/createsupplierinvoice/", "dsSupplierInvoice");
}
public AjaxResult loadbommstr(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "bommstr/loadbommstr/", "dsBommaster");
}
public AjaxResult costcenterdetail(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "costcenter/costcenterdetail/", "dsSearchCondition");
}
public AjaxResult salesorderexport(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "salesorder/salesorderexport/", "dsSearchCondition");
}
public AjaxResult costdetail(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "cost/costdetail/", "dsSearchCondition");
}
public AjaxResult exportcustomer(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "customer/exportcustomer/", "dsSearchCondition");
}
public AjaxResult routingdetail(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "routing/routingdetail/", "dsRouting");
}
public AjaxResult productionschedule(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "production/productionschedule/", "dsSearchCondition");
}
public AjaxResult intransfer(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "transactions/intransfer/", "dsinvtransfer");
}
public AjaxResult loadbommastr(String body) throws JSchException, IOException {
return linuxAccessService.executeShell(body, "bom/loadbommastr/", "dsBommaster");
JSONObject jsonObject = JSONObject.parseObject(body);
String key = "";
for(String keyTemp : jsonObject.keySet()) {
jsonObject = JSONObject.parseObject(jsonObject.getString(keyTemp));
key = keyTemp;
}
String domain = jsonObject.getString("domain");
if(domain == null || domain.isEmpty()) {
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空");
}
String companyCode = jsonObject.getString("company_code");
if(companyCode == null || companyCode.isEmpty()) {
return AjaxResult.error(HttpStatus.COMPANY_CODE_ERROR, "公司编码不能为空");
}
QueryWrapper<LinuxAccess> linuxAccessQueryWrapper = new QueryWrapper<>();
linuxAccessQueryWrapper.eq("company_code", companyCode);
linuxAccessQueryWrapper.eq("uri", interfaceName);
LinuxAccess linuxAccess = linuxAccessService.getOne(linuxAccessQueryWrapper);
if(linuxAccess == null) {
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在");
}
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>();
qadAccessQueryWrapper.eq("company_code", companyCode);
qadAccessQueryWrapper.eq("domain", domain);
QadAccess qadAccess = qadAccessService.getOne(qadAccessQueryWrapper);
if(qadAccess == null) {
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR");
}
//生成traceid
String traceid = jsonObject.getString("traceid");
jsonObject.remove("traceid");
jsonObject.remove("dataid");
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
return linuxAccessService.executeShell(linuxAccess, qadAccess, traceid, inJson, domain);
}
}

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

@ -1,7 +1,5 @@
package com.win.system.service;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jcraft.jsch.JSchException;
@ -59,47 +57,17 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce
/**
* 执行shell脚本
*
* @param body 参数
* @param uri uri
* @param key
* @param linuxAccess linuxAccess
* @param qadAccess qadAccess
* @param traceid traceid
* @param inJson inJson
* @param domain domain
* @return 执行结果
* @throws JSchException shell异常
* @throws IOException io异常
*/
public AjaxResult executeShell(String body, String uri, String key) throws JSchException, IOException {
JSONObject jsonObject = JSONObject.parseObject(body);
jsonObject = JSONObject.parseObject(jsonObject.getString(key));
String domain = jsonObject.getString("domain");
if(domain == null || domain.isEmpty()) {
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空");
}
String companyCode = jsonObject.getString("company_code");
if(companyCode == null || companyCode.isEmpty()) {
return AjaxResult.error(HttpStatus.COMPANY_CODE_ERROR, "公司编码不能为空");
}
QueryWrapper<LinuxAccess> linuxAccessQueryWrapper = new QueryWrapper<>();
linuxAccessQueryWrapper.eq("company_code", companyCode);
linuxAccessQueryWrapper.eq("uri", uri);
LinuxAccess linuxAccess = baseMapper.selectOne(linuxAccessQueryWrapper);
if(linuxAccess == null) {
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在");
}
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>();
qadAccessQueryWrapper.eq("company_code", companyCode);
qadAccessQueryWrapper.eq("domain", domain);
QadAccess qadAccess = qadAccessMapper.selectOne(qadAccessQueryWrapper);
if(qadAccess == null) {
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR");
}
public AjaxResult executeShell(LinuxAccess linuxAccess, QadAccess qadAccess, String traceid, String inJson, String domain) throws JSchException, IOException {
Session session = shellUtil.getShellSession(linuxAccess.getUserName(), linuxAccess.getPassword(), linuxAccess.getIpAddress(), linuxAccess.getPort());
//生成traceid
String traceid = jsonObject.getString("traceid");
jsonObject.remove("traceid");
jsonObject.remove("dataid");
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
//写入json
String result = shellUtil.execute(session, "touch " + linuxAccess.getWorkPath() + traceid + ".json && echo '" + inJson + "'>" + linuxAccess.getWorkPath() + traceid + ".json");
log.info("write json result : {}", result);
@ -135,46 +103,16 @@ public class LinuxAccessService extends ServiceImpl<LinuxAccessMapper, LinuxAcce
/**
* 执行命令行
*
* @param body 参数
* @param uri uri
* @param key
* @param linuxAccess linuxAccess
* @param qadAccess qadAccess
* @param traceid traceid
* @param inJson inJson
* @param domain domain
* @return 执行结果
* @throws InterruptedException 命令行异常
* @throws IOException io异常
*/
public AjaxResult executeCommand(String body, String uri, String key) throws IOException, InterruptedException {
JSONObject jsonObject = JSONObject.parseObject(body);
jsonObject = JSONObject.parseObject(jsonObject.getString(key));
String domain = jsonObject.getString("domain");
if(domain == null || domain.isEmpty()) {
return AjaxResult.error(HttpStatus.DOMAIN_ERROR, "域不能为空");
}
String companyCode = jsonObject.getString("company_code");
if(companyCode == null || companyCode.isEmpty()) {
return AjaxResult.error(HttpStatus.COMPANY_CODE_ERROR, "公司编码不能为空");
}
QueryWrapper<LinuxAccess> linuxAccessQueryWrapper = new QueryWrapper<>();
linuxAccessQueryWrapper.eq("company_code", companyCode);
linuxAccessQueryWrapper.eq("uri", uri);
LinuxAccess linuxAccess = baseMapper.selectOne(linuxAccessQueryWrapper);
if(linuxAccess == null) {
return AjaxResult.error(HttpStatus.LINUX_ACCESS_ERROR, "linux访问控制不存在");
}
QueryWrapper<QadAccess> qadAccessQueryWrapper = new QueryWrapper<>();
qadAccessQueryWrapper.eq("company_code", companyCode);
qadAccessQueryWrapper.eq("domain", domain);
QadAccess qadAccess = qadAccessMapper.selectOne(qadAccessQueryWrapper);
if(qadAccess == null) {
return AjaxResult.error(HttpStatus.QAD_ACCESS_ERROR, "QAD_ACCESS_ERROR");
}
//生成traceid
String traceid = jsonObject.getString("traceid");
jsonObject.remove("traceid");
jsonObject.remove("dataid");
jsonObject.remove("company_code");
jsonObject.remove("domain");
String inJson = "{\"" + key + "\":"+ jsonObject+"}";
log.info("inJson: {}", inJson);
public AjaxResult executeCommand(LinuxAccess linuxAccess, QadAccess qadAccess, String traceid, String inJson, String domain) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(linuxAccess.getWorkPath() + traceid + ".json");
fileOutputStream.write(inJson.getBytes());
fileOutputStream.close();

Loading…
Cancel
Save