package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.CloudCoachPaymentProgram;
import com.ym.mec.biz.dal.page.CloudCoachPaymentProgramQueryInfo;
import com.ym.mec.biz.service.CloudCoachPaymentProgramService;
import com.ym.mec.biz.service.OrganizationService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api(tags = "云教练缴费项目")
@RequestMapping("cloudCoachPaymentProgram")
@RestController
public class CloudCoachPaymentProgramController extends BaseController {

    @Autowired
    private CloudCoachPaymentProgramService cloudCoachPaymentProgramService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private OrganizationService organizationService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('cloudCoachPaymentProgram/add')")
    public Object add(@RequestBody CloudCoachPaymentProgram cloudCoachPaymentProgram){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        cloudCoachPaymentProgram.setOperator(sysUser.getId());
        cloudCoachPaymentProgramService.add(cloudCoachPaymentProgram);
        return succeed();
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('cloudCoachPaymentProgram/update')")
    public Object update(@RequestBody CloudCoachPaymentProgram cloudCoachPaymentProgram){
        cloudCoachPaymentProgramService.modify(cloudCoachPaymentProgram);
        return succeed();
    }

    @ApiOperation(value = "审核")
    @PostMapping("/audit")
    @PreAuthorize("@pcs.hasPermissions('cloudCoachPaymentProgram/audit')")
    public Object audit(@RequestBody CloudCoachPaymentProgram cloudCoachPaymentProgram){
        cloudCoachPaymentProgramService.audit(cloudCoachPaymentProgram);
        return succeed();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('cloudCoachPaymentProgram/queryPage')")
    public Object queryPage(CloudCoachPaymentProgramQueryInfo queryInfo){
        queryInfo.setOrganId(organizationService.getEmployeeOrgan(queryInfo.getOrganId()));
        return succeed(cloudCoachPaymentProgramService.queryPage(queryInfo));
    }
}
