apzl_leasing/src_tenwa/com/tenwa/apzl/comm/MailingContainerNumberImport.java
2020-04-17 11:02:36 +08:00

75 lines
2.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.tenwa.apzl.comm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.amarsoft.are.jbo.BizObject;
import com.amarsoft.are.jbo.JBOTransaction;
import com.amarsoft.awe.util.SqlObject;
import com.amarsoft.awe.util.Transaction;
import com.amarsoft.context.ASUser;
import com.amarsoft.dict.als.cache.CacheLoaderFactory;
import com.tenwa.comm.exception.BusinessException;
import com.tenwa.comm.util.jboutil.DataOperatorUtil;
import com.tenwa.officetempalte.importcallback.impl.BaseImportExcelCallBack;
public class MailingContainerNumberImport extends BaseImportExcelCallBack{
@Override
public void run(ASUser CurUser, BizObject importObject,Map<String, String> model, Integer rowIndex, JBOTransaction tx,Transaction Sqlca) throws Exception {
}
@Override
public void runBefore(ASUser CurUser, Map<String, String> model, List<BizObject> importObjects, JBOTransaction tx,Transaction Sqlca) throws Exception {
Transaction Sqlca1 = Transaction.createTransaction(CacheLoaderFactory.getDataSource());
/**
* 定义全局变量
*/
String error=""; // 错误描述
boolean flag=false; // 错误描述
String ARCHIVING_CABINET_NO=null; // 导入的邮寄柜号
String CONTRACT_NUMBER=null;
String sql1=""; // 原有的数据
/**
* 校验本次导入数据在导入表是否已有
*/
List<Map<String, String>> list = new ArrayList<Map<String,String>>();
Map<String, String> map = new HashMap<String, String>();
List<String> arrayList = new ArrayList<String>();
List<String> exclarrayList = new ArrayList<String>();
for(BizObject bo:importObjects){
ARCHIVING_CABINET_NO=bo.getAttribute("ARCHIVING_CABINET_NO").getString();
arrayList.add(ARCHIVING_CABINET_NO);
// 通过本次excel中的数据查询导入的表, 判断是否重复
sql1="SELECT ARCHIVING_CABINET_NO,CONTRACT_NUMBER FROM LB_FILE_ARCHIVING_INFO WHERE ARCHIVING_CABINET_NO='"+ARCHIVING_CABINET_NO+"'";
List<Map<String, String>> dataList = DataOperatorUtil.getDataBySql(Sqlca, sql1, null);
// 有结果集, 说明重复
if(dataList.size()>0){
if(! exclarrayList.contains(ARCHIVING_CABINET_NO) ){
exclarrayList.add(ARCHIVING_CABINET_NO);
}
flag=true;
}
}
if(flag) {
throw new BusinessException("excl中的邮寄柜号:"+String.join(", ", exclarrayList)+"已存在 ");
}
long count = arrayList.stream().distinct().count();
boolean isRepeat = count < arrayList.size();
if(isRepeat){
Set<String> set = new HashSet<>();
Set<String> exist = new HashSet<>();
for (String s : arrayList) {
if (set.contains(s)) {
exist.add(s);
} else {
set.add(s);
}
}
throw new BusinessException("excl中的邮寄柜号:"+String.join(", ", exist)+"重复。");
}
}
}