美文网首页
根据id相同拼成一个对象,把每个对象里面的funcid,拼接成一

根据id相同拼成一个对象,把每个对象里面的funcid,拼接成一

作者: 码天下 | 来源:发表于2020-05-07 15:00 被阅读0次
3ef877ced5fc6d33dabee63cdcd29a0.png

1。获取数据。

List<AdminStationVO> findAdminStationList = mapper.findAdminStation(adminStationVO);
            //2对获取的数据进行从新封装
            System.out.println("findAdminStationList"+findAdminStationList);
            //遍历获取的数据findAdminStationList
            for (AdminStationVO adminStationData : findAdminStationList) {
                
                //创建一个对象接收数据
                AdminStationVO vo=new AdminStationVO();
                String id = adminStationData.getId();
                String stationname = adminStationData.getStationname();
                Integer devicetypeid = adminStationData.getDevicetypeid();
                String deptName = adminStationData.getDeptName();
                String username = adminStationData.getUsername();
                String channel = adminStationData.getChannel();
                Date createdime = adminStationData.getCreatedime();//开通时间
                Date expirationdate = adminStationData.getExpirationdate();//到期时间
                String serialnumber = adminStationData.getSerialnumber();//设备号
                String authorizekey = adminStationData.getAuthorizekey();//加密狗的key
                String address = adminStationData.getAddress();//地址
                String remarks = adminStationData.getRemarks();//开通的功能
                String adminUsername = adminStationData.getAdminUsername();//审核人员
                Integer serialamount = adminStationData.getSerialamount();
                Integer keyamount = adminStationData.getKeyamount();
                
                String function = adminStationData.getFunction();//开通功能的编号
                Integer funcid = adminStationData.getFuncid();
                Integer type = adminStationData.getType();//cloud_func表 的type字段
                vo.setId(id);
                vo.setStationname(stationname);
                vo.setDevicetypeid(devicetypeid);
                vo.setDeptName(deptName);
                vo.setUsername(username);
                vo.setChannel(channel);
                vo.setCreatedime(createdime);
                vo.setExpirationdate(expirationdate);
                vo.setSerialnumber(serialnumber);
                vo.setAuthorizekey(authorizekey);
                vo.setAddress(address);
                vo.setRemarks(remarks);
                vo.setAdminUsername(adminUsername);
                vo.setType(type);
                vo.setFunction(function);
                vo.setFuncid(funcid);
                vo.setSerialamount(serialamount);
                vo.setKeyamount(keyamount);
                //对象添加到集合
                newDataList.add(vo);
            }
                    List<AdminStationVO> arrayList = new ArrayList<AdminStationVO>();

                      //重点在这里
            HashMap<String,AdminStationVO> tempMap = new HashMap<String,AdminStationVO>();
            String invests = null;
            int quantity = 0;
            //去掉重复的key
            for (AdminStationVO newdata : newDataList) {
                String temp = newdata.getId();//user_id相同的属性
                String userName = newdata.getStationname();
                Integer devicetypeid = newdata.getDevicetypeid();
                String deptName = newdata.getDeptName();
                String username = newdata.getUsername();
                String channel = newdata.getChannel();
                Date createdime = newdata.getCreatedime();//开通时间
                Date expirationdate = newdata.getExpirationdate();//到期时间
                String serialnumber = newdata.getSerialnumber();//设备号
                String authorizekey = newdata.getAuthorizekey();//加密狗的key
                String address = newdata.getAddress();//地址
                String remarks = newdata.getRemarks();//开通的功能
                String adminUsername = newdata.getAdminUsername();//审核人员
                Integer type = newdata.getType();//cloud_func表 的type字段
                Integer serialamount = newdata.getSerialamount();
                Integer keyamount = newdata.getKeyamount();
                 //containsKey(Object key)该方法判断Map集合中是否包含指定的键名,如果包含返回true,不包含返回false
                System.out.println("temp"+temp);
                 if(tempMap.containsKey(temp)){
                 AdminStationVO newInvest = new AdminStationVO();
                 newInvest.setId(temp);
                 newInvest.setStationname(userName);
                 newInvest.setDevicetypeid(devicetypeid);
                 newInvest.setDeptName(deptName);
                 newInvest.setUsername(username);
                 newInvest.setChannel(channel);
                 newInvest.setCreatedime(createdime);
                 newInvest.setExpirationdate(expirationdate);
                 newInvest.setSerialnumber(serialnumber);
                 newInvest.setAuthorizekey(authorizekey);
                 newInvest.setAddress(address);
                 newInvest.setSerialamount(serialamount);
                 newInvest.setKeyamount(keyamount);
                 newInvest.setAdminUsername(adminUsername);
                 newInvest.setType(type);
                 //合并相同invest的  getFuncid();
                                //重点 获取上一个的属性值在这里做拼接   invests =fun + newdata.getFuncid();
                 String fun=tempMap.get(temp).getFuncid()+",";
                 //invests = tempMap.get(temp).getType() + newdata.getType();
                 invests =fun + newdata.getFuncid();
                // quantity = tempMap.get(temp).getQuantity() + investOrder.getQuantity();
                                //拼接好的值放入另一个属性
                 newInvest.setStationData(invests);
            
                 tempMap.put(temp,newInvest);
                 }else{
                     //不存在重复的存入map .第一次把获取到的目标属性字段 添加 到另一个字段中保存
                     String fun=newdata.getFuncid()+",";
                     newdata.setStationData(fun);
                     tempMap.put(temp,newdata );
                 }
                 System.out.println("tempMapwww"+tempMap);
                }

            System.out.println("tempMap11111111"+tempMap);
            //去除重复key的list
            List<AdminStationVO> newList = new ArrayList<AdminStationVO>();
            for(String temp:tempMap.keySet()){
               newList.add(tempMap.get(temp));
            }

相关文章

网友评论

      本文标题:根据id相同拼成一个对象,把每个对象里面的funcid,拼接成一

      本文链接:https://www.haomeiwen.com/subject/rfraghtx.html