Bläddra i källkod

Merge branch 'dev' of trick9191/wlyy2.0 into dev

trick9191 5 år sedan
förälder
incheckning
8a8068eb6e

+ 638 - 638
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionExpressageService.java

@ -1,638 +1,638 @@
package com.yihu.jw.hospital.prescription.service;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.hospital.prescription.*;
import com.yihu.jw.hospital.prescription.dao.*;
import com.yihu.jw.hospital.prescription.service.entrance.util.SFUtils;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.http.HttpClientKit;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import java.util.*;
/**
 *  门诊物流服务
 * lith 2019.06.04
 */
@Service
public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescriptionExpressageDO, PrescriptionExpressageDao> {
    private static Logger logger = LoggerFactory.getLogger(PrescriptionExpressageService.class);
    //顺丰快递接口请求地址
    @Value("${express.sf_url}")
    private String sf_url;
    //顺丰快递接口接入编码
    @Value("${express.sf_code}")
    private String sf_code;
    //顺丰快递接口checkword
    @Value("${express.sf_check_word}")
    private String sf_check_word;
    @Autowired
    private SFUtils SFUtils;
    @Autowired
    private JpaTransactionManager transactionManager;
    //处方日志
    @Autowired
    private WlyyOutpatientExpressageLogDao outpatientExpressageLogDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private WlyyExpressagePriceDao expressagePriceDao;
    @Autowired
    private PrescriptionExpressageLogDao prescriptionExpressageLogDao;
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Autowired
    private BaseOrgDao baseOrgDao;
    /**
     * 组装请求参数,发送请求
     * @param xml
     * @return
     * @throws Exception
     */
    private String SFExpressPost(String xml)throws Exception{
        String verifyCode = SFUtils.verifyCodeSFXmlStr(xml,sf_check_word);
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("xml", xml));
        params.add(new BasicNameValuePair("verifyCode", verifyCode));
        String re = HttpClientKit.post(sf_url, params, "UTF-8");
        return re;
    }
    /**
     * 校验返回的xml报文
     * @param responseXml
     * @param title
     */
    private void verificationResponXml(String responseXml,String title) throws Exception {
        String error = "";
        if (StringUtils.isBlank(responseXml)) {
            // 如果返回的XML报文为空,请求也算失败
            //保存http日志
            error = title + ",返回的XML为空!";
            logger.info(error);
            throw new Exception(error);
        }else{
//          报错的报文示例<Response service="ScopeService"><Head>ERR</Head><ERROR code="8014">校验码错误 </ERROR></Response>
            Document doc = DocumentHelper.parseText(responseXml);
            String headvalue = doc.selectSingleNode("/Response/Head").getText();
            if(StringUtils.isNotBlank(headvalue) && "ERR".equals(headvalue)){
                //错误代码
                String errorCode = "";
                //错误代对应的文字
                String errorMessage = doc.selectSingleNode("/Response/ERROR").getText();
                Document error_doc = doc.selectSingleNode("/Response/ERROR").getDocument();
                Element root = error_doc.getRootElement();
                List<?> child = root.elements();
                for (Object o : child){
                    Element e = (Element) o;
                    errorCode = e.attributeValue("code");
                }
                error = title+","+errorCode+","+errorMessage;
                logger.info(error);
                throw new Exception(error);
            }
        }
    }
    /**
     * 查询派送地址是否属于顺丰的派送范围
     * @param d_address 派送地址
     * @return
     */
    public Boolean getSFOrderFilterService(String d_address) throws Exception {
        boolean result = false;
        String xml = SFUtils.getSFOrderFilterXml(d_address,sf_code,"","","","");
        String re = this.SFExpressPost(xml);
//        String re = "<Response service=\"OrderFilterService\"><Head>OK</Head><Body><OrderFilterResponse orderid=\"TE201407020016\" filter_result=\"2\" origincode=\"755\" remark=\"2\"/></Body></Response>";
        //xml验证
        verificationResponXml(re,"查询派送地址是否有效失败!");
        Document doc = DocumentHelper.parseText(re);
        String headvalue = doc.selectSingleNode("/Response/Head").getText();
        Element root = doc.getRootElement();
        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
            //是否能派送:1:人工确认;2:可收派;3:不可以收派
            String filter_result = "";
            Element firstWorldElement = root.element("Body");
            List<Element> elements = firstWorldElement.elements();
            for (Element o : elements){
                filter_result = o.attributeValue("filter_result");
            }
            if(StringUtils.isNotBlank(filter_result) && "2".equals(filter_result)){
                result = true;
            }
        }
        return result;
    }
    /**
     * 向顺丰快递下订单
     * @param sfexpress_obj
     * @return
     * @throws Exception
     */
    public WlyyPrescriptionExpressageDO postSFOrderService(WlyyPrescriptionExpressageDO sfexpress_obj) throws Exception {
        //获取医生所处的医院详细地址,作为寄件人地址
        WlyyPrescriptionDO prescription = prescriptionDao.findOne(sfexpress_obj.getOutpatientId());
        BaseOrgDO hospital = baseOrgDao.findByCode(prescription.getHospital());
        String xml = SFUtils.postSFOrderService(sfexpress_obj,hospital,sf_code);
        logger.info("顺丰快递下订单:xml"+xml);
        String re = this.SFExpressPost(xml);
//        String re = "<Response service=\"OrderService\"><Head>OK</Head><Body><OrderResponse filter_result=\"2\" destcode=\"592\" mailno=\"444844978335\" origincode=\"592\" orderid=\"6daa6baec5fd4b65a1b023a8b60e2e91\"/></Body></Response>";
        //xml验证
        logger.info("顺丰快递下订单:re"+re);
        verificationResponXml(re,"向顺丰快递下订单失败!");
        Document doc = DocumentHelper.parseText(re);
        String headvalue = doc.selectSingleNode("/Response/Head").getText();
        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
            Element root = doc.getRootElement();
            if (root.element("Body") != null)     //包含OrderResponse节点
            {
                root = root.element("Body");
            }
            //是否能派送:1:人工确认;2:可收派;3:不可以收派
            String filter_result = "";
            String orderid = "";//业务订单号
            String mailno = "";//顺丰运单号
            String destCode = "";//目的地区域代码
            List<?> child = root.elements();
            for (Object o : child) {
                Element e = (Element) o;
                filter_result = e.attributeValue("filter_result");
                orderid = e.attributeValue("orderid");
                mailno = e.attributeValue("mailno");
                destCode = e.attributeValue("destcode");
            }
            if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
                logger.info("顺丰快递下订单失败:派送地址不可派送,门诊编号:"+sfexpress_obj.getOutpatientId());
                throw new Exception("顺丰快递下订单失败:派送地址不可派送");
            }
            if(StringUtils.isBlank(mailno)){
                logger.info("顺丰快递下订单失败:未获取到快递单号!门诊编号:"+sfexpress_obj.getOutpatientId());
                throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
            }
            sfexpress_obj.setMailno(mailno);
            sfexpress_obj.setCityCode(destCode);
        }
        return sfexpress_obj;
    }
    /**
     * 调用顺丰接口获取物流路由日志,与本地匹配,进行增量修改,并返回完整日志列表
     * @param prescription
     * @param sfexpress_obj
     * @param sfexpresslogList
     * @return
     */
    public List<WlyyPrescriptionExpressageLogDO> getRoutInfos(WlyyPrescriptionDO prescription, WlyyPrescriptionExpressageDO sfexpress_obj, List<WlyyPrescriptionExpressageLogDO> sfexpresslogList) throws Exception {
        String xml = SFUtils.getRoutInfos(sfexpress_obj,sf_code);
        String re = this.SFExpressPost(xml);
        //xml验证
        verificationResponXml(re,"查询顺丰快递路由信息失败!");
        Document doc = DocumentHelper.parseText(re);
        String headvalue = doc.selectSingleNode("/Response/Head").getText();
        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
            Element root = doc.getRootElement();
            if (root.element("Body") != null)     //取报文根节点
            {
                root = root.element("Body");
            }
            List<?> child = root.elements();
            String mailno = "";
            Map<String,List<WlyyPrescriptionExpressageLogDO>> wayroutlsit = new HashMap<>();
            for (Object o : child) {
                Element e = (Element) o;
                mailno = e.attributeValue("mailno");
                //判断快递单号不为空,且和我们本地的一致
                if(StringUtils.isNotBlank(mailno) &&
                        sfexpress_obj.getMailno().equals(mailno)){
                    //解析报文,结合本地数据返回最终的日志结果
                    return this.xmltologlist(e,sfexpresslogList,sfexpress_obj);
                }else{
                    continue;
                }
            }
        }
        return null;
    }
    private List<WlyyPrescriptionExpressageLogDO> xmltologlist(Element e, List<WlyyPrescriptionExpressageLogDO> sfexpresslogList, WlyyPrescriptionExpressageDO sfexpress_obj)throws Exception{
        //获取本地所有路由信息的时间集
        Set<String> routAcceptTimeSet = new HashSet<>();
        for (WlyyPrescriptionExpressageLogDO log: sfexpresslogList) {
            routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
        }
        List<?> child = e.elements();
        List<WlyyPrescriptionExpressageLogDO> newroutinfolist = new ArrayList<>();
        //用于判断新节点是否包含了"已收件"的节点
        boolean isContainEndRoutInfo = false;
        for (Object o : child) {
            Element routinfoe = (Element) o;
            String accept_time = routinfoe.attributeValue("accept_time");
            String accept_address = routinfoe.attributeValue("accept_address");
            String accept_remark = routinfoe.attributeValue("remark");
            String opcode = routinfoe.attributeValue("opcode");
            //和时间集作比对,过滤已存在的
            if(!routAcceptTimeSet.contains(accept_time)){
                WlyyPrescriptionExpressageLogDO newlogobj = new WlyyPrescriptionExpressageLogDO();
                newlogobj.setAcceptTime(DateUtil.strToDate(accept_time));
                newlogobj.setAcceptAddress(accept_address);
                newlogobj.setAcceptRemark(accept_remark);
                newlogobj.setOpCode(opcode);
                newlogobj.setId(UUID.randomUUID().toString().replace("-",""));
                newlogobj.setOutpatientId(sfexpress_obj.getOutpatientId());
                newlogobj.setExpressageId(sfexpress_obj.getId());
                newlogobj.setCreateTime(new Date());
                newroutinfolist.add(newlogobj);
                sfexpresslogList.add(newlogobj);
                //aopcode=80,为已签收
                if("80".equals(opcode)){
                    isContainEndRoutInfo = true;
                }
            }
        }
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
        try {
            //如果有新增的路由信息,则添加到数据库
            if(!newroutinfolist.isEmpty()){
                prescriptionExpressageLogDao.save(newroutinfolist);
            }
            //如果路由信息节点包含了"已收件"节点,这修改处方派送状态为完成,增加物流派送日志为完成
            if(isContainEndRoutInfo){
                //修改处方状态为完成
                prescriptionDao.updateStatus(sfexpress_obj.getId(), 100,new Date());
                //保存门诊处方配送成功的日志
                WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
                outpatiExpressLog.setOutpatientId(sfexpress_obj.getOutpatientId());
                outpatiExpressLog.setId(UUID.randomUUID().toString());
                outpatiExpressLog.setType(8);
                outpatiExpressLog.setCreateTime(new Date());
                outpatiExpressLog.setFlag(1);
                outpatiExpressLog.setStatus(100);
                outpatientExpressageLogDao.save(outpatiExpressLog);
            }
            //事务提交
            transactionManager.commit(status);
        } catch (Exception ex) {
            //报错事务回滚
            transactionManager.rollback(status);
        }
        return sfexpresslogList;
    }
    /**
     * 解析顺丰推送过来的路由信息,和本地数据匹配并进行增量更新)
     * @param xml
     * @return
     * @throws Exception
     */
    public void SFRoutePushService(String xml) throws Exception{
        Document doc = DocumentHelper.parseText(xml);
        Element root = doc.getRootElement();
        if (root.element("Body") != null)     //包含WaybillRoute节点
        {
            root = root.element("Body");
        }
        List<?> child = root.elements();
        Map<String,List<WlyyPrescriptionExpressageLogDO>> wayroutlsit = new HashMap<>();
        for (Object o : child) {
            Element routinfoe = (Element) o;
            WlyyPrescriptionExpressageLogDO sflog = new WlyyPrescriptionExpressageLogDO();
            String accept_time = routinfoe.attributeValue("accepttime");
            String accept_address = routinfoe.attributeValue("acceptaddress");
            String accept_remark = routinfoe.attributeValue("remark");
            String opcode = routinfoe.attributeValue("opcode");
            String mailno = routinfoe.attributeValue("mailno");
            String orderid = routinfoe.attributeValue("orderid");
            sflog.setAcceptTime(DateUtil.strToDate(accept_time));
            sflog.setAcceptAddress(accept_address);
            sflog.setAcceptRemark(accept_remark);
            sflog.setOpCode(opcode);
            sflog.setExpressageId(orderid);
            sflog.setId(UUID.randomUUID().toString());
            sflog.setCreateTime(new Date());
            if(wayroutlsit.keySet().contains(mailno)){
                wayroutlsit.get(mailno).add(sflog);
            }else{
                List<WlyyPrescriptionExpressageLogDO> newsflogs = new ArrayList<>();
                newsflogs.add(sflog);
                wayroutlsit.put(mailno,newsflogs);
            }
        }
        if(!wayroutlsit.keySet().isEmpty()){
            for (String mailno:wayroutlsit.keySet()) {
                List<WlyyPrescriptionExpressageLogDO> pushSFLogs = wayroutlsit.get(mailno);
                //同一个快递单号的执行一个事务操作
                this.saveSFPushRoutInfos(mailno,pushSFLogs);
            }
        }
    }
    /**
     * 同一个快递单号的执行一个事务操作
     * @param mailno
     * @param pushSFLogs
     */
    public void saveSFPushRoutInfos(String mailno,List<WlyyPrescriptionExpressageLogDO> pushSFLogs){
        //根据快递单号获取处方配送详细信息
        WlyyPrescriptionExpressageDO sfexpress = prescriptionExpressageDao.findByPrescriptionExpressMailno(mailno);
        //根据快递单号获取本地的路由信息
        List<WlyyPrescriptionExpressageLogDO> localroutinfos = prescriptionExpressageLogDao.queryByOutpatientId(sfexpress.getOutpatientId());
        //需要增量更新到本地的路由信息集合
        List<WlyyPrescriptionExpressageLogDO> newroutinfolist = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事务隔离级别,开启新事务
        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
        try {
            //用于判断新节点是否包含了"已收件"的节点
            boolean isContainEndRoutInfo = false;
            //获取本地所有路由信息的时间集
            Set<String> routAcceptTimeSet = new HashSet<>();
            for (WlyyPrescriptionExpressageLogDO log: localroutinfos) {
                routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
            }
            for (WlyyPrescriptionExpressageLogDO pushlog: pushSFLogs) {
                //判断是否有已收件的路由节点
                if("80".equals(pushlog.getOpCode())){
                    isContainEndRoutInfo = true;
                }
                if(routAcceptTimeSet.contains(DateUtil.dateToStrLong(pushlog.getAcceptTime()))){
                    continue;
                }else{
                    pushlog.setOutpatientId(sfexpress.getOutpatientId());
                    newroutinfolist.add(pushlog);
                }
            }
            //如果有新增的路由信息,则添加到数据库
            if(!newroutinfolist.isEmpty()){
                prescriptionExpressageLogDao.save(newroutinfolist);
            }
            //如果路由信息节点包含了"已收件"节点,则修改处方状态为完成,增加物流派送日志为完成
            if(isContainEndRoutInfo){
                //修改处方状态为完成
                prescriptionDao.updateStatus(sfexpress.getOutpatientId(), 100,new Date());
                //保存配送成功的日志
                WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
                outpatiExpressLog.setOutpatientId(sfexpress.getOutpatientId());
                outpatiExpressLog.setId(UUID.randomUUID().toString());
                outpatiExpressLog.setType(8);
                outpatiExpressLog.setCreateTime(new Date());
                outpatiExpressLog.setFlag(1);
                outpatiExpressLog.setStatus(100);
                outpatientExpressageLogDao.save(outpatiExpressLog);
            }
            //事务提交
            transactionManager.commit(status);
        } catch (Exception ex) {
            //报错事务回滚
            transactionManager.rollback(status);
        }
    }
    /**
     * 根据收寄地址获取快递费用
     * @param d_province 省份名称
     * @param d_city     城市名称
     * @return
     */
    public WlyyExpressagePriceDO getSFExpressPrice(String d_province, String d_city) throws Exception{
        String end_address_name = "";
        if("厦门市".equals(d_city)){
            end_address_name = "同城";
        }else{
            if("福建省".equals(d_province)){
                end_address_name = "省内";
            }else{
                end_address_name = d_province;
            }
        }
        end_address_name = "%"+end_address_name.replaceAll("省","").replaceAll("市","")+"%";
        WlyyExpressagePriceDO sfprice =  expressagePriceDao.getExprePriceByIdAndEndAdressName("shunfeng",end_address_name);
        return sfprice;
    }
    /**
     * 根据处方快递订单号判断是否下单成功
     * 如果下单成功,保存处方物流记录,保存配送日志
     * @param sfexpress_obj
     * @return
     * @throws Exception
     */
    public boolean sfOrderSearchService(WlyyPrescriptionExpressageDO sfexpress_obj)  throws Exception{
        boolean go_on = false;
        String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getId(),sf_code);
        String re = this.SFExpressPost(xml);
        try {
            //xml验证
            verificationResponXml(re,"订单处理失败!");
            Document doc = DocumentHelper.parseText(re);
            String headvalue = doc.selectSingleNode("/Response/Head").getText();
            if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
                //是否能派送:1:人工确认;2:可收派;3:不可以收派
                String filter_result = "";
                String orderid = "";//业务订单号
                String mailno = "";//顺丰运单号
                String destCode = "";//目的地区域代码
                //错误代对应的文字
                Document redoc = doc.selectSingleNode("/Response/Body/Orderresponse").getDocument();
                Element root = redoc.getRootElement();
                List<?> child = root.elements();
                for (Object o : child) {
                    Element e = (Element) o;
                    filter_result = e.attributeValue("filter_result");
                    orderid = e.attributeValue("orderid");
                    mailno = e.attributeValue("mailno");
                    destCode = e.attributeValue("destCode");
                }
                if(StringUtils.isBlank(mailno)){
                    logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getOutpatientId());
                    return true;
                }
                if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
                    logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
                    return true;
                }
                sfexpress_obj.setMailno(mailno);
                sfexpress_obj.setCityCode(destCode);
            }
            //如果成功获取到快递单号,则保存处方物流记录,保存配送日志
            //修改处方状态为配送中
            prescriptionDao.updateStatus(sfexpress_obj.getOutpatientId(),65);
            //保存处方物流记录
            prescriptionExpressageDao.save(sfexpress_obj);
            //保存配送日志
            WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
            outpatiExpressLog.setOutpatientId(sfexpress_obj.getOutpatientId());
            outpatiExpressLog.setId(UUID.randomUUID().toString());
            outpatiExpressLog.setType(8);
            outpatiExpressLog.setCreateTime(new Date());
            outpatiExpressLog.setFlag(1);
            outpatiExpressLog.setStatus(100);
            outpatientExpressageLogDao.save(outpatiExpressLog);
        }catch (Exception ex){
            logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
            //如果订单处理失败,则可以继续下单
            go_on = true;
        }
        return go_on;
    }
    public boolean sfOrderSearchServiceJustSearch(WlyyPrescriptionExpressageDO sfexpress_obj)  throws Exception{
        String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getId(),sf_code);
        String re = this.SFExpressPost(xml);
        boolean reslut = false;
        try {
            //xml验证
            verificationResponXml(re,"订单处理失败!");
            Document doc = DocumentHelper.parseText(re);
            String headvalue = doc.selectSingleNode("/Response/Head").getText();
            if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
                Element root = doc.getRootElement();
                if (root.element("Body") != null)     //包含OrderResponse节点
                {
                    root = root.element("Body");
                }
                //是否能派送:1:人工确认;2:可收派;3:不可以收派
                String filter_result = "";
                String orderid = "";//业务订单号
                String mailno = "";//顺丰运单号
                List<?> child = root.elements();
                for (Object o : child) {
                    Element e = (Element) o;
                    filter_result = e.attributeValue("filter_result");
                    orderid = e.attributeValue("orderid");
                    mailno = e.attributeValue("mailno");
                }
                if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
                    logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
                    throw new Exception("顺丰快递下订单失败:派送地址不可派送");
                }
                if(StringUtils.isBlank(mailno)){
                    logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getOutpatientId());
                    throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
                }
            }
        }catch (Exception ex){
            logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
            //如果订单处理失败,则可以继续下单
            throw new Exception(ex.getMessage());
        }
        return reslut;
    }
    public String getRoutInfosSearch(WlyyPrescriptionExpressageDO sfexpress_obj)throws Exception {
        String xml = SFUtils.getRoutInfos(sfexpress_obj,sf_code);
        String re = this.SFExpressPost(xml);
        return xml;
    }
}
//package com.yihu.jw.hospital.prescription.service;
//
//import com.yihu.jw.entity.base.org.BaseOrgDO;
//import com.yihu.jw.entity.hospital.prescription.*;
//import com.yihu.jw.hospital.prescription.dao.*;
//import com.yihu.jw.hospital.prescription.service.entrance.util.SFUtils;
//import com.yihu.jw.org.dao.BaseOrgDao;
//import com.yihu.jw.util.date.DateUtil;
//import com.yihu.jw.util.http.HttpClientKit;
//import com.yihu.mysql.query.BaseJpaService;
//import org.apache.commons.lang3.StringUtils;
//import org.apache.http.NameValuePair;
//import org.apache.http.message.BasicNameValuePair;
//import org.dom4j.Document;
//import org.dom4j.DocumentHelper;
//import org.dom4j.Element;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.TransactionDefinition;
//import org.springframework.transaction.TransactionStatus;
//import org.springframework.transaction.support.DefaultTransactionDefinition;
//
//import java.util.*;
//
///**
// *  门诊物流服务
// * lith 2019.06.04
// */
//
//@Service
//public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescriptionExpressageDO, PrescriptionExpressageDao> {
//    private static Logger logger = LoggerFactory.getLogger(PrescriptionExpressageService.class);
//
////    //顺丰快递接口请求地址
////    //@Value("${express.sf_url}")
////    private String sf_url;
////
////    //顺丰快递接口接入编码
////    //@Value("${express.sf_code}")
////    private String sf_code;
////
////    //顺丰快递接口checkword
////    //@Value("${express.sf_check_word}")
////    private String sf_check_word;
//
//    @Autowired
//    private SFUtils SFUtils;
//
//    @Autowired
//    private JpaTransactionManager transactionManager;
//
//    //处方日志
//    @Autowired
//    private WlyyOutpatientExpressageLogDao outpatientExpressageLogDao;
//
//    @Autowired
//    private PrescriptionDao prescriptionDao;
//
//    @Autowired
//    private WlyyExpressagePriceDao expressagePriceDao;
//
//    @Autowired
//    private PrescriptionExpressageLogDao prescriptionExpressageLogDao;
//
//    @Autowired
//    private PrescriptionExpressageDao prescriptionExpressageDao;
//
//    @Autowired
//    private BaseOrgDao baseOrgDao;
//
//
//    /**
//     * 组装请求参数,发送请求
//     * @param xml
//     * @return
//     * @throws Exception
//     */
//    private String SFExpressPost(String xml)throws Exception{
//        String verifyCode = SFUtils.verifyCodeSFXmlStr(xml,sf_check_word);
//        List<NameValuePair> params = new ArrayList<>();
//        params.add(new BasicNameValuePair("xml", xml));
//        params.add(new BasicNameValuePair("verifyCode", verifyCode));
//        String re = HttpClientKit.post(sf_url, params, "UTF-8");
//        return re;
//    }
//
//    /**
//     * 校验返回的xml报文
//     * @param responseXml
//     * @param title
//     */
//    private void verificationResponXml(String responseXml,String title) throws Exception {
//        String error = "";
//        if (StringUtils.isBlank(responseXml)) {
//            // 如果返回的XML报文为空,请求也算失败
//            //保存http日志
//            error = title + ",返回的XML为空!";
//            logger.info(error);
//            throw new Exception(error);
//        }else{
////          报错的报文示例<Response service="ScopeService"><Head>ERR</Head><ERROR code="8014">校验码错误 </ERROR></Response>
//            Document doc = DocumentHelper.parseText(responseXml);
//            String headvalue = doc.selectSingleNode("/Response/Head").getText();
//            if(StringUtils.isNotBlank(headvalue) && "ERR".equals(headvalue)){
//                //错误代码
//                String errorCode = "";
//                //错误代对应的文字
//                String errorMessage = doc.selectSingleNode("/Response/ERROR").getText();
//                Document error_doc = doc.selectSingleNode("/Response/ERROR").getDocument();
//                Element root = error_doc.getRootElement();
//                List<?> child = root.elements();
//                for (Object o : child){
//                    Element e = (Element) o;
//                    errorCode = e.attributeValue("code");
//                }
//                error = title+","+errorCode+","+errorMessage;
//                logger.info(error);
//                throw new Exception(error);
//            }
//        }
//    }
//
//
//    /**
//     * 查询派送地址是否属于顺丰的派送范围
//     * @param d_address 派送地址
//     * @return
//     */
//    public Boolean getSFOrderFilterService(String d_address) throws Exception {
//
//        boolean result = false;
//
//        String xml = SFUtils.getSFOrderFilterXml(d_address,sf_code,"","","","");
//
//        String re = this.SFExpressPost(xml);
//
////        String re = "<Response service=\"OrderFilterService\"><Head>OK</Head><Body><OrderFilterResponse orderid=\"TE201407020016\" filter_result=\"2\" origincode=\"755\" remark=\"2\"/></Body></Response>";
//
//        //xml验证
//        verificationResponXml(re,"查询派送地址是否有效失败!");
//
//
//        Document doc = DocumentHelper.parseText(re);
//        String headvalue = doc.selectSingleNode("/Response/Head").getText();
//        Element root = doc.getRootElement();
//        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
//            //是否能派送:1:人工确认;2:可收派;3:不可以收派
//            String filter_result = "";
//
//            Element firstWorldElement = root.element("Body");
//
//            List<Element> elements = firstWorldElement.elements();
//
//            for (Element o : elements){
//                filter_result = o.attributeValue("filter_result");
//            }
//
//            if(StringUtils.isNotBlank(filter_result) && "2".equals(filter_result)){
//                result = true;
//            }
//        }
//        return result;
//
//
//    }
//
//    /**
//     * 向顺丰快递下订单
//     * @param sfexpress_obj
//     * @return
//     * @throws Exception
//     */
//    public WlyyPrescriptionExpressageDO postSFOrderService(WlyyPrescriptionExpressageDO sfexpress_obj) throws Exception {
//
//        //获取医生所处的医院详细地址,作为寄件人地址
//        WlyyPrescriptionDO prescription = prescriptionDao.findOne(sfexpress_obj.getOutpatientId());
//        BaseOrgDO hospital = baseOrgDao.findByCode(prescription.getHospital());
//
//        String xml = SFUtils.postSFOrderService(sfexpress_obj,hospital,sf_code);
//        logger.info("顺丰快递下订单:xml"+xml);
//        String re = this.SFExpressPost(xml);
////        String re = "<Response service=\"OrderService\"><Head>OK</Head><Body><OrderResponse filter_result=\"2\" destcode=\"592\" mailno=\"444844978335\" origincode=\"592\" orderid=\"6daa6baec5fd4b65a1b023a8b60e2e91\"/></Body></Response>";
//
//        //xml验证
//        logger.info("顺丰快递下订单:re"+re);
//        verificationResponXml(re,"向顺丰快递下订单失败!");
//
//        Document doc = DocumentHelper.parseText(re);
//        String headvalue = doc.selectSingleNode("/Response/Head").getText();
//        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
//            Element root = doc.getRootElement();
//            if (root.element("Body") != null)     //包含OrderResponse节点
//            {
//                root = root.element("Body");
//            }
//
//            //是否能派送:1:人工确认;2:可收派;3:不可以收派
//            String filter_result = "";
//            String orderid = "";//业务订单号
//            String mailno = "";//顺丰运单号
//            String destCode = "";//目的地区域代码
//            List<?> child = root.elements();
//            for (Object o : child) {
//                Element e = (Element) o;
//                filter_result = e.attributeValue("filter_result");
//                orderid = e.attributeValue("orderid");
//                mailno = e.attributeValue("mailno");
//                destCode = e.attributeValue("destcode");
//            }
//            if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
//                logger.info("顺丰快递下订单失败:派送地址不可派送,门诊编号:"+sfexpress_obj.getOutpatientId());
//                throw new Exception("顺丰快递下订单失败:派送地址不可派送");
//            }
//
//            if(StringUtils.isBlank(mailno)){
//                logger.info("顺丰快递下订单失败:未获取到快递单号!门诊编号:"+sfexpress_obj.getOutpatientId());
//                throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
//            }
//            sfexpress_obj.setMailno(mailno);
//            sfexpress_obj.setCityCode(destCode);
//        }
//        return sfexpress_obj;
//    }
//
//
//    /**
//     * 调用顺丰接口获取物流路由日志,与本地匹配,进行增量修改,并返回完整日志列表
//     * @param prescription
//     * @param sfexpress_obj
//     * @param sfexpresslogList
//     * @return
//     */
//    public List<WlyyPrescriptionExpressageLogDO> getRoutInfos(WlyyPrescriptionDO prescription, WlyyPrescriptionExpressageDO sfexpress_obj, List<WlyyPrescriptionExpressageLogDO> sfexpresslogList) throws Exception {
//        String xml = SFUtils.getRoutInfos(sfexpress_obj,sf_code);
//        String re = this.SFExpressPost(xml);
//        //xml验证
//        verificationResponXml(re,"查询顺丰快递路由信息失败!");
//        Document doc = DocumentHelper.parseText(re);
//        String headvalue = doc.selectSingleNode("/Response/Head").getText();
//        if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
//            Element root = doc.getRootElement();
//            if (root.element("Body") != null)     //取报文根节点
//            {
//                root = root.element("Body");
//            }
//            List<?> child = root.elements();
//            String mailno = "";
//            Map<String,List<WlyyPrescriptionExpressageLogDO>> wayroutlsit = new HashMap<>();
//            for (Object o : child) {
//                Element e = (Element) o;
//                mailno = e.attributeValue("mailno");
//                //判断快递单号不为空,且和我们本地的一致
//                if(StringUtils.isNotBlank(mailno) &&
//                        sfexpress_obj.getMailno().equals(mailno)){
//
//                    //解析报文,结合本地数据返回最终的日志结果
//                    return this.xmltologlist(e,sfexpresslogList,sfexpress_obj);
//                }else{
//                    continue;
//                }
//            }
//        }
//        return null;
//    }
//
//    private List<WlyyPrescriptionExpressageLogDO> xmltologlist(Element e, List<WlyyPrescriptionExpressageLogDO> sfexpresslogList, WlyyPrescriptionExpressageDO sfexpress_obj)throws Exception{
//
//        //获取本地所有路由信息的时间集
//        Set<String> routAcceptTimeSet = new HashSet<>();
//        for (WlyyPrescriptionExpressageLogDO log: sfexpresslogList) {
//            routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
//        }
//
//        List<?> child = e.elements();
//
//        List<WlyyPrescriptionExpressageLogDO> newroutinfolist = new ArrayList<>();
//
//        //用于判断新节点是否包含了"已收件"的节点
//        boolean isContainEndRoutInfo = false;
//
//        for (Object o : child) {
//            Element routinfoe = (Element) o;
//            String accept_time = routinfoe.attributeValue("accept_time");
//            String accept_address = routinfoe.attributeValue("accept_address");
//            String accept_remark = routinfoe.attributeValue("remark");
//            String opcode = routinfoe.attributeValue("opcode");
//
//            //和时间集作比对,过滤已存在的
//            if(!routAcceptTimeSet.contains(accept_time)){
//                WlyyPrescriptionExpressageLogDO newlogobj = new WlyyPrescriptionExpressageLogDO();
//                newlogobj.setAcceptTime(DateUtil.strToDate(accept_time));
//                newlogobj.setAcceptAddress(accept_address);
//                newlogobj.setAcceptRemark(accept_remark);
//                newlogobj.setOpCode(opcode);
//                newlogobj.setId(UUID.randomUUID().toString().replace("-",""));
//                newlogobj.setOutpatientId(sfexpress_obj.getOutpatientId());
//                newlogobj.setExpressageId(sfexpress_obj.getId());
//                newlogobj.setCreateTime(new Date());
//                newroutinfolist.add(newlogobj);
//                sfexpresslogList.add(newlogobj);
//                //aopcode=80,为已签收
//                if("80".equals(opcode)){
//                    isContainEndRoutInfo = true;
//                }
//            }
//        }
//
//
//        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事物隔离级别,开启新事务
//        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
//        try {
//
//            //如果有新增的路由信息,则添加到数据库
//            if(!newroutinfolist.isEmpty()){
//                prescriptionExpressageLogDao.save(newroutinfolist);
//            }
//
//            //如果路由信息节点包含了"已收件"节点,这修改处方派送状态为完成,增加物流派送日志为完成
//            if(isContainEndRoutInfo){
//                //修改处方状态为完成
//                prescriptionDao.updateStatus(sfexpress_obj.getId(), 100,new Date());
//
//                //保存门诊处方配送成功的日志
//                WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
//                outpatiExpressLog.setOutpatientId(sfexpress_obj.getOutpatientId());
//                outpatiExpressLog.setId(UUID.randomUUID().toString());
//                outpatiExpressLog.setType(8);
//                outpatiExpressLog.setCreateTime(new Date());
//                outpatiExpressLog.setFlag(1);
//                outpatiExpressLog.setStatus(100);
//                outpatientExpressageLogDao.save(outpatiExpressLog);
//            }
//
//            //事务提交
//            transactionManager.commit(status);
//        } catch (Exception ex) {
//            //报错事务回滚
//            transactionManager.rollback(status);
//        }
//
//
//        return sfexpresslogList;
//    }
//
//    /**
//     * 解析顺丰推送过来的路由信息,和本地数据匹配并进行增量更新)
//     * @param xml
//     * @return
//     * @throws Exception
//     */
//    public void SFRoutePushService(String xml) throws Exception{
//        Document doc = DocumentHelper.parseText(xml);
//        Element root = doc.getRootElement();
//        if (root.element("Body") != null)     //包含WaybillRoute节点
//        {
//            root = root.element("Body");
//        }
//        List<?> child = root.elements();
//
//        Map<String,List<WlyyPrescriptionExpressageLogDO>> wayroutlsit = new HashMap<>();
//        for (Object o : child) {
//            Element routinfoe = (Element) o;
//            WlyyPrescriptionExpressageLogDO sflog = new WlyyPrescriptionExpressageLogDO();
//            String accept_time = routinfoe.attributeValue("accepttime");
//            String accept_address = routinfoe.attributeValue("acceptaddress");
//            String accept_remark = routinfoe.attributeValue("remark");
//            String opcode = routinfoe.attributeValue("opcode");
//            String mailno = routinfoe.attributeValue("mailno");
//            String orderid = routinfoe.attributeValue("orderid");
//
//            sflog.setAcceptTime(DateUtil.strToDate(accept_time));
//            sflog.setAcceptAddress(accept_address);
//            sflog.setAcceptRemark(accept_remark);
//            sflog.setOpCode(opcode);
//            sflog.setExpressageId(orderid);
//            sflog.setId(UUID.randomUUID().toString());
//            sflog.setCreateTime(new Date());
//            if(wayroutlsit.keySet().contains(mailno)){
//                wayroutlsit.get(mailno).add(sflog);
//            }else{
//                List<WlyyPrescriptionExpressageLogDO> newsflogs = new ArrayList<>();
//                newsflogs.add(sflog);
//                wayroutlsit.put(mailno,newsflogs);
//            }
//        }
//
//        if(!wayroutlsit.keySet().isEmpty()){
//            for (String mailno:wayroutlsit.keySet()) {
//                List<WlyyPrescriptionExpressageLogDO> pushSFLogs = wayroutlsit.get(mailno);
//                //同一个快递单号的执行一个事务操作
//                this.saveSFPushRoutInfos(mailno,pushSFLogs);
//            }
//        }
//    }
//
//    /**
//     * 同一个快递单号的执行一个事务操作
//     * @param mailno
//     * @param pushSFLogs
//     */
//    public void saveSFPushRoutInfos(String mailno,List<WlyyPrescriptionExpressageLogDO> pushSFLogs){
//
//        //根据快递单号获取处方配送详细信息
//        WlyyPrescriptionExpressageDO sfexpress = prescriptionExpressageDao.findByPrescriptionExpressMailno(mailno);
//        //根据快递单号获取本地的路由信息
//        List<WlyyPrescriptionExpressageLogDO> localroutinfos = prescriptionExpressageLogDao.queryByOutpatientId(sfexpress.getOutpatientId());
//        //需要增量更新到本地的路由信息集合
//        List<WlyyPrescriptionExpressageLogDO> newroutinfolist = new ArrayList<>();
//
//        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
//        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); // 事务隔离级别,开启新事务
//        TransactionStatus status = transactionManager.getTransaction(def); // 获得事务状态
//        try {
//
//            //用于判断新节点是否包含了"已收件"的节点
//            boolean isContainEndRoutInfo = false;
//
//            //获取本地所有路由信息的时间集
//            Set<String> routAcceptTimeSet = new HashSet<>();
//            for (WlyyPrescriptionExpressageLogDO log: localroutinfos) {
//                routAcceptTimeSet.add(DateUtil.dateToStrLong(log.getAcceptTime()));
//            }
//
//            for (WlyyPrescriptionExpressageLogDO pushlog: pushSFLogs) {
//
//                //判断是否有已收件的路由节点
//                if("80".equals(pushlog.getOpCode())){
//                    isContainEndRoutInfo = true;
//                }
//
//                if(routAcceptTimeSet.contains(DateUtil.dateToStrLong(pushlog.getAcceptTime()))){
//                    continue;
//                }else{
//                    pushlog.setOutpatientId(sfexpress.getOutpatientId());
//                    newroutinfolist.add(pushlog);
//                }
//            }
//
//            //如果有新增的路由信息,则添加到数据库
//            if(!newroutinfolist.isEmpty()){
//                prescriptionExpressageLogDao.save(newroutinfolist);
//            }
//
//            //如果路由信息节点包含了"已收件"节点,则修改处方状态为完成,增加物流派送日志为完成
//            if(isContainEndRoutInfo){
//                //修改处方状态为完成
//                prescriptionDao.updateStatus(sfexpress.getOutpatientId(), 100,new Date());
//
//                //保存配送成功的日志
//                WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
//                outpatiExpressLog.setOutpatientId(sfexpress.getOutpatientId());
//                outpatiExpressLog.setId(UUID.randomUUID().toString());
//                outpatiExpressLog.setType(8);
//                outpatiExpressLog.setCreateTime(new Date());
//                outpatiExpressLog.setFlag(1);
//                outpatiExpressLog.setStatus(100);
//                outpatientExpressageLogDao.save(outpatiExpressLog);
//            }
//            //事务提交
//            transactionManager.commit(status);
//        } catch (Exception ex) {
//            //报错事务回滚
//            transactionManager.rollback(status);
//        }
//
//
//    }
//
//    /**
//     * 根据收寄地址获取快递费用
//     * @param d_province 省份名称
//     * @param d_city     城市名称
//     * @return
//     */
//    public WlyyExpressagePriceDO getSFExpressPrice(String d_province, String d_city) throws Exception{
//        String end_address_name = "";
//
//        if("厦门市".equals(d_city)){
//            end_address_name = "同城";
//        }else{
//            if("福建省".equals(d_province)){
//                end_address_name = "省内";
//            }else{
//                end_address_name = d_province;
//            }
//        }
//        end_address_name = "%"+end_address_name.replaceAll("省","").replaceAll("市","")+"%";
//        WlyyExpressagePriceDO sfprice =  expressagePriceDao.getExprePriceByIdAndEndAdressName("shunfeng",end_address_name);
//        return sfprice;
//    }
//
//    /**
//     * 根据处方快递订单号判断是否下单成功
//     * 如果下单成功,保存处方物流记录,保存配送日志
//     * @param sfexpress_obj
//     * @return
//     * @throws Exception
//     */
//    public boolean sfOrderSearchService(WlyyPrescriptionExpressageDO sfexpress_obj)  throws Exception{
//
//        boolean go_on = false;
//
//        String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getId(),sf_code);
//        String re = this.SFExpressPost(xml);
//
//        try {
//            //xml验证
//            verificationResponXml(re,"订单处理失败!");
//
//            Document doc = DocumentHelper.parseText(re);
//            String headvalue = doc.selectSingleNode("/Response/Head").getText();
//            if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
//                //是否能派送:1:人工确认;2:可收派;3:不可以收派
//                String filter_result = "";
//                String orderid = "";//业务订单号
//                String mailno = "";//顺丰运单号
//                String destCode = "";//目的地区域代码
//
//                //错误代对应的文字
//                Document redoc = doc.selectSingleNode("/Response/Body/Orderresponse").getDocument();
//                Element root = redoc.getRootElement();
//                List<?> child = root.elements();
//                for (Object o : child) {
//                    Element e = (Element) o;
//                    filter_result = e.attributeValue("filter_result");
//                    orderid = e.attributeValue("orderid");
//                    mailno = e.attributeValue("mailno");
//                    destCode = e.attributeValue("destCode");
//                }
//
//                if(StringUtils.isBlank(mailno)){
//                    logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getOutpatientId());
//                    return true;
//                }
//
//                if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
//                    logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
//                    return true;
//                }
//
//                sfexpress_obj.setMailno(mailno);
//                sfexpress_obj.setCityCode(destCode);
//            }
//
//            //如果成功获取到快递单号,则保存处方物流记录,保存配送日志
//            //修改处方状态为配送中
//            prescriptionDao.updateStatus(sfexpress_obj.getOutpatientId(),65);
//
//            //保存处方物流记录
//            prescriptionExpressageDao.save(sfexpress_obj);
//
//            //保存配送日志
//            WlyyOutpatientExpressageLogDO outpatiExpressLog = new WlyyOutpatientExpressageLogDO();
//            outpatiExpressLog.setOutpatientId(sfexpress_obj.getOutpatientId());
//            outpatiExpressLog.setId(UUID.randomUUID().toString());
//            outpatiExpressLog.setType(8);
//            outpatiExpressLog.setCreateTime(new Date());
//            outpatiExpressLog.setFlag(1);
//            outpatiExpressLog.setStatus(100);
//            outpatientExpressageLogDao.save(outpatiExpressLog);
//
//
//        }catch (Exception ex){
//            logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
//            //如果订单处理失败,则可以继续下单
//            go_on = true;
//        }
//
//        return go_on;
//
//    }
//
//    public boolean sfOrderSearchServiceJustSearch(WlyyPrescriptionExpressageDO sfexpress_obj)  throws Exception{
//
//        String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getId(),sf_code);
//        String re = this.SFExpressPost(xml);
//
//        boolean reslut = false;
//
//        try {
//            //xml验证
//            verificationResponXml(re,"订单处理失败!");
//
//            Document doc = DocumentHelper.parseText(re);
//            String headvalue = doc.selectSingleNode("/Response/Head").getText();
//            if(StringUtils.isNotBlank(headvalue) && "OK".equals(headvalue)) {
//                Element root = doc.getRootElement();
//                if (root.element("Body") != null)     //包含OrderResponse节点
//                {
//                    root = root.element("Body");
//                }
//
//                //是否能派送:1:人工确认;2:可收派;3:不可以收派
//                String filter_result = "";
//                String orderid = "";//业务订单号
//                String mailno = "";//顺丰运单号
//                List<?> child = root.elements();
//                for (Object o : child) {
//                    Element e = (Element) o;
//                    filter_result = e.attributeValue("filter_result");
//                    orderid = e.attributeValue("orderid");
//                    mailno = e.attributeValue("mailno");
//                }
//                if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
//                    logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
//                    throw new Exception("顺丰快递下订单失败:派送地址不可派送");
//                }
//
//                if(StringUtils.isBlank(mailno)){
//                    logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getOutpatientId());
//                    throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
//                }
//            }
//
//
//
//        }catch (Exception ex){
//            logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getOutpatientId());
//            //如果订单处理失败,则可以继续下单
//            throw new Exception(ex.getMessage());
//        }
//
//        return reslut;
//    }
//
//    public String getRoutInfosSearch(WlyyPrescriptionExpressageDO sfexpress_obj)throws Exception {
//        String xml = SFUtils.getRoutInfos(sfexpress_obj,sf_code);
//        String re = this.SFExpressPost(xml);
//
//        return xml;
//    }
//
//}

+ 11 - 2
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -185,6 +185,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " o.origin_adm_no AS originAdmNo, " +
                " o.register_no AS registerNo, " +
                " o.origin_register_no AS originRegisterNo, " +
                " o.hos" +
                " o.dept AS dept, " +
                " o.dept_name AS deptName, " +
                " o.patient AS patient, " +
@ -434,13 +435,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    public Boolean appointmentRevisit(String outpatientJson,String expressageJson)throws Exception{
        //1.保存就诊实体
        WlyyOutpatientDO outpatientDO = objectMapper.readValue(outpatientJson,WlyyOutpatientDO.class);
        BasePatientDO patientDO = basePatientDao.findById(outpatientDO.getPatient());
        outpatientDO.setMjz("mz");
        outpatientDO.setStatus("0");
        outpatientDO.setCreateTime(new Date());
        outpatientDO.setIdcard(patientDO.getIdcard());
        outpatientDO.setCreateTime(new Date());
        WlyyOutpatientDO outpatient = outpatientDao.save(outpatientDO);
        //2.物流信息
        BasePatientDO patientDO = basePatientDao.findById(outpatient.getPatient());
        WlyyPrescriptionExpressageDO expressageDO = objectMapper.readValue(expressageJson,WlyyPrescriptionExpressageDO.class);
        expressageDO.setDel(1);
        expressageDO.setCreateTime(new Date());
@ -570,7 +577,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @throws Exception
     */
    public JSONArray findPatientCard(String patient)throws Exception{
        return entranceService.BS15018(null,patient,demoFlag);
        BasePatientDO patientDO = basePatientDao.findById(patient);
        return entranceService.BS15018(patientDO.getIdcard(),null,demoFlag);
    }
@ -635,4 +643,5 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return list;
    }
    public JSONArray find
}

+ 15 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/base/dict/DictHospitalDeptDO.java

@ -2,6 +2,8 @@ package com.yihu.jw.entity.base.dict;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IntegerIdentityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
@ -39,6 +41,12 @@ public class DictHospitalDeptDO extends IntegerIdentityEntity {
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	private Date createTime;
    /**
     * 6总部7金榜8夏禾
     */
    @Autowired
    private String deptTypeCode;
	@Column(name = "org_code")
    public String getOrgCode() {
@ -72,6 +80,12 @@ public class DictHospitalDeptDO extends IntegerIdentityEntity {
        this.createTime = createTime;
    }
    @Column(name = "dept_type_code")
    public String getDeptTypeCode() {
        return deptTypeCode;
    }
    public void setDeptTypeCode(String deptTypeCode) {
        this.deptTypeCode = deptTypeCode;
    }
}

+ 6 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java

@ -70,6 +70,12 @@ public class BaseHospitalRequestMapping {
         */
        public static final String findDeptByHospital ="/findDeptByHospital";
        /**
         * 查询部门下医生
         */
        public static final String findDoctorByHospitalAndDept = "/findDoctorByHospitalAndDept";
        //=================end=======================================
        /**

+ 9 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/dict/DictHospitalDeptVO.java

@ -47,6 +47,9 @@ public class DictHospitalDeptVO extends IntegerIdentityVO{
	@ApiModelProperty(value = "创建时间", example = "yyyy-MM-dd HH:mm:ss/该字段可不填")
    private Date createTime;
    @ApiModelProperty(value = "6总部7金榜8夏禾", example = "神经内科")
    private String deptTypeCode;
    public String getOrgCode() {
        return orgCode;
@ -76,5 +79,11 @@ public class DictHospitalDeptVO extends IntegerIdentityVO{
        this.createTime = createTime;
    }
    public String getDeptTypeCode() {
        return deptTypeCode;
    }
    public void setDeptTypeCode(String deptTypeCode) {
        this.deptTypeCode = deptTypeCode;
    }
}

+ 79 - 79
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/expressage/ExpressageEndpoint.java

@ -1,79 +1,79 @@
package com.yihu.jw.entrance.controller.expressage;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
import com.yihu.jw.hospital.prescription.service.PrescriptionExpressageService;
import com.yihu.jw.hospital.prescription.service.PrescriptionService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.net.URLDecoder;
import java.util.List;
@RestController
@RequestMapping(value = BaseHospitalRequestMapping.Expressage.PREFIX)
@Api(value = "门诊处方快递物流管理器", description = "门诊处方快递物流管理器", tags = {"wlyy基础服务 - 门诊处方快递物流管理服务接口"})
public class ExpressageEndpoint extends EnvelopRestEndpoint {
    private static Logger logger = LoggerFactory.getLogger(ExpressageEndpoint.class);
    @Autowired
    private PrescriptionExpressageService sfexpressService;
    @Autowired
    private PrescriptionExpressageService prescriptionExpressageService;
    private String successxml = "<Response service='RoutePushService'><Head>OK</Head></Response>";
    private String failedxml = "<Response service='RoutePushService'><Head>ERR</Head><ERROR code='-1'>系统发生数据错误或运行时异常</ERROR></Response>";
    @RequestMapping(value="/routepushservice",method = RequestMethod.POST)
    @ApiOperation("接受顺丰推送过来的路由信息")
    public Envelop SFRoutePushService (
            @ApiParam(name="content", value="入参报文") @RequestParam(value = "content",required = true) String content){
        try {
            content = URLDecoder.decode(content,"utf-8");
            logger.info("顺丰路由信息推送,xml="+content);
            sfexpressService.SFRoutePushService(content);
            return success(successxml);
        }catch (Exception e){
            logger.error("接收顺丰路由信息推送失败,入参xml:"+content);
            //日志文件中记录异常信息
            //返回接口异常信息处理结果
            return failed(failedxml);
        }
    }
    @RequestMapping(value="/sfrouteserviceSearch",method = RequestMethod.GET)
    @ApiOperation("通过门诊编号查询顺丰物流派送记录")
    public Envelop SFRouteServiceSearch(@ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
        try {
            List<WlyyPrescriptionExpressageDO> expressageDOList = prescriptionExpressageService.findByField("outpatientId",outpatientId);
            if(CollectionUtils.isEmpty(expressageDOList)){
                return failed("当前门诊没有物流信息!");
            }
            WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
            String result  = sfexpressService.getRoutInfosSearch(sfexpress_obj);
            return success(result);
        }catch (Exception e){
            //日志文件中记录异常信息
            //返回接口异常信息处理结果
            return failed( "查询失败,"+e.getMessage());
        }
    }
}
//package com.yihu.jw.entrance.controller.expressage;
//
//import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
//import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
//import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
//import com.yihu.jw.hospital.prescription.service.PrescriptionExpressageService;
//import com.yihu.jw.hospital.prescription.service.PrescriptionService;
//import com.yihu.jw.restmodel.web.Envelop;
//import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
//import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.util.CollectionUtils;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.net.URLDecoder;
//import java.util.List;
//
//@RestController
//@RequestMapping(value = BaseHospitalRequestMapping.Expressage.PREFIX)
//@Api(value = "门诊处方快递物流管理器", description = "门诊处方快递物流管理器", tags = {"wlyy基础服务 - 门诊处方快递物流管理服务接口"})
//public class ExpressageEndpoint extends EnvelopRestEndpoint {
//    private static Logger logger = LoggerFactory.getLogger(ExpressageEndpoint.class);
//
//    @Autowired
//    private PrescriptionExpressageService sfexpressService;
//
//    @Autowired
//    private PrescriptionExpressageService prescriptionExpressageService;
//
//    private String successxml = "<Response service='RoutePushService'><Head>OK</Head></Response>";
//    private String failedxml = "<Response service='RoutePushService'><Head>ERR</Head><ERROR code='-1'>系统发生数据错误或运行时异常</ERROR></Response>";
//
//    @RequestMapping(value="/routepushservice",method = RequestMethod.POST)
//    @ApiOperation("接受顺丰推送过来的路由信息")
//    public Envelop SFRoutePushService (
//            @ApiParam(name="content", value="入参报文") @RequestParam(value = "content",required = true) String content){
//        try {
//            content = URLDecoder.decode(content,"utf-8");
//            logger.info("顺丰路由信息推送,xml="+content);
//            sfexpressService.SFRoutePushService(content);
//            return success(successxml);
//        }catch (Exception e){
//            logger.error("接收顺丰路由信息推送失败,入参xml:"+content);
//            //日志文件中记录异常信息
//            //返回接口异常信息处理结果
//            return failed(failedxml);
//        }
//    }
//
//    @RequestMapping(value="/sfrouteserviceSearch",method = RequestMethod.GET)
//    @ApiOperation("通过门诊编号查询顺丰物流派送记录")
//    public Envelop SFRouteServiceSearch(@ApiParam(name="outpatientId", value="门诊编号") @RequestParam(value = "outpatientId",required = true) String outpatientId){
//        try {
//            List<WlyyPrescriptionExpressageDO> expressageDOList = prescriptionExpressageService.findByField("outpatientId",outpatientId);
//            if(CollectionUtils.isEmpty(expressageDOList)){
//                return failed("当前门诊没有物流信息!");
//            }
//            WlyyPrescriptionExpressageDO sfexpress_obj = expressageDOList.get(0);
//            String result  = sfexpressService.getRoutInfosSearch(sfexpress_obj);
//            return success(result);
//        }catch (Exception e){
//            //日志文件中记录异常信息
//            //返回接口异常信息处理结果
//            return failed( "查询失败,"+e.getMessage());
//        }
//
//    }
//
//
//
//}

+ 7 - 10
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -17,10 +17,7 @@ import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@ -161,7 +158,7 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.findPatientCard)
    @ApiOperation(value = "查询患者就诊卡", notes = "查询患者就诊卡")
    public ListEnvelop findPatientCard(@ApiParam(name = "patient", value = "续方明细")
    public ListEnvelop findPatientCard(@ApiParam(name = "patient", value = "居民Code")
                                       @RequestParam(value = "patient", required = true)String patient)throws Exception {
        return success(prescriptionService.findPatientCard(patient));
    }
@ -186,8 +183,8 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
        return success(prescriptionService.findDeptByHospital(orgCode));
    }
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.findDeptByHospital)
    @ApiOperation(value = "查询机构底下部门", notes = "查询机构底下部门")
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.findDoctorByHospitalAndDept)
    @ApiOperation(value = "查询部门下医生", notes = "查询机构底下部门")
    public ListEnvelop findDoctorByHospitalAndDept(@ApiParam(name = "orgCode", value = "机构code")
                                                   @RequestParam(value = "orgCode", required = true)String orgCode,
                                                   @ApiParam(name = "dept", value = "部门code")
@ -195,12 +192,12 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
        return success(prescriptionService.findDoctorByHospitalAndDept(orgCode,dept));
    }
    @GetMapping(value = BaseHospitalRequestMapping.Prescription.appointmentRevisit)
    @PostMapping(value = BaseHospitalRequestMapping.Prescription.appointmentRevisit)
    @ApiOperation(value = "居民发起复诊", notes = "居民发起复诊")
    public ObjEnvelop appointmentRevisit(@ApiParam(name = "outpatientJson", value = "居民门诊json")
                                         @RequestParam(value = "outpatientJson", required = false)String outpatientJson,
                                         @ApiParam(name = "outpatientJson", value = "居民物流json")
                                         @RequestParam(value = "outpatientJson", required = false)String expressageJson)throws Exception {
                                         @ApiParam(name = "expressageJson", value = "居民物流json")
                                         @RequestParam(value = "expressageJson", required = false)String expressageJson)throws Exception {
        return success(BaseHospitalRequestMapping.Prescription.api_success,prescriptionService.appointmentRevisit(outpatientJson,expressageJson));
    }