| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | } |
| | | QueryWrapper<ManageRoleMenu> wrapper = new QueryWrapper(); |
| | | wrapper.eq("role_id",id); |
| | | System.out.println(manageRoleMenuMapper.selectCount(wrapper)); |
| | | if (manageRoleMenuMapper.selectCount(wrapper)==0){ |
| | | |
| | | wrapper.eq("is_delete",0); |
| | | List<Map> result = manageRoleMenuMapper.getDataByMenuIds(list,id); |
| | | List<Map> result1 = manageRoleMenuMapper.getDataByRoleId(id); |
| | | if (manageRoleMenuMapper.selectCount(wrapper)==0 || result.size()==0){ |
| | | List<Map> insertList = new ArrayList<>(); |
| | | for (Object temp:list) { |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("role_id",id); |
| | | map.put("menu_id",Integer.parseInt(temp.toString())); |
| | | insertList.add(map); |
| | | } |
| | | manageRoleMenuMapper.insertBatch(insertList); |
| | | } |
| | | return null; |
| | | List updateList = new ArrayList(); |
| | | for (Map manageRoleMenu:result1) { |
| | | int have = 1; |
| | | for (Object temp:list){ |
| | | if (manageRoleMenu.get("menu_id").equals(Integer.parseInt(temp.toString()))){ |
| | | have = 2; |
| | | continue; |
| | | } |
| | | } |
| | | if (have == 2){ |
| | | continue; |
| | | } |
| | | updateList.add(manageRoleMenu.get("menu_id")); |
| | | } |
| | | List insertList = new ArrayList(); |
| | | for (Object temp:list) { |
| | | int have = 1; |
| | | for (Map manageRoleMenu:result1){ |
| | | if (manageRoleMenu.get("menu_id").equals(Integer.parseInt(temp.toString()))){ |
| | | have = 2; |
| | | continue; |
| | | } |
| | | } |
| | | if (have == 2){ |
| | | continue; |
| | | } |
| | | insertList.add(temp); |
| | | } |
| | | if (updateList.size()>0){ |
| | | manageRoleMenuMapper.updateDeleteStateByRoleIdMenuIds(updateList,id); |
| | | } |
| | | if (insertList.size()>0){ |
| | | List mapList = new ArrayList(); |
| | | for (Object temp:insertList) { |
| | | Map<String,Integer> insertMap = new HashMap<>(); |
| | | insertMap.put("role_id",id); |
| | | insertMap.put("menu_id",Integer.parseInt(temp.toString())); |
| | | mapList.add(insertMap); |
| | | } |
| | | manageRoleMenuMapper.insertBatch(mapList); |
| | | } |
| | | resultMap.put("code",ResponseCodeEnum.SUCCESS.getCode()); |
| | | resultMap.put("msg",ResponseCodeEnum.SUCCESS.getMsg()); |
| | | return resultMap; |
| | | } |
| | | } |