package com.bonus.material.ma.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.common.log.enums.OperaType;
import com.bonus.material.common.annotation.PreventRepeatSubmit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.material.ma.domain.TypeKeeper;
import com.bonus.material.ma.service.ITypeKeeperService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.page.TableDataInfo;

/**
 * 库管员配置Controller
 * @author bonus
 */
@Api(tags = "库管员配置API")
@RestController
@RequestMapping("/ma_type_keeper")
public class TypeKeeperController extends BaseController {

    @Autowired
    private ITypeKeeperService typeKeeperService;

    /**
     * 查询库管员配置列表
     */
    @ApiOperation(value = "查询库管员配置列表")
    @RequiresPermissions("ma:keeper:list")
    @GetMapping("/list")
    public TableDataInfo list(TypeKeeper typeKeeper) {
        startPage();
        List<TypeKeeper> list = typeKeeperService.selectTypeKeeperList(typeKeeper);
        return getDataTable(list);
    }

    /**
     * 导出库管员配置列表
     */
    @ApiOperation(value = "导出库管员配置列表")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:keeper:export")
    @SysLog(title = "库管员配置", businessType = OperaType.EXPORT, module = "物资管理->导出库管员配置")
    @PostMapping("/export")
    public void export(HttpServletResponse response, TypeKeeper typeKeeper) {
        List<TypeKeeper> list = typeKeeperService.selectTypeKeeperList(typeKeeper);
        ExcelUtil<TypeKeeper> util = new ExcelUtil<TypeKeeper>(TypeKeeper.class);
        util.exportExcel(response, list, "库管员配置数据");
    }

    /**
     * 获取库管员配置详细信息
     */
    @ApiOperation(value = "获取库管员配置详细信息")
    @RequiresPermissions("ma:keeper:query")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(typeKeeperService.selectTypeKeeperByID(ID));
    }

    /**
     * 新增库管员配置
     */
//    @ApiOperation(value = "新增库管员配置")
//    @PreventRepeatSubmit
//    @RequiresPermissions("ma:keeper:add")
//    @SysLog(title = "库管员配置", businessType = OperaType.INSERT, module = "物资管理->新增库管员配置")
//    @PostMapping
//    public AjaxResult add(@RequestBody TypeKeeper typeKeeper) {
//        return toAjax(typeKeeperService.insertTypeKeeper(typeKeeper));
//    }

    /**
     * 新增库管员配置
     */
    @ApiOperation(value = "新增库管员配置")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:keeper:add")
    @SysLog(title = "库管员配置", businessType = OperaType.INSERT, module = "物资管理->新增库管员配置")
    @PostMapping
    public AjaxResult add(@RequestBody List<TypeKeeper> typeKeepers) {
        return toAjax(typeKeeperService.insertTypeKeeper(typeKeepers));
    }

    /**
     * 修改库管员配置
     */
    @ApiOperation(value = "修改库管员配置")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:keeper:edit")
    @SysLog(title = "库管员配置", businessType = OperaType.UPDATE, module = "物资管理->修改库管员配置")
    @PutMapping
    public AjaxResult edit(@RequestBody TypeKeeper typeKeeper) {
        return toAjax(typeKeeperService.updateTypeKeeper(typeKeeper));
    }

    /**
     * 批量删除库管员配置
     */
    @ApiOperation(value = "批量删除库管员配置")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:keeper:remove")
    @SysLog(title = "库管员配置", businessType = OperaType.DELETE, module = "物资管理->批量删除库管员配置")
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(typeKeeperService.deleteTypeKeeperByIDs(IDs));
    }

    /**
     * 删除单个库管员配置
     */
//    @ApiOperation(value = "删除单个库管员配置")
//    @PreventRepeatSubmit
//    @RequiresPermissions("ma:keeper:remove")
//    @SysLog(title = "库管员配置", businessType = OperaType.DELETE, logType = 1,module = "物资管理->删除单个库管员配置")
//    @DeleteMapping
//    public AjaxResult remove(@RequestBody TypeKeeper typeKeeper)
//    {
//        return toAjax(typeKeeperService.deleteTypeKeeperByUserIdAndTypeId(typeKeeper));
//    }

    @ApiOperation(value = "删除库管员配置")
    @PreventRepeatSubmit
    @RequiresPermissions("ma:keeper:remove")
    @SysLog(title = "库管员配置", businessType = OperaType.DELETE, logType = 1,module = "物资管理->删除单个库管员配置")
    @DeleteMapping
    public AjaxResult remove(@RequestBody List<TypeKeeper> typeKeepers)
    {
        return toAjax(typeKeeperService.deleteTypeKeeperByUserIdAndTypeId(typeKeepers));
    }
}
