package com.zhongzheng.controller.pay;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zhongzheng.common.annotation.Log;
import com.zhongzheng.common.core.controller.BaseController;
import com.zhongzheng.common.core.domain.AjaxResult;
import com.zhongzheng.common.enums.BusinessType;
import com.zhongzheng.modules.pay.vo.PayCostVo;
import com.zhongzheng.modules.pay.bo.PayCostQueryBo;
import com.zhongzheng.modules.pay.bo.PayCostAddBo;
import com.zhongzheng.modules.pay.bo.PayCostEditBo;
import com.zhongzheng.modules.pay.service.IPayCostService;
import com.zhongzheng.common.utils.poi.ExcelUtil;
import com.zhongzheng.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 费用类型Controller
 * 
 * @author ruoyi
 * @date 2021-10-12
 */
@Api(value = "费用类型控制器", tags = {"费用类型管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/pay/cost")
public class PayCostController extends BaseController {

    private final IPayCostService iPayCostService;

    /**
     * 查询费用类型列表
     */
    @ApiOperation("查询费用类型列表")
    @PreAuthorize("@ss.hasPermi('pay:cost:list')")
    @GetMapping("/list")
    public TableDataInfo<PayCostVo> list(PayCostQueryBo bo) {
        startPage();
        List<PayCostVo> list = iPayCostService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出费用类型列表
     */
 /*   @ApiOperation("导出费用类型列表")
    @PreAuthorize("@ss.hasPermi('pay:cost:export')")
    @Log(title = "费用类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<PayCostVo> export(PayCostQueryBo bo) {
        List<PayCostVo> list = iPayCostService.queryList(bo);
        ExcelUtil<PayCostVo> util = new ExcelUtil<PayCostVo>(PayCostVo.class);
        return util.exportExcel(list, "费用类型");
    }*/

    /**
     * 获取费用类型详细信息
     */
    @ApiOperation("获取费用类型详细信息")
    @PreAuthorize("@ss.hasPermi('pay:cost:query')")
    @GetMapping("/{costId}")
    public AjaxResult<PayCostVo> getInfo(@PathVariable("costId" ) Long costId) {
        return AjaxResult.success(iPayCostService.queryById(costId));
    }

    /**
     * 新增费用类型
     */
    @ApiOperation("新增费用类型")
    @PreAuthorize("@ss.hasPermi('pay:cost:add')")
    @Log(title = "费用类型", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody PayCostAddBo bo) {
        return toAjax(iPayCostService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改费用类型
     */
    @ApiOperation("修改费用类型")
    @PreAuthorize("@ss.hasPermi('pay:cost:edit')")
    @Log(title = "费用类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult<Void> edit(@RequestBody PayCostEditBo bo) {
        return toAjax(iPayCostService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除费用类型
     */
/*    @ApiOperation("删除费用类型")
    @PreAuthorize("@ss.hasPermi('pay:cost:remove')")
    @Log(title = "费用类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{costIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] costIds) {
        return toAjax(iPayCostService.deleteWithValidByIds(Arrays.asList(costIds), true) ? 1 : 0);
    }*/
}
