package com.wzj.soopin.member.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.convert.MemberLoginInfoConvert;
import com.wzj.soopin.member.domain.bo.MemberLoginInfoBO;
import com.wzj.soopin.member.domain.po.MemberLoginInfo;
import com.wzj.soopin.member.domain.vo.MemberLoginInfoVO;
import com.wzj.soopin.member.service.IMemberLoginInfoService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.web.core.BaseController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员登录记录Controller
 *
 * @author zcc
 * @date 2023-07-26
 */
@Tag(name ="会员登录记录接口列表")
@RestController
@RequestMapping("/ums/member/loginInfo/")
@RequiredArgsConstructor
public class MemberLoginInfoController extends BaseController {
    private final IMemberLoginInfoService service;
    private final MemberLoginInfoConvert convert;

   @Tag(name ="查询会员登录记录列表")
    @SaCheckPermission("ums:memberlogininfo:list")
    @PostMapping("list")
    public R<Page<MemberLoginInfoVO>> list(@RequestBody MemberLoginInfoBO query, @RequestBody Page page) {
        Page<MemberLoginInfo> list = service.page(page,query.toWrapper());
        return R.ok(convert.toVO(list));
    }

   @Tag(name ="导出会员登录记录列表")
    @SaCheckPermission("ums:memberlogininfo:export")
    @Log(title = "会员登录记录", businessType = BusinessType.EXPORT)
    @PostMapping("export")
    public R<String> export(MemberLoginInfoBO query) {
        List<MemberLoginInfo> list = service.list(query.toWrapper());
        ExcelUtil<MemberLoginInfoVO> util = new ExcelUtil<>(MemberLoginInfoVO.class);
        return R.ok(util.writeExcel(convert.toVO(list), "会员登录记录数据"));
    }


    @Tag(name ="导出会员登录记录列表")
    @SaCheckPermission("ums:memberlogininfo:export")
    @Log(title = "会员登录记录", businessType = BusinessType.EXPORT)
    @PostMapping("add")
    public R<Boolean> add(@RequestBody MemberLoginInfoBO bo) {
        return R.ok(service.save(convert.toPo(bo)));
    }

    @Tag(name ="获取会员登录记录详细信息")
    @SaCheckPermission("ums:memberlogininfo:query")
    @GetMapping(value = "{id}")
    public R<MemberLoginInfoVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

   @Tag(name ="修改会员登录记录")
    @SaCheckPermission("ums:memberlogininfo:edit")
    @Log(title = "会员登录记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public R  edit(@RequestBody MemberLoginInfoBO memberLoginInfo) {
        return R.ok(service.updateById(convert.toPo(memberLoginInfo)));
    }

   @Tag(name ="删除会员登录记录")
    @SaCheckPermission("ums:memberlogininfo:remove")
    @Log(title = "会员登录记录", businessType = BusinessType.DELETE)
	@DeleteMapping("{id}")
    public R  remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }
}
