|
@@ -3,6 +3,7 @@ package com.dragoninfo.dcuc.auth.sub.business.impl;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.dragoninfo.dcuc.auth.admin.service.IAppMtAuthService;
|
|
|
import com.dragoninfo.dcuc.auth.auth.constance.CommonCons;
|
|
|
+import com.dragoninfo.dcuc.auth.constance.AddSyncContance;
|
|
|
import com.dragoninfo.dcuc.auth.sub.business.IAuthOrgBusiness;
|
|
|
import com.dragoninfo.dcuc.auth.sub.dto.AuthOrgDTO;
|
|
|
import com.dragoninfo.dcuc.auth.sub.dto.ExcelImpOrgInfo;
|
|
@@ -33,6 +34,8 @@ import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
@@ -42,6 +45,7 @@ import java.io.ByteArrayInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -92,6 +96,9 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
|
|
|
@Autowired
|
|
|
private IDuceapUploadFacade uploadFacade;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedissonClient redissonClient;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<AuthOrgDTO> autOrgInfoPage(Searchable searchable) {
|
|
|
Page<AuthOrgInfo> page = authOrgInfoService.autOrgInfoPage(searchable);
|
|
@@ -132,6 +139,8 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
|
|
|
public ResponseStatus impExcel(String fileId) {
|
|
|
DocContentDTO fileContent = uploadFacade.getFileContent(fileId);
|
|
|
InputStream inputStream = new ByteArrayInputStream(fileContent.getFileData());
|
|
|
+ //分布式锁
|
|
|
+ RLock lock = redissonClient.getLock(AddSyncContance.ORG_SYNC_KEY);
|
|
|
try {
|
|
|
checkCache();
|
|
|
List<ExcelImpOrgInfo> list = loadOrgFromExcel(inputStream);
|
|
@@ -139,11 +148,19 @@ public class AuthOrgBusinessImpl implements IAuthOrgBusiness {
|
|
|
verifyOrgInfo(list);
|
|
|
//保存数据
|
|
|
saveImport(list);
|
|
|
+ boolean tryLock = lock.tryLock(0, 1, TimeUnit.MINUTES);
|
|
|
+ if (!tryLock) {
|
|
|
+ return ResponseStatus.fail("机构正在同步中,请稍后导入");
|
|
|
+ }
|
|
|
authOrgTreeService.reInitTrees(false);
|
|
|
} catch (IOException e) {
|
|
|
return ResponseStatus.fail("文件格式不对");
|
|
|
} catch (NumberFormatException e){
|
|
|
return ResponseStatus.fail(e.getMessage());
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ return ResponseStatus.fail("机构正在同步中,请稍后导入");
|
|
|
+ }finally {
|
|
|
+ lock.unlock();
|
|
|
}
|
|
|
return ResponseStatus.success("导入成功");
|
|
|
}
|