| | |
| | | package com.smartor.service.impl; |
| | | |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.smartor.domain.SvyLibTemplateScript; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.mapper.ServiceSubtaskMapper; |
| | | import com.smartor.mapper.SvyLibTemplateScriptMapper; |
| | | import com.smartor.service.ISvyLibTemplateScriptService; |
| | | import com.smartor.service.ISvyLibTemplateTargetoptionService; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static net.sf.jsqlparser.parser.feature.Feature.values; |
| | | |
| | | /** |
| | | * 模板问卷题目Service业务层处理 |
| | |
| | | @Service |
| | | public class SvyLibTemplateScriptServiceImpl implements ISvyLibTemplateScriptService |
| | | { |
| | | ISvyLibTemplateTargetoptionService svyLibTemplateTargetoptionService; |
| | | |
| | | @Autowired |
| | | private SvyLibTemplateScriptMapper svyLibTemplateScriptMapper; |
| | | |
| | | @Autowired |
| | | private ServiceSubtaskMapper serviceSubtaskMapper; |
| | | |
| | | /** |
| | | * 查询模板问卷题目 |
| | |
| | | { |
| | | return svyLibTemplateScriptMapper.deleteSvyLibTemplateScriptByTopicid(topicid); |
| | | } |
| | | |
| | | public Map<Long, ServiceSubtaskScriptCount> countPatByScript(ServiceSubtaskCountReq serviceSubtaskCountReq) |
| | | { |
| | | Map<Long, ServiceSubtaskScriptCount> result = new HashMap<>(); |
| | | serviceSubtaskCountReq.setType("2"); |
| | | List<ServiceSubtaskScriptCount> counts = serviceSubtaskMapper.getSfStatisticsScriptDetails(serviceSubtaskCountReq); |
| | | List<ServiceSubtaskScriptCount> itemCounts = serviceSubtaskMapper.getSfStatisticsScriptItemDetails(serviceSubtaskCountReq); |
| | | |
| | | if(ObjectUtils.isNotEmpty(counts)){ |
| | | for(ServiceSubtaskScriptCount count:counts){ |
| | | Long scriptid = count.getScriptid(); |
| | | //排除scriptid为空的情况 |
| | | if(ObjectUtils.isEmpty(scriptid)){ |
| | | continue; |
| | | } |
| | | Map<String, ServiceSubtaskScriptCount> itemCountMap = new HashMap<>(); |
| | | //问卷加上空白选项 |
| | | if(ObjectUtils.isNotEmpty(count.getTemplateid()) |
| | | && ObjectUtils.isNotEmpty(count.getSubtaskType()) |
| | | && count.getSubtaskType().equals("2")){ |
| | | SvyLibTemplateScript script = selectSvyLibTemplateScriptByTopicid(scriptid); |
| | | if(ObjectUtils.isNotEmpty(script)){ |
| | | SvyLibTemplateTargetoption targetoptionVo = new SvyLibTemplateTargetoption(); |
| | | targetoptionVo.setOrgid(script.getOrgid()); |
| | | targetoptionVo.setScriptid(script.getScriptid()); |
| | | List<SvyLibTemplateTargetoption> targetoptions |
| | | = svyLibTemplateTargetoptionService.selectSvyLibTemplateTargetoptionList(targetoptionVo); |
| | | if(ObjectUtils.isNotEmpty(targetoptions)){ |
| | | //填入空白信息 |
| | | targetoptions.forEach(targetoption ->{ |
| | | ServiceSubtaskScriptCount emptyCount = new ServiceSubtaskScriptCount(); |
| | | emptyCount.setScriptid(count.getScriptid()); |
| | | emptyCount.setScriptContent(count.getScriptContent()); |
| | | emptyCount.setScriptType(count.getScriptType()); |
| | | emptyCount.setSubtaskType(count.getSubtaskType()); |
| | | emptyCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | emptyCount.setAllQuantity(count.getAllQuantity()); |
| | | emptyCount.setCompletedPercentage(count.getCompletedPercentage()); |
| | | emptyCount.setTemplateid(count.getTemplateid()); |
| | | emptyCount.setChosenQuantity(0); |
| | | emptyCount.setChosenPercentage("0.0"); |
| | | emptyCount.setOptionText(targetoption.getOptioncontent()); |
| | | itemCountMap.put(targetoption.getOptioncontent(),emptyCount); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | itemCounts.forEach(itemCount ->{ |
| | | if(ObjectUtils.isNotEmpty(count.getScriptid()) && ObjectUtils.isNotEmpty(itemCount.getScriptid())){ |
| | | if(count.getScriptid().equals(itemCount.getScriptid())){ |
| | | //放入统计信息 |
| | | itemCount.setScriptContent(count.getScriptContent()); |
| | | itemCount.setScriptType(count.getScriptType()); |
| | | itemCount.setSubtaskType(count.getSubtaskType()); |
| | | itemCount.setCompletedQuantity(count.getCompletedQuantity()); |
| | | itemCount.setAllQuantity(count.getAllQuantity()); |
| | | itemCount.setCompletedPercentage(count.getCompletedPercentage()); |
| | | itemCount.setTemplateid(count.getTemplateid()); |
| | | //计算选择比例 |
| | | int chosenQuantity = ObjectUtils.isNotEmpty(itemCount.getChosenQuantity())?itemCount.getChosenQuantity():0; |
| | | int completedQuantity = itemCount.getCompletedQuantity(); |
| | | if(ObjectUtils.isNotEmpty(completedQuantity) && completedQuantity != 0){ |
| | | BigDecimal chosenPercentage = (new BigDecimal(chosenQuantity)).divide(new BigDecimal(completedQuantity), 2, RoundingMode.HALF_UP); |
| | | itemCount.setChosenPercentage(chosenPercentage.toString()); |
| | | } |
| | | itemCountMap.put(itemCount.getOptionText(), itemCount); |
| | | } |
| | | } |
| | | }); |
| | | List<ServiceSubtaskScriptCount> details = new ArrayList<>(itemCountMap.values()); |
| | | count.setDetails(details); |
| | | result.put(scriptid, count); |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | } |