|
@@ -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;
|
|
|
+ }
|
|
|
+
|
|
|
}
|