Przeglądaj źródła

支付实体类更新

wujunjie 7 lat temu
rodzic
commit
5545d03b96

+ 45 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionPay.java

@ -51,9 +51,54 @@ public class PrescriptionPay extends IdEntity {
    private Integer bdrugPay;//乙类支付金额
    private Integer unlessAmount;//非医保费用
    private Integer exceedAmount;//超封顶线金额
    private Integer accountBalance;//个人账户余额
    private Integer healthBalance;//健康账户余额
    private String recipeContent;//处方主信息
    private String zdlist;//诊断明细
    private String mxlist;//处方明细
    private Date createTime;//续方确认支付时间
    private Date czrq;//续方记录最后操作时间
    public Integer getAccountBalance() {
        return accountBalance;
    }
    public void setAccountBalance(Integer accountBalance) {
        this.accountBalance = accountBalance;
    }
    public Integer getHealthBalance() {
        return healthBalance;
    }
    public void setHealthBalance(Integer healthBalance) {
        this.healthBalance = healthBalance;
    }
    public String getRecipeContent() {
        return recipeContent;
    }
    public void setRecipeContent(String recipeContent) {
        this.recipeContent = recipeContent;
    }
    public String getZdlist() {
        return zdlist;
    }
    public void setZdlist(String zdlist) {
        this.zdlist = zdlist;
    }
    public String getMxlist() {
        return mxlist;
    }
    public void setMxlist(String mxlist) {
        this.mxlist = mxlist;
    }
    public String getCode() {
        return code;
    }

+ 354 - 41
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/entity/prescription/PrescriptionPay.java

@ -14,30 +14,98 @@ import java.util.Date;
@Entity
@Table(name = "wlyy_prescription_pay")
public class PrescriptionPay extends IdEntity {
    private String code;//业务code
    private String payNum;//支付流水号
    private String prescriptionCode;//续方code
    private Date createTime;//创建时间
    private String ybCard;//医保卡号
    private Integer type;// 1 医保支付
    private Integer status;//状态  成功1 失败0
    private Integer ybCost;//统筹金额  单位分
    private Integer myCost;//自费金额  单位分
    public String getCode() {
        return code;
    private String code;//接入应用业务流水号outChargeNo
    private String prescriptionCode;//开处方的医生code 关联 wlyy_prescription
    private Integer type;//1 医保支付
    private Date outChargeTime;//接入应用时间
    private String channel;//支付方式
    private String chargeNo;//支付平台流水号
    private Date chargeTime;//支付平台交易成功时间
    private String billNo;//待结算费用单据号
    private String cardNo;//医保卡号
    private Integer totalAmount;//交易总金额
    private Integer insuranceAmount;//医保支付金额
    private Integer selfPayAmount;//自付金额
    private String openid;//用户openID
    private String userName;//用户名字
    private String idType;//证件类型
    private String idNo;//证件号码
    private String tradeStatus;//交易状态
    private String miSettleNo;//医保收费单据号
    private String miRegisterNo;//医保挂号
    private Date miCollectDate;//收费日期
    private Date miCollectTime;//收费时间
    private String miCollectorName;//收费人姓名
    private Integer miTotalFee;//本次报销总额
    private Integer selfPay;//个人现金支付
    private Integer accountPay;//个人账户支付
    private Integer heathPay;//健康账户支付
    private Integer cadresPay;//公务员补助
    private Integer fundPay;//基金支付
    private Integer healthCarePay;//保健基金支付
    private Integer commercePay;//商业保险支付
    private Integer familyPay;//共济账户支付
    private Integer civilPay;//民政补助金额
    private String civilZone;//民政行政区号
    private Integer bdrugPay;//乙类支付金额
    private Integer unlessAmount;//非医保费用
    private Integer exceedAmount;//超封顶线金额
    private Integer accountBalance;//个人账户余额
    private Integer healthBalance;//健康账户余额
    private String recipeContent;//处方主信息
    private String zdlist;//诊断明细
    private String mxlist;//处方明细
    private Date createTime;//续方确认支付时间
    private Date czrq;//续方记录最后操作时间
    public Integer getAccountBalance() {
        return accountBalance;
    }
    public void setCode(String code) {
        this.code = code;
    public void setAccountBalance(Integer accountBalance) {
        this.accountBalance = accountBalance;
    }
    public Integer getHealthBalance() {
        return healthBalance;
    }
    public void setHealthBalance(Integer healthBalance) {
        this.healthBalance = healthBalance;
    }
    public String getRecipeContent() {
        return recipeContent;
    }
    public void setRecipeContent(String recipeContent) {
        this.recipeContent = recipeContent;
    }
    public String getZdlist() {
        return zdlist;
    }
    public void setZdlist(String zdlist) {
        this.zdlist = zdlist;
    }
    public String getMxlist() {
        return mxlist;
    }
    public void setMxlist(String mxlist) {
        this.mxlist = mxlist;
    }
    public String getPayNum() {
        return payNum;
    public String getCode() {
        return code;
    }
    public void setPayNum(String payNum) {
        this.payNum = payNum;
    public void setCode(String code) {
        this.code = code;
    }
    public String getPrescriptionCode() {
@ -48,52 +116,297 @@ public class PrescriptionPay extends IdEntity {
        this.prescriptionCode = prescriptionCode;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCreateTime() {
        return createTime;
    public Date getOutChargeTime() {
        return outChargeTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    public void setOutChargeTime(Date outChargeTime) {
        this.outChargeTime = outChargeTime;
    }
    public String getYbCard() {
        return ybCard;
    public String getChannel() {
        return channel;
    }
    public void setYbCard(String ybCard) {
        this.ybCard = ybCard;
    public void setChannel(String channel) {
        this.channel = channel;
    }
    public Integer getType() {
        return type;
    public String getChargeNo() {
        return chargeNo;
    }
    public void setType(Integer type) {
        this.type = type;
    public void setChargeNo(String chargeNo) {
        this.chargeNo = chargeNo;
    }
    public Integer getStatus() {
        return status;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getChargeTime() {
        return chargeTime;
    }
    public void setChargeTime(Date chargeTime) {
        this.chargeTime = chargeTime;
    }
    public String getBillNo() {
        return billNo;
    }
    public void setBillNo(String billNo) {
        this.billNo = billNo;
    }
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    public Integer getTotalAmount() {
        return totalAmount;
    }
    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }
    public Integer getInsuranceAmount() {
        return insuranceAmount;
    }
    public void setInsuranceAmount(Integer insuranceAmount) {
        this.insuranceAmount = insuranceAmount;
    }
    public Integer getSelfPayAmount() {
        return selfPayAmount;
    }
    public void setStatus(Integer status) {
        this.status = status;
    public void setSelfPayAmount(Integer selfPayAmount) {
        this.selfPayAmount = selfPayAmount;
    }
    public Integer getYbCost() {
        return ybCost;
    public String getOpenid() {
        return openid;
    }
    public void setYbCost(Integer ybCost) {
        this.ybCost = ybCost;
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    public Integer getMyCost() {
        return myCost;
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getIdType() {
        return idType;
    }
    public void setIdType(String idType) {
        this.idType = idType;
    }
    public String getIdNo() {
        return idNo;
    }
    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }
    public String getTradeStatus() {
        return tradeStatus;
    }
    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }
    public String getMiSettleNo() {
        return miSettleNo;
    }
    public void setMiSettleNo(String miSettleNo) {
        this.miSettleNo = miSettleNo;
    }
    public String getMiRegisterNo() {
        return miRegisterNo;
    }
    public void setMiRegisterNo(String miRegisterNo) {
        this.miRegisterNo = miRegisterNo;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getMiCollectDate() {
        return miCollectDate;
    }
    public void setMiCollectDate(Date miCollectDate) {
        this.miCollectDate = miCollectDate;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getMiCollectTime() {
        return miCollectTime;
    }
    public void setMiCollectTime(Date miCollectTime) {
        this.miCollectTime = miCollectTime;
    }
    public String getMiCollectorName() {
        return miCollectorName;
    }
    public void setMiCollectorName(String miCollectorName) {
        this.miCollectorName = miCollectorName;
    }
    public Integer getMiTotalFee() {
        return miTotalFee;
    }
    public void setMiTotalFee(Integer miTotalFee) {
        this.miTotalFee = miTotalFee;
    }
    public Integer getSelfPay() {
        return selfPay;
    }
    public void setSelfPay(Integer selfPay) {
        this.selfPay = selfPay;
    }
    public Integer getAccountPay() {
        return accountPay;
    }
    public void setAccountPay(Integer accountPay) {
        this.accountPay = accountPay;
    }
    public Integer getHeathPay() {
        return heathPay;
    }
    public void setHeathPay(Integer heathPay) {
        this.heathPay = heathPay;
    }
    public Integer getCadresPay() {
        return cadresPay;
    }
    public void setCadresPay(Integer cadresPay) {
        this.cadresPay = cadresPay;
    }
    public Integer getFundPay() {
        return fundPay;
    }
    public void setFundPay(Integer fundPay) {
        this.fundPay = fundPay;
    }
    public Integer getHealthCarePay() {
        return healthCarePay;
    }
    public void setHealthCarePay(Integer healthCarePay) {
        this.healthCarePay = healthCarePay;
    }
    public Integer getCommercePay() {
        return commercePay;
    }
    public void setCommercePay(Integer commercePay) {
        this.commercePay = commercePay;
    }
    public Integer getFamilyPay() {
        return familyPay;
    }
    public void setFamilyPay(Integer familyPay) {
        this.familyPay = familyPay;
    }
    public Integer getCivilPay() {
        return civilPay;
    }
    public void setCivilPay(Integer civilPay) {
        this.civilPay = civilPay;
    }
    public String getCivilZone() {
        return civilZone;
    }
    public void setCivilZone(String civilZone) {
        this.civilZone = civilZone;
    }
    public Integer getBdrugPay() {
        return bdrugPay;
    }
    public void setBdrugPay(Integer bdrugPay) {
        this.bdrugPay = bdrugPay;
    }
    public Integer getUnlessAmount() {
        return unlessAmount;
    }
    public void setUnlessAmount(Integer unlessAmount) {
        this.unlessAmount = unlessAmount;
    }
    public Integer getExceedAmount() {
        return exceedAmount;
    }
    public void setExceedAmount(Integer exceedAmount) {
        this.exceedAmount = exceedAmount;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    public void setMyCost(Integer myCost) {
        this.myCost = myCost;
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 413 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionPay.java

@ -0,0 +1,413 @@
package com.yihu.wlyy.entity.patient.prescription;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by chenweida on 2017/7/26.
 * 处方支付表
 */
@Entity
@Table(name = "wlyy_prescription_pay")
public class PrescriptionPay extends IdEntity {
    private String code;//接入应用业务流水号outChargeNo
    private String prescriptionCode;//开处方的医生code 关联 wlyy_prescription
    private Integer type;//1 医保支付
    private Date outChargeTime;//接入应用时间
    private String channel;//支付方式
    private String chargeNo;//支付平台流水号
    private Date chargeTime;//支付平台交易成功时间
    private String billNo;//待结算费用单据号
    private String cardNo;//医保卡号
    private Integer totalAmount;//交易总金额
    private Integer insuranceAmount;//医保支付金额
    private Integer selfPayAmount;//自付金额
    private String openid;//用户openID
    private String userName;//用户名字
    private String idType;//证件类型
    private String idNo;//证件号码
    private String tradeStatus;//交易状态
    private String miSettleNo;//医保收费单据号
    private String miRegisterNo;//医保挂号
    private Date miCollectDate;//收费日期
    private Date miCollectTime;//收费时间
    private String miCollectorName;//收费人姓名
    private Integer miTotalFee;//本次报销总额
    private Integer selfPay;//个人现金支付
    private Integer accountPay;//个人账户支付
    private Integer heathPay;//健康账户支付
    private Integer cadresPay;//公务员补助
    private Integer fundPay;//基金支付
    private Integer healthCarePay;//保健基金支付
    private Integer commercePay;//商业保险支付
    private Integer familyPay;//共济账户支付
    private Integer civilPay;//民政补助金额
    private String civilZone;//民政行政区号
    private Integer bdrugPay;//乙类支付金额
    private Integer unlessAmount;//非医保费用
    private Integer exceedAmount;//超封顶线金额
    private Integer accountBalance;//个人账户余额
    private Integer healthBalance;//健康账户余额
    private String recipeContent;//处方主信息
    private String zdlist;//诊断明细
    private String mxlist;//处方明细
    private Date createTime;//续方确认支付时间
    private Date czrq;//续方记录最后操作时间
    public Integer getAccountBalance() {
        return accountBalance;
    }
    public void setAccountBalance(Integer accountBalance) {
        this.accountBalance = accountBalance;
    }
    public Integer getHealthBalance() {
        return healthBalance;
    }
    public void setHealthBalance(Integer healthBalance) {
        this.healthBalance = healthBalance;
    }
    public String getRecipeContent() {
        return recipeContent;
    }
    public void setRecipeContent(String recipeContent) {
        this.recipeContent = recipeContent;
    }
    public String getZdlist() {
        return zdlist;
    }
    public void setZdlist(String zdlist) {
        this.zdlist = zdlist;
    }
    public String getMxlist() {
        return mxlist;
    }
    public void setMxlist(String mxlist) {
        this.mxlist = mxlist;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getPrescriptionCode() {
        return prescriptionCode;
    }
    public void setPrescriptionCode(String prescriptionCode) {
        this.prescriptionCode = prescriptionCode;
    }
    public Integer getType() {
        return type;
    }
    public void setType(Integer type) {
        this.type = type;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getOutChargeTime() {
        return outChargeTime;
    }
    public void setOutChargeTime(Date outChargeTime) {
        this.outChargeTime = outChargeTime;
    }
    public String getChannel() {
        return channel;
    }
    public void setChannel(String channel) {
        this.channel = channel;
    }
    public String getChargeNo() {
        return chargeNo;
    }
    public void setChargeNo(String chargeNo) {
        this.chargeNo = chargeNo;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getChargeTime() {
        return chargeTime;
    }
    public void setChargeTime(Date chargeTime) {
        this.chargeTime = chargeTime;
    }
    public String getBillNo() {
        return billNo;
    }
    public void setBillNo(String billNo) {
        this.billNo = billNo;
    }
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    public Integer getTotalAmount() {
        return totalAmount;
    }
    public void setTotalAmount(Integer totalAmount) {
        this.totalAmount = totalAmount;
    }
    public Integer getInsuranceAmount() {
        return insuranceAmount;
    }
    public void setInsuranceAmount(Integer insuranceAmount) {
        this.insuranceAmount = insuranceAmount;
    }
    public Integer getSelfPayAmount() {
        return selfPayAmount;
    }
    public void setSelfPayAmount(Integer selfPayAmount) {
        this.selfPayAmount = selfPayAmount;
    }
    public String getOpenid() {
        return openid;
    }
    public void setOpenid(String openid) {
        this.openid = openid;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getIdType() {
        return idType;
    }
    public void setIdType(String idType) {
        this.idType = idType;
    }
    public String getIdNo() {
        return idNo;
    }
    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }
    public String getTradeStatus() {
        return tradeStatus;
    }
    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }
    public String getMiSettleNo() {
        return miSettleNo;
    }
    public void setMiSettleNo(String miSettleNo) {
        this.miSettleNo = miSettleNo;
    }
    public String getMiRegisterNo() {
        return miRegisterNo;
    }
    public void setMiRegisterNo(String miRegisterNo) {
        this.miRegisterNo = miRegisterNo;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getMiCollectDate() {
        return miCollectDate;
    }
    public void setMiCollectDate(Date miCollectDate) {
        this.miCollectDate = miCollectDate;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getMiCollectTime() {
        return miCollectTime;
    }
    public void setMiCollectTime(Date miCollectTime) {
        this.miCollectTime = miCollectTime;
    }
    public String getMiCollectorName() {
        return miCollectorName;
    }
    public void setMiCollectorName(String miCollectorName) {
        this.miCollectorName = miCollectorName;
    }
    public Integer getMiTotalFee() {
        return miTotalFee;
    }
    public void setMiTotalFee(Integer miTotalFee) {
        this.miTotalFee = miTotalFee;
    }
    public Integer getSelfPay() {
        return selfPay;
    }
    public void setSelfPay(Integer selfPay) {
        this.selfPay = selfPay;
    }
    public Integer getAccountPay() {
        return accountPay;
    }
    public void setAccountPay(Integer accountPay) {
        this.accountPay = accountPay;
    }
    public Integer getHeathPay() {
        return heathPay;
    }
    public void setHeathPay(Integer heathPay) {
        this.heathPay = heathPay;
    }
    public Integer getCadresPay() {
        return cadresPay;
    }
    public void setCadresPay(Integer cadresPay) {
        this.cadresPay = cadresPay;
    }
    public Integer getFundPay() {
        return fundPay;
    }
    public void setFundPay(Integer fundPay) {
        this.fundPay = fundPay;
    }
    public Integer getHealthCarePay() {
        return healthCarePay;
    }
    public void setHealthCarePay(Integer healthCarePay) {
        this.healthCarePay = healthCarePay;
    }
    public Integer getCommercePay() {
        return commercePay;
    }
    public void setCommercePay(Integer commercePay) {
        this.commercePay = commercePay;
    }
    public Integer getFamilyPay() {
        return familyPay;
    }
    public void setFamilyPay(Integer familyPay) {
        this.familyPay = familyPay;
    }
    public Integer getCivilPay() {
        return civilPay;
    }
    public void setCivilPay(Integer civilPay) {
        this.civilPay = civilPay;
    }
    public String getCivilZone() {
        return civilZone;
    }
    public void setCivilZone(String civilZone) {
        this.civilZone = civilZone;
    }
    public Integer getBdrugPay() {
        return bdrugPay;
    }
    public void setBdrugPay(Integer bdrugPay) {
        this.bdrugPay = bdrugPay;
    }
    public Integer getUnlessAmount() {
        return unlessAmount;
    }
    public void setUnlessAmount(Integer unlessAmount) {
        this.unlessAmount = unlessAmount;
    }
    public Integer getExceedAmount() {
        return exceedAmount;
    }
    public void setExceedAmount(Integer exceedAmount) {
        this.exceedAmount = exceedAmount;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 5 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionPayDao.java

@ -12,6 +12,11 @@ import java.util.List;
 * Created by chenweida on 2017/7/27.
 */
public interface PrescriptionPayDao extends PagingAndSortingRepository<PrescriptionPay, Long>, JpaSpecificationExecutor<PrescriptionPay> {
    //    查询已经支付成功的支付记录
    @Query("from PrescriptionPay p where p.prescriptionCode=?1 and p.tradeStatus=1")
    PrescriptionPay findByPrescriptionPay(String prescriptionCode);
    //查询支付记录
    @Query("from PrescriptionPay p where p.prescriptionCode=?1 ")
    PrescriptionPay findByCode(String prescriptionCode);
}

+ 775 - 24
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PatientPrescriptionPayService.java

@ -1,60 +1,811 @@
package com.yihu.wlyy.service.app.prescription;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.organization.Hospital;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.entity.patient.prescription.Prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionPay;
import com.yihu.wlyy.repository.charge.ChargeDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.*;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.third.httplog.LogService;
import com.yihu.wlyy.service.weixin.wxpay.common.Configure;
import com.yihu.wlyy.service.weixin.wxpay.model.BindCard;
import com.yihu.wlyy.service.weixin.wxpay.model.Charge;
import com.yihu.wlyy.service.weixin.wxpay.service.OnePayService;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.wx.OnePayController;
import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
import com.ylzinfo.onepay.sdk.domain.RequestParams;
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
import com.ylzinfo.onepay.sdk.utils.DateUtil;
import com.ylzinfo.onepay.sdk.utils.StringUtil;
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.jdbc.core.JdbcTemplate;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Service;
import org.springframework.util.StreamUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
/**
 * Created by Reece on 2017/7/28/028.
 * 患者支付
 *
 */
@Service
public class PatientPrescriptionPayService extends BaseService {
    //公共配置文件
    Properties systemConf = SystemConf.getInstance().getSystemProperties();
    private static final Logger LOGGER = LoggerFactory.getLogger(OnePayController.class);
    //    各环境对应配置
    @Value("${server.server_url}")
    private String serverUrl;
    @Value("${wechat.accId}")
    private String accId;
    //    Java配置文件 后续删除
    private String signType = "MD5";
    private String encryptType = "AES";
    //    引入实例
    @Autowired
    private Configure config;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private LogService logService;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private OnePayService onePayService;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private PrescriptionPayDao payDao;
    @Autowired
    private ChargeDao chargeDao;
    @Autowired
    private HospitalMappingDao mappingDao;
    @Autowired
    private PrescriptionLogService payLogService;
    @Autowired
    private PrescriptionService prescriptionService;
    @Autowired
    private PrescriptionInfoDao infoDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private HospitalDao hospitalDao;
    @Autowired
    private PrescriptionDao prescriptionDao;
    @Autowired
    private PrescriptionExpressageDao expressageDao;
    /**
     * 患者支付接口
     * 长处方配送信息查询接口
     *
     * @param payInfo
     * @param
     * @return
     */
    public JSONObject charge()throws Exception{
        JSONObject jsonObject = new JSONObject();
        return jsonObject;
    public JSONObject dispatch(String prescriptionCode, String orgCode) throws Exception {
        JSONObject result = new JSONObject();
        List manage = new ArrayList();
        Hospital hospital = hospitalDao.findByCode(orgCode);
        String hostpitalName = hospital.getName();
        String address = hospital.getAddress();
        String streeCode = hospital.getRoadCode();
        String townCode = hospital.getTown();
        String townName = hospital.getTownName();
        String cityCode = hospital.getCity();
        String cityName = hospital.getCityName();
        String provinceCode = hospital.getProvince();
        String provinceName = hospital.getProvinceName();
        List<PrescriptionInfo> prescriptionInfos = infoDao.findByPrescriptionCode(prescriptionCode);
        for (PrescriptionInfo presInfo : prescriptionInfos) {
//            是否冷藏 1是 0否
            int refrigerate = presInfo.getIsRefrigerate();
            if (refrigerate == 1) {
//                只能自取返回签约社区信息
                Map self = new HashMap();
                self.put("code", orgCode);
                self.put("name", hostpitalName);
                self.put("provinceCode", provinceCode);
                self.put("provinceName", provinceName);
                self.put("cityCode", cityCode);
                self.put("cityName", cityName);
                self.put("townCode", townCode);
                self.put("townName", townName);
                self.put("streeCode", streeCode);
                self.put("address", address);
                self.put("type", 1);
                result.put("self", self);
                return result;
            }
        }
        String h = orgCode.substring(0, 8);
        String sql = "SELECT h.`code`,h.`name`,h.`province` provinceCode,h.`province_name` provinceName,h.`city` cityCode ,h.`city_name` cityName," +
                " h.`town` townCode,h.`town_name` townName,h.`road_code` streeCode,h.`address` " +
                " FROM dm_hospital h  " +
                " WHERE h.`code` LIKE '%" + h + "%' AND RIGHT(h.code,2)<>'00' ";
        List<Map<String, Object>> hs = jdbcTemplate.queryForList(sql);
        for (Map<String, Object> hspital : hs) {
            Map temp = new HashMap();
            String code = (String) hspital.get("code");
            String name = (String) hspital.get("name");
            provinceCode = (String) hspital.get("provinceCode");
            provinceName = (String) hspital.get("provinceName");
            cityCode = (String) hspital.get("cityCode");
            cityName = (String) hspital.get("cityName");
            townCode = (String) hspital.get("townCode");
            townName = (String) hspital.get("townName");
            streeCode = (String) hspital.get("streeCode");
            address = (String) hspital.get("address");
            temp.put("code", code);
            temp.put("name", name);
            temp.put("provinceCode", provinceCode);
            temp.put("provinceName", provinceName);
            temp.put("cityCode", cityCode);
            temp.put("cityName", cityName);
            temp.put("townCode", townCode);
            temp.put("townName", townName);
            temp.put("streeCode", streeCode);
            temp.put("address", address);
            manage.add(temp);
        }
        //                社区下没有服务站只能自取或快递
        if (hs == null) {
            Map self = new HashMap();
            self.put("code", orgCode);
            self.put("name", hostpitalName);
            self.put("provinceCode", provinceCode);
            self.put("provinceName", provinceName);
            self.put("cityCode", cityCode);
            self.put("cityName", cityName);
            self.put("townCode", townCode);
            self.put("townName", townName);
            self.put("streeCode", streeCode);
            self.put("address", address);
            self.put("type", 1);
            Map express = new HashMap();
            express.put("type", 2);
            result.put("self", self);
            result.put("express", express);
            return result;
        }
        Map self = new HashMap();
        self.put("code", orgCode);
        self.put("name", hostpitalName);
        self.put("provinceCode", provinceCode);
        self.put("provinceName", provinceName);
        self.put("cityCode", cityCode);
        self.put("cityName", cityName);
        self.put("townCode", townCode);
        self.put("townName", townName);
        self.put("streeCode", streeCode);
        self.put("address", address);
        self.put("type", 1);
        Map express = new HashMap();
        express.put("type", 2);
        Map manager = new HashMap();
        manager.put("codes", manage);
        manager.put("type", 3);
        result.put("self", self);
        result.put("express", express);
        result.put("manager", manager);
        return result;
    }
    /**
     * 患者支付结果查询接口
     * 长处方支付成功前端页面回调接口
     *
     * @param outChargeNo
     * @param
     * @return
     */
    public JSONObject chargeQuery(String outChargeNo)throws Exception{
        JSONObject jsonObject = new JSONObject();
        return jsonObject;
    public void recipeReturnUrl(HttpServletRequest request, HttpServletResponse response, String accessToken) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        Prescription prescription = null;
        int flag = 0;
        Boolean isSuccess = false;
        String error = "";
        String responses = "";
        response.setContentType("text/html;charset=utf-8");
        try {
            //		如:查询显示订单信息
            isSuccess = true;
            flag = 1;
            String appId = request.getParameter("appId");
            String billNo = request.getParameter("billNo");//待结算费用单据号
            String cardNo = request.getParameter("cardNo");//医保卡号
            String channel = request.getParameter("channel");//支付方式
            String chargeNo = request.getParameter("chargeNo");//支付平台流水号
            String chargeTime = request.getParameter("chargeTime");//支付平台交易成功时间
            String idNo = request.getParameter("idNo");//证件号码
            String idType = request.getParameter("idType");//证件类型
            String insuranceAmount = request.getParameter("insuranceAmount");//医保支付金额
            String outChargeNo = request.getParameter("outChargeNo");//接入应用业务流水号
            String outChargeTime = request.getParameter("outChargeTime");//接入应用时间
            String selfPayAmount = request.getParameter("selfPayAmount");//自付金额
            String sign = request.getParameter("sign");
            String signType = request.getParameter("signType");
            String timestamp = request.getParameter("timestamp");
            String totalAmount = request.getParameter("totalAmount");//交易总金额
            String tradeStatus = request.getParameter("tradeStatus");//交易状态
            String userId = request.getParameter("userId");//用户openID
            String userName = request.getParameter("userName");//用户名字
            String result = chargeQuery(outChargeNo, accessToken);//业务出参
            org.json.JSONObject param = new org.json.JSONObject(result);
            String requestParam = param.getString("responseContent");
            org.json.JSONObject responseContents = new org.json.JSONObject(requestParam);//医保结构体
            PrescriptionPay prescriptionPay = payDao.findByCode(outChargeNo);
            if (responseContents != null) {
                String miSettleNo = responseContents.getString("miSettleNo");//医保收费单据号 (医保签约号)
                String miRegisterNo = responseContents.getString("miRegisterNo");//医保挂号
                String miCollectDate = responseContents.getString("miCollectDate");//收费日期
                String miCollectTime = responseContents.getString("miCollectTime");//收费时间
                String miCollectorName = responseContents.getString("miCollectorName");//收费人姓名
                String miTotalFee = responseContents.getString("miTotalFee");//本次报销总额
                String selfPay = responseContents.getString("selfPay");//个人现金支付
                String accountPay = responseContents.getString("accountPay");//个人账户支付
                String heathPay = responseContents.getString("heathPay");//健康账户支付
                String cadresPay = responseContents.getString("cadresPay");//公务员补助
                String fundPay = responseContents.getString("fundPay");//基金支付
                String healthCarePay = responseContents.getString("healthCarePay");//保健基金支付
                String commercePay = responseContents.getString("commercePay");//商业保险支付
                String familyPay = responseContents.getString("familyPay");//共济账户支付
                String civilPay = responseContents.getString("civilPay");//民政补助金额
                String civilZone = responseContents.getString("civilZone");//民政行政区号
                String bdrugPay = responseContents.getString("bdrugPay");//乙类支付金额
                String unlessAmount = responseContents.getString("unlessAmount");//非医保费用
                String exceedAmount = responseContents.getString("exceedAmount");//超封顶线金额
                String accountBalance = responseContents.getString("accountBalance");//个人账户余额
                String healthBalance = responseContents.getString("healthBalance");//健康账户余额
                prescriptionPay.setBillNo(billNo);//待结算费用单据号
                prescriptionPay.setInsuranceAmount(Integer.parseInt(insuranceAmount));//医保支付金额
                prescriptionPay.setSelfPayAmount(Integer.parseInt(selfPayAmount));//自付金额
                prescriptionPay.setMiSettleNo(miSettleNo);//医保收费单据号
                prescriptionPay.setMiRegisterNo(miRegisterNo);//医保挂号
                prescriptionPay.setMiCollectDate(format.parse(miCollectDate));//收费日期
                prescriptionPay.setMiCollectTime(format.parse(miCollectTime));//收费时间
                prescriptionPay.setMiCollectorName(miCollectorName);//收费人姓名
                prescriptionPay.setMiTotalFee(Integer.parseInt(miTotalFee));//本次报销总额
                prescriptionPay.setSelfPay(Integer.parseInt(selfPay));//个人现金支付
                prescriptionPay.setAccountPay(Integer.parseInt(accountPay));//个人账户支付
                prescriptionPay.setHeathPay(Integer.parseInt(heathPay));//健康账户支付
                prescriptionPay.setCadresPay(Integer.parseInt(cadresPay));//公务员补助
                prescriptionPay.setFundPay(Integer.parseInt(fundPay));//基金支付
                prescriptionPay.setHealthCarePay(Integer.parseInt(healthCarePay));//保健基金支付
                prescriptionPay.setCommercePay(Integer.parseInt(commercePay));//商业保险支付
                prescriptionPay.setFamilyPay(Integer.parseInt(familyPay));//共济账户支付
                prescriptionPay.setCivilPay(Integer.parseInt(civilPay));//民政补助金额
                prescriptionPay.setCivilZone(civilZone);//民政行政区号
                prescriptionPay.setBdrugPay(Integer.parseInt(bdrugPay));//乙类支付金额
                prescriptionPay.setUnlessAmount(Integer.parseInt(unlessAmount));//非医保费用
                prescriptionPay.setExceedAmount(Integer.parseInt(exceedAmount));//超封顶线金额
                prescriptionPay.setAccountBalance(Integer.parseInt(accountBalance));//个人账户余额
                prescriptionPay.setHealthBalance(Integer.parseInt(healthBalance));//健康账户余额
                //        保存数据库更改记录
                payDao.save(prescriptionPay);
            }
            String prescriptionCode = prescriptionPay.getPrescriptionCode();
            prescription = prescriptionDao.findByCode(prescriptionCode);
            PrescriptionExpressage expressage = expressageDao.findByPrescriptionPay(prescriptionCode);
            if ("0".equals(tradeStatus)) {
                prescriptionPay.setTradeStatus("1");//交易状态 成功1 失败0
                prescription.setStatus(30);//续费状态 30支付成功 21支付失败
                expressage.setDel(1);//快递信息状态 1可用 0删除
                expressageDao.save(expressage);
                prescriptionDao.save(prescription);
            } else if ("1".equals(tradeStatus)) {
                prescriptionPay.setTradeStatus("0");//交易状态 成功1 失败0
                prescription.setStatus(21);////续费状态 30支付成功 21支付失败
                expressage.setDel(0);//快递信息状态 1可用 0删除
                expressageDao.save(expressage);
                prescriptionDao.save(prescription);
            }
        } catch (Exception e) {
            isSuccess = false;
            response.getWriter().write(e.getMessage());
        }
        //                记录log日志到数据库
        logService.saveHttpLog(isSuccess, config.getReturnUrl(), "长处方支付页面跳转", "POST", null, "", responses, error, logService.onepayType);
        //记录支付log日志到数据库
        payLogService.addLog(prescription, 2, flag, 1);
    }
    /**
     * 支付成功前端页面回调接口
     * 长处方对接方异步回调接口
     *
     * @param json
     * @return
     */
    public JSONObject returnUrl()throws Exception{
        JSONObject jsonObject = new JSONObject();
        return jsonObject;
    public void receiveRecipeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        Prescription prescription = null;
        Boolean isSuccess = false;
        int flag = 0;
        String error = "";
        String responses = "";
        response.setContentType("text/html;charset=utf-8");
        InputStream inputStream = request.getInputStream();
        String params = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8"));
        org.json.JSONObject json = new org.json.JSONObject(params);
        String appId = json.getString("appId");
        HospitalMapping hospital = mappingDao.findByAppId(appId);
        String appSecret = hospital.getAppSecret();
        LOGGER.info("回调参数:{}", params);
        if (StringUtil.isEmpty(params)) {
            response.getWriter().write("empty");
            return;
        }
        // 参数转换
        ResponseParams<?> encryptRes = JSON.parseObject(params, ResponseParams.class);
        OnepayDefaultClient client = new OnepayDefaultClient("", appId, appSecret, encryptRes.getSignType(), encryptRes.getEncryptType());
        try {
            LOGGER.info("解密前:{}", JSON.toJSONString(encryptRes));
            ResponseParams<?> decryptRes = client.decryptNotifyResponse(encryptRes);
            LOGGER.info("解密后:{}", JSON.toJSONString(decryptRes));
            boolean isDecrypt = ("-1".equals(decryptRes.getRespCode()) ? false : true); // 是否解密失败
            if (!isDecrypt) {
                response.getWriter().write("DECRYPT FAILURE");
            } else {
                boolean isVerify = client.verifyResponseSign(decryptRes);
                LOGGER.info("验签结果:{}", isVerify);
                if (!isVerify) {
                    response.getWriter().write("FAILURE");
                } else {
//					业务逻辑代码
                    flag = 1;
                    isSuccess = true;
                    responses = JSON.toJSONString(decryptRes);
                    org.json.JSONObject requestParams = new org.json.JSONObject(responses);
                    org.json.JSONObject requestParam = requestParams.getJSONObject("param");//业务出参
                    String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
                    String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
                    String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
                    String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
                    String channel = requestParam.getString("channel");//支付方式
                    String billNo = requestParam.getString("billNo");//待结算费用单据号
                    String cardNo = requestParam.getString("cardNo");//医保卡号
                    String totalAmount = requestParam.getString("totalAmount");//交易总金额
                    String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
                    String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
                    String userId = requestParam.getString("userId");//用户openID
                    String userName = requestParam.getString("userName");//用户名字
                    String idType = requestParam.getString("idType");//证件类型
                    String idNo = requestParam.getString("idNo");//证件号码
                    String tradeStatus = requestParam.getString("tradeStatus");//交易状态
                    org.json.JSONObject responseContents = requestParams.getJSONObject("responseContent");//医保结构体
                    String miSettleNo = responseContents.getString("miSettleNo");//医保收费单据号 (医保签约号)
                    String miRegisterNo = responseContents.getString("miRegisterNo");//医保挂号
                    String miCollectDate = responseContents.getString("miCollectDate");//收费日期
                    String miCollectTime = responseContents.getString("miCollectTime");//收费时间
                    String miCollectorName = responseContents.getString("miCollectorName");//收费人姓名
                    String miTotalFee = responseContents.getString("miTotalFee");//本次报销总额
                    String selfPay = responseContents.getString("selfPay");//个人现金支付
                    String accountPay = responseContents.getString("accountPay");//个人账户支付
                    String heathPay = responseContents.getString("heathPay");//健康账户支付
                    String cadresPay = responseContents.getString("cadresPay");//公务员补助
                    String fundPay = responseContents.getString("fundPay");//基金支付
                    String healthCarePay = responseContents.getString("healthCarePay");//保健基金支付
                    String commercePay = responseContents.getString("commercePay");//商业保险支付
                    String familyPay = responseContents.getString("familyPay");//共济账户支付
                    String civilPay = responseContents.getString("civilPay");//民政补助金额
                    String civilZone = responseContents.getString("civilZone");//民政行政区号
                    String bdrugPay = responseContents.getString("bdrugPay");//乙类支付金额
                    String unlessAmount = responseContents.getString("unlessAmount");//非医保费用
                    String exceedAmount = responseContents.getString("exceedAmount");//超封顶线金额
                    String accountBalance = responseContents.getString("accountBalance");//个人账户余额
                    String healthBalance = responseContents.getString("healthBalance");//健康账户余额
                    //更新数据
                    PrescriptionPay prescriptionPay = payDao.findByCode(outChargeNo);
                    prescriptionPay.setBillNo(billNo);//待结算费用单据号
                    prescriptionPay.setInsuranceAmount(Integer.parseInt(insuranceAmount));//医保支付金额
                    prescriptionPay.setSelfPayAmount(Integer.parseInt(selfPayAmount));//自付金额
                    prescriptionPay.setMiSettleNo(miSettleNo);//医保收费单据号
                    prescriptionPay.setMiRegisterNo(miRegisterNo);//医保挂号
                    prescriptionPay.setMiCollectDate(format.parse(miCollectDate));//收费日期
                    prescriptionPay.setMiCollectTime(format.parse(miCollectTime));//收费时间
                    prescriptionPay.setMiCollectorName(miCollectorName);//收费人姓名
                    prescriptionPay.setMiTotalFee(Integer.parseInt(miTotalFee));//本次报销总额
                    prescriptionPay.setSelfPay(Integer.parseInt(selfPay));//个人现金支付
                    prescriptionPay.setAccountPay(Integer.parseInt(accountPay));//个人账户支付
                    prescriptionPay.setHeathPay(Integer.parseInt(heathPay));//健康账户支付
                    prescriptionPay.setCadresPay(Integer.parseInt(cadresPay));//公务员补助
                    prescriptionPay.setFundPay(Integer.parseInt(fundPay));//基金支付
                    prescriptionPay.setHealthCarePay(Integer.parseInt(healthCarePay));//保健基金支付
                    prescriptionPay.setCommercePay(Integer.parseInt(commercePay));//商业保险支付
                    prescriptionPay.setFamilyPay(Integer.parseInt(familyPay));//共济账户支付
                    prescriptionPay.setCivilPay(Integer.parseInt(civilPay));//民政补助金额
                    prescriptionPay.setCivilZone(civilZone);//民政行政区号
                    prescriptionPay.setBdrugPay(Integer.parseInt(bdrugPay));//乙类支付金额
                    prescriptionPay.setUnlessAmount(Integer.parseInt(unlessAmount));//非医保费用
                    prescriptionPay.setExceedAmount(Integer.parseInt(exceedAmount));//超封顶线金额
                    prescriptionPay.setAccountBalance(Integer.parseInt(accountBalance));//个人账户余额
                    prescriptionPay.setHealthBalance(Integer.parseInt(healthBalance));//健康账户余额
                    String prescriptionCode = prescriptionPay.getPrescriptionCode();
                    prescription = prescriptionDao.findByCode(prescriptionCode);
                    PrescriptionExpressage expressage = expressageDao.findByPrescriptionPay(prescriptionCode);
                    if ("0".equals(tradeStatus)) {
                        prescriptionPay.setTradeStatus("1");//交易状态 成功1 失败0
                        prescription.setStatus(30);//续费状态 30支付成功 21支付失败
                        expressage.setDel(1);//快递信息状态 1可用 0删除
                        expressageDao.save(expressage);
                        prescriptionDao.save(prescription);
                    } else if ("1".equals(tradeStatus)) {
                        prescriptionPay.setTradeStatus("0");//交易状态 成功1 失败0
                        prescription.setStatus(21);////续费状态 30支付成功 21支付失败
                        expressage.setDel(0);//快递信息状态 1可用 0删除
                        expressageDao.save(expressage);
                        prescriptionDao.save(prescription);
                    }
                    //        保存数据库更改记录
                    payDao.save(prescriptionPay);
                    response.getWriter().write("SUCCESS");
                }
            }
        } catch (Exception e) {
            response.getWriter().write(e.getMessage());
        }
        //                记录log日志到数据库
        logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
        //记录支付log日志到数据库
        payLogService.addLog(prescription, 2, flag, 1);
    }
    //******************************************  反射获取私有属性基本工具方法  *******************************************************************************
    public BindCard getBindCard(Object obj, String openId) throws Exception {
        Class cls = obj.getClass();
        //获得类的私有方法
        Method method = cls.getDeclaredMethod("privateMethod", null);
        method.setAccessible(true); //没有设置就会报错
        //调用该方法
        BindCard bindCard = (BindCard) method.invoke(obj, openId);
        return bindCard;
    }
//******************************************  长处方支付基本工具方法  *******************************************************************************
    /**
     * 对接方异步回调接口
     *
     * @return
     * 长处方支付,成功则返回支付路径
     */
    @Transactional
    public String charge(int type, String addressJson, String orgCode, String prescriptionCode, int totalAmount, String people, String accessToken) throws Exception {
        //获取机构映射
        HospitalMapping hos = mappingDao.findByCode(orgCode);
        if (hos == null) {
            throw new Exception("no hospital mapping!");
        }
        String orgName = hos.getName();
        String appId = hos.getAppId();
        String appSecret = hos.getAppSecret();
        Patient patient = patientDao.findByCode(people);
        String userName = patient.getName();
        String openid = patient.getOpenid();
        String userAddress = patient.getAddress();
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        Date now = new Date();
        Boolean isSuccess = true;
        int flag = 1;
        String msgBody = "";
        String response = "";
        String error = "";
        String result = "";
        String channel = "WX_MMP";   //  医保支付渠道
        String subject = "续方订单支付";   //  订单名称
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
//     未真正完成支付以前预存储支付信息到wlyy_prescription_pay表 更改wlyy_prescription表支付时间  wlyy_prescription_expressage 新增物流记录
        PrescriptionExpressage expressage = new PrescriptionExpressage();
        expressage.setCode(getCode());
        expressage.setPrescriptionCode(prescriptionCode);
        JSONObject addressInfo = JSON.parseObject(addressJson);
        String phone = addressInfo.getString("phone");
        expressage.setMobile(phone);//收货人手机号码
        String proviceCode = addressInfo.getString("provinceCode");
        expressage.setProvinceCode(proviceCode);//省代码
        String proviceName = addressInfo.getString("provinceName");
        expressage.setProvinceName(proviceName);//省名称
        String cityCode = addressInfo.getString("cityCode");
        expressage.setCityCode(cityCode);//市代码
        String cityName = addressInfo.getString("cityName");
        expressage.setCityName(cityName);//市名称
        String townCode = addressInfo.getString("townCode");
        expressage.setTownCode(townCode);//区code
        String townName = addressInfo.getString("townName");
        expressage.setTownName(townName);//区名称
        String streeCode = addressInfo.getString("streeCode");
        expressage.setStreetCode(streeCode);//街道code
        String streeName = addressInfo.getString("streeName");
        expressage.setStreetName(streeName);//街道名称
        String address = addressInfo.getString("address");
        expressage.setHospitalAddress(address);//取药地址
        switch (type) {
            case 1:
                //自取保存居民信息
                expressage.setName(userName);//居民姓名
                expressage.setAddress(userAddress);//居民详细地址
                expressage.setHospitalCode(orgCode);//机构code
                expressage.setHospitalName(hos.getName());//取药点
                expressage.setCreateTime(now);//创建时间
                expressage.setOneselfPickupFlg(1);//是否自取 1是 0否
                expressage.setDel(1);//有效
                break;
            case 2:
                //快递保存信息
                String name = addressInfo.getString("receiver");
                expressage.setName(name);//居民姓名
                expressage.setHospitalCode(orgCode);//机构code
                expressage.setHospitalName("顺丰快递");//取药点
//                expressage.setHospitalAddress("5");//取药地址
                expressage.setCreateTime(now);//创建时间
                expressage.setOneselfPickupFlg(0);//是否自取 1是 0否
                expressage.setDel(1);//有效
                break;
            case 3:
                //健管师配送
                expressage.setName(userName);//收件人姓名
                String orgCodess = addressInfo.getString("code");
                expressage.setHospitalCode(orgCodess);//机构code
                String orgNames = addressInfo.getString("name");
                expressage.setHospitalName(orgNames);//取药点
                expressage.setCreateTime(now);//创建时间
                expressage.setOneselfPickupFlg(0);//是否自取 1是 0否
                expressage.setDel(1);//有效
                break;
        }
        Prescription prescription = prescriptionDao.findByCode(prescriptionCode);
        prescription.setPayTime(now);
        PrescriptionPay prescriptionPay = new PrescriptionPay();
//        居民信息
        prescriptionPay.setCode(uuid);  //  接入应用支付业务流水号
        prescriptionPay.setPrescriptionCode(prescriptionCode);   //开处方的医生code 关联 wlyy_prescription
        prescriptionPay.setType(1);//支付方式 1 医保支付
        prescriptionPay.setOutChargeTime(new Date());//接入应用时间
        prescriptionPay.setChannel(channel);//支付方式
        prescriptionPay.setChargeTime(new Date());//预支付时间
        prescriptionPay.setOpenid(openid);     //  用戶微信openid
        prescriptionPay.setTotalAmount(totalAmount);//交易总金额
        prescriptionPay.setCreateTime(now);
        prescriptionPay.setCzrq(now);
        try {
            BindCard card = getBindCard(onePayService, openid);
            String name = card.getAttachName();
            String ssc = card.getAttachCardNo();
            String idType = card.getAttachIdType();
            String idNo = card.getAttachIdNo();
            prescriptionPay.setCardNo(ssc);//医保卡号
            prescriptionPay.setUserName(name);//用户名字
            prescriptionPay.setIdType(idType);//证件类型
            prescriptionPay.setIdNo(idNo);//证件号码
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
            String currentDateTime = formatter.format(now);
            RequestParams requestParams = new RequestParams();
//            长处方结算入参
//            requestParams.setVersion();
//            requestParams.setSign();
//            requestParams.setEncryptData();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(currentDateTime);
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTransType(config.getChargeType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outChargeNo", uuid);  //接入应用结算业务流水号
            params.put("outChargeTime", currentDateTime);    //接入应用内结算时间
            params.put("userId", openid);   //用户 ID
            params.put("cardNo", ssc);   //医保卡号"D64775061"
            //获取绑卡信息
            params.put("userName", name);
            params.put("idType", idType);
            params.put("idNo", idNo);
            params.put("totalAmount", Integer.toString(totalAmount));   //处方总金额
            Properties systemConf = SystemConf.getInstance().getSystemProperties();
            String returnUrl = systemConf.getProperty("return_url");
            returnUrl = returnUrl.replace("{server}", serverUrl);
            params.put("returnUrl", returnUrl);   //长处方页面跳转地址
            params.put("channel", channel);  //微信医保支付
            params.put("merchName", orgName);  //收款单位名称
            params.put("subject", subject);  //订单名称
            params.put("wxToken", accessToken);
            JSONObject jsonParams = prescriptionService.getPayInfo(prescriptionCode);
            JSONObject recipe = jsonParams.getJSONObject("recipeContent");
            params.put("recipeContent", recipe);// 处方主信息
            prescriptionPay.setRecipeContent(recipe.toJSONString());//处方主信息
            JSONObject zdContent = jsonParams.getJSONObject("zdlist");
            params.put("zdlist", zdContent);// 诊断明细
            prescriptionPay.setZdlist(zdContent.toJSONString());//诊断明细
            JSONObject mxContent = jsonParams.getJSONObject("mxlist");
            params.put("mxlist", mxContent);//处方明细
            prescriptionPay.setMxlist(mxContent.toJSONString());//处方明细
            Map<String, String> map = new HashMap<>();//请求结构体
            map.put("feeType", "06");//长处方结算
            map.put("settleType", "01"); //诊间医保结算
            params.put("requestContent", objectMapper.writeValueAsString(map));// 请求结构体
            requestParams.setParam(params);
            msgBody = JSON.toJSONString(requestParams);
            //执行支付  获取预支付原生返回值
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            response = JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                JSONObject json = res.getParam();
                String chargeNo = String.valueOf(json.get("chargeNo"));      //医保结算业务流水号
                result = String.valueOf(json.get("payUrl"));
                prescriptionPay.setChargeNo(chargeNo);//支付后返回的流水号
            } else {
                isSuccess = false;
                flag = 0;
                error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
            }
        } catch (Exception ex) {
            isSuccess = false;
            flag = 0;
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            error = sw.toString();
        }
        //保存交易记录
        payDao.save(prescriptionPay);
        //保存续方更改消息
        prescriptionDao.save(prescription);
        //保存物流信息
        expressageDao.save(expressage);
        //保存http日志
        logService.saveHttpLog(isSuccess, config.getRecipeChargeType(), "长处方结算", "POST", null, msgBody, response, error, logService.onepayType);
        //保存长处方日志  type=2易联众对接 flag =1成功 flag=0 0失败 userType 1 患者 2医生
        payLogService.addLog(prescription, 2, flag, 1);
        if (!isSuccess) {
            throw new Exception(error);
        }
        return result;
    }
//******************************************  支付查询基本工具方法  *******************************************************************************
    /**
     * 家庭医生签约支付查询
     */
    public JSONObject receiveNotify() throws Exception{
        JSONObject jsonObject = new JSONObject();
        return jsonObject;
    public String chargeQuery(String code, String accessToken) throws Exception {
        int flag =0;
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        String result = null;
        WlyyCharge charge = chargeDao.findByCode(code);
        HospitalMapping hospitalMapping = mappingDao.findByCode(charge.getHospital());
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), hospitalMapping.getAppId(), hospitalMapping.getAppSecret(), signType, encryptType);
        try {
            RequestParams requestParams = new RequestParams();
//            requestParams.setVersion();
//            requestParams.setSign();
//            requestParams.setEncryptData();
//            requestParams.setAppId(appId);
            requestParams.setAppId(hospitalMapping.getAppId());
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTransType(config.getChargeQueryType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outChargeNo", code);  //接入应用结算业务流水号
            params.put("wxToken", accessToken);
            requestParams.setParam(params);
            msgBody = JSON.toJSONString(requestParams);
            //执行支付 返回原生返回值
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            response = JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                //业务处理*******************
//                只返回业务出参
//                result = JSON.toJavaObject(res.getParam(), Charge.class);
                flag = 1;
                result = JSON.toJSONString(res.getParam());
//                 返回医保机构体
                LOGGER.info("请求成功,返回参数: " + result);
            } else {
                isSuccess = false;
                error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
            }
        } catch (Exception ex) {
            isSuccess = false;
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            ex.printStackTrace(pw);
            error = sw.toString();
        }
        //type = 3易联众接口保存http日志
        logService.saveHttpLog(isSuccess, config.getRecipeChargeType(), "长处方支付查询", "POST", null, msgBody, response, error, logService.onepayType);
        if (!isSuccess) {
            throw new Exception(error);
        }
        return result;
    }
//基卫接口
//    第三方快递接口
}

+ 28 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/common/Configure.java

@ -27,6 +27,34 @@ public class Configure {
//	易联众异步回调
	private String receiveNotify = "wlyy.onepay.receiveNotify";
	private String returnUrl = "wlyy.onepay.returnUrl";
//  长处方系列
	private String recipeChargeType = "onepay.trade.long.recipe.charge";
	private String recipeReturnUrl = "wlyy.patient.prescription.pay.recipeReturnUrl";
	private String receiveRecipeNotify = "wlyy.patient.prescription.pay.receiveRecipeNotify";
	public String getRecipeChargeType() {
		return recipeChargeType;
	}
	public void setRecipeChargeType(String recipeChargeType) {
		this.recipeChargeType = recipeChargeType;
	}
	public String getRecipeReturnUrl() {
		return recipeReturnUrl;
	}
	public void setRecipeReturnUrl(String recipeReturnUrl) {
		this.recipeReturnUrl = recipeReturnUrl;
	}
	public String getReceiveRecipeNotify() {
		return receiveRecipeNotify;
	}
	public void setReceiveRecipeNotify(String receiveRecipeNotify) {
		this.receiveRecipeNotify = receiveRecipeNotify;
	}
	public String getReturnUrl() {
		return returnUrl;

+ 65 - 31
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/prescription/PatientPrescriptionPayController.java

@ -1,6 +1,7 @@
package com.yihu.wlyy.web.patient.prescription;
import com.yihu.wlyy.service.app.prescription.PatientPrescriptionPayService;
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -8,13 +9,12 @@ import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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 org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
 * Created by Reece on 2017/7/28.
@ -29,55 +29,89 @@ public class PatientPrescriptionPayController extends WeixinBaseController {
    private PatientPrescriptionPayService payService;
    /**
     * 患者支付接口
     * 患者长处方支付接口 可配送方式查询
     *
     * @param payInfo
     * @param orgCode 居民签约社区code
     * @param prescriptionCode 续方code
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/charge", method = RequestMethod.POST)
    @ApiOperation(value = "患者支付接口")
    public String charge(@RequestParam(required = true) @ApiParam(value = "支付数据", name = "payInfo") String payInfo) throws  Exception{
    @RequestMapping(value = "/dispatch", method = RequestMethod.POST)
    @ApiOperation(value = "配送方式查询接口")
    public String dispatch(
            @RequestParam(required = true) @ApiParam(value = "续方code", name = "prescriptionCode") String prescriptionCode,
            @RequestParam(required = true) @ApiParam(value = "居民签约社区code", name = "orgCode") String orgCode) throws Exception {
        try {
            JSONObject json = new JSONObject(payInfo);
            JSONObject patientInfo = json.getJSONObject("patientInfo");
            JSONObject expressageInfo = json.getJSONObject("expressageInfo");
            JSONObject prescriptionInfo = json.getJSONObject("prescriptionInfo");
            JSONObject totalAmount = json.getJSONObject("totalAmount");
            payService.charge();
                return error(-1, "获取失败");
            com.alibaba.fastjson.JSONObject result = payService.dispatch(prescriptionCode,orgCode);
            return write(200, "获取成功","data",result);
        } catch (Exception e) {
            return error(-1, "获取失败");
        }
    }
    /**
     * 患者支付结果查询接口
     * 患者长处方支付接口
     *
     * @param orgCode          患者签约医院code
     * @param prescriptionCode 续方code
     * @param type             配送方式 1:自取 2:快递 3:健管师配送
     * @param addressJson      配送信息json
     * @param totalAmount      订单总金额
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/recipeCharge", method = RequestMethod.POST)
    @ApiOperation(value = "患者长处方支付接口")
    public String recipeCharge(
            @RequestParam(required = true) @ApiParam(value = "居民社区code", name = "orgCode") String orgCode,
            @RequestParam(required = true) @ApiParam(value = "续方code", name = "prescriptionCode") String prescriptionCode,
            @RequestParam(required = true) @ApiParam(value = "配送方式", name = "type") int type,
            @RequestParam(required = true) @ApiParam(value = "配送地址json", name = "addressJson",defaultValue = "{\"townName\":\"海沧区\",\"code\":\"3502050100\",\"address\":" +
                    "\"冰岛\",\"cityName\":\"厦门市\",\"townCode\":\"350205\",\"provinceCode\":\"350000\",\"cityCode\":\"350200\",\"name\":\"海沧区嵩屿街道社区卫生服务中心\"," +
                    "\"provinceName\":\"福建省\",\"streeCode\":\"35020501\",\"streeName\":\"皇后大道东\",\"phone\":\"13253541190\"}") String addressJson,
            @RequestParam(required = true) @ApiParam(value = "订单总金额", name = "totalAmount") int totalAmount) throws Exception {
        try {
            String accessToken = getAccessToken();
            String patient = getUID();
            payService.charge(type,addressJson,orgCode, prescriptionCode, totalAmount, patient, accessToken);
            return error(-1, "获取失败");
        } catch (Exception e) {
            return error(-1, "获取失败");
        }
    }
    /**
     * 患者家签及长处方支付结果查询接口
     *
     * @param outChargeNo
     * @return
     */
    @RequestMapping(value = "/chargeQuery", method = RequestMethod.GET)
    @RequestMapping(value = "/recipeChargeQuery", method = RequestMethod.GET)
    @ApiOperation(value = "患者支付结果查询接口")
    public String chargeQuery(@RequestParam(required = true) @ApiParam(value = "支付应用流水号", name = "outChargeNo") String outChargeNo) throws  Exception{
    public String chargeQuery(@RequestParam(required = true) @ApiParam(value = "支付应用流水号", name = "outChargeNo") String outChargeNo) throws Exception {
        try {
            payService.chargeQuery(outChargeNo);
            String accessToken = getAccessToken();
            payService.chargeQuery(outChargeNo, accessToken);
            return error(-1, "获取失败");
        } catch (Exception e) {
            return error(-1, "获取失败");
        }
    }
    /**
     * 支付成功前端页面回调接口
     * 长处方支付成功前端页面回调接口
     *
     * @param json
     * @param
     * @return
     */
    @RequestMapping(value = "/returnUrl", method = RequestMethod.GET)
    @RequestMapping(value = "/recipeReturnUrl", method = RequestMethod.POST)
    @ApiOperation(value = "支付成功前端页面回调接口")
    public String returnUrl(String json) throws Exception{
    public String recipeReturnUrl(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            payService.returnUrl();
            String accessToken = getAccessToken();
            payService.recipeReturnUrl(request, response, accessToken);
            return error(-1, "获取失败");
        } catch (Exception e) {
            return error(-1, "获取失败");
@ -85,18 +119,18 @@ public class PatientPrescriptionPayController extends WeixinBaseController {
    }
    /**
     * 对接方异步回调接口
     * 长处方对接方异步回调接口
     *
     * @return
     */
    @RequestMapping(value = "/receiveNotify", method = RequestMethod.GET)
    @RequestMapping(value = "/receiveRecipeNotify", method = RequestMethod.POST)
    @ApiOperation(value = "对接方异步回调接口")
    public String receiveNotify(HttpServletRequest request, HttpServletResponse response) throws Exception{
    public String receiveRecipeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            payService.receiveNotify();
            return error(-1, "获取失败");
            payService.receiveRecipeNotify(request, response);
            return error(200, "回调成功!");
        } catch (Exception e) {
            return error(-1, "获取失败");
            return error(-1, "回调失败!");
        }
    }