package com.bonus.canteen.core.warehouse.controller;

import com.bonus.canteen.core.warehouse.domain.WareHouseCategory;
import com.bonus.canteen.core.warehouse.service.WareHouseCategoryService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存类别Controller
 * 
 * @author jsk
 * @date 2025-04-05
 */
@Api(tags = "库存类别接口")
@RestController
@RequestMapping("/warehouse_category")
public class WareHouseCategoryController extends BaseController {
    @Autowired
    private WareHouseCategoryService wareHouseCategoryService;

    /**
     * @author jsk
     * 查询库存类别列表
     */
    @ApiOperation(value = "查询库存类别列表")
    @GetMapping("/list")
    public TableDataInfo list(WareHouseCategory WareHouseCategory) {
        startPage();
        List<WareHouseCategory> list = wareHouseCategoryService.selectWareHouseCategoryList(WareHouseCategory);
        return getDataTable(list);
    }

    /**
     * @author jsk
     * 新增库存类别
     */
    @ApiOperation(value = "新增库存类别")
    //@PreventRepeatSubmit
    //@RequiresPermissions("WareHouse:info:add")
    @SysLog(title = "库存类别", businessType = OperaType.INSERT, logType = 1,module = "库存管理->新增库存类别")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WareHouseCategory WareHouseCategory) {
        try {
            return toAjax(wareHouseCategoryService.insertWareHouseCategory(WareHouseCategory));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * @author jsk
     * 修改库存类别
     */
    @ApiOperation(value = "修改库存类别")
    @SysLog(title = "库存类别", businessType = OperaType.UPDATE, logType = 1,module = "库存管理->修改库存类别")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody WareHouseCategory WareHouseCategory) {
        try {
            return toAjax(wareHouseCategoryService.updateWareHouseCategory(WareHouseCategory));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * @author jsk
     * 删除库存类别
     */
    @ApiOperation(value = "删除库存类别")
    @SysLog(title = "库存类别", businessType = OperaType.DELETE, logType = 1,module = "库存管理->删除库存类别")
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody WareHouseCategory WareHouseCategory) {
        return toAjax(wareHouseCategoryService.deleteWareHouseCategoryByWareHouseCategoryId(WareHouseCategory));
    }

}
