1. /**
  2. * 通过userID 获取对应的机构
  3. * @param userId
  4. * @return
  5. */
  6. @Override
  7. public BaseResult getUserIdOrg(String userId) {
  8. UserOrgMapping userOrgMapping = new UserOrgMapping();
  9. userOrgMapping.setUserId(userId);
  10. UserOrgMapping one = userOrgMappingMapper.selectOne(userOrgMapping);
  11. String code = one.getOrgCode();
  12. ArrayList<Object> list = Lists.newArrayList();
  13. list.add(code);
  14. while (code.length()!=2){
  15. code=code.substring(0,code.length()-2);
  16. list.add(code);
  17. }
  18. log.info("切割的机构orgCode"+list);
  19. Example listMapper = new Example(OrganizationChart.class);
  20. Example.Criteria criteria = listMapper.createCriteria();
  21. criteria.andIn("orgCode",list);
  22. //什么都不写 默认以主键ID排序
  23. listMapper.orderBy("orgCode");
  24. List<OrganizationChart> chartList = organizationChartMapper.selectByExample(listMapper);
  25. if (ObjectUtil.isEmpty(chartList)){
  26. return ResultTools.resultError(ErrorCodeConst.ERROR_CODE_NO,"");
  27. }
  28. for (OrganizationChart o:
  29. chartList) {
  30. log.info(o.getOrgCode()+" "+o.getOrgName()+" "+o.getOrgType());
  31. }
  32. return ResultTools.result(chartList);
  33. }

In 里面的字段

查询到的结果 默认为会以 主键Id 排序 升序排列