|
|
@ -24,11 +24,11 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.dynamic.datasource.annotation.DataSource; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.FieldConstant; |
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.dataaggre.constant.DataSourceConstant; |
|
|
|
import com.epmet.dataaggre.dao.epmettduck.PrUserProjectDao; |
|
|
|
import com.epmet.dataaggre.dto.epmettduck.InputMapDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmettduck.PrUserProjectDTO; |
|
|
|
import com.epmet.dataaggre.dto.epmettduck.ProjectItemTypeEnum; |
|
|
|
import com.epmet.dataaggre.dto.epmettduck.result.AnalysisReportResDTO; |
|
|
@ -43,7 +43,10 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
/** |
|
|
|
* 项目表 |
|
|
@ -142,6 +145,7 @@ public class PrUserProjectServiceImpl extends BaseServiceImpl<PrUserProjectDao, |
|
|
|
for(AnalysisReportResDTO item:itemList){ |
|
|
|
String currentType=item.getType(); |
|
|
|
String key="field".concat(item.getFormItemId()); |
|
|
|
log.info("key="+key); |
|
|
|
|
|
|
|
Map<String, Object> detail=new HashMap<>(); |
|
|
|
//总采集数
|
|
|
@ -162,31 +166,50 @@ public class PrUserProjectServiceImpl extends BaseServiceImpl<PrUserProjectDao, |
|
|
|
|
|
|
|
for(PrUserProjectResultEntity res:resultList){ |
|
|
|
JSONObject originalData = JSON.parseObject(res.getOriginalData()); |
|
|
|
log.info("----------------------key:"+key+",值: "+originalData.get(key)); |
|
|
|
//手机号、邮箱、身份证: INPUT
|
|
|
|
if(ProjectItemTypeEnum.INPUT.getValue().equals(currentType)){ |
|
|
|
if(StringUtils.isNotBlank(originalData.get(key).toString())){ |
|
|
|
validTotal+=1; |
|
|
|
//手机号、邮箱、身份证、单行文本: INPUT
|
|
|
|
//多行文本
|
|
|
|
//时间选择
|
|
|
|
//日期选择
|
|
|
|
if(ProjectItemTypeEnum.INPUT.getValue().equals(currentType) |
|
|
|
||ProjectItemTypeEnum.TEXTAREA.getValue().equals(currentType) |
|
|
|
||ProjectItemTypeEnum.TIME.getValue().equals(currentType) |
|
|
|
||ProjectItemTypeEnum.DATE.getValue().equals(currentType)){ |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
if(StringUtils.isNotBlank(originalData.get(key).toString())){ |
|
|
|
validTotal+=1; |
|
|
|
} |
|
|
|
}else{ |
|
|
|
log.warn("没有当前的key:,可能用户没填写吧"+key); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//省市联动: PROVINCE_CITY
|
|
|
|
if(ProjectItemTypeEnum.PROVINCE_CITY.getValue().equals(currentType)){ |
|
|
|
List<String> provinceCityList= (List<String>) originalData.get(key); |
|
|
|
if(!CollectionUtils.isEmpty(provinceCityList)){ |
|
|
|
validTotal+=1; |
|
|
|
//时间范围选择
|
|
|
|
//日期范围选择
|
|
|
|
if(ProjectItemTypeEnum.PROVINCE_CITY.getValue().equals(currentType) |
|
|
|
||ProjectItemTypeEnum.TIME_RANGE.getValue().equals(currentType) |
|
|
|
||ProjectItemTypeEnum.DATE_RANGE.getValue().equals(currentType)){ |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
List<String> provinceCityList= (List<String>) originalData.get(key); |
|
|
|
if(!CollectionUtils.isEmpty(provinceCityList)){ |
|
|
|
validTotal+=1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//地理位置:INPUT_MAP
|
|
|
|
if(ProjectItemTypeEnum.INPUT_MAP.getValue().equals(currentType)){ |
|
|
|
InputMapDTO inputMapDTO= (InputMapDTO) originalData.get(key); |
|
|
|
if(null!=inputMapDTO&&StringUtils.isNotBlank(inputMapDTO.getAddress())){ |
|
|
|
validTotal+=1; |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
List<String> provinceCityList= (List<String>) originalData.get(key); |
|
|
|
log.info("地理位置:"+JSON.toJSONString(provinceCityList,true)); |
|
|
|
if (!CollectionUtils.isEmpty(provinceCityList) && provinceCityList.size() == 3) { |
|
|
|
validTotal += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
detail.put("validTotal",validTotal); |
|
|
|
item.setDetail(detail); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -210,18 +233,21 @@ public class PrUserProjectServiceImpl extends BaseServiceImpl<PrUserProjectDao, |
|
|
|
|
|
|
|
|
|
|
|
//4、计数器显示所有填写者选择的数字总和
|
|
|
|
if(ProjectItemTypeEnum.TEXTAREA.getValue().equals(currentType)){ |
|
|
|
if(ProjectItemTypeEnum.NUMBER_INPUT.getValue().equals(currentType)){ |
|
|
|
int sumTotal=0; |
|
|
|
for(PrUserProjectResultEntity res:resultList){ |
|
|
|
JSONObject originalData = JSON.parseObject(res.getOriginalData()); |
|
|
|
Integer score= (Integer) originalData.get(key); |
|
|
|
if(null!=score){ |
|
|
|
sumTotal+=score; |
|
|
|
validTotal+=1; |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
Integer score= (Integer) originalData.get(key); |
|
|
|
if(null!=score){ |
|
|
|
sumTotal+=score; |
|
|
|
validTotal+=1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
detail.put("validTotal",validTotal); |
|
|
|
detail.put("sumTotal",sumTotal); |
|
|
|
item.setDetail(detail); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -232,41 +258,63 @@ public class PrUserProjectServiceImpl extends BaseServiceImpl<PrUserProjectDao, |
|
|
|
int closedTotal=0; |
|
|
|
for(PrUserProjectResultEntity res:resultList){ |
|
|
|
JSONObject originalData = JSON.parseObject(res.getOriginalData()); |
|
|
|
Boolean result= (Boolean) originalData.get(key); |
|
|
|
if(null!=result){ |
|
|
|
validTotal+=1; |
|
|
|
if(result){ |
|
|
|
openTotal+=1; |
|
|
|
}else{ |
|
|
|
closedTotal+=1; |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
Boolean result= (Boolean) originalData.get(key); |
|
|
|
if(null!=result){ |
|
|
|
validTotal+=1; |
|
|
|
if(result){ |
|
|
|
openTotal+=1; |
|
|
|
}else{ |
|
|
|
closedTotal+=1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
detail.put("validTotal",validTotal); |
|
|
|
detail.put("openTotal",openTotal); |
|
|
|
detail.put("closedTotal",closedTotal); |
|
|
|
item.setDetail(detail); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
//6、滑块、颜色选择、上传不统计
|
|
|
|
|
|
|
|
//7、评分统计1星几人,2星几人,3星几人......,显示平均分
|
|
|
|
if(ProjectItemTypeEnum.RATE.getValue().equals(currentType)){ |
|
|
|
if (ProjectItemTypeEnum.RATE.getValue().equals(currentType)) { |
|
|
|
// 1、标签设置的满星是几个星星?
|
|
|
|
RateExpandStruct rateExpandStruct = JSON.parseObject(item.getExpand(), RateExpandStruct.class); |
|
|
|
//int maxStarNum=;
|
|
|
|
//detail.put("maxStarNum",maxStarNum);
|
|
|
|
if (null != rateExpandStruct && null != rateExpandStruct.getMax()) { |
|
|
|
detail.put("maxStarNum", rateExpandStruct.getMax()); |
|
|
|
} else { |
|
|
|
log.warn(String.format("当前评分组件未设置最大值,默认赋值5,projectKey:%s,itemId:%s",projectKey,item.getFormItemId())); |
|
|
|
detail.put("maxStarNum", NumConstant.FIVE); |
|
|
|
} |
|
|
|
|
|
|
|
for(PrUserProjectResultEntity res:resultList){ |
|
|
|
//总分
|
|
|
|
int totalStarNum = 0; |
|
|
|
Map<Integer, Integer> starMap = new HashMap<>(); |
|
|
|
for (PrUserProjectResultEntity res : resultList) { |
|
|
|
JSONObject originalData = JSON.parseObject(res.getOriginalData()); |
|
|
|
Integer starNum= (Integer) originalData.get(key); |
|
|
|
if(null!=starNum){ |
|
|
|
validTotal+=1; |
|
|
|
if(originalData.containsKey(key)){ |
|
|
|
Integer starNum = (Integer) originalData.get(key); |
|
|
|
if (null != starNum) { |
|
|
|
validTotal += 1; |
|
|
|
totalStarNum += starNum; |
|
|
|
Integer count = starMap.get(starNum); |
|
|
|
starMap.put(starNum, count == null ? 1 : count + 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//2、几条有效记录
|
|
|
|
detail.put("validTotal",validTotal); |
|
|
|
//按照星星大小升序排列
|
|
|
|
this.sortMap(starMap, true); |
|
|
|
//2、平均分
|
|
|
|
detail.put("avgStarNum", new BigDecimal((float)totalStarNum / validTotal).setScale(0, BigDecimal.ROUND_HALF_UP)); |
|
|
|
//3、几条有效记录
|
|
|
|
detail.put("validTotal", validTotal); |
|
|
|
//4、得分列表
|
|
|
|
detail.put("starProfile", starMap); |
|
|
|
item.setDetail(detail); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
@ -275,4 +323,17 @@ public class PrUserProjectServiceImpl extends BaseServiceImpl<PrUserProjectDao, |
|
|
|
return itemList; |
|
|
|
} |
|
|
|
|
|
|
|
private List<Map.Entry<Integer, Integer>> sortMap(Map<Integer, Integer> map, boolean asc) { |
|
|
|
|
|
|
|
Stream<Map.Entry<Integer, Integer>> stream = null; |
|
|
|
if (asc) { |
|
|
|
stream = map.entrySet().stream().sorted(Map.Entry.comparingByValue()); |
|
|
|
} else { |
|
|
|
stream = map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())); |
|
|
|
} |
|
|
|
return stream.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |