AnswersheetService

package com.iflytek.edu.zx.answersheet.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.swing.plaf.basic.BasicComboBoxUI.KeyHandler;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.iflytek.edu.elp.common.dto.page.PageParam;
import com.iflytek.edu.elp.common.util.JSONUtils;
import com.iflytek.edu.elp.common.util.KeyHolder;
import com.iflytek.edu.zx.answersheet.dao.AnswerSheetDao;
import com.iflytek.edu.zx.answersheet.model.AnswersheetConfig;
import com.iflytek.edu.zx.answersheet.model.AnswersheetSource;
import com.iflytek.edu.zx.answersheet.model.Desc;
import com.iflytek.edu.zx.answersheet.service.AnswersheetService;
/**
 * 答题卡服务实现。
 * 
 * @author mt
 * 
 */
@Service("answersheetService")
public class AnswersheetServiceImpl implements AnswersheetService{
	
	/**
	 * answerSheetDao
	 */
	@Resource
	private AnswerSheetDao answerSheetDao;

	@Override
	public AnswersheetConfig getAnswersheet(String uuid) {
		Assert.hasLength(uuid,"uuid must has length.");
		return answerSheetDao.find(uuid);
	}

	@Override
	public AnswersheetConfig getBaseInfo(String uuid) {
		Assert.hasLength(uuid,"uuid must has length.");
		return answerSheetDao.findBaseInfo(uuid);
	}

	@Override
	public String createAnswersheet(AnswersheetConfig answersheetConfig) {
		check4Create(answersheetConfig);
		
		answersheetConfig.setCreateTime(new Date());
		answersheetConfig.setId(KeyHolder.getKey());
		answersheetConfig.setUpdateTime(new Date());
		answersheetConfig.setIsDelete(true);//没被删除的
		answersheetConfig.setIsUsed(false);
		
		answerSheetDao.insert(answersheetConfig);
		
		return answersheetConfig.getId();
	}
	
	private void check4Create(AnswersheetConfig answersheetConfig){
		Assert.notNull(answersheetConfig, "answersheetConfig must not be null.");
		Assert.notNull(answersheetConfig.getDesc(), "answersheetConfig.getDesc must not be null.");
		Assert.hasLength(answersheetConfig.getLocationJson(), "answersheetConfig.locationJson must has length.");
		Assert.hasLength(answersheetConfig.getCreator().getId(), "answersheetConfig.creator.code must has length.");
		Assert.hasLength(answersheetConfig.getHtml(), "answersheetConfig.html must has length.");
	}

	@Override
	public void modifyAnswersheet(String uuid, String updatorId,
			String locationJson, Desc desc, String html) {
		check4Modify(uuid, updatorId, locationJson, desc, html);
		answerSheetDao.update(uuid, updatorId, locationJson, desc, html);
		
	}
	
	/**
	 * 对修改答题卡进行参数检查
	 */
	private void check4Modify(String uuid, String updatorId,String locationJson, Desc desc, String html){
		Assert.hasLength(uuid,"uuid must has length.");
		Assert.hasLength(updatorId,"updatorId must has length.");
		Assert.hasLength(locationJson,"locationJson must has length.");
		Assert.notNull(desc,"desc must not be null.");
		Assert.hasLength(html,"html must has length.");
	}

	@Override
	public void delete(String uuid) {
		Assert.hasLength(uuid,"uuid must has length.");
		answerSheetDao.delete(uuid);
		
	}

	@Override
	public int getCount(String creatorId) {
		Assert.hasLength(creatorId,"creatorId must has length.");
		return answerSheetDao.findCount(creatorId);
	}

	@Override
	public void setUsed(List<String> uuidList, boolean isUsed) {
		Assert.notEmpty(uuidList, "uuidList must not be empty.");
		answerSheetDao.updateIsUsed(uuidList,isUsed);
	}

	@Override
	public Boolean isUsed(String uuid) {
		Assert.hasLength(uuid,"uuid must has length. ");
		return answerSheetDao.findIsUsed(uuid);
	}

	@Override
	public AnswersheetConfig getAnswersheetByPaperId(String paperId) {
		Assert.hasLength(paperId,"paperId must has length.");
		return answerSheetDao.findAnswersheetByPaperId(paperId);
	}

	@Override
	public void deleteByPaperId(String paperId) {
		Assert.hasLength(paperId,"paperId must has length.");
		answerSheetDao.deleteByPaperId(paperId);
	}

	@Override
	public Desc getDesc(String uuid) {
		Assert.hasLength(uuid,"uuid must has length.");
		Desc desc = JSONUtils.parseObject(answerSheetDao.findFrontJson(uuid), Desc.class);
		return desc;
	}

	@Override
	public List<AnswersheetConfig> getAnswersheets(String creatorId,PageParam pageParam) {
		Assert.hasLength(creatorId,"creatorId has length.");
		Assert.notNull(pageParam, "pageParam must not be null.");
		return answerSheetDao.findAnswersheets(creatorId, pageParam);
	}

	@Override
	public Desc getDesc(String paperId, AnswersheetSource source) {
		Assert.hasLength(paperId,"paperId must has length.");
		Assert.notNull(source,"source must not be null.");
		Desc desc = JSONUtils.parseObject(answerSheetDao.findFrontJson(paperId,source), Desc.class);
		return desc;
	}

	@Override
	public String getLocationJson(String uuid) {
		Assert.hasLength(uuid,"uuid must has length.");
		return answerSheetDao.findLocationJson(uuid);
	}
	
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值