package com.ruoyi.cms.controller.app;

import com.ruoyi.cms.domain.AppReviewJob;
import com.ruoyi.common.core.domain.entity.AppUser;
import com.ruoyi.common.core.domain.entity.Company;
import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.JobFair;
import com.ruoyi.cms.domain.query.MineJobQuery;
import com.ruoyi.cms.service.*;
import com.ruoyi.common.annotation.BussinessLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.cms.domain.vo.AppUserLky;
import com.ruoyi.common.core.domain.model.RegisterBody;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SiteSecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * app用户Controller
 * 
 * @author lishundong
 * @date 2024-09-03
 */
@RestController
@RequestMapping("/app/user")
@Api(tags = "移动端:用户相关")
public class AppUserController extends BaseController
{
    @Autowired
    private IAppUserService appUserService;
    @Autowired
    private IAppReviewJobService appReviewJobService;
    @Autowired
    private IJobCollectionService jobCollectionService;
    @Autowired
    private ICompanyCollectionService companyCollectionService;
    @Autowired
    private IJobApplyService jobApplyService;
    @Autowired
    private IFairCollectionService fairCollectionService;
    /**
     * 查询岗位列表
     */
    @ApiOperation("保存注册信息")
    @PostMapping("/registerUser")
    @BussinessLog(title = "保存简历")
    public AjaxResult registerUser(@RequestBody RegisterBody registerBody)
    {
        appUserService.registerAppUser(registerBody);
        return AjaxResult.success();
    }

    @ApiOperation("保存简历")
    @PostMapping("/resume")
    public AjaxResult saveResume(@RequestBody AppUser appUser)
    {
        appUser.setUserId(SiteSecurityUtils.getUserId());
        appUserService.updateAppUser(appUser);
        return AjaxResult.success();
    }

    @ApiOperation("查看简历")
    @GetMapping("/resume")
    public AjaxResult getResume()
    {
        AppUser appUser = appUserService.selectAppUserByUserId(SiteSecurityUtils.getUserId());
        return AjaxResult.success(appUser);
    }
    @ApiOperation("我的浏览")
    @GetMapping("/review")
    public TableDataInfo review(MineJobQuery jobQuery)
    {
        startPage();
        List<Job> jobs = appReviewJobService.review(jobQuery);
        return getDataTable(jobs);
    }
    @ApiOperation("我的浏览-日期数组")
    @GetMapping("/review/array")
    public AjaxResult reviewArray(MineJobQuery jobQuery)
    {

        List<String> dateList = appReviewJobService.reviewArray();
        return AjaxResult.success(dateList);
    }
    @ApiOperation("我的岗位收藏")
    @GetMapping("/collection/job")
    public TableDataInfo collectionJob()
    {
        startPage();
        List<Job> jobs = jobCollectionService.collectionJob();
        return getDataTable(jobs);
    }
    @ApiOperation("我的公司收藏")
    @GetMapping("/collection/company")
    public TableDataInfo collectionCompany()
    {
        startPage();
        List<Company> jobs = companyCollectionService.collectionCompany();
        return getDataTable(jobs);
    }
    @ApiOperation("我的招聘会收藏")
    @GetMapping("/collection/fair")
    public TableDataInfo collectionFair(@RequestParam(name = "type") Integer type)
    {
        startPage();
        List<JobFair> jobs = fairCollectionService.appCollectionFair(type);
        return getDataTable(jobs);
    }
    @ApiOperation("我申请的岗位")
    @GetMapping("/apply/job")
    public TableDataInfo applyJob()
    {
        startPage();
        List<Job> jobs = jobApplyService.applyJob();
        return getDataTable(jobs);
    }
    @ApiOperation("统计")
    @GetMapping("/statistics")
    public AjaxResult statistics()
    {
        HashMap<String,Integer> result = jobApplyService.statistics();
        return AjaxResult.success(result);
    }

    @ApiOperation("根据条件查询用户信息")
    @GetMapping("/list")
    public AjaxResult getUserList(AppUser appUser)
    {
        List<AppUser> list = appUserService.selectAppUserList(appUser);
        return AjaxResult.success(list);
    }

    @ApiOperation("返回求职者劳科院-当前职位名称、技能标签")
    @GetMapping("/appUserInfo")
    public AjaxResult appUserInfo(AppUser appUser)
    {
        if(!SiteSecurityUtils.isLogin()){
            return AjaxResult.error("未登录！");
        }
        appUser.setUserId(SiteSecurityUtils.getUserId());
        AppUserLky appUserLky = appUserService.selectAppUserInfo(appUser);
        return AjaxResult.success(appUserLky);
    }

    @PostMapping("/browse")
    @ApiOperation("用户浏览")
    public AjaxResult browse(@RequestBody AppReviewJob appReviewJob)
    {
        if(appReviewJob.getJobId()==null){
            return AjaxResult.error("岗位id为空");
        }
        if(!SiteSecurityUtils.isLogin()){
            return AjaxResult.error("用户未登录!");
        }
        if(StringUtils.isEmpty(appReviewJob.getReviewDate())){
            appReviewJob.setReviewDate(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date()));
        }
        appReviewJob.setUserId(SiteSecurityUtils.getUserId());
        return toAjax(appReviewJobService.insertAppReviewJob(appReviewJob));
    }
}
