123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package com.sagacloud.route;
- import com.alibaba.fastjson.JSONObject;
- import com.github.rjeschke.txtmark.Processor;
- import com.sagacloud.route.processors.Insurance.*;
- import com.sagacloud.route.processors.GetPropByPjProcessor;
- import com.sagacloud.route.processors.Maintainance.FilterPropertyProcessor;
- import com.sagacloud.route.processors.Maintainance.QueryPropertyProcesspr;
- import com.sagacloud.route.processors.Manufacturer.MaunfacturerFilter;
- import com.sagacloud.route.processors.Manufacturer.GetVenderBySpecProcessor;
- import com.sagacloud.route.processors.PeriodTask.StatisticsProcessor;
- import com.sagacloud.route.processors.supplier.SupplierFilter;
- import com.sagacloud.utils.Const;
- import org.apache.commons.io.IOUtils;
- import javax.ws.rs.core.MediaType;
- import java.io.StringWriter;
- import java.util.ArrayList;
- import java.util.List;
- public class Route extends ExceptionHandlerBaseRoute {
- @Override
- public void configure() throws Exception {
- configExceptionHandler();
- rest().get("/doc")
- .produces("text/html;charset=UTF-8")
- .route()
- .process(msg -> {
- String docContentStr = Processor.process(Route.class.getClassLoader().getResourceAsStream("documentation.md"));
- StringWriter writer = new StringWriter();
- IOUtils.copy(Route.class.getClassLoader().getResourceAsStream("template.html"), writer, "utf-8");
- String tmplateContentStr = writer.toString();
- msg.getOut().setBody(tmplateContentStr.replace("#replaceMePlease#", docContentStr));
- });
-
- rest("/manufacturer/property/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(exchange -> {
- String jsonStr = exchange.getIn().getBody(String.class);
- JSONObject json = JSONObject.parseObject(jsonStr);
- exchange.setProperty("venderId",json.getString("venderId"));
- exchange.getIn().setBody(jsonStr);
- })
- .to("direct:getPropertiesByPj")
- .process(new GetVenderBySpecProcessor())
- .to(Const.venders+"/manufacturer/specification/query_vender")
- .process(new MaunfacturerFilter());
-
- rest("/supplier/property/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(exchange -> {
- String jsonStr = exchange.getIn().getBody(String.class);
- JSONObject json = JSONObject.parseObject(jsonStr);
- exchange.setProperty("venderId",json.getString("venderId"));
- exchange.getIn().setBody(jsonStr);
- })
- .to("direct:getPropertiesByPj")
- .process(new GetVenderBySpecProcessor())
- .to(Const.venders+"/manufacturer/specification/query_vender")
- .process(new SupplierFilter());
-
- rest("/insurance/project/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(new GetInsuranceNoListProcessor())
- .to(String.join("", InitEnvRoute.venders, "/insurance/contract/query"))
- .process(new HandleWarrantyFromVenderProcessor())
- .to("direct:getPropertiesByPj")
-
- .process(new GetPropertyUnderWarrantyProcessor());
-
- rest("/insurance/contract/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(new GetInsuranceNoListProcessor())
- .to(String.join("", InitEnvRoute.venders, "/insurance/contract/query"))
- .process(new HandleWarrantyFromVenderProcessor())
- .to("direct:getPropertiesByPj")
- .process(new GetPropertyCountInAllWarrantyProcessor());
-
- rest("/insurance/contract/property/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(new StoreInsuranceNoProcessor())
- .to("direct:getPropertiesByPj")
- .process(new GetPropertyInCertainWarrantyProcessor());
-
- rest("/maintainance/property/").post("query")
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(new QueryPropertyProcesspr())
- .to("direct:getPropertiesByPj")
- .process(new FilterPropertyProcessor());
- rest("/test/").get().produces(MediaType.APPLICATION_JSON).route()
- .process(msg -> {
- List<String> lst = new ArrayList<>();
- for(int i = 0; i < 1000; i++){
- lst.add("hh" + i);
- }
- msg.getOut().setBody(lst);
- }).split(body(), (oldmsg, newmsg) -> {
- if(oldmsg == null){
- return newmsg;
- }
- oldmsg.getIn().setBody(oldmsg.getIn().getBody(String.class) + newmsg.getIn().getBody(String.class));
- return oldmsg;
- }).parallelProcessing().parallelAggregate().to("direct://test");
-
-
-
- from("direct:getProperty").process(new StatisticsProcessor())
- .to(String.join("", InitEnvRoute.venders, "/auxiliary/property/create_by_project"));
-
- from("direct:getPropertiesByPj")
- .process(new GetPropByPjProcessor())
- .to(Const.dataPlatform+"/property/relation_query");
- rest("/test").post()
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .to("direct:getPropertiesByPj");
- }
- }
|