From bfdb3faf4f27df01718f58ac8c4ec0bcc092e7b6 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期六, 30 十一月 2024 18:50:47 +0800 Subject: [PATCH] 生成数据明细导出修改 --- ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java | 129 ++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 122 insertions(+), 7 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java index 220d113..79fc921 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java @@ -1,22 +1,29 @@ package com.ruoyi.web.controller.api; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.mysql.cj.xdevapi.Collection; import com.ruoyi.common.basic.PageInfo; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.system.domain.TShop; +import com.ruoyi.framework.web.service.TokenService; +import com.ruoyi.system.domain.*; import com.ruoyi.system.dto.TShopDTO; import com.ruoyi.system.query.TShopQuery; -import com.ruoyi.system.service.ISysUserService; -import com.ruoyi.system.service.TShopService; +import com.ruoyi.system.service.*; import com.ruoyi.system.vo.TShopVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; + +import static com.ruoyi.common.core.domain.AjaxResult.error; /** * <p> @@ -33,11 +40,35 @@ private final TShopService shopService; private final ISysUserService userService; + private final TBoardService boardService; + private final TokenService tokenService; + private final TGoodsService goodsService; + private final TGoodsTypeService goodsTypeService; + private final TOrderMealService mealService; + private final TOrderMealGoodsService mealGoodsService; + private final TOrderSaleService saleService; + private final TOrderSaleGoodsService saleGoodsService; + private final TOrderStockService stockService; + private final TOrderStockGoodsService stockGoodsService; + private final TStockDataSetService stockDataSetService; + private final TDataGeneratorService dataGeneratorService; @Autowired - public TShopController(TShopService shopService, ISysUserService userService) { + public TShopController(TShopService shopService, ISysUserService userService, TBoardService boardService, TokenService tokenService, TGoodsService goodsService, TGoodsTypeService goodsTypeService, TOrderMealService mealService, TOrderMealGoodsService mealGoodsService, TOrderSaleService saleService, TOrderSaleGoodsService saleGoodsService, TOrderStockService stockService, TOrderStockGoodsService stockGoodsService, TStockDataSetService stockDataSetService, TDataGeneratorService dataGeneratorService) { this.shopService = shopService; this.userService = userService; + this.boardService = boardService; + this.tokenService = tokenService; + this.goodsService = goodsService; + this.goodsTypeService = goodsTypeService; + this.mealService = mealService; + this.mealGoodsService = mealGoodsService; + this.saleService = saleService; + this.saleGoodsService = saleGoodsService; + this.stockService = stockService; + this.stockGoodsService = stockGoodsService; + this.stockDataSetService = stockDataSetService; + this.dataGeneratorService = dataGeneratorService; } /** @@ -55,9 +86,18 @@ @ApiOperation( value = "添加店铺信息") @PostMapping(value = "/add") public AjaxResult<String> add(@RequestBody TShopDTO dto) { + SysUser user = new SysUser(); + user.setUserName(dto.getAccount()); + user.setPhonenumber(dto.getAccount()); + if (!userService.checkUserNameUnique(user)) + { + return error("添加用户'" + user.getUserName() + "'失败,登录账号已存在"); + } shopService.save(dto); // 添加账号 - userService.addAccount(dto); + Long userId = userService.addAccount(dto); + dto.setUserId(userId); + shopService.updateById(dto); return AjaxResult.success(); } @@ -67,6 +107,14 @@ @ApiOperation( value = "编辑店铺信息") @PostMapping(value = "/edit") public AjaxResult<String> edit(@RequestBody TShopDTO dto) { + SysUser user = new SysUser(); + user.setUserName(dto.getAccount()); + user.setPhonenumber(dto.getAccount()); + user.setUserId(dto.getUserId()); + if (!userService.checkUserNameUnique(user)) + { + return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在"); + } shopService.updateById(dto); userService.updateAccount(dto); return AjaxResult.success(); @@ -77,8 +125,28 @@ */ @ApiOperation( value = "查看店铺信息详情") @GetMapping(value = "/getDetailById") - public AjaxResult<TShop> getDetailById(@RequestParam("id") Long id) { - return AjaxResult.success(shopService.getById(id)); + public AjaxResult<TShopVO> getDetailById(@RequestParam("id") Long id) { + TShop shop = shopService.getById(id); + TShopVO shopVO = new TShopVO(); + BeanUtils.copyProperties(shop,shopVO); + List<TBoard> list = boardService.list(Wrappers.lambdaQuery(TBoard.class) + .eq(TBoard::getShopId, id)); + shopVO.setBoards(list); + return AjaxResult.success(shopVO); + } + + /** + * 用户查看店铺信息详情 + */ + @ApiOperation( value = "用户查看店铺信息详情") + @GetMapping(value = "/getDetailByUserId") + public AjaxResult<TShop> getDetailByUserId() { + Integer roleType = tokenService.getLoginUser().getRoleType(); + if(roleType == 1){ + return error("该用户不是商家账号"); + } + return AjaxResult.success(shopService.getOne(Wrappers.<TShop>lambdaQuery().eq(TShop::getUserId, tokenService.getLoginUser().getUserId()) + .last("LIMIT 1"))); } /** @@ -93,6 +161,53 @@ if(Objects.nonNull(sysUser)){ userService.deleteUserById(sysUser.getUserId()); } + // 删除店铺下的桌子 + long boardCount = boardService.count(Wrappers.lambdaQuery(TBoard.class) + .eq(TBoard::getShopId, id)); + if(boardCount>0){ + boardService.deleteByShopId(id); + } + // 删除店铺下的餐品分类 + long goodsCount = goodsService.count(Wrappers.lambdaQuery(TGoods.class) + .eq(TGoods::getShopId, id)); + if(goodsCount>0){ + goodsService.deleteByShopId(id); + } + long goodsTypeCount = goodsTypeService.count(Wrappers.lambdaQuery(TGoodsType.class) + .eq(TGoodsType::getShopId, id)); + if (goodsTypeCount>0){ + goodsTypeService.deleteByShopId(id); + } + // 删除店铺下的餐饮订单 + List<TOrderMeal> mealList = mealService.list(Wrappers.lambdaQuery(TOrderMeal.class) + .eq(TOrderMeal::getShopId, id)); + List<Long> mealIds = mealList.stream().map(TOrderMeal::getId).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(mealIds)){ + mealGoodsService.deleteByOrderId(mealIds); + mealService.deleteByShopId(id); + } + // 删除店铺下的销售数据 + List<TOrderSale> saleList = saleService.list(Wrappers.lambdaQuery(TOrderSale.class) + .eq(TOrderSale::getShopId, id)); + List<Long> saleIds = saleList.stream().map(TOrderSale::getId).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(saleIds)){ + saleGoodsService.deleteByOrderId(saleIds); + saleService.deleteByShopId(id); + } + // 删除店铺下的进货数据 + List<TOrderStock> stockList = stockService.list(Wrappers.lambdaQuery(TOrderStock.class) + .eq(TOrderStock::getShopId, id)); + List<Long> stockIds = stockList.stream().map(TOrderStock::getId).collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(stockIds)){ + stockGoodsService.deleteByOrderId(stockIds); + stockService.deleteByShopId(id); + } + // 删除店铺下的生成数据 + long dataGeneratorCount = dataGeneratorService.count(Wrappers.lambdaQuery(TDataGenerator.class) + .eq(TDataGenerator::getShopId, id)); + if (dataGeneratorCount>0){ + dataGeneratorService.deleteByShopId(id); + } return AjaxResult.success(shopService.removeById(id)); } -- Gitblit v1.7.1