Selaa lähdekoodia

电子健康卡获取二维码链接

wujunjie 7 vuotta sitten
vanhempi
commit
afefbe2cb5

+ 135 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/ylz/EHCConfigura.java

@ -0,0 +1,135 @@
package com.yihu.wlyy.entity.ylz;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * 易联众支付相关配置参数
 * Created by Reece on 2017/9/9/009.
 */
@Entity
@Table(name = "ylz_ehc_config")
public class EHCConfigura extends IdEntity implements Serializable {
    //    基础配置参数
    private String ehcApi ;
    private String appId;
    private String appKey;
    private String termId;
    private String version;
    private String signType;
    private String encType;
    private String ehcRedirecturl;
    private String ehcVerify;
    private String ehcRegquery;
    private int del; //配置状态 0无效 1有效
    private Date createTime;
    private Date czrq;
    public String getEhcRedirecturl() {
        return ehcRedirecturl;
    }
    public void setEhcRedirecturl(String ehcRedirecturl) {
        this.ehcRedirecturl = ehcRedirecturl;
    }
    public String getEhcApi() {
        return ehcApi;
    }
    public void setEhcApi(String ehcApi) {
        this.ehcApi = ehcApi;
    }
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getAppKey() {
        return appKey;
    }
    public void setAppKey(String appKey) {
        this.appKey = appKey;
    }
    public String getTermId() {
        return termId;
    }
    public void setTermId(String termId) {
        this.termId = termId;
    }
    public String getVersion() {
        return version;
    }
    public void setVersion(String version) {
        this.version = version;
    }
    public String getSignType() {
        return signType;
    }
    public void setSignType(String signType) {
        this.signType = signType;
    }
    public String getEncType() {
        return encType;
    }
    public void setEncType(String encType) {
        this.encType = encType;
    }
    public String getEhcVerify() {
        return ehcVerify;
    }
    public void setEhcVerify(String ehcVerify) {
        this.ehcVerify = ehcVerify;
    }
    public String getEhcRegquery() {
        return ehcRegquery;
    }
    public void setEhcRegquery(String ehcRegquery) {
        this.ehcRegquery = ehcRegquery;
    }
    public int getDel() {
        return del;
    }
    public void setDel(int del) {
        this.del = del;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 138 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/ylz/EHCLog.java

@ -0,0 +1,138 @@
package com.yihu.wlyy.entity.ylz;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * 易联众电子健康卡log表
 * Created by Reece on 2017/9/20.
 */
@Entity
@Table(name = "ylz_ehc_log")
public class EHCLog extends IdEntity {
    private String patient;
    // 接口类型 0二维码链接 1查询(注册)
    private String type;
    // 业务内容
    private String content;
    // 调用接口
    private String api;
    // 调用方式
    private String method;
    // 调用参数
    private String params;
    // 调用头部信息
    private String header;
    // 返回结果
    private String response;
    // 状态 0失败 1成功
    private String status;
    // 创建时间
    private Date createTime;
    //异常信息
    private String error;
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @Column(name = "type")
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    @Column(name = "content")
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }
    @Column(name = "api")
    public String getApi() {
        return api;
    }
    public void setApi(String api) {
        this.api = api;
    }
    @Column(name = "method")
    public String getMethod() {
        return method;
    }
    public void setMethod(String method) {
        this.method = method;
    }
    @Column(name = "params")
    public String getParams() {
        return params;
    }
    public void setParams(String params) {
        this.params = params;
    }
    @Column(name = "header")
    public String getHeader() {
        return header;
    }
    public void setHeader(String header) {
        this.header = header;
    }
    @Column(name = "response")
    public String getResponse() {
        return response;
    }
    public void setResponse(String response) {
        this.response = response;
    }
    @Column(name = "status")
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    @Column(name = "create_time")
    @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;
    }
    @Column(name = "error")
    public String getError() {
        return error;
    }
    public void setError(String error) {
        this.error = error;
    }
}

+ 15 - 1
patient-co/patient-co-wlyy/pom.xml

@ -428,7 +428,13 @@
        <!--易联众支付-->
        <dependency>
            <groupId>com.ylz</groupId>
            <artifactId>onpay-java-sdk-all</artifactId>
            <artifactId>ehc-sdk</artifactId>
        </dependency>
        <!--易联众电子健康卡-->
        <dependency>
            <groupId>com.ylz</groupId>
            <artifactId>ehc-sdk</artifactId>
        </dependency>
        <dependency>
@ -452,6 +458,14 @@
            <artifactId>commons-collections</artifactId>
            <version>3.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.ylz</groupId>
            <artifactId>onpay-java-sdk-all</artifactId>
        </dependency>
        <dependency>
            <groupId>com.ylz</groupId>
            <artifactId>onpay-java-sdk-all</artifactId>
        </dependency>
        <!--elasticsearch end-->
    </dependencies>
    <build>

+ 18 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/ylz/EHCConfiguraDao.java

@ -0,0 +1,18 @@
package com.yihu.wlyy.repository.ylz;
import com.yihu.wlyy.entity.ylz.EHCConfigura;
import com.yihu.wlyy.entity.ylz.PayConfigura;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Reece on 2017/9/9.
 */
public interface EHCConfiguraDao extends PagingAndSortingRepository<EHCConfigura, Long>, JpaSpecificationExecutor<EHCConfigura> {
    //查询有效支付相关配置(只有一条有效记录)
    @Query("select t from EHCConfigura t where t.del = 1 ")
    EHCConfigura findWorkConfigura();
}

+ 17 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/ylz/EHCLogDao.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.repository.ylz;
import com.yihu.wlyy.entity.ylz.EHCLog;
import com.yihu.wlyy.entity.ylz.PayLog;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Reece on 2017/9/20.
 */
public interface EHCLogDao extends PagingAndSortingRepository<EHCLog, Long>, JpaSpecificationExecutor<EHCLog> {
    //根据居民code查询该居民电子健康卡日志记录
    @Query("select t from EHCLog t where t.patient = ?1 ")
    EHCLog findByPatient(String patient);
}

+ 196 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/ehc/PatientEHCService.java

@ -0,0 +1,196 @@
package com.yihu.wlyy.service.app.ehc;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.ylz.EHCConfigura;
import com.yihu.wlyy.entity.ylz.EHCLog;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.ylz.EHCConfiguraDao;
import com.yihu.wlyy.repository.ylz.EHCLogDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import com.ylzinfo.ehc.EhcHandler;
import com.ylzinfo.ehc.trans.TransRequest;
import com.ylzinfo.ehc.utils.DateUtils;
import org.apache.commons.lang3.StringUtils;
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.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
/**
 * Created by Reece on 2017/10/25/025.
 * 居民电子健康卡业务处理
 */
@Service
public class PatientEHCService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(PatientEHCService.class);
    @Value("${wechat.accId}")
    private String accId;
    @Autowired
    private EHCConfiguraDao ehcConfiguraDao;
    @Autowired
    private PatientDao patientDao;
    @Autowired
    private EHCLogDao ehcLogDao;
    public String EHCRedirecturl(String getUid) throws Exception {
        String result = null;
        try {
            String format = "yyyyMMddHHmmss";
            String currentTime = DateUtils.getOutTradeTime();
            String uuid = DateUtil.getUidNo(4);
            EHCConfigura config = ehcConfiguraDao.findWorkConfigura();
            String api = config.getEhcApi();
            String appId = config.getAppId();
            String termId = config.getTermId();
            String appKey = config.getAppKey();
            String signType = config.getSignType();
            String encType = config.getEncType();
            String version = config.getVersion();
            String redirecturl = config.getEhcRedirecturl();
            Patient patient = patientDao.findByCode(getUid);
            String openId = patient.getOpenid();
            String idcard = patient.getIdcard();
            String name = patient.getName();
            Integer sex = patient.getSex();//1男,2女
            if (StringUtils.isEmpty(openId)) {
                return "-1";
            }
            if (StringUtils.isEmpty(idcard)) {
                return "-1";
            }
            if (StringUtils.isEmpty(name)) {
                return "-1";
            }
            if (sex == null) {
                return "-1";
            }
            Date birthday = patient.getBirthday();
            String mobile = patient.getMobile();
            String phone = patient.getPhone();
            String provinceName = patient.getProvinceName();
            String cityName = patient.getCityName();
            String townName = patient.getTownName();
            String streetName = patient.getStreetName();
            String address = patient.getAddress();
            JSONObject bizContent = new JSONObject();
            bizContent.put("open_id", openId);
            bizContent.put("account_id", accId);
            bizContent.put("out_trade_no", uuid);
            bizContent.put("out_trade_time", currentTime);
            bizContent.put("id_type", "01");
            bizContent.put("id_no", idcard);
            bizContent.put("user_name", name);
            bizContent.put("user_sex", "" + sex);
            bizContent.put("birthday", DateUtil.dateToStr(birthday, format));
            bizContent.put("mobile_phone", mobile);
            bizContent.put("telephone", phone);
            bizContent.put("address", address);
            bizContent.put("work_unit", provinceName + cityName + townName + streetName);
            result = httpUtils(getUid, api, appId, termId, appKey, signType, encType, version, redirecturl, bizContent);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
    /**
     * http发送请求工具类
     *
     * @param api      网关地址
     * @param appId
     * @param termId
     * @param appKey
     * @param signType
     * @param encType
     * @param version
     * @param url      接口路径
     */
    public String httpUtils(String patient, String api, String appId, String termId, String appKey, String signType, String encType, String version, String url, JSONObject bizContent) throws Exception {
        String params = null;
        String encParams = null;
        String response = null;
        String error = null;
        try {
            TransRequest request = new TransRequest();
            request.setMethod(url);
            request.setApp_id(appId);
            request.setTerm_id(termId);
            request.setVersion(version);
            request.setTimestamp(DateUtils.getOutTradeTime());
            request.setSign_type(signType);
            request.setEnc_type(encType);
            request.setBiz_content(JSONObject.toJSONString(bizContent));
            params = JSONObject.toJSONString(request);
            EhcHandler ehcHandler = new EhcHandler(api, appId, termId, appKey);
            String result = ehcHandler.buildGet(request);
            System.out.println(result);
            encParams = JSONObject.toJSONString(request);
            response = result;
        } catch (Exception e) {
            e.printStackTrace();
            error = e.getMessage();
        }
        //保存日志
        getLog(patient, url, params, response, error);
        logger.info("**************** EHC LOG START **********************");
        logger.info("EHC API " + url);
        logger.info("EHC PARAMS " + encParams);
        logger.info("EHC RESPONSE " + response);
        logger.info("EHC ERROR " + error);
        logger.info("**************** EHC LOG END **********************");
        return response;
    }
    public void getLog(String patient, String api, String params, String response, String error) throws Exception {
        try {
            String type = null;
            String content = null;
            String method = null;
            EHCLog ehcLog = ehcLogDao.findByPatient(patient);
            if (ehcLog == null) {
                ehcLog = new EHCLog();
            }
            switch (api) {
                case "ehc.ehealthcode.redirecturl":
                    type = "0";
                    content = "获取电子健康卡链接";
                    method = "GET";
                    break;
            }
            ehcLog.setPatient(patient);
            ehcLog.setApi(api);
            ehcLog.setType(type);
            ehcLog.setContent(content);
            ehcLog.setMethod(method);
            ehcLog.setParams(params);
            ehcLog.setResponse(response);
            ehcLog.setStatus("1");
            ehcLog.setCreateTime(new Date());
            ehcLog.setError(error);
            if (StringUtils.isNotEmpty(error)) {
                ehcLog.setStatus("0");
            }
            ehcLogDao.save(ehcLog);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

+ 9 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/DateUtil.java

@ -680,6 +680,15 @@ public class DateUtil {
		return getUserDate("yyyyMMddhhmmss") + getRandom(k);
	}
	/**
	 * 取得流水号 生成格式为yyyymmddhhmmss+k位随机UUID
	 *
	 * @param k 表示是取几位随机数,可以自己定
	 */
	public static String getUidNo(int k) {
		return getUserDate("yyyyMMddhhmmss") + UUID.randomUUID().toString().replaceAll("-", "").substring(0, k);
	}
	/**
	 * 返回一个随机数
	 * 

+ 59 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/ehc/PatientEHCController.java

@ -0,0 +1,59 @@
package com.yihu.wlyy.web.patient.ehc;
import com.yihu.wlyy.service.app.ehc.PatientEHCService;
import com.yihu.wlyy.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.ResponseBody;
/**
 * Created by Reece on 2017/10/25/025.
 * 居民电子健康卡相关接口
 */
@Controller
@RequestMapping(value = "/patient/ehc")
@Api(description = "电子健康卡接口-居民端")
public class PatientEHCController extends WeixinBaseController {
    @Autowired
    private PatientEHCService ehcService;
    /**
     * 电子健康卡获取二维码链接
     *
     * @throws Exception
     */
    @RequestMapping(value = "/redirecturl", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("电子健康卡获取二维码链接")
    public String EHCVerify() {
        try {
            String msg = null;
            int code = 0;
            String patient = getUID();
            String result = ehcService.EHCRedirecturl(patient);
            switch (result) {
                case "-1":
                    msg = "居民信息缺失,请检查后再试!";
                    code = -1;
                    break;
                default:
                    msg = "二维码获取成功!";
                    code = 200;
                    break;
            }
            if ("-1".equals(code)) {
                return error(code, msg);
            }
            return write(code, msg, "data", result);
        } catch (Exception e) {
            return error(-1, e.getMessage());
        }
    }
}

+ 7 - 0
pom.xml

@ -49,6 +49,7 @@
        <version.zxing>3.2.0</version.zxing>
        <version.fastdfs>1.2.17</version.fastdfs>
        <version.ylz>1.0.0</version.ylz>
        <version.ylz.ehc>1.0.0.20171025</version.ylz.ehc>
        <version.elasticsearch>2.4.4</version.elasticsearch>
        <version.jest>2.4.0</version.jest>
@ -570,6 +571,12 @@
                <artifactId>onpay-java-sdk-all</artifactId>
                <version>${version.ylz}</version>
            </dependency>
            <!--易联众电子健康卡-->
            <dependency>
                <groupId>com.ylz</groupId>
                <artifactId>ehc-sdk</artifactId>
                <version>${version.ylz.ehc}</version>
            </dependency>
            <!--elasticsearch start-->
            <dependency>
                <groupId>org.elasticsearch</groupId>