前后台两个List比较

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);
                    }
                   
                }
                
            }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值