package com.zcxk.evaluation.service.impl;


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.zcxk.evaluation.dao.EvaluationItemValueMapper;
import com.zcxk.evaluation.entity.EvaluationItemValueEntity;
import com.zcxk.evaluation.service.EvaluationItemValueService;
import com.zcxk.model.LoginUser;
import com.zcxk.util.UserUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 考评项分值Service接口
 *
 * @author: WYY
 * @date 2021-05-08 09:27
 */
@Service
public class EvaluationItemValueServiceImpl extends ServiceImpl<EvaluationItemValueMapper, EvaluationItemValueEntity> implements EvaluationItemValueService {

    @Resource
    private EvaluationItemValueMapper evaluationItemValueMapper;

    /**
     * 自定义分页查询，含关联实体对像
     */
    @Override
    public IPage<EvaluationItemValueEntity> findPage(IPage<EvaluationItemValueEntity> page, EvaluationItemValueEntity evaluationItemValueEntity) {
        LoginUser currentUser = UserUtil.getCurrentUser();
        if(currentUser!=null) {
            evaluationItemValueEntity.setTenantId(currentUser.getTenantId());
        }
        Page<EvaluationItemValueEntity> iPage = evaluationItemValueMapper.findPage(page,evaluationItemValueEntity);
        return iPage;
    }

    /**
     * 查列表
     */
    @Override
    public List<EvaluationItemValueEntity> findList(EvaluationItemValueEntity evaluationItemValueEntity) {
        LoginUser currentUser = UserUtil.getCurrentUser();
        if(currentUser!=null) {
            evaluationItemValueEntity.setTenantId(currentUser.getTenantId());
        }
        return evaluationItemValueMapper.findList(evaluationItemValueEntity);
    }

    /**
     * 批量删除
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delEvaluationItemValueByIds(Long[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }

    /**
     * 单个删除
     */
    @Override
    public boolean delEvaluationItemValueById(Long id) {
        return this.removeById(id);
    }

    /**
     * 保存
     */
    @Override
    public boolean addEvaluationItemValue(EvaluationItemValueEntity evaluationItemValue) {
        if (this.save(evaluationItemValue)) {
            return true;
        }
        return false;
    }

    /**
     * 修改根居ID
     */
    @Override
    public boolean updateEvaluationItemValueById(EvaluationItemValueEntity evaluationItemValue) {
        if (this.updateById(evaluationItemValue)) {
            return true;
        }
        return false;
    }

    /**
     * 根居ID获取对象
     */
    @Override
    public EvaluationItemValueEntity findEvaluationItemValueById(Long id) {
        return evaluationItemValueMapper.findEvaluationItemValueById(id);
    }
    /**
     * 修改状态为删除
     */
    @Override
    public boolean updateByItemId(Long id) {
        return evaluationItemValueMapper.updateByItemId(id);
    }
}
