package com.sqx.modules.intention.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.common.service.CommonInfoService;
import com.sqx.modules.intention.dao.IntentionDao;
import com.sqx.modules.intention.entity.Intention;
import com.sqx.modules.intention.service.IntentionService;
import com.sqx.modules.resumes.entity.RuleClassify;
import com.sqx.modules.resumes.service.RuleClassifyService;
import com.sqx.modules.resumes.service.RulePostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import weixin.popular.bean.datacube.article.Usershare;

import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author www.javacoder.top
 * @since 2023-01-13
 */
@Service
public class IntentionServiceImpl extends ServiceImpl<IntentionDao, Intention> implements IntentionService {
    @Autowired
    CommonInfoService commonInfoService;
    @Autowired
    private UserService userService;
    @Autowired
    private RuleClassifyService classifyService;

    @Override
    public Result saveUpdate(Intention intention) {
        int num = baseMapper.selectCount(new QueryWrapper<Intention>().eq("user_id", intention.getUserId()).eq("is_default", 1));
        if (num < 3) {
             return Result.upStatus(baseMapper.insert(intention));
        }else {
            return  Result.error("最多保存三条求职意向");
        }
    }
    @Override
    public IPage<Intention> getIntentionList(Integer page, Integer limit, Intention intention) {
        Page<Intention> pages;
        if (page != null && limit != null) {
            pages = new Page<>(page, limit);
        } else {
            pages = new Page<>();
            pages.setSize(-1);
        }
        return baseMapper.selectPage(pages, new QueryWrapper<>(intention).orderByDesc("create_time"));
    }

    @Override
    public List<Intention> getIntention(Long userId) {
        QueryWrapper<Intention>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("is_default",1);
        return baseMapper.selectList(queryWrapper);
    }
}
