lihui001 3 rokov pred
rodič
commit
82fa81deef

+ 9 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceMapper.java

@@ -190,4 +190,13 @@ public interface DeviceMapper {
     List<DeviceVo> queryDeviceInfoList(@Param("deviceNo") String deviceNo, @Param("meterNo") String meterNo, @Param("userCondition") UserCondition userCondition);
 
     List<MeterSyncDto> meterSync(@Param("meterSync") MeterSyncInputDto meterSync);
+
+    /**
+    * 统计小区下有多少个设备数
+    * @author Andy
+    * @date 16:04 2021/9/10
+    * @param communityId:
+    * @return int
+    **/
+    int countDeviceByCommunityId(int communityId);
 }

+ 0 - 3
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/CommunityMapper.xml

@@ -259,10 +259,7 @@
     left join rmcp_org org2 on org2.id = sc.dept_org_id
     where
     sc.status = 1
-    <if test="dto.tenantId != null"> and sc.tenant_id = #{dto.tenantId} </if>
     <if test="dto.name != null and dto.name != ''"> and sc.name like concat('%',#{dto.name} ,'%')</if>
-    <if test="dto.companyOrgId != null"> and sc.company_org_id = #{dto.companyOrgId}</if>
-    <if test="dto.deptOrgId != null"> and sc.dept_org_id = #{dto.deptOrgId}</if>
     <include refid="permissionCondition"/>
     order by sc.create_date desc
   </select>

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/mapper/DeviceMapper.xml

@@ -835,4 +835,8 @@
     and rd.file_no in
     <foreach collection="meterSync.fileNo" item="item" open="(" separator="," close=")">#{item}</foreach>
   </select>
+
+  <select id="countDeviceByCommunityId" resultType="java.lang.Integer">
+    select count(1) from rmcp_device where community_id = #{communityId} and status = 1
+  </select>
 </mapper>

+ 8 - 0
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/CommunityServiceImpl.java

@@ -13,6 +13,7 @@ import com.zcxk.rmcp.api.dto.community.CommunityPageDto;
 import com.zcxk.rmcp.api.enums.RmcpErrorEnum;
 import com.zcxk.rmcp.api.vo.CommunityVo;
 import com.zcxk.rmcp.core.dao.CommunityMapper;
+import com.zcxk.rmcp.core.dao.DeviceMapper;
 import com.zcxk.rmcp.core.entity.Community;
 import com.zcxk.rmcp.web.service.CommunityService;
 import lombok.extern.slf4j.Slf4j;
@@ -38,6 +39,9 @@ public class CommunityServiceImpl implements CommunityService {
     @Resource
     private CommunityMapper communityMapper;
 
+    @Resource
+    private DeviceMapper deviceMapper;
+
     @Override
     public int updateByPrimaryKeySelective(CommunityAddDto communityDto) {
         Community community = new Community();
@@ -86,6 +90,10 @@ public class CommunityServiceImpl implements CommunityService {
         community.setUpdateDate(LocalDateTime.now());
         community.setId(id);
         community.setStatus(StatusEnum.DELETE.getCode());
+        // 小区有绑定设备就不能删除
+        if (deviceMapper.countDeviceByCommunityId(id) > 0 ){
+            throw BusinessException.builder(RmcpErrorEnum.RMCP_UPDATE_FAIL.getStatus(), "删除失败,该小区已绑定设备!");
+        }
         communityMapper.updateByPrimaryKeySelective(community);
     }