一个html页面保存的时候有2种数据分别存到2个DB里的解决办法

实体类1:

public class TbAssess extends BaseEntity {
     // 考核ID
    private String assessId;

     // 年份
    private String year;

     // 绩效系数
    private BigDecimal performanceCoefficient;

     // 考核负责人
    private String assessHead;

     // 考核成员
    private String assessTeam;
    
     // 考核类型(备用字段1改名)
    private String assessType;
}

实体类2:

public class TbAssessIndex extends BaseEntity {
     // 考核指标ID
    private String assessIndexId;

     // 考核ID
    private String assessId;

     // 考核内容
    private String assessContent;

     // 负责人
    private String leader;

     // 得分
    private BigDecimal score;
}

实体类3:(只是为了综合实体类1和2,方便后面的保存)

public class TbAssessForm extends TbAssess {
    
     // 考核小组负责人名称
    private String assessHeadName;

     // 登录者名称
    private String registerName;
    
     // 考核分数
    private BigDecimal scoreSum;
    
     // list集合
    private List<TbAssessIndex> detailList;
    
    //考核类型
    private String assessTypeName;
}

后台保存方法:

/**
     * 保存
     * 
     * @param  tbAssessForm 考核信息
     * @return ResultBean
     * @throws SQLException 
     */
    public ResultBean save(TbAssessForm tbAssessForm) throws SQLException {
        ResultBean bean = new ResultBean();
        boolean flag = false;
        String assessId = "";
        if (!StringUtil.isBlank(tbAssessForm.getAssessId())) {
            flag = true;
            assessId = tbAssessForm.getAssessId();
            TbAssess tbAssess = new TbAssess();
            tbAssess.setAssessId(assessId);
            tbAssess = super.searchOneData(tbAssess, ImsSqlmapConstants.TB_TBASSESS_SELECTBYPRIMARYKEY);
            if(tbAssess == null){
                tbAssess = new TbAssess();
            }
            tbAssess.setYear(tbAssessForm.getYear());
            tbAssess.setPerformanceCoefficient(tbAssessForm.getPerformanceCoefficient());
            tbAssess.setAssessHead(tbAssessForm.getAssessHead());
            tbAssess.setAssessTeam(tbAssessForm.getAssessTeam());
            tbAssess.setAssessType(tbAssessForm.getAssessType());
            super.update(tbAssess,ImsSqlmapConstants.TB_ASSESS_UPDATE);
            
        }
        if (!flag) {
            assessId = super.getSeqNo(SeqNoConstants.TBASSESS_ID, 8);
            TbAssess tbAssess = new TbAssess();
            // 考核ID
            tbAssess.setAssessId(assessId);
            // 年份
            tbAssess.setYear(tbAssessForm.getYear());
            //考核类型
            tbAssess.setAssessType(tbAssessForm.getAssessType());
            // 绩效系数
            tbAssess.setPerformanceCoefficient(tbAssessForm.getPerformanceCoefficient());
            // 考核负责人
            tbAssess.setAssessHead(tbAssessForm.getAssessHead());
            // 考核成员
            tbAssess.setAssessTeam(tbAssessForm.getAssessTeam());
            super.insert(tbAssess, ImsSqlmapConstants.TB_TBASSESS_INSERT);
        }
        List<TbAssessIndex> tbAssessIndexList = tbAssessForm.getDetailList();
        List<TbAssessIndex> tbAssessIndexBatchInsertList = new ArrayList<TbAssessIndex>();
        List<TbAssessIndex> tbAssessIndexBatchUpdateList = new ArrayList<TbAssessIndex>();
        if (tbAssessIndexList != null) {
            for (TbAssessIndex tbAssessIndex : tbAssessIndexList) {
                if (StringUtil.isBlank(tbAssessIndex.getAssessIndexId())) {
                    // 考核指标ID
                    tbAssessIndex.setAssessIndexId(super.getSeqNo(SeqNoConstants.TBASSESSINDEX_ID, 8));
                    // 考核ID
                    tbAssessIndex.setAssessId(assessId);
                    // 考核内容
                    // 负责人
                    // 得分
                    // 新增插入
                    tbAssessIndex.setCreatedForInsert(super.getLoginUserName());
                    tbAssessIndexBatchInsertList.add(tbAssessIndex);
                } else {
                    // 清空更新者信息,自动补充为当前更新者信息
                    tbAssessIndex.setUpdateUser(null);

                    tbAssessIndex.setLastModifiedForUpdate(super.getLoginUserName());
                    // 更新
                    tbAssessIndexBatchUpdateList.add(tbAssessIndex);
                }
                
            }
        }
        if (CollectionUtils.isNotEmpty(tbAssessIndexBatchInsertList)) {
            super.commonDao.batchUpdate(tbAssessIndexBatchInsertList, ImsSqlmapConstants.TB_ASSESSINDEX_BATCHINSERT);
        }
        if (CollectionUtils.isNotEmpty(tbAssessIndexBatchUpdateList)) {
            super.commonDao.batchUpdate(tbAssessIndexBatchUpdateList, ImsSqlmapConstants.TB_ASSESSINDEX_BATCHUPDATE);
        }
        // 返回考核ID
        bean.setData(assessId);
        return bean;
    }

 

posted @ 2018-08-30 14:59  等你,在雨中  阅读(439)  评论(0编辑  收藏  举报