|
@@ -0,0 +1,130 @@
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
+import com.fdkankan.manage.common.ResultCode;
|
|
|
+import com.fdkankan.manage.entity.Feedback;
|
|
|
+import com.fdkankan.manage.entity.FeedbackOption;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.mapper.IFeedbackMapper;
|
|
|
+import com.fdkankan.manage.service.IFeedbackOptionService;
|
|
|
+import com.fdkankan.manage.service.IFeedbackService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.vo.request.FeedbackParam;
|
|
|
+import com.fdkankan.manage.vo.response.GroupByAvg;
|
|
|
+import com.fdkankan.manage.vo.response.GroupByCount;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-01-24
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FeedbackServiceImpl extends ServiceImpl<IFeedbackMapper, Feedback> implements IFeedbackService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IFeedbackOptionService feedbackOptionService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(FeedbackParam param) {
|
|
|
+ LambdaQueryWrapper<Feedback> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if(param.getHardwareOptionId() != null){
|
|
|
+ wrapper.eq(Feedback::getHardwareOptionId,param.getHardwareOptionId());
|
|
|
+ }
|
|
|
+ if(param.getSoftwareOptionId() != null){
|
|
|
+ wrapper.eq(Feedback::getSoftwareOptionId,param.getSoftwareOptionId());
|
|
|
+ }
|
|
|
+ if(param.getIndustryOptionId() != null){
|
|
|
+ wrapper.eq(Feedback::getIndustryOptionId,param.getIndustryOptionId());
|
|
|
+ }
|
|
|
+ if(param.getStatus() != null){
|
|
|
+ wrapper.eq(Feedback::getStatus,param.getStatus());
|
|
|
+ }
|
|
|
+ Page<Feedback> page = this.page(new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
|
|
|
+ HashSet<Integer> optionIds = new HashSet<>();
|
|
|
+ Set<Integer> collect = page.getRecords().stream().map(Feedback::getHardwareOptionId).collect(Collectors.toSet());
|
|
|
+ Set<Integer> collect1 = page.getRecords().stream().map(Feedback::getSoftwareOptionId).collect(Collectors.toSet());
|
|
|
+ Set<Integer> collect2 = page.getRecords().stream().map(Feedback::getIndustryOptionId).collect(Collectors.toSet());
|
|
|
+ optionIds.addAll(collect);
|
|
|
+ optionIds.addAll(collect1);
|
|
|
+ optionIds.addAll(collect2);
|
|
|
+ HashMap<Integer, FeedbackOption> map = feedbackOptionService.getMapByIds(optionIds);
|
|
|
+ for (Feedback record : page.getRecords()) {
|
|
|
+ if(record.getHardwareOptionId()!=null && map.get(record.getHardwareOptionId())!= null){
|
|
|
+ record.setHardwareOption(map.get(record.getHardwareOptionId()));
|
|
|
+ }
|
|
|
+ if(record.getSoftwareOptionId()!=null && map.get(record.getSoftwareOptionId())!= null){
|
|
|
+ record.setSoftwareOption(map.get(record.getSoftwareOptionId()));
|
|
|
+ }
|
|
|
+ if(record.getIndustryOptionId()!=null && map.get(record.getIndustryOptionId())!= null){
|
|
|
+ record.setIndustryOption(map.get(record.getIndustryOptionId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return PageInfo.PageInfo(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void handle(Feedback param) {
|
|
|
+ if(param.getId() == null){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<Feedback> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(Feedback::getId,param.getId());
|
|
|
+ if(StringUtils.isNotBlank(param.getResult())){
|
|
|
+ wrapper.set(Feedback::getResult,param.getResult());
|
|
|
+ }
|
|
|
+ wrapper.set(Feedback::getStatus,1);
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object scoreAug() {
|
|
|
+
|
|
|
+ HashMap<Integer,BigDecimal> map = new HashMap<>();
|
|
|
+ List<GroupByAvg> list = this.getBaseMapper().scoreAugHardware();
|
|
|
+ List<GroupByAvg> list2 = this.getBaseMapper().scoreAugSoftware();
|
|
|
+ list.forEach(e ->map.put(e.getId(),e.getAvg()));
|
|
|
+ list2.forEach(e ->map.put(e.getId(),e.getAvg()));
|
|
|
+
|
|
|
+ List<FeedbackOption> options = feedbackOptionService.list();
|
|
|
+
|
|
|
+ List<FeedbackOption> hardwareList = options.stream().filter(e -> e.getTypeId().equals(2)).collect(Collectors.toList());
|
|
|
+ List<FeedbackOption> softwareList = options.stream().filter(e -> e.getTypeId().equals(2)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ setScore(hardwareList,map);
|
|
|
+ setScore(softwareList,map);
|
|
|
+ HashMap<String,Object> result = new HashMap<>();
|
|
|
+ result.put("hardware",hardwareList);
|
|
|
+ result.put("software",softwareList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setScore(List<FeedbackOption> list,HashMap<Integer,BigDecimal> map){
|
|
|
+ for (FeedbackOption feedbackOption : list) {
|
|
|
+ BigDecimal value = map.get(feedbackOption.getTypeId());
|
|
|
+ if(value == null){
|
|
|
+ feedbackOption.setScore("暂无评分");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal bigDecimal = value.setScale(1, RoundingMode.HALF_UP);
|
|
|
+ feedbackOption.setScore(bigDecimal.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|