Pārlūkot izejas kodu

新增接口,返回职位及列表

zhangchen 2 dienas atpakaļ
vecāks
revīzija
9f9ff50e89

+ 27 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreStaffPositionCountVo.java

@@ -0,0 +1,27 @@
+package shop.alien.entity.store.vo;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 员工职位统计VO
+ *
+ * @author system
+ * @since 2025-01-XX
+ */
+@Data
+@ApiModel(value = "StoreStaffPositionCountVo对象", description = "员工职位统计")
+public class StoreStaffPositionCountVo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "员工职位")
+    private String staffPosition;
+
+    @ApiModelProperty(value = "该职位对应的员工数量")
+    private Long count;
+}
+

+ 42 - 4
alien-store/src/main/java/shop/alien/store/controller/StoreStaffConfigController.java

@@ -12,6 +12,7 @@ import shop.alien.entity.store.StoreStaffConfig;
 import shop.alien.entity.store.dto.StoreStaffConfigListQueryDto;
 import shop.alien.entity.store.vo.StoreStaffDetailVo;
 import shop.alien.entity.store.vo.StoreStaffFitnessDetailVo;
+import shop.alien.entity.store.vo.StoreStaffPositionCountVo;
 import shop.alien.mapper.StoreDictionaryMapper;
 import shop.alien.store.service.StoreStaffConfigService;
 
@@ -150,15 +151,17 @@ public class StoreStaffConfigController {
             @ApiImplicitParam(name = "page", value = "分页页数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "size", value = "分页条数", dataType = "Integer", paramType = "query", required = false),
             @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true),
-            @ApiImplicitParam(name = "status", value = "员工状态(0-待审核 1-审核通过 2-审核拒绝)", dataType = "String", paramType = "query", required = false)
+            @ApiImplicitParam(name = "status", value = "员工状态(0-待审核 1-审核通过 2-审核拒绝)", dataType = "String", paramType = "query", required = false),
+            @ApiImplicitParam(name = "staffPosition", value = "员工职位", dataType = "String", paramType = "query", required = false)
     })
     @GetMapping("/queryStaffList")
     public R<IPage<StoreStaffConfig>> queryStaffList(
             @RequestParam(value = "page", defaultValue = "1") Integer page,
             @RequestParam(value = "size", defaultValue = "10") Integer size,
             @RequestParam(value = "storeId") Integer storeId,
-            @RequestParam(value = "status", required = false) String status) {
-        log.info("查询员工列表,参数:page={}, size={}, storeId={}, status={}", page, size, storeId, status);
+            @RequestParam(value = "status", required = false) String status,
+            @RequestParam(value = "staffPosition", required = false) String staffPosition) {
+        log.info("查询员工列表,参数:page={}, size={}, storeId={}, status={}, staffPosition={}", page, size, storeId, status, staffPosition);
 
         // 参数校验
         if (storeId == null || storeId <= 0) {
@@ -176,7 +179,7 @@ public class StoreStaffConfigController {
             size = 100;
         }
 
-        IPage<StoreStaffConfig> result = storeStaffConfigService.queryStaffList(page, size, storeId, status);
+        IPage<StoreStaffConfig> result = storeStaffConfigService.queryStaffList(page, size, storeId, status, staffPosition);
         log.info("查询员工列表成功,共{}条记录", result.getTotal());
         return R.data(result);
     }
@@ -373,4 +376,39 @@ public class StoreStaffConfigController {
         }
     }
 
+    /**
+     * 查询指定店铺的员工职位统计信息
+     *
+     * @param storeId 店铺ID,必填
+     * @return 员工职位统计列表,每个元素包含职位名称和对应员工数量
+     */
+    @ApiOperation("查询员工职位统计(用户端)")
+    @ApiOperationSupport(order = 10)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "storeId", value = "店铺ID", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getStaffPositionCount")
+    public R<List<StoreStaffPositionCountVo>> getStaffPositionCount(
+            @RequestParam(value = "storeId") Integer storeId) {
+        log.info("查询员工职位统计,参数:storeId={}", storeId);
+
+        try {
+            // 参数校验
+            if (storeId == null || storeId <= 0) {
+                log.warn("查询员工职位统计失败,店铺ID无效:storeId={}", storeId);
+                return R.fail("店铺ID不能为空且必须大于0");
+            }
+
+            List<StoreStaffPositionCountVo> result = storeStaffConfigService.getStaffPositionCount(storeId);
+            log.info("查询员工职位统计成功,storeId={},职位数量:{}", storeId, result.size());
+            return R.data(result);
+        } catch (IllegalArgumentException e) {
+            log.warn("查询员工职位统计失败,参数错误:{}", e.getMessage());
+            return R.fail(e.getMessage());
+        } catch (Exception e) {
+            log.error("查询员工职位统计异常,storeId={},异常信息:{}", storeId, e.getMessage(), e);
+            return R.fail("查询失败:" + e.getMessage());
+        }
+    }
+
 }

+ 20 - 6
alien-store/src/main/java/shop/alien/store/service/StoreStaffConfigService.java

@@ -3,8 +3,10 @@ package shop.alien.store.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import shop.alien.entity.store.StoreStaffConfig;
 import shop.alien.entity.store.dto.StoreStaffConfigListQueryDto;
+import shop.alien.entity.store.vo.StoreStaffPositionCountVo;
 
 import java.io.IOException;
+import java.util.List;
 
 public interface StoreStaffConfigService {
 
@@ -74,17 +76,18 @@ public interface StoreStaffConfigService {
     /**
      * 员工列表查询(用户端)
      * <p>
-     * 查询指定店铺的员工列表,支持按状态筛选
+     * 查询指定店铺的员工列表,支持按状态和职位筛选
      * 排序规则:先按置顶状态降序,再按置顶时间降序,最后按创建时间降序
      * </p>
      *
-     * @param page    分页页数,必须大于0
-     * @param size    分页条数,必须大于0
-     * @param storeId 店铺ID,必须大于0
-     * @param status  员工状态,可选(0-待审核 1-审核通过 2-审核拒绝),为空时查询所有状态
+     * @param page          分页页数,必须大于0
+     * @param size          分页条数,必须大于0
+     * @param storeId       店铺ID,必须大于0
+     * @param status        员工状态,可选(0-待审核 1-审核通过 2-审核拒绝),为空时查询所有状态
+     * @param staffPosition 员工职位,可选,为空时查询所有职位
      * @return 员工列表分页结果
      */
-    IPage<StoreStaffConfig> queryStaffList(Integer page, Integer size, Integer storeId, String status);
+    IPage<StoreStaffConfig> queryStaffList(Integer page, Integer size, Integer storeId, String status, String staffPosition);
 
     /**
      * 员工详情查询(用户端)
@@ -128,4 +131,15 @@ public interface StoreStaffConfigService {
      * @return 健身教练详情(包含员工信息、基本信息和认证/荣誉列表),如果员工不存在则返回null
      */
     shop.alien.entity.store.vo.StoreStaffFitnessDetailVo getFitnessCoachDetail(Integer id);
+
+    /**
+     * 查询指定店铺的员工职位统计信息
+     * <p>
+     * 统计指定店铺下各个职位的员工数量,只统计未删除的员工
+     * </p>
+     *
+     * @param storeId 店铺ID,必须大于0
+     * @return 员工职位统计列表,每个元素包含职位名称和对应员工数量
+     */
+    List<StoreStaffPositionCountVo> getStaffPositionCount(Integer storeId);
 }

+ 50 - 1
alien-store/src/main/java/shop/alien/store/service/impl/StoreStaffConfigServiceImpl.java

@@ -20,6 +20,7 @@ import shop.alien.entity.store.excelVo.StoreStaffConfigExcelVo;
 import shop.alien.entity.store.excelVo.util.ExcelGenerator;
 import shop.alien.entity.store.vo.StoreStaffDetailVo;
 import shop.alien.entity.store.vo.StoreStaffFitnessDetailVo;
+import shop.alien.entity.store.vo.StoreStaffPositionCountVo;
 import shop.alien.mapper.*;
 import shop.alien.store.service.StoreStaffConfigService;
 import shop.alien.store.service.StoreStaffFitnessBaseService;
@@ -35,6 +36,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Collectors;
 
@@ -781,7 +783,7 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
     }
 
     @Override
-    public IPage<StoreStaffConfig> queryStaffList(Integer page, Integer size, Integer storeId, String status) {
+    public IPage<StoreStaffConfig> queryStaffList(Integer page, Integer size, Integer storeId, String status, String staffPosition) {
         // 参数校验
         if (page == null || page < 1) {
             page = 1;
@@ -808,6 +810,11 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
             queryWrapper.eq(StoreStaffConfig::getStatus, status);
         }
 
+        // 可选条件:员工职位筛选
+        if (StringUtils.isNotEmpty(staffPosition)) {
+            queryWrapper.eq(StoreStaffConfig::getStaffPosition, staffPosition);
+        }
+
         // 排序规则:先按置顶状态降序(置顶的在前),再按置顶时间降序,最后按创建时间降序
         queryWrapper.orderByDesc(StoreStaffConfig::getTopStatus)
                 .orderByDesc(StoreStaffConfig::getTopTime)
@@ -1004,4 +1011,46 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
             throw new RuntimeException("查询健身教练详情异常:" + e.getMessage(), e);
         }
     }
+
+    @Override
+    public List<StoreStaffPositionCountVo> getStaffPositionCount(Integer storeId) {
+        log.info("查询员工职位统计,storeId={}", storeId);
+
+        // 参数校验
+        if (storeId == null || storeId <= 0) {
+            log.warn("查询员工职位统计失败,店铺ID无效:storeId={}", storeId);
+            throw new IllegalArgumentException("店铺ID不能为空且必须大于0");
+        }
+
+        // 构建查询条件:查询指定店铺下未删除的员工
+        LambdaQueryWrapper<StoreStaffConfig> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(StoreStaffConfig::getStoreId, storeId)
+                .eq(StoreStaffConfig::getDeleteFlag, CommonConstant.DELETE_FLAG_UNDELETE)
+                // 只查询staff_position不为空的记录
+                .isNotNull(StoreStaffConfig::getStaffPosition)
+                .ne(StoreStaffConfig::getStaffPosition, "");
+
+        // 查询所有符合条件的员工
+        List<StoreStaffConfig> staffList = storeStaffConfigMapper.selectList(queryWrapper);
+
+        // 按职位分组统计(查询条件已过滤空值,此处直接分组即可)
+        Map<String, Long> positionCountMap = staffList.stream()
+                .collect(Collectors.groupingBy(
+                        StoreStaffConfig::getStaffPosition,
+                        Collectors.counting()
+                ));
+
+        // 转换为VO列表
+        List<StoreStaffPositionCountVo> result = positionCountMap.entrySet().stream()
+                .map(entry -> {
+                    StoreStaffPositionCountVo vo = new StoreStaffPositionCountVo();
+                    vo.setStaffPosition(entry.getKey());
+                    vo.setCount(entry.getValue());
+                    return vo;
+                })
+                .collect(Collectors.toList());
+
+        log.info("查询员工职位统计成功,storeId={},职位数量:{}", storeId, result.size());
+        return result;
+    }
 }