package com.pnkx.web.controller.life;

import com.pnkx.common.annotation.Log;
import com.pnkx.common.core.controller.BaseController;
import com.pnkx.common.core.domain.AjaxResult;
import com.pnkx.common.core.page.TableDataInfo;
import com.pnkx.common.enums.BusinessType;
import com.pnkx.domain.po.PxBookkeepingAccount;
import com.pnkx.domain.po.PxBookkeepingClassification;
import com.pnkx.service.IPxBookKeepingAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author by PHY
 * @classname PxAdminBookkeepingAccountController
 * @date 2021-11-08 21:01
 * @description: 描述
 */
@Api("生活工具-生活账本-账户管理")
@RestController
@RequestMapping("/bookkeeping/account")
public class PxBookkeepingAccountController extends BaseController {
    @Resource
    private IPxBookKeepingAccountService pxBookkeepingAccountService;

    /**
     * 查询最近使用账户列表
     */
    @ApiOperation("查询最近使用账户列表")
    @Log(title = "查询最近使用账户列表")
    @GetMapping("/getLatelyAccountList")
    public TableDataInfo getLatelyAccountList(PxBookkeepingClassification pxBookkeepingClassification) {
        startPage();
        List<PxBookkeepingAccount> list = pxBookkeepingAccountService.getLatelyAccountList(pxBookkeepingClassification);
        return getDataTable(list);
    }

    /**
     * 查询账本用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PxBookkeepingAccount pxBookkeepingAccount) {
        startPage();
        List<PxBookkeepingAccount> list = pxBookkeepingAccountService.selectPxBookkeepingAccountList(pxBookkeepingAccount);
        return getDataTable(list);
    }

    /**
     * 获取账本用户详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pxBookkeepingAccountService.selectPxBookkeepingAccountById(id));
    }

    /**
     * 新增账本用户
     */
    @ApiOperation("新增账本用户")
    @Log(title = "新增账本用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PxBookkeepingAccount pxBookkeepingAccount) {
        return toAjax(pxBookkeepingAccountService.insertPxBookkeepingAccount(pxBookkeepingAccount));
    }

    /**
     * 修改账本用户
     */
    @Log(title = "修改账本用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PxBookkeepingAccount pxBookkeepingAccount) {
        return toAjax(pxBookkeepingAccountService.updatePxBookkeepingAccount(pxBookkeepingAccount));
    }

    /**
     * 删除账本用户
     */
    @Log(title = "账本用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id) {
        return toAjax(pxBookkeepingAccountService.deletePxBookkeepingAccountById(id));
    }
}
