Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]发现了个bug #8

Open
fansq-j opened this issue Dec 30, 2020 · 6 comments
Open

[BUG]发现了个bug #8

fansq-j opened this issue Dec 30, 2020 · 6 comments

Comments

@fansq-j
Copy link

fansq-j commented Dec 30, 2020

描述错误
清楚简洁地描述错误是什么。
删除行列没有效果

重现
重现错误的步骤:
1.第一步操作
直接删除就行
4.最后看到了什么错误
代码没有报错 应该是后端代码没有写全
期望的结果
对您期望发生的结果简洁明了的描述。
删除成功
屏幕截图或演示
方便的话,贴上屏幕截图或在线链接复现问题,我们复测时会更精准

最新

备注
其他说明
我本地改了 可以交流一下

@iamxuchen800117
Copy link
Contributor

是否可以提供下,您本地代码修改的地方,我们更新下代码?谢谢

@fansq-j
Copy link
Author

fansq-j commented Jan 4, 2021

/**
 * 3.5.1 删除行或列
 *
 * @param gridKey 文件id
 * @param bson    操作内容
 * @return 操作结果
 */
private String operationDrc(String gridKey, DBObject bson) {
    //	当前sheet的index值
    String i = bson.get(ExcelEnum.I.getValue()).toString();
    //行操作还是列操作,值r代表行,c代表列
    String rc = bson.get(ExcelEnum.RC.getValue()).toString();
    //从第几行或者列开始删除
    Integer index = null;
    //删除多少行或者列
    Integer len = null;
    //需要修改的合并单元格信息
    DBObject mc = null;
    BasicDBList borderInfo = null;
    if (bson.get(ExcelEnum.V.getValue()) != null) {
        DBObject v = (DBObject) bson.get(ExcelEnum.V.getValue());
        if (v.containsField(ExcelEnum.INDEX.getValue())) {
            index = Integer.parseInt(v.get(ExcelEnum.INDEX.getValue()).toString());
        }
        if (v.containsField(ExcelEnum.LEN.getValue())) {
            len = Integer.parseInt(v.get(ExcelEnum.LEN.getValue()).toString());
        }
        if (v.containsField(ExcelEnum.MC.getValue())) {
            mc = (DBObject) v.get(ExcelEnum.MC.getValue());
        }
        if (v.containsField(ExcelEnum.BORDER_INFO.getValue())) {
            borderInfo = (BasicDBList) v.get(ExcelEnum.BORDER_INFO.getValue());
        }
    }
    if (index == null || len == null) {
        throw new InputException(InputErrorEnum.INVALID_INPUT);
    }
    //mongodb的key,用于删除
    List<String> mongodbKeys = new ArrayList<>(16);
    //查询的是数据库的一条记录  包含数据库字段 和数据库字段值 1、先获取原数据
    DBObject dbObject = gridUpdateDao.getBlockMergeByGridKey(gridKey, i, mongodbKeys);
    if (dbObject == null) {
        throw new InputException(InputErrorEnum.INVALID_INPUT);
    }
    //这个获取jsonData的值  不包含jsonData这个key
    DBObject jsonData = GridFileUtil.getObjectByIndex(dbObject, ExcelEnum.JSON_DATA.getValue());
    //获取整个表格
    //获取cellData的值
    BasicDBList cellDataList = GridFileUtil.getSheetByCallData(dbObject);
    for (int x = cellDataList.size() - 1; x >= 0; x--) {
        DBObject cell = BasicDBObject.parse(JSONObject.toJSONString(cellDataList.get(x)));
        int r = Integer.parseInt(cell.get(ExcelEnum.R_LOWE.getValue()).toString());
        int c = Integer.parseInt(cell.get(ExcelEnum.C_LOWE.getValue()).toString());
        //判断是否删除
        if (rc.equals(ExcelEnum.R_LOWE.getValue())) {
            //行操作
            if (r == index ) {
                //删除范围内
                cellDataList.remove(x);
            }
            if (r >index) {
                //删除之后需要
                cell.put(ExcelEnum.R_LOWE.getValue(), r - len);
                cellDataList.put(x,cell);
            }
        } else if (rc.equals(ExcelEnum.C_LOWE.getValue())) {
            //列操作
            if (c == index) {
                //删除范围内
                cellDataList.remove(x);
            }
            if (c >index) {
                //删除之后需要
                cell.put(ExcelEnum.C_LOWE.getValue(), c - len);
                cellDataList.put(x,cell);
            }
        }
    }
    dbObject.put(ExcelEnum.CELL_DATA_LOWER.getValue(),cellDataList);
    if(index!=null && len!=null){
        if(StringUtils.pathEquals(ExcelEnum.R_LOWE.getValue(),rc)){
            Object rowObj = jsonData.get(ExcelEnum.ROW.getValue());
            int rowInt = Integer.parseInt(rowObj.toString());
            jsonData.put(ExcelEnum.ROW.getValue(),rowInt-len);
        }
        if(StringUtils.pathEquals(ExcelEnum.C_LOWE.getValue(),rc)){
            Object columnObj = jsonData.get(ExcelEnum.COLUMN.getValue());
            int columnInt = Integer.parseInt(columnObj.toString());
            jsonData.put(ExcelEnum.ROW.getValue(),columnInt-len);
        }
    }
    // 多块
    //更新一下config中的merge信息
    DBObject d = new BasicDBObject();
    if (mc != null) {
        d.put(ExcelEnum.MERGE.getValue(), mc);
        jsonData.put(ExcelEnum.CONFIG.getValue(), d);
        //对mc进行遍历,更新jfgridfile[1].data中合并单元格(mc)的数据
        gridUpdateDao.drcArcHandleMc(mc, cellDataList);
    }
    //更新一下config中的merge信息
    if (borderInfo != null) {
        d.put(ExcelEnum.BORDER_INFO.getValue(), mc);
        jsonData.put(ExcelEnum.CONFIG.getValue(), d);
    }
    dbObject.put(ExcelEnum.JSON_DATA.getValue(), jsonData);
    //数据分组,删除原有数据,重新保存
    String rowCol = "";
    Object rowColObj = dbObject.get(ExcelEnum.ROW_COL.getValue());
    if(!ObjectUtils.isEmpty(rowColObj)){
        rowCol = rowColObj.toString();
    }
    List<DBObject> blocks = JfGridConfigModel.toDataSplit(rowCol,dbObject);
    gridUpdateDao.updateArc(gridKey, blocks, mongodbKeys);
    return ExcelEnum.SUCCESS.getValue();
}

@fansq-j
Copy link
Author

fansq-j commented Jan 4, 2021

也不知道考虑的全面不全面 我本地试了可以 大佬帮忙看看 谢谢

@iamxuchen800117
Copy link
Contributor

感谢,提供了代码,目前线上已更新!

@fansq-j
Copy link
Author

fansq-j commented Jan 4, 2021

大佬 我看你提交的代码没改啥啊 是我本地写的考虑的不全面吗 麻烦给我说一下吧

@iamxuchen800117
Copy link
Contributor

是这样的,最早提交的代码,新增与删除行(列)这块是缺失,后面已经更新了。对比了2边的代码,应该都可以正确删除,新增。你代码很棒!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants