Kaynağa Gözat

fix:修改餐桌信息列表查询

huangjinliang 1 hafta önce
ebeveyn
işleme
0a7825b917

+ 4 - 7
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/TableInfoService.java

@@ -1,8 +1,11 @@
 package com.fuint.common.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fuint.common.param.PageParam;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
+import com.fuint.framework.web.PageResult;
+import com.fuint.repository.bean.TableInfoBean;
 import com.fuint.repository.model.MtTableInfo;
 import com.fuint.framework.exception.BusinessCheckException;
 import java.util.List;
@@ -16,13 +19,6 @@ import java.util.Map;
  */
 public interface TableInfoService extends IService<MtTableInfo> {
 
-    /**
-     * 分页查询列表
-     *
-     * @param paginationRequest
-     * @return
-     */
-    PaginationResponse<MtTableInfo> queryTableInfoListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException;
 
     /**
      * 添加餐桌信息
@@ -102,4 +98,5 @@ public interface TableInfoService extends IService<MtTableInfo> {
      */
     boolean updateTable(MtTableInfo updateEntity) throws BusinessCheckException;
 
+    PageResult<TableInfoBean> selectTableList(String tableName, PageParam param) throws BusinessCheckException;
 }

+ 39 - 22
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/TableInfoServiceImpl.java

@@ -1,9 +1,14 @@
 package com.fuint.common.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fuint.common.dto.AccountInfo;
 import com.fuint.common.enums.StatusEnum;
+import com.fuint.common.param.PageParam;
 import com.fuint.common.service.TableInfoService;
 import com.fuint.common.util.AuthUserUtil;
 import com.fuint.common.util.I18nUtil;
@@ -11,21 +16,26 @@ import com.fuint.framework.annoation.OperationServiceLog;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
+import com.fuint.framework.web.PageResult;
+import com.fuint.repository.bean.TableInfoBean;
+import com.fuint.repository.mapper.MtStoreMapper;
 import com.fuint.repository.mapper.MtTableCategoryMapper;
 import com.fuint.repository.mapper.MtTableInfoMapper;
+import com.fuint.repository.model.MtStore;
 import com.fuint.repository.model.MtTableCategory;
 import com.fuint.repository.model.MtTableInfo;
-import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 餐桌信息服务接口
@@ -43,33 +53,15 @@ public class TableInfoServiceImpl extends ServiceImpl<MtTableInfoMapper, MtTable
 
     private MtTableCategoryMapper tableCategoryMapper;
 
+    private MtStoreMapper storeMapper;
+
     /**
      * 分页查询数据列表
      *
      * @param paginationRequest
      * @return
      */
-    @Override
-    public PaginationResponse<MtTableInfo> queryTableInfoListByPagination(PaginationRequest paginationRequest) {
-        //构建分页条件
-        Page<MtTableInfo> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
-        //构建查询条件
-        LambdaQueryWrapper<MtTableInfo> lambdaQueryWrapper = Wrappers.lambdaQuery();
-        //排除已经删除数据
-        lambdaQueryWrapper.ne(MtTableInfo::getDeleteFlag, 1);
 
-        lambdaQueryWrapper.orderByAsc(MtTableInfo::getId);
-        List<MtTableInfo> dataList = mtTableInfoMapper.selectList(lambdaQueryWrapper);
-
-        PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
-        PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
-        PaginationResponse<MtTableInfo> paginationResponse = new PaginationResponse(pageImpl, MtTableInfo.class);
-        paginationResponse.setTotalPages(pageHelper.getPages());
-        paginationResponse.setTotalElements(pageHelper.getTotal());
-        paginationResponse.setContent(dataList);
-
-        return paginationResponse;
-    }
 
     /**
      * 添加餐桌信息
@@ -195,7 +187,6 @@ public class TableInfoServiceImpl extends ServiceImpl<MtTableInfoMapper, MtTable
     @Transactional(rollbackFor = Exception.class)
     public boolean saveTable(MtTableInfo entity) throws BusinessCheckException {
         // 校验桌号唯一性
-
         Long storeId = AuthUserUtil.get().getStoreId();
         if (storeId==null || storeId<0){
             throw new BusinessCheckException("平台号无权限修改");
@@ -227,4 +218,30 @@ public class TableInfoServiceImpl extends ServiceImpl<MtTableInfoMapper, MtTable
         return updateById(entity);
     }
 
+    @Override
+    public PageResult<TableInfoBean> selectTableList(String tableName, PageParam param) throws BusinessCheckException {
+        AccountInfo accountInfo = AuthUserUtil.get();
+        //检查是否登入
+        if (accountInfo == null){
+            throw new BusinessCheckException(I18nUtil.getMessage("notAuthenticated"));
+        }
+        //分页查询
+        IPage<MtTableInfo> mtTableInfoIPage = this.baseMapper.selectPage(new Page<>(param.getPage(), param.getPageSize()), new LambdaQueryWrapper<MtTableInfo>()
+                 .eq((accountInfo.getStoreId()!=null && accountInfo.getStoreId()>0),MtTableInfo::getStoreId,accountInfo.getStoreId())
+                .likeRight(StringUtils.isNotEmpty(tableName), MtTableInfo::getTableNumber, tableName));
+        //补全字段
+        List<TableInfoBean> beanList = mtTableInfoIPage.getRecords().stream().map(mtTableInfo -> {
+            TableInfoBean tableInfoBean = new TableInfoBean();
+            Long storeId = mtTableInfo.getStoreId();
+            //mtTableInfo copy到TableInfoBean
+            BeanUtils.copyProperties(mtTableInfo, tableInfoBean);
+            //获取店铺信息
+            MtStore mtStore = storeMapper.selectById(storeId);
+            tableInfoBean.setStoreName(mtStore.getName());
+            return tableInfoBean;
+        }).collect(Collectors.toList());
+        //返回
+        return PageResult.<TableInfoBean>builder().data(beanList).total(Math.toIntExact(mtTableInfoIPage.getTotal())).build();
+    }
+
 }

+ 5 - 64
fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendTableInfoController.java

@@ -3,11 +3,13 @@ package com.fuint.module.backendApi.controller;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fuint.common.dto.AccountInfo;
 import com.fuint.common.dto.ext.TableInfoDto;
+import com.fuint.common.param.PageParam;
 import com.fuint.common.service.SettingService;
 import com.fuint.common.service.TableCategoryService;
 import com.fuint.common.util.I18nUtil;
 import com.fuint.common.util.TokenUtil;
 import com.fuint.framework.web.BaseController;
+import com.fuint.framework.web.PageResult;
 import com.fuint.framework.web.ResponseObject;
 import com.fuint.common.Constants;
 import com.fuint.common.enums.StatusEnum;
@@ -15,6 +17,7 @@ import com.fuint.common.service.TableInfoService;
 import com.fuint.framework.pagination.PaginationRequest;
 import com.fuint.framework.pagination.PaginationResponse;
 import com.fuint.framework.exception.BusinessCheckException;
+import com.fuint.repository.bean.TableInfoBean;
 import com.fuint.repository.model.MtTableCategory;
 import com.fuint.repository.model.MtTableInfo;
 import com.fuint.utils.StringUtil;
@@ -53,78 +56,16 @@ public class BackendTableInfoController extends BaseController {
     /**
      * 餐桌信息列表查询
      *
-     * @param  request HttpServletRequest对象
      * @return 餐桌信息列表
      */
     @ApiOperation(value = "餐桌信息列表查询")
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     @CrossOrigin
 //    @PreAuthorize("@pms.hasPermission('table_info:list')")
-    public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
-        // 1. 获取请求参数
-        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 tableNumber = request.getParameter("tableNumber");
-        String status = request.getParameter("status");
-        String categoryId = request.getParameter("categoryId");
-
-        // 2. 用户认证
-        AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
-        Long storeId;
-        if (accountInfo == null) {
-            return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
-        } else {
-            storeId = accountInfo.getStoreId();
-        }
+    public PageResult<TableInfoBean> list(@RequestParam("tableName") String tableName, PageParam param) throws BusinessCheckException {
+        return  tableInfoService.selectTableList(tableName,param);
 
-        // 3. 构建分页请求
-        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 (storeId != null && storeId > 0) {
-            params.put("storeId", storeId);
-        }
-        // 查询条件
-        if (StringUtil.isNotEmpty(tableNumber)) {
-            params.put("tableNumber", tableNumber + "%"); // 后缀模糊匹配
-        }
-        if (StringUtil.isNotEmpty(status)) {
-            params.put("status", status);
-        }
-        if (StringUtil.isNotEmpty(categoryId)) {
-            params.put("categoryId", Long.parseLong(categoryId));
-        }
-        params.put("deleteFlag", 0); // 只查未删除记录
-        paginationRequest.setSearchParams(params);
-        //执行分页查询
-        PaginationResponse<MtTableInfo> paginationResponse = tableInfoService.queryTableInfoListByPagination(paginationRequest);
-
-        // 获取附加数据
-        Map<String, Object> extraData = new HashMap<>();
-        // 获取分类列表
-        Map<String, Object> categoryParams = new HashMap<>();
-        categoryParams.put("merchantId", accountInfo.getMerchantId());
-        categoryParams.put("status", StatusEnum.ENABLED.getKey());
-        List<MtTableCategory> categoryList = categoryService.queryTableCategoryListByParams(categoryParams);
-
-        // 获取系统配置
-        String imagePath = settingService.getUploadBasePath();
-
-        // 构造返回结果
-        Map<String, Object> result = new HashMap<>();
-        result.put("paginationData", paginationResponse);
-        result.put("categoryList", categoryList);
-        result.put("imagePath", imagePath);
-
-        return getSuccessResult(result);
     }
 
     /**

+ 38 - 0
fuintBackend/fuint-repository/src/main/java/com/fuint/repository/bean/TableInfoBean.java

@@ -0,0 +1,38 @@
+package com.fuint.repository.bean;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class TableInfoBean {
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty("餐桌容纳人数")
+    private Integer capacity;
+
+
+    @ApiModelProperty("记录创建时间")
+    private Date createTime;
+
+
+    @ApiModelProperty("餐桌ID,主键,自增")
+    private Long id;
+
+    @ApiModelProperty("店铺名称")
+    private String storeName;
+
+    @ApiModelProperty("餐桌编号,如T001、T002等")
+    private String tableNumber;
+
+
+    @ApiModelProperty("分类名称")
+    private String categoryName;
+
+    @ApiModelProperty("记录更新时间")
+    private Date updateTime;
+
+}