123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- package com.sagacloud.route;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.github.rjeschke.txtmark.Processor;
- import com.sagacloud.Exceptions.InvalidPostException;
- import com.sagacloud.cache.ProPasCache;
- import com.sagacloud.pojos.DPSelectPropertyResult;
- 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.VenderMapProcessor;
- import com.sagacloud.route.processors.supplier.SupplierFilter;
- import com.sagacloud.utils.Const;
- import org.apache.camel.Exchange;
- import org.apache.commons.io.IOUtils;
- import javax.ws.rs.core.MediaType;
- import java.io.StringWriter;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by Xiaoyu on 2018/7/10
- */
- 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")
- //.to(String.join("", InitEnvRoute.dataPlatform, "/property/relation_query"))
- .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");
- rest("/project/sync").post()
- .consumes(MediaType.APPLICATION_JSON)
- .produces(MediaType.APPLICATION_JSON)
- .route()
- .process(exchange -> {
- String jsonStr = exchange.getIn().getBody(String.class);
- JSONObject json = JSONObject.parseObject(jsonStr);
- JSONArray projectArr = json.getJSONArray("project");
- List<String> projectList = projectArr.toJavaList(String.class);
- if (projectList == null || projectList.size() == 0) {
- throw new InvalidPostException("project不能为空");
- }
- exchange.setProperty("projectList", projectList);
- })
- .to("direct:buildVenderMap");
- //同步全部项目的资产信息
- from("direct:syncAllProject")
- .process(exchange -> {
- exchange.setProperty("projectList", ProPasCache.pjList);
- })
- .to("direct:buildVenderMap");
- // 需要输入 body是Pj1101080001, getProperty("propertyData") 是 DPSelectPropertyResult类型,
- // getProperty("idMap") 是 Map<String, String>类型, 说明: 所有DPID --> venderId
- // getProperty("nameMap") 是 Map<String, Map<String, String>>类型 说明: 信息点Name --> (厂商库该信息点的值 --> 所属厂商)
- from("direct:getPropertyStatisticsByProject").process(new StatisticsProcessor())
- .to(String.join("", InitEnvRoute.venders, "/auxiliary/property/create_by_project"));
- //body为JSONObject,含有projectId字段
- from("direct:getPropertiesByPj")
- .process(new GetPropByPjProcessor())
- .to(Const.dataPlatform + "/property/relation_query");
- from("direct:buildVenderMap")
- .to(Const.venders + "/auxiliary/vender/query_detail?bridgeEndpoint=true&method=POST")
- .process(new VenderMapProcessor())
- .split(body()).parallelProcessing()
- .process(exchange -> {
- String projectId = exchange.getIn().getBody(String.class);
- JSONObject json = new JSONObject();
- json.put("projectId", projectId);
- exchange.setProperty("projectId" + exchange.getExchangeId(), projectId);
- exchange.getIn().setBody(json.toString());
- })
- .to("direct:getPropertiesByPj")
- .process(exchange -> {
- String jsonStr = exchange.getIn().getBody(String.class);
- DPSelectPropertyResult dpResult = JSONObject.parseObject(jsonStr, DPSelectPropertyResult.class);
- exchange.setProperty("propertyData" + exchange.getExchangeId(), dpResult);
- exchange.getIn().setBody(exchange.getProperty("projectId" + exchange.getExchangeId()));
- })
- .to("direct:getPropertyStatisticsByProject");
- }
- }
|