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

import com.bonus.canteen.core.alloc.domain.AllocArea;
import com.bonus.canteen.core.supermarket.domain.SupermarketProduct;
import com.bonus.canteen.core.supermarket.service.SupermarketProductService;
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_product")
public class SupermarketProductController extends BaseController {
    @Autowired
    private SupermarketProductService supermarketProductService;

    /**
     * @author jsk
     * 查询商品列表
     */
    @ApiOperation(value = "查询商品列表")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketProduct SupermarketProduct) {
        startPage();
        List<SupermarketProduct> list = supermarketProductService.selectSupermarketProductList(SupermarketProduct);
        return getDataTable(list);
    }

    /**
     * @author jsk
     * 查询未入超市商品列表
     */
    @ApiOperation(value = "查询未入超市商品列表")
    @GetMapping("/nosupermarketlist")
    public TableDataInfo nosupermarketlist(SupermarketProduct SupermarketProduct) {
        startPage();
        List<SupermarketProduct> list = supermarketProductService.selectNoSupermarketProductList(SupermarketProduct);
        return getDataTable(list);
    }

    /**
     * @author jsk
     * 新增商品
     */
    @ApiOperation(value = "新增商品")
    @SysLog(title = "商品", businessType = OperaType.INSERT, logType = 1,module = "商超管理->新增商品")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SupermarketProduct SupermarketProduct) {
        try {
            return toAjax(supermarketProductService.insertSupermarketProduct(SupermarketProduct));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * @author jsk
     * 批量添加商品到超市
     */
    @ApiOperation(value = "修改商品")
    @SysLog(title = "商品", businessType = OperaType.UPDATE, logType = 1,module = "商超管理->修改商品")
    @PostMapping("/editbatch")
    public AjaxResult editbatch(@RequestBody SupermarketProduct SupermarketProduct) {
        try {
            return toAjax(supermarketProductService.updateBatchSupermarketProduct(SupermarketProduct));
        } 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 SupermarketProduct SupermarketProduct) {
        try {
            return toAjax(supermarketProductService.updateSupermarketProduct(SupermarketProduct));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }
    /**
     * @author jsk
     * 修改商品状态
     */
    @ApiOperation(value = "修改商品状态")
    @SysLog(title = "商品", businessType = OperaType.UPDATE, logType = 1,module = "商超管理->修改商品状态")
    @PostMapping("/editState")
    public AjaxResult editState(@RequestBody SupermarketProduct SupermarketProduct) {
        try {
            return toAjax(supermarketProductService.updateSupermarketProductState(SupermarketProduct));
        } catch (Exception e) {
            return error("系统错误, " + e.getMessage());
        }
    }

    /**
     * @author jsk
     * 批量删除商品
     */
    @ApiOperation(value = "批量删除商品")
    @SysLog(title = "商品", businessType = OperaType.DELETE, logType = 1,module = "商超管理->删除商品")
    @PostMapping("/dels")
    public AjaxResult removes(@RequestBody SupermarketProduct supermarketProducts) {
        return toAjax(supermarketProductService.deleteSupermarketProductByProductIds(supermarketProducts));
    }

    /**
     * @author jsk
     * 删除商品
     */
    @ApiOperation(value = "删除商品")
    @SysLog(title = "商品", businessType = OperaType.DELETE, logType = 1,module = "商超管理->删除商品")
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody SupermarketProduct supermarketProduct) {
        return toAjax(supermarketProductService.deleteSupermarketProductByProductId(supermarketProduct));
    }
}
