|
@@ -0,0 +1,338 @@
|
|
|
+package com.tourism.webadmin.back.controller;
|
|
|
+
|
|
|
+import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.tourism.common.log.annotation.OperationLog;
|
|
|
+import com.tourism.common.log.model.constant.SysOperationLogType;
|
|
|
+import com.github.pagehelper.page.PageMethod;
|
|
|
+import com.tourism.webadmin.back.vo.*;
|
|
|
+import com.tourism.webadmin.back.dto.*;
|
|
|
+import com.tourism.webadmin.back.model.*;
|
|
|
+import com.tourism.webadmin.back.service.*;
|
|
|
+import com.tourism.common.core.object.*;
|
|
|
+import com.tourism.common.core.util.*;
|
|
|
+import com.tourism.common.core.constant.*;
|
|
|
+import com.tourism.common.core.annotation.MyRequestBody;
|
|
|
+import com.tourism.common.additional.config.ApplicationConfig;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springdoc.core.annotations.ParameterObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 餐馆区域管理操作控制器类。
|
|
|
+ *
|
|
|
+ * @author 吃饭睡觉
|
|
|
+ * @date 2024-09-06
|
|
|
+ */
|
|
|
+@Tag(name = "餐馆区域管理管理接口")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/admin/app/restaurantAreaMenu")
|
|
|
+public class RestaurantAreaMenuController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ApplicationConfig appConfig;
|
|
|
+ @Autowired
|
|
|
+ private RestaurantAreaMenuService restaurantAreaMenuService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增餐馆区域管理数据。
|
|
|
+ *
|
|
|
+ * @param restaurantAreaMenuDto 新增对象。
|
|
|
+ * @return 应答结果对象,包含新增对象主键Id。
|
|
|
+ */
|
|
|
+ @ApiOperationSupport(ignoreParameters = {"restaurantAreaMenuDto.id"})
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.add")
|
|
|
+ @OperationLog(type = SysOperationLogType.ADD)
|
|
|
+ @PostMapping("/add")
|
|
|
+ public ResponseResult<Long> add(@MyRequestBody RestaurantAreaMenuDto restaurantAreaMenuDto) {
|
|
|
+ String errorMessage = MyCommonUtil.getModelValidationError(restaurantAreaMenuDto, false);
|
|
|
+ if (errorMessage != null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
|
|
|
+ }
|
|
|
+ RestaurantAreaMenu restaurantAreaMenu = MyModelUtil.copyTo(restaurantAreaMenuDto, RestaurantAreaMenu.class);
|
|
|
+ // 验证关联Id的数据合法性
|
|
|
+ CallResult callResult = restaurantAreaMenuService.verifyRelatedData(restaurantAreaMenu, null);
|
|
|
+ if (!callResult.isSuccess()) {
|
|
|
+ return ResponseResult.errorFrom(callResult);
|
|
|
+ }
|
|
|
+ // 验证父Id的数据合法性
|
|
|
+ RestaurantAreaMenu parentRestaurantAreaMenu;
|
|
|
+ if (MyCommonUtil.isNotBlankOrNull(restaurantAreaMenu.getParentId())) {
|
|
|
+ parentRestaurantAreaMenu = restaurantAreaMenuService.getById(restaurantAreaMenu.getParentId());
|
|
|
+ if (parentRestaurantAreaMenu == null) {
|
|
|
+ errorMessage = "数据验证失败,关联的父节点并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ restaurantAreaMenu = restaurantAreaMenuService.saveNew(restaurantAreaMenu);
|
|
|
+ return ResponseResult.success(restaurantAreaMenu.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新餐馆区域管理数据。
|
|
|
+ *
|
|
|
+ * @param restaurantAreaMenuDto 更新对象。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.update")
|
|
|
+ @OperationLog(type = SysOperationLogType.UPDATE)
|
|
|
+ @PostMapping("/update")
|
|
|
+ public ResponseResult<Void> update(@MyRequestBody RestaurantAreaMenuDto restaurantAreaMenuDto) {
|
|
|
+ String errorMessage = MyCommonUtil.getModelValidationError(restaurantAreaMenuDto, true);
|
|
|
+ if (errorMessage != null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_VALIDATED_FAILED, errorMessage);
|
|
|
+ }
|
|
|
+ RestaurantAreaMenu restaurantAreaMenu = MyModelUtil.copyTo(restaurantAreaMenuDto, RestaurantAreaMenu.class);
|
|
|
+ RestaurantAreaMenu originalRestaurantAreaMenu = restaurantAreaMenuService.getById(restaurantAreaMenu.getId());
|
|
|
+ if (originalRestaurantAreaMenu == null) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,当前 [数据] 并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ // 验证关联Id的数据合法性
|
|
|
+ CallResult callResult = restaurantAreaMenuService.verifyRelatedData(restaurantAreaMenu, originalRestaurantAreaMenu);
|
|
|
+ if (!callResult.isSuccess()) {
|
|
|
+ return ResponseResult.errorFrom(callResult);
|
|
|
+ }
|
|
|
+ // 验证父Id的数据合法性
|
|
|
+ if (MyCommonUtil.isNotBlankOrNull(restaurantAreaMenu.getParentId())
|
|
|
+ && ObjectUtil.notEqual(restaurantAreaMenu.getParentId(), originalRestaurantAreaMenu.getParentId())) {
|
|
|
+ RestaurantAreaMenu parentRestaurantAreaMenu = restaurantAreaMenuService.getById(restaurantAreaMenu.getParentId());
|
|
|
+ if (parentRestaurantAreaMenu == null) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,关联的 [父节点] 并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_PARENT_ID_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!restaurantAreaMenuService.update(restaurantAreaMenu, originalRestaurantAreaMenu)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除餐馆区域管理数据。
|
|
|
+ *
|
|
|
+ * @param id 删除对象主键Id。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.delete")
|
|
|
+ @OperationLog(type = SysOperationLogType.DELETE)
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public ResponseResult<Void> delete(@MyRequestBody Long id) {
|
|
|
+ if (MyCommonUtil.existBlankArgument(id)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
|
|
+ }
|
|
|
+ return this.doDelete(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除餐馆区域管理数据。
|
|
|
+ *
|
|
|
+ * @param idList 待删除对象的主键Id列表。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.delete")
|
|
|
+ @OperationLog(type = SysOperationLogType.DELETE_BATCH)
|
|
|
+ @PostMapping("/deleteBatch")
|
|
|
+ public ResponseResult<Void> deleteBatch(@MyRequestBody List<Long> idList) {
|
|
|
+ if (MyCommonUtil.existBlankArgument(idList)) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.ARGUMENT_NULL_EXIST);
|
|
|
+ }
|
|
|
+ for (Long id : idList) {
|
|
|
+ ResponseResult<Void> responseResult = this.doDelete(id);
|
|
|
+ if (!responseResult.isSuccess()) {
|
|
|
+ return responseResult;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 列出符合过滤条件的餐馆区域管理列表。
|
|
|
+ *
|
|
|
+ * @param restaurantAreaMenuDtoFilter 过滤对象。
|
|
|
+ * @param orderParam 排序参数。
|
|
|
+ * @param pageParam 分页参数。
|
|
|
+ * @return 应答结果对象,包含查询结果集。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.view")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public ResponseResult<MyPageData<RestaurantAreaMenuVo>> list(
|
|
|
+ @MyRequestBody RestaurantAreaMenuDto restaurantAreaMenuDtoFilter,
|
|
|
+ @MyRequestBody MyOrderParam orderParam,
|
|
|
+ @MyRequestBody MyPageParam pageParam) {
|
|
|
+ if (pageParam != null) {
|
|
|
+ PageMethod.startPage(pageParam.getPageNum(), pageParam.getPageSize(), pageParam.getCount());
|
|
|
+ }
|
|
|
+ RestaurantAreaMenu restaurantAreaMenuFilter = MyModelUtil.copyTo(restaurantAreaMenuDtoFilter, RestaurantAreaMenu.class);
|
|
|
+ String orderBy = MyOrderParam.buildOrderBy(orderParam, RestaurantAreaMenu.class);
|
|
|
+ List<RestaurantAreaMenu> restaurantAreaMenuList =
|
|
|
+ restaurantAreaMenuService.getRestaurantAreaMenuListWithRelation(restaurantAreaMenuFilter, orderBy);
|
|
|
+ return ResponseResult.success(MyPageUtil.makeResponseData(restaurantAreaMenuList, RestaurantAreaMenuVo.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入主表数据列表。
|
|
|
+ *
|
|
|
+ * @param importFile 上传的文件,目前仅仅支持xlsx和xls两种格式。
|
|
|
+ * @return 应答结果对象。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.import")
|
|
|
+ @OperationLog(type = SysOperationLogType.IMPORT)
|
|
|
+ @PostMapping("/import")
|
|
|
+ public ResponseResult<Void> importBatch(
|
|
|
+ @RequestParam Boolean skipHeader,
|
|
|
+ @RequestParam("importFile") MultipartFile importFile) throws IOException {
|
|
|
+ String filename = ImportUtil.saveImportFile(appConfig.getUploadFileBaseDir(), null, importFile);
|
|
|
+ // 这里可以指定需要忽略导入的字段集合。如创建时间、创建人、更新时间、更新人、主键Id和逻辑删除,
|
|
|
+ // 以及一些存在缺省值且无需导入的字段。其中主键字段和逻辑删除字段不需要在这里设置,批量插入逻辑会自动处理的。
|
|
|
+ Set<String> ignoreFieldSet = new HashSet<>();
|
|
|
+ ignoreFieldSet.add("createUserId");
|
|
|
+ ignoreFieldSet.add("createTime");
|
|
|
+ ignoreFieldSet.add("updateUserId");
|
|
|
+ ignoreFieldSet.add("updateTime");
|
|
|
+ List<ImportUtil.ImportHeaderInfo> headerInfoList = ImportUtil.makeHeaderInfoList(RestaurantAreaMenu.class, ignoreFieldSet);
|
|
|
+ // 下面是导入时需要注意的地方,如果我们缺省生成的代码,与实际情况存在差异,请手动修改。
|
|
|
+ // 1. 头信息数据字段,我们只是根据当前的主表实体对象生成了缺省数组,开发者可根据实际情况,对headerInfoList进行修改。
|
|
|
+ ImportUtil.ImportHeaderInfo[] headerInfos = headerInfoList.toArray(new ImportUtil.ImportHeaderInfo[]{});
|
|
|
+ // 2. 这里需要根据实际情况决定,导入文件中第一行是否为中文头信息,如果是可以跳过。这里我们默认为true。
|
|
|
+ // 这里根据自己的实际需求,为doImport的最后一个参数,传递需要进行字典转换的字段集合。
|
|
|
+ // 注意,集合中包含需要翻译的Java字段名,如: gradeId。
|
|
|
+ Set<String> translatedDictFieldSet = new HashSet<>();
|
|
|
+ List<RestaurantAreaMenu> dataList =
|
|
|
+ ImportUtil.doImport(headerInfos, skipHeader, filename, RestaurantAreaMenu.class, translatedDictFieldSet);
|
|
|
+ CallResult result = restaurantAreaMenuService.verifyImportList(dataList, translatedDictFieldSet);
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ // result中返回了具体的验证失败对象,如果需要返回更加详细的错误,可根据实际情况手动修改。
|
|
|
+ return ResponseResult.errorFrom(result);
|
|
|
+ }
|
|
|
+ restaurantAreaMenuService.saveNewBatch(dataList, -1);
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出符合过滤条件的餐馆区域管理列表。
|
|
|
+ *
|
|
|
+ * @param restaurantAreaMenuDtoFilter 过滤对象。
|
|
|
+ * @param orderParam 排序参数。
|
|
|
+ * @throws IOException 文件读写失败。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.export")
|
|
|
+ @OperationLog(type = SysOperationLogType.EXPORT, saveResponse = false)
|
|
|
+ @PostMapping("/export")
|
|
|
+ public void export(
|
|
|
+ @MyRequestBody RestaurantAreaMenuDto restaurantAreaMenuDtoFilter,
|
|
|
+ @MyRequestBody MyOrderParam orderParam) throws IOException {
|
|
|
+ RestaurantAreaMenu restaurantAreaMenuFilter = MyModelUtil.copyTo(restaurantAreaMenuDtoFilter, RestaurantAreaMenu.class);
|
|
|
+ String orderBy = MyOrderParam.buildOrderBy(orderParam, RestaurantAreaMenu.class);
|
|
|
+ List<RestaurantAreaMenu> resultList =
|
|
|
+ restaurantAreaMenuService.getRestaurantAreaMenuListWithRelation(restaurantAreaMenuFilter, orderBy);
|
|
|
+ // 导出文件的标题数组
|
|
|
+ // NOTE: 下面的代码中仅仅导出了主表数据,主表聚合计算数据和主表关联字典的数据。
|
|
|
+ // 一对一从表数据的导出,可根据需要自行添加。如:headerMap.put("slaveFieldName.xxxField", "标题名称")
|
|
|
+ Map<String, String> headerMap = new LinkedHashMap<>(13);
|
|
|
+ headerMap.put("id", "主键id");
|
|
|
+ headerMap.put("parentIdDictMap.name", "父级id");
|
|
|
+ headerMap.put("levelNum", "菜单等级");
|
|
|
+ headerMap.put("levelName", "菜单名称");
|
|
|
+ headerMap.put("showOrder", "显示顺序");
|
|
|
+ headerMap.put("enableDictMap.name", "是否启用,0禁用,1启用");
|
|
|
+ headerMap.put("isHotspotDictMap.name", "是否热点,0非热点,1热点");
|
|
|
+ headerMap.put("hotOrder", "热门排序");
|
|
|
+ headerMap.put("createUserId", "创建用户");
|
|
|
+ headerMap.put("createTime", "创建时间");
|
|
|
+ headerMap.put("updateUserId", "更新用户");
|
|
|
+ headerMap.put("updateTime", "更新时间");
|
|
|
+ headerMap.put("dataState", "删除标记(1: 正常 -1: 已删除)");
|
|
|
+ ExportUtil.doExport(resultList, headerMap, "restaurantAreaMenu.xlsx");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看指定餐馆区域管理对象详情。
|
|
|
+ *
|
|
|
+ * @param id 指定对象主键Id。
|
|
|
+ * @return 应答结果对象,包含对象详情。
|
|
|
+ */
|
|
|
+ @SaCheckPermission("restaurantAreaMenu.view")
|
|
|
+ @GetMapping("/view")
|
|
|
+ public ResponseResult<RestaurantAreaMenuVo> view(@RequestParam Long id) {
|
|
|
+ RestaurantAreaMenu restaurantAreaMenu = restaurantAreaMenuService.getByIdWithRelation(id, MyRelationParam.full());
|
|
|
+ if (restaurantAreaMenu == null) {
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ RestaurantAreaMenuVo restaurantAreaMenuVo = MyModelUtil.copyTo(restaurantAreaMenu, RestaurantAreaMenuVo.class);
|
|
|
+ return ResponseResult.success(restaurantAreaMenuVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 以字典形式返回全部餐馆区域管理数据集合。字典的键值为[id, levelName]。
|
|
|
+ * 白名单接口,登录用户均可访问。
|
|
|
+ *
|
|
|
+ * @param filter 过滤对象。
|
|
|
+ * @return 应答结果对象,包含的数据为 List<Map<String, String>>,map中包含两条记录,key的值分别是id和name,value对应具体数据。
|
|
|
+ */
|
|
|
+ @GetMapping("/listDict")
|
|
|
+ public ResponseResult<List<Map<String, Object>>> listDict(@ParameterObject RestaurantAreaMenuDto filter) {
|
|
|
+ List<RestaurantAreaMenu> resultList =
|
|
|
+ restaurantAreaMenuService.getListByFilter(MyModelUtil.copyTo(filter, RestaurantAreaMenu.class));
|
|
|
+ return ResponseResult.success(MyCommonUtil.toDictDataList(
|
|
|
+ resultList, RestaurantAreaMenu::getId, RestaurantAreaMenu::getLevelName, RestaurantAreaMenu::getParentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据字典Id集合,获取查询后的字典数据。
|
|
|
+ *
|
|
|
+ * @param dictIds 字典Id集合。
|
|
|
+ * @return 应答结果对象,包含字典形式的数据集合。
|
|
|
+ */
|
|
|
+ @GetMapping("/listDictByIds")
|
|
|
+ public ResponseResult<List<Map<String, Object>>> listDictByIds(@RequestParam List<Long> dictIds) {
|
|
|
+ List<RestaurantAreaMenu> resultList = restaurantAreaMenuService.getInList(new HashSet<>(dictIds));
|
|
|
+ return ResponseResult.success(MyCommonUtil.toDictDataList(
|
|
|
+ resultList, RestaurantAreaMenu::getId, RestaurantAreaMenu::getLevelName, RestaurantAreaMenu::getParentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据父主键Id,以字典的形式返回其下级数据列表。
|
|
|
+ * 白名单接口,登录用户均可访问。
|
|
|
+ *
|
|
|
+ * @param parentId 父主键Id。
|
|
|
+ * @return 按照字典的形式返回下级数据列表。
|
|
|
+ */
|
|
|
+ @GetMapping("/listDictByParentId")
|
|
|
+ public ResponseResult<List<Map<String, Object>>> listDictByParentId(@RequestParam(required = false) Long parentId) {
|
|
|
+ List<RestaurantAreaMenu> resultList = restaurantAreaMenuService.getListByParentId("parentId", parentId);
|
|
|
+ return ResponseResult.success(MyCommonUtil.toDictDataList(
|
|
|
+ resultList, RestaurantAreaMenu::getId, RestaurantAreaMenu::getLevelName, RestaurantAreaMenu::getParentId));
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseResult<Void> doDelete(Long id) {
|
|
|
+ String errorMessage;
|
|
|
+ // 验证关联Id的数据合法性
|
|
|
+ RestaurantAreaMenu originalRestaurantAreaMenu = restaurantAreaMenuService.getById(id);
|
|
|
+ if (originalRestaurantAreaMenu == null) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,当前 [对象] 并不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ if (restaurantAreaMenuService.hasChildren(id)) {
|
|
|
+ // NOTE: 修改下面方括号中的话述
|
|
|
+ errorMessage = "数据验证失败,当前 [对象存在子对象] ,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.HAS_CHILDREN_DATA, errorMessage);
|
|
|
+ }
|
|
|
+ if (!restaurantAreaMenuService.remove(id)) {
|
|
|
+ errorMessage = "数据操作失败,删除的对象不存在,请刷新后重试!";
|
|
|
+ return ResponseResult.error(ErrorCodeEnum.DATA_NOT_EXIST, errorMessage);
|
|
|
+ }
|
|
|
+ return ResponseResult.success();
|
|
|
+ }
|
|
|
+}
|