package com.ym.mec.collectfee.controller;

import com.ym.mec.collectfee.common.web.BaseController;
import com.ym.mec.collectfee.entity.OrderQueryInfo;
import com.ym.mec.collectfee.service.OrderService;
import com.ym.mec.collectfee.utils.Constants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController()
@RequestMapping("order")
public class OrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    /**
     * 获取订单列表
     * @param userId
     * @return
     */
    @PostMapping("/getOrderList")
//    @ApiOperation(value = "根据学生编号，获取订单列表")
//    @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "学生编号", required = true, dataType = "Integer")})
    public Object getOrders(Integer userId){
        if(userId == null){
            return failed(Constants.PARAM_VERIFY_ERROR_MSG);
        }
        return succeed(orderService.getOrderByUserId(userId));
    }
    
    @PostMapping("/checkOrderList")
//  @ApiOperation(value = "根据学生编号，获取订单列表")
//  @ApiImplicitParams({ @ApiImplicitParam(name = "classId", value = "乐团编号", required = true, dataType = "Integer")})
	  public Object checkOrders(Integer classId, Integer type, String voicyPart, String startTime, String endTime, Integer branchId){
	      return succeed(orderService.getOrderByClassId(classId,type,voicyPart,startTime,endTime,branchId));
    }

    @PostMapping("/orderListPage")
//  @ApiOperation(value = "根据学生编号，获取订单列表")
//  @ApiImplicitParams({ @ApiImplicitParam(name = "classId", value = "乐团编号", required = true, dataType = "Integer")})
    public Object orderListPage(@ModelAttribute OrderQueryInfo queryInfo){
        return succeed(orderService.queryOrderPage(queryInfo));
    }

    /**
     * 查询报名人数
     * @param poName
     * @param voicePart
     * @return
     */
    @PostMapping("/applyNum")
//    @ApiOperation(value = "根据乐团名称、声部名称，查询报名人数")
//    @ApiImplicitParams({ @ApiImplicitParam(name = "poName", value = "乐团名称", required = true, dataType = "String"),
//            @ApiImplicitParam(name = "voicePart", value = "声部名称", required = true, dataType = "String")})
    public Object queryNum(String poName,String voicePart){
        if(StringUtils.isEmpty(voicePart) || StringUtils.isEmpty(poName)){
            return failed(Constants.PARAM_VERIFY_ERROR_MSG);
        }
        return succeed(orderService.countOrder(poName, voicePart));
    }

    /**
     * 推送订单
     * @param batchNum
     * @return
     */
//    @PostMapping("/pushOrder")
//    public String pushOrder(String batchNum){
//        return orderService.pushOrder(batchNum);
//    }

}
