From d2df9cb0f18f652a43c7fe6ac380a836a7f29f06 Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Fri, 11 Apr 2025 18:06:55 +0800 Subject: [PATCH 1/6] update form --- .../flow/components/FlowContent.tsx | 8 +- .../flow/components/FlowFormOpinion.tsx | 6 +- .../components/flow/components/FlowPage.tsx | 12 +- .../flow/domain/FlowEventContext.ts | 21 +- mobile-ui/src/components/flow/types.ts | 4 +- mobile-ui/src/components/flow/view/index.tsx | 6 +- mobile-ui/src/components/form/common.tsx | 8 +- .../components/form/domain/FormInstance.tsx | 323 ++++++++++++++++++ mobile-ui/src/components/form/index.tsx | 302 ++-------------- mobile-ui/src/pages/levave/form.tsx | 8 +- mobile-ui/src/pages/person/education/form.tsx | 41 ++- mobile-ui/src/pages/test/index.tsx | 129 +++---- 12 files changed, 472 insertions(+), 396 deletions(-) create mode 100644 mobile-ui/src/components/form/domain/FormInstance.tsx diff --git a/mobile-ui/src/components/flow/components/FlowContent.tsx b/mobile-ui/src/components/flow/components/FlowContent.tsx index 47c5d70c..0949d166 100644 --- a/mobile-ui/src/components/flow/components/FlowContent.tsx +++ b/mobile-ui/src/components/flow/components/FlowContent.tsx @@ -14,7 +14,7 @@ const FlowContent= () => { const flowViewReactContext = useContext(FlowViewReactContext); const flowRecordContext = flowViewReactContext?.flowRecordContext; - const formAction = flowViewReactContext?.formAction; + const formInstance = flowViewReactContext?.formInstance; const FlowFormView = flowRecordContext?.getFlowFormView() as React.ComponentType; @@ -27,7 +27,7 @@ const FlowContent= () => { useEffect(() => { if(!flowRecordContext?.isEditable()){ setTimeout(()=>{ - formAction?.current?.disableAll(); + formInstance?.disableAll(); },100); } }, []); @@ -37,10 +37,10 @@ const FlowContent= () => {
- {formAction && ( + {formInstance && ( )} diff --git a/mobile-ui/src/components/flow/components/FlowFormOpinion.tsx b/mobile-ui/src/components/flow/components/FlowFormOpinion.tsx index d70537f4..fe300015 100644 --- a/mobile-ui/src/components/flow/components/FlowFormOpinion.tsx +++ b/mobile-ui/src/components/flow/components/FlowFormOpinion.tsx @@ -6,17 +6,17 @@ import {FlowViewReactContext} from "@/components/flow/view"; const FlowFormOpinion = ()=>{ const flowViewReactContext = useContext(FlowViewReactContext); - const opinionAction = flowViewReactContext?.opinionAction; + const opinionInstance = flowViewReactContext?.opinionInstance; const flowRecordContext = flowViewReactContext?.flowRecordContext; useEffect(() => { - opinionAction?.current?.setFieldValue("advice", flowRecordContext?.getOpinionAdvice()); + opinionInstance?.setFieldValue("advice", flowRecordContext?.getOpinionAdvice()); }, []); return ( <>
{ return [ { diff --git a/mobile-ui/src/components/flow/components/FlowPage.tsx b/mobile-ui/src/components/flow/components/FlowPage.tsx index 8ed6bc9b..acf4c9c5 100644 --- a/mobile-ui/src/components/flow/components/FlowPage.tsx +++ b/mobile-ui/src/components/flow/components/FlowPage.tsx @@ -10,7 +10,7 @@ import { import {useDispatch, useSelector} from "react-redux"; import {FlowReduxState, updateState} from "@/components/flow/store/FlowSlice"; import {FlowRecordContext} from "@/components/flow/domain/FlowRecordContext"; -import {FormAction} from "@/components/form"; +import Form from "@/components/form"; import {FlowStateContext} from "@/components/flow/domain/FlowStateContext"; import {FlowEventContext} from "@/components/flow/domain/FlowEventContext"; import FlowResult from "@/components/flow/components/FlowResult"; @@ -34,8 +34,8 @@ const FlowPage: React.FC = (props) => { const currentState = useSelector((state: FlowReduxState) => state.flow); const flowRecordContext = new FlowRecordContext(props, props.flowData); - const formAction = React.useRef(null); - const opinionAction = React.useRef(null); + const formInstance = Form.useForm(); + const opinionInstance = Form.useForm(); const flowStateContext = new FlowStateContext(currentState, (state: any) => { dispatch(updateState({ @@ -43,7 +43,7 @@ const FlowPage: React.FC = (props) => { })); }); const flowTriggerContext = new FlowTriggerContext(); - const flowEvenContext = new FlowEventContext(flowRecordContext, flowTriggerContext, formAction, opinionAction, flowStateContext); + const flowEvenContext = new FlowEventContext(flowRecordContext, flowTriggerContext, formInstance, opinionInstance, flowStateContext); const flowButtonClickContext = new FlowButtonClickContext(flowEvenContext, flowStateContext); const FlowFormView = flowRecordContext.getFlowFormView() as React.ComponentType; @@ -70,8 +70,8 @@ const FlowPage: React.FC = (props) => { flowTriggerContext: flowTriggerContext, flowButtonClickContext: flowButtonClickContext, - formAction: formAction, - opinionAction: opinionAction + formInstance: formInstance, + opinionInstance: opinionInstance }}>
{currentState.result && ( diff --git a/mobile-ui/src/components/flow/domain/FlowEventContext.ts b/mobile-ui/src/components/flow/domain/FlowEventContext.ts index 71f0f0b7..2abeda57 100644 --- a/mobile-ui/src/components/flow/domain/FlowEventContext.ts +++ b/mobile-ui/src/components/flow/domain/FlowEventContext.ts @@ -7,6 +7,7 @@ import {FlowUser} from "@/components/flow/types"; import {FlowSubmitResultParser} from "@/components/flow/domain/FlowResultParser"; import {UserSelectMode} from "@/components/flow/store/FlowSlice"; import {FlowTriggerContext} from "@/components/flow/domain/FlowTriggerContext"; +import FormInstance from "@/components/form/domain/FormInstance"; /** * 流程的事件控制上下文对象 @@ -15,28 +16,28 @@ export class FlowEventContext { private readonly flowRecordContext: FlowRecordContext; private readonly flowTriggerContext: FlowTriggerContext; - private readonly flowAction: React.RefObject; - private readonly opinionAction: React.RefObject; + private readonly flowInstance: FormInstance; + private readonly opinionInstance: FormInstance; private readonly flowStateContext: FlowStateContext; constructor(flowViewContext: FlowRecordContext, flowTriggerContext:FlowTriggerContext, - flowAction: React.RefObject, - opinionAction: React.RefObject, + flowInstance: FormInstance, + opinionInstance: FormInstance, flowStateContext: FlowStateContext) { this.flowRecordContext = flowViewContext; this.flowTriggerContext = flowTriggerContext; - this.flowAction = flowAction; - this.opinionAction = opinionAction; + this.flowInstance = flowInstance; + this.opinionInstance = opinionInstance; this.flowStateContext = flowStateContext; } private getRequestBody = () => { - const formData = this.flowAction.current?.getFieldsValue(); + const formData = this.opinionInstance.getFieldsValue(); const flowData = this.flowRecordContext.getFlowFormParams(); const workCode = this.flowRecordContext.getWorkCode(); const recordId = this.flowStateContext.getRecordId(); - const advice = this.opinionAction.current?.getFieldsValue(); + const advice = this.opinionInstance.getFieldsValue(); return { recordId, @@ -51,8 +52,8 @@ export class FlowEventContext { private validateForm = async () => { - const formState = await this.flowAction.current?.validate(); - const opinionState = await this.opinionAction.current?.validate(); + const formState = await this.flowInstance.validate(); + const opinionState = await this.opinionInstance.validate(); return formState && opinionState; } diff --git a/mobile-ui/src/components/flow/types.ts b/mobile-ui/src/components/flow/types.ts index 4878a57f..64d066a9 100644 --- a/mobile-ui/src/components/flow/types.ts +++ b/mobile-ui/src/components/flow/types.ts @@ -1,5 +1,5 @@ import React from "react"; -import {FormAction} from "@/components/form"; +import FormInstance from "@/components/form/domain/FormInstance"; // 流程图中线的类型 @@ -106,7 +106,7 @@ export interface FlowFormViewProps { // 表单数据 data: FlowFormParams; // 表单控制对象 - formAction: React.RefObject; + form: FormInstance; // 数据版本 dataVersion?: number; } diff --git a/mobile-ui/src/components/flow/view/index.tsx b/mobile-ui/src/components/flow/view/index.tsx index 986a5be3..2cdd5cf5 100644 --- a/mobile-ui/src/components/flow/view/index.tsx +++ b/mobile-ui/src/components/flow/view/index.tsx @@ -6,12 +6,12 @@ import {Skeleton} from "antd-mobile"; import {FlowRecordContext} from "@/components/flow/domain/FlowRecordContext"; import {FlowEventContext} from "@/components/flow/domain/FlowEventContext"; import {detail} from "@/api/flow"; -import {FormAction} from "@/components/form"; import {FlowStateContext} from "@/components/flow/domain/FlowStateContext"; import FlowPage from "@/components/flow/components/FlowPage"; import {FlowTriggerContext} from "@/components/flow/domain/FlowTriggerContext"; import {FlowButtonClickContext} from "@/components/flow/domain/FlowButtonClickContext"; import "./index.scss"; +import FormInstance from "@/components/form/domain/FormInstance"; // 流程视图上下文属性 interface FlowViewReactContextProps { @@ -26,9 +26,9 @@ interface FlowViewReactContextProps { // 流程按钮点击触发控制器上下文对象 flowButtonClickContext: FlowButtonClickContext; // 表单操作对象 - formAction: React.RefObject; + formInstance: FormInstance; // 审批意见操作对象 - opinionAction: React.RefObject; + opinionInstance: FormInstance; } export const FlowViewReactContext = createContext(null); diff --git a/mobile-ui/src/components/form/common.tsx b/mobile-ui/src/components/form/common.tsx index eee2e5bd..8f707c25 100644 --- a/mobile-ui/src/components/form/common.tsx +++ b/mobile-ui/src/components/form/common.tsx @@ -4,8 +4,8 @@ import {FormItemProps} from "@/components/form/types"; const formFieldInit = (props: FormItemProps,reloadOption?:()=>void) => { const formContext = React.useContext(FormContext) || undefined; - const formAction = formContext?.formAction; - const validateContext = formContext?.validateContext; + const formAction = formContext?.getFormAction(); + const validateContext = formContext?.getFormValidateContext(); const [random, setRandom] = React.useState(0); const rules= props.required?[{required: true}]:[]; @@ -20,14 +20,14 @@ const formFieldInit = (props: FormItemProps,reloadOption?:()=>void) => { } } } - const reloadContext = formContext?.reloadContext; + const reloadContext = formContext?.getFormFieldReloadListenerContext(); if (reloadContext) { reloadContext.addListener(props.name, () => { setRandom(Math.random); }); } - const optionContext = formContext?.optionContext; + const optionContext = formContext?.getFormFieldOptionListenerContext(); if (optionContext) { optionContext.addListener(props.name, () => { if(reloadOption){ diff --git a/mobile-ui/src/components/form/domain/FormInstance.tsx b/mobile-ui/src/components/form/domain/FormInstance.tsx new file mode 100644 index 00000000..475768e3 --- /dev/null +++ b/mobile-ui/src/components/form/domain/FormInstance.tsx @@ -0,0 +1,323 @@ +import {FormValidateContext} from "@/components/form/validate"; +import {FormFieldOptionListenerContext, FormFieldReloadListenerContext} from "@/components/form/listener"; +import {FormInstance as MobileFormInstance} from "rc-field-form/es/interface"; +import {FormField} from "@/components/form/types"; +import {NamePath} from "antd-mobile/es/components/form"; +import {Form as MobileForm, Toast} from "antd-mobile"; +import {FiledData, FormAction} from "@/components/form"; +import React from "react"; + +class FormInstance { + private readonly validateContext: FormValidateContext; + private readonly reloadContext: FormFieldReloadListenerContext; + private readonly optionContext: FormFieldOptionListenerContext; + private readonly formInstance: MobileFormInstance; + private readonly formAction: FormAction; + private fields: FormField[]; + + private fieldsUpdateDispatch: React.Dispatch> | undefined; + + public setFieldsUpdateDispatch = (fieldsUpdateDispatch: React.Dispatch>) => { + this.fieldsUpdateDispatch = fieldsUpdateDispatch; + } + + private updateFields = (resetFields:(prevState: FormField[]) => FormField[]) => { + this.fields = resetFields(this.fields); + if (this.fieldsUpdateDispatch) { + this.fieldsUpdateDispatch(resetFields); + } + } + + private namePathEqual = (name1: NamePath, name2: NamePath) => { + if (Array.isArray(name1) && Array.isArray(name2)) { + if (name1.length !== name2.length) { + return false; + } + for (let i = 0; i < name1.length; i++) { + if (name1[i] !== name2[i]) { + return false; + } + } + return true; + } + return name1 === name2; + } + + public submit = async () => { + const res = await this.validateContext.validate(this.formAction); + if (res) { + this.formInstance.submit(); + } + } + + public reset = (values?: any) => { + this.formInstance.resetFields(); + if (values) { + this.formInstance.setFieldsValue(values); + this.reloadContext.notifyAll(); + } + } + + public hidden = (name: NamePath) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + if (this.namePathEqual(field.props.name, name)) { + return { + ...field, + props: { + ...field.props, + hidden: true, + required: false + } + } + } + return field; + })); + this.validateContext.clear(); + } + + public required = (name: NamePath, required: boolean) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + if (this.namePathEqual(field.props.name,name)) { + return { + ...field, + props: { + ...field.props, + required: required + } + } + } + return field; + })); + this.validateContext.clear(); + } + + public show = (name: NamePath) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + if (this.namePathEqual(field.props.name,name)) { + return { + ...field, + props: { + ...field.props, + hidden: false + } + } + } + return field; + })); + this.validateContext.clear(); + } + + public disable = (name: NamePath) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + if (this.namePathEqual(field.props.name,name)) { + return { + ...field, + props: { + ...field.props, + disabled: true + } + } + } + return field; + })); + this.validateContext.clear(); + } + + public disableAll = () => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + return { + ...field, + props: { + ...field.props, + disabled: true + } + } + })); + this.validateContext.clear(); + } + + public enable = (name: NamePath) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + if (this.namePathEqual(field.props.name,name)) { + return { + ...field, + props: { + ...field.props, + disabled: false + } + } + } + return field; + })); + this.validateContext.clear(); + } + + public enableAll = () => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.map((field) => { + return { + ...field, + props: { + ...field.props, + disabled: false + } + } + })); + this.validateContext.clear(); + } + + public remove = (name: NamePath) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => prevFields.filter((field) => !this.namePathEqual(field.props.name,name))); + this.validateContext.clear(); + } + + public create = (field: FormField, index?: number) => { + if (this.fields.length == 0) { + Toast.show('表单项未加载'); + return; + } + this.updateFields(prevFields => { + const filteredFields = prevFields.filter((item) => item.props.name !== field.props.name); + if (index === undefined || index < 0) { + return [...filteredFields, field]; + } else { + const newFields = [...filteredFields]; + newFields.splice(index, 0, field); + return newFields; + } + }); + this.validateContext.clear(); + } + + public getFieldValue = (name: NamePath) => { + return this.formInstance.getFieldValue(name); + } + + public getFieldsValue = () => { + return this.formInstance.getFieldsValue(); + } + + public getFieldProps = (name: NamePath) => { + for (const field of this.fields) { + if (this.namePathEqual(field.props.name, name)) { + return field; + } + } + return null; + } + + public reloadOptions = (name: NamePath) => { + this.optionContext.notify(name); + } + + public reloadAllOptions = () => { + this.optionContext.notifyAll(); + } + + public setFieldValue = (name: NamePath, value: any) => { + this.formInstance.setFieldValue(name, value); + this.reloadContext.notify(name); + this.validateContext?.validateField(name, this.formAction); + } + + public setFieldsValue = (values: any) => { + this.formInstance.setFieldsValue(values); + this.reloadContext.notifyAll(); + } + + public setFields = (fields: FiledData[]) => { + this.formInstance.setFields(fields); + } + + public validate = () => { + return this.validateContext.validate(this.formAction); + } + + public resetFields = (fields:FormField[]) => { + this.fields = fields; + } + + constructor() { + this.validateContext = new FormValidateContext(); + this.reloadContext = new FormFieldReloadListenerContext(); + this.optionContext = new FormFieldOptionListenerContext(); + this.formInstance = MobileForm.useForm()[0]; + this.fields = []; + this.formAction = { + submit: this.submit, + reset: this.reset, + hidden: this.hidden, + show: this.show, + remove: this.remove, + create: this.create, + disable: this.disable, + disableAll: this.disableAll, + enable: this.enable, + enableAll: this.enableAll, + required: this.required, + getFieldValue: this.getFieldValue, + getFieldsValue: this.getFieldsValue, + getFieldProps: this.getFieldProps, + reloadOptions: this.reloadOptions, + reloadAllOptions: this.reloadAllOptions, + setFieldValue: this.setFieldValue, + setFieldsValue: this.setFieldsValue, + setFields: this.setFields, + validate: this.validate, + } + } + + public getFormAction = () => { + return this.formAction; + } + + public getFormValidateContext = () => { + return this.validateContext; + } + + public getFormFieldReloadListenerContext = () => { + return this.reloadContext; + } + + public getFormFieldOptionListenerContext = () => { + return this.optionContext; + } + + public getFormControlInstance = ():MobileFormInstance => { + return this.formInstance; + } + +} + +export default FormInstance; diff --git a/mobile-ui/src/components/form/index.tsx b/mobile-ui/src/components/form/index.tsx index 65f22379..123c4d50 100644 --- a/mobile-ui/src/components/form/index.tsx +++ b/mobile-ui/src/components/form/index.tsx @@ -1,11 +1,10 @@ import React, {useEffect} from "react"; -import {Form as MobileForm, Toast} from "antd-mobile"; +import {Form as MobileForm} from "antd-mobile"; import FormFactory from "@/components/form/factory"; import {FormField} from "@/components/form/types"; -import {FormValidateContext} from "@/components/form/validate"; import {NamePath} from "antd-mobile/es/components/form"; -import {FormFieldOptionListenerContext, FormFieldReloadListenerContext} from "@/components/form/listener"; import "./form.scss"; +import FormInstance from "@/components/form/domain/FormInstance"; export interface FiledData { name: NamePath; @@ -60,8 +59,6 @@ export interface FormProps { loadFields?: ()=>Promise; // 表单提交事件 onFinish?: (values: any) => Promise; - // 表单控制对象 - actionRef?: React.Ref; // form布局,默认vertical layout?: 'horizontal' | 'vertical'; // children元素 @@ -70,283 +67,29 @@ export interface FormProps { footer?: React.ReactNode; // 初始化值 initialValues?: any; + // 表单控制对象 + actionRef?: React.Ref; + // 表单实例 + form?: FormInstance; } -interface FormContextProps { - // form表单的控制对象 - formAction: FormAction; - // 检验控制对象 - validateContext: FormValidateContext; - // 表单刷新监听对象 - reloadContext:FormFieldReloadListenerContext; - // 选项刷新监听对象 - optionContext:FormFieldOptionListenerContext; -} - -export const FormContext = React.createContext(null); - - -const namePathEqual = (name1: NamePath, name2: NamePath): boolean => { - if (Array.isArray(name1) && Array.isArray(name2)) { - if (name1.length !== name2.length) { - return false; - } - for (let i = 0; i < name1.length; i++) { - if (name1[i] !== name2[i]) { - return false; - } - } - return true; - } - return name1 === name2; -} - - -const Form: React.FC = (props) => { - - const [form] = MobileForm.useForm(); - - const validateContext = new FormValidateContext(); - const reloadContext = new FormFieldReloadListenerContext(); - const optionContext = new FormFieldOptionListenerContext(); - - const formAction = { - submit: async () => { - const res = await validateContext.validate(formAction); - if (res) { - form.submit(); - } - }, - - reset: (values?: any) => { - reloadFields(); - form.resetFields(); - if (values) { - form.setFieldsValue(values); - reloadContext.notifyAll(); - } - }, - - hidden: (name: NamePath) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - if (namePathEqual(field.props.name,name)) { - return { - ...field, - props: { - ...field.props, - hidden: true, - required: false - } - } - } - return field; - })); - validateContext.clear(); - }, - - required:(name: NamePath,required:boolean) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - if (namePathEqual(field.props.name,name)) { - return { - ...field, - props: { - ...field.props, - required: required - } - } - } - return field; - })); - validateContext.clear(); - }, - - show: (name: NamePath) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - if (namePathEqual(field.props.name,name)) { - return { - ...field, - props: { - ...field.props, - hidden: false - } - } - } - return field; - })); - validateContext.clear(); - }, - disable: (name: NamePath) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - if (namePathEqual(field.props.name,name)) { - return { - ...field, - props: { - ...field.props, - disabled: true - } - } - } - return field; - })); - validateContext.clear(); - }, +export const FormContext = React.createContext(null); - disableAll:()=>{ - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - return { - ...field, - props: { - ...field.props, - disabled: true - } - } - })); - validateContext.clear(); - }, +const FormComponent: React.FC = (props) => { - enable: (name: NamePath) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - if (namePathEqual(field.props.name,name)) { - return { - ...field, - props: { - ...field.props, - disabled: false - } - } - } - return field; - })); - validateContext.clear(); - }, - - enableAll:()=>{ - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.map((field) => { - return { - ...field, - props: { - ...field.props, - disabled: false - } - } - })); - validateContext.clear(); - }, - - remove: (name: NamePath) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => prevFields.filter((field) => !namePathEqual(field.props.name,name))); - validateContext.clear(); - }, - - create: (field: FormField, index?: number) => { - if(fields.length==0){ - Toast.show('表单项未加载'); - return; - } - setFields(prevFields => { - const filteredFields = prevFields.filter((item) => item.props.name !== field.props.name); - if (index === undefined || index < 0) { - return [...filteredFields, field]; - } else { - const newFields = [...filteredFields]; - newFields.splice(index, 0, field); - return newFields; - } - }); - validateContext.clear(); - }, - - getFieldValue(name: NamePath): any { - return form.getFieldValue(name); - }, - - getFieldsValue(): any { - return form.getFieldsValue(); - }, - - getFieldProps(name: NamePath): FormField | null { - for (const field of fields) { - if (namePathEqual(field.props.name,name)) { - return field; - } - } - return null; - }, - - reloadOptions:(name: NamePath) => { - optionContext.notify(name); - }, - - reloadAllOptions:()=>{ - optionContext.notifyAll(); - }, - - setFieldValue(name: NamePath, value: any): void { - form.setFieldValue(name, value); - reloadContext.notify(name); - validateContext?.validateField(name, formAction); - }, - - setFieldsValue(values: any): void { - form.setFieldsValue(values); - reloadContext.notifyAll(); - }, - - setFields(fields: FiledData[]): void { - form.setFields(fields); - }, - - validate(): Promise { - return validateContext.validate(formAction); - } - } - - const formContextProps = { - formAction: formAction, - validateContext: validateContext, - reloadContext:reloadContext, - optionContext:optionContext - } + const formInstance = props.form? props.form : new FormInstance(); const [fields, setFields] = React.useState([]); + formInstance.setFieldsUpdateDispatch(setFields); + + const formControl = formInstance.getFormControlInstance() ; const reloadFields = ()=>{ if(props.loadFields){ props.loadFields().then(fields=>{ setFields(fields); + formInstance.resetFields(fields); }) } } @@ -356,16 +99,12 @@ const Form: React.FC = (props) => { }, [props.loadFields]); - React.useImperativeHandle(props.actionRef, () => { - return formAction - }, [fields]); - return ( { props.onFinish && props.onFinish(values); }} @@ -384,4 +123,15 @@ const Form: React.FC = (props) => { ) } +type FormType = typeof FormComponent; +type FormComponentType = FormType & { + useForm: ()=>FormInstance; +}; + +const Form = FormComponent as FormComponentType; +Form.useForm = ()=>{ + return new FormInstance(); +}; + export default Form; + diff --git a/mobile-ui/src/pages/levave/form.tsx b/mobile-ui/src/pages/levave/form.tsx index 47e5dabf..2041657e 100644 --- a/mobile-ui/src/pages/levave/form.tsx +++ b/mobile-ui/src/pages/levave/form.tsx @@ -6,7 +6,7 @@ import {FlowViewReactContext} from "@/components/flow/view"; import {fields} from "@/pages/levave/fields"; const LeaveForm: React.FC = (props) => { - const formAction = props.formAction; + const formInstance = props.form; const flowViewReactContext = useContext(FlowViewReactContext); console.log('LeaveForm init:', props); @@ -22,7 +22,7 @@ const LeaveForm: React.FC = (props) => { useEffect(() => { // 设置表单数据 if (props.dataVersion && props.data) { - formAction.current?.setFieldsValue({ + formInstance?.setFieldsValue({ ...props.data }); } @@ -32,7 +32,7 @@ const LeaveForm: React.FC = (props) => { return ( { return fields; }} @@ -51,7 +51,7 @@ const LeaveForm: React.FC = (props) => { margin: 5 }} onClick={async () => { - formAction.current && await formAction.current.validate(); + formInstance?.validate(); }} >校验表单 diff --git a/mobile-ui/src/pages/person/education/form.tsx b/mobile-ui/src/pages/person/education/form.tsx index 68ed493e..88187621 100644 --- a/mobile-ui/src/pages/person/education/form.tsx +++ b/mobile-ui/src/pages/person/education/form.tsx @@ -5,7 +5,7 @@ import BasicInfo from "@/components/info/BasicInfo"; import FormInfo from "@/components/info/FormInfo"; import {Button, Toast} from "antd-mobile"; import {loadFields} from "@/pages/person/education/fields"; -import {FormAction} from "@/components/form"; +import Form from "@/components/form"; import {Grid} from "antd-mobile/es/components/grid/grid"; const EducationForm = () => { @@ -13,7 +13,7 @@ const EducationForm = () => { const item = location.state; // console.log('items:', item); - const formAction = React.useRef(null); + const formInstance = Form.useForm(); const [state,setState] = React.useState({ name:"", @@ -22,12 +22,11 @@ const EducationForm = () => { return ( <> -
教育信息维护 {state.name} | {state.age}
{ return loadFields(state,setState); @@ -40,89 +39,89 @@ const EducationForm = () => { - + const formInstance = Form.useForm(); - ) -} - -const Test = () => { - const value = 'Hello, Context!'; - - const childAction = React.useRef(null); return ( - - -
- { - console.log(values); - }} - /> -
- - +
+ + { + setVisible(false) }} - >test - - + closeOnAction={true} + content={( + { + return fields + }} + /> + )} + /> +
) } From cfdab9c1d2f1e648f0589eb5ea7a0f93bbd30006 Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Mon, 14 Apr 2025 10:04:59 +0800 Subject: [PATCH 2/6] remove application --- .../app/cmd/domain/router/UserRouter.java | 35 +++++++++- .../example-app/example-app-cmd-meta/pom.xml | 12 ++++ .../example/app/cmd/meta/pojo}/FlowCmd.java | 2 +- .../app/cmd/meta/pojo}/FlowWorkCmd.java | 2 +- .../app/cmd/meta/service}/FlowWorkRouter.java | 17 +++-- example/example-application/pom.xml | 66 ------------------- .../example/command/UserCmdController.java | 51 -------------- .../codingapi/example/handler/AHandler.java | 21 ------ .../codingapi/example/handler/BHandler.java | 21 ------ .../codingapi/example/handler/CHandler.java | 28 -------- .../example/handler/GlobalEventHandler.java | 16 ----- .../example/handler/MyLeaveHandler.java | 14 ---- .../example/handler/Test2Handler.java | 37 ----------- .../example/handler/TestHandler.java | 36 ---------- .../codingapi/example/pojo/cmd/LeaveCmd.java | 21 ------ .../codingapi/example/pojo/cmd/UserCmd.java | 26 -------- .../codingapi/example/router/UserRouter.java | 63 ------------------ .../example/domain/user/entity/User.java | 7 ++ .../example-infra/example-infra-flow/pom.xml | 12 ---- .../infra/flow/AutoFlowConfiguration.java} | 12 +--- .../infra/flow/user/FlowUserRepository.java | 5 ++ .../infra/db/AutoDomainConfiguration.java | 17 +++++ .../api/domain/UserDomainCmdController.java | 28 +++++++- .../api/meta}/FlowRecordCmdController.java | 34 +++++----- .../api/meta}/FlowWorkCmdController.java | 6 +- .../api}/query/FlowRecordQueryController.java | 13 ++-- .../api}/query/FlowWorkQueryController.java | 6 +- .../api}/query/LeaveQueryController.java | 6 +- .../api}/query/UserQueryController.java | 6 +- .../query/app/FlowAppQueryController.java | 10 +-- .../query/app/LeaveAppQueryController.java | 6 +- .../example/handler/LeaveHandler.java | 4 +- .../codingapi/example/runner/UserRunner.java | 2 +- 33 files changed, 161 insertions(+), 481 deletions(-) rename example/{example-application/src/main/java/com/codingapi/example/pojo/cmd => example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo}/FlowCmd.java (99%) rename example/{example-application/src/main/java/com/codingapi/example/pojo/cmd => example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo}/FlowWorkCmd.java (94%) rename example/{example-application/src/main/java/com/codingapi/example/router => example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service}/FlowWorkRouter.java (81%) delete mode 100644 example/example-application/pom.xml delete mode 100644 example/example-application/src/main/java/com/codingapi/example/command/UserCmdController.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/AHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/BHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/GlobalEventHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/MyLeaveHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/Test2Handler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/handler/TestHandler.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/pojo/cmd/LeaveCmd.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/pojo/cmd/UserCmd.java delete mode 100644 example/example-application/src/main/java/com/codingapi/example/router/UserRouter.java rename example/{example-application/src/main/java/com/codingapi/example/register/ExampleAutoConfiguration.java => example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/AutoFlowConfiguration.java} (68%) create mode 100644 example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java rename example/{example-application/src/main/java/com/codingapi/example/command => example-interface/src/main/java/com/codingapi/example/api/meta}/FlowRecordCmdController.java (74%) rename example/{example-application/src/main/java/com/codingapi/example/command => example-interface/src/main/java/com/codingapi/example/api/meta}/FlowWorkCmdController.java (90%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/FlowRecordQueryController.java (92%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/FlowWorkQueryController.java (81%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/LeaveQueryController.java (81%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/UserQueryController.java (81%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/app/FlowAppQueryController.java (95%) rename example/{example-application/src/main/java/com/codingapi/example => example-interface/src/main/java/com/codingapi/example/api}/query/app/LeaveAppQueryController.java (90%) rename example/{example-application => example-interface}/src/main/java/com/codingapi/example/handler/LeaveHandler.java (83%) rename example/{example-application => example-interface}/src/main/java/com/codingapi/example/runner/UserRunner.java (88%) diff --git a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java index 087a2040..53f96654 100644 --- a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java +++ b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java @@ -14,7 +14,7 @@ public class UserRouter { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; - public void save(UserCmd.UpdateRequest request){ + public void createOrUpdate(UserCmd.UpdateRequest request){ if(request.hasId()){ User user = userRepository.getUserById(request.getId()); user.setName(request.getName()); @@ -31,4 +31,37 @@ public void save(UserCmd.UpdateRequest request){ userRepository.save(user); } } + + public void removeEntrust(long id) { + User user = userRepository.getUserById(id); + if(user!=null){ + user.removeEntrust(); + userRepository.save(user); + } + } + + public void createEntrust(UserCmd.EntrustRequest request){ + User user = userRepository.getUserById(request.getId()); + if(user!=null){ + User entrustOperator = userRepository.getUserById(request.getEntrustUserId()); + user.setEntrustOperator(entrustOperator); + userRepository.save(user); + } + } + + public void changeManager(long id){ + User user = userRepository.getUserById(id); + if(user!=null){ + user.changeManager(); + userRepository.save(user); + } + } + + public void removeUser(long id){ + User user = userRepository.getUserById(id); + if(user!=null){ + userRepository.delete(id); + } + } + } diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml index 91b9d7d9..0cf83b6c 100644 --- a/example/example-app/example-app-cmd-meta/pom.xml +++ b/example/example-app/example-app-cmd-meta/pom.xml @@ -23,6 +23,18 @@ ${project.version} + + com.codingapi.springboot + example-infra-flow + ${project.version} + + + + com.codingapi.springboot + example-infra-security + ${project.version} + + diff --git a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowCmd.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java similarity index 99% rename from example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowCmd.java rename to example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java index 9ca1b025..89a1970d 100644 --- a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowCmd.java +++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java @@ -1,4 +1,4 @@ -package com.codingapi.example.pojo.cmd; +package com.codingapi.example.app.cmd.meta.pojo; import com.alibaba.fastjson.JSONObject; import com.codingapi.springboot.flow.bind.IBindData; diff --git a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowWorkCmd.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowWorkCmd.java similarity index 94% rename from example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowWorkCmd.java rename to example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowWorkCmd.java index 1f7a108c..e9331732 100644 --- a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/FlowWorkCmd.java +++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowWorkCmd.java @@ -1,4 +1,4 @@ -package com.codingapi.example.pojo.cmd; +package com.codingapi.example.app.cmd.meta.pojo; import com.codingapi.springboot.security.gateway.TokenContext; import lombok.Getter; diff --git a/example/example-application/src/main/java/com/codingapi/example/router/FlowWorkRouter.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowWorkRouter.java similarity index 81% rename from example/example-application/src/main/java/com/codingapi/example/router/FlowWorkRouter.java rename to example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowWorkRouter.java index ff244544..68e4156a 100644 --- a/example/example-application/src/main/java/com/codingapi/example/router/FlowWorkRouter.java +++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowWorkRouter.java @@ -1,17 +1,16 @@ -package com.codingapi.example.router; +package com.codingapi.example.app.cmd.meta.service; -import com.codingapi.example.domain.User; -import com.codingapi.example.entity.FlowWorkEntity; -import com.codingapi.example.jpa.FlowWorkEntityRepository; -import com.codingapi.example.pojo.cmd.FlowWorkCmd; -import com.codingapi.example.repository.UserRepository; +import com.codingapi.example.app.cmd.meta.pojo.FlowWorkCmd; +import com.codingapi.example.infra.flow.entity.FlowWorkEntity; +import com.codingapi.example.infra.flow.jpa.FlowWorkEntityRepository; +import com.codingapi.example.infra.flow.user.FlowUserRepository; import com.codingapi.springboot.flow.domain.FlowWork; import com.codingapi.springboot.flow.repository.FlowWorkRepository; +import com.codingapi.springboot.flow.user.IFlowOperator; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - @Service @AllArgsConstructor @Transactional @@ -19,14 +18,14 @@ public class FlowWorkRouter { private final FlowWorkRepository flowWorkRepository; private final FlowWorkEntityRepository flowWorkEntityRepository; - private final UserRepository userRepository; + private final FlowUserRepository flowUserRepository; public void delete(long id) { flowWorkRepository.delete(id); } public void save(FlowWorkCmd.CreateRequest request) { - User user = userRepository.getUserByUsername(request.getUsername()); + IFlowOperator user = flowUserRepository.getUserByUsername(request.getUsername()); long id = request.getId(); if (id == 0) { FlowWork flowWork = new FlowWork( diff --git a/example/example-application/pom.xml b/example/example-application/pom.xml deleted file mode 100644 index de17a844..00000000 --- a/example/example-application/pom.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - com.codingapi.springboot - springboot-example - 3.3.67 - - 4.0.0 - - example-application - - - 17 - 17 - UTF-8 - 0.12.5 - - - - - - com.codingapi.springboot - example-domain-leave - ${project.version} - - - - com.codingapi.springboot - example-domain-user - ${project.version} - - - - com.codingapi.springboot - springboot-starter-security - ${codingapi.framework.version} - - - - io.jsonwebtoken - jjwt-api - ${jsonwebtoken.jjwt.version} - - - - io.jsonwebtoken - jjwt-impl - ${jsonwebtoken.jjwt.version} - - - - io.jsonwebtoken - jjwt-jackson - ${jsonwebtoken.jjwt.version} - - - - org.springframework.boot - spring-boot-starter-web - - - - - diff --git a/example/example-application/src/main/java/com/codingapi/example/command/UserCmdController.java b/example/example-application/src/main/java/com/codingapi/example/command/UserCmdController.java deleted file mode 100644 index d28404c4..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/command/UserCmdController.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.codingapi.example.command; - -import com.codingapi.example.pojo.cmd.UserCmd; -import com.codingapi.example.router.UserRouter; -import com.codingapi.springboot.framework.dto.request.IdRequest; -import com.codingapi.springboot.framework.dto.response.Response; -import lombok.AllArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/api/cmd/user") -@AllArgsConstructor -public class UserCmdController { - - private final UserRouter userRouter; - - @PostMapping("/save") - public Response save(@RequestBody UserCmd.UpdateRequest request) { - userRouter.save(request); - return Response.buildSuccess(); - } - - @PostMapping("/removeEntrust") - public Response removeEntrust(@RequestBody IdRequest request) { - userRouter.removeEntrust(request.getLongId()); - return Response.buildSuccess(); - } - - @PostMapping("/entrust") - public Response entrust(@RequestBody UserCmd.EntrustRequest request) { - userRouter.entrust(request); - return Response.buildSuccess(); - } - - @PostMapping("/changeManager") - public Response changeManager(@RequestBody IdRequest request) { - userRouter.changeManager(request.getLongId()); - return Response.buildSuccess(); - } - - @PostMapping("/remove") - public Response remove(@RequestBody IdRequest request) { - userRouter.remove(request.getLongId()); - return Response.buildSuccess(); - } - - -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/AHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/AHandler.java deleted file mode 100644 index 49a1d2cc..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/AHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.AEvent; -import com.codingapi.example.event.BEvent; -import com.codingapi.springboot.framework.event.EventPusher; -import com.codingapi.springboot.framework.event.EventTraceContext; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -@Slf4j -@Service -public class AHandler implements IHandler { - - @Override - public void handler(AEvent event) { - log.info("a event:{},eventKey:{}",event, EventTraceContext.getInstance().getEventKey()); - - EventPusher.push(new BEvent()); - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/BHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/BHandler.java deleted file mode 100644 index e3831bae..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/BHandler.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.BEvent; -import com.codingapi.example.event.CEvent; -import com.codingapi.springboot.framework.event.EventPusher; -import com.codingapi.springboot.framework.event.EventTraceContext; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -@Slf4j -@Service -public class BHandler implements IHandler { - - @Override - public void handler(BEvent event) { - log.info("b event:{},eventKey:{}",event, EventTraceContext.getInstance().getEventKey()); - - EventPusher.push(new CEvent()); - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java deleted file mode 100644 index 34b02124..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/CHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.AEvent; -import com.codingapi.example.event.CEvent; -import com.codingapi.springboot.framework.event.EventPusher; -import com.codingapi.springboot.framework.event.EventTraceContext; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -@Slf4j -@Service -public class CHandler implements IHandler { - - @Override - public void handler(CEvent event) { - log.info("c event:{},eventKey:{}", event, EventTraceContext.getInstance().getEventKey()); - -// EventPusher.push(new AEvent(),true); -// throw new RuntimeException("c handler error"); - } - - @Override - public void error(Exception exception) throws Exception { - log.error("c handler error:{}", exception.getMessage()); - throw exception; - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/GlobalEventHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/GlobalEventHandler.java deleted file mode 100644 index eaa77ff2..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/GlobalEventHandler.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.springboot.framework.event.IEvent; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -@Slf4j -@Service -public class GlobalEventHandler implements IHandler { - - @Override - public void handler(IEvent event) { - log.info("global event:{}", event); - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/MyLeaveHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/MyLeaveHandler.java deleted file mode 100644 index d9eaf752..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/MyLeaveHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.UserEvent; -import com.codingapi.springboot.framework.event.IHandler; -import org.springframework.stereotype.Component; - -@Component -public class MyLeaveHandler implements IHandler { - - @Override - public void handler(UserEvent event) { - - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/Test2Handler.java b/example/example-application/src/main/java/com/codingapi/example/handler/Test2Handler.java deleted file mode 100644 index b085f437..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/Test2Handler.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.AEvent; -import com.codingapi.example.event.TestEvent; -import com.codingapi.example.infra.entity.TestEntity; -import com.codingapi.example.infra.jpa.TestEntityRepository; -import com.codingapi.springboot.framework.event.EventPusher; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.AllArgsConstructor; -import org.springframework.stereotype.Repository; - -@Repository -@AllArgsConstructor -public class Test2Handler implements IHandler { - - private TestEntityRepository testEntityRepository; - - @Override - public void handler(TestEvent event) { - TestEntity entity = new TestEntity(event.getName()+"123"); - testEntityRepository.save(entity); - - new Thread(()->{ - EventPusher.push(new AEvent()); - }).start(); - -// new Thread(()->{ -// EventPusher.push(new AEvent()); -// }).start(); - } - - - @Override - public int order() { - return 100; - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/TestHandler.java b/example/example-application/src/main/java/com/codingapi/example/handler/TestHandler.java deleted file mode 100644 index de8439d3..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/handler/TestHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.codingapi.example.handler; - -import com.codingapi.example.event.AEvent; -import com.codingapi.example.event.TestEvent; -import com.codingapi.example.infra.entity.TestEntity; -import com.codingapi.example.infra.jpa.TestEntityRepository; -import com.codingapi.springboot.framework.event.EventPusher; -import com.codingapi.springboot.framework.event.IHandler; -import lombok.AllArgsConstructor; -import org.springframework.stereotype.Repository; - -@Repository -@AllArgsConstructor -public class TestHandler implements IHandler { - - private TestEntityRepository testEntityRepository; - - @Override - public void handler(TestEvent event) { - TestEntity entity = new TestEntity(event.getName()+"123"); - testEntityRepository.save(entity); - - new Thread(()->{ - EventPusher.push(new AEvent()); - }).start(); - -// new Thread(()->{ -// EventPusher.push(new AEvent()); -// }).start(); - } - - @Override - public int order() { - return 10; - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/LeaveCmd.java b/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/LeaveCmd.java deleted file mode 100644 index 9548ce79..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/LeaveCmd.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.codingapi.example.pojo.cmd; - -import com.codingapi.springboot.security.gateway.TokenContext; -import lombok.Getter; -import lombok.Setter; - -public class LeaveCmd { - - @Setter - @Getter - public static class StartLeave{ - private String desc; - private int days; - private String flowCode; - - - public String getUsername(){ - return TokenContext.current().getUsername(); - } - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/UserCmd.java b/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/UserCmd.java deleted file mode 100644 index dab1673a..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/pojo/cmd/UserCmd.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.codingapi.example.pojo.cmd; - -import lombok.Getter; -import lombok.Setter; - -public class UserCmd { - - @Setter - @Getter - public static class UpdateRequest{ - private long id; - private String name; - private String username; - private String password; - private boolean flowManager; - } - - - @Setter - @Getter - public static class EntrustRequest{ - private long id; - private long entrustUserId; - - } -} diff --git a/example/example-application/src/main/java/com/codingapi/example/router/UserRouter.java b/example/example-application/src/main/java/com/codingapi/example/router/UserRouter.java deleted file mode 100644 index a5398125..00000000 --- a/example/example-application/src/main/java/com/codingapi/example/router/UserRouter.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.codingapi.example.router; - -import com.codingapi.example.domain.User; -import com.codingapi.example.gateway.PasswordEncoder; -import com.codingapi.example.pojo.cmd.UserCmd; -import com.codingapi.example.repository.UserRepository; -import lombok.AllArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@AllArgsConstructor -public class UserRouter { - - private final UserRepository userRepository; - private final PasswordEncoder passwordEncoder; - - - public void save(UserCmd.UpdateRequest request){ - if(request.getId() ==0 ){ - User user = new User(); - user.setName(request.getName()); - user.setPassword(request.getPassword()); - user.setUsername(request.getUsername()); - user.setFlowManager(request.isFlowManager()); - user.setCreateTime(System.currentTimeMillis()); - user.encodePassword(passwordEncoder); - userRepository.save(user); - }else { - User user = userRepository.getUserById(request.getId()); - user.setName(request.getName()); - user.setPassword(request.getPassword()); - user.setUsername(request.getUsername()); - user.setFlowManager(request.isFlowManager()); - user.encodePassword(passwordEncoder); - userRepository.save(user); - } - } - - - public void entrust(UserCmd.EntrustRequest request){ - User user = userRepository.getUserById(request.getId()); - User entrustOperator = userRepository.getUserById(request.getEntrustUserId()); - user.setEntrustOperator(entrustOperator); - userRepository.save(user); - } - - public void changeManager(Long id) { - User user = userRepository.getUserById(id); - user.setFlowManager(!user.isFlowManager()); - userRepository.save(user); - } - - - public void removeEntrust(Long id) { - User user = userRepository.getUserById(id); - user.setEntrustOperator(null); - userRepository.save(user); - } - - public void remove(Long id) { - userRepository.delete(id); - } -} diff --git a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java index 84f60f96..287f1219 100644 --- a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java +++ b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java @@ -34,6 +34,13 @@ public static User admin(PasswordEncoder passwordEncoder) { return user; } + public void removeEntrust() { + this.entrustOperator = null; + } + + public void changeManager() { + this.isFlowManager = !this.isFlowManager; + } public void encodePassword(PasswordEncoder passwordEncoder) { this.password = passwordEncoder.encode(this.password); diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml index 6cb69d98..b9c6af79 100644 --- a/example/example-infra/example-infra-flow/pom.xml +++ b/example/example-infra/example-infra-flow/pom.xml @@ -18,18 +18,6 @@ - - com.codingapi.springboot - example-domain-user - ${project.version} - - - - com.codingapi.springboot - example-domain-leave - ${project.version} - - com.codingapi.springboot springboot-starter-flow diff --git a/example/example-application/src/main/java/com/codingapi/example/register/ExampleAutoConfiguration.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/AutoFlowConfiguration.java similarity index 68% rename from example/example-application/src/main/java/com/codingapi/example/register/ExampleAutoConfiguration.java rename to example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/AutoFlowConfiguration.java index e62cff54..57e5383e 100644 --- a/example/example-application/src/main/java/com/codingapi/example/register/ExampleAutoConfiguration.java +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/AutoFlowConfiguration.java @@ -1,20 +1,12 @@ -package com.codingapi.example.register; +package com.codingapi.example.infra.flow; -import com.codingapi.example.gateway.PasswordEncoder; -import com.codingapi.example.repository.UserRepository; -import com.codingapi.example.service.UserService; import com.codingapi.springboot.flow.repository.*; import com.codingapi.springboot.flow.service.FlowService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class ExampleAutoConfiguration { - - @Bean - public UserService userService(UserRepository userRepository, PasswordEncoder passwordEncoder) { - return new UserService(userRepository, passwordEncoder); - } +public class AutoFlowConfiguration { @Bean public FlowService flowService(FlowWorkRepository flowWorkRepository, diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java index 507716ce..4249cb29 100644 --- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java @@ -23,4 +23,9 @@ public List findByIds(List ids) { public IFlowOperator getFlowOperatorById(long id) { return new FlowUser(userRepository.getUserById(id)); } + + + public IFlowOperator getUserByUsername(String username) { + return new FlowUser(userRepository.getUserByUsername(username)); + } } diff --git a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java new file mode 100644 index 00000000..c282f43b --- /dev/null +++ b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java @@ -0,0 +1,17 @@ +package com.codingapi.example.infra.db; + +import com.codingapi.example.domain.user.gateway.PasswordEncoder; +import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.domain.user.service.UserService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AutoDomainConfiguration { + + @Bean + public UserService userService(UserRepository userRepository, PasswordEncoder passwordEncoder) { + return new UserService(userRepository, passwordEncoder); + } + +} diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/domain/UserDomainCmdController.java b/example/example-interface/src/main/java/com/codingapi/example/api/domain/UserDomainCmdController.java index 13139b85..7863f88f 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/domain/UserDomainCmdController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/domain/UserDomainCmdController.java @@ -2,6 +2,7 @@ import com.codingapi.example.app.cmd.domain.pojo.UserCmd; import com.codingapi.example.app.cmd.domain.router.UserRouter; +import com.codingapi.springboot.framework.dto.request.IdRequest; import com.codingapi.springboot.framework.dto.response.Response; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.PostMapping; @@ -18,7 +19,32 @@ public class UserDomainCmdController { @PostMapping("/save") public Response save(@RequestBody UserCmd.UpdateRequest request) { - userRouter.save(request); + userRouter.createOrUpdate(request); return Response.buildSuccess(); } + + @PostMapping("/removeEntrust") + public Response removeEntrust(@RequestBody IdRequest request) { + userRouter.removeEntrust(request.getLongId()); + return Response.buildSuccess(); + } + + @PostMapping("/entrust") + public Response entrust(@RequestBody UserCmd.EntrustRequest request) { + userRouter.createEntrust(request); + return Response.buildSuccess(); + } + + @PostMapping("/changeManager") + public Response changeManager(@RequestBody IdRequest request) { + userRouter.changeManager(request.getLongId()); + return Response.buildSuccess(); + } + + @PostMapping("/remove") + public Response remove(@RequestBody IdRequest request) { + userRouter.removeUser(request.getLongId()); + return Response.buildSuccess(); + } + } diff --git a/example/example-application/src/main/java/com/codingapi/example/command/FlowRecordCmdController.java b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java similarity index 74% rename from example/example-application/src/main/java/com/codingapi/example/command/FlowRecordCmdController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java index 76222e64..29078ec8 100644 --- a/example/example-application/src/main/java/com/codingapi/example/command/FlowRecordCmdController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java @@ -1,13 +1,13 @@ -package com.codingapi.example.command; +package com.codingapi.example.api.meta; -import com.codingapi.example.domain.user.entity.User; -import com.codingapi.example.domain.user.repository.UserRepository; -import com.codingapi.example.pojo.cmd.FlowCmd; +import com.codingapi.example.app.cmd.meta.pojo.FlowCmd; +import com.codingapi.example.infra.flow.user.FlowUserRepository; import com.codingapi.springboot.flow.pojo.FlowResult; import com.codingapi.springboot.flow.pojo.FlowStepResult; import com.codingapi.springboot.flow.pojo.FlowSubmitResult; import com.codingapi.springboot.flow.result.MessageResult; import com.codingapi.springboot.flow.service.FlowService; +import com.codingapi.springboot.flow.user.IFlowOperator; import com.codingapi.springboot.framework.dto.response.Response; import com.codingapi.springboot.framework.dto.response.SingleResponse; import lombok.AllArgsConstructor; @@ -24,24 +24,24 @@ public class FlowRecordCmdController { private final FlowService flowService; - private final UserRepository userRepository; + private final FlowUserRepository flowUserRepository; @PostMapping("/startFlow") public SingleResponse startFlow(@RequestBody FlowCmd.StartFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); return SingleResponse.of(flowService.startFlow(request.getWorkCode(), current, request.getBindData(), request.getAdvice())); } @PostMapping("/getFlowStep") public SingleResponse getFlowStep(@RequestBody FlowCmd.FlowStep request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); return SingleResponse.of(flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current)); } @PostMapping("/trySubmitFlow") public SingleResponse trySubmitFlow(@RequestBody FlowCmd.SubmitFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); if (request.getRecordId() > 0) { return SingleResponse.of(flowService.trySubmitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion())); } else { @@ -52,7 +52,7 @@ public SingleResponse trySubmitFlow(@RequestBody FlowCmd.Submi @PostMapping("/submitFlow") public SingleResponse submitFlow(@RequestBody FlowCmd.SubmitFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); if (current.isFlowManager()) { return SingleResponse.of(flowService.interfere(request.getRecordId(), current, request.getBindData(), request.getOpinion())); } else { @@ -62,21 +62,21 @@ public SingleResponse submitFlow(@RequestBody FlowCmd.SubmitFlow req @PostMapping("/custom") public SingleResponse customFlowEvent(@RequestBody FlowCmd.CustomFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); return SingleResponse.of(flowService.customFlowEvent(request.getRecordId(), current, request.getButtonId(), request.getBindData(), request.getOpinion())); } @PostMapping("/save") public Response save(@RequestBody FlowCmd.SaveFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); flowService.save(request.getRecordId(), current, request.getBindData(), request.getAdvice()); return Response.buildSuccess(); } @PostMapping("/recall") public Response recall(@RequestBody FlowCmd.RecallFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); flowService.recall(request.getRecordId(), current); return Response.buildSuccess(); } @@ -84,8 +84,8 @@ public Response recall(@RequestBody FlowCmd.RecallFlow request) { @PostMapping("/transfer") public Response transfer(@RequestBody FlowCmd.TransferFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); - User target = userRepository.getUserById(request.getTargetUserId()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + IFlowOperator target = flowUserRepository.getFlowOperatorById(request.getTargetUserId()); flowService.transfer(request.getRecordId(), current, target, request.getBindData(), request.getAdvice()); return Response.buildSuccess(); } @@ -93,7 +93,7 @@ public Response transfer(@RequestBody FlowCmd.TransferFlow request) { @PostMapping("/postponed") public Response postponed(@RequestBody FlowCmd.PostponedFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); flowService.postponed(request.getRecordId(), current, request.getTimeOut()); return Response.buildSuccess(); } @@ -101,7 +101,7 @@ public Response postponed(@RequestBody FlowCmd.PostponedFlow request) { @PostMapping("/urge") public Response urge(@RequestBody FlowCmd.UrgeFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); flowService.urge(request.getRecordId(), current); return Response.buildSuccess(); } @@ -109,7 +109,7 @@ public Response urge(@RequestBody FlowCmd.UrgeFlow request) { @PostMapping("/remove") public Response remove(@RequestBody FlowCmd.RemoveFlow request) { - User current = userRepository.getUserByUsername(request.getUserName()); + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); flowService.remove(request.getRecordId(), current); return Response.buildSuccess(); } diff --git a/example/example-application/src/main/java/com/codingapi/example/command/FlowWorkCmdController.java b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowWorkCmdController.java similarity index 90% rename from example/example-application/src/main/java/com/codingapi/example/command/FlowWorkCmdController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowWorkCmdController.java index f2599b7e..f5aa40d5 100644 --- a/example/example-application/src/main/java/com/codingapi/example/command/FlowWorkCmdController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowWorkCmdController.java @@ -1,7 +1,7 @@ -package com.codingapi.example.command; +package com.codingapi.example.api.meta; -import com.codingapi.example.pojo.cmd.FlowWorkCmd; -import com.codingapi.example.router.FlowWorkRouter; +import com.codingapi.example.app.cmd.meta.pojo.FlowWorkCmd; +import com.codingapi.example.app.cmd.meta.service.FlowWorkRouter; import com.codingapi.springboot.framework.dto.request.IdRequest; import com.codingapi.springboot.framework.dto.response.Response; import lombok.AllArgsConstructor; diff --git a/example/example-application/src/main/java/com/codingapi/example/query/FlowRecordQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java similarity index 92% rename from example/example-application/src/main/java/com/codingapi/example/query/FlowRecordQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java index f4aebbcf..86934232 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/FlowRecordQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java @@ -1,9 +1,10 @@ -package com.codingapi.example.query; +package com.codingapi.example.api.query; -import com.codingapi.example.domain.User; -import com.codingapi.example.entity.FlowRecordEntity; -import com.codingapi.example.jpa.FlowRecordEntityRepository; -import com.codingapi.example.repository.UserRepository; +import com.codingapi.example.domain.user.entity.User; +import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.infra.flow.entity.FlowRecordEntity; +import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; +import com.codingapi.example.infra.flow.user.FlowUser; import com.codingapi.springboot.flow.pojo.FlowDetail; import com.codingapi.springboot.flow.service.FlowService; import com.codingapi.springboot.framework.dto.request.SearchRequest; @@ -41,7 +42,7 @@ public SingleResponse detail(SearchRequest searchRequest) { } String workCode = searchRequest.getParameter("workCode"); User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - return SingleResponse.of(flowService.detail(id, workCode, user)); + return SingleResponse.of(flowService.detail(id, workCode, new FlowUser(user))); } diff --git a/example/example-application/src/main/java/com/codingapi/example/query/FlowWorkQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java similarity index 81% rename from example/example-application/src/main/java/com/codingapi/example/query/FlowWorkQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java index 4084383c..b81ca03a 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/FlowWorkQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java @@ -1,7 +1,7 @@ -package com.codingapi.example.query; +package com.codingapi.example.api.query; -import com.codingapi.example.entity.FlowWorkEntity; -import com.codingapi.example.jpa.FlowWorkEntityRepository; +import com.codingapi.example.infra.flow.entity.FlowWorkEntity; +import com.codingapi.example.infra.flow.jpa.FlowWorkEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; diff --git a/example/example-application/src/main/java/com/codingapi/example/query/LeaveQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java similarity index 81% rename from example/example-application/src/main/java/com/codingapi/example/query/LeaveQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java index d4a3afd4..171071ec 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/LeaveQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java @@ -1,7 +1,7 @@ -package com.codingapi.example.query; +package com.codingapi.example.api.query; -import com.codingapi.example.infra.entity.LeaveEntity; -import com.codingapi.example.infra.jpa.LeaveEntityRepository; +import com.codingapi.example.infra.db.entity.LeaveEntity; +import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; diff --git a/example/example-application/src/main/java/com/codingapi/example/query/UserQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java similarity index 81% rename from example/example-application/src/main/java/com/codingapi/example/query/UserQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java index b9354f45..9b4cb087 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/UserQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java @@ -1,7 +1,7 @@ -package com.codingapi.example.query; +package com.codingapi.example.api.query; -import com.codingapi.example.infra.entity.UserEntity; -import com.codingapi.example.infra.jpa.UserEntityRepository; +import com.codingapi.example.infra.db.entity.UserEntity; +import com.codingapi.example.infra.db.jpa.UserEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; diff --git a/example/example-application/src/main/java/com/codingapi/example/query/app/FlowAppQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java similarity index 95% rename from example/example-application/src/main/java/com/codingapi/example/query/app/FlowAppQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java index 2c4e7f71..907a159f 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/app/FlowAppQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java @@ -1,10 +1,10 @@ -package com.codingapi.example.query.app; +package com.codingapi.example.api.query.app; -import com.codingapi.example.domain.User; -import com.codingapi.example.entity.FlowRecordEntity; -import com.codingapi.example.jpa.FlowRecordEntityRepository; -import com.codingapi.example.repository.UserRepository; +import com.codingapi.example.domain.user.entity.User; +import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.infra.flow.entity.FlowRecordEntity; +import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; import com.codingapi.springboot.fast.jpa.SQLBuilder; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; diff --git a/example/example-application/src/main/java/com/codingapi/example/query/app/LeaveAppQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java similarity index 90% rename from example/example-application/src/main/java/com/codingapi/example/query/app/LeaveAppQueryController.java rename to example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java index f73e0d04..7e4bc23e 100644 --- a/example/example-application/src/main/java/com/codingapi/example/query/app/LeaveAppQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java @@ -1,7 +1,7 @@ -package com.codingapi.example.query.app; +package com.codingapi.example.api.query.app; -import com.codingapi.example.infra.entity.LeaveEntity; -import com.codingapi.example.infra.jpa.LeaveEntityRepository; +import com.codingapi.example.infra.db.entity.LeaveEntity; +import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; import com.codingapi.springboot.fast.jpa.SQLBuilder; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; diff --git a/example/example-application/src/main/java/com/codingapi/example/handler/LeaveHandler.java b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java similarity index 83% rename from example/example-application/src/main/java/com/codingapi/example/handler/LeaveHandler.java rename to example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java index 10fa81dc..d025cdc4 100644 --- a/example/example-application/src/main/java/com/codingapi/example/handler/LeaveHandler.java +++ b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java @@ -1,7 +1,7 @@ package com.codingapi.example.handler; -import com.codingapi.example.domain.Leave; -import com.codingapi.example.repository.LeaveRepository; +import com.codingapi.example.domain.leave.entity.Leave; +import com.codingapi.example.domain.leave.repository.LeaveRepository; import com.codingapi.springboot.flow.event.FlowApprovalEvent; import com.codingapi.springboot.framework.event.IHandler; import lombok.AllArgsConstructor; diff --git a/example/example-application/src/main/java/com/codingapi/example/runner/UserRunner.java b/example/example-interface/src/main/java/com/codingapi/example/runner/UserRunner.java similarity index 88% rename from example/example-application/src/main/java/com/codingapi/example/runner/UserRunner.java rename to example/example-interface/src/main/java/com/codingapi/example/runner/UserRunner.java index b3da7a4c..90156deb 100644 --- a/example/example-application/src/main/java/com/codingapi/example/runner/UserRunner.java +++ b/example/example-interface/src/main/java/com/codingapi/example/runner/UserRunner.java @@ -1,6 +1,6 @@ package com.codingapi.example.runner; -import com.codingapi.example.service.UserService; +import com.codingapi.example.domain.user.service.UserService; import lombok.AllArgsConstructor; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; From ffc0e927f278d50ef4fdb6fcca0700bf5ed2ab0c Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Mon, 14 Apr 2025 10:20:51 +0800 Subject: [PATCH 3/6] remove application --- admin-ui/src/pages/flow/leave/index.tsx | 2 +- .../example/infra/flow/form/LeaveForm.java | 20 +++++++++++++++++++ .../example/infra/flow/user/FlowUser.java | 6 +++++- .../infra/flow/user/FlowUserRepository.java | 7 ++++++- .../example/handler/LeaveHandler.java | 13 ++++++++++-- 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java diff --git a/admin-ui/src/pages/flow/leave/index.tsx b/admin-ui/src/pages/flow/leave/index.tsx index 0dbea241..bfc61a8d 100644 --- a/admin-ui/src/pages/flow/leave/index.tsx +++ b/admin-ui/src/pages/flow/leave/index.tsx @@ -62,7 +62,7 @@ const LeavePage = () => { view={LeaveForm} workCode={"leave"} formParams={{ - clazzName: 'com.codingapi.example.domain.Leave', + clazzName: 'com.codingapi.example.infra.flow.form.LeaveForm', username: username }} /> diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java new file mode 100644 index 00000000..52658644 --- /dev/null +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java @@ -0,0 +1,20 @@ +package com.codingapi.example.infra.flow.form; + +import com.codingapi.springboot.flow.bind.IBindData; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class LeaveForm implements IBindData { + private long id; + private String desc; + private int days; + private String username; + private long createTime; + +} diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUser.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUser.java index 0c029048..1d7c4102 100644 --- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUser.java +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUser.java @@ -28,6 +28,10 @@ public boolean isFlowManager() { @Override public IFlowOperator entrustOperator() { - return new FlowUser(user.getEntrustOperator()); + if(user.getEntrustOperator()!=null) { + return new FlowUser(user.getEntrustOperator()); + }else { + return null; + } } } diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java index 4249cb29..e58b68ac 100644 --- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/user/FlowUserRepository.java @@ -1,5 +1,6 @@ package com.codingapi.example.infra.flow.user; +import com.codingapi.example.domain.user.entity.User; import com.codingapi.example.domain.user.repository.UserRepository; import com.codingapi.springboot.flow.repository.FlowOperatorRepository; import com.codingapi.springboot.flow.user.IFlowOperator; @@ -7,6 +8,7 @@ import org.springframework.stereotype.Repository; import java.util.List; +import java.util.stream.Collectors; @Repository @AllArgsConstructor @@ -16,7 +18,10 @@ public class FlowUserRepository implements FlowOperatorRepository { @Override public List findByIds(List ids) { - return List.of(); + return ids.stream().map(id->{ + User user = userRepository.getUserById(id); + return new FlowUser(user); + }).collect(Collectors.toList()); } @Override diff --git a/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java index d025cdc4..a8b105bd 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java +++ b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java @@ -2,6 +2,7 @@ import com.codingapi.example.domain.leave.entity.Leave; import com.codingapi.example.domain.leave.repository.LeaveRepository; +import com.codingapi.example.infra.flow.form.LeaveForm; import com.codingapi.springboot.flow.event.FlowApprovalEvent; import com.codingapi.springboot.framework.event.IHandler; import lombok.AllArgsConstructor; @@ -15,8 +16,16 @@ public class LeaveHandler implements IHandler { @Override public void handler(FlowApprovalEvent event) { - if(event.isFinish() && event.match(Leave.class)){ - Leave leave = (Leave)event.getBindData(); + if(event.isFinish() && event.match(LeaveForm.class)){ + LeaveForm form = (LeaveForm)event.getBindData(); + + Leave leave = new Leave(); + leave.setId(form.getId()); + leave.setUsername(form.getUsername()); + leave.setCreateTime(form.getCreateTime()); + leave.setDays(form.getDays()); + leave.setDesc(form.getDesc()); + leaveRepository.save(leave); } } From 4ba513658576722c851b2039c7b35c82ce0c104a Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Mon, 14 Apr 2025 11:07:31 +0800 Subject: [PATCH 4/6] remove application --- .../LeaveDomainConfiguration.java | 15 +++++ .../UserDomainConfiguration.java} | 4 +- .../example/app/cmd/domain/pojo/UserCmd.java | 6 ++ .../app/cmd/domain/router/UserRouter.java | 58 +++++-------------- .../domain/leave/service/LeaveService.java | 15 +++++ .../example/domain/user/entity/User.java | 35 ++++++----- .../domain/user/entity/UserMetric.java | 25 ++++++++ .../domain/user/service/UserService.java | 53 ++++++++++++++++- .../example/infra/flow/form/LeaveForm.java | 12 ++++ .../infra/db/convert/UserConvertor.java | 4 +- .../example/infra/db/entity/UserEntity.java | 5 ++ .../example/handler/LeaveHandler.java | 19 ++---- 12 files changed, 171 insertions(+), 80 deletions(-) create mode 100644 example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/LeaveDomainConfiguration.java rename example/{example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java => example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/UserDomainConfiguration.java} (83%) create mode 100644 example/example-domain/example-domain-leave/src/main/java/com/codingapi/example/domain/leave/service/LeaveService.java create mode 100644 example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/UserMetric.java diff --git a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/LeaveDomainConfiguration.java b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/LeaveDomainConfiguration.java new file mode 100644 index 00000000..1cce645c --- /dev/null +++ b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/LeaveDomainConfiguration.java @@ -0,0 +1,15 @@ +package com.codingapi.example.app.cmd.domain.configuration; + +import com.codingapi.example.domain.leave.repository.LeaveRepository; +import com.codingapi.example.domain.leave.service.LeaveService; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class LeaveDomainConfiguration { + + @Bean + public LeaveService leaveService(LeaveRepository leaveRepository){ + return new LeaveService(leaveRepository); + } +} diff --git a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/UserDomainConfiguration.java similarity index 83% rename from example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java rename to example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/UserDomainConfiguration.java index c282f43b..34a2de7a 100644 --- a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/AutoDomainConfiguration.java +++ b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/configuration/UserDomainConfiguration.java @@ -1,4 +1,4 @@ -package com.codingapi.example.infra.db; +package com.codingapi.example.app.cmd.domain.configuration; import com.codingapi.example.domain.user.gateway.PasswordEncoder; import com.codingapi.example.domain.user.repository.UserRepository; @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration; @Configuration -public class AutoDomainConfiguration { +public class UserDomainConfiguration { @Bean public UserService userService(UserRepository userRepository, PasswordEncoder passwordEncoder) { diff --git a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/pojo/UserCmd.java b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/pojo/UserCmd.java index cefafbb7..7ee0f5bf 100644 --- a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/pojo/UserCmd.java +++ b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/pojo/UserCmd.java @@ -1,5 +1,6 @@ package com.codingapi.example.app.cmd.domain.pojo; +import com.codingapi.example.domain.user.entity.UserMetric; import lombok.Getter; import lombok.Setter; @@ -12,6 +13,11 @@ public static class UpdateRequest{ private String name; private String username; private String password; + + public UserMetric toMetric(){ + return new UserMetric(name, username, password); + } + private boolean flowManager; public boolean hasId(){ diff --git a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java index 53f96654..1b4fccd0 100644 --- a/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java +++ b/example/example-app/example-app-cmd-domain/src/main/java/com/codingapi/example/app/cmd/domain/router/UserRouter.java @@ -1,9 +1,7 @@ package com.codingapi.example.app.cmd.domain.router; import com.codingapi.example.app.cmd.domain.pojo.UserCmd; -import com.codingapi.example.domain.user.entity.User; -import com.codingapi.example.domain.user.gateway.PasswordEncoder; -import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.domain.user.service.UserService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Component; @@ -11,57 +9,29 @@ @AllArgsConstructor public class UserRouter { - private final UserRepository userRepository; - private final PasswordEncoder passwordEncoder; + private final UserService userService; - public void createOrUpdate(UserCmd.UpdateRequest request){ - if(request.hasId()){ - User user = userRepository.getUserById(request.getId()); - user.setName(request.getName()); - user.setPassword(request.getPassword()); - user.setFlowManager(request.isFlowManager()); - user.encodePassword(passwordEncoder); - userRepository.save(user); - }else { - User user = new User(); - user.setName(request.getName()); - user.setPassword(request.getPassword()); - user.setFlowManager(request.isFlowManager()); - user.encodePassword(passwordEncoder); - userRepository.save(user); + public void createOrUpdate(UserCmd.UpdateRequest request) { + if (request.hasId()) { + userService.update(request.getId(), request.toMetric()); + } else { + userService.create(request.toMetric()); } } public void removeEntrust(long id) { - User user = userRepository.getUserById(id); - if(user!=null){ - user.removeEntrust(); - userRepository.save(user); - } + userService.removeEntrust(id); } - public void createEntrust(UserCmd.EntrustRequest request){ - User user = userRepository.getUserById(request.getId()); - if(user!=null){ - User entrustOperator = userRepository.getUserById(request.getEntrustUserId()); - user.setEntrustOperator(entrustOperator); - userRepository.save(user); - } + public void createEntrust(UserCmd.EntrustRequest request) { + userService.createEntrust(request.getId(),request.getEntrustUserId()); } - public void changeManager(long id){ - User user = userRepository.getUserById(id); - if(user!=null){ - user.changeManager(); - userRepository.save(user); - } + public void changeManager(long id) { + userService.changeManager(id); } - public void removeUser(long id){ - User user = userRepository.getUserById(id); - if(user!=null){ - userRepository.delete(id); - } + public void removeUser(long id) { + userService.removeUser(id); } - } diff --git a/example/example-domain/example-domain-leave/src/main/java/com/codingapi/example/domain/leave/service/LeaveService.java b/example/example-domain/example-domain-leave/src/main/java/com/codingapi/example/domain/leave/service/LeaveService.java new file mode 100644 index 00000000..6988c17f --- /dev/null +++ b/example/example-domain/example-domain-leave/src/main/java/com/codingapi/example/domain/leave/service/LeaveService.java @@ -0,0 +1,15 @@ +package com.codingapi.example.domain.leave.service; + +import com.codingapi.example.domain.leave.entity.Leave; +import com.codingapi.example.domain.leave.repository.LeaveRepository; +import lombok.AllArgsConstructor; + +@AllArgsConstructor +public class LeaveService { + + private final LeaveRepository leaveRepository; + + public void create(Leave leave) { + leaveRepository.save(leave); + } +} diff --git a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java index 287f1219..29f5ed7f 100644 --- a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java +++ b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/User.java @@ -10,30 +10,37 @@ @NoArgsConstructor public class User { + public final static String USER_ADMIN_USERNAME = "admin"; + public final static String USER_ADMIN_PASSWORD = "admin"; + public final static String USER_ADMIN_NAME = "admin"; + private long id; - private String name; - private String username; - private String password; + private UserMetric userMetric; private boolean isFlowManager; private User entrustOperator; private long createTime; - public User(String name, PasswordEncoder passwordEncoder) { - this.name = name; - this.username = name; - this.password = passwordEncoder.encode(name); - } - - public static User admin(PasswordEncoder passwordEncoder) { + UserMetric metric = UserMetric.createAdmin(); + User user = new User(); - user.setName("admin"); - user.setUsername("admin"); - user.setPassword("admin"); + user.setUserMetric(metric); user.encodePassword(passwordEncoder); return user; } + public String getName(){ + return userMetric.getName(); + } + + public String getUsername(){ + return userMetric.getUsername(); + } + + public String getPassword(){ + return userMetric.getPassword(); + } + public void removeEntrust() { this.entrustOperator = null; } @@ -43,6 +50,6 @@ public void changeManager() { } public void encodePassword(PasswordEncoder passwordEncoder) { - this.password = passwordEncoder.encode(this.password); + this.userMetric.encodePassword(passwordEncoder); } } diff --git a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/UserMetric.java b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/UserMetric.java new file mode 100644 index 00000000..391ffe1f --- /dev/null +++ b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/entity/UserMetric.java @@ -0,0 +1,25 @@ +package com.codingapi.example.domain.user.entity; + +import com.codingapi.example.domain.user.gateway.PasswordEncoder; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +public class UserMetric { + + private String name; + private String username; + private String password; + + public void encodePassword(PasswordEncoder passwordEncoder) { + this.password = passwordEncoder.encode(this.password); + } + + public static UserMetric createAdmin() { + return new UserMetric(User.USER_ADMIN_NAME, User.USER_ADMIN_USERNAME, User.USER_ADMIN_PASSWORD); + } + +} diff --git a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/service/UserService.java b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/service/UserService.java index 903a53de..b67cdb48 100644 --- a/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/service/UserService.java +++ b/example/example-domain/example-domain-user/src/main/java/com/codingapi/example/domain/user/service/UserService.java @@ -1,24 +1,71 @@ package com.codingapi.example.domain.user.service; import com.codingapi.example.domain.user.entity.User; +import com.codingapi.example.domain.user.entity.UserMetric; import com.codingapi.example.domain.user.gateway.PasswordEncoder; import com.codingapi.example.domain.user.repository.UserRepository; import lombok.AllArgsConstructor; +import static com.codingapi.example.domain.user.entity.User.USER_ADMIN_USERNAME; + @AllArgsConstructor public class UserService { private final UserRepository userRepository; private final PasswordEncoder passwordEncoder; - public final static String USER_ADMIN = "admin"; - public void initAdmin() { - User admin = userRepository.getUserByUsername(USER_ADMIN); + User admin = userRepository.getUserByUsername(USER_ADMIN_USERNAME); if (admin == null) { admin = User.admin(passwordEncoder); userRepository.save(admin); } } + public void create(UserMetric userMetric) { + User user = new User(); + user.setUserMetric(userMetric); + user.encodePassword(passwordEncoder); + userRepository.save(user); + } + + + public void update(long id, UserMetric metric) { + User user = userRepository.getUserById(id); + user.setUserMetric(metric); + user.encodePassword(passwordEncoder); + userRepository.save(user); + } + + public void removeEntrust(long id) { + User user = userRepository.getUserById(id); + if(user!=null){ + user.removeEntrust(); + userRepository.save(user); + } + } + + public void createEntrust(long userId,long entrustId) { + User user = userRepository.getUserById(userId); + if(user!=null){ + User entrustOperator = userRepository.getUserById(entrustId); + user.setEntrustOperator(entrustOperator); + userRepository.save(user); + } + } + + public void changeManager(long id){ + User user = userRepository.getUserById(id); + if(user!=null){ + user.changeManager(); + userRepository.save(user); + } + } + + public void removeUser(long id){ + User user = userRepository.getUserById(id); + if(user!=null){ + userRepository.delete(id); + } + } } diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java index 52658644..d0f5846b 100644 --- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java +++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/form/LeaveForm.java @@ -1,5 +1,6 @@ package com.codingapi.example.infra.flow.form; +import com.codingapi.example.domain.leave.entity.Leave; import com.codingapi.springboot.flow.bind.IBindData; import lombok.AllArgsConstructor; import lombok.Getter; @@ -17,4 +18,15 @@ public class LeaveForm implements IBindData { private String username; private long createTime; + + public Leave toLeave() { + Leave leave = new Leave(); + leave.setId(id); + leave.setUsername(username); + leave.setCreateTime(createTime); + leave.setDays(days); + leave.setDesc(desc); + return leave; + } + } diff --git a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/convert/UserConvertor.java b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/convert/UserConvertor.java index 8464826d..bb5a637a 100644 --- a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/convert/UserConvertor.java +++ b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/convert/UserConvertor.java @@ -12,9 +12,7 @@ public static User convert(UserEntity entity, UserEntityRepository userEntityRep } User user = new User(); user.setId(entity.getId()); - user.setName(entity.getName()); - user.setUsername(entity.getUsername()); - user.setPassword(entity.getPassword()); + user.setUserMetric(entity.getUserMetric()); user.setFlowManager(entity.isFlowManager()); user.setCreateTime(entity.getCreateTime()); if (entity.getEntrustOperatorId() != 0) { diff --git a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/entity/UserEntity.java b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/entity/UserEntity.java index b49d4dcd..ec803c32 100644 --- a/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/entity/UserEntity.java +++ b/example/example-infra/example-infra-jpa/src/main/java/com/codingapi/example/infra/db/entity/UserEntity.java @@ -1,5 +1,6 @@ package com.codingapi.example.infra.db.entity; +import com.codingapi.example.domain.user.entity.UserMetric; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; @@ -27,4 +28,8 @@ public class UserEntity { private String entrustOperatorName; private long createTime; + + public UserMetric getUserMetric() { + return new UserMetric(name,username,password); + } } diff --git a/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java index a8b105bd..25a381bf 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java +++ b/example/example-interface/src/main/java/com/codingapi/example/handler/LeaveHandler.java @@ -1,7 +1,6 @@ package com.codingapi.example.handler; -import com.codingapi.example.domain.leave.entity.Leave; -import com.codingapi.example.domain.leave.repository.LeaveRepository; +import com.codingapi.example.domain.leave.service.LeaveService; import com.codingapi.example.infra.flow.form.LeaveForm; import com.codingapi.springboot.flow.event.FlowApprovalEvent; import com.codingapi.springboot.framework.event.IHandler; @@ -12,21 +11,13 @@ @AllArgsConstructor public class LeaveHandler implements IHandler { - private final LeaveRepository leaveRepository; + private final LeaveService leaveService; @Override public void handler(FlowApprovalEvent event) { - if(event.isFinish() && event.match(LeaveForm.class)){ - LeaveForm form = (LeaveForm)event.getBindData(); - - Leave leave = new Leave(); - leave.setId(form.getId()); - leave.setUsername(form.getUsername()); - leave.setCreateTime(form.getCreateTime()); - leave.setDays(form.getDays()); - leave.setDesc(form.getDesc()); - - leaveRepository.save(leave); + if (event.isFinish() && event.match(LeaveForm.class)) { + LeaveForm form = (LeaveForm) event.getBindData(); + leaveService.create(form.toLeave()); } } } From 51f359d516b51cfab0562e8ea10d5f41c6a3894f Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Mon, 14 Apr 2025 12:04:53 +0800 Subject: [PATCH 5/6] add meta --- .../cmd/meta/service/FlowRecordRouter.java | 92 +++++++++++++++++++ .../api/meta/FlowRecordCmdController.java | 56 +++-------- 2 files changed, 105 insertions(+), 43 deletions(-) create mode 100644 example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java diff --git a/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java new file mode 100644 index 00000000..9f9e1bff --- /dev/null +++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java @@ -0,0 +1,92 @@ +package com.codingapi.example.app.cmd.meta.service; + +import com.codingapi.example.app.cmd.meta.pojo.FlowCmd; +import com.codingapi.example.infra.flow.user.FlowUserRepository; +import com.codingapi.springboot.flow.pojo.FlowResult; +import com.codingapi.springboot.flow.pojo.FlowStepResult; +import com.codingapi.springboot.flow.pojo.FlowSubmitResult; +import com.codingapi.springboot.flow.result.MessageResult; +import com.codingapi.springboot.flow.service.FlowService; +import com.codingapi.springboot.flow.user.IFlowOperator; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class FlowRecordRouter { + + + private final FlowService flowService; + private final FlowUserRepository flowUserRepository; + + public FlowResult startFlow(FlowCmd.StartFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + return flowService.startFlow(request.getWorkCode(), current, request.getBindData(), request.getAdvice()); + } + + public FlowStepResult getFlowStep(FlowCmd.FlowStep request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + return flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current); + } + + + public FlowSubmitResult trySubmitFlow(FlowCmd.SubmitFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + if (request.getRecordId() > 0) { + return flowService.trySubmitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion()); + } else { + return flowService.trySubmitFlow(request.getWorkCode(), current, request.getBindData(), request.getOpinion()); + } + } + + + public FlowResult submitFlow(FlowCmd.SubmitFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + if (current.isFlowManager()) { + return flowService.interfere(request.getRecordId(), current, request.getBindData(), request.getOpinion()); + } else { + return flowService.submitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion()); + } + } + + public MessageResult customFlowEvent(FlowCmd.CustomFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + return flowService.customFlowEvent(request.getRecordId(), current, request.getButtonId(), request.getBindData(), request.getOpinion()); + } + + + public void save(FlowCmd.SaveFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + flowService.save(request.getRecordId(), current, request.getBindData(), request.getAdvice()); + } + + public void recall(FlowCmd.RecallFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + flowService.recall(request.getRecordId(), current); + } + + + public void transfer(FlowCmd.TransferFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + IFlowOperator target = flowUserRepository.getFlowOperatorById(request.getTargetUserId()); + flowService.transfer(request.getRecordId(), current, target, request.getBindData(), request.getAdvice()); + } + + + public void postponed(FlowCmd.PostponedFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + flowService.postponed(request.getRecordId(), current, request.getTimeOut()); + } + + + public void urge(FlowCmd.UrgeFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + flowService.urge(request.getRecordId(), current); + } + + + public void remove(FlowCmd.RemoveFlow request) { + IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); + flowService.remove(request.getRecordId(), current); + } +} diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java index 29078ec8..ad992359 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java @@ -1,13 +1,11 @@ package com.codingapi.example.api.meta; import com.codingapi.example.app.cmd.meta.pojo.FlowCmd; -import com.codingapi.example.infra.flow.user.FlowUserRepository; +import com.codingapi.example.app.cmd.meta.service.FlowRecordRouter; import com.codingapi.springboot.flow.pojo.FlowResult; import com.codingapi.springboot.flow.pojo.FlowStepResult; import com.codingapi.springboot.flow.pojo.FlowSubmitResult; import com.codingapi.springboot.flow.result.MessageResult; -import com.codingapi.springboot.flow.service.FlowService; -import com.codingapi.springboot.flow.user.IFlowOperator; import com.codingapi.springboot.framework.dto.response.Response; import com.codingapi.springboot.framework.dto.response.SingleResponse; import lombok.AllArgsConstructor; @@ -23,94 +21,66 @@ @AllArgsConstructor public class FlowRecordCmdController { - private final FlowService flowService; - private final FlowUserRepository flowUserRepository; + private final FlowRecordRouter flowRecordRouter; @PostMapping("/startFlow") public SingleResponse startFlow(@RequestBody FlowCmd.StartFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - return SingleResponse.of(flowService.startFlow(request.getWorkCode(), current, request.getBindData(), request.getAdvice())); + return SingleResponse.of(flowRecordRouter.startFlow(request)); } @PostMapping("/getFlowStep") public SingleResponse getFlowStep(@RequestBody FlowCmd.FlowStep request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - return SingleResponse.of(flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current)); + return SingleResponse.of(flowRecordRouter.getFlowStep(request)); } - @PostMapping("/trySubmitFlow") public SingleResponse trySubmitFlow(@RequestBody FlowCmd.SubmitFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - if (request.getRecordId() > 0) { - return SingleResponse.of(flowService.trySubmitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion())); - } else { - return SingleResponse.of(flowService.trySubmitFlow(request.getWorkCode(), current, request.getBindData(), request.getOpinion())); - } + return SingleResponse.of(flowRecordRouter.trySubmitFlow(request)); } - @PostMapping("/submitFlow") public SingleResponse submitFlow(@RequestBody FlowCmd.SubmitFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - if (current.isFlowManager()) { - return SingleResponse.of(flowService.interfere(request.getRecordId(), current, request.getBindData(), request.getOpinion())); - } else { - return SingleResponse.of(flowService.submitFlow(request.getRecordId(), current, request.getBindData(), request.getOpinion())); - } + return SingleResponse.of(flowRecordRouter.submitFlow(request)); } @PostMapping("/custom") public SingleResponse customFlowEvent(@RequestBody FlowCmd.CustomFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - return SingleResponse.of(flowService.customFlowEvent(request.getRecordId(), current, request.getButtonId(), request.getBindData(), request.getOpinion())); + return SingleResponse.of(flowRecordRouter.customFlowEvent(request)); } - @PostMapping("/save") public Response save(@RequestBody FlowCmd.SaveFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - flowService.save(request.getRecordId(), current, request.getBindData(), request.getAdvice()); + flowRecordRouter.save(request); return Response.buildSuccess(); } @PostMapping("/recall") public Response recall(@RequestBody FlowCmd.RecallFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - flowService.recall(request.getRecordId(), current); + flowRecordRouter.recall(request); return Response.buildSuccess(); } - @PostMapping("/transfer") public Response transfer(@RequestBody FlowCmd.TransferFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - IFlowOperator target = flowUserRepository.getFlowOperatorById(request.getTargetUserId()); - flowService.transfer(request.getRecordId(), current, target, request.getBindData(), request.getAdvice()); + flowRecordRouter.transfer(request); return Response.buildSuccess(); } - @PostMapping("/postponed") public Response postponed(@RequestBody FlowCmd.PostponedFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - flowService.postponed(request.getRecordId(), current, request.getTimeOut()); + flowRecordRouter.postponed(request); return Response.buildSuccess(); } - @PostMapping("/urge") public Response urge(@RequestBody FlowCmd.UrgeFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - flowService.urge(request.getRecordId(), current); + flowRecordRouter.urge(request); return Response.buildSuccess(); } - @PostMapping("/remove") public Response remove(@RequestBody FlowCmd.RemoveFlow request) { - IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName()); - flowService.remove(request.getRecordId(), current); + flowRecordRouter.remove(request); return Response.buildSuccess(); } From 9197aa77a64c9752ca198aaad0ea8b60dbd88c6b Mon Sep 17 00:00:00 2001 From: lorne <1991wangliang@gmail.com> Date: Mon, 14 Apr 2025 14:23:58 +0800 Subject: [PATCH 6/6] add query --- example/example-app/example-app-query/pom.xml | 20 +++ .../query/service/FlowAppQueryService.java | 118 ++++++++++++++++++ .../query/service/FlowRecordQueryService.java | 83 ++++++++++++ .../query/service/FlowWorkQueryService.java | 19 +++ .../query/service/LeaveAppQueryService.java | 32 +++++ .../app/query/service/LeaveQueryService.java | 21 ++++ .../app/query/service/UserQueryService.java | 20 +++ .../api/query/FlowRecordQueryController.java | 49 ++------ .../api/query/FlowWorkQueryController.java | 6 +- .../api/query/LeaveQueryController.java | 6 +- .../api/query/UserQueryController.java | 6 +- .../api/query/app/FlowAppQueryController.java | 87 ++----------- .../query/app/LeaveAppQueryController.java | 23 +--- 13 files changed, 344 insertions(+), 146 deletions(-) create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowAppQueryService.java create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowRecordQueryService.java create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowWorkQueryService.java create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveAppQueryService.java create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveQueryService.java create mode 100644 example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/UserQueryService.java diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml index 1640e29c..78ec5c22 100644 --- a/example/example-app/example-app-query/pom.xml +++ b/example/example-app/example-app-query/pom.xml @@ -17,4 +17,24 @@ + + + com.codingapi.springboot + example-infra-jpa + ${project.version} + + + + com.codingapi.springboot + example-infra-flow + ${project.version} + + + + com.codingapi.springboot + example-infra-security + ${project.version} + + + diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowAppQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowAppQueryService.java new file mode 100644 index 00000000..63a24e88 --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowAppQueryService.java @@ -0,0 +1,118 @@ +package com.codingapi.example.app.query.service; + +import com.codingapi.example.domain.user.entity.User; +import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.infra.flow.entity.FlowRecordEntity; +import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; +import com.codingapi.springboot.fast.jpa.SQLBuilder; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import com.codingapi.springboot.security.gateway.TokenContext; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +@Service +@AllArgsConstructor +public class FlowAppQueryService { + + private final FlowRecordEntityRepository flowRecordQuery; + private final UserRepository userRepository; + + public Page list(SearchRequest searchRequest) { + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) "); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by d.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findAllByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) "); + sqlBuilder.addParam(user.getId()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by d.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' "); + sqlBuilder.addParam(user.getId()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by r.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findDoneByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) "); + sqlBuilder.addParam(user.getId()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by d.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findInitiatedByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) "); + sqlBuilder.addParam(user.getId()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by d.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findTimeoutTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 "); + sqlBuilder.addParam(user.getId()); + sqlBuilder.addParam(System.currentTimeMillis()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by r.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } + + + public Page findPostponedTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 "); + sqlBuilder.addParam(user.getId()); + if(StringUtils.hasText(lastId)){ + sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by r.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest); + } +} diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowRecordQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowRecordQueryService.java new file mode 100644 index 00000000..0da1cf88 --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowRecordQueryService.java @@ -0,0 +1,83 @@ +package com.codingapi.example.app.query.service; + +import com.codingapi.example.domain.user.entity.User; +import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.infra.flow.entity.FlowRecordEntity; +import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; +import com.codingapi.example.infra.flow.user.FlowUser; +import com.codingapi.springboot.flow.pojo.FlowDetail; +import com.codingapi.springboot.flow.service.FlowService; +import com.codingapi.springboot.framework.dto.request.PageRequest; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import com.codingapi.springboot.security.gateway.TokenContext; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class FlowRecordQueryService { + + private final FlowRecordEntityRepository flowRecordQuery; + private final UserRepository userRepository; + private final FlowService flowService; + + public Page list(SearchRequest searchRequest) { + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize(), Sort.by("id").descending()); + return flowRecordQuery.findAllFlowRecords(pageRequest); + } + + + public FlowDetail detail(SearchRequest searchRequest) { + long id = 0; + if (searchRequest.getParameter("id") != null) { + id = Long.parseLong(searchRequest.getParameter("id")); + } + String workCode = searchRequest.getParameter("workCode"); + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + return flowService.detail(id, workCode, new FlowUser(user)); + } + + + public Page findAllByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findAllByOperatorId(user.getId(), pageRequest); + } + + + public Page findTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findTodoByOperatorId(user.getId(), pageRequest); + } + + + public Page findDoneByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findDoneByOperatorId(user.getId(), pageRequest); + } + + + public Page findInitiatedByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findInitiatedByOperatorId(user.getId(), pageRequest); + } + + + public Page findTimeoutTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findTimeoutTodoByOperatorId(user.getId(), System.currentTimeMillis(), pageRequest); + } + + + public Page findPostponedTodoByOperatorId(SearchRequest searchRequest) { + User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); + PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); + return flowRecordQuery.findPostponedTodoByOperatorId(user.getId(), pageRequest); + } +} diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowWorkQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowWorkQueryService.java new file mode 100644 index 00000000..521ab324 --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/FlowWorkQueryService.java @@ -0,0 +1,19 @@ +package com.codingapi.example.app.query.service; + +import com.codingapi.example.infra.flow.entity.FlowWorkEntity; +import com.codingapi.example.infra.flow.jpa.FlowWorkEntityRepository; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class FlowWorkQueryService { + + private final FlowWorkEntityRepository flowWorkEntityRepository; + + public Page list(SearchRequest searchRequest) { + return flowWorkEntityRepository.searchRequest(searchRequest); + } +} diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveAppQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveAppQueryService.java new file mode 100644 index 00000000..6aa830f8 --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveAppQueryService.java @@ -0,0 +1,32 @@ +package com.codingapi.example.app.query.service; + +import com.codingapi.example.infra.db.entity.LeaveEntity; +import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; +import com.codingapi.springboot.fast.jpa.SQLBuilder; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import com.codingapi.springboot.security.gateway.TokenContext; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +@Service +@AllArgsConstructor +public class LeaveAppQueryService { + + private final LeaveEntityRepository leaveEntityRepository; + + public Page list(SearchRequest searchRequest) { + String username = TokenContext.current().getUsername(); + String lastId = searchRequest.getParameter("lastId"); + SQLBuilder sqlBuilder = new SQLBuilder("from LeaveEntity l where 1 =1 "); + sqlBuilder.append(" and l.username = ? ", username); + if (StringUtils.hasText(lastId)) { + sqlBuilder.append(" and l.id < ? ", Long.parseLong(lastId)); + } + sqlBuilder.appendSql(" order by l.id desc "); + PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); + return leaveEntityRepository.dynamicPageQuery(sqlBuilder, pageRequest); + } +} diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveQueryService.java new file mode 100644 index 00000000..ba6198ea --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/LeaveQueryService.java @@ -0,0 +1,21 @@ +package com.codingapi.example.app.query.service; + + +import com.codingapi.example.infra.db.entity.LeaveEntity; +import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class LeaveQueryService { + + private final LeaveEntityRepository leaveEntityRepository; + + public Page list(SearchRequest searchRequest){ + return leaveEntityRepository.searchRequest(searchRequest); + } + +} diff --git a/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/UserQueryService.java b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/UserQueryService.java new file mode 100644 index 00000000..25c7139f --- /dev/null +++ b/example/example-app/example-app-query/src/main/java/com/codingapi/example/app/query/service/UserQueryService.java @@ -0,0 +1,20 @@ +package com.codingapi.example.app.query.service; + +import com.codingapi.example.infra.db.entity.UserEntity; +import com.codingapi.example.infra.db.jpa.UserEntityRepository; +import com.codingapi.springboot.framework.dto.request.SearchRequest; +import lombok.AllArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.stereotype.Service; + +@Service +@AllArgsConstructor +public class UserQueryService { + + private final UserEntityRepository userEntityRepository; + + public Page list(SearchRequest searchRequest) { + return userEntityRepository.searchRequest(searchRequest); + } + +} diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java index 86934232..6046d25e 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowRecordQueryController.java @@ -1,19 +1,12 @@ package com.codingapi.example.api.query; -import com.codingapi.example.domain.user.entity.User; -import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.app.query.service.FlowRecordQueryService; import com.codingapi.example.infra.flow.entity.FlowRecordEntity; -import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; -import com.codingapi.example.infra.flow.user.FlowUser; import com.codingapi.springboot.flow.pojo.FlowDetail; -import com.codingapi.springboot.flow.service.FlowService; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import com.codingapi.springboot.framework.dto.response.SingleResponse; -import com.codingapi.springboot.security.gateway.TokenContext; import lombok.AllArgsConstructor; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -23,76 +16,54 @@ @AllArgsConstructor public class FlowRecordQueryController { - private final FlowRecordEntityRepository flowRecordQuery; - private final UserRepository userRepository; - private final FlowService flowService; + private final FlowRecordQueryService flowRecordQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest) { - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize(), Sort.by("id").descending()); - return MultiResponse.of(flowRecordQuery.findAllFlowRecords(pageRequest)); + return MultiResponse.of(flowRecordQueryService.list(searchRequest)); } @GetMapping("/detail") public SingleResponse detail(SearchRequest searchRequest) { - long id = 0; - if (searchRequest.getParameter("id") != null) { - id = Long.parseLong(searchRequest.getParameter("id")); - } - String workCode = searchRequest.getParameter("workCode"); - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - return SingleResponse.of(flowService.detail(id, workCode, new FlowUser(user))); + return SingleResponse.of(flowRecordQueryService.detail(searchRequest)); } @GetMapping("/findAllByOperatorId") public MultiResponse findAllByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findAllByOperatorId(user.getId(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findAllByOperatorId(searchRequest)); } @GetMapping("/findTodoByOperatorId") public MultiResponse findTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findTodoByOperatorId(user.getId(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findTodoByOperatorId(searchRequest)); } @GetMapping("/findDoneByOperatorId") public MultiResponse findDoneByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findDoneByOperatorId(user.getId(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findDoneByOperatorId(searchRequest)); } @GetMapping("/findInitiatedByOperatorId") public MultiResponse findInitiatedByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findInitiatedByOperatorId(user.getId(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findInitiatedByOperatorId(searchRequest)); } @GetMapping("/findTimeoutTodoByOperatorId") public MultiResponse findTimeoutTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findTimeoutTodoByOperatorId(user.getId(), System.currentTimeMillis(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findTimeoutTodoByOperatorId(searchRequest)); } @GetMapping("/findPostponedTodoByOperatorId") public MultiResponse findPostponedTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - PageRequest pageRequest = PageRequest.of(searchRequest.getCurrent(), searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.findPostponedTodoByOperatorId(user.getId(), pageRequest)); + return MultiResponse.of(flowRecordQueryService.findPostponedTodoByOperatorId(searchRequest)); } - } diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java index b81ca03a..cf68a075 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/FlowWorkQueryController.java @@ -1,7 +1,7 @@ package com.codingapi.example.api.query; +import com.codingapi.example.app.query.service.FlowWorkQueryService; import com.codingapi.example.infra.flow.entity.FlowWorkEntity; -import com.codingapi.example.infra.flow.jpa.FlowWorkEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; @@ -14,11 +14,11 @@ @AllArgsConstructor public class FlowWorkQueryController { - private final FlowWorkEntityRepository flowWorkEntityRepository; + private final FlowWorkQueryService flowWorkQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest) { - return MultiResponse.of(flowWorkEntityRepository.searchRequest(searchRequest)); + return MultiResponse.of(flowWorkQueryService.list(searchRequest)); } } diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java index 171071ec..c018858e 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/LeaveQueryController.java @@ -1,7 +1,7 @@ package com.codingapi.example.api.query; +import com.codingapi.example.app.query.service.LeaveQueryService; import com.codingapi.example.infra.db.entity.LeaveEntity; -import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; @@ -14,11 +14,11 @@ @AllArgsConstructor public class LeaveQueryController { - private final LeaveEntityRepository leaveEntityRepository; + private final LeaveQueryService leaveQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest){ - return MultiResponse.of(leaveEntityRepository.searchRequest(searchRequest)); + return MultiResponse.of(leaveQueryService.list(searchRequest)); } diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java index 9b4cb087..db8ceadc 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/UserQueryController.java @@ -1,7 +1,7 @@ package com.codingapi.example.api.query; +import com.codingapi.example.app.query.service.UserQueryService; import com.codingapi.example.infra.db.entity.UserEntity; -import com.codingapi.example.infra.db.jpa.UserEntityRepository; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; import lombok.AllArgsConstructor; @@ -14,10 +14,10 @@ @AllArgsConstructor public class UserQueryController { - private final UserEntityRepository userEntityRepository; + private final UserQueryService userQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest) { - return MultiResponse.of(userEntityRepository.searchRequest(searchRequest)); + return MultiResponse.of(userQueryService.list(searchRequest)); } } diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java index 907a159f..8c4ac875 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/FlowAppQueryController.java @@ -1,17 +1,11 @@ package com.codingapi.example.api.query.app; -import com.codingapi.example.domain.user.entity.User; -import com.codingapi.example.domain.user.repository.UserRepository; +import com.codingapi.example.app.query.service.FlowAppQueryService; import com.codingapi.example.infra.flow.entity.FlowRecordEntity; -import com.codingapi.example.infra.flow.jpa.FlowRecordEntityRepository; -import com.codingapi.springboot.fast.jpa.SQLBuilder; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; -import com.codingapi.springboot.security.gateway.TokenContext; import lombok.AllArgsConstructor; -import org.springframework.data.domain.PageRequest; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -21,109 +15,46 @@ @AllArgsConstructor public class FlowAppQueryController { - private final FlowRecordEntityRepository flowRecordQuery; - private final UserRepository userRepository; + private final FlowAppQueryService flowAppQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest) { - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) "); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by d.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.list(searchRequest)); } @GetMapping("/findAllByOperatorId") public MultiResponse findAllByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) "); - sqlBuilder.addParam(user.getId()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by d.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findAllByOperatorId(searchRequest)); } @GetMapping("/findTodoByOperatorId") public MultiResponse findTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' "); - sqlBuilder.addParam(user.getId()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by r.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findTodoByOperatorId(searchRequest)); } @GetMapping("/findDoneByOperatorId") public MultiResponse findDoneByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) "); - sqlBuilder.addParam(user.getId()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by d.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findDoneByOperatorId(searchRequest)); } @GetMapping("/findInitiatedByOperatorId") public MultiResponse findInitiatedByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) "); - sqlBuilder.addParam(user.getId()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and d.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by d.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findInitiatedByOperatorId(searchRequest)); } @GetMapping("/findTimeoutTodoByOperatorId") public MultiResponse findTimeoutTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 "); - sqlBuilder.addParam(user.getId()); - sqlBuilder.addParam(System.currentTimeMillis()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by r.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findTimeoutTodoByOperatorId(searchRequest)); } @GetMapping("/findPostponedTodoByOperatorId") public MultiResponse findPostponedTodoByOperatorId(SearchRequest searchRequest) { - User user = userRepository.getUserByUsername(TokenContext.current().getUsername()); - String lastId = searchRequest.getParameter("lastId"); - SQLBuilder sqlBuilder = new SQLBuilder("from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 "); - sqlBuilder.addParam(user.getId()); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and r.id < ?",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by r.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); - return MultiResponse.of(flowRecordQuery.dynamicPageQuery(sqlBuilder,pageRequest)); + return MultiResponse.of(flowAppQueryService.findPostponedTodoByOperatorId(searchRequest)); } } diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java index 7e4bc23e..5ccfd5f3 100644 --- a/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java +++ b/example/example-interface/src/main/java/com/codingapi/example/api/query/app/LeaveAppQueryController.java @@ -1,14 +1,10 @@ package com.codingapi.example.api.query.app; +import com.codingapi.example.app.query.service.LeaveAppQueryService; import com.codingapi.example.infra.db.entity.LeaveEntity; -import com.codingapi.example.infra.db.jpa.LeaveEntityRepository; -import com.codingapi.springboot.fast.jpa.SQLBuilder; import com.codingapi.springboot.framework.dto.request.SearchRequest; import com.codingapi.springboot.framework.dto.response.MultiResponse; -import com.codingapi.springboot.security.gateway.TokenContext; import lombok.AllArgsConstructor; -import org.springframework.data.domain.PageRequest; -import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -18,24 +14,11 @@ @AllArgsConstructor public class LeaveAppQueryController { - private final LeaveEntityRepository leaveEntityRepository; + private final LeaveAppQueryService leaveAppQueryService; @GetMapping("/list") public MultiResponse list(SearchRequest searchRequest){ - String username = TokenContext.current().getUsername(); - String lastId = searchRequest.getParameter("lastId"); - - SQLBuilder sqlBuilder = new SQLBuilder("from LeaveEntity l where 1 =1 "); - sqlBuilder.append(" and l.username = ? ",username); - if(StringUtils.hasText(lastId)){ - sqlBuilder.append(" and l.id < ? ",Long.parseLong(lastId)); - } - sqlBuilder.appendSql(" order by l.id desc "); - PageRequest pageRequest = PageRequest.of(0, searchRequest.getPageSize()); -// return MultiResponse.empty(); - return MultiResponse.of(leaveEntityRepository.dynamicPageQuery(sqlBuilder,pageRequest)); - + return MultiResponse.of(leaveAppQueryService.list(searchRequest)); } - }