diff --git a/pom.xml b/pom.xml index ed7db5d..02cf9c8 100644 --- a/pom.xml +++ b/pom.xml @@ -55,11 +55,25 @@ com.netflix.graphql.dgs graphql-dgs-pagination + + com.netflix.graphql.dgs + graphql-dgs-extended-scalars + com.netflix.graphql.dgs.codegen graphql-dgs-codegen-client-core ${dgs.codegen.version} + + + com.graphql-java + graphql-java-extended-scalars + + + javax.annotation + javax.annotation-api + 1.3.2 + org.projectlombok lombok @@ -80,6 +94,11 @@ hutool-all 5.4.0 + + + + + org.springframework.boot spring-boot-starter-test @@ -87,8 +106,11 @@ org.springframework.cloud - spring-cloud-openfeign-core - 2.1.3.RELEASE + spring-cloud-starter-openfeign + + + org.springframework.graphql + spring-graphql @@ -119,7 +141,7 @@ true - true + false com.longfor src/main/resources/schema @@ -130,6 +152,15 @@ ]]> + + + + + + + + + diff --git a/src/main/java/com/longfor/c2/graphql/starter/BffApplication.java b/src/main/java/com/longfor/c2/graphql/starter/BffApplication.java index a68f299..4b806be 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/BffApplication.java +++ b/src/main/java/com/longfor/c2/graphql/starter/BffApplication.java @@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; @SpringBootApplication -//@EnableFeignClients +@EnableFeignClients public class BffApplication { public static void main(String[] args) { diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/ShopClient.java b/src/main/java/com/longfor/c2/graphql/starter/client/ShopClient.java index 679fc46..2aebd75 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/client/ShopClient.java +++ b/src/main/java/com/longfor/c2/graphql/starter/client/ShopClient.java @@ -1,9 +1,45 @@ package com.longfor.c2.graphql.starter.client; +import com.longfor.c2.graphql.starter.client.request.PolymerShopInfoQueryReq; +import com.longfor.c2.graphql.starter.client.response.BaseShopInfo; +import com.longfor.c2.graphql.starter.client.request.Request; +import com.longfor.c2.graphql.starter.client.response.ContractInfoResponse; +import com.longfor.c2.graphql.starter.client.response.DyAccountInfoResponse; +import com.longfor.c2.graphql.starter.client.response.Response; +import com.longfor.types.ContractInfo; +import com.longfor.types.DyAccountInfo; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopUnitInfo; import org.springframework.cloud.openfeign.FeignClient; -// -//@FeignClient("shop") -//public interface ShopClient { -// -// -//} +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import java.util.List; + + +@FeignClient(value = "shop", url = "http://localhost:18801") +public interface ShopClient { + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopPolymerInfo") + Response> queryPolymerShopInfo(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryBaseShopInfo") + Response> queryBaseShopInfo(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopContractEntity") + Response> queryShopContractEntity(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopSquareContractEntity") + Response> queryShopSquareContractEntity(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopInnovateContractEntity") + Response> queryShopInnovateContractEntity(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopUnitInfo") + Response> queryShopUnitInfo(Request req); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryShopBrandInfos") + Response> queryShopBrandInfos(Request request); + + @RequestMapping(method = RequestMethod.POST, value = "/open/shop/queryDyAccountInfo") + Response> queryDyAccountInfo(Request request); +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/request/PolymerShopInfoQueryReq.java b/src/main/java/com/longfor/c2/graphql/starter/client/request/PolymerShopInfoQueryReq.java new file mode 100644 index 0000000..d958c94 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/request/PolymerShopInfoQueryReq.java @@ -0,0 +1,8 @@ +package com.longfor.c2.graphql.starter.client.request; +import lombok.Data; +import java.util.List; + +@Data +public class PolymerShopInfoQueryReq { + private List shopIds; +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/request/Request.java b/src/main/java/com/longfor/c2/graphql/starter/client/request/Request.java new file mode 100644 index 0000000..5574a37 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/request/Request.java @@ -0,0 +1,27 @@ +package com.longfor.c2.graphql.starter.client.request; + +import java.io.Serializable; + +public class Request implements Serializable { + private static final long serialVersionUID = 1L; + private T data; + + public Request() { + } + + public T getData() { + return this.data; + } + + public void setData(T data) { + this.data = data; + } + + public String toString() { + String sep = "; "; + StringBuffer sb = new StringBuffer(); + sb.append("Request").append(":"); + sb.append("[data]").append(" = ").append(this.getData()).append(sep); + return sb.toString(); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/response/BaseShopInfo.java b/src/main/java/com/longfor/c2/graphql/starter/client/response/BaseShopInfo.java new file mode 100644 index 0000000..a41e036 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/response/BaseShopInfo.java @@ -0,0 +1,64 @@ +package com.longfor.c2.graphql.starter.client.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +public class BaseShopInfo { + private Integer shopId; + + private String shopName; + + private String shopStatus; + + private String shopValidity; + + private String shopType; + + private String projectId; + + private String projectName; + + private BigDecimal shopArea; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planInDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planOpenDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planStartDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planEndDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realInDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realOpenDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realStartDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realEndDate; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime receiveDate; + + private String formatId; + + private String formatName; +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/response/ContractInfoResponse.java b/src/main/java/com/longfor/c2/graphql/starter/client/response/ContractInfoResponse.java new file mode 100644 index 0000000..531b33c --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/response/ContractInfoResponse.java @@ -0,0 +1,62 @@ +package com.longfor.c2.graphql.starter.client.response; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import java.time.LocalDateTime; + +@Data +public class ContractInfoResponse { + private Integer shopId; + + private String contractNo; + + private String contractId; + + private String contractType; + + private String buildType; + + private String contractStatus; + + private String archiveStatus; + + private Integer version; + + private Boolean valid; + + private Integer groupNum; + + private String customerId; + + private String customerName; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planInDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planOpenDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planStartDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planEndDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime planEnterDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realInDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realOpenDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realStartDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realEndDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realEnterDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realDecorateDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realReturnDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime realLeaveDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime terminateDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime changeEffectiveDate; +} \ No newline at end of file diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/response/DyAccountInfoResponse.java b/src/main/java/com/longfor/c2/graphql/starter/client/response/DyAccountInfoResponse.java new file mode 100644 index 0000000..925dd93 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/response/DyAccountInfoResponse.java @@ -0,0 +1,21 @@ +package com.longfor.c2.graphql.starter.client.response; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.longfor.types.DyAccountInfo; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class DyAccountInfoResponse extends DyAccountInfo { + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime statusUpdateTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime bindTime; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime openDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime closureDate; + +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/client/response/Response.java b/src/main/java/com/longfor/c2/graphql/starter/client/response/Response.java new file mode 100644 index 0000000..2479ee6 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/client/response/Response.java @@ -0,0 +1,76 @@ +package com.longfor.c2.graphql.starter.client.response; +import java.io.Serializable; + + +public class Response implements Serializable { + private static final long serialVersionUID = 1L; + protected D data; + protected int code; + protected String msg; + protected String curTime; + protected transient boolean showLog = true; + + public Response() { + } + + public Response(D data) { + this.data = data; + } + + + + + public D getData() { + return this.data; + } + + public int getCode() { + return this.code; + } + + public String getMsg() { + return this.msg; + } + + public String getCurTime() { + return this.curTime; + } + + public void setData(D data) { + this.data = data; + } + + public void setCode(int code) { + this.code = code; + } + + public void setMsg(String msg) { + this.msg = msg; + } + + public void setCurTime(String curTime) { + this.curTime = curTime; + } + + + public Response code(int code) { + this.code = code; + return this; + } + + public Response msg(String msg) { + this.msg = msg; + return this; + } + + public Response curTime(String curTime) { + this.curTime = curTime; + return this; + } + + public Response data(D data) { + this.data = data; + return this; + } + +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/autoconfigure/ApiSignConfigLoad.java b/src/main/java/com/longfor/c2/graphql/starter/config/ApiSignConfigLoad.java similarity index 95% rename from src/main/java/com/longfor/c2/graphql/starter/autoconfigure/ApiSignConfigLoad.java rename to src/main/java/com/longfor/c2/graphql/starter/config/ApiSignConfigLoad.java index b9b0096..e342c49 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/autoconfigure/ApiSignConfigLoad.java +++ b/src/main/java/com/longfor/c2/graphql/starter/config/ApiSignConfigLoad.java @@ -1,4 +1,4 @@ -package com.longfor.c2.graphql.starter.autoconfigure; +package com.longfor.c2.graphql.starter.config; import com.alibaba.fastjson.JSONObject; import com.longfor.c2.graphql.starter.entity.AppSecretInfo; diff --git a/src/main/java/com/longfor/c2/graphql/starter/autoconfigure/CachedHttpServletRequestWrapper.java b/src/main/java/com/longfor/c2/graphql/starter/config/CachedHttpServletRequestWrapper.java similarity index 98% rename from src/main/java/com/longfor/c2/graphql/starter/autoconfigure/CachedHttpServletRequestWrapper.java rename to src/main/java/com/longfor/c2/graphql/starter/config/CachedHttpServletRequestWrapper.java index 4ed45b0..fcbee21 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/autoconfigure/CachedHttpServletRequestWrapper.java +++ b/src/main/java/com/longfor/c2/graphql/starter/config/CachedHttpServletRequestWrapper.java @@ -1,4 +1,4 @@ -package com.longfor.c2.graphql.starter.autoconfigure; +package com.longfor.c2.graphql.starter.config; import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; diff --git a/src/main/java/com/longfor/c2/graphql/starter/config/GraphQlConfig.java b/src/main/java/com/longfor/c2/graphql/starter/config/GraphQlConfig.java new file mode 100644 index 0000000..a773c26 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/config/GraphQlConfig.java @@ -0,0 +1,14 @@ +package com.longfor.c2.graphql.starter.config; + +import graphql.scalars.ExtendedScalars; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.graphql.execution.RuntimeWiringConfigurer; + +@Configuration +public class GraphQlConfig { + @Bean + public RuntimeWiringConfigurer runtimeWiringConfigurer() { + return wiringBuilder -> wiringBuilder.scalar(ExtendedScalars.GraphQLBigDecimal); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ContractInfoQueryKey.java b/src/main/java/com/longfor/c2/graphql/starter/customcontext/ContractInfoQueryKey.java new file mode 100644 index 0000000..191d713 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/customcontext/ContractInfoQueryKey.java @@ -0,0 +1,9 @@ +package com.longfor.c2.graphql.starter.customcontext; + +import lombok.Data; + +@Data +public class ContractInfoQueryKey { + private Integer shopId; + private String contractType; //合同类型 REALITY-招商合同,INNOVATE-创新合同,SQUARE-广场合同 +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryArgument.java b/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryArgument.java deleted file mode 100644 index 39340ef..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryArgument.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.longfor.c2.graphql.starter.customcontext; - -import lombok.Data; - -@Data -public class ExtendElementQueryArgument { - private String type; -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryKey.java b/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryKey.java deleted file mode 100644 index 2998c20..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ExtendElementQueryKey.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.longfor.c2.graphql.starter.customcontext; - -import lombok.Data; - -@Data -public class ExtendElementQueryKey { - private Integer id; - private ExtendElementQueryArgument arguments; -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomContext.java b/src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContext.java similarity index 50% rename from src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomContext.java rename to src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContext.java index 08afc45..87007ed 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomContext.java +++ b/src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContext.java @@ -2,10 +2,13 @@ package com.longfor.c2.graphql.starter.customcontext; import lombok.Data; -@Data -public class ShopCustomContext { - private String extendElementTypeName; +import java.util.List; - public ShopCustomContext() { +@Data +public class GlobalCustomContext { + private String extendElementTypeName; + private List shopIds; + + public GlobalCustomContext() { } } diff --git a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomerContextBuilder.java b/src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContextBuilder.java similarity index 51% rename from src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomerContextBuilder.java rename to src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContextBuilder.java index 661e53d..5040871 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/customcontext/ShopCustomerContextBuilder.java +++ b/src/main/java/com/longfor/c2/graphql/starter/customcontext/GlobalCustomContextBuilder.java @@ -3,11 +3,12 @@ package com.longfor.c2.graphql.starter.customcontext; import com.netflix.graphql.dgs.context.DgsCustomContextBuilder; import org.springframework.stereotype.Component; +//@Component @Component -public class ShopCustomerContextBuilder implements DgsCustomContextBuilder { +public class GlobalCustomContextBuilder implements DgsCustomContextBuilder { @Override - public ShopCustomContext build() { - return new ShopCustomContext(); + public GlobalCustomContext build() { + return new GlobalCustomContext(); } } diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/BaseShopInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/BaseShopInfoDataFetcher.java deleted file mode 100644 index 4d0f975..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/BaseShopInfoDataFetcher.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.longfor.c2.graphql.starter.datafetchers; - -import com.longfor.DgsConstants; -import com.longfor.c2.graphql.starter.dataloaders.BaseShopInfoDataLoader; -import com.longfor.c2.graphql.starter.services.ShopService; -import com.longfor.types.BaseShopInfo; -import com.longfor.types.Shop; -import com.netflix.graphql.dgs.*; -import org.dataloader.DataLoader; - -import java.util.concurrent.CompletableFuture; - -@DgsComponent -public class BaseShopInfoDataFetcher { - private final ShopService shopService; - - public BaseShopInfoDataFetcher(ShopService shopService) { - this.shopService = shopService; - } - - /** - * This datafetcher resolves the shows field on Query. - * It uses an @InputArgument to get the titleFilter from the Query if one is defined. - */ - @DgsData(parentType = DgsConstants.SHOP.TYPE_NAME, field = DgsConstants.SHOP.BaseShopInfo) - public CompletableFuture baseShopInfo(DgsDataFetchingEnvironment dfe) { - DataLoader shopDataLoader = dfe.getDataLoader(BaseShopInfoDataLoader.class); - Shop shop = dfe.getSource(); - return shopDataLoader.load(shop.getShopId()); - } - - -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractDataFetcher.java deleted file mode 100644 index 74a7040..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractDataFetcher.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.longfor.c2.graphql.starter.datafetchers; - -import com.longfor.c2.graphql.starter.services.ContractService; -import com.longfor.types.Contract; -import com.netflix.graphql.dgs.DgsComponent; -import com.netflix.graphql.dgs.DgsQuery; -import com.netflix.graphql.dgs.InputArgument; - -import java.util.List; -import java.util.stream.Collectors; - -@DgsComponent -public class ContractDataFetcher { - private final ContractService contractService; - - public ContractDataFetcher(ContractService contractService) { - this.contractService = contractService; - } - - /** - * This datafetcher resolves the shows field on Query. - * It uses an @InputArgument to get the titleFilter from the Query if one is defined. - */ - @DgsQuery - public List contracts(@InputArgument("titleFilter") String titleFilter) { - if (titleFilter == null) { - return contractService.contracts(); - } - - return contractService.contracts().stream().filter(s -> s.getTitle().contains(titleFilter)).collect(Collectors.toList()); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractInfoDataFetcher.java new file mode 100644 index 0000000..517e697 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ContractInfoDataFetcher.java @@ -0,0 +1,54 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.customcontext.ContractInfoQueryKey; +import com.longfor.c2.graphql.starter.customcontext.GlobalCustomContext; +import com.longfor.c2.graphql.starter.dataloaders.ContractInfoDataLoader; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ContractInfo; +import com.longfor.types.ShopInfo; +import com.netflix.graphql.dgs.DgsComponent; +import com.netflix.graphql.dgs.DgsData; +import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; +import com.netflix.graphql.dgs.InputArgument; +import com.netflix.graphql.dgs.context.DgsContext; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@DgsComponent +@Slf4j +public class ContractInfoDataFetcher { + private final ShopService shopService; + + public ContractInfoDataFetcher(ShopService shopService) { + this.shopService = shopService; + } + + /** + * This datafetcher resolves the shows field on Query. + * It uses an @InputArgument to get the titleFilter from the Query if one is defined. + * contractType + * investmentContractInfo:招商店铺 + * squareContractInfo:创新店铺 + * innovateContractInfos:广场店铺 + */ + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.ContractInfos) + public CompletableFuture> contractInfos(@InputArgument String contractType, DgsDataFetchingEnvironment dfe) { + GlobalCustomContext myCustomContext = DgsContext.getCustomContext(dfe); + + List shopIds = myCustomContext.getShopIds(); + log.info("Dgs contractInfos List: ids={}, contractType={}", shopIds, contractType); + ShopInfo shopInfo = dfe.getSource(); + DataLoader dataLoader = dfe.getDataLoader(ContractInfoDataLoader.class); + log.info("Dgs contractInfos List: shopInfo={}", shopInfo); + ContractInfoQueryKey queryKey = new ContractInfoQueryKey(); + queryKey.setShopId(shopInfo.getShopId()); + queryKey.setContractType(shopInfo.getShopType()); + + return dataLoader.load(queryKey); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/DyAccountInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/DyAccountInfoDataFetcher.java new file mode 100644 index 0000000..bd16fc7 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/DyAccountInfoDataFetcher.java @@ -0,0 +1,42 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.customcontext.GlobalCustomContext; +import com.longfor.c2.graphql.starter.dataloaders.DyAccountInfoDataLoader; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ContractInfo; +import com.longfor.types.DyAccountInfo; +import com.longfor.types.ShopInfo; +import com.netflix.graphql.dgs.DgsComponent; +import com.netflix.graphql.dgs.DgsData; +import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; +import com.netflix.graphql.dgs.InputArgument; +import com.netflix.graphql.dgs.context.DgsContext; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@DgsComponent +@Slf4j +public class DyAccountInfoDataFetcher { + + + /** + * This datafetcher resolves the shows field on Query. + * It uses an @InputArgument to get the titleFilter from the Query if one is defined. + * contractType + * investmentContractInfo:招商店铺 + * squareContractInfo:创新店铺 + * innovateContractInfos:广场店铺 + */ + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.DyAccountInfo) + public CompletableFuture dyAccountInfo(DgsDataFetchingEnvironment dfe) { + ShopInfo shopInfo = dfe.getSource(); + log.info("DgsData dyAccountInfo List: shopId={}", shopInfo.getShopId()); + DataLoader dataLoader = dfe.getDataLoader(DyAccountInfoDataLoader.class); + return dataLoader.load(shopInfo.getShopId()); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtendElementDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtendElementDataFetcher.java deleted file mode 100644 index f41dda1..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtendElementDataFetcher.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.longfor.c2.graphql.starter.datafetchers; - -import com.longfor.DgsConstants; -import com.longfor.c2.graphql.starter.customcontext.ExtendElementQueryArgument; -import com.longfor.c2.graphql.starter.customcontext.ExtendElementQueryKey; -import com.longfor.c2.graphql.starter.dataloaders.ExtendElementDataLoaderWithMappedKeys; -import com.longfor.c2.graphql.starter.services.ExtendElementService; -import com.longfor.types.ExtendElement; -import com.longfor.types.Shop; -import com.netflix.graphql.dgs.DgsComponent; -import com.netflix.graphql.dgs.DgsData; -import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; -import com.netflix.graphql.dgs.InputArgument; -import org.dataloader.DataLoader; - -import java.util.List; -import java.util.concurrent.CompletableFuture; - -@DgsComponent -public class ExtendElementDataFetcher { - private final ExtendElementService extendElementService; - - public ExtendElementDataFetcher(ExtendElementService extendElementService) { - this.extendElementService = extendElementService; - } - - /** - * This datafetcher resolves the shows field on Query. - * It uses an @InputArgument to get the titleFilter from the Query if one is defined. - */ - @DgsData(parentType = DgsConstants.SHOP.TYPE_NAME, field = DgsConstants.SHOP.ExtendElements) - public CompletableFuture> extendElements(@InputArgument("typeNameFilter") String typeNameFilter , DgsDataFetchingEnvironment dfe) { - // method 1: Use custom context to pass the arguments to data loader -// Shop shop = dfe.getSource(); -// DataLoader> dataLoader = dfe.getDataLoader(ExtendElementDataLoaderWithCustomContext.class); -// ShopCustomContext customContext = DgsContext.getCustomContext(dfe); -// customContext.setExtendElementTypeName(typeNameFilter); -// return dataLoader.load(shop.getShopId()); - - // method 2: Use the mapped keys to pass the arguments to data loader - // 2.1 As passed ExtendElementQueryKey as key and dataloader accepts the Set as parameters, - // Let's say we have keyA, keyB, keyC, and keyA holds the same value with keyB, then the downstream DataLoader will only have 2 - // EntrySet, the query will be only 2 - Shop shop = dfe.getSource(); - DataLoader> dataLoader = dfe.getDataLoader(ExtendElementDataLoaderWithMappedKeys.class); - ExtendElementQueryArgument arg = new ExtendElementQueryArgument(); - arg.setType(dfe.getExecutionStepInfo().getArgument("typeNameFilter")); - ExtendElementQueryKey queryKey = new ExtendElementQueryKey(); - queryKey.setId(shop.getShopId()); - queryKey.setArguments(arg); - - return dataLoader.load(queryKey); - - } - - -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtentDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtentDataFetcher.java deleted file mode 100644 index dec23e5..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ExtentDataFetcher.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.longfor.c2.graphql.starter.datafetchers; - -import com.longfor.DgsConstants; -import com.longfor.c2.graphql.starter.services.ExtentService; -import com.longfor.types.Extent; -import com.netflix.graphql.dgs.DgsComponent; -import com.netflix.graphql.dgs.DgsData; -import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; - -import java.util.List; - -@DgsComponent -public class ExtentDataFetcher { - private final ExtentService extentService; - - public ExtentDataFetcher(ExtentService extentService) { - this.extentService = extentService; - } - - @DgsData(parentType = DgsConstants.SHOP.TYPE_NAME, field = DgsConstants.SHOP.Extents) - public List extents(DgsDataFetchingEnvironment dfe){ - Integer current = dfe.getExecutionStepInfo().getArgument("current"); - Integer size = dfe.getExecutionStepInfo().getArgument("size"); - List extents = this.extentService.extents(); - return extents; - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopBrandInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopBrandInfoDataFetcher.java new file mode 100644 index 0000000..85618de --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopBrandInfoDataFetcher.java @@ -0,0 +1,45 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import cn.hutool.core.bean.BeanUtil; +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.customcontext.GlobalCustomContext; +import com.longfor.c2.graphql.starter.dataloaders.ShopBrandInfoDataLoader; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.BrandInfo; +import com.longfor.types.ContractInfo; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopInfo; +import com.netflix.graphql.dgs.*; +import com.netflix.graphql.dgs.context.DgsContext; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@DgsComponent +@Slf4j +public class ShopBrandInfoDataFetcher { + private final ShopService shopService; + + public ShopBrandInfoDataFetcher(ShopService shopService) { + this.shopService = shopService; + } + + /** + * This datafetcher resolves the shows field on Query. + * It uses an @InputArgument to get the titleFilter from the Query if one is defined. + */ + + + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.BrandInfos) + public CompletableFuture> shopBrandInfos(DgsDataFetchingEnvironment dfe) { + ShopInfo shopInfo = dfe.getSource(); + log.info("DgsData shopBrandInfos List: shopId={}", shopInfo.getShopId()); + DataLoader dataLoader = dfe.getDataLoader(ShopBrandInfoDataLoader.class); + CompletableFuture> future = dataLoader.load(shopInfo.getShopId()); + return future.thenApply(t -> t.stream().map(x-> BeanUtil.toBean(x, BrandInfo.class)).collect(Collectors.toList())); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopDataFetcher.java deleted file mode 100644 index 145109f..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopDataFetcher.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.longfor.c2.graphql.starter.datafetchers; - -import com.longfor.c2.graphql.starter.services.ShopService; -import com.longfor.types.Shop; -import com.netflix.graphql.dgs.DgsComponent; -import com.netflix.graphql.dgs.DgsQuery; -import com.netflix.graphql.dgs.InputArgument; -import lombok.extern.slf4j.Slf4j; - -import java.util.List; -import java.util.stream.Collectors; - -@DgsComponent -@Slf4j -public class ShopDataFetcher { - private final ShopService shopService; - - public ShopDataFetcher(ShopService shopService) { - this.shopService = shopService; - } - - /** - * This datafetcher resolves the shows field on Query. - * It uses an @InputArgument to get the titleFilter from the Query if one is defined. - */ - @DgsQuery - public List shops(@InputArgument("shopNameFilter") String shopNameFilter) { - if (shopNameFilter == null) { - return shopService.shops(); - } - log.info("Query shops: shopNameFilter={}", shopNameFilter); - - return shopService.shops().stream().collect(Collectors.toList()); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFloorDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFloorDataFetcher.java new file mode 100644 index 0000000..8096411 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFloorDataFetcher.java @@ -0,0 +1,122 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import cn.hutool.core.bean.BeanUtil; +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.customcontext.ContractInfoQueryKey; +import com.longfor.c2.graphql.starter.dataloaders.ContractInfoDataLoader; +import com.longfor.c2.graphql.starter.dataloaders.ShopBrandInfoDataLoader; +import com.longfor.c2.graphql.starter.dataloaders.ShopUnitInfoDataLoader; +import com.longfor.types.*; +import com.netflix.graphql.dgs.DgsComponent; +import com.netflix.graphql.dgs.DgsData; +import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; +import org.springframework.util.CollectionUtils; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@DgsComponent +@Slf4j +public class ShopFloorDataFetcher { + + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.ShopFloors) + public CompletableFuture> shopFloor(DgsDataFetchingEnvironment dfe) { + DataLoader shopUnitInfoDataLoader = dfe.getDataLoader(ShopUnitInfoDataLoader.class); + DataLoader shopBrandsInfoDataLoader = dfe.getDataLoader(ShopBrandInfoDataLoader.class); + DataLoader shopContractInfoDataLoader = dfe.getDataLoader(ContractInfoDataLoader.class); + ShopInfo shopInfo = dfe.getSource(); + ContractInfoQueryKey queryKey = new ContractInfoQueryKey(); + queryKey.setShopId(shopInfo.getShopId()); + queryKey.setContractType(shopInfo.getShopType()); + + log.info("DgsData shopFloor: shopId={}", shopInfo.getShopId()); + CompletableFuture> futureUnitInfos = shopUnitInfoDataLoader.load(shopInfo.getShopId()); + CompletableFuture> futureBrandInfos = shopBrandsInfoDataLoader.load(shopInfo.getShopId()); + CompletableFuture> futureContracts = shopContractInfoDataLoader.load(queryKey); + return futureUnitInfos.thenCompose(unitInfos -> futureBrandInfos.thenCompose(brandInfos -> + futureContracts.thenApply(contracts -> + combineToShopFloor(unitInfos, brandInfos, contracts, shopInfo)))); + } + + private List combineToShopFloor(List unitInfos, List brandInfos, List contracts, ShopInfo shopInfo) { + if (CollectionUtils.isEmpty(unitInfos)) { + return null; + } + String projectId = shopInfo.getProjectId(); + String projectName = shopInfo.getProjectName(); + LocalDateTime updateTime = shopInfo.getUpdateTime(); + String contractNo = contracts.stream().findFirst().map(ContractInfo::getContractNo).orElse(""); + List shopFloors = new ArrayList<>(); + if (CollectionUtils.isEmpty(brandInfos)) { + shopFloors = unitInfos.stream().map(unitInfo -> buildShopFloor(shopInfo, contractNo, projectId, projectName, updateTime, unitInfo)).collect(Collectors.toList()); + } else { + List newBrandInfos = adjustBrandFormat(brandInfos); + for (ShopUnitInfo unitInfo : unitInfos) { + for (ShopBrandInfo brandInfo : newBrandInfos) { + ShopFloor shopFloor = buildShopFloor(shopInfo, contractNo, projectId, projectName, updateTime, unitInfo); + shopFloor.setFormat1Id(brandInfo.getFormat1Id()); + shopFloor.setFormat1Name(brandInfo.getFormat1Name()); + shopFloor.setFormat2Id(brandInfo.getFormat2Id()); + shopFloor.setFormat2Name(brandInfo.getFormat2Name()); + shopFloor.setFormat3Id(brandInfo.getFormat3Id()); + shopFloor.setFormat3Name(brandInfo.getFormat3Name()); + shopFloors.add(shopFloor); + } + } + } + return shopFloors; + } + + private ShopFloor buildShopFloor(ShopInfo shopInfo, String contractNo, String projectId, String projectName, LocalDateTime updateTime, ShopUnitInfo unitInfo) { + ShopFloor shopFloor = new ShopFloor(); + shopFloor.setShopId(shopInfo.getShopId()); + shopFloor.setContractNo(contractNo); + shopFloor.setProjectId(projectId); + shopFloor.setProjectName(projectName); + shopFloor.setBlockId(unitInfo.getBlockId()); + shopFloor.setBlockName(unitInfo.getBlockName()); + shopFloor.setFloorId(unitInfo.getFloorId()); + shopFloor.setFloorNo(unitInfo.getFloorNo()); + shopFloor.setUnitId(unitInfo.getUnitId()); + shopFloor.setCreateTime(updateTime); + shopFloor.setUpdateTime(updateTime); + return shopFloor; + } + + private List adjustBrandFormat(List brandInfos) { + if (CollectionUtils.isEmpty(brandInfos)) { + return null; + } + List result = new ArrayList<>(); + for (ShopBrandInfo brandInfo : brandInfos) { + + ShopBrandInfo newBrandInfo = BeanUtil.toBean(brandInfo, ShopBrandInfo.class); + + if (brandInfo.getLastLevel() != null && brandInfo.getLastLevel() == 2) { + newBrandInfo.setFormat1Id(brandInfo.getFormat2Id()); + newBrandInfo.setFormat1Name(brandInfo.getFormat2Name()); + + newBrandInfo.setFormat2Id(brandInfo.getFormat3Id()); + newBrandInfo.setFormat2Name(brandInfo.getFormat3Name()); + + newBrandInfo.setFormat3Id(null); + newBrandInfo.setFormat3Name(null); + } + if (brandInfo.getLastLevel() != null && brandInfo.getLastLevel() == 1) { + newBrandInfo.setFormat1Id(brandInfo.getFormat3Id()); + newBrandInfo.setFormat1Name(brandInfo.getFormat3Name()); + + newBrandInfo.setFormat3Id(null); + newBrandInfo.setFormat3Name(null); + } + result.add(newBrandInfo); + } + return result; + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFormatInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFormatInfoDataFetcher.java new file mode 100644 index 0000000..254f88e --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopFormatInfoDataFetcher.java @@ -0,0 +1,43 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import cn.hutool.core.bean.BeanUtil; +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.dataloaders.ShopBrandInfoDataLoader; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopFormatInfo; +import com.longfor.types.ShopInfo; +import com.netflix.graphql.dgs.DgsComponent; +import com.netflix.graphql.dgs.DgsData; +import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.stream.Collectors; + +@DgsComponent +@Slf4j +public class ShopFormatInfoDataFetcher { + + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.FormatInfo) + public CompletableFuture shopFormatInfo(DgsDataFetchingEnvironment dfe) { + ShopInfo shopInfo = dfe.getSource(); + log.info("DgsData shopFormatInfo: shopId={}", shopInfo.getShopId()); + DataLoader dataLoader = dfe.getDataLoader(ShopBrandInfoDataLoader.class); + CompletableFuture> future = dataLoader.load(shopInfo.getShopId()); + + return future.thenApply(t -> { + log.info("shopFormatInfo={}",t.toString()); + Optional formatInfo = t.stream().findFirst().map(x-> BeanUtil.toBean(x, ShopFormatInfo.class)); + if (formatInfo.isPresent()) { + return formatInfo.get(); + } else { + return null; + } + + }); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopInfoDataFetcher.java new file mode 100644 index 0000000..c82c3c4 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopInfoDataFetcher.java @@ -0,0 +1,53 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import cn.hutool.core.bean.BeanUtil; +import com.longfor.c2.graphql.starter.client.ShopClient; +import com.longfor.c2.graphql.starter.client.request.PolymerShopInfoQueryReq; +import com.longfor.c2.graphql.starter.client.request.Request; +import com.longfor.c2.graphql.starter.client.response.BaseShopInfo; +import com.longfor.c2.graphql.starter.client.response.Response; +import com.longfor.c2.graphql.starter.customcontext.GlobalCustomContext; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ShopInfo; +import com.longfor.types.ShopUnitInfo; +import com.netflix.graphql.dgs.*; +import com.netflix.graphql.dgs.context.DgsContext; +import graphql.schema.idl.RuntimeWiring; +import graphql.schema.idl.TypeRuntimeWiring; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +@DgsComponent +@Slf4j +public class ShopInfoDataFetcher { + private final ShopService shopService; + + public ShopInfoDataFetcher(ShopService shopService) { + this.shopService = shopService; + } + + /** + * This datafetcher resolves the shows field on Query. + * It uses an @InputArgument to get the titleFilter from the Query if one is defined. + */ + @DgsQuery + public List shopInfos(@InputArgument("shopIds") List shopIds, DgsDataFetchingEnvironment dfe) { + if (shopIds == null) { + return new ArrayList(); + } + log.info("Query shopInfos: shopIds={}", shopIds); + GlobalCustomContext context = DgsContext.getCustomContext(dfe); + context.setShopIds(shopIds); + + List baseShopInfos = shopService.getShops(shopIds); + List shopInfos = baseShopInfos.stream().map(t ->BeanUtil.toBean(t, ShopInfo.class)).collect(Collectors.toList()); + return shopInfos; + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopUnitInfoDataFetcher.java b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopUnitInfoDataFetcher.java new file mode 100644 index 0000000..4c0215f --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/datafetchers/ShopUnitInfoDataFetcher.java @@ -0,0 +1,52 @@ +package com.longfor.c2.graphql.starter.datafetchers; + +import com.longfor.DgsConstants; +import com.longfor.c2.graphql.starter.customcontext.GlobalCustomContext; +import com.longfor.c2.graphql.starter.dataloaders.ShopUnitInfoDataLoader; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopInfo; +import com.longfor.types.ShopUnitInfo; +import com.netflix.graphql.dgs.DgsComponent; +import com.netflix.graphql.dgs.DgsData; +import com.netflix.graphql.dgs.DgsDataFetchingEnvironment; +import com.netflix.graphql.dgs.InputArgument; +import com.netflix.graphql.dgs.context.DgsContext; +import lombok.extern.slf4j.Slf4j; +import org.dataloader.DataLoader; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +@DgsComponent +@Slf4j +public class ShopUnitInfoDataFetcher { + private final ShopService shopService; + + public ShopUnitInfoDataFetcher(ShopService shopService) { + this.shopService = shopService; + } + + /** + * This datafetcher resolves the shows field on Query. + * It uses an @InputArgument to get the titleFilter from the Query if one is defined. + */ + + + @DgsData(parentType = DgsConstants.SHOPINFO.TYPE_NAME, field = DgsConstants.SHOPINFO.ShopUnitInfos) + public CompletableFuture> shopUnitInfos(DgsDataFetchingEnvironment dfe) { + + GlobalCustomContext myCustomContext = DgsContext.getCustomContext(dfe); + if (myCustomContext.getShopIds() == null) { + return CompletableFuture.completedFuture(new ArrayList()); + } + List shopIds = myCustomContext.getShopIds(); + log.info("DgsData shopUnitInfos List: shopIds={}", shopIds); + + ShopInfo shopInfo= dfe.getSource(); + + DataLoader dataLoader = dfe.getDataLoader(ShopUnitInfoDataLoader.class); + return dataLoader.load(shopInfo.getShopId()); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/BaseShopInfoDataLoader.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/BaseShopInfoDataLoader.java deleted file mode 100644 index 5f3a582..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/BaseShopInfoDataLoader.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.longfor.c2.graphql.starter.dataloaders; - -import com.longfor.c2.graphql.starter.services.BaseShopInfoService; -import com.longfor.types.BaseShopInfo; -import com.netflix.graphql.dgs.DgsDataLoader; -import org.dataloader.MappedBatchLoader; - -import java.util.ArrayList; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; - -@DgsDataLoader(name = "baseShopInfoData") -public class BaseShopInfoDataLoader implements MappedBatchLoader { - - private final BaseShopInfoService baseShopInfoService; - - public BaseShopInfoDataLoader(BaseShopInfoService baseShopInfoService){ - this.baseShopInfoService = baseShopInfoService; - } - - @Override - public CompletionStage> load(Set ShopIds) { - return CompletableFuture.supplyAsync(() -> baseShopInfoService.baseShopInfoForShop(new ArrayList<>(ShopIds))); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ContractInfoDataLoader.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ContractInfoDataLoader.java new file mode 100644 index 0000000..5fb52ee --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ContractInfoDataLoader.java @@ -0,0 +1,48 @@ +package com.longfor.c2.graphql.starter.dataloaders; + +import com.longfor.c2.graphql.starter.customcontext.ContractInfoQueryKey; +import com.longfor.c2.graphql.starter.services.ContractService; +import com.longfor.types.ContractInfo; +import com.netflix.graphql.dgs.DgsDataLoader; +import org.dataloader.BatchLoaderEnvironment; +import org.dataloader.MappedBatchLoaderWithContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.stream.Collectors; + +@DgsDataLoader(name = "contractInfoDataLoader") +public class ContractInfoDataLoader implements MappedBatchLoaderWithContext> { + @Autowired + private ContractService contractService; + + @Override + public CompletionStage>> load(Set set, BatchLoaderEnvironment batchLoaderEnvironment) { + Map> groupedKeys = set.stream().collect(Collectors.groupingBy(ContractInfoQueryKey::getContractType, Collectors.toList())); + + CompletableFuture>> completableFuture = CompletableFuture.supplyAsync(() -> { + List>>> futures = new ArrayList<>(); + for (List groupedKey : groupedKeys.values()) { + Set shopIds = groupedKey.stream().map(ContractInfoQueryKey::getShopId).collect(Collectors.toSet()); + String contractType = groupedKey.get(0).getContractType(); + CompletableFuture>> future = CompletableFuture.supplyAsync(() -> + contractService.contractInfos(shopIds.stream().collect(Collectors.toList()), contractType) + ); + futures.add(future); + } + List>> contractInfos = futures.stream().map(CompletableFuture::join).collect(Collectors.toList()); + Map> mappedContracts = new HashMap<>(); + int i = 0; + for (List groupedKey : groupedKeys.values()) { + Map> contractInfo = contractInfos.get(i++); + for (ContractInfoQueryKey key : groupedKey) { + mappedContracts.put(key, contractInfo.get(key.getShopId())); + } + } + return mappedContracts; + }); + return completableFuture; + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/DyAccountInfoDataLoader.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/DyAccountInfoDataLoader.java new file mode 100644 index 0000000..ff82972 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/DyAccountInfoDataLoader.java @@ -0,0 +1,32 @@ +package com.longfor.c2.graphql.starter.dataloaders; + +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.DyAccountInfo; +import com.netflix.graphql.dgs.DgsDataLoader; +import org.dataloader.BatchLoaderEnvironment; +import org.dataloader.MappedBatchLoaderWithContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.stream.Collectors; + +@DgsDataLoader(name = "dyAccountInfoDataLoader") +public class DyAccountInfoDataLoader implements MappedBatchLoaderWithContext { + + @Autowired + private ShopService shopService; + + @Override + public CompletionStage> load(Set set, BatchLoaderEnvironment batchLoaderEnvironment) { + return CompletableFuture.supplyAsync(() -> { + List dyAccountInfos= shopService.getDyAccountInfo(set.stream().collect(Collectors.toList())); + Map> mappedDyAccounts = dyAccountInfos.stream().collect(Collectors.groupingBy(DyAccountInfo::getShopId)); + Map mappedDyAccount = mappedDyAccounts.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get(0))); + return mappedDyAccount; + }); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithCustomContext.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithCustomContext.java deleted file mode 100644 index 431b08f..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithCustomContext.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.longfor.c2.graphql.starter.dataloaders; - -import com.longfor.DgsConstants; -import com.longfor.c2.graphql.starter.customcontext.ShopCustomContext; -import com.longfor.c2.graphql.starter.services.ExtendElementService; -import com.longfor.types.ExtendElement; -import com.netflix.graphql.dgs.DgsDataLoader; -import com.netflix.graphql.dgs.context.DgsContext; -import org.dataloader.BatchLoaderEnvironment; -import org.dataloader.MappedBatchLoaderWithContext; - -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.stream.Collectors; - -@DgsDataLoader(name = DgsConstants.SHOP.ExtendElements) -public class ExtendElementDataLoaderWithCustomContext implements MappedBatchLoaderWithContext> { - private final ExtendElementService extendElementService; - - - public ExtendElementDataLoaderWithCustomContext(ExtendElementService extendElementService) { - this.extendElementService = extendElementService; - } - - @Override - public CompletionStage>> load(Set set, BatchLoaderEnvironment environment) { -// DataFetchingEnvironment environment = DataFetcherExceptionHandler.getEnvironment(); - ShopCustomContext customContext = DgsContext.getCustomContext(environment); - String typeNameFilter = customContext.getExtendElementTypeName(); - - return CompletableFuture.supplyAsync(()-> { - List all = this.extendElementService.extendElements(typeNameFilter); - return set.stream().collect(Collectors.toMap(t -> t, t -> all)); - } ); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithMappedKeys.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithMappedKeys.java deleted file mode 100644 index bc34141..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ExtendElementDataLoaderWithMappedKeys.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.longfor.c2.graphql.starter.dataloaders; - -import com.longfor.DgsConstants; -import com.longfor.c2.graphql.starter.customcontext.ExtendElementQueryArgument; -import com.longfor.c2.graphql.starter.customcontext.ExtendElementQueryKey; -import com.longfor.c2.graphql.starter.services.ExtendElementService; -import com.longfor.types.ExtendElement; -import com.netflix.graphql.dgs.DgsDataLoader; -import org.dataloader.BatchLoaderEnvironment; -import org.dataloader.MappedBatchLoaderWithContext; - -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.stream.Collectors; - -/** - * Showcase the query: - * query Shops { - * shops { - * shopId - * baseShopInfo { - * shopId - * shopName - * shopStatus - * } - * expandData: extendElements (typeNameFilter: "TypeA"){ - * attId,code,type,value - * } - * expandData2: extendElements(typeNameFilter: "TypeB"){ - * attId,code,type,value - * } - * } - * } - */ -@DgsDataLoader(name = DgsConstants.SHOP.ExtendElements) -public class ExtendElementDataLoaderWithMappedKeys implements MappedBatchLoaderWithContext> { - private final ExtendElementService extendElementService; - - - public ExtendElementDataLoaderWithMappedKeys(ExtendElementService extendElementService) { - this.extendElementService = extendElementService; - } - - @Override - public CompletionStage>> load(Set set, BatchLoaderEnvironment environment) { - // groupBy arguments, so the query will hold the same argument with different shopId - Map> queryMap = set.stream().collect(Collectors.groupingBy(ExtendElementQueryKey::getArguments)); - - CompletableFuture>> completableFuture = CompletableFuture.supplyAsync(() -> { - - List>>> futures = new ArrayList<>(); - for (List groupedKeys : queryMap.values()) { - Set shopIds = groupedKeys.stream().map(ExtendElementQueryKey::getId).collect(Collectors.toSet()); - ExtendElementQueryArgument argument = groupedKeys.get(0).getArguments(); - CompletableFuture>> future = CompletableFuture.supplyAsync(() -> - fetchExtendElements(shopIds.stream().collect(Collectors.toList()), argument) - ); - futures.add(future); - } - List>> elementResult = futures.stream().map(CompletableFuture::join).collect(Collectors.toList()); - - // rebuild querykey->result map - Map> mappedElements = new HashMap<>(); - int i = 0; - - for (List groupedKeys : queryMap.values()) { - Map> result = elementResult.get(i++); - for (ExtendElementQueryKey key : groupedKeys) { - mappedElements.put(key, result.getOrDefault(key.getId(), new ArrayList<>())); - } - } - return mappedElements; - - }); - return completableFuture; - } - - public Map> fetchExtendElements(List ids, ExtendElementQueryArgument argument) { - List extendElementList = - ids.stream().map(id -> ExtendElement.newBuilder().attId(id).type(argument.getType()).build()).collect(Collectors.toList()); - List finalExtendElementList = extendElementList.stream().filter(t -> !t.getType().equals("TypeB")).collect(Collectors.toList()); - return finalExtendElementList.stream().collect(Collectors.toMap(ExtendElement::getAttId, t -> Arrays.asList(t))); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopBrandInfoDataLoader.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopBrandInfoDataLoader.java new file mode 100644 index 0000000..b9e2d12 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopBrandInfoDataLoader.java @@ -0,0 +1,33 @@ +package com.longfor.c2.graphql.starter.dataloaders; + +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ShopBrandInfo; +import com.netflix.graphql.dgs.DgsDataLoader; +import org.dataloader.BatchLoaderEnvironment; +import org.dataloader.MappedBatchLoaderWithContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.stream.Collectors; + +@DgsDataLoader(name = "shopBrandInfoDataLoader") +public class ShopBrandInfoDataLoader implements MappedBatchLoaderWithContext> { + private final ShopService shopService; + + public ShopBrandInfoDataLoader(ShopService shopService) { + this.shopService = shopService; + } + + @Override + public CompletionStage>> load(Set set, BatchLoaderEnvironment batchLoaderEnvironment) { + List shopIds = set.stream().collect(Collectors.toList()); + return CompletableFuture.supplyAsync(() -> { + List shopBrandInfos = shopService.getShopBrandInfo(shopIds); + return shopBrandInfos.stream().collect(Collectors.groupingBy(ShopBrandInfo::getShopId)); + }); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopUnitInfoDataLoader.java b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopUnitInfoDataLoader.java new file mode 100644 index 0000000..b9bd36e --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/dataloaders/ShopUnitInfoDataLoader.java @@ -0,0 +1,33 @@ +package com.longfor.c2.graphql.starter.dataloaders; + +import com.longfor.c2.graphql.starter.customcontext.ContractInfoQueryKey; +import com.longfor.c2.graphql.starter.services.ContractService; +import com.longfor.c2.graphql.starter.services.ShopService; +import com.longfor.types.ContractInfo; +import com.longfor.types.ShopUnitInfo; +import com.netflix.graphql.dgs.DgsDataLoader; +import org.dataloader.BatchLoaderEnvironment; +import org.dataloader.MappedBatchLoaderWithContext; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.*; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionStage; +import java.util.stream.Collectors; + +@DgsDataLoader(name = "shopUnitInfoDataLoader") +public class ShopUnitInfoDataLoader implements MappedBatchLoaderWithContext> { + + @Autowired + private ShopService shopService; + + @Override + public CompletionStage>> load(Set set, BatchLoaderEnvironment batchLoaderEnvironment) { + List shopIds = + set.stream().collect(Collectors.toList()); + return CompletableFuture.supplyAsync(() -> { + List shopUnitInfos = shopService.getShopUnitInfo(shopIds); + return shopUnitInfos.stream().collect(Collectors.groupingBy(ShopUnitInfo::getShopId)); + }); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/filter/AccessFilter.java b/src/main/java/com/longfor/c2/graphql/starter/filter/AccessFilter.java index c0383d4..77e900d 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/filter/AccessFilter.java +++ b/src/main/java/com/longfor/c2/graphql/starter/filter/AccessFilter.java @@ -1,7 +1,7 @@ package com.longfor.c2.graphql.starter.filter; -import com.longfor.c2.graphql.starter.autoconfigure.ApiSignConfigLoad; -import com.longfor.c2.graphql.starter.autoconfigure.CachedHttpServletRequestWrapper; +import com.longfor.c2.graphql.starter.config.ApiSignConfigLoad; +import com.longfor.c2.graphql.starter.config.CachedHttpServletRequestWrapper; import com.longfor.c2.graphql.starter.entity.AppSecretInfo; import com.longfor.c2.graphql.starter.entity.SignRequest; import com.longfor.c2.graphql.starter.entity.ValidationResult; diff --git a/src/main/java/com/longfor/c2/graphql/starter/scalars/DateTimeScalar.java b/src/main/java/com/longfor/c2/graphql/starter/scalars/DateTimeScalar.java new file mode 100644 index 0000000..770bf22 --- /dev/null +++ b/src/main/java/com/longfor/c2/graphql/starter/scalars/DateTimeScalar.java @@ -0,0 +1,41 @@ +package com.longfor.c2.graphql.starter.scalars; + +import com.netflix.graphql.dgs.DgsScalar; +import graphql.language.StringValue; +import graphql.schema.Coercing; +import graphql.schema.CoercingParseLiteralException; +import graphql.schema.CoercingParseValueException; +import graphql.schema.CoercingSerializeException; +import org.jetbrains.annotations.NotNull; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@DgsScalar(name="DgsDateTime") +public class DateTimeScalar implements Coercing { + + @Override + public String serialize(@NotNull Object dataFetcherResult) throws CoercingSerializeException { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + if (dataFetcherResult instanceof LocalDateTime) { + return ((LocalDateTime) dataFetcherResult).format(formatter); + } else { + throw new CoercingSerializeException("Not a valid DateTime"); + } + } + + @Override + public @NotNull LocalDateTime parseValue(@NotNull Object input) throws CoercingParseValueException { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + return LocalDateTime.parse(input.toString(), formatter); + } + + @Override + public @NotNull LocalDateTime parseLiteral(@NotNull Object input) throws CoercingParseLiteralException { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + if (input instanceof StringValue) { + return LocalDateTime.parse(((StringValue) input).getValue(), formatter); + } + throw new CoercingParseLiteralException("Value is not a valid ISO date time"); + } +} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/BaseShopInfoService.java b/src/main/java/com/longfor/c2/graphql/starter/services/BaseShopInfoService.java deleted file mode 100644 index c022ee8..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/BaseShopInfoService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.longfor.c2.graphql.starter.services; - -import com.longfor.types.BaseShopInfo; - -import java.util.List; -import java.util.Map; - -public interface BaseShopInfoService { - Map baseShopInfoForShop(List shopIds); -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/ContractService.java b/src/main/java/com/longfor/c2/graphql/starter/services/ContractService.java index 5d8990d..23c63a4 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/services/ContractService.java +++ b/src/main/java/com/longfor/c2/graphql/starter/services/ContractService.java @@ -1,9 +1,11 @@ package com.longfor.c2.graphql.starter.services; -import com.longfor.types.Contract; +import com.longfor.types.ContractInfo; import java.util.List; +import java.util.Map; public interface ContractService { - List contracts(); + + Map> contractInfos(List shopIds, String contractType); } diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/ExtendElementService.java b/src/main/java/com/longfor/c2/graphql/starter/services/ExtendElementService.java deleted file mode 100644 index 0646597..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/ExtendElementService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.longfor.c2.graphql.starter.services; - -import com.longfor.types.ExtendElement; - -import java.util.List; - -public interface ExtendElementService { - List allExtendElements(); - List extendElements(String typeName); -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/ExtentService.java b/src/main/java/com/longfor/c2/graphql/starter/services/ExtentService.java deleted file mode 100644 index 1de6063..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/ExtentService.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.longfor.c2.graphql.starter.services; - -import com.longfor.types.Extent; - -import java.util.List; - -public interface ExtentService { - List extents(); - -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/ShopService.java b/src/main/java/com/longfor/c2/graphql/starter/services/ShopService.java index 4a85660..a3ee5cf 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/services/ShopService.java +++ b/src/main/java/com/longfor/c2/graphql/starter/services/ShopService.java @@ -1,10 +1,33 @@ package com.longfor.c2.graphql.starter.services; -import com.longfor.types.Contract; -import com.longfor.types.Shop; +import com.longfor.c2.graphql.starter.client.response.BaseShopInfo; +import com.longfor.types.DyAccountInfo; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopUnitInfo; import java.util.List; public interface ShopService { - List shops(); + /** + * 获取商铺信息 + * @param shopIds + * @return + */ + List getShops(List shopIds); + + /** + * 获取商铺单元信息 + * @param shopIds + * @return + */ + List getShopUnitInfo(List shopIds); + + /** + * 获取商铺品牌信息 + * @param shopIds + * @return + */ + List getShopBrandInfo(List shopIds); + + List getDyAccountInfo(List shopIds); } diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/impl/BaseShopInfoServiceImpl.java b/src/main/java/com/longfor/c2/graphql/starter/services/impl/BaseShopInfoServiceImpl.java deleted file mode 100644 index a286401..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/impl/BaseShopInfoServiceImpl.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.longfor.c2.graphql.starter.services.impl; - -import com.longfor.c2.graphql.starter.services.BaseShopInfoService; -import com.longfor.types.BaseShopInfo; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -@Service -public class BaseShopInfoServiceImpl implements BaseShopInfoService { - public Map baseShopInfoForShop(List shopIds) { - Map map = shopIds.stream().collect(Collectors.toMap(shopId -> shopId, shopId -> BaseShopInfo.newBuilder().shopId(shopId).shopName("AAA" + shopId.toString()).build())); - return map; - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ContractServiceImpl.java b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ContractServiceImpl.java index 05435c8..c8de423 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ContractServiceImpl.java +++ b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ContractServiceImpl.java @@ -1,17 +1,45 @@ package com.longfor.c2.graphql.starter.services.impl; +import cn.hutool.core.bean.BeanUtil; +import com.longfor.c2.graphql.starter.client.ShopClient; +import com.longfor.c2.graphql.starter.client.request.PolymerShopInfoQueryReq; +import com.longfor.c2.graphql.starter.client.request.Request; +import com.longfor.c2.graphql.starter.client.response.ContractInfoResponse; +import com.longfor.c2.graphql.starter.client.response.Response; import com.longfor.c2.graphql.starter.services.ContractService; +import com.longfor.types.ContractInfo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.longfor.types.Contract; -import java.util.Arrays; -import java.util.List; + +import java.util.*; +import java.util.function.Supplier; +import java.util.stream.Collectors; @Service public class ContractServiceImpl implements ContractService { + @Autowired + private ShopClient shopClient; + + @Override - public List contracts() { - return Arrays.asList( Contract.newBuilder().id(1).title("A1").build(), - Contract.newBuilder().id(2).title("B1").build()); + public Map> contractInfos(List shopIds, String contractType) { + PolymerShopInfoQueryReq req = new PolymerShopInfoQueryReq(); + req.setShopIds(shopIds); + Request request = new Request(); + request.setData(req); + // TODO:Remove the hard code here + // 合同类型 REALITY-招商合同,INNOVATE-创新合同,SQUARE-广场合同 + + Map>>> methodMap = new HashMap<>(); + methodMap.put("REALITY", () -> shopClient.queryShopContractEntity(request)); + methodMap.put("INNOVATE", () -> shopClient.queryShopInnovateContractEntity(request)); + methodMap.put("SQUARE", () -> shopClient.queryShopSquareContractEntity(request)); + Response> response = methodMap.getOrDefault(contractType, () -> new Response<>(new ArrayList<>())).get(); + List contractInfos = response.getData(); + if (contractInfos == null) { + return new HashMap<>(); + } + return contractInfos.stream().filter(t->t.getValid()).map(t -> BeanUtil.toBean(t, ContractInfo.class)).collect(Collectors.groupingBy(ContractInfo::getShopId)); } } diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtendElementServiceImpl.java b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtendElementServiceImpl.java deleted file mode 100644 index 3db6b7a..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtendElementServiceImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.longfor.c2.graphql.starter.services.impl; - -import com.longfor.c2.graphql.starter.services.ExtendElementService; -import com.longfor.types.ExtendElement; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -@Service -public class ExtendElementServiceImpl implements ExtendElementService { - @Override - public List allExtendElements() { - return Arrays.asList(ExtendElement.newBuilder().attId(1).code("A").type("TypeA").value("AA").build(), - ExtendElement.newBuilder().attId(2).code("B").type("TypeB").value("BB").build(), - ExtendElement.newBuilder().attId(3).code("C").type("TypeC").value("CC").build()); - } - - @Override - public List extendElements(String typeName) { - return allExtendElements().stream().filter(t -> typeName.equals(t.getType())).collect(Collectors.toList()); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtentServiceImpl.java b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtentServiceImpl.java deleted file mode 100644 index acb657f..0000000 --- a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ExtentServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.longfor.c2.graphql.starter.services.impl; - -import com.longfor.c2.graphql.starter.services.ExtentService; -import com.longfor.types.Extent; -import org.springframework.stereotype.Service; - -import java.util.Arrays; -import java.util.List; - -@Service -public class ExtentServiceImpl implements ExtentService { - @Override - public List extents() { - return Arrays.asList( - Extent.newBuilder().attId(1).type("TypeA").code("A").value("A").build(), - Extent.newBuilder().attId(2).type("TypeB").code("B").value("B").build(), - Extent.newBuilder().attId(3).type("TypeC").code("C").value("C").build(), - Extent.newBuilder().attId(4).type("TypeA").code("A").value("A").build(), - Extent.newBuilder().attId(5).type("TypeB").code("B").value("B").build(), - Extent.newBuilder().attId(6).type("TypeC").code("C").value("C").build(), - Extent.newBuilder().attId(7).type("TypeA").code("A").value("A").build(), - Extent.newBuilder().attId(8).type("TypeB").code("B").value("B").build() - ); - } -} diff --git a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ShopServiceImpl.java b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ShopServiceImpl.java index ea64f96..abf1ccc 100644 --- a/src/main/java/com/longfor/c2/graphql/starter/services/impl/ShopServiceImpl.java +++ b/src/main/java/com/longfor/c2/graphql/starter/services/impl/ShopServiceImpl.java @@ -1,18 +1,73 @@ package com.longfor.c2.graphql.starter.services.impl; +import cn.hutool.core.bean.BeanUtil; +import com.longfor.c2.graphql.starter.client.ShopClient; +import com.longfor.c2.graphql.starter.client.request.PolymerShopInfoQueryReq; +import com.longfor.c2.graphql.starter.client.request.Request; +import com.longfor.c2.graphql.starter.client.response.BaseShopInfo; +import com.longfor.c2.graphql.starter.client.response.DyAccountInfoResponse; +import com.longfor.c2.graphql.starter.client.response.Response; import com.longfor.c2.graphql.starter.services.ShopService; -import com.longfor.types.Shop; +import com.longfor.types.DyAccountInfo; +import com.longfor.types.ShopBrandInfo; +import com.longfor.types.ShopUnitInfo; import org.springframework.stereotype.Service; -import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; @Service public class ShopServiceImpl implements ShopService { + private final ShopClient shopClient; + + public ShopServiceImpl(ShopClient shopClient) { + this.shopClient = shopClient; + } + @Override - public List shops() { - return Arrays.asList( Shop.newBuilder().shopId(1).build(), - Shop.newBuilder().shopId(2).build()); + public List getShops(List shopIds) { + PolymerShopInfoQueryReq req = createPolymerShopInfoQueryReq(shopIds); + Response> response = shopClient.queryBaseShopInfo(createRequest(req)); + return response.getData(); + } + + @Override + public List getShopUnitInfo(List shopIds) { + PolymerShopInfoQueryReq req = createPolymerShopInfoQueryReq(shopIds); + Response> response = shopClient.queryShopUnitInfo(createRequest(req)); + return response.getData(); + } + + @Override + public List getShopBrandInfo(List shopIds) { + PolymerShopInfoQueryReq req = createPolymerShopInfoQueryReq(shopIds); + Response> response = shopClient.queryShopBrandInfos(createRequest(req)); + return response.getData(); + } + + @Override + public List getDyAccountInfo(List shopIds) { + PolymerShopInfoQueryReq req = createPolymerShopInfoQueryReq(shopIds); + Response> response = shopClient.queryDyAccountInfo(createRequest(req)); + List data = response.getData(); + List dyAccountInfos = data.stream() + .map(t -> BeanUtil.toBean(t, DyAccountInfo.class)) + .collect(Collectors.toList()); + return dyAccountInfos; + } + + // Extract common logic to create PolymerShopInfoQueryReq object + private PolymerShopInfoQueryReq createPolymerShopInfoQueryReq(List shopIds) { + PolymerShopInfoQueryReq req = new PolymerShopInfoQueryReq(); + req.setShopIds(shopIds); + return req; + } + + // Extract common logic to create Request object + private Request createRequest(T data) { + Request request = new Request<>(); + request.setData(data); + return request; } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..e69de29 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +0,0 @@ - diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/schema/schema.graphqls b/src/main/resources/schema/schema.graphqls index d02e31d..736730e 100644 --- a/src/main/resources/schema/schema.graphqls +++ b/src/main/resources/schema/schema.graphqls @@ -1,41 +1,8 @@ type Query { - contracts(titleFilter: String): [Contract] - shops(shopNameFilter: String):[Shop!]! + shopInfos(shopIds: [Int]):[ShopInfo] } -type Contract { - id: Int - title: String @uppercase - releaseYear: Int -} -type Shop{ - shopId: Int - baseShopInfo:BaseShopInfo - extendElements(typeNameFilter: String): [ExtendElement] - extents(current: Int!,size: Int!): [Extent] -} - -type BaseShopInfo{ - shopId: Int - shopName: String - shopStatus: String -} - -type ExtendElement{ - attId: Int - code:String - type : String - value: String -} - -# for Paging -type Extent @connection{ - attId: Int - code:String - type : String - value: String -} #scalar DateTime directive @skipcodegen on FIELD_DEFINITION diff --git a/src/main/resources/schema/schema.shop.graphqls b/src/main/resources/schema/schema.shop.graphqls new file mode 100644 index 0000000..251b3fb --- /dev/null +++ b/src/main/resources/schema/schema.shop.graphqls @@ -0,0 +1,168 @@ +type ShopInfo{ + # 店铺id + shopId:Int + # 店铺名称 + shopName:String + # 店铺状态 + shopStatus: String + # 店铺有效性(10A,10B) + shopValidity: String + # 店铺类型 + shopType: String + # 店铺所属项目 + projectId:String + # 项目名称 + projectName:String + # 店铺面积 + shopArea:BigDecimal + createTime:DgsDateTime + updateTime:DgsDateTime + # 预计开始时间 + planInDate:DgsDateTime + # 预计开业时间 + planOpenDate:DgsDateTime + # 预计开始时间 + planStartDate:DgsDateTime + # 预计结束时间 + planEndDate:DgsDateTime + # 实际开始时间 + realInDate:DgsDateTime + # 实际开业时间 + realOpenDate:DgsDateTime + # 实际开始时间 + realStartDate:DgsDateTime + # 实际结束时间 + realEndDate:DgsDateTime + # 接铺时间 + receiveDate:DgsDateTime + # 主业态id + formatId:String + # 主业态名称 + formatName:String + formatInfo:FormatInfo + brandInfos:[BrandInfo] + shopUnitInfos:[ShopUnitInfo] + shopFloors:[ShopFloor] + # investmentContractInfo:招商店铺 + # squareContractInfo:创新店铺 + # innovateContractInfos:广场店铺 + contractInfos(contractType:String): [ContractInfo] + dyAccountInfo:DyAccountInfo +} + +type ShopBrandInfo{ + shopId:Int + brandId:String + brandName:String + brandEnName:String + lastLevel:Int + format1Id:String + format1Name:String + format2Id:String + format2Name:String + format3Id:String + format3Name:String +} + +type FormatInfo { + format1Id:String + format1Name:String + format2Id:String + format2Name:String + format3Id:String + format3Name:String +} + +type BrandInfo{ + brandId:String + brandName:String + brandEnName:String +} + +type ShopUnitInfo { + shopId: Int + unitId:String + unitNo:String + blockId:String + blockNo:String + blockName:String + floorId:String + floorNo:String + floorName:String + status:String +} + +type ShopFloor{ + shopId:Int + contractNo:String + projectId:String + projectName:String + blockId:String + blockName:String + floorId:String + floorNo:String + isFloorNoBelong:Int + shopFloorCount:Int + unitId:String + format1Id:String + format1Name:String + format2Id:String + format2Name:String + format3Id:String + format3Name:String + createTime:DgsDateTime + updateTime:DgsDateTime +} + +type ContractInfo{ + shopId: Int + contractNo:String + contractId:String + contractType:String + buildType:String + contractStatus:String + archiveStatus:String + version:Int + valid:Boolean + groupNum:Int + customerId:String + customerName:String + planInDate:DgsDateTime + planOpenDate:DgsDateTime + planStartDate:DgsDateTime + planEndDate:DgsDateTime + planEnterDate:DgsDateTime + realInDate:DgsDateTime + realOpenDate:DgsDateTime + realStartDate:DgsDateTime + realEndDate:DgsDateTime + realEnterDate:DgsDateTime + realDecorateDate:DgsDateTime + realReturnDate:DgsDateTime + realLeaveDate:DgsDateTime + terminateDate:DgsDateTime + changeEffectiveDate:DgsDateTime +} + +type DyAccountInfo{ + shopId: Int + accountNo:String + accountName:String + shortAccountName:String + status:String + statusUpdateTime:DgsDateTime + bindId:String + bindTime:DgsDateTime + openDate:DgsDateTime + closureDate:DgsDateTime + dyProducts:[DyProductInfo] +} + +type DyProductInfo{ + shopId: Int + prdName:String + prdCode:String + prdRate:String +} +scalar BigDecimal +scalar DgsDateTime \ No newline at end of file