
package com.wzj.soopin.transaction.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.member.convert.AccountBillConvert;
import com.wzj.soopin.member.domain.bo.AccountBillBO;
import com.wzj.soopin.member.domain.po.AccountBill;
import com.wzj.soopin.member.domain.vo.AccountBillVO;
import com.wzj.soopin.transaction.service.IAccountBillService;
import io.swagger.v3.oas.annotations.Operation;
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.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员信息Controller
 *
 * @author zcc
 * @date 2022-11-28
 */
@Tag(name = "账单")
@RequestMapping("/ums/account/bill")
@RestController
@RequiredArgsConstructor
public class AccountBillController extends BaseController {
    private final IAccountBillService service;

    private final AccountBillConvert convert;


    @Operation(summary = "查询账单列表")
    @SaCheckPermission("ums:accountbill:list")
    @PostMapping("page")
    public R<Page<AccountBillVO>> page(@RequestBody AccountBillBO bo,
                                       @RequestBody  Page<AccountBill> page) {
        Page<AccountBill> memberPage = service.page(page,bo.toWrapper());
        return R.ok(convert.toVO(memberPage));
    }


    @Operation(summary = "查询账单列表")
    @SaCheckPermission("ums:accountbill:list")
    @PostMapping("list")
    public R<List<AccountBillVO>> list(@RequestBody AccountBillBO bo) {
        List<AccountBill> memberPage = service.list(bo.toWrapper());
        return R.ok(convert.toVO(memberPage));
    }

    @Operation(summary = "导出账单")
    @SaCheckPermission("ums:accountbill:export")
    @PostMapping("export")
    public ResponseEntity<String> export(AccountBillBO query) {
        List<AccountBill> list = service.list(query.toWrapper());
        ExcelUtil<AccountBillVO> util = new ExcelUtil<>(AccountBillVO.class);
        return ResponseEntity.ok(util.writeExcel(convert.toVO(list), "账单"));
    }

    @Operation(summary = "获取账单详情")
    @SaCheckPermission("ums:accountbill:query")
    @GetMapping(value = "{id}")
    public R<AccountBillVO> getInfo(@PathVariable("id") Long id) {
        return R.ok(convert.toVO(service.getById(id)));
    }

    @Operation(summary = "新增账单")
    @SaCheckPermission("ums:accountbill:add")
    @Log(title = "新增账单", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public R add(@RequestBody AccountBillBO member) {
        return R.ok(service.save(convert.toPo(member)));
    }

    @Operation(summary = "修改账单")
    @SaCheckPermission("ums:accountbill:edit")
    @Log(title = "修改账单", businessType = BusinessType.UPDATE)
    @PostMapping("update")
    public R edit(@RequestBody AccountBillBO member) {
        return R.ok(service.updateById(convert.toPo(member)));
    }



    @Operation(summary = "删除账单")
    @SaCheckPermission("ums:accountbill:remove")
    @Log(title = "删除账单", businessType = BusinessType.DELETE)
    @DeleteMapping("{id}")
    public R  remove(@PathVariable Long id) {
        return R.ok(service.removeById(id));
    }




}
