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

import com.bonus.canteen.core.supermarket.domain.SupermarketUnit;
import com.bonus.canteen.core.supermarket.service.SupermarketUnitService;
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("/supermarket_unit")
public class SupermarketUnitController extends BaseController {
    @Autowired
    private SupermarketUnitService supermarketUnitService;

    /**
     * @author jsk
     * 查询单位列表
     */
    @ApiOperation(value = "查询单位列表")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketUnit SupermarketUnit) {
        startPage();
        List<SupermarketUnit> list = supermarketUnitService.selectSupermarketUnitList(SupermarketUnit);
        return getDataTable(list);
    }

    /**
     * @author jsk
     * 新增单位
     */
    @ApiOperation(value = "新增单位")
    @SysLog(title = "单位", businessType = OperaType.INSERT, logType = 1,module = "商超管理->新增单位")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SupermarketUnit SupermarketUnit) {
        try {
            return toAjax(supermarketUnitService.insertSupermarketUnit(SupermarketUnit));
        } 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 SupermarketUnit SupermarketUnit) {
        try {
            return toAjax(supermarketUnitService.updateSupermarketUnit(SupermarketUnit));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * @author jsk
     * 删除单位
     */
    @ApiOperation(value = "删除单位")
    @SysLog(title = "单位", businessType = OperaType.DELETE, logType = 1,module = "商超管理->删除单位")
    @PostMapping("/del")
    public AjaxResult remove(@PathVariable Long SupermarketIds) {
        return toAjax(supermarketUnitService.deleteSupermarketUnitBySupermarketId(SupermarketIds));
    }

}
