fix: hybrid approach — keep CFR for files where alt has import/lambda issues

Restored CFR versions for: OrganizationServiceImpl, ValidateManager,
PersonAuditServiceImpl, DeviceGroupRefChangeEventHandler,
CommonAppExportTaskServiceImpl, CommonAppFileManageServiceImpl,
CommonAppExportExecuteTask

Deleted re-appeared orphans: CpImageStoreServiceImpl, SelfRegistryHandler

Applied batch fixes: map(()), computeIfAbsent(()), (Object) removal,
Lists/Sets.newHashSet cleanup

Result: 200→144 errors (-56, -28%)
This commit is contained in:
反编译工作区
2026-05-06 00:32:57 +08:00
parent 5f22d6f8f7
commit 6376384672
14 changed files with 3141 additions and 4072 deletions
@@ -1,4 +1,5 @@
package cn.cloudwalk.service.organization.export; package cn.cloudwalk.service.organization.export;
// 业务服务
import cn.cloudwalk.client.organization.batch.param.download.FilePartFinishPara; import cn.cloudwalk.client.organization.batch.param.download.FilePartFinishPara;
import cn.cloudwalk.client.organization.batch.param.download.FilePartInitResult; import cn.cloudwalk.client.organization.batch.param.download.FilePartInitResult;
import cn.cloudwalk.client.organization.common.enums.FileStatusEnum; import cn.cloudwalk.client.organization.common.enums.FileStatusEnum;
@@ -17,14 +18,21 @@ import cn.cloudwalk.client.organization.result.PersonProListResult;
import cn.cloudwalk.client.organization.service.ICommonAppDownloadCenterService; import cn.cloudwalk.client.organization.service.ICommonAppDownloadCenterService;
import cn.cloudwalk.client.organization.service.ICommonAppFileManageService; import cn.cloudwalk.client.organization.service.ICommonAppFileManageService;
import cn.cloudwalk.client.organization.service.ICommonStorageService; import cn.cloudwalk.client.organization.service.ICommonStorageService;
import cn.cloudwalk.client.organization.service.LabelService;
import cn.cloudwalk.client.organization.service.OrganizationService; import cn.cloudwalk.client.organization.service.OrganizationService;
import cn.cloudwalk.client.organization.service.store.result.OrganizationResult; import cn.cloudwalk.client.organization.service.store.result.OrganizationResult;
import cn.cloudwalk.cloud.context.CloudwalkCallContext; import cn.cloudwalk.cloud.context.CloudwalkCallContext;
import cn.cloudwalk.cloud.result.CloudwalkResult; import cn.cloudwalk.cloud.result.CloudwalkResult;
import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitResultDTO; import cn.cloudwalk.intelligent.davinci.storage.bean.part.dto.PartInitResultDTO;
import cn.cloudwalk.intelligent.davinci.storage.manager.FilePartManager;
import cn.cloudwalk.intelligent.davinci.storage.manager.FileStorageManager;
import cn.cloudwalk.service.organization.common.AbstractImagStoreService;
import cn.cloudwalk.service.organization.common.CommonDownloadDataConfig; import cn.cloudwalk.service.organization.common.CommonDownloadDataConfig;
import cn.cloudwalk.service.organization.common.MultipartFileUtils; import cn.cloudwalk.service.organization.common.MultipartFileUtils;
import cn.cloudwalk.service.organization.config.ChannelFileReader; import cn.cloudwalk.service.organization.config.ChannelFileReader;
import cn.cloudwalk.service.organization.export.CommonAppExportFileByLabelHandler;
import cn.cloudwalk.service.organization.export.CommonAppExportFileByOrgHandler;
import cn.cloudwalk.service.organization.export.CommonAppExportFileHandler;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -34,21 +42,25 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.util.Base64Utils; import org.springframework.util.Base64Utils;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@Service @Service
@EnableAsync @EnableAsync
public class CommonAppExportExecuteTask extends AbstractImagStoreService { public class CommonAppExportExecuteTask
extends AbstractImagStoreService {
private static final Logger log = LoggerFactory.getLogger(CommonAppExportExecuteTask.class); private static final Logger log = LoggerFactory.getLogger(CommonAppExportExecuteTask.class);
@Autowired @Autowired
private ICommonAppDownloadCenterService commonAppDownloadCenterService; private ICommonAppDownloadCenterService commonAppDownloadCenterService;
@@ -70,28 +82,29 @@ private ICommonAppFileManageService iCommonAppFileManageService;
private FilePartManager filePartManager; private FilePartManager filePartManager;
@Autowired @Autowired
private FileStorageManager fileStorageManager; private FileStorageManager fileStorageManager;
@Value("${cloudwalk.common-app.download.shardingSize}") @Value(value="${cloudwalk.common-app.download.shardingSize}")
private Integer shardingSize; private Integer shardingSize;
String fileName = "人员信息"; String fileName = "人员信息";
String orgFileName = "机构信息"; String orgFileName = "机构信息";
String labelFileName = "标签信息"; String labelFileName = "标签信息";
@Async @Async
public void execute(ExportRecordTaskParam task, CloudwalkCallContext cloudwalkCallContext) { public void execute(ExportRecordTaskParam task, CloudwalkCallContext cloudwalkCallContext) {
this.logger.info("开始执行人员信息导出功能"); this.logger.info("开始执行人员信息导出功能");
QueryImgPersonParam queryImgPersonParam = new QueryImgPersonParam(); QueryImgPersonParam queryImgPersonParam = new QueryImgPersonParam();
BeanUtils.copyProperties(task, queryImgPersonParam); BeanUtils.copyProperties((Object)task, (Object)queryImgPersonParam);
try { try {
CloudwalkResult<List<ImgStorePersonGetResult>> recordList = getPersonData(queryImgPersonParam, cloudwalkCallContext); CloudwalkResult<List<ImgStorePersonGetResult>> recordList = this.getPersonData(queryImgPersonParam, cloudwalkCallContext);
if (CollectionUtils.isEmpty((Collection)recordList.getData())) { if (CollectionUtils.isEmpty((Collection)((Collection)recordList.getData()))) {
this.logger.info("查询导出记录为空, businessId = {}, task = {}", task.getBusinessId(), task); this.logger.info("查询导出记录为空, businessId = {}, task = {}", (Object)task.getBusinessId(), (Object)task);
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
this.logger.info("导出记录总数为{}", Integer.valueOf(((List)recordList.getData()).size())); this.logger.info("导出记录总数为{}", (Object)((List)recordList.getData()).size());
Map<String, List<ImgStorePersonGetResult>> dataMap = new HashMap<>(); HashMap<String, List<ImgStorePersonGetResult>> dataMap = new HashMap<String, List<ImgStorePersonGetResult>>();
dataMap.put(this.fileName, recordList.getData()); dataMap.put(this.fileName, (List<ImgStorePersonGetResult>)recordList.getData());
PersonProListResult personProListResult = (PersonProListResult)this.imgStorePersonPropertiesService.getList(task.getBusinessId()).getData(); PersonProListResult personProListResult = (PersonProListResult)this.imgStorePersonPropertiesService.getList(task.getBusinessId()).getData();
List<ImgPersonProGetResult> properties = personProListResult.getProperties(); List properties = personProListResult.getProperties();
ImgPersonProGetResult result1 = new ImgPersonProGetResult(); ImgPersonProGetResult result1 = new ImgPersonProGetResult();
result1.setId("1"); result1.setId("1");
result1.setName("门禁设备(在线)"); result1.setName("门禁设备(在线)");
@@ -119,41 +132,42 @@ result3.setHasDefault(Integer.valueOf(1));
properties.add(result1); properties.add(result1);
properties.add(result2); properties.add(result2);
properties.add(result3); properties.add(result3);
this.logger.info("导出的字段属性为:{}", JSONObject.toJSON(properties)); this.logger.info("导出的字段属性为:{}", JSONObject.toJSON((Object)properties));
this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows().intValue()); this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows());
this.commonDownloadDataConfig.setHasContainImage(task.getHasContainImage()); this.commonDownloadDataConfig.setHasContainImage(task.getHasContainImage());
Path zipPath = (new CommonAppExportFileHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult)).process(); Path zipPath = new CommonAppExportFileHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult).process();
int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId()); int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId());
if (status > 1) { if (status > 1) {
this.logger.info("下载中心已取消下载文件,fileId = {}", task.getFileId()); this.logger.info("下载中心已取消下载文件,fileId = {}", (Object)task.getFileId());
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString()); this.exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString());
} }
catch (Exception e) { catch (Exception e) {
this.logger.error("导出人员任务失败:{}", e.getMessage()); this.logger.error("导出人员任务失败:{}", (Object)e.getMessage());
this.commonAppDownloadCenterService.finishDownload(task.getBusinessId(), task.getFileId(), null, null, FileStatusEnum.ERROR.getCode()); this.commonAppDownloadCenterService.finishDownload(task.getBusinessId(), task.getFileId(), null, null, FileStatusEnum.ERROR.getCode());
throw new RuntimeException("执行导出人员记录任务异常"); throw new RuntimeException("执行导出人员记录任务异常");
} }
} }
@Async @Async
public void executeOrg(ExportOrgTaskParam task, CloudwalkCallContext context) { public void executeOrg(ExportOrgTaskParam task, CloudwalkCallContext context) {
this.logger.info("开始执行机构信息导出功能"); this.logger.info("开始执行机构信息导出功能");
QueryOrganizationParam queryImgPersonParam = new QueryOrganizationParam(); QueryOrganizationParam queryImgPersonParam = new QueryOrganizationParam();
BeanUtils.copyProperties(task, queryImgPersonParam); BeanUtils.copyProperties((Object)task, (Object)queryImgPersonParam);
try { try {
CloudwalkResult<List<OrganizationResult>> recordList = getOrgData(queryImgPersonParam, context); CloudwalkResult<List<OrganizationResult>> recordList = this.getOrgData(queryImgPersonParam, context);
if (CollectionUtils.isEmpty((Collection)recordList.getData())) { if (CollectionUtils.isEmpty((Collection)((Collection)recordList.getData()))) {
this.logger.info("查询导出记录为空, businessId = {}, task = {}", task.getBusinessId(), task); this.logger.info("查询导出记录为空, businessId = {}, task = {}", (Object)task.getBusinessId(), (Object)task);
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
this.logger.info("导出记录总数为{}", Integer.valueOf(((List)recordList.getData()).size())); this.logger.info("导出记录总数为{}", (Object)((List)recordList.getData()).size());
Map<String, List<OrganizationResult>> dataMap = new HashMap<>(); HashMap<String, List<OrganizationResult>> dataMap = new HashMap<String, List<OrganizationResult>>();
dataMap.put(this.orgFileName, recordList.getData()); dataMap.put(this.orgFileName, (List<OrganizationResult>)recordList.getData());
PersonProListResult personProListResult = new PersonProListResult(); PersonProListResult personProListResult = new PersonProListResult();
List<ImgPersonProGetResult> properties = new ArrayList<>(); ArrayList<ImgPersonProGetResult> properties = new ArrayList<ImgPersonProGetResult>();
ImgPersonProGetResult result1 = new ImgPersonProGetResult(); ImgPersonProGetResult result1 = new ImgPersonProGetResult();
result1.setId("1"); result1.setId("1");
result1.setName("机构名称"); result1.setName("机构名称");
@@ -228,15 +242,15 @@ properties.add(result7);
properties.add(result8); properties.add(result8);
personProListResult.setProperties(properties); personProListResult.setProperties(properties);
this.logger.info("导出的字段属性为:{}", JSONObject.toJSON(properties)); this.logger.info("导出的字段属性为:{}", JSONObject.toJSON(properties));
this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows().intValue()); this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows());
Path zipPath = (new CommonAppExportFileByOrgHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult)).process(); Path zipPath = new CommonAppExportFileByOrgHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult).process();
int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId()); int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId());
if (status > 1) { if (status > 1) {
this.logger.info("下载中心已取消下载文件,fileId = {}", task.getFileId()); this.logger.info("下载中心已取消下载文件,fileId = {}", (Object)task.getFileId());
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString()); this.exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString());
} }
catch (Exception e) { catch (Exception e) {
this.logger.error("导出机构任务失败:{}", e); this.logger.error("导出机构任务失败:{}", e);
@@ -244,23 +258,24 @@ this.commonAppDownloadCenterService.finishDownload(task.getBusinessId(), task.ge
throw new RuntimeException("执行导出机构信息任务异常"); throw new RuntimeException("执行导出机构信息任务异常");
} }
} }
@Async @Async
public void executeLabel(ExportLabelTaskParam task, CloudwalkCallContext context) { public void executeLabel(ExportLabelTaskParam task, CloudwalkCallContext context) {
this.logger.info("开始执行标签信息导出功能"); this.logger.info("开始执行标签信息导出功能");
PageLabelParam pageLabelParam = new PageLabelParam(); PageLabelParam pageLabelParam = new PageLabelParam();
BeanUtils.copyProperties(task, pageLabelParam); BeanUtils.copyProperties((Object)task, (Object)pageLabelParam);
try { try {
CloudwalkResult<List<PageLabelResult>> recordList = getLabelData(pageLabelParam, context); CloudwalkResult<List<PageLabelResult>> recordList = this.getLabelData(pageLabelParam, context);
if (CollectionUtils.isEmpty((Collection)recordList.getData())) { if (CollectionUtils.isEmpty((Collection)((Collection)recordList.getData()))) {
this.logger.info("查询导出记录为空, businessId = {}, task = {}", task.getBusinessId(), task); this.logger.info("查询导出记录为空, businessId = {}, task = {}", (Object)task.getBusinessId(), (Object)task);
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
this.logger.info("导出记录总数为{}", Integer.valueOf(((List)recordList.getData()).size())); this.logger.info("导出记录总数为{}", (Object)((List)recordList.getData()).size());
Map<String, List<PageLabelResult>> dataMap = new HashMap<>(); HashMap<String, List<PageLabelResult>> dataMap = new HashMap<String, List<PageLabelResult>>();
dataMap.put(this.labelFileName, recordList.getData()); dataMap.put(this.labelFileName, (List<PageLabelResult>)recordList.getData());
PersonProListResult personProListResult = new PersonProListResult(); PersonProListResult personProListResult = new PersonProListResult();
List<ImgPersonProGetResult> properties = new ArrayList<>(); ArrayList<ImgPersonProGetResult> properties = new ArrayList<ImgPersonProGetResult>();
ImgPersonProGetResult result1 = new ImgPersonProGetResult(); ImgPersonProGetResult result1 = new ImgPersonProGetResult();
result1.setId("1"); result1.setId("1");
result1.setName("标签名称"); result1.setName("标签名称");
@@ -335,15 +350,15 @@ properties.add(result7);
properties.add(result8); properties.add(result8);
personProListResult.setProperties(properties); personProListResult.setProperties(properties);
this.logger.info("导出的字段属性为:{}", JSONObject.toJSON(properties)); this.logger.info("导出的字段属性为:{}", JSONObject.toJSON(properties));
this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows().intValue()); this.commonDownloadDataConfig.setExcelMaxRows(task.getExcelMaxRows());
Path zipPath = (new CommonAppExportFileByLabelHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult)).process(); Path zipPath = new CommonAppExportFileByLabelHandler(task.getBusinessId(), this.fileName, task.getFileId(), dataMap, this.commonDownloadDataConfig, this.fileStorageManager, this.commonAppDownloadCenterService, personProListResult).process();
int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId()); int status = this.commonAppDownloadCenterService.queryDownloadStatus(task.getBusinessId(), task.getFileId());
if (status > 1) { if (status > 1) {
this.logger.info("下载中心已取消下载文件,fileId = {}", task.getFileId()); this.logger.info("下载中心已取消下载文件,fileId = {}", (Object)task.getFileId());
exportUpload(task.getBusinessId(), task.getFileId(), null); this.exportUpload(task.getBusinessId(), task.getFileId(), null);
return; return;
} }
exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString()); this.exportUpload(task.getBusinessId(), task.getFileId(), zipPath.toString());
} }
catch (Exception e) { catch (Exception e) {
this.logger.error("导出标签任务失败:{}", e); this.logger.error("导出标签任务失败:{}", e);
@@ -351,69 +366,82 @@ this.commonAppDownloadCenterService.finishDownload(task.getBusinessId(), task.ge
throw new RuntimeException("执行导出标签信息任务异常"); throw new RuntimeException("执行导出标签信息任务异常");
} }
} }
private CloudwalkResult<List<ImgStorePersonGetResult>> getPersonData(QueryImgPersonParam queryImgPersonParam, CloudwalkCallContext cloudwalkCallContext) { private CloudwalkResult<List<ImgStorePersonGetResult>> getPersonData(QueryImgPersonParam queryImgPersonParam, CloudwalkCallContext cloudwalkCallContext) {
CloudwalkResult<List<ImgStorePersonGetResult>> recordList = new CloudwalkResult(); CloudwalkResult recordList = new CloudwalkResult();
try { try {
recordList = this.imgStorePersonService.listByPage(queryImgPersonParam, cloudwalkCallContext); recordList = this.imgStorePersonService.listByPage(queryImgPersonParam, cloudwalkCallContext);
} catch (Exception e) { }
catch (Exception e) {
this.logger.error("查询记录数据失败"); this.logger.error("查询记录数据失败");
} }
return recordList; return recordList;
} }
private CloudwalkResult<List<OrganizationResult>> getOrgData(QueryOrganizationParam param, CloudwalkCallContext context) { private CloudwalkResult<List<OrganizationResult>> getOrgData(QueryOrganizationParam param, CloudwalkCallContext context) {
CloudwalkResult<List<OrganizationResult>> recordList = new CloudwalkResult(); CloudwalkResult recordList = new CloudwalkResult();
try { try {
recordList = this.organizationService.listByPage(param, context); recordList = this.organizationService.listByPage(param, context);
} catch (Exception e) { }
catch (Exception e) {
this.logger.error("查询机构记录数据失败"); this.logger.error("查询机构记录数据失败");
} }
return recordList; return recordList;
} }
private CloudwalkResult<List<PageLabelResult>> getLabelData(PageLabelParam param, CloudwalkCallContext cloudwalkCallContext) { private CloudwalkResult<List<PageLabelResult>> getLabelData(PageLabelParam param, CloudwalkCallContext cloudwalkCallContext) {
CloudwalkResult<List<PageLabelResult>> recordList = new CloudwalkResult(); CloudwalkResult recordList = new CloudwalkResult();
try { try {
recordList = this.labelService.listByPage(param, cloudwalkCallContext); recordList = this.labelService.listByPage(param, cloudwalkCallContext);
} catch (Exception e) { }
catch (Exception e) {
this.logger.error("查询标签记录数据失败"); this.logger.error("查询标签记录数据失败");
} }
return recordList; return recordList;
} }
private void exportUpload(String businessId, String fileId, String zipPathStr) throws IOException { private void exportUpload(String businessId, String fileId, String zipPathStr) throws IOException {
try { try {
if (StringUtils.isNotBlank(zipPathStr)) { if (StringUtils.isNotBlank((CharSequence)zipPathStr)) {
uploadFile(businessId, fileId, zipPathStr); this.uploadFile(businessId, fileId, zipPathStr);
} else { } else {
byte[] data = Base64Utils.decodeFromString("UEsDBBQACAgIAAuPmlAAAAAAAAAAAAAAAAAGAAAAZW1wdHkvAwBQSwcIAAAAAAIAAAAAAAAAUEsBAhQAFAAICAgAC4+aUAAAAAACAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAGVtcHR5L1BLBQYAAAAAAQABADQAAAA2AAAAAAA="); byte[] data = Base64Utils.decodeFromString((String)"UEsDBBQACAgIAAuPmlAAAAAAAAAAAAAAAAAGAAAAZW1wdHkvAwBQSwcIAAAAAAIAAAAAAAAAUEsBAhQAFAAICAgAC4+aUAAAAAACAAAAAAAAAAYAAAAAAAAAAAAAAAAAAAAAAGVtcHR5L1BLBQYAAAAAAQABADQAAAA2AAAAAAA=");
uploadFile(businessId, fileId, data, data.length); this.uploadFile(businessId, fileId, data, data.length);
} }
} catch (Exception e) { }
this.logger.error("将导出文件生成的zip上传到文件管理中心发生异常:{}", e.getMessage()); catch (Exception e) {
this.logger.error("将导出文件生成的zip上传到文件管理中心发生异常:{}", (Object)e.getMessage());
throw new RuntimeException("将导出文件生成的zip上传到文件管理中心发生异常"); throw new RuntimeException("将导出文件生成的zip上传到文件管理中心发生异常");
} finally { }
this.logger.debug("删除压缩包:{}", zipPathStr); finally {
this.logger.debug("删除压缩包:{}", (Object)zipPathStr);
File file = new File(zipPathStr); File file = new File(zipPathStr);
if (file.exists()) { if (file.exists()) {
Files.delete(file.toPath()); Files.delete(file.toPath());
} }
} }
} }
private void uploadFile(String businessId, String fileId, byte[] data, long fileSize) { private void uploadFile(String businessId, String fileId, byte[] data, long fileSize) {
String uuidCode = UUID.randomUUID().toString().replaceAll("-", ""); String uuidCode = UUID.randomUUID().toString().replaceAll("-", "");
String name = uuidCode + this.commonDownloadDataConfig.getCompressionType(); String name = new StringBuffer(uuidCode).append(this.commonDownloadDataConfig.getCompressionType()).toString();
String filePath = this.commonAppStorageService.saveFileBySharding(name, data); String filePath = this.commonAppStorageService.saveFileBySharding(name, data);
this.logger.info("存储文件名:fileId = {}, filePath = {}", fileId, filePath); this.logger.info("存储文件名:fileId = {}, filePath = {}", (Object)fileId, (Object)filePath);
int status = this.commonAppDownloadCenterService.queryDownloadStatus(businessId, fileId); int status = this.commonAppDownloadCenterService.queryDownloadStatus(businessId, fileId);
if (status == FileStatusEnum.PRODUCING.getCode().intValue() || status == FileStatusEnum.ERROR.getCode().intValue()) { if (status == FileStatusEnum.PRODUCING.getCode() || status == FileStatusEnum.ERROR.getCode()) {
this.commonAppDownloadCenterService.finishDownload(businessId, fileId, filePath, Long.valueOf(fileSize), FileStatusEnum.FINISH.getCode()); this.commonAppDownloadCenterService.finishDownload(businessId, fileId, filePath, Long.valueOf(fileSize), FileStatusEnum.FINISH.getCode());
} else { } else {
this.commonAppStorageService.deleteFile(filePath); this.commonAppStorageService.deleteFile(filePath);
} }
} }
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void uploadFile(String businessId, String fileId, String zipPathStr) throws IOException { private void uploadFile(String businessId, String fileId, String zipPathStr) throws IOException {
ChannelFileReader reader = new ChannelFileReader(zipPathStr, this.shardingSize.intValue()); try (ChannelFileReader reader = new ChannelFileReader(zipPathStr, this.shardingSize);){
try {
String uuidCode = UUID.randomUUID().toString().replaceAll("-", ""); String uuidCode = UUID.randomUUID().toString().replaceAll("-", "");
String name = uuidCode + this.commonDownloadDataConfig.getCompressionType(); String name = new StringBuffer(uuidCode).append(this.commonDownloadDataConfig.getCompressionType()).toString();
FilePartInitResult resp = this.iCommonAppFileManageService.filePartInit(name); FilePartInitResult resp = this.iCommonAppFileManageService.filePartInit(name);
if (resp == null) { if (resp == null) {
this.logger.info("分片上传文件初始化返回值为空"); this.logger.info("分片上传文件初始化返回值为空");
@@ -422,49 +450,43 @@ return;
AtomicInteger i = new AtomicInteger(1); AtomicInteger i = new AtomicInteger(1);
long fileSize = 0L; long fileSize = 0L;
while (reader.read() != -1) { while (reader.read() != -1) {
this.logger.info("分片上传第{}次", Integer.valueOf(i.get())); this.logger.info("分片上传第{}次", (Object)i.get());
fileSize += (reader.getArray()).length; fileSize += (long)reader.getArray().length;
uploadFileBySharding(reader.getArray(), resp.getFilePath(), resp.getUploadId(), this.fileName, String.valueOf(i.getAndAdd(1))); this.uploadFileBySharding(reader.getArray(), resp.getFilePath(), resp.getUploadId(), this.fileName, String.valueOf(i.getAndAdd(1)));
} }
String filePath = filePartFinish(fileSize, resp); String filePath = this.filePartFinish(fileSize, resp);
if (filePath == null) { if (filePath == null) {
this.logger.info("分片上传文件完成接口返回值为空"); this.logger.info("分片上传文件完成接口返回值为空");
return; return;
} }
this.logger.info("分片上传文件完成接口返回值 filePath = {}", filePath); this.logger.info("分片上传文件完成接口返回值 filePath = {}", (Object)filePath);
this.logger.info("存储文件名:fileId = {}, filePath = {}", fileId, filePath); this.logger.info("存储文件名:fileId = {}, filePath = {}", (Object)fileId, (Object)filePath);
int status = this.commonAppDownloadCenterService.queryDownloadStatus(businessId, fileId); int status = this.commonAppDownloadCenterService.queryDownloadStatus(businessId, fileId);
if (status == FileStatusEnum.PRODUCING.getCode().intValue() || status == FileStatusEnum.ERROR.getCode().intValue()) { if (status == FileStatusEnum.PRODUCING.getCode() || status == FileStatusEnum.ERROR.getCode()) {
this.commonAppDownloadCenterService.finishDownload(businessId, fileId, filePath, Long.valueOf(fileSize), FileStatusEnum.FINISH.getCode()); this.commonAppDownloadCenterService.finishDownload(businessId, fileId, filePath, Long.valueOf(fileSize), FileStatusEnum.FINISH.getCode());
} else { } else {
this.commonAppStorageService.deleteFile(filePath); this.commonAppStorageService.deleteFile(filePath);
} }
this.logger.info("完成上传任务 fileId = {}", fileId); this.logger.info("完成上传任务 fileId = {}", (Object)fileId);
} catch (Exception e) {
this.logger.error("分片上传文件报错 {}: {}", e.getClass().getName(), e.getMessage());
} finally {
reader.close();
} }
} }
private String filePartFinish(long fileSize, FilePartInitResult resp) { private String filePartFinish(long fileSize, FilePartInitResult resp) {
FilePartFinishPara para = new FilePartFinishPara(); FilePartFinishPara para = new FilePartFinishPara();
BeanUtils.copyProperties(resp, para); BeanUtils.copyProperties((Object)resp, (Object)para);
para.setFileSize(Long.valueOf(fileSize)); para.setFileSize(Long.valueOf(fileSize));
para.setReturnType(Integer.valueOf(0)); para.setReturnType(Integer.valueOf(0));
return this.iCommonAppFileManageService.filePartFinish(para); return this.iCommonAppFileManageService.filePartFinish(para);
} }
private void uploadFileBySharding(byte[] bytes, String filePath, String uploadId, String fileName, String partNumber) { private void uploadFileBySharding(byte[] bytes, String filePath, String uploadId, String fileName, String partNumber) {
MultipartFile mfile = MultipartFileUtils.getMultipartFile(fileName, bytes); MultipartFile mfile = MultipartFileUtils.getMultipartFile(fileName, bytes);
try { try {
PartInitResultDTO partInitResultDTO = this.filePartManager.append(filePath, Integer.valueOf(partNumber), uploadId, mfile); PartInitResultDTO partInitResultDTO = this.filePartManager.append(filePath, Integer.valueOf(partNumber), uploadId, mfile);
} catch (Exception e) { }
this.logger.error("分片更新文件错误{}:{}", e.getClass().getName(), e.getMessage()); catch (Exception e) {
this.logger.error("分片更新文件错误{}:{}", (Object)e.getClass().getName(), (Object)e.getMessage());
} }
} }
} }
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/export/CommonAppExportExecuteTask.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -203,7 +203,7 @@ PersonBatchImportTask.BATCH_SEMAPHORE.release();
private void cleanFiles(BatchImportContext context) { private void cleanFiles(BatchImportContext context) {
try { try {
FileUtils.deleteDirectory(context.getUnzipFolder()); FileUtils.deleteDirectory(context.getUnzipFolder());
this.personFileService.delete(Lists.newArrayList((Object[])new String[] { context.getBatchImport().getFilePath() })); this.personFileService.delete(Lists.newArrayList(context.getBatchImport().getFilePath() ));
FileUtils.deleteQuietly(new File(this.tempPath, context.getBatchImport().getBatchNo() + ".zip")); FileUtils.deleteQuietly(new File(this.tempPath, context.getBatchImport().getBatchNo() + ".zip"));
} catch (Exception ex) { } catch (Exception ex) {
logger.error("", ex); logger.error("", ex);
@@ -19,9 +19,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
@Service @Service
@EnableAsync @EnableAsync
public class CommonAppExportTaskServiceImpl extends AbstractImagStoreService implements ICommonAppExportTaskService { public class CommonAppExportTaskServiceImpl
extends AbstractImagStoreService
implements ICommonAppExportTaskService {
private static final Logger log = LoggerFactory.getLogger(CommonAppExportTaskServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(CommonAppExportTaskServiceImpl.class);
@Autowired @Autowired
private ICommonAppDownloadCenterService commonAppDownloadCenterService; private ICommonAppDownloadCenterService commonAppDownloadCenterService;
@@ -36,40 +40,44 @@ private ComponentInnerKafkaConfig componentInnerKafkaConfig;
String fileName = "人员信息"; String fileName = "人员信息";
String orgFileName = "机构信息"; String orgFileName = "机构信息";
String labelFileName = "标签信息"; String labelFileName = "标签信息";
public String add(CloudwalkCallContext cloudwalkCallContext, ExportRecordTaskParam task) throws ServiceException { public String add(CloudwalkCallContext cloudwalkCallContext, ExportRecordTaskParam task) throws ServiceException {
String name = createFileName(this.fileName); String name = this.createFileName(this.fileName);
this.logger.info("创建下载任务,任务文件名称:name = {}", name); this.logger.info("创建下载任务,任务文件名称:name = {}", (Object)name);
updateCloudwalkContext(cloudwalkCallContext, task); this.updateCloudwalkContext(cloudwalkCallContext, task);
String fileId = this.commonAppDownloadCenterService.createDownload(cloudwalkCallContext, name, task.getBusinessId()); String fileId = this.commonAppDownloadCenterService.createDownload(cloudwalkCallContext, name, task.getBusinessId());
task.setFileId(fileId); task.setFileId(fileId);
task.setFileName(name); task.setFileName(name);
this.commonAppExportExecuteTask.execute(task, cloudwalkCallContext); this.commonAppExportExecuteTask.execute(task, cloudwalkCallContext);
return fileId; return fileId;
} }
public String addOrgExport(CloudwalkCallContext context, ExportOrgTaskParam task) throws ServiceException { public String addOrgExport(CloudwalkCallContext context, ExportOrgTaskParam task) throws ServiceException {
String name = createFileName(this.orgFileName); String name = this.createFileName(this.orgFileName);
this.logger.info("创建下载任务,任务文件名称:name = {}", name); this.logger.info("创建下载任务,任务文件名称:name = {}", (Object)name);
ExportRecordTaskParam taskParam = new ExportRecordTaskParam(); ExportRecordTaskParam taskParam = new ExportRecordTaskParam();
taskParam.setBusinessId(task.getBusinessId()); taskParam.setBusinessId(task.getBusinessId());
updateCloudwalkContext(context, taskParam); this.updateCloudwalkContext(context, taskParam);
String fileId = this.commonAppDownloadCenterService.createDownload(context, name, task.getBusinessId()); String fileId = this.commonAppDownloadCenterService.createDownload(context, name, task.getBusinessId());
task.setFileId(fileId); task.setFileId(fileId);
task.setFileName(name); task.setFileName(name);
this.commonAppExportExecuteTask.executeOrg(task, context); this.commonAppExportExecuteTask.executeOrg(task, context);
return fileId; return fileId;
} }
public String addLabelExport(CloudwalkCallContext context, ExportLabelTaskParam task) throws ServiceException { public String addLabelExport(CloudwalkCallContext context, ExportLabelTaskParam task) throws ServiceException {
String name = createFileName(this.labelFileName); String name = this.createFileName(this.labelFileName);
this.logger.info("创建下载任务,任务文件名称:name = {}", name); this.logger.info("创建下载任务,任务文件名称:name = {}", (Object)name);
ExportRecordTaskParam taskParam = new ExportRecordTaskParam(); ExportRecordTaskParam taskParam = new ExportRecordTaskParam();
taskParam.setBusinessId(task.getBusinessId()); taskParam.setBusinessId(task.getBusinessId());
updateCloudwalkContext(context, taskParam); this.updateCloudwalkContext(context, taskParam);
String fileId = this.commonAppDownloadCenterService.createDownload(context, name, task.getBusinessId()); String fileId = this.commonAppDownloadCenterService.createDownload(context, name, task.getBusinessId());
task.setFileId(fileId); task.setFileId(fileId);
task.setFileName(name); task.setFileName(name);
this.commonAppExportExecuteTask.executeLabel(task, context); this.commonAppExportExecuteTask.executeLabel(task, context);
return fileId; return fileId;
} }
private void updateCloudwalkContext(CloudwalkCallContext cloudwalkCallContext, ExportRecordTaskParam task) { private void updateCloudwalkContext(CloudwalkCallContext cloudwalkCallContext, ExportRecordTaskParam task) {
cloudwalkCallContext.setServiceCode(this.componentInnerKafkaConfig.getServiceCode()); cloudwalkCallContext.setServiceCode(this.componentInnerKafkaConfig.getServiceCode());
UserContext userContext = new UserContext(); UserContext userContext = new UserContext();
@@ -80,6 +88,7 @@ CompanyContext companyContext = new CompanyContext();
companyContext.setCompanyId(task.getBusinessId()); companyContext.setCompanyId(task.getBusinessId());
cloudwalkCallContext.setCompany(companyContext); cloudwalkCallContext.setCompany(companyContext);
} }
private String createFileName(String type) { private String createFileName(String type) {
StringBuilder nameBuilder = new StringBuilder(); StringBuilder nameBuilder = new StringBuilder();
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
@@ -92,8 +101,3 @@ return nameBuilder.toString();
} }
} }
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/CommonAppExportTaskServiceImpl.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -13,11 +13,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service @Service
public class CommonAppFileManageServiceImpl implements ICommonAppFileManageService { public class CommonAppFileManageServiceImpl
implements ICommonAppFileManageService {
private static final Logger log = LoggerFactory.getLogger(CommonAppFileManageServiceImpl.class); private static final Logger log = LoggerFactory.getLogger(CommonAppFileManageServiceImpl.class);
@Autowired @Autowired
private FilePartManager filePartManager; private FilePartManager filePartManager;
public FilePartInitResult filePartInit(String fileName) { public FilePartInitResult filePartInit(String fileName) {
FilePartInitResult result = new FilePartInitResult(); FilePartInitResult result = new FilePartInitResult();
PartInitDTO dto = new PartInitDTO(); PartInitDTO dto = new PartInitDTO();
@@ -25,15 +29,18 @@ dto.setFileName(fileName);
PartInitResultDTO partInitResultDTO = new PartInitResultDTO(); PartInitResultDTO partInitResultDTO = new PartInitResultDTO();
try { try {
partInitResultDTO = this.filePartManager.init(dto); partInitResultDTO = this.filePartManager.init(dto);
} catch (DavinciServiceException e) {
log.error("分片上传文件初始化接口错误 request = {}", fileName);
} }
BeanUtils.copyProperties(partInitResultDTO, result); catch (DavinciServiceException e) {
log.error("分片上传文件初始化接口错误 request = {}", (Object)fileName);
}
BeanUtils.copyProperties((Object)partInitResultDTO, (Object)result);
return result; return result;
} }
public FilePartInitResult filePartAppend(FilePartAppendPara para) { public FilePartInitResult filePartAppend(FilePartAppendPara para) {
return null; return null;
} }
public String filePartFinish(FilePartFinishPara para) { public String filePartFinish(FilePartFinishPara para) {
PartFinishDTO partFinishDTO = new PartFinishDTO(); PartFinishDTO partFinishDTO = new PartFinishDTO();
partFinishDTO.setFilePath(para.getFilePath()); partFinishDTO.setFilePath(para.getFilePath());
@@ -42,15 +49,11 @@ partFinishDTO.setReturnType(para.getReturnType());
partFinishDTO.setUploadId(para.getUploadId()); partFinishDTO.setUploadId(para.getUploadId());
try { try {
return this.filePartManager.finish(partFinishDTO); return this.filePartManager.finish(partFinishDTO);
} catch (DavinciServiceException e) { }
log.error("分片上传文件完成接口错误{}:{}", e.getClass().getName(), e.getMessage()); catch (DavinciServiceException e) {
log.error("分片上传文件完成接口错误{}:{}", (Object)((Object)((Object)e)).getClass().getName(), (Object)e.getMessage());
return null; return null;
} }
} }
} }
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/CommonAppFileManageServiceImpl.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -687,7 +687,7 @@ groupPersonRefParam.setGroupStatus(GroupModelStatusEnum.MODEL_WAIT.getCode());
} }
} }
} }
this.groupPersonRefMapper.updateImageData(groupPersonRefParam, Lists.newArrayList((Object[])new String[] { imgStorePerson.getId() })); this.groupPersonRefMapper.updateImageData(groupPersonRefParam, Lists.newArrayList(imgStorePerson.getId() ));
} }
} }
public CloudwalkResult<CloudwalkPageAble<ImageStorePersonResult>> page(QueryImageStorePersonParam queryParam, CloudwalkCallContext context) { public CloudwalkResult<CloudwalkPageAble<ImageStorePersonResult>> page(QueryImageStorePersonParam queryParam, CloudwalkCallContext context) {
@@ -106,9 +106,9 @@ handleGroupPersonSynTask(imageStoreId);
public void addGroupPersonSynTask(String imageStoreId, String personId, boolean isAdd) { public void addGroupPersonSynTask(String imageStoreId, String personId, boolean isAdd) {
GroupPersonSynData groupPersonSynData = new GroupPersonSynData(); GroupPersonSynData groupPersonSynData = new GroupPersonSynData();
if (isAdd) { if (isAdd) {
groupPersonSynData.setAddPersonIds(Lists.newArrayList((Object[])new String[] { personId })); groupPersonSynData.setAddPersonIds(Lists.newArrayList(personId ));
} else { } else {
groupPersonSynData.setDelPersonIds(Lists.newArrayList((Object[])new String[] { personId })); groupPersonSynData.setDelPersonIds(Lists.newArrayList(personId ));
} }
String jsonData = JsonUtils.toJson(groupPersonSynData); String jsonData = JsonUtils.toJson(groupPersonSynData);
addWaitSynTask(imageStoreId, jsonData); addWaitSynTask(imageStoreId, jsonData);
@@ -138,7 +138,7 @@ Map<String, GroupPersonRef> imageStoreIdsMap = this.cpImageStorePersonManager.ge
List<String> imageStoreIds = Lists.newArrayList(imageStoreIdsMap.keySet()); List<String> imageStoreIds = Lists.newArrayList(imageStoreIdsMap.keySet());
if (Collections3.isNotEmpty(imageStoreIds)) { if (Collections3.isNotEmpty(imageStoreIds)) {
GroupPersonSynData groupPersonSynData = new GroupPersonSynData(); GroupPersonSynData groupPersonSynData = new GroupPersonSynData();
groupPersonSynData.setAddPersonIds(Lists.newArrayList((Object[])new String[] { personId })); groupPersonSynData.setAddPersonIds(Lists.newArrayList(personId ));
String jsonData = JsonUtils.toJson(groupPersonSynData); String jsonData = JsonUtils.toJson(groupPersonSynData);
for (String imageStoreId : imageStoreIds) { for (String imageStoreId : imageStoreIds) {
addWaitSynTask(imageStoreId, jsonData); addWaitSynTask(imageStoreId, jsonData);
@@ -171,7 +171,7 @@ List<String> imageStoreIdsNeedDelete = Lists.newArrayList(imageStoreIdsBefore);
this.logger.info("addGroupPersonSynTask - 新增图库待同步任务(更新人员注册照) imageStoreIdsAfter{}imageStoreIdsNeedDelete: {}", imageStoreIds, imageStoreIdsNeedDelete); this.logger.info("addGroupPersonSynTask - 新增图库待同步任务(更新人员注册照) imageStoreIdsAfter{}imageStoreIdsNeedDelete: {}", imageStoreIds, imageStoreIdsNeedDelete);
if (Collections3.isNotEmpty(imageStoreIdsNeedDelete)) { if (Collections3.isNotEmpty(imageStoreIdsNeedDelete)) {
GroupPersonSynData groupPersonSynData = new GroupPersonSynData(); GroupPersonSynData groupPersonSynData = new GroupPersonSynData();
groupPersonSynData.setDelPersonIds(Lists.newArrayList((Object[])new String[] { personId })); groupPersonSynData.setDelPersonIds(Lists.newArrayList(personId ));
String jsonData = JsonUtils.toJson(groupPersonSynData); String jsonData = JsonUtils.toJson(groupPersonSynData);
for (String imageStoreId : imageStoreIdsNeedDelete) { for (String imageStoreId : imageStoreIdsNeedDelete) {
addWaitSynTask(imageStoreId, jsonData); addWaitSynTask(imageStoreId, jsonData);
@@ -408,11 +408,11 @@ List<SyncPersonDTO> syncPersonList = Lists.newArrayList();
if (StringUtils.isNotBlank(synData.getPersonId())) { if (StringUtils.isNotBlank(synData.getPersonId())) {
this.logger.info("CpImageStorePersonSynManager handleImageStoreIncrementSyn 单人员更新注册照:{}{}", synData this.logger.info("CpImageStorePersonSynManager handleImageStoreIncrementSyn 单人员更新注册照:{}{}", synData
.getPersonId(), synData.getOldImageId()); .getPersonId(), synData.getOldImageId());
Map<String, GroupPersonRef> associatedPersonResultsAfterUpdate = this.cpImageStorePersonManager.getGroupPersonRefByPersons(waitSyncImageStore.getId(), Lists.newArrayList((Object[])new String[] { synData.getPersonId() })); Map<String, GroupPersonRef> associatedPersonResultsAfterUpdate = this.cpImageStorePersonManager.getGroupPersonRefByPersons(waitSyncImageStore.getId(), Lists.newArrayList(synData.getPersonId() ));
Map<String, GroupPersonRef> associatedPersonResultsBeforeUpdate = this.cpImageStorePersonManager.getOldAssociatedPersonIds(waitSyncImageStore.getId(), Lists.newArrayList((Object[])new String[] { synData.getPersonId() })); Map<String, GroupPersonRef> associatedPersonResultsBeforeUpdate = this.cpImageStorePersonManager.getOldAssociatedPersonIds(waitSyncImageStore.getId(), Lists.newArrayList(synData.getPersonId() ));
GroupPersonRef refAfterUpdate = associatedPersonResultsAfterUpdate.get(synData.getPersonId()); GroupPersonRef refAfterUpdate = associatedPersonResultsAfterUpdate.get(synData.getPersonId());
if (refAfterUpdate != null) { if (refAfterUpdate != null) {
List<ImgStorePerson> associatedPersonExpiryDateAfterUpdate = this.imgStorePersonMapper.selectExpiryDateByIds(Lists.newArrayList((Object[])new String[] { synData.getPersonId() })); List<ImgStorePerson> associatedPersonExpiryDateAfterUpdate = this.imgStorePersonMapper.selectExpiryDateByIds(Lists.newArrayList(synData.getPersonId() ));
if (CollectionUtil.isNotEmpty(associatedPersonExpiryDateAfterUpdate)) { if (CollectionUtil.isNotEmpty(associatedPersonExpiryDateAfterUpdate)) {
ImgStorePerson personExpiryDate = associatedPersonExpiryDateAfterUpdate.get(0); ImgStorePerson personExpiryDate = associatedPersonExpiryDateAfterUpdate.get(0);
if (personExpiryDate.getExpiryBeginDate() != null || personExpiryDate.getExpiryEndDate() != null) { if (personExpiryDate.getExpiryBeginDate() != null || personExpiryDate.getExpiryEndDate() != null) {
@@ -228,7 +228,7 @@ this.groupPersonRefMapper.logicDeleteExpireNullByParam(deleteParam);
} }
for (String deleteImageStoreId : imageStoreIdsNeedDelete) { for (String deleteImageStoreId : imageStoreIdsNeedDelete) {
handleImageStoreImageChange(deleteImageStoreId, handleImageStoreImageChange(deleteImageStoreId,
Sets.newHashSet((Object[])new String[] { imgStorePerson.getImageId() }), false); Sets.newHashSet(imgStorePerson.getImageId() ), false);
} }
} }
@Async("handleImageTaskExecutor") @Async("handleImageTaskExecutor")
@@ -1,14 +1,24 @@
package cn.cloudwalk.service.organization.service; package cn.cloudwalk.service.organization.service;
// 业务服务 // 业务服务
import cn.cloudwalk.client.organization.service.store.utils.SnowFlake; import cn.cloudwalk.client.organization.service.store.utils.SnowFlake;
import cn.cloudwalk.data.organization.dto.QueryGroupPersonDTO; import cn.cloudwalk.data.organization.dto.QueryGroupPersonDTO;
import cn.cloudwalk.data.organization.dto.SyncPersonDTO; import cn.cloudwalk.data.organization.dto.SyncPersonDTO;
import cn.cloudwalk.data.organization.entity.GroupPersonRef; import cn.cloudwalk.data.organization.entity.GroupPersonRef;
import cn.cloudwalk.data.organization.mapper.GroupPersonRefMapper;
import cn.cloudwalk.service.organization.common.JsonUtils; import cn.cloudwalk.service.organization.common.JsonUtils;
import cn.cloudwalk.service.organization.service.CpImageStorePersonTxHandler;
import cn.cloudwalk.service.organization.service.CpImageStoreSyncManager;
import cn.cloudwalk.service.organization.utils.BeanCopyUtils; import cn.cloudwalk.service.organization.utils.BeanCopyUtils;
import cn.cloudwalk.task.sdk.client.TaskExecClient;
import cn.cloudwalk.task.sdk.starter.config.init.properties.QuartzTaskProperties;
import cn.hutool.core.collection.ConcurrentHashSet; import cn.hutool.core.collection.ConcurrentHashSet;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@@ -18,30 +28,35 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.redis.core.RedisCallback;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.quartz.Scheduler; import org.quartz.Scheduler;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import org.quartz.Trigger; import org.quartz.Trigger;
import org.quartz.TriggerBuilder; import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.ReturnType; import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript; import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@Service @Service
public class CpImageStorePersonValidateManager { public class CpImageStorePersonValidateManager {
private static final Logger log = LoggerFactory.getLogger(CpImageStorePersonValidateManager.class); private static final Logger log = LoggerFactory.getLogger(CpImageStorePersonValidateManager.class);
private final String VALIDATE_JOB_GROUP_LOCK = "validate_job_group_lock:"; private final String VALIDATE_JOB_GROUP_LOCK = "validate_job_group_lock:";
@Value("${group-person.syn.config.lock-validate-job-group-second:30}") @Value(value="${group-person.syn.config.lock-validate-job-group-second:30}")
private String lockValidateJobGroupSecond; private String lockValidateJobGroupSecond;
@Value("${group-person.syn.config.lock-validate-job-group-time-out:120}") @Value(value="${group-person.syn.config.lock-validate-job-group-time-out:120}")
private String lockValidateJobGroupTimeOut; private String lockValidateJobGroupTimeOut;
@Value("${group-person.syn.config.delay-add-validate-data:false}") @Value(value="${group-person.syn.config.delay-add-validate-data:false}")
private Boolean delayAddValidateData; private Boolean delayAddValidateData;
@Value("${group-person.syn.config.delay-add-validate-hour:48}") @Value(value="${group-person.syn.config.delay-add-validate-hour:48}")
private Long delayAddValidateHour; private Long delayAddValidateHour;
@Autowired @Autowired
private QuartzTaskProperties quartzTaskProperties; private QuartzTaskProperties quartzTaskProperties;
@@ -59,330 +74,311 @@ private DefaultRedisScript<String> lockValidateJobRedisScript;
private DefaultRedisScript<String> unlockValidateJobRedisScript; private DefaultRedisScript<String> unlockValidateJobRedisScript;
@Resource @Resource
private GroupPersonRefMapper groupPersonRefMapper; private GroupPersonRefMapper groupPersonRefMapper;
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void addValidateData(List<SyncPersonDTO> syncPersonList) { public void addValidateData(List<SyncPersonDTO> syncPersonList) {
log.info("bind接口service 查询syncPersonList{}", JSONObject.toJSONString(syncPersonList)); Long lockValue;
ConcurrentHashSet concurrentHashSet = new ConcurrentHashSet(); log.info("bind接口service 查询syncPersonList{}", (Object)JSONObject.toJSONString(syncPersonList));
Map<Long, Set<SyncPersonLocal>> addMap = new ConcurrentHashMap<>(); ConcurrentHashSet deleteSet = new ConcurrentHashSet();
Map<Long, Set<SyncPersonLocal>> removeMap = new ConcurrentHashMap<>(); ConcurrentHashMap addMap = new ConcurrentHashMap();
ConcurrentHashSet<SyncPersonDTO> concurrentHashSet1 = new ConcurrentHashSet(); ConcurrentHashMap removeMap = new ConcurrentHashMap();
Set<String> changeGroupIdSet = Sets.newHashSet(); ConcurrentHashSet addSet = new ConcurrentHashSet();
HashSet changeGroupIdSet = Sets.newHashSet();
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
syncPersonList.parallelStream().forEach(syncPersonDTO -> { syncPersonList.parallelStream().forEach(arg_0 -> this.lambda$addValidateData$4(changeGroupIdSet, currentTime, (Set)deleteSet, removeMap, addMap, (Set)addSet, arg_0));
syncPersonDTO.setOldExpiryBeginDate(Optional.<Long>ofNullable(syncPersonDTO.getOldExpiryBeginDate()).orElse(null)); Iterator iterator = addSet.iterator();
syncPersonDTO.setOldExpiryEndDate(Optional.<Long>ofNullable(syncPersonDTO.getOldExpiryEndDate()).orElse(null));
syncPersonDTO.setNewExpiryBeginDate(Optional.<Long>ofNullable(syncPersonDTO.getNewExpiryBeginDate()).orElse(null));
syncPersonDTO.setNewExpiryEndDate(Optional.<Long>ofNullable(syncPersonDTO.getNewExpiryEndDate()).orElse(null));
changeGroupIdSet.add(syncPersonDTO.getImageStoreId());
int action = syncPersonDTO.getAction();
switch (action) {
case -1:
delDataManager(currentTime, syncPersonDTO, deleteSet, removeMap, addMap);
break;
case 0:
addDataManager(currentTime, syncPersonDTO, addSet, removeMap, addMap);
break;
case 1:
updateDataManage(currentTime, syncPersonDTO, deleteSet, addSet, removeMap, addMap);
break;
}
});
Iterator<SyncPersonDTO> iterator = concurrentHashSet1.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
SyncPersonDTO syncPersonDTO = iterator.next(); SyncPersonDTO syncPersonDTO = (SyncPersonDTO)iterator.next();
if (concurrentHashSet.contains(syncPersonDTO)) { if (deleteSet.contains(syncPersonDTO)) {
concurrentHashSet.remove(syncPersonDTO); deleteSet.remove(syncPersonDTO);
iterator.remove(); continue;
} if (StringUtils.isBlank(syncPersonDTO.getImageId())) {
iterator.remove(); iterator.remove();
}
}
Scheduler scheduler = this.taskExecClient.getScheduler(this.quartzTaskProperties.getSchedulerName());
for (Map.Entry<Long, Set<SyncPersonLocal>> entry : removeMap.entrySet()) {
Long key = entry.getKey();
Long lockValue = Long.valueOf(SnowFlake.nextId());
try { if (validateJobGroupLock(key, lockValue))
{ TriggerKey triggerKey = TriggerKey.triggerKey(key.toString(), "QZ_PERSON_VALIDATE_JOB");
Trigger trigger = scheduler.getTrigger(triggerKey);
if (trigger == null)
{
validateJobGroupUnLock(key, lockValue); continue; } String dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY"); if (StringUtils.isNotBlank(dataSet)) { List<SyncPersonLocal> syncPersonDTOS = JsonUtils.toObjList(dataSet, SyncPersonLocal.class); syncPersonDTOS = removeAll(syncPersonDTOS, entry.getValue()); if (addMap.containsKey(key)) { Set<SyncPersonLocal> keyAddSet = addMap.get(key); syncPersonDTOS = addAll(syncPersonDTOS, keyAddSet); addMap.remove(key); } trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDTOS)); scheduler.rescheduleJob(triggerKey, trigger); } } else { log.error("CpImageStorePersonValidateManager addValidateData removeJob time out"); } } catch (SchedulerException e) { log.error("获取trigger异常:{}", e.getLocalizedMessage()); } catch (Exception e) { log.error("移除trigger未知异常:{}", e.getMessage()); } finally { validateJobGroupUnLock(key, lockValue); }
}
for (Map.Entry<Long, Set<SyncPersonLocal>> entry : addMap.entrySet()) {
if (!((Set)entry.getValue()).isEmpty()) {
Long key = entry.getKey();
Long lockValue = Long.valueOf(SnowFlake.nextId());
Long addValidateTime = Long.valueOf(currentTime + this.delayAddValidateHour.longValue() * 60L * 60L * 1000L);
if (this.delayAddValidateData.booleanValue() && key.longValue() > addValidateTime.longValue()) {
continue; continue;
} }
if (!StringUtils.isBlank((CharSequence)syncPersonDTO.getImageId())) continue;
iterator.remove();
}
Scheduler scheduler = this.taskExecClient.getScheduler(this.quartzTaskProperties.getSchedulerName());
for (Map.Entry<Long, Set<SyncPersonLocal>> entry : ((Map<Long, Set<SyncPersonLocal>>) (Map) removeMap).entrySet()) {
Long l = (Long)entry.getKey();
lockValue = SnowFlake.nextId();
try { try {
if (validateJobGroupLock(key, lockValue)) { if (this.validateJobGroupLock(l, lockValue)) {
TriggerKey triggerKey = TriggerKey.triggerKey(key.toString(), "QZ_PERSON_VALIDATE_JOB"); String dataSet;
TriggerKey triggerKey = TriggerKey.triggerKey((String)l.toString(), (String)"QZ_PERSON_VALIDATE_JOB");
Trigger trigger = scheduler.getTrigger(triggerKey);
if (trigger == null || !StringUtils.isNotBlank((CharSequence)(dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY")))) continue;
List<SyncPersonLocal> syncPersonDTOS = JsonUtils.toObjList(dataSet, SyncPersonLocal.class);
syncPersonDTOS = CpImageStorePersonValidateManager.removeAll(syncPersonDTOS, entry.getValue());
if (addMap.containsKey(l)) {
Set keyAddSet = (Set)addMap.get(l);
syncPersonDTOS = CpImageStorePersonValidateManager.addAll(syncPersonDTOS, keyAddSet);
addMap.remove(l);
}
trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDTOS));
scheduler.rescheduleJob(triggerKey, trigger);
continue;
}
log.error("CpImageStorePersonValidateManager addValidateData removeJob time out");
}
catch (SchedulerException e) {
log.error("获取trigger异常:{}", (Object)e.getLocalizedMessage());
}
catch (Exception e) {
log.error("移除trigger未知异常:{}", (Object)e.getMessage());
}
finally {
this.validateJobGroupUnLock(l, lockValue);
}
}
for (Map.Entry<Long, Set<SyncPersonLocal>> entry : ((Map<Long, Set<SyncPersonLocal>>) (Map) addMap).entrySet()) {
if (((Set)entry.getValue()).isEmpty()) continue;
Long l = (Long)entry.getKey();
lockValue = SnowFlake.nextId();
Long addValidateTime = currentTime + this.delayAddValidateHour * 60L * 60L * 1000L;
if (this.delayAddValidateData.booleanValue() && l > addValidateTime) continue;
try {
if (this.validateJobGroupLock(l, lockValue)) {
TriggerKey triggerKey = TriggerKey.triggerKey((String)l.toString(), (String)"QZ_PERSON_VALIDATE_JOB");
Trigger trigger = scheduler.getTrigger(triggerKey); Trigger trigger = scheduler.getTrigger(triggerKey);
if (trigger == null) { if (trigger == null) {
trigger = TriggerBuilder.newTrigger().withIdentity(key.toString(), "QZ_PERSON_VALIDATE_JOB").withDescription("trigger at:" + key).forJob("PERSON_VALIDATE_JOB_NAME", "QZ_PERSON_VALIDATE_JOB").startAt(new Date(key.longValue())).usingJobData("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(entry.getValue())).build(); trigger = TriggerBuilder.newTrigger().withIdentity(l.toString(), "QZ_PERSON_VALIDATE_JOB").withDescription("trigger at:" + l).forJob("PERSON_VALIDATE_JOB_NAME", "QZ_PERSON_VALIDATE_JOB").startAt(new Date(l)).usingJobData("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(entry.getValue())).build();
scheduler.scheduleJob(trigger); scheduler.scheduleJob(trigger);
} else { continue;
String dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY");
if (StringUtils.isNotBlank(dataSet)) {
syncPersonDtoList = JsonUtils.toObjList(dataSet, SyncPersonLocal.class);
} else {
syncPersonDtoList = Lists.newArrayList();
} }
List<SyncPersonLocal> syncPersonDtoList = addAll(syncPersonDtoList, entry.getValue()); String dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY");
List<SyncPersonLocal> syncPersonDtoList = StringUtils.isNotBlank((CharSequence)dataSet) ? JsonUtils.toObjList(dataSet, SyncPersonLocal.class) : new ArrayList<>();
syncPersonDtoList = CpImageStorePersonValidateManager.addAll(syncPersonDtoList, entry.getValue());
trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDtoList)); trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDtoList));
scheduler.rescheduleJob(triggerKey, trigger); scheduler.rescheduleJob(triggerKey, trigger);
continue;
} }
} else {
log.error("CpImageStorePersonValidateManager addValidateData addOrModJob time out"); log.error("CpImageStorePersonValidateManager addValidateData addOrModJob time out");
} }
} catch (SchedulerException e) { catch (SchedulerException e) {
log.error("添加trigger异常:{}", e.getLocalizedMessage()); log.error("添加trigger异常:{}", (Object)e.getLocalizedMessage());
} catch (Exception e) { }
log.error("添加trigger未知异常:{}", e.getMessage()); catch (Exception e) {
} finally { log.error("添加trigger未知异常:{}", (Object)e.getMessage());
validateJobGroupUnLock(key, lockValue); }
finally {
this.validateJobGroupUnLock(l, lockValue);
} }
} }
} this.updateExpiryDateStatus(currentTime, syncPersonList);
updateExpiryDateStatus(Long.valueOf(currentTime), syncPersonList); Map<String, List<SyncPersonDTO>> deleteImageMap = (Map<String, List<SyncPersonDTO>>) (Map) deleteSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
Map<String, List<SyncPersonDTO>> deleteImageMap = (Map<String, List<SyncPersonDTO>>)concurrentHashSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
for (Map.Entry<String, List<SyncPersonDTO>> entry : deleteImageMap.entrySet()) { for (Map.Entry<String, List<SyncPersonDTO>> entry : deleteImageMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet()); Set<String> keySet = entry.getValue().parallelStream().map(s -> s.getImageId()).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, false); this.cpImageStorePersonTxHandler.handleImageStoreImageChange((String)entry.getKey(), keySet, false);
} }
Map<String, List<SyncPersonDTO>> addImageMap = (Map<String, List<SyncPersonDTO>>)concurrentHashSet1.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId)); Map<String, List<SyncPersonDTO>> addImageMap = (java.util.Map<java.lang.String,java.util.List<cn.cloudwalk.data.organization.dto.SyncPersonDTO>>) addSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
for (Map.Entry<String, List<SyncPersonDTO>> entry : addImageMap.entrySet()) { for (Map.Entry<String, List<SyncPersonDTO>> entry : addImageMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet()); Set<String> keySet = entry.getValue().parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true); this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true);
} }
this.cpImageStoreSyncManager.sendChangeToDevice(changeGroupIdSet, false); this.cpImageStoreSyncManager.sendChangeToDevice(changeGroupIdSet, false);
} }
private void updateExpiryDateStatus(Long currentTime, List<SyncPersonDTO> syncPersonList) { private void updateExpiryDateStatus(Long currentTime, List<SyncPersonDTO> syncPersonList) {
GroupPersonRef groupPersonRef = new GroupPersonRef(); GroupPersonRef groupPersonRef = new GroupPersonRef();
syncPersonList.stream().forEach(syncPerson -> { syncPersonList.stream().forEach(syncPerson -> {
Long addValidateTime = Long.valueOf(currentTime.longValue() + this.delayAddValidateHour.longValue() * 60L * 60L * 1000L); Long addValidateTime = currentTime + this.delayAddValidateHour * 60L * 60L * 1000L;
groupPersonRef.setId(syncPerson.getGroupPersonRefId()); groupPersonRef.setId(syncPerson.getGroupPersonRefId());
groupPersonRef.setExpiryBeginDateStatus(Integer.valueOf(1)); groupPersonRef.setExpiryBeginDateStatus(Integer.valueOf(1));
if (this.delayAddValidateData.booleanValue() && null != syncPerson.getNewExpiryBeginDate() && syncPerson.getNewExpiryBeginDate().longValue() > addValidateTime.longValue()) { if (this.delayAddValidateData.booleanValue() && null != syncPerson.getNewExpiryBeginDate() && syncPerson.getNewExpiryBeginDate() > addValidateTime) {
groupPersonRef.setExpiryBeginDateStatus(Integer.valueOf(0)); groupPersonRef.setExpiryBeginDateStatus(Integer.valueOf(0));
} }
groupPersonRef.setExpiryEndDateStatus(Integer.valueOf(1)); groupPersonRef.setExpiryEndDateStatus(Integer.valueOf(1));
if (this.delayAddValidateData.booleanValue() && null != syncPerson.getNewExpiryEndDate() && syncPerson.getNewExpiryEndDate().longValue() > addValidateTime.longValue()) { if (this.delayAddValidateData.booleanValue() && null != syncPerson.getNewExpiryEndDate() && syncPerson.getNewExpiryEndDate() > addValidateTime) {
groupPersonRef.setExpiryEndDateStatus(Integer.valueOf(0)); groupPersonRef.setExpiryEndDateStatus(Integer.valueOf(0));
} }
Set<String> ids = new HashSet<>(); HashSet<String> ids = new HashSet<String>();
ids.add(groupPersonRef.getId()); ids.add(groupPersonRef.getId());
this.groupPersonRefMapper.updateStatusByIds(groupPersonRef, ids); this.groupPersonRefMapper.updateStatusByIds(groupPersonRef, ids);
}); });
} }
private boolean validateJobGroupLock(Long key, Long lockValue) { private boolean validateJobGroupLock(Long key, Long lockValue) {
Long start = Long.valueOf(System.currentTimeMillis()); Long start = System.currentTimeMillis();
log.info("CpImageStorePersonValidateManager validateJobGroupLock{},{},{}", new Object[]{key, lockValue, start}); log.info("CpImageStorePersonValidateManager validateJobGroupLock{},{},{}", new Object[]{key, lockValue, start});
String lockKey = "validate_job_group_lock:" + key; String lockKey = "validate_job_group_lock:" + key;
while (true) { while (true) {
Long lockResult = (Long)this.redisTemplate.execute(connection -> (Long)connection.eval(this.lockValidateJobRedisScript.getScriptAsString().getBytes(), ReturnType.INTEGER, 0, new byte[][] { lockKey.getBytes(), String.valueOf(lockValue).getBytes(), this.lockValidateJobGroupSecond.getBytes() })); Long lockResult;
if (0L == lockResult.longValue()) { if (0L == (lockResult = (Long)this.redisTemplate.execute((RedisCallback) connection -> (Long)connection.eval(this.lockValidateJobRedisScript.getScriptAsString().getBytes(), ReturnType.INTEGER, 0, (byte[][])new byte[][]{lockKey.getBytes(), String.valueOf(lockValue).getBytes(), this.lockValidateJobGroupSecond.getBytes()})))) {
log.info("CpImageStorePersonValidateManager validateJobGroupLock success:{}", key); log.info("CpImageStorePersonValidateManager validateJobGroupLock success:{}", (Object)key);
return true; return true;
} }
long waitTime = System.currentTimeMillis() - start.longValue(); long waitTime = System.currentTimeMillis() - start;
log.info("CpImageStorePersonValidateManager validateJobGroupLock wait{},{}", key, Long.valueOf(waitTime)); log.info("CpImageStorePersonValidateManager validateJobGroupLock wait{},{}", (Object)key, (Object)waitTime);
if (waitTime >= Long.valueOf(this.lockValidateJobGroupTimeOut).longValue()) { if (waitTime >= Long.valueOf(this.lockValidateJobGroupTimeOut)) {
log.info("CpImageStorePersonValidateManager validateJobGroupLock wait out:{}", key); log.info("CpImageStorePersonValidateManager validateJobGroupLock wait out:{}", (Object)key);
return false; return false;
} }
try { try {
Thread.sleep(100L); Thread.sleep(100L);
} catch (InterruptedException e) { continue;
}
catch (InterruptedException e) {
log.error("CpImageStorePersonValidateManager validateJobGroupLock sleep error:", e); log.error("CpImageStorePersonValidateManager validateJobGroupLock sleep error:", e);
Thread.currentThread().interrupt(); Thread.currentThread().interrupt();
continue;
}
break;
} }
} }
}
private boolean validateJobGroupUnLock(Long key, Long lockValue) { private boolean validateJobGroupUnLock(Long key, Long lockValue) {
log.info("CpImageStorePersonValidateManager validateJobGroupUnLock{},{}", key, lockValue); log.info("CpImageStorePersonValidateManager validateJobGroupUnLock{},{}", (Object)key, (Object)lockValue);
String lockKey = "validate_job_group_lock:" + key; String lockKey = "validate_job_group_lock:" + key;
Long lockResult = (Long)this.redisTemplate.execute(connection -> (Long)connection.eval(this.unlockValidateJobRedisScript.getScriptAsString().getBytes(), ReturnType.INTEGER, 0, new byte[][] { lockKey.getBytes(), String.valueOf(lockValue).getBytes() })); Long lockResult = (Long)this.redisTemplate.execute((RedisCallback) connection -> (Long)connection.eval(this.unlockValidateJobRedisScript.getScriptAsString().getBytes(), ReturnType.INTEGER, 0, (byte[][])new byte[][]{lockKey.getBytes(), String.valueOf(lockValue).getBytes()}));
if (0L == lockResult.longValue()) { if (0L == lockResult) {
log.info("CpImageStorePersonValidateManager validateJobGroupUnLock success{},{}", key, lockValue); log.info("CpImageStorePersonValidateManager validateJobGroupUnLock success{},{}", (Object)key, (Object)lockValue);
return true; return true;
} }
log.error("CpImageStorePersonValidateManager validateJobGroupUnLock fail{},{}", key, lockValue); log.error("CpImageStorePersonValidateManager validateJobGroupUnLock fail{},{}", (Object)key, (Object)lockValue);
return false; return false;
} }
private void delDataManager(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> deleteSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) { private void delDataManager(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> deleteSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) {
Set timeSet;
Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate(); Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate();
Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate(); Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate();
Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate(); Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate();
Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate(); Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate();
deleteSet.add(syncPersonDTO); deleteSet.add(syncPersonDTO);
if (oldExpiryBeginDate != null) { if (oldExpiryBeginDate != null) {
Set<SyncPersonLocal> removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet()); Set removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet());
removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
.getImageId(), 0));
} }
if (oldExpiryEndDate != null) { if (oldExpiryEndDate != null) {
Set<SyncPersonLocal> removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet()); Set removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet());
removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
.getImageId(), -1));
} }
if (newExpiryBeginDate != null && newExpiryBeginDate.longValue() > currentTime) { if (newExpiryBeginDate != null && newExpiryBeginDate > currentTime) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
} }
if (newExpiryEndDate != null && newExpiryEndDate.longValue() > currentTime) { if (newExpiryEndDate != null && newExpiryEndDate > currentTime) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
} }
} }
private void addDataManager(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> addSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) { private void addDataManager(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> addSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) {
Set timeSet;
Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate(); Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate();
Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate(); Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate();
Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate(); Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate();
Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate(); Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate();
if (newExpiryBeginDate == null || newExpiryBeginDate.longValue() <= currentTime) { if (newExpiryBeginDate == null || newExpiryBeginDate <= currentTime) {
addSet.add(syncPersonDTO); addSet.add(syncPersonDTO);
} else { } else {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
} }
if (newExpiryEndDate != null && newExpiryEndDate.longValue() <= currentTime) { if (newExpiryEndDate != null && newExpiryEndDate <= currentTime) {
addSet.remove(syncPersonDTO); addSet.remove(syncPersonDTO);
} else if (newExpiryEndDate != null) { } else if (newExpiryEndDate != null) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
} }
if (oldExpiryBeginDate != null) { if (oldExpiryBeginDate != null) {
Set<SyncPersonLocal> removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet()); Set removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet());
removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
.getImageId(), 0));
} }
if (oldExpiryEndDate != null) { if (oldExpiryEndDate != null) {
Set<SyncPersonLocal> removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet()); Set removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet());
removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
.getImageId(), -1));
} }
} }
private void updateDataManage(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> deleteSet, Set<SyncPersonDTO> addSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) { private void updateDataManage(long currentTime, SyncPersonDTO syncPersonDTO, Set<SyncPersonDTO> deleteSet, Set<SyncPersonDTO> addSet, Map<Long, Set<SyncPersonLocal>> removeMap, Map<Long, Set<SyncPersonLocal>> addMap) {
Set timeSet;
boolean addFlag;
String oldImageId = syncPersonDTO.getOldImageId(); String oldImageId = syncPersonDTO.getOldImageId();
Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate(); Long oldExpiryBeginDate = syncPersonDTO.getOldExpiryBeginDate();
Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate(); Long oldExpiryEndDate = syncPersonDTO.getOldExpiryEndDate();
Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate(); Long newExpiryBeginDate = syncPersonDTO.getNewExpiryBeginDate();
Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate(); Long newExpiryEndDate = syncPersonDTO.getNewExpiryEndDate();
boolean addFlag = ((newExpiryBeginDate == null || newExpiryBeginDate.longValue() <= currentTime) && (newExpiryEndDate == null || newExpiryEndDate.longValue() > currentTime)); boolean bl = addFlag = !(newExpiryBeginDate != null && newExpiryBeginDate > currentTime || newExpiryEndDate != null && newExpiryEndDate <= currentTime);
if (addFlag) { if (addFlag) {
addSet.add(syncPersonDTO); addSet.add(syncPersonDTO);
} }
if (StringUtils.isNotBlank(oldImageId)) { if (StringUtils.isNotBlank((CharSequence)oldImageId)) {
SyncPersonDTO delDto = new SyncPersonDTO(); SyncPersonDTO delDto = new SyncPersonDTO();
BeanCopyUtils.copyProperties(syncPersonDTO, delDto); BeanCopyUtils.copyProperties((Object)syncPersonDTO, (Object)delDto);
delDto.setImageId(oldImageId); delDto.setImageId(oldImageId);
deleteSet.add(delDto); deleteSet.add(delDto);
} else { } else {
boolean delFlag = (StringUtils.isBlank(oldImageId) && (oldExpiryBeginDate == null || oldExpiryBeginDate.longValue() <= currentTime) && (oldExpiryEndDate == null || oldExpiryEndDate.longValue() > currentTime)); boolean delFlag;
boolean bl2 = delFlag = !(!StringUtils.isBlank((CharSequence)oldImageId) || oldExpiryBeginDate != null && oldExpiryBeginDate > currentTime || oldExpiryEndDate != null && oldExpiryEndDate <= currentTime);
if (delFlag) { if (delFlag) {
deleteSet.add(syncPersonDTO); deleteSet.add(syncPersonDTO);
} }
} }
if (oldExpiryBeginDate != null) { if (oldExpiryBeginDate != null) {
Set<SyncPersonLocal> removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet()); Set removeAddSet = removeMap.computeIfAbsent(oldExpiryBeginDate, k -> new ConcurrentHashSet());
if (StringUtils.isNotBlank(oldImageId)) { if (StringUtils.isNotBlank((CharSequence)oldImageId)) {
removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), oldImageId, 0)); removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), oldImageId, 0));
} else { } else {
removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeAddSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
.getImageId(), 0));
} }
} }
if (oldExpiryEndDate != null) { if (oldExpiryEndDate != null) {
Set<SyncPersonLocal> removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet()); Set removeEndSet = removeMap.computeIfAbsent(oldExpiryEndDate, k -> new ConcurrentHashSet());
if (StringUtils.isNotBlank(oldImageId)) { if (StringUtils.isNotBlank((CharSequence)oldImageId)) {
removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), oldImageId, -1)); removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), oldImageId, -1));
} else { } else {
removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO removeEndSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
.getImageId(), -1));
} }
} }
if (newExpiryBeginDate != null && newExpiryBeginDate.longValue() > currentTime) { if (newExpiryBeginDate != null && newExpiryBeginDate > currentTime) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryBeginDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), 0));
} }
if (newExpiryEndDate != null && newExpiryEndDate.longValue() > currentTime) { if (newExpiryEndDate != null && newExpiryEndDate > currentTime) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet()); timeSet = addMap.computeIfAbsent(newExpiryEndDate, k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1)); timeSet.add(new SyncPersonLocal(syncPersonDTO.getGroupPersonRefId(), syncPersonDTO.getImageStoreId(), syncPersonDTO.getImageId(), -1));
} }
} private static class SyncPersonLocal {
private String groupPersonRefId; private String imageStoreId; private String imageId; private int action;
public void setGroupPersonRefId(String groupPersonRefId) { this.groupPersonRefId = groupPersonRefId; } public void setImageStoreId(String imageStoreId) { this.imageStoreId = imageStoreId; } public void setImageId(String imageId) { this.imageId = imageId; } public void setAction(int action) { this.action = action; } public String toString() { return "CpImageStorePersonValidateManager.SyncPersonLocal(groupPersonRefId=" + getGroupPersonRefId() + ", imageStoreId=" + getImageStoreId() + ", imageId=" + getImageId() + ", action=" + getAction() + ")"; }
public SyncPersonLocal() {}
public SyncPersonLocal(String groupPersonRefId, String imageStoreId, String imageId, int action) {
this.groupPersonRefId = groupPersonRefId;
this.imageStoreId = imageStoreId;
this.imageId = imageId;
this.action = action;
}
public String getGroupPersonRefId() {
return this.groupPersonRefId;
} public String getImageStoreId() {
return this.imageStoreId;
} public String getImageId() {
return this.imageId;
}
public int getAction() {
return this.action;
}
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof SyncPersonLocal)) {
return false;
}
SyncPersonLocal other = (SyncPersonLocal)o;
return (getAction() == other.getAction() && ((
getGroupPersonRefId() == null && other.getGroupPersonRefId() == null) || (getGroupPersonRefId() != null && getGroupPersonRefId().equals(other.getGroupPersonRefId()))) && ((
getImageId() == null && other.getImageId() == null) || (getImageId() != null && getImageId().equals(other.getImageId()))) && ((
getImageStoreId() == null && other.getImageStoreId() == null) || (getImageStoreId() != null && getImageStoreId().equals(other.getImageStoreId()))));
}
public int hashCode() {
return super.hashCode();
}
} }
public void syncDataToGroup(String dataJson) { public void syncDataToGroup(String dataJson) {
log.info("CpImageStorePersonValidateManager syncDataToGroup start dataJson{}", dataJson); Set<String> keySet;
log.info("CpImageStorePersonValidateManager syncDataToGroup start dataJson{}", (Object)dataJson);
List<SyncPersonLocal> syncPersonDTOS = JsonUtils.toObjList(dataJson, SyncPersonLocal.class); List<SyncPersonLocal> syncPersonDTOS = JsonUtils.toObjList(dataJson, SyncPersonLocal.class);
Map<Integer, List<SyncPersonLocal>> map = (Map<Integer, List<SyncPersonLocal>>)syncPersonDTOS.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getAction)); Map<Integer, List<SyncPersonLocal>> map = syncPersonDTOS.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getAction));
List<SyncPersonLocal> addList = map.get(Integer.valueOf(0)); List<SyncPersonLocal> addList = map.get(0);
List<SyncPersonLocal> deleteList = map.get(Integer.valueOf(-1)); List<SyncPersonLocal> deleteList = map.get(-1);
if (!CollectionUtils.isEmpty(deleteList)) { if (!CollectionUtils.isEmpty(deleteList)) {
Map<String, List<SyncPersonLocal>> deleteMap = (Map<String, List<SyncPersonLocal>>)deleteList.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getImageStoreId)); Map<String, List<SyncPersonLocal>> deleteMap = deleteList.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getImageStoreId));
for (Map.Entry<String, List<SyncPersonLocal>> entry : deleteMap.entrySet()) { for (Map.Entry<String, List<SyncPersonLocal>> entry : deleteMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonLocal::getImageId).collect(Collectors.toSet()); keySet = entry.getValue().parallelStream().map(SyncPersonLocal::getImageId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, false); this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, false);
} }
} }
if (!CollectionUtils.isEmpty(addList)) { if (!CollectionUtils.isEmpty(addList)) {
Map<String, List<SyncPersonLocal>> addMap = (Map<String, List<SyncPersonLocal>>)addList.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getImageStoreId)); Map<String, List<SyncPersonLocal>> addMap = addList.parallelStream().collect(Collectors.groupingBy(SyncPersonLocal::getImageStoreId));
for (Map.Entry<String, List<SyncPersonLocal>> entry : addMap.entrySet()) { for (Map.Entry<String, List<SyncPersonLocal>> entry : addMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonLocal::getImageId).collect(Collectors.toSet()); keySet = entry.getValue().parallelStream().map(SyncPersonLocal::getImageId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true); this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true);
} }
} }
if (!CollectionUtils.isEmpty(addList)) { if (!CollectionUtils.isEmpty(addList)) {
Set<String> addRefIds = (Set<String>)addList.parallelStream().map(SyncPersonLocal::getGroupPersonRefId).collect(Collectors.toSet()); Set<String> addRefIds = addList.parallelStream().map(SyncPersonLocal::getGroupPersonRefId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.updateGroupPersonRefStatus((short)0, addRefIds); this.cpImageStorePersonTxHandler.updateGroupPersonRefStatus((short)0, addRefIds);
} }
if (!CollectionUtils.isEmpty(deleteList)) { if (!CollectionUtils.isEmpty(deleteList)) {
Set<String> deleteRefIds = (Set<String>)deleteList.parallelStream().map(SyncPersonLocal::getGroupPersonRefId).collect(Collectors.toSet()); Set<String> deleteRefIds = deleteList.parallelStream().map(SyncPersonLocal::getGroupPersonRefId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.updateGroupPersonRefStatus((short)1, deleteRefIds); this.cpImageStorePersonTxHandler.updateGroupPersonRefStatus((short)1, deleteRefIds);
} }
if (!CollectionUtils.isEmpty(syncPersonDTOS)) { if (!CollectionUtils.isEmpty(syncPersonDTOS)) {
Set<String> changeGroupIdSet = (Set<String>)syncPersonDTOS.parallelStream().map(SyncPersonLocal::getImageStoreId).collect(Collectors.toSet()); Set<String> changeGroupIdSet = syncPersonDTOS.parallelStream().map(SyncPersonLocal::getImageStoreId).collect(Collectors.toSet());
this.cpImageStoreSyncManager this.cpImageStoreSyncManager.sendChangeToDevice(changeGroupIdSet, true);
.sendChangeToDevice(changeGroupIdSet, true);
} }
log.info("CpImageStorePersonValidateManager syncDataToGroup end"); log.info("CpImageStorePersonValidateManager syncDataToGroup end");
} }
private static List<SyncPersonLocal> removeAll(List<SyncPersonLocal> list, Set<SyncPersonLocal> set) { private static List<SyncPersonLocal> removeAll(List<SyncPersonLocal> list, Set<SyncPersonLocal> set) {
if (set != null && !set.isEmpty()) { if (set != null && !set.isEmpty()) {
Iterator<SyncPersonLocal> it = set.iterator(); Iterator<SyncPersonLocal> it = set.iterator();
@@ -392,6 +388,7 @@ list.remove(it.next());
} }
return list; return list;
} }
private static List<SyncPersonLocal> addAll(List<SyncPersonLocal> list, Set<SyncPersonLocal> set) { private static List<SyncPersonLocal> addAll(List<SyncPersonLocal> list, Set<SyncPersonLocal> set) {
if (!CollectionUtils.isEmpty(set)) { if (!CollectionUtils.isEmpty(set)) {
Iterator<SyncPersonLocal> it = set.iterator(); Iterator<SyncPersonLocal> it = set.iterator();
@@ -401,116 +398,207 @@ list.add(it.next());
} }
return list; return list;
} }
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void delayAddValidateTrigger() { public void delayAddValidateTrigger() {
if (!this.delayAddValidateData.booleanValue()) { if (!this.delayAddValidateData.booleanValue()) {
log.debug("DelayPersonValidateTask 未开启延迟添加定时任务开关"); log.debug("DelayPersonValidateTask 未开启延迟添加定时任务开关");
return; return;
} }
Long currentTime = Long.valueOf(System.currentTimeMillis()); Long currentTime = System.currentTimeMillis();
Long delayTime = Long.valueOf(currentTime.longValue() + this.delayAddValidateHour.longValue() * 60L * 60L * 1000L); Long delayTime = currentTime + this.delayAddValidateHour * 60L * 60L * 1000L;
QueryGroupPersonDTO queryGroupPersonDTO = new QueryGroupPersonDTO(); QueryGroupPersonDTO queryGroupPersonDTO = new QueryGroupPersonDTO();
queryGroupPersonDTO.setStartTime(currentTime); queryGroupPersonDTO.setStartTime(currentTime);
queryGroupPersonDTO.setEndTime(delayTime); queryGroupPersonDTO.setEndTime(delayTime);
queryGroupPersonDTO.setExpiryBeginDateStatus(Integer.valueOf(0)); queryGroupPersonDTO.setExpiryBeginDateStatus(Integer.valueOf(0));
queryGroupPersonDTO.setExpiryEndDateStatus(Integer.valueOf(0)); queryGroupPersonDTO.setExpiryEndDateStatus(Integer.valueOf(0));
List<GroupPersonRef> waitAddValidateList = this.groupPersonRefMapper.queryByExpiryDateStatus(queryGroupPersonDTO); List<GroupPersonRef> waitAddValidateList = this.groupPersonRefMapper.queryByExpiryDateStatus(queryGroupPersonDTO);
if (CollectionUtils.isEmpty(waitAddValidateList)) { if (CollectionUtils.isEmpty((Collection)waitAddValidateList)) {
log.debug("[{}-{}]时间范围内没有需要添加的trigger", queryGroupPersonDTO.getStartTime(), queryGroupPersonDTO.getEndTime()); log.debug("[{}-{}]时间范围内没有需要添加的trigger", (Object)queryGroupPersonDTO.getStartTime(), (Object)queryGroupPersonDTO.getEndTime());
} }
Map<Long, Set<SyncPersonLocal>> addMap = new ConcurrentHashMap<>(); ConcurrentHashMap addMap = new ConcurrentHashMap();
ConcurrentHashSet<SyncPersonDTO> concurrentHashSet = new ConcurrentHashSet(); ConcurrentHashSet addSet = new ConcurrentHashSet();
ConcurrentHashSet concurrentHashSet1 = new ConcurrentHashSet(); ConcurrentHashSet deleteSet = new ConcurrentHashSet();
Set<String> changeGroupIdSet = Sets.newHashSet(); HashSet changeGroupIdSet = Sets.newHashSet();
List<SyncPersonDTO> syncPersonList = Lists.newArrayListWithCapacity(waitAddValidateList.size()); ArrayList syncPersonList = Lists.newArrayListWithCapacity((int)waitAddValidateList.size());
waitAddValidateList = (List<GroupPersonRef>)waitAddValidateList.stream().sorted(Comparator.comparing(GroupPersonRef::getExpiryBeginDate)).collect( waitAddValidateList = (List) waitAddValidateList.stream().sorted(Comparator.comparing(GroupPersonRef::getExpiryBeginDate)).collect(Collectors.toList());
Collectors.toList()); waitAddValidateList.stream().forEach(arg_0 -> this.lambda$delayAddValidateTrigger$24(changeGroupIdSet, syncPersonList, currentTime, (Set)addSet, delayTime, addMap, (Set)deleteSet, arg_0));
waitAddValidateList.stream().forEach(waitAddValidate -> { Iterator iterator = addSet.iterator();
waitAddValidate.setExpiryBeginDate(Optional.<Long>ofNullable(waitAddValidate.getExpiryBeginDate()).orElse(null));
waitAddValidate.setExpiryEndDate(Optional.<Long>ofNullable(waitAddValidate.getExpiryEndDate()).orElse(null));
changeGroupIdSet.add(waitAddValidate.getImageStoreId());
if (waitAddValidate.getExpiryBeginDateStatus().intValue() == 0) {
SyncPersonDTO addSyncPersonDTO = this.cpImageStorePersonTxHandler.generateSyncPersonDTO(waitAddValidate, 0, null, null);
syncPersonList.add(addSyncPersonDTO);
if (waitAddValidate.getExpiryBeginDate().longValue() <= currentTime.longValue()) {
addSet.add(addSyncPersonDTO);
} else if (waitAddValidate.getExpiryBeginDate().longValue() <= delayTime.longValue()) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(waitAddValidate.getExpiryBeginDate(), k -> new HashSet<>());
timeSet.add(new SyncPersonLocal(addSyncPersonDTO.getGroupPersonRefId(), addSyncPersonDTO.getImageStoreId(), addSyncPersonDTO.getImageId(), 0));
}
}
if (waitAddValidate.getExpiryEndDateStatus().intValue() == 0) {
SyncPersonDTO deleteSyncPersonDTO = this.cpImageStorePersonTxHandler.generateSyncPersonDTO(waitAddValidate, -1, null, null);
syncPersonList.add(deleteSyncPersonDTO);
if (waitAddValidate.getExpiryEndDate().longValue() <= currentTime.longValue()) {
deleteSet.add(deleteSyncPersonDTO);
} else if (waitAddValidate.getExpiryEndDate().longValue() <= delayTime.longValue()) {
Set<SyncPersonLocal> timeSet = addMap.computeIfAbsent(waitAddValidate.getExpiryEndDate(), k -> new HashSet<>());
timeSet.add(new SyncPersonLocal(deleteSyncPersonDTO.getGroupPersonRefId(), deleteSyncPersonDTO.getImageStoreId(), deleteSyncPersonDTO.getImageId(), -1));
}
}
});
Iterator<SyncPersonDTO> iterator = concurrentHashSet.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
SyncPersonDTO syncPersonDTO = iterator.next(); SyncPersonDTO syncPersonDTO = (SyncPersonDTO)iterator.next();
if (concurrentHashSet1.contains(syncPersonDTO)) { if (deleteSet.contains(syncPersonDTO)) {
concurrentHashSet1.remove(syncPersonDTO); deleteSet.remove(syncPersonDTO);
iterator.remove(); continue; iterator.remove();
} if (StringUtils.isBlank(syncPersonDTO.getImageId())) { continue;
}
if (!StringUtils.isBlank((CharSequence)syncPersonDTO.getImageId())) continue;
iterator.remove(); iterator.remove();
} }
}
Scheduler scheduler = this.taskExecClient.getScheduler(this.quartzTaskProperties.getSchedulerName()); Scheduler scheduler = this.taskExecClient.getScheduler(this.quartzTaskProperties.getSchedulerName());
for (Map.Entry<Long, Set<SyncPersonLocal>> entry : addMap.entrySet()) { for (Map.Entry<Long, Set<SyncPersonLocal>> entry : ((Map<Long, Set<SyncPersonLocal>>) (Map) addMap).entrySet()) {
if (!((Set)entry.getValue()).isEmpty()) { if (((Set)entry.getValue()).isEmpty()) continue;
Long key = entry.getKey(); Long l = (Long)entry.getKey();
Long lockValue = Long.valueOf(SnowFlake.nextId()); Long lockValue = SnowFlake.nextId();
try { try {
if (validateJobGroupLock(key, lockValue)) { if (this.validateJobGroupLock(l, lockValue)) {
TriggerKey triggerKey = TriggerKey.triggerKey(key.toString(), "QZ_PERSON_VALIDATE_JOB"); TriggerKey triggerKey = TriggerKey.triggerKey((String)l.toString(), (String)"QZ_PERSON_VALIDATE_JOB");
Trigger trigger = scheduler.getTrigger(triggerKey); Trigger trigger = scheduler.getTrigger(triggerKey);
if (trigger == null) { if (trigger == null) {
trigger = TriggerBuilder.newTrigger().withIdentity(key.toString(), "QZ_PERSON_VALIDATE_JOB").withDescription("trigger at:" + key).forJob("PERSON_VALIDATE_JOB_NAME", "QZ_PERSON_VALIDATE_JOB").startAt(new Date(key.longValue())).usingJobData("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(entry.getValue())).build(); trigger = TriggerBuilder.newTrigger().withIdentity(l.toString(), "QZ_PERSON_VALIDATE_JOB").withDescription("trigger at:" + l).forJob("PERSON_VALIDATE_JOB_NAME", "QZ_PERSON_VALIDATE_JOB").startAt(new Date(l)).usingJobData("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(entry.getValue())).build();
scheduler.scheduleJob(trigger); scheduler.scheduleJob(trigger);
} else { continue;
String dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY");
if (StringUtils.isNotBlank(dataSet)) {
syncPersonDtoList = JsonUtils.toObjList(dataSet, SyncPersonLocal.class);
} else {
syncPersonDtoList = Lists.newArrayList();
} }
List<SyncPersonLocal> syncPersonDtoList = addAll(syncPersonDtoList, entry.getValue()); String dataSet = trigger.getJobDataMap().getString("VALIDATE_TRIGGER_KEY");
List<SyncPersonLocal> syncPersonDtoList = StringUtils.isNotBlank((CharSequence)dataSet) ? JsonUtils.toObjList(dataSet, SyncPersonLocal.class) : new ArrayList<>();
syncPersonDtoList = CpImageStorePersonValidateManager.addAll(syncPersonDtoList, entry.getValue());
trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDtoList)); trigger.getJobDataMap().put("VALIDATE_TRIGGER_KEY", JsonUtils.toJson(syncPersonDtoList));
scheduler.rescheduleJob(triggerKey, trigger); scheduler.rescheduleJob(triggerKey, trigger);
continue;
} }
} else {
log.error("CpImageStorePersonValidateManager addValidateData addOrModJob time out"); log.error("CpImageStorePersonValidateManager addValidateData addOrModJob time out");
} }
} catch (SchedulerException e) { catch (SchedulerException e) {
log.error("添加trigger异常:{}", e.getLocalizedMessage()); log.error("添加trigger异常:{}", (Object)e.getLocalizedMessage());
} catch (Exception e) { }
log.error("添加trigger未知异常:{}", e.getMessage()); catch (Exception e) {
} finally { log.error("添加trigger未知异常:{}", (Object)e.getMessage());
validateJobGroupUnLock(key, lockValue); }
finally {
this.validateJobGroupUnLock(l, lockValue);
} }
} }
} this.updateExpiryDateStatus(currentTime, syncPersonList);
updateExpiryDateStatus(currentTime, syncPersonList); Map<String, List<SyncPersonDTO>> deleteImageMap = (Map<String, List<SyncPersonDTO>>) (Map) deleteSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
Map<String, List<SyncPersonDTO>> deleteImageMap = (Map<String, List<SyncPersonDTO>>)concurrentHashSet1.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
for (Map.Entry<String, List<SyncPersonDTO>> entry : deleteImageMap.entrySet()) { for (Map.Entry<String, List<SyncPersonDTO>> entry : deleteImageMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet()); Set<String> keySet = entry.getValue().parallelStream().map(s -> s.getImageId()).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, false); this.cpImageStorePersonTxHandler.handleImageStoreImageChange((String)entry.getKey(), keySet, false);
} }
Map<String, List<SyncPersonDTO>> addImageMap = (Map<String, List<SyncPersonDTO>>)concurrentHashSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId)); Map<String, List<SyncPersonDTO>> addImageMap = (java.util.Map<java.lang.String,java.util.List<cn.cloudwalk.data.organization.dto.SyncPersonDTO>>) addSet.parallelStream().collect(Collectors.groupingBy(SyncPersonDTO::getImageStoreId));
for (Map.Entry<String, List<SyncPersonDTO>> entry : addImageMap.entrySet()) { for (Map.Entry<String, List<SyncPersonDTO>> entry : addImageMap.entrySet()) {
Set<String> keySet = (Set<String>)((List)entry.getValue()).parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet()); Set<String> keySet = entry.getValue().parallelStream().map(SyncPersonDTO::getImageId).collect(Collectors.toSet());
this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true); this.cpImageStorePersonTxHandler.handleImageStoreImageChange(entry.getKey(), keySet, true);
} }
this.cpImageStoreSyncManager.sendChangeToDevice(changeGroupIdSet, false); this.cpImageStoreSyncManager.sendChangeToDevice(changeGroupIdSet, false);
} }
private /* synthetic */ void lambda$delayAddValidateTrigger$24(Set changeGroupIdSet, List syncPersonList, Long currentTime, Set addSet, Long delayTime, Map addMap, Set deleteSet, GroupPersonRef waitAddValidate) {
Set timeSet;
waitAddValidate.setExpiryBeginDate((Long)Optional.ofNullable(waitAddValidate.getExpiryBeginDate()).map(date -> date / 1000L * 1000L).orElse(null));
waitAddValidate.setExpiryEndDate((Long)Optional.ofNullable(waitAddValidate.getExpiryEndDate()).map(date -> date / 1000L * 1000L).orElse(null));
changeGroupIdSet.add(waitAddValidate.getImageStoreId());
if (waitAddValidate.getExpiryBeginDateStatus() == 0) {
SyncPersonDTO addSyncPersonDTO = this.cpImageStorePersonTxHandler.generateSyncPersonDTO(waitAddValidate, 0, null, null);
syncPersonList.add(addSyncPersonDTO);
if (waitAddValidate.getExpiryBeginDate() <= currentTime) {
addSet.add(addSyncPersonDTO);
} else if (waitAddValidate.getExpiryBeginDate() <= delayTime) {
timeSet = (java.util.Set) addMap.computeIfAbsent(waitAddValidate.getExpiryBeginDate(), k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(addSyncPersonDTO.getGroupPersonRefId(), addSyncPersonDTO.getImageStoreId(), addSyncPersonDTO.getImageId(), 0));
}
}
if (waitAddValidate.getExpiryEndDateStatus() == 0) {
SyncPersonDTO deleteSyncPersonDTO = this.cpImageStorePersonTxHandler.generateSyncPersonDTO(waitAddValidate, -1, null, null);
syncPersonList.add(deleteSyncPersonDTO);
if (waitAddValidate.getExpiryEndDate() <= currentTime) {
deleteSet.add(deleteSyncPersonDTO);
} else if (waitAddValidate.getExpiryEndDate() <= delayTime) {
timeSet = (java.util.Set) addMap.computeIfAbsent(waitAddValidate.getExpiryEndDate(), k -> new ConcurrentHashSet());
timeSet.add(new SyncPersonLocal(deleteSyncPersonDTO.getGroupPersonRefId(), deleteSyncPersonDTO.getImageStoreId(), deleteSyncPersonDTO.getImageId(), -1));
}
}
} }
private /* synthetic */ void lambda$addValidateData$4(Set changeGroupIdSet, long currentTime, Set deleteSet, Map removeMap, Map addMap, Set addSet, SyncPersonDTO syncPersonDTO) {
syncPersonDTO.setOldExpiryBeginDate((Long)Optional.ofNullable(syncPersonDTO.getOldExpiryBeginDate()).map(date -> date / 1000L * 1000L).orElse(null));
syncPersonDTO.setOldExpiryEndDate((Long)Optional.ofNullable(syncPersonDTO.getOldExpiryEndDate()).map(date -> date / 1000L * 1000L).orElse(null));
syncPersonDTO.setNewExpiryBeginDate((Long)Optional.ofNullable(syncPersonDTO.getNewExpiryBeginDate()).map(date -> date / 1000L * 1000L).orElse(null));
syncPersonDTO.setNewExpiryEndDate((Long)Optional.ofNullable(syncPersonDTO.getNewExpiryEndDate()).map(date -> date / 1000L * 1000L).orElse(null));
changeGroupIdSet.add(syncPersonDTO.getImageStoreId());
int action = syncPersonDTO.getAction();
switch (action) {
case -1: {
this.delDataManager(currentTime, syncPersonDTO, deleteSet, removeMap, addMap);
break;
}
case 0: {
this.addDataManager(currentTime, syncPersonDTO, addSet, removeMap, addMap);
break;
}
case 1: {
this.updateDataManage(currentTime, syncPersonDTO, deleteSet, addSet, removeMap, addMap);
break;
}
}
}
private static class SyncPersonLocal {
private String groupPersonRefId;
private String imageStoreId;
private String imageId;
private int action;
public SyncPersonLocal() {
}
public SyncPersonLocal(String groupPersonRefId, String imageStoreId, String imageId, int action) {
this.groupPersonRefId = groupPersonRefId;
this.imageStoreId = imageStoreId;
this.imageId = imageId;
this.action = action;
}
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (!(o instanceof SyncPersonLocal)) {
return false;
}
SyncPersonLocal other = (SyncPersonLocal)o;
return this.getAction() == other.getAction() && (this.getGroupPersonRefId() == null && other.getGroupPersonRefId() == null || this.getGroupPersonRefId() != null && this.getGroupPersonRefId().equals(other.getGroupPersonRefId())) && (this.getImageId() == null && other.getImageId() == null || this.getImageId() != null && this.getImageId().equals(other.getImageId())) && (this.getImageStoreId() == null && other.getImageStoreId() == null || this.getImageStoreId() != null && this.getImageStoreId().equals(other.getImageStoreId()));
}
public int hashCode() {
return super.hashCode();
}
public String getGroupPersonRefId() {
return this.groupPersonRefId;
}
public String getImageStoreId() {
return this.imageStoreId;
}
public String getImageId() {
return this.imageId;
}
public int getAction() {
return this.action;
}
public void setGroupPersonRefId(String groupPersonRefId) {
this.groupPersonRefId = groupPersonRefId;
}
public void setImageStoreId(String imageStoreId) {
this.imageStoreId = imageStoreId;
}
public void setImageId(String imageId) {
this.imageId = imageId;
}
public void setAction(int action) {
this.action = action;
}
public String toString() {
return "CpImageStorePersonValidateManager.SyncPersonLocal(groupPersonRefId=" + this.getGroupPersonRefId() + ", imageStoreId=" + this.getImageStoreId() + ", imageId=" + this.getImageId() + ", action=" + this.getAction() + ")";
}
}
}
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/CpImageStorePersonValidateManager.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -1,783 +0,0 @@
package cn.cloudwalk.service.organization.service;
// 业务服务
import cn.cloudwalk.client.account.account.param.GeneralQueryBusinessParam;
import cn.cloudwalk.client.account.account.result.AcBusinessDTO;
import cn.cloudwalk.client.account.account.service.AcBusinessService;
import cn.cloudwalk.client.aggregate.application.param.ApplicationImageStoreQueryParam;
import cn.cloudwalk.client.aggregate.application.result.ApplicationImageStoreQueryResult;
import cn.cloudwalk.client.aggregate.application.service.ApplicationImageStoreService;
import cn.cloudwalk.client.aggregate.common.enums.DelStatusEnum;
import cn.cloudwalk.client.aggregate.common.enums.SyncStatusEnum;
import cn.cloudwalk.client.aggregate.device.param.DeviceImageStoreQueryParam;
import cn.cloudwalk.client.aggregate.device.result.DeviceImageStoreQueryResult;
import cn.cloudwalk.client.aggregate.device.service.AggDeviceImageStoreService;
import cn.cloudwalk.client.aggregate.group.param.AgImageStoreAddParam;
import cn.cloudwalk.client.aggregate.group.param.AgImageStoreEditParam;
import cn.cloudwalk.client.aggregate.group.param.AgImageStoreKeyParam;
import cn.cloudwalk.client.aggregate.group.param.AgImageStoreQueryParam;
import cn.cloudwalk.client.aggregate.group.result.AgImageStoreResult;
import cn.cloudwalk.client.aggregate.group.service.AgImageStoreService;
import cn.cloudwalk.client.device.mgn.atomic.param.CoreDeviceQueryParam;
import cn.cloudwalk.client.device.mgn.atomic.result.AtomicDeviceGetResult;
import cn.cloudwalk.client.device.mgn.atomic.service.AtomicDeviceService;
import cn.cloudwalk.client.organization.common.enums.CpImageStoreMatchPatternEnum;
import cn.cloudwalk.client.organization.service.store.param.AddImageStoreParam;
import cn.cloudwalk.client.organization.service.store.param.AssociatedParam;
import cn.cloudwalk.client.organization.service.store.param.BaseImageStoreParam;
import cn.cloudwalk.client.organization.service.store.param.DelImageStoreParam;
import cn.cloudwalk.client.organization.service.store.param.DetailImageStoreParam;
import cn.cloudwalk.client.organization.service.store.param.EditImageStoreParam;
import cn.cloudwalk.client.organization.service.store.param.QueryImageStoreParam;
import cn.cloudwalk.client.organization.service.store.result.AssociatedResult;
import cn.cloudwalk.client.organization.service.store.result.DeviceInfoResult;
import cn.cloudwalk.client.organization.service.store.result.ImageStoreDetailResult;
import cn.cloudwalk.client.organization.service.store.result.ImageStoreResult;
import cn.cloudwalk.client.organization.service.store.result.ImgStorePersonResult;
import cn.cloudwalk.client.organization.service.store.result.LabelResult;
import cn.cloudwalk.client.organization.service.store.result.OrganizationResult;
import cn.cloudwalk.client.organization.service.store.result.PageImageStoreResult;
import cn.cloudwalk.client.organization.service.store.service.CpImageStoreService;
import cn.cloudwalk.client.resource.application.param.ApplicationBasicParam;
import cn.cloudwalk.client.resource.application.param.ApplicationQueryParam;
import cn.cloudwalk.client.resource.application.result.ApplicationResult;
import cn.cloudwalk.client.resource.application.service.ApplicationService;
import cn.cloudwalk.client.resource.common.en.CommonStatusEnum;
import cn.cloudwalk.cloud.annotation.CloudwalkParamsValidate;
import cn.cloudwalk.cloud.context.CloudwalkCallContext;
import cn.cloudwalk.cloud.exception.ServiceException;
import cn.cloudwalk.cloud.page.CloudwalkPageAble;
import cn.cloudwalk.cloud.page.CloudwalkPageInfo;
import cn.cloudwalk.cloud.result.CloudwalkResult;
import cn.cloudwalk.cloud.utils.BeanCopyUtils;
import cn.cloudwalk.cloud.utils.CloudwalkDateUtils;
import cn.cloudwalk.data.organization.dto.DelGroupPersonDTO;
import cn.cloudwalk.data.organization.dto.GetsImageStoreAssociatedDTO;
import cn.cloudwalk.data.organization.dto.ImageStoreCountDTO;
import cn.cloudwalk.data.organization.dto.ImgStorePersonQueryDto;
import cn.cloudwalk.data.organization.dto.OrganizationImageStoreQueryDTO;
import cn.cloudwalk.data.organization.dto.QueryGroupPersonDTO;
import cn.cloudwalk.data.organization.entity.GroupPersonRef;
import cn.cloudwalk.data.organization.entity.ImgStorePerson;
import cn.cloudwalk.data.organization.entity.IsImageStoreAssociated;
import cn.cloudwalk.data.organization.entity.OrganizationImageStore;
import cn.cloudwalk.data.organization.mapper.GroupPersonRefMapper;
import cn.cloudwalk.data.organization.mapper.ImgStoreLabelMapper;
import cn.cloudwalk.data.organization.mapper.ImgStoreOrganizationMapper;
import cn.cloudwalk.data.organization.mapper.ImgStorePersonMapper;
import cn.cloudwalk.data.organization.mapper.IsImageStoreAssociatedMapper;
import cn.cloudwalk.data.organization.mapper.OrganizationImageStoreMapper;
import cn.cloudwalk.service.organization.common.AbstractImagStoreService;
import cn.cloudwalk.service.organization.common.JsonUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springside.modules.utils.Collections3;
@Service
public class CpImageStoreServiceImpl
extends AbstractImagStoreService
implements CpImageStoreService
{
@Autowired
private IsImageStoreAssociatedMapper isImageStoreAssociatedMapper;
@Autowired
private ImgStoreLabelMapper imgStoreLabelMapper;
@Autowired
private ImgStoreOrganizationMapper imgStoreOrganizationMapper;
@Autowired
private ImgStorePersonMapper personMapper;
@Autowired
private GroupPersonRefMapper groupPersonRefMapper;
@Autowired
private OrganizationImageStoreMapper organizationImageStoreMapper;
@Autowired
private AcBusinessService acBusinessService;
@Autowired
private ApplicationService applicationService;
@Autowired
private AgImageStoreService agImageStoreService;
@Autowired
private ApplicationImageStoreService applicationImageStoreService;
@Autowired
private AggDeviceImageStoreService deviceImageStoreService;
@Autowired
private CpImageStorePersonSynManager cpImageStorePersonSynManager;
@Resource
private CpImageStorePersonManager cpImageStorePersonManager;
@Resource
private AtomicDeviceService atomicDeviceService;
@Resource
private ApplicationImageStoreService appImageStoreService;
@Value("${cloudwalk.imagestore.person.searchSize:2}")
private int searchSize;
@Transactional(rollbackFor = {Exception.class})
@CloudwalkParamsValidate
public CloudwalkResult<String> add(AddImageStoreParam param, CloudwalkCallContext context) throws ServiceException {
String imageStoreId = CloudwalkDateUtils.getUUID();
AgImageStoreAddParam addParam = new AgImageStoreAddParam();
addParam.setId(imageStoreId);
addParam.setName(param.getName());
addParam.setType(param.getType());
addParam.setBusinessId(param.getBusinessId());
addParam.setSourceApplicationId(param.getSourceApplicationId());
if (StringUtils.isBlank(param.getBusinessId()))
{
addParam.setBusinessId(context.getCompany().getCompanyId());
}
List<IsImageStoreAssociated> imageStoreAssociatedList = addBaseImageStore((BaseImageStoreParam)param, context, imageStoreId, addParam.getBusinessId());
if (imageStoreAssociatedList.size() > 0) {
this.isImageStoreAssociatedMapper.batchInsert(imageStoreAssociatedList);
}
CloudwalkResult<String> addResult = this.agImageStoreService.add(addParam, context);
if (!addResult.isSuccess()) {
throw new ServiceException(addResult.getCode(), addResult.getMessage());
}
this.cpImageStorePersonSynManager.addGroupPersonSynTask(Lists.newArrayList(imageStoreId ), "isAll");
return CloudwalkResult.success(imageStoreId);
}
@Transactional(rollbackFor = {Exception.class})
@CloudwalkParamsValidate
public CloudwalkResult<Boolean> edit(EditImageStoreParam param, CloudwalkCallContext context) throws ServiceException {
checkExistAndStatus(param.getImageStoreId());
AgImageStoreEditParam editParam = new AgImageStoreEditParam();
editParam.setId(param.getImageStoreId());
editParam.setName(param.getName());
String businessId = param.getBusinessId();
if (StringUtils.isBlank(businessId))
{
businessId = context.getCompany().getCompanyId();
}
List<IsImageStoreAssociated> imageStoreAssociatedList = addBaseImageStore((BaseImageStoreParam)param, context, param.getImageStoreId(), businessId);
if (checkAssociatedIsChange(param.getImageStoreId(), imageStoreAssociatedList)) {
this.isImageStoreAssociatedMapper.deleteAllByImageId(param.getImageStoreId());
if (imageStoreAssociatedList.size() > 0) {
this.isImageStoreAssociatedMapper.batchInsert(imageStoreAssociatedList);
}
editParam.setStatus(SyncStatusEnum.SYNC_WAIT.getCode());
}
CloudwalkResult<Boolean> editResult = this.agImageStoreService.edit(editParam, context);
if (!editResult.isSuccess()) {
throw new ServiceException(editResult.getCode(), editResult.getMessage());
}
this.cpImageStorePersonSynManager.addGroupPersonSynTask(Lists.newArrayList(param.getImageStoreId() ), "isAll");
return CloudwalkResult.success(Boolean.TRUE);
}
private boolean checkAssociatedIsChange(String imageStoreId, List<IsImageStoreAssociated> associatedListAfterUpdate) {
GetsImageStoreAssociatedDTO queryDTO = new GetsImageStoreAssociatedDTO();
queryDTO.setImageStoreId(imageStoreId);
List<IsImageStoreAssociated> associatedListBeforeUpdate = this.isImageStoreAssociatedMapper.gets(queryDTO);
if (CollectionUtils.isEmpty(associatedListBeforeUpdate) &&
CollectionUtils.isEmpty(associatedListAfterUpdate)) {
return false;
}
if (associatedListBeforeUpdate.size() != associatedListAfterUpdate.size()) {
return true;
}
Set<String> associatedStrBeforeUpdate = new HashSet<>(associatedListBeforeUpdate.size());
for (IsImageStoreAssociated associateBefore : associatedListBeforeUpdate) {
String action = (associateBefore.getAssociatedAction() != null) ? String.valueOf(associateBefore.getAssociatedAction()) : "";
associatedStrBeforeUpdate.add(action + associateBefore.getAssociatedObjectIdType() + associateBefore.getAssociatedObjectId() + associateBefore
.getExpiryBeginDate() + associateBefore.getExpiryEndDate() + associateBefore.getValidDateCron());
}
Set<String> associatedStrAfterUpdate = new HashSet<>(associatedListAfterUpdate.size());
for (IsImageStoreAssociated associateBeforeAfter : associatedListAfterUpdate) {
String action = (associateBeforeAfter.getAssociatedAction() != null) ? String.valueOf(associateBeforeAfter.getAssociatedAction()) : "";
associatedStrAfterUpdate.add(action + associateBeforeAfter.getAssociatedObjectIdType() + associateBeforeAfter.getAssociatedObjectId() + associateBeforeAfter
.getExpiryBeginDate() + associateBeforeAfter.getExpiryEndDate() + associateBeforeAfter.getValidDateCron());
}
associatedStrBeforeUpdate.removeAll(associatedStrAfterUpdate);
return !CollectionUtils.isEmpty(associatedStrBeforeUpdate);
}
@Transactional(rollbackFor = {Exception.class})
@CloudwalkParamsValidate
public CloudwalkResult<Boolean> delete(DelImageStoreParam param, CloudwalkCallContext context) throws ServiceException {
checkAppRefByImageStoreIdForDelete(param.getId(), context);
checkExistAndStatus(param.getId());
QueryGroupPersonDTO queryDTO = new QueryGroupPersonDTO();
queryDTO.setImageStoreId(param.getId());
queryDTO.setIsDel(Short.valueOf(DelStatusEnum.NORAML.getCode().shortValue()));
List<GroupPersonRef> groupPersonList = this.groupPersonRefMapper.query(queryDTO);
this.isImageStoreAssociatedMapper.deleteAllByImageId(param.getId());
DelGroupPersonDTO delGroupPersonDTO = new DelGroupPersonDTO();
delGroupPersonDTO.setImageStoreId(param.getId());
delGroupPersonDTO.setLastUpdateTime(Long.valueOf(System.currentTimeMillis()));
delGroupPersonDTO.setLastUpdateUserId(context.getUser().getCaller());
this.groupPersonRefMapper.logicDeleteByParam(delGroupPersonDTO);
CloudwalkResult<Boolean> delete = this.agImageStoreService.delete((AgImageStoreKeyParam)BeanCopyUtils.copyProperties(param, AgImageStoreKeyParam.class), context);
if (!delete.isSuccess()) {
throw new ServiceException(delete.getCode(), delete.getMessage());
}
return CloudwalkResult.success(Boolean.TRUE);
}
private void checkAppRefByImageStoreIdForDelete(String imageStoreId, CloudwalkCallContext context) throws ServiceException {
ApplicationImageStoreQueryParam queryParam = new ApplicationImageStoreQueryParam();
queryParam.setImageStoreId(imageStoreId);
CloudwalkResult<List<ApplicationImageStoreQueryResult>> queryResult = this.applicationImageStoreService.query(queryParam, context);
if (!queryResult.isSuccess()) {
throw new ServiceException(queryResult.getCode(), queryResult.getMessage());
}
if (!CollectionUtils.isEmpty((Collection)queryResult.getData())) {
throw new ServiceException("53013545",
getMessage("53013545"));
}
}
public CloudwalkResult<CloudwalkPageAble<PageImageStoreResult>> page(QueryImageStoreParam queryImageStoreParam, CloudwalkCallContext context) throws ServiceException {
boolean isEnd = handleQueryParam(queryImageStoreParam);
if (isEnd) {
return CloudwalkResult.success(new CloudwalkPageAble(new ArrayList(), new CloudwalkPageInfo(queryImageStoreParam
.getCurrentPage(), queryImageStoreParam.getRowsOfPage()), 0L));
}
AgImageStoreQueryParam queryParam = (AgImageStoreQueryParam)BeanCopyUtils.copyProperties(queryImageStoreParam, AgImageStoreQueryParam.class);
if (StringUtils.isBlank(queryParam.getBusinessId()))
{
queryParam.setBusinessId(context.getCompany().getCompanyId());
}
CloudwalkResult<CloudwalkPageAble<AgImageStoreResult>> agPageResult = this.agImageStoreService.page(queryParam);
if (!agPageResult.isSuccess()) {
return CloudwalkResult.fail(agPageResult.getCode(), agPageResult.getMessage());
}
if (agPageResult.getData() == null) {
return CloudwalkResult.success(new CloudwalkPageAble(new ArrayList(), new CloudwalkPageInfo(queryParam
.getCurrentPage(), queryParam.getRowsOfPage()), 0L));
}
List<PageImageStoreResult> resultList = packageCpResult(((CloudwalkPageAble)agPageResult.getData()).getDatas(), queryParam.getBusinessId());
return CloudwalkResult.success(new CloudwalkPageAble(resultList, new CloudwalkPageInfo(
(int)((CloudwalkPageAble)agPageResult.getData()).getCurrentPage(), (int)((CloudwalkPageAble)agPageResult.getData()).getPageSize()), ((CloudwalkPageAble)agPageResult
.getData()).getTotalRows()));
}
public CloudwalkResult<List<ImageStoreResult>> list(QueryImageStoreParam queryImageStoreParam, CloudwalkCallContext cloudwalkContext) throws ServiceException {
List<ImageStoreResult> resultList = new ArrayList<>();
boolean isEnd = handleQueryParam(queryImageStoreParam);
if (isEnd) {
return CloudwalkResult.success(resultList);
}
AgImageStoreQueryParam queryParam = (AgImageStoreQueryParam)BeanCopyUtils.copyProperties(queryImageStoreParam, AgImageStoreQueryParam.class);
if (StringUtils.isBlank(queryParam.getBusinessId()))
{
queryParam.setBusinessId(cloudwalkContext.getCompany().getCompanyId());
}
CloudwalkResult<List<AgImageStoreResult>> agQueryResult = this.agImageStoreService.query(queryParam);
if (!agQueryResult.isSuccess()) {
return CloudwalkResult.fail(agQueryResult.getCode(), agQueryResult.getMessage());
}
if (!CollectionUtils.isEmpty(queryImageStoreParam.getLabelIds())) {
GetsImageStoreAssociatedDTO get = new GetsImageStoreAssociatedDTO();
get.setAssociatedObjectIds(queryImageStoreParam.getLabelIds());
get.setAssociatedObjectIdType(Integer.valueOf(2));
List<IsImageStoreAssociated> associateds = this.isImageStoreAssociatedMapper.gets(get);
if (CollectionUtils.isEmpty(associateds)) {
return CloudwalkResult.success(resultList);
}
List<String> imageStoreIds = Collections3.extractToList(associateds, "imageStoreId");
List<AgImageStoreResult> collect = (List<AgImageStoreResult>)((List)agQueryResult.getData()).stream().filter(a -> imageStoreIds.contains(a.getId())).collect(
Collectors.toList());
agQueryResult.setData(collect);
}
resultList = packageImageStoreResult((Collection<AgImageStoreResult>)agQueryResult.getData(), queryParam.getBusinessId());
return CloudwalkResult.success(resultList);
}
@CloudwalkParamsValidate
public CloudwalkResult<ImageStoreDetailResult> detail(DetailImageStoreParam param, CloudwalkCallContext context) {
AgImageStoreQueryParam queryParam = new AgImageStoreQueryParam();
queryParam.setId(param.getId());
CloudwalkResult<List<AgImageStoreResult>> queryResult = this.agImageStoreService.query(queryParam);
if (!queryResult.isSuccess()) {
return CloudwalkResult.fail(queryResult.getCode(), queryResult.getMessage());
}
if (CollectionUtils.isEmpty((Collection)queryResult.getData())) {
return CloudwalkResult.fail("53013502",
getMessage("53013502"));
}
AgImageStoreResult agImageStoreResult = ((List<AgImageStoreResult>)queryResult.getData()).get(0);
ImageStoreDetailResult result = (ImageStoreDetailResult)BeanCopyUtils.copyProperties(agImageStoreResult, ImageStoreDetailResult.class);
result.setPersonNum(getPersonNum(agImageStoreResult.getId()));
try {
result.setBusinessName(getBusinessName(result.getBusinessId()));
} catch (ServiceException e) {
this.logger.error("查询企业名称错误e:{}", e.getMessage());
return CloudwalkResult.fail(e.getCode(), e.getMessage());
}
try {
result.setSourceApplicationName(getSourceApplicationName(result.getSourceApplicationId()));
} catch (ServiceException e) {
this.logger.error("查询来源应用名称错误e:{}", e.getMessage());
return CloudwalkResult.fail(e.getCode(), e.getMessage());
}
getAssociated(result);
DeviceImageStoreQueryParam deviceParam = new DeviceImageStoreQueryParam();
deviceParam.setImageStoreId(param.getId());
CloudwalkResult<List<DeviceImageStoreQueryResult>> deviceResult = this.deviceImageStoreService.query(deviceParam, context);
if (deviceResult.isSuccess()) {
result.setDevices(getDeviceList((List<DeviceImageStoreQueryResult>)deviceResult.getData(), context));
} else {
this.logger.error("图库详情关联设备名称获取失败,result:[{}]", JSONObject.toJSONString(deviceResult));
}
ApplicationImageStoreQueryParam appParam = new ApplicationImageStoreQueryParam();
appParam.setImageStoreId(param.getId());
CloudwalkResult<List<ApplicationImageStoreQueryResult>> appResult = this.applicationImageStoreService.query(appParam, context);
if (appResult.isSuccess()) {
result.setApplicationNames(Collections3.extractToList((Collection)appResult.getData(), "applicationName"));
} else {
this.logger.error("图库详情关联应用名称获取失败,result:[{}]", JSONObject.toJSONString(appResult));
}
return CloudwalkResult.success(result);
}
private List<DeviceInfoResult> getDeviceList(List<DeviceImageStoreQueryResult> resultList, CloudwalkCallContext context) {
List<DeviceInfoResult> list = Lists.newArrayListWithCapacity(resultList.size());
try {
List<String> deviceIds = (List<String>)resultList.stream().map(DeviceImageStoreQueryResult::getDeviceId).collect(Collectors.toList());
CoreDeviceQueryParam param = new CoreDeviceQueryParam();
param.setIds(deviceIds);
param.setBusinessId(context.getCompany().getCompanyId());
CloudwalkResult<List<AtomicDeviceGetResult>> deviceResult = this.atomicDeviceService.list(param, context);
Map<String, String> deviceMap = new HashMap<>();
if (deviceResult.isSuccess()) {
deviceMap = (Map<String, String>)((List)deviceResult.getData()).stream().collect(Collectors.toMap(device -> device.getId(), device -> device.getDeviceCode()));
}
for (DeviceImageStoreQueryResult result : resultList) {
DeviceInfoResult dr = new DeviceInfoResult();
dr.setDeviceId(result.getDeviceId());
dr.setDeviceCode(deviceMap.get(result.getDeviceId()));
dr.setDeviceName(result.getDeviceName());
dr.setIdentifyType(result.getIdentifyType());
list.add(dr);
}
} catch (Exception e) {
this.logger.error("exception:{}", e.getMessage());
}
return list;
}
private IsImageStoreAssociated getAssociated(String objectId, long time, String userId, String imageStoreId, Integer action, Integer objectType) {
IsImageStoreAssociated associated = new IsImageStoreAssociated();
associated.setId(getPrimaryId());
associated.setAssociatedAction(action);
associated.setAssociatedObjectId(objectId);
associated.setAssociatedObjectIdType(objectType);
associated.setCreateTime(Long.valueOf(time));
associated.setCreateUserId(userId);
associated.setImageStoreId(imageStoreId);
associated.setLastUpdateTime(Long.valueOf(time));
associated.setLastUpdateUserId(userId);
return associated;
}
private IsImageStoreAssociated getAssociated(AssociatedParam associatedParam, long time, String userId, String imageStoreId, Integer action, Integer objectType) {
IsImageStoreAssociated associated = getAssociated(associatedParam.getObjectId(), time, userId, imageStoreId, action, objectType);
associated.setExpiryBeginDate(associatedParam.getExpiryBeginDate());
associated.setExpiryEndDate(associatedParam.getExpiryEndDate());
associated.setValidDateCron(null);
if (!CollectionUtils.isEmpty(associatedParam.getValidDateCron())) {
associated.setValidDateCron(JSON.toJSONString(associatedParam.getValidDateCron()));
}
return associated;
}
private List<IsImageStoreAssociated> addBaseImageStore(BaseImageStoreParam param, CloudwalkCallContext context, String imageStoreId, String businessId) throws ServiceException {
List<String> includePersonIds;
long time = System.currentTimeMillis();
if (CollectionUtils.isEmpty(param.getIncludePersons())) {
includePersonIds = new ArrayList<>();
} else {
includePersonIds = (List<String>)param.getIncludePersons().stream().map(AssociatedParam::getObjectId).collect(Collectors.toList());
}
if (CollectionUtils.isEmpty(param.getIncludeOrganizations()) &&
CollectionUtils.isEmpty(param.getIncludeLabels()) &&
CollectionUtils.isEmpty(includePersonIds)) {
return new ArrayList<>();
}
List<IsImageStoreAssociated> imageStoreAssociatedList = new ArrayList<>();
if (CpImageStoreMatchPatternEnum.getByCode(param.getMatchPattern()) != null) {
imageStoreAssociatedList.add(getAssociated(param.getMatchPattern(), time, context.getUser().getCaller(), imageStoreId, (Integer)null,
Integer.valueOf(4)));
} else {
imageStoreAssociatedList.add(getAssociated(CpImageStoreMatchPatternEnum.MERGE.getCode(), time, context.getUser().getCaller(), imageStoreId, (Integer)null,
Integer.valueOf(4)));
}
AssociatedParam imageStoreAssociatedParam = new AssociatedParam();
imageStoreAssociatedParam.setObjectId(imageStoreId);
imageStoreAssociatedParam.setExpiryBeginDate(param.getExpiryBeginDate());
imageStoreAssociatedParam.setExpiryEndDate(param.getExpiryEndDate());
imageStoreAssociatedParam.setValidDateCron(param.getValidDateCron());
imageStoreAssociatedList.add(getAssociated(imageStoreAssociatedParam, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(0), Integer.valueOf(5)));
if (!CollectionUtils.isEmpty(param.getIncludeOrganizations())) {
if (this.imgStoreOrganizationMapper.getOrgByIds(param.getIncludeOrganizations(), businessId).size() != param
.getIncludeOrganizations().size()) {
throw new ServiceException("53013513", getMessage("53013513"));
}
for (String objectId : param.getIncludeOrganizations()) {
imageStoreAssociatedList.add(getAssociated(objectId, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(0), Integer.valueOf(1)));
}
}
if (!CollectionUtils.isEmpty(param.getIncludeLabels())) {
if (this.imgStoreLabelMapper.getLabelByIds(param.getIncludeLabels(), businessId).size() != param
.getIncludeLabels().size()) {
throw new ServiceException("53013514", getMessage("53013514"));
}
for (String objectId : param.getIncludeLabels()) {
imageStoreAssociatedList.add(getAssociated(objectId, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(0), Integer.valueOf(2)));
}
}
if (!CollectionUtils.isEmpty(includePersonIds)) {
ImgStorePersonQueryDto dto = new ImgStorePersonQueryDto();
dto.setIds(includePersonIds);
dto.setBusinessId(businessId);
dto.setIsDel(DelStatusEnum.NORAML.getCode());
if (this.personMapper.gets(dto).size() != includePersonIds.size()) {
throw new ServiceException("53013515", getMessage("53013515"));
}
for (AssociatedParam associatedParam : param.getIncludePersons()) {
if (!param.getNullDateIsLongTerm().booleanValue() && (null == associatedParam
.getExpiryBeginDate() || null == associatedParam.getExpiryEndDate())) {
associatedParam.setExpiryBeginDate(imageStoreAssociatedParam.getExpiryBeginDate());
associatedParam.setExpiryEndDate(imageStoreAssociatedParam.getExpiryEndDate());
associatedParam.setValidDateCron(imageStoreAssociatedParam.getValidDateCron());
}
imageStoreAssociatedList.add(getAssociated(associatedParam, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(0), Integer.valueOf(3)));
}
}
if (!CollectionUtils.isEmpty(param.getExcludeLabels())) {
if (this.imgStoreLabelMapper.getLabelByIds(param.getExcludeLabels(), businessId).size() != param
.getExcludeLabels().size()) {
throw new ServiceException("53013516", getMessage("53013516"));
}
for (String objectId : param.getExcludeLabels()) {
imageStoreAssociatedList.add(getAssociated(objectId, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(1), Integer.valueOf(2)));
}
}
if (!CollectionUtils.isEmpty(param.getExcludePersons())) {
ImgStorePersonQueryDto dto = new ImgStorePersonQueryDto();
dto.setIds(param.getExcludePersons());
dto.setBusinessId(businessId);
dto.setIsDel(DelStatusEnum.NORAML.getCode());
if (this.personMapper.gets(dto).size() != param.getExcludePersons().size()) {
throw new ServiceException("53013517", getMessage("53013517"));
}
for (String objectId : param.getExcludePersons()) {
imageStoreAssociatedList.add(getAssociated(objectId, time, context.getUser().getCaller(), imageStoreId,
Integer.valueOf(1), Integer.valueOf(3)));
}
}
return imageStoreAssociatedList;
}
private String getBusinessName(String businessId) throws ServiceException {
GeneralQueryBusinessParam generalQueryBusinessParam = new GeneralQueryBusinessParam();
generalQueryBusinessParam.setId(businessId);
CloudwalkResult<List<AcBusinessDTO>> cloudwalkResult = this.acBusinessService.generalQuery(generalQueryBusinessParam);
if (cloudwalkResult == null) {
throw new ServiceException("53013535",
getMessage("53013535"));
}
if (!cloudwalkResult.isSuccess()) {
throw new ServiceException(cloudwalkResult.getCode(), cloudwalkResult.getMessage());
}
if (cloudwalkResult.getData() != null && ((List)cloudwalkResult.getData()).size() > 0) {
return ((AcBusinessDTO)((List<AcBusinessDTO>)cloudwalkResult.getData()).get(0)).getName();
}
return null;
}
private String getSourceApplicationName(String sourceApplicationId) throws ServiceException {
if (StringUtils.isEmpty(sourceApplicationId)) {
return null;
}
ApplicationBasicParam applicationBasicParam = new ApplicationBasicParam();
applicationBasicParam.setIds(Arrays.asList(new String[] { sourceApplicationId }));
CloudwalkResult<List<ApplicationResult>> cloudwalkResult = this.applicationService.gets(applicationBasicParam);
if (cloudwalkResult == null) {
throw new ServiceException("53013547",
getMessage("53013547"));
}
if (!cloudwalkResult.isSuccess()) {
throw new ServiceException(cloudwalkResult.getCode(), cloudwalkResult.getMessage());
}
if (cloudwalkResult.getData() != null && ((List)cloudwalkResult.getData()).size() > 0) {
return ((ApplicationResult)((List<ApplicationResult>)cloudwalkResult.getData()).get(0)).getName();
}
return null;
}
private void checkExistAndStatus(String iamgeStoreId) throws ServiceException {
AgImageStoreQueryParam queryParam = new AgImageStoreQueryParam();
queryParam.setId(iamgeStoreId);
CloudwalkResult<List<AgImageStoreResult>> query = this.agImageStoreService.query(queryParam);
if (!query.isSuccess()) {
throw new ServiceException(query.getCode(), query.getMessage());
}
if (CollectionUtils.isEmpty((Collection)query.getData())) {
throw new ServiceException("53013502",
getMessage("53013502"));
}
if (SyncStatusEnum.SYNC_ING.getCode().equals(((AgImageStoreResult)((List<AgImageStoreResult>)query.getData()).get(0)).getStatus())) {
throw new ServiceException("53013512",
getMessage("53013512"));
}
}
private Map<String, String> getBusinessNameMap() throws ServiceException {
CloudwalkResult<List<AcBusinessDTO>> listCloudwalkResult = this.acBusinessService.generalQuery(new GeneralQueryBusinessParam());
if (!listCloudwalkResult.isSuccess()) {
throw new ServiceException(listCloudwalkResult.getCode(), listCloudwalkResult.getMessage());
}
if (CollectionUtils.isEmpty((Collection)listCloudwalkResult.getData())) {
return new HashMap<>();
}
return Collections3.extractToMap((Collection)listCloudwalkResult.getData(), "id", "name");
}
private Map<String, String> getSourceApplicationNameMap(String businessId) throws ServiceException {
ApplicationQueryParam param = new ApplicationQueryParam();
param.setBusinessId(businessId);
param.setStatus(CommonStatusEnum.ENABLE.getCode());
CloudwalkResult<List<ApplicationResult>> listCloudwalkResult = this.applicationService.query(param);
if (!listCloudwalkResult.isSuccess()) {
throw new ServiceException(listCloudwalkResult.getCode(), listCloudwalkResult.getMessage());
}
if (CollectionUtils.isEmpty((Collection)listCloudwalkResult.getData())) {
return new HashMap<>();
}
return Collections3.extractToMap((Collection)listCloudwalkResult.getData(), "id", "name");
}
private void getAssociated(ImageStoreDetailResult result) {
GetsImageStoreAssociatedDTO get = new GetsImageStoreAssociatedDTO();
get.setImageStoreId(result.getId());
List<IsImageStoreAssociated> associateds = this.isImageStoreAssociatedMapper.gets(get);
String matchPattern = null;
List<String> includeLabelIds = new ArrayList<>();
List<String> includeOrganizationIds = new ArrayList<>();
List<String> includePersonIds = new ArrayList<>();
Map<String, AssociatedResult> includePersonMap = new HashMap<>();
List<String> excludeLabelIds = new ArrayList<>();
List<String> excludePersonIds = new ArrayList<>();
String businessId = result.getBusinessId();
for (IsImageStoreAssociated associated : associateds) {
if (4 == associated.getAssociatedObjectIdType().intValue()) {
matchPattern = associated.getAssociatedObjectId(); continue;
}
if (0 == associated.getAssociatedAction().intValue()) {
if (1 == associated.getAssociatedObjectIdType().intValue()) {
includeOrganizationIds.add(associated.getAssociatedObjectId()); continue;
} if (2 == associated.getAssociatedObjectIdType().intValue()) {
includeLabelIds.add(associated.getAssociatedObjectId()); continue;
} if (3 == associated.getAssociatedObjectIdType().intValue()) {
includePersonIds.add(associated.getAssociatedObjectId());
AssociatedResult associatedResult = new AssociatedResult();
BeanCopyUtils.copyProperties(associated, associatedResult);
associatedResult.setObjectId(associated.getAssociatedObjectId());
includePersonMap.put(associated.getAssociatedObjectId(), associatedResult); continue;
} if (5 == associated.getAssociatedObjectIdType().intValue()) {
result.setExpiryBeginDate(associated.getExpiryBeginDate());
result.setExpiryEndDate(associated.getExpiryEndDate());
result.setValidDateCron(JsonUtils.toStrList(associated.getValidDateCron()));
} continue;
} if (1 == associated.getAssociatedAction().intValue()) {
if (2 == associated.getAssociatedObjectIdType().intValue()) {
excludeLabelIds.add(associated.getAssociatedObjectId()); continue;
} if (3 == associated.getAssociatedObjectIdType().intValue()) {
excludePersonIds.add(associated.getAssociatedObjectId());
}
}
}
result.setMatchPattern(matchPattern);
if (!CollectionUtils.isEmpty(includeLabelIds)) {
result.setIncludeLabels(BeanCopyUtils.copy(this.imgStoreLabelMapper.getLabelByIds(includeLabelIds, businessId), LabelResult.class));
} else {
result.setIncludeLabels(new ArrayList());
}
if (!CollectionUtils.isEmpty(includeOrganizationIds)) {
result.setIncludeOrganizations(BeanCopyUtils.copy(this.imgStoreOrganizationMapper.getOrgByIds(includeOrganizationIds, businessId), OrganizationResult.class));
} else {
result.setIncludeOrganizations(new ArrayList());
}
ImgStorePersonQueryDto getDTO = new ImgStorePersonQueryDto();
if (!CollectionUtils.isEmpty(includePersonIds)) {
getDTO.setIds(includePersonIds);
getDTO.setIsDel(DelStatusEnum.NORAML.getCode());
List<ImgStorePerson> personList = this.personMapper.gets(getDTO);
List<ImgStorePersonResult> includePersons = new ArrayList<>();
personList.forEach(imgStorePerson -> {
ImgStorePersonResult imgStorePersonResult = new ImgStorePersonResult();
BeanCopyUtils.copyProperties(imgStorePerson, imgStorePersonResult);
AssociatedResult associatedResult = (AssociatedResult)includePersonMap.get(imgStorePerson.getId());
BeanCopyUtils.copyProperties(associatedResult, imgStorePersonResult);
imgStorePersonResult.setValidDateCron(JsonUtils.toStrList(associatedResult.getValidDateCron()));
includePersons.add(imgStorePersonResult);
});
result.setIncludePersons(includePersons);
} else {
result.setIncludePersons(new ArrayList());
}
if (!CollectionUtils.isEmpty(excludeLabelIds)) {
result.setExcludeLabels(BeanCopyUtils.copy(this.imgStoreLabelMapper.getLabelByIds(excludeLabelIds, businessId), LabelResult.class));
} else {
result.setExcludeLabels(new ArrayList());
}
if (!CollectionUtils.isEmpty(excludePersonIds)) {
getDTO.setIds(excludePersonIds);
getDTO.setIsDel(DelStatusEnum.NORAML.getCode());
result.setExcludePersons(BeanCopyUtils.copy(this.personMapper.gets(getDTO), ImgStorePersonResult.class));
} else {
result.setExcludePersons(new ArrayList());
}
}
private boolean handleQueryParam(QueryImageStoreParam queryParam) {
if (StringUtils.isNotBlank(queryParam.getOrgId()) ||
!CollectionUtils.isEmpty(queryParam.getOrgIds())) {
List<OrganizationImageStore> orgImageStoreList = this.organizationImageStoreMapper.query((OrganizationImageStoreQueryDTO)BeanCopyUtils.copyProperties(queryParam, OrganizationImageStoreQueryDTO.class));
GetsImageStoreAssociatedDTO orgParam = new GetsImageStoreAssociatedDTO();
orgParam.setAssociatedObjectIdType(Integer.valueOf(1));
List<String> orgIds = new ArrayList<>(500);
if (StringUtils.isNotBlank(queryParam.getOrgId())) {
orgIds.add(queryParam.getOrgId());
}
if (!CollectionUtils.isEmpty(queryParam.getOrgIds())) {
orgIds.addAll(queryParam.getOrgIds());
}
orgParam.setAssociatedObjectIds(orgIds);
List<IsImageStoreAssociated> orgResultList = this.isImageStoreAssociatedMapper.gets(orgParam);
if (CollectionUtils.isEmpty(orgImageStoreList) && CollectionUtils.isEmpty(orgResultList)) {
return true;
}
List<String> imageStoreIds = Collections3.extractToList(orgImageStoreList, "imageStoreId");
imageStoreIds.addAll(Collections3.extractToList(orgResultList, "imageStoreId"));
if (StringUtils.isNotBlank(queryParam.getId())) {
if (!imageStoreIds.contains(queryParam.getId())) {
return true;
}
} else if (!CollectionUtils.isEmpty(queryParam.getIds())) {
imageStoreIds.retainAll(queryParam.getIds());
}
if (CollectionUtils.isEmpty(imageStoreIds)) {
return true;
}
queryParam.setIds(imageStoreIds);
}
if (!CollectionUtils.isEmpty(queryParam.getPersonIds())) {
QueryGroupPersonDTO queryGroupPersonDTO = (QueryGroupPersonDTO)BeanCopyUtils.copyProperties(queryParam, QueryGroupPersonDTO.class);
queryGroupPersonDTO.setIsDel(DelStatusEnum.NORAML.getCode());
List<GroupPersonRef> queryResult = this.groupPersonRefMapper.query(queryGroupPersonDTO);
if (CollectionUtils.isEmpty(queryResult)) {
return true;
}
List<String> imageStoreIds = Collections3.extractToList(queryResult, "imageStoreId");
if (StringUtils.isNotBlank(queryParam.getId())) {
if (!imageStoreIds.contains(queryParam.getId())) {
return true;
}
} else if (!CollectionUtils.isEmpty(queryParam.getIds())) {
imageStoreIds.retainAll(queryParam.getIds());
}
if (CollectionUtils.isEmpty(imageStoreIds)) {
return true;
}
queryParam.setIds(imageStoreIds);
}
if (!CollectionUtils.isEmpty(queryParam.getLabelIds())) {
GetsImageStoreAssociatedDTO labelParam = new GetsImageStoreAssociatedDTO();
labelParam.setAssociatedObjectIdType(Integer.valueOf(2));
labelParam.setAssociatedObjectIds(queryParam.getLabelIds());
List<IsImageStoreAssociated> labelResultList = this.isImageStoreAssociatedMapper.gets(labelParam);
if (CollectionUtils.isEmpty(labelResultList)) {
return true;
}
List<String> imageStoreIds = Collections3.extractToList(labelResultList, "imageStoreId");
if (StringUtils.isNotBlank(queryParam.getId())) {
if (!imageStoreIds.contains(queryParam.getId())) {
return true;
}
} else if (!CollectionUtils.isEmpty(queryParam.getIds())) {
imageStoreIds.retainAll(queryParam.getIds());
}
if (CollectionUtils.isEmpty(imageStoreIds)) {
return true;
}
queryParam.setIds(imageStoreIds);
}
return false;
}
private List<ImageStoreResult> packageImageStoreResult(Collection<AgImageStoreResult> agDatas, String businessId) throws ServiceException {
if (CollectionUtils.isEmpty(agDatas)) {
return new ArrayList<>();
}
List<String> imageIds = (List<String>)agDatas.stream().map(AgImageStoreResult::getId).collect(Collectors.toList());
long startTime = System.currentTimeMillis();
List<ImageStoreCountDTO> countByImageStoreIds = Lists.newArrayListWithCapacity(imageIds.size());
List<List<String>> partition = Lists.partition(imageIds, this.searchSize);
partition.stream().forEach(p -> {
List<ImageStoreCountDTO> list = this.groupPersonRefMapper.getCountByImageStoreIds(p);
if (!CollectionUtils.isEmpty(list)) {
countByImageStoreIds.addAll(list);
}
});
long endTime = System.currentTimeMillis();
this.logger.info("图库分页查询耗时:[{}],searchSize:[{}]", Long.valueOf(endTime - startTime), Integer.valueOf(this.searchSize));
Map<String, Integer> countMap = (Map<String, Integer>)countByImageStoreIds.stream().filter(imageStoreCountDTO -> (null != imageStoreCountDTO)).collect(Collectors.toMap(ImageStoreCountDTO::getId, ImageStoreCountDTO::getCount, (k1, k2) -> k1));
Map<String, String> businessNameMap = getBusinessNameMap();
Map<String, String> sourceApplicationNameMap = getSourceApplicationNameMap(businessId);
List<ImageStoreResult> resultList = new ArrayList<>(agDatas.size());
for (AgImageStoreResult agData : agDatas) {
ImageStoreResult temp = (ImageStoreResult)BeanCopyUtils.copyProperties(agData, ImageStoreResult.class);
temp.setBusinessName(businessNameMap.get(temp.getBusinessId()));
temp.setSourceApplicationName(sourceApplicationNameMap.get(temp.getSourceApplicationId()));
temp.setPersonNum(countMap.containsKey(agData.getId()) ? countMap.get(agData.getId()) : Integer.valueOf(0));
getAssociated((ImageStoreDetailResult)temp);
resultList.add(temp);
}
return resultList;
}
private List<PageImageStoreResult> packageCpResult(Collection<AgImageStoreResult> agDatas, String businessId) throws ServiceException {
if (CollectionUtils.isEmpty(agDatas)) {
return new ArrayList<>();
}
List<String> imageIds = (List<String>)agDatas.stream().map(AgImageStoreResult::getId).collect(Collectors.toList());
long startTime = System.currentTimeMillis();
List<ImageStoreCountDTO> countByImageStoreIds = Lists.newArrayListWithCapacity(imageIds.size());
List<List<String>> partition = Lists.partition(imageIds, this.searchSize);
partition.stream().forEach(p -> {
List<ImageStoreCountDTO> list = this.groupPersonRefMapper.getCountByImageStoreIds(p);
if (!CollectionUtils.isEmpty(list)) {
countByImageStoreIds.addAll(list);
}
});
long endTime = System.currentTimeMillis();
this.logger.info("图库分页查询耗时:[{}],searchSize:[{}]", Long.valueOf(endTime - startTime), Integer.valueOf(this.searchSize));
Map<String, Integer> countMap = (Map<String, Integer>)countByImageStoreIds.stream().filter(imageStoreCountDTO -> (null != imageStoreCountDTO)).collect(Collectors.toMap(ImageStoreCountDTO::getId, ImageStoreCountDTO::getCount, (k1, k2) -> k1));
Map<String, String> businessNameMap = getBusinessNameMap();
Map<String, String> sourceApplicationNameMap = getSourceApplicationNameMap(businessId);
List<PageImageStoreResult> resultList = new ArrayList<>(agDatas.size());
for (AgImageStoreResult agData : agDatas) {
PageImageStoreResult temp = (PageImageStoreResult)BeanCopyUtils.copyProperties(agData, PageImageStoreResult.class);
temp.setBusinessName(businessNameMap.get(temp.getBusinessId()));
temp.setSourceApplicationName(sourceApplicationNameMap.get(temp.getSourceApplicationId()));
temp.setPersonNum(countMap.containsKey(agData.getId()) ? countMap.get(agData.getId()) : Integer.valueOf(0));
resultList.add(temp);
}
return resultList;
}
private Integer getPersonNum(String id) {
List<ImageStoreCountDTO> countByImageStoreIds = this.groupPersonRefMapper.getCountByImageStoreIds(Lists.newArrayList(id ));
if (CollectionUtils.isEmpty(countByImageStoreIds) || countByImageStoreIds.get(0) == null) {
return Integer.valueOf(0);
}
return ((ImageStoreCountDTO)countByImageStoreIds.get(0)).getCount();
}
}
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/CpImageStoreServiceImpl.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -3,7 +3,6 @@ package cn.cloudwalk.service.organization.service;
import cn.cloudwalk.client.aggregate.device.param.DeviceImageStoreQueryParam; import cn.cloudwalk.client.aggregate.device.param.DeviceImageStoreQueryParam;
import cn.cloudwalk.client.aggregate.device.param.DeviceImageStoreReSyncParam; import cn.cloudwalk.client.aggregate.device.param.DeviceImageStoreReSyncParam;
import cn.cloudwalk.client.aggregate.device.result.DeviceImageStoreQueryResult; import cn.cloudwalk.client.aggregate.device.result.DeviceImageStoreQueryResult;
import cn.cloudwalk.client.aggregate.device.result.DeviceImageStoreReSyncResult;
import cn.cloudwalk.client.aggregate.device.service.AggDeviceImageStoreService; import cn.cloudwalk.client.aggregate.device.service.AggDeviceImageStoreService;
import cn.cloudwalk.client.device.mgn.atomic.param.AtomicDeviceCommonParam; import cn.cloudwalk.client.device.mgn.atomic.param.AtomicDeviceCommonParam;
import cn.cloudwalk.client.device.mgn.atomic.result.CoreDeviceDetailResult; import cn.cloudwalk.client.device.mgn.atomic.result.CoreDeviceDetailResult;
@@ -21,10 +20,12 @@ import cn.cloudwalk.data.organization.mapper.DeviceImageStoreMapper;
import cn.cloudwalk.data.organization.mapper.DevicePersonSyncLogMapper; import cn.cloudwalk.data.organization.mapper.DevicePersonSyncLogMapper;
import cn.cloudwalk.data.organization.mapper.GroupPersonRefMapper; import cn.cloudwalk.data.organization.mapper.GroupPersonRefMapper;
import cn.cloudwalk.service.organization.common.AbstractImagStoreService; import cn.cloudwalk.service.organization.common.AbstractImagStoreService;
import cn.cloudwalk.service.organization.service.CpImageStoreSyncManager;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@@ -35,10 +36,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@Component @Component
public class DeviceGroupRefChangeEventHandler public class DeviceGroupRefChangeEventHandler
extends AbstractImagStoreService extends AbstractImagStoreService {
{
@Resource @Resource
private AggDeviceImageStoreService aggDeviceImageStoreService; private AggDeviceImageStoreService aggDeviceImageStoreService;
@Resource @Resource
@@ -53,48 +54,51 @@ private DeviceImageStoreMapper deviceImageStoreMapper;
private GroupPersonRefMapper groupPersonRefMapper; private GroupPersonRefMapper groupPersonRefMapper;
@Resource @Resource
private UUIDSerial uuidSerial; private UUIDSerial uuidSerial;
@Value("${person.partition.size:100}") @Value(value="${person.partition.size:100}")
private Integer personPartitionSize; private Integer personPartitionSize;
@Async("deviceGroupChangeTaskExecutor")
@Async(value="deviceGroupChangeTaskExecutor")
public void handler(DeviceGroupRefChangeEvent event) { public void handler(DeviceGroupRefChangeEvent event) {
if (null == event) { if (null == event) {
return; return;
} }
if (StringUtils.isBlank(event.getDeviceId()) || StringUtils.isBlank(event.getGroupId())) { if (StringUtils.isBlank((CharSequence)event.getDeviceId()) || StringUtils.isBlank((CharSequence)event.getGroupId())) {
this.logger.warn("设备[{}]或者图库[{}]为空", event.getDeviceId(), event.getGroupId()); this.logger.warn("设备[{}]或者图库[{}]为空", (Object)event.getDeviceId(), (Object)event.getGroupId());
return; return;
} }
this.logger.debug("Kafka消费设备图库变更数据:[{}]", JSON.toJSONString(event)); this.logger.debug("Kafka消费设备图库变更数据:[{}]", (Object)JSON.toJSONString((Object)event));
try { try {
AtomicDeviceCommonParam queryDevice = new AtomicDeviceCommonParam(); AtomicDeviceCommonParam queryDevice = new AtomicDeviceCommonParam();
queryDevice.setId(event.getDeviceId()); queryDevice.setId(event.getDeviceId());
CloudwalkResult<CoreDeviceDetailResult> deviceResult = this.atomicDeviceService.detail(queryDevice, getCloudwalkContext()); CloudwalkResult deviceResult = this.atomicDeviceService.detail(queryDevice, this.getCloudwalkContext());
if (!deviceResult.isSuccess() || null == deviceResult.getData()) { if (!deviceResult.isSuccess() || null == deviceResult.getData()) {
this.logger.warn("查询设备[{}]失败", event.getDeviceId()); this.logger.warn("查询设备[{}]失败", (Object)event.getDeviceId());
return; return;
} }
CoreDeviceDetailResult device = (CoreDeviceDetailResult)deviceResult.getData(); CoreDeviceDetailResult device = (CoreDeviceDetailResult)deviceResult.getData();
if (device.getIdentifyType().shortValue() != 0) { if (device.getIdentifyType() != 0) {
this.logger.warn("设备[{}]非前端识别", device.getId()); this.logger.warn("设备[{}]非前端识别", (Object)device.getId());
return; return;
} }
saveDeviceImageStoreChange(event); this.saveDeviceImageStoreChange(event);
unbindDeviceImageStore(event, device); this.unbindDeviceImageStore(event, device);
bindDeviceImageStore(event); this.bindDeviceImageStore(event);
} catch (Exception e) { }
this.logger.error("执行报错 {}: {}", e.getClass().getName(), e.getMessage()); catch (Exception e) {
this.logger.error("执行报错 {}: {}", (Object)e.getClass().getName(), (Object)e.getMessage());
} }
} }
private int saveDeviceImageStoreChange(DeviceGroupRefChangeEvent event) { private int saveDeviceImageStoreChange(DeviceGroupRefChangeEvent event) {
Long time = Long.valueOf(System.currentTimeMillis()); Long time = System.currentTimeMillis();
DeviceImageStore query = new DeviceImageStore(); DeviceImageStore query = new DeviceImageStore();
query.setDeviceId(event.getDeviceId()); query.setDeviceId(event.getDeviceId());
query.setImageStoreId(event.getGroupId()); query.setImageStoreId(event.getGroupId());
query.setType(Integer.valueOf(event.getType().shortValue())); query.setType(Integer.valueOf(event.getType().shortValue()));
query.setLastUpdateTime(time); query.setLastUpdateTime(time);
List<DeviceImageStore> result = this.deviceImageStoreMapper.select(query); List result = this.deviceImageStoreMapper.select(query);
if (CollectionUtils.isEmpty(result)) { if (CollectionUtils.isEmpty((Collection)result)) {
this.logger.debug("根据设备[{}]图库[{}]未查询到变更记录,新增", event.getDeviceId(), event.getGroupId()); this.logger.debug("根据设备[{}]图库[{}]未查询到变更记录,新增", (Object)event.getDeviceId(), (Object)event.getGroupId());
query.setId(this.uuidSerial.uuid()); query.setId(this.uuidSerial.uuid());
query.setCreateTime(time); query.setCreateTime(time);
return this.deviceImageStoreMapper.insertSelective(query); return this.deviceImageStoreMapper.insertSelective(query);
@@ -104,131 +108,128 @@ query.setFinishPullTime(null);
query.setStatus(StatusEnum.UNNOTIFY.getValue()); query.setStatus(StatusEnum.UNNOTIFY.getValue());
return this.deviceImageStoreMapper.update(query); return this.deviceImageStoreMapper.update(query);
} }
private void unbindDeviceImageStore(DeviceGroupRefChangeEvent event, CoreDeviceDetailResult device) { private void unbindDeviceImageStore(DeviceGroupRefChangeEvent event, CoreDeviceDetailResult device) {
if (event.getType().shortValue() != 2) { if (event.getType() != 2) {
return; return;
} }
this.logger.debug("开始处理设备[{}]图库[{}]解绑", event.getDeviceId(), event.getGroupId()); this.logger.debug("开始处理设备[{}]图库[{}]解绑", (Object)event.getDeviceId(), (Object)event.getGroupId());
try { try {
DeviceImageStoreQueryParam storeQueryParam = new DeviceImageStoreQueryParam(); DeviceImageStoreQueryParam storeQueryParam = new DeviceImageStoreQueryParam();
storeQueryParam.setDeviceId(event.getDeviceId()); storeQueryParam.setDeviceId(event.getDeviceId());
CloudwalkResult<List<DeviceImageStoreQueryResult>> imageStoreResult = this.aggDeviceImageStoreService.query(storeQueryParam, getCloudwalkContext()); CloudwalkResult imageStoreResult = this.aggDeviceImageStoreService.query(storeQueryParam, this.getCloudwalkContext());
if (imageStoreResult.isSuccess() && !CollectionUtils.isEmpty((Collection)imageStoreResult.getData())) { if (imageStoreResult.isSuccess() && !CollectionUtils.isEmpty((Collection)((Collection)imageStoreResult.getData()))) {
this.logger.debug("设备[{}]仍绑定其他图库", event.getDeviceId()); this.logger.debug("设备[{}]仍绑定其他图库", (Object)event.getDeviceId());
String deviceCode = device.getDeviceCode(); String deviceCode = device.getDeviceCode();
if (null == device.getSupportMultiPersonGroup() || if (null == device.getSupportMultiPersonGroup() || Objects.equals(device.getSupportMultiPersonGroup().intValue(), DeviceAbilityEnum.NOT_SUPPORT_MULTI_PERSON_GROUP.getCode())) {
Objects.equals(Integer.valueOf(device.getSupportMultiPersonGroup().intValue()), this.logger.debug("设备[{}]code[{}]不支持多图库,下发50009", (Object)event.getDeviceId(), (Object)deviceCode);
Integer.valueOf(DeviceAbilityEnum.NOT_SUPPORT_MULTI_PERSON_GROUP.getCode()))) { List<String> imageStoreIds = ((List)imageStoreResult.getData()).stream().map(DeviceImageStoreQueryResult::getImageStoreId).collect(Collectors.toList());
this.logger.debug("设备[{}]code[{}]不支持多图库,下发50009", event.getDeviceId(), deviceCode); this.updateSyncLog(event, imageStoreIds);
List<String> imageStoreIds = (List<String>)((List)imageStoreResult.getData()).stream().map(DeviceImageStoreQueryResult::getImageStoreId).collect( HashSet changeGroupIdSet = Sets.newHashSet();
Collectors.toList());
updateSyncLog(event, imageStoreIds);
Set<String> changeGroupIdSet = Sets.newHashSet();
changeGroupIdSet.add(event.getGroupId()); changeGroupIdSet.add(event.getGroupId());
((List)imageStoreResult.getData()).stream().forEach(imageStore -> changeGroupIdSet.add(imageStore.getImageStoreId())); ((List)imageStoreResult.getData()).stream().forEach(imageStore -> changeGroupIdSet.add(imageStore.getImageStoreId()));
this.cpImageStoreSyncManager.sendChangeToDevice(event.getDeviceId(), changeGroupIdSet, false); this.cpImageStoreSyncManager.sendChangeToDevice(event.getDeviceId(), changeGroupIdSet, false);
return; return;
} }
} }
notify50010(event); this.notify50010(event);
} catch (Exception e) { }
catch (Exception e) {
this.logger.error("设备[{}]图库[{}]解绑执行异常:{}", new Object[]{event.getDeviceId(), event.getGroupId(), e.getMessage()}); this.logger.error("设备[{}]图库[{}]解绑执行异常:{}", new Object[]{event.getDeviceId(), event.getGroupId(), e.getMessage()});
} }
} }
private void updateSyncLog(DeviceGroupRefChangeEvent event, List<String> imageStoreIds) { private void updateSyncLog(DeviceGroupRefChangeEvent event, List<String> imageStoreIds) {
DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO(); DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO();
query.setDeviceId(event.getDeviceId()); query.setDeviceId(event.getDeviceId());
query.setImageStoreId(event.getGroupId()); query.setImageStoreId(event.getGroupId());
List<DevicePersonSyncLog> dbSyncLogList = this.devicePersonSyncLogMapper.query(query); List dbSyncLogList = this.devicePersonSyncLogMapper.query(query);
Set<String> personIdSet = (Set<String>)dbSyncLogList.stream().map(DevicePersonSyncLog::getPersonId).collect( Set personIdSet = dbSyncLogList.stream().map(DevicePersonSyncLog::getPersonId).collect(Collectors.toSet());
Collectors.toSet()); List personIdPartition = Lists.partition((List)Lists.newArrayList(personIdSet), (int)this.personPartitionSize);
List<List<String>> personIdPartition = Lists.partition(Lists.newArrayList(personIdSet), this.personPartitionSize.intValue()); for (List personIds : personIdPartition) {
for (List<String> personIds : personIdPartition) {
query.setImageStoreIds(imageStoreIds); query.setImageStoreIds(imageStoreIds);
query.setPersonIds(personIds); query.setPersonIds(personIds);
List<String> personIdList = this.devicePersonSyncLogMapper.findPersonIds(query); List personIdList = this.devicePersonSyncLogMapper.findPersonIds(query);
Long currentTime = Long.valueOf(System.currentTimeMillis()); Long currentTime = System.currentTimeMillis();
if (!CollectionUtils.isEmpty(personIdList)) { if (!CollectionUtils.isEmpty((Collection)personIdList)) {
this.logger.info("移除在其他图库中的人员:[{}]", personIdList); this.logger.info("移除在其他图库中的人员:[{}]", (Object)personIdList);
personIdSet.removeAll(personIdList); personIdSet.removeAll(personIdList);
query.setPersonIds(personIdList); query.setPersonIds(personIdList);
query.setLastUpdateTime(currentTime); query.setLastUpdateTime(currentTime);
this.devicePersonSyncLogMapper.updateLastTimeOfGroupPerson(query); this.devicePersonSyncLogMapper.updateLastTimeOfGroupPerson(query);
query.setLastUpdateTime(null); query.setLastUpdateTime(null);
query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue().intValue())); query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue()));
query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue())); query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue()));
int res = this.devicePersonSyncLogMapper.updateIsDel(query); int res = this.devicePersonSyncLogMapper.updateIsDel(query);
this.logger.info("设备[{}]图库[{}]更新[{}]条人员存在其他图库中", new Object[] { event.getDeviceId(), event.getGroupId(), Integer.valueOf(res) }); this.logger.info("设备[{}]图库[{}]更新[{}]条人员存在其他图库中", new Object[]{event.getDeviceId(), event.getGroupId(), res});
} }
this.groupPersonRefMapper.updateLastUpdateTimeByPersonIds(event.getGroupId(), personIds, currentTime); this.groupPersonRefMapper.updateLastUpdateTimeByPersonIds(event.getGroupId(), personIds, currentTime);
} }
if (!CollectionUtils.isEmpty(personIdSet)) { if (!CollectionUtils.isEmpty(personIdSet)) {
personIdPartition = Lists.partition(Lists.newArrayList(personIdSet), this.personPartitionSize.intValue()); personIdPartition = Lists.partition((List)Lists.newArrayList(personIdSet), (int)this.personPartitionSize);
query = new DevicePersonSyncLogDTO(); query = new DevicePersonSyncLogDTO();
query.setDeviceId(event.getDeviceId()); query.setDeviceId(event.getDeviceId());
query.setImageStoreId(event.getGroupId()); query.setImageStoreId(event.getGroupId());
for (List<String> personIds : personIdPartition) { for (List personIds : personIdPartition) {
query.setPersonIds(personIds); query.setPersonIds(personIds);
query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis()));
query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue().intValue())); query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue()));
query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue())); query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue()));
int res = this.devicePersonSyncLogMapper.updateIsDel(query); int res = this.devicePersonSyncLogMapper.updateIsDel(query);
this.logger.info("设备[{}]图库[{}]更新[{}]条人员不存在其他图库中", new Object[] { event.getDeviceId(), event.getGroupId(), Integer.valueOf(res) }); this.logger.info("设备[{}]图库[{}]更新[{}]条人员不存在其他图库中", new Object[]{event.getDeviceId(), event.getGroupId(), res});
} }
} }
} }
private void notify50010(DeviceGroupRefChangeEvent event) { private void notify50010(DeviceGroupRefChangeEvent event) {
try { try {
DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO(); DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO();
query.setDeviceId(event.getDeviceId()); query.setDeviceId(event.getDeviceId());
query.setImageStoreId(event.getGroupId()); query.setImageStoreId(event.getGroupId());
query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis()));
query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue().intValue())); query.setIsDel(Integer.valueOf(StatusEnum.INVALID.getValue()));
query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue())); query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue()));
int res = this.devicePersonSyncLogMapper.updateIsDel(query); int res = this.devicePersonSyncLogMapper.updateIsDel(query);
this.logger.debug("设备[{}]图库[{}]解绑,逻辑删除[{}]条同步记录", new Object[] { event.getDeviceId(), event.getGroupId(), Integer.valueOf(res) }); this.logger.debug("设备[{}]图库[{}]解绑,逻辑删除[{}]条同步记录", new Object[]{event.getDeviceId(), event.getGroupId(), res});
this.logger.debug("设备[{}]图库[{}]下发50010", event.getDeviceId(), event.getGroupId()); this.logger.debug("设备[{}]图库[{}]下发50010", (Object)event.getDeviceId(), (Object)event.getGroupId());
DeviceImageStoreReSyncParam deviceImageStoreReSyncParam = new DeviceImageStoreReSyncParam(); DeviceImageStoreReSyncParam deviceImageStoreReSyncParam = new DeviceImageStoreReSyncParam();
deviceImageStoreReSyncParam.setDeviceId(event.getDeviceId()); deviceImageStoreReSyncParam.setDeviceId(event.getDeviceId());
deviceImageStoreReSyncParam.setImageStoreId(event.getGroupId()); deviceImageStoreReSyncParam.setImageStoreId(event.getGroupId());
CloudwalkResult<List<DeviceImageStoreReSyncResult>> result = this.aggDeviceImageStoreService.reSync(deviceImageStoreReSyncParam, getCloudwalkContext()); CloudwalkResult result = this.aggDeviceImageStoreService.reSync(deviceImageStoreReSyncParam, this.getCloudwalkContext());
if (result.isSuccess()) { if (result.isSuccess()) {
DeviceImageStore notify = new DeviceImageStore(); DeviceImageStore notify = new DeviceImageStore();
notify.setDeviceId(event.getDeviceId()); notify.setDeviceId(event.getDeviceId());
notify.setImageStoreId(event.getGroupId()); notify.setImageStoreId(event.getGroupId());
List<DeviceImageStore> deviceImageStoreList = this.deviceImageStoreMapper.select(notify); List deviceImageStoreList = this.deviceImageStoreMapper.select(notify);
if (!CollectionUtils.isEmpty(deviceImageStoreList)) { if (!CollectionUtils.isEmpty((Collection)deviceImageStoreList)) {
notify = deviceImageStoreList.get(0); notify = (DeviceImageStore)deviceImageStoreList.get(0);
notify.setStatus(StatusEnum.NOTIFY.getValue()); notify.setStatus(StatusEnum.NOTIFY.getValue());
notify.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); notify.setLastUpdateTime(Long.valueOf(System.currentTimeMillis()));
this.deviceImageStoreMapper.update(notify); this.deviceImageStoreMapper.update(notify);
} }
} }
} catch (Exception e) { }
catch (Exception e) {
this.logger.error("设备[{}]图库[{}]解绑执行异常:{}", new Object[]{event.getDeviceId(), event.getGroupId(), e.getMessage()}); this.logger.error("设备[{}]图库[{}]解绑执行异常:{}", new Object[]{event.getDeviceId(), event.getGroupId(), e.getMessage()});
} }
} }
private void bindDeviceImageStore(DeviceGroupRefChangeEvent event) { private void bindDeviceImageStore(DeviceGroupRefChangeEvent event) {
if (event.getType().shortValue() != 1) { if (event.getType() != 1) {
return; return;
} }
this.logger.debug("开始处理设备[{}]图库[{}]绑定", event.getDeviceId(), event.getGroupId()); this.logger.debug("开始处理设备[{}]图库[{}]绑定", (Object)event.getDeviceId(), (Object)event.getGroupId());
DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO(); DevicePersonSyncLogDTO query = new DevicePersonSyncLogDTO();
query.setDeviceId(event.getDeviceId()); query.setDeviceId(event.getDeviceId());
query.setImageStoreId(event.getGroupId()); query.setImageStoreId(event.getGroupId());
query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis())); query.setLastUpdateTime(Long.valueOf(System.currentTimeMillis()));
query.setIsDel(Integer.valueOf(StatusEnum.VALID.getValue().intValue())); query.setIsDel(Integer.valueOf(StatusEnum.VALID.getValue()));
query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue())); query.setStatus(Integer.valueOf(SyncStatusEnum.NOT_PULL.getValue()));
int res = this.devicePersonSyncLogMapper.updateIsDel(query); int res = this.devicePersonSyncLogMapper.updateIsDel(query);
this.logger.debug("设备[{}]图库[{}]绑定,更新[{}]条同步记录", new Object[] { event.getDeviceId(), event.getGroupId(), Integer.valueOf(res) }); this.logger.debug("设备[{}]图库[{}]绑定,更新[{}]条同步记录", new Object[]{event.getDeviceId(), event.getGroupId(), res});
Set<String> changeGroupIdSet = Sets.newHashSet(); HashSet changeGroupIdSet = Sets.newHashSet();
changeGroupIdSet.add(event.getGroupId()); changeGroupIdSet.add(event.getGroupId());
this.cpImageStoreSyncManager.sendChangeToDevice(event.getDeviceId(), changeGroupIdSet, false); this.cpImageStoreSyncManager.sendChangeToDevice(event.getDeviceId(), changeGroupIdSet, false);
} }
} }
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/DeviceGroupRefChangeEventHandler.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/
@@ -388,7 +388,7 @@ this.imgStoreLabelMapper.deletePerson(delPersonLabelDTO);
List<String> imageIdResultList = Lists.newArrayList(); List<String> imageIdResultList = Lists.newArrayList();
for (Map.Entry<String, List<String>> entry : delMap.entrySet()) { for (Map.Entry<String, List<String>> entry : delMap.entrySet()) {
GroupPersonSynData groupPersonSynData = new GroupPersonSynData(); GroupPersonSynData groupPersonSynData = new GroupPersonSynData();
groupPersonSynData.setDelPersonIds(Lists.newArrayList((Object[])new String[] { entry.getKey() })); groupPersonSynData.setDelPersonIds(Lists.newArrayList(entry.getKey() ));
String jsonData = JsonUtils.toJson(groupPersonSynData); String jsonData = JsonUtils.toJson(groupPersonSynData);
for (String imageStoreId : entry.getValue()) { for (String imageStoreId : entry.getValue()) {
this.cpImageStorePersonSynManager.addWaitSynTask(imageStoreId, jsonData); this.cpImageStorePersonSynManager.addWaitSynTask(imageStoreId, jsonData);
@@ -1,264 +0,0 @@
package cn.cloudwalk.service.organization.service;
// 业务服务
import cn.cloudwalk.client.device.mgn.atomic.param.CoreDeviceQueryParam;
import cn.cloudwalk.client.device.mgn.atomic.result.AtomicDeviceGetResult;
import cn.cloudwalk.client.device.mgn.atomic.service.AtomicDeviceService;
import cn.cloudwalk.client.organization.common.enums.DefaultPropertyEnum;
import cn.cloudwalk.client.organization.common.enums.RegistryTypeEnum;
import cn.cloudwalk.client.organization.common.enums.StatusEnum;
import cn.cloudwalk.client.organization.common.enums.UniquePropertyEnum;
import cn.cloudwalk.client.organization.service.store.param.AddPersonRegistryParam;
import cn.cloudwalk.client.organization.service.store.param.QueryPersonRegistryParam;
import cn.cloudwalk.client.organization.service.store.result.DeviceResult;
import cn.cloudwalk.client.organization.service.store.result.PersonPropertiesResult;
import cn.cloudwalk.client.organization.service.store.result.PersonRegistryResult;
import cn.cloudwalk.client.organization.service.store.service.IPersonRegistryHandler;
import cn.cloudwalk.cloud.annotation.CloudwalkParamsValidate;
import cn.cloudwalk.cloud.context.CloudwalkCallContext;
import cn.cloudwalk.cloud.exception.ServiceException;
import cn.cloudwalk.cloud.result.CloudwalkResult;
import cn.cloudwalk.cloud.utils.BeanCopyUtils;
import cn.cloudwalk.data.organization.entity.ImgStorePersonProperties;
import cn.cloudwalk.data.organization.entity.PersonRegistry;
import cn.cloudwalk.data.organization.entity.PersonRegistryDevice;
import cn.cloudwalk.data.organization.entity.PersonRegistryProperties;
import cn.cloudwalk.data.organization.mapper.ImgStorePersonPropertiesMapper;
import cn.cloudwalk.data.organization.mapper.PersonRegistryDeviceMapper;
import cn.cloudwalk.data.organization.mapper.PersonRegistryPropertiesMapper;
import cn.cloudwalk.service.organization.common.AbstractImagStoreService;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springside.modules.utils.Collections3;
@Service("SelfRegistryHandler")
public class SelfRegistryHandler
extends AbstractImagStoreService
implements IPersonRegistryHandler
{
@Resource
private CommonPersonRegistryService commonPersonRegistryService;
@Resource
private AtomicDeviceService atomicDeviceService;
@Resource
private ImgStorePersonPropertiesMapper imgStorePersonPropertiesMapper;
@Resource
private PersonRegistryPropertiesMapper personRegistryPropertiesMapper;
@Resource
private PersonRegistryDeviceMapper personRegistryDeviceMapper;
@CloudwalkParamsValidate
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}, value = "transactionManager")
public CloudwalkResult<Boolean> save(AddPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String businessId = context.getCompany().getCompanyId();
param.setBusinessId(businessId);
CloudwalkResult<Boolean> result = validateParams(param, context);
if (!result.isSuccess()) {
return result;
}
PersonRegistry personRegistry = this.commonPersonRegistryService.getByBusinessAndType(businessId, RegistryTypeEnum.SELF_REGISTRY.getValue());
if (null != personRegistry) {
param.setId(personRegistry.getId());
update(param, context);
} else {
insert(param, context);
}
return CloudwalkResult.success(Boolean.valueOf(true));
}
private CloudwalkResult<Boolean> validateParams(AddPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
if (null == param.getCodeStatus()) {
return CloudwalkResult.fail("53014502",
getMessage("53014502"));
}
if (CollectionUtils.isEmpty(param.getPropertyIdList())) {
return CloudwalkResult.fail("53014503",
getMessage("53014503"));
}
List<ImgStorePersonProperties> dbPersonProList = this.imgStorePersonPropertiesMapper.selectByIds(param.getBusinessId(), param.getPropertyIdList());
if (CollectionUtils.isEmpty(dbPersonProList) || dbPersonProList.size() != param.getPropertyIdList().size()) {
this.logger.warn("注册属性不属于人员基本属性,注册属性Id列表:[{}]", JSONObject.toJSONString(param.getPropertyIdList()));
return CloudwalkResult.fail("53014508",
getMessage("53014508"));
}
for (DefaultPropertyEnum default_property : DefaultPropertyEnum.values()) {
Optional<ImgStorePersonProperties> requiredOptional = dbPersonProList.stream().filter(property -> default_property.getValue().equals(property.getCode())).findFirst();
if (!requiredOptional.isPresent()) {
this.logger.warn("{}未勾选,注册属性Id列表:[{}]", default_property.getDescription(),
JSONObject.toJSONString(param.getPropertyIdList()));
return CloudwalkResult.fail("53014511", "注册属性" + default_property
.getDescription() + "必须勾选");
}
}
if (Objects.equals(param.getDeviceStatus(), StatusEnum.CLOSE.getValue()) ||
Objects.equals(param.getCodeStatus(), StatusEnum.CLOSE.getValue())) {
ImgStorePersonProperties queryPersonPro = new ImgStorePersonProperties();
queryPersonPro.setBusinessId(param.getBusinessId());
queryPersonPro.setStatus(StatusEnum.VALID.getValue());
queryPersonPro.setHasRequired(StatusEnum.REQUIRED.getValue());
List<ImgStorePersonProperties> requiredPersonProList = this.imgStorePersonPropertiesMapper.select(queryPersonPro);
if (!CollectionUtils.isEmpty(requiredPersonProList)) {
List<String> requiredPersonProIdList = Collections3.extractToList(requiredPersonProList, "id");
dbPersonProList = (List<ImgStorePersonProperties>)dbPersonProList.stream().filter(pro -> requiredPersonProIdList.contains(pro.getId())).collect(Collectors.toList());
if (dbPersonProList.size() != requiredPersonProList.size()) {
this.logger.warn("设备注册审核和扫码注册审核未同时打开,有未勾选的必填属性,注册属性Id列表:[{}]",
JSONObject.toJSONString(param.getPropertyIdList()));
return CloudwalkResult.fail("53014511",
getMessage("53014511"));
}
}
}
this.commonPersonRegistryService.validateOrg(param);
this.commonPersonRegistryService.validateLabel(param);
this.commonPersonRegistryService.validateDevice(param, context);
return CloudwalkResult.success(Boolean.valueOf(true));
}
private CloudwalkResult<Boolean> insert(AddPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String id = getPrimaryId();
this.commonPersonRegistryService.insertPersonRegistry(id, param, context);
this.commonPersonRegistryService.batchInsertPersonRegistryProperty(id, param);
this.commonPersonRegistryService.batchInsertPersonRegistryDevice(id, param, context, Boolean.valueOf(false));
return CloudwalkResult.success(Boolean.valueOf(true));
}
private CloudwalkResult<Boolean> update(AddPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
this.commonPersonRegistryService.updatePersonRegistry(param, context);
this.commonPersonRegistryService.batchUpdatePersonRegistryProperty(param);
this.commonPersonRegistryService.batchUpdatePersonRegistryDevice(param, context, Boolean.valueOf(false));
return CloudwalkResult.success(Boolean.valueOf(true));
}
@CloudwalkParamsValidate
public CloudwalkResult<PersonRegistryResult> detail(QueryPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String businessId = param.getBusinessId();
if (StringUtils.isBlank(businessId)) {
businessId = context.getCompany().getCompanyId();
}
PersonRegistryResult result = new PersonRegistryResult();
ImgStorePersonProperties queryPersonPro = new ImgStorePersonProperties();
queryPersonPro.setBusinessId(businessId);
queryPersonPro.setStatus(StatusEnum.VALID.getValue());
List<ImgStorePersonProperties> personPropertyList = this.imgStorePersonPropertiesMapper.select(queryPersonPro);
if (CollectionUtils.isEmpty(personPropertyList)) {
this.logger.warn("不存在人员属性");
return CloudwalkResult.fail("53014524",
getMessage("53014524"));
}
List<PersonPropertiesResult> proResultList = BeanCopyUtils.copy(personPropertyList, PersonPropertiesResult.class);
proResultList.forEach(propertyResult -> {
if (DefaultPropertyEnum.hasProperty(propertyResult.getCode())) {
propertyResult.setHasChecked(StatusEnum.CHECKED.getValue());
propertyResult.setHasDisabled(StatusEnum.DISABLED.getValue());
}
});
proResultList = (List<PersonPropertiesResult>)proResultList.stream().sorted(Comparator.comparing(PersonPropertiesResult::getOrderNum)).collect(Collectors.toList());
result.setPropertyList(proResultList);
PersonRegistry dbPersonRegistry = this.commonPersonRegistryService.getByBusinessAndType(businessId, RegistryTypeEnum.SELF_REGISTRY.getValue());
if (null != dbPersonRegistry) {
result = (PersonRegistryResult)BeanCopyUtils.copyProperties(dbPersonRegistry, PersonRegistryResult.class);
result.setPropertyList(proResultList);
this.commonPersonRegistryService.setOrg(dbPersonRegistry, result);
this.commonPersonRegistryService.setLabel(dbPersonRegistry, result);
List<PersonRegistryDevice> dbPersonRegistryDeviceList = this.personRegistryDeviceMapper.select(dbPersonRegistry.getId(), null);
if (!CollectionUtils.isEmpty(dbPersonRegistryDeviceList)) {
CoreDeviceQueryParam coreDeviceQueryParam = new CoreDeviceQueryParam();
coreDeviceQueryParam.setBusinessId(businessId);
coreDeviceQueryParam
.setDeviceCodes(Collections3.extractToList(dbPersonRegistryDeviceList, "deviceCode"));
CloudwalkResult<List<AtomicDeviceGetResult>> deviceGetResult = this.atomicDeviceService.list(coreDeviceQueryParam, context);
if (!CollectionUtils.isEmpty((Collection)deviceGetResult.getData())) {
List<DeviceResult> deviceResultList = Lists.newArrayListWithCapacity(((List)deviceGetResult.getData()).size());
((List)deviceGetResult.getData()).forEach(device -> {
DeviceResult deviceResult = new DeviceResult();
deviceResult.setDeviceCode(device.getDeviceCode());
deviceResult.setDeviceName(device.getDeviceName());
deviceResultList.add(deviceResult);
});
result.setDeviceList(deviceResultList);
}
}
List<PersonRegistryProperties> dbPersonRegistryProList = this.personRegistryPropertiesMapper.select(dbPersonRegistry.getId(), null);
List<String> personPropertyIdList = Collections3.extractToList(dbPersonRegistryProList, "personPropertyId");
result.getPropertyList().forEach(propertyResult -> {
if (personPropertyIdList.contains(propertyResult.getId())) {
propertyResult.setHasChecked(StatusEnum.CHECKED.getValue());
}
});
}
return CloudwalkResult.success(result);
}
@CloudwalkParamsValidate
public CloudwalkResult<List<PersonPropertiesResult>> getRegistryPropertyList(QueryPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String businessId = param.getBusinessId();
if (StringUtils.isBlank(businessId)) {
businessId = context.getCompany().getCompanyId();
}
PersonRegistry dbPersonRegistry = (PersonRegistry)this.commonPersonRegistryService.getResultByBusinessAndType(businessId, RegistryTypeEnum.SELF_REGISTRY.getValue()).getData();
this.commonPersonRegistryService.validateDevice(param, dbPersonRegistry);
return CloudwalkResult.success(getPersonPropertyList(dbPersonRegistry, true));
}
@CloudwalkParamsValidate
public CloudwalkResult<List<PersonPropertiesResult>> getAuditPropertyList(QueryPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String businessId = param.getBusinessId();
if (StringUtils.isBlank(businessId)) {
businessId = context.getCompany().getCompanyId();
}
PersonRegistry dbPersonRegistry = (PersonRegistry)this.commonPersonRegistryService.getResultByBusinessAndType(businessId, RegistryTypeEnum.SELF_REGISTRY.getValue()).getData();
return CloudwalkResult.success(getPersonPropertyList(dbPersonRegistry, false));
}
private List<PersonPropertiesResult> getPersonPropertyList(PersonRegistry personRegistry, boolean isChecked) {
List<PersonRegistryProperties> dbPersonRegistryProList = this.personRegistryPropertiesMapper.select(personRegistry.getId(), null);
List<String> personProIdList = Collections3.extractToList(dbPersonRegistryProList, "personPropertyId");
ImgStorePersonProperties queryPersonPro = new ImgStorePersonProperties();
queryPersonPro.setBusinessId(personRegistry.getBusinessId());
queryPersonPro.setStatus(StatusEnum.VALID.getValue());
List<ImgStorePersonProperties> dbPersonProList = this.imgStorePersonPropertiesMapper.select(queryPersonPro);
List<PersonPropertiesResult> proResultList = BeanCopyUtils.copy(dbPersonProList, PersonPropertiesResult.class);
List<PersonPropertiesResult> defaultProList = BeanCopyUtils.copy(dbPersonProList, PersonPropertiesResult.class);
proResultList = (List<PersonPropertiesResult>)proResultList.stream().filter(proResult -> (personProIdList.contains(proResult.getId()) == isChecked)).collect(Collectors.toList());
defaultProList = (List<PersonPropertiesResult>)defaultProList.stream().filter(proResult -> DefaultPropertyEnum.hasProperty(proResult.getCode())).collect(Collectors.toList());
if (isChecked) {
proResultList.removeAll(defaultProList);
proResultList.addAll(defaultProList);
proResultList.forEach(proResult -> {
proResult.setHasChecked(StatusEnum.CHECKED.getValue());
if (DefaultPropertyEnum.hasProperty(proResult.getCode())) {
proResult.setHasDisabled(StatusEnum.DISABLED.getValue());
}
});
} else {
proResultList.removeAll(defaultProList);
}
proResultList = (List<PersonPropertiesResult>)proResultList.stream().sorted(Comparator.comparing(PersonPropertiesResult::getOrderNum)).collect(Collectors.toList());
return proResultList;
}
@CloudwalkParamsValidate
public CloudwalkResult<PersonPropertiesResult> getUniqueRegistryProperty(QueryPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
String businessId = param.getBusinessId();
if (StringUtils.isBlank(businessId)) {
businessId = context.getCompany().getCompanyId();
}
PersonRegistry dbPersonRegistry = (PersonRegistry)this.commonPersonRegistryService.getResultByBusinessAndType(businessId, RegistryTypeEnum.SELF_REGISTRY.getValue()).getData();
List<PersonPropertiesResult> propertyList = getPersonPropertyList(dbPersonRegistry, true);
AtomicReference<PersonPropertiesResult> result = new AtomicReference<>();
propertyList.stream().filter(property -> UniquePropertyEnum.hasProperty(property.getCode()))
.findFirst().ifPresent(personPropertiesResult -> result.set(personPropertiesResult));
return CloudwalkResult.success(result.get());
}
public CloudwalkResult<PersonPropertiesResult> getBindProperty(QueryPersonRegistryParam param, CloudwalkCallContext context) throws ServiceException {
return null;
}
}
/* Location: /media/zebra/9e8fa357-7db6-4d70-88ed-d5de5a059a663/星河湾星中星/部署包/ninca_common_component_organization_01-ninca_common_component_organization/ninca-common-component-organization-V2.9.2_20210730/BOOT-INF/lib/cwos-component-organization-service-v2.9.2_xinghewan.jar!/cn/cloudwalk/service/organization/service/SelfRegistryHandler.class
* Java compiler version: 8 (52.0)
* JD-Core Version: 1.1.3
*/