lyhzzz 1 ماه پیش
والد
کامیت
9998d6f090

+ 5 - 0
src/main/java/com/fdkankan/ucenter/entity/Case.java

@@ -7,6 +7,8 @@ import com.baomidou.mybatisplus.annotation.TableLogic;
 import com.baomidou.mybatisplus.annotation.TableName;
 import java.io.Serializable;
 import java.util.Date;
+import java.util.List;
+
 import lombok.Getter;
 import lombok.Setter;
 
@@ -126,4 +128,7 @@ public class Case implements Serializable {
 
     @TableField(exist = false)
     private Integer feedbackOptionId;
+
+    @TableField(exist = false)
+    private List<FeedbackOption> feedbackOptionList;
 }

+ 4 - 0
src/main/java/com/fdkankan/ucenter/service/IFeedbackOptionService.java

@@ -3,6 +3,9 @@ package com.fdkankan.ucenter.service;
 import com.fdkankan.ucenter.entity.FeedbackOption;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.HashMap;
+import java.util.HashSet;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IFeedbackOptionService extends IService<FeedbackOption> {
 
+    HashMap<Integer, FeedbackOption> getMapByIds(HashSet<Integer> optionIds);
 }

+ 35 - 1
src/main/java/com/fdkankan/ucenter/service/impl/CaseServiceImpl.java

@@ -1,13 +1,20 @@
 package com.fdkankan.ucenter.service.impl;
 
+import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.ucenter.entity.Case;
+import com.fdkankan.ucenter.entity.FeedbackOption;
 import com.fdkankan.ucenter.mapper.ICaseMapper;
 import com.fdkankan.ucenter.service.ICaseService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.ucenter.service.IFeedbackOptionService;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 
 /**
@@ -21,6 +28,8 @@ import java.util.List;
 @Service
 public class CaseServiceImpl extends ServiceImpl<ICaseMapper, Case> implements ICaseService {
 
+    @Autowired
+    IFeedbackOptionService feedbackOptionService;
     @Override
     public List<Case> allList(Case caseEntity) {
         LambdaQueryWrapper<Case> wrapper = new LambdaQueryWrapper<>();
@@ -37,6 +46,31 @@ public class CaseServiceImpl extends ServiceImpl<ICaseMapper, Case> implements I
         wrapper.eq(Case::getIsPublic,1);
         wrapper.orderByAsc(Case::getSort);
         wrapper.orderByAsc(Case::getId);
-        return this.list(wrapper);
+        List<Case> list = this.list(wrapper);
+        HashSet<Integer> feedIds = new HashSet<>();
+        for (Case aCase : list) {
+            if(StringUtils.isNotBlank(aCase.getFeedbackOptionIds())){
+                JSONArray jsonArray = JSONArray.parseArray(aCase.getFeedbackOptionIds());
+                for (Object object : jsonArray) {
+                    feedIds.add((Integer) object);
+                }
+            }
+        }
+        HashMap<Integer, FeedbackOption> mapByIds = feedbackOptionService.getMapByIds(feedIds);
+        for (Case aCase : list) {
+            if(StringUtils.isNotBlank(aCase.getFeedbackOptionIds())){
+                JSONArray jsonArray = JSONArray.parseArray(aCase.getFeedbackOptionIds());
+                List<FeedbackOption> options = new ArrayList<>();
+                for (Object object : jsonArray) {
+                    FeedbackOption feedbackOption = mapByIds.get((Integer) object);
+                    if(feedbackOption!=null){
+                        options.add(feedbackOption);
+                    }
+                }
+                aCase.setFeedbackOptionList(options);
+            }
+        }
+
+        return list;
     }
 }

+ 9 - 0
src/main/java/com/fdkankan/ucenter/service/impl/FeedbackOptionServiceImpl.java

@@ -22,4 +22,13 @@ import java.util.List;
 @Service
 public class FeedbackOptionServiceImpl extends ServiceImpl<IFeedbackOptionMapper, FeedbackOption> implements IFeedbackOptionService {
 
+    @Override
+    public HashMap<Integer, FeedbackOption> getMapByIds(HashSet<Integer> optionIds) {
+        HashMap<Integer, FeedbackOption> map = new HashMap<>();
+        if(ObjectUtils.isNotEmpty(optionIds)){
+            List<FeedbackOption> feedbackOptions = this.listByIds(optionIds);
+            feedbackOptions.forEach(e -> map.put(e.getId(),e));
+        }
+        return map;
+    }
 }