package com.example.aliossjava.controller;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Map;


@RestController
public class CompanyNameController {
    @Autowired
    private com.example.aliossjava.common.CompanyNameUtils CompanyNameUtils;
    /**
     *
     * @param baseinfo
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping(value = "/getNames",method = RequestMethod.POST)
    public Map<String,Object> companyName(@RequestBody @Valid String baseinfo) throws Exception {

        try {
            JSONObject jsonObject = JSONObject.parseObject(baseinfo);
            String region=jsonObject.getString("region");
            String type=jsonObject.getString("type");
            String modality=jsonObject.getString("modality");
            String nameNum=jsonObject.getString("nameNum");
            String goodName=jsonObject.getString("goodName");
            Integer from = jsonObject.getInteger("from");
            Integer size = jsonObject.getInteger("size");
            return CompanyNameUtils.nameList(region, type, modality, nameNum, goodName,from,size);
        } catch (Exception e) {
            System.out.println("getNames-error："+e.toString());
            return null;
        }
    }
}
