Преглед на файлове

增加企业解绑方法。

zhengqiang преди 5 години
родител
ревизия
e477bcfd32

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/CompanyDeviceRelationDAO.java

@@ -19,4 +19,5 @@ public interface CompanyDeviceRelationDAO {
 	List<CompanyDeviceRelation> search(Map<String,Object> searchParams,List<Sort> sortList);
     List<DeviceInfo> findDeviceByCompanyId(String companyId);
 	int deleteByCompanyId(String companyId);
+    int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/CompanyDeviceRelationService.java

@@ -17,4 +17,5 @@ public interface CompanyDeviceRelationService {
 	Page<CompanyDeviceRelation> pageSearch(Map<String, Object> searchParams,int pageNum,int pageSize,boolean count,List<Sort> sortList);
 	List<DeviceInfo> findDeviceByCompanyId(String companyId);
 	int deleteByCompanyId(String companyId);
+    int deleteByCompanyIdAndDeviceId(String companyId, String deviceId);
 }

+ 14 - 10
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/CompanyDeviceRelationServiceImpl.java

@@ -1,19 +1,18 @@
 package com.jpsoft.smart.modules.base.service.impl;
 
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.annotation.Resource;
-
-import com.jpsoft.smart.modules.base.entity.DeviceInfo;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
 import com.jpsoft.smart.modules.base.dao.CompanyDeviceRelationDAO;
 import com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation;
+import com.jpsoft.smart.modules.base.entity.DeviceInfo;
 import com.jpsoft.smart.modules.base.service.CompanyDeviceRelationService;
-import com.github.pagehelper.Page;
 import com.jpsoft.smart.modules.common.dto.Sort;
-import com.github.pagehelper.PageHelper;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
 
 @Transactional
 @Component(value="companyDeviceRelationService")
@@ -79,4 +78,9 @@ public class CompanyDeviceRelationServiceImpl implements CompanyDeviceRelationSe
 	public int deleteByCompanyId(String companyId) {
 		return companyDeviceRelationDAO.deleteByCompanyId(companyId);
 	}
+
+	@Override
+	public int deleteByCompanyIdAndDeviceId(String companyId, String deviceId) {
+		return companyDeviceRelationDAO.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+	}
 }

+ 4 - 0
common/src/main/resources/mapper/base/CompanyDeviceRelation.xml

@@ -41,6 +41,10 @@
     <delete id="deleteByCompanyId" parameterType="string">
         delete from base_company_device_relation where company_id=#{0}
     </delete>
+    <delete id="deleteByCompanyIdAndDeviceId" parameterType="string">
+        delete from base_company_device_relation
+        where company_id=#{companyId} and device_id=#{deviceId}
+    </delete>
     <update id="update" parameterType="com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation">
         update base_company_device_relation
         <set>

+ 26 - 1
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -443,7 +443,7 @@ public class CompanyInfoController {
         try {
             String[] arr = deviceIds.split(",");
 
-            companyDeviceRelationService.deleteByCompanyId(companyId);
+//            companyDeviceRelationService.deleteByCompanyId(companyId);
 
             for (String deviceId : arr) {
                 CompanyDeviceRelation cdr = new CompanyDeviceRelation();
@@ -469,4 +469,29 @@ public class CompanyInfoController {
 
         return messageResult;
     }
+
+    @Transactional(rollbackFor = Exception.class)
+    @PostMapping("unbindDevice")
+    public MessageResult<String> unbindDevice(String companyId,String deviceIds,@ModelAttribute String subject){
+        MessageResult<String> messageResult = new MessageResult<>();
+
+        try {
+            String[] arr = deviceIds.split(",");
+
+            for (String deviceId : arr) {
+                companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+            }
+
+            messageResult.setResult(true);
+        }
+        catch (Exception ex){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+
+            logger.error(ex.getMessage(),ex);
+            messageResult.setResult(false);
+            messageResult.setMessage(ex.getMessage());
+        }
+
+        return messageResult;
+    }
 }