优化:基于阿里巴巴 Java 开发手册(黄山版)优化 Jackson 超大整数配置

1.编程规约>前后端规约>第6条:
【强制】对于需要使用超大整数的场景,服务端一律使用 String 字符串类型返回,禁止使用 Long 类型。
说明:Java 服务端如果直接返回 Long 整型数据给前端,Javascript 会自动转换为 Number 类型(注:此类型为双精度浮点数,表示原理与取值范围等同于 Java 中的 Double)。Long 类型能表示的最大值是 263-1,在取值范围之内,超过 253(9007199254740992)的数值转化为Javascript 的 Number 时,有些数值会产生精度损失。
扩展说明,在 Long 取值范围内,任何 2 的指数次的整数都是绝对不会存在精度损失的,所以说精度损失是一个概率问题。若浮点数尾数位与指数位空间不限,则可以精确表示任何整数,但很不幸,双精度浮点数的尾数位只有 52 位。
反例:通常在订单号或交易号大于等于 16 位,大概率会出现前后端订单数据不一致的情况。比如,后端传输的 "orderId":362909601374617692,前端拿到的值却是:362909601374617660
This commit is contained in:
2023-03-05 19:31:02 +08:00
parent 95784e5c7d
commit 8823211fd9
14 changed files with 57 additions and 112 deletions

View File

@@ -318,7 +318,7 @@
updateTime: '',
parentName: '',
});
const ids = ref<Array<number>>([]);
const ids = ref<Array<string>>([]);
const title = ref('');
const single = ref(true);
const multiple = ref(true);
@@ -384,7 +384,7 @@
*
* @param id ID
*/
const toUpdate = (id: number) => {
const toUpdate = (id: string) => {
reset();
listDeptTree({}).then((res) => {
treeData.value = res.data;
@@ -448,7 +448,7 @@
*
* @param id ID
*/
const toDetail = async (id: number) => {
const toDetail = async (id: string) => {
if (detailLoading.value) return;
detailLoading.value = true;
detailVisible.value = true;
@@ -493,7 +493,7 @@
*
* @param ids ID 列表
*/
const handleDelete = (ids: Array<number>) => {
const handleDelete = (ids: Array<string>) => {
deleteDept(ids).then((res) => {
proxy.$message.success(res.msg);
getList();

View File

@@ -360,7 +360,7 @@
const { DisEnableStatusEnum } = proxy.useDict('DisEnableStatusEnum');
const menuList = ref<MenuRecord[]>([]);
const ids = ref<Array<number>>([]);
const ids = ref<Array<string>>([]);
const title = ref('');
const single = ref(true);
const multiple = ref(true);
@@ -427,7 +427,7 @@
*
* @param id ID
*/
const toUpdate = (id: number) => {
const toUpdate = (id: string) => {
reset();
listMenuTree({}).then((res) => {
treeData.value = res.data;
@@ -519,7 +519,7 @@
*
* @param ids ID 列表
*/
const handleDelete = (ids: Array<number>) => {
const handleDelete = (ids: Array<string>) => {
deleteMenu(ids).then((res) => {
proxy.$message.success(res.msg);
getList();

View File

@@ -419,7 +419,7 @@
deptIds: undefined,
});
const total = ref(0);
const ids = ref<Array<number>>([]);
const ids = ref<Array<string>>([]);
const title = ref('');
const single = ref(true);
const multiple = ref(true);
@@ -494,7 +494,7 @@
*
* @param id ID
*/
const toUpdate = (id: number) => {
const toUpdate = (id: string) => {
reset();
menuCheckStrictly.value = false;
deptCheckStrictly.value = false;
@@ -644,7 +644,7 @@
*
* @param id ID
*/
const toDetail = async (id: number) => {
const toDetail = async (id: string) => {
if (detailLoading.value) return;
getMenuTree();
getDeptTree();
@@ -690,7 +690,7 @@
*
* @param ids ID 列表
*/
const handleDelete = (ids: Array<number>) => {
const handleDelete = (ids: Array<string>) => {
deleteRole(ids).then((res) => {
proxy.$message.success(res.msg);
getList();

View File

@@ -345,7 +345,7 @@
:mask-closable="false"
unmount-on-close
render-to-body
@ok="handleUpdateUserRole"
@ok="handleUpdateRole"
@cancel="handleCancel"
>
<a-form ref="userRoleFormRef" :model="form" :rules="rules" size="large">
@@ -505,7 +505,7 @@
deptId: undefined,
});
const total = ref(0);
const ids = ref<Array<number>>([]);
const ids = ref<Array<string>>([]);
const title = ref('');
const single = ref(true);
const multiple = ref(true);
@@ -598,7 +598,7 @@
*
* @param id ID
*/
const toUpdate = (id: number) => {
const toUpdate = (id: string) => {
reset();
getDeptOptions();
getRoleOptions();
@@ -614,7 +614,7 @@
*
* @param id ID
*/
const toUpdateRole = (id: number) => {
const toUpdateRole = (id: string) => {
reset();
getRoleOptions();
getUser(id).then((res) => {
@@ -665,7 +665,7 @@
description: '',
status: 1,
deptId: undefined,
roleIds: [] as Array<number>,
roleIds: [] as Array<string>,
};
proxy.$refs.formRef?.resetFields();
};
@@ -704,9 +704,9 @@
};
/**
* 修改用户角色
* 修改角色
*/
const handleUpdateUserRole = () => {
const handleUpdateRole = () => {
proxy.$refs.userRoleFormRef.validate((valid: any) => {
if (!valid && form.value.userId !== undefined) {
updateUserRole({ roleIds: form.value.roleIds }, form.value.userId).then(
@@ -725,7 +725,7 @@
*
* @param id ID
*/
const toDetail = async (id: number) => {
const toDetail = async (id: string) => {
if (detailLoading.value) return;
detailLoading.value = true;
detailVisible.value = true;
@@ -769,7 +769,7 @@
*
* @param ids ID 列表
*/
const handleDelete = (ids: Array<number>) => {
const handleDelete = (ids: Array<string>) => {
deleteUser(ids).then((res) => {
proxy.$message.success(res.msg);
getList();
@@ -781,7 +781,7 @@
*
* @param id ID
*/
const handleResetPassword = (id: number) => {
const handleResetPassword = (id: string) => {
resetPassword(id).then((res) => {
proxy.$message.success(res.msg);
});