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

import com.bonus.canteen.core.warehouse.domain.WareHouseInfo;
import com.bonus.canteen.core.warehouse.service.WareHouseInfoService;
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_info")
public class WareHouseInfoController extends BaseController {
    @Autowired
    private WareHouseInfoService wareHouseInfoService;

    /**
     * @author jsk
     * 查询仓库列表
     */
    @ApiOperation(value = "查询仓库列表")
    @GetMapping("/list")
    public TableDataInfo list(WareHouseInfo WareHouseInfo) {
        startPage();
        List<WareHouseInfo> list = wareHouseInfoService.selectWareHouseInfoList(WareHouseInfo);
        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 WareHouseInfo WareHouseInfo) {
        try {
            return toAjax(wareHouseInfoService.insertWareHouseInfo(WareHouseInfo));
        } 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 WareHouseInfo WareHouseInfo) {
        try {
            return toAjax(wareHouseInfoService.updateWareHouseInfo(WareHouseInfo));
        } 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 WareHouseInfo WareHouseInfo) {
        return toAjax(wareHouseInfoService.deleteWareHouseInfoByWareHouseId(WareHouseInfo));
    }

}
