@ -9,9 +9,11 @@ import com.alibaba.fastjson.JSONObject;
import com.ccsens.ht.bean.po.* ;
import com.ccsens.ht.bean.po.* ;
import com.ccsens.ht.persist.dao.* ;
import com.ccsens.ht.persist.dao.* ;
import com.ccsens.ht.uitl.Constant ;
import com.ccsens.ht.uitl.Constant ;
import com.ccsens.util.CodeEnum ;
import com.ccsens.util.PoiUtil ;
import com.ccsens.util.PoiUtil ;
import com.ccsens.util.PropUtil ;
import com.ccsens.util.PropUtil ;
import com.ccsens.util.StringUtil ;
import com.ccsens.util.StringUtil ;
import com.ccsens.util.exception.BaseException ;
import lombok.extern.slf4j.Slf4j ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -237,6 +239,40 @@ public class ImportService implements IImportService {
}
}
}
}
@Override
public void importReportRecord ( File excelFile , int sheetIndex ) throws Exception {
List < Object [ ] > reports = PoiUtil . readExce ( excelFile , sheetIndex , null , 1 , false ) ;
log . info ( "导入报告单其他记录,读取数据完成" ) ;
List < HtReport > htReports = htReportDao . selectByExample ( new HtReportExample ( ) ) ;
Map < String , Long > reportMap = new HashMap < > ( ) ;
htReports . forEach ( htReport - > reportMap . put ( htReport . getCode ( ) , htReport . getId ( ) ) ) ;
log . info ( "报告单类型查询完成" ) ;
List < HtQuestionRecord > reportRecordList = new ArrayList < > ( ) ;
List < HtQuestionRecordOption > optionList = new ArrayList < > ( ) ;
for ( Object [ ] objs : reports ) {
if ( ! pageData ( objs ) ) {
log . info ( "测评报告单数据不足,跳转下一行" ) ;
continue ;
}
Long id = reportMap . get ( String . valueOf ( objs [ 0 ] ) ) ;
if ( id = = null ) {
log . info ( "报告单类型不存在:{}" , objs [ 0 ] ) ;
throw new BaseException ( CodeEnum . PARAM_ERROR ) ;
}
HtQuestionRecord record = initRecord ( objs , id , optionList , Constant . Ht . QuestionRecord . RECORD_TYPE_CODE , 1 ) ;
reportRecordList . add ( record ) ;
}
if ( ! reportRecordList . isEmpty ( ) ) {
htQuestionRecordDao . insertBatch ( reportRecordList ) ;
}
if ( ! optionList . isEmpty ( ) ) {
htQuestionRecordOptionDao . insertBatch ( optionList ) ;
}
}
/ * *
/ * *
* 保存试题
* 保存试题
* * /
* * /
@ -259,6 +295,39 @@ public class ImportService implements IImportService {
int sort = objs . length > 3 & & StringUtil . checkNum ( String . valueOf ( objs [ 3 ] ) , false ) ? Integer . parseInt ( String . valueOf ( objs [ 3 ] ) ) : 1 ;
int sort = objs . length > 3 & & StringUtil . checkNum ( String . valueOf ( objs [ 3 ] ) , false ) ? Integer . parseInt ( String . valueOf ( objs [ 3 ] ) ) : 1 ;
String type = String . valueOf ( objs [ 0 ] ) ;
String type = String . valueOf ( objs [ 0 ] ) ;
initData ( evaluationCode , questionList , optionList , introduceList , ruleList , questionRecordList , questionRecordOptionList , optionDescList , optionDescDelList , parentCode , objs , sort , type ) ;
}
if ( ! questionList . isEmpty ( ) ) {
htQuestionDao . insertBatch ( questionList ) ;
}
if ( ! optionList . isEmpty ( ) ) {
htQuestionOptionDao . insertBatch ( optionList ) ;
}
if ( ! introduceList . isEmpty ( ) ) {
htQuestionIntroducerDao . insertBatch ( introduceList ) ;
}
if ( ! ruleList . isEmpty ( ) ) {
htQuestionScoringRuleDao . insertBatch ( ruleList ) ;
}
if ( ! questionRecordList . isEmpty ( ) ) {
htQuestionRecordDao . insertBatch ( questionRecordList ) ;
}
if ( ! questionRecordOptionList . isEmpty ( ) ) {
htQuestionRecordOptionDao . insertBatch ( questionRecordOptionList ) ;
}
if ( ! optionDescDelList . isEmpty ( ) ) {
htQuestionOptionDescDao . delete ( optionDescDelList ) ;
}
if ( ! optionDescList . isEmpty ( ) ) {
htQuestionOptionDescDao . insertBatch ( optionDescList ) ;
}
}
/ * *
* 试题导入 : 将obj [ ] 转换成 对应的data
* /
private void initData ( String evaluationCode , List < HtQuestion > questionList , List < HtQuestionOption > optionList , List < HtQuestionIntroducer > introduceList , List < HtQuestionScoringRule > ruleList , List < HtQuestionRecord > questionRecordList , List < HtQuestionRecordOption > questionRecordOptionList , List < HtQuestionOptionDesc > optionDescList , List < Long > optionDescDelList , Map < String , String > parentCode , Object [ ] objs , int sort , String type ) {
switch ( type ) {
switch ( type ) {
case Constant . Import . EVALUATION_QUESTION :
case Constant . Import . EVALUATION_QUESTION :
HtQuestion question = initQuestion ( objs , evaluationCode , sort ) ;
HtQuestion question = initQuestion ( objs , evaluationCode , sort ) ;
@ -303,42 +372,13 @@ public class ImportService implements IImportService {
if ( questionList . isEmpty ( ) ) {
if ( questionList . isEmpty ( ) ) {
break ;
break ;
}
}
HtQuestionRecord record = initRecord ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , questionRecordOptionList ) ;
HtQuestionRecord record = initRecord ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , questionRecordOptionList , Constant . Ht . QuestionRecord . RECORD_TYPE_QUESTION , ( byte ) 3 ) ;
questionRecordList . add ( record ) ;
questionRecordList . add ( record ) ;
break ;
break ;
default :
default :
log . info ( "{}类型未知,不解析" , type ) ;
log . info ( "{}类型未知,不解析" , type ) ;
break ;
break ;
}
}
}
if ( ! questionList . isEmpty ( ) ) {
htQuestionDao . insertBatch ( questionList ) ;
}
if ( ! optionList . isEmpty ( ) ) {
htQuestionOptionDao . insertBatch ( optionList ) ;
}
if ( ! introduceList . isEmpty ( ) ) {
htQuestionIntroducerDao . insertBatch ( introduceList ) ;
}
if ( ! ruleList . isEmpty ( ) ) {
htQuestionScoringRuleDao . insertBatch ( ruleList ) ;
}
if ( ! questionRecordList . isEmpty ( ) ) {
htQuestionRecordDao . insertBatch ( questionRecordList ) ;
}
if ( ! questionRecordOptionList . isEmpty ( ) ) {
htQuestionRecordOptionDao . insertBatch ( questionRecordOptionList ) ;
}
if ( ! optionDescDelList . isEmpty ( ) ) {
htQuestionOptionDescDao . delete ( optionDescDelList ) ;
}
if ( ! optionDescList . isEmpty ( ) ) {
htQuestionOptionDescDao . insertBatch ( optionDescList ) ;
}
}
}
/ * *
/ * *
@ -348,16 +388,16 @@ public class ImportService implements IImportService {
* @param questionRecordOptions record选项
* @param questionRecordOptions record选项
* @return record
* @return record
* /
* /
private HtQuestionRecord initRecord ( Object [ ] objs , Long id , List < HtQuestionRecordOption > questionRecordOptions ) {
private HtQuestionRecord initRecord ( Object [ ] objs , Long id , List < HtQuestionRecordOption > questionRecordOptions , byte recordType , int sortIndex ) {
HtQuestionRecord record = new HtQuestionRecord ( ) ;
HtQuestionRecord record = new HtQuestionRecord ( ) ;
String content = ( String ) objs [ 2 ] ;
String content = ( String ) objs [ 2 ] ;
JSONObject json = JSONObject . parseObject ( content ) ;
JSONObject json = JSONObject . parseObject ( content ) ;
BeanUtils . copyProperties ( json , record ) ;
BeanUtils . copyProperties ( json , record ) ;
record . setRecordType ( Constant . Ht . QuestionRecord . RECORD_TYPE_QUESTION ) ;
record . setRecordType ( recordType ) ;
// 判断是否存在,设置id
// 判断是否存在,设置id
int sortIndex = 3 ;
int sort = StringUtil . checkNum ( String . valueOf ( objs [ sortIndex ] ) , false ) ?
int sort = StringUtil . checkNum ( String . valueOf ( objs [ sortIndex ] ) , false ) ?
Integer . parseInt ( String . valueOf ( objs [ sortIndex ] ) ) : Constant . Ht . Question . RULE_TYPE_DEFAULT ;
Integer . parseInt ( String . valueOf ( objs [ sortIndex ] ) ) : Constant . Ht . Question . RULE_TYPE_DEFAULT ;
record . setSort ( sort ) ;
HtQuestionRecordExample recordExample = new HtQuestionRecordExample ( ) ;
HtQuestionRecordExample recordExample = new HtQuestionRecordExample ( ) ;
recordExample . createCriteria ( ) . andQuestionIdEqualTo ( id ) . andSortEqualTo ( sort ) ;
recordExample . createCriteria ( ) . andQuestionIdEqualTo ( id ) . andSortEqualTo ( sort ) ;
List < HtQuestionRecord > questionRecords = htQuestionRecordDao . selectByExample ( recordExample ) ;
List < HtQuestionRecord > questionRecords = htQuestionRecordDao . selectByExample ( recordExample ) ;
@ -368,6 +408,7 @@ public class ImportService implements IImportService {
record . setId ( questionRecords . get ( 0 ) . getId ( ) ) ;
record . setId ( questionRecords . get ( 0 ) . getId ( ) ) ;
}
}
log . info ( "添加record:{}" , record ) ;
log . info ( "添加record:{}" , record ) ;
if ( ! json . containsKey ( Constant . Import . RELATION_OPTION ) ) {
if ( ! json . containsKey ( Constant . Import . RELATION_OPTION ) ) {
return record ;
return record ;