BackendSmsTemplateController.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.fuint.module.backendApi.controller;
  2. import com.fuint.common.Constants;
  3. import com.fuint.common.dto.AccountInfo;
  4. import com.fuint.common.dto.SmsTemplateDto;
  5. import com.fuint.common.service.SmsTemplateService;
  6. import com.fuint.common.util.TokenUtil;
  7. import com.fuint.framework.exception.BusinessCheckException;
  8. import com.fuint.framework.pagination.PaginationRequest;
  9. import com.fuint.framework.pagination.PaginationResponse;
  10. import com.fuint.framework.web.BaseController;
  11. import com.fuint.framework.web.ResponseObject;
  12. import com.fuint.repository.model.MtSmsTemplate;
  13. import com.fuint.utils.StringUtil;
  14. import io.swagger.annotations.Api;
  15. import io.swagger.annotations.ApiOperation;
  16. import lombok.AllArgsConstructor;
  17. import org.springframework.security.access.prepost.PreAuthorize;
  18. import org.springframework.web.bind.annotation.*;
  19. import javax.servlet.http.HttpServletRequest;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * 短信模板管理类controller
  24. *
  25. * Created by FSQ
  26. * CopyRight https://www.fuint.cn
  27. */
  28. @Api(tags="管理端-短信模板相关接口")
  29. @RestController
  30. @AllArgsConstructor
  31. @RequestMapping(value = "/backendApi/smsTemplate")
  32. public class BackendSmsTemplateController extends BaseController {
  33. /**
  34. * 短信模板服务接口
  35. */
  36. private SmsTemplateService smsTemplateService;
  37. /**
  38. * 查询短信模板列表
  39. *
  40. * @param request
  41. * @return
  42. * @throws BusinessCheckException
  43. */
  44. @ApiOperation(value = "查询短信模板列表")
  45. @RequestMapping(value = "/list", method = RequestMethod.GET)
  46. @CrossOrigin
  47. @PreAuthorize("@pms.hasPermission('smsTemplate:index')")
  48. public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
  49. String token = request.getHeader("Access-Token");
  50. Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
  51. Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
  52. String name = request.getParameter("content") == null ? "" : request.getParameter("content");
  53. String code = request.getParameter("code") == null ? "" : request.getParameter("code");
  54. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  55. Map<String, Object> searchParams = new HashMap<>();
  56. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  57. searchParams.put("merchantId", accountInfo.getMerchantId());
  58. }
  59. if (StringUtil.isNotEmpty(code)) {
  60. searchParams.put("code", code);
  61. }
  62. if (StringUtil.isNotEmpty(name)) {
  63. searchParams.put("name", name);
  64. }
  65. PaginationRequest paginationRequest = new PaginationRequest();
  66. paginationRequest.setCurrentPage(page);
  67. paginationRequest.setPageSize(pageSize);
  68. paginationRequest.setSearchParams(searchParams);
  69. PaginationResponse<MtSmsTemplate> paginationResponse = smsTemplateService.querySmsTemplateListByPagination(paginationRequest);
  70. Map<String, Object> result = new HashMap<>();
  71. result.put("paginationResponse", paginationResponse);
  72. return getSuccessResult(result);
  73. }
  74. /**
  75. * 保存短信模板
  76. *
  77. * @param request HttpServletRequest对象
  78. * @return
  79. */
  80. @ApiOperation(value = "保存短信模板")
  81. @RequestMapping(value = "/save", method = RequestMethod.POST)
  82. @CrossOrigin
  83. @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
  84. public ResponseObject saveHandler(HttpServletRequest request, @RequestBody SmsTemplateDto smsTemplateDto) throws BusinessCheckException {
  85. String token = request.getHeader("Access-Token");
  86. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  87. smsTemplateDto.setMerchantId(accountInfo.getMerchantId());
  88. smsTemplateService.saveSmsTemplate(smsTemplateDto);
  89. return getSuccessResult(true);
  90. }
  91. /**
  92. * 模板详情
  93. *
  94. * @param request
  95. * @return
  96. */
  97. @ApiOperation(value = "模板详情")
  98. @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
  99. @CrossOrigin
  100. @PreAuthorize("@pms.hasPermission('smsTemplate:index')")
  101. public ResponseObject info(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {
  102. String token = request.getHeader("Access-Token");
  103. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  104. MtSmsTemplate mtSmsTemplate = smsTemplateService.querySmsTemplateById(id.intValue());
  105. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  106. if (!accountInfo.getMerchantId().equals(mtSmsTemplate.getMerchantId())) {
  107. return getFailureResult(1004);
  108. }
  109. }
  110. Map<String, Object> result = new HashMap();
  111. result.put("smsTemplate", mtSmsTemplate);
  112. return getSuccessResult(result);
  113. }
  114. /**
  115. * 删除短信模板
  116. *
  117. * @param request
  118. * @return
  119. */
  120. @ApiOperation(value = "删除短信模板")
  121. @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
  122. @CrossOrigin
  123. @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
  124. public ResponseObject delete(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  125. String token = request.getHeader("Access-Token");
  126. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  127. String operator = accountInfo.getAccountName();
  128. smsTemplateService.deleteTemplate(id, operator);
  129. return getSuccessResult(true);
  130. }
  131. }