|
|
|
@ -16,6 +16,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.jayway.jsonpath.JsonPath; |
|
|
|
import com.jayway.jsonpath.JsonPath; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
import org.jetbrains.annotations.NotNull; |
|
|
|
@ -27,6 +28,7 @@ import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
@ -85,6 +87,16 @@ public class OnlineFormTenantSyncServiceImpl implements OnlineFormTenantSyncServ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public Boolean syncUpdateTenant(Long pageId, List<Long> tenantIdSet) { |
|
|
|
public Boolean syncUpdateTenant(Long pageId, List<Long> tenantIdSet) { |
|
|
|
|
|
|
|
syncFormUpdate(pageId, tenantIdSet); |
|
|
|
|
|
|
|
syncFormMetadata(Collections.singletonList(pageId), tenantIdSet); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void syncFormUpdate(Long pageId, Collection<Long> tenantIdSet) { |
|
|
|
|
|
|
|
if (pageId == null || CollUtil.isEmpty(tenantIdSet)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
List<OnlineForm> onlineFormListByPageIds = onlineFormService.getOnlineFormListByPageIds(Collections.singleton(pageId)); |
|
|
|
List<OnlineForm> onlineFormListByPageIds = onlineFormService.getOnlineFormListByPageIds(Collections.singleton(pageId)); |
|
|
|
for (OnlineForm onlineForm : onlineFormListByPageIds) { |
|
|
|
for (OnlineForm onlineForm : onlineFormListByPageIds) { |
|
|
|
List<OnlineDatasource> datasourceList = onlineDatasourceService.getOnlineDatasourceListByFormIds(Collections.singleton(onlineForm.getFormId())); |
|
|
|
List<OnlineDatasource> datasourceList = onlineDatasourceService.getOnlineDatasourceListByFormIds(Collections.singleton(onlineForm.getFormId())); |
|
|
|
@ -92,30 +104,8 @@ public class OnlineFormTenantSyncServiceImpl implements OnlineFormTenantSyncServ |
|
|
|
.map(OnlineDatasource::getDatasourceId) |
|
|
|
.map(OnlineDatasource::getDatasourceId) |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
RBucket<OnlineForm> bucket = redissonClient.getBucket("lastUpdateOnlineForm:" + onlineForm.getFormId()); |
|
|
|
RBucket<OnlineForm> bucket = redissonClient.getBucket("lastUpdateOnlineForm:" + onlineForm.getFormId()); |
|
|
|
OnlineForm lastUpdateOnlineForm; |
|
|
|
OnlineForm lastUpdateOnlineForm = bucket.get(); |
|
|
|
if (null != bucket) { |
|
|
|
|
|
|
|
lastUpdateOnlineForm = bucket.get(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
lastUpdateOnlineForm = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 根据表单json中的relativeFormCode获取到对应的查询数据源数据
|
|
|
|
|
|
|
|
String widgetJson = onlineForm.getWidgetJson(); |
|
|
|
|
|
|
|
List<String> relativeFormCodeList = parseRelativeFormCodes(widgetJson); |
|
|
|
|
|
|
|
List<OnlCgreportHead> onlCgreportHeadList = relativeFormCodeList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportHeadService.list(new LambdaQueryWrapper<OnlCgreportHead>() |
|
|
|
|
|
|
|
.in(OnlCgreportHead::getCode, relativeFormCodeList)); |
|
|
|
|
|
|
|
List<String> onlCgreportHeadIdList = onlCgreportHeadList.stream().map(OnlCgreportHead::getId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
List<OnlCgreportItem> onlCgreportItemList = onlCgreportHeadIdList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportItemService.list(new LambdaQueryWrapper<OnlCgreportItem>() |
|
|
|
|
|
|
|
.in(OnlCgreportItem::getCgrheadId, onlCgreportHeadIdList)); |
|
|
|
|
|
|
|
List<OnlCgreportParam> onlCgreportParamList = onlCgreportHeadIdList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportParamService.list(new LambdaQueryWrapper<OnlCgreportParam>() |
|
|
|
|
|
|
|
.in(OnlCgreportParam::getCgrheadId, onlCgreportHeadIdList)); |
|
|
|
|
|
|
|
for (Long tenantId : tenantIdSet) { |
|
|
|
for (Long tenantId : tenantIdSet) { |
|
|
|
// 表单更新同步通知
|
|
|
|
|
|
|
|
JSONObject formMsgJsonData = new JSONObject(); |
|
|
|
JSONObject formMsgJsonData = new JSONObject(); |
|
|
|
formMsgJsonData.put("tenantId", tenantId); |
|
|
|
formMsgJsonData.put("tenantId", tenantId); |
|
|
|
formMsgJsonData.put("adminOnlineForm", onlineForm); |
|
|
|
formMsgJsonData.put("adminOnlineForm", onlineForm); |
|
|
|
@ -128,51 +118,84 @@ public class OnlineFormTenantSyncServiceImpl implements OnlineFormTenantSyncServ |
|
|
|
TenantConstant.UPDATE_TENANT_ONLINE_FORM_COMMAND, |
|
|
|
TenantConstant.UPDATE_TENANT_ONLINE_FORM_COMMAND, |
|
|
|
formMsgJsonData.toJSONString(), |
|
|
|
formMsgJsonData.toJSONString(), |
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY); |
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY); |
|
|
|
//表单数据源更新同步新增
|
|
|
|
} |
|
|
|
JSONObject onlCgreportHeadMsgJsonData = new JSONObject(); |
|
|
|
} |
|
|
|
onlCgreportHeadMsgJsonData.put("tenantId", tenantId); |
|
|
|
} |
|
|
|
onlCgreportHeadMsgJsonData.put("onlCgreportHeadList", onlCgreportHeadList); |
|
|
|
|
|
|
|
onlCgreportHeadMsgJsonData.put("onlCgreportItemList", onlCgreportItemList); |
|
|
|
@Override |
|
|
|
onlCgreportHeadMsgJsonData.put("onlCgreportParamList", onlCgreportParamList); |
|
|
|
public void syncFormMetadata(Collection<Long> pageIds, Collection<Long> tenantIdSet) { |
|
|
|
|
|
|
|
if (CollUtil.isEmpty(pageIds) || CollUtil.isEmpty(tenantIdSet)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 1. 查询数据源:按表单 widgetJson 里的 relativeFormCode 反查
|
|
|
|
|
|
|
|
for (Long pageId : pageIds) { |
|
|
|
|
|
|
|
List<OnlineForm> onlineFormList = onlineFormService.getOnlineFormListByPageIds(Collections.singleton(pageId)); |
|
|
|
|
|
|
|
for (OnlineForm onlineForm : onlineFormList) { |
|
|
|
|
|
|
|
List<String> relativeFormCodeList = parseRelativeFormCodes(onlineForm.getWidgetJson()); |
|
|
|
|
|
|
|
List<OnlCgreportHead> onlCgreportHeadList = relativeFormCodeList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportHeadService.list(new LambdaQueryWrapper<OnlCgreportHead>() |
|
|
|
|
|
|
|
.in(OnlCgreportHead::getCode, relativeFormCodeList)); |
|
|
|
|
|
|
|
List<String> onlCgreportHeadIdList = onlCgreportHeadList.stream().map(OnlCgreportHead::getId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
List<OnlCgreportItem> onlCgreportItemList = onlCgreportHeadIdList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportItemService.list(new LambdaQueryWrapper<OnlCgreportItem>() |
|
|
|
|
|
|
|
.in(OnlCgreportItem::getCgrheadId, onlCgreportHeadIdList)); |
|
|
|
|
|
|
|
List<OnlCgreportParam> onlCgreportParamList = onlCgreportHeadIdList.isEmpty() |
|
|
|
|
|
|
|
? Collections.emptyList() |
|
|
|
|
|
|
|
: iOnlCgreportParamService.list(new LambdaQueryWrapper<OnlCgreportParam>() |
|
|
|
|
|
|
|
.in(OnlCgreportParam::getCgrheadId, onlCgreportHeadIdList)); |
|
|
|
|
|
|
|
if (onlCgreportHeadList.isEmpty()) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (Long tenantId : tenantIdSet) { |
|
|
|
|
|
|
|
JSONObject msg = new JSONObject(); |
|
|
|
|
|
|
|
msg.put("tenantId", tenantId); |
|
|
|
|
|
|
|
msg.put("onlCgreportHeadList", onlCgreportHeadList); |
|
|
|
|
|
|
|
msg.put("onlCgreportItemList", onlCgreportItemList); |
|
|
|
|
|
|
|
msg.put("onlCgreportParamList", onlCgreportParamList); |
|
|
|
|
|
|
|
dataSyncProducer.sendOrderly( |
|
|
|
|
|
|
|
tenantId, |
|
|
|
|
|
|
|
applicationConfig.getTenantSyncTopic(), |
|
|
|
|
|
|
|
OnlCgreportHead.class.getSimpleName(), |
|
|
|
|
|
|
|
TenantConstant.INSERT_TENANT_ONL_CGREPORT_HEAD_COMMAND, |
|
|
|
|
|
|
|
msg.toJSONString(), |
|
|
|
|
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 2. 表单元数据:按页面递归取整棵表树
|
|
|
|
|
|
|
|
for (Long pageId : pageIds) { |
|
|
|
|
|
|
|
String sql = getOnlFormHeadByPageIdSQL(pageId); |
|
|
|
|
|
|
|
List<OnlFormHead> headList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(OnlFormHead.class), Collections.singleton(pageId)); |
|
|
|
|
|
|
|
if (CollUtil.isEmpty(headList)) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<OnlFormFind> findList = onlFormFindService.list(new LambdaQueryWrapper<OnlFormFind>().in(OnlFormFind::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormField> fieldList = onlFormFieldService.list(new LambdaQueryWrapper<OnlFormField>().in(OnlFormField::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormCheck> checkList = onlFormCheckService.list(new LambdaQueryWrapper<OnlFormCheck>().in(OnlFormCheck::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormIndex> indexList = onlFormIndexService.list(new LambdaQueryWrapper<OnlFormIndex>().in(OnlFormIndex::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormKey> keyList = onlFormKeyService.list(new LambdaQueryWrapper<OnlFormKey>().in(OnlFormKey::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormPage> pageList = onlFormPageService.list(new LambdaQueryWrapper<OnlFormPage>().in(OnlFormPage::getHeadId, headList)); |
|
|
|
|
|
|
|
for (Long tenantId : tenantIdSet) { |
|
|
|
|
|
|
|
JSONObject msg = new JSONObject(); |
|
|
|
|
|
|
|
msg.put("tenantId", tenantId); |
|
|
|
|
|
|
|
msg.put("onlFormHeadList", headList); |
|
|
|
|
|
|
|
msg.put("onlFormFindList", findList); |
|
|
|
|
|
|
|
msg.put("onlFormFieldList", fieldList); |
|
|
|
|
|
|
|
msg.put("onlFormCheckList", checkList); |
|
|
|
|
|
|
|
msg.put("onlFormIndexList", indexList); |
|
|
|
|
|
|
|
msg.put("onlFormKeyList", keyList); |
|
|
|
|
|
|
|
msg.put("onlFormPageList", pageList); |
|
|
|
dataSyncProducer.sendOrderly( |
|
|
|
dataSyncProducer.sendOrderly( |
|
|
|
tenantId, |
|
|
|
tenantId, |
|
|
|
applicationConfig.getTenantSyncTopic(), |
|
|
|
applicationConfig.getTenantSyncTopic(), |
|
|
|
OnlCgreportHead.class.getSimpleName(), |
|
|
|
OnlFormHead.class.getSimpleName(), |
|
|
|
TenantConstant.INSERT_TENANT_ONL_CGREPORT_HEAD_COMMAND, |
|
|
|
TenantConstant.INSERT_TENANT_ONL_FORM_HEAD_COMMAND, |
|
|
|
onlCgreportHeadMsgJsonData.toJSONString(), |
|
|
|
msg.toJSONString(), |
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY); |
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//根据页面ID获取表单元数据列表
|
|
|
|
|
|
|
|
String sql = getOnlFormHeadByPageIdSQL(pageId); |
|
|
|
|
|
|
|
List<OnlFormHead> headList = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(OnlFormHead.class), Collections.singleton(pageId)); |
|
|
|
|
|
|
|
List<OnlFormFind> findList = onlFormFindService.list(new LambdaQueryWrapper<OnlFormFind>().in(OnlFormFind::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormField> fieldList = onlFormFieldService.list(new LambdaQueryWrapper<OnlFormField>().in(OnlFormField::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormCheck> checkList = onlFormCheckService.list(new LambdaQueryWrapper<OnlFormCheck>().in(OnlFormCheck::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormIndex> indexList = onlFormIndexService.list(new LambdaQueryWrapper<OnlFormIndex>().in(OnlFormIndex::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormKey> keyList = onlFormKeyService.list(new LambdaQueryWrapper<OnlFormKey>().in(OnlFormKey::getHeadId, headList)); |
|
|
|
|
|
|
|
List<OnlFormPage> pageList = onlFormPageService.list(new LambdaQueryWrapper<OnlFormPage>().in(OnlFormPage::getHeadId, headList)); |
|
|
|
|
|
|
|
// 表单元数据通知更新新增
|
|
|
|
|
|
|
|
for(Long tenantId : tenantIdSet){ |
|
|
|
|
|
|
|
JSONObject messageJsonData = new JSONObject(); |
|
|
|
|
|
|
|
messageJsonData.put("tenantId", tenantId); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormHeadList", headList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormFindList", findList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormFieldList", fieldList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormCheckList", checkList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormIndexList", indexList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormKeyList", keyList); |
|
|
|
|
|
|
|
messageJsonData.put("onlFormPageList", pageList); |
|
|
|
|
|
|
|
dataSyncProducer.sendOrderly( |
|
|
|
|
|
|
|
tenantId, |
|
|
|
|
|
|
|
applicationConfig.getTenantSyncTopic(), |
|
|
|
|
|
|
|
OnlFormHead.class.getSimpleName(), |
|
|
|
|
|
|
|
TenantConstant.INSERT_TENANT_ONL_FORM_HEAD_COMMAND, |
|
|
|
|
|
|
|
messageJsonData.toJSONString(), |
|
|
|
|
|
|
|
TenantConstant.MESSAGE_QUEUE_SELECTOR_KEY |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|