Selaa lähdekoodia

通用接口路由编排

lingfeng 8 vuotta sitten
vanhempi
commit
7e7622fa7d

+ 18 - 0
hos-camel/src/main/java/com/yihu/hos/camel/crawler/processor/Processor0.java

@ -0,0 +1,18 @@
package com.yihu.hos.camel.crawler.processor;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.http.common.HttpMessage;
/**
 * Created by Zdm on 2016/7/13.
 */
public class Processor0 implements Processor {
    public void process(Exchange exchange) throws Exception {
        Message outMessage = exchange.getOut();
        HttpMessage inMessage = (HttpMessage) exchange.getIn();
        outMessage.setHeader(Exchange.HTTP_QUERY, inMessage.getRequest().getQueryString());
    }
}

+ 31 - 0
hos-camel/src/main/java/com/yihu/hos/camel/crawler/route/CrawlerRouteBulider.java

@ -0,0 +1,31 @@
package com.yihu.hos.camel.crawler.route;
import com.yihu.hos.camel.crawler.processor.Processor0;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
/**
 * Created by lingfeng on 2016/7/25.
 */
public class CrawlerRouteBulider extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("jetty:http://192.168.131.96:8066/crawlerPull").routeId("crawlerPull")
                .process(new Processor0()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http://192.168.131.96:8088/crawler/patientList");
        from("jetty:http://192.168.131.96:8066/crawlerPush").routeId("crawlerPush")
                .process(new Processor0()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http://192.168.131.96:8088/crawler/patient");
        from("jetty:http://192.168.131.96:8066/crawlerFlowPull").routeId("crawlerFlowPull")
                .process(new Processor0()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http://192.168.131.96:8088/crawler/patientListFlow");
        from("jetty:http://192.168.131.96:8066/crawlerFlowPush").routeId("crawlerFlowPush")
                .process(new Processor0()).setHeader(Exchange.HTTP_METHOD, constant("POST"))
                .to("http://192.168.131.96:8088/crawler/patientFlow");
    }
}

+ 56 - 1
hos-rest/src/main/java/com/yihu/hos/rest/controllers/CrawlerController.java

@ -2,6 +2,7 @@ package com.yihu.hos.rest.controllers;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.rest.models.crawler.patient.Patient;
import com.yihu.hos.rest.services.crawler.CrawlerFlowManager;
import com.yihu.hos.rest.services.crawler.CrawlerManager;
import com.yihu.hos.rest.services.crawler.CrawlerService;
import com.yihu.hos.rest.services.standard.adapter.AdapterSchemeService;
@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Date;
/**
@ -36,6 +38,9 @@ public class CrawlerController {
    CrawlerService crawlerService;
    @Resource
    CrawlerManager crawlerManager;
    @Resource
    CrawlerFlowManager crawlerFlowManager;
    @Resource(name = AdapterSchemeService.BEAN_ID)
    private AdapterSchemeService adapterSchemeService;
@ -78,7 +83,7 @@ public class CrawlerController {
    @RequestMapping(value = "patient", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    @ResponseBody
    public Result crawler(
    public Result crawlerPatient(
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient") String patientInfo) {
@ -95,6 +100,56 @@ public class CrawlerController {
        }
    }
    @RequestMapping(value = "patient/flow", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    @ResponseBody
    public Result crawlerPatientFlow(
            @ApiParam(name = "patient", value = "病人索引信息", required = true)
            @RequestParam(value = "patient") String patientInfo) {
        Patient patient = crawlerFlowManager.parsePatient(patientInfo);
        if (patient != null) {
            Boolean result = crawlerFlowManager.collectProcess(patient);
            if (result) {
                return Result.success("采集上传成功");
            } else {
                return Result.error("采集上传失败");
            }
        } else {
            return Result.error("参数转换病人实体失败");
        }
    }
    @RequestMapping(value = "patientList", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    @ResponseBody
    public Result crawlerPatientList(
            @ApiParam(name = "beginDate", value = "开始时间", required = true)
            @RequestParam(value = "beginDate") Date beginDate,
            @ApiParam(name = "endDate", value = "开始时间", required = true)
            @RequestParam(value = "endDate") Date endDate) {
        try {
            return crawlerManager.dataCrawler(beginDate, endDate);
        } catch (Exception e) {
            return Result.error("采集上传失败");
        }
    }
    @RequestMapping(value = "patientListFlow", method = RequestMethod.POST)
    @ApiOperation(value = "采集病人健康档案", produces = "application/json", notes = "采集病人健康档案")
    @ResponseBody
    public Result crawlerPatientListFlow(
            @ApiParam(name = "beginDate", value = "开始时间", required = true)
            @RequestParam(value = "beginDate") Date beginDate,
            @ApiParam(name = "endDate", value = "开始时间", required = true)
            @RequestParam(value = "endDate") Date endDate) {
        try {
            return crawlerFlowManager.dataCrawler(beginDate, endDate);
        } catch (Exception e) {
            return Result.error("采集上传失败");
        }
    }
    /**
     * 保存任务编排数据
     */

+ 7 - 3
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/CrawlerFlowManager.java

@ -22,6 +22,7 @@ import com.yihu.hos.rest.models.standard.bo.AdapterVersion;
import com.yihu.hos.rest.services.standard.adapter.AdapterDatasetService;
import com.yihu.hos.rest.services.standard.adapter.AdapterSchemeVersionService;
import com.yihu.hos.web.framework.model.DictItem;
import com.yihu.hos.web.framework.model.Result;
import com.yihu.hos.web.framework.util.springutil.SpringBeanUtil;
import java.util.*;
@ -52,7 +53,10 @@ public class CrawlerFlowManager {
    }
    public String dataCrawler(Map<String, Object> condition) {
    public Result dataCrawler(Date beginDate, Date endDate) {
        Map<String, Object> condition = new HashMap<>();
        condition.put("beginDate", beginDate);
        condition.put("endDate", endDate);
        Integer count = 0;
        Integer totalCount = 0;
        String message;
@ -62,7 +66,7 @@ public class CrawlerFlowManager {
        if (!getDataForPrepare()) {
            message = "适配数据尚未准备";
            logger.error(message);
            return message;
            return Result.error(message);
        }
        List<Patient> patientList = dispatch.getPatientList(condition, adapterDataSetMap);
        if (!CollectionUtil.isEmpty(patientList)) {
@ -75,7 +79,7 @@ public class CrawlerFlowManager {
            }
        }
        message = "本次采集病人共" + totalCount + "条,成功采集信息" + count + "条";
        return message;
        return Result.success(message);
    }
    public boolean collectProcess(Patient patient) {

+ 9 - 14
hos-rest/src/main/java/com/yihu/hos/rest/services/crawler/CrawlerManager.java

@ -2,10 +2,6 @@ package com.yihu.hos.rest.services.crawler;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.dbhelper.common.DBList;
import com.yihu.ehr.dbhelper.common.MongodbQuery;
import com.yihu.ehr.dbhelper.common.QueryCondition;
import com.yihu.ehr.dbhelper.common.QueryEntity;
import com.yihu.hos.core.datatype.CollectionUtil;
import com.yihu.hos.core.datatype.StringUtil;
import com.yihu.hos.core.log.Logger;
@ -20,16 +16,12 @@ import com.yihu.hos.rest.models.standard.bo.AdapterVersion;
import com.yihu.hos.rest.services.standard.adapter.AdapterDatasetService;
import com.yihu.hos.rest.services.standard.adapter.AdapterSchemeVersionService;
import com.yihu.hos.web.framework.model.DictItem;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.yihu.hos.web.framework.model.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
@Service("CrawlerManager")
public class CrawlerManager {
    public static final String BEAN_ID = "CrawlerManager";
@ -56,7 +48,10 @@ public class CrawlerManager {
    }
    public String dataCrawler(Map<String, Object> condition) {
    public Result dataCrawler(Date beginDate, Date endDate) {
        Map<String, Object> condition = new HashMap<>();
        condition.put("beginDate", beginDate);
        condition.put("endDate", endDate);
        Integer count = 0;
        Integer totalCount = 0;
        String message;
@ -66,7 +61,7 @@ public class CrawlerManager {
        if (!getDataForPrepare()) {
            message = "适配数据尚未准备";
            logger.error(message);
            return message;
            return Result.error(message);
        }
        List<Patient> patientList = dispatch.getPatientList(condition, adapterDataSetMap);
@ -80,7 +75,7 @@ public class CrawlerManager {
            }
        }
        message = "本次采集病人共" + totalCount + "条,成功采集信息"+ count + "条";
        return message;
        return Result.success(message);
    }
    //单个病人采集上传