feat(eims): 添加点检计划和保养计划的导入功能
| | |
| | | import type { InspectPlanVO } from './model'; |
| | | |
| | | import type { ID, IDS } from '#/api/common'; |
| | | |
| | | import { commonExport } from '#/api/helper'; |
| | | import { commonExport, ContentTypeEnum } from '#/api/helper'; |
| | | import { requestClient } from '#/api/request'; |
| | | |
| | | enum Api { |
| | | inspectPlanExport = '/eims/inspectPlan/export', |
| | | inspectPlanList = '/eims/inspectPlan/list', |
| | | root = '/eims/inspectPlan' |
| | | root = '/eims/inspectPlan', |
| | | inspectPlanImport = '/eims/inspectPlan/importData', |
| | | inspectPlanImportTemplate = '/eims/inspectPlan/importTemplate' |
| | | } |
| | | |
| | | /** |
| | |
| | | export function inspPlanExport(data: any) { |
| | | return commonExport(Api.inspectPlanExport, data); |
| | | } |
| | | |
| | | /** |
| | | * ä¸è½½ç¹æ£è®¡å导å
¥æ¨¡æ¿ |
| | | */ |
| | | export function downloadImportTemplate() { |
| | | return commonExport(Api.inspectPlanImportTemplate); |
| | | } |
| | | |
| | | /** |
| | | * ä»excel导å
¥ç¹æ£è®¡åæ°æ® |
| | | * @param data |
| | | * @returns void |
| | | */ |
| | | export function inspPlanImportData(data: any) { |
| | | return requestClient.post<{ code: number; msg: string }>(Api.inspectPlanImport, data, { |
| | | headers: { |
| | | 'Content-Type': ContentTypeEnum.FORM_DATA |
| | | }, |
| | | isTransformResponse: false |
| | | }); |
| | | } |
| | |
| | | |
| | | import type { ID, IDS } from '#/api/common'; |
| | | |
| | | import { commonExport } from '#/api/helper'; |
| | | import { commonExport, ContentTypeEnum } from '#/api/helper'; |
| | | import { requestClient } from '#/api/request'; |
| | | |
| | | enum Api { |
| | | maintPlanExport = '/eims/maintPlan/export', |
| | | maintPlanList = '/eims/maintPlan/list', |
| | | root = '/eims/maintPlan' |
| | | root = '/eims/maintPlan', |
| | | maintPlanImport = '/eims/maintPlan/importData', |
| | | maintPlanImportTemplate = '/eims/maintPlan/importTemplate' |
| | | } |
| | | |
| | | /** |
| | |
| | | export function maintPlanExport(data: any) { |
| | | return commonExport(Api.maintPlanExport, data); |
| | | } |
| | | |
| | | /** |
| | | * ä¸è½½ä¿å
»è®¡å导å
¥æ¨¡æ¿ |
| | | */ |
| | | export function downloadImportTemplate() { |
| | | return commonExport(Api.maintPlanImportTemplate); |
| | | } |
| | | |
| | | /** |
| | | * ä»excel导å
¥ä¿å
»è®¡åæ°æ® |
| | | * @param data |
| | | * @returns void |
| | | */ |
| | | export function maintPlanImportData(data: any) { |
| | | return requestClient.post<{ code: number; msg: string }>(Api.maintPlanImport, data, { |
| | | headers: { |
| | | 'Content-Type': ContentTypeEnum.FORM_DATA |
| | | }, |
| | | isTransformResponse: false |
| | | }); |
| | | } |
| | |
| | | field: 'inspName', |
| | | minWidth: 200 |
| | | }, |
| | | { |
| | | title: 'ç¹æ£ç±»å', |
| | | field: 'inspType', |
| | | minWidth: 120, |
| | | slots: { |
| | | default: ({ row }) => { |
| | | return renderDict(row.inspType, DictEnum.EIMS_INSPECT_TYPE); |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | title: 'ç¹æ£äºº', |
| | | field: 'inspUserName', |
| | | minWidth: 100 |
| | | }, |
| | | { |
| | | title: '循ç¯å¨æ', |
| | | field: 'inspCycleUnitName', |
| | | minWidth: 80 |
| | | }, |
| | | { |
| | | title: 'æ¶é´è®¡ç®è§å', |
| | | field: 'inspRule', |
| | | minWidth: 140, |
| | | slots: { |
| | | default: ({ row }) => { |
| | | return renderDict(row.inspRule, DictEnum.MAINT_TIME_RULE); |
| | | } |
| | | } |
| | | }, |
| | | { |
| | | title: '馿¬¡æ§è¡æ¶é´', |
| | | field: 'inspFirstTime', |
| | | minWidth: 160 |
| | | }, |
| | | { |
| | | title: '䏿¬¡æ§è¡æ¶é´', |
| | | field: 'inspLastTime', |
| | | minWidth: 160 |
| | | }, |
| | | { |
| | | title: '䏿¬¡æ§è¡æ¶é´', |
| | | field: 'inspNextTime', |
| | | minWidth: 160 |
| | | }, |
| | | // { |
| | | // title: 'ç¹æ£ç±»å', |
| | | // field: 'inspType', |
| | | // minWidth: 120, |
| | | // slots: { |
| | | // default: ({ row }) => { |
| | | // return renderDict(row.inspType, DictEnum.EIMS_INSPECT_TYPE); |
| | | // } |
| | | // } |
| | | // }, |
| | | // { |
| | | // title: 'ç¹æ£äºº', |
| | | // field: 'inspUserName', |
| | | // minWidth: 100 |
| | | // }, |
| | | // { |
| | | // title: '循ç¯å¨æ', |
| | | // field: 'inspCycleUnitName', |
| | | // minWidth: 80 |
| | | // }, |
| | | // { |
| | | // title: 'æ¶é´è®¡ç®è§å', |
| | | // field: 'inspRule', |
| | | // minWidth: 140, |
| | | // slots: { |
| | | // default: ({ row }) => { |
| | | // return renderDict(row.inspRule, DictEnum.MAINT_TIME_RULE); |
| | | // } |
| | | // } |
| | | // }, |
| | | // { |
| | | // title: '馿¬¡æ§è¡æ¶é´', |
| | | // field: 'inspFirstTime', |
| | | // minWidth: 160 |
| | | // }, |
| | | // { |
| | | // title: '䏿¬¡æ§è¡æ¶é´', |
| | | // field: 'inspLastTime', |
| | | // minWidth: 160 |
| | | // }, |
| | | // { |
| | | // title: '䏿¬¡æ§è¡æ¶é´', |
| | | // field: 'inspNextTime', |
| | | // minWidth: 160 |
| | | // }, |
| | | { |
| | | title: 'å建æ¶é´', |
| | | field: 'createTime', |
| | |
| | | fieldName: 'inspName', |
| | | label: 'ç¹æ£é¡¹' |
| | | }, |
| | | { |
| | | component: 'RadioGroup', |
| | | componentProps: { |
| | | buttonStyle: 'solid', |
| | | options: getDictOptions(DictEnum.EIMS_INSPECT_TYPE), |
| | | optionType: 'button' |
| | | }, |
| | | fieldName: 'inspType', |
| | | defaultValue: '1', |
| | | label: 'ç¹æ£ç±»å' |
| | | }, |
| | | // { |
| | | // component: 'RadioGroup', |
| | | // componentProps: { |
| | | // buttonStyle: 'solid', |
| | | // options: getDictOptions(DictEnum.EIMS_INSPECT_TYPE), |
| | | // optionType: 'button' |
| | | // }, |
| | | // fieldName: 'inspType', |
| | | // defaultValue: '1', |
| | | // label: 'ç¹æ£ç±»å' |
| | | // }, |
| | | { |
| | | component: 'Input', |
| | | fieldName: 'inspDesc', |
| | | label: 'ç¹æ£è¯´æ' |
| | | }, |
| | | { |
| | | component: 'InputNumber', |
| | | fieldName: 'inspCycle', |
| | | label: 'ç¹æ£å¨æ', |
| | | formItemClass: 'col-span-1', |
| | | componentProps: { |
| | | min: 1 |
| | | } |
| | | }, |
| | | { |
| | | component: 'Select', |
| | | componentProps: { |
| | | getPopupContainer, |
| | | options: getDictOptions(DictEnum.MAINT_CYCLE_UNIT) |
| | | }, |
| | | fieldName: 'inspCycleUnit', |
| | | formItemClass: 'col-span-1 w-[80px]', |
| | | labelWidth: 0, |
| | | label: '' |
| | | }, |
| | | |
| | | { |
| | | component: 'Select', |
| | | componentProps: { |
| | | getPopupContainer, |
| | | options: getDictOptions(DictEnum.MAINT_TIME_RULE) |
| | | }, |
| | | fieldName: 'inspRule', |
| | | label: 'ç¹æ£è§å ' |
| | | }, |
| | | { |
| | | component: 'Input', |
| | | fieldName: 'inspUser', |
| | | label: 'ç¨æ·id', |
| | | dependencies: { |
| | | show: () => false, |
| | | triggerFields: [''] |
| | | } |
| | | }, |
| | | { |
| | | component: 'Input', |
| | | fieldName: 'inspUserName', |
| | | label: 'ç¹æ£äºº' |
| | | }, |
| | | { |
| | | component: 'Input', |
| | | fieldName: 'inspDept', |
| | | label: 'é¨é¨id', |
| | | dependencies: { |
| | | show: () => false, |
| | | triggerFields: [''] |
| | | } |
| | | }, |
| | | // { |
| | | // component: 'InputNumber', |
| | | // fieldName: 'inspCycle', |
| | | // label: 'ç¹æ£å¨æ', |
| | | // formItemClass: 'col-span-1', |
| | | // componentProps: { |
| | | // min: 1 |
| | | // } |
| | | // }, |
| | | // { |
| | | // component: 'Select', |
| | | // componentProps: { |
| | | // getPopupContainer, |
| | | // options: getDictOptions(DictEnum.MAINT_CYCLE_UNIT) |
| | | // }, |
| | | // fieldName: 'inspCycleUnit', |
| | | // formItemClass: 'col-span-1 w-[80px]', |
| | | // labelWidth: 0, |
| | | // label: '' |
| | | // }, |
| | | // |
| | | // { |
| | | // component: 'Select', |
| | | // componentProps: { |
| | | // getPopupContainer, |
| | | // options: getDictOptions(DictEnum.MAINT_TIME_RULE) |
| | | // }, |
| | | // fieldName: 'inspRule', |
| | | // label: 'ç¹æ£è§å ' |
| | | // }, |
| | | // { |
| | | // component: 'Input', |
| | | // fieldName: 'inspUser', |
| | | // label: 'ç¨æ·id', |
| | | // dependencies: { |
| | | // show: () => false, |
| | | // triggerFields: [''] |
| | | // } |
| | | // }, |
| | | // { |
| | | // component: 'Input', |
| | | // fieldName: 'inspUserName', |
| | | // label: 'ç¹æ£äºº' |
| | | // }, |
| | | // { |
| | | // component: 'Input', |
| | | // fieldName: 'inspDept', |
| | | // label: 'é¨é¨id', |
| | | // dependencies: { |
| | | // show: () => false, |
| | | // triggerFields: [''] |
| | | // } |
| | | // }, |
| | | { |
| | | component: 'RadioGroup', |
| | | componentProps: { |
| | |
| | | defaultValue: '0', |
| | | label: 'ç¶æ' |
| | | }, |
| | | { |
| | | component: 'DatePicker', |
| | | componentProps: { |
| | | format: 'YYYY-MM-DD', |
| | | showTime: false, |
| | | valueFormat: 'YYYY-MM-DD', |
| | | getPopupContainer |
| | | }, |
| | | fieldName: 'inspFirstTime', |
| | | label: '馿¬¡ç¹æ£æ¶é´' |
| | | }, |
| | | { |
| | | component: 'DatePicker', |
| | | componentProps: { |
| | | format: 'YYYY-MM-DD', |
| | | showTime: false, |
| | | valueFormat: 'YYYY-MM-DD', |
| | | getPopupContainer |
| | | }, |
| | | fieldName: 'inspLastTime', |
| | | label: '䏿¬¡ç¹æ£æ¶é´' |
| | | }, |
| | | { |
| | | component: 'DatePicker', |
| | | componentProps: { |
| | | format: 'YYYY-MM-DD', |
| | | showTime: false, |
| | | valueFormat: 'YYYY-MM-DD', |
| | | getPopupContainer |
| | | }, |
| | | fieldName: 'inspNextTime', |
| | | label: '䏿¬¡ç¹æ£æ¶é´', |
| | | }, |
| | | // { |
| | | // component: 'DatePicker', |
| | | // componentProps: { |
| | | // format: 'YYYY-MM-DD', |
| | | // showTime: false, |
| | | // valueFormat: 'YYYY-MM-DD', |
| | | // getPopupContainer |
| | | // }, |
| | | // fieldName: 'inspFirstTime', |
| | | // label: '馿¬¡ç¹æ£æ¶é´' |
| | | // }, |
| | | // { |
| | | // component: 'DatePicker', |
| | | // componentProps: { |
| | | // format: 'YYYY-MM-DD', |
| | | // showTime: false, |
| | | // valueFormat: 'YYYY-MM-DD', |
| | | // getPopupContainer |
| | | // }, |
| | | // fieldName: 'inspLastTime', |
| | | // label: '䏿¬¡ç¹æ£æ¶é´' |
| | | // }, |
| | | // { |
| | | // component: 'DatePicker', |
| | | // componentProps: { |
| | | // format: 'YYYY-MM-DD', |
| | | // showTime: false, |
| | | // valueFormat: 'YYYY-MM-DD', |
| | | // getPopupContainer |
| | | // }, |
| | | // fieldName: 'inspNextTime', |
| | | // label: '䏿¬¡ç¹æ£æ¶é´', |
| | | // }, |
| | | { |
| | | component: 'Textarea', |
| | | fieldName: 'remark', |
| | |
| | | |
| | | import { onMounted, ref } from 'vue'; |
| | | |
| | | import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui'; |
| | | import { Page, useVbenDrawer, useVbenModal, type VbenFormProps } from '@vben/common-ui'; |
| | | import { $t } from '@vben/locales'; |
| | | import { addFullName, getPopupContainer, getVxePopupContainer } from '@vben/utils'; |
| | | |
| | |
| | | |
| | | import { columns, querySchema } from './data'; |
| | | import inspPlanDrawer from './insp-plan-drawer.vue'; |
| | | import inspPlanImportModal from './insp-plan-import-modal.vue'; |
| | | |
| | | defineExpose({ |
| | | tableSelect |
| | |
| | | const [InspRecordDrawer, inspRecordDrawerApi] = useVbenDrawer({ |
| | | connectedComponent: inspRecordDrawer |
| | | }); |
| | | |
| | | /** |
| | | * 导å
¥ |
| | | */ |
| | | const [InspPlanImportModal, inspPlanImportModalApi] = useVbenModal({ |
| | | connectedComponent: inspPlanImportModal |
| | | }); |
| | | |
| | | function handleImport() { |
| | | inspPlanImportModalApi.open(); |
| | | } |
| | | |
| | | function handleAdd() { |
| | | inspPlanDrawerApi.setData({}); |
| | |
| | | <a-button v-access:code="['eims:inspectPlan:export']" @click="handleDownloadExcel"> |
| | | {{ $t('pages.common.export') }} |
| | | </a-button> |
| | | <a-button v-access:code="['eims:inspectPlan:import']" @click="handleImport"> |
| | | {{ $t('pages.common.import') }} |
| | | </a-button> |
| | | <a-button |
| | | :disabled="!vxeCheckboxChecked(tableApi)" |
| | | danger |
| | |
| | | </div> |
| | | <InspPlanDrawer @reload="tableApi.query()" /> |
| | | <InspRecordDrawer @reload="tableApi.query()" /> |
| | | <InspPlanImportModal @reload="tableApi.query()" /> |
| | | </Page> |
| | | </template> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <script setup lang="ts"> |
| | | import type { UploadFile } from 'ant-design-vue/es/upload/interface'; |
| | | |
| | | import { h, ref, unref } from 'vue'; |
| | | |
| | | import { useVbenModal } from '@vben/common-ui'; |
| | | import { ExcelIcon, InBoxIcon } from '@vben/icons'; |
| | | |
| | | import { Modal, Switch, Upload } from 'ant-design-vue'; |
| | | |
| | | import { downloadImportTemplate, inspPlanImportData } from '#/api/eims/insp-plan'; |
| | | import { commonDownloadExcel } from '#/utils/file/download'; |
| | | |
| | | const emit = defineEmits<{ reload: [] }>(); |
| | | |
| | | const UploadDragger = Upload.Dragger; |
| | | |
| | | const [BasicModal, modalApi] = useVbenModal({ |
| | | onCancel: handleCancel, |
| | | onConfirm: handleSubmit, |
| | | }); |
| | | |
| | | const fileList = ref<UploadFile[]>([]); |
| | | const checked = ref(false); |
| | | |
| | | async function handleSubmit() { |
| | | try { |
| | | modalApi.modalLoading(true); |
| | | if (fileList.value.length !== 1) { |
| | | handleCancel(); |
| | | return; |
| | | } |
| | | const data = { |
| | | file: fileList.value[0]!.originFileObj as Blob, |
| | | updateSupport: unref(checked), |
| | | }; |
| | | const { code, msg } = await inspPlanImportData(data); |
| | | let modal = Modal.success; |
| | | if (code === 200) { |
| | | emit('reload'); |
| | | } else { |
| | | emit('reload'); |
| | | modal = Modal.error; |
| | | } |
| | | handleCancel(); |
| | | modal({ |
| | | content: h('div', { |
| | | class: 'max-h-[260px] overflow-y-auto', |
| | | innerHTML: msg, // åå°å·²ç»å¤çxssé®é¢ |
| | | }), |
| | | title: 'æç¤º', |
| | | }); |
| | | } catch (error) { |
| | | console.warn(error); |
| | | modalApi.close(); |
| | | } finally { |
| | | modalApi.modalLoading(false); |
| | | } |
| | | } |
| | | |
| | | function handleCancel() { |
| | | modalApi.close(); |
| | | fileList.value = []; |
| | | checked.value = false; |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <BasicModal |
| | | :close-on-click-modal="false" |
| | | :fullscreen-button="false" |
| | | title="ç¹æ£è®¡å导å
¥" |
| | | > |
| | | <!-- z-indexä¸è®¾ç½®ä¼é®æ¡æ¨¡æ¿ä¸è½½loading --> |
| | | <!-- æå¨å¤ç è䏿¯æ¾å
¥æä»¶å°±ä¸ä¼ --> |
| | | <UploadDragger |
| | | v-model:file-list="fileList" |
| | | :before-upload="() => false" |
| | | :max-count="1" |
| | | :show-upload-list="true" |
| | | accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" |
| | | > |
| | | <p class="ant-upload-drag-icon flex items-center justify-center"> |
| | | <InBoxIcon class="text-primary size-[48px]" /> |
| | | </p> |
| | | <p class="ant-upload-text">ç¹å»æè
ææ½å°æ¤å¤ä¸ä¼ æä»¶</p> |
| | | </UploadDragger> |
| | | <div class="mt-2 flex flex-col gap-2"> |
| | | <div class="flex items-center gap-2"> |
| | | <span>å
许导å
¥xlsx, xlsæä»¶</span> |
| | | <a-button |
| | | type="link" |
| | | @click="commonDownloadExcel(downloadImportTemplate, 'ç¹æ£è®¡å导å
¥æ¨¡æ¿')" |
| | | > |
| | | <div class="flex items-center gap-[4px]"> |
| | | <ExcelIcon /> |
| | | <span>ä¸è½½æ¨¡æ¿</span> |
| | | </div> |
| | | </a-button> |
| | | </div> |
| | | <div class="flex items-center gap-2"> |
| | | <span class="text-red-500">â ï¸ç¹å«æ³¨æâ ï¸ï¼è¯·ä¸è½½æ¨¡çä¿æå¯¼å
¥æä»¶è¡¨å¤´å模çä¸è´å导å
¥</span> |
| | | </div> |
| | | <!-- <div class="flex items-center gap-2">--> |
| | | <!-- <span :class="{ 'text-red-500': checked }">--> |
| | | <!-- æ¯å¦æ´æ°/è¦çå·²åå¨çç¹æ£è®¡åæ°æ®--> |
| | | <!-- </span>--> |
| | | <!-- <Switch v-model:checked="checked" />--> |
| | | <!-- </div>--> |
| | | </div> |
| | | </BasicModal> |
| | | </template> |
| | |
| | | |
| | | import { onMounted, ref } from 'vue'; |
| | | |
| | | import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui'; |
| | | import { Page, useVbenDrawer, useVbenModal, type VbenFormProps } from '@vben/common-ui'; |
| | | import { $t } from '@vben/locales'; |
| | | import { addFullName, getPopupContainer, getVxePopupContainer } from '@vben/utils'; |
| | | |
| | |
| | | |
| | | import { columns, querySchema } from './data'; |
| | | import maintPlanDrawer from './maint-plan-drawer.vue'; |
| | | import maintPlanImportModal from './maint-plan-import-modal.vue'; |
| | | |
| | | |
| | | defineExpose({ |
| | |
| | | const [MaintOrderDrawer, maintOrderDrawerApi] = useVbenDrawer({ |
| | | connectedComponent: maintOrderDrawer, |
| | | }); |
| | | |
| | | /** |
| | | * 导å
¥ |
| | | */ |
| | | const [MaintPlanImportModal, maintPlanImportModalApi] = useVbenModal({ |
| | | connectedComponent: maintPlanImportModal |
| | | }); |
| | | |
| | | function handleImport() { |
| | | maintPlanImportModalApi.open(); |
| | | } |
| | | |
| | | function handleAdd() { |
| | | maintPlanDrawerApi.setData({}); |
| | |
| | | <a-button v-access:code="['eims:maintPlan:export']" @click="handleDownloadExcel"> |
| | | {{ $t('pages.common.export') }} |
| | | </a-button> |
| | | <a-button v-access:code="['eims:maintPlan:import']" @click="handleImport"> |
| | | {{ $t('pages.common.import') }} |
| | | </a-button> |
| | | <a-button |
| | | :disabled="!vxeCheckboxChecked(tableApi)" |
| | | danger |
| | |
| | | </div> |
| | | <MaintPlanDrawer @reload="tableApi.query()" /> |
| | | <MaintOrderDrawer @reload="tableApi.query()" /> |
| | | <MaintPlanImportModal @reload="tableApi.query()" /> |
| | | </Page> |
| | | </template> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <script setup lang="ts"> |
| | | import type { UploadFile } from 'ant-design-vue/es/upload/interface'; |
| | | |
| | | import { h, ref, unref } from 'vue'; |
| | | |
| | | import { useVbenModal } from '@vben/common-ui'; |
| | | import { ExcelIcon, InBoxIcon } from '@vben/icons'; |
| | | |
| | | import { Modal, Switch, Upload } from 'ant-design-vue'; |
| | | |
| | | import { downloadImportTemplate, maintPlanImportData } from '#/api/eims/maint-plan'; |
| | | import { commonDownloadExcel } from '#/utils/file/download'; |
| | | |
| | | const emit = defineEmits<{ reload: [] }>(); |
| | | |
| | | const UploadDragger = Upload.Dragger; |
| | | |
| | | const [BasicModal, modalApi] = useVbenModal({ |
| | | onCancel: handleCancel, |
| | | onConfirm: handleSubmit, |
| | | }); |
| | | |
| | | const fileList = ref<UploadFile[]>([]); |
| | | const checked = ref(false); |
| | | |
| | | async function handleSubmit() { |
| | | try { |
| | | modalApi.modalLoading(true); |
| | | if (fileList.value.length !== 1) { |
| | | handleCancel(); |
| | | return; |
| | | } |
| | | const data = { |
| | | file: fileList.value[0]!.originFileObj as Blob, |
| | | updateSupport: unref(checked), |
| | | }; |
| | | const { code, msg } = await maintPlanImportData(data); |
| | | let modal = Modal.success; |
| | | if (code === 200) { |
| | | emit('reload'); |
| | | } else { |
| | | emit('reload'); |
| | | modal = Modal.error; |
| | | } |
| | | handleCancel(); |
| | | modal({ |
| | | content: h('div', { |
| | | class: 'max-h-[260px] overflow-y-auto', |
| | | innerHTML: msg, // åå°å·²ç»å¤çxssé®é¢ |
| | | }), |
| | | title: 'æç¤º', |
| | | }); |
| | | } catch (error) { |
| | | console.warn(error); |
| | | modalApi.close(); |
| | | } finally { |
| | | modalApi.modalLoading(false); |
| | | } |
| | | } |
| | | |
| | | function handleCancel() { |
| | | modalApi.close(); |
| | | fileList.value = []; |
| | | checked.value = false; |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <BasicModal |
| | | :close-on-click-modal="false" |
| | | :fullscreen-button="false" |
| | | title="ä¿å
»è®¡å导å
¥" |
| | | > |
| | | <!-- z-indexä¸è®¾ç½®ä¼é®æ¡æ¨¡æ¿ä¸è½½loading --> |
| | | <!-- æå¨å¤ç è䏿¯æ¾å
¥æä»¶å°±ä¸ä¼ --> |
| | | <UploadDragger |
| | | v-model:file-list="fileList" |
| | | :before-upload="() => false" |
| | | :max-count="1" |
| | | :show-upload-list="true" |
| | | accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" |
| | | > |
| | | <p class="ant-upload-drag-icon flex items-center justify-center"> |
| | | <InBoxIcon class="text-primary size-[48px]" /> |
| | | </p> |
| | | <p class="ant-upload-text">ç¹å»æè
ææ½å°æ¤å¤ä¸ä¼ æä»¶</p> |
| | | </UploadDragger> |
| | | <div class="mt-2 flex flex-col gap-2"> |
| | | <div class="flex items-center gap-2"> |
| | | <span>å
许导å
¥xlsx, xlsæä»¶</span> |
| | | <a-button |
| | | type="link" |
| | | @click="commonDownloadExcel(downloadImportTemplate, 'ä¿å
»è®¡å导å
¥æ¨¡æ¿')" |
| | | > |
| | | <div class="flex items-center gap-[4px]"> |
| | | <ExcelIcon /> |
| | | <span>ä¸è½½æ¨¡æ¿</span> |
| | | </div> |
| | | </a-button> |
| | | </div> |
| | | <div class="flex items-center gap-2"> |
| | | <span class="text-red-500">â ï¸ç¹å«æ³¨æâ ï¸ï¼è¯·ä¸è½½æ¨¡çä¿æå¯¼å
¥æä»¶è¡¨å¤´å模çä¸è´å导å
¥</span> |
| | | </div> |
| | | <!-- <div class="flex items-center gap-2">--> |
| | | <!-- <span :class="{ 'text-red-500': checked }">--> |
| | | <!-- æ¯å¦æ´æ°/è¦çå·²åå¨çä¿å
»è®¡åæ°æ®--> |
| | | <!-- </span>--> |
| | | <!-- <Switch v-model:checked="checked" />--> |
| | | <!-- </div>--> |
| | | </div> |
| | | </BasicModal> |
| | | </template> |
| | |
| | | package org.dromara.eims.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import lombok.RequiredArgsConstructor; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.constraints.*; |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.dromara.common.idempotent.annotation.RepeatSubmit; |
| | |
| | | import org.dromara.eims.domain.bo.EimsInspectPlanBo; |
| | | import org.dromara.eims.service.IEimsInspectPlanService; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * ç¹æ£è®¡å |
| | |
| | | @PathVariable Long[] ids) { |
| | | return toAjax(eimsInspectPlanService.deleteWithValidByIds(List.of(ids), true)); |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥æ°æ® |
| | | * |
| | | * @param file 导å
¥æä»¶ |
| | | * @param updateSupport æ¯å¦æ´æ°å·²å卿°æ® |
| | | */ |
| | | @Log(title = "ç¹æ£è®¡å", businessType = BusinessType.IMPORT) |
| | | @SaCheckPermission("eims:inspectPlan:import") |
| | | @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { |
| | | // ExcelResult<InspectCheckItemVo> result = ExcelUtil.importExcel(file.getInputStream(), InspectCheckItemVo.class, new InspectCheckItemImportListener(updateSupport)); |
| | | String res = eimsInspectPlanService.importData(file, updateSupport); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | | * è·å导å
¥æ¨¡æ¿ |
| | | */ |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) throws UnsupportedEncodingException { |
| | | // 设置ååºç±»å |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | |
| | | // 设置æä»¶å |
| | | String fileName = URLEncoder.encode("ç¹æ£è®¡å导å
¥æ¨¡æ¿", "UTF-8"); |
| | | response.setHeader("Content-Disposition", |
| | | "attachment;filename=" + fileName + ".xlsx"); |
| | | |
| | | // è¯»åæ¨¡æ¿æä»¶ |
| | | ClassPathResource templateResource = new ClassPathResource("template/dj.xlsx"); |
| | | try (InputStream inputStream = templateResource.getInputStream(); |
| | | ServletOutputStream outputStream = response.getOutputStream()) { |
| | | |
| | | // æµæ·è´ |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("æ¨¡æ¿æä»¶è¯»å失败", e); |
| | | } |
| | | } |
| | | } |
| | |
| | | package org.dromara.eims.controller; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.net.URLEncoder; |
| | | import java.util.List; |
| | | |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import lombok.RequiredArgsConstructor; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import jakarta.validation.constraints.*; |
| | | import cn.dev33.satoken.annotation.SaCheckPermission; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.validation.annotation.Validated; |
| | | import org.dromara.common.idempotent.annotation.RepeatSubmit; |
| | |
| | | import org.dromara.eims.domain.bo.EimsMaintPlanBo; |
| | | import org.dromara.eims.service.IEimsMaintPlanService; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | /** |
| | | * ä¿å
»è®¡å |
| | |
| | | @PathVariable Long[] ids) { |
| | | return toAjax(eimsMaintPlanService.deleteWithValidByIds(List.of(ids), true)); |
| | | } |
| | | |
| | | /** |
| | | * 导å
¥æ°æ® |
| | | * |
| | | * @param file 导å
¥æä»¶ |
| | | * @param updateSupport æ¯å¦æ´æ°å·²å卿°æ® |
| | | */ |
| | | @Log(title = "ä¿å
»è®¡å", businessType = BusinessType.IMPORT) |
| | | @SaCheckPermission("eims:maintPlan:import") |
| | | @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| | | public R<Void> importData(@RequestPart("file") MultipartFile file, boolean updateSupport) throws Exception { |
| | | //ExcelResult<MaintCheckItemVo> result = ExcelUtil.importExcel(file.getInputStream(), MaintCheckItemVo.class, new MaintCheckItemImportListener(updateSupport)); |
| | | |
| | | |
| | | String res = eimsMaintPlanService.importData(file, updateSupport); |
| | | |
| | | return R.ok(res); |
| | | } |
| | | |
| | | /** |
| | | * è·å导å
¥æ¨¡æ¿ |
| | | */ |
| | | @PostMapping("/importTemplate") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 设置ååºç±»å |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); |
| | | response.setCharacterEncoding("utf-8"); |
| | | |
| | | // 设置æä»¶å |
| | | String fileName = URLEncoder.encode("ä¿å
»è®¡å导å
¥æ¨¡æ¿", "UTF-8"); |
| | | response.setHeader("Content-Disposition", |
| | | "attachment;filename=" + fileName + ".xls"); |
| | | |
| | | // è¯»åæ¨¡æ¿æä»¶ |
| | | ClassPathResource templateResource = new ClassPathResource("template/by.xls"); |
| | | try (InputStream inputStream = templateResource.getInputStream(); |
| | | ServletOutputStream outputStream = response.getOutputStream()) { |
| | | |
| | | // æµæ·è´ |
| | | byte[] buffer = new byte[1024]; |
| | | int bytesRead; |
| | | while ((bytesRead = inputStream.read(buffer)) != -1) { |
| | | outputStream.write(buffer, 0, bytesRead); |
| | | } |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("æ¨¡æ¿æä»¶è¯»å失败", e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.eims.domain.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import lombok.Data; |
| | | import lombok.NoArgsConstructor; |
| | | import org.dromara.common.excel.annotation.ExcelDictFormat; |
| | | import org.dromara.common.excel.convert.ExcelDictConvert; |
| | | |
| | | import java.io.Serial; |
| | | import java.io.Serializable; |
| | | |
| | | /** |
| | | * ç¹æ£é¡¹ç®å¯¼å
¥VO |
| | | * |
| | | * @author zhuguifei |
| | | */ |
| | | @Data |
| | | @NoArgsConstructor |
| | | public class InspectCheckItemVo implements Serializable { |
| | | @Serial |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | |
| | | |
| | | /** |
| | | * ç¹æ£é¡¹åç§° |
| | | */ |
| | | @ExcelProperty(value = "å
容") |
| | | private String itemName; |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.eims.domain.vo; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * ä¿å
»ç¹æ£é¡¹ç®å®ä½ |
| | | */ |
| | | @Data |
| | | public class MaintCheckItemVo { |
| | | |
| | | /** |
| | | * 宿½é¡¹ç® |
| | | */ |
| | | @ExcelProperty("宿½é¡¹ç®") |
| | | private String itemName; |
| | | |
| | | /** |
| | | * å¨æï¼æï¼ |
| | | */ |
| | | @ExcelProperty("卿") |
| | | private String period; |
| | | |
| | | /** |
| | | * 1ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("1æ") |
| | | private String january; |
| | | |
| | | /** |
| | | * 2ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("2æ") |
| | | private String february; |
| | | |
| | | /** |
| | | * 3ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("3æ") |
| | | private String march; |
| | | |
| | | /** |
| | | * 4ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("4æ") |
| | | private String april; |
| | | |
| | | /** |
| | | * 5ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("5æ") |
| | | private String may; |
| | | |
| | | /** |
| | | * 6ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("6æ") |
| | | private String june; |
| | | |
| | | /** |
| | | * 7ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("7æ") |
| | | private String july; |
| | | |
| | | /** |
| | | * 8ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("8æ") |
| | | private String august; |
| | | |
| | | /** |
| | | * 9ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("9æ") |
| | | private String september; |
| | | |
| | | /** |
| | | * 10ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("10æ") |
| | | private String october; |
| | | |
| | | /** |
| | | * 11ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("11æ") |
| | | private String november; |
| | | |
| | | /** |
| | | * 12ææ£æ¥ç¶æ |
| | | */ |
| | | @ExcelProperty("12æ") |
| | | private String december; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.eims.listener; |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.read.listener.ReadListener; |
| | | |
| | | import java.util.Map; |
| | | |
| | | public class EasyExcelCellListener implements ReadListener<Map<Integer,String>> { |
| | | |
| | | private String cellValue; |
| | | private int targetRow; |
| | | private int targetColumn; |
| | | |
| | | private boolean isCellRead = false; |
| | | |
| | | public EasyExcelCellListener(int targetRow, int targetColumn) { |
| | | this.targetRow = targetRow; |
| | | this.targetColumn = targetColumn; |
| | | } |
| | | |
| | | @Override |
| | | //invokeæ¹æ³çåæ°ç±»åè·éå®ç°çReadListenerçç±»å |
| | | public void invoke(Map<Integer,String> map, AnalysisContext analysisContext) { |
| | | if(isCellRead){ |
| | | return; |
| | | } |
| | | int currentRow = analysisContext.readRowHolder().getRowIndex()+1; |
| | | if(currentRow == targetRow ){ |
| | | cellValue = map.get(targetColumn-1); |
| | | isCellRead = true; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | |
| | | } |
| | | |
| | | public String getCellValue() { |
| | | return cellValue; |
| | | } |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.eims.listener; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import com.alibaba.excel.exception.ExcelDataConvertException; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.core.service.DictService; |
| | | import org.dromara.common.core.utils.SpringUtils; |
| | | import org.dromara.common.excel.core.ExcelListener; |
| | | import org.dromara.common.excel.core.ExcelResult; |
| | | import org.dromara.common.satoken.utils.LoginHelper; |
| | | import org.dromara.eims.domain.vo.EimsEquVo; |
| | | import org.dromara.eims.domain.vo.InspectCheckItemVo; |
| | | import org.dromara.eims.service.IEimsEquService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ç¹æ£é¡¹ç®å¯¼å
¥çå¬å¨ |
| | | * |
| | | * @author zhuguifei |
| | | */ |
| | | @Data |
| | | @Slf4j |
| | | public class InspectCheckItemImportListener extends AnalysisEventListener<InspectCheckItemVo> implements ExcelListener<InspectCheckItemVo> { |
| | | |
| | | private final IEimsEquService equService; |
| | | private final DictService dictService; |
| | | private final Long operUserId; |
| | | private final Boolean isUpdateSupport; |
| | | |
| | | /** |
| | | * æåæ¡æ° |
| | | */ |
| | | private Integer successCount = 0; |
| | | |
| | | /** |
| | | * å¤±è´¥æ¡æ° |
| | | */ |
| | | private Integer failureCount = 0; |
| | | |
| | | /** |
| | | * 导å
¥æåæ°æ®å表 |
| | | */ |
| | | private List<InspectCheckItemVo> successList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 导å
¥å¤±è´¥æ°æ®å表 |
| | | */ |
| | | private List<InspectCheckItemVo> failureList = new ArrayList<>(); |
| | | |
| | | private final StringBuilder successMsg = new StringBuilder(); |
| | | private final StringBuilder failureMsg = new StringBuilder(); |
| | | |
| | | public InspectCheckItemImportListener(Boolean isUpdateSupport) { |
| | | this.equService = SpringUtils.getBean(IEimsEquService.class); |
| | | this.dictService = SpringUtils.getBean(DictService.class); |
| | | this.isUpdateSupport = isUpdateSupport; |
| | | this.operUserId = LoginHelper.getUserId(); |
| | | } |
| | | |
| | | @Override |
| | | public void invoke(InspectCheckItemVo data, AnalysisContext context) { |
| | | try { |
| | | // æ°æ®æ ¡éª |
| | | if (!validateData(data)) { |
| | | failureList.add(data); |
| | | failureCount++; |
| | | failureMsg.append("<br/>").append(failureCount).append("ãç¹æ£é¡¹ ") |
| | | .append(data.getItemName()).append(" æ°æ®æ ¡éªå¤±è´¥"); |
| | | return; |
| | | } |
| | | |
| | | |
| | | successList.add(data); |
| | | successCount++; |
| | | successMsg.append("<br/>").append(successCount).append("ãç¹æ£é¡¹ ") |
| | | .append(data.getItemName()).append(" 导å
¥æå"); |
| | | |
| | | } catch (Exception e) { |
| | | failureList.add(data); |
| | | failureCount++; |
| | | String msg = "<br/>" + failureCount + "ãç¹æ£é¡¹ " + data.getItemName() + " 导å
¥å¤±è´¥ï¼"; |
| | | failureMsg.append(msg).append(e.getMessage()); |
| | | log.error("导å
¥ç¹æ£é¡¹ç®å¤±è´¥ï¼", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | log.info("ç¹æ£é¡¹ç®å¯¼å
¥å®æï¼æåï¼{}æ¡ï¼å¤±è´¥ï¼{}æ¡", successCount, failureCount); |
| | | } |
| | | |
| | | @Override |
| | | public void onException(Exception exception, AnalysisContext context) throws Exception { |
| | | log.error("导å
¥å¼å¸¸", exception); |
| | | if (exception instanceof ExcelDataConvertException) { |
| | | ExcelDataConvertException e = (ExcelDataConvertException) exception; |
| | | failureMsg.append("<br/>").append("第").append(e.getRowIndex()).append("è¡ï¼ç¬¬").append(e.getColumnIndex()) |
| | | .append("åè§£æå¼å¸¸ï¼").append(e.getCause().getMessage()); |
| | | } else { |
| | | failureMsg.append(exception.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ExcelResult<InspectCheckItemVo> getExcelResult() { |
| | | return new ExcelResult<InspectCheckItemVo>() { |
| | | @Override |
| | | public List<InspectCheckItemVo> getList() { |
| | | return successList; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getErrorList() { |
| | | return List.of(); |
| | | } |
| | | |
| | | @Override |
| | | public String getAnalysis() { |
| | | if (successCount > 0) { |
| | | successMsg.insert(0, "æåæ¨ï¼å
± " + successCount + " æ¡æ°æ®å¯¼å
¥æåï¼"); |
| | | } |
| | | if (failureCount > 0) { |
| | | failureMsg.insert(0, "徿±æï¼å
± " + failureCount + " æ¡æ°æ®å¯¼å
¥å¤±è´¥ï¼"); |
| | | } |
| | | return successMsg + failureMsg.toString(); |
| | | } |
| | | }; |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ°æ® |
| | | * |
| | | * @param data å¾
æ ¡éªæ°æ® |
| | | * @return æ ¡éªç»æ |
| | | */ |
| | | private boolean validateData(InspectCheckItemVo data) { |
| | | if (data.getItemName() == null || data.getItemName().trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | return true; |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.dromara.eims.listener; |
| | | |
| | | import com.alibaba.excel.context.AnalysisContext; |
| | | import com.alibaba.excel.event.AnalysisEventListener; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.dromara.common.excel.core.ExcelListener; |
| | | import org.dromara.common.excel.core.ExcelResult; |
| | | import org.dromara.eims.domain.vo.MaintCheckItemVo; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * ä¿å
»ç¹æ£é¡¹ç®å¯¼å
¥çå¬å¨ |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Data |
| | | @Slf4j |
| | | public class MaintCheckItemImportListener extends AnalysisEventListener<MaintCheckItemVo> implements ExcelListener<MaintCheckItemVo> { |
| | | |
| | | /** |
| | | * æåæ¡æ° |
| | | */ |
| | | private Integer successCount = 0; |
| | | |
| | | /** |
| | | * å¤±è´¥æ¡æ° |
| | | */ |
| | | private Integer failureCount = 0; |
| | | |
| | | /** |
| | | * 导å
¥æåæ°æ®å表 |
| | | */ |
| | | private List<MaintCheckItemVo> successList = new ArrayList<>(); |
| | | |
| | | /** |
| | | * 导å
¥å¤±è´¥æ°æ®å表 |
| | | */ |
| | | private List<MaintCheckItemVo> failureList = new ArrayList<>(); |
| | | |
| | | public MaintCheckItemImportListener(Boolean isUpdateSupport) { |
| | | super(); |
| | | } |
| | | |
| | | @Override |
| | | public void invoke(MaintCheckItemVo data, AnalysisContext context) { |
| | | try { |
| | | // æ°æ®æ ¡éª |
| | | if (!validateData(data)) { |
| | | failureList.add(data); |
| | | failureCount++; |
| | | return; |
| | | } |
| | | successList.add(data); |
| | | successCount++; |
| | | } catch (Exception e) { |
| | | failureList.add(data); |
| | | failureCount++; |
| | | log.error("导å
¥ä¿å
»ç¹æ£é¡¹ç®å¤±è´¥ï¼", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext context) { |
| | | log.info("ä¿å
»ç¹æ£é¡¹ç®å¯¼å
¥å®æï¼æåï¼{}æ¡ï¼å¤±è´¥ï¼{}æ¡", successCount, failureCount); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ°æ® |
| | | * |
| | | * @param data å¾
æ ¡éªæ°æ® |
| | | * @return æ ¡éªç»æ |
| | | */ |
| | | private boolean validateData(MaintCheckItemVo data) { |
| | | if (data.getItemName() == null || data.getItemName().trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | if (data.getPeriod() == null || data.getPeriod().trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | // æ ¡éª1-12æä»½ç¶æå¼ |
| | | return validateMonthStatus(data.getJanuary()) |
| | | && validateMonthStatus(data.getFebruary()) |
| | | && validateMonthStatus(data.getMarch()) |
| | | && validateMonthStatus(data.getApril()) |
| | | && validateMonthStatus(data.getMay()) |
| | | && validateMonthStatus(data.getJune()) |
| | | && validateMonthStatus(data.getJuly()) |
| | | && validateMonthStatus(data.getAugust()) |
| | | && validateMonthStatus(data.getSeptember()) |
| | | && validateMonthStatus(data.getOctober()) |
| | | && validateMonthStatus(data.getNovember()) |
| | | && validateMonthStatus(data.getDecember()); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæä»½ç¶æå¼ |
| | | * |
| | | * @param status ç¶æå¼ |
| | | * @return æ ¡éªç»æ |
| | | */ |
| | | private boolean validateMonthStatus(String status) { |
| | | // ç¶æå¼å¯ä»¥ä¸ºç©º |
| | | if (status == null || status.trim().isEmpty()) { |
| | | return true; |
| | | } |
| | | // ç¶æå¼å¿
须符åè§èï¼æ ¹æ®å®é
ä¸å¡éæ±å®ä¹ææçç¶æå¼ï¼ |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public ExcelResult<MaintCheckItemVo> getExcelResult() { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | import org.dromara.eims.domain.bo.EimsInspectPlanBo; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | TableDataInfo<EimsInspectPlanVo> queryPageListCustom(EimsInspectPlanBo bo, PageQuery pageQuery); |
| | | |
| | | String importData(MultipartFile file, boolean updateSupport) throws IOException; |
| | | } |
| | |
| | | import org.dromara.eims.domain.bo.EimsMaintPlanBo; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | | import org.dromara.common.mybatis.core.page.PageQuery; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | |
| | |
| | | * @return ä¿å
»è®¡åå页å表 |
| | | */ |
| | | TableDataInfo<EimsMaintPlanVo> queryPageListCustom(EimsMaintPlanBo bo, PageQuery pageQuery); |
| | | |
| | | String importData(MultipartFile inputStream, boolean updateSupport) throws IOException; |
| | | } |
| | |
| | | package org.dromara.eims.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.mybatis.core.page.TableDataInfo; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.eims.domain.EimsEqu; |
| | | import org.dromara.eims.domain.vo.EimsEquVo; |
| | | import org.dromara.eims.domain.vo.EimsMaintPlanVo; |
| | | import org.dromara.eims.domain.vo.InspectCheckItemVo; |
| | | import org.dromara.eims.listener.EasyExcelCellListener; |
| | | import org.dromara.eims.listener.InspectCheckItemImportListener; |
| | | import org.dromara.eims.mapper.EimsEquMapper; |
| | | import org.dromara.system.domain.SysDept; |
| | | import org.dromara.system.domain.vo.SysDeptVo; |
| | | import org.dromara.system.mapper.SysDeptMapper; |
| | |
| | | import org.dromara.eims.domain.EimsInspectPlan; |
| | | import org.dromara.eims.mapper.EimsInspectPlanMapper; |
| | | import org.dromara.eims.service.IEimsInspectPlanService; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Collection; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * ç¹æ£è®¡åServiceä¸å¡å±å¤ç |
| | |
| | | |
| | | private final EimsInspectPlanMapper baseMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final EimsEquMapper equMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | return baseMapper.deleteByIds(ids) > 0; |
| | | } |
| | | |
| | | @Override |
| | | public String importData(MultipartFile file, boolean updateSupport) throws IOException, IOException { |
| | | int successNum = 0; |
| | | int failureNum = 0; |
| | | StringBuilder successMsg = new StringBuilder(); |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | |
| | | // ç¹æ£é¡¹ç®å表ï¼å设åå¨å¯¹åºçç¹æ£é¡¹VOï¼ |
| | | InspectCheckItemImportListener checkItemImportListener = new InspectCheckItemImportListener(updateSupport); |
| | | EasyExcel.read(file.getInputStream(), InspectCheckItemVo.class, checkItemImportListener).headRowNumber(3).sheet().doRead(); |
| | | List<InspectCheckItemVo> successList = checkItemImportListener.getSuccessList(); |
| | | |
| | | // 读ååºå®èµäº§ç¼å·ï¼å设ä½ç½®ä¸åï¼ |
| | | EasyExcelCellListener assetNoListener = new EasyExcelCellListener(2, 23); |
| | | EasyExcel.read(file.getInputStream(), assetNoListener).headRowNumber(0).sheet().doReadSync(); |
| | | String assetNo = Optional.ofNullable(assetNoListener.getCellValue()) |
| | | .map(value -> { |
| | | int colonIndex = Math.max(value.indexOf(":"), value.indexOf("ï¼")); // åå¹¶åå·å¤ç |
| | | return colonIndex != -1 ? value.substring(colonIndex + 1) : value; |
| | | }) |
| | | .map(String::trim) |
| | | .orElseThrow(() -> new ServiceException("导å
¥å¤±è´¥ï¼æ æ³è¯»ååºå®èµäº§ç¼å·")); |
| | | |
| | | |
| | | |
| | | // æ¥è¯¢è®¾å¤ä¿¡æ¯ |
| | | QueryWrapper<EimsEqu> query = new QueryWrapper<>(); |
| | | query.eq("asset_no", assetNo); |
| | | EimsEquVo equVo = equMapper.selectVoOne(query); |
| | | if (equVo == null) throw new ServiceException("è®¾å¤æªæ¾å°ï¼è¯·å
å¨è®¾å¤å°å¸ä¸æ·»å "); |
| | | |
| | | |
| | | for (InspectCheckItemVo itemVo : successList) { |
| | | if ("设å¤ç¶æå¡ç¶æ".equals(itemVo.getItemName())) break; |
| | | EimsInspectPlanBo bo = new EimsInspectPlanBo(); |
| | | bo.setEquId(equVo.getEquId()); |
| | | bo.setInspName(itemVo.getItemName()); |
| | | bo.setStatus("0"); |
| | | bo.setInspType("1"); |
| | | bo.setInspRule("0"); |
| | | |
| | | if (!insertByBo(bo)) { |
| | | failureNum++; |
| | | failureMsg.append(failureNum).append("ã导å
¥å¤±è´¥<br>"); |
| | | } else { |
| | | successNum++; |
| | | successMsg.append(successNum).append("ã导å
¥æå<br>"); |
| | | } |
| | | } |
| | | |
| | | return failureNum > 0 ? failureMsg.toString() : successMsg.toString(); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package org.dromara.eims.service.impl; |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.SneakyThrows; |
| | | import org.dromara.common.core.constant.DictConstants; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.utils.DateUtils; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.eims.domain.vo.EimsRepairResVo; |
| | | import org.dromara.eims.domain.EimsEqu; |
| | | import org.dromara.eims.domain.vo.EimsEquVo; |
| | | import org.dromara.eims.domain.vo.MaintCheckItemVo; |
| | | import org.dromara.eims.listener.EasyExcelCellListener; |
| | | import org.dromara.eims.listener.MaintCheckItemImportListener; |
| | | import org.dromara.eims.mapper.EimsEquMapper; |
| | | import org.dromara.system.domain.SysDept; |
| | | import org.dromara.system.domain.vo.SysDeptVo; |
| | | import org.dromara.system.mapper.SysDeptMapper; |
| | |
| | | import org.dromara.eims.domain.EimsMaintPlan; |
| | | import org.dromara.eims.mapper.EimsMaintPlanMapper; |
| | | import org.dromara.eims.service.IEimsMaintPlanService; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | private final EimsMaintPlanMapper baseMapper; |
| | | private final SysDeptMapper sysDeptMapper; |
| | | private final EimsEquMapper equMapper; |
| | | |
| | | /** |
| | | * æ¥è¯¢ä¿å
»è®¡å |
| | |
| | | } |
| | | |
| | | |
| | | public String importData(MultipartFile is, boolean updateSupport) throws IOException { |
| | | int successNum = 0; |
| | | int failureNum = 0; |
| | | StringBuilder successMsg = new StringBuilder(); |
| | | StringBuilder failureMsg = new StringBuilder(); |
| | | |
| | | |
| | | // ä¿å
»é¡¹ç®å表 |
| | | MaintCheckItemImportListener checkItemImportListener = new MaintCheckItemImportListener(updateSupport); |
| | | EasyExcel.read(is.getInputStream(), MaintCheckItemVo.class, checkItemImportListener).headRowNumber(4).sheet().doRead(); |
| | | List<MaintCheckItemVo> successList = checkItemImportListener.getSuccessList(); |
| | | |
| | | |
| | | // 读ååºå®èµäº§ç¼å· |
| | | EasyExcelCellListener readListener = new EasyExcelCellListener(3, 1); |
| | | EasyExcel.read(is.getInputStream(), readListener).headRowNumber(0).sheet().doReadSync(); |
| | | String assetNo = Optional.ofNullable(readListener.getCellValue()) |
| | | .map(value -> { |
| | | int colonIndex = Math.max(value.indexOf(":"), value.indexOf("ï¼")); // åå¹¶åå·å¤ç |
| | | return colonIndex != -1 ? value.substring(colonIndex + 1) : value; |
| | | }) |
| | | .map(String::trim) |
| | | .orElseThrow(() -> new ServiceException("导å
¥å¤±è´¥ï¼æ æ³è¯»ååºå®èµäº§ç¼å·")); |
| | | |
| | | |
| | | |
| | | // 读åä¿å
»è®¡å年份 |
| | | EasyExcelCellListener readYearListener = new EasyExcelCellListener(2, 3); |
| | | EasyExcel.read(is.getInputStream(), readYearListener).headRowNumber(0).sheet().doReadSync(); |
| | | String yearStr = readYearListener.getCellValue(); |
| | | String year = yearStr.replaceAll("[^\\d]", ""); // å»é¤éæ°åå符 |
| | | year = (year.length() == 4) ? year : DateUtils.getDate().substring(0,4); |
| | | |
| | | QueryWrapper<EimsEqu> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("asset_no", assetNo); |
| | | EimsEquVo eimsEquVo = equMapper.selectVoOne(queryWrapper); |
| | | if (eimsEquVo == null) throw new ServiceException("导å
¥å¤±è´¥ï¼è®¾å¤æªæ¾å°è¯·å¨è®¾å¤å°å¸ä¸æ·»å "); |
| | | |
| | | // æä»½å段å¤çä¼å |
| | | String[] monthFields = {"january","february","march","april","may","june", |
| | | "july","august","september","october","november","december"}; |
| | | |
| | | for (MaintCheckItemVo itemVo : successList) { |
| | | if ("æ§è¡äººç¾å".equals(itemVo.getItemName())) break; |
| | | |
| | | EimsMaintPlanBo maintPlanBo = new EimsMaintPlanBo(); |
| | | maintPlanBo.setEquId(eimsEquVo.getEquId()); |
| | | maintPlanBo.setMaintName(itemVo.getItemName()); |
| | | maintPlanBo.setStatus("0"); |
| | | maintPlanBo.setMaintType("1"); |
| | | maintPlanBo.setMaintRule("0"); |
| | | // æ·»å periodæ ¡éª |
| | | String period = itemVo.getPeriod(); |
| | | if (StringUtils.isBlank(period)) { |
| | | failureNum++; |
| | | failureMsg.append(failureNum).append("ã卿忮µä¸ºç©º<br>"); |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | if (period.length() > 1) { |
| | | maintPlanBo.setMaintCycle(Long.parseLong(period.substring(0, period.length() - 1))); |
| | | String substring = period.substring(period.length() - 1); |
| | | // 转æ¢å¨æåä½ï¼M转æ¢ä¸º3ï¼D转æ¢ä¸º1ï¼Y转æ¢ä¸º5ï¼W转æ¢ä¸º2ï¼Q转æ¢ä¸º4 |
| | | switch (substring) { |
| | | case "M": |
| | | substring = "3"; |
| | | break; |
| | | case "D": |
| | | substring = "1"; |
| | | break; |
| | | case "Y": |
| | | substring = "5"; |
| | | break; |
| | | case "W": |
| | | substring = "2"; |
| | | break; |
| | | case "Q": |
| | | substring = "4"; |
| | | break; |
| | | default: |
| | | } |
| | | maintPlanBo.setMaintCycleUnit(substring); |
| | | } else { |
| | | maintPlanBo.setMaintCycle(Long.parseLong(period)); |
| | | maintPlanBo.setMaintCycleUnit(""); |
| | | } |
| | | } catch (NumberFormatException e) { |
| | | failureNum++; |
| | | failureMsg.append(failureNum).append("ãæ æçå¨ææ ¼å¼:").append(period).append("<br>"); |
| | | continue; |
| | | } |
| | | |
| | | // æä»½å¤æä¼å |
| | | for (int i = 0; i < monthFields.length; i++) { |
| | | try { |
| | | String monthValue = (String) MaintCheckItemVo.class |
| | | .getMethod("get" + StringUtils.capitalize(monthFields[i])) |
| | | .invoke(itemVo); |
| | | |
| | | if (StringUtils.isNotBlank(monthValue)) { |
| | | String month = String.format("%02d", i+1); // ä¿è¯ä¸¤ä½æä»½ |
| | | maintPlanBo.setMaintFirstTime(DateUtils.parseDate(year + "-" + month + "-01")); |
| | | break; |
| | | } |
| | | } catch (Exception e) { |
| | | // åå°å¼å¸¸å¤ç |
| | | failureNum++; |
| | | failureMsg.append(failureNum).append("ãæä»½å段访é®å¼å¸¸<br>"); |
| | | continue; |
| | | } |
| | | } |
| | | |
| | | if (maintPlanBo.getMaintFirstTime() != null) { |
| | | Date firstTime = maintPlanBo.getMaintFirstTime(); |
| | | Date nextTime = calcNextTime(firstTime, maintPlanBo.getMaintCycle().intValue(), 1); |
| | | maintPlanBo.setMaintNextTime(nextTime); |
| | | } |
| | | |
| | | if (!insertByBo(maintPlanBo)) { |
| | | failureNum++; |
| | | failureMsg.append(failureNum).append("ã设å¤ï¼").append(eimsEquVo.getEquName()).append("ï¼å¯¼å
¥å¤±è´¥<br>"); |
| | | } else { |
| | | successNum++; |
| | | successMsg.append("<br/>").append(successNum).append("ã设å¤ï¼").append(eimsEquVo.getEquName()).append("ï¼å¯¼å
¥æå"); |
| | | } |
| | | } |
| | | |
| | | if (failureNum > 0) { |
| | | failureMsg.insert(0, "徿±æï¼å¯¼å
¥å¤±è´¥ï¼å
± " + failureNum + " æ¡æ°æ®æ ¼å¼ä¸æ£ç¡®ï¼é误å¦ä¸ï¼"); |
| | | return failureMsg.toString(); |
| | | } else { |
| | | successMsg.insert(0, "æåæ¨ï¼æ°æ®å·²å
¨é¨å¯¼å
¥æåï¼å
± " + successNum + " æ¡ï¼æ°æ®å¦ä¸ï¼"); |
| | | return successMsg.toString(); |
| | | } |
| | | } |
| | | |
| | | |
| | | private Date calcNextTime(Date firstTime, int intervalMonths, int initialOffset) { |
| | | if (intervalMonths <= 0) { |
| | | throw new IllegalArgumentException("Interval months must be positive"); |
| | | } |
| | | if (firstTime == null) { |
| | | throw new IllegalArgumentException("First time cannot be null"); |
| | | } |
| | | |
| | | Date current = new Date(); |
| | | int adjustmentCount = initialOffset; |
| | | |
| | | Date workingDate = (Date) firstTime.clone(); |
| | | while (workingDate.before(current)) { |
| | | adjustmentCount++; |
| | | workingDate = DateUtils.addMonths(workingDate, intervalMonths); |
| | | } |
| | | |
| | | return (Date) workingDate.clone(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |