service.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import BaseService from '@/utils/BaseService';
  2. import { request } from 'umi';
  3. import SystemConst from '@/utils/const';
  4. class Service extends BaseService<TemplateItem> {
  5. public getTypes = () =>
  6. request(`/${SystemConst.API_BASE}/notifier/config/types`, {
  7. method: 'GET',
  8. });
  9. public getMetadata = (type: string, provider: string) =>
  10. request(`${this.uri}/${type}/${provider}/metadata`, {
  11. method: 'GET',
  12. });
  13. public batchInsert = (data: Record<any, any>[]) =>
  14. request(`${this.uri}/_batch`, {
  15. method: 'POST',
  16. data,
  17. });
  18. public getConfigs = (data: any) =>
  19. request(`${SystemConst.API_BASE}/notifier/config/_query`, {
  20. method: 'POST',
  21. data,
  22. });
  23. public getHistoryLog = (templateId: string, data: Record<string, any>) =>
  24. request(`${SystemConst.API_BASE}/notify/history/template/${templateId}/_query`, {
  25. method: 'POST',
  26. data,
  27. });
  28. public debug = (id: string, templateId: string, data: Record<string, any>) =>
  29. request(`${SystemConst.API_BASE}/notifier/${id}/${templateId}/_send`, {
  30. method: 'POST',
  31. data,
  32. });
  33. public sendMessage = (notifierId: string) =>
  34. request(`${SystemConst.API_BASE}/notifier/${notifierId}/_send`, {
  35. method: 'POST',
  36. });
  37. dingTalk = {
  38. getDepartments: (id: string) =>
  39. request(`${SystemConst.API_BASE}/notifier/dingtalk/corp/${id}/departments`).then(
  40. (resp: any) => {
  41. return resp.result?.map((item: any) => ({
  42. label: item.name,
  43. value: item.id,
  44. }));
  45. },
  46. ),
  47. getDepartmentsTree: (id: string) =>
  48. request(`${SystemConst.API_BASE}/notifier/dingtalk/corp/${id}/departments/tree`).then(
  49. (resp: any) => {
  50. return resp.result?.map((item: any) => ({
  51. label: item.name,
  52. value: item.id,
  53. }));
  54. },
  55. ),
  56. getUser: (id: string) =>
  57. request(`${SystemConst.API_BASE}/notifier/dingtalk/corp/${id}/users`).then((resp: any) => {
  58. return resp.result?.map((item: any) => ({
  59. label: item.name,
  60. value: item.id,
  61. }));
  62. }),
  63. };
  64. weixin = {
  65. getTags: (id: string) =>
  66. request(`${SystemConst.API_BASE}/notifier/wechat/corp/${id}/tags`).then((resp: any) => {
  67. return resp.result?.map((item: any) => ({
  68. label: item.name,
  69. value: item.id,
  70. }));
  71. }),
  72. getDepartments: (id: string) =>
  73. request(`${SystemConst.API_BASE}/notifier/wechat/corp/${id}/departments`).then(
  74. (resp: any) => {
  75. return resp.result?.map((item: any) => ({
  76. label: item.name,
  77. value: item.id,
  78. }));
  79. },
  80. ),
  81. getUser: (id: string) =>
  82. request(`${SystemConst.API_BASE}/notifier/wechat/corp/${id}/users`).then((resp: any) => {
  83. return resp.result?.map((item: any) => ({
  84. label: item.name,
  85. value: item.id,
  86. }));
  87. }),
  88. getOfficialTags: (configId: string) =>
  89. request(`${SystemConst.API_BASE}/notifier/wechat/official/${configId}/tags`).then(
  90. (resp: any) => {
  91. return resp.result?.map((item: any) => ({
  92. label: item.name,
  93. value: item.id,
  94. }));
  95. },
  96. ),
  97. getOfficialTemplates: (configId: string) =>
  98. request(`${SystemConst.API_BASE}/notifier/wechat/official/${configId}/templates`).then(
  99. (resp: any) => {
  100. return resp.result?.map((item: any) => ({
  101. ...item,
  102. label: item.title,
  103. value: item.id,
  104. }));
  105. },
  106. ),
  107. };
  108. aliyun = {
  109. getSigns: (id: string) =>
  110. request(`${SystemConst.API_BASE}/notifier/sms/aliyun/${id}/signs`).then((resp: any) => {
  111. return resp.result?.map((item: any) => ({
  112. ...item,
  113. label: item.signName,
  114. value: item.signName,
  115. }));
  116. }),
  117. getTemplates: (id: string) =>
  118. request(`${SystemConst.API_BASE}/notifier/sms/aliyun/${id}/templates`).then((resp: any) => {
  119. return resp.result?.map((item: any) => ({
  120. ...item,
  121. label: item.templateName,
  122. value: item.templateCode,
  123. }));
  124. }),
  125. };
  126. }
  127. export default Service;