BackendBannerController.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package com.fuint.module.backendApi.controller;
  2. import com.fuint.common.dto.AccountInfo;
  3. import com.fuint.common.service.StoreService;
  4. import com.fuint.common.util.TokenUtil;
  5. import com.fuint.framework.web.BaseController;
  6. import com.fuint.framework.web.ResponseObject;
  7. import com.fuint.common.Constants;
  8. import com.fuint.common.dto.BannerDto;
  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.common.service.BannerService;
  15. import com.fuint.repository.model.MtBanner;
  16. import com.fuint.repository.model.MtStore;
  17. import com.fuint.utils.StringUtil;
  18. import io.swagger.annotations.Api;
  19. import io.swagger.annotations.ApiOperation;
  20. import org.springframework.beans.factory.annotation.Autowired;
  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. @RequestMapping(value = "/backendApi/banner")
  35. public class BackendBannerController extends BaseController {
  36. /**
  37. * 焦点图服务接口
  38. */
  39. @Autowired
  40. private BannerService bannerService;
  41. /**
  42. * 系统设置服务接口
  43. * */
  44. @Autowired
  45. private SettingService settingService;
  46. /**
  47. * 店铺服务接口
  48. */
  49. @Autowired
  50. private StoreService storeService;
  51. /**
  52. * 焦点图列表查询
  53. *
  54. * @param request HttpServletRequest对象
  55. * @return banner列表
  56. */
  57. @ApiOperation(value = "焦点图列表查询")
  58. @RequestMapping(value = "/list", method = RequestMethod.GET)
  59. @CrossOrigin
  60. public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
  61. String token = request.getHeader("Access-Token");
  62. Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
  63. Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
  64. String title = request.getParameter("title");
  65. String status = request.getParameter("status");
  66. String searchStoreId = request.getParameter("storeId");
  67. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  68. Integer storeId;
  69. if (accountInfo == null) {
  70. return getFailureResult(1001, "请先登录");
  71. } else {
  72. storeId = accountInfo.getStoreId();
  73. }
  74. PaginationRequest paginationRequest = new PaginationRequest();
  75. paginationRequest.setCurrentPage(page);
  76. paginationRequest.setPageSize(pageSize);
  77. Map<String, Object> params = new HashMap<>();
  78. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  79. params.put("merchantId", accountInfo.getMerchantId());
  80. }
  81. if (StringUtil.isNotEmpty(title)) {
  82. params.put("title", title);
  83. }
  84. if (StringUtil.isNotEmpty(status)) {
  85. params.put("status", status);
  86. }
  87. if (StringUtil.isNotEmpty(searchStoreId)) {
  88. params.put("storeId", searchStoreId);
  89. }
  90. if (storeId != null && storeId > 0) {
  91. params.put("storeId", storeId);
  92. }
  93. paginationRequest.setSearchParams(params);
  94. PaginationResponse<MtBanner> paginationResponse = bannerService.queryBannerListByPagination(paginationRequest);
  95. Map<String, Object> paramsStore = new HashMap<>();
  96. paramsStore.put("status", StatusEnum.ENABLED.getKey());
  97. if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
  98. paramsStore.put("storeId", accountInfo.getStoreId().toString());
  99. }
  100. if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
  101. paramsStore.put("merchantId", accountInfo.getMerchantId());
  102. }
  103. List<MtStore> storeList = storeService.queryStoresByParams(paramsStore);
  104. String imagePath = settingService.getUploadBasePath();
  105. Map<String, Object> result = new HashMap<>();
  106. result.put("dataList", paginationResponse);
  107. result.put("imagePath", imagePath);
  108. result.put("storeList", storeList);
  109. return getSuccessResult(result);
  110. }
  111. /**
  112. * 更新焦点图状态
  113. *
  114. * @return
  115. */
  116. @ApiOperation(value = "更新焦点图状态")
  117. @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
  118. @CrossOrigin
  119. public ResponseObject updateStatus(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  120. String token = request.getHeader("Access-Token");
  121. String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
  122. Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
  123. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  124. if (accountInfo == null) {
  125. return getFailureResult(1001, "请先登录");
  126. }
  127. MtBanner mtBanner = bannerService.queryBannerById(id);
  128. if (mtBanner == null) {
  129. return getFailureResult(201);
  130. }
  131. String operator = accountInfo.getAccountName();
  132. BannerDto bannerDto = new BannerDto();
  133. bannerDto.setOperator(operator);
  134. bannerDto.setId(id);
  135. bannerDto.setStatus(status);
  136. bannerService.updateBanner(bannerDto);
  137. return getSuccessResult(true);
  138. }
  139. /**
  140. * 保存焦点图
  141. *
  142. * @param request HttpServletRequest对象
  143. * @return
  144. */
  145. @ApiOperation(value = "保存焦点图")
  146. @RequestMapping(value = "/save", method = RequestMethod.POST)
  147. @CrossOrigin
  148. public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
  149. String token = request.getHeader("Access-Token");
  150. String id = params.get("id") == null ? "" : params.get("id").toString();
  151. String title = params.get("title") == null ? "" : params.get("title").toString();
  152. String description = params.get("description") == null ? "" : params.get("description").toString();
  153. String image = params.get("image") == null ? "" : params.get("image").toString();
  154. String url = params.get("url") == null ? "" : params.get("url").toString();
  155. String status = params.get("status") == null ? "" : params.get("status").toString();
  156. String storeId = params.get("storeId") == null ? "0" : params.get("storeId").toString();
  157. String sort = params.get("sort") == null ? "0" : params.get("sort").toString();
  158. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  159. if (accountInfo == null) {
  160. return getFailureResult(1001, "请先登录");
  161. }
  162. BannerDto info = new BannerDto();
  163. info.setTitle(title);
  164. info.setDescription(description);
  165. info.setImage(image);
  166. info.setUrl(url);
  167. info.setOperator(accountInfo.getAccountName());
  168. info.setStatus(status);
  169. info.setStoreId(Integer.parseInt(storeId));
  170. info.setSort(Integer.parseInt(sort));
  171. info.setMerchantId(accountInfo.getMerchantId());
  172. if (StringUtil.isNotEmpty(id)) {
  173. info.setId(Integer.parseInt(id));
  174. bannerService.updateBanner(info);
  175. } else {
  176. bannerService.addBanner(info);
  177. }
  178. return getSuccessResult(true);
  179. }
  180. /**
  181. * 获取焦点图详情
  182. *
  183. * @param id
  184. * @return
  185. */
  186. @ApiOperation(value = "获取焦点图详情")
  187. @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
  188. @CrossOrigin
  189. public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
  190. String token = request.getHeader("Access-Token");
  191. AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
  192. if (accountInfo == null) {
  193. return getFailureResult(1001, "请先登录");
  194. }
  195. MtBanner bannerInfo = bannerService.queryBannerById(id);
  196. String imagePath = settingService.getUploadBasePath();
  197. Map<String, Object> result = new HashMap<>();
  198. result.put("bannerInfo", bannerInfo);
  199. result.put("imagePath", imagePath);
  200. return getSuccessResult(result);
  201. }
  202. }