package cn.iocoder.yudao.module.inspection.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.entity.InspectionGoodsSku;
import cn.iocoder.yudao.module.inspection.service.InspectionGoodsSkuService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * (InspectionGoodsSku)表控制层
 *
 * @author makejava
 * @since 2023-08-08 16:59:29
 */
@RestController
@RequestMapping("/admin-api/system/inspectionGoodsSku")
public class InspectionGoodsSkuController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private InspectionGoodsSkuService inspectionGoodsSkuService;

    /**
     * 分页查询所有数据

     * @param inspectionGoodsSku 查询实体
     * @return 所有数据
     */
    @GetMapping("/list")
    public CommonResult selectAll(InspectionGoodsSku inspectionGoodsSku,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<InspectionGoodsSku> page = new Page<>(pageNum, pageSize);
        IPage<InspectionGoodsSku> resList = this.inspectionGoodsSkuService.page(page,new QueryWrapper<>(inspectionGoodsSku));
        return success(resList);
    }


    /**
     * 新增数据
     *
     * @param inspectionGoodsSku 实体对象
     * @return 新增结果
     */
    @PostMapping("/add")
    public CommonResult insert(@RequestBody InspectionGoodsSku inspectionGoodsSku) {
        this.inspectionGoodsSkuService.save(inspectionGoodsSku);
        return success();
    }

    /**
     * 修改数据
     *
     * @param inspectionGoodsSku 实体对象
     * @return 修改结果
     */
    @PostMapping("/edit")
    public CommonResult update(@RequestBody InspectionGoodsSku inspectionGoodsSku) {
        this.inspectionGoodsSkuService.updateById(inspectionGoodsSku);
        return success();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/del")
    public CommonResult delete(@RequestParam("idList") List<Long> idList) {
        return success(this.inspectionGoodsSkuService.removeByIds(idList));
    }
}

