/*
 *    Copyright (c) 2018-2025, hnqz All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: hnqz
 */

package com.qunzhixinxi.hnqz.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qunzhixinxi.hnqz.common.core.util.R;
import com.qunzhixinxi.hnqz.common.log.annotation.SysLog;
import com.qunzhixinxi.hnqz.admin.entity.WmDeptBudget;
import com.qunzhixinxi.hnqz.admin.service.WmDeptBudgetService;
import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 *
 *
 * @author xyz
 * @date 2021-04-26 18:05:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/budget" )
@Api(value = "budget", tags = "预算管理")
public class WmDeptBudgetController {

    private final  WmDeptBudgetService wmDeptBudgetService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param wmDeptBudget
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/getBudgetViewPage" )
	public R getBudgetViewPage(Page page, WmDeptBudget wmDeptBudget) {
		wmDeptBudget.setDeptId(SecurityUtils.getUser().getDeptId());
		return R.ok(wmDeptBudgetService.getBudgetViewPage(page, wmDeptBudget));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param wmDeptBudget
	 * @return
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@GetMapping("/getBudgetEntViewPage" )
	public R getBudgetEntViewPage(Page page, WmDeptBudget wmDeptBudget) {
		wmDeptBudget.setDeclareDept(SecurityUtils.getUser().getDeptId());
		return R.ok(wmDeptBudgetService.getBudgetEntViewPage(page, wmDeptBudget));
	}


    /**
     * 分页查询
     * @param page 分页对象
     * @param wmDeptBudget
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getWmDeptBudgetPage(Page page, WmDeptBudget wmDeptBudget) {
        return R.ok(wmDeptBudgetService.page(page, Wrappers.query(wmDeptBudget)));
    }


    /**
     * 通过id查询
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(wmDeptBudgetService.getById(id));
    }

    /**
     * 新增
     * @param wmDeptBudget
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @SysLog("新增" )
    @PostMapping
    public R save(@RequestBody WmDeptBudget wmDeptBudget) {
		wmDeptBudget.setDeptId(SecurityUtils.getUser().getDeptId());
		wmDeptBudget.setCreateTime(LocalDateTime.now());
        return R.ok(wmDeptBudgetService.save(wmDeptBudget));
    }

    /**
     * 修改
     * @param wmDeptBudget
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @SysLog("修改" )
    @PutMapping
    public R updateById(@RequestBody WmDeptBudget wmDeptBudget) {
        return R.ok(wmDeptBudgetService.updateById(wmDeptBudget));
    }

    /**
     * 通过id删除
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @SysLog("通过id删除" )
    @DeleteMapping("/{id}" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(wmDeptBudgetService.removeById(id));
    }

}
