Merge pull request 'feat: 支持查询没有利用的单号' (#442) from feat_not_used_numbers into @hera/dev
Reviewed-on: daoyoucloud/tachycode#442
This commit is contained in:
commit
5deae2d569
@ -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,
|
||||
|
@ -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' });
|
||||
}
|
||||
|
@ -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 = {
|
@ -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');
|
@ -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<any>({
|
@ -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) => {
|
@ -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) => {
|
@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Application,
|
||||
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) {}
|
||||
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 = () => {
|
||||
const { data } = useRequest<any>({ resource: 'records', action: 'unused' });
|
||||
return <div>{data?.data?.map((number) => <Tag key={number}>{number}</Tag>)}</div>;
|
||||
};
|
||||
|
||||
UnusedRecordsBlock.displayName = 'UnusedRecordsBlock';
|
||||
|
||||
export const UnusedRecordsBlockInitializer: React.FC = () => {
|
||||
const { insert } = useSchemaInitializer();
|
||||
const itemConfig = useSchemaInitializerItem();
|
||||
return (
|
||||
<SchemaInitializerItem
|
||||
{...itemConfig}
|
||||
icon={<ToolOutlined />}
|
||||
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 <SchemaToolbar title={fieldSchema.title} settings={fieldSchema['x-settings']} {...props} />;
|
||||
};
|
||||
|
||||
UnusedRecordsBlockToolbar.displayName = 'UnusedRecordsBlockToolbar';
|
@ -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')
|
||||
async unusedRecords(ctx: Context) {
|
||||
const repo = ctx.db.getRepository<CollectionRepository>('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<Repository>('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<Repository>('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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user