Browse Source

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

# Conflicts:
#	business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/XzzxEntranceService.java
wangzhinan 4 years ago
parent
commit
eccf79fea1

+ 359 - 0
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -0,0 +1,359 @@
package com.yihu.jw.order;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
import com.yihu.jw.entity.base.wx.BasePatientWechatDo;
import com.yihu.jw.entity.base.wx.WxPayLogDO;
import com.yihu.jw.entity.base.wx.WxWechatDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import com.yihu.jw.order.dao.BusinessOrderDao;
import com.yihu.jw.order.dao.BusinessOrderRefundDao;
import com.yihu.jw.order.pay.wx.WeChatConfig;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import com.yihu.jw.util.common.XMLUtil;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.util.wechat.WeiXinPayUtils;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.wechat.dao.BasePatientWechatDao;
import com.yihu.jw.wechat.dao.WechatDao;
import com.yihu.jw.wechat.dao.WxPayLogDao;
import com.yihu.jw.wechat.service.WxPayLogService;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
/**
 *
 * 业务订单
 */
@Service
public class BusinessOrderService {
    @Autowired
    private BusinessOrderDao businessOrderDao;
    @Autowired
    private WechatDao wechatDao;
    @Autowired
    private WxPayLogDao wxPayLogDao;
    @Autowired
    private BasePatientWechatDao patientWechatDao;
    @Autowired
    private BasePatientDao patientDao;
    @Autowired
    private BusinessOrderRefundDao orderRefundDao;
    public BusinessOrderDO saveOrder(BusinessOrderDO businessOrderDO) throws Exception {
        businessOrderDO.setStatus(0);
        businessOrderDO.setCreateTime(new Date());
        businessOrderDO.setUpdateTime(new Date());
        businessOrderDO.setOrderNo(getGuid());
        businessOrderDO = businessOrderDao.save(businessOrderDO);
        return businessOrderDO;
    }
    /**
     * 创建订单并输出微信JSAPI参数
     * @param businessOrderDO
     * @param wechatId
     * @return
     * @throws Exception
     */
    public Map<String, Object> saveOrderAndPay(BusinessOrderDO businessOrderDO,String wechatId) throws Exception {
        businessOrderDO.setStatus(0);
        businessOrderDO.setCreateTime(new Date());
        businessOrderDO.setUpdateTime(new Date());
        businessOrderDO.setOrderNo(getGuid());
        businessOrderDO = businessOrderDao.save(businessOrderDO);
        List<BasePatientWechatDo> patientWechatDos = patientWechatDao.findByWechatIdAndPatientId(wechatId,businessOrderDO.getPatient());
        String openId = "";
        if (patientWechatDos!=null&&patientWechatDos.size()!=0){
            openId = patientWechatDos.get(0).getOpenid();
        }
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        String url = wxWechatDO.getBaseUrl();
        String notifyUrl =url+"/ykyy"+BaseHospitalRequestMapping.WxPay.Notify;
        return unifiedorder(wechatId,businessOrderDO.getDescription(),businessOrderDO.getPayPrice().toString(),WeChatConfig.TRADE_TYPE_JSAPI,openId,businessOrderDO.getOrderNo(),notifyUrl);
    }
    /**
     * 微信统一下单接口
     *
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> unifiedorder(Map<String,String> par,String appKey) throws Exception {
        String xml = WeiXinPayUtils.getXmlBeforUnifiedorder(par, appKey);
        Map<String, Object> map = WeiXinPayUtils.unifiedorder(xml,true);
        //创建日志记录
        createLog(par,xml,map);
        map.remove("wxPayResult");
        return map;
    }
    /**
     * 微信统一退款接口
     *
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> refund(Map<String,String> par,String appKey) throws Exception {
        String xml = WeiXinPayUtils.getXmlBeforUnifiedorder(par, appKey);
        Map<String, Object> map = WeiXinPayUtils.refund(xml,true);
        //创建日志记录
        createLog(par,xml,map);
        map.remove("wxPayResult");
        return map;
    }
    /**
     * 微信下单
     * @param wechatId
     * @param body
     * @param totalFee
     * @param tradeType
     * @param openId
     * @param ourTradeNo
     * @param notifyUrl
     * @return
     * @throws Exception
     */
    public Map<String,Object> unifiedorder(String wechatId,String body,String totalFee,String tradeType,String openId,String ourTradeNo,String notifyUrl) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        if(!StringUtils.isNoneBlank(notifyUrl)){
            throw new Exception("notifyUrl is null :the notifyUrl is "+notifyUrl);
        }
        if(!StringUtils.isNoneBlank(body)){
            throw new Exception("body is null :the body is "+body);
        }
        if(!StringUtils.isNoneBlank(tradeType)){
            throw new Exception("tradeType is null :the tradeType is "+tradeType);
        }
        if(!StringUtils.isNoneBlank(openId)){
            throw new Exception("openId is null :the openId is "+openId);
        }
        if(!StringUtils.isNoneBlank(ourTradeNo)){
            throw new Exception("ourTradeNo is null :the ourTradeNo is "+ourTradeNo);
        }
        HashMap<String, String> map = new HashMap<>();
        map.put("appid",wxWechatDO.getAppId());
        map.put("mch_id",wxWechatDO.getMchId());
        map.put("body",body);
        map.put("out_trade_no",ourTradeNo);
        map.put("total_fee",totalFee);
        map.put("spbill_create_ip",getServerIp());
        map.put("notify_url",notifyUrl);
        map.put("trade_type", tradeType);
        map.put("openid", openId);
        Map<String, Object> pay = unifiedorder(map, wxWechatDO.getAppKey());
        String returnCode = pay.get("return_code").toString();
        if (returnCode.equalsIgnoreCase("SUCCESS")){
            String appid = pay.get("appid").toString();
            String mchId = pay.get("mch_id").toString();
            String nonceStr = pay.get("nonce_str").toString();
            String prepayId = pay.get("prepay_id").toString();
            Map<String,String> param = new HashedMap();
            param.put("appid",appid);
            param.put("partnerid",mchId);
            param.put("prepayid",prepayId);
            param.put("package","Sign=WXPay");
            param.put("noncestr",nonceStr);
            param.put("timestamp",getTimeStamp());
            param = WeiXinPayUtils.getMapAfterUnifiedorder(param,wxWechatDO.getAppKey());
            pay.put("jsapi",param);
        }
        return pay;
    }
    /**
     * 微信退款
     * @param wechatId
     * @param patient
     * @param orderNo
     * @param refundPrice
     * @param description
     * @return
     * @throws Exception
     */
    public Map<String,Object> orderRefund(String wechatId,String patient,String orderNo,Double refundPrice,String description) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if (wxWechatDO==null){
            throw new Exception("this wechatId is null");
        }
        BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(orderNo);
        if (businessOrderDO==null){
            throw new Exception("this orderId not exit");
        }
        BasePatientDO patientDO = patientDao.findById(patient);
        if (patientDO==null){
            throw new Exception("this patient not exit");
        }
        BusinessOrderRefundDO orderRefundDO = new BusinessOrderRefundDO();
        orderRefundDO.setCreateTime(new Date());
        orderRefundDO.setUpdateTime(new Date());
        orderRefundDO.setStatus(1);
        orderRefundDO.setOrderNo(orderNo);
        orderRefundDO.setOrderPrice(businessOrderDO.getPayPrice());
        orderRefundDO.setRefundPrice(refundPrice);
        orderRefundDO.setAppId(wxWechatDO.getAppId());
        orderRefundDO.setMchId(wxWechatDO.getMchId());
        orderRefundDO.setOutRefundNo(getGuid());
        orderRefundDO.setPatient(patient);
        orderRefundDO.setPatientName(patientDO.getName());
        orderRefundDO.setRefundDesc(description);
        orderRefundDO = orderRefundDao.save(orderRefundDO);
        Map<String,Object> map = refund(wechatId,orderRefundDO.getOrderNo(),orderRefundDO.getOutRefundNo(),orderRefundDO.getOrderPrice().toString(),orderRefundDO.getRefundPrice().toString(),orderRefundDO.getRefundDesc());
        if (map.get("return_code").toString().equalsIgnoreCase("SUCCESS")){
            orderRefundDO.setStatus(2);
            orderRefundDO.setRefundTime(new Date());
            orderRefundDao.save(orderRefundDO);
        }
        return map;
    }
    public Map<String,Object> refund(String wechatId,String outTradeNo,String outRefundNo,String totalFee,String refundFee,String descrption) throws Exception {
        WxWechatDO wxWechatDO = wechatDao.findById(wechatId);
        if(wxWechatDO==null){
            throw new Exception("can't find wechat:the wxId is "+wechatId);
        }
        if(!StringUtils.isNoneBlank(refundFee)){
            throw new Exception("refundFee is null :the refundFee is "+refundFee);
        }
        if(!StringUtils.isNoneBlank(outRefundNo)){
            throw new Exception("outRefundNo is null :the outRefundNo is "+outRefundNo);
        }
        if(!StringUtils.isNoneBlank(outTradeNo)){
            throw new Exception("outTradeNo is null :the outTradeNo is "+outTradeNo);
        }
        HashMap<String, String> map = new HashMap<>();
        map.put("appid",wxWechatDO.getAppId());
        map.put("mch_id",wxWechatDO.getMchId());
        map.put("out_trade_no",outTradeNo);
        map.put("out_refund_no",outRefundNo);
        map.put("refund_fee",refundFee);
        map.put("total_fee",totalFee);
        map.put("refund_desc",descrption);
        Map<String, Object> refund = refund(map, wxWechatDO.getAppKey());
        return refund;
    }
    /**
     * 添加微信支付日志
     * @param map
     * @param orderPar
     * @param orderRes
     */
    public void createLog(Map<String,String> map,String orderPar,Map<String,Object> orderRes){
        WxPayLogDO wxPayLogDO = new WxPayLogDO();
        wxPayLogDO.setSeqNo(map.get("out_trade_no"));
        wxPayLogDO.setOpenId(map.get("openid"));
        wxPayLogDO.setType(0);
        wxPayLogDO.setOrderParams(orderPar);
        wxPayLogDO.setOrderResponse(orderRes.get("wxPayResult").toString());
        String return_code = orderRes.get("return_code").toString();
        if("SUCCESS".equalsIgnoreCase(return_code)){
            wxPayLogDO.setOrderStatus(1);
        }else{
            wxPayLogDO.setOrderStatus(-1);
        }
        wxPayLogDO.setCreateTime(new Date());
        wxPayLogDO.setPayStatus(0);
        wxPayLogDao.save(wxPayLogDO);
    }
    /**
     * 获取服务器ip地址
     *
     * @return
     * @throws UnknownHostException
     */
    public String getServerIp() throws UnknownHostException {
        InetAddress address = InetAddress.getLocalHost();//获取的是本地的IP地址 //PC-20140317PXKX/192.168.0.121
        String hostAddress = address.getHostAddress();//192.168.0.121
        return hostAddress;
    }
    /**
     *  获取当前时间戳
     * @return 当前时间戳字符串
     */
    public static String getTimeStamp(){
        return String.valueOf(System.currentTimeMillis()/1000);
    }
    /**
     * 获取唯一的支付流水号
     */
    public static int Guid=100;
    synchronized public String getGuid() {
        return DateUtil.dateToStr(new Date(),"yyyyMMddHHmmssSSS")+(new Random().nextInt(10));
    }
    /**
     * 微信支付回调
     *
     *
     * @param result
     * @return
     */
    public Map<String,String> getWxPayResultNotify(String result) {
        Map<String,String> rs = new HashedMap();
        Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
        if("SUCCESS".equals(wxrs.get("return_code").toString())){
            // 我方 订单号+时间差
            String seqNo = wxrs.get("out_trade_no")+"";
            // 微信充值流水号
            String wxSeqNo = wxrs.get("transaction_id")+"";
            // 微信分配的终端设备号
            String wxDeviceInfo = wxrs.get("device_info")+"";
            String timeEnd= wxrs.get("time_end")+"";
            //更改业务状态,做日志保存等操作
            BusinessOrderDO businessOrderDO = businessOrderDao.selectByOrderNo(seqNo);
            businessOrderDO.setPayTime(DateUtil.strToDate(timeEnd,DateUtil.YYYY_MM_DD_HH_MM_SS));
            businessOrderDO.setStatus(1);
            //操作微信日志表记录
            List<WxPayLogDO> wxPayLogDOs = wxPayLogDao.findBySeqNo(seqNo);
            WxPayLogDO wxPayLogDO = wxPayLogDOs.get(0);
            wxPayLogDO.setPayResponse(result);
            wxPayLogDO.setPayStatus(1);
            wxPayLogDO.setPayTime(new Date());
            wxPayLogDO.setPayStatus(1);
            wxPayLogDao.save(wxPayLogDO);
            rs.put("code","1");
            rs.put("message","支付成功");
        }else{
            rs.put("code","-1");
            rs.put("return_msg","FAIL");
        }
        return rs;
    }
}

+ 7 - 2
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/dao/order/businessOrderDao.java

@ -1,14 +1,19 @@
package com.yihu.jw.hospital.dao.order;
package com.yihu.jw.order.dao;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface businessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, Integer>, JpaSpecificationExecutor<BusinessOrderDO>  {
public interface BusinessOrderDao extends PagingAndSortingRepository<BusinessOrderDO, Integer>, JpaSpecificationExecutor<BusinessOrderDO>  {
    @Query("from BusinessOrderDO w where w.orderNo = ?1 ")
    BusinessOrderDO selectByOrderNo(String orderNo);
}

+ 17 - 0
business/base-service/src/main/java/com/yihu/jw/order/dao/BusinessOrderRefundDao.java

@ -0,0 +1,17 @@
package com.yihu.jw.order.dao;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.entity.order.BusinessOrderRefundDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface BusinessOrderRefundDao extends PagingAndSortingRepository<BusinessOrderRefundDO, Integer>, JpaSpecificationExecutor<BusinessOrderRefundDO>  {
    @Query("from BusinessOrderDO w where w.orderNo = ?1 ")
    BusinessOrderRefundDO selectByOrderNo(String orderNo);
}

+ 26 - 0
business/base-service/src/main/java/com/yihu/jw/order/pay/wx/WeChatConfig.java

@ -0,0 +1,26 @@
package com.yihu.jw.order.pay.wx;
/**
 * Created by wangzhinan on 2020/4/21.
 */
public class WeChatConfig {
    /**微信支付api证书路径*/
    public static final String CERT_PATH = "***/apiclient_cert.p12";
    /**微信统一下单url*/
    public static final String UNIFIED_ORDER_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
    /**微信申请退款url*/
    public static final String REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund";
    /**微信交易类型:公众号支付*/
    public static final String TRADE_TYPE_JSAPI = "JSAPI";
    /**微信交易类型:原生扫码支付*/
    public static final String TRADE_TYPE_NATIVE = "NATIVE";
    /**微信甲乙类型:APP支付*/
    public static final String TRADE_TYPE_APP = "APP";
}

+ 111 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/order/BusinessOrderDO.java

@ -1,27 +1,99 @@
package com.yihu.jw.entity.order;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IntegerIdentityEntity;
import com.yihu.jw.entity.IntegerIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;
/**
 * 业务订单表
 */
@Entity
@Table(name = "base_business_order_pay")
public class BusinessOrderDO extends IntegerIdentityEntityWithOperator {
public class BusinessOrderDO extends IntegerIdentityEntity {
    private String patient;//居民code
    private String patientName;//居民名字
    private String orderNo;//订单号
    private Integer orderType;//订单类型
    private String relationCode;//业务关联code
    private String relationName;//业务关联名称
    private String description;//支付备注
    private Integer payType;//支付类型1微信2支付宝
    private Double payPrice;//支付金额
    private Date payTime;//支付时间
    private Integer status;//0待支付1支付成功2支付失败3取消
    private Date createTime;
    private String createUser;
    private String createUserName;
    private Date updateTime;
    private String updateUser;
    private String updateUserName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "create_time", nullable = false, length = 0,updatable = false)
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Column(name = "create_user",updatable = false)
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    @Column(name = "create_user_name",updatable = false)
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "update_time", nullable = false, length = 0)
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    @Column(name = "update_user")
    public String getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
    @Column(name = "update_user_name")
    public String getUpdateUserName() {
        return updateUserName;
    }
    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }
    @Column(name = "order_no")
    public String getOrderNo() {
        return orderNo;
@ -85,4 +157,42 @@ public class BusinessOrderDO extends IntegerIdentityEntityWithOperator {
    public void setPayPrice(Double payPrice) {
        this.payPrice = payPrice;
    }
    @Column(name = "description")
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "patient_name")
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "pay_time")
    public Date getPayTime() {
        return payTime;
    }
    public void setPayTime(Date payTime) {
        this.payTime = payTime;
    }
}

+ 194 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/order/BusinessOrderRefundDO.java

@ -0,0 +1,194 @@
package com.yihu.jw.entity.order;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.IntegerIdentityEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 业务订单表
 */
@Entity
@Table(name = "base_business_order_refund")
public class BusinessOrderRefundDO extends IntegerIdentityEntity {
    private String patient;//居民code
    private String patientName;//居民名字
    private String orderNo;//订单号
    private String outRefundNo;//退款订单号
    private Double orderPrice;//订单金额
    private Double refundPrice;//退款金额
    private String appId;//公众号id
    private String mchId;//商户号
    private String refundDesc;//退款原因
    private Integer status;//状态1待退款2已退款
    private Date refundTime;//退款时间
    private Date createTime;
    private String createUser;
    private String createUserName;
    private Date updateTime;
    private String updateUser;
    private String updateUserName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "create_time", nullable = false, length = 0,updatable = false)
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @Column(name = "create_user",updatable = false)
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    @Column(name = "create_user_name",updatable = false)
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "update_time", nullable = false, length = 0)
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    @Column(name = "update_user")
    public String getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
    @Column(name = "update_user_name")
    public String getUpdateUserName() {
        return updateUserName;
    }
    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }
    @Column(name = "order_no")
    public String getOrderNo() {
        return orderNo;
    }
    public void setOrderNo(String orderNo) {
        this.orderNo = orderNo;
    }
    @Column(name = "patient")
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "patient_name")
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    @Column(name = "out_refund_no")
    public String getOutRefundNo() {
        return outRefundNo;
    }
    public void setOutRefundNo(String outRefundNo) {
        this.outRefundNo = outRefundNo;
    }
    @Column(name = "order_price")
    public Double getOrderPrice() {
        return orderPrice;
    }
    public void setOrderPrice(Double orderPrice) {
        this.orderPrice = orderPrice;
    }
    @Column(name = "refund_price")
    public Double getRefundPrice() {
        return refundPrice;
    }
    public void setRefundPrice(Double refundPrice) {
        this.refundPrice = refundPrice;
    }
    @Column(name = "app_id")
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    @Column(name = "mch_id")
    public String getMchId() {
        return mchId;
    }
    public void setMchId(String mchId) {
        this.mchId = mchId;
    }
    @Column(name = "status")
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    @Column(name = "refund_time")
    public Date getRefundTime() {
        return refundTime;
    }
    public void setRefundTime(Date refundTime) {
        this.refundTime = refundTime;
    }
    @Column(name = "refund_desc")
    public String getRefundDesc() {
        return refundDesc;
    }
    public void setRefundDesc(String refundDesc) {
        this.refundDesc = refundDesc;
    }
}

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

@ -734,4 +734,11 @@ public class BaseHospitalRequestMapping {
        public static final String app="/app";
    }
    public static class WxPay extends Basic{
        public static final String wechatPay =  "/wechatPay";
        public static final String Notify =  "/notify";
    }
}

+ 94 - 1
common/common-util/src/main/java/com/yihu/jw/util/wechat/WeiXinPayUtils.java

@ -42,6 +42,29 @@ public class WeiXinPayUtils {
        }
    }
    /**
     * 调起支付的接口
     * @param param
     * @param appKey
     * @return
     * @throws Exception
     */
    public static Map<String, String> getMapAfterUnifiedorder(Map<String, String> param,String appKey) throws Exception {
        synchronized (WeiXinPayUtils.class) {
            WXPayConstants.SignType  wxSignType = WXPayConstants.SignType.MD5;
            String signType = param.get("sign_type");
            if("HMAC-SHA256".equalsIgnoreCase(signType)){
                wxSignType = WXPayConstants.SignType.HMACSHA256;
            }
            //获取微信签名
            String signature = WeiXinPayUtils.generateSignature(param, appKey, wxSignType);
            param.put("sign",signature);
            return param;
        }
    }
    /**
     *
     * 微信支付,统一下单
@ -96,6 +119,76 @@ public class WeiXinPayUtils {
    }
    /**
     *
     * 微信支付,查询订单
     *
     * param 对应的key值参见文档 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_2&index=4 (sign,nonce_str两个参数,此接口会自动生成)
     *
     * @param param
     * @param appKey
     * @return  返回的map为微信返回报文转换成的map,
     *            此外map中 有个属性 wxPayResult.该属性放着微信返回的原始报文数据
     * @throws Exception
     */
    public static Map<String,Object> orderquery(Map<String, String> param,String appKey) throws Exception {
        synchronized (WeiXinPayUtils.class) {
            String xml = getXmlBeforUnifiedorder(param, appKey);
            String result = HttpUtil.sendPost("https://api.mch.weixin.qq.com/pay/orderquery", xml);
            Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
            wxrs.put("wxPayResult",wxrs);
            return wxrs;
        }
    }
    public static Map<String,Object> orderquery(String param,boolean withResult) throws Exception {
        synchronized (WeiXinPayUtils.class) {
            String result = HttpUtil.sendPost("https://api.mch.weixin.qq.com/pay/orderquery", param);
            Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
            if(withResult){
                wxrs.put("wxPayResult",wxrs);
            }
            return wxrs;
        }
    }
    /**
     *
     * 微信支付,申请退款
     *
     * param 对应的key值参见文档 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 (sign,nonce_str两个参数,此接口会自动生成)
     *
     * @param param
     * @param appKey
     * @return  返回的map为微信返回报文转换成的map,
     *            此外map中 有个属性 wxPayResult.该属性放着微信返回的原始报文数据
     * @throws Exception
     */
    public static Map<String,Object> refund(Map<String, String> param,String appKey) throws Exception {
        synchronized (WeiXinPayUtils.class) {
            String xml = getXmlBeforUnifiedorder(param, appKey);
            String result = HttpUtil.sendPost("https://api.mch.weixin.qq.com/secapi/pay/refund", xml);
            Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
            wxrs.put("wxPayResult",wxrs);
            return wxrs;
        }
    }
    public static Map<String,Object> refund(String param,boolean withResult) throws Exception {
        synchronized (WeiXinPayUtils.class) {
            String result = HttpUtil.sendPost("https://api.mch.weixin.qq.com/secapi/pay/refund", param);
            Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
            if(withResult){
                wxrs.put("wxPayResult",wxrs);
            }
            return wxrs;
        }
    }
    /**
     * 获取随机字符串 Nonce Str
     *
@ -190,7 +283,7 @@ public class WeiXinPayUtils {
        map.put("trade_type","JSAPI");
        map.put("openid", "oDGGt0QrJvH-YbDCHFgjd3Exc0Sw");
        Map<String, Object> pay = unifiedorder(map, "yF4e9Rr1sVdqCF6c7cqqMPSNsCjYGyf9");
        System.out.println("--------------");
        System.out.println("--------------"+pay);
    }
}

+ 144 - 4
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/ykyy/YkyyController.java

@ -1,19 +1,26 @@
package com.yihu.jw.hospital.endpoint.ykyy;
import com.yihu.jw.entity.hospital.mapping.HospitalDeptMappingDO;
import com.yihu.jw.entity.order.BusinessOrderDO;
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
import com.yihu.jw.hospital.ykyy.service.YkyyService;
import com.yihu.jw.order.BusinessOrderService;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import com.yihu.jw.rm.patient.PatientRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
/**
@ -27,6 +34,10 @@ public class YkyyController extends EnvelopRestEndpoint {
    @Autowired
    private YkyyService ykyyService;
    @Value("${wechat.id}")
    private String wxId;
    @Autowired
    private BusinessOrderService businessOrderService;
    @GetMapping(value = "/selectCardList")
@ -58,4 +69,133 @@ public class YkyyController extends EnvelopRestEndpoint {
        }
    }
    /**
     * 创建订单
     * @param json
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "createOrder", method = RequestMethod.POST)
    @ApiOperation("创建订单")
    public ObjEnvelop saveOrder(
            @ApiParam(name = "json", value = "json", required = true)
            @RequestParam(required = true)String json) throws Exception {
        BusinessOrderDO businessOrderDO = objectMapper.readValue(json,BusinessOrderDO.class);
        try {
            return ObjEnvelop.getSuccess("ok",businessOrderService.saveOrder(businessOrderDO));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 调用微信
     * @param body
     * @param totalFee
     * @param tradeType
     * @param openId
     * @param outTradeNo
     * @param notifyUrl
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "weixinPay", method = RequestMethod.POST)
    @ApiOperation("调用微信支付")
    public ObjEnvelop unifiedorder(
            @ApiParam(name = "body", value = "body", required = true)
            @RequestParam(required = true)String body,
            @ApiParam(name = "totalFee", value = "totalFee", required = true)
            @RequestParam(required = true)String totalFee,
            @ApiParam(name = "tradeType", value = "tradeType", required = true)
            @RequestParam(required = true)String tradeType,
            @ApiParam(name = "openId", value = "openId", required = true)
            @RequestParam(required = true)String openId,
            @ApiParam(name = "outTradeNo", value = "outTradeNo", required = true)
            @RequestParam(required = true)String outTradeNo,
            @ApiParam(name = "notifyUrl", value = "notifyUrl", required = true)
            @RequestParam(required = true)String notifyUrl) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",businessOrderService.unifiedorder(wxId,body,totalFee,tradeType,openId,outTradeNo,notifyUrl));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 创建订单并获取微信支付参数
     * @param json
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "saveOrderAndPay", method = RequestMethod.POST)
    @ApiOperation("创建订单并获取微信支付参数")
    public ObjEnvelop saveOrderAndPay(
            @ApiParam(name = "json", value = "json", required = true)
            @RequestParam(required = false)String json) throws Exception {
        BusinessOrderDO businessOrderDO = objectMapper.readValue(json,BusinessOrderDO.class);
        try {
            return ObjEnvelop.getSuccess("ok",businessOrderService.saveOrderAndPay(businessOrderDO,wxId));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    /**
     * 微信支付异步回调
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @ResponseBody
    @ApiOperation("微信支付结果通知")
    @RequestMapping(value = BaseHospitalRequestMapping.WxPay.Notify, method = {RequestMethod.GET, RequestMethod.POST})
    public Map<String, String> wxPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String result = "";
        String inputLine;
        while ((inputLine = request.getReader().readLine()) != null) {
            result += inputLine;
        }
        request.getReader().close();
        Map<String, String> map = businessOrderService.getWxPayResultNotify(result);
        return map;
    }
    /**
     *
     * 微信退款
     * @param patient
     * @param orderNo
     * @param refundPrice
     * @param description
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "orderRefund", method = RequestMethod.POST)
    @ApiOperation("微信退款")
    public ObjEnvelop orderRefund(
            @ApiParam(name = "patient", value = "patient", required = true)
            @RequestParam(required = true)String patient,
            @ApiParam(name = "orderNo", value = "orderNo", required = true)
            @RequestParam(required = true)String orderNo,
            @ApiParam(name = "refundPrice", value = "refundPrice", required = true)
            @RequestParam(required = true)String refundPrice,
            @ApiParam(name = "description", value = "description", required = true)
            @RequestParam(required = true)String description) throws Exception {
        try {
            return ObjEnvelop.getSuccess("ok",businessOrderService.orderRefund(wxId,patient,orderNo,Double.parseDouble(refundPrice),description));
        } catch (Exception e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
}

+ 0 - 14
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/service/order/BusinessOrderService.java

@ -1,14 +0,0 @@
package com.yihu.jw.hospital.service.order;
import org.springframework.stereotype.Service;
/**
 *
 * 业务订单
 */
@Service
public class BusinessOrderService {
}

+ 0 - 1
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/wechat/WechatPayService.java

@ -140,6 +140,5 @@ public class WechatPayService {
            rs.put("return_msg","FAIL");
        }
        return rs;
    }
}