Explorar el Código

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

wujunjie hace 8 años
padre
commit
5b5a6aeb7e

+ 20 - 0
patient-co-wlyy/pom.xml

@ -156,6 +156,12 @@
            <artifactId>kaptcha</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>com.ylzinfo.onepay</groupId>
            <artifactId>onepay</artifactId>
            <version>1.0</version>
        </dependency>
        <!-- spring data access -->
        <dependency>
            <groupId>org.springframework.data</groupId>
@ -539,6 +545,20 @@
                <artifactId>maven-install-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>onepay</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>com.ylzinfo.onepay</groupId>
                            <artifactId>onepay</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${basedir}/src/main/resources/onepay-java-sdk.jar</file>
                        </configuration>
                    </execution>
                    <execution>
                        <id>kaptcha</id>
                        <phase>initialize</phase>

+ 21 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/organization/HospitalMapping.java

@ -22,6 +22,11 @@ public class HospitalMapping extends IdEntity {
	private String type;
	// 映射机构代码
	private String mappingCode;
	// 易联众appid
	private String appId;
	// 易联众app secret
	private String appSecret;
	public String getType() {
		return type;
@ -54,4 +59,20 @@ public class HospitalMapping extends IdEntity {
	public void setMappingCode(String mappingCode) {
		this.mappingCode = mappingCode;
	}
	public String getAppId() {
		return appId;
	}
	public void setAppId(String appId) {
		this.appId = appId;
	}
	public String getAppSecret() {
		return appSecret;
	}
	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/health/repository/DevicePatientHealthIndexDao.java

@ -98,7 +98,7 @@ public interface DevicePatientHealthIndexDao
	@Query(value = "select a.* from device.wlyy_patient_health_index a where a.user = ?1 and a.type = ?2 and a.record_date >= ?3 and a.record_date <= ?4 and a.del = '1' order by a.sort_date desc ,record_date desc limit ?5 ,?6",nativeQuery = true)
	List<DevicePatientHealthIndex> findIndexByPatientNative(String patient, int type, Date start, Date end,int currentSize,int pageSize);
	@Query(value = "select DATE_FORMAT(a.record_date,'%Y-%m-%d') from device.wlyy_patient_health_index a where a.user = ?1 and a.record_date >= ?2 and a.record_date <= ?3 and a.del = '1' group by DATE_FORMAT(a.record_date,'%Y-%m-%d') order by DATE_FORMAT(a.record_date,'%Y-%m-%d') desc limit ?4,5?",nativeQuery = true)
	@Query(value = "select DATE_FORMAT(a.record_date,'%Y-%m-%d') from device.wlyy_patient_health_index a where a.user = ?1 and a.record_date >= ?2 and a.record_date <= ?3 and a.del = '1' group by DATE_FORMAT(a.record_date,'%Y-%m-%d') order by DATE_FORMAT(a.record_date,'%Y-%m-%d') desc limit ?4 ,?5",nativeQuery = true)
	List<String> findDateList(String patient,Date start ,Date end,int currentSize,int pageSize);
}

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/organization/HospitalMappingDao.java

@ -23,4 +23,6 @@ public interface HospitalMappingDao extends PagingAndSortingRepository<HospitalM
	@Query("select a.code from HospitalMapping a where a.mappingCode=?1 and a.type=?2")
	String getCodeByMapping(String mappingCode,String type);
	HospitalMapping findByCode(String code);
}

+ 49 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthIndexService.java

@ -397,6 +397,7 @@ public class PatientHealthIndexService extends BaseService {
                String data = item.getValue1();
                String dataType = item.getValue2();
                Date recordDate = item.getRecordDate();
                obj.setId(item.getId());
                if (data != null && dataType != null) {
                    if (dataType.equals("1")) {
                        obj.setValue1(data);
@ -452,34 +453,42 @@ public class PatientHealthIndexService extends BaseService {
                String data = item.getValue1();
                String dataType = item.getValue2();
                Date recordDate = item.getRecordDate();
                Long id = item.getId();
                if (data != null && dataType != null) {
                    if (dataType.equals("1")) {
                        obj.put("value1",data);
                        obj.put("time1",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("2")) {
                        obj.put("value2",data);
                        obj.put("time2",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("3")) {
                        obj.put("value3",data);
                        obj.put("time3",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("4")) {
                        obj.put("value4",data);
                        obj.put("time4",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("5")) {
                        obj.put("value5",data);
                        obj.put("time5",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("6")) {
                        obj.put("value6",data);
                        obj.put("time6",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    } else if (dataType.equals("7")) {
                        obj.put("value7",data);
                        obj.put("time7",recordDate);
                        obj.put("id",id);
                        hadData = true;
                    }
                }
@ -797,6 +806,46 @@ public class PatientHealthIndexService extends BaseService {
        return re;
    }
    /**
     * 查询指标记录
     *
     * @param patient
     * @param type
     * @param start
     * @param end
     * @param page
     * @param pageSize
     * @return
     */
    public List<Object> findIndexByPatient2(String patient, int type, String start, String end, int page, int pageSize) {
        List<Object> re = new ArrayList<>();
        if (page > 0) {
            page = page - 1;
        }
        Date startDate = DateUtil.strToDate(start, DateUtil.YYYY_MM_DD_HH_MM_SS);
        Date endDate = DateUtil.strToDate(end, DateUtil.YYYY_MM_DD_HH_MM_SS);
        if (type == 1)   //血糖特殊处理
        {
            PageRequest pageRequest = new PageRequest(page, pageSize);
            //根据时间过滤排序
            List<String> dateList = patientHealthIndexDao.findDateList(patient, startDate, endDate, pageRequest.getOffset(),pageRequest.getPageSize());
            if (dateList != null && dateList.size() > 0) {
                for (String dateString : dateList) {
                    com.alibaba.fastjson.JSONObject obj = getPatientXT_Json(patient, dateString);
                    if (obj != null) {
                        re.add(obj);
                    }
                }
            }
        } else {
            // 排序
        }
        return re;
    }
    /**
     * 根据患者标志获取健康指标
     *

+ 16 - 16
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -217,19 +217,19 @@ public class GuahaoXMService implements IGuahaoService {
            // 请求失败
            //保存http日志
            error = title;
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        }
    }
@ -298,7 +298,7 @@ public class GuahaoXMService implements IGuahaoService {
            }
            //保存http日志
            logService.saveHttpLog(true,ORG_LIST,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORG_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        }
        return re;
    }
@ -343,7 +343,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DEP_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DEP_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -436,7 +436,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -486,7 +486,7 @@ public class GuahaoXMService implements IGuahaoService {
        verificationXml(xml,"获取医生排班表失败!",DOCTOR_ARRANGE,content,method,msgBody,res);
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_ARRANGE,content,method,null,msgBody,res,null,logService.archiveType);
        return xmlToList(xml);
    }
@ -562,7 +562,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE_SIMPLE,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_ARRANGE_SIMPLE,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -630,7 +630,7 @@ public class GuahaoXMService implements IGuahaoService {
            //xml验证
            verificationXml(response,"获取医生排班表失败!",ORDER_CREATE,content,method,msgBody,res);
            //保存http日志
            logService.saveHttpLog(true,ORDER_CREATE,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORDER_CREATE,content,method,null,msgBody,res,null,logService.archiveType);
            re = CreateOrderAfter(response, hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, sectionType, startTime, endTime, patient, patientName, cardNo, clinicCard, patientPhone, null, null);
        } else {
            throw new Exception("该排班信息错误或者不存在!");
@ -685,7 +685,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(isOk,ORDER_CANCEL,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(isOk,ORDER_CANCEL,content,method,null,msgBody,res,null,logService.archiveType);
        return isOk;
    }
@ -778,7 +778,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return doctor;
    }
@ -856,10 +856,10 @@ public class GuahaoXMService implements IGuahaoService {
                }
                //保存http日志
                logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
                logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            } else {
                //保存http日志
                logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,errMsg,"2");
                logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,errMsg,logService.archiveType);
                throw new Exception(errMsg);
            }
        } catch (Exception ex) {
@ -999,7 +999,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,REG_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,REG_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return patientRegList;
    }
@ -1115,12 +1115,12 @@ public class GuahaoXMService implements IGuahaoService {
            patientReservation.setDoctorJob(guahaoDoctor.getTitle());//职称
            //保存http日志
            logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            return patientReservation;
        } else {
            //保存http日志
            logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            return null;
        }
    }

+ 10 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/httplog/LogService.java

@ -21,6 +21,13 @@ public class LogService {
    @Autowired
    private SystemDictService systemDictService;
    public String openApiType = "0";
    public String signType = "1";
    public String archiveType = "2";
    public String onepayType = "3";
    /**
     * 新增开放api调用日志
     * */
@ -48,7 +55,7 @@ public class LogService {
    /**
     * 保存http调用日志
     * 保存http调用日志  type 0开放api  1基卫接口  2市民健康网接口   3易联众接口
     */
    public void saveHttpLog(Boolean isSuccess,String url,String content,String method,String header,String params,String response,String error,String type)
    {
@ -76,4 +83,6 @@ public class LogService {
            ex.printStackTrace();
        }
    }
}

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

@ -0,0 +1,72 @@
package com.yihu.wlyy.service.weixin.wxpay.common;
import org.springframework.context.annotation.Configuration;
/**
 * User: hzp
 * Date: 20170518
 * 这里放置各种配置数据
 */
@Configuration
public class Configure {
	/******************************* 易联众统一支付平台 ***********************************************************/
	private String onepayApi = "http://120.42.37.94:1301/onepay-web/";
	private String onepayAppId = "1BGKM1UHM03P7B2CA8C000005626EB0E";
	private String onepayAppSecret = "1BGKM1UHM03I7B2CA8C00000AB682E9A";
	private String bindCardType = "onepay.sicard.bind.info";
	private String chargeType = "onepay.trade.medical.charge";
	private String chargeQueryType = "onepay.trade.medical.charge.query";
	public String getOnepayApi() {
		return onepayApi;
	}
	public String getOnepayAppId() {
		return onepayAppId;
	}
	public String getOnepayAppSecret() {
		return onepayAppSecret;
	}
	public String getBindCardType() {
		return bindCardType;
	}
	public String getChargeType() {
		return chargeType;
	}
	public String getChargeQueryType() {
		return chargeQueryType;
	}
	/******************* 微信社保支付配置 ******************************************/
	//这个就是自己要保管好的私有Key了(切记只能放在自己的后台代码里,不能放在任何可能被看到源代码的客户端程序中)
	// 每次自己Post数据给API的时候都要用这个key来对所有字段进行签名,生成的签名会放在Sign这个字段,API收到Post数据的时候也会用同样的签名算法对Post过来的数据进行签名和验证
	// 收到API的返回的时候也要用这个key来对返回的数据算下签名,跟API的Sign数据进行比较,如果值不一致,有可能数据被第三方给篡改
	private String key = "2935b54b53a957d9516c920a544f2537";
	//微信分配的公众号ID(开通公众号之后可以获取到)
	private String appID = "wxd03f859efdf0873d";
	public String getKey(){
		return key;
	}
	public String getAppid(){
		return appID;
	}
	//获取token地址
	public String TOKEN_API = "https://api.weixin.qq.com/payinsurance/gettoken";
	//挂号/诊间支付统一下单 API 接口
	public String ORDER_API = "https://api.weixin.qq.com/payinsurance/unifiedorder?access_token ACCESS_TOKEN";
}

+ 70 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/model/BindCard.java

@ -0,0 +1,70 @@
package com.yihu.wlyy.service.weixin.wxpay.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.service.third.httplog.LogService;
import com.yihu.wlyy.service.weixin.wxpay.common.Configure;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
 * 社保卡绑定信息
 * add by hzp at 20170524
 */
public class BindCard {
    private String cardNo;
    private String idType;
    private String idNo;
    private String userName;
    private String userId;
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    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 getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
}

+ 161 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/model/Charge.java

@ -0,0 +1,161 @@
package com.yihu.wlyy.service.weixin.wxpay.model;
/**
 * 医保扣费
 * add by hzp at 20170524
 */
public class Charge {
    private String tradeStatus; //交易状态    0 成功 1 失败  2 已退款
    private String settleNo;  //医保业务流水号
    private String settleTime;  //  医保交易成功时间
    private String outSettleNo;  //  接入应用业务流水号
    private String outSettleTime;  //  接入应用内业务时间
    private String medOrgNo;  //  医疗机构编号
    private String medOrgName;  //  医疗机构名称
    private String billNo;  //  待结算费用单据号
    private String cardNo;  //  医保卡号
    private String totalAmount;  //  交易总金额
    private String insuranceAmount;  //  医保支付金额
    private String selfPayAmount;  //  自付金额
    private String userId;  // 用户openId
    private String userName;  // 用户姓名
    private String idType;  // 证件号码
    private String idNo;  // 证件类型
    private String responseContent;  //扣费详情
    public String getTradeStatus() {
        return tradeStatus;
    }
    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }
    public String getSettleNo() {
        return settleNo;
    }
    public void setSettleNo(String settleNo) {
        this.settleNo = settleNo;
    }
    public String getSettleTime() {
        return settleTime;
    }
    public void setSettleTime(String settleTime) {
        this.settleTime = settleTime;
    }
    public String getOutSettleNo() {
        return outSettleNo;
    }
    public void setOutSettleNo(String outSettleNo) {
        this.outSettleNo = outSettleNo;
    }
    public String getOutSettleTime() {
        return outSettleTime;
    }
    public void setOutSettleTime(String outSettleTime) {
        this.outSettleTime = outSettleTime;
    }
    public String getMedOrgNo() {
        return medOrgNo;
    }
    public void setMedOrgNo(String medOrgNo) {
        this.medOrgNo = medOrgNo;
    }
    public String getMedOrgName() {
        return medOrgName;
    }
    public void setMedOrgName(String medOrgName) {
        this.medOrgName = medOrgName;
    }
    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 String getTotalAmount() {
        return totalAmount;
    }
    public void setTotalAmount(String totalAmount) {
        this.totalAmount = totalAmount;
    }
    public String getInsuranceAmount() {
        return insuranceAmount;
    }
    public void setInsuranceAmount(String insuranceAmount) {
        this.insuranceAmount = insuranceAmount;
    }
    public String getSelfPayAmount() {
        return selfPayAmount;
    }
    public void setSelfPayAmount(String selfPayAmount) {
        this.selfPayAmount = selfPayAmount;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    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 getResponseContent() {
        return responseContent;
    }
    public void setResponseContent(String responseContent) {
        this.responseContent = responseContent;
    }
}

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

@ -0,0 +1,256 @@
package com.yihu.wlyy.service.weixin.wxpay.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
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.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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
 * 易联众统一支付服务类
 * add by hzp at 20170523
 */
@Service
public class OnePayService {
    @Autowired
    private Configure config;
    @Autowired
    private LogService logService;
    private String signType= "MD5";
    private String encryptType= "AES";
    @Autowired
    private HospitalMappingDao hospitalMappingDao;
    /**
     * 查询绑卡信息
     */
    public BindCard bindCard(String openid) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        BindCard result = null;
        String appId = config.getOnepayAppId();
        String appSecret = config.getOnepayAppSecret();
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(),appId, appSecret, signType, encryptType);
        try {
            RequestParams requestParams = new RequestParams();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            // 请求报文体参数,详见接口文档各接口——请求参数定义
            // 如医保绑卡信息请求参数
            JSONObject params = new JSONObject();
            params.put("userId", openid);
            requestParams.setParam(params);
            requestParams.setTransType(config.getBindCardType());
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            msgBody =  JSON.toJSONString(requestParams);
            response =  JSON.toJSONString(res);
            // 如医保卡绑卡信息返回参数
            if (OnepayDefaultClient.isSuccessful(res)) {
                result = JSON.toJavaObject(res.getParam(), BindCard.class);
                //业务处理***********
                System.out.println("请求成功,返回参数:" + result.getCardNo() + "," +  result.getIdType() + "," + result.getIdNo() + "," + result.getUserName() + "," + result.getUserId());
            }
            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();
        }
        //保存http日志
        logService.saveHttpLog(isSuccess,config.getBindCardType(),"查询绑卡信息","POST",null,msgBody,response,error,logService.onepayType);
        if(!isSuccess)
        {
            throw new Exception(error);
        }
        return result;
    }
    /**
     * 家庭医生签约支付
     */
    public String charge(String orgCode,String code,String date,String cardNo,String openid) throws Exception
    {
        //获取机构映射
        HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
        if(hos==null)
        {
            throw new Exception("no hospital mapping!");
        }
        return charge(hos.getAppId(), hos.getAppSecret(), code, date, cardNo, openid);
    }
    /**
     * 家庭医生签约支付
     */
    public String charge(String appId,String appSecret,String code,String date,String cardNo,String openid) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        String result = "";
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(),appId, appSecret, signType, encryptType);
        try {
            RequestParams requestParams = new RequestParams();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setTransType(config.getChargeType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outSettleNo",code);  //接入应用结算业务流水号
            params.put("outSettleTime",date);    //接入应用内结算时间
            params.put("userId",openid);   //用户 ID
            params.put("cardNo",cardNo);   //医保卡号"D64775061"
            params.put("totalAmount","1");   //交易总金额
            params.put("selfpayAmount","0");   //自费金额
            params.put("insuranceAmount","1");   //医保支付金额
            params.put("returnUrl","http://");   //页面跳转地址
            params.put("feeDetail","{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"120\",\"itemNowPrice\":\"120\",\"itemNum\":\"1\",\"itemTotalAmt\":\"120\"}");   //费用明细
            params.put("channel","WX_MMP");  //微信医保支付
            //extendParams 扩展入参
            //requestContent 请求结构体
            requestParams.setParam(params);
            //执行支付
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            msgBody =  JSON.toJSONString(requestParams);
            response =  JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                JSONObject json = res.getParam();
                result = String.valueOf(json.get("settleNo"));      //医保结算业务流水号
                String payUrl =  String.valueOf(json.get("payUrl"));
                //业务处理***********
            } 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();
        }
        //保存http日志
        logService.saveHttpLog(isSuccess,config.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
        if(!isSuccess)
        {
            throw new Exception(error);
        }
        return result;
    }
    /**
     * 家庭医生签约支付查询
     */
    public Charge chargeQuery(String code) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        Charge result = null;
        String appId = config.getOnepayAppId();
        String appSecret = config.getOnepayAppSecret();
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(),appId, appSecret, signType, encryptType);
        try {
            RequestParams requestParams = new RequestParams();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setTransType(config.getChargeQueryType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outSettleNo",code);  //接入应用结算业务流水号
            params.put("settleNo","");
            requestParams.setParam(params);
            //执行支付
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            msgBody =  JSON.toJSONString(requestParams);
            response =  JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                result = JSON.toJavaObject(res.getParam(),Charge.class);
                //业务处理*******************
                System.out.println("请求成功,返回参数:" + result.getTradeStatus() +"  " + result.getUserName());
            } 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();
        }
        //保存http日志
        logService.saveHttpLog(isSuccess,config.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
        if(!isSuccess)
        {
            throw new Exception(error);
        }
        return result;
    }
}

+ 488 - 479
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/health/PatientHealthController.java

@ -2,6 +2,7 @@ package com.yihu.wlyy.web.patient.health;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.yihu.wlyy.health.entity.DevicePatientHealthIndex;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -29,267 +30,267 @@ import com.yihu.wlyy.web.BaseController;
@Api(description = "患者指标")
public class PatientHealthController extends BaseController {
    @Autowired
    private PatientHealthIndexService healthIndexService;
	@Autowired
	private PatientHealthIndexService healthIndexService;
    /**
     * 更改接口(包括手动记录的修改和所有的删除)
     * 血糖  value1 血糖值 value2 1234567血糖时间段
     * 血压  value1 高压 value2 低压 value3脉搏 value4心率不齐(0否 1是)
     * 体重 value1 体重值
     * 腰围 value1 腰围值
     * @param id
     * @param value1 字段值
     * @return
     */
    @RequestMapping(value = "/modify", method = RequestMethod.GET)
    @ResponseBody
    public String modify(@RequestParam long id,
                         @RequestParam(required = false) String value1,
                         @RequestParam(required = false) String value2,
                         @RequestParam(required = false) String value3,
                         @RequestParam(required = false) String value4) {
        try {
            healthIndexService.modify(id,value1,value2,value3,value4);
            return write(200, "更改成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "更改失败!");
        }
    }
	/**
	 * 更改接口(包括手动记录的修改和所有的删除)
	 * 血糖  value1 血糖值 value2 1234567血糖时间段
	 * 血压  value1 高压 value2 低压 value3脉搏 value4心率不齐(0否 1是)
	 * 体重 value1 体重值
	 * 腰围 value1 腰围值
	 *
	 * @param id
	 * @param value1 字段值
	 * @return
	 */
	@RequestMapping(value = "/modify", method = RequestMethod.GET)
	@ResponseBody
	public String modify(@RequestParam long id,
						 @RequestParam(required = false) String value1,
						 @RequestParam(required = false) String value2,
						 @RequestParam(required = false) String value3,
						 @RequestParam(required = false) String value4) {
		try {
			healthIndexService.modify(id, value1, value2, value3, value4);
			return write(200, "更改成功!");
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "更改失败!");
		}
	}
    /**
     * 患者最近的各项健康信息
     *
     * @return
     */
    @RequestMapping(value = "/getRecentData")
    @ResponseBody
    public String getRecentData() {
        try {
            List list = new ArrayList();
            String patient = getUID();
	/**
	 * 患者最近的各项健康信息
	 *
	 * @return
	 */
	@RequestMapping(value = "/getRecentData")
	@ResponseBody
	public String getRecentData() {
		try {
			List list = new ArrayList();
			String patient = getUID();
//            健康指标类型(1血糖,2血压,3体重,4腰围)
            Map map = healthIndexService.findDataByPatient(patient, 1);
            Map map1 = healthIndexService.findDataByPatient(patient, 2);
            Map map2 = healthIndexService.findDataByPatient(patient, 3);
            Map map3 = healthIndexService.findDataByPatient(patient, 4);
			Map map = healthIndexService.findDataByPatient(patient, 1);
			Map map1 = healthIndexService.findDataByPatient(patient, 2);
			Map map2 = healthIndexService.findDataByPatient(patient, 3);
			Map map3 = healthIndexService.findDataByPatient(patient, 4);
//            血糖各个时间段取值
            if (map.size() != 0) {
                Map sugar = new HashMap();
                Object time = map.get("time");
                String isDevice = map.get("isDevice").toString();
                Object value1 = map.get("value1");
                Object value2 = map.get("value2");
                Object value3 = map.get("value3");
                Object value4 = map.get("value4");
                Object value5 = map.get("value5");
                Object value6 = map.get("value6");
                Object value7 = map.get("value7");
                sugar.put("type", 1);
                sugar.put("isDevice", isDevice);
                if (time != null) {
                    sugar.put("time", time);
                }
                if (value1 != null) {
                    sugar.put("value1", value1);
                }
                if (value2 != null) {
                    sugar.put("value2", value2);
                }
                if (value3 != null) {
                    sugar.put("value3", value3);
                }
                if (value4 != null) {
                    sugar.put("value4", value4);
                }
                if (value5 != null) {
                    sugar.put("value5", value5);
                }
                if (value6 != null) {
                    sugar.put("value6", value6);
                }
                if (value7 != null) {
                    sugar.put("value7", value7);
                }
                list.add(sugar);
            }
			if (map.size() != 0) {
				Map sugar = new HashMap();
				Object time = map.get("time");
				String isDevice = map.get("isDevice").toString();
				Object value1 = map.get("value1");
				Object value2 = map.get("value2");
				Object value3 = map.get("value3");
				Object value4 = map.get("value4");
				Object value5 = map.get("value5");
				Object value6 = map.get("value6");
				Object value7 = map.get("value7");
				sugar.put("type", 1);
				sugar.put("isDevice", isDevice);
				if (time != null) {
					sugar.put("time", time);
				}
				if (value1 != null) {
					sugar.put("value1", value1);
				}
				if (value2 != null) {
					sugar.put("value2", value2);
				}
				if (value3 != null) {
					sugar.put("value3", value3);
				}
				if (value4 != null) {
					sugar.put("value4", value4);
				}
				if (value5 != null) {
					sugar.put("value5", value5);
				}
				if (value6 != null) {
					sugar.put("value6", value6);
				}
				if (value7 != null) {
					sugar.put("value7", value7);
				}
				list.add(sugar);
			}
//            血压  value1高压 value2低压 value3脉搏 value4心率不齐
            if (map1.size() != 0) {
                Map pa = new HashMap();
                Object time = map1.get("time");
                String isDevice = map1.get("isDevice").toString();
                Object value1 = map1.get("value1");
                Object value2 = map1.get("value2");
                Object value3 = map1.get("value3");
                Object value4 = map1.get("value4");
                Object value5 = map1.get("value5");
                Object value6 = map1.get("value6");
                Object value7 = map1.get("value7");
                pa.put("type", 2);
                pa.put("isDevice", isDevice);
                if (time != null) {
                    pa.put("time", time);
                }
                if (value1 != null) {
                    pa.put("value1", value1);
                }
                if (value2 != null) {
                    pa.put("value2", value2);
                }
                if (value3 != null) {
                    pa.put("value3", value3);
                }
                if (value4 != null) {
                    pa.put("value4", value4);
                }
                if (value5 != null) {
                    pa.put("value5", value5);
                }
                if (value6 != null) {
                    pa.put("value6", value6);
                }
                if (value7 != null) {
                    pa.put("value7", value7);
                }
                list.add(pa);
            }
			if (map1.size() != 0) {
				Map pa = new HashMap();
				Object time = map1.get("time");
				String isDevice = map1.get("isDevice").toString();
				Object value1 = map1.get("value1");
				Object value2 = map1.get("value2");
				Object value3 = map1.get("value3");
				Object value4 = map1.get("value4");
				Object value5 = map1.get("value5");
				Object value6 = map1.get("value6");
				Object value7 = map1.get("value7");
				pa.put("type", 2);
				pa.put("isDevice", isDevice);
				if (time != null) {
					pa.put("time", time);
				}
				if (value1 != null) {
					pa.put("value1", value1);
				}
				if (value2 != null) {
					pa.put("value2", value2);
				}
				if (value3 != null) {
					pa.put("value3", value3);
				}
				if (value4 != null) {
					pa.put("value4", value4);
				}
				if (value5 != null) {
					pa.put("value5", value5);
				}
				if (value6 != null) {
					pa.put("value6", value6);
				}
				if (value7 != null) {
					pa.put("value7", value7);
				}
				list.add(pa);
			}
//            体重 value1 体重
            if (map2.size() != 0) {
                Map weight = new HashMap();
                Object time = map2.get("time");
                String isDevice = map2.get("isDevice").toString();
                Object value1 = map2.get("value1");
                Object value2 = map2.get("value2");
                Object value3 = map2.get("value3");
                Object value4 = map2.get("value4");
                Object value5 = map2.get("value5");
                Object value6 = map2.get("value6");
                Object value7 = map2.get("value7");
                weight.put("type", 3);
                weight.put("isDevice", isDevice);
                if (time != null) {
                    weight.put("time", time);
                }
                if (value1 != null) {
                    weight.put("value1", value1);
                }
                if (value2 != null) {
                    weight.put("value2", value2);
                }
                if (value3 != null) {
                    weight.put("value3", value3);
                }
                if (value4 != null) {
                    weight.put("value4", value4);
                }
                if (value5 != null) {
                    weight.put("value5", value5);
                }
                if (value6 != null) {
                    weight.put("value6", value6);
                }
                if (value7 != null) {
                    weight.put("value7", value7);
                }
                list.add(weight);
            }
			if (map2.size() != 0) {
				Map weight = new HashMap();
				Object time = map2.get("time");
				String isDevice = map2.get("isDevice").toString();
				Object value1 = map2.get("value1");
				Object value2 = map2.get("value2");
				Object value3 = map2.get("value3");
				Object value4 = map2.get("value4");
				Object value5 = map2.get("value5");
				Object value6 = map2.get("value6");
				Object value7 = map2.get("value7");
				weight.put("type", 3);
				weight.put("isDevice", isDevice);
				if (time != null) {
					weight.put("time", time);
				}
				if (value1 != null) {
					weight.put("value1", value1);
				}
				if (value2 != null) {
					weight.put("value2", value2);
				}
				if (value3 != null) {
					weight.put("value3", value3);
				}
				if (value4 != null) {
					weight.put("value4", value4);
				}
				if (value5 != null) {
					weight.put("value5", value5);
				}
				if (value6 != null) {
					weight.put("value6", value6);
				}
				if (value7 != null) {
					weight.put("value7", value7);
				}
				list.add(weight);
			}
//            腰围 value1腰围
            if (map3.size() != 0) {
                Map waist = new HashMap();
                Object time = map3.get("time");
                String isDevice = map3.get("isDevice").toString();
                Object value1 = map3.get("value1");
                Object value2 = map3.get("value2");
                Object value3 = map3.get("value3");
                Object value4 = map3.get("value4");
                Object value5 = map3.get("value5");
                Object value6 = map3.get("value6");
                Object value7 = map3.get("value7");
                waist.put("type", 4);
                waist.put("isDevice", isDevice);
                if (time != null) {
                    waist.put("time", time);
                }
                if (value1 != null) {
                    waist.put("value1", value1);
                }
                if (value2 != null) {
                    waist.put("value2", value2);
                }
                if (value3 != null) {
                    waist.put("value3", value3);
                }
                if (value4 != null) {
                    waist.put("value4", value4);
                }
                if (value5 != null) {
                    waist.put("value5", value5);
                }
                if (value6 != null) {
                    waist.put("value6", value6);
                }
                if (value7 != null) {
                    waist.put("value7", value7);
                }
                list.add(waist);
            }
            return write(200, "查询成功", "data", list);
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
			if (map3.size() != 0) {
				Map waist = new HashMap();
				Object time = map3.get("time");
				String isDevice = map3.get("isDevice").toString();
				Object value1 = map3.get("value1");
				Object value2 = map3.get("value2");
				Object value3 = map3.get("value3");
				Object value4 = map3.get("value4");
				Object value5 = map3.get("value5");
				Object value6 = map3.get("value6");
				Object value7 = map3.get("value7");
				waist.put("type", 4);
				waist.put("isDevice", isDevice);
				if (time != null) {
					waist.put("time", time);
				}
				if (value1 != null) {
					waist.put("value1", value1);
				}
				if (value2 != null) {
					waist.put("value2", value2);
				}
				if (value3 != null) {
					waist.put("value3", value3);
				}
				if (value4 != null) {
					waist.put("value4", value4);
				}
				if (value5 != null) {
					waist.put("value5", value5);
				}
				if (value6 != null) {
					waist.put("value6", value6);
				}
				if (value7 != null) {
					waist.put("value7", value7);
				}
				list.add(waist);
			}
			return write(200, "查询成功", "data", list);
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
    /**
     * 患者最近填写的健康指标
     *
     * @return
     */
    @RequestMapping(value = "recent")
    @ResponseBody
    public String recent() {
        try {
            JSONArray array = healthIndexService.findRecentByPatient(getUID());
            if (array != null) {
                return write(200, "查询成功", "list", array);
            } else {
                return error(-1, "查询失败");
            }
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败");
        }
    }
	/**
	 * 患者最近填写的健康指标
	 *
	 * @return
	 */
	@RequestMapping(value = "recent")
	@ResponseBody
	public String recent() {
		try {
			JSONArray array = healthIndexService.findRecentByPatient(getUID());
			if (array != null) {
				return write(200, "查询成功", "list", array);
			} else {
				return error(-1, "查询失败");
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "查询失败");
		}
	}
	/**
	 * 获取患者最后填写的健康指标(新)
	 *
	 * @return
	 */
	@RequestMapping(value="last")
	@RequestMapping(value = "last")
	@ResponseBody
	public String last(){
	public String last() {
		try {
			Map<String,Object> map = new HashMap<>();
			Map<String, Object> map = new HashMap<>();
			String patient = getUID();
			DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient,1);
			if(xt!=null)
			{
				map.put("xt",xt);
			DevicePatientHealthIndex xt = healthIndexService.findLastByPatien(patient, 1);
			if (xt != null) {
				map.put("xt", xt);
			}
			DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient,2);
			if(xy!=null)
			{
				map.put("xy",xy);
			DevicePatientHealthIndex xy = healthIndexService.findLastByPatien(patient, 2);
			if (xy != null) {
				map.put("xy", xy);
			}
			DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient,3);
			if(tz != null){
				map.put("tz",tz);
			DevicePatientHealthIndex tz = healthIndexService.findLastByPatien(patient, 3);
			if (tz != null) {
				map.put("tz", tz);
			}
			DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient,4);
			if(sg != null){
				map.put("sg",sg);
			DevicePatientHealthIndex sg = healthIndexService.findLastByPatien(patient, 4);
			if (sg != null) {
				map.put("sg", sg);
			}
			return write(200, "查询成功", "data", map);
		} catch (Exception ex) {
@ -299,16 +300,17 @@ public class PatientHealthController extends BaseController {
	/**
	 * 保存患者健康指标 (旧)
	 *
	 * @param intervene 干预标志
	 * @param time 记录时间
	 * @param value1 血糖/收缩压/体重/腰围/早餐前空腹
	 * @param value2 舒张压/早餐后空腹
	 * @param value3 午餐空腹
	 * @param value4 午餐后
	 * @param value5 晚餐空腹
	 * @param value6 晚餐后
	 * @param value7 睡前
	 * @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @param time      记录时间
	 * @param value1    血糖/收缩压/体重/腰围/早餐前空腹
	 * @param value2    舒张压/早餐后空腹
	 * @param value3    午餐空腹
	 * @param value4    午餐后
	 * @param value5    晚餐空腹
	 * @param value6    晚餐后
	 * @param value7    睡前
	 * @param type      健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @return 操作结果
	 */
	@RequestMapping(value = "add")
@ -316,144 +318,145 @@ public class PatientHealthController extends BaseController {
	public String add(@RequestParam(required = false) String intervene, String time, String value1, String value2, String value3, String value4, String value5, String value6, String value7, int type) {
		try {
            DevicePatientHealthIndex healthIndex = null;
            if (type == 1) {
                // 血糖等一天只能存在一条数据
                Iterable<DevicePatientHealthIndex> list = healthIndexService.findByPatienDate(getUID(), type, DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
                if (list != null) {
                    for (DevicePatientHealthIndex model : list) {
                        healthIndex = model;
                    }
                }
            }
            if (healthIndex == null) {
                healthIndex = new DevicePatientHealthIndex();
            }
            // 设置患者标识
            healthIndex.setUser(getUID());
            // 设置干预标识,默认为NULL
            healthIndex.setIntervene(intervene);
			DevicePatientHealthIndex healthIndex = null;
			if (type == 1) {
				// 血糖等一天只能存在一条数据
				Iterable<DevicePatientHealthIndex> list = healthIndexService.findByPatienDate(getUID(), type, DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
				if (list != null) {
					for (DevicePatientHealthIndex model : list) {
						healthIndex = model;
					}
				}
			}
			if (healthIndex == null) {
				healthIndex = new DevicePatientHealthIndex();
			}
			// 设置患者标识
			healthIndex.setUser(getUID());
			// 设置干预标识,默认为NULL
			healthIndex.setIntervene(intervene);
            int index = 0;
            double value = 0;
			int index = 0;
			double value = 0;
            // 设置血糖/收缩压/体重/腰围/早餐前空腹
            if (NumberUtils.toDouble(value1, 0) > 0) {
                healthIndex.setValue1(value1);
                index = 1;
                value = NumberUtils.toDouble(value1, 0);
            }
            // 设置 舒张压/早餐后血糖
            if (NumberUtils.toDouble(value2, 0) > 0) {
                healthIndex.setValue2(value2);
                index = 2;
                value = NumberUtils.toDouble(value2, 0);
            }
            // 设置午餐前血糖
            if (NumberUtils.toDouble(value3, 0) > 0) {
                healthIndex.setValue3(value3);
                index = 3;
                value = NumberUtils.toDouble(value3, 0);
            }
            // 设置午餐后血糖
            if (NumberUtils.toDouble(value4, 0) > 0) {
                healthIndex.setValue4(value4);
                index = 4;
                value = NumberUtils.toDouble(value4, 0);
            }
            // 设置晚餐前血糖
            if (NumberUtils.toDouble(value5, 0) > 0) {
                healthIndex.setValue5(value5);
                index = 5;
                value = NumberUtils.toDouble(value5, 0);
            }
            // 设置晚餐后血糖
            if (NumberUtils.toDouble(value6, 0) > 0) {
                healthIndex.setValue6(value6);
                index = 6;
                value = NumberUtils.toDouble(value6, 0);
            }
            // 设置睡前血糖
            if (NumberUtils.toDouble(value7, 0) > 0) {
                healthIndex.setValue7(value7);
                index = 7;
                value = NumberUtils.toDouble(value7, 0);
            }
            // 设置健康指标类型(1血糖,2血压,3体重,4腰围)
            healthIndex.setType(type);
            // 设置记录时间
            if (type == 2) {
                healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
            } else {
                healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
            }
            healthIndex.setSortDate(DateUtil.strToDateAppendNowTime(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
            // 保存到数据库
            healthIndex = healthIndexService.save(healthIndex, index, value, getUID());
            if (healthIndex == null) {
                return error(-1, "保存失败!");
            }
            return success("保存成功!");
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "保存失败!");
        }
    }
			// 设置血糖/收缩压/体重/腰围/早餐前空腹
			if (NumberUtils.toDouble(value1, 0) > 0) {
				healthIndex.setValue1(value1);
				index = 1;
				value = NumberUtils.toDouble(value1, 0);
			}
			// 设置 舒张压/早餐后血糖
			if (NumberUtils.toDouble(value2, 0) > 0) {
				healthIndex.setValue2(value2);
				index = 2;
				value = NumberUtils.toDouble(value2, 0);
			}
			// 设置午餐前血糖
			if (NumberUtils.toDouble(value3, 0) > 0) {
				healthIndex.setValue3(value3);
				index = 3;
				value = NumberUtils.toDouble(value3, 0);
			}
			// 设置午餐后血糖
			if (NumberUtils.toDouble(value4, 0) > 0) {
				healthIndex.setValue4(value4);
				index = 4;
				value = NumberUtils.toDouble(value4, 0);
			}
			// 设置晚餐前血糖
			if (NumberUtils.toDouble(value5, 0) > 0) {
				healthIndex.setValue5(value5);
				index = 5;
				value = NumberUtils.toDouble(value5, 0);
			}
			// 设置晚餐后血糖
			if (NumberUtils.toDouble(value6, 0) > 0) {
				healthIndex.setValue6(value6);
				index = 6;
				value = NumberUtils.toDouble(value6, 0);
			}
			// 设置睡前血糖
			if (NumberUtils.toDouble(value7, 0) > 0) {
				healthIndex.setValue7(value7);
				index = 7;
				value = NumberUtils.toDouble(value7, 0);
			}
			// 设置健康指标类型(1血糖,2血压,3体重,4腰围)
			healthIndex.setType(type);
			// 设置记录时间
			if (type == 2) {
				healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
			} else {
				healthIndex.setRecordDate(DateUtil.strToDate(time, DateUtil.YYYY_MM_DD));
			}
			healthIndex.setSortDate(DateUtil.strToDateAppendNowTime(time, DateUtil.YYYY_MM_DD_HH_MM_SS));
			// 保存到数据库
			healthIndex = healthIndexService.save(healthIndex, index, value, getUID());
			if (healthIndex == null) {
				return error(-1, "保存失败!");
			}
			return success("保存成功!");
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "保存失败!");
		}
	}
    @RequestMapping(value = "addPatientHealthIndex", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("新增患者指标")
    public String addPatientHealthIndex(@ApiParam(name = "data", value = "指标数据", defaultValue = "{\"gi\":\"5.5\",\"gi_type\":\"1\"}")
                                        @RequestParam(value = "data", required = true) String data,
                                        @ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                        @RequestParam(value = "type", required = true) String type) {
        try {
            DevicePatientHealthIndex obj = healthIndexService.addPatientHealthIndex(data, type, getUID(), null);
            //血糖和血压需要校验
            if (type.equals("1") || type.equals("2")) {
                healthIndexService.verifyHealthIndex(obj.getId());
            }
	@RequestMapping(value = "addPatientHealthIndex", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("新增患者指标")
	public String addPatientHealthIndex(@ApiParam(name = "data", value = "指标数据", defaultValue = "{\"gi\":\"5.5\",\"gi_type\":\"1\"}")
										@RequestParam(value = "data", required = true) String data,
										@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
										@RequestParam(value = "type", required = true) String type) {
		try {
			DevicePatientHealthIndex obj = healthIndexService.addPatientHealthIndex(data, type, getUID(), null);
			//血糖和血压需要校验
			if (type.equals("1") || type.equals("2")) {
				healthIndexService.verifyHealthIndex(obj.getId());
			}
            return success("新增患者指标成功!");
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
			return success("新增患者指标成功!");
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
    @RequestMapping(value = "verifyPatientHealthIndex", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("校验患者指标")
    public String verifyPatientHealthIndex(@ApiParam(name = "id", value = "指标id", defaultValue = "")
                                           @RequestParam(value = "id", required = true) Long id) {
        try {
            healthIndexService.verifyHealthIndex(id);
	@RequestMapping(value = "verifyPatientHealthIndex", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("校验患者指标")
	public String verifyPatientHealthIndex(@ApiParam(name = "id", value = "指标id", defaultValue = "")
										   @RequestParam(value = "id", required = true) Long id) {
		try {
			healthIndexService.verifyHealthIndex(id);
            return success("校验患者指标成功!");
        } catch (Exception ex) {
            return invalidUserException(ex, -1, ex.getMessage());
        }
    }
			return success("校验患者指标成功!");
		} catch (Exception ex) {
			return invalidUserException(ex, -1, ex.getMessage());
		}
	}
	/**
	 * 根据患者标志获取健康指标
	 *
	 * @param type 健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @return 操作结果
	 */
	@RequestMapping(value = "chart",method = RequestMethod.POST)
	@RequestMapping(value = "chart", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("根据患者标志获取健康指标(图表)")
	public String getHealthIndexChartByPatient(@ApiParam(name="type",value="指标类型",defaultValue = "1")
												   @RequestParam(value="type",required = true) int type,
											   @ApiParam(name="gi_type",value="就餐类型",defaultValue = "1")
											       @RequestParam(value = "gi_type",required = false) int gi_type,
											   @ApiParam(name="begin",value="开始时间",defaultValue = "2016-08-23 00:00:00")
											   @RequestParam(value="begin",required = true) String begin,
											   @ApiParam(name="end",value="结束时间",defaultValue = "2016-09-23 00:00:00")
												   @RequestParam(value="end",required = true) String end) {
	public String getHealthIndexChartByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
											   @RequestParam(value = "type", required = true) int type,
											   @ApiParam(name = "gi_type", value = "就餐类型", defaultValue = "1")
											   @RequestParam(value = "gi_type", required = false) int gi_type,
											   @ApiParam(name = "begin", value = "开始时间", defaultValue = "2016-08-23 00:00:00")
											   @RequestParam(value = "begin", required = true) String begin,
											   @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-09-23 00:00:00")
											   @RequestParam(value = "end", required = true) String end) {
		try {
			List<DevicePatientHealthIndex> list =
				 healthIndexService.findChartByPatient(getUID(),type,gi_type,begin,end);
					healthIndexService.findChartByPatient(getUID(), type, gi_type, begin, end);
			if (list == null) {
				return success("查询成功!");
@ -470,9 +473,9 @@ public class PatientHealthController extends BaseController {
				modelJson.put("value6", model.getValue6());
				modelJson.put("value7", model.getValue7());
				modelJson.put("type", model.getType());
				if(type == 2){
				if (type == 2) {
					modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
				}else{
				} else {
					modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
				}
				modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
@ -485,112 +488,118 @@ public class PatientHealthController extends BaseController {
		}
	}
    /**
     * 根据患者标志获取健康指标
     *
     * @param type     健康指标类型(1血糖,2血压,3体重,4腰围)
     * @param pagesize 页数
     * @return 操作结果
     */
    @RequestMapping(value = "list", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("患者获取健康指标")
    public String getHealthIndexByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
                                          @RequestParam(value = "type", required = true) int type,
                                          @ApiParam(name = "start", value = "开始时间", defaultValue = "2016-07-23 00:00:00")
                                          @RequestParam(value = "start", required = true) String start,
                                          @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-08-23 00:00:00")
                                          @RequestParam(value = "end", required = true) String end,
                                          @ApiParam(name = "page", value = "第几页", defaultValue = "1")
                                          @RequestParam(value = "page", required = true) int page,
                                          @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
                                          @RequestParam(value = "pagesize", required = true) int pagesize) {
        try {
            List<DevicePatientHealthIndex> list = healthIndexService.findIndexByPatient(getUID(), type, start, end, page, pagesize);
            JSONArray jsonArray = new JSONArray();
            if (list != null) {
                for (DevicePatientHealthIndex model : list) {
                    JSONObject modelJson = new JSONObject();
                    modelJson.put("id", model.getId());
                    modelJson.put("patient", model.getUser());
                    modelJson.put("value1", model.getValue1());
                    modelJson.put("value2", model.getValue2());
                    modelJson.put("value3", model.getValue3());
                    modelJson.put("value4", model.getValue4());
                    modelJson.put("value5", model.getValue5());
                    modelJson.put("value6", model.getValue6());
                    modelJson.put("value7", model.getValue7());
                    modelJson.put("type", model.getType());
                    if (type == 2) {
                        modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                    } else {
                        modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
                    }
                    modelJson.put("sortDate", DateUtil.dateToStrLong(model.getSortDate()));
                    modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
                    jsonArray.put(modelJson);
                }
            }
	/**
	 * 根据患者标志获取健康指标
	 *
	 * @param type     健康指标类型(1血糖,2血压,3体重,4腰围)
	 * @param pagesize 页数
	 * @return 操作结果
	 */
	@RequestMapping(value = "list", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation("患者获取健康指标")
	public String getHealthIndexByPatient(@ApiParam(name = "type", value = "指标类型", defaultValue = "1")
										  @RequestParam(value = "type", required = true) int type,
										  @ApiParam(name = "start", value = "开始时间", defaultValue = "2016-07-23 00:00:00")
										  @RequestParam(value = "start", required = true) String start,
										  @ApiParam(name = "end", value = "结束时间", defaultValue = "2016-08-23 00:00:00")
										  @RequestParam(value = "end", required = true) String end,
										  @ApiParam(name = "page", value = "第几页", defaultValue = "1")
										  @RequestParam(value = "page", required = true) int page,
										  @ApiParam(name = "pagesize", value = "每页几行", defaultValue = "10")
										  @RequestParam(value = "pagesize", required = true) int pagesize) {
		try {
			JSONArray jsonArray = new JSONArray();
			if (type == 1) {
				List<Object> list = healthIndexService.findIndexByPatient2(getUID(), type, start, end, page, pagesize);
				jsonArray = new JSONArray(list);
			}else{
				List<DevicePatientHealthIndex> list = healthIndexService.findIndexByPatient(getUID(), type, start, end, page, pagesize);
				if (list != null) {
					for (DevicePatientHealthIndex model : list) {
						JSONObject modelJson = new JSONObject();
						modelJson.put("id", model.getId());
						modelJson.put("patient", model.getUser());
						modelJson.put("value1", model.getValue1());
						modelJson.put("value2", model.getValue2());
						modelJson.put("value3", model.getValue3());
						modelJson.put("value4", model.getValue4());
						modelJson.put("value5", model.getValue5());
						modelJson.put("value6", model.getValue6());
						modelJson.put("value7", model.getValue7());
						modelJson.put("type", model.getType());
						if (type == 2) {
							modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD_HH_MM_SS));
						} else {
							modelJson.put("date", DateUtil.dateToStr(model.getRecordDate(), DateUtil.YYYY_MM_DD));
						}
						modelJson.put("sortDate", DateUtil.dateToStrLong(model.getSortDate()));
						modelJson.put("czrq", DateUtil.dateToStr(model.getCzrq(), DateUtil.YYYY_MM_DD_HH_MM_SS));
						jsonArray.put(modelJson);
					}
				}
			}
            return write(200, "查询成功", "list", jsonArray);
        } catch (Exception ex) {
            error(ex);
            return invalidUserException(ex, -1, "查询失败!");
        }
    }
			return write(200, "查询成功", "list", jsonArray);
		} catch (Exception ex) {
			error(ex);
			return invalidUserException(ex, -1, "查询失败!");
		}
	}
    /**
     * 患者健康指标预警值查询
     *
     * @return
     */
    @RequestMapping(value = "standard")
    @ResponseBody
    public String standard() {
        try {
            JSONArray standardArray = new JSONArray();
            JSONArray userArray = new JSONArray();
            Iterable<PatientHealthStandard> iterable = healthIndexService.findStandardByPatient(getUID());
            Iterator<PatientHealthStandard> iterator = null;
            if (iterable != null) {
                iterator = iterable.iterator();
            }
            // 预警值未设置,返回默认值
            StringBuffer sb = new StringBuffer();
            sb.append("[");
            // 默认血糖(餐前,餐后二小时)
            sb.append("{min_value_1:3.9, max_value_1:6.1, min_value_2:4.4, max_value_2:7.8, type:1},");
            // 默认血压(收缩压,舒张压)
            sb.append("{min_value_1:90, max_value_1:139, min_value_2:60, max_value_2:89, type:2}");
            sb.append("]");
            standardArray = new JSONArray(sb.toString());
            if (iterator != null) {
                while (iterator.hasNext()) {
                    PatientHealthStandard phs = iterator.next();
                    if (phs == null) {
                        continue;
                    }
                    JSONObject json = new JSONObject();
                    // 最低安全值(血糖餐前\收缩压\体重\腰围)
                    json.put("min_value_1", phs.getMinValue1());
                    // 最高安全值(血糖餐前\收缩压\体重\腰围)
                    json.put("max_value_1", phs.getMaxValue1());
                    // 最低安全值(血糖餐后\舒张压)
                    json.put("min_value_2", phs.getMinValue2());
                    // 最高安全值(血糖餐后\舒张压)
                    json.put("max_value_2", phs.getMaxValue2());
                    // 健康指标类型:1血糖,2血压,3体重,4腰围
                    json.put("type", phs.getType());
                    userArray.put(json);
                }
            }
            JSONObject json = new JSONObject();
            json.put("standard", standardArray);
            json.put("custom", userArray);
            return write(200, "查询成功", "data", json);
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "查询失败!");
        }
    }
	/**
	 * 患者健康指标预警值查询
	 *
	 * @return
	 */
	@RequestMapping(value = "standard")
	@ResponseBody
	public String standard() {
		try {
			JSONArray standardArray = new JSONArray();
			JSONArray userArray = new JSONArray();
			Iterable<PatientHealthStandard> iterable = healthIndexService.findStandardByPatient(getUID());
			Iterator<PatientHealthStandard> iterator = null;
			if (iterable != null) {
				iterator = iterable.iterator();
			}
			// 预警值未设置,返回默认值
			StringBuffer sb = new StringBuffer();
			sb.append("[");
			// 默认血糖(餐前,餐后二小时)
			sb.append("{min_value_1:3.9, max_value_1:6.1, min_value_2:4.4, max_value_2:7.8, type:1},");
			// 默认血压(收缩压,舒张压)
			sb.append("{min_value_1:90, max_value_1:139, min_value_2:60, max_value_2:89, type:2}");
			sb.append("]");
			standardArray = new JSONArray(sb.toString());
			if (iterator != null) {
				while (iterator.hasNext()) {
					PatientHealthStandard phs = iterator.next();
					if (phs == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					// 最低安全值(血糖餐前\收缩压\体重\腰围)
					json.put("min_value_1", phs.getMinValue1());
					// 最高安全值(血糖餐前\收缩压\体重\腰围)
					json.put("max_value_1", phs.getMaxValue1());
					// 最低安全值(血糖餐后\舒张压)
					json.put("min_value_2", phs.getMinValue2());
					// 最高安全值(血糖餐后\舒张压)
					json.put("max_value_2", phs.getMaxValue2());
					// 健康指标类型:1血糖,2血压,3体重,4腰围
					json.put("type", phs.getType());
					userArray.put(json);
				}
			}
			JSONObject json = new JSONObject();
			json.put("standard", standardArray);
			json.put("custom", userArray);
			return write(200, "查询成功", "data", json);
		} catch (Exception e) {
			error(e);
			return invalidUserException(e, -1, "查询失败!");
		}
	}
}

+ 81 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -0,0 +1,81 @@
package com.yihu.wlyy.web.wx;
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.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.http.MediaType;
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 hzp on 2017/05/23.
 */
@Controller
@RequestMapping(value = "/onepay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "统一支付服务")
public class OnePayController extends WeixinBaseController {
    @Autowired
    private OnePayService pay;
    @RequestMapping(value = "bindCard", method = RequestMethod.POST)
    @ApiOperation("查询绑卡信息")
    @ResponseBody
    public String bindCard() throws Exception {
        try {
            BindCard bindCard = pay.bindCard(getOpenid());         //oULM4xOARzTFqr9y1aTWuzCQdUL0
            return write(200, "查询绑卡信息成功!","data",bindCard);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "charge", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付")
    @ResponseBody
    public String charge(
                         @ApiParam(name="orgCode",value="医疗机构编号",defaultValue = "3502050300")
                         @RequestParam String orgCode,
                         @ApiParam(name="code",value="签约代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                         @RequestParam String code,
                         @ApiParam(name="date",value="签约付款时间yyyyMMddHHmmss",defaultValue = "20170523172400")
                         @RequestParam String date,
                         @ApiParam(name="cardNo",value="社保卡号",defaultValue = "DC0261911")
                         @RequestParam String cardNo) throws Exception {
        try {
            String settleNo = pay.charge(orgCode,code,date,cardNo,getOpenid());  //"oULM4xOARzTFqr9y1aTWuzCQdUL0"
            return write(200, "家庭医生签约支付成功!","data",settleNo);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "chargeQuery", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付查询")
    @ResponseBody
    public String chargeQuery(@ApiParam(name="code",value="签约代码",defaultValue = "20170523172835")
                               @RequestParam String code) throws Exception {
        try {
            Charge charge = pay.chargeQuery(code);
            return write(200, "家庭医生签约支付查询成功!","data",charge);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
}

BIN
patient-co-wlyy/src/main/resources/onepay-java-sdk.jar