|
@@ -1,54 +1,197 @@
|
|
|
package com.fuint.module.backendApi.controller;
|
|
|
|
|
|
-import com.fuint.common.dto.AccountInfo;
|
|
|
import com.fuint.common.util.TokenUtil;
|
|
|
-import com.fuint.framework.exception.BusinessCheckException;
|
|
|
import com.fuint.framework.web.BaseController;
|
|
|
import com.fuint.framework.web.ResponseObject;
|
|
|
+import com.fuint.common.Constants;
|
|
|
+import com.fuint.common.enums.StatusEnum;
|
|
|
+import com.fuint.framework.pagination.PaginationRequest;
|
|
|
+import com.fuint.framework.pagination.PaginationResponse;
|
|
|
+import com.fuint.framework.exception.BusinessCheckException;
|
|
|
+import com.fuint.common.service.BannerService;
|
|
|
+import com.fuint.repository.model.${className};
|
|
|
+import com.fuint.utils.StringUtil;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
- * ${moduleName}管理类Controller
|
|
|
+ * ${moduleName}管理类controller
|
|
|
*
|
|
|
- * @Created by ${author}
|
|
|
- * @CopyRight https://www.fuint.cn
|
|
|
+ * Created by ${author}
|
|
|
+ * CopyRight https://www.fuint.cn
|
|
|
*/
|
|
|
-@Api(tags="管理端-${moduleName}管理相关接口")
|
|
|
+@Api(tags="管理端-${moduleName}相关接口")
|
|
|
@RestController
|
|
|
@AllArgsConstructor
|
|
|
@RequestMapping(value = "/backendApi/${tableName}")
|
|
|
public class Backend${tableClass}Controller extends BaseController {
|
|
|
|
|
|
- /**
|
|
|
- * ${moduleName}列表查询
|
|
|
- *
|
|
|
- * @param request HttpServletRequest对象
|
|
|
- * @return ${moduleName}列表
|
|
|
- */
|
|
|
+ /**
|
|
|
+ * ${moduleName}服务接口
|
|
|
+ */
|
|
|
+ private ${tableClass}Service ${tableName}Service;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * ${moduleName}列表查询
|
|
|
+ *
|
|
|
+ * @param request HttpServletRequest对象
|
|
|
+ * @return ${moduleName}列表
|
|
|
+ */
|
|
|
@ApiOperation(value = "${moduleName}列表查询")
|
|
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
|
|
@CrossOrigin
|
|
|
- @PreAuthorize("@pms.hasPermission('content:article:index')")
|
|
|
+ @PreAuthorize("@pms.hasPermission('${tableName}:list')")
|
|
|
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
|
|
|
String token = request.getHeader("Access-Token");
|
|
|
+ Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
|
|
|
+ Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
|
|
|
+ String title = request.getParameter("title");
|
|
|
+ String status = request.getParameter("status");
|
|
|
+ String searchStoreId = request.getParameter("storeId");
|
|
|
+
|
|
|
+ AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
+ Integer storeId;
|
|
|
+ if (accountInfo == null) {
|
|
|
+ return getFailureResult(1001, "请先登录");
|
|
|
+ } else {
|
|
|
+ storeId = accountInfo.getStoreId();
|
|
|
+ }
|
|
|
+
|
|
|
+ PaginationRequest paginationRequest = new PaginationRequest();
|
|
|
+ paginationRequest.setCurrentPage(page);
|
|
|
+ paginationRequest.setPageSize(pageSize);
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
|
|
|
+ params.put("merchantId", accountInfo.getMerchantId());
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotEmpty(title)) {
|
|
|
+ params.put("title", title);
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotEmpty(status)) {
|
|
|
+ params.put("status", status);
|
|
|
+ }
|
|
|
+ if (StringUtil.isNotEmpty(searchStoreId)) {
|
|
|
+ params.put("storeId", searchStoreId);
|
|
|
+ }
|
|
|
+ if (storeId != null && storeId > 0) {
|
|
|
+ params.put("storeId", storeId);
|
|
|
+ }
|
|
|
+ paginationRequest.setSearchParams(params);
|
|
|
+ PaginationResponse<${className}> paginationResponse = ${tableName}Service.query${tableName}ListByPagination(paginationRequest);
|
|
|
+
|
|
|
+ Map<String, Object> paramsStore = new HashMap<>();
|
|
|
+ paramsStore.put("status", StatusEnum.ENABLED.getKey());
|
|
|
+ if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
|
|
|
+ paramsStore.put("storeId", accountInfo.getStoreId().toString());
|
|
|
+ }
|
|
|
+ if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
|
|
|
+ paramsStore.put("merchantId", accountInfo.getMerchantId());
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("dataList", paginationResponse);
|
|
|
+
|
|
|
+ return getSuccessResult(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新${moduleName}状态
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "更新${moduleName}状态")
|
|
|
+ @RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
|
|
|
+ @CrossOrigin
|
|
|
+ @PreAuthorize("@pms.hasPermission('${tableName}:edit')")
|
|
|
+ public ResponseObject updateStatus(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
|
|
|
+ String token = request.getHeader("Access-Token");
|
|
|
+ String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
|
|
|
+ Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
|
|
|
+
|
|
|
+ AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
+ if (accountInfo == null) {
|
|
|
+ return getFailureResult(1001, "请先登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ ${className} ${tablePrefix}${tableClass} = ${tableName}Service.query${tableClass}ById(id)};
|
|
|
+ if (${tablePrefix}${tableClass} == null) {
|
|
|
+ return getFailureResult(201);
|
|
|
+ }
|
|
|
+
|
|
|
+ String operator = accountInfo.getAccountName();
|
|
|
+ ${tablePrefix}${tableClass}.setOperator(operator);
|
|
|
+ ${tableName}Service.update${tableClass}(${tablePrefix}${tableClass});
|
|
|
+
|
|
|
+ return getSuccessResult(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存${moduleName}
|
|
|
+ *
|
|
|
+ * @param request HttpServletRequest对象
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "保存${moduleName}")
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+ @CrossOrigin
|
|
|
+ @PreAuthorize("@pms.hasPermission('${tableName}:add')")
|
|
|
+ public ResponseObject saveHandler(HttpServletRequest request, @RequestBody Map<String, Object> params) throws BusinessCheckException {
|
|
|
+ String token = request.getHeader("Access-Token");
|
|
|
+ String id = params.get("id") == null ? "" : params.get("id").toString();
|
|
|
+ String status = params.get("status") == null ? "" : params.get("status").toString();
|
|
|
+ String storeId = params.get("storeId") == null ? "0" : params.get("storeId").toString();
|
|
|
+ String sort = params.get("sort") == null ? "0" : params.get("sort").toString();
|
|
|
+
|
|
|
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
if (accountInfo == null) {
|
|
|
return getFailureResult(1001, "请先登录");
|
|
|
}
|
|
|
|
|
|
+ ${className} info = new ${className}();
|
|
|
+ info.setOperator(accountInfo.getAccountName());
|
|
|
+ info.setStatus(status);
|
|
|
+ info.setStoreId(Integer.parseInt(storeId));
|
|
|
+ info.setSort(Integer.parseInt(sort));
|
|
|
+ info.setMerchantId(accountInfo.getMerchantId());
|
|
|
+ if (StringUtil.isNotEmpty(id)) {
|
|
|
+ info.setId(Integer.parseInt(id));
|
|
|
+ ${tableName}Service.update${className}(info);
|
|
|
+ } else {
|
|
|
+ ${tableName}Service.add${className}(info);
|
|
|
+ }
|
|
|
+
|
|
|
+ return getSuccessResult(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取${moduleName}详情
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "获取${moduleName}详情")
|
|
|
+ @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
|
|
|
+ @CrossOrigin
|
|
|
+ @PreAuthorize("@pms.hasPermission('${tableName}:list')")
|
|
|
+ public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
|
|
|
+ String token = request.getHeader("Access-Token");
|
|
|
+ AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
|
|
|
+ if (accountInfo == null) {
|
|
|
+ return getFailureResult(1001, "请先登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ ${className} ${tableName}Info = ${tableName}Service.query${tableClass}ById(id);
|
|
|
+
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("dataList", new ArrayList<>());
|
|
|
+ result.put("${tableName}Info", ${tableName}Info);
|
|
|
|
|
|
return getSuccessResult(result);
|
|
|
}
|