Skip to content

Commit

Permalink
fix(mis): 消费记录导出日期时区不一致修复 (#1485)
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-vah authored Feb 27, 2025
2 parents 2cef16e + cc1f0cf commit 0a8e628
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-starfishes-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@scow/mis-web": patch
---

消费记录导出日期时区不一致修复
3 changes: 3 additions & 0 deletions apps/mis-web/src/pageComponents/file/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export const urlToExport = ({
count,
query,
encoding,
timeZone,
}: {
exportApi: string
columns: string[],
count: number,
query: Record<string, string | number | boolean | string[] | undefined>
encoding: Encoding
timeZone?: string | undefined
},
) => {
const params = new URLSearchParams();
Expand All @@ -54,6 +56,7 @@ export const urlToExport = ({
});
params.append("count", count.toString());
params.append("encoding", encoding);
params.append("timeZone",timeZone ?? "UTC");
const queryString = params.toString();
const fullPath = join(publicConfig.BASE_PATH, `/api/file/${exportApi}?${queryString}`);
return fullPath;
Expand Down
3 changes: 3 additions & 0 deletions apps/mis-web/src/pageComponents/finance/ChargeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ export const ChargeTable: React.FC<Props> = ({

// 处理消费记录导出的函数
const handleExport = async (columns: string[], encoding: Encoding) => {
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

const totalCount = totalResultData?.totalCount ?? 0;
if (totalCount > MAX_EXPORT_COUNT) {
message.error(t(pCommon("exportMaxDataErrorMsg"), [MAX_EXPORT_COUNT]));
Expand All @@ -176,6 +178,7 @@ export const ChargeTable: React.FC<Props> = ({
window.location.href = urlToExport({
encoding,
exportApi: "exportChargeRecord",
timeZone:timeZone,
columns,
count: totalCount,
query: {
Expand Down
7 changes: 4 additions & 3 deletions apps/mis-web/src/pages/api/file/exportChargeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const ExportChargeRecordSchema = typeboxRouteSchema({
searchType: Type.Optional(Type.Enum(SearchType)),
userIds: Type.Optional(Type.String()),
encoding: Type.Enum(Encoding),
timeZone:Type.Optional(Type.String()),
}),

responses:{
Expand All @@ -62,7 +63,7 @@ export const ExportChargeRecordSchema = typeboxRouteSchema({
export default route(ExportChargeRecordSchema, async (req, res) => {
const { query } = req;

const { columns, startTime, endTime, searchType, isPlatformRecords, count, userIds, encoding } = query;
const { columns, startTime, endTime, searchType, isPlatformRecords, count, userIds, encoding, timeZone } = query;
let { accountNames, types } = query;
accountNames = emptyStringArrayToUndefined(accountNames);
types = emptyStringArrayToUndefined(types);
Expand Down Expand Up @@ -92,7 +93,7 @@ export default route(ExportChargeRecordSchema, async (req, res) => {

const client = getClient(ExportServiceClient);

const filename = `charge_record-${new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" })}.csv`;
const filename = `charge_record-${new Date().toLocaleString("zh-CN", { timeZone: timeZone ?? "UTC" })}.csv`;
const dispositionParm = "filename* = UTF-8''" + encodeURIComponent(filename);

const contentTypeWithCharset = getContentTypeWithCharset(filename, encoding);
Expand Down Expand Up @@ -125,7 +126,7 @@ export default route(ExportChargeRecordSchema, async (req, res) => {
accountName: x.accountName,
tenantName: x.tenantName,
userId: x.userId,
time: x.time ? new Date(x.time).toISOString() : "",
time: x.time ? new Date(x.time).toLocaleString("zh-CN", { timeZone: timeZone ?? "UTC" }) : "",
amount: nullableMoneyToString(x.amount),
type: x.type,
comment: x.comment,
Expand Down

0 comments on commit 0a8e628

Please sign in to comment.