package com.goafanti.evaluation.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.goafanti.common.dao.ValueEvaluationMapper;
import com.goafanti.common.model.ValueEvaluation;
import com.goafanti.core.mybatis.BaseMybatisDao;
import com.goafanti.core.mybatis.JDBCIdGenerator;
import com.goafanti.core.mybatis.page.Pagination;
import com.goafanti.core.shiro.token.TokenManager;

@Service
@Transactional
public class ValueEvaluationService extends BaseMybatisDao<ValueEvaluationMapper> {
	@Autowired
	ValueEvaluationMapper	valueEvaluationMapper;

	@Autowired
	JDBCIdGenerator			idGenerator;

	public int insert(ValueEvaluation ve) {
		ve.setId(idGenerator.generateId());
		return valueEvaluationMapper.insertSelective(ve);
	}

	public int update(ValueEvaluation ve) {
		return valueEvaluationMapper.updateByPrimaryKeySelective(ve);
	}

	public ValueEvaluation getMyEvaluation(Long id) {
		Map<String, Object> params = new HashMap<>();
		params.put("uid", TokenManager.getUserId());
		params.put("id", id);
		return valueEvaluationMapper.selectByPrimaryKeyAndUser(params);
	}

	public int deleteMySteps(List<Long> ids) {
		Map<String, Object> params = new HashMap<>();
		params.put("uid", TokenManager.getUserId());
		params.put("ids", ids);
		return valueEvaluationMapper.deleteRecords(params);
	}

	@SuppressWarnings("unchecked")
	public Pagination<ValueEvaluation> list(Integer pageNo, Integer pageSize) {
		Map<String, Object> params = new HashMap<>();
		params.put("uid", TokenManager.getUserId());
		return (Pagination<ValueEvaluation>) findPage("findUserListByPage", "findUserListCount", params, pageNo,
				pageSize);
	}
}
