Browse Source

眼科医保结算流程

wangzhinan 1 year ago
parent
commit
8be1a53a15

+ 44 - 7
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -678,16 +678,16 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        logger.info("map:"+map.toString());
        Map<String, Object> pay = unifiedorder(map, wxWechatDO.getAppKey());
        String returnCode = pay.get("return_code").toString();
        String resultCode = pay.get("result_code").toString();
        System.out.println("-----返回结果:"+resultCode);
        System.out.println("-----return_code:"+returnCode);
        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();
            String trade = "";
            String resultCode = pay.get("result_code").toString();
            System.out.println("-----返回结果:"+resultCode);
            if ("SUCCESS".equalsIgnoreCase(resultCode)){
                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();
                String trade = "";
                trade = pay.get("trade_type").toString();
                if (trade.equalsIgnoreCase("Native")){
                    Map<String,String> param = new HashedMap();
@ -744,6 +744,7 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
    }
    /**
     * 微信退款
     * @param wechatId
@ -1132,6 +1133,42 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        return rs;
    }
    public Map<String,String> getWxPayResultCloudNotify(String result) {
        Map<String,String> rs = new HashedMap();
        Map<String,Object> wxrs =  XMLUtil.xmltoMap(result);
        logger.info("回调参数"+wxrs+"==============="+result);
        if("SUCCESS".equals(wxrs.get("return_code").toString())){
            // 我方 订单号+时间差
            String seqNo = wxrs.get("out_trade_no")+"";
            String totalFee=wxrs.get("total_fee")+"";
            // 微信充值流水号
            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);
            businessOrderDO.setUpdateTime(new Date());
            businessOrderDao.save(businessOrderDO);
            //操作微信日志表记录
            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("return_code","SUCCESS");
            rs.put("return_msg","OK");
        }else{
            rs.put("return_code","FAIL");
            rs.put("return_msg","OK");
        }
        return rs;
    }
    public String sendDataToYkt(String orderNo){

+ 0 - 340
common/common-util/src/main/java/com/yihu/jw/util/common/CommonUtil.java

@ -1,340 +0,0 @@
package com.yihu.jw.util.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.fastdfs.FastDFSUtil;
import com.yihu.jw.entity.util.SystemConfEntity;
import com.yihu.jw.util.http.HttpClientUtil;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Created by yeshijie on 2023/2/13.
 */
@Component
public class CommonUtil {
    private Logger logger = LoggerFactory.getLogger(CommonUtil.class);
//    @Value("${neiwang.enable}")
    private Boolean isneiwang = false;  //如果不是内网项目要转到到内网wlyy在上传
//    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
//    @Value("${neiwang.wlyy}")
    private String neiwangWlyy;  //内网的项目地址
    @Autowired
    private HttpClientUtil httpClientUtil;
    public static String getCode() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }
    /**
     * 传入身高体重,计算BMI值
     *
     * @param weightStr 体重
     * @param heightStr 身高
     * @return
     */
    public static double getBMIByWeightAndHeight(String weightStr, String heightStr) {
        DecimalFormat df2 = new DecimalFormat("###.00");
        double weight = Double.parseDouble(weightStr);
        Integer heightCM = Integer.parseInt(heightStr);
        heightStr = df2.format(heightCM / 100d);
        double height = Double.parseDouble(heightStr);
        double bmi = weight / (height * height);
        return bmi;
    }
    /**
     * 删除文件夹
     * @param folder
     */
    public static void deleteFolder(File folder){
        File[] files  = folder.listFiles();
        if (files != null){
            for(File f: files){
                if (f.isDirectory()){
                    deleteFolder(f);
                }else {
                    f.delete();
                }
            }
        }
        folder.delete();
    }
    /**
     * double转字符串,在转int
     * double*100转int 有bug 34.3会会变成3429
     * @param d
     * @return
     */
    public static Integer doubleToInt(Double d){
        if(d==null){
            return 0;
        }
        String currency = String.valueOf(d);
        int index = currency.indexOf(".");
        int length = currency.length();
        Integer amLong = 0;
        if(index == -1){
            amLong = Integer.valueOf(currency+"00");
        }else if(length - index >= 3){
            amLong = Integer.valueOf((currency.substring(0, index+3)).replace(".", ""));
            if(length-index>3){
                if(Integer.valueOf(currency.substring(index+3,index+4))>=5){
                    amLong++;
                }
            }
        }else if(length - index == 2){
            amLong = Integer.valueOf((currency.substring(0, index+2)).replace(".", "")+0);
        }else{
            amLong = Integer.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");
        }
        return amLong;
    }
    public static List<String> getTagContent(String source, String regString) {
        List<String> result = new ArrayList<String>();
        Matcher m = Pattern.compile(regString).matcher(source);
        while (m.find()) {
            try {
                String r = StringEscapeUtils.unescapeHtml3(URLDecoder.decode(m.group(1),"utf-8"));
                result.add(r);
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    public String copyTempVoice(String voices) throws Exception {
        if (isneiwang) {
            // 文件保存的临时路径
            String serverUrl = fastdfs_file_url;
            FastDFSUtil fastDFSUtil = new FastDFSUtil();
            String fileUrls = "";
            File f = new File(voices);
            if (f.exists()) {
                String fileName = f.getName();
                InputStream in = new FileInputStream(f);
                ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                in.close();
                if (result != null) {
                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + serverUrl
                            + result.get("groupName").toString().replaceAll("\"", "") + "/"
                            + result.get("remoteFileName").toString().replaceAll("\"", "");
                    f.delete();
                }
            }
            return fileUrls;
        } else {
            String fileUrls = toNeiWang(voices, "");
            return fileUrls;
        }
    }
    /**
     * 如果是外网那是发送到内网的服务器
     *
     * @param files
     * @return
     */
    public String toNeiWang(String files, String tempPath) throws FileNotFoundException {
        logger.info(" toNeiWang start files :" + tempPath + files);
        //转发到内网服务器
        String[] fileArray = files.split(",");
        String fileUrls = "";
        for (String file : fileArray) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
            File f = new File(tempPath + file);
            logger.info(" toNeiWang File exists :" + f.exists());
            if (f.exists()) {
                String fileName = f.getName();
                InputStream in = new FileInputStream(f);
                String returnStr = request(request, in, fileName);
                logger.info("returnStr :" + returnStr);
                logger.info("fileName :" + fileName);
                logger.info("result :" + returnStr.toString());
                if (returnStr != null) {
                    //1.3.7去掉前缀
                    fileUrls += returnStr+",";
                    f.delete();
                }
            } else {
                String path = tempPath + file;
                String returnStr = request(request, path);
                logger.info("result :" + returnStr.toString());
                if (returnStr != null) {
                    //1.3.7去掉前缀
                    fileUrls += returnStr+",";
                }
            }
        }
        logger.info(" toNeiWang end files :" + fileUrls);
        return fileUrls.substring(0,fileUrls.length()-1);
    }
    private String request(HttpServletRequest request, String path) {
        String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径
        String result = "";
        try {
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("filePaths", path));
            // 将响应内容转换为字符串
            result = httpClientUtil.post(url, params, "UTF-8");
        }  catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    public String request(String remote_url, MultipartFile file, String type) {
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        logger.info(file.getOriginalFilename());
        String result = "";
        try {
            String fileName = file.getOriginalFilename();
            HttpPost httpPost = new HttpPost(remote_url);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addBinaryBody("file", file.getInputStream(), ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
            builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
            if (!org.springframework.util.StringUtils.isEmpty(type)) {
                builder.addTextBody("type", type); //发送类型
            }
            HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);// 执行提交
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                // 将响应内容转换为字符串
                result = EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    public String request(HttpServletRequest request, InputStream in, String fileName) {
        String url = neiwangWlyy + "/wlyy/upload/commonUpload";//uri请求路径
        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
        String result = "";
        try {
            HttpPost httpPost = new HttpPost(url);
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            builder.addBinaryBody("file", in, ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
            builder.addTextBody("filename", fileName);// 类似浏览器表单提交,对应input的name和value
            if (!org.springframework.util.StringUtils.isEmpty(request.getParameter("type")) ||
                    !org.springframework.util.StringUtils.isEmpty(request.getAttribute("type"))) {
                builder.addTextBody("type",  null != request.getParameter("type") ? request.getParameter("type") : String.valueOf(request.getAttribute("type"))); //发送类型
            }
            HttpEntity entity = builder.build();
            httpPost.setEntity(entity);
            HttpResponse response = httpClient.execute(httpPost);// 执行提交
            HttpEntity responseEntity = response.getEntity();
            if (responseEntity != null) {
                // 将响应内容转换为字符串
                result = EntityUtils.toString(responseEntity, Charset.forName("UTF-8"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                httpClient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
    public String copyTempImage(String files) throws Exception {
        String tempPath = SystemConfEntity.getInstance().getTempPath() + File.separator;
        if (isneiwang) {
            // 文件保存的临时路径
            String[] fileArray = files.split(",");
            FastDFSUtil fastDFSUtil = new FastDFSUtil();
            String fileUrls = "";
            for (String file : fileArray) {
                File f = new File(tempPath + file);
                File fs = new File(tempPath + file + "_small");
                if (f.exists()) {
                    String fileName = f.getName();
                    InputStream in = new FileInputStream(f);
                    ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                    in.close();
                    if (result != null) {
                        //1.3.7去掉前缀
                        fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",")
                                + result.get("groupName").toString().replaceAll("\"", "") + "/"
                                + result.get("remoteFileName").toString().replaceAll("\"", "");
                        f.delete();
                        if (fs.exists()) {
                            fs.delete();
                        }
                    }
                }
            }
            return fileUrls;
        } else {
            String fileUrls = toNeiWang(files, tempPath);
            return fileUrls;
        }
    }
}

+ 46 - 3
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/endpoint/patient/PayEndpoint.java

@ -8,11 +8,15 @@ import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService;
import com.yihu.jw.care.service.pay.PayService;
import com.yihu.jw.care.util.WxpayUtil;
import com.yihu.jw.care.util.XMLUtil;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
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.restmodel.ResponseContant;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
@ -21,6 +25,7 @@ import com.yihu.jw.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -28,7 +33,10 @@ 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.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -175,7 +183,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = "cloudWxPay")
    @ApiOperation(value = "云照护支付")
    @ObserverRequired
    public ObjEnvelop wxWapPay(
    public ObjEnvelop cloudWxPay(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = false) String relationCode,
            @ApiParam(name = "relationName", value = "关联表名称")
@ -188,7 +196,7 @@ public class PayEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "doctor", required = false) String doctor,
            @ApiParam(name = "fee", value = "费用金额")
            @RequestParam(value = "fee", required = false) String fee,
            @ApiParam(name = "depositType", value = "支付类型")
            @ApiParam(name = "depositType", value = "支付类型 NATIVE pc二维码,JSAPI 公众号支付,APPLETS 小程序支付")
            @RequestParam(value = "depositType", required = false) String depositType,
            @ApiParam(name = "appletCode", value = "费用金额")
            @RequestParam(value = "appletCode", required = false) String appletCode) {
@ -199,6 +207,19 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "selectOrderByRelationCode")
    @ApiOperation(value = "云照护支付查询记录")
    @ObserverRequired
    public ObjEnvelop selectOrderByRelationCode(
            @ApiParam(name = "relationCode", value = "关联表id")
            @RequestParam(value = "relationCode", required = true) String relationCode) {
        try{
            return ObjEnvelop.getSuccess("请求成功",payService.selectOrderByRelationCode(relationCode));
        }catch (Exception e){
            return failedObjEnvelopException2(e);
        }
    }
    @PostMapping(value = "cloudWxRefund")
    @ApiOperation(value = "云照护支付退款")
@ -219,6 +240,29 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    /**
     * 微信支付回调
     *
     * @param request
     * @return java.lang.String
     */
    @PostMapping("open/cloudPayNotify")
    @ResponseBody
    @ApiOperation("云照护微信支付回调")
    public String cloudPayNotify(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String result = "";
        String inputLine;
        while ((inputLine = request.getReader().readLine()) != null) {
            result += inputLine;
        }
        request.getReader().close();
        //im处方发消息
        Map<String,Object> wxrs =  com.yihu.jw.util.common.XMLUtil.xmltoMap(result);
        Map<String, String> map = new HashedMap();
        map= payService.getWxPayResultCloudNotify(result);
        return com.yihu.jw.util.common.XMLUtil.map2xml(map);
    }
    @PostMapping(value = "applyRefund")
    @ApiOperation(value = "申请退款")
    @ObserverRequired
@ -315,7 +359,6 @@ public class PayEndpoint extends EnvelopRestEndpoint {
        }
    }
    /**
     * 微信支付退款回调
     *

+ 22 - 4
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/pay/PayService.java

@ -813,7 +813,7 @@ public class PayService {
     * @param relationCode
     * @param relationName
     * @param orderType
     * @param depositType
     * @param depositType NATIVE pc二维码,JSAPI 公众号支付,APPLETS 小程序支付
     * @return
     * @throws Exception
     */
@ -885,8 +885,7 @@ public class PayService {
                }
                businessOrderDO.setOrderNo(getOrderNo());
                businessOrderDO= businessOrderDao.save(businessOrderDO);
                String url = wxWechatDO.getBaseUrl();
                String notifyUrl =url;
                String notifyUrl ="https://zhyzh.gongshu.gov.cn/cloudCare/pay/open/cloudPayNotify";
                String totalFee =businessOrderDO.getPayPrice().intValue()+"";
                map = businessOrderService.unifiedorder(wechatId,businessOrderDO.getDescription(),totalFee, depositType,openId,businessOrderDO.getOrderNo(),notifyUrl,businessOrderDO.getPatient());
            }
@ -898,9 +897,17 @@ public class PayService {
    }
    /**
     * 查询订单是否支付
     * @param relationCode
     * @return
     */
    public BusinessOrderDO selectOrderByRelationCode(String relationCode){
        return businessOrderDao.selectByRelationCode(relationCode);
    }
    /**
     * 云照护支付退款
     * @param wechatId
     * @param patient
     * @param orderNo
     * @param refundPrice
@ -948,6 +955,7 @@ public class PayService {
                orderRefundDO.setRefundTime(new Date());
                orderRefundDO.setRefundDesc(map.get("err_code_des").toString());
                orderRefundDao.save(orderRefundDO);
            }else {
                orderRefundDO.setStatus(2);
                orderRefundDO.setRefundTime(new Date());
@ -962,6 +970,16 @@ public class PayService {
        return map;
    }
    /**
     * 云照护支付回调
     * @param result
     * @return
     */
    public Map<String,String> getWxPayResultCloudNotify(String result) {
        return businessOrderService.getWxPayResultCloudNotify(result);
    }
    public String getOrderNo(){
        return ""+System.currentTimeMillis()+(int)(Math.random()*900)+100;
    }