package com.rongwei.trainingcommon.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwei.training.domain.TrainingDemandSurveyBackupsDo;
import com.rongwei.training.vo.QuestionnaireRecordingVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Entity com.rongwei.training.domain.TrainingDemandSurveyBackups
 */
public interface TrainingDemandSurveyBackupsDao extends BaseMapper<TrainingDemandSurveyBackupsDo> {

    @Select("SELECT\n" +
            "\ttdsb.* \n" +
            "FROM\n" +
            "\ttraining_demand_survey_backups tdsb \n" +
            "\tleft join training_demand_survey tds on tdsb.OLDSURVEYID = tds.ID and tds.DELETED='0'\n" +
            "\tWHERE  tdsb.DELETED='0'\n" +
            "\tAND now() <= tdsb.DEADLINE\n" +
            "\tand tds.STATE = '1'\n" +
            "\tand tdsb.PARTICIPATEUSERID like CONCAT('%',#{userId},'%')")
    List<TrainingDemandSurveyBackupsDo> getValidListData(@Param("userId") String userId);

    @Update("UPDATE training_demand_survey_backups \n" +
            "SET NOPARTICIPATINGUSERID = REPLACE ( NOPARTICIPATINGUSERID, #{userId}, '' ),\n" +
            "NOPARTICIPATINGUSERNAME = REPLACE ( NOPARTICIPATINGUSERNAME, #{userName}, '' ),\n" +
            "PARTICIPATINGUSERID = IF(ISNULL(PARTICIPATINGUSERID), #{userId} ,CONCAT(PARTICIPATINGUSERID, ',', #{userId})),\n" +
            "PARTICIPATINGUSERNAME = IF(ISNULL(PARTICIPATINGUSERNAME), #{userName} ,CONCAT(PARTICIPATINGUSERNAME, ',', #{userName} ))\n" +
            "where ID=#{surveyId}")
    void updateParticipant(@Param("userId") String userId, @Param("userName") String userName, @Param("surveyId") String surveyId);


    List<QuestionnaireRecordingVo> getQuestionnaireInformation(@Param("id") String id);
}




