瀏覽代碼

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 5 年之前
父節點
當前提交
edbbaf8b42

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

@ -1,12 +1,13 @@
package com.yihu.jw.hospital.prescription.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
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.patient.dao.BasePatientDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.sfutils.HttpClientUtils;
import com.yihu.jw.utils.sfutils.SHAUtils;
@ -19,6 +20,7 @@ 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;
@ -38,12 +40,15 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
    //顺丰快递接口请求地址
    @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
@ -73,6 +78,9 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
    @Autowired
    private OutpatientDao outpatientDao;
    
    @Autowired
    private BasePatientDao basePatientDao;
    @Autowired
    private SfConfigDao sfConfigDao;
@ -98,12 +106,12 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
//        params.add(new BasicNameValuePair("xml", xml));
//        params.add(new BasicNameValuePair("verifyCode", verifyCode));
    
        JSONObject j =  addOrder();
        j.put("xml",xml);
        j.put("verifyCode",verifyCode);
//        JSONObject j =  addOrder();
//        j.put("xml",xml);
//        j.put("verifyCode",verifyCode);
        
        String re = HttpClientUtils.doPost(sf_url, j.toJSONString(), ContentType.APPLICATION_JSON);
        return re;
//        String re = HttpClientUtils.doPost(sf_url, j.toJSONString(), ContentType.APPLICATION_JSON);
        return null;
    }
    /**
@ -197,56 +205,20 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
        //获取医生所处的医院详细地址,作为寄件人地址
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(sfexpress_obj.getOutpatientId());
        BaseOrgDO hospital = baseOrgDao.findByCode(outpatientDO.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>";
        BasePatientDO basePatientDO = basePatientDao.findById(outpatientDO.getPatient());
    
        JSONObject params = SFUtils.postSFOrderServiceV2(sfexpress_obj,hospital,basePatientDO);
        String re = this.SFExpressPostV2(params);
        //xml验证
        logger.info("顺丰快递下订单:re"+re);
        verificationResponXml(re,"向顺丰快递下订单失败!");
        verificationResponV2(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) && "1".equals(filter_result)){
                logger.info("顺丰快递下订单失败:派送地址需人工审核,门诊编号:"+sfexpress_obj.getOutpatientId());
                throw new Exception("顺丰快递下订单失败:派送地址需人工审核");
            }
        JSONObject respone = JSONObject.parseObject(re);
            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);
        }
        String mailno = "";//顺丰运单号
    
        mailno = respone.getJSONObject("result").getJSONArray("successResult").getJSONObject(0).getString("mailNo");
        sfexpress_obj.setMailno(mailno);
        return sfexpress_obj;
    }
@ -740,58 +712,53 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
        prescriptionLog.setFlag(1);
        outpatientExpressageLogDao.save(prescriptionLog);
    }
    public JSONObject addOrder(){
        String json = "{" +
                "    \"orderThirds\": [" +
                "        {" +
                "            \"bspOrderNo\": \"jkzltest05\"," +
                "            \"depositumInfo\": \"西瓜\"," +
                "            \"depositumNo\": \"3\"," +
                "            \"destAddress\": \"白石龙一区175栋\"," +
                "            \"destCity\": \"深圳市\"," +
                "            \"destDistrict\": \"龙华新区\"," +
                "            \"destName\": \"梁飞\"," +
                "            \"destPhone\": \"15986618684\"," +
                "            \"destProvince\": \"广东省\"," +
                "            \"expressType\": \"1\"," +
                "            \"hospitalCode\": \"\"," +
                "            \"monthlyCard\": \"\"," +
                "            \"orderDate\": 1561363194848," +
                "            \"packagesNo\": 1," +
                "            \"parcelWeighs\": \"10\"," +
                "            \"patientIdentityCardNo\": \"411081199102201259\"," +
                "            \"patientName\": \"佩奇\"," +
                "            \"patientPhone\": \"15113149999\"," +
                "            \"payMethod\": 1," +
                "            \"remark\": \"备注\"," +
                "            \"srcAddress\": \"中山大道\"," +
                "            \"srcCity\": \"上海市\"," +
                "            \"srcDistrict\": \"黄浦区\"," +
                "            \"srcName\": \"佩奇\"," +
                "            \"srcPhone\": \"15113149999\"," +
                "            \"productCode\": \"OTHER\"," +
                "            \"srcProvince\": \"上海市\"" +
                "        }" +
                "    ]" +
                " " +
                "}";
        JSONObject j = JSON.parseObject(json);
        return j;
    
    
    /**
     * 组装请求参数,发送请求
     * @param params
     * @return
     * @throws Exception
     */
    private String SFExpressPostV2(JSONObject params)throws Exception{
        params.put("version","1.0");
        params.put("timestamp",new Date().getTime());
        String sign = SHAUtils.SHA512(params.toJSONString()+sf_check_word);
        String url =sf_url+"/api/open/api/addOrder?hospitalCode="+sf_code+"&sign="+sign;
    
        logger.info("顺丰快递下订单:sf_url"+url);
        logger.info("顺丰快递下订单:params"+params.toString());
        
        
        String re = HttpClientUtils.doPost(url, params.toJSONString(), ContentType.APPLICATION_JSON);
        return re;
    }
    public void test()throws Exception{
        JSONObject j =  addOrder();
        j.put("version","1.0");
        j.put("timestamp",new Date());
        String sign = SHAUtils.SHA512(j.toJSONString()+"AAAABBBBCCCCDDDD");
        String hospitalCode = "HD000001";
        String url ="http://mrds-admin-ci.sit.sf-express.com:45478/api/open/api/addOrder?hospitalCode="+hospitalCode+"&sign="+sign;
        String rs = HttpClientUtils.doPost(url,j.toJSONString(), ContentType.APPLICATION_JSON);
        System.out.println(rs);
    
    /**
     * 校验返回的报文
     * @param response
     */
    private void verificationResponV2(String response) throws Exception {
        String error = "";
        if (StringUtils.isBlank(response)) {
            // 如果返回的XML报文为空,请求也算失败
            //保存http日志
            error = "返回的报文为空!";
            logger.info(error);
            throw new Exception(error);
        }else{
            JSONObject object = JSONObject.parseObject(response);
//          报错的报文示例<Response service="ScopeService"><Head>ERR</Head><ERROR code="8014">校验码错误 </ERROR></Response>
            Boolean success = object.getBoolean("success");
            String message = object.getString("message");
            if(StringUtils.isNotBlank(message) && !success){
                //错误代码
                String errorCode = object.getString("code");
                error = "顺丰快递接口请求失败:"+errorCode+","+message;
                logger.info(error);
                throw new Exception(error);
            }
        }
    }
//    public JSONObject addSFOrder(WlyyPrescriptionExpressageDO expressageDO){

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

@ -4234,33 +4234,50 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByAdmNo(admNo);
        
        Object result = "";
        
    
        System.out.println("获取顺丰物流面单信息:wlyyOutpatientDOs.isEmpty()="+wlyyOutpatientDOs.isEmpty());
        if(!wlyyOutpatientDOs.isEmpty() && wlyyOutpatientDOs.size()>0){
            List<WlyyPrescriptionExpressageDO> expressageDOList = sfexpressService.findByField("outpatientId",wlyyOutpatientDOs.get(0).getId());
            WlyyPrescriptionExpressageDO sfexpress_obj = null;
            System.out.println("获取顺丰物流面单信息:CollectionUtils.isEmpty(expressageDOList)="+CollectionUtils.isEmpty(expressageDOList));
            if(CollectionUtils.isEmpty(expressageDOList)){
                throw new Exception("顺丰快递下单失败,未找到该处方的派送地址!");
            }else{
                System.out.println("获取顺丰物流面单信息:1");
                sfexpress_obj = expressageDOList.get(0);
                System.out.println("获取顺丰物流面单信息:2");
                BasePatientDO basePatientDO = basePatientDao.findById(wlyyOutpatientDOs.get(0).getPatient());
                //如果该处方的快递单号已生成,则说明已经下单成功,不需要重复下单,直接返回面单信息
                System.out.println("获取顺丰物流面单信息:3");
                if(org.apache.commons.lang.StringUtils.isNotBlank(sfexpress_obj.getMailno())){
                    //处方已下单成功
                    System.out.println("获取顺丰物流面单信息:4");
                }else{
                    //如果该处方的快递单号未生成,则继续下单
                    //根据业务订单号判断是否已经下单成功
                    boolean go_on = sfexpressService.sfOrderSearchService(sfexpress_obj);
            
                    //如果该业务订单号未下单成功过,则重新下单
                    if(go_on){
                    //--2020.05.20--顺丰V2.0接口已不提供查询接口,直接单下单--START
//                    boolean go_on = sfexpressService.sfOrderSearchService(sfexpress_obj);
//
//                    //如果该业务订单号未下单成功过,则重新下单
//                    if(go_on){
//                        //请求顺丰接口下单,成功下单后,返回快递单号
//                        sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
//                        //保存快递单号和增加处方物流记录为配送
//                        sfexpressService.updatePrescriptionExpressage(sfexpress_obj);
//                    }
                    //--2020.05.20--顺丰V2.0接口已不提供查询接口,直接单下单--END
                        //请求顺丰接口下单,成功下单后,返回快递单号
                        sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
                        //保存快递单号和增加处方物流记录为配送
                        sfexpressService.updatePrescriptionExpressage(sfexpress_obj);
                    }
                    sfexpress_obj = sfexpressService.postSFOrderService(sfexpress_obj);
                    System.out.println("获取顺丰物流面单信息:5");
                    //保存快递单号和增加处方物流记录为配送
                    sfexpressService.updatePrescriptionExpressage(sfexpress_obj);
                    System.out.println("获取顺丰物流面单信息:6");
                    
                }
                
                if(sfexpress_obj != null && StringUtils.isNoneBlank(sfexpress_obj.getMailno())){
                    System.out.println("获取顺丰物流面单信息:7");
                    com.alibaba.fastjson.JSONObject sfJsonObject = new com.alibaba.fastjson.JSONObject();
    
                    sfJsonObject.put("mailno", sfexpress_obj.getMailno());
@ -4291,10 +4308,11 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    sfJsonObject.put("receive_time","");
                    sfJsonObject.put("dispensaryType",2);
                    result = sfJsonObject;
                    System.out.println("获取顺丰物流面单信息:8");
                }
            }
        }
        System.out.println("获取顺丰物流面单信息:9");
        return result;
    }
    

+ 66 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/util/SFUtils.java

@ -1,6 +1,9 @@
package com.yihu.jw.hospital.prescription.service.entrance.util;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionExpressageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
@ -18,6 +21,7 @@ import sun.misc.BASE64Encoder;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -107,7 +111,7 @@ public class SFUtils {
    /**
     * 向顺丰快递下订单
     * 向顺丰快递下订单--V1
     * @param sfexpress_obj
     * @param hospital
     * @return
@ -298,4 +302,65 @@ public class SFUtils {
    }
    //-----------顺丰快递验证码加密的相关方法------------------END
    
    
    
    /**
     * 组装顺丰快递下订单参数--V2
     * @param sfexpress_obj
     * @param hospital
     * @return
     */
    public JSONObject postSFOrderServiceV2(WlyyPrescriptionExpressageDO sfexpress_obj, BaseOrgDO hospital,  BasePatientDO basePatientDO) {
    
        JSONObject params = new JSONObject();//请求参数
        JSONArray orders = new JSONArray();//订单集合
        JSONObject order = new JSONObject();//单个订单
        order.put("bspOrderNo",sfexpress_obj.getId());
        order.put("payMethod",2);//付款方式到付
        order.put("expressType",1);//使用顺丰标快
        order.put("patientName",basePatientDO.getName());
        order.put("patientPhone",basePatientDO.getMobile());
        order.put("patientIdentityCardNo",basePatientDO.getIdcard());
    
        order.put("srcName",hospital.getName());
        order.put("srcPhone",hospital.getMobile());
        order.put("srcProvince",hospital.getProvinceName());
        order.put("srcCity",hospital.getCityName());
        order.put("srcDistrict",hospital.getTownName());
        order.put("srcAddress",hospital.getAddress());
        
        order.put("destName",sfexpress_obj.getName());
        order.put("destPhone",sfexpress_obj.getMobile());
        order.put("destProvince",sfexpress_obj.getProvinceName());
        order.put("destCity",sfexpress_obj.getCityName());
        order.put("destDistrict",sfexpress_obj.getTownName());
        order.put("destAddress",sfexpress_obj.getAddress());
        
        order.put("packagesNo",1);
        order.put("depositumInfo","药品");
        order.put("productCode","OTHER");
        
        //根据快递物流获取门诊信息,根据门诊信息获取处方订单的药品详情
        List<WlyyPrescriptionDO> prescriptionDOList = prescriptionService.findByField("outpatientId",sfexpress_obj.getOutpatientId());
        
        Set<String> prescriptionIdSet = new HashSet<>();
        prescriptionDOList.forEach(
                onePrescription -> {
                    prescriptionIdSet.add(onePrescription.getId());
                }
        );
        List<WlyyPrescriptionInfoDO> prescriptionInfolist = prescriptionInfoDao.queryAllByPrescriptionIdInAndDel(prescriptionIdSet,1);
        
        if(!prescriptionInfolist.isEmpty()){
            order.put("depositumNo",prescriptionInfolist.size());
        }else{
            order.put("depositumNo",1);
        }
        
        orders.add(order);
        params.put("orderThirds",orders);
        return params;
    }
}

File diff suppressed because it is too large
+ 1 - 0
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/third/PrescriptionUpdateController.java


+ 4 - 0
svr/svr-internet-hospital-entrance/src/main/resources/application.yml

@ -158,6 +158,10 @@ wlyy:
  url: http://www.xmtyw.cn/wlyytest/
wechat:
  id: xm_zsyy_wx  # base库中,wx_wechat 的id字段
express:
  sf_url: https://mrds-admin.sf-express.com:443
  sf_code: WH000102
  sf_check_word: TGUQASFNAZyjt9112
---

+ 4 - 2
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/expressage/ExpressageEndpoint.java

@ -79,7 +79,9 @@ public class ExpressageEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "d_address", required = true) String d_address){
        try {
            boolean result = sfexpressService.getSFOrderFilterService(d_address);
//            boolean result = sfexpressService.getSFOrderFilterService(d_address);
            //二代接口无查询是否可派送的接口,默认返回成功
            boolean result = true;
            if(result){
                return success("地址可派送!");
@ -185,7 +187,7 @@ public class ExpressageEndpoint extends EnvelopRestEndpoint {
    @ApiOperation("test")
    public Envelop test(String test){
        try {
            sfexpressService.test();
//            sfexpressService.test();
            return success("ok");
        }catch (Exception e) {
            return failed("异常," + e.getMessage());