获取重量api接口测试1.4

This commit is contained in:
ptt 2025-11-05 10:37:33 +08:00
parent 93c014db92
commit 858bcfec46
5 changed files with 59 additions and 17 deletions

View File

@ -3,6 +3,8 @@ package com.ruoyi.operation.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.basedata.domain.Truepound; import com.ruoyi.basedata.domain.Truepound;
import com.ruoyi.basedata.service.ITruepoundService; import com.ruoyi.basedata.service.ITruepoundService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.DictUtils; import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
@ -19,17 +21,19 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
@RestController @RestController
@RequestMapping("/util/getPound") @RequestMapping("/util/getPound")
public class getPoundWeightData { public class getPoundWeightData extends BaseController {
@Autowired @Autowired
private ISysConfigService sysConfigService; private ISysConfigService sysConfigService;
@Autowired @Autowired
private ITruepoundService truepoundService; private ITruepoundService truepoundService;
@GetMapping(value = "/getWeight/{poundid}") @GetMapping(value = "/getWeight/{poundid}")
public BigDecimal getPoundWeight(@PathVariable("poundid")String poundid) { public AjaxResult getPoundWeight(@PathVariable("poundid")String poundid) {
Truepound truepound = truepoundService.selectTruepoundById(poundid); Truepound truepound = truepoundService.selectTruepoundById(poundid);
if(truepound==null){ if(truepound==null){
throw new RuntimeException("磅点id:"+poundid+"不存在对应的实际磅点不存在"); throw new RuntimeException("磅点id:"+poundid+"不存在对应的实际磅点不存在");
@ -46,8 +50,20 @@ public class getPoundWeightData {
} }
String api = sysConfig.getConfigValue()+pound_api; String api = sysConfig.getConfigValue()+pound_api;
JSONObject jsonObject = doGetRequest(api); JSONObject jsonObject = doGetRequest(api);
HashMap<String, Object> hashMap = new HashMap<>();
if(1==1){
hashMap.put("code", jsonObject.get("code"));
hashMap.put("message", jsonObject.getString("message"));
hashMap.put("data", jsonObject.get("data"));
hashMap.put("return", jsonObject.get("return"));
return success(hashMap);
}
if (jsonObject.getIntValue("code") == 0) { if (jsonObject.getIntValue("code") == 0) {
return jsonObject.getBigDecimal("data"); hashMap.put("code", jsonObject.get("code"));
hashMap.put("message", jsonObject.getString("message"));
hashMap.put("data", jsonObject.get("data"));
hashMap.put("return", jsonObject.get("return"));
return success(hashMap);
}else{ }else{
String message = jsonObject.getString("message"); String message = jsonObject.getString("message");
throw new RuntimeException(message); throw new RuntimeException(message);
@ -78,7 +94,9 @@ public class getPoundWeightData {
} }
in.close(); in.close();
return new JSONObject(response.toString().isEmpty()); JSONObject jsonObject = JSONObject.parseObject(response.toString());
jsonObject.put("return",response.toString());
return jsonObject;
} else { } else {
JSONObject put = new JSONObject(); JSONObject put = new JSONObject();
put.put("code", 1); put.put("code", 1);

View File

@ -908,10 +908,16 @@ export default {
//const randomInt = Math.floor(Math.random() * 9900 + 100); //const randomInt = Math.floor(Math.random() * 9900 + 100);
// //
//this.queryParams.weight = new Decimal(randomInt / 100); //this.queryParams.weight = new Decimal(randomInt / 100);
this.$modal.loading("正在获取重量,请稍候...");
getWeight(this.queryParams.poundid).then(response => { getWeight(this.queryParams.poundid).then(response => {
this.queryParams.weight = response; debugger
console.log("返参"+response); console.log(response);
}) this.queryParams.weight = response.data.data;
}).then(() => {
this.$modal.closeLoading()
}).catch(() => {
this.$modal.closeLoading()
});
}, },
// //
// //

View File

@ -835,12 +835,18 @@ export default {
handleGetweight() { handleGetweight() {
// 100 10000 1.00 100.00 // 100 10000 1.00 100.00
//const randomInt = Math.floor(Math.random() * 9900 + 100); //const randomInt = Math.floor(Math.random() * 9900 + 100);
getWeight(this.queryParams.poundid).then(response => {
this.queryParams.weight = response;
console.log("返参"+response);
})
// //
//this.queryParams.weight = new Decimal(randomInt / 100); //this.queryParams.weight = new Decimal(randomInt / 100);
this.$modal.loading("正在获取重量,请稍候...");
getWeight(this.queryParams.poundid).then(response => {
debugger
console.log(response);
this.queryParams.weight = response.data.data;
}).then(() => {
this.$modal.closeLoading()
}).catch(() => {
this.$modal.closeLoading()
});
}, },
// //
handleStopTimer() { handleStopTimer() {

View File

@ -1028,10 +1028,16 @@ watch: {
// //
//this.queryParams.weight = new Decimal(randomInt / 100); //this.queryParams.weight = new Decimal(randomInt / 100);
this.$modal.loading("正在获取重量,请稍候...");
getWeight(this.queryParams.poundid).then(response => { getWeight(this.queryParams.poundid).then(response => {
this.queryParams.weight = response; debugger
console.log("返参"+response); console.log(response);
}) this.queryParams.weight = response.data.data;
}).then(() => {
this.$modal.closeLoading()
}).catch(() => {
this.$modal.closeLoading()
});
}, },
// //
getEmpPoundData(){ getEmpPoundData(){

View File

@ -716,10 +716,16 @@ export default {
// //
//this.queryParams.weight = new Decimal(randomInt / 100); //this.queryParams.weight = new Decimal(randomInt / 100);
this.$modal.loading("正在获取重量,请稍候...");
getWeight(this.queryParams.poundid).then(response => { getWeight(this.queryParams.poundid).then(response => {
this.queryParams.weight = response; debugger
console.log("返参"+response); console.log(response);
}) this.queryParams.weight = response.data.data;
}).then(() => {
this.$modal.closeLoading()
}).catch(() => {
this.$modal.closeLoading()
});
}, },
// //