package com.younike.member.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.AppMember;
import com.younike.service.service.IAppMemberService;

/**
 * 会员用户Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/appMember")
public class AppMemberController extends BaseController {
    @Autowired
    private IAppMemberService appMemberService;

    /**
     * 查询会员用户列表
     */
    @RequiresPermissions("member:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<AppMember> page) {

        return appMemberService.page(page);
    }


    /**
     * 获取会员用户详细信息
     */
    @RequiresPermissions("member:query")
    @GetMapping(value = "/{appMemberId}")
    public APIResult getInfo(@PathVariable("appMemberId") String appMemberId) {
        return ResultGenerator.getSuccessResult(appMemberService.getById(appMemberId));
    }

    /**
     * 新增会员用户
     */
    @RequiresPermissions("member:add")
    @OpLog(title = "会员用户", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody AppMember appMember) {
        return ResultGenerator.getSuccessResult(appMemberService.save(appMember));
    }

    /**
     * 修改会员用户
     */
    @RequiresPermissions("member:edit")
    @OpLog(title = "会员用户", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody AppMember appMember) {
        return ResultGenerator.getSuccessResult(appMemberService.updateById(appMember));
    }

    /**
     * 删除会员用户
     */
    @RequiresPermissions("member:remove")
    @OpLog(title = "会员用户", type = BusinessType.DELETE)
    @DeleteMapping("/{appMemberIds}")
    public APIResult remove(@PathVariable List<String> appMemberIds) {
        return ResultGenerator.getSuccessResult(appMemberService.removeByIds(appMemberIds));
    }
}
