package com.ruoyi.cms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cms.domain.AppReviewJob;
import com.ruoyi.cms.domain.Job;
import com.ruoyi.cms.domain.query.MineJobQuery;
import com.ruoyi.cms.mapper.AppReviewJobMapper;
import com.ruoyi.cms.service.IAppReviewJobService;
import com.ruoyi.common.utils.SiteSecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 用户岗位浏览记录Service业务层处理
 *
 * @author ${author}
 * @date 2025-02-14
 */
@Service
public class AppReviewJobServiceImpl extends ServiceImpl<AppReviewJobMapper, AppReviewJob> implements IAppReviewJobService
{
    @Autowired
    private AppReviewJobMapper appReviewJobMapper;

    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    /**
     * 查询用户岗位浏览记录
     *
     * @param id 用户岗位浏览记录主键
     * @return 用户岗位浏览记录
     */
    @Override
    public AppReviewJob selectAppReviewJobById(Long id)
    {
        return appReviewJobMapper.selectById(id);
    }

    /**
     * 查询用户岗位浏览记录列表
     *
     * @param appReviewJob 用户岗位浏览记录
     * @return 用户岗位浏览记录
     */
    @Override
    public List<AppReviewJob> selectAppReviewJobList(AppReviewJob appReviewJob)
    {
        return appReviewJobMapper.selectAppReviewJobList(appReviewJob);
    }

    /**
     * 新增用户岗位浏览记录
     *
     * @param appReviewJob 用户岗位浏览记录
     * @return 结果
     */
    @Override
    public int insertAppReviewJob(AppReviewJob appReviewJob)
    {
        return appReviewJobMapper.insert(appReviewJob);
    }

    /**
     * 修改用户岗位浏览记录
     *
     * @param appReviewJob 用户岗位浏览记录
     * @return 结果
     */
    @Override
    public int updateAppReviewJob(AppReviewJob appReviewJob)
    {
        return appReviewJobMapper.updateById(appReviewJob);
    }

    /**
     * 批量删除用户岗位浏览记录
     *
     * @param ids 需要删除的用户岗位浏览记录主键
     * @return 结果
     */
    @Override
    public int deleteAppReviewJobByIds(Long[] ids)
    {
        return appReviewJobMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public List<Job> review(MineJobQuery jobQuery) {
        List<Job> jobs = appReviewJobMapper.review(SiteSecurityUtils.getUserId(),jobQuery);
        return jobs;
    }

    @Override
    public List<String> reviewArray() {
        List<AppReviewJob> appReviewJobs = appReviewJobMapper.reviewArray(SiteSecurityUtils.getUserId());
        return appReviewJobs.stream().map(x -> formatter.format(x.getReviewDate())).collect(Collectors.toList());
    }

    @Override
    public List<Job> selectAppReviewJobListJob(AppReviewJob appReviewJob) {
        return appReviewJobMapper.selectAppReviewJobListJob(appReviewJob);
    }
}