package com.icloud.server.scala.route

//import lombok.Data
//import org.h2.store.Data
import com.icloud.server.web.json.JsonResult
import io.swagger.annotations.Api
import lombok.Data
import org.springframework.data.jpa.repository.{JpaRepository, JpaSpecificationExecutor}
import org.springframework.data.repository.{CrudRepository, PagingAndSortingRepository}
import org.springframework.stereotype.Repository
import org.springframework.web.bind.annotation.{CrossOrigin, PostMapping, RequestMapping, RestController}

import java.util
import javax.annotation.Resource
import javax.persistence.{Column, Entity, Id, Table}
import scala.beans.BeanProperty
/** 初始化路由 ---前端在1.0版本不用了
 * @Author : yang
 * @Date : 2022-07-05 5:44 PM
 * @Version : 2.1.2
 */
@Api( tags = Array( "路由初始化" ), value = "API" )
@RestController
@RequestMapping( Array( "/init/" ) )
@CrossOrigin
class IinitController {
  @Resource
  @BeanProperty
  var mr:MenuinitRepository=_

  @PostMapping( Array( "/list-menus" ) ) def getroute (): JsonResult = {
    //一级菜单
    val menuinits = mr.findByTypesAndStatus( 1, 0 )
//    var url="{\n    path: '/home',\n    name: 'Home',\n    component: Home,\n    redirect:'/home/paybind',\n    children:[\n      {\n        path:'/home/page',\n        component:  ()=>import('@/views/home/page/index.vue'),\n        meta:{\n          iconfont:'icon-fencengpeizhi'\n        },\n        redirect:'/home/page/paybind',\n        children:[\n          {\n            path: '/home/page/paybind',\n            name: 'PayBind',\n            component:  ()=>import('@/views/home/page/pay-bind/index.vue')\n          },\n          {\n            path: '/home/page/payconfig',\n            name: 'PayConfig',\n            component:  ()=>import('@/views/home/page/pay-config/index.vue')\n          },\n        ]\n      },\n      {\n        path: '/home/goodscabinet',\n        name: 'GoodsCabinet',\n        meta:{\n          iconfont:'icon-shangpin'\n        },\n        component:  ()=>import('@/views/goods-cabinet/index.vue')\n      },\n      {\n        path: '/home/paylist',\n        name: 'PayList',\n        meta:{\n          iconfont:'icon-zhifubao'\n        },\n        component:  ()=>import('@/views/pay-list/index.vue')\n      },\n    ]\n  },"
    new JsonResult(menuinits)

  }
}


@Repository trait MenuinitRepository extends CrudRepository[Menuinit, Long] with JpaSpecificationExecutor[Menuinit] with JpaRepository[Menuinit, Long] with PagingAndSortingRepository[Menuinit, Long] {
  def findByStatus(status:Int):util.List[Menuinit]
  def findByTypesAndStatus(types:Int,status:Int):util.List[Menuinit]
  def findByParentidAndStatus(parentid:Int,status:Int):util.List[Menuinit]

}
@Data
@Entity
@Table( name = "menu_init" )
class Menuinit{
  @Id
  @BeanProperty
  @Column var id: Int = _
  @BeanProperty
  @Column var name: String = _
  @BeanProperty
  @Column(name = "type")
  var types: Int = _
  @BeanProperty
  @Column var sort: Int = _
  @BeanProperty
  @Column(name="parent_id")
  var parentid: Int = _
  @BeanProperty
  @Column var path: String = _
  @BeanProperty
  @Column var icon: String = _
  @BeanProperty
  @Column var component: String = _
  @BeanProperty
  @Column var status: Int = _
  @BeanProperty
  @Column var deleted: Int = _

}
