优化erp查询异常抛出测试

This commit is contained in:
liss
2025-10-13 17:11:36 +08:00
parent 2268b802df
commit 8cce3a2aaa
3 changed files with 52 additions and 2 deletions

View File

@@ -117,4 +117,12 @@ public class ErpCompanyController {
return success(true);
}
@PostMapping("/test1")
@Operation(summary = "获取配置")
@PreAuthorize("@ss.hasPermission('sply:erp-company:get')")
public CommonResult<String> test1() {
String TEST = erpCompanyService.test1();
return success(TEST);
}
}

View File

@@ -72,4 +72,6 @@ public interface ErpCompanyService {
ErpCompanyDO getErpCompanyByNumber(String number);
void test();
String test1();
}

View File

@@ -16,9 +16,15 @@ import com.zt.plat.module.erp.enums.OftenEnum;
import com.zt.plat.module.erp.utils.ErpConfig;
import com.zt.plat.module.erp.utils.MyRedisConfig;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,6 +35,7 @@ import java.util.stream.Collectors;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.module.erp.enums.ApiConstants.TABLE_FIELD_SPLY_ERP_CPN_NUM;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_COMPANY_NOT_EXISTS;
import static com.zt.plat.module.erp.enums.ErrorCodeConstants.ERP_ERROR_EXISTS;
import static dm.jdbc.util.DriverUtil.log;
/**
@@ -42,11 +49,14 @@ public class ErpCompanyServiceImpl implements ErpCompanyService {
@Resource
private ErpCompanyMapper erpCompanyMapper;
@Resource
private MyRedisConfig myRedisConfig;
@Resource
private ErpConfig erpConfig;
@Value("${erp.address}")
private String erpAddress;
@Value("${erp.sapsys}")
private String sapsys;
@Override
public ErpCompanyRespVO createErpCompany(ErpCompanySaveReqVO createReqVO) {
@@ -250,4 +260,34 @@ public class ErpCompanyServiceImpl implements ErpCompanyService {
throw exception(ERP_COMPANY_NOT_EXISTS);
}
}
@Override
public String test1() {
try {
String address = erpAddress + "-" + sapsys;
OftenEnum.FuncnrEnum funcnrEnum = OftenEnum.FuncnrEnum.公司代码;
String funcnr = funcnrEnum.getFuncnr();
// 构建完整URL
String url = "http://" + erpAddress + "/api/rfc/get";
// 构建请求参数
JSONObject requestBody = new JSONObject();
requestBody.put("sapsys", sapsys);
requestBody.put("funcnr", funcnr); // 获取枚举值
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.valueOf(MediaType.APPLICATION_JSON_UTF8_VALUE));
// 创建HTTP请求实体
HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toJSONString(), headers);
// 发送POST请求
RestTemplate restTemplate = new RestTemplate();
// ResponseEntity<String> response = restTemplate.postForEntity(url, requestEntity, String.class);
return address;
} catch (Exception e) {
throw exception(ERP_ERROR_EXISTS);
}
}
}