UserScoreSignDaoImpl 代码记录

package com.iflytek.edu.zx.archive.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.iflytek.edu.elp.common.dao.base.AbstractBaseDao;
import com.iflytek.edu.elp.common.dto.page.PageParam;
import com.iflytek.edu.zx.archive.dao.UserScoreSignDao;
import com.iflytek.edu.zx.archive.model.UserScoreSign;

/**
 * @author yywang5
 */
@Repository("userScoreSignDao")
public class UserScoreSignDaoImpl extends AbstractBaseDao implements UserScoreSignDao {

	@Override
	public void insert(UserScoreSign userScoreSign) {
		Assert.notNull(userScoreSign, "userScoreSign is required!");
		String sql = "insert into archive_userscoresign (id,topicSetId,userId,userName,classId,signUserName,phoneNum,createTime,parentTitle)";
		sql += "values(:id,:topicSetId,:userId,:userName,:classId,:signUserName,:phoneNum,:createTime,:parentTitle)";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("id", userScoreSign.getId());
		params.put("topicSetId", userScoreSign.getTopicSetId());
		params.put("userId", userScoreSign.getUserId());
		params.put("userName", userScoreSign.getUserName());
		params.put("classId", userScoreSign.getClassId());
		params.put("signUserName", userScoreSign.getSignUserName());
		params.put("phoneNum", userScoreSign.getPhoneNum());
		params.put("createTime", userScoreSign.getCreateTime());
		params.put("parentTitle", userScoreSign.getParentTitle());
		namedParameterJdbcTemplate.update(sql, params);
	}

	@Override
	public UserScoreSign find(String topicSetId, String userId) {
		Assert.notNull(topicSetId, "topicSetId is required!");
		Assert.notNull(userId, "userId is required!");
		String sql = "select * from archive_userscoresign where topicSetId=:topicSetId and userId=:userId limit 1";
		Map<String, String> params = new HashMap<String, String>();
		params.put("topicSetId", topicSetId);
		params.put("userId", userId);
		List<UserScoreSign> ussList = namedParameterJdbcTemplate.query(sql, params, new UserScoreSignMapper());
		if (CollectionUtils.isNotEmpty(ussList)) {
			return ussList.get(0);
		}
		return null;
	}

	@Override
	public List<UserScoreSign> findByClassId(String topicSetId, String classId) {
		Assert.notNull(topicSetId, "topicSetId is required!");
		Assert.notNull(classId, "classId is required!");
		String sql = "select * from archive_userscoresign where topicSetId=:topicSetId and classId=:classId ";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("topicSetId", topicSetId);
		params.put("classId", classId);
		return namedParameterJdbcTemplate.query(sql, params, new UserScoreSignMapper());
	}
	
	@Override
	public List<UserScoreSign> findByClassId(Set<String> classIds, PageParam pageParams) {
		Assert.notNull(classIds, "classIds is required!");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("classIds", classIds);
		String orderBy = StringUtils.isEmpty(pageParams.getOrderBy())? "createTime":pageParams.getOrderBy();
		String orderDirection = pageParams.getOrderDirection() == null? "desc":pageParams.getOrderDirection().name();
		String sql = "select * from archive_userscoresign where classId in (:classIds) order by " +orderBy+ " "+orderDirection+" limit :startIndex, :pageSize";
		return namedParameterJdbcTemplate.query(sql, params, new UserScoreSignMapper());
	}

	@Override
	public List<UserScoreSign> findByUserIds(Set<String> userIds, PageParam pageParams) {
		Assert.notEmpty(userIds,"userIds is required!");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userIds", userIds);
		String orderBy = StringUtils.isEmpty(pageParams.getOrderBy())? "createTime":pageParams.getOrderBy();
		String orderDirection = pageParams.getOrderDirection() == null? "desc":pageParams.getOrderDirection().name();
		params.put("startIndex", pageParams.getStartIndex());
		params.put("pageSize", pageParams.getPageSize());
		String sql = "select * from archive_userscoresign where userId in (:userIds) order by " +orderBy+ " "+orderDirection+" limit :startIndex, :pageSize";
		return namedParameterJdbcTemplate.query(sql, params, new UserScoreSignMapper());
	}

	private class UserScoreSignMapper implements RowMapper<UserScoreSign> {
		@Override
		public UserScoreSign mapRow(ResultSet rs, int rowNum) throws SQLException {
			UserScoreSign userScoreSign = new UserScoreSign();
			userScoreSign.setId(rs.getString("id"));
			userScoreSign.setClassId(rs.getString("classId"));
			userScoreSign.setTopicSetId(rs.getString("topicSetId"));
			userScoreSign.setPhoneNum(rs.getString("phoneNum"));
			userScoreSign.setSignUserName(rs.getString("signUserName"));
			userScoreSign.setUserId(rs.getString("userId"));
			userScoreSign.setUserName(rs.getString("userName"));
			userScoreSign.setCreateTime(rs.getTimestamp("createTime"));
			userScoreSign.setParentTitle(rs.getString("parentTitle"));
			return userScoreSign;
		}
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值