package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.MemberRankSetting;
import com.ym.mec.biz.service.MemberRankSettingService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;
import com.yonge.log.model.AuditLogAnnotation;
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.*;

import java.util.HashMap;

@RequestMapping("memberRankSetting")
@Api(tags = "会员等级服务")
@RestController
public class MemberRankSettingController extends BaseController {

    @Autowired
    private MemberRankSettingService memberRankSettingService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('memberRankSetting/add')")
    @AuditLogAnnotation(operateName = "新增会员等级")
    public Object add(@RequestBody MemberRankSetting memberRankSetting) {
        memberRankSettingService.add(memberRankSetting);
        return succeed();
    }

    @ApiOperation(value = "获取详情")
    @GetMapping("/get")
    @PreAuthorize("@pcs.hasPermissions('memberRankSetting/get')")
    @AuditLogAnnotation(operateName = "会员等级详情")
    public Object get(Integer memberRankSettingId) {
        return succeed(memberRankSettingService.getDetail(memberRankSettingId));
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('memberRankSetting/update')")
    public Object update(@RequestBody MemberRankSetting memberRankSetting) {
        memberRankSettingService.updateSetting(memberRankSetting);
        return succeed();
    }

    @ApiOperation(value = "分页查询")
    @GetMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('memberRankSetting/queryPage')")
    public Object queryPage(QueryInfo queryInfo) {
        return succeed(memberRankSettingService.queryPage(queryInfo));
    }

    @ApiOperation(value = "获取所有会员列表")
    @GetMapping("/findAll")
    @PreAuthorize("@pcs.hasPermissions('memberRankSetting/findAll')")
    public Object findAll() {
        return succeed(memberRankSettingService.findAll(new HashMap<>()));
    }
}
