boolean flag = false;
List<DepositContractInfo> l = depositContractInfoDao.find((new StringBuilder("from ")).append("DepositContractInfo").append(" c where c.conractType = '0' and c.").append("loanApplyId").append("=? ").toString(), loanApply.getId()); //后台查询的List
for(int i=0;i<l.size();i++){
DepositContractInfo depositContractInfo = l.get(i);
for(int j=0;j<depositContractInfoEReceiveModel.getDepositContractInfoList().size();j++){
DepositContractInfoEViewModel viewModel = depositContractInfoEReceiveModel.getDepositContractInfoList().get(j);
if(viewModel.getId()==null || !depositContractInfo.getId().equals(viewModel.getId())){
continue;
}
flag = true;
break;
}
if(!flag){
depositContractInfoDao.delete(depositContractInfo);
}
}
for(DepositContractInfoEViewModel p:depositContractInfoEReceiveModel.getDepositContractInfoList()){
long userId = CurrentSession.getCurrentUser().getId();
Date createDate = DateUtil.getCurrentTime();
DepositContractInfo depositContractInfo = null;
if(null==p.getId()){
depositContractInfo = new DepositContractInfo();
BeanMapper.copy(p, depositContractInfo);
depositContractInfo.setCreateDate(createDate);
depositContractInfo.setCreateUser(userId);
depositContractInfo.setLoanApplyId(loanApply.getId());
}else{
depositContractInfo = depositContractInfoDao.findUniqueBy("id", p.getId());
Date crDate = depositContractInfo.getCreateDate();
long crId = depositContractInfo.getCreateUser();
BeanMapper.copy(p, depositContractInfo);
depositContractInfo.setCreateDate(crDate);
depositContractInfo.setCreateUser(crId);
depositContractInfo.setModifyDate(createDate);
depositContractInfo.setModifyUser(userId);
depositContractInfo.setLoanApplyId(loanApply.getId());
}
depositContractInfoDao.saveOrUpdate(depositContractInfo);
Attachment attachmentQuery = new Attachment();
if(null!=depositContractInfo.getId()){
attachmentQuery.setBusinessId(depositContractInfo.getId().toString());
attachmentQuery.setObjectType(26);
List<Attachment> listDb = fileService.getFileDao().getPageAttachment(Integer.MAX_VALUE, Integer.MAX_VALUE, attachmentQuery).getDatas();
//一个业务ID只可能有一个附件
if(CollectionUtils.isNotEmpty(listDb)){
Attachment a = listDb.get(0);
//判断附件是否有变化 没有变化则不变 有变化则先删除再新增
if(!a.getFileId().equals(p.getFileId())){
fileService.delAttachment(a.getId());
Attachment att = new Attachment();
att.setBusinessId(depositContractInfo.getId().toString());
att.setObjectType(p.getObjectType());
att.setFileType(p.getFileType());
att.setFileId(p.getFileId());
att.setFileName(p.getFileName());
att.setCreateDate(new Date());
att.setCreateUser(CurrentSession.getCurrentUser().getId().toString());
fileService.getFileDao().save(att);
}
}else{
Attachment att = new Attachment();
att.setBusinessId(depositContractInfo.getId().toString());
att.setObjectType(p.getObjectType());
att.setFileType(p.getFileType());
att.setFileId(p.getFileId());
att.setFileName(p.getFileName());
att.setCreateDate(new Date());
att.setCreateUser(CurrentSession.getCurrentUser().getId().toString());
fileService.getFileDao().save(att);
}
}
}
List<DepositContractInfo> l = depositContractInfoDao.find((new StringBuilder("from ")).append("DepositContractInfo").append(" c where c.conractType = '0' and c.").append("loanApplyId").append("=? ").toString(), loanApply.getId()); //后台查询的List
for(int i=0;i<l.size();i++){
DepositContractInfo depositContractInfo = l.get(i);
for(int j=0;j<depositContractInfoEReceiveModel.getDepositContractInfoList().size();j++){
DepositContractInfoEViewModel viewModel = depositContractInfoEReceiveModel.getDepositContractInfoList().get(j);
if(viewModel.getId()==null || !depositContractInfo.getId().equals(viewModel.getId())){
continue;
}
flag = true;
break;
}
if(!flag){
depositContractInfoDao.delete(depositContractInfo);
}
}
for(DepositContractInfoEViewModel p:depositContractInfoEReceiveModel.getDepositContractInfoList()){
long userId = CurrentSession.getCurrentUser().getId();
Date createDate = DateUtil.getCurrentTime();
DepositContractInfo depositContractInfo = null;
if(null==p.getId()){
depositContractInfo = new DepositContractInfo();
BeanMapper.copy(p, depositContractInfo);
depositContractInfo.setCreateDate(createDate);
depositContractInfo.setCreateUser(userId);
depositContractInfo.setLoanApplyId(loanApply.getId());
}else{
depositContractInfo = depositContractInfoDao.findUniqueBy("id", p.getId());
Date crDate = depositContractInfo.getCreateDate();
long crId = depositContractInfo.getCreateUser();
BeanMapper.copy(p, depositContractInfo);
depositContractInfo.setCreateDate(crDate);
depositContractInfo.setCreateUser(crId);
depositContractInfo.setModifyDate(createDate);
depositContractInfo.setModifyUser(userId);
depositContractInfo.setLoanApplyId(loanApply.getId());
}
depositContractInfoDao.saveOrUpdate(depositContractInfo);
Attachment attachmentQuery = new Attachment();
if(null!=depositContractInfo.getId()){
attachmentQuery.setBusinessId(depositContractInfo.getId().toString());
attachmentQuery.setObjectType(26);
List<Attachment> listDb = fileService.getFileDao().getPageAttachment(Integer.MAX_VALUE, Integer.MAX_VALUE, attachmentQuery).getDatas();
//一个业务ID只可能有一个附件
if(CollectionUtils.isNotEmpty(listDb)){
Attachment a = listDb.get(0);
//判断附件是否有变化 没有变化则不变 有变化则先删除再新增
if(!a.getFileId().equals(p.getFileId())){
fileService.delAttachment(a.getId());
Attachment att = new Attachment();
att.setBusinessId(depositContractInfo.getId().toString());
att.setObjectType(p.getObjectType());
att.setFileType(p.getFileType());
att.setFileId(p.getFileId());
att.setFileName(p.getFileName());
att.setCreateDate(new Date());
att.setCreateUser(CurrentSession.getCurrentUser().getId().toString());
fileService.getFileDao().save(att);
}
}else{
Attachment att = new Attachment();
att.setBusinessId(depositContractInfo.getId().toString());
att.setObjectType(p.getObjectType());
att.setFileType(p.getFileType());
att.setFileId(p.getFileId());
att.setFileName(p.getFileName());
att.setCreateDate(new Date());
att.setCreateUser(CurrentSession.getCurrentUser().getId().toString());
fileService.getFileDao().save(att);
}
}
}