Bladeren bron

统一支付功能

hzp 7 jaren geleden
bovenliggende
commit
f80febbca1

+ 21 - 12
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/charge/WlyyCharge.java

@ -15,8 +15,9 @@ import java.util.Date;
@Table(name = "wlyy_charge")
@Table(name = "wlyy_charge")
public class WlyyCharge extends IdEntity {
public class WlyyCharge extends IdEntity {
	private String signCode;   //签约代码
	private String code;   //  接入应用支付业务流水号
	private String code;   //  接入应用支付业务流水号
	private String chargeType;   //交易类型  1签约 2续签
	private String chargeRelation;   //交易关联代码
	private Date createTime;   //  接入应用内支付时间
	private Date createTime;   //  接入应用内支付时间
	private String patient;   //  用户
	private String patient;   //  用户
	private String openid;   //  用戶微信openid
	private String openid;   //  用戶微信openid
@ -29,23 +30,32 @@ public class WlyyCharge extends IdEntity {
	private Integer totalAmount;   //  交易总金额
	private Integer totalAmount;   //  交易总金额
	private Integer selfpayAmount;   //  自费金额
	private Integer selfpayAmount;   //  自费金额
	private Integer insuranceAmount;   //  医保支付金额
	private Integer insuranceAmount;   //  医保支付金额
	private Integer feeDetail;   //  费用明细
	private String feeDetail;   //  费用明细
	private String channel;   //  医保支付渠道
	private String channel;   //  医保支付渠道
	private String merchName;   //  收款单位名称
	private String merchName;   //  收款单位名称
	private String subject;   //  订单名称
	private String subject;   //  订单名称
	private String tradeStatus;   //  交易状态0 成功 1 失败 2 已退款
	private String tradeStatus;   //  交易状态0 成功 1 失败 2 已退款
	private String chargeNo;   //  流水号
	private String chargeNo;   //  流水号
	private Date chargeTime;   // 扣费时间
	private String chargeTime;   // 扣费时间YYYYMMDDHHMMSS
	private String medOrgNo;   //  医疗机构编码
	private String medOrgNo;   //  医疗机构编码
	private String medOrgName;   //  医疗机构名称
	private String medOrgName;   //  医疗机构名称
	private String billNo;   //  待结算费用单据号
	private String billNo;   //  待结算费用单据号
	public String getSignCode() {
		return signCode;
	public String getChargeType() {
		return chargeType;
	}
	public void setChargeType(String chargeType) {
		this.chargeType = chargeType;
	}
	}
	public void setSignCode(String signCode) {
		this.signCode = signCode;
	public String getChargeRelation() {
		return chargeRelation;
	}
	public void setChargeRelation(String chargeRelation) {
		this.chargeRelation = chargeRelation;
	}
	}
	public String getCode() {
	public String getCode() {
@ -153,11 +163,11 @@ public class WlyyCharge extends IdEntity {
		this.insuranceAmount = insuranceAmount;
		this.insuranceAmount = insuranceAmount;
	}
	}
	public Integer getFeeDetail() {
	public String getFeeDetail() {
		return feeDetail;
		return feeDetail;
	}
	}
	public void setFeeDetail(Integer feeDetail) {
	public void setFeeDetail(String feeDetail) {
		this.feeDetail = feeDetail;
		this.feeDetail = feeDetail;
	}
	}
@ -201,12 +211,11 @@ public class WlyyCharge extends IdEntity {
		this.chargeNo = chargeNo;
		this.chargeNo = chargeNo;
	}
	}
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getChargeTime() {
	public String getChargeTime() {
		return chargeTime;
		return chargeTime;
	}
	}
	public void setChargeTime(Date chargeTime) {
	public void setChargeTime(String chargeTime) {
		this.chargeTime = chargeTime;
		this.chargeTime = chargeTime;
	}
	}

+ 6 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/charge/ChargeDao.java

@ -6,10 +6,15 @@
package com.yihu.wlyy.repository.charge;
package com.yihu.wlyy.repository.charge;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface ChargeDao extends PagingAndSortingRepository<WlyyCharge, Long>, JpaSpecificationExecutor<WlyyCharge> {
public interface ChargeDao extends PagingAndSortingRepository<WlyyCharge, Long>, JpaSpecificationExecutor<WlyyCharge> {
	
    List<WlyyCharge> findByChargeTypeAndChargeRelation(String chargeType,String chargeRelation);
    List<WlyyCharge> findByPatient(String patient, Pageable pageRequest);
}
}

+ 77 - 17
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/service/OnePayService.java

@ -18,16 +18,15 @@ import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
import com.ylzinfo.onepay.sdk.domain.RequestParams;
import com.ylzinfo.onepay.sdk.domain.RequestParams;
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
import com.ylzinfo.onepay.sdk.utils.DateUtil;
import com.ylzinfo.onepay.sdk.utils.DateUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.StringWriter;
import java.text.SimpleDateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
/**
/**
 * 易联众统一支付服务类
 * 易联众统一支付服务类
@ -150,7 +149,7 @@ public class OnePayService {
    /**
    /**
     * 家庭医生签约支付
     * 家庭医生签约支付
     */
     */
    public String charge(String orgCode,String signCode,String patient,String openid) throws Exception
    public String charge(String orgCode,String chargeType,String chargeRelation,Integer totalAmount,Integer selfpayAmount,Integer insuranceAmount,String feeDetail,String patient,String openid) throws Exception
    {
    {
        //获取机构映射
        //获取机构映射
        HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
        HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
@ -159,13 +158,13 @@ public class OnePayService {
            throw new Exception("no hospital mapping!");
            throw new Exception("no hospital mapping!");
        }
        }
        return charge(orgCode,hos.getName(),hos.getAppId(), hos.getAppSecret(), signCode,patient,openid);
        return charge(orgCode,hos.getName(),hos.getAppId(), hos.getAppSecret(), chargeType,chargeRelation,totalAmount, selfpayAmount, insuranceAmount, feeDetail,patient,openid);
    }
    }
    /**
    /**
     * 家庭医生签约支付,成功则返回支付路径
     * 家庭医生签约支付,成功则返回支付路径
     */
     */
    private String charge(String orgCode,String orgName,String appId,String appSecret,String signCode,String patient,String openid) throws Exception
    private String charge(String orgCode,String orgName,String appId,String appSecret,String chargeType,String chargeRelation,Integer totalAmount,Integer selfpayAmount,Integer insuranceAmount,String feeDetail,String patient,String openid) throws Exception
    {
    {
        Boolean isSuccess = true;
        Boolean isSuccess = true;
        String msgBody = "";
        String msgBody = "";
@ -179,7 +178,9 @@ public class OnePayService {
        WlyyCharge charge = new WlyyCharge();
        WlyyCharge charge = new WlyyCharge();
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        charge.setSignCode(signCode);    //签约代码
        charge.setChargeType(chargeType);   //交易类型
        charge.setChargeRelation(chargeRelation);  //交易关联代码
        charge.setCode(uuid);  //  接入应用支付业务流水号
        charge.setCode(uuid);  //  接入应用支付业务流水号
        Date now = new Date();
        Date now = new Date();
        charge.setCreateTime(now);
        charge.setCreateTime(now);
@ -199,11 +200,10 @@ public class OnePayService {
            charge.setChannel(channel);
            charge.setChannel(channel);
            charge.setMerchName(orgName);
            charge.setMerchName(orgName);
            charge.setSubject(subject);
            charge.setSubject(subject);
            /*private Integer totalAmount;   //  交易总金额
            private Integer selfpayAmount;   //  自费金额
            private Integer insuranceAmount;   //  医保支付金额
            private Integer feeDetail;   //  费用明细*/
            charge.setTotalAmount(totalAmount);  //  交易总金额
            charge.setSelfpayAmount(selfpayAmount);  //  自费金额
            charge.setInsuranceAmount(insuranceAmount);  //  医保支付金额
            charge.setFeeDetail(feeDetail);  //  费用明细
@ -228,11 +228,11 @@ public class OnePayService {
            params.put("userName",name);
            params.put("userName",name);
            params.put("idType",idType);
            params.put("idType",idType);
            params.put("idNo",idNo);
            params.put("idNo",idNo);
            params.put("totalAmount","1");   //交易总金额
            params.put("selfpayAmount","0");   //自费金额
            params.put("insuranceAmount","1");   //医保支付金额
            params.put("totalAmount",totalAmount);   //交易总金额
            params.put("selfpayAmount",selfpayAmount);   //自费金额
            params.put("insuranceAmount",insuranceAmount);   //医保支付金额
            params.put("returnUrl","https://mp.weixin.qq.com/insurance/pay/detail");   //页面跳转地址
            params.put("returnUrl","https://mp.weixin.qq.com/insurance/pay/detail");   //页面跳转地址
            params.put("feeDetail","[{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"1\",\"itemNowPrice\":\"1\",\"itemNum\":\"1\",\"itemTotalAmt\":\"1\"}]");   //费用明细
            params.put("feeDetail",feeDetail);   //费用明细
            params.put("channel",channel);  //微信医保支付
            params.put("channel",channel);  //微信医保支付
            params.put("merchName",orgName);  //收款单位名称
            params.put("merchName",orgName);  //收款单位名称
            params.put("subject",subject);  //订单名称
            params.put("subject",subject);  //订单名称
@ -385,6 +385,8 @@ public class OnePayService {
            if (OnepayDefaultClient.isSuccessful(res)) {
            if (OnepayDefaultClient.isSuccessful(res)) {
                JSONObject json = res.getParam();
                JSONObject json = res.getParam();
                result = String.valueOf(json.get("sicardUrl"));      //电子社保卡连接
                result = String.valueOf(json.get("sicardUrl"));      //电子社保卡连接
                //保存到患者表
            }
            }
            else {
            else {
                isSuccess = false;
                isSuccess = false;
@ -409,4 +411,62 @@ public class OnePayService {
        return result;
        return result;
    }
    }
    /**
     *更新所有记录的交易状态
     */
    private List<WlyyCharge> updateTradeStatus(List<WlyyCharge> list)
    {
        //更新交易状态
        if(list!=null &&list.size()>0)
        {
            for(WlyyCharge item:list)
            {
                try{
                    Charge charge = chargeQuery(item.getCode());
                    if(charge!=null)
                    {
                        item.setTradeStatus(charge.getTradeStatus());            //  交易状态0 成功 1 失败 2 已退款
                        item.setChargeNo(charge.getChargeNo());       //  流水号
                        item.setChargeTime(charge.getChargeTime());      // 扣费时间
                        item.setMedOrgNo(charge.getMedOrgNo()); // 医疗机构编码
                        item.setMedOrgName(charge.getMedOrgName());  //医疗机构名称
                        item.setBillNo(charge.getBillNo());  //待结算费用单据号
                    }
                }
                catch (Exception ex)
                {
                    System.out.print("update trade status fail!");
                }
            }
            chargeDao.save(list);
        }
        return list;
    }
    /**
     * 通过交易关联代码获取交易列表
     */
    public List<WlyyCharge> chargeList(String chargeType,String chargeRelation) throws Exception
    {
        List<WlyyCharge> list = chargeDao.findByChargeTypeAndChargeRelation(chargeType,chargeRelation);
        return updateTradeStatus(list);
    }
    /**
     * 通过患者代码获取交易列表
     */
    public List<WlyyCharge> chargeListByPatient(String patient, Integer page, Integer size) throws Exception
    {
        PageRequest pageRequest = new PageRequest(page - 1, size);
        List<WlyyCharge> list = chargeDao.findByPatient(patient,pageRequest);
        return updateTradeStatus(list);
    }
}
}

+ 49 - 5
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.web.wx;
package com.yihu.wlyy.web.wx;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.service.weixin.wxpay.model.BindCard;
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.model.Charge;
import com.yihu.wlyy.service.weixin.wxpay.service.OnePayService;
import com.yihu.wlyy.service.weixin.wxpay.service.OnePayService;
@ -23,6 +24,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map;
/**
/**
@ -57,10 +59,20 @@ public class OnePayController extends WeixinBaseController {
    public String charge(
    public String charge(
                         @ApiParam(name="orgCode",value="医疗机构编号",defaultValue = "3502050300")
                         @ApiParam(name="orgCode",value="医疗机构编号",defaultValue = "3502050300")
                         @RequestParam String orgCode,
                         @RequestParam String orgCode,
                         @ApiParam(name="signCode",value="签约代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                         @RequestParam String signCode) throws Exception {
                         @ApiParam(name="chargeType",value="支付类型",defaultValue = "1")
                         @RequestParam String chargeType,
                         @ApiParam(name="chargeRelation",value="支付关联代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                         @RequestParam String chargeRelation,
                         @ApiParam(name="totalAmount",value="交易总金额(分)",defaultValue = "1")
                         @RequestParam Integer totalAmount,
                         @ApiParam(name="selfpayAmount",value="自费金额(分)",defaultValue = "0")
                         @RequestParam Integer selfpayAmount,
                         @ApiParam(name="insuranceAmount",value="医保支付金额(分)",defaultValue = "1")
                         @RequestParam Integer insuranceAmount,
                         @ApiParam(name="feeDetail",value="费用明细",defaultValue = "[{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"1\",\"itemNowPrice\":\"1\",\"itemNum\":\"1\",\"itemTotalAmt\":\"1\"}]")
                         @RequestParam String feeDetail) throws Exception {
        try {
        try {
            String settleNo = pay.charge(orgCode,signCode,"patient","ohNH9sh4uwuJCxIwcLJtGTX-BaSk");  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
            String settleNo = pay.charge(orgCode,chargeType,chargeRelation,totalAmount, selfpayAmount, insuranceAmount, feeDetail,"patient","ohNH9sh4uwuJCxIwcLJtGTX-BaSk");  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
            return write(200, "家庭医生签约支付成功!","data",settleNo);
            return write(200, "家庭医生签约支付成功!","data",settleNo);
        }
        }
        catch (Exception e)
        catch (Exception e)
@ -100,11 +112,43 @@ public class OnePayController extends WeixinBaseController {
    }
    }
    @RequestMapping(value = "chargeList", method = RequestMethod.POST)
    @ApiOperation("获取某次签约的支付记录")
    @ResponseBody
    public String chargeList(@ApiParam(name="chargeType",value="支付类型",defaultValue = "1")
                                  @RequestParam String chargeType,
                                  @ApiParam(name="chargeRelation",value="支付关联代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                                  @RequestParam String chargeRelation) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeList(chargeType,chargeRelation);
            return write(200, "获取某次签约的支付记录成功!","data",charge);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "chargeListByPatient", method = RequestMethod.POST)
    @ApiOperation("获取患者的支付记录")
    @ResponseBody
    public String chargeListByPatient(@ApiParam(name="patient",value="患者代码",defaultValue = "")
                             @RequestParam String patient,
                             @ApiParam(name="page",value="第几页,从1开始",defaultValue = "1")
                             @RequestParam Integer page,
                             @ApiParam(name="size",value="每页几行",defaultValue = "10")
                             @RequestParam Integer size) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeListByPatient(patient,page,size);
            return write(200, "获取患者的支付记录成功!","data",charge);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }