package com.ruoyi.cms.controller.app;


import com.ruoyi.common.core.domain.entity.Company;
import com.ruoyi.cms.domain.CompanyCard;
import com.ruoyi.cms.domain.query.LabelQuery;
import com.ruoyi.cms.mapper.CompanyCardMapper;
import com.ruoyi.cms.service.ICompanyCardService;
import com.ruoyi.cms.service.ICompanyCollectionService;
import com.ruoyi.cms.service.ICompanyService;
import com.ruoyi.common.annotation.BussinessLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 公司Controller
 * 
 * @author lishundong
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/app/company")
@Api(tags = "移动端：公司")
public class AppCompanyController extends BaseController
{
    @Autowired
    private ICompanyService companyService;
    @Autowired
    private ICompanyCollectionService companyCollectionService;
    @Autowired
    private ICompanyCardService companyCardService;
    @Autowired
    private CompanyCardMapper companyCardMapper;
    /**
     * 获取公司详细信息
     */
    @ApiOperation("获取公司详细信息")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(companyService.selectCompanyByCompanyId(companyId));
    }
    /**
     * 用户收藏公司
     */
    @BussinessLog(title = "用户收藏公司")
    @PostMapping("/collection/{companyId}")
    @ApiOperation("用户收藏公司")
    public AjaxResult companyCollection(@PathVariable("companyId") Long companyId)
    {
        return toAjax(companyCollectionService.companyCollection(companyId));
    }

    /**
     * 用户取消收藏公司
     */
    @BussinessLog(title = "用户取消收藏公司")
    @DeleteMapping("/collection/{companyId}")
    @ApiOperation("用户取消收藏公司")
    public AjaxResult companyCancel(@PathVariable("companyId") Long companyId)
    {
        return toAjax(companyCollectionService.companyCancel(companyId));
    }
    /**
     * 公司下的岗位
     */
    @GetMapping("/job/{companyId}")
    @ApiOperation("公司下的岗位")
    public TableDataInfo jobCompany(@ApiParam("公司id") @PathVariable Long companyId)
    {
        startPage();
        return getDataTable(companyCollectionService.jobCompany(companyId));
    }
    @GetMapping("/card")
    @ApiOperation("查看企业卡片")
    public TableDataInfo card()
    {
        startPage();
        return getDataTable(companyCardService.cardApp());
    }
    @BussinessLog(title = "收藏企业卡片")
    @PutMapping("/card/collection/{companyCardId}")
    @ApiOperation("收藏企业卡片")
    public AjaxResult cardCollection(@PathVariable Long companyCardId)
    {
        companyCardService.cardCollection(companyCardId);
        return success();
    }
    @BussinessLog(title = "取消收藏企业卡片")
    @DeleteMapping("/card/collection/{companyCardId}")
    @ApiOperation("取消收藏公司卡片")
    public AjaxResult cardCancel(@PathVariable Long companyCardId)
    {
        companyCardService.cardCancel(companyCardId);
        return success();
    }
    @GetMapping("/count/{companyId}")
    @ApiOperation("公司招聘的岗位数量")
    public AjaxResult count(@PathVariable Long companyId)
    {
        Integer count = companyService.count(companyId);
        return success(count);
    }
    @GetMapping("/label")
    @ApiOperation("公司标签下的公司")
    public TableDataInfo label(LabelQuery labelQuery)
    {
        CompanyCard companyCard = companyCardMapper.selectById(labelQuery.getCardId());
        startPage();
        List<Company> companyList = companyService.label(companyCard,labelQuery);
        return getDataTable(companyList);
    }
    @PostMapping("/register")
    @ApiOperation("招聘企业登记")
    @BussinessLog(title = "招聘企业登记")
    public AjaxResult register(Company company)
    {
        companyService.register(company);
        return AjaxResult.success();
    }
    @GetMapping("/register/status")
    @ApiOperation("招聘企业登记进度查询")
    public AjaxResult registerStatus()
    {
        Company status = companyService.registerStatus();
        return AjaxResult.success(status);
    }

    @GetMapping("/queryCodeCompany")
    @ApiOperation("根据社会信用代码查询企业")
    public AjaxResult queryCodeCompany(@RequestParam("code") String code)
    {
        if (!StringUtils.hasText(code)) {
            return AjaxResult.error("社会信用代码不能为空");
        }
        return AjaxResult.success(companyService.queryCodeCompany(code));
    }

    @ApiOperation("模糊查询公司列表")
    @GetMapping("/likeList")
    public TableDataInfo likeList(Company company)
    {
        List<Company> list = companyService.selectLikeCompanyList(company);
        return getDataTable(list);
    }
}
