BackendSmsTemplateController.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. @ApiOperation(value = "查询短信模板列表")
  41. @RequestMapping(value = "/list", method = RequestMethod.GET)
  42. @CrossOrigin
  43. @PreAuthorize("@pms.hasPermission('smsTemplate:index')")
  44. public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
  45. String token = request.getHeader("Access-Token");
  46. Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
  47. Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
  48. String name = request.getParameter("content") == null ? "" : request.getParameter("content");
  49. String code = request.getParameter("code") == null ? "" : request.getParameter("code");
  50. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  51. Map<String, Object> searchParams = new HashMap<>();
  52. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  53. searchParams.put("merchantId", accountInfo.getMerchantId());
  54. }
  55. if (StringUtil.isNotEmpty(code)) {
  56. searchParams.put("code", code);
  57. }
  58. if (StringUtil.isNotEmpty(name)) {
  59. searchParams.put("name", name);
  60. }
  61. PaginationRequest paginationRequest = new PaginationRequest();
  62. paginationRequest.setCurrentPage(page);
  63. paginationRequest.setPageSize(pageSize);
  64. paginationRequest.setSearchParams(searchParams);
  65. PaginationResponse<MtSmsTemplate> paginationResponse = smsTemplateService.querySmsTemplateListByPagination(paginationRequest);
  66. Map<String, Object> result = new HashMap<>();
  67. result.put("paginationResponse", paginationResponse);
  68. return getSuccessResult(result);
  69. }
  70. /**
  71. * 保存短信模板
  72. */
  73. @ApiOperation(value = "保存短信模板")
  74. @RequestMapping(value = "/save", method = RequestMethod.POST)
  75. @CrossOrigin
  76. @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
  77. public ResponseObject saveHandler(HttpServletRequest request, @RequestBody SmsTemplateDto smsTemplateDto) throws BusinessCheckException {
  78. String token = request.getHeader("Access-Token");
  79. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  80. smsTemplateDto.setMerchantId(accountInfo.getMerchantId());
  81. smsTemplateService.saveSmsTemplate(smsTemplateDto);
  82. return getSuccessResult(true);
  83. }
  84. /**
  85. * 模板详情
  86. */
  87. @ApiOperation(value = "模板详情")
  88. @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
  89. @CrossOrigin
  90. @PreAuthorize("@pms.hasPermission('smsTemplate:index')")
  91. public ResponseObject info(HttpServletRequest request, @PathVariable("id") Long id) throws BusinessCheckException {
  92. String token = request.getHeader("Access-Token");
  93. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  94. MtSmsTemplate mtSmsTemplate = smsTemplateService.querySmsTemplateById(id.intValue());
  95. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  96. if (!accountInfo.getMerchantId().equals(mtSmsTemplate.getMerchantId())) {
  97. return getFailureResult(1004);
  98. }
  99. }
  100. Map<String, Object> result = new HashMap();
  101. result.put("smsTemplate", mtSmsTemplate);
  102. return getSuccessResult(result);
  103. }
  104. /**
  105. * 删除短信模板
  106. */
  107. @ApiOperation(value = "删除短信模板")
  108. @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
  109. @CrossOrigin
  110. @PreAuthorize("@pms.hasPermission('smsTemplate:edit')")
  111. public ResponseObject delete(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  112. String token = request.getHeader("Access-Token");
  113. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  114. smsTemplateService.deleteTemplate(id, accountInfo.getAccountName());
  115. return getSuccessResult(true);
  116. }
  117. }