| | |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.smartor.domain.ServiceSubtask; |
| | | import com.smartor.domain.*; |
| | | import com.smartor.domain.ServiceSubtaskDetail; |
| | | import com.smartor.domain.ServiceSubtaskDetail; |
| | | import com.smartor.domain.ServiceTask; |
| | | import com.smartor.mapper.ServiceSubtaskDetailMapper; |
| | | import com.smartor.mapper.ServiceSubtaskMapper; |
| | | import com.smartor.service.IServiceSubtaskDetailService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | return serviceTaskMap; |
| | | } |
| | | |
| | | |
| | | /* |
| | | * @param targetid |
| | | * @return 指标统计 |
| | | */ |
| | | @Override |
| | | public List<ServiceSubtaskDetailTarget> countPatByTarget(Long targetid) { |
| | | List<ServiceSubtaskDetailTarget> serviceSubtaskDetailTargets = ServiceSubtaskDetailMapper.countPatByTarget(targetid); |
| | | if (CollectionUtils.isNotEmpty(serviceSubtaskDetailTargets)) { |
| | | Long totalCount = serviceSubtaskDetailTargets.stream().filter(target -> target.getMatchedtext() == null || target.getMatchedtext().isEmpty()).mapToLong(target -> target.getCount() != null ? target.getCount() : 0) // 确保 count 为 0 如果为 null |
| | | .sum(); |
| | | |
| | | Long allShowCount = 0L; |
| | | |
| | | // 遍历列表,将 matchedText 为""赋值给 null |
| | | for (ServiceSubtaskDetailTarget target : serviceSubtaskDetailTargets) { |
| | | if (target.getMatchedtext() == null) { |
| | | target.setCount(target.getCount() != null ? target.getCount() + totalCount : totalCount); // 给 matchedText 为 null 的对象赋值 |
| | | } |
| | | //允许null相加,不允许""相加 |
| | | if (target.getMatchedtext() == null || !target.getMatchedtext().isEmpty()) { |
| | | allShowCount = allShowCount + target.getCount(); |
| | | } |
| | | } |
| | | |
| | | // 使用迭代器删除 matchedText 为 "" 的对象 |
| | | Iterator<ServiceSubtaskDetailTarget> iterator = serviceSubtaskDetailTargets.iterator(); |
| | | while (iterator.hasNext()) { |
| | | ServiceSubtaskDetailTarget target = iterator.next(); |
| | | if (target.getMatchedtext() != null && target.getMatchedtext().isEmpty()) { |
| | | iterator.remove(); // 删除 matchedText 为 "" 的对象 |
| | | } |
| | | } |
| | | for (ServiceSubtaskDetailTarget target : serviceSubtaskDetailTargets) { |
| | | target.setTargetShowCount(allShowCount.toString()); |
| | | BigDecimal count = new BigDecimal(target.getCount() != null ? target.getCount().toString() : "0"); |
| | | BigDecimal allCount = new BigDecimal(allShowCount.toString()); |
| | | if (allCount.compareTo(BigDecimal.ZERO) == 0) |
| | | target.setPercentage(count.divide(allCount, 2, RoundingMode.HALF_UP).toString()); |
| | | } |
| | | } |
| | | |
| | | return serviceSubtaskDetailTargets; |
| | | } |
| | | |
| | | } |