添加档案信息excl导入方法
This commit is contained in:
parent
723b766892
commit
b5cb57c002
@ -46,7 +46,7 @@
|
||||
doTemp.appendJboWhere(" O.flow_name='마운<EBA788>헝(폼났)' and O.PHASENAME='땐데놓<EB8DB0>'");
|
||||
};
|
||||
String button = "true";
|
||||
if(!"administrator".equals(userId)){
|
||||
if("administrator".equals(userId)){
|
||||
button="false";
|
||||
ros = "false";
|
||||
}
|
||||
|
||||
@ -42,6 +42,8 @@
|
||||
sourceMap.put("sFilePath", sFilePath);
|
||||
sourceMap.put("sFileSize", fileSize);
|
||||
cindex=fs.batchImportExcelByConfig( CurUser,myAmarsoftUpload.getFiles().getFile(0).getFileName(), myAmarsoftUpload.getFiles().getFile(0).toInputStream(), sourceMap.get("templateNo"), sourceMap);
|
||||
}else if (importparam.indexOf("archivesCU")>0){//档案信息导入,自动导入合同id和归档人
|
||||
cindex=fs.archivesImportExcelByConfig( CurUser,myAmarsoftUpload.getFiles().getFile(0).getFileName(), myAmarsoftUpload.getFiles().getFile(0).toInputStream(), sourceMap.get("templateNo"), sourceMap);
|
||||
}else{
|
||||
cindex=fs.importExcelByConfig( CurUser,myAmarsoftUpload.getFiles().getFile(0).getFileName(), myAmarsoftUpload.getFiles().getFile(0).toInputStream(), sourceMap.get("templateNo"), sourceMap);
|
||||
}
|
||||
|
||||
@ -64,17 +64,13 @@
|
||||
//增加其他配置参数
|
||||
importCondition["inputuserid"]="<%=CurUser.getUserID()%>";
|
||||
importCondition["inputorgid"]="<%=CurUser.getOrgID()%>";
|
||||
importCondition["type"]="archivesCU";
|
||||
var sparam=JSON.stringify(importCondition).replace(/,/g,"@");//生成模板的参数据
|
||||
AsDialog.PopView("/Tenwa/Core/OfficeTemplate/TemplateManager/BFTemplateTest/uploadExcel.jsp","importparam="+sparam,
|
||||
{width:"350px",height:"40px",title:"上传文件下载数据"},function(){
|
||||
updateContractId();
|
||||
reloadSelf();
|
||||
});
|
||||
}
|
||||
//更新对应的contractid
|
||||
function updateContractId(){
|
||||
RunJavaMethodSqlca("com.tenwa.lease.function.ImportContractId","updateContractId","");
|
||||
reloadSelf();
|
||||
}
|
||||
//模板下载
|
||||
function DiscountDownload(){
|
||||
var sId="091cbd1a827243ae821e75fcddc5319b";
|
||||
|
||||
@ -20,4 +20,7 @@ public abstract class ImportCallBack {
|
||||
public abstract void runAfter(ASUser CurUser,Map<String,String>model,List<BizObject> importObjects,JBOTransaction tx,Transaction Sqlca) throws Exception;
|
||||
public abstract void importExcel(BizObject importConfig,List<BizObject> columnConfigs,List<String> exceptionMessage,
|
||||
ASUser CurUser,Map<String,String> model,List<BizObject>importObjects,Sheet sheet,JBOTransaction tx,Transaction Sqlca)throws Exception;
|
||||
public abstract void archivesImportExcel(BizObject importConfig,List<BizObject> columnConfigs,List<String> exceptionMessage,
|
||||
ASUser CurUser,Map<String,String> model,List<BizObject>importObjects,Sheet sheet,JBOTransaction tx,Transaction Sqlca)throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@ -33,6 +33,7 @@ import com.tenwa.officetempalte.util.PoiExcelUtil;
|
||||
import com.tenwa.reckon.util.UUIDUtil;
|
||||
|
||||
import jbo.app.tenwa.calc.LC_CARD_DEDUCT_DOC;
|
||||
import jbo.com.tenwa.lease.comm.LB_CONTRACT_INFO;
|
||||
/**
|
||||
* 默认excel导入处理类
|
||||
* */
|
||||
@ -528,4 +529,128 @@ public class BaseImportExcelCallBack extends ImportCallBack{
|
||||
}
|
||||
}}
|
||||
|
||||
//档案归档信息
|
||||
public void archivesImportExcel(BizObject importConfig,List<BizObject> columnConfigs,List<String> exceptionMessage,
|
||||
ASUser CurUser,Map<String,String> model,List<BizObject>importObjects,Sheet sheet,JBOTransaction tx,Transaction Sqlca) throws Exception {
|
||||
|
||||
BizObjectManager lciManage=JBOFactory.getBizObjectManager(LB_CONTRACT_INFO.CLASS_NAME,Sqlca);
|
||||
|
||||
String importClass=FileOperatorUtil.nullToString(importConfig.getAttribute("relativeclass").getValue(),"");//导入对应的类
|
||||
if(importClass.length()<2){
|
||||
throw new BusinessException("导入没有"+importConfig.getAttribute("sheetname").getString()+"配置对应该的表或类");
|
||||
}
|
||||
String sHeaderIndex=FileOperatorUtil.nullToString(importConfig.getAttribute("rowline").getValue(),"1");//标题行
|
||||
String sDataIndex=FileOperatorUtil.nullToString(importConfig.getAttribute("dateindex").getValue(),"2");//数据行
|
||||
String[] headerIndexs = sHeaderIndex.split(",");
|
||||
int DataRowindex=Integer.parseInt(sDataIndex);
|
||||
List<Row> headerRows = new ArrayList<Row>();
|
||||
// 获取标题行
|
||||
for (int i = 0; i < headerIndexs.length; i++) {
|
||||
headerRows.add(sheet.getRow(Integer.parseInt(headerIndexs[i]) - 1));
|
||||
}
|
||||
int rowCount = sheet.getPhysicalNumberOfRows();
|
||||
BizObjectManager importManager = JBOFactory.getBizObjectManager(importClass);
|
||||
tx.join(importManager);
|
||||
String value="";
|
||||
|
||||
Map<String,BizObject>columnMap=new HashMap<String,BizObject>();
|
||||
columnMap=ExcelImportUtil.getImportColumnMap(columnConfigs);
|
||||
|
||||
for (int rowIndex =( DataRowindex-1); rowIndex < rowCount; rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
//判断这一行是不是都为空字符
|
||||
boolean isemptyrow=false;
|
||||
if(null==row){continue;}//如果这个这一行为空则调过这一行
|
||||
int cellnumbers=row.getPhysicalNumberOfCells();
|
||||
if(cellnumbers<=0){continue;}//如果这一行的单元格数据为O则进调过这一行
|
||||
Iterator<Cell> tempIt = row.cellIterator();
|
||||
if(tempIt.hasNext()){
|
||||
Cell cellt = (Cell) tempIt.next();
|
||||
value = PoiExcelUtil.getCellValue(cellt);
|
||||
if(value.length()==0){continue;}
|
||||
if(value.indexOf("合计")>=0){continue;}//如果这一行为合计则跳过这一行。
|
||||
}
|
||||
for (Iterator<Cell> cit = row.cellIterator(); cit.hasNext();) {
|
||||
Cell cell = (Cell) cit.next();
|
||||
value = PoiExcelUtil.getCellValue(cell);
|
||||
value = value.trim();
|
||||
if(value.length()>0){isemptyrow=true;}
|
||||
}
|
||||
if(isemptyrow==false){continue;}//如果这一行都为空则跳过这一行。
|
||||
|
||||
BizObject importObject=importManager.newObject();
|
||||
for (int i=0;i<headerRows.get(0).getLastCellNum();i++) {
|
||||
|
||||
Cell cell =row.getCell(i);
|
||||
value = PoiExcelUtil.getCellValue(cell);
|
||||
value = value.trim();
|
||||
int colIndex = i;
|
||||
String headername=ExcelImportUtil.getImportHanderName(headerRows, colIndex);
|
||||
if(columnMap.containsKey(headername)){
|
||||
BizObject columnConfig=columnMap.get(headername);
|
||||
String dataType=columnConfig.getAttribute("datatype").getString();//数据类型
|
||||
String isImport=columnConfig.getAttribute("isimport").getString();//是否必填
|
||||
String dateSource=columnConfig.getAttribute("datesource").getString();//数据的来源
|
||||
String sourceSql=columnConfig.getAttribute("souresql").getString();//数据的来源
|
||||
|
||||
if(value!=null&&value.length()>0){
|
||||
if(dataType.equals("data_type5")){value=value.replaceAll(",", "");}
|
||||
if(dateSource.equals("data_source3")||dateSource.equals("data_source4")){
|
||||
if(null==sourceSql||sourceSql.length()<10){
|
||||
exceptionMessage.add("导入配置中"+headername+"是通过操作取得没有配置对应该的SQL或java类");
|
||||
}else{
|
||||
|
||||
String temp=value;
|
||||
value=this.getExcelImportMapValue(CurUser,columnConfig, value, model,tx,Sqlca);
|
||||
if(value==null||value.length()==0){
|
||||
exceptionMessage.add("导入第"+(rowIndex+1)+"行中第"+(colIndex+1)+"列中的"+temp+"是在数据库中没有对应该的列");
|
||||
}
|
||||
}
|
||||
}
|
||||
importObject.setAttributeValue(columnConfig.getAttribute("importcolumn").getString(), value);
|
||||
if("合同编号".equals(headername)){
|
||||
BizObject lci = lciManage.createQuery(" contract_no=:contract_no ").setParameter("contract_no", value).getSingleResult(false);
|
||||
importObject.setAttributeValue("contract_id", lci==null?"":lci.getAttribute("id").toString());
|
||||
|
||||
}
|
||||
}else if(isImport.equals("yes")){
|
||||
exceptionMessage.add("导入第"+(rowIndex+1)+"行中第"+(colIndex+1)+"列中没有数据!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//设计归档人
|
||||
importObject.setAttributeValue("ARCHIVING_PERSON", CurUser.getUserName());
|
||||
//每列数据从据从前台取数并判断是否必填,和数据类型
|
||||
exceptionMessage.addAll(ExcelImportUtil.setImportOjbectDataFromPageAndCheck(columnMap,importObject,model,rowIndex+1));
|
||||
try{
|
||||
//每导入一行的回调类用来远行自定义的方法
|
||||
this.run(CurUser, importObject, model, rowIndex, tx, Sqlca);
|
||||
}catch(BusinessException e){
|
||||
exceptionMessage.add(e.getMessage());
|
||||
}
|
||||
importObjects.add(importObject);
|
||||
}
|
||||
if(exceptionMessage.size()>0){
|
||||
throw new BusinessException(exceptionMessage.toString());
|
||||
}else{
|
||||
if(importObjects.size()>0){
|
||||
//导入之后的回调
|
||||
this.runBefore(CurUser, model,importObjects, tx, Sqlca);
|
||||
//删除源数据
|
||||
deleteSourceDeleteBeforeDelete(importConfig,model,Sqlca);
|
||||
//导入正式的数据
|
||||
String isSave=importConfig.getAttribute("isSave").getString();
|
||||
if(isSave.equals("0")){
|
||||
}else{
|
||||
for(int cindex=0;cindex<importObjects.size();cindex++){
|
||||
importManager.saveObject(importObjects.get(cindex));
|
||||
}
|
||||
}
|
||||
//导入之后的回调
|
||||
this.runAfter(CurUser, model,importObjects, tx, Sqlca);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -175,6 +175,67 @@ public class FileTemplateService {
|
||||
return importObjects.size();
|
||||
}
|
||||
|
||||
//档案信息导入
|
||||
public int archivesImportExcelByConfig(ASUser CurUser,String fileName,InputStream sourceFile,String templateno,Map<String,String> model) throws Exception{
|
||||
if(templateno==null){
|
||||
throw new BusinessException("请传入模板号");
|
||||
}
|
||||
Map<String,String>searchCondtion=new HashMap<String,String>();
|
||||
searchCondtion.put("id", templateno);
|
||||
//模板配置
|
||||
BizObject template=DataOperatorUtil.getSingleJBO(BF_TEMPLATE.CLASS_NAME, searchCondtion, tx);
|
||||
if(template==null){
|
||||
throw new BusinessException("模板号"+templateno+"在系统中未找到配置");
|
||||
}
|
||||
searchCondtion.clear();
|
||||
searchCondtion.put("templateId", template.getAttribute("id").getString());
|
||||
List<BizObject> importConfigs=DataOperatorUtil.getSetJBO(BF_IMPORTCONFIG.CLASS_NAME, searchCondtion, tx);
|
||||
List<String>exceptionMessage=new ArrayList<String>();
|
||||
List<BizObject>importObjects=new ArrayList<BizObject>();
|
||||
if(null==importConfigs||importConfigs.size()==0){
|
||||
throw new BusinessException("导入没有配置");
|
||||
}else{
|
||||
for(BizObject importConfig : importConfigs){
|
||||
searchCondtion.clear();
|
||||
searchCondtion.put("importconfig", importConfig.getAttribute("id").getString());
|
||||
List<BizObject>columnConfigs=DataOperatorUtil.getSetJBO(BF_IMPORTCOLUMN.CLASS_NAME, searchCondtion, tx);
|
||||
if(null==columnConfigs||columnConfigs.size()==0){
|
||||
throw new BusinessException("导入没有"+importConfig.getAttribute("sheetname").getString()+"配置下面列数据");
|
||||
}else{
|
||||
String sheetName=FileOperatorUtil.nullToString(importConfig.getAttribute("sheetname").getValue(),"");
|
||||
Workbook wb = null;
|
||||
if (fileName.endsWith("xlsx")) {
|
||||
wb = PoiExcelUtil.readWorkbook(sourceFile, ExcelVersionEnum.VERSION2007);
|
||||
} else {
|
||||
wb = PoiExcelUtil.readWorkbook(sourceFile, ExcelVersionEnum.VERSION2003);
|
||||
}
|
||||
Sheet sheet =null;
|
||||
if(sheetName.equals("")){sheet = wb.getSheetAt(0);}
|
||||
else{sheet=wb.getSheet(sheetName);}
|
||||
|
||||
Class<ImportCallBack> call=null;
|
||||
Method callImport=null;
|
||||
String importclass=importConfig.getAttribute("importclass").getString();
|
||||
try{
|
||||
if(importclass.length()>0){
|
||||
call=(Class<ImportCallBack>) Class.forName(importclass);
|
||||
}else{
|
||||
call=(Class<ImportCallBack>) Class.forName("com.tenwa.officetempalte.importcallback.impl.BaseImportExcelCallBack");
|
||||
}
|
||||
}catch(Exception e){
|
||||
throw new BusinessException("模板"+template.getAttribute("templatename").getString()+",表:"+importConfig.getAttribute("importtable").getString()+"导入处理类没找到");
|
||||
}
|
||||
ImportCallBack cb=call.newInstance();
|
||||
cb.archivesImportExcel(importConfig, columnConfigs, exceptionMessage, CurUser, model, importObjects, sheet, tx, Sqlca);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return importObjects.size();
|
||||
}
|
||||
|
||||
public void closeTransaction() throws Exception{
|
||||
if(Sqlca!=null){
|
||||
Sqlca.commit();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user