Browse Source

添加接口, 获取店铺下的所有人员,获取商户下的所有人员,获取商户下的所有店铺

gaohp 11 tháng trước cách đây
mục cha
commit
19dab1389b
14 tập tin đã thay đổi với 234 bổ sung2 xóa
  1. 22 0
      feifan-framework/feifan-common/src/main/java/cn/newfeifan/mall/framework/common/util/validation/ValidationUtils.java
  2. 7 0
      feifan-module-mall/feifan-module-promotion-api/src/main/java/cn/newfeifan/mall/module/promotion/enums/ErrorCodeConstants.java
  3. 6 0
      feifan-module-sale/feifan-module-sale-biz/pom.xml
  4. 20 0
      feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/controller/admin/merchant/MerchantController.java
  5. 58 2
      feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/controller/admin/shop/ShopController.java
  6. 28 0
      feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/service/shop/ShopService.java
  7. 36 0
      feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/service/shop/ShopServiceImpl.java
  8. 6 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserPageReqVO.java
  9. 11 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserRespVO.java
  10. 6 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserSaveReqVO.java
  11. 11 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/dal/dataobject/user/AdminUserDO.java
  12. 2 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/dal/mysql/user/AdminUserMapper.java
  13. 3 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserService.java
  14. 18 0
      feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserServiceImpl.java

+ 22 - 0
feifan-framework/feifan-common/src/main/java/cn/newfeifan/mall/framework/common/util/validation/ValidationUtils.java

@@ -2,6 +2,9 @@ package cn.newfeifan.mall.framework.common.util.validation;
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.lang.Assert;
+import cn.hutool.core.util.ObjectUtil;
+import cn.newfeifan.mall.framework.common.enums.UserTypeEnum;
+import cn.newfeifan.mall.framework.common.pojo.CommonResult;
 import org.springframework.util.StringUtils;
 
 import javax.validation.ConstraintViolation;
@@ -11,6 +14,10 @@ import javax.validation.Validator;
 import java.util.Set;
 import java.util.regex.Pattern;
 
+import static cn.newfeifan.mall.framework.common.exception.enums.GlobalErrorCodeConstants.FORBIDDEN;
+import static cn.newfeifan.mall.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.error;
+
 /**
  * 校验工具类
  *
@@ -52,4 +59,19 @@ public class ValidationUtils {
         }
     }
 
+//    /**
+//     * 判断是否是管理员账号, 不是管理员,没有权限
+//     */
+//    public static CommonResult checkAdmin(LoginUser loginUser){
+//        if (loginUser==null){
+//            return error(UNAUTHORIZED);
+//        }
+//        // 添加校验, 如果是平台用户的话, 就不能修改商户信息
+//        if (ObjectUtil.notEqual(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue())) {
+//            return error(FORBIDDEN);
+//        }
+//        return
+//    }
+
+
 }

+ 7 - 0
feifan-module-mall/feifan-module-promotion-api/src/main/java/cn/newfeifan/mall/module/promotion/enums/ErrorCodeConstants.java

@@ -125,4 +125,11 @@ public interface ErrorCodeConstants {
     ErrorCode DIY_PAGE_NOT_EXISTS = new ErrorCode(1_013_018_000, "装修页面不存在");
     ErrorCode DIY_PAGE_NAME_USED = new ErrorCode(1_013_018_001, "装修页面名称({})已经被使用");
 
+    // ========== 商户,店铺相关 ==========
+    ErrorCode SHOP_NOT_EXIST = new ErrorCode(1_013_019_000, "店铺不存在");
+    ErrorCode MER_NOT_EXIST = new ErrorCode(1_013_019_001, "商户不存在");
+
+
+
+
 }

+ 6 - 0
feifan-module-sale/feifan-module-sale-biz/pom.xml

@@ -37,6 +37,12 @@
             <version>${revision}</version>
         </dependency>
 
+        <dependency>
+            <groupId>cn.newfeifan.zx</groupId>
+            <artifactId>feifan-module-system-biz</artifactId>
+            <version>${revision}</version>
+        </dependency>
+
         <!-- 业务组件 -->
         <dependency>
             <groupId>cn.newfeifan.zx</groupId>

+ 20 - 0
feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/controller/admin/merchant/MerchantController.java

@@ -1,5 +1,9 @@
 package cn.newfeifan.mall.sale.controller.admin.merchant;
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.newfeifan.mall.framework.common.enums.UserTypeEnum;
+import cn.newfeifan.mall.framework.security.core.LoginUser;
+import cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils;
 import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantPageReqVO;
 import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantRespVO;
 import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantSaveReqVO;
@@ -22,6 +26,10 @@ import cn.newfeifan.mall.framework.common.pojo.PageParam;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.common.pojo.CommonResult;
 import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+
+import static cn.newfeifan.mall.framework.common.exception.enums.GlobalErrorCodeConstants.FORBIDDEN;
+import static cn.newfeifan.mall.framework.common.exception.enums.GlobalErrorCodeConstants.UNAUTHORIZED;
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.error;
 import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
 
 import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
@@ -50,6 +58,14 @@ public class MerchantController {
     @Operation(summary = "更新商户")
     @PreAuthorize("@ss.hasPermission('sale:merchant:update')")
     public CommonResult<Boolean> updateMerchant(@Valid @RequestBody MerchantSaveReqVO updateReqVO) {
+        /*LoginUser loginUser =  SecurityFrameworkUtils.getLoginUser();
+        if (loginUser==null){
+            return error(UNAUTHORIZED);
+        }
+        // 添加校验, 如果是平台用户的话, 就不能修改商户信息
+        if (ObjectUtil.notEqual(loginUser.getUserType(), UserTypeEnum.ADMIN.getValue())) {
+            return error(FORBIDDEN);
+        }*/
         merchantService.updateMerchant(updateReqVO);
         return success(true);
     }
@@ -72,6 +88,10 @@ public class MerchantController {
         return success(BeanUtils.toBean(merchant, MerchantRespVO.class));
     }
 
+
+
+
+
     @GetMapping("/page")
     @Operation(summary = "获得商户分页")
     @PreAuthorize("@ss.hasPermission('sale:merchant:query')")

+ 58 - 2
feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/controller/admin/shop/ShopController.java

@@ -1,11 +1,19 @@
 package cn.newfeifan.mall.sale.controller.admin.shop;
 
+import cn.newfeifan.mall.module.enums.ErrorCodeConstants;
+import cn.newfeifan.mall.module.system.api.user.dto.AdminUserRespDTO;
+import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserRespVO;
+import cn.newfeifan.mall.sale.controller.admin.merchant.vo.MerchantRespVO;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopPageReqVO;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopRespVO;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopSaveReqVO;
+import cn.newfeifan.mall.sale.dal.dataobject.merchant.MerchantDO;
+import cn.newfeifan.mall.sale.service.merchant.MerchantService;
 import cn.newfeifan.mall.sale.service.shop.ShopService;
 import org.springframework.web.bind.annotation.*;
+
 import javax.annotation.Resource;
+
 import org.springframework.validation.annotation.Validated;
 import org.springframework.security.access.prepost.PreAuthorize;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -16,17 +24,22 @@ import javax.validation.*;
 import javax.servlet.http.*;
 import java.util.*;
 import java.io.IOException;
+import java.util.stream.Collectors;
 
 import cn.newfeifan.mall.framework.common.pojo.PageParam;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.common.pojo.CommonResult;
 import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.error;
 import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
 
 import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
 
 import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
+
 import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;
+import static cn.newfeifan.mall.module.enums.ErrorCodeConstants.MERCHANT_NOT_EXISTS;
 
 import cn.newfeifan.mall.sale.dal.dataobject.shop.ShopDO;
 
@@ -36,6 +49,10 @@ import cn.newfeifan.mall.sale.dal.dataobject.shop.ShopDO;
 @Validated
 public class ShopController {
 
+
+    @Resource
+    private MerchantService merchantService;
+
     @Resource
     private ShopService shopService;
 
@@ -72,6 +89,45 @@ public class ShopController {
         return success(BeanUtils.toBean(shop, ShopRespVO.class));
     }
 
+
+    @GetMapping("/getAllShop")
+    @Operation(summary = "获得商户下所有店铺")
+    @Parameter(name = "merId", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('sale:merchant:query')")
+    public CommonResult<List<ShopRespVO>> getMerchantAllShop(@RequestParam("merId") Long merId) {
+        // 获取所有店铺
+        List<ShopRespVO> shops = shopService.getMerchantAllShop(merId);
+        return success(shops);
+    }
+
+
+    @GetMapping("/getAllUser")
+    @Operation(summary = "获取店铺下的所有人员列表")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('sale:merchant:query')")
+    public CommonResult<List<UserRespVO>> getAllUser(@RequestParam("id") Long id) {
+        // 获取所有店铺
+        List<UserRespVO> shops = shopService.getAllUser(id);
+        return success(shops);
+    }
+
+
+    @GetMapping("/getAllUserByMer")
+    @Operation(summary = "获取商户下的所有人员列表")
+    @Parameter(name = "merId", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('sale:merchant:query')")
+    public CommonResult<List<UserRespVO>> getAllUserByMer(@RequestParam("merId") Long merId) {
+        // 获取所有店铺
+        List<ShopRespVO> shops = shopService.getMerchantAllShop(merId);
+        if (shops.isEmpty()) {
+            return success(Collections.emptyList());
+        }
+        List<Long> shopIds = shops.stream().map(ShopRespVO::getId).collect(Collectors.toList());
+        List<UserRespVO> userRespVOS = shopService.getAllUser(shopIds);
+        return success(userRespVOS);
+    }
+
+
     @GetMapping("/page")
     @Operation(summary = "获得店铺分页")
     @PreAuthorize("@ss.hasPermission('sale:shop:query')")
@@ -85,12 +141,12 @@ public class ShopController {
     @PreAuthorize("@ss.hasPermission('sale:shop:export')")
     @OperateLog(type = EXPORT)
     public void exportShopExcel(@Valid ShopPageReqVO pageReqVO,
-              HttpServletResponse response) throws IOException {
+                                HttpServletResponse response) throws IOException {
         pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
         List<ShopDO> list = shopService.getShopPage(pageReqVO).getList();
         // 导出 Excel
         ExcelUtils.write(response, "店铺.xls", "数据", ShopRespVO.class,
-                        BeanUtils.toBean(list, ShopRespVO.class));
+                BeanUtils.toBean(list, ShopRespVO.class));
     }
 
 }

+ 28 - 0
feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/service/shop/ShopService.java

@@ -1,11 +1,16 @@
 package cn.newfeifan.mall.sale.service.shop;
 
 import javax.validation.*;
+
+import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserRespVO;
+import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopRespVO;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopSaveReqVO;
 import cn.newfeifan.mall.sale.dal.dataobject.shop.ShopDO;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopPageReqVO;
 
+import java.util.List;
+
 /**
  * 店铺 Service 接口
  *
@@ -51,4 +56,27 @@ public interface ShopService {
      */
     PageResult<ShopDO> getShopPage(ShopPageReqVO pageReqVO);
 
+
+    /**
+     * 获取商户下的所有店铺
+     * @param merId
+     * @return
+     */
+    List<ShopRespVO> getMerchantAllShop(Long merId);
+
+
+    /**
+     * 获取店铺下的所有用户
+     * @param id
+     * @return
+     */
+    List<UserRespVO> getAllUser(Long id);
+
+    /**
+     * 根据店铺列表获取所有的用户
+     * @param shopIds
+     * @return
+     */
+    List<UserRespVO> getAllUser(List<Long> shopIds);
+
 }

+ 36 - 0
feifan-module-sale/feifan-module-sale-biz/src/main/java/cn/newfeifan/mall/sale/service/shop/ShopServiceImpl.java

@@ -1,16 +1,25 @@
 package cn.newfeifan.mall.sale.service.shop;
 
+import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserRespVO;
+import cn.newfeifan.mall.module.system.dal.dataobject.user.AdminUserDO;
+import cn.newfeifan.mall.module.system.service.user.AdminUserService;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopPageReqVO;
+import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopRespVO;
 import cn.newfeifan.mall.sale.controller.admin.shop.vo.ShopSaveReqVO;
 import cn.newfeifan.mall.sale.dal.mysql.shop.ShopMapper;
 import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
+
 import org.springframework.validation.annotation.Validated;
 
 import cn.newfeifan.mall.sale.dal.dataobject.shop.ShopDO;
 import cn.newfeifan.mall.framework.common.pojo.PageResult;
 import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
 
+import java.util.List;
+import java.util.stream.Collectors;
+
 import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
 import static cn.newfeifan.mall.module.enums.ErrorCodeConstants.SHOP_NOT_EXISTS;
 
@@ -68,4 +77,31 @@ public class ShopServiceImpl implements ShopService {
         return shopMapper.selectPage(pageReqVO);
     }
 
+    @Override
+    public List<ShopRespVO> getMerchantAllShop(Long merId) {
+        List<ShopDO> shopDOS = shopMapper.selectList();
+        // 筛选
+        shopDOS = shopDOS.stream().filter(k -> k.getMerchantId() != null && k.getMerchantId().equals(merId)).collect(Collectors.toList());
+        return BeanUtils.toBean(shopDOS, ShopRespVO.class);
+    }
+
+    @Resource
+    private AdminUserService userService;
+
+    @Override
+    public List<UserRespVO> getAllUser(Long id) {
+
+        List<AdminUserDO> userRespVO = userService.getUserByShopId(id);
+
+        return BeanUtils.toBean(userRespVO, UserRespVO.class);
+    }
+
+    @Override
+    public List<UserRespVO> getAllUser(List<Long> shopIds) {
+
+        List<AdminUserDO> userRespVO = userService.getUserByShopIds(shopIds);
+
+        return BeanUtils.toBean(userRespVO, UserRespVO.class);
+    }
+
 }

+ 6 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserPageReqVO.java

@@ -38,4 +38,10 @@ public class UserPageReqVO extends PageParam {
     @Schema(description = "所在地", example = "26117")
     private Long areaId;
 
+    @Schema(description = "用户类型", example = "9160")
+    private Long categoryId;
+
+    @Schema(description = "店铺id", example = "9887")
+    private Long shopId;
+
 }

+ 11 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserRespVO.java

@@ -75,4 +75,15 @@ public class UserRespVO{
     @ExcelProperty("所在地")
     private Long areaId;
 
+
+    @Schema(description = "用户类型", example = "9160")
+    private Long categoryId;
+
+    @Schema(description = "店铺id", example = "9887")
+    private Long shopId;
+
+
+
+
+
 }

+ 6 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/controller/admin/user/vo/user/UserSaveReqVO.java

@@ -54,6 +54,12 @@ public class UserSaveReqVO {
     @Schema(description = "所在地", example = "26117")
     private Long areaId;
 
+    @Schema(description = "用户类型", example = "9160")
+    private Long categoryId;
+
+    @Schema(description = "店铺id", example = "9887")
+    private Long shopId;
+
     // ========== 仅【创建】时,需要传递的字段 ==========
 
     @Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")

+ 11 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/dal/dataobject/user/AdminUserDO.java

@@ -99,6 +99,17 @@ public class AdminUserDO extends TenantBaseDO {
      */
     private Long areaId;
 
+    /**
+     * 所在地
+     */
+    private Long categoryId;
+
+
+    /**
+     * 店铺id
+     */
+    private Long shopId;
+
 
 
 

+ 2 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/dal/mysql/user/AdminUserMapper.java

@@ -31,6 +31,8 @@ public interface AdminUserMapper extends BaseMapperX<AdminUserDO> {
                 .likeIfPresent(AdminUserDO::getMobile, reqVO.getMobile())
                 .eqIfPresent(AdminUserDO::getStatus, reqVO.getStatus())
                 .eqIfPresent(AdminUserDO::getAreaId, reqVO.getAreaId())
+                .eqIfPresent(AdminUserDO::getCategoryId, reqVO.getCategoryId())
+                .eqIfPresent(AdminUserDO::getShopId, reqVO.getShopId())
                 .betweenIfPresent(AdminUserDO::getCreateTime, reqVO.getCreateTime())
                 .inIfPresent(AdminUserDO::getDeptId, deptIds)
                 .orderByDesc(AdminUserDO::getId));

+ 3 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserService.java

@@ -201,4 +201,7 @@ public interface AdminUserService {
      */
     boolean isPasswordMatch(String rawPassword, String encodedPassword);
 
+    List<AdminUserDO> getUserByShopId(Long id);
+
+    List<AdminUserDO> getUserByShopIds(List<Long> shopIds);
 }

+ 18 - 0
feifan-module-system/feifan-module-system-biz/src/main/java/cn/newfeifan/mall/module/system/service/user/AdminUserServiceImpl.java

@@ -26,6 +26,7 @@ import cn.newfeifan.mall.module.system.service.dept.DeptService;
 import cn.newfeifan.mall.module.system.service.dept.PostService;
 import cn.newfeifan.mall.module.system.service.permission.PermissionService;
 import cn.newfeifan.mall.module.system.service.tenant.TenantService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.google.common.annotations.VisibleForTesting;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
@@ -282,6 +283,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 
     /**
      * 获得部门条件:查询指定部门的子部门编号们,包括自身
+     *
      * @param deptId 部门编号
      * @return 部门编号集合
      */
@@ -380,6 +382,7 @@ public class AdminUserServiceImpl implements AdminUserService {
 
     /**
      * 校验旧密码
+     *
      * @param id          用户 id
      * @param oldPassword 旧密码
      */
@@ -442,6 +445,21 @@ public class AdminUserServiceImpl implements AdminUserService {
         return passwordEncoder.matches(rawPassword, encodedPassword);
     }
 
+    @Override
+    public List<AdminUserDO> getUserByShopId(Long id) {
+        return userMapper.selectList(new LambdaQueryWrapper<AdminUserDO>().eq(AdminUserDO::getShopId, id));
+    }
+
+    @Override
+    public List<AdminUserDO> getUserByShopIds(List<Long> shopIds) {
+
+        if (shopIds.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        return userMapper.selectList(new LambdaQueryWrapper<AdminUserDO>().in(AdminUserDO::getShopId, shopIds));
+    }
+
     /**
      * 对密码进行加密
      *