package com.goafanti.Interview.service.impl;

import com.goafanti.Interview.service.UserInterviewProjectService;
import com.goafanti.common.constant.AFTConstants;
import com.goafanti.common.dao.UserInterviewProjectMapper;
import com.goafanti.common.model.UserInterviewProject;
import com.goafanti.common.model.UserInterviewProjectBo;
import com.goafanti.common.utils.BeanUtilsExt;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 客户面谈项目表(UserInterviewProject)表服务实现类
 *
 * @author makejava
 * @since 2025-04-11 11:02:01
 */
@Service("userInterviewProjectService")
public class UserInterviewProjectServiceImpl extends BaseMybatisDao<UserInterviewProjectMapper> implements UserInterviewProjectService {
    @Resource
    private UserInterviewProjectMapper userInterviewProjectMapper;


    @Override
    public Pagination<UserInterviewProjectBo> list(UserInterviewProject userInterviewProject, Integer pageNo, Integer pageSize) {
        Map<String, Object> params = BeanUtilsExt.pushMap(userInterviewProject);
        if (!TokenManager.hasRole(AFTConstants.SUPERADMIN)){
            userInterviewProject.setAid(TokenManager.getAdminId());
        }
        return (Pagination<UserInterviewProjectBo>) findPage("findUserInterviewProjectList",
                "findUserInterviewProjectCount", params, pageNo, pageSize);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UserInterviewProject queryById(Integer id) {
        return this.userInterviewProjectMapper.selectById(id);
    }


    /**
     * 新增数据
     *
     * @param userInterviewProject 实例对象
     * @return 实例对象
     */
    @Override
    public UserInterviewProject insert(UserInterviewProject userInterviewProject) {
        userInterviewProject.setType(0);
        userInterviewProject.setStatus(0);
        userInterviewProject.setAid(TokenManager.getAdminId());
        this.userInterviewProjectMapper.insert(userInterviewProject);
        return userInterviewProject;
    }

    /**
     * 修改数据
     *
     * @param userInterviewProject 实例对象
     * @return 实例对象
     */
    @Override
    public UserInterviewProject update(UserInterviewProject userInterviewProject) {
        this.userInterviewProjectMapper.update(userInterviewProject);
        return this.queryById(userInterviewProject.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.userInterviewProjectMapper.deleteById(id) > 0;
    }
}
