package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.dto.ActivityUserMapperAddDto;
import com.ym.mec.biz.dal.entity.ActivityUserMapper;
import com.ym.mec.biz.dal.page.ActivityStudentQueryInfo;
import com.ym.mec.biz.service.ActivityUserMapperService;
import com.ym.mec.biz.service.SysUserCashAccountLogService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.PageInfo;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@Api(tags = "学员活动排课记录服务")
@RequestMapping("activityUserMapper")
@RestController
public class ActivityUserMapperController extends BaseController {

    @Autowired
    private ActivityUserMapperService activityUserMapperService;
    @Autowired
    private SysUserCashAccountLogService sysUserCashAccountLogService;

    @ApiOperation(value = "添加活动排课资格")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('activityUserMapper/add')")
    public Object add(@RequestBody ActivityUserMapperAddDto activityUserMapperAddDto){
        activityUserMapperService.add(activityUserMapperAddDto);
        return succeed();
    }

    @ApiOperation(value = "取消活动排课资格")
    @RequestMapping("/cut")
    @PreAuthorize("@pcs.hasPermissions('activityUserMapper/cut')")
    public Object cut(Integer activityUserMapperId, String memo, BigDecimal amount){
        activityUserMapperService.cut(activityUserMapperId,memo,amount);
        return succeed();
    }

    @ApiOperation(value = "获取学员活动排课资格列表")
    @RequestMapping("/queryActivityUserMapper")
    @PreAuthorize("@pcs.hasPermissions('activityUserMapper/queryActivityUserMapper')")
    public Object queryActivityUserMapper(ActivityStudentQueryInfo queryInfo){
        return succeed(activityUserMapperService.queryActivityUserMapper(queryInfo));
    }

    @ApiOperation(value = "获取列表")
    @RequestMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('activityUserMapper/queryPage')")
    public Object queryPage(ActivityStudentQueryInfo queryInfo){
        PageInfo<ActivityUserMapper> pageInfo = activityUserMapperService.queryPage(queryInfo);
        List<ActivityUserMapper> rows = pageInfo.getRows();
        if(rows != null && rows.size() > 0){
            for (ActivityUserMapper row : rows) {
                row.setActualPrice(sysUserCashAccountLogService.musicReturnFeeCharges(row.getActualPrice(),0));
            }
        }
        return succeed(pageInfo);
    }
}
