package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.dto.MusicGroupPaymentCalenderAddStudentDto;
import com.ym.mec.biz.dal.page.MusicCalenderDetailQueryInfo;
import com.ym.mec.biz.service.MusicGroupPaymentCalenderDetailService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;

@RequestMapping("musicGroupPaymentCalenderDetail")
@Api(tags = "乐团缴费明细")
@RestController
public class MusicGroupPaymentCalenderDetailController extends BaseController {

    @Autowired
    private MusicGroupPaymentCalenderDetailService musicGroupPaymentCalenderDetailService;

    @ApiOperation(value = "分页查询乐团缴费明细列表")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/queryPage')")
    public Object queryPage(MusicCalenderDetailQueryInfo queryInfo) {
        return succeed(musicGroupPaymentCalenderDetailService.queryPage(queryInfo));
    }

    @ApiOperation(value = "修改学员预计缴费金额")
    @PostMapping("/updateExpectAmount")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/updateExpectAmount')")
    public Object updateExpectAmount(BigDecimal expectAmount,String ids) {
        musicGroupPaymentCalenderDetailService.updateExpectAmount(expectAmount,ids);
        return succeed();
    }

    @ApiOperation(value = "新增缴费学员列表获取")
    @PostMapping("/queryFeeStudents")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/queryFeeStudents')")
    public Object queryFeeStudents(String musicGroupId,String search,Integer subjectId) {
        return succeed(musicGroupPaymentCalenderDetailService.queryFeeStudents(musicGroupId,search,subjectId));
    }

    @ApiOperation(value = "乐团缴费记录新增学员")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/add')")
    public Object add(Long musicGroupPaymentCalenderId,Integer userId) {
        musicGroupPaymentCalenderDetailService.add(musicGroupPaymentCalenderId,userId);
        return succeed();
    }

    @ApiOperation(value = "乐团缴费记录新增学员")
    @PostMapping("/batchAdd")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/batchAdd')")
	public Object batchAdd(@RequestBody MusicGroupPaymentCalenderAddStudentDto musicGroupPaymentCalenderAddStudentDto) {
		musicGroupPaymentCalenderDetailService.batchAdd(musicGroupPaymentCalenderAddStudentDto.getBatchNo(),
				musicGroupPaymentCalenderAddStudentDto.getUserIdList());
		return succeed();
	}

    @ApiOperation(value = "批量删除缴费信息")
    @PostMapping("/batchDel")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/batchDel')")
    public Object batchDel(String musicGroupPaymentCalenderDetailIds) {
    	if(StringUtils.isBlank(musicGroupPaymentCalenderDetailIds)){
    		return failed("请求参数错误");
    	}
        musicGroupPaymentCalenderDetailService.batchDel(musicGroupPaymentCalenderDetailIds);
        return succeed();
    }

    @ApiOperation(value = "开启缴费")
    @PostMapping("/openPayment")
    @PreAuthorize("@pcs.hasPermissions('musicGroupPaymentCalenderDetail/openPayment')")
    public HttpResponseResult openPayment(String ids) {
        HttpResponseResult<Object> succeed = succeed();
        succeed.setMsg(musicGroupPaymentCalenderDetailService.openPayment(ids));
        return succeed;
    }
}
