package com.xjrsoft.module.ledger.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.module.ledger.dto.AddLedgerConfigReleaseDto;
import com.xjrsoft.module.ledger.dto.LedgerConfigReleasePageDto;
import com.xjrsoft.module.ledger.dto.UpdateLedgerConfigReleaseDto;
import com.xjrsoft.module.ledger.service.ILedgerConfigReleaseService;
import com.xjrsoft.module.ledger.vo.LedgerConfigPageVo;
import com.xjrsoft.module.ledger.vo.LedgerConfigReleaseInfoVo;
import com.xjrsoft.module.ledger.vo.LedgerConfigReleasePageVo;
import com.xjrsoft.module.ledger.vo.LedgerConfigReleaseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
* @title: 台账发布表
* @Author dzx
* @Date: 2024-03-07
* @Version 1.0
*/
@RestController
@RequestMapping("/ledger" + "/ledgerConfigRelease")
@Api(value = "/ledger"  + "/ledgerConfigRelease",tags = "台账发布表代码")
@AllArgsConstructor
public class LedgerConfigReleaseController {


    private final ILedgerConfigReleaseService ledgerConfigReleaseService;

    @GetMapping(value = "/page")
    @ApiOperation(value="台账发布表列表(分页)")
    @SaCheckPermission("ledgerconfigrelease:detail")
    public RT<PageOutput<LedgerConfigReleasePageVo>> page(@Valid LedgerConfigReleasePageDto dto){
        Page<LedgerConfigPageVo> page = ledgerConfigReleaseService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<LedgerConfigReleasePageVo> pageOutput = ConventPage.getPageOutput(page, LedgerConfigReleasePageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询台账发布表信息")
    @SaCheckPermission("ledgerconfigrelease:detail")
    public RT<LedgerConfigReleaseVo> info(@RequestParam Long id){
        LedgerConfigReleaseVo release = ledgerConfigReleaseService.getRelease(id);
        if (release == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(release);
    }

    @GetMapping(value = "/config-into")
    @ApiOperation(value="根据id查询台账菜单配置信息")
    @SaCheckPermission("ledgerconfigrelease:detail")
    public RT<LedgerConfigReleaseInfoVo> configInto(@RequestParam Long id){
        LedgerConfigReleaseInfoVo release = ledgerConfigReleaseService.getConfigInfo(id);
        if (release == null) {
            return RT.error("找不到此数据！");
        }
        return RT.ok(release);
    }


    @PostMapping
    @ApiOperation(value = "新增台账发布表")
    @SaCheckPermission("ledgerconfigrelease:add")
    public RT<Boolean> add(@Valid @RequestBody AddLedgerConfigReleaseDto dto){
        boolean isSuccess = ledgerConfigReleaseService.addRelease(dto);
        return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改台账发布表")
    @SaCheckPermission("ledgerconfigrelease:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateLedgerConfigReleaseDto dto){
        return RT.ok(ledgerConfigReleaseService.updateRelease(dto));
    }

    @DeleteMapping
    @ApiOperation(value = "删除台账发布表")
    @SaCheckPermission("ledgerconfigrelease:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(ledgerConfigReleaseService.deleteRelease(ids));
    }

}