Sfoglia il codice sorgente

人员详情接口新增喜欢字段

zhangchen 3 mesi fa
parent
commit
20188c31d2

+ 7 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreStaffDetailWithPerformanceVo.java

@@ -40,5 +40,12 @@ public class StoreStaffDetailWithPerformanceVo implements Serializable {
      */
     @ApiModelProperty(value = "是否今日演出(true-今日有演出,false-今日无演出)")
     private Boolean hasPerformanceToday;
+
+    /**
+     * 是否喜欢(true-已喜欢,false-未喜欢)
+     * 根据当前登录用户的token中的userid判断
+     */
+    @ApiModelProperty(value = "是否喜欢(true-已喜欢,false-未喜欢)")
+    private Boolean isLiked;
 }
 

+ 17 - 5
alien-store/src/main/java/shop/alien/store/controller/StoreStaffConfigController.java

@@ -2,12 +2,15 @@ package shop.alien.store.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import io.swagger.annotations.*;
+import springfox.documentation.annotations.ApiIgnore;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.StoreStaffConfig;
 import shop.alien.entity.store.StoreStaffTitle;
+import shop.alien.entity.store.UserLoginInfo;
+import shop.alien.util.common.TokenInfo;
 import shop.alien.entity.store.dto.StoreStaffConfigListQueryDto;
 import shop.alien.entity.store.vo.StaffTitleGroupVo;
 import shop.alien.entity.store.vo.StoreStaffDetailVo;
@@ -266,8 +269,10 @@ public class StoreStaffConfigController {
     })
     @GetMapping("/queryStaffDetail")
     public R<StoreStaffDetailWithPerformanceVo> queryStaffDetail(
-            @RequestParam(value = "id", required = true) Integer id) {
-        log.info("查询员工详情(包含演出列表),id={}", id);
+            @RequestParam(value = "id", required = true) Integer id,
+            @ApiIgnore @TokenInfo UserLoginInfo userLoginInfo) {
+        log.info("查询员工详情(包含演出列表),id={},userId={}", 
+                id, userLoginInfo != null ? userLoginInfo.getUserId() : null);
 
         try {
             // 参数校验
@@ -276,17 +281,24 @@ public class StoreStaffConfigController {
                 return R.fail("员工ID不能为空且必须大于0");
             }
 
+            // 获取用户ID(可能为null,如果用户未登录)
+            Integer userId = null;
+            if (userLoginInfo != null) {
+                userId = userLoginInfo.getUserId();
+            }
+
             // 调用服务层查询
             StoreStaffDetailWithPerformanceVo result =
-                    storeStaffConfigService.queryStaffDetailWithPerformance(id);
+                    storeStaffConfigService.queryStaffDetailWithPerformance(id, userId);
 
             if (result == null) {
                 log.warn("查询员工详情失败,员工不存在:id={}", id);
                 return R.fail("员工不存在");
             }
 
-            log.info("查询员工详情成功,id={},演出安排数量:{}",
-                    id, result.getPerformanceScheduleList() != null ? result.getPerformanceScheduleList().size() : 0);
+            log.info("查询员工详情成功,id={},演出安排数量:{},是否喜欢:{}",
+                    id, result.getPerformanceScheduleList() != null ? result.getPerformanceScheduleList().size() : 0,
+                    result.getIsLiked());
             return R.data(result);
         } catch (IllegalArgumentException e) {
             log.warn("查询员工详情参数错误,id={},错误信息:{}", id, e.getMessage());

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/StoreStaffConfigService.java

@@ -132,9 +132,10 @@ public interface StoreStaffConfigService {
      * </p>
      *
      * @param id 员工主键ID,必须大于0
+     * @param userId 当前登录用户ID,可为null(未登录时)
      * @return 员工详情(包含演出列表),如果员工不存在则返回null
      */
-    shop.alien.entity.store.vo.StoreStaffDetailWithPerformanceVo queryStaffDetailWithPerformance(Integer id);
+    shop.alien.entity.store.vo.StoreStaffDetailWithPerformanceVo queryStaffDetailWithPerformance(Integer id, Integer userId);
 
     /**
      * 获取美食员工列表

+ 44 - 4
alien-store/src/main/java/shop/alien/store/service/impl/StoreStaffConfigServiceImpl.java

@@ -27,12 +27,14 @@ import shop.alien.entity.store.vo.PerformanceScheduleVo;
 import shop.alien.entity.store.StoreComment;
 import shop.alien.entity.store.StoreStaffReview;
 import shop.alien.entity.store.StoreStaffTitle;
+import shop.alien.entity.store.LifeLikeRecord;
 import shop.alien.entity.store.vo.StaffTitleGroupVo;
 import shop.alien.entity.store.vo.StoreStaffDetailVo;
 import shop.alien.entity.store.vo.StoreStaffDetailWithPerformanceVo;
 import shop.alien.entity.store.vo.StoreStaffFitnessDetailVo;
 import shop.alien.entity.store.vo.StoreStaffPositionCountVo;
 import shop.alien.mapper.*;
+import shop.alien.mapper.LifeLikeRecordMapper;
 import shop.alien.store.service.StoreStaffConfigService;
 import shop.alien.store.service.StoreStaffFitnessBaseService;
 import shop.alien.store.service.StoreStaffFitnessCertificationService;
@@ -92,6 +94,8 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
 
     private final StoreStaffFitnessExperienceService storeStaffFitnessExperienceService;
 
+    private final LifeLikeRecordMapper lifeLikeRecordMapper;
+
     /**
      * 认证类型:认证
      */
@@ -939,8 +943,8 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
      * @return 员工详情(包含演出列表),如果员工不存在则返回null
      */
     @Override
-    public StoreStaffDetailWithPerformanceVo queryStaffDetailWithPerformance(Integer id) {
-        log.info("查询员工详情(包含演出列表),id={}", id);
+    public StoreStaffDetailWithPerformanceVo queryStaffDetailWithPerformance(Integer id, Integer userId) {
+        log.info("查询员工详情(包含演出列表),id={},userId={}", id, userId);
 
         // 参数校验
         if (id == null || id <= 0) {
@@ -963,15 +967,19 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
             // 判断今日是否有演出
             Boolean hasPerformanceToday = checkHasPerformanceToday(id);
 
+            // 判断是否喜欢(根据userId查询点赞记录)
+            Boolean isLiked = checkIsLiked(id, userId);
+
             // 构建返回对象
             StoreStaffDetailWithPerformanceVo result =
                     new StoreStaffDetailWithPerformanceVo();
             result.setStaffInfo(staffConfig);
             result.setPerformanceScheduleList(performanceScheduleList);
             result.setHasPerformanceToday(hasPerformanceToday);
+            result.setIsLiked(isLiked);
 
-            log.info("查询员工详情(包含演出列表)成功,id={},演出安排数量:{},今日是否有演出:{}",
-                    id, performanceScheduleList != null ? performanceScheduleList.size() : 0, hasPerformanceToday);
+            log.info("查询员工详情(包含演出列表)成功,id={},演出安排数量:{},今日是否有演出:{},是否喜欢:{}",
+                    id, performanceScheduleList != null ? performanceScheduleList.size() : 0, hasPerformanceToday, isLiked);
             return result;
         } catch (Exception e) {
             log.error("查询员工详情(包含演出列表)异常,id={},异常信息:{}", id, e.getMessage(), e);
@@ -1805,4 +1813,36 @@ public class StoreStaffConfigServiceImpl implements StoreStaffConfigService {
             throw new RuntimeException("根据标题ID查询员工列表失败:" + e.getMessage(), e);
         }
     }
+
+    /**
+     * 检查用户是否喜欢该员工
+     * <p>
+     * 根据userId查询life_like_record表,判断是否存在点赞记录
+     * type = "8" 表示点赞员工
+     * </p>
+     *
+     * @param staffId 员工ID
+     * @param userId 用户ID,可为null(未登录时返回false)
+     * @return true-已喜欢,false-未喜欢
+     */
+    private Boolean checkIsLiked(Integer staffId, Integer userId) {
+        // 如果用户未登录,返回false
+        if (userId == null || userId <= 0) {
+            return false;
+        }
+
+        try {
+            LambdaQueryWrapper<LifeLikeRecord> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(LifeLikeRecord::getType, "8") // 8-点赞员工
+                    .eq(LifeLikeRecord::getDianzanId, String.valueOf(userId))
+                    .eq(LifeLikeRecord::getHuifuId, String.valueOf(staffId))
+                    .eq(LifeLikeRecord::getDeleteFlag, 0);
+            long count = lifeLikeRecordMapper.selectCount(queryWrapper);
+            return count > 0;
+        } catch (Exception e) {
+            log.error("查询员工是否喜欢异常,staffId={},userId={},异常信息:{}", 
+                    staffId, userId, e.getMessage(), e);
+            return false;
+        }
+    }
 }