package com.icloud.server.scala.payorder

import com.icloud.server.web.JsonResult
import io.swagger.annotations.{Api, ApiOperation}
import org.springframework.data.domain.{PageRequest, Pageable, Sort}
import org.springframework.web.bind.annotation.{CrossOrigin, PostMapping, RequestMapping, RequestParam, ResponseBody, RestController}

import javax.annotation.Resource
import scala.beans.BeanProperty

@Api( tags = Array( "订单查询" ), value = "API",hidden = true )
@RestController
@RequestMapping(Array("/orders/"))
@CrossOrigin
class OrderController {

  @Resource
  @BeanProperty
  var por: PayOrderRepository = _

  @ApiOperation( value = "分页查询所有", notes = "" )
  @PostMapping( Array( "findall" ) )
  @ResponseBody
  def getorder(@RequestParam uid:Int,@RequestParam page:Int, @RequestParam size:Int): JsonResult ={
    val request :Pageable= PageRequest.of(page-1, size, Sort.Direction.DESC, "id")

    new JsonResult(por.findAllByMerchantidOrderByIdDesc(uid,request))
  }
  @ApiOperation( value = "精确查询订单", notes = "" )
  @PostMapping( Array( "findorderid" ) )
  @ResponseBody
  def getOrderNo(@RequestParam uid:Long,@RequestParam orderid:Long): JsonResult ={
    new JsonResult(por.findByIdAndMerchantid(orderid,uid))
  }
}
