package com.zcloud.modules.oa.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.zcloud.common.utils.PageUtils;
import com.zcloud.modules.oa.dao.OaPostDao;
import com.zcloud.modules.oa.entity.OaPostEntity;
import com.zcloud.modules.oa.service.OaPostService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author fangjiakai
 * @Desc 岗位(OaPost)表服务实现类
 * @Date 2023-10-17 16:31:25
 */
@Service("oaPostService")
public class OaPostServiceImpl extends ServiceImpl<OaPostDao, OaPostEntity> implements OaPostService {

    @Override
    public PageUtils listPage(Map<String, Object> params) {
		Page<Map<String,Object>> page = new Page<>(Integer.parseInt(params.get("curPage").toString()),Integer.parseInt(params.get("limit").toString()));
		params.put("isDelete",0);
        IPage<Map<String,Object>> ipage = baseMapper.listPage(page,params);
        return new PageUtils(ipage);
    }


   @Override
	public void delete(String postId,String userId){
		OaPostEntity oaPost = baseMapper.selectById(postId);
		oaPost.setOperator(userId);
	    baseMapper.deleteById(oaPost);
	}

	@Override
	public boolean savePost(OaPostEntity param) {
		QueryWrapper<OaPostEntity> queryWrapper = new QueryWrapper<>();
//		queryWrapper.eq("department_id",param.getDepartmentId());
		queryWrapper.eq("name",param.getName());

		OaPostEntity oaPostEntity = baseMapper.selectOne(queryWrapper);
		if (oaPostEntity != null)
			return false;

		baseMapper.insert(param);
		return true;
	}

	@Override
	public OaPostEntity getByName(String name, String departmentId) {
		QueryWrapper<OaPostEntity> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("department_id",departmentId);
		queryWrapper.eq("name",name);
		return baseMapper.selectOne(queryWrapper);
	}
}
