package com.mortals.xhx.module.feedback.dao.ibatis;


import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.ParamDto;
import com.mortals.framework.model.Result;
import com.mortals.framework.util.StringUtils;
import com.mortals.xhx.module.feedback.model.vo.FeedbackStaffInfoVo;
import com.mortals.xhx.module.feedback.model.vo.OptionSummaryVo;
import com.mortals.xhx.module.feedback.model.vo.QuestionAnswerVo;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;
import com.mortals.xhx.module.feedback.dao.FeedbackDao;
import com.mortals.xhx.module.feedback.model.FeedbackEntity;

import java.util.ArrayList;
import java.util.Date;
import com.mortals.framework.dao.ibatis.BaseCRUDDaoMybatis;
import java.util.List;
/**
* 绩效反馈记录信息DaoImpl DAO接口
*
* @author zxfei
* @date 2023-07-05
*/
@Repository("feedbackDao")
public class FeedbackDaoImpl extends BaseCRUDDaoMybatis<FeedbackEntity,Long> implements FeedbackDao {


    @Override
    public Result<FeedbackStaffInfoVo> getFeedbackStaffList(FeedbackEntity query,PageInfo pageInfo) {
        String sqlId = "getFeedbackStaffList";

        Result result = new Result();
        List list = null;
        int count = this.getFeedbackStaffListCount(query);
        if (count == 0) {
            list = new ArrayList();
        } else if (pageInfo.getPrePageResult() == -1) {
            list = this.getSqlSession().selectList(this.getSqlId(sqlId), query);
        } else {
            if (pageInfo.getBeginIndex() > count) {
                pageInfo.setCurrPage(1);
            }

            RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
            list = this.getSqlSession().selectList(this.getSqlId(sqlId), query, rowBounds);
        }

        pageInfo.setTotalResult(count);
        result.setPageInfo(pageInfo);
        result.setList((List)list);
        return result;
    }

    @Override
    public List<OptionSummaryVo> getOptionSummaryList(Long feedbackId) {
        return this.getSqlSession().selectList(this.getSqlId("getOptionSummaryList"), feedbackId);
    }

    @Override
    public Result<QuestionAnswerVo> getQuestionAnswerList(Long questionId, PageInfo pageInfo) {
        String sqlId = "getQuestionAnswerList";

        Result result = new Result();
        List list = null;
        int count = this.getQuestionAnswerListCount(questionId);
        if (count == 0) {
            list = new ArrayList();
        } else if (pageInfo.getPrePageResult() == -1) {
            list = this.getSqlSession().selectList(this.getSqlId(sqlId), questionId);
        } else {
            if (pageInfo.getBeginIndex() > count) {
                pageInfo.setCurrPage(1);
            }

            RowBounds rowBounds = new RowBounds(pageInfo.getBeginIndex(), pageInfo.getPrePageResult());
            list = this.getSqlSession().selectList(this.getSqlId(sqlId), questionId, rowBounds);
        }

        pageInfo.setTotalResult(count);
        result.setPageInfo(pageInfo);
        result.setList((List)list);
        return result;
    }

    private int getQuestionAnswerListCount(Long questionId) {
        return (Integer)this.getSqlSession().selectOne(this.getSqlId("getQuestionAnswerListCount"), questionId);
    }

    private int getFeedbackStaffListCount(FeedbackEntity query) {
        return (Integer)this.getSqlSession().selectOne(this.getSqlId("getFeedbackStaffListCount"), query);
    }
}
