Forráskód Böngészése

Merge branch 'dev' of huangwenjie/patient-co-management into dev

trick9191 7 éve
szülő
commit
21c1114cff

+ 14 - 4
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -1,9 +1,6 @@
package com.yihu.wlyy.event;
import com.yihu.wlyy.job.PrescriptionPayOverdueJob;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.SignAgainJob;
import com.yihu.wlyy.job.SignEndJob;
import com.yihu.wlyy.job.*;
import com.yihu.wlyy.job.consult.EvaluateScoreJob;
import com.yihu.wlyy.util.SystemConf;
import org.slf4j.Logger;
@ -59,6 +56,7 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
            } else {
                logger.info("prescription pay overdue job exist");
            }
            //启动发送产检提醒模板消息
//            if (!quartzHelper.isExistJob("prenatal_inspector_job")) {
//                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("prenatal_inspector_job_trigger");
@ -67,6 +65,18 @@ public class ApplicationEvent implements ApplicationListener<ContextRefreshedEve
//            } else {
//                logger.info("prenatal_inspector_job exist");
//            }
            //遍历支付成功,快递下单失败的记录,重新下单,10分钟跑一次
            if (!quartzHelper.isExistJob("sfexpress_reorder_job")) {
                String trigger = SystemConf.getInstance().getSystemProperties().getProperty("sfexpress_reorder_job");
                quartzHelper.addJob(SFExpressJob.class, trigger, "sfexpress_reorder_job", new HashMap<String, Object>());
                logger.info("sfexpress reorder job job success");
            } else {
                logger.info("sfexpress reorder job job exist");
            }
        } catch (Exception e) {
            logger.info("sign end job start failed");
        }

+ 54 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/job/SFExpressJob.java

@ -0,0 +1,54 @@
package com.yihu.wlyy.job;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.app.prescription.PrescriptionExpressageService;
import com.yihu.wlyy.service.app.prescription.PrescriptionInfoService;
import com.yihu.wlyy.service.express.SFExpressService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.SendNews;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.WeixinBaseController;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 *@author huangwenjie
 *@date 2017/8/12 14:11
 *遍历顺丰快递下单失败的记录,重新下单
 */
public class SFExpressJob implements Job {
    @Autowired
    private PrescriptionExpressageService prescriptionExpressageService;
    @Autowired
    private SFExpressService sfexpressService;
    private static final Logger logger = LoggerFactory.getLogger(SFExpressJob.class);
    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try {
            logger.info("顺丰快递JOB开始:搜索已支付成功,但是顺丰快递下单失败的处方物流记录,重新下单---------时间:"+ DateUtil.getNowDate());
            List<PrescriptionExpressage> expresslist = prescriptionExpressageService.findByPrescriptionPaidExpressOrderFail();
            if(!expresslist.isEmpty()){
                logger.info("顺丰快递JOB:找到"+expresslist.size()+"条下单失败记录,开始重新下单"+ DateUtil.getNowDate());
                sfexpressService.reOrderExpress(expresslist);
            }else{
                logger.info("顺丰快递JOB:未找到下单失败的处方快递记录"+ DateUtil.getNowDate());
            }
            logger.info("顺丰快递JOB结束:搜索已支付成功,但是顺丰快递下单失败的处方物流记录,重新下单---------时间:"+ DateUtil.getNowDate());
        } catch (Exception e) {
            e.printStackTrace();
            logger.info("顺丰快递JOB执行出错:错误信息"+ e.getMessage());
        }
    }
}

+ 6 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionExpressageDao.java

@ -2,14 +2,20 @@ package com.yihu.wlyy.repository.prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionPay;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by chenweida on 2017/7/27.
 */
public interface PrescriptionExpressageDao extends PagingAndSortingRepository<PrescriptionExpressage, Long>, JpaSpecificationExecutor<PrescriptionExpressage> {
    @Query("from PrescriptionExpressage p where p.prescriptionCode=?1")
    PrescriptionExpressage findByPrescriptionPay(String prescriptionCode);
    @Query(value = "select p.* FROM wlyy_prescription_expressage p LEFT JOIN wlyy_prescription a on a.code = p.prescription_code where a.status = 30 and p.mobile is null",nativeQuery = true)
    List<PrescriptionExpressage> findByPrescriptionPaidExpressOrderFail();
}

+ 25 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionExpressageLogDao.java

@ -0,0 +1,25 @@
package com.yihu.wlyy.repository.prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressageLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * 处方物流配送详情
 * @author  huangwenjie 2017.08.03
 */
public interface PrescriptionExpressageLogDao extends
        PagingAndSortingRepository<PrescriptionExpressageLog, Long>,
        JpaSpecificationExecutor<PrescriptionExpressageLog> {
    /**
     * 根据处方号获取该处方的物流配送日志,按路由节点发生的时间倒序排序
     * @param prescriptionCode
     * @return
     */
    @Query("from PrescriptionExpressageLog p where p.prescriptionCode=?1 order by p.acceptTime desc")
    List<PrescriptionExpressageLog> findByPrescriptionCode(String prescriptionCode);
}

+ 67 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionExpressageService.java

@ -0,0 +1,67 @@
package com.yihu.wlyy.service.app.prescription;
import com.yihu.wlyy.entity.patient.prescription.*;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao;
import com.yihu.wlyy.repository.prescription.PrescriptionLogDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
 * Created by chenweida on 2017/7/27.
 * 订单物流相关
 */
@Service
public class PrescriptionExpressageService {
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Value("${wechat.wechat_base_url}")
    private String wechat_base_url;
    @Value("${wechat.appId}")
    private String appId;
    @Autowired
    private PrescriptionLogDao prescriptionLogDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    /**
     * 获取所以已支付成功,但是顺丰快递下单失败的物流记录列表
     * @return
     * @throws Exception
     */
    public List<PrescriptionExpressage> findByPrescriptionPaidExpressOrderFail() throws Exception {
        return prescriptionExpressageDao.findByPrescriptionPaidExpressOrderFail();
    }
    /**
     * 1,保存快递单号增
     * 2,加处方物流记录为配送
     * 3,修改处方状态为配送配送中
     *
     * @param prescriptionExpressage
     * @throws Exception
     */
    public void updatePrescriptionExpressage(PrescriptionExpressage prescriptionExpressage) throws Exception {
        //修改处方状态为配送配送中
        prescriptionDao.updateStatus(prescriptionExpressage.getPrescriptionCode(),65);
        //保存处方物流记录
        prescriptionExpressageDao.save(prescriptionExpressage);
        //保存配送日志
        PrescriptionLog prescriptionLog = new PrescriptionLog();
        prescriptionLog.setPrescriptionCode(prescriptionExpressage.getPrescriptionCode());
        prescriptionLog.setCode(UUID.randomUUID().toString());
        prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.sf.getValue());
        prescriptionLog.setCreateTime(new Date());
        prescriptionLog.setFlag(1);
        prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing.getValue());
        prescriptionLogDao.save(prescriptionLog);
    }
}

+ 33 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java

@ -0,0 +1,33 @@
package com.yihu.wlyy.service.app.prescription;
import com.yihu.wlyy.entity.patient.prescription.*;
import com.yihu.wlyy.repository.prescription.*;
import com.yihu.wlyy.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
 * Created by Trick on 2017/7/25.
 */
@Service
@Transactional
public class PrescriptionInfoService extends BaseService {
    @Autowired
    private PrescriptionInfoDao prescriptionInfoDao;
    private static final Logger logger = LoggerFactory.getLogger(PrescriptionInfoService.class);
    /**
     * 获取处方下的详细药品
     * @param prescriptionCode
     * @return
     */
    public List<PrescriptionInfo> getPrescriptionInfo(String prescriptionCode) {
        return prescriptionInfoDao.findByPrescriptionCode(prescriptionCode);
    }
}

+ 25 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionService.java

@ -0,0 +1,25 @@
package com.yihu.wlyy.service.app.prescription;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * Created by huangwenjie on 2017/8/12.
 */
@Service
public class PrescriptionService extends BaseService {
    @Autowired
    private PrescriptionDao prescriptionDao;
    /**
     *  获取处方信息
     * @param prescriptionCode 处方code
     * @return
     */
    public Prescription findByCode(String prescriptionCode) {
        return prescriptionDao.findByCode(prescriptionCode);
    }
}

+ 294 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/service/express/SFExpressService.java

@ -0,0 +1,294 @@
package com.yihu.wlyy.service.express;
import com.yihu.wlyy.entity.dict.DmExpressagePriceEntity;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressageLog;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionLog;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.repository.prescription.PrescriptionExpressageDao;
import com.yihu.wlyy.repository.prescription.PrescriptionLogDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.prescription.PrescriptionExpressageService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SFUtils;
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.*;
/**
 * 顺丰快递业务层方法
 * Created by huangwenjie  on 2017/8/2.
 */
@Service
public class SFExpressService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(SFExpressService.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 HttpClientUtil HttpClientUtil;
    @Autowired
    private SFUtils SFUtils;
    @Autowired
    private PrescriptionLogDao prescriptionLogDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PrescriptionExpressageDao prescriptionExpressageDao;
    @Autowired
    private PrescriptionExpressageService prescriptionExpressageService;
    @Autowired
    private HospitalDao hospitalDao;
    /**
     * 组装请求参数,发送请求
     * @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 = HttpClientUtil.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 expresslist
     */
    public void reOrderExpress(List<PrescriptionExpressage> expresslist) throws Exception{
        for (PrescriptionExpressage prescriptionExpressage : expresslist) {
            try {
                //根据业务订单号判断是否已经下单成功
                boolean go_on = this.sfOrderSearchService(prescriptionExpressage);
                //如果该业务订单号未下单成功过,则重新下单
                if(go_on){
                    //请求顺丰接口下单,成功下单后,返回快递单号
                    prescriptionExpressage = this.postSFOrderService(prescriptionExpressage);
                    //保存快递单号和增加处方物流记录为配送
                    prescriptionExpressageService.updatePrescriptionExpressage(prescriptionExpressage);
                }
                logger.info("顺丰快递JOB:重新下单成功,处方编码:"+prescriptionExpressage.getPrescriptionCode());
            }catch (Exception e){
                logger.info("顺丰快递JOB:重新下单失败,处方编码:"+prescriptionExpressage.getPrescriptionCode());
                continue;
            }
        }
    }
    /**
     * 向顺丰快递下订单
     * @param sfexpress_obj
     * @return
     * @throws Exception
     */
    public PrescriptionExpressage postSFOrderService(PrescriptionExpressage sfexpress_obj) throws Exception {
        //获取医生所处的医院详细地址,作为寄件人地址
        Prescription prescription = prescriptionDao.findByCode(sfexpress_obj.getPrescriptionCode());
        Hospital hospital = hospitalDao.findByCode(prescription.getHospital());
        String xml = SFUtils.postSFOrderService(sfexpress_obj,hospital,sf_code);
        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验证
        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.getPrescriptionCode());
                throw new Exception("顺丰快递下订单失败:派送地址不可派送");
            }
            if(StringUtils.isBlank(mailno)){
                logger.info("顺丰快递下订单失败:未获取到快递单号!"+sfexpress_obj.getPrescriptionCode());
                throw new Exception("顺丰快递下订单失败:未获取到快递单号!");
            }
            sfexpress_obj.setMailno(mailno);
            sfexpress_obj.setCityCode(destCode);
        }
        return sfexpress_obj;
    }
    /**
     * 根据处方快递订单号判断是否下单成功
     * 如果下单成功,保存处方物流记录,保存配送日志
     * @param sfexpress_obj
     * @return
     * @throws Exception
     */
    public boolean sfOrderSearchService(PrescriptionExpressage sfexpress_obj)  throws Exception{
        boolean go_on = false;
        String xml = SFUtils.sfOrderSearchService(sfexpress_obj.getCode(),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.getPrescriptionCode());
                    return true;
                }
                if(StringUtils.isNotBlank(filter_result) && "3".equals(filter_result)){
                    logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getPrescriptionCode());
                    return true;
                }
                sfexpress_obj.setMailno(mailno);
                sfexpress_obj.setCityCode(destCode);
            }
            //如果成功获取到快递单号,则保存处方物流记录,保存配送日志
            //修改处方状态为配送中
            prescriptionDao.updateStatus(sfexpress_obj.getPrescriptionCode(),65);
            //保存处方物流记录
            prescriptionExpressageDao.save(sfexpress_obj);
            //保存配送日志
            PrescriptionLog prescriptionLog = new PrescriptionLog();
            prescriptionLog.setPrescriptionCode(sfexpress_obj.getPrescriptionCode());
            prescriptionLog.setCode(UUID.randomUUID().toString());
            prescriptionLog.setType(PrescriptionLog.PrescriptionLogType.sf.getValue());
            prescriptionLog.setCreateTime(new Date());
            prescriptionLog.setFlag(1);
            prescriptionLog.setStatus(PrescriptionLog.PrescriptionLogStatus.expressageing.getValue());
            prescriptionLogDao.save(prescriptionLog);
        }catch (Exception ex){
            logger.info("顺丰快递下订单失败:派送地址不可派送,处方编号:"+sfexpress_obj.getPrescriptionCode());
            //如果订单处理失败,则可以继续下单
            go_on = true;
        }
        return go_on;
    }
}

+ 255 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/util/SFUtils.java

@ -0,0 +1,255 @@
package com.yihu.wlyy.util;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo;
import com.yihu.wlyy.service.app.prescription.PrescriptionInfoService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.List;
/**
 * 顺丰速递接口相关的一些公用方法
 * @author huangwenjie 2017.8.2
 */
@Component
public class SFUtils {
    private static Logger logger = LoggerFactory.getLogger(SFUtils.class);
    @Autowired
    private PrescriptionInfoService prescriptionInfoService;
    /**
     * 生成接口校验码
     * 1.先把XML报文与checkword前后连接。
     * 2.把连接后的字符串做 MD5(16位) 编码。
     * 3.把MD5编码后的数据进行 Base64 编码,此时编码后的字符串即为校验码。
     * @param xml   xml报文
     * @param sf_check_word  接口check_word
     * @return
     */
    public String verifyCodeSFXmlStr(String xml,String sf_check_word){
        String verifyCode = xml+sf_check_word;
        verifyCode = md5EncryptAndBase64(verifyCode);
        return verifyCode;
    }
    /**
     * 查询派送地址是否属于顺丰的派送范围
     * @param d_address     派送地址
     * @param sf_code       顺丰接口接入码
     * @param orderid       订单ID
     * @param j_tel         寄方电话
     * @param j_address     寄方地址
     * @param d_tel         收方电话
     * @return
     */
    public String getSFOrderFilterXml(String d_address,String sf_code,String orderid,String j_tel,String j_address,String d_tel){
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='OrderFilterService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<OrderFilter filter_type='1' ");
        //订单号
        if(StringUtils.isNotBlank(orderid)){
            xml.append("orderid='"+orderid+"' ");
        }
        //派送地址,必填
        xml.append("d_address='"+d_address+"'/>");
        //如果扩张字段有不为空的,则增加扩张字段参数
        if(StringUtils.isNotBlank(j_tel) ||
                StringUtils.isNotBlank(j_address)||
                    StringUtils.isNotBlank(d_tel)){
            xml.append("<OrderFilterOption ");
            //寄方电话
            if(StringUtils.isNotBlank(j_tel)){
                xml.append("j_tel='"+j_tel+"' ");
            }
            //寄方地址
            if(StringUtils.isNotBlank(j_address)){
                xml.append("j_address='"+j_address+"' ");
            }
            //收方电话
            if(StringUtils.isNotBlank(d_tel)){
                xml.append("d_tel='"+d_tel+"' ");
            }
            xml.append("/></OrderFilter>");
        }
        xml.append("</Body></Request>");
        return xml.toString();
    }
    /**
     * 向顺丰快递下订单
     * @param sfexpress_obj
     * @param hospital
     * @return
     */
    public String postSFOrderService(PrescriptionExpressage sfexpress_obj, Hospital hospital, String sf_code) {
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='OrderService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<Order ");
        //订单号(快递业务号作为订单号"SF开头的为顺丰快递")
        xml.append("orderid='"+sfexpress_obj.getCode()+"' ");
        /**
         * --------寄方参数------
         */
        //寄件方公司名称
        if(StringUtils.isNotBlank(hospital.getName())){
            xml.append("j_company='"+hospital.getName()+"' ");
        }
        //寄方联系人
        if(StringUtils.isNotBlank(hospital.getName())){
            xml.append("j_contact='"+hospital.getName()+"' ");
        }
        //寄件方联系电话
        if(StringUtils.isNotBlank(hospital.getPhone())){
            xml.append("j_tel='"+hospital.getPhone()+"' ");
            xml.append("j_mobile='"+hospital.getPhone()+"' ");
        }
        //寄方所在省份
        if(StringUtils.isNotBlank(hospital.getProvinceName())){
            xml.append("j_province='"+hospital.getProvinceName()+"' ");
        }
        //寄方所在城市
        if(StringUtils.isNotBlank(hospital.getCityName())){
            xml.append("j_city='"+hospital.getCityName()+"' ");
        }
        //寄方所在县/区
        if(StringUtils.isNotBlank(hospital.getTownName())){
            xml.append("j_county='"+hospital.getTownName()+"' ");
        }
        //寄件方详细地址,包括省市县/区
        if(StringUtils.isNotBlank(hospital.getAddress())){
            xml.append("j_address='"+hospital.getAddress()+"' ");
        }
        /**
         * --------收方参数------
         */
        //派送地址,必填
        xml.append("d_address='"+sfexpress_obj.getAddress()+"' ");
        //到件方单位名称,因为接口不能为空,这里默认放到件方联系人
        xml.append("d_company='"+sfexpress_obj.getName()+"' ");
        //到件方联系人
        xml.append("d_contact='"+sfexpress_obj.getName()+"' ");
        //到件方联系电话
        xml.append("d_tel='"+sfexpress_obj.getPhone()+"' ");
        //到件方手机
        if(StringUtils.isNotBlank(sfexpress_obj.getMobile())){
            xml.append("d_mobile='"+sfexpress_obj.getMobile()+"' ");
        }
        xml.append("d_province='"+sfexpress_obj.getProvinceName()+"' ");
        xml.append("d_city='"+sfexpress_obj.getCityName()+"' ");
        xml.append("d_county='"+sfexpress_obj.getTownName()+"' ");
        //快件产品类别:11,医药常温
        //付款方式:1:寄方付,2:收方付 3:第三方付
        xml.append("express_type='11' pay_method='2' >");
//        xml.append("express_type='11' pay_method='1' custid='9999999999'>");
        //获取订单的药品详情
        List<PrescriptionInfo> prescriptionInfolist = prescriptionInfoService.getPrescriptionInfo(sfexpress_obj.getPrescriptionCode());
        if(!prescriptionInfolist.isEmpty()){
            for (int i = 0; i < prescriptionInfolist.size(); i++) {
                xml.append("<Cargo name='"+prescriptionInfolist.get(i).getDrugName()+"' count='"+prescriptionInfolist.get(i).getNum()+"'></Cargo>");
            }
        }
        xml.append("</Order></Request>");
        return xml.toString();
    }
    /**
     * 顺丰路由查询
     * @param sfexpress_obj
     * @param sf_code
     * @return
     */
    public String getRoutInfos(PrescriptionExpressage sfexpress_obj, String sf_code) {
        //head 传入接口接入码
        StringBuilder xml = new StringBuilder("<Request service='RouteService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<RouteRequest tracking_type='1' method_type='1' ").append("tracking_number='"+sfexpress_obj.getMailno()+"' />");
        xml.append("</Body></Request>");
        return xml.toString();
    }
    /**
     * 订单结果查询接口
     * @param sfexpress_objCode
     * @param sf_code
     * @return
     */
    public String sfOrderSearchService(String sfexpress_objCode, String sf_code) {
        StringBuilder xml = new StringBuilder("<Request service='OrderSearchService' lang='zh-cn'><Head>"+sf_code+"</Head><Body>");
        xml.append("<OrderSearch orderid='"+sfexpress_objCode+"'/>");
        xml.append("</Body></Request>");
        return xml.toString();
    }
    //-----------顺丰快递验证码加密的相关方法------------------START
    public static String loadFile(String fileName) {
        InputStream fis;
        try {
            fis = new FileInputStream(fileName);
            byte[] bs = new byte[fis.available()];
            fis.read(bs);
            String res = new String(bs);
            fis.close();
            return res;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public static String md5EncryptAndBase64(String str) {
        return encodeBase64(md5Encrypt(str));
    }
    private static byte[] md5Encrypt(String encryptStr) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(encryptStr.getBytes("utf8"));
            return md5.digest();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    private static String encodeBase64(byte[] b) {
        BASE64Encoder base64Encode = new BASE64Encoder();
        String str = base64Encode.encode(b);
        return str;
    }
    public static void main(String[] args) {
        String xml = "<Request service='OrderSearchService' lang='zh-cn'><Head>SDDF</Head><Body><OrderSearch orderid='6daa6baec5fd4b65a1b023a8b60e2e76'/></Body></Request>";
        String check_word = "ttzlgGyOQu4L";
        System.out.println(md5EncryptAndBase64(xml + check_word));
//        System.out.println(md5EncryptAndBase64("abc"));
//        System.out.println(md5EncryptAndBase64("中"));
    }
    //-----------顺丰快递验证码加密的相关方法------------------END
}

+ 18 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/web/quota/JobController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.quota;
import com.yihu.wlyy.job.FollowupPlanJob;
import com.yihu.wlyy.job.QuartzHelper;
import com.yihu.wlyy.job.SFExpressJob;
import com.yihu.wlyy.job.consult.ConsultCleanerJob;
import com.yihu.wlyy.job.consult.FamousConsultTimesJob;
import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
@ -341,4 +342,21 @@ public class JobController extends BaseController {
        }
    }
    /**
     * 遍历顺丰快递下单失败的记录,重新下单
     *@author huangwenjie
     *@date 2017/8/12 15:35
     */
    @RequestMapping(value = "/reOrderExpress", method = RequestMethod.POST)
    @ApiOperation("添加超时咨询自动关闭任务")
    public String reOrderExpressJob() {
        try {
            quartzHelper.startNow(SFExpressJob.class, "SFEXPRESS-REORDER", null);
            return write(200, "");
        } catch (Exception e) {
            error(e);
            return error(-1, e.getMessage());
        }
    }
}

+ 25 - 1
patient-co/patient-co-wlyy-job/src/main/resources/application.yml

@ -161,6 +161,12 @@ ylzpay:
  onepayAppId: 1BGKM1UHM03P7B2CA8C000005626EB0E
  onepayAppSecret: 1BGKM1UHM03I7B2CA8C00000AB682E9A
express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService
#  sf_url: https://bsp-ois.sit.sf-express.com:9443/bsp-ois/sfexpressServic
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
---
##正式的配置
@ -252,6 +258,12 @@ ylzpay:
  onepayAppId: 1BLF5SEGN00087165F0A000027362BE5
  onepayAppSecret: 1BLF5SCBO01V3E78A8C00000F3A0FFE7
express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService
#  sf_url: https://bsp-ois.sit.sf-express.com:9443/bsp-ois/sfexpressServic
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
---
##开发的配置
spring:
@ -342,6 +354,12 @@ ylzpay:
  onepayAppId: 1BGKM1UHM03P7B2CA8C000005626EB0E
  onepayAppSecret: 1BGKM1UHM03I7B2CA8C00000AB682E9A
express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService
#  sf_url: https://bsp-ois.sit.sf-express.com:9443/bsp-ois/sfexpressServic
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L
---
##开发连测试用这个版本的配置
spring:
@ -421,4 +439,10 @@ sign:
quartz:
  name: schedulerFactoryBean_test_dev
  name: schedulerFactoryBean_test_dev
express:
  sf_url: http://218.17.248.244:11080/bsp-oisp/sfexpressService
#  sf_url: https://bsp-ois.sit.sf-express.com:9443/bsp-ois/sfexpressServic
  sf_code: SDDF
  sf_check_word: ttzlgGyOQu4L

+ 3 - 0
patient-co/patient-co-wlyy-job/src/main/resources/system.properties

@ -81,6 +81,9 @@ evaluate_score_job = 0 0 */2 * * ?
#续方支付到期,每天0点触发
prescription_pay_overdue_job = 0 0 0 * * ?
#遍历支付成功,快递下单失败的记录,重新下单,10分钟跑一次
sfexpress_reorder_job=0 0/10 * * * ?
#统一支付平台支付成功后页面跳转地址
return_url={server}/wx/html/qygl/html/pay_result.html
#统一支付平台支付接口地址