package com.dsk.web.controller.search.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONObject;
import com.dsk.common.core.domain.AjaxResult;
import com.dsk.common.dtos.ComposeQueryDto;
import com.dsk.web.controller.search.service.BusinessOpportunityRadarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 查企业
 * @author Administrator
 *
 */
@RequestMapping("/enterprise")
@RestController
public class CompanySearchController {


    @Resource
    BusinessOpportunityRadarService opportunityRadarService;

    /*
     * 模糊查询企业名称
     */
    @RequestMapping("/index")
    public AjaxResult landMarketPage(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.enterpriseIndex(object);
    }

    /*
     * 完全匹配企业名称
     */
    @GetMapping("/findByName/{keyword}")
    public AjaxResult findByName(@PathVariable String keyword) {
        return opportunityRadarService.enterpriseByName(keyword);
    }

    /*
     * 完全匹配企业名称
     */
    @PostMapping("/page")
    public AjaxResult page(@RequestBody JSONObject object) {
        ComposeQueryDto compose = JSONObject.parseObject(object.toJSONString(), ComposeQueryDto.class);
        if (PageQueryLimit.pageLimit(compose.getPage())){
            return AjaxResult.error("翻页已达到上限");
        }
        return opportunityRadarService.enterprisePage(object);
    }
}
