package com.fjhx.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.Material;
import com.fjhx.service.MaterialExService;
import com.fjhx.service.MaterialService;
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.Map;

/**
 * 物料 前端控制器
 */
@RestController
@RequestMapping("/material")
public class MaterialController {

    @Autowired
    private MaterialService materialService;

    @Autowired
    private MaterialExService materialExService;

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

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

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

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

    @PostMapping("/list")
    public R list() {
        return R.success(materialService.list());
    }

}
