|
@@ -0,0 +1,205 @@
|
|
|
+package com.fdkankan.manage.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.CacheUtil;
|
|
|
+import com.fdkankan.manage.common.PageInfo;
|
|
|
+import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
+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.IExcelService;
|
|
|
+import com.fdkankan.manage.service.IFeedbackOptionService;
|
|
|
+import com.fdkankan.manage.service.IFeedbackService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.manage.util.ProvinceUtils;
|
|
|
+import com.fdkankan.manage.vo.request.FeedbackParam;
|
|
|
+import com.fdkankan.manage.vo.request.OrderParam;
|
|
|
+import com.fdkankan.manage.vo.response.DownOrderVo;
|
|
|
+import com.fdkankan.manage.vo.response.FeedbackVo;
|
|
|
+import com.fdkankan.manage.vo.response.GroupByAvg;
|
|
|
+import com.fdkankan.manage.vo.response.IpAddressVo;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.*;
|
|
|
+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) {
|
|
|
+ CacheUtil.feedbackParam = param;
|
|
|
+ return PageInfo.PageInfo(this.pageListByParam(param));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Page<FeedbackVo> pageListByParam(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());
|
|
|
+ }
|
|
|
+ wrapper.orderByDesc(Feedback::getId);
|
|
|
+ List<FeedbackVo> listVo = new ArrayList<>();
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+ FeedbackVo feedbackVo = new FeedbackVo();
|
|
|
+ BeanUtil.copyProperties(record,feedbackVo);
|
|
|
+ listVo.add(feedbackVo);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<FeedbackVo> voPage = new Page<>(param.getPageNum(),param.getPageSize());
|
|
|
+ voPage.setRecords(listVo);
|
|
|
+ voPage.setTotal(page.getTotal());
|
|
|
+ return voPage;
|
|
|
+ }
|
|
|
+
|
|
|
+ @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.getAvgCount()));
|
|
|
+ list2.forEach(e ->map.put(e.getId(),e.getAvgCount()));
|
|
|
+
|
|
|
+ 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(3)).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.getId());
|
|
|
+ if(value == null ){
|
|
|
+ feedbackOption.setScore(null);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal bigDecimal = value.setScale(1, RoundingMode.HALF_UP);
|
|
|
+ feedbackOption.setScore(bigDecimal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getDefaultAddress(HttpServletRequest request) {
|
|
|
+ //获取ip地址
|
|
|
+ String clientIP = ServletUtil.getClientIP(request);
|
|
|
+ if(StringUtils.isBlank(clientIP)){
|
|
|
+ return new IpAddressVo();
|
|
|
+ }
|
|
|
+ String redisKey = String.format(RedisKeyUtil.ipAddress,clientIP);
|
|
|
+ if(redisUtil.hasKey(redisKey)){
|
|
|
+ return JSONObject.parseObject(redisUtil.get(redisKey));
|
|
|
+ }
|
|
|
+ IpAddressVo addressByIp = ProvinceUtils.getAddressByIp(clientIP);
|
|
|
+ redisUtil.set(redisKey,JSONObject.toJSONString(addressByIp));
|
|
|
+ return addressByIp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ IExcelService excelService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
+ FeedbackParam feedbackParam = CacheUtil.feedbackParam;
|
|
|
+ feedbackParam.setPageNum(1);
|
|
|
+ feedbackParam.setPageSize(5000);
|
|
|
+ Page<FeedbackVo> page = this.pageListByParam(feedbackParam);
|
|
|
+
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ excelWriter = EasyExcel.write(resp.getOutputStream(),FeedbackVo.class).build();
|
|
|
+ excelService.commonExport(req,resp,"用户反馈列表",page.getRecords(),excelWriter);
|
|
|
+ while (page.hasNext()){
|
|
|
+ feedbackParam.setPageNum(feedbackParam.getPageNum()+1);
|
|
|
+ page = this.pageListByParam(feedbackParam);
|
|
|
+ if(page.getRecords().size() >0){
|
|
|
+ excelService.commonExport(req,resp,"用户反馈列表",page.getRecords(),excelWriter);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(excelWriter !=null){
|
|
|
+ excelWriter.finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|