Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mis): 白名单账户新增有效期字段,到期自动移除 #1243

Merged
merged 13 commits into from
May 16, 2024
5 changes: 5 additions & 0 deletions apps/mis-server/src/entities/AccountWhitelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@ export class AccountWhitelist {
@Property()
operatorId: string;

@Property()
expirationDate: Date;
usaveh marked this conversation as resolved.
Show resolved Hide resolved

constructor(init: {
account: EntityOrRef<Account>,
time?: Date,
comment: string
operatorId: string;
expirationDate?: Date
}) {
this.account = toRef(init.account);
this.time = init.time ?? new Date();
this.comment = init.comment;
this.operatorId = init.operatorId;
this.expirationDate = init.expirationDate ?? new Date("2099-12-31 00:00");
usaveh marked this conversation as resolved.
Show resolved Hide resolved
}
}
13 changes: 13 additions & 0 deletions apps/mis-server/src/migrations/Migration20240507062612.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Migration } from '@mikro-orm/migrations';

export class Migration20240507062612 extends Migration {

async up(): Promise<void> {
this.addSql('alter table `account_whitelist` add `expiration_date` datetime not null;');
}

async down(): Promise<void> {
this.addSql('alter table `account_whitelist` drop column `expiration_date`;');
}

}
3 changes: 2 additions & 1 deletion apps/mis-server/src/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ export const accountServiceServer = plugin((server) => {
},

whitelistAccount: async ({ request, em, logger }) => {
const { accountName, comment, operatorId, tenantName } = request;
const { accountName, comment, operatorId, tenantName, expirationDate } = request;

const account = await em.findOne(Account, { accountName, tenant: { name: tenantName } },
{ populate: [ "tenant"]});
Expand All @@ -338,6 +338,7 @@ export const accountServiceServer = plugin((server) => {
time: new Date(),
comment,
operatorId,
expirationDate:new Date(expirationDate),
});
account.whitelist = toRef(whitelist);

Expand Down
10 changes: 10 additions & 0 deletions apps/mis-web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export default {
amount: "Amount",
unit: "CNY",
comment: "Comment",
indate:"Indate",

submit: "Submit",
time: "Time",
type: "Type",
Expand Down Expand Up @@ -236,6 +238,7 @@ export default {
blockThresholdAmountTooltip: "The account will be blocked "
+ "when the balance is less than the block threshold amount.",
comment: "Comment",
indate:"Indate",
status: "Status",
statusTooltip: "Account Status Explanation",
statusFrozenTooltip: "Frozen: The account has been frozen by the account administrator "
Expand Down Expand Up @@ -617,6 +620,13 @@ export default {
notExist: "Account does not exist!",
addSuccess: "Added successfully!",
addWhiteList: "Add Whitelisted Account",
indate:"Indate",
custom:"Custom",
oneWeek:"One Week",
oneMonth:"One Month",
oneYear:"One Year",
permanent:"Permanent",

},
adminJobTable: {
batch: "Batch Search",
Expand Down
8 changes: 8 additions & 0 deletions apps/mis-web/src/i18n/zh_cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default {
amount:"金额",
unit:"元",
comment:"备注",
indate:"有效期",
usaveh marked this conversation as resolved.
Show resolved Hide resolved
submit:"提交",
time:"时间",
type:"类型",
Expand Down Expand Up @@ -236,6 +237,7 @@ export default {
blockThresholdAmountTooltip: "当账户余额低于此值时,账户将被封锁",

comment:"备注",
indate:"有效期",
status:"状态",
statusTooltip: "账户状态说明",
statusFrozenTooltip: "冻结:账户已被账户管理员冻结,无法通过此账户提交作业",
Expand Down Expand Up @@ -617,6 +619,12 @@ export default {
notExist:"账户不存在!",
addSuccess:"添加成功!",
addWhiteList:"添加白名单账户",
indate:"有效期",
custom:"自定义",
oneWeek:"一周",
oneMonth:"一个月",
oneYear:"一年",
permanent:"永久有效",
},
adminJobTable:{
batch:"批量搜索",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
*/

import { PlusOutlined } from "@ant-design/icons";
import { App, Button, Form, Input, Modal } from "antd";
import { App, Button, DatePicker, Flex, Form, Input, Modal, Select } from "antd";
import dayjs from "dayjs";
import React, { useState } from "react";
import { api } from "src/apis";
import { prefix, useI18nTranslateToString } from "src/i18n";

interface FormProps {
accountName: string;
comment: string;
indate: string;
expirationDate: dayjs.Dayjs
}

interface ModalProps {
Expand All @@ -39,12 +42,60 @@
const { message } = App.useApp();
const [loading, setLoading] = useState(false);
const [form] = Form.useForm<FormProps>();
const [selectedOption, setSelectedOption] = useState<string>("custom"); // 添加状态来跟踪选择的选项

const onOk = async () => {
const { accountName, comment } = await form.validateFields();
setLoading(true);

await api.whitelistAccount({ body: { accountName: accountName.trim(), comment } })
const options = [ // 定义 Select 选项数组,使用国际化函数 t() 翻译每个选项的 label
{ value: "custom", label: t(p("custom")) },
{ value: "oneWeek", label: t(p("oneWeek")) },
{ value: "oneMonth", label: t(p("oneMonth")) },
{ value: "oneYear", label: t(p("oneYear")) },
{ value: "permanent", label: t(p("permanent")) },
];

// 定义规范时间
const dateFormat = "YYYY-MM-DD";
// dateRange的时间
const [expirationDate, setExpirationDate] = useState<dayjs.Dayjs>(dayjs());

// 对dateRange时间根据options选项进行处理
React.useEffect(() => {
let newDate: dayjs.Dayjs;
switch (selectedOption) {
case "oneWeek":
newDate = dayjs().add(1, "week");
break;

case "oneMonth":
newDate = dayjs().add(1, "month");
break;

case "oneYear":
newDate = dayjs().add(1, "year");
break;

case "permanent":
newDate = dayjs("2099-12-31");
break;

case "custom":
newDate = expirationDate.isValid() ? expirationDate : dayjs();
break;

default:
newDate = dayjs();
break;
}
setExpirationDate(newDate); // 更新组件状态
form.setFieldsValue({ expirationDate: newDate });
}, [selectedOption]);



const onOk = async () => {
const { accountName, indate, expirationDate, comment } = await form.validateFields();

Check warning on line 96 in apps/mis-web/src/pageComponents/tenant/AddWhitelistedAccountButton.tsx

View workflow job for this annotation

GitHub Actions / Test and version packages

'indate' is assigned a value but never used. Allowed unused vars must match /^_/u
await api.whitelistAccount({ body: { accountName: accountName.trim(), comment,
expirationDate:expirationDate.toISOString() } })
.httpError(404, () => {
message.error(t(p("notExist")));
})
Expand All @@ -70,6 +121,33 @@
<Form.Item name="accountName" rules={[{ required: true }]} label={t(pCommon("accountName"))}>
<Input />
</Form.Item>
{/* 日期选择 */}
<Flex justify='space-between'>
<Form.Item
name="indate"
label={t(pCommon("indate"))}
rules={[{ required: true }]}
>
<Select
defaultValue={options[0].value}
options={options}
onChange={(value) => setSelectedOption(value)} // 更新选择
usaveh marked this conversation as resolved.
Show resolved Hide resolved
/>
</Form.Item>
<Form.Item
name="expirationDate"
rules={[{ required: selectedOption === "custom", message:"请输入有效期" }]}
style={{ width: "60%" }}
>
{/* 根据选项禁用或启用 DatePicker */}
<DatePicker
disabled={selectedOption !== "custom"}
minDate={dayjs(dayjs().format(dateFormat))}
value={ expirationDate }
onChange={(date) => setExpirationDate(date)} // 更新状态
/>
</Form.Item>
</Flex>
<Form.Item name="comment" rules={[{ required: true }]} label={t(pCommon("comment"))}>
<Input.TextArea />
</Form.Item>
Expand All @@ -82,12 +160,16 @@
refresh: () => void;
}



export const AddWhitelistedAccountButton: React.FC<Props> = ({ refresh }) => {

const [modalShow, setModalShow] = useState(false);

const t = useI18nTranslateToString();



return (
<>
<NewAccountModal close={() => setModalShow(false)} open={modalShow} refresh={refresh} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const WhitelistAccountSchema = typeboxRouteSchema({
body: Type.Object({
accountName: Type.String(),
comment: Type.String(),
expirationDate:Type.String(),
usaveh marked this conversation as resolved.
Show resolved Hide resolved
}),

responses: {
Expand All @@ -47,7 +48,7 @@ export default route(WhitelistAccountSchema,
return;
}

const { accountName, comment } = req.body;
const { accountName, comment, expirationDate } = req.body;

const logInfo = {
operatorUserId: info.identityId,
Expand All @@ -65,6 +66,7 @@ export default route(WhitelistAccountSchema,
accountName,
operatorId: info.identityId,
comment,
expirationDate,
})
.then(async () => {
await callLog(logInfo, OperationResult.SUCCESS);
Expand Down
1 change: 1 addition & 0 deletions protos/server/account.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ message WhitelistAccountRequest {
string account_name = 2;
string operator_id = 3;
string comment = 4;
string expiration_date = 5;
usaveh marked this conversation as resolved.
Show resolved Hide resolved
}

// NOT_FOUND: account is not found.
Expand Down