1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| package cn.liweidan.springboot.swagger2.endpoint;
import cn.liweidan.springboot.swagger2.dbo.UserDo; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController;
import java.util.*; import java.util.stream.Collectors;
@RestController @RequestMapping("user") public class UserEndpoint {
Map<Long, List<Long>> orgRelationUser = new HashMap<>(); List<UserDo> userDoList = new ArrayList<>();
public UserEndpoint() {
userDoList.add(new UserDo(1L, "weidan", 6000L, 18)); userDoList.add(new UserDo(2L, "xiaodan", 10000L, 36)); userDoList.add(new UserDo(3L, "dadan", 9000L, 28)); userDoList.add(new UserDo(4L, "Sally", 12000L, 24)); userDoList.add(new UserDo(5L, "weisuodan", 20000L, 20));
List<Long> userIds1 = new ArrayList<>(3); userIds1.add(1L); userIds1.add(3L); userIds1.add(4L); orgRelationUser.put(10L, userIds1);
List<Long> userIds2 = new ArrayList<>(2); userIds2.add(2L); userIds2.add(5L); orgRelationUser.put(7L, userIds2); }
@ApiOperation(value = "用户资源请求入口", notes = "可以根据公司的id查询到隶属于该公司的员工") @ApiImplicitParams({ // 参数集合,指定传递的参数的类型,是否必须,作用,数据类型等等 @ApiImplicitParam(name = "orgId", value = "需要查询的公司的ID", required = true, paramType = "query", dataType = "String") }) @GetMapping(params = "orgId") public List<UserDo> selectByOrg(@RequestParam("orgId") Long orgId) { List<Long> userIds = orgRelationUser.get(orgId); if (Objects.isNull(userIds) userIds.isEmpty()) { return new ArrayList<>(0); } return userDoList.stream().filter(userDo -> userIds.contains(userDo.getId())).collect(Collectors.toList()); }
}
|