package com.fjhx.controller.warehouse;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.base.BaseEntity;
import com.fjhx.entity.warehouse.Warehouse;
import com.fjhx.params.warehouse.WarehouseVo;
import com.fjhx.service.warehouse.WarehouseService;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 仓库 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-24
 */
@RestController
@RequestMapping("/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseService warehouseService;

    @PostMapping("/page")
    public R page(@RequestBody Map<String, Object> condition) {
        Page<Warehouse> result = warehouseService.getPage(condition);
        return R.success(result);
    }

    @PostMapping("/add")
    public R add(@RequestBody WarehouseVo warehouseVo) {
        warehouseService.add(warehouseVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody WarehouseVo warehouseVo) {
        warehouseService.edit(warehouseVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody WarehouseVo warehouseVo) {
        warehouseService.delete(warehouseVo);
        return R.success();
    }

    @PostMapping("/details")
    public R details(@RequestBody WarehouseVo warehouseVo) {
        return R.data(warehouseService.getById(warehouseVo.getId()));
    }

    @PostMapping("/select")
    public R select() {
        return R.success(warehouseService.select());
    }

    @PostMapping("list")
    public R getList() {
        List<Warehouse> list = warehouseService.list(q -> q.select(BaseEntity::getId, Warehouse::getName, Warehouse::getType));
        return R.success(list);
    }

}

