package com.JN.demo.zmquotation.controller;

import com.JN.common.R;
import com.JN.demo.zmquotation.dto.InventoryDto;
import com.JN.demo.zmquotation.dto.MaterialDto;
import com.JN.demo.zmquotation.dto.RegionDto;
import com.JN.demo.zmquotation.service.InventoryService;
import com.JN.demo.zmquotation.service.MaterialService;
import com.JN.demo.zmquotation.service.RegionService;
import lombok.experimental.PackagePrivate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @ClassName ZMController
 * @Description TODO
 * @Author JIAL
 * @Date 2024/2/19 8:47
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/zmquotation")
public class ZMController {
    @Autowired
    RegionService regionService;

    @Autowired
    MaterialService materialService;

    @Autowired
    InventoryService inventoryService;

    /**
     * @title queryRegionList
     * @description 查询地区列表信息
     * @author JIAL
     * @param: regionName
     * @updateTime 2024/2/20 16:54
     * @return: com.JN.common.R<java.util.List<com.JN.demo.zmquotation.dto.RegionDto>>
     */
    @PostMapping("/regionList")
    public R queryRegionList(@RequestParam("regionName") String regionName){

        List<RegionDto> regionList = regionService.queryRegionListByName(regionName);

        log.info("查询到的地区列表结果是：{}", regionList);

        return R.success(regionList);
    }

    /**
     * @title queryMaterialList
     * @description 查询物料信息
     * @author JIAL
     * @param: precMaterialName
     * @param: vagueMaterialName
     * @param: vagueModel
     * @updateTime 2024/2/20 16:54
     * @return: com.JN.common.R<java.util.List<com.JN.demo.zmquotation.dto.MaterialDto>>
     */
    @PostMapping("/materialList")
    public R queryMaterialList(@RequestParam("precMaterialName") String precMaterialName,
                               @RequestParam("vagueMaterialName") String vagueMaterialName,
                               @RequestParam("vagueModel") String vagueModel) {
        List<MaterialDto> materialList = materialService.queryMaterialListByParam(precMaterialName, vagueMaterialName, vagueModel);

  /*      Map<String, Object> result = new HashMap<>();
        result.put("rows", materialList);
        result.put("total", materialNum);*/

        return R.success(materialList);
    }

    /**
     * @title queryInventoryList
     * @description 获取盘具列表
     * @author JIAL
     * @updateTime 2024/2/22 10:09
     * @return: com.JN.common.R<java.util.List<com.JN.demo.zmquotation.dto.InventoryDto>>
     */
    @PostMapping("/inventoryList")
    public R queryInventoryList() {
        List<InventoryDto> inventoryList = inventoryService.queryInventoryList();

        return R.success(inventoryList);
    }


}
