package com.fjhx.controller.tda;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.entity.tda.TdaProduct;
import com.fjhx.params.tda.TdaProductEx;
import com.fjhx.params.tda.TdaProductVo;
import com.fjhx.service.tda.TdaProductService;
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-21
 */
@RestController
@RequestMapping("/tdaProduct")
public class TdaProductController {

    @Autowired
    private TdaProductService tdaProductService;

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

    @PostMapping("/add")
    public R add(@RequestBody TdaProductVo tdaProductVo) {
        tdaProductService.add(tdaProductVo);
        return R.success();
    }

    @PostMapping("/delete")
    public R delete(@RequestBody TdaProductVo tdaProductVo) {
        tdaProductService.delete(tdaProductVo);
        return R.success();
    }

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

    /**
     * 获取添加过的厂商名称列表
     */
    @PostMapping("/manufacturerNameList")
    public R manufacturerNameList() {
        List<?> result = tdaProductService.getDistinctList(TdaProduct::getManufacturerName);
        return R.success(result);
    }

    /**
     * 获取添加过的设备类型列表
     */
    @PostMapping("/deviceTypeList")
    public R deviceTypeList() {
        List<?> result = tdaProductService.getDistinctList(TdaProduct::getDeviceType);
        return R.success(result);
    }

}

