From bc2544ed3449ee9ce1a8a0147a7e191458e221a9 Mon Sep 17 00:00:00 2001 From: sealday Date: Wed, 20 Mar 2024 18:23:30 +0800 Subject: [PATCH 1/3] feat: add unused records block --- .../src/client/hooks/usePdfPath.tsx | 2 +- .../@hera/plugin-rental/src/client/index.tsx | 18 +++-- .../AddToChecklistActionInitializer.tsx | 2 +- .../ColumnSwitchActionInitializer.tsx | 2 +- .../PDFViewerPrintActionInitializer.tsx | 0 .../RecordPrintSetupActionInitializer.tsx | 2 +- .../RecordPrintSetupMargingTopInitializer.tsx | 2 +- ...SettlementExcelExportActionInitializer.tsx | 0 .../{ => actions}/SettlementExportExcel.tsx | 6 +- ...SettlementStyleSwitchActionInitializer.tsx | 0 .../blocks/UnusedRecordsBlockInitializer.tsx | 80 +++++++++++++++++++ 11 files changed, 99 insertions(+), 15 deletions(-) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/AddToChecklistActionInitializer.tsx (92%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/ColumnSwitchActionInitializer.tsx (95%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/PDFViewerPrintActionInitializer.tsx (100%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/RecordPrintSetupActionInitializer.tsx (95%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/RecordPrintSetupMargingTopInitializer.tsx (96%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/SettlementExcelExportActionInitializer.tsx (100%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/SettlementExportExcel.tsx (99%) rename packages/plugins/@hera/plugin-rental/src/client/schema-initializer/{ => actions}/SettlementStyleSwitchActionInitializer.tsx (100%) create mode 100644 packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx diff --git a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx index 2e54ce1c2..65ddc05c9 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/hooks/usePdfPath.tsx @@ -1,6 +1,6 @@ import { useRecord } from '@nocobase/client'; import React, { createContext, useContext, useState } from 'react'; -import { SettlementStyleContext } from '../schema-initializer/SettlementStyleSwitchActionInitializer'; +import { SettlementStyleContext } from '../schema-initializer/actions/SettlementStyleSwitchActionInitializer'; export const PdfIsDoubleContext = createContext({ isDouble: null, diff --git a/packages/plugins/@hera/plugin-rental/src/client/index.tsx b/packages/plugins/@hera/plugin-rental/src/client/index.tsx index 15d245b8b..8e666761e 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/index.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/index.tsx @@ -10,7 +10,7 @@ import { RecordFeeConvertedAmount } from './custom-components/RecordFeeConverted import { ReadFeeConvertedAmount } from './custom-components/RecordFeeConvertedRead'; import { RecordDetails } from './custom-components/RecordDetails'; import { Locale, tval } from './locale'; -import { AddToChecklistActionInitializer } from './schema-initializer/AddToChecklistActionInitializer'; +import { AddToChecklistActionInitializer } from './schema-initializer/actions/AddToChecklistActionInitializer'; import { useAddToChecklistActionProps } from './hooks/useAddToChecklistActionProps'; import { DetailChecks } from './custom-components/DetailChecks'; import { @@ -18,7 +18,7 @@ import { PrintCounterAction, PrintCounterProvider, usePDFViewerCountablePrintActionProps, -} from './schema-initializer/PDFViewerPrintActionInitializer'; +} from './schema-initializer/actions/PDFViewerPrintActionInitializer'; import { PdfIsDoubleProvider, useRecordPdfPath, @@ -26,22 +26,23 @@ import { useWaybillPdfPath, WaybillsProvider, } from './hooks/usePdfPath'; -import { ColumnSwitchAction, ColumnSwitchActionInitializer } from './schema-initializer/ColumnSwitchActionInitializer'; +import { ColumnSwitchAction, ColumnSwitchActionInitializer } from './schema-initializer/actions/ColumnSwitchActionInitializer'; import { SettlementExcelExportActionInitializer, useSettlementExcelExportActionProps, -} from './schema-initializer/SettlementExcelExportActionInitializer'; +} from './schema-initializer/actions/SettlementExcelExportActionInitializer'; import { SettlementStyleProvider, SettlementStyleSwitchAction, SettlementStyleSwitchActionInitializer, useSettlementStyleSwitchActionProps, -} from './schema-initializer/SettlementStyleSwitchActionInitializer'; -import { RecordPrintSetupActionInitializer, PrintSetup } from './schema-initializer/RecordPrintSetupActionInitializer'; +} from './schema-initializer/actions/SettlementStyleSwitchActionInitializer'; +import { RecordPrintSetupActionInitializer, PrintSetup } from './schema-initializer/actions/RecordPrintSetupActionInitializer'; import { RecordPrintSetupMargingTopInitializer, PrintSetupMargingTop, -} from './schema-initializer/RecordPrintSetupMargingTopInitializer'; +} from './schema-initializer/actions/RecordPrintSetupMargingTopInitializer'; +import { UnusedRecordsBlockHelper } from './schema-initializer/blocks/UnusedRecordsBlockInitializer'; export class PluginRentalClient extends Plugin { locale: Locale; async afterAdd() {} @@ -188,6 +189,9 @@ export class PluginRentalClient extends Plugin { useSettlementExcelExportActionProps, useSettlementStyleSwitchActionProps, }); + + await new UnusedRecordsBlockHelper(this.app).load(); + // FIXME await this.app.apiClient.resource('link-manage').init({ name: 'DetailCheckPage' }); } diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/AddToChecklistActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/AddToChecklistActionInitializer.tsx similarity index 92% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/AddToChecklistActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/AddToChecklistActionInitializer.tsx index 31ef2ae11..17adedd95 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/AddToChecklistActionInitializer.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/AddToChecklistActionInitializer.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { ActionInitializer } from '@nocobase/client'; -import { tval } from '../locale'; +import { tval } from '../../locale'; export const AddToChecklistActionInitializer = (props) => { const schema = { diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/ColumnSwitchActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/ColumnSwitchActionInitializer.tsx similarity index 95% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/ColumnSwitchActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/ColumnSwitchActionInitializer.tsx index cbe74333c..6ae092298 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/ColumnSwitchActionInitializer.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/ColumnSwitchActionInitializer.tsx @@ -1,7 +1,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { ActionInitializer, useRequest } from '@nocobase/client'; import { Radio } from 'antd'; -import { PdfIsDoubleContext } from '../hooks/usePdfPath'; +import { PdfIsDoubleContext } from '../../hooks/usePdfPath'; export const ColumnSwitchAction = (props) => { const [value, setValue] = useState('0'); diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/PDFViewerPrintActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/PDFViewerPrintActionInitializer.tsx similarity index 100% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/PDFViewerPrintActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/PDFViewerPrintActionInitializer.tsx diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupActionInitializer.tsx similarity index 95% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupActionInitializer.tsx index acd7e0406..ce6e25d08 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupActionInitializer.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupActionInitializer.tsx @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { ActionInitializer } from '@nocobase/client'; import { Radio, RadioChangeEvent } from 'antd'; import { useRequest } from '@nocobase/client'; -import { PdfIsLoadContext } from '../hooks/usePdfPath'; +import { PdfIsLoadContext } from '../../hooks/usePdfPath'; export const PrintSetup = (props) => { const [value, setValue] = useState(''); const settingsData = useRequest({ diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupMargingTopInitializer.tsx similarity index 96% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupMargingTopInitializer.tsx index 132aac202..33523091a 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/RecordPrintSetupMargingTopInitializer.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/RecordPrintSetupMargingTopInitializer.tsx @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useState } from 'react'; import { ActionInitializer, useAPIClient } from '@nocobase/client'; import { Input } from 'antd'; import { useRequest } from '@nocobase/client'; -import { PdfMargingTopContext } from '../hooks/usePdfPath'; +import { PdfMargingTopContext } from '../../hooks/usePdfPath'; import { debounce } from 'lodash'; import { useCurrentUserContext } from '@nocobase/client'; export const PrintSetupMargingTop = (props) => { diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementExcelExportActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementExcelExportActionInitializer.tsx similarity index 100% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementExcelExportActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementExcelExportActionInitializer.tsx diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementExportExcel.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementExportExcel.tsx similarity index 99% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementExportExcel.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementExportExcel.tsx index dd3b45989..38c765d82 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementExportExcel.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementExportExcel.tsx @@ -1,9 +1,9 @@ import ExcelJS from 'exceljs'; import { saveAs } from 'file-saver'; import * as QRCode from 'qrcode'; -import { RecordCategory, PromptText, Itemcategory, AddItemsCategory } from '../../utils/constants'; -import { converDate } from '../../utils/daysUtils'; -import { formatPercent } from '../../utils/currencyUtils'; +import { RecordCategory, PromptText, Itemcategory, AddItemsCategory } from '../../../utils/constants'; +import { converDate } from '../../../utils/daysUtils'; +import { formatPercent } from '../../../utils/currencyUtils'; import { message } from 'antd'; export const excelDataHandle = (excelData) => { diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementStyleSwitchActionInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementStyleSwitchActionInitializer.tsx similarity index 100% rename from packages/plugins/@hera/plugin-rental/src/client/schema-initializer/SettlementStyleSwitchActionInitializer.tsx rename to packages/plugins/@hera/plugin-rental/src/client/schema-initializer/actions/SettlementStyleSwitchActionInitializer.tsx diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx new file mode 100644 index 000000000..c33a8e502 --- /dev/null +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx @@ -0,0 +1,80 @@ +import React from 'react'; +import { + Application, + SchemaInitializerItem, + SchemaSettings, + SchemaToolbar, + useSchemaInitializer, + useSchemaInitializerItem, +} from '@nocobase/client'; +import { useFieldSchema } from '@formily/react'; +import { ToolOutlined } from '@ant-design/icons'; + +export class UnusedRecordsBlockHelper { + constructor(private app: Application) {} + async load() { + this.app.schemaSettingsManager.add(unusedRecordsBlockSettings); + this.app.schemaInitializerManager.get('page:addBlock').add('otherBlocks.unusedRecords', { + name: 'unusedRecords', + title: 'unusedRecords', + Component: UnusedRecordsBlockInitializer.displayName, + }); + this.app.addComponents({ + UnusedRecordsBlock, + UnusedRecordsBlockInitializer, + UnusedRecordsBlockToolbar, + }); + } +} + +export const UnusedRecordsBlock: React.FC = () => { + return
没使用的单号
; +}; + +UnusedRecordsBlock.displayName = 'UnusedRecordsBlock'; + +export const UnusedRecordsBlockInitializer: React.FC = () => { + const { insert } = useSchemaInitializer(); + const itemConfig = useSchemaInitializerItem(); + return ( + } + onClick={() => { + insert({ + type: 'void', + 'x-toolbar': 'UnusedRecordsBlockToolbar', + 'x-settings': 'unusedRecordsBlockSettings', + 'x-component': 'CardItem', + properties: { + viewer: { + type: 'void', + 'x-component': 'UnusedRecordsBlock', + }, + }, + }); + }} + /> + ); +}; +UnusedRecordsBlockInitializer.displayName = 'UnusedRecordsBlockInitializer'; + +export const unusedRecordsBlockSettings = new SchemaSettings({ + name: 'unusedRecordsBlockSettings', + items: [ + { + name: 'remove', + type: 'remove', + componentProps: { + removeParentsIfNoChildren: true, + }, + }, + ], +}); + +export const UnusedRecordsBlockToolbar: React.FC = (props) => { + const fieldSchema = useFieldSchema(); + return ; +}; + +UnusedRecordsBlockToolbar.displayName = 'UnusedRecordsBlockToolbar'; From 23e387caf2a1a3cd45ae44a592eeee46f184c06e Mon Sep 17 00:00:00 2001 From: sealday Date: Wed, 20 Mar 2024 18:48:42 +0800 Subject: [PATCH 2/3] feat: support api --- .../src/server/actions/records-controller.ts | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts index 4c22732a5..68f936039 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts @@ -5,7 +5,8 @@ import { SystemSettingService, SqlLoader } from '@hera/plugin-core'; import { Action, Controller, Inject } from '@nocobase/utils'; import { Movement } from '../../utils/constants'; import _ from 'lodash'; -import { FilterParser } from '@nocobase/database'; +import { FilterParser, Repository } from '@nocobase/database'; +import { CollectionRepository } from '@nocobase/plugin-collection-manager'; @Controller('records') export class RecordPreviewController { @Inject(() => SqlLoader) @@ -195,4 +196,30 @@ export class RecordPreviewController { const double = isDouble === '0' || isDouble === '1' ? isDouble : pdfExplain[0].record_columns; ctx.body = await this.recordPdfService.transformPdfV2(record, leaseData, feeData, { isDouble: double, printSetup }); } + + @Action('unused_records') + async unusedRecords(ctx: Context) { + const repo = ctx.db.getRepository('collections'); + const record = await repo.findOne({ filter: { name: 'records' }, appends: ['fields'] }); + const numberField = record.fields.find((field) => field.name === 'number'); + const seqRepo = ctx.db.getRepository('sequences'); + const sequence = await seqRepo.findOne({ + filter: { + collection: 'records', + field: 'number', + key: numberField.options.patterns[0].options.key, + }, + }); + const current = sequence.current; + // 找从 200000 到 current 中有哪个没有的 + const recordsRepo = ctx.db.getRepository('records'); + const records = await recordsRepo.find({ + fields: ['number'], + }); + const shouldBe = Array(current - 200001) + .fill(0) + .map((_, i) => 200001 + i); + const numbers = records.map((record) => Number(record.number)); + ctx.body = _.difference(shouldBe, numbers); + } } From 70d8b2cfef250fd94a342a44110487dceca2a50f Mon Sep 17 00:00:00 2001 From: sealday Date: Wed, 20 Mar 2024 18:57:38 +0800 Subject: [PATCH 3/3] feat: support unused number --- .../blocks/UnusedRecordsBlockInitializer.tsx | 5 ++++- .../plugin-rental/src/server/actions/records-controller.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx index c33a8e502..17609a950 100644 --- a/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx +++ b/packages/plugins/@hera/plugin-rental/src/client/schema-initializer/blocks/UnusedRecordsBlockInitializer.tsx @@ -4,11 +4,13 @@ import { SchemaInitializerItem, SchemaSettings, SchemaToolbar, + useRequest, useSchemaInitializer, useSchemaInitializerItem, } from '@nocobase/client'; import { useFieldSchema } from '@formily/react'; import { ToolOutlined } from '@ant-design/icons'; +import { Tag } from 'antd'; export class UnusedRecordsBlockHelper { constructor(private app: Application) {} @@ -28,7 +30,8 @@ export class UnusedRecordsBlockHelper { } export const UnusedRecordsBlock: React.FC = () => { - return
没使用的单号
; + const { data } = useRequest({ resource: 'records', action: 'unused' }); + return
{data?.data?.map((number) => {number})}
; }; UnusedRecordsBlock.displayName = 'UnusedRecordsBlock'; diff --git a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts index 68f936039..3410850b4 100644 --- a/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts +++ b/packages/plugins/@hera/plugin-rental/src/server/actions/records-controller.ts @@ -197,7 +197,7 @@ export class RecordPreviewController { ctx.body = await this.recordPdfService.transformPdfV2(record, leaseData, feeData, { isDouble: double, printSetup }); } - @Action('unused_records') + @Action('unused') async unusedRecords(ctx: Context) { const repo = ctx.db.getRepository('collections'); const record = await repo.findOne({ filter: { name: 'records' }, appends: ['fields'] });