@ -18,39 +18,62 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils ;
import org.apache.commons.lang3.ObjectUtils ;
import java.math.BigDecimal ;
import java.math.BigDecimal ;
import java.util.List ;
@Slf4j
@Slf4j
public class CasebookService {
public class CasebookService {
public Result placeOrder ( MerchantEnum merchantEnum , String ip , String openid , String patientId , String treatNum , String totalFee , String applyId , String getWay , String useToName ) {
// 下单
if ( openid = = null | | patientId = = null | | totalFee = = null ) {
public Result placeOrder ( MerchantEnum merchantEnum , String ip , String openId , String patientId , String patientName , String treatNum , BigDecimal totalFee , String applyId , Integer getWay , String useToNo , String useToName , String address , String phone ) throws ServiceException {
if ( openId = = null | | patientId = = null | | patientName = = null | | treatNum = = null | | totalFee = = null | | applyId = = null | | getWay = = null | | useToName = = null ) {
return Result . error ( ResultEnum . PARAM_IS_DEFECT ) ;
return Result . error ( ResultEnum . PARAM_IS_DEFECT ) ;
}
}
if ( new BigDecimal ( totalFee ) . compareTo ( BigDecimal . ZERO ) = = 0 ) {
if ( totalFee . compareTo ( BigDecimal . ZERO ) = = 0 ) {
return Result . error ( ResultEnum . PAY_MONEY_IS_ZERO ) ;
return Result . error ( ResultEnum . PAY_MONEY_IS_ZERO ) ;
}
}
PayCasebook order = selectOrderByApplyId ( applyId , treatNum ) ;
PayCasebook order = selectOrderByApplyId ( applyId , treatNum ) ;
String outTradeNo = CodeHelper . getOutTradeNo ( merchantEnum ) ;
String outTradeNo = CodeHelper . getOutTradeNo ( merchantEnum ) ;
log . info ( "{} [病历]查询订单 order=[{}]" , merchantEnum . NAME , JsonHelper . toJsonString ( order ) ) ;
if ( order = = null ) {
if ( order ! = null ) {
PayCasebook addInfo = new PayCasebook ( ) ;
addInfo . setTreatNum ( treatNum ) ;
addInfo . setPatientName ( patientName ) ;
addInfo . setUseToNo ( useToNo ) ;
addInfo . setUseToName ( useToName ) ;
addInfo . setGetWay ( getWay ) ;
addInfo . setAddress ( address ) ;
addInfo . setPhone ( phone ) ;
// =========================
addInfo . setApplyId ( applyId ) ;
addInfo . setOutTradeNo ( outTradeNo ) ;
addInfo . setTotalFee ( totalFee ) ;
addInfo . setPayMoney ( totalFee ) ;
addInfo . setPayStatus ( - 1 ) ; // 待支付
if ( ! addResApply ( addInfo , openId , patientId ) ) {
log . info ( "[病历复印]预约申请信息存储失败 patientId={}, openId={}, patientId={}" , patientId , openId , patientId ) ;
return Result . error ( ResultEnum . SPECIFIED_QUESTIONED_USER_NOT_EXIST ) ;
}
} else {
log . info ( "{} [病历复印]下单-查询到订单 order=[{}]" , merchantEnum . NAME , JsonHelper . toJsonString ( order ) ) ;
if ( order . hasPayStatusPaid ( ) ) {
if ( order . hasPayStatusPaid ( ) ) {
log . info ( "{} [病历]订单已支付 applyId={}, outTradeNo={}" , merchantEnum . NAME , applyId , order . getOutTradeNo ( ) ) ;
log . info ( "{} [病历复印 ]订单已支付 applyId={}, outTradeNo={}" , merchantEnum . NAME , applyId , order . getOutTradeNo ( ) ) ;
return Result . error ( ResultEnum . PAY_REPEAT ) ;
return Result . error ( ResultEnum . PAY_REPEAT ) ;
}
}
if ( ObjectUtils . isEmpty ( order . getOutTradeNo ( ) ) ) {
if ( ! ObjectUtils . isEmpty ( order . getOutTradeNo ( ) ) ) {
outTradeNo = order . getOutTradeNo ( ) ;
outTradeNo = order . getOutTradeNo ( ) ;
}
}
}
if ( ! updatePrepayInfo ( applyId , treatNum , new BigDecimal ( totalFee ) , outTradeNo ) ) {
if ( ! updatePrepayInfo ( applyId , treatNum , totalFee , outTradeNo ) ) {
log . info ( "{} [病历]下单信息存储失败 applyId-{}, patientId={},treatNum-{}" , merchantEnum . NAME , applyId , patientId , treatNum ) ;
log . info ( "{} [病历复印]下单信息存储失败 applyId={}, patientId={}, treatNum= {}" , merchantEnum . NAME , applyId , patientId , treatNum ) ;
return Result . error ( ResultEnum . SPECIFIED_QUESTIONED_USER_NOT_EXIST ) ;
return Result . error ( ResultEnum . SPECIFIED_QUESTIONED_USER_NOT_EXIST ) ;
}
}
}
String body = "病历复印缴费 住院号:" + treatNum ;
String body = "病历复印 住院号:" + treatNum ;
JSONObject respJson = PayService . createOrder ( merchantEnum , openid , patientId , totalFee , outTradeNo , PQREnum . CASEBOOK . CODE , ip , body ) ;
JSONObject respJson = PayService . createOrder ( merchantEnum , openI d , patientId , totalFee . toString ( ) , outTradeNo , PQREnum . CASEBOOK . CODE , ip , body ) ;
if ( respJson = = null ) {
if ( respJson = = null ) {
return Result . error ( ResultEnum . PAY_ERROR ) ; // 支付异常
return Result . error ( ResultEnum . PAY_ERROR ) ; // 支付异常
}
}
@ -58,22 +81,37 @@ public class CasebookService {
}
}
// /**
// * [病历复印]判断【今天】是否存在预约记录
// *
// * @param openId openId
// * @param patientId 患者id
// * @param treatNum 住院号
// * @param getWay 方式
// * @param useToNo 模板号
// * @param useToName 模板名称
// * @return bool
// */
// public boolean hasResInfo(String openId, String patientId, String treatNum, String getWay, String useToNo, String useToName) throws ServiceException {
// if (ObjectUtils.isEmpty(openId) || ObjectUtils.isEmpty(patientId) || ObjectUtils.isEmpty(treatNum) || ObjectUtils.isEmpty(useToNo) || ObjectUtils.isEmpty(useToName)) {
// throw new ServiceException(ResultEnum.PARAM_IS_DEFECT);
// }
// return new CasebookDao().selectIsExit(openId, patientId, treatNum, getWay, useToNo, useToName);
// }
/ * *
/ * *
* [ 病历复印 ] 判断 【 今天 】 是否存在预约记录
* [ 病历复印 ] 查询今日预约申请的数据
*
*
* @param openId openId
* @param patientId 患者id
* @param patientId 患者id
* @param treatNum 住院号
* @param treatNum 住院号
* @param getWay 方式
* @param useToNo 模板号
* @param useToName 模板名称
* @return bool
* @return bool
* /
* /
public boolean hasResInfo ( String openId , String patientId , String treatNum , String getWay , String useToNo , String useToName ) throws ServiceException {
public List < PayCasebook > queryListByTreat ( String patientId , String treatNum ) throws ServiceException {
if ( ObjectUtils . isEmpty ( openId ) | | ObjectUtils . isEmpty ( patientId ) | | ObjectUtils . isEmpty ( treatNum ) | | ObjectUtils . isEmpty ( useToNo ) | | ObjectUtils . isEmpty ( useToName ) ) {
if ( ObjectUtils . isEmpty ( patientId ) | | ObjectUtils . isEmpty ( treatNum ) ) {
throw new ServiceException ( ResultEnum . PARAM_IS_DEFECT ) ;
throw new ServiceException ( ResultEnum . PARAM_IS_DEFECT ) ;
}
}
return new CasebookDao ( ) . selectIsExit ( openId , patientId , treatNum , getWay , useToNo , useToName ) ;
return new CasebookDao ( ) . selectListByTreat ( patientId , treatNum ) ;
}
}
@ -86,11 +124,10 @@ public class CasebookService {
* @param outTradeNo 订单号
* @param outTradeNo 订单号
* @return bool
* @return bool
* /
* /
public boolean updatePrepayInfo ( String applyId , String treatNum , BigDecimal totalFee , String outTradeNo ) {
public boolean updatePrepayInfo ( String applyId , String treatNum , BigDecimal totalFee , String outTradeNo ) throws ServiceException {
log . info ( "[病历复印]更新下单信息 applyId={}, treatNum={}, totalFee={}, outTradeNo={}" , applyId , treatNum , totalFee , totalFee ) ;
log . info ( "[病历复印]更新下单信息 applyId={}, treatNum={}, totalFee={}, outTradeNo={}" , applyId , treatNum , totalFee , outTradeNo ) ;
if ( ObjectUtils . isEmpty ( applyId ) | | totalFee . compareTo ( BigDecimal . ZERO ) = = 0 | | ObjectUtils . isEmpty ( outTradeNo ) ) {
if ( ObjectUtils . isEmpty ( applyId ) | | totalFee . compareTo ( BigDecimal . ZERO ) = = 0 | | ObjectUtils . isEmpty ( outTradeNo ) ) {
log . error ( "[病历复印]更新下单信息失败 applyId={}, totalFee={}, outTradeNo={}" , applyId , totalFee , totalFee ) ;
throw new ServiceException ( ResultEnum . PARAM_IS_DEFECT ) ;
return false ;
}
}
return new CasebookDao ( ) . updatePrepayInfo ( applyId , treatNum , totalFee , outTradeNo ) ;
return new CasebookDao ( ) . updatePrepayInfo ( applyId , treatNum , totalFee , outTradeNo ) ;
}
}
@ -116,34 +153,32 @@ public class CasebookService {
* @param casebook 订单信息
* @param casebook 订单信息
* @return bool
* @return bool
* /
* /
public long addResApply ( PayCasebook casebook , String openId , String patientId ) {
public boolean addResApply ( PayCasebook casebook , String openId , String patientId ) {
if ( casebook = = null ) {
if ( casebook = = null | | ObjectUtils . isEmpty ( casebook . getApplyId ( ) ) ) {
log . info ( "casebook is null" ) ;
return false ;
return - 1 ;
}
}
return new CasebookDao ( ) . insert ( casebook , openId , patientId ) ;
return new CasebookDao ( ) . insert ( casebook , openId , patientId ) ;
}
}
public PayCasebook queryOrderByOutTradeNo ( String outTradeNo ) {
/ * *
if ( ObjectUtils . isEmpty ( outTradeNo ) ) {
* 预约成功后 , 记录申请id
return null ;
*
}
* @param id id
return new CasebookDao ( ) . selectByOutTradeNo ( outTradeNo ) ;
* @param applyId 申请id
* @return bool
* /
public boolean updateApplyIdById ( long id , String applyId ) {
return new CasebookDao ( ) . updateApplyIdById ( id , applyId ) ;
}
}
// 支付回调通知
// 支付回调通知
public void paidNotify ( MerchantEnum merchantEnum , String openid , BigDecimal totalFee , String outTradeNo , String bankTransNo , String payInfo ) {
public void paidNotify ( MerchantEnum merchantEnum , String openid , BigDecimal totalFee , String outTradeNo , String bankTransNo , String payInfo ) {
CasebookDao casebookDao = new CasebookDao ( ) ;
PayCasebook order = queryOrderByOutTradeNo ( outTradeNo ) ;
PayCasebook order = casebookDao . selectByOutTradeNo ( outTradeNo ) ;
if ( order = = null ) {
log . error ( "[病历复印][回调]未找到订单 outTradeNo={}, bankTransNo={}, totalFee={}" , outTradeNo , bankTransNo , totalFee ) ;
return ;
}
String applyId = order . getApplyId ( ) ;
String applyId = order . getApplyId ( ) ;
if ( ObjectUtils . isEmpty ( applyId ) ) {
if ( ObjectUtils . isEmpty ( applyId ) ) {
log . error ( "[病历复印]回调: 病历申请ID缺失 outTradeNo={}, bankTransNo={}, applyId={}" , outTradeNo , bankTransNo , applyId ) ;
log . error ( "[病历复印][回调] 病历申请ID缺失 outTradeNo={}, bankTransNo={}, applyId={}" , outTradeNo , bankTransNo , applyId ) ;
return ;
return ;
}
}
@ -152,6 +187,7 @@ public class CasebookService {
return ;
return ;
}
}
CasebookDao casebookDao = new CasebookDao ( ) ;
String tradeNo = PEnum . CASEBOOK . toTradeNo ( bankTransNo ) ;
String tradeNo = PEnum . CASEBOOK . toTradeNo ( bankTransNo ) ;
if ( ! casebookDao . updatePayStateOk ( outTradeNo , bankTransNo ) ) {
if ( ! casebookDao . updatePayStateOk ( outTradeNo , bankTransNo ) ) {
log . info ( "[病历复印]修改支付状态失败 outTradeNo={}, bankTransNo={}, applyId={}" , outTradeNo , bankTransNo , applyId ) ;
log . info ( "[病历复印]修改支付状态失败 outTradeNo={}, bankTransNo={}, applyId={}" , outTradeNo , bankTransNo , applyId ) ;
@ -191,5 +227,17 @@ public class CasebookService {
// return false;
// return false;
// }
// }
// return new CasebookDao().selectIsPay(patientId, treatNum, applyId, getWay, useToName);
// return new CasebookDao().selectIsPay(patientId, treatNum, applyId, getWay, useToName);
// }
//
// /**
// * 预约成功后,记录申请id
// *
// * @param id id
// * @param applyId 申请id
// * @return bool
// */
// public boolean updateApplyIdById(long id, String applyId) {
// return new CasebookDao().updateApplyIdById(id, applyId);
// }
// }
}
}