Commit c312a77b827d132f25d87000935941c5bbf4e106
Merge branch 'localhost-cxy' into 'master'
fix: 组织修改实现 See merge request huang/thingsboard3.3.2!21
Showing
2 changed files
with
18 additions
and
2 deletions
1 | 1 | package org.thingsboard.server.dao.yunteng.entities; |
2 | 2 | |
3 | +import com.baomidou.mybatisplus.annotation.FieldStrategy; | |
4 | +import com.baomidou.mybatisplus.annotation.TableField; | |
3 | 5 | import com.baomidou.mybatisplus.annotation.TableName; |
4 | 6 | import lombok.Data; |
5 | 7 | import lombok.EqualsAndHashCode; |
... | ... | @@ -9,6 +11,8 @@ import org.thingsboard.server.common.data.yunteng.constant.ModelConstants; |
9 | 11 | @EqualsAndHashCode(callSuper = true) |
10 | 12 | @TableName(ModelConstants.Table.IOTFS_ORGANIZATION_TABLE_NAME) |
11 | 13 | public class Organization extends TenantBaseEntity { |
14 | + | |
15 | + @TableField(updateStrategy = FieldStrategy.IGNORED) | |
12 | 16 | private String parentId; |
13 | 17 | private String name; |
14 | 18 | private int sort; | ... | ... |
... | ... | @@ -107,8 +107,10 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
107 | 107 | @Override |
108 | 108 | @Transactional |
109 | 109 | public OrganizationDTO updateOrganization(OrganizationDTO organizationDTO, String tenantId) { |
110 | + //选择的组织 | |
110 | 111 | Organization organization = baseMapper.selectById(organizationDTO.getId()); |
111 | 112 | Organization parent = null; |
113 | + //父级组织不为空,则查询到父级组织 | |
112 | 114 | if (StringUtils.isNotBlank(organizationDTO.getParentId())) { |
113 | 115 | Organization parentOrganization = baseMapper.selectById(organizationDTO.getParentId()); |
114 | 116 | if (parentOrganization.getTenantId().equals(tenantId)) { |
... | ... | @@ -118,10 +120,10 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
118 | 120 | if (organization == null) { |
119 | 121 | return null; |
120 | 122 | } |
123 | + //数据一致则返回给前端 | |
121 | 124 | if (organization.getName().equals(organizationDTO.getName()) |
122 | 125 | && organization.getSort() == organizationDTO.getSort() |
123 | - && (organization.getRemark() != null | |
124 | - && organization.getRemark().equals(organizationDTO.getRemark())) | |
126 | + && (organization.getRemark() != null && organization.getRemark().equals(organizationDTO.getRemark())) | |
125 | 127 | && Objects.equals(organization.getParentId(), organizationDTO.getParentId())) { |
126 | 128 | return organizationDTO; |
127 | 129 | } |
... | ... | @@ -130,6 +132,8 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
130 | 132 | organization.setSort(organizationDTO.getSort()); |
131 | 133 | if (parent != null) { |
132 | 134 | organization.setParentId(parent.getId()); |
135 | + }else{ | |
136 | + organization.setParentId(null); | |
133 | 137 | } |
134 | 138 | baseMapper.updateById(organization); |
135 | 139 | organization.copyToDTO(organizationDTO); |
... | ... | @@ -139,9 +143,11 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
139 | 143 | @Override |
140 | 144 | public List<OrganizationDTO> getMyOrganizations( |
141 | 145 | boolean isPtTenantAdmin, String tenantId, String currentUserId) { |
146 | + //如果是租户管理员,则返回该租户id下的所有组织 | |
142 | 147 | if (isPtTenantAdmin) { |
143 | 148 | return findOrganizationTree(tenantId); |
144 | 149 | } else { |
150 | + //返回当前用户组织id集 | |
145 | 151 | Set<String> organizationIds = |
146 | 152 | userOrganizationMappingMapper |
147 | 153 | .selectList( |
... | ... | @@ -151,6 +157,7 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
151 | 157 | .stream() |
152 | 158 | .map(UserOrganizationMapping::getOrganizationId) |
153 | 159 | .collect(Collectors.toSet()); |
160 | + | |
154 | 161 | List<Organization> organizations = |
155 | 162 | baseMapper.selectList( |
156 | 163 | new QueryWrapper<Organization>() |
... | ... | @@ -161,6 +168,11 @@ public class YtOrganizationServiceImpl extends AbstractBaseService<OrganizationM |
161 | 168 | } |
162 | 169 | } |
163 | 170 | |
171 | + /** | |
172 | + * 查询租户id下的所有组织 | |
173 | + * @param tenantId | |
174 | + * @return | |
175 | + */ | |
164 | 176 | private List<OrganizationDTO> findOrganizationTree(String tenantId) { |
165 | 177 | List<OrganizationDTO> organizationTreeList = |
166 | 178 | baseMapper.findOrganizationTreeList(tenantId, null); | ... | ... |