فهرست منبع

feat:桌号具体信息(关联桌号分类表)curd

huangjinliang 1 هفته پیش
والد
کامیت
c22502ef22

+ 8 - 0
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/TableCategoryService.java

@@ -68,4 +68,12 @@ public interface TableCategoryService extends IService<MtTableCategory> {
      * @return
      * */
     List<MtTableCategory> queryTableCategoryListByParams(Map<String, Object> params) throws BusinessCheckException;
+
+    /**
+     * 校验分类是否存在且有效
+     * @param categoryId 分类ID
+     * @return 是否存在有效分类
+     */
+    boolean existCategory(Long categoryId) throws BusinessCheckException;
+
 }

+ 27 - 0
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/TableInfoService.java

@@ -71,8 +71,35 @@ public interface TableInfoService extends IService<MtTableInfo> {
 
 	List<MtTableInfo> selectTableListByStoreId(Long storeId, Long categoryId);
 
+
+
+
+
     /**
      * 校验分类是否存在
      */
     boolean existCategory(Long categoryId);
+
+    /**
+     * 根据桌分类id查询具体的餐桌信息
+     * @param categoryId
+     * @return
+     */
+    List<MtTableInfo> findByCategoryId(Long categoryId);
+
+    /**
+     * 保存餐桌信息
+     * @param entity
+     * @return
+     * @throws BusinessCheckException
+     */
+    boolean saveTable(MtTableInfo entity) throws BusinessCheckException;
+
+    /**
+     * 修改餐桌信息接口
+     * @param updateEntity
+     * @return
+     */
+    boolean updateTable(MtTableInfo updateEntity) throws BusinessCheckException;
+
 }

+ 18 - 0
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/TableCategoryServiceImpl.java

@@ -158,4 +158,22 @@ public class TableCategoryServiceImpl extends ServiceImpl<MtTableCategoryMapper,
         List<MtTableCategory> dataList = mtTableCategoryMapper.selectList(lambdaQueryWrapper);
         return dataList;
     }
+
+    /**
+     * 校验分类是否存在且有效
+     * @param categoryId 分类ID
+     * @return 是否存在有效分类
+     */
+    @Override
+    public boolean existCategory(Long categoryId) {
+        if (categoryId == null || categoryId < 1) {
+            return false;
+        }
+        // 构造查询条件(包含删除状态校验)
+        LambdaQueryWrapper<MtTableCategory> query = new LambdaQueryWrapper<>();
+        query.eq(MtTableCategory::getId, categoryId)
+                .eq(MtTableCategory::getDeleteFlag, 0); // 0-未删除
+        return mtTableCategoryMapper.selectCount(query) > 0;
+    }
+
 }

+ 42 - 2
fuintBackend/fuint-application/src/main/java/com/fuint/common/service/impl/TableInfoServiceImpl.java

@@ -3,7 +3,6 @@ package com.fuint.common.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fuint.common.service.TableCategoryService;
 import com.fuint.framework.annoation.OperationServiceLog;
 import com.fuint.framework.exception.BusinessCheckException;
 import com.fuint.framework.pagination.PaginationRequest;
@@ -16,7 +15,6 @@ import com.fuint.common.enums.StatusEnum;
 import com.fuint.repository.mapper.MtTableInfoMapper;
 import com.github.pagehelper.PageHelper;
 import lombok.AllArgsConstructor;
-import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import com.github.pagehelper.Page;
@@ -24,6 +22,7 @@ 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.*;
 
 /**
@@ -50,8 +49,11 @@ public class TableInfoServiceImpl extends ServiceImpl<MtTableInfoMapper, MtTable
      */
     @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);
@@ -180,4 +182,42 @@ public class TableInfoServiceImpl extends ServiceImpl<MtTableInfoMapper, MtTable
                         .eq(MtTableInfo::getId, categoryId)
         ) > 0;
     }
+
+    @Override
+    public List<MtTableInfo> findByCategoryId(Long categoryId) {
+        List<MtTableInfo> tableInfos = mtTableInfoMapper.findByCategoryId(categoryId);
+        return tableInfos;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean saveTable(MtTableInfo entity) throws BusinessCheckException {
+        // 校验桌号唯一性
+        LambdaQueryWrapper<MtTableInfo> query = new LambdaQueryWrapper<>();
+        query.eq(MtTableInfo::getTableNumber, entity.getTableNumber())
+                .eq(MtTableInfo::getDeleteFlag, 0);
+        if (mtTableInfoMapper.exists(query)) {
+            throw new BusinessCheckException("桌号已存在");
+        }
+
+        // 自动填充时间(兼容数据库自动填充)
+//        LocalDateTime now = LocalDateTime.now();
+        if (entity.getCreateTime() == null) {
+            entity.setCreateTime(new Date());
+        }
+        entity.setUpdateTime(new Date());
+
+        return mtTableInfoMapper.insert(entity) > 0;
+    }
+
+    /**
+     * 修改餐桌信息接口
+     * @param entity
+     * @return
+     */
+    @Override
+    public boolean updateTable(MtTableInfo entity) throws BusinessCheckException{
+        return updateById(entity);
+    }
+
 }

+ 185 - 25
fuintBackend/fuint-application/src/main/java/com/fuint/module/backendApi/controller/BackendTableInfoController.java

@@ -1,6 +1,10 @@
 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.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;
@@ -11,15 +15,19 @@ 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.model.MtTableCategory;
 import com.fuint.repository.model.MtTableInfo;
 import com.fuint.utils.StringUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.BeanUtils;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -38,6 +46,9 @@ public class BackendTableInfoController extends BaseController {
      * 餐桌信息服务接口
      */
     private TableInfoService tableInfoService;
+    private TableCategoryService categoryService;
+
+     private SettingService settingService;
 
     /**
      * 餐桌信息列表查询
@@ -48,15 +59,17 @@ public class BackendTableInfoController extends BaseController {
     @ApiOperation(value = "餐桌信息列表查询")
     @RequestMapping(value = "/list", method = RequestMethod.GET)
     @CrossOrigin
-    @PreAuthorize("@pms.hasPermission('table_info:list')")
+//    @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 title = request.getParameter("title");
+        String tableNumber = request.getParameter("tableNumber");
         String status = request.getParameter("status");
-        String searchStoreId = request.getParameter("storeId");
+        String categoryId = request.getParameter("categoryId");
 
+        // 2. 用户认证
         AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
         Long storeId;
         if (accountInfo == null) {
@@ -65,40 +78,51 @@ public class BackendTableInfoController extends BaseController {
             storeId = accountInfo.getStoreId();
         }
 
+        // 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 (StringUtil.isNotEmpty(title)) {
-            params.put("title", title);
+        // 店铺维度过滤
+        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(searchStoreId)) {
-            params.put("storeId", searchStoreId);
-        }
-        if (storeId != null && storeId > 0) {
-            params.put("storeId", storeId);
+        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> 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> 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("paginationResponse", paginationResponse);
+        result.put("paginationData", paginationResponse);
+        result.put("categoryList", categoryList);
+        result.put("imagePath", imagePath);
 
         return getSuccessResult(result);
     }
@@ -167,22 +191,158 @@ public class BackendTableInfoController extends BaseController {
     /**
      * 获取餐桌信息详情
      *
-     * @param id
+     * @param categoryId
      * @return
      */
-    @ApiOperation(value = "获取餐桌信息详情")
-    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
+    @ApiOperation(value = "根据餐桌分类id获取餐桌信息详情")
+    @RequestMapping(value = "/info/{categoryId}", method = RequestMethod.GET)
     @CrossOrigin
     @PreAuthorize("@pms.hasPermission('table_info:list')")
-    public ResponseObject info(HttpServletRequest request, @PathVariable("id") Integer id) throws BusinessCheckException {
+    public ResponseObject info(HttpServletRequest request, @PathVariable("categoryId") Long categoryId) throws BusinessCheckException {
         String token = request.getHeader("Access-Token");
         AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
         if (accountInfo == null) {
             return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
         }
 
-        Map<String, Object> result = new HashMap<>();
+        List<MtTableInfo> mtTableInfo = tableInfoService.findByCategoryId(categoryId);
 
-        return getSuccessResult(result);
+        return getSuccessResult(mtTableInfo);
+    }
+
+
+
+    @ApiOperation("新增餐桌信息接口")
+    @PostMapping("/create")
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('table:create')")
+    public ResponseObject createTable(
+            HttpServletRequest request,
+             @RequestBody TableInfoDto dto) throws BusinessCheckException {
+
+        // 身份验证
+        String token = request.getHeader("Access-Token");
+        AccountInfo account = TokenUtil.getAccountInfoByToken(token);
+        if (account == null) {
+            return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
+        }
+
+        // 校验分类是否存在
+        if (!categoryService.existCategory(dto.getCategoryId())) {
+            return getFailureResult(2001, "关联分类不存在");
+        }
+
+        // 构造实体
+        MtTableInfo entity = new MtTableInfo();
+        BeanUtils.copyProperties(dto, entity);
+        entity.setCreateUserId(account.getAccountName());
+        entity.setUpdateUserId(account.getAccountName());
+        entity.setTableStatus(0); // 默认空闲状态
+        entity.setDeleteFlag(0);
+
+        // 保存数据
+        boolean result = tableInfoService.saveTable(entity);
+        return result ? getSuccessResult(true) : getFailureResult(500, "保存失败");
+    }
+
+    @ApiOperation("修改餐桌信息接口")
+    @PostMapping("/update")
+    @CrossOrigin
+//    @PreAuthorize("@pms.hasPermission('table:update')")
+    public ResponseObject updateTable(
+            HttpServletRequest request,
+           @RequestBody TableInfoDto dto) throws BusinessCheckException {
+
+        // 1. 身份验证
+        String token = request.getHeader("Access-Token");
+        AccountInfo account = TokenUtil.getAccountInfoByToken(token);
+        if (account == null) {
+            return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
+        }
+
+        // 2. 校验基础数据
+        MtTableInfo existTable = tableInfoService.getById(dto.getId());
+        if (existTable == null || existTable.getDeleteFlag() == 1) {
+            return getFailureResult(201, "餐桌不存在或已被删除");
+        }
+
+        // 3. 业务校验
+        verifyUpdateData(dto, existTable, account);
+
+        // 4. 执行更新
+        MtTableInfo updateEntity = buildUpdateEntity(dto, existTable, account);
+        boolean result = tableInfoService.updateTable(updateEntity);
+
+        return result ? getSuccessResult(true) : getFailureResult(500, "更新失败");
     }
+
+
+
+
+    @ApiOperation("逻辑删除餐桌")
+    @DeleteMapping("/delete/{id}")
+    @CrossOrigin
+    @PreAuthorize("@pms.hasPermission('table:delete')")
+    public ResponseObject logicalDelete(
+            HttpServletRequest request,
+            @PathVariable Long id) throws BusinessCheckException {
+
+        // 1. 身份验证
+        String token = request.getHeader("Access-Token");
+        AccountInfo account = TokenUtil.getAccountInfoByToken(token);
+        if (account == null) {
+            return getFailureResult(1001, I18nUtil.getMessage("notAuthenticated"));
+        }
+
+        // 2. 校验数据存在性
+        MtTableInfo table = tableInfoService.getById(id);
+        if (table == null || table.getDeleteFlag().equals(1)) {
+            return getFailureResult(201, "餐桌不存在或已被删除");
+        }
+
+        // 3. 执行逻辑删除
+        MtTableInfo updateEntity = new MtTableInfo();
+        updateEntity.setId(id);
+        updateEntity.setDeleteFlag(1);
+        updateEntity.setUpdateUserId(account.getAccountName());
+        updateEntity.setUpdateTime(new Date());
+
+        boolean result = tableInfoService.updateById(updateEntity);
+        return result ? getSuccessResult(true) : getFailureResult(500, "删除失败");
+    }
+
+
+
+    private void verifyUpdateData(TableInfoDto dto, MtTableInfo existTable, AccountInfo account)
+            throws BusinessCheckException {
+
+        // 校验分类有效性
+        if (!categoryService.existCategory(dto.getCategoryId())) {
+            throw new BusinessCheckException("关联分类不存在");
+        }
+
+        // 校验桌号唯一性(排除自身)
+        LambdaQueryWrapper<MtTableInfo> query = new LambdaQueryWrapper<>();
+        query.ne(MtTableInfo::getId, dto.getId())
+                .eq(MtTableInfo::getTableNumber, dto.getTableNumber())
+                .eq(MtTableInfo::getDeleteFlag, 0);
+        if (tableInfoService.count(query) > 0) {
+            throw new BusinessCheckException("桌号已被使用");
+        }
+    }
+
+    private MtTableInfo buildUpdateEntity(TableInfoDto dto, MtTableInfo exist, AccountInfo account) {
+        MtTableInfo entity = new MtTableInfo();
+        BeanUtils.copyProperties(dto, entity);
+        entity.setUpdateUserId(account.getAccountName());
+        entity.setUpdateTime(new Date());
+
+        // 保留不可修改字段
+        entity.setCreateUserId(exist.getCreateUserId());
+        entity.setCreateTime(exist.getCreateTime());
+        entity.setDeleteFlag(exist.getDeleteFlag());
+
+        return entity;
+    }
+
 }

+ 22 - 0
fuintBackend/fuint-repository/src/main/java/com/fuint/repository/mapper/MtTableInfoMapper.java

@@ -1,7 +1,15 @@
 package com.fuint.repository.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.fuint.repository.model.MtTableInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+
+import java.util.List;
 
 /**
  * 餐桌信息 Mapper 接口
@@ -11,4 +19,18 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface MtTableInfoMapper extends BaseMapper<MtTableInfo> {
 
+
+
+    //根据分类id查询
+    @Select("SELECT * FROM mt_table_info WHERE category_id = #{categoryId} AND delete_flag = 0")
+    List<MtTableInfo> findByCategoryId(@Param("categoryId") Long categoryId);
+
+
+    /**
+     * 检查指定条件的记录是否存在
+     * @param queryWrapper 查询条件
+     * @return 是否存在符合条件的记录
+     */
+    @Select("SELECT 1 FROM mt_table_info ${ew.customSqlSegment} LIMIT 1")
+    Boolean exists(@Param(Constants.WRAPPER) Wrapper<MtTableInfo> queryWrapper);
 }