其他分享
首页 > 其他分享> > 批量维护关系数据

批量维护关系数据

作者:互联网

传入Id以逗号隔开,要求不在里面的删除,原来没有的新增

public void modifyApplication(String groupId, String appIds) {
        if(StringUtil.isEmpty(groupId)){
            throw new RequiredException("组Id不能为空");
        }

        Example example = new Example(GroupApp.class);
        example.createCriteria()
                .andEqualTo("groupId", groupId)
                .andEqualTo("status", 1);
        List<GroupApp> dbApps = this.groupAppMapper.selectByExample(example);

        String dbAppIds = dbApps.stream().map(GroupApp::getAppId).collect(Collectors.joining(","));
        String[] appIdList = appIds.split(",");
        List<GroupApp> deleteList = dbApps.stream().filter(p-> !appIds.contains(p.getAppId())).collect(Collectors.toList());

        deleteList.forEach(p -> {
            GroupAppVo item = new GroupAppVo();
            item.setGroupId(groupId);
            item.setAppId(p.getAppId());
            this.groupAppService.delete(item);
        });

        for (String appId : appIdList) {
            if (!dbAppIds.contains(appId)){
                GroupAppVo item = new GroupAppVo();
                item.setGroupId(groupId);
                item.setAppId(appId);
                this.groupAppService.create(item);
            }
        }
    }

 

标签:appIds,String,批量,关系数据,item,new,维护,groupId,GroupAppVo
来源: https://www.cnblogs.com/season2009/p/12936757.html