获取重量api接口测试
This commit is contained in:
parent
00b759c198
commit
681db4295d
|
|
@ -1,12 +1,86 @@
|
||||||
package com.ruoyi.operation.service.impl;
|
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;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/util/getPound")
|
||||||
public class getPoundWeightData {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,4 +86,6 @@ public interface ISysConfigService
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public boolean checkConfigKeyUnique(SysConfig config);
|
public boolean checkConfigKeyUnique(SysConfig config);
|
||||||
|
|
||||||
|
public SysConfig selectConfigByConfigKey(String configKey);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,4 +229,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
||||||
{
|
{
|
||||||
return CacheConstants.SYS_CONFIG_KEY + configKey;
|
return CacheConstants.SYS_CONFIG_KEY + configKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SysConfig selectConfigByConfigKey(String ConfigKey){
|
||||||
|
SysConfig sysConfig = new SysConfig();
|
||||||
|
sysConfig.setConfigKey(ConfigKey);
|
||||||
|
return configMapper.selectConfig(sysConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,12 @@ export function formatDate(date) {
|
||||||
|
|
||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
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'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -636,6 +636,7 @@ import {
|
||||||
listPoundmst, unComplete,
|
listPoundmst, unComplete,
|
||||||
updatePoundmst
|
updatePoundmst
|
||||||
} from "@/api/measurement/bill/poundmst";
|
} from "@/api/measurement/bill/poundmst";
|
||||||
|
import { getWeight } from "@/api/measurement/util/util.js";
|
||||||
import Decimal from "decimal.js";
|
import Decimal from "decimal.js";
|
||||||
import {getTruepound} from "@/api/measurement/basedata/truepound";
|
import {getTruepound} from "@/api/measurement/basedata/truepound";
|
||||||
import {
|
import {
|
||||||
|
|
@ -905,10 +906,11 @@ export default {
|
||||||
if (!this.checkPoundSelected())return;
|
if (!this.checkPoundSelected())return;
|
||||||
// 生成 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;
|
||||||
|
})
|
||||||
// 转换为两位小数,内存中是有限小数
|
// 转换为两位小数,内存中是有限小数
|
||||||
this.queryParams.weight = new Decimal(randomInt / 100);
|
//this.queryParams.weight = new Decimal(randomInt / 100);
|
||||||
debugger
|
|
||||||
},
|
},
|
||||||
//单击主榜单进行单选。
|
//单击主榜单进行单选。
|
||||||
//主榜单单击选中,并将车号进行赋值。(单选)
|
//主榜单单击选中,并将车号进行赋值。(单选)
|
||||||
|
|
|
||||||
|
|
@ -485,6 +485,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { getWeight } from "@/api/measurement/util/util.js";
|
||||||
import { synchronizeData } from "@/api/measurement/operation/outinpound"
|
import { synchronizeData } from "@/api/measurement/operation/outinpound"
|
||||||
import SearchSelect from "@/components/SearchSelect/index.vue";
|
import SearchSelect from "@/components/SearchSelect/index.vue";
|
||||||
//导入过磅申请的列表查询。
|
//导入过磅申请的列表查询。
|
||||||
|
|
|
||||||
|
|
@ -716,6 +716,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { getWeight } from "@/api/measurement/util/util.js";
|
||||||
import { listShortdispound, getShortdispound, delShortdispound, addShortdispound, updateShortdispound } from "@/api/measurement/operation/shortdispound"
|
import { listShortdispound, getShortdispound, delShortdispound, addShortdispound, updateShortdispound } from "@/api/measurement/operation/shortdispound"
|
||||||
import Decimal from "decimal.js";
|
import Decimal from "decimal.js";
|
||||||
import SearchSelect from "@/components/SearchSelect/index.vue";
|
import SearchSelect from "@/components/SearchSelect/index.vue";
|
||||||
|
|
|
||||||
|
|
@ -442,6 +442,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { getWeight } from "@/api/measurement/util/util.js";
|
||||||
import { listSteelpound, getSteelpound, delSteelpound, addSteelpound, updateSteelpound } from "@/api/measurement/operation/steelpound"
|
import { listSteelpound, getSteelpound, delSteelpound, addSteelpound, updateSteelpound } from "@/api/measurement/operation/steelpound"
|
||||||
import {getTruepound} from "@/api/measurement/basedata/truepound";
|
import {getTruepound} from "@/api/measurement/basedata/truepound";
|
||||||
import SearchSelect from "@/components/SearchSelect";
|
import SearchSelect from "@/components/SearchSelect";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue