| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import { reactive, computed } from 'vue';
- import { SelectedFilterPersonInfo } from '@/api/message/person-group';
- export enum type {
- violationAlarm = 1,
- platformStatistics = 2,
- personnelStatistics = 3,
- }
- export enum StatisticType {
- none = 0,
- week = 1,
- month = 2,
- year = 4,
- custom = 5,
- }
- export interface finalReportMessage {
- configIdList: [] | null;
- type: number;
- statisticType: StatisticType;
- dayOfWeek: number;
- monthList: [string];
- dayOfMonthList: [string];
- pushTimeList: [string];
- pushChannel: [];
- userGroupList: [];
- designatedUserList: [];
- customUserList: [];
- recipientType: number;
- customPushConfigList: finalCustom[];
- }
- export interface reportMessage {
- configIdList: [] | null;
- type: number;
- statisticType: StatisticType;
- dayOfWeek: number;
- monthList: [string];
- monthAndDayList: [string, string] | any;
- dayOfMonthList: [string];
- pushTimeList: [string];
- pushChannel: [];
- userGroupList: any[];
- designatedUserList: SelectedFilterPersonInfo[];
- customUserList: any;
- recipientType: number | undefined;
- customPushConfigList: computeCustom[] | any;
- }
- export interface finalCustom {
- // 最终返回给接口的自定义报告类
- configId: number | null;
- customStartTime: string;
- customEndTime: string;
- customUserList: SelectedFilterPersonInfo[];
- pushTime: string;
- recipientType: string;
- userGroupList: [];
- isDeleted: number;
- }
- export interface computeCustom {
- configId: number | null; // 临时自定义报告类,daterange用于给customStartTime和customEndTime提供计算值,pushDay和pushTime用于给finalPushTime提供计算值
- daterange: null;
- customStartTime: any;
- customEndTime: any;
- pushDay: null;
- pushTime: null;
- finalPushTime: any;
- recipientType: string;
- userGroupList: [];
- customUserList: [];
- isDeleted: number;
- }
- export const createCustomReport = () => {
- const newCustomReport = reactive<computeCustom>({
- configId: null,
- daterange: null,
- customStartTime: computed(() =>
- newCustomReport.daterange === null ? null : newCustomReport.daterange[0],
- ),
- customEndTime: computed(() =>
- newCustomReport.daterange === null ? null : newCustomReport.daterange[1],
- ),
- pushDay: null,
- pushTime: null,
- finalPushTime: computed(() => {
- return newCustomReport.pushDay === null || newCustomReport.pushTime === null
- ? null
- : newCustomReport.pushDay + ' ' + newCustomReport.pushTime;
- }),
- recipientType: '',
- userGroupList: [],
- customUserList: [],
- isDeleted: 0,
- });
- return newCustomReport;
- };
- export const toReportMessage = (form: reportMessage, receivedData: finalReportMessage) => {
- form.configIdList = receivedData.configIdList;
- form.type = receivedData.type;
- form.statisticType = receivedData.statisticType;
- form.dayOfWeek = receivedData.dayOfWeek;
- form.monthList = receivedData.monthList;
- form.dayOfMonthList = receivedData.dayOfMonthList;
- form.pushTimeList = receivedData.pushTimeList;
- form.pushChannel = receivedData.pushChannel;
- form.userGroupList = receivedData.userGroupList?.map((user: any) => user.id);
- form.designatedUserList = receivedData.designatedUserList.map((user: any) => ({
- id: user.userId,
- staffNo: user.userNumber,
- realname: user.userNickname,
- }));
- form.customUserList.value = receivedData.customUserList.map((user: any) => ({
- id: user.userId,
- staffNo: user.userNumber,
- realname: user.userNickname,
- }));
- form.recipientType = receivedData.recipientType;
- form.customPushConfigList = [];
- if (receivedData.statisticType === 2) {
- form.dayOfMonthList[0] = receivedData.dayOfMonthList[0].toString();
- }
- if (receivedData.statisticType === 4) {
- form.monthAndDayList.length = 0;
- form.monthAndDayList?.push(receivedData.monthList[0].toString());
- form.monthAndDayList?.push(receivedData.dayOfMonthList[0].toString());
- }
- if (receivedData.statisticType === 5) {
- let tempconfig = {};
- let customPushConfigList: any[] = [];
- for (let config of receivedData.customPushConfigList) {
- tempconfig['configId'] = config.configId;
- tempconfig['isDeleted'] = 0;
- tempconfig['daterange'] = [
- config.customStartTime.split(' ')[0],
- config.customEndTime.split(' ')[0],
- ];
- tempconfig['pushDay'] = config.pushTime.split(' ')[0];
- tempconfig['pushTime'] = config.pushTime.split(' ')[1];
- tempconfig['recipientType'] = config.recipientType.toString();
- tempconfig['userGroupList'] = config.userGroupList;
- tempconfig['customUserList'] = config.customUserList.map((user: any) => {
- return {
- id: user.userId,
- staffNo: user.userNumber,
- nickname: user.userNickname,
- };
- });
- tempconfig['userGroupList'] = config.userGroupList?.map((user: any) => user.id);
- customPushConfigList.push(tempconfig);
- tempconfig = {};
- }
- form.customPushConfigList = customPushConfigList;
- for (let customConfig of form.customPushConfigList) {
- const finalPushTime = computed(
- () => customConfig['pushDay'] + ' ' + customConfig['pushTime'],
- );
- customConfig['finalPushTime'] = finalPushTime;
- const customStartTime = computed(() => customConfig['daterange'][0]);
- const customEndTime = computed(() => customConfig['daterange'][1]);
- customConfig['customStartTime'] = customStartTime;
- customConfig['customEndTime'] = customEndTime;
- }
- }
- };
- export const reportMessageToFinal = (form) => {
- // 临时表单转为只存在后端需要字段的表单
- let tempCustom = {};
- let customPushConfigList: any[] = [];
- if (form.customPushConfigList.length > 0) {
- if (!form.customPushConfigList[0].daterange) {
- // 如果有值则表示用户填了自定义的表单
- return;
- } else {
- for (let config of form.customPushConfigList) {
- for (let key in config) {
- if (key === 'daterange' || key === 'pushDay' || key === 'pushTime') {
- continue;
- } else if (key === 'finalPushTime') {
- tempCustom['pushTime'] = config[key];
- } else if (key === 'customUserList') {
- tempCustom['customUserList'] = config[key].map((user) => user.id);
- } else {
- tempCustom[key] = config[key];
- }
- }
- customPushConfigList.push(tempCustom);
- tempCustom = {};
- }
- }
- }
- return {
- configIdList: form.configIdList,
- type: form.type,
- statisticType: form.statisticType,
- dayOfWeek: form.dayOfWeek,
- monthList: form.monthList,
- dayOfMonthList: form.dayOfMonthList,
- pushTimeList: form.pushTimeList,
- pushChannel: form.pushChannel,
- userGroupList: form.userGroupList?.map((userOrId) => (userOrId.id ? userOrId.id : userOrId)), // 用户对象和id可能会同时存在列表中
- recipientType: form.recipientType,
- customPushConfigList: customPushConfigList,
- designatedUserList: form.designatedUserList.map((user) => user.id), // 只取出id
- customUserList: form.customUserList.value?.map((user) => user.id),
- };
- };
|