Skip to content

Commit

Permalink
fix(mis): 计费调整精确到分 (#1236)
Browse files Browse the repository at this point in the history
涉及到金额的显示页面,全部只展示到分,涉及到金额的输入页面,全部限制为只允许输入精确到分。涉及到金额的导出,也全部只展示到分。
1. 仪表盘:
  a. 账户信息:“可用余额”;
2. 用户空间:
  a. 已结束的作业: “作业计费合计”、“作业计费”、“详情-作业计费”;
  b. 集群和分区信息:“单价”;
  c. 操作日志中,操作内容相关;
3. 账户管理:
  a. 账户信息:“账户余额”、“封锁阈值”;
  b. 已结束的作业: “作业计费合计”、“作业计费”、“详情-作业计费”;
  c. 用户管理:“已用额度/用户限额”、“限额管理-当前已使用/总限额”、“限额管理-修改限额至”;
  d. 充值记录:“合计”、“交费金额”;
  e. 消费记录:“合计”、“扣费金额”;
4. 租户管理
  a. 租户信息:“租户余额”、“默认账户封锁阈值”、“设置默认账户封锁阈值”;
  b. 作业价格表: “单价(元)”、“设置计费价格-单价(元)”;
  c. 已结束的作业:“租户计费"、"平台计费”、详情中的“租户计费"、"平台计费”、“租户计费合计”、“平台计费合计”;
  d. 账户列表中所有金额相关;
  e. 白名单账户列表所有金额相关;
  f. 账户充值限制只能充值金额精确到分;
  g. 账户充值记录、租户充值记录、账户消费记录、操作日志所有金额相关;
5. 平台管理:
  a. 作业计费价格表、租户列表、账户列表所有金额相关;
  b. 充值记录、账户消费记录、操作日志所有金额相关;
  c. 平台数据统计:消费列,金额显示精确到分:消费/充值金额,可视图表金额显示精确到分,坐标轴动态tick动态精确到分。
  • Loading branch information
cuvalign committed May 6, 2024
1 parent c178b72 commit 5a8a09a
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 24 deletions.
7 changes: 5 additions & 2 deletions apps/mis-web/src/pageComponents/admin/DataBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const DataBarChart: React.FC<Props> = ({
xLabel = "",
toolTipFormatter = (value) => value,
}) => {

const tickFormatter = (value: number) => {
const roundedValue = Number.isInteger(value) ? value : parseFloat(value.toFixed(2));
return roundedValue.toString();
};
return (
<StatisticContainer>
{isLoading ? <Spin /> : (
Expand All @@ -64,7 +67,7 @@ export const DataBarChart: React.FC<Props> = ({
label={{ value: xLabel, position: "insideBottom", offset: 0 }}
height={40}
/>
<YAxis padding={{ top: 20 }} />
<YAxis padding={{ top: 20 }} tickFormatter={tickFormatter} />
<Tooltip
formatter={toolTipFormatter}
/>
Expand Down
8 changes: 5 additions & 3 deletions apps/mis-web/src/pageComponents/admin/StatisticCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface Props {
loading: boolean
icon: React.ReactNode | React.ForwardRefExoticComponent<{}>;
iconColor?: string
precision?: number | undefined
}

const Container = styled.div`
Expand All @@ -40,7 +41,8 @@ const iconToNode = (Icon: any, color?: string) => {

const p = prefix("pageComp.admin.statisticCard.");

export const StatisticCard: React.FC<Props> = ({ title, newAddValue = 0, totalValue = 0, loading, icon, iconColor }) =>
export const StatisticCard: React.FC<Props> = ({ title, newAddValue = 0,
totalValue = 0, loading, icon, iconColor, precision = 0 }) =>
{
const t = useI18nTranslateToString();

Expand All @@ -52,7 +54,7 @@ export const StatisticCard: React.FC<Props> = ({ title, newAddValue = 0, totalVa
<Statistic
title={title}
value={newAddValue}
precision={0}
precision={precision}
loading={loading}
valueStyle={{ color: "#94070A" }}
/>
Expand All @@ -63,7 +65,7 @@ export const StatisticCard: React.FC<Props> = ({ title, newAddValue = 0, totalVa
title={`${t(p("total"))}${title}: `}
value={totalValue}
loading={loading}
precision={0}
precision={precision}
valueStyle={{ color: "grey", marginLeft: "10px", fontSize: 14, marginBottom: 4 }}
/>
</Card>
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-web/src/pageComponents/common/PaymentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const PaymentTable: React.FC<Props> = ({ accountName, searchType }) => {
</Form.Item>
<Form.Item label={t(p("sum"))}>
<strong>
{data ? data.total.toFixed(3) : 0}
{data ? data.total.toFixed(2) : 0}
</strong>
</Form.Item>
<Form.Item>
Expand Down Expand Up @@ -234,7 +234,7 @@ export const PaymentTable: React.FC<Props> = ({ accountName, searchType }) => {
: undefined
}
<Table.Column dataIndex="time" title={t(p("paymentDate"))} width="13.5%" render={(v) => formatDateTime(v)} />
<Table.Column dataIndex="amount" title={t(p("paymentAmount"))} width="10%" render={(v) => v.toFixed(3)} />
<Table.Column dataIndex="amount" title={t(p("paymentAmount"))} width="10%" render={(v) => v.toFixed(2)} />
<Table.Column
dataIndex="type"
title={t(pCommon("type"))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const AccountInfoSection: React.FC<Props> = ({ info }) => {
title={t("dashboard.account.balance")}
valueStyle={{ color: minOne < 0 ? "red" : undefined }}
prefix={"¥"}
value={minOne.toFixed(3)}
value={minOne.toFixed(2)}
/>
</Row>
</StatCard>
Expand Down
2 changes: 1 addition & 1 deletion apps/mis-web/src/pageComponents/finance/ChargeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const ChargeForm: React.FC = () => {
<Input />
</Form.Item>
<Form.Item name="amount" label={t(pCommon("amount"))} rules={[{ required: true }]}>
<InputNumber step={0.01} addonAfter={t(pCommon("unit"))} />
<InputNumber step={0.01} addonAfter={t(pCommon("unit"))} precision={2} />
</Form.Item>
<Form.Item
name="type"
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-web/src/pageComponents/finance/ChargeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const ChargeTable: React.FC<Props> = ({
</Form.Item>
<Form.Item label={t(pCommon("sum"))}>
<strong>
{totalResultData?.totalAmount ?? 0}
{totalResultData?.totalAmount?.toFixed(2) ?? 0}
</strong>
</Form.Item>
<Form.Item>
Expand Down Expand Up @@ -300,7 +300,7 @@ export const ChargeTable: React.FC<Props> = ({
render={(_, r) => r.userId ? (`${r.userId} (${r.userName})`) : ""}
/>
<Table.Column<ChargeInfo> dataIndex="time" title={t(p("time"))} render={(v) => formatDateTime(v)} />
<Table.Column<ChargeInfo> dataIndex="amount" title={t(p("amount"))} render={(v) => v.toFixed(3)} />
<Table.Column<ChargeInfo> dataIndex="amount" title={t(p("amount"))} render={(v) => v.toFixed(2)} />
<Table.Column<ChargeInfo> dataIndex="type" title={t(pCommon("type"))} />
<Table.Column<ChargeInfo>
dataIndex="comment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const EditPriceModal: React.FC<CommonModalProps & {
<Select options={Object.values(AmountStrategy).map((x) => ({ label: x, value: x }))} />
</Form.Item>
<Form.Item label={t(p("price"))} name="price" rules={[{ required: true }]}>
<InputNumber precision={3} min={0} />
<InputNumber precision={2} min={0} />
</Form.Item>
<Form.Item label={t(pCommon("comment"))} name="description">
<Input />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const EditPriceModal: React.FC<CommonModalProps & {
/>
</Form.Item>
<Form.Item label={t(p("price"))} name="price" initialValue={0} rules={[{ required: true }]}>
<InputNumber precision={3} min={0} />
<InputNumber precision={2} min={0} />
</Form.Item>
<Form.Item label={t(pCommon("comment"))} name="description">
<Input />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const AccountWhitelistTable: React.FC<Props> = ({
<>
<Divider type="vertical" />
<span>
{t(p("debtSum"))}<strong>{getTotalDebtAmount(data).toFixed(3)} {t(pCommon("unit"))}</strong>
{t(p("debtSum"))}<strong>{getTotalDebtAmount(data).toFixed(2)} {t(pCommon("unit"))}</strong>
</span>
</>
</div>
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-web/src/pages/accounts/[accountName]/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export const AccountInfoPage: NextPage<Props> = requireAuth(
</Tag>
</Descriptions.Item>
<Descriptions.Item label={t("common.accountBalance")}>
{balance.toFixed(3)} {t("common.unit")}
{balance.toFixed(2)} {t("common.unit")}
</Descriptions.Item>
<Descriptions.Item label={t("common.blockThresholdAmount")}>
{blockThresholdAmount.toFixed(3)} {t("common.unit")}
{blockThresholdAmount.toFixed(2)} {t("common.unit")}
</Descriptions.Item>
</Descriptions>

Expand Down
9 changes: 5 additions & 4 deletions apps/mis-web/src/pages/admin/statistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ requireAuth((u) => u.platformRoles.includes(PlatformRole.PLATFORM_ADMIN))

return topChargeAccount?.results.map((r) => ({
x: r.accountName,
y: moneyToNumber(r.chargedAmount),
y: moneyToNumber(r.chargedAmount).toFixed(2),
})) || [];
}, [query, topChargeAccount]);

const topPayAccountData = useMemo(() => {

return topPayAccount?.results.map((r) => ({
x: r.accountName,
y: moneyToNumber(r.payAmount),
y: moneyToNumber(r.payAmount).toFixed(2),
})) || [];
}, [query, topPayAccount]);

Expand Down Expand Up @@ -383,6 +383,7 @@ requireAuth((u) => u.platformRoles.includes(PlatformRole.PLATFORM_ADMIN))
loading={totalChargeAmountLoading || dailyChargeLoading}
icon={MoneyCollectOutlined}
iconColor="#feca57"
precision={2}
/>
</Col>
<Col span={24}>
Expand Down Expand Up @@ -446,7 +447,7 @@ requireAuth((u) => u.platformRoles.includes(PlatformRole.PLATFORM_ADMIN))
<DataLineChart
data={dailyChargeData.map((d) => ({
x: d.date.format("YYYY-MM-DD"),
y: d.count,
y: d.count.toFixed(2),
}))}
title={t(p("chargeAmount"))}
isLoading={dailyChargeLoading}
Expand All @@ -468,7 +469,7 @@ requireAuth((u) => u.platformRoles.includes(PlatformRole.PLATFORM_ADMIN))
<DataLineChart
data={dailyPayData.map((d) => ({
x: d.date.format("YYYY-MM-DD"),
y: d.count,
y: d.count.toFixed(2),
}))}
title={t(p("payAmount"))}
toolTipFormatter={amountToolTipFormatter}
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-web/src/pages/tenant/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ export const TenantInfoPage: NextPage<Props> = requireAuth((u) => u.tenantRoles.
{userCount}
</Descriptions.Item>
<Descriptions.Item label={t("common.tenantBalance")}>
{moneyToNumber(balance).toFixed(3)} {t("common.unit")}
{moneyToNumber(balance).toFixed(2)} {t("common.unit")}
</Descriptions.Item>
<Descriptions.Item label={t("common.defaultAccountBlockThreshold")}>
<Space>
<span>
{moneyToNumber(defaultAccountBlockThreshold).toFixed(3)} {t("common.unit")}
{moneyToNumber(defaultAccountBlockThreshold).toFixed(2)} {t("common.unit")}
</span>
<ChangeDefaultAccountBlockThresholdLink
tenantName={tenantName}
Expand Down
4 changes: 2 additions & 2 deletions apps/mis-web/src/utils/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { moneyToNumber } from "@scow/lib-decimal";
import type { Money } from "@scow/protos/build/common/money";

export function moneyToString(money: Money) {
return moneyToNumber(money).toFixed(3);
return moneyToNumber(money).toFixed(2);
}

export function nullableMoneyToString(money: Money | undefined) {
return money ? moneyToString(money) : Number.prototype.toFixed.call(0, 3);
return money ? moneyToString(money) : Number.prototype.toFixed.call(0, 2);
}

0 comments on commit 5a8a09a

Please sign in to comment.