最近遇到了对这种数据的处理,接口传入参数为
{
"userName":"zhangsan",
"concernedservices":[a1,a2,a3],
"unconcernedservices":[b1,b2,b3],
}
对用户进行权限管理,不同权限的用户可以选择不同的服务,根据接口传入用户名称和关注服务列表以及取消关注服务列表,针对用户对服务进行关注和取消关注,需要转换成以下格式:
[{"username":"zhangsan","conceredservice":"a1"}
{"username":"zhangsan","conceredservice":"a2"}
{"username":"zhangsan","conceredservice":"a3"}
{"username":"zhangsan","unconceredservice":"b1"}
{"username":"zhangsan","unconceredservice":"b2"}
{"username":"zhangsan","unconceredservice":"b3"}]
for循环遍历,将服务关注和取消关注取出和username组成新的map放入list中,再对list进行遍历,依次操作
for (Integer s:serviceList) {
Map<String , Object> paraMap = new HashMap<>();
paraMap.put("service", s);
paraMap.put("userName", userName);
System.out.println("paraMap=====>"+paraMap);
paraList.add(paraMap);
}
for (Integer s:unconcernList) {
Map<String , Object> paraMap1 = new HashMap<>();
paraMap1.put("unconcerns", s);
paraMap1.put("userName", userName);
System.out.println("paraMap1=====>"+paraMap1);
paraList2.add(paraMap1);
}
for (int i = 0; i < paraList.size(); i++) {
int b = skyFunctionMapper.getUnConcerned(paraList.get(i));
System.out.println("b======>"+b);
if (b>0) {
a = skyFunctionMapper.updatetoConcern(paraList.get(i));
} else {
a = skyFunctionMapper.serviceConcern(paraList.get(i));
}
}
for (int i = 0; i < paraList2.size(); i++) {
a1 = skyFunctionMapper.serviceUnConcern(paraList2.get(i));
}