package thyyxxk.wxservice_server.dao; import com.wechat.pay.java.service.payments.model.Transaction; import org.apache.ibatis.annotations.*; import thyyxxk.wxservice_server.entity.PureCodeName; import thyyxxk.wxservice_server.entity.appointment.DoctorInfo; import thyyxxk.wxservice_server.entity.electronichealthcard.HisRegister; import thyyxxk.wxservice_server.entity.paymzfee.MedinsSettle; import thyyxxk.wxservice_server.entity.scheduled.TradeNo; import thyyxxk.wxservice_server.entity.wxapi.WxPayOrder; import java.math.BigDecimal; import java.util.List; /** * @author dj */ @Mapper public interface WxApiDao { @Select("select rtrim(name) from mz_patient_mi with(nolock) where patient_id=#{patientId}") String selectPatientName(String patientId); @Select("select top 1 * from t_wechat_pay_order with(nolock) where patient_id=#{patientId} " + "and mzy_request_id=#{mzyRequestId} and cashpay_amt=#{cost} ") WxPayOrder selectSameGhOrder(String patientId, Integer mzyRequestId, BigDecimal cost); @Select("select top 1 * from t_wechat_pay_order with(nolock) where his_ord_num=#{hisOrdNum} " + "and cashpay_amt=#{cost} order by create_datetime desc") WxPayOrder selectSameMzPayOrder(String hisOrdNum, BigDecimal cost); @Select("select count(1) from mzy_reqrec WITH(NOLOCK) where psordnum=#{tradeNo} and cancel_mark=0") int alreadyPaidRegisterFee(String tradeNo); @Insert("insert into t_wechat_pay_order (body,openid,total_fee,patient_id," + "patient_name,inpatient_no,admiss_times,app_id,mch_id,prepay_id," + "time_stamp,trade_no,create_order_sign,pay_sign,spbill_create_ip," + "create_datetime,trade_state,serial_no,order_type,his_ord_num," + "mzy_request_id,yj_req_no,his_status,query_state_times,ap_time," + "fundpay_amt,acctpay_amt,coupon_amt,cashpay_amt,coupon_id,sgl_check_id," + "sgl_check_notified,drug_purchase_id,wxmall_package_id) " + "values (#{body},#{openid},#{totalFee},#{patientId},#{patientName},#{inpatientNo}," + "#{admissTimes},#{appId},#{mchId},#{prepayId},#{timeStamp},#{tradeNo},#{createOrderSign}," + "#{paySign},#{spbillCreateIp},#{createDatetime},#{tradeState},#{serialNo},#{orderType}," + "#{hisOrdNum},#{mzyRequestId},#{yjReqNo},0,0,#{apTime},#{fundpayAmt}," + "#{acctpayAmt},#{couponAmt},#{cashpayAmt},#{couponId},#{sglCheckId}," + "#{sglCheckNotified},#{drugPurchaseId},#{wxmallPackageId})") void insertNewOrder(WxPayOrder param); @Select("select * from t_si_setlinfo where pat_no=#{patNo} and times=#{times} and revoked=0") MedinsSettle selectSettleinfo(String patNo, int times); @Update("update t_wechat_pay_order set trade_state=#{tradeState}, pay_datetime=#{successTime}, " + "query_state_times=(query_state_times+1),last_query_state=getdate() where trade_no=#{tradeNo}") void updatePayStatusAndPayTime(String tradeNo, Transaction.TradeStateEnum tradeState, String successTime); @Update("update t_wechat_pay_order set trade_state=#{tradeState},pay_datetime=#{successTime},openid=#{openid}, " + "query_state_times=(query_state_times+1),last_query_state=getdate() where trade_no=#{tradeNo}") void updatePayStatusAndPayTimeAndOpenid(String tradeNo, Transaction.TradeStateEnum tradeState, String successTime, String openid); @Update("update t_wechat_pay_order set trade_state=#{tradeState},query_state_times=(query_state_times+1), " + "last_query_state=getdate() where trade_no=#{tradeNo}") void updatePayStatusAndQueryTimes(String tradeNo, Transaction.TradeStateEnum tradeState); @Update("update t_wechat_pay_order set trade_state=#{tradeState},query_state_times=(query_state_times+1), " + "openid=#{openid},last_query_state=getdate() where trade_no=#{tradeNo}") void updatePayStatusAndQueryTimesAndOpenid(String tradeNo, Transaction.TradeStateEnum tradeState, String openid); @Update("update t_wechat_pay_order set trade_state=#{tradeState} where trade_no=#{tradeNo}") void updatePayStatusOnly(String tradeNo, Transaction.TradeStateEnum tradeState); @Select("select count(1) from mz_deposit_file WITH(NOLOCK) where psordnum=#{tradeNo} and pay_mark=0") int alreadyPayed(String tradeNo); @Select("select trade_state as tradeState,refund_id as name from t_wechat_pay_order where trade_no=#{tradeNo} ") PureCodeName selectPayStatus(String tradeNo); @Update("update t_wechat_pay_order set trade_state='REFUND',refund_op_code='99999'," + "refund_reason=#{reason},his_status=0,refund_op_datetime=getdate() " + "where trade_no=#{tradeNo}") void refundOrder(String tradeNo, String reason); @Update("update t_wechat_pay_order set trade_state='REFUND' where trade_no=#{tradeNo}") void updateRefundStatus(String tradeNo); @Update("update t_wechat_pay_order set his_status=1 where trade_no=#{tradeNo}") void updateSuccessHisStatus(String tradeNo); @Update("update t_patient_coupons set coupon_state='USED' where id=#{id}") void couponUsed(String id); @Select("select datediff(day,getdate(),request_day) as dateDiff, " + "rtrim(unit_code) as unitCode from mzy_reqrec where psordnum=#{tradeNo}") HisRegister selectRegisterDateDiff(String tradeNo); @Select("select count(1) from mz_deposit_file where psordnum=#{tradeNo} and cheque_type='2'") int selectFundPayCount(String tradeNo); @Select("select * from t_wechat_pay_order with(nolock) where trade_no=#{tradeNo}") WxPayOrder selectOrderByTradeNo(String tradeNo); @Select("select order_type from t_wechat_pay_order with(nolock) where trade_no=#{tradeNo}") Integer selectOrderType(String tradeNo); @Select("select trade_no,trade_state,query_state_times, " + "offset=datediff(minute,create_datetime,last_query_state) " + "from t_wechat_pay_order with(nolock) " + "where openid!='' and his_status=0 and order_type in (1,2,3) " + "and trade_state='NOTPAY' " + "union " + "select trade_no,trade_state,query_state_times, " + "offset=datediff(minute,create_datetime,last_query_state) " + "from t_wechat_pay_order with(nolock) where order_type=5 " + "and sgl_check_notified=0 and trade_state in ('NOTPAY','SUCCESS')") List selectTradeNosForScheduleTask(); @Select("select openid from t_wechat_patient_bind with(nolock) " + "where (patient_id=#{cardNo} or ic_card_no=#{cardNo}) and del_flag=0") List selectOpenidByCardNo(String cardNo); @Select("select rtrim(a.code) doctorCode,rtrim(a.name) doctorName,rtrim(b.name) doctorTitle,rtrim(a.dept_code) deptCode, " + "deptName=(select rtrim(name) from zd_unit_code with(nolock) where code=a.dept_code), " + "a.specialty,a.introduction,a.portrait " + "from a_employee_mi a with(nolock), zd_emp_title b with(nolock) " + "where a.code=#{doctorCode} and a.emp_tit_code=b.code and " + "a.code not in ('00000', '00026') and isnull(a.del_flag,0)<>1") DoctorInfo selectDoctorInfo(String doctorCode); @Select("select trade_no from t_wechat_pay_order where his_ord_num=#{hisOrdNum} " + "and trade_state not in ('SUCCESS','CLOSED')") List selectTradeNoByHisOrdNum(String hisOrdNum); @Select("select trade_state from t_wechat_pay_order with(nolock) where trade_no=#{tradeNo}") Transaction.TradeStateEnum selectOrderStatus(String tradeNo); @Update("update t_wechat_pay_order set refund_id=#{refundId}, refund_op_code=#{refundOpCode}, his_status=0, " + "refund_op_datetime=#{refundOpDatetime}, refund_reason=#{refundReason}, trade_state='REFUND' where trade_no=#{tradeNo}") void updateRefundId(WxPayOrder order); @Delete("delete from t_wechat_pay_order where trade_no=#{tradeNo}") void deleteOrder(String tradeNo); @Update("update t_wechat_pay_order set trade_state='REFUND', refund_reason=#{msg}, his_status=0 where trade_no=#{tradeNo}") void alreadyRefund(String tradeNo, String msg); @Update("update t_si_setlinfo set mz_saved=1 where pat_no=#{patId} and times=#{times} and revoked=0") void updateMzSavedFlag(String patId, String times); @Update("update t_wechat_pay_order set sgl_check_notified=1 where trade_no=#{tradeNo}") void updateCytjNotified(String tradeNo); }