package com.fjhx.controller.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.Product;
import com.fjhx.params.production.ProductWorkingRoute;
import com.fjhx.service.ProductService;
import com.fjhx.service.product.ProductExService;
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-07-14
 */
@RestController
@RequestMapping("/product")
public class ProductExController {

    @Autowired
    private ProductExService productExService;

    @Autowired
    private ProductService productService;

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

    @PostMapping("/add")
    public R add(@RequestBody Map<String, Object> map) {
        productExService.add(map);
        return R.success();
    }

    @PostMapping("/edit")
    public R edit(@RequestBody Map<String, Object> map) {
        productExService.edit(map);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody Map<String, Object> map) {
        productExService.delete(map);
        return R.success();
    }

    @PostMapping("getUnitList")
    public R getUnitList() {
        List<String> result = productService.getUnitList();
        return R.success(result);
    }

    @PostMapping("list")
    public R list() {
        List<Map<String, Object>> result = productExService.getList();
        return R.success(result);
    }

    /**
     * 获取产品关联工序
     */
    @PostMapping("getWorkingRoute")
    public R getWorkingRoute(@RequestBody Product product) {
        ProductWorkingRoute productWorkingRoute = productExService.getWorkingRoute(product.getId());
        return R.success(productWorkingRoute);
    }

}

