package com.icloud.server.scala.goods

import com.fasterxml.jackson.annotation.{JsonAutoDetect, JsonIdentityInfo}
import com.icloud.server.scala.engine.service.{Goodspayditche, Goodspaye}
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 org.hibernate.annotations.Fetch
import org.hibernate.annotations.FetchMode
import org.hibernate.annotations.Proxy
import org.springframework.data.domain.Pageable

import java.util
import javax.persistence._
import java.util.{Date, Set}
import javax.persistence.{Column, Entity, Id, Table}
import scala.beans.BeanProperty
import scala.jdk.CollectionConverters._

/** 商品链接检索服务
 * @Author : yang
 * @Date : 2022-07-13 23:22
 * @Version : 2.1.2
 */



@Repository trait GoodspayRepository1 extends CrudRepository[Goodspay2, Long]
  with JpaSpecificationExecutor[Goodspay2] with JpaRepository[Goodspay2, Long]
  with PagingAndSortingRepository[Goodspay2, Long] {
  def findBySubjectLikeAndStatusAndUseridOrderByIdDesc(subject: String,status:Int,userid: Long) :util.List[Goodspay2]
//  def findByUseridAndStatus(userid: String,status: Int): java.util.List[Goodspay2]
  def findByStatusAndUseridOrderByIdDesc(status: Int,userid: String,pageable: Pageable): java.util.List[Goodspay2]

}
@Data
@Entity
//@Table(name = "goods")
@NoArgsConstructor
@AllArgsConstructor
//@Proxy (`lazy` = false)
//@Data
//@Entity
@Table(name = "goods_pay")
//@NoArgsConstructor
//@AllArgsConstructor
//@JsonIdentityInfo (generator = classOf[Nothing] )
class Goodspay2 extends Serializable {
  //  @GeneratedValue( strategy = GenerationType.IDENTITY )
  @Id
  @BeanProperty
  @Column(name = "id")
  var id: Long = _
  @transient
  @BeanProperty
  @Column
  var username:String=_

  @BeanProperty
  @Column
  var subject:String=_
  @BeanProperty
  @Column(name = "short_name")
  var shortname: String = _
  @BeanProperty
  @Column( name = "user_id" )
  var userid: String = _
  @BeanProperty
  @Column(name = "goods_id" ,insertable = false, updatable = false)
  var goodsid: Long = _
  @BeanProperty
  @Column(name = "payment_model")
  var paymentmodel: Int = _
  @BeanProperty
  @Column(name = "payment")
  var payment: Long = _
  @BeanProperty
  @Column(name = "full_phone")
  var fullphone: String = _
  @BeanProperty
  @Column(name = "expire_model")
  var expiremodel: String = _
  @BeanProperty
  @Column(name = "expire_endtime")
  var expireendtime: Date = _
  @BeanProperty
  @Column
  var starttime: Date = _
  @BeanProperty
  @Column(name = "expire_millisecond")
  var expiremillisecond: Long = _
  @BeanProperty
  @Column
  var remark: String = _
  @BeanProperty
  @Column var status: Int = _
  @CreationTimestamp
  @BeanProperty
  @Column var CREATETIME: Date = _
  @UpdateTimestamp
  @BeanProperty
  @Column var UPDATETIME: Date = _

  //多对一
//  @ManyToOne(fetch = FetchType.EAGER)
//  @Fetch(FetchMode.JOIN)
//  @JoinColumn(name = "goods_id")
//  var goods2: Goods2 = _
  @BeanProperty
  @JoinColumn(name = "goods_id")
  @OneToOne(fetch = FetchType.EAGER, cascade = Array(CascadeType.ALL)) var goods: Goods2 = _
//  @BeanProperty
//  @JoinColumn( name = "ditch_id" )
//  @OneToOne( fetch = FetchType.EAGER, cascade = Array( CascadeType.ALL ) ) var goodspayditch2: Goodspayditch2 = _

  @BeanProperty //  @JsonIgnore
  @OneToMany( mappedBy = "goodspay2", cascade = Array( CascadeType.ALL ), fetch = FetchType.EAGER ) //targetEntity=classOf[UserRole] ,,fetch = FetchType.EAGER targetEntity=classOf[UserRole] ,
  var goodspayditch: util.List[Goodspayditch2] = _
}



@Data
@Entity
@Table(name = "goods_pay_ditch")
@NoArgsConstructor
@AllArgsConstructor
class Goodspayditch2 extends Serializable {
  @Id
  @BeanProperty
  @Column( name = "ditch_id" )
  var id: Long = _

  @BeanProperty
  @Column(name = "goods_id")
  var goodsid: Long = _

//  @BeanProperty
//  @Column(name = "goods_pay_id")
//  var goodspayid: Long = _
  @BeanProperty
  @Column(name = "pay_name")
  var payname: String = _
  @BeanProperty
  @Column(name = "opt_pay")
  var optpay: Long = _
  @BeanProperty
  @Column(name = "random")
  var random: String = _
  @BeanProperty
  @Column(name = "appoint_pay")
  var appointpay: Long = _

  @BeanProperty
  @Column var status: Int = _
  @CreationTimestamp
  @BeanProperty
  @Column var CREATETIME: Date = _
  @UpdateTimestamp
  @BeanProperty
  @Column var UPDATETIME: Date = _
  @ManyToOne// (fetch=FetchType.LAZY)//(fetch=FetchType.EAGER)//fetch=FetchType.LAZY
  @JoinColumn( name = "goods_pay_id" ) var goodspay2: Goodspay2 = _


}



@Data
@Entity
@Table(name = "goods")
@NoArgsConstructor
@AllArgsConstructor
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
class Goods2 extends Serializable {
  @Id
  @BeanProperty
  @Column(name = "goods_id")
  var goodsid: Long = _
  @BeanProperty
  @Column(name = "tenant_id")
  var tenantid: Long = _
  @BeanProperty
  @Column(name = "user_id")
  var userid: Long = _
  @BeanProperty
  @Column(name = "full_phone")
  var fullphone: String = _
  @BeanProperty
  @Column var subject: String = _
  @BeanProperty
  @Column var free: String = _
  @BeanProperty
  @Column(name = "short_name")
  var shortname: String = _
  @BeanProperty
  @Column(name = "pic_url")
  var picurl: String = _
  @BeanProperty
  @Column
  var body: String = _
  @BeanProperty
  @Column
  var price: Long = _
  @BeanProperty
  @Column
  var sellcount: Long = _
  @BeanProperty
  @Column
  var sellamount: Long = _
  @BeanProperty
  @Column(name = "marking_price")
  var markingprice: Long = _
  @BeanProperty
  @Column(name = "selling_model")
  var sellingmodel: String = _
  @BeanProperty
  @Column var status: Int = _
  @BeanProperty
  @Column var parent: Int = _
  @CreationTimestamp
  @BeanProperty
  @Column var CREATETIME: Date = _
  @UpdateTimestamp
  @BeanProperty
  @Column var UPDATETIME: Date = _
  @JoinColumn(name = "goods_package_id")
  @OneToOne(fetch = FetchType.EAGER, cascade = Array(CascadeType.ALL)) var goodspackage: GoodsPackage = _

}


//@Repository trait GoodsPackageRepository extends CrudRepository[GoodsPackage, Long] with JpaSpecificationExecutor[GoodsPackage] with JpaRepository[GoodsPackage, Long] with PagingAndSortingRepository[GoodsPackage, Long] {
//  def findByGoodsidAndStatus(goodsid: Long, status: Int): java.util.List[GoodsPackage]
//
//}


@Data
@Entity
@Table(name = "goods_package")
@NoArgsConstructor
@AllArgsConstructor
class GoodsPackage2 extends Serializable {
  //  @GeneratedValue( strategy = GenerationType.IDENTITY )
  @Id
  @BeanProperty
  @Column(name = "id")
  var id: Long = _

//  @BeanProperty
//  @Column(name = "goods_id")
//  var goodsid: Long = _
//  @JoinColumn(name = "goods_id")
//  @OneToOne(fetch = FetchType.EAGER, cascade = Array(CascadeType.ALL)) var goods2: Goods2 = _
  @BeanProperty
  @Column(name = "sub_goods_id")
  var subgoodsid: Long = _

  @BeanProperty
  @Column
  var remark: String = _
  @BeanProperty
  @Column var status: Int = _
  @CreationTimestamp
  @BeanProperty
  @Column var CREATETIME: Date = _
  @UpdateTimestamp
  @BeanProperty
  @Column var UPDATETIME: Date = _


}