AnswerService.java.svn-base 3.1 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
package jp.agentec.sinaburocast.service;

import java.util.List;

import jp.agentec.sinaburocast.common.SinaburoConstant;
import jp.agentec.sinaburocast.entity.Answer;

import org.seasar.extension.jdbc.where.SimpleWhere;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.framework.container.annotation.tiger.InstanceType;


@Component(instance=InstanceType.SINGLETON)
public class AnswerService extends AbstractService<Answer> {

	public static final String ID_SEQ_NAME = "answer_id_seq";

	/**
	 * IDを発行して、登録する。
	 */
	public int insertAnswer(Answer answer, String insId) {
		answer.answerId = getSeqNextVal(Integer.class, ID_SEQ_NAME);
		return super.insert(answer, insId);
	}


    public Answer findById(Integer answerId) {
        return select().id(answerId).getSingleResult();
    }

    public List<Answer> findAllOrderById() {
        return select().orderBy("answerId asc").getResultList();
    }


    public List<Answer> findAllByEnqueteId(String eid) {
        return select().where(new SimpleWhere().eq("enqueteId",eid)).getResultList();
    }

    public List<Answer> findAllByQuestionId(Integer questionId) {
        return select().where(new SimpleWhere().eq("questionId",questionId)).getResultList();
    }

    /**
     * アンケート検索画面で削除ボタンを押した場合。論理削除
     * @param eid アンケートID
     * @return
     */
    public int deleteByEnqueteId(String eid,String adminLoginId){

    	List<Answer> answerList = findAllByEnqueteId(eid);

    	for(Answer answer :answerList){
    		answer.delFlg = (short)Integer.parseInt(SinaburoConstant.DelFlg.DEL);
    		update(answer,adminLoginId);
    	}

    	return 0;

    }
    /**
     * 設問IDの回答一覧を取得する。
     * @param eid
     * @param questionId
     * @return
     */
    public List<Answer> findAllByEnqueteIdAndQuestionId(String eid,Integer questionId ) {
        return select().where(new SimpleWhere().eq("enqueteId",eid).eq("questionId", questionId)).orderBy("answerNo").getResultList();
    }

    /**
     * 設問IDの回答一覧を取得する。
     * @param answerId リスト
     * @return
     */
    public List<Answer> findAllByAnswerId(String [] answerId) {
    	return select().where(new SimpleWhere().in("answerId",answerId)).orderBy("answerNo").getResultList();
    }

    /**
     * 設問一覧で削除した場合
     * @param eid
     * @param adminLoginId
     * @return
     */
    public int deleteByQuestionId(Integer questionId,String adminLoginId){

    	List<Answer> answerList = findAllByQuestionId(questionId);

    	for(Answer answer :answerList){
    		answer.delFlg = (short)Integer.parseInt(SinaburoConstant.DelFlg.DEL);
    		update(answer,adminLoginId);
    	}

    	return 0;
    }

    /**
     * 設問編集で更新した場合
     * @param eid
     * @param adminLoginId
     * @return
     */
    public int recodeDeleteByQuestionId(Integer questionId,String adminLoginId){

    	List<Answer> answerList = findAllByQuestionId(questionId);

    	for(Answer answer :answerList){
    		this.delete(answer);
    	}
    	return 0;
    }



}