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.PxBookkeepingRecord;
import com.pnkx.service.IPxBookkeepingRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author PHY
 * @classname PxAdminBookkeepingRecordController
 * @data 2021/11/18 0018 14:33
 * @description 描述
 */
@RestController
@RequestMapping("/bookkeeping/record")
public class PxBookkeepingRecordController extends BaseController {
    @Resource
    private IPxBookkeepingRecordService pxBookkeepingRecordService;

    /**
     * 查询账本记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PxBookkeepingRecord pxBookkeepingRecord) {
        startPage();
        return pxBookkeepingRecordService.selectPxBookkeepingRecordList(pxBookkeepingRecord);
    }

    /**
     * 获取账本记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pxBookkeepingRecordService.selectPxBookkeepingRecordById(id));
    }

    /**
     * 新增账本记录
     */
    @Log(title = "新增账本记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PxBookkeepingRecord pxBookkeepingRecord) {
        return toAjax(pxBookkeepingRecordService.insertPxBookkeepingRecord(pxBookkeepingRecord));
    }

    /**
     * 修改账本记录
     */
    @Log(title = "修改账本记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PxBookkeepingRecord pxBookkeepingRecord) {
        return toAjax(pxBookkeepingRecordService.updatePxBookkeepingRecord(pxBookkeepingRecord));
    }

    /**
     * 删除账本记录
     */
    @Log(title = "账本记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pxBookkeepingRecordService.deletePxBookkeepingRecordByIds(ids));
    }
}
