package com.icloud.server.scala.paynotify

import com.icloud.server.payutils.dto.PayOrderDO
import lombok.{AllArgsConstructor, Data, NoArgsConstructor}
import org.hibernate.annotations.{CreationTimestamp, UpdateTimestamp}
import org.springframework.data.jpa.repository.{JpaRepository, JpaSpecificationExecutor}
import org.springframework.data.repository.{CrudRepository, PagingAndSortingRepository}
import org.springframework.stereotype.Repository

import java.util
import java.util.Date
import javax.persistence.{Column, Entity, GeneratedValue, GenerationType, Id, Table}
import scala.beans.BeanProperty
/**订单校验
 * @Author : yang
 * @Date : 2022-07-26 00:41
 * @Version : 2.1.2
 */

@Repository
trait PayNotifyRepository extends CrudRepository[PayNotifyEntity, Long] with JpaSpecificationExecutor[PayNotifyEntity] with JpaRepository[PayNotifyEntity, Long] with PagingAndSortingRepository[PayNotifyEntity, Long]{


  def findByMerchantorderidAndOuttradenoAndStatus(merchantorderid:String,outtradeno: String,status: Int): util.List[PayNotifyEntity]
  def findByMerchantorderidAndStatus(merchantorderid:String,status: Int): util.List[PayNotifyEntity]
}
@Data
@Entity
@Table(name = "pay_out_trade_no")
@NoArgsConstructor
@AllArgsConstructor
class PayNotifyEntity extends Serializable {
  @Id
  @BeanProperty
  @Column(name = "id")
  var id: Long = _

  @BeanProperty
  @Column(name = "merchant_order_id")
  var merchantorderid: String = _

  @BeanProperty
  @Column(name = "attach")
  var outtradeno: String = _
  @BeanProperty
  @Column(name = "notify_url")
  var notifyurl: String = _
  @BeanProperty
  @Column(name = "notify_status")
  var status: Int = _


  def toEntity(id: Long, merchantorderid: String, outtradeno: String, notifyurl: String, notifystatus: Int): PayNotifyEntity = {
    this.id = id
    this.merchantorderid = merchantorderid
    this.outtradeno = outtradeno
    this.notifyurl = notifyurl
    this.status = notifystatus
    this
  }

}



@Repository
trait PayNotifyLogRepository extends CrudRepository[PayNotifyLogEntity, Long] with JpaSpecificationExecutor[PayNotifyLogEntity] with JpaRepository[PayNotifyLogEntity, Long] with PagingAndSortingRepository[PayNotifyLogEntity, Long]{


//  def findByMerchantorderidAndOuttradeno(merchantorderid:String,outtradeno: String): util.List[PayNotifyEntity]
}
@Data
@Entity
@Table(name = "pay_notify_log")
@NoArgsConstructor
@AllArgsConstructor
class PayNotifyLogEntity extends Serializable {
  @Id
  @BeanProperty
  @GeneratedValue( strategy = GenerationType.IDENTITY )
  @Column(name = "id")
  var id: Long = _
  @BeanProperty
  @Column(name = "task_id")
  var taskid: String = _
  @BeanProperty
  @Column(name = "notify_times")
  var notifytimes: Int = _
  @BeanProperty
  @Column(name = "response")
  var response: String = _
  @BeanProperty
  @Column(name = "status")
  var status: Int = 1
  @BeanProperty
  @Column(name = "creator")
  var creator: String = _

  @BeanProperty
  @Column(name = "updater")
  var updater: String = _
  @BeanProperty
  @Column(name = "deleted")
  var deleted: Boolean = false
  @BeanProperty
  @Column(name = "appid")
  var appid: String = _

  def toEntity( taskid: String, response: String, creator: String, updater: String,appid: String): PayNotifyLogEntity = {
    this.taskid = taskid
    this.notifytimes = notifytimes
    this.response = response

    this.creator = creator
    this.updater = updater
    this.appid = appid
    this
  }

}
