package com.dgtly.api.controller;

import com.dgtly.common.annotation.ApiPassToken;
import com.dgtly.common.core.controller.ApiBaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.core.domain.ParameterObject;
import com.dgtly.common.core.domain.ResultType;
import com.dgtly.companyext.domain.CompanyExtInfo;
import com.dgtly.companyext.service.ICompanyExtInfoService;
import com.dgtly.goods.domain.GoodsInfo;
import com.dgtly.system.domain.SysCompany;
import com.dgtly.system.service.ISysCompanyService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/company/")
@ApiPassToken/* 不用验证token  方法上可用*/
public class SysCompanyController extends ApiBaseController {


    @Autowired
    private ISysCompanyService companyService;

    @Autowired
    private ICompanyExtInfoService companyExtInfoService;

    @ApiOperation(value = "商家详情")
    @ApiImplicitParam(name = "params" , paramType = "body")
    @PostMapping("/details")
    public Object detail(){
        ParameterObject obj =  getParameterObject();
        obj.checkParameterNotNull("id");
        Long companyId = obj.getLong(" id");
        CompanyExtInfo  companyExtInfo =  companyExtInfoService.selectCompanyExtInfoByCompanyId(companyId);
        if(companyExtInfo!=null){
            return AjaxResult.success(companyExtInfo);
        }else{
            return AjaxResult.error(ResultType.NUll);
        }
    }


    @ApiOperation(value = "热门商家列表")
    @ApiImplicitParam(name = "params" , paramType = "body")
    @PostMapping("/hotlist")
    public Object getHotList(){
        List<SysCompany> goodsInfos =  companyService.selectCompanyHotList();
        return AjaxResult.success().putKV("list",goodsInfos);
    }

}
