diff --git a/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java b/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java index 3e1c546..e32756a 100644 --- a/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java +++ b/src/main/java/club/joylink/xiannccda/constants/common/FaultQueryType.java @@ -3,6 +3,8 @@ package club.joylink.xiannccda.constants.common; public enum FaultQueryType { // FAULT_EMERGENCY_GUIDE 开头是应急故障,FAULT_EXIT_SERVICE 开头是故障退出服务 // T 代表车辆,T后面代表车辆型号 + + FAULT_EMERGENCY_NCC, FAULT_EMERGENCY_GUIDE, FAULT_EXIT_SERVICE, FAULT_EMERGENCY_GUIDE_T_DK37, diff --git a/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java b/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java index 755b980..28ae086 100644 --- a/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java +++ b/src/main/java/club/joylink/xiannccda/controller/FaultQueryController.java @@ -7,6 +7,7 @@ import club.joylink.xiannccda.constants.common.FaultQueryType; import club.joylink.xiannccda.dto.alertTip.AlertTipInfoDto; import club.joylink.xiannccda.dto.alertTip.AlertTipQueryDTO; import club.joylink.xiannccda.dto.alertTip.AlertTipSaveDTO; +import club.joylink.xiannccda.dto.fq.FaultQueryNcc; import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; import club.joylink.xiannccda.dto.fq.FaultType; import club.joylink.xiannccda.dto.fq.FaultType.FaultTypeDetail; @@ -58,14 +59,22 @@ public class FaultQueryController { // @CommonLogAnno(name = "决策信息-查看", logType = CommonLogTypeEnum.OPERATE, subLogType = SubEventType.QUERY) public List faultType() { return List.of(new FaultType(3, - List.of(new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_GUIDE, "车辆故障应急处置指导关键点"), new FaultTypeDetail(FaultQueryType.FAULT_EXIT_SERVICE, "车辆故障退出服务地点"))) + List.of(new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_GUIDE, "车辆故障应急处置指导关键点"), new FaultTypeDetail(FaultQueryType.FAULT_EXIT_SERVICE, "车辆故障退出服务地点") + , new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_NCC, "NCC应急查询"))) , new FaultType(4, List.of(new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_GUIDE_T_DK37, "车辆故障应急处置指导关键点-DK37车型"), new FaultTypeDetail(FaultQueryType.FAULT_EXIT_SERVICE_T_DK37, "车辆故障退出服务地点-DK37车型") , new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_GUIDE_T_CCD_5037, "车辆故障应急处置指导关键点CCD-5037车型"), - new FaultTypeDetail(FaultQueryType.FAULT_EXIT_SERVICE_T_CCD_5037, "车辆故障退出服务地点CCD-5037车型"))) + new FaultTypeDetail(FaultQueryType.FAULT_EXIT_SERVICE_T_CCD_5037, "车辆故障退出服务地点CCD-5037车型"), new FaultTypeDetail(FaultQueryType.FAULT_EMERGENCY_NCC, "NCC应急查询"))) ); } + @SecurityRequirement(name = "jwt") + @Operation(summary = "保存故障查询") + @PostMapping("/ncc") + public List queryFQForNcc() { + return this.faultQueryRepository.fqNcc(); + } + @SecurityRequirement(name = "jwt") @Operation(summary = "保存故障查询") @PostMapping() diff --git a/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryNcc.java b/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryNcc.java new file mode 100644 index 0000000..3b0c4ed --- /dev/null +++ b/src/main/java/club/joylink/xiannccda/dto/fq/FaultQueryNcc.java @@ -0,0 +1,50 @@ +package club.joylink.xiannccda.dto.fq; + +import club.joylink.xiannccda.entity.FaultQuery; +import com.google.common.collect.Lists; +import java.security.PublicKey; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.Data; + +@Data +public class FaultQueryNcc { + + public FaultQueryNcc() { + + } + + public FaultQueryNcc(String typeName, List fqList) { + this.nccTypeName = typeName; + Map> dataMapList = fqList.stream().collect(Collectors.groupingBy(FaultQuery::getFaultDriverShower, Collectors.mapping(FaultQuery::getResultMsg, Collectors.toList()))); + List tl = Lists.newArrayList(); + dataMapList.forEach((k, v) -> { + tl.add(new NccData(k, v)); + }); + this.nccData = tl; + } + + private String nccTypeName; + private List nccData; + + @Data + public static class NccData { + + public NccData() { + + } + + public NccData(String action, List datas) { + + this.action = action; + this.datas = datas; + } + + private String action; + private List datas; + } +} + + diff --git a/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java b/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java index 0613e5d..a6412f6 100644 --- a/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/IFaultQueryRepository.java @@ -1,9 +1,11 @@ package club.joylink.xiannccda.repository; +import club.joylink.xiannccda.dto.fq.FaultQueryNcc; import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; import club.joylink.xiannccda.entity.FaultQuery; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; /** *

@@ -17,5 +19,7 @@ public interface IFaultQueryRepository extends IService { void newSaveOrUpdate(FaultQuery fq); + List fqNcc(); + IPage page(FaultQueryReqDTO reqDTO); } diff --git a/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java b/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java index 7e4d36f..e766987 100644 --- a/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java +++ b/src/main/java/club/joylink/xiannccda/repository/impl/FaultQueryRepository.java @@ -1,6 +1,8 @@ package club.joylink.xiannccda.repository.impl; +import club.joylink.xiannccda.constants.common.FaultQueryType; import club.joylink.xiannccda.dto.CommonPageRequest; +import club.joylink.xiannccda.dto.fq.FaultQueryNcc; import club.joylink.xiannccda.dto.fq.FaultQueryReqDTO; import club.joylink.xiannccda.entity.FaultQuery; import club.joylink.xiannccda.exception.BusinessExceptionAssertEnum; @@ -10,9 +12,21 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.StringPool; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.google.common.base.Splitter; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.collect.Lists; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.TreeMap; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -27,6 +41,9 @@ import org.springframework.stereotype.Service; @Service public class FaultQueryRepository extends ServiceImpl implements IFaultQueryRepository { + + private final static Cache> FQ_NCC_CACHE = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.MINUTES).build(); + @Override public void newSaveOrUpdate(FaultQuery fq) { if (fq.getId() == null) { @@ -40,13 +57,50 @@ public class FaultQueryRepository extends ServiceImpl page(FaultQueryReqDTO reqDTO) { + public List fqNcc() { + try { + return FQ_NCC_CACHE.get(FaultQueryType.FAULT_EMERGENCY_NCC.name(), () -> { + List nccList = queryNccData(); + return nccList; + }); + } catch (ExecutionException e) { + throw new RuntimeException(e); + } + } + + private List queryNccData() { + FaultQueryReqDTO dto = new FaultQueryReqDTO(); + dto.setFaultType(FaultQueryType.FAULT_EMERGENCY_NCC.name()); + Page p = new Page(); + p.setCurrent(1); + p.setSize(999); + QueryWrapper qw = createQueryWrapper(dto); + IPage page = this.page(p, qw); +// Map> typeMapList = page.getRecords().stream().collect(Collectors.groupingBy(FaultQuery::getFaultNameShower, TreeMap::new, Collectors.toList())).descendingMap(); + Map> typeMapList = page.getRecords().stream().collect(Collectors.groupingBy(FaultQuery::getFaultNameShower, Collectors.collectingAndThen(Collectors.toList(), list -> { + list.sort(Comparator.comparingLong(FaultQuery::getId)); + return list; + }))); + List nccList = Lists.newArrayList(); + typeMapList.forEach((k, v) -> { + nccList.add(new FaultQueryNcc(k, v)); + }); + return nccList; + } + + private QueryWrapper createQueryWrapper(FaultQueryReqDTO reqDTO) { QueryWrapper qw = new QueryWrapper<>(); LambdaQueryWrapper lam = qw.lambda().eq(Objects.nonNull(reqDTO.getLineId()), FaultQuery::getLineId, reqDTO.getLineId()) .like(StringUtils.isNotEmpty(reqDTO.getFaultName()), FaultQuery::getFaultNameShower, reqDTO.getFaultName()); if (StringUtils.isNotEmpty(reqDTO.getFaultType())) { lam.in(FaultQuery::getFaultType, Splitter.on(StringPool.COMMA).trimResults().splitToList(reqDTO.getFaultType())); } + return qw; + } + + @Override + public IPage page(FaultQueryReqDTO reqDTO) { + QueryWrapper qw = createQueryWrapper(reqDTO); return this.page(CommonPageRequest.defaultPage(), qw); } }