package com.fjhx.controller.material;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.tool.api.R;
import com.fjhx.entity.material.Material;
import com.fjhx.params.material.MaterialVo;
import com.fjhx.service.material.MaterialService;
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.Map;

/**
 * <p>
 * 物料 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-11-24
 */
@RestController
@RequestMapping("/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

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

    @PostMapping("/add")
    public R add(@RequestBody MaterialVo materialVo){
        materialService.add(materialVo);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody MaterialVo materialVo){
        materialService.edit(materialVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody MaterialVo materialVo){
        materialService.delete(materialVo);
        return R.success();
    }

    @PostMapping("/details")
    public R details(@RequestBody MaterialVo materialVo){
        return R.success(materialService.getById(materialVo.getId()));
    }

}

