获取重量api接口测试

This commit is contained in:
ptt 2025-11-04 16:11:38 +08:00
parent 00b759c198
commit 681db4295d
8 changed files with 101 additions and 5 deletions

View File

@ -1,12 +1,86 @@
package com.ruoyi.operation.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.math.BigDecimal;
@RestController
@RequestMapping("/util/getPound")
public class getPoundWeightData {
@Autowired
private ISysConfigService sysConfigService;
public BigDecimal getPoundWeight(String poundNumber) {
@GetMapping(value = "/getWeight/{poundid}")
public BigDecimal getPoundWeight(@PathVariable("poundid")String poundid) {
//根据地磅编码在系统参数中获取接口地址调用接口返回数据
return BigDecimal.ZERO;
String pound_api = DictUtils.getDictLabel("pound_api", poundid);
SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("pound_api_ip");
String api = sysConfig.getConfigValue()+pound_api;
JSONObject jsonObject = doGetRequest(api);
if (jsonObject.getIntValue("code") == 0) {
return jsonObject.getBigDecimal("data");
}else{
String message = jsonObject.getString("message");
throw new RuntimeException(message);
}
}
/**
* 通用GET请求方法
*/
private JSONObject doGetRequest(String bsseurl) {
HttpURLConnection connection = null;
try {
URL url = new URL(bsseurl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return new JSONObject(response.toString().isEmpty());
} else {
JSONObject put = new JSONObject();
put.put("code", 1);
put.put("message", "HTTP请求失败: " + responseCode);
put.put("data", null);
return put;
}
} catch (Exception e) {
JSONObject put = new JSONObject();
put.put("code", 1);
put.put("message", "请求异常: " + e.getMessage());
put.put("data", null);
return put;
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
}

View File

@ -86,4 +86,6 @@ public interface ISysConfigService
* @return 结果
*/
public boolean checkConfigKeyUnique(SysConfig config);
public SysConfig selectConfigByConfigKey(String configKey);
}

View File

@ -229,4 +229,10 @@ public class SysConfigServiceImpl implements ISysConfigService
{
return CacheConstants.SYS_CONFIG_KEY + configKey;
}
public SysConfig selectConfigByConfigKey(String ConfigKey){
SysConfig sysConfig = new SysConfig();
sysConfig.setConfigKey(ConfigKey);
return configMapper.selectConfig(sysConfig);
}
}

View File

@ -10,3 +10,12 @@ export function formatDate(date) {
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
import request from '@/utils/request'
// 获取流水编码
export function getWeight(poundid) {
return request({
url: '/util/getPound/getWeight/'+poundid,
method: 'get'
})
}

View File

@ -636,6 +636,7 @@ import {
listPoundmst, unComplete,
updatePoundmst
} from "@/api/measurement/bill/poundmst";
import { getWeight } from "@/api/measurement/util/util.js";
import Decimal from "decimal.js";
import {getTruepound} from "@/api/measurement/basedata/truepound";
import {
@ -905,10 +906,11 @@ export default {
if (!this.checkPoundSelected())return;
// 100 10000 1.00 100.00
const randomInt = Math.floor(Math.random() * 9900 + 100);
getWeight(this.queryParams.poundid).then(response => {
this.queryParams.weight = response;
})
//
this.queryParams.weight = new Decimal(randomInt / 100);
debugger
//this.queryParams.weight = new Decimal(randomInt / 100);
},
//
//

View File

@ -485,6 +485,7 @@
</template>
<script>
import { getWeight } from "@/api/measurement/util/util.js";
import { synchronizeData } from "@/api/measurement/operation/outinpound"
import SearchSelect from "@/components/SearchSelect/index.vue";
//

View File

@ -716,6 +716,7 @@
</template>
<script>
import { getWeight } from "@/api/measurement/util/util.js";
import { listShortdispound, getShortdispound, delShortdispound, addShortdispound, updateShortdispound } from "@/api/measurement/operation/shortdispound"
import Decimal from "decimal.js";
import SearchSelect from "@/components/SearchSelect/index.vue";

View File

@ -442,6 +442,7 @@
</template>
<script>
import { getWeight } from "@/api/measurement/util/util.js";
import { listSteelpound, getSteelpound, delSteelpound, addSteelpound, updateSteelpound } from "@/api/measurement/operation/steelpound"
import {getTruepound} from "@/api/measurement/basedata/truepound";
import SearchSelect from "@/components/SearchSelect";