class.ts 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import { reactive, computed } from 'vue';
  2. import { SelectedFilterPersonInfo } from '@/api/message/person-group';
  3. export enum type {
  4. violationAlarm = 1,
  5. platformStatistics = 2,
  6. personnelStatistics = 3,
  7. }
  8. export enum StatisticType {
  9. none = 0,
  10. week = 1,
  11. month = 2,
  12. year = 4,
  13. custom = 5,
  14. }
  15. export interface finalReportMessage {
  16. configIdList: [] | null;
  17. type: number;
  18. statisticType: StatisticType;
  19. dayOfWeek: number;
  20. monthList: [string];
  21. dayOfMonthList: [string];
  22. pushTimeList: [string];
  23. pushChannel: [];
  24. userGroupList: [];
  25. designatedUserList: [];
  26. customUserList: [];
  27. recipientType: number;
  28. customPushConfigList: finalCustom[];
  29. }
  30. export interface reportMessage {
  31. configIdList: [] | null;
  32. type: number;
  33. statisticType: StatisticType;
  34. dayOfWeek: number;
  35. monthList: [string];
  36. monthAndDayList: [string, string] | any;
  37. dayOfMonthList: [string];
  38. pushTimeList: [string];
  39. pushChannel: [];
  40. userGroupList: any[];
  41. designatedUserList: SelectedFilterPersonInfo[];
  42. customUserList: any;
  43. recipientType: number | undefined;
  44. customPushConfigList: computeCustom[] | any;
  45. }
  46. export interface finalCustom {
  47. // 最终返回给接口的自定义报告类
  48. configId: number | null;
  49. customStartTime: string;
  50. customEndTime: string;
  51. customUserList: SelectedFilterPersonInfo[];
  52. pushTime: string;
  53. recipientType: string;
  54. userGroupList: [];
  55. isDeleted: number;
  56. }
  57. export interface computeCustom {
  58. configId: number | null; // 临时自定义报告类,daterange用于给customStartTime和customEndTime提供计算值,pushDay和pushTime用于给finalPushTime提供计算值
  59. daterange: null;
  60. customStartTime: any;
  61. customEndTime: any;
  62. pushDay: null;
  63. pushTime: null;
  64. finalPushTime: any;
  65. recipientType: string;
  66. userGroupList: [];
  67. customUserList: [];
  68. isDeleted: number;
  69. }
  70. export const createCustomReport = () => {
  71. const newCustomReport = reactive<computeCustom>({
  72. configId: null,
  73. daterange: null,
  74. customStartTime: computed(() =>
  75. newCustomReport.daterange === null ? null : newCustomReport.daterange[0],
  76. ),
  77. customEndTime: computed(() =>
  78. newCustomReport.daterange === null ? null : newCustomReport.daterange[1],
  79. ),
  80. pushDay: null,
  81. pushTime: null,
  82. finalPushTime: computed(() => {
  83. return newCustomReport.pushDay === null || newCustomReport.pushTime === null
  84. ? null
  85. : newCustomReport.pushDay + ' ' + newCustomReport.pushTime;
  86. }),
  87. recipientType: '',
  88. userGroupList: [],
  89. customUserList: [],
  90. isDeleted: 0,
  91. });
  92. return newCustomReport;
  93. };
  94. export const toReportMessage = (form: reportMessage, receivedData: finalReportMessage) => {
  95. form.configIdList = receivedData.configIdList;
  96. form.type = receivedData.type;
  97. form.statisticType = receivedData.statisticType;
  98. form.dayOfWeek = receivedData.dayOfWeek;
  99. form.monthList = receivedData.monthList;
  100. form.dayOfMonthList = receivedData.dayOfMonthList;
  101. form.pushTimeList = receivedData.pushTimeList;
  102. form.pushChannel = receivedData.pushChannel;
  103. form.userGroupList = receivedData.userGroupList?.map((user: any) => user.id);
  104. form.designatedUserList = receivedData.designatedUserList.map((user: any) => ({
  105. id: user.userId,
  106. staffNo: user.userNumber,
  107. realname: user.userNickname,
  108. }));
  109. form.customUserList.value = receivedData.customUserList.map((user: any) => ({
  110. id: user.userId,
  111. staffNo: user.userNumber,
  112. realname: user.userNickname,
  113. }));
  114. form.recipientType = receivedData.recipientType;
  115. form.customPushConfigList = [];
  116. if (receivedData.statisticType === 2) {
  117. form.dayOfMonthList[0] = receivedData.dayOfMonthList[0].toString();
  118. }
  119. if (receivedData.statisticType === 4) {
  120. form.monthAndDayList.length = 0;
  121. form.monthAndDayList?.push(receivedData.monthList[0].toString());
  122. form.monthAndDayList?.push(receivedData.dayOfMonthList[0].toString());
  123. }
  124. if (receivedData.statisticType === 5) {
  125. let tempconfig = {};
  126. let customPushConfigList: any[] = [];
  127. for (let config of receivedData.customPushConfigList) {
  128. tempconfig['configId'] = config.configId;
  129. tempconfig['isDeleted'] = 0;
  130. tempconfig['daterange'] = [
  131. config.customStartTime.split(' ')[0],
  132. config.customEndTime.split(' ')[0],
  133. ];
  134. tempconfig['pushDay'] = config.pushTime.split(' ')[0];
  135. tempconfig['pushTime'] = config.pushTime.split(' ')[1];
  136. tempconfig['recipientType'] = config.recipientType.toString();
  137. tempconfig['userGroupList'] = config.userGroupList;
  138. tempconfig['customUserList'] = config.customUserList.map((user: any) => {
  139. return {
  140. id: user.userId,
  141. staffNo: user.userNumber,
  142. nickname: user.userNickname,
  143. };
  144. });
  145. tempconfig['userGroupList'] = config.userGroupList?.map((user: any) => user.id);
  146. customPushConfigList.push(tempconfig);
  147. tempconfig = {};
  148. }
  149. form.customPushConfigList = customPushConfigList;
  150. for (let customConfig of form.customPushConfigList) {
  151. const finalPushTime = computed(
  152. () => customConfig['pushDay'] + ' ' + customConfig['pushTime'],
  153. );
  154. customConfig['finalPushTime'] = finalPushTime;
  155. const customStartTime = computed(() => customConfig['daterange'][0]);
  156. const customEndTime = computed(() => customConfig['daterange'][1]);
  157. customConfig['customStartTime'] = customStartTime;
  158. customConfig['customEndTime'] = customEndTime;
  159. }
  160. }
  161. };
  162. export const reportMessageToFinal = (form) => {
  163. // 临时表单转为只存在后端需要字段的表单
  164. let tempCustom = {};
  165. let customPushConfigList: any[] = [];
  166. if (form.customPushConfigList.length > 0) {
  167. if (!form.customPushConfigList[0].daterange) {
  168. // 如果有值则表示用户填了自定义的表单
  169. return;
  170. } else {
  171. for (let config of form.customPushConfigList) {
  172. for (let key in config) {
  173. if (key === 'daterange' || key === 'pushDay' || key === 'pushTime') {
  174. continue;
  175. } else if (key === 'finalPushTime') {
  176. tempCustom['pushTime'] = config[key];
  177. } else if (key === 'customUserList') {
  178. tempCustom['customUserList'] = config[key].map((user) => user.id);
  179. } else {
  180. tempCustom[key] = config[key];
  181. }
  182. }
  183. customPushConfigList.push(tempCustom);
  184. tempCustom = {};
  185. }
  186. }
  187. }
  188. return {
  189. configIdList: form.configIdList,
  190. type: form.type,
  191. statisticType: form.statisticType,
  192. dayOfWeek: form.dayOfWeek,
  193. monthList: form.monthList,
  194. dayOfMonthList: form.dayOfMonthList,
  195. pushTimeList: form.pushTimeList,
  196. pushChannel: form.pushChannel,
  197. userGroupList: form.userGroupList?.map((userOrId) => (userOrId.id ? userOrId.id : userOrId)), // 用户对象和id可能会同时存在列表中
  198. recipientType: form.recipientType,
  199. customPushConfigList: customPushConfigList,
  200. designatedUserList: form.designatedUserList.map((user) => user.id), // 只取出id
  201. customUserList: form.customUserList.value?.map((user) => user.id),
  202. };
  203. };