优化测试
This commit is contained in:
parent
5f74d354ba
commit
b2fe07fd4b
|
|
@ -5,20 +5,14 @@ import com.nflg.wms.admin.pojo.dto.LdapUserDTO;
|
||||||
import com.nflg.wms.admin.service.BasdeSerialNumberControllerService;
|
import com.nflg.wms.admin.service.BasdeSerialNumberControllerService;
|
||||||
import com.nflg.wms.admin.service.SapService;
|
import com.nflg.wms.admin.service.SapService;
|
||||||
import com.nflg.wms.common.pojo.ApiResult;
|
import com.nflg.wms.common.pojo.ApiResult;
|
||||||
import com.nflg.wms.common.pojo.qo.C_MaterialReturnItemQO;
|
|
||||||
import com.nflg.wms.repository.service.ILanguageService;
|
import com.nflg.wms.repository.service.ILanguageService;
|
||||||
import com.nflg.wms.starter.BaseController;
|
import com.nflg.wms.starter.BaseController;
|
||||||
import com.sap.conn.jco.JCoException;
|
import com.sap.conn.jco.JCoException;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -82,14 +76,4 @@ public class TestController extends BaseController {
|
||||||
String ids=basdeSerialNumberControllerService.generateSerialNumber(0);
|
String ids=basdeSerialNumberControllerService.generateSerialNumber(0);
|
||||||
return ApiResult.success(ids);
|
return ApiResult.success(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 打印SAP函数参数,需在控制台查看
|
|
||||||
* @param functionName SAP函数名
|
|
||||||
*/
|
|
||||||
@GetMapping("/sap/function/params")
|
|
||||||
public ApiResult<Void> printSAPFunctionParams(@Valid @RequestParam @NotBlank String functionName) throws JCoException {
|
|
||||||
sapService.printMeta(functionName);
|
|
||||||
return ApiResult.success();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -85,11 +85,13 @@ public class SapService {
|
||||||
});
|
});
|
||||||
tables.put("T_LIST1", list1);
|
tables.put("T_LIST1", list1);
|
||||||
|
|
||||||
List<Map<String, Object>> list2 = new ArrayList<>();
|
if (CollectionUtil.isNotEmpty(sernrs)) {
|
||||||
sernrs.forEach(item -> {
|
List<Map<String, Object>> list2 = new ArrayList<>();
|
||||||
list2.add(Map.of("SERNR", item));
|
sernrs.forEach(item -> {
|
||||||
});
|
list2.add(Map.of("SERNR", item));
|
||||||
tables.put("T_LIST2", list2);
|
});
|
||||||
|
tables.put("T_LIST2", list2);
|
||||||
|
}
|
||||||
|
|
||||||
JCoFunction function = exec("ZWM00_MB107", parameters, tables);
|
JCoFunction function = exec("ZWM00_MB107", parameters, tables);
|
||||||
|
|
||||||
|
|
@ -582,64 +584,4 @@ public class SapService {
|
||||||
throw new NflgException(STATE.BusinessError, "SAP调用异常:" + MDC.get(Constant.TRACE_ID));
|
throw new NflgException(STATE.BusinessError, "SAP调用异常:" + MDC.get(Constant.TRACE_ID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printMeta(String functionName) {
|
|
||||||
try {
|
|
||||||
functionName=functionName.toUpperCase();
|
|
||||||
JCoFunction function = repository.getFunction(functionName);
|
|
||||||
VUtil.trueThrowBusinessError(Objects.isNull(function)).throwMessage("方法"+functionName+"不存在");
|
|
||||||
printMeta(function);
|
|
||||||
}catch (Exception e){
|
|
||||||
log.error("打印方法参数信息异常", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printMeta(JCoFunction function){
|
|
||||||
log.trace("-------------------------------------------------------");
|
|
||||||
log.trace("SAP {} 方法参数信息", function.getName());
|
|
||||||
log.trace("-- Import结构");
|
|
||||||
printParameterField(function.getImportParameterList());
|
|
||||||
log.trace("-- Changing结构");
|
|
||||||
printParameterField(function.getChangingParameterList());
|
|
||||||
log.trace("-- Export结构");
|
|
||||||
printParameterField(function.getExportParameterList());
|
|
||||||
log.trace("-- Table结构");
|
|
||||||
printParameterField(function.getTableParameterList());
|
|
||||||
log.trace("-------------------------------------------------------");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printParameterField(JCoParameterList parameterList){
|
|
||||||
if (Objects.nonNull(parameterList)) {
|
|
||||||
JCoParameterFieldIterator iterator = parameterList.getParameterFieldIterator();
|
|
||||||
if (Objects.nonNull(iterator)) {
|
|
||||||
while (iterator.hasNextField()) {
|
|
||||||
JCoParameterField field = iterator.nextParameterField();
|
|
||||||
log.trace("名称:{},类型:{},描述:{}", field.getName(), field.getTypeAsString(),field.getDescription());
|
|
||||||
if (field.isTable()){
|
|
||||||
printJCoTable(field.getTable());
|
|
||||||
}else if (field.isStructure()){
|
|
||||||
printStructure(field.getStructure());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printJCoTable(JCoTable table){
|
|
||||||
log.trace("Table结构");
|
|
||||||
JCoRecordFieldIterator iterator=table.getRecordFieldIterator();
|
|
||||||
while (iterator.hasNextField()) {
|
|
||||||
JCoRecordField field = iterator.nextRecordField();
|
|
||||||
log.trace("名称:{},类型:{},描述:{}", field.getName(), field.getTypeAsString(),field.getDescription());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printStructure(JCoStructure structure){
|
|
||||||
log.trace("Structure结构");
|
|
||||||
JCoRecordFieldIterator iterator=structure.getRecordFieldIterator();
|
|
||||||
while (iterator.hasNextField()) {
|
|
||||||
JCoRecordField field = iterator.nextRecordField();
|
|
||||||
log.trace("名称:{},类型:{},描述:{}", field.getName(), field.getTypeAsString(),field.getDescription());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,172 @@
|
||||||
package com.nflg.wms.admin;
|
package com.nflg.wms.admin;
|
||||||
|
|
||||||
import com.nflg.wms.admin.service.SapService;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.sap.conn.jco.*;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
public class SapMetaPrintTest {
|
public class SapMetaPrintTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SapService sapService;
|
private JCoRepository repository;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ZWM00_MB007(){
|
public void ZWM00_MB007() throws JCoException {
|
||||||
sapService.printMeta("ZWM00_MB007");
|
printMeta("ZWM00_MB007");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ZWM00_MB107(){
|
public void ZWM00_MB107() throws JCoException {
|
||||||
sapService.printMeta("ZWM00_MB107");
|
printMeta("ZWM00_MB107");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printMeta(String functionName) throws JCoException {
|
||||||
|
functionName = functionName.toUpperCase();
|
||||||
|
JCoFunction function = repository.getFunction(functionName);
|
||||||
|
if (Objects.isNull(function)) {
|
||||||
|
print("方法" + functionName + "不存在");
|
||||||
|
} else {
|
||||||
|
printMeta(function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printMeta(JCoFunction function){
|
||||||
|
print("SAP {} 方法参数信息", function.getName());
|
||||||
|
printParameterField("Import",function.getImportParameterList());
|
||||||
|
printParameterField("Changing",function.getChangingParameterList());
|
||||||
|
printParameterField("Export",function.getExportParameterList());
|
||||||
|
printParameterField("Table",function.getTableParameterList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printParameterField(String name, JCoParameterList parameterList){
|
||||||
|
print("▶ "+name);
|
||||||
|
if (Objects.nonNull(parameterList)) {
|
||||||
|
JCoParameterFieldIterator iterator = parameterList.getParameterFieldIterator();
|
||||||
|
if (Objects.nonNull(iterator)) {
|
||||||
|
List<JCoParameterField> fields = new ArrayList<>();
|
||||||
|
List<String[]> data = new ArrayList<>();
|
||||||
|
while (iterator.hasNextField()) {
|
||||||
|
JCoParameterField field = iterator.nextParameterField();
|
||||||
|
data.add(new String[]{field.getName(), field.getTypeAsString(), field.getDescription()});
|
||||||
|
if (field.isTable() || field.isStructure()){
|
||||||
|
fields.add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printTable(data);
|
||||||
|
fields.forEach(field->{
|
||||||
|
if (field.isTable()){
|
||||||
|
printJCoTable(field);
|
||||||
|
}else if (field.isStructure()){
|
||||||
|
printStructure(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printJCoTable(JCoParameterField pfield){
|
||||||
|
print("★★ {}({}) 参数", pfield.getName(),pfield.getDescription());
|
||||||
|
JCoTable table=pfield.getTable();
|
||||||
|
JCoRecordFieldIterator iterator = table.getRecordFieldIterator();
|
||||||
|
List<String[]> data = new ArrayList<>();
|
||||||
|
while (iterator.hasNextField()) {
|
||||||
|
JCoRecordField field = iterator.nextRecordField();
|
||||||
|
data.add(new String[]{field.getName(), field.getTypeAsString(), field.getDescription()});
|
||||||
|
}
|
||||||
|
printTable(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printStructure(JCoParameterField pfield){
|
||||||
|
print("★★ {}({}) 参数", pfield.getName(),pfield.getDescription());
|
||||||
|
JCoStructure structure=pfield.getStructure();
|
||||||
|
JCoRecordFieldIterator iterator=structure.getRecordFieldIterator();
|
||||||
|
List<String[]> data = new ArrayList<>();
|
||||||
|
while (iterator.hasNextField()) {
|
||||||
|
JCoRecordField field = iterator.nextRecordField();
|
||||||
|
data.add(new String[]{field.getName(), field.getTypeAsString(), field.getDescription()});
|
||||||
|
}
|
||||||
|
printTable(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printTable(List<String[]> datas){
|
||||||
|
SimpleTable table = new SimpleTable();
|
||||||
|
table.addHeader("序号","名称", "类型", "描述");
|
||||||
|
for (int i = 0; i < datas.size(); i++){
|
||||||
|
table.addRow(String.valueOf(i+1), datas.get(i)[0], datas.get(i)[1], datas.get(i)[2]);
|
||||||
|
}
|
||||||
|
table.print();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void print(String content){
|
||||||
|
System.out.println(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void print(String template,Object... args){
|
||||||
|
System.out.println(StrUtil.format(template,args));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 简单实现示例
|
||||||
|
private static class SimpleTable {
|
||||||
|
private final List<String[]> rows = new ArrayList<>();
|
||||||
|
private final List<String> headers = new ArrayList<>();
|
||||||
|
|
||||||
|
public void addHeader(String... headers) {
|
||||||
|
this.headers.addAll(Arrays.asList(headers));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRow(String... values) {
|
||||||
|
rows.add(values);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void print() {
|
||||||
|
// 计算每列最大宽度
|
||||||
|
int[] maxWidths = new int[headers.size()];
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
maxWidths[i] = headers.get(i).length();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String[] row : rows) {
|
||||||
|
for (int i = 0; i < row.length && i < maxWidths.length; i++) {
|
||||||
|
maxWidths[i] = Math.max(maxWidths[i], row[i].length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打印表格
|
||||||
|
printLine(maxWidths);
|
||||||
|
printRow(headers.toArray(new String[0]), maxWidths);
|
||||||
|
printLine(maxWidths);
|
||||||
|
|
||||||
|
for (String[] row : rows) {
|
||||||
|
printRow(row, maxWidths);
|
||||||
|
}
|
||||||
|
printLine(maxWidths);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printLine(int[] widths) {
|
||||||
|
System.out.print("+");
|
||||||
|
for (int width : widths) {
|
||||||
|
for (int i = 0; i < width + 2; i++) {
|
||||||
|
System.out.print("-");
|
||||||
|
}
|
||||||
|
System.out.print("+");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printRow(String[] row, int[] widths) {
|
||||||
|
System.out.print("|");
|
||||||
|
for (int i = 0; i < widths.length; i++) {
|
||||||
|
String value = i < row.length ? row[i] : "";
|
||||||
|
System.out.printf(" %-" + widths[i] + "s |", value);
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue