Read excl field and insert into database

Elevator insurance

public class FileImportVSImpl implements FileImportVS {
public String savePolicyInfoImport(FileImportResultVO vo) {
String RsStr = "";
ExcelService excelService = new ExcelServiceImpl();
ImportResult importResult = null;
String operator = BusinessContextUtils.getUserContext().getOperatorId(); // Operator
String operator_time =DBControl.DateFormat4Str(CommonJdbcDaoUtils.getSystemDate(),"yyyyMMddHHmmss"); //Operation time
String branch_code = DBControl.getBranchcode(); //Get the user's organization code
if(vo.getFiledataFileName(). endsWith(".xls")||vo.getFiledataFileName().endsWith(".XLS")) {
try {
importResult = excelService.read(new FileInputStream(vo.getFiledata()), 1);
if(importResult.getResultList().size()>0){
String batch_no = DBControl.getSeqVal("seq_logging_infos");
for (int i=1;i<importResult.getResultList().size();i++) {
// StringBuffer sql = new StringBuffer(" insert into tb_temp_policy_info t ( t.id,t.batch_number,t.branch_code,t.serial_number,t.policy_holder,t.made_by," );旧模板sql先留住
//        sql.append(" t.serviced_by,t.managed_by,t.elevator_owner,t.building_nature,t.elevator_classes")
//        .append(" ,t.security_marksno,t.registration_code,t.install_address,t.contract_no,t.device_id,t.register_department,")
//        .append(" t.inspected_by,t.next_inspection,t.emergency_phone,t.production_date,t.load_limit_no,t.elevator_type,t.effective_date,t.expiry_date)")
//        .append(" values ( FUNC_GET_SEQ_VAL('seq_temp_policy_info') , '").append(batch_no).append("','").append(branch_code);
StringBuffer sql = new StringBuffer(" insert into tb_temp_policy_info t ( t.id,t.batch_number,t.branch_code,t.serial_number,t.policy_holder,t.made_by," );
    sql.append(" t.serviced_by,t.managed_by,t.elevator_owner,t.building_nature,t.elevator_classes")
       .append(" ,t.security_marksno,t.registration_code,t.install_address,t.contract_no,t.device_id,t.register_department,")
       .append(" t.inspected_by,t.next_inspection,t.emergency_phone,t.production_date,t.load_limit_no,t.role,t.branch_code_tb,t.address,t.post,t.tel,t.effective_date,t.expiry_date,t.rate,t.mail)")
       .append(" values ( FUNC_GET_SEQ_VAL('seq_temp_policy_info') , '").append(batch_no).append("','").append(branch_code);
int colsum = importResult.getResultList().get(i).size();
if(colsum!=28){
throw new BusinessException("第"+i+"行数据的列数为"+colsum+"不符合要求,请重新上传");
}
for(int j=0;j<28;j++){
       sql.append("','").append(importResult.getResultList().get(i).get(j));
      
}
sql.append("')");
CommonJdbcDaoUtils.update(sql.toString());
}
String sql_log = "insert into tb_logging_infos (id,file_name,Start_date,end_date,operator,branch_code,batch_sum) values (?,?,to_date(?,'yyyyMMddhh24miss'),sysdate,?,?,"+(importResult.getResultList().size()-1)+")";
CommonJdbcDaoUtils.update(sql_log, batch_no,vo.getFiledataFileName(),operator_time,operator,branch_code);
RsStr = batch_no ;
}
} catch (FileNotFoundException e) {
RsStr = "";
throw new BusinessException("Failed to upload file:" + e .getStackTrace().toString());
} catch (Exception e) {
e.printStackTrace();
throw new BusinessException("Failed to upload file: Please check if the template data meets the requirements!");
}
} else {  
RsStr = " ";
throw new BusinessException("The uploaded file must be in excel 2003 or later format!");
}
return RsStr;
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326873154&siteId=291194637