ソースを参照

fixed 商品列表查询功能优化

fushengqian 3 週間 前
コミット
2a4d7ed033

+ 43 - 0
fuint-application/src/main/java/com/fuint/common/param/GoodsListParam.java

@@ -0,0 +1,43 @@
+package com.fuint.common.param;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import java.io.Serializable;
+
+/**
+ * 商品列表请求参数
+ *
+ * Created by FSQ
+ * CopyRight https://www.fuint.cn
+ */
+@Data
+public class GoodsListParam extends PageParam implements Serializable {
+
+    @ApiModelProperty(value="商品名称", name="name")
+    private String name;
+
+    @ApiModelProperty(value="商品编码", name="goodsNo")
+    private String goodsNo;
+
+    @ApiModelProperty(value="是否单规格", name="isSingleSpec")
+    private String isSingleSpec;
+
+    @ApiModelProperty(value="商品类型", name="type")
+    private String type;
+
+    @ApiModelProperty(value="商品状态", name="status")
+    private String status;
+
+    @ApiModelProperty(value="所属商户", name="merchantId")
+    private Integer merchantId;
+
+    @ApiModelProperty(value="所属店铺", name="storeId")
+    private Integer storeId;
+
+    @ApiModelProperty(value="是否有库存", name="stock")
+    private String stock;
+
+    @ApiModelProperty(value="商品分类", name="cateId")
+    private Integer cateId;
+
+}

+ 19 - 0
fuint-application/src/main/java/com/fuint/common/util/CommonUtil.java

@@ -12,6 +12,7 @@ import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.regex.Pattern;
 import java.util.regex.Matcher;
+import java.lang.reflect.Field;
 
 /**
  * 通用工具
@@ -21,6 +22,24 @@ import java.util.regex.Matcher;
  */
 public class CommonUtil {
 
+    /**
+     * 对象转化成map
+     *
+     * @param obj 对象
+     * @return
+     * */
+    public static Map<String, Object> convert(Object obj) throws IllegalAccessException {
+        Map<String, Object> map = new HashMap<>();
+        Class<?> clazz = obj.getClass();
+
+        for (Field field : clazz.getDeclaredFields()) {
+             field.setAccessible(true);
+             map.put(field.getName(), field.get(obj));
+        }
+
+        return map;
+    }
+
     /**
      * 隐藏手机号中间4位
      *

+ 14 - 49
fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendGoodsController.java

@@ -2,11 +2,11 @@ package com.fuint.module.backendApi.controller;
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
-import com.fuint.common.Constants;
 import com.fuint.common.dto.*;
 import com.fuint.common.enums.GoodsTypeEnum;
 import com.fuint.common.enums.StatusEnum;
 import com.fuint.common.enums.YesOrNoEnum;
+import com.fuint.common.param.GoodsListParam;
 import com.fuint.common.service.*;
 import com.fuint.common.util.CommonUtil;
 import com.fuint.common.util.TokenUtil;
@@ -79,22 +79,11 @@ public class BackendGoodsController extends BaseController {
      * @return
      */
     @ApiOperation(value = "分页查询商品列表")
-    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    @RequestMapping(value = "/list", method = RequestMethod.POST)
     @CrossOrigin
     @PreAuthorize("@pms.hasPermission('goods:goods:index')")
-    public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
+    public ResponseObject list(HttpServletRequest request, @RequestBody GoodsListParam param) throws BusinessCheckException, IllegalAccessException {
         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 name = request.getParameter("name");
-        String goodsNo = request.getParameter("goodsNo");
-        String isSingleSpec = request.getParameter("isSingleSpec");
-        String type = request.getParameter("type");
-        String status = request.getParameter("status");
-        String searchStoreId = request.getParameter("storeId");
-        String stock = request.getParameter("stock");
-        String cateId = request.getParameter("cateId");
-
         AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
 
         TAccount account = accountService.getAccountInfoById(accountInfo.getId());
@@ -102,41 +91,17 @@ public class BackendGoodsController extends BaseController {
         Integer merchantId = account.getMerchantId() == null ? 0 : account.getMerchantId();
 
         PaginationRequest paginationRequest = new PaginationRequest();
-        paginationRequest.setCurrentPage(page);
-        paginationRequest.setPageSize(pageSize);
+        paginationRequest.setCurrentPage(param.getPage());
+        paginationRequest.setPageSize(param.getPageSize());
 
-        Map<String, Object> params = new HashMap<>();
-        if (StringUtil.isNotEmpty(searchStoreId)) {
-            params.put("storeId", searchStoreId);
-        }
         if (merchantId > 0) {
-            params.put("merchantId", merchantId);
+            param.setMerchantId(merchantId);
         }
         if (storeId > 0) {
-            params.put("storeId", storeId);
-        }
-        if (StringUtil.isNotEmpty(name)) {
-            params.put("name", name);
-        }
-        if (StringUtil.isNotEmpty(type)) {
-            params.put("type", type);
-        }
-        if (StringUtil.isNotEmpty(cateId)) {
-            params.put("cateId", cateId);
-        }
-        if (StringUtil.isNotEmpty(goodsNo)) {
-            params.put("goodsNo", goodsNo);
-        }
-        if (StringUtil.isNotEmpty(isSingleSpec)) {
-            params.put("isSingleSpec", isSingleSpec);
-        }
-        if (StringUtil.isNotEmpty(status)) {
-            params.put("status", status);
-        }
-        if (StringUtil.isNotEmpty(stock)) {
-            params.put("stock", stock);
+            param.setStoreId(storeId);
         }
-        paginationRequest.setSearchParams(params);
+
+        paginationRequest.setSearchParams(CommonUtil.convert(param));
         PaginationResponse<GoodsDto> paginationResponse = goodsService.queryGoodsListByPagination(paginationRequest);
 
         // 商品类型列表
@@ -144,20 +109,20 @@ public class BackendGoodsController extends BaseController {
 
         Map<String, Object> paramsStore = new HashMap<>();
         paramsStore.put("status", StatusEnum.ENABLED.getKey());
-        if (storeId != null && storeId > 0) {
-            paramsStore.put("storeId", storeId.toString());
+        if (storeId > 0) {
+            paramsStore.put("storeId", storeId);
         }
-        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+        if (merchantId > 0) {
             paramsStore.put("merchantId", accountInfo.getMerchantId());
         }
         List<MtStore> storeList = storeService.queryStoresByParams(paramsStore);
 
         Map<String, Object> cateParam = new HashMap<>();
         cateParam.put("status", StatusEnum.ENABLED.getKey());
-        if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
+        if (merchantId > 0) {
             cateParam.put("merchantId", accountInfo.getMerchantId());
         }
-        if (storeId != null && storeId > 0) {
+        if (storeId > 0) {
             cateParam.put("storeId", storeId.toString());
         }
         List<MtGoodsCate> cateList = cateService.queryCateListByParams(cateParam);