springboot中多个不同对象的属性进行比较,将不同的值用使用数组查询出,并保存在意向表中

版权声明:ApassionBoy https://blog.csdn.net/weixin_43150581/article/details/82586158

多表维护


    @MethodParameter(desc="orgTenantTypeQueryAll",input="user",postType={},postName="",queryString="",httpMethod="get",userParam="user")
    @Override
    public List<DsspOrgTenantType> orgTenantTypeQueryAll(User user) throws Exception {
        //租户类型
        //List<DsspTenantType> list3=this.getBeanDaoHelper().queryAll(DsspTenantType.class, "queryList", true, null, user);
        //关系表
        //List<DsspOrgTenantType> tenantTypes=this.getBeanDaoHelper().queryAll(DsspOrgTenantType.class, "queryWhereOrgId", true, null, user);
        //所有租户
        List<DsspOrgTenantType> list=this.getBeanDaoHelper().queryAll(DsspOrgTenantType.class, "queryAllOrgType", true, null, user);
        //租户配置表
        List<TenantConfig> list2=this.getBeanDaoHelper().queryAll(TenantConfig.class, "tenantConfigquery", true, null, user);

        if (list != null && list.size() > 0) {    //判断list所有租户是否为空
            String[] arry = new String[list.size()];  //定义数组,将租户人数赋值给数组(所有租户值)
            for (int i = 0; i < list.size(); i++) {   
                arry[i] = list.get(i).getOrgId();     //将list值赋值给数组
            }
            if (list2 != null && list2.size() > 0) {   //判断配置表list2是否为空(配置表的值)
                String[] arry2 = new String[list2.size()];   //同上将定义数组......
                for (int i = 0; i < list2.size(); i++) {
                    arry2[i] = list2.get(i).getOrgId();      //同将list2理赋值给数组
                }
                List<String> listt2 = Arrays.asList(arry2);   //将数组或对象转换成List集合
                List<String> listt1 = new ArrayList<String>();   //新定义一个String类型集合
                for (String st : arry) {    //循环出所有租户数组arry中的值
                    if (!listt2.contains(st)) {    //将配置表数组arry2中的值拿出与arry比较,取出不同的值
                        listt1.add(st);    //将不同的值赋值给上面新建的String类型List集合
                    }
                }
                listt1.removeAll(Collections.singleton(null));   //去除数组中的null元素
                String[] tenantId=new String[listt1.size()];     //定义数组将得到的集合中不同值存入
                for (int i = 0; i < listt1.size(); i++) {      
                    tenantId[i]=listt1.get(i);        //向数组中存入值
                }
                for(int i=0;i<tenantId.length;i++){   //得到最后一次更新的值
                    listt2=Arrays.asList(tenantId[i]);
                }
                for(String li:listt2){
                    String orgId=li; //得到值
                    List<DsspOrgTenantType>    tenantTypess=this.getBeanDaoHelper().queryWhere(DsspOrgTenantType.class,"org_id=?", new Object[] { orgId }, null);  //查询方法得到tenantTypess对象
                    String tenantTypeId=null;  //定义参数租户类型ID
                    for (int i=0;i<tenantTypess.size();i++) {
                        tenantTypeId=tenantTypess.get(i).getTenantTypeId();//将查询到的值赋值给tenantTypeId

                        List<DsTenantConfigTemplate>   configTemplates=this.getBeanDaoHelper().queryWhere(DsTenantConfigTemplate.class,"select * from ds_tenant_config_template where template_id=?", new Object[]{tenantTypeId},null);   //通过tenantTypeId查询到模板表中的数据,添加到配置表中
                        if(configTemplates!=null && configTemplates.size()>0){
                            for(int j=0;j<configTemplates.size();j++){
                                System.out.println(configTemplates.get(j).getTemplateId());
                                    Map<String,String> map=new HashMap<String, String>();  //使用map的key,value传入参数
                                    map.put("id",configTemplates.get(j).getId());
                                    map.put("key",configTemplates.get(j).getKey());
                                    map.put("value",configTemplates.get(j).getValue());
                                    map.put("org_id",configTemplates.get(j).getTemplateId());
                                    map.put("status",configTemplates.get(j).getStatus());
                                    map.put("dictionary_type",configTemplates.get(j).getDictionaryType());
                                    map.put("dictionary_url",configTemplates.get(j).getDictionaryUrl());
                                    this.getBeanDaoHelper().saveOriginalByMap(map, "ds_tenant_config", null);
                                    System.out.println("维护 成功");
                            }
                        }else{
                            System.out.println("没有");
                        }

                    }
                }
            }
        }
        return list;
    }

如有疑问,请在下方留言,我会及时回答,谢谢

猜你喜欢

转载自blog.csdn.net/weixin_43150581/article/details/82586158