BackendBookCateController.java 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. package com.fuint.module.backendApi.controller;
  2. import com.fuint.common.dto.AccountInfo;
  3. import com.fuint.common.service.BookCateService;
  4. import com.fuint.common.service.StoreService;
  5. import com.fuint.common.util.TokenUtil;
  6. import com.fuint.framework.web.BaseController;
  7. import com.fuint.framework.web.ResponseObject;
  8. import com.fuint.common.Constants;
  9. import com.fuint.common.enums.StatusEnum;
  10. import com.fuint.common.service.SettingService;
  11. import com.fuint.framework.pagination.PaginationRequest;
  12. import com.fuint.framework.pagination.PaginationResponse;
  13. import com.fuint.framework.exception.BusinessCheckException;
  14. import com.fuint.repository.model.MtBookCate;
  15. import com.fuint.repository.model.MtStore;
  16. import com.fuint.utils.StringUtil;
  17. import io.swagger.annotations.Api;
  18. import io.swagger.annotations.ApiOperation;
  19. import lombok.AllArgsConstructor;
  20. import org.springframework.security.access.prepost.PreAuthorize;
  21. import org.springframework.web.bind.annotation.*;
  22. import javax.servlet.http.HttpServletRequest;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * 预约分类管理类controller
  28. *
  29. * Created by FSQ
  30. * CopyRight https://www.fuint.cn
  31. */
  32. @Api(tags="管理端-预约分类相关接口")
  33. @RestController
  34. @AllArgsConstructor
  35. @RequestMapping(value = "/backendApi/bookCate")
  36. public class BackendBookCateController extends BaseController {
  37. /**
  38. * 预约分类服务接口
  39. */
  40. private BookCateService bookCateService;
  41. /**
  42. * 系统设置服务接口
  43. * */
  44. private SettingService settingService;
  45. /**
  46. * 店铺服务接口
  47. */
  48. private StoreService storeService;
  49. /**
  50. * 预约分类列表查询
  51. *
  52. * @param request HttpServletRequest对象
  53. * @return 预约分类列表
  54. */
  55. @ApiOperation(value = "预约分类列表查询")
  56. @RequestMapping(value = "/list", method = RequestMethod.GET)
  57. @CrossOrigin
  58. @PreAuthorize("@pms.hasPermission('book:index')")
  59. public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
  60. String token = request.getHeader("Access-Token");
  61. Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
  62. Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
  63. String name = request.getParameter("name");
  64. String status = request.getParameter("status");
  65. String searchStoreId = request.getParameter("storeId");
  66. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  67. Integer storeId = accountInfo.getStoreId();
  68. PaginationRequest paginationRequest = new PaginationRequest();
  69. paginationRequest.setCurrentPage(page);
  70. paginationRequest.setPageSize(pageSize);
  71. Map<String, Object> params = new HashMap<>();
  72. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  73. params.put("merchantId", accountInfo.getMerchantId());
  74. }
  75. if (StringUtil.isNotEmpty(name)) {
  76. params.put("name", name);
  77. }
  78. if (StringUtil.isNotEmpty(status)) {
  79. params.put("status", status);
  80. }
  81. if (StringUtil.isNotEmpty(searchStoreId)) {
  82. params.put("storeId", searchStoreId);
  83. }
  84. if (storeId != null && storeId > 0) {
  85. params.put("storeId", storeId);
  86. }
  87. paginationRequest.setSearchParams(params);
  88. PaginationResponse<MtBookCate> paginationResponse = bookCateService.queryBookCateListByPagination(paginationRequest);
  89. Map<String, Object> paramsStore = new HashMap<>();
  90. paramsStore.put("status", StatusEnum.ENABLED.getKey());
  91. if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
  92. paramsStore.put("storeId", accountInfo.getStoreId().toString());
  93. }
  94. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  95. paramsStore.put("merchantId", accountInfo.getMerchantId());
  96. }
  97. List<MtStore> storeList = storeService.queryStoresByParams(paramsStore);
  98. String imagePath = settingService.getUploadBasePath();
  99. Map<String, Object> result = new HashMap<>();
  100. result.put("dataList", paginationResponse);
  101. result.put("imagePath", imagePath);
  102. result.put("storeList", storeList);
  103. return getSuccessResult(result);
  104. }
  105. /**
  106. * 更新预约分类状态
  107. *
  108. * @return
  109. */
  110. @ApiOperation(value = "更新预约分类状态")
  111. @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
  112. @CrossOrigin
  113. @PreAuthorize("@pms.hasPermission('book:index')")
  114. public ResponseObject updateStatus(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  115. String token = request.getHeader("Access-Token");
  116. String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
  117. Integer cateId = params.get("cateId") == null ? 0 : Integer.parseInt(params.get("cateId").toString());
  118. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  119. MtBookCate mtBookCate = bookCateService.getBookCateById(cateId);
  120. if (mtBookCate == null) {
  121. return getFailureResult(201);
  122. }
  123. String operator = accountInfo.getAccountName();
  124. mtBookCate.setOperator(operator);
  125. mtBookCate.setStatus(status);
  126. bookCateService.updateBookCate(mtBookCate);
  127. return getSuccessResult(true);
  128. }
  129. /**
  130. * 保存预约分类
  131. *
  132. * @param request HttpServletRequest对象
  133. * @return
  134. */
  135. @ApiOperation(value = "保存预约分类")
  136. @RequestMapping(value = "/save", method = RequestMethod.POST)
  137. @CrossOrigin
  138. @PreAuthorize("@pms.hasPermission('book:index')")
  139. public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  140. String token = request.getHeader("Access-Token");
  141. String id = params.get("id") == null ? "" : params.get("id").toString();
  142. String name = params.get("name") == null ? "" : params.get("name").toString();
  143. String description = params.get("description") == null ? "" : params.get("description").toString();
  144. String logo = params.get("logo") == null ? "" : params.get("logo").toString();
  145. String status = params.get("status") == null ? "" : params.get("status").toString();
  146. String storeId = (params.get("storeId") == null || StringUtil.isEmpty(params.get("storeId").toString())) ? "0" : params.get("storeId").toString();
  147. String sort = (params.get("sort") == null || StringUtil.isEmpty(params.get("sort").toString())) ? "0" : params.get("sort").toString();
  148. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  149. if (accountInfo.getMerchantId() == null || accountInfo.getMerchantId() < 1) {
  150. throw new BusinessCheckException("平台方帐号无法执行该操作,请使用商户帐号操作");
  151. }
  152. MtBookCate mtBookCate = new MtBookCate();
  153. mtBookCate.setName(name);
  154. mtBookCate.setDescription(description);
  155. mtBookCate.setLogo(logo);
  156. mtBookCate.setOperator(accountInfo.getAccountName());
  157. mtBookCate.setStoreId(Integer.parseInt(storeId));
  158. mtBookCate.setMerchantId(accountInfo.getMerchantId());
  159. mtBookCate.setSort(Integer.parseInt(sort));
  160. mtBookCate.setStatus(status);
  161. if (StringUtil.isNotEmpty(id)) {
  162. mtBookCate.setId(Integer.parseInt(id));
  163. bookCateService.updateBookCate(mtBookCate);
  164. } else {
  165. bookCateService.addBookCate(mtBookCate);
  166. }
  167. return getSuccessResult(true);
  168. }
  169. /**
  170. * 获取预约分类详情
  171. *
  172. * @param id
  173. * @return
  174. */
  175. @ApiOperation(value = "获取预约分类详情")
  176. @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
  177. @CrossOrigin
  178. @PreAuthorize("@pms.hasPermission('book:index')")
  179. public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  180. String token = request.getHeader("Access-Token");
  181. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  182. MtBookCate bookCateInfo = bookCateService.getBookCateById(id);
  183. String imagePath = settingService.getUploadBasePath();
  184. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  185. if (!bookCateInfo.getMerchantId().equals(accountInfo.getMerchantId())) {
  186. return getFailureResult(1004);
  187. }
  188. }
  189. Map<String, Object> result = new HashMap<>();
  190. result.put("bookCateInfo", bookCateInfo);
  191. result.put("imagePath", imagePath);
  192. return getSuccessResult(result);
  193. }
  194. }