| | |
| | | for (Long id : idList |
| | | ) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", id); |
| | | map.put("id", ""+id); |
| | | map.put("name", collect.get(id).getOrgName()); |
| | | map.put("level", collect.get(id).getOrgLevel()); |
| | | List<Long> childs = sysOrganizations.stream().filter(e -> e.getOrgParentId() == id).map(e -> e.getId()).collect(Collectors.toList()); |
| | |
| | | @Override |
| | | @Transactional |
| | | public boolean saveOrUpdateSer(SysOrganization sysOrganization) { |
| | | //获取code |
| | | |
| | | if (sysOrganization.getId() == null) { |
| | | //保存 |
| | | String code = this.getCode(sysOrganization); |
| | | sysOrganization.setOrgCode(code); |
| | | baseMapper.insert(sysOrganization); |
| | | } else { |
| | | //更新 |
| | | SysOrganization sysOrg = baseMapper.selectById(sysOrganization.getId()); |
| | | if(sysOrg.getOrgParentId()!=sysOrganization.getOrgParentId()){ |
| | | String code = this.getCode(sysOrganization); |
| | | sysOrganization.setOrgCode(code); |
| | | } |
| | | int i = baseMapper.updateById(sysOrganization); |
| | | } |
| | | redisUtils.hdel(RedisConstant.ORGANIZATION, sysOrganization.getId().toString()); |
| | | redisUtils.hset(RedisConstant.ORGANIZATION, sysOrganization.getId().toString(), sysOrganization); |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取自己组织的code |
| | | * @param sysOrganization |
| | | * @return |
| | | */ |
| | | public String getCode(SysOrganization sysOrganization){ |
| | | //获取父级 |
| | | Long orgParentId = sysOrganization.getOrgParentId(); |
| | | if (orgParentId == null) { |
| | | return null; |
| | | } |
| | | SysOrganization sysOrg = baseMapper.selectById(orgParentId); |
| | | if(sysOrg!=null){ |
| | | String orgCode = sysOrg.getOrgCode(); |
| | | //查询 |
| | | QueryWrapper queryWrapper=new QueryWrapper(); |
| | | queryWrapper.eq("org_parent_id",sysOrg.getId()); |
| | | queryWrapper.orderByAsc("id"); |
| | | List<SysOrganization> list = baseMapper.selectList(queryWrapper); |
| | | if (list.size()>0) { |
| | | SysOrganization sysOrganizationLast = list.get(list.size() - 1); |
| | | String orgCodeLast = sysOrganizationLast.getOrgCode(); |
| | | String orgCodeLastQianZhui=orgCodeLast.substring(0,orgCodeLast.length() - 4); |
| | | Integer codenum = Integer.valueOf(orgCodeLast.substring(orgCodeLast.length() - 4)); |
| | | String str="0000"; |
| | | str+=(codenum+1); |
| | | String substring = str.substring(str.length() - 4); |
| | | return orgCodeLastQianZhui+substring; |
| | | }else { |
| | | String fucode = sysOrg.getOrgCode(); |
| | | String str="0001"; |
| | | return fucode+str; |
| | | } |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | } |