Commit 817b064022f13566fffbc1b3e3e5eb9b3825a310

Authored by xp.Huang
1 parent 8b3eb8b8

perf: 删除产品时验证产品是否被组态使用

... ... @@ -209,7 +209,7 @@ non.existent.tenant = Rule chain is referencing to non-existent tenant!
209 209 root.rule.chain.is.present = Another root rule chain is present in scope of current tenant!
210 210 edge.root.rule.chain.is.present = Another edge template root rule chain is present in scope of current tenant!
211 211 app.openapi.api.isnull = The current application does not have a callable API. Please contact the administrator
212   -
  212 +device.profile.used.for.configuration.center = The product used for [%s] configuration center and cannot delete!!!
213 213
214 214
215 215
... ...
... ... @@ -209,5 +209,5 @@ non.existent.tenant =规则链正在引用不存在的租户
209 209 root.rule.chain.is.present =当前租户范围内存在另一个根规则链
210 210 edge.root.rule.chain.is.present =当前租户范围内存在另一个边缘模板根规则链
211 211 app.openapi.api.isnull = 当前应用不存在可调用api请联系管理员
212   -
  212 +device.profile.used.for.configuration.center = 产品被【%s】组态使用,不能删除!!!
213 213
... ...
... ... @@ -203,7 +203,7 @@ public enum ErrorMessage {
203 203 ROOT_RULE_CHAIN_IS_PRESENT (400167,"当前租户范围内存在另一个根规则链!","root.rule.chain.is.present"),
204 204 EDGE_ROOT_RULE_CHAIN_IS_PRESENT(400168,"当前租户范围内存在另一个边缘模板根规则链!","edge.root.rule.chain.is.present"),
205 205 APP_OPENAPI_API_ISNULL(400169,"当前应用不存在可调用api请联系管理员","app.openapi.api.isnull"),
206   -
  206 + DEVICE_PROFILE_USED_FOR_CENTER(400170,"产品被【%s】组态使用,不能删除!!!","device.profile.used.for.configuration.center"),
207 207
208 208 HAVE_NO_PERMISSION(500002, "没有修改权限", "have.no.permission"),
209 209 NOT_ALLOWED_ISOLATED_IN_MONOLITH(500003, "【monolith】模式下,不能选择【isolated】类型的租户配置", "not.allowed.isolated.in.monolith"),
... ...
... ... @@ -31,13 +31,11 @@ import org.thingsboard.server.common.data.yunteng.utils.i18n.MessageUtils;
31 31 import org.thingsboard.server.common.data.yunteng.utils.tools.TkPageData;
32 32 import org.thingsboard.server.dao.rule.RuleChainService;
33 33 import org.thingsboard.server.dao.yunteng.entities.*;
  34 +import org.thingsboard.server.dao.yunteng.mapper.ConfigurationCenterMapper;
34 35 import org.thingsboard.server.dao.yunteng.mapper.DeviceMapper;
35 36 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileCategoryMapper;
36 37 import org.thingsboard.server.dao.yunteng.mapper.TkDeviceProfileMapper;
37   -import org.thingsboard.server.dao.yunteng.service.AbstractTbBaseService;
38   -import org.thingsboard.server.dao.yunteng.service.ConvertConfigService;
39   -import org.thingsboard.server.dao.yunteng.service.SceneLinkageService;
40   -import org.thingsboard.server.dao.yunteng.service.TkDeviceProfileService;
  38 +import org.thingsboard.server.dao.yunteng.service.*;
41 39
42 40 import java.time.LocalDateTime;
43 41 import java.util.*;
... ... @@ -60,6 +58,8 @@ public class TkDeviceProfileServiceImpl
60 58
61 59 private final SceneLinkageService sceneLinkageService;
62 60
  61 + private final ConfigurationCenterMapper configurationCenterMapper;
  62 +
63 63
64 64
65 65 @Override
... ... @@ -313,6 +313,15 @@ public class TkDeviceProfileServiceImpl
313 313 if (count > 0) {
314 314 throw new TkDataValidationException(MessageUtils.message(ErrorMessage.DEVICE_PROFILE_USED_BY_DEVICE.getI18nCode()));
315 315 }
  316 + for (String deviceProfileId:ids){
  317 + //删除检查产品是否被组态使用
  318 + List<ConfigurationCenterDTO> checkResult = configurationCenterMapper.getConfigurationCenterByDeviceProfileId(deviceProfileId,tenantId);
  319 + if(null != checkResult && !checkResult.isEmpty()){
  320 + throw new TkDataValidationException(String.format(MessageUtils.message(ErrorMessage.
  321 + DEVICE_PROFILE_USED_FOR_CENTER.getI18nCode())
  322 + ,checkResult.get(0).getName()));
  323 + }
  324 + }
316 325 }
317 326
318 327 @Override
... ...
... ... @@ -18,4 +18,13 @@ public interface ConfigurationCenterMapper extends BaseMapper<TkConfigurationCen
18 18
19 19 List<ConfigurationContentInfoDTO> getConfigurationInfoById(
20 20 @Param("id") String id, @Param("tenantId") String tenantId);
  21 +
  22 + /**
  23 + * 通过产品ID和租户ID查询被哪些组态使用
  24 + * @param deviceProfileId 产品ID
  25 + * @param tenantId 租户ID
  26 + * @return 组态中心列表
  27 + */
  28 + List<ConfigurationCenterDTO> getConfigurationCenterByDeviceProfileId(
  29 + @Param("deviceProfileId") String deviceProfileId, @Param("tenantId") String tenantId);
21 30 }
... ...
... ... @@ -40,11 +40,11 @@
40 40
41 41 <sql id="columns">
42 42 a.id,a.name,a.platform,a.organization_id,a.thumbnail, a.remark,a.update_time,a.create_time,a.creator,a.tenant_id,
43   - a.updater,io.name AS organization_name,a.view_type,a.access_credentials,a.product_and_device,a.template_id
  43 + a.updater,a.view_type,a.access_credentials,a.product_and_device,a.template_id
44 44 </sql>
45 45 <select id="getConfigurationCenterPage" resultMap="configurationCenterMap">
46 46 SELECT
47   - <include refid="columns"/>
  47 + <include refid="columns"/>,io.name AS organization_name
48 48 FROM tk_configuration_center a
49 49 LEFT JOIN tk_organization io ON io.id = a.organization_id
50 50 <where>
... ... @@ -74,4 +74,14 @@
74 74 tk_configuration_content icct ON icc.id = icct.configuration_id
75 75 WHERE icc.id = #{id} AND icc.tenant_id = #{tenantId}
76 76 </select>
  77 +
  78 + <select id="getConfigurationCenterByDeviceProfileId" resultMap="configurationCenterMap">
  79 + SELECT
  80 + <include refid="columns"/>
  81 + FROM
  82 + tk_configuration_center a
  83 + WHERE
  84 + a.tenant_id = #{tenantId}
  85 + AND POSITION ( #{deviceProfileId} IN product_and_device ) >0
  86 + </select>
77 87 </mapper>
... ...