// 保理补充费率协议线下审核流程集合
List<Record> protocolList = new ArrayList<>();
// 保理业务线下审核流程集合
List<Record> offlineList = new ArrayList<>();
// 发起保理补充费率协议线下审核流程
// 获取只含有保理补充费率协议的文件信息
String filesSql = " SELECT configu_date from sys_business_configure_info WHERE sys_status = 1 and configu_type_id = 'zdf_file_id' ";
List<Record> files = Db.find(filesSql);
//遍历临时表的数据
for (Record facRecDetTemp : facRecDetTempList) {
//获取临时表的文件id
String documentId = facRecDetTemp.getStr("documentId");
boolean iSOK = false;
//遍历保理补充费率协议的文件信息
for (Record file : files) {
//如果2个文件的id一致,则结束files循环,如果不一致,就一直循环,直到files循环结束
if (file.getStr("configuDate").equals(documentId)) {
iSOK = true;
break;
} else {
iSOK = false;
}
}
// 这里不管files的循环结果是啥,只添加一次。
if (iSOK) {
protocolList.add(facRecDetTemp);
} else {
offlineList.add(facRecDetTemp);
}
}
// 查询该笔付款确认书的是否存在未完成的保理补充费率协议线下审核流程
String isStatus = " SELECT " +
" COUNT(0) AS num " +
"FROM " +
" bpm_process_instance " +
"WHERE " +
" sys_status = 1 " +
"AND process_name = 'BusinessModel2.0/保理补充费率协议线下审核流程' " +
"AND STATUS = '等待中' " +
"AND biz_uuid = ? " ;
long num = Db.queryLong(isStatus,receptionUuid);
// 如果不存在未完成的保理补充费率协议线下审核流程,则发起新的流程
if (num == 0) {
List<String> facRecList = new ArrayList<>();
// 发起保理补充费率协议线下审核流程
// 获取只含有保理补充费率协议的文件信息
String sql = " SELECT configu_date from sys_business_configure_info WHERE sys_status = 1 and configu_type_id = 'zdf_file_id' ";
List<Record> files = Db.find(sql);
//遍历
for (int x = 0; x < documentId.length; x++) {
//获取临时表的文件id
String document = documentId[x];
//遍历保理补充费率协议的文件信息
for (Record file : files) {
if (file.getStr("configuDate").equals(document)) {
facRecList.add(document);
}
}
}
//集合转数组
String[] documentIdstrs = new String[facRecList.size()];
facRecList.toArray(documentIdstrs);
// 发起保理补充费率协议线下审核流程
// 上传的文件id
String[] myScanningFileId = new String[documentIdstrs.length];
// 是否入池需补文件总数
int myIfSupplyFile = 0;
// 补寄文件总数
int mySupplyFiles = documentIdstrs.length;
// 补寄资料类型
String[] mySupplyFileType = new String[documentIdstrs.length];
int p = 0;
//遍历获取筛选后的补寄文件的id
for (int m = 0; m < documentIdstrs.length; m++) {
//遍历前端获取的json数据
for (BizNeedSupplementFileInfo bns : bnsfis) {
//获取补寄文件的id
String documentIdstr = documentIdstrs[m];
//获取json数据里面的文件id
String docId = bns.getStr("documentId");
if (documentIdstr.equals(docId)) {
//设置上传的文件id
myScanningFileId[p] = bns.get("scanningFileId");
//设置补寄文件总数
//是否入池前需补
String myIfSupplyNeed = bns.get("ifSupplyNeed");
if ("1".equals(myIfSupplyNeed)) {
myIfSupplyFile = myIfSupplyFile + 1;
}
//设置补寄资料类型
mySupplyFileType[p] = bns.get("supplyFileType");
p++;
}
}
}
//发起保理补充费率协议线下审核流程
startProsess(ctl, bizId, receptionUuid, documentIdstrs, myScanningFileId, myIfSupplyFile, mySupplyFiles, mySupplyFileType);
// 查询配置表补寄文件的id
String sql= "SELECT " +
" c.configu_date " +
"FROM " +
" biz_factoring_reception a, " +
" biz_factoring_reception_detail b, " +
" sys_business_configure_info c , " +
" biz_supplementary_file_info d " +
"WHERE " +
" a.uuid = b.receive_id " +
"AND b.document_id = c.configu_date " +
"AND c.configu_type_id = 'zdf_file_id' " +
"AND d.pay_id = a.biz_id " +
"AND a.sys_status = 1 " +
"AND b.sys_status = 1 " +
"AND c.sys_status = 1 " +
"and d.sys_status = 1 " +
"AND a.uuid = ? ";
// 获取补寄文件的id
List<Record> documentIds=Db.find(sql,receptionUuid);
// 定义一个标志位,判断是否发起保理补充费率协议线下审核流程
boolean isProtocolHave = false ;
// 定义一个标志位,判断是否发起保理业务线下审核流程
boolean isOfflineHave = false ;
// 遍历获取补寄文件的id
for (int i = 0; i < documentId.length; i++) {
//当前补寄文件不为空时
if(documentIds.size()>0){
String fileId = documentId[i];
for (Record docId:documentIds){
//如果上传的补寄资料的id与配置表补寄文件的id一致,则发起保理补充费率协议线下审核流程
if (fileId.equals(docId.getStr("configuDate"))){
isProtocolHave = true ;
}else {
isOfflineHave = true ;
}
}
}else {
//为空的情况,就直接发起保理业务线下审核流程
isOfflineHave = true ;
}
}
// 如果同时含有补寄文件和非补寄文件,则同时发起保理补充费率协议线下审核流程,保理业务线下审核流程
if (isOfflineHave && isProtocolHave) {
// 保理补充费率协议线下审核流程集合
List<String> protocolList = new ArrayList<>();
// 保理业务线下审核流程集合
List<String> offlineList = new ArrayList<>();
// 发起保理补充费率协议线下审核流程
// 获取只含有保理补充费率协议的文件信息
String filesSql = " SELECT configu_date from sys_business_configure_info WHERE sys_status = 1 and configu_type_id = 'zdf_file_id' ";
List<Record> files = Db.find(filesSql);
//数组转集合
List<String> facRecDetTemp = Arrays.asList(documentId);
//遍历临时表的数据
for (String facRecDe : facRecDetTemp) {
boolean iSOK = false;
//遍历保理补充费率协议的文件信息
for (Record file : files) {
//如果2个文件的id一致,则结束files循环,如果不一致,就一直循环,直到files循环结束
if (file.getStr("configuDate").equals(facRecDe)) {
iSOK = true;
break;
} else {
iSOK = false;
}
}
// 不管files的循环结果是啥,只添加一次。
if (iSOK) {
protocolList.add(facRecDe);
} else {
offlineList.add(facRecDe);
}
}
// 重新构造:接收文件类型的key值
if (offlineList.size() > 0) {
//集合转数组
String[] documentIdstrings = new String[offlineList.size()];
offlineList.toArray(documentIdstrings);
Map<String, String> map = reconstructParameter(supplyFileType, haveYJ, haveSMJ, documentIdstrings, scanningFileId, receiveNo, sourceMap);
// 1.发起保理业务线下审核流程
this.startBpmProcessInstance(ctl.getCurrentUser(), this.getEnv()
.getFactoringBusinessAuditProcess(), this
.buildBpmSource(map), objToString(receptionUuid),
isHaveDoOfflineDoc ? "1" : "0");
}
if (protocolList.size() > 0) {
//集合转数组
String[] documentIdstrings = new String[protocolList.size()];
protocolList.toArray(documentIdstrings);
Map<String, String> map = reconstructParameter(supplyFileType, haveYJ, haveSMJ, documentIdstrings, scanningFileId, receiveNo, sourceMap);
// 2.发起保理补充费率协议线下审核流程
this.startBpmProcessInstance(ctl.getCurrentUser(), "BusinessModel2.0/保理补充费率协议线下审核流程",
this.buildBpmSource(map), objToString(receptionUuid), isHaveDoOfflineDoc ? "1" : "0");
}
} else if (isOfflineHave && !isProtocolHave) {
//如果含有非补寄文件,则发起保理业务线下审核流程
// 1.发起保理业务线下审核流程
this.startBpmProcessInstance(ctl.getCurrentUser(), this.getEnv()
.getFactoringBusinessAuditProcess(), this
.buildBpmSource(sourceMap), objToString(receptionUuid),
isHaveDoOfflineDoc ? "1" : "0");
} else if (!isOfflineHave && isProtocolHave) {
//如果含有补寄文件,则发起保理补充费率协议线下审核流程
this.startBpmProcessInstance(ctl.getCurrentUser(), "BusinessModel2.0/保理补充费率协议线下审核流程",
this.buildBpmSource(sourceMap), objToString(receptionUuid), isHaveDoOfflineDoc ? "1" : "0");
}