package com.fjhx.material.controller;

import com.fjhx.base.ListPageMap;
import com.fjhx.entity.material.Material;
import com.fjhx.material.service.MaterialService;
import com.fjhx.params.material.EditMaterialVo;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

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

    @Autowired
    private MaterialService materialService;

    /**
     * 下拉物料
     */
    @PostMapping("/selectList")
    public R selectList(@RequestBody Map<String, Object> condition) {
        ListPageMap.getListPageMap(condition);
        List<Material> list = materialService.selectList(condition);
        return R.success(list);
    }

    /**
     * 下拉物料
     */
    @GetMapping("/selectPurposeList")
    public R selectPurposeList(@RequestParam(required = false) String purpose) {
        List<Material> list = materialService.selectPurpose(purpose);
        return R.success(list);
    }

    @PostMapping("getMaterialPrice")
    public R getMaterialPrice(@RequestBody Map<String, String> condition) {
        List<Map<String, Object>> result = materialService.getMaterialPrice(condition.get("materialCode"));
        return R.success(result);
    }

    @PostMapping("edit")
    public R edit(@RequestBody EditMaterialVo editMaterialVo) {
        boolean flag = materialService.edit(editMaterialVo);
        return R.success(flag);
    }

}

