package com.ym.mec.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ym.mec.biz.dal.entity.LeaveCategory;
import com.ym.mec.biz.service.LeaveCategoryService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;

@RequestMapping("leaveCategory")
@Api(tags = "请假类型服务")
@RestController
public class LeaveCategoryController extends BaseController {

    @Autowired
    private LeaveCategoryService leaveCategoryService;

    @ApiOperation(value = "新增请假类型")
    @PostMapping("/add")
    @PreAuthorize("@pcs.hasPermissions('leaveCategory/add')")
    public Object add(LeaveCategory leaveCategory) {
        leaveCategoryService.insert(leaveCategory);
        return succeed();
    }

    @ApiOperation(value = "删除请假类型")
    @PostMapping("/del/{id}")
    @PreAuthorize("@pcs.hasPermissions('leaveCategory/del')")
    public Object del(@ApiParam(value = "请假类型编号", required = true) @PathVariable("id") Integer id) {
        leaveCategoryService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改请假类型")
    @PostMapping("/update")
    @PreAuthorize("@pcs.hasPermissions('leaveCategory/update')")
    public Object update(LeaveCategory leaveCategory) {
        leaveCategory.setUpdateTime(new Date());
        leaveCategoryService.update(leaveCategory);
        return succeed();
    }

    @ApiOperation(value = "分页查询请假类型列表")
    @PostMapping("/queryPage")
    @PreAuthorize("@pcs.hasPermissions('leaveCategory/queryPage')")
    public Object queryPage(QueryInfo queryInfo) {
        return succeed(leaveCategoryService.queryPage(queryInfo));
    }

}
