@ -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,60 +295,7 @@ 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 ] ) ;
switch ( type ) {
initData ( evaluationCode , questionList , optionList , introduceList , ruleList , questionRecordList , questionRecordOptionList , optionDescList , optionDescDelList , parentCode , objs , sort , type ) ;
case Constant . Import . EVALUATION_QUESTION :
HtQuestion question = initQuestion ( objs , evaluationCode , sort ) ;
question . setEvaluationCode ( parentCode . getOrDefault ( question . getParentCode ( ) , question . getEvaluationCode ( ) ) ) ;
questionList . add ( question ) ;
break ;
case Constant . Import . EVALUATION_RELATION :
HtQuestion relationQuestion = initQuestion ( objs , evaluationCode , sort ) ;
relationQuestion . setEvaluationCode ( parentCode . getOrDefault ( relationQuestion . getParentCode ( ) , relationQuestion . getEvaluationCode ( ) ) ) ;
if ( CollectionUtil . isNotEmpty ( questionList ) ) {
HtQuestion prev = questionList . get ( questionList . size ( ) - 1 ) ;
if ( prev . getRelationId ( ) ! = null & & prev . getRelationId ( ) > 0 ) {
prev . setRelationId ( prev . getRelationId ( ) ) ;
} else {
prev . setRelationId ( prev . getId ( ) ) ;
}
}
questionList . add ( relationQuestion ) ;
break ;
case Constant . Import . EVALUATION_OPTION :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionOption option = initOption ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , sort , optionDescList , optionDescDelList ) ;
optionList . add ( option ) ;
break ;
case Constant . Import . EVALUATION_PARSE :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionIntroducer introduce = initIntroduce ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , sort ) ;
introduceList . add ( introduce ) ;
break ;
case Constant . Import . EVALUATION_RULE :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionScoringRule rule = initRule ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) ) ;
ruleList . add ( rule ) ;
break ;
case Constant . Import . EVALUATION_RECORD :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionRecord record = initRecord ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , questionRecordOptionList ) ;
questionRecordList . add ( record ) ;
break ;
default :
log . info ( "{}类型未知,不解析" , type ) ;
break ;
}
}
}
if ( ! questionList . isEmpty ( ) ) {
if ( ! questionList . isEmpty ( ) ) {
@ -341,6 +324,63 @@ public class ImportService implements IImportService {
}
}
}
}
/ * *
* 试题导入 : 将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 ) {
case Constant . Import . EVALUATION_QUESTION :
HtQuestion question = initQuestion ( objs , evaluationCode , sort ) ;
question . setEvaluationCode ( parentCode . getOrDefault ( question . getParentCode ( ) , question . getEvaluationCode ( ) ) ) ;
questionList . add ( question ) ;
break ;
case Constant . Import . EVALUATION_RELATION :
HtQuestion relationQuestion = initQuestion ( objs , evaluationCode , sort ) ;
relationQuestion . setEvaluationCode ( parentCode . getOrDefault ( relationQuestion . getParentCode ( ) , relationQuestion . getEvaluationCode ( ) ) ) ;
if ( CollectionUtil . isNotEmpty ( questionList ) ) {
HtQuestion prev = questionList . get ( questionList . size ( ) - 1 ) ;
if ( prev . getRelationId ( ) ! = null & & prev . getRelationId ( ) > 0 ) {
prev . setRelationId ( prev . getRelationId ( ) ) ;
} else {
prev . setRelationId ( prev . getId ( ) ) ;
}
}
questionList . add ( relationQuestion ) ;
break ;
case Constant . Import . EVALUATION_OPTION :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionOption option = initOption ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , sort , optionDescList , optionDescDelList ) ;
optionList . add ( option ) ;
break ;
case Constant . Import . EVALUATION_PARSE :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionIntroducer introduce = initIntroduce ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , sort ) ;
introduceList . add ( introduce ) ;
break ;
case Constant . Import . EVALUATION_RULE :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionScoringRule rule = initRule ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) ) ;
ruleList . add ( rule ) ;
break ;
case Constant . Import . EVALUATION_RECORD :
if ( questionList . isEmpty ( ) ) {
break ;
}
HtQuestionRecord record = initRecord ( objs , questionList . get ( questionList . size ( ) - 1 ) . getId ( ) , questionRecordOptionList , Constant . Ht . QuestionRecord . RECORD_TYPE_QUESTION , ( byte ) 3 ) ;
questionRecordList . add ( record ) ;
break ;
default :
log . info ( "{}类型未知,不解析" , type ) ;
break ;
}
}
/ * *
/ * *
* 封装record 及 option
* 封装record 及 option
* @param objs 一列
* @param objs 一列
@ -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 ;