فهرست منبع

飞书账号批量添加

xw 2 روز پیش
والد
کامیت
3e1663d8cf

+ 59 - 16
fs-company/src/main/java/com/fs/company/controller/feishu/FeishuAccountController.java

@@ -30,7 +30,7 @@ public class FeishuAccountController extends BaseController {
     @Autowired
     private ICompanyUserService companyUserService;
 
-    /** 鎴戠殑椋炰功璐﹀彿鍒楄〃锛堝綋鍓嶇敤鎴锋暟鎹�級 */
+    /** ??????????б??????????????? */
     @GetMapping("/my/list")
     public TableDataInfo myList(@RequestParam(required = false) Integer status,
                                 @RequestParam(required = false) String phone,
@@ -44,7 +44,7 @@ public class FeishuAccountController extends BaseController {
         return getDataTable(list);
     }
 
-    /** 浼佷笟椋炰功璐﹀彿鍒楄〃锛堢�鐞嗗憳鏌ョ湅/鍒嗛厤锛� */
+    /** ???????????б?????????????/?????? */
     @GetMapping("/company/list")
     public TableDataInfo companyList(@RequestParam(required = false) Integer status,
                                      @RequestParam(required = false) String phone,
@@ -86,8 +86,8 @@ public class FeishuAccountController extends BaseController {
         return AjaxResult.success(account);
     }
 
-    /** 鎴戠殑椋炰功璐﹀彿 - 鏂板� */
-    @Log(title = "鎴戠殑椋炰功璐﹀彿", businessType = BusinessType.INSERT)
+    /** ????????? - ????? */
+    @Log(title = "?????????", businessType = BusinessType.INSERT)
     @PostMapping("/my")
     public AjaxResult addMy(@RequestBody FeishuAccount account) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
@@ -97,28 +97,51 @@ public class FeishuAccountController extends BaseController {
         return toAjax(feishuAccountService.insertFeishuAccount(account));
     }
 
-    /** 浼佷笟椋炰功璐﹀彿 - 鏂板�骞跺垎閰嶉攢鍞� */
-    @Log(title = "椋炰功璐﹀彿绠$悊", businessType = BusinessType.INSERT)
+    /** ????????? - ???????? */
+    @Log(title = "?????????", businessType = BusinessType.INSERT)
+    @PostMapping("/my/batch")
+    public AjaxResult addMyBatch(@RequestBody List<FeishuAccount> accounts) {
+        CompanyUser user = SecurityUtils.getLoginUser().getUser();
+        prepareBatchAccounts(accounts, user.getCompanyId(), false);
+        for (FeishuAccount account : accounts) {
+            account.setCompanyUserId(user.getUserId());
+        }
+        int count = feishuAccountService.insertFeishuAccountBatch(accounts);
+        return AjaxResult.success("??????? " + count + " ?????");
+    }
+
+    /** ?????????? - ?????????????? */
+    @Log(title = "??????????", businessType = BusinessType.INSERT)
     @PostMapping("/company")
     public AjaxResult addCompany(@RequestBody FeishuAccount account) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
         account.setCompanyId(user.getCompanyId());
         if (account.getCompanyUserId() == null) {
-            throw new CustomException("璇烽€夋嫨閿€鍞�汉鍛�");
+            throw new CustomException("????????????");
         }
         requireCompanyUser(account.getCompanyUserId(), user.getCompanyId());
         validateAccountPayload(account, true);
         return toAjax(feishuAccountService.insertFeishuAccount(account));
     }
 
+    /** ?????????? - ?????????????????? */
+    @Log(title = "??????????", businessType = BusinessType.INSERT)
+    @PostMapping("/company/batch")
+    public AjaxResult addCompanyBatch(@RequestBody List<FeishuAccount> accounts) {
+        CompanyUser user = SecurityUtils.getLoginUser().getUser();
+        prepareBatchAccounts(accounts, user.getCompanyId(), true);
+        int count = feishuAccountService.insertFeishuAccountBatch(accounts);
+        return AjaxResult.success("??????? " + count + " ?????");
+    }
+
     @Log(title = "Feishu account", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody FeishuAccount account) {
         return addMy(account);
     }
 
-    /** 鎴戠殑椋炰功璐﹀彿 - 缂栬緫 */
-    @Log(title = "鎴戠殑椋炰功璐﹀彿", businessType = BusinessType.UPDATE)
+    /** ????????? - ?? */
+    @Log(title = "?????????", businessType = BusinessType.UPDATE)
     @PutMapping("/my")
     public AjaxResult editMy(@RequestBody FeishuAccount account) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
@@ -130,8 +153,8 @@ public class FeishuAccountController extends BaseController {
         return toAjax(feishuAccountService.updateFeishuAccount(account));
     }
 
-    /** 浼佷笟椋炰功璐﹀彿 - 缂栬緫/閲嶆柊鍒嗛厤 */
-    @Log(title = "椋炰功璐﹀彿绠$悊", businessType = BusinessType.UPDATE)
+    /** ?????????? - ??/???·??? */
+    @Log(title = "??????????", businessType = BusinessType.UPDATE)
     @PutMapping("/company")
     public AjaxResult editCompany(@RequestBody FeishuAccount account) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
@@ -153,7 +176,7 @@ public class FeishuAccountController extends BaseController {
         return editMy(account);
     }
 
-    @Log(title = "鎴戠殑椋炰功璐﹀彿", businessType = BusinessType.DELETE)
+    @Log(title = "?????????", businessType = BusinessType.DELETE)
     @DeleteMapping("/my/{id}")
     public AjaxResult removeMy(@PathVariable Long id) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
@@ -162,7 +185,7 @@ public class FeishuAccountController extends BaseController {
         return toAjax(feishuAccountService.deleteFeishuAccountById(id));
     }
 
-    @Log(title = "椋炰功璐﹀彿绠$悊", businessType = BusinessType.DELETE)
+    @Log(title = "??????????", businessType = BusinessType.DELETE)
     @DeleteMapping("/company/{id}")
     public AjaxResult removeCompany(@PathVariable Long id) {
         CompanyUser user = SecurityUtils.getLoginUser().getUser();
@@ -193,10 +216,10 @@ public class FeishuAccountController extends BaseController {
 
     private void validateAccountPayload(FeishuAccount account, boolean requireSecret) {
         if (StringUtils.isBlank(account.getAppId())) {
-            throw new CustomException("AppId涓嶈兘涓虹┖");
+            throw new CustomException("AppId???????");
         }
         if (requireSecret && StringUtils.isBlank(account.getAppSecret())) {
-            throw new CustomException("AppSecret涓嶈兘涓虹┖");
+            throw new CustomException("AppSecret???????");
         }
     }
 
@@ -209,7 +232,27 @@ public class FeishuAccountController extends BaseController {
     private void requireCompanyUser(Long companyUserId, Long companyId) {
         CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
         if (companyUser == null || !companyId.equals(companyUser.getCompanyId())) {
-            throw new CustomException("鎵€閫変汉鍛樹笉灞炰簬褰撳墠浼佷笟");
+            throw new CustomException("所选人员不属于当前企业");
+        }
+    }
+
+    private void prepareBatchAccounts(List<FeishuAccount> accounts, Long companyId, boolean requireSales) {
+        if (accounts == null || accounts.isEmpty()) {
+            throw new CustomException("请至少添加一个账号");
+        }
+        Long companyUserId = accounts.get(0).getCompanyUserId();
+        if (requireSales && companyUserId == null) {
+            throw new CustomException("请选择销售人员");
+        }
+        if (requireSales) {
+            requireCompanyUser(companyUserId, companyId);
+        }
+        for (FeishuAccount account : accounts) {
+            account.setCompanyId(companyId);
+            if (requireSales) {
+                account.setCompanyUserId(companyUserId);
+            }
+            validateAccountPayload(account, true);
         }
     }
 }

+ 4 - 2
fs-service/src/main/java/com/fs/feishu/service/IFeishuAccountService.java

@@ -16,6 +16,8 @@ public interface IFeishuAccountService {
 
     int insertFeishuAccount(FeishuAccount account);
 
+    int insertFeishuAccountBatch(List<FeishuAccount> accounts);
+
     int updateFeishuAccount(FeishuAccount account);
 
     int deleteFeishuAccountById(Long id);
@@ -25,12 +27,12 @@ public interface IFeishuAccountService {
     void validateCompanyScope(FeishuAccount account, Long companyId);
 
     /**
-     * 轮询查询当�用户�用飞书账�(负载�衡选��用账�)
+     * �询查询当�用户�用�书账�(负载�衡选��用账�)
      */
     Long pollSendAccountId(Long companyUserId);
 
     /**
-     * 解���账�,支�指定账�时使用指定账�,�指定则轮询
+     * 解���账�,��指定账�时使用指定账�,�指定则轮�
      */
     Long resolveSendAccountId(Long companyUserId, Long feishuAccountId);
 

+ 29 - 10
fs-service/src/main/java/com/fs/feishu/service/impl/FeishuAccountServiceImpl.java

@@ -8,6 +8,7 @@ import com.fs.feishu.service.IFeishuAccountService;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.util.Date;
 import java.util.List;
@@ -59,6 +60,24 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
         return feishuAccountMapper.insert(account);
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int insertFeishuAccountBatch(List<FeishuAccount> accounts) {
+        if (accounts == null || accounts.isEmpty()) {
+            throw new CustomException("请至少添加一个账号");
+        }
+        int count = 0;
+        for (int i = 0; i < accounts.size(); i++) {
+            FeishuAccount account = accounts.get(i);
+            try {
+                count += insertFeishuAccount(account);
+            } catch (CustomException e) {
+                throw new CustomException("第" + (i + 1) + "个账号添加失败: " + e.getMessage());
+            }
+        }
+        return count;
+    }
+
     @Override
     public int updateFeishuAccount(FeishuAccount account) {
         account.setUpdateTime(new Date());
@@ -73,30 +92,30 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
     @Override
     public void validateOwnership(FeishuAccount account, Long companyId, Long companyUserId) {
         if (account == null) {
-            throw new CustomException("椋炰功璐﹀彿涓嶅瓨鍦�");
+            throw new CustomException("飞书账号不存??");
         }
         if (companyId != null && account.getCompanyId() != null && !companyId.equals(account.getCompanyId())) {
-            throw new CustomException("鏃犳潈鎿嶄綔璇ヨ处鍙�");
+            throw new CustomException("无权操作该账??");
         }
         if (companyUserId != null && account.getCompanyUserId() != null && !companyUserId.equals(account.getCompanyUserId())) {
-            throw new CustomException("鏃犳潈鎿嶄綔璇ヨ处鍙�");
+            throw new CustomException("无权操作该账??");
         }
     }
 
     @Override
     public void validateCompanyScope(FeishuAccount account, Long companyId) {
         if (account == null) {
-            throw new CustomException("椋炰功璐﹀彿涓嶅瓨鍦�");
+            throw new CustomException("飞书账号不存??");
         }
         if (companyId == null || account.getCompanyId() == null || !companyId.equals(account.getCompanyId())) {
-            throw new CustomException("鏃犳潈鎿嶄綔璇ヨ处鍙�");
+            throw new CustomException("无权操作该账??");
         }
     }
 
     @Override
     public Long pollSendAccountId(Long companyUserId) {
         if (companyUserId == null) {
-            throw new CustomException("鐢ㄦ埛ID涓嶈兘涓虹┖");
+            throw new CustomException("用户ID不能为空");
         }
         return clientPool.pollNextAccountId(companyUserId);
     }
@@ -104,7 +123,7 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
     @Override
     public Long resolveSendAccountId(Long companyUserId, Long feishuAccountId) {
         if (companyUserId == null) {
-            throw new CustomException("鐢ㄦ埛ID涓嶈兘涓虹┖");
+            throw new CustomException("用户ID不能为空");
         }
         if (feishuAccountId != null) {
             requireEnabledAccount(feishuAccountId, companyUserId);
@@ -116,13 +135,13 @@ public class FeishuAccountServiceImpl implements IFeishuAccountService {
     private FeishuAccount requireEnabledAccount(Long feishuAccountId, Long companyUserId) {
         FeishuAccount account = feishuAccountMapper.selectById(feishuAccountId);
         if (account == null) {
-            throw new CustomException("椋炰功璐﹀彿涓嶅瓨鍦�");
+            throw new CustomException("飞书账号不存??");
         }
         if (!companyUserId.equals(account.getCompanyUserId())) {
-            throw new CustomException("璇ヨ处鍙蜂笉灞炰簬褰撳墠鐢ㄦ埛");
+            throw new CustomException("该账号不属于当前用户");
         }
         if (!Integer.valueOf(1).equals(account.getStatus())) {
-            throw new CustomException("璐﹀彿涓嶅彲鐢�: " + account.getErrorMsg());
+            throw new CustomException("账号不可??: " + account.getErrorMsg());
         }
         return account;
     }