前后端分目录
This commit is contained in:
23
ddp/ddp-common/ddp-service/pom.xml
Normal file
23
ddp/ddp-common/ddp-service/pom.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>ddp-common</artifactId>
|
||||
<groupId>com.fibo.ddp</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>ddp-common-service</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fibo.ddp</groupId>
|
||||
<artifactId>ddp-common-dao</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface AnalyseCommonService<T> {
|
||||
|
||||
List<T> getAnalyseData(AnalyseRequestParam param);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseDecisionResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseDecisionResult)表服务接口
|
||||
*/
|
||||
public interface AnalyseDecisionResultService extends IService<AnalyseDecisionResult>,AnalyseCommonService<List<AnalyseDecisionResult>> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseDecisionTables;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseDecisionTables)表服务接口
|
||||
*/
|
||||
public interface AnalyseDecisionTablesService extends IService<AnalyseDecisionTables> ,AnalyseCommonService<List<List<AnalyseDecisionTables>>>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineCall;
|
||||
|
||||
/**
|
||||
* (AnalyseEngineCall)表服务接口
|
||||
*/
|
||||
public interface AnalyseEngineCallService extends IService<AnalyseEngineCall> ,AnalyseCommonService<AnalyseEngineCall>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseEngineNode)表服务接口
|
||||
*/
|
||||
public interface AnalyseEngineNodeService extends IService<AnalyseEngineNode> ,AnalyseCommonService<List<AnalyseEngineNode>>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineSummary;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseEngineSummaryVo;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (TAnalyseEngineSummary)表服务接口
|
||||
*/
|
||||
public interface AnalyseEngineSummaryService extends IService<AnalyseEngineSummary> {
|
||||
|
||||
Map<String, AnalyseEngineSummaryVo>getAnalyseData(AnalyseRequestParam param);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseRule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseRule)表服务接口
|
||||
*/
|
||||
public interface AnalyseRuleService extends IService<AnalyseRule> ,AnalyseCommonService<List<AnalyseRule>>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseScorecard;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseScorecard)表服务接口
|
||||
*/
|
||||
public interface AnalyseScorecardService extends IService<AnalyseScorecard>,AnalyseCommonService<List<List<AnalyseScorecard>>> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseData;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
|
||||
public interface AnalyseService{
|
||||
|
||||
AnalyseData getAnalyseData(AnalyseRequestParam param);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.fibo.ddp.common.service.analyse;
|
||||
|
||||
/**
|
||||
* 不同统计入库
|
||||
*/
|
||||
public interface StatisticsService {
|
||||
public void statisticData();
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineMapper;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineVersionMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorEngineMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorNodeMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorStrategyMapper;
|
||||
import com.fibo.ddp.common.model.analyse.*;
|
||||
import com.fibo.ddp.common.model.enginex.risk.Engine;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineResultSetDTO;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineVersion;
|
||||
import com.fibo.ddp.common.model.monitor.decisionflow.TMonitorEngine;
|
||||
import com.fibo.ddp.common.model.monitor.decisionflow.TMonitorNodeDTO;
|
||||
import com.fibo.ddp.common.model.monitor.decisionflow.TMonitorStrategyDTO;
|
||||
import com.fibo.ddp.common.service.analyse.*;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by niuge on 2021/11/5.
|
||||
*/
|
||||
@Service
|
||||
public class AnalyseChartStatisticServiceImpl implements StatisticsService {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private EngineVersionMapper engineVersionMapper;
|
||||
@Autowired
|
||||
private EngineMapper engineMapper;
|
||||
@Autowired
|
||||
private AnalyseEngineCallService analyseEngineCallService;
|
||||
@Autowired
|
||||
private TMonitorEngineMapper monitorEngineMapper;
|
||||
@Autowired
|
||||
private TMonitorNodeMapper monitorNodeMapper;
|
||||
@Autowired
|
||||
private TMonitorStrategyMapper monitorStrategyMapper;
|
||||
@Autowired
|
||||
private AnalyseDecisionResultService analyseDecisionResultService;
|
||||
@Autowired
|
||||
private AnalyseRuleService analyseRuleService;
|
||||
@Autowired
|
||||
private AnalyseScorecardService analyseScorecardService;
|
||||
@Autowired
|
||||
private AnalyseDecisionTablesService analyseDecisionTablesService;
|
||||
@Autowired
|
||||
private AnalyseEngineNodeService analyseEngineNodeService;
|
||||
|
||||
@Override
|
||||
public void statisticData() {
|
||||
//图表数据统计
|
||||
AnalyseChartEngineCallCount();
|
||||
//决策引擎执行结果 统计
|
||||
AnalyseDecisionResultCount();
|
||||
//决策引擎规则命中次数 统计
|
||||
AnalyseRuleCount();
|
||||
//决策引擎规则评分卡命中次数 统计
|
||||
AnalyseScorecardCount();
|
||||
//决策引擎 决策表命中次数 统计
|
||||
AnalyseDecisionTablesCount();
|
||||
//决策引擎 节点层面
|
||||
AnalyseNodeCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格 节点命中次数 统计(一天统计 一次)
|
||||
*/
|
||||
private void AnalyseNodeCount() {
|
||||
//节点命中次数 统计(一天统计 一次)
|
||||
List<TMonitorNodeDTO> monitorNodeDTOS = monitorNodeMapper.countNodeHit();
|
||||
List<AnalyseEngineNode> analyseEngineNodes = new ArrayList<>();
|
||||
for (int i = 0; i < monitorNodeDTOS.size(); i++) {
|
||||
TMonitorNodeDTO tMonitorNodeDTO = monitorNodeDTOS.get(i);
|
||||
buildNode(tMonitorNodeDTO,analyseEngineNodes);
|
||||
}
|
||||
analyseEngineNodeService.saveBatch(analyseEngineNodes);
|
||||
}
|
||||
|
||||
private void buildNode(TMonitorNodeDTO tMonitorNodeDTO, List<AnalyseEngineNode> analyseEngineNodes) {
|
||||
AnalyseEngineNode analyseEngineNode = new AnalyseEngineNode();
|
||||
analyseEngineNode.setCallDate(tMonitorNodeDTO.getCallDate());
|
||||
//引擎id
|
||||
analyseEngineNode.setEngineId(tMonitorNodeDTO.getEngineId());
|
||||
//引擎版本id
|
||||
analyseEngineNode.setVersionId(tMonitorNodeDTO.getEngineVersionId());
|
||||
analyseEngineNode.setVersionCode(null);
|
||||
analyseEngineNode.setEngineName(null);
|
||||
analyseEngineNode.setEngineDescription(null);
|
||||
analyseEngineNode.setOrganId(tMonitorNodeDTO.getOrganId());
|
||||
analyseEngineNode.setNodeName(tMonitorNodeDTO.getNodeName());
|
||||
analyseEngineNode.setNodeId(tMonitorNodeDTO.getNodeId());
|
||||
analyseEngineNode.setPassCount(tMonitorNodeDTO.getTotal());
|
||||
analyseEngineNode.setCreateTime(new Date());
|
||||
analyseEngineNode.setCreateUserId(Long.valueOf(1));
|
||||
analyseEngineNode.setUpdateUserId(Long.valueOf(1));
|
||||
analyseEngineNode.setUpdateTime(new Date());
|
||||
analyseEngineNodes.add(analyseEngineNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格 决策表调用次数 统计(一天统计 一次)
|
||||
*/
|
||||
private void AnalyseDecisionTablesCount() {
|
||||
List<TMonitorStrategyDTO> monitorStrategyDTOS = monitorStrategyMapper.countDecisionTables();
|
||||
List<AnalyseDecisionTables> analyseDecisionTables = new ArrayList<>();
|
||||
for (int i = 0; i < monitorStrategyDTOS.size(); i++) {
|
||||
TMonitorStrategyDTO tMonitorStrategyDTO = monitorStrategyDTOS.get(i);
|
||||
buildDecisionTables(tMonitorStrategyDTO,analyseDecisionTables);
|
||||
}
|
||||
analyseDecisionTablesService.saveBatch(analyseDecisionTables);
|
||||
}
|
||||
|
||||
private void buildDecisionTables(TMonitorStrategyDTO tMonitorStrategyDTO, List<AnalyseDecisionTables> analyseDecisionTables) {
|
||||
AnalyseDecisionTables decisionTables = new AnalyseDecisionTables();
|
||||
decisionTables.setCallDate(tMonitorStrategyDTO.getCallDate());
|
||||
//引擎id
|
||||
decisionTables.setEngineId(tMonitorStrategyDTO.getEngineId());
|
||||
decisionTables.setEngineName(null);
|
||||
decisionTables.setEngineDescription(null);
|
||||
//引擎版本id
|
||||
decisionTables.setVersionId(tMonitorStrategyDTO.getEngineVersionId());
|
||||
//组织id
|
||||
decisionTables.setOrganId(tMonitorStrategyDTO.getOrganId());
|
||||
decisionTables.setDecisonTablesId(tMonitorStrategyDTO.getStrategyId());
|
||||
decisionTables.setDecisonTablesName(tMonitorStrategyDTO.getStrategyName());
|
||||
decisionTables.setDecisonTablesVersionCode(null);
|
||||
decisionTables.setDecisonTablesVersionId(null);
|
||||
decisionTables.setResultCount(tMonitorStrategyDTO.getTotal());
|
||||
//执行结果
|
||||
decisionTables.setResult(tMonitorStrategyDTO.getResult());
|
||||
|
||||
decisionTables.setCreateTime(new Date());
|
||||
decisionTables.setCreateUserId(Long.valueOf(1));
|
||||
decisionTables.setUpdateUserId(Long.valueOf(1));
|
||||
decisionTables.setUpdateTime(new Date());
|
||||
analyseDecisionTables.add(decisionTables);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格 评分卡调用次数 统计(一天统计 一次)
|
||||
*/
|
||||
private void AnalyseScorecardCount() {
|
||||
List<TMonitorStrategyDTO> monitorStrategyDTOS = monitorStrategyMapper.countScorecardHit();
|
||||
List<AnalyseScorecard> analyseScorecards = new ArrayList<>();
|
||||
for (int i = 0; i < monitorStrategyDTOS.size(); i++) {
|
||||
TMonitorStrategyDTO tMonitorStrategyDTO = monitorStrategyDTOS.get(i);
|
||||
buildScorecard(tMonitorStrategyDTO,analyseScorecards);
|
||||
}
|
||||
analyseScorecardService.saveBatch(analyseScorecards);
|
||||
}
|
||||
|
||||
private void buildScorecard(TMonitorStrategyDTO tMonitorStrategyDTO, List<AnalyseScorecard> analyseScorecards) {
|
||||
AnalyseScorecard analyseScorecard = new AnalyseScorecard();
|
||||
analyseScorecard.setCallDate(tMonitorStrategyDTO.getCallDate());
|
||||
//引擎id
|
||||
analyseScorecard.setEngineId(tMonitorStrategyDTO.getEngineId());
|
||||
analyseScorecard.setEngineName(null);
|
||||
analyseScorecard.setEngineDescription(null);
|
||||
//引擎版本id
|
||||
analyseScorecard.setVersionId(tMonitorStrategyDTO.getEngineVersionId());
|
||||
analyseScorecard.setOrganId(tMonitorStrategyDTO.getOrganId());
|
||||
analyseScorecard.setScorecardId(tMonitorStrategyDTO.getStrategyId());
|
||||
analyseScorecard.setScorecardName(tMonitorStrategyDTO.getStrategyName());
|
||||
analyseScorecard.setScorecardVersionCode(null);
|
||||
analyseScorecard.setScorecardVersionId(null);
|
||||
//评分卡执行输出结果
|
||||
analyseScorecard.setResult(tMonitorStrategyDTO.getResult());
|
||||
analyseScorecard.setResultCount(tMonitorStrategyDTO.getTotal());
|
||||
analyseScorecard.setCreateTime(new Date());
|
||||
analyseScorecard.setCreateUserId(Long.valueOf(1));
|
||||
analyseScorecard.setUpdateUserId(Long.valueOf(1));
|
||||
analyseScorecard.setUpdateTime(new Date());
|
||||
analyseScorecards.add(analyseScorecard);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格 规则调用次数 统计(一天统计 一次)
|
||||
*/
|
||||
private void AnalyseRuleCount() {
|
||||
//一天统计一次 按照时间统计
|
||||
List<TMonitorStrategyDTO> monitorStrategyDTOS = monitorStrategyMapper.countRule();
|
||||
List<AnalyseRule> analyseRules = new ArrayList<>();
|
||||
for (int i = 0; i < monitorStrategyDTOS.size(); i++) {
|
||||
TMonitorStrategyDTO tMonitorStrategyDTO = monitorStrategyDTOS.get(i);
|
||||
buildRules(tMonitorStrategyDTO,analyseRules);
|
||||
}
|
||||
analyseRuleService.saveBatch(analyseRules);
|
||||
|
||||
}
|
||||
|
||||
private void buildRules(TMonitorStrategyDTO tMonitorStrategyDTO, List<AnalyseRule> analyseRules) {
|
||||
AnalyseRule analyseRule = new AnalyseRule();
|
||||
analyseRule.setCallDate(tMonitorStrategyDTO.getCallDate());
|
||||
//引擎id
|
||||
analyseRule.setEngineId(tMonitorStrategyDTO.getEngineId());
|
||||
//引擎版本id
|
||||
analyseRule.setVersionId(tMonitorStrategyDTO.getEngineVersionId());
|
||||
analyseRule.setEngineName(null);
|
||||
analyseRule.setEngineDescription(null);
|
||||
analyseRule.setOrganId(tMonitorStrategyDTO.getOrganId());
|
||||
analyseRule.setRuleId(tMonitorStrategyDTO.getStrategyId());
|
||||
analyseRule.setRuleName(tMonitorStrategyDTO.getStrategyName());
|
||||
analyseRule.setRuleVersionCode(null);
|
||||
analyseRule.setRuleVersionId(null);
|
||||
analyseRule.setHitCount(tMonitorStrategyDTO.getTotal());
|
||||
analyseRule.setCreateTime(new Date());
|
||||
analyseRule.setCreateUserId(Long.valueOf(1));
|
||||
analyseRule.setUpdateUserId(Long.valueOf(1));
|
||||
analyseRule.setUpdateTime(new Date());
|
||||
analyseRules.add(analyseRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格引擎调用 统计(一天统计一次)
|
||||
*/
|
||||
private void AnalyseChartEngineCallCount() {
|
||||
//查引擎版本表 按 引擎id ,引擎版本Id,组织id 来进行分组
|
||||
List<EngineVersion> engineVersions = engineVersionMapper.selectAll();
|
||||
//循环统计 统计结果放数组中里
|
||||
List<AnalyseEngineCall> engineCalls = new ArrayList<>();
|
||||
for (int i = 0; i < engineVersions.size(); i++) {
|
||||
EngineVersion engineVersion = engineVersions.get(i);
|
||||
Long engineId = engineVersion.getEngineId();
|
||||
Long versionId = engineVersion.getVersionId();
|
||||
Engine engine1 = engineMapper.selectById(engineId);
|
||||
if(engine1==null){
|
||||
continue;
|
||||
}
|
||||
if(i%20==0){
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(Long.valueOf("5"));//等待时
|
||||
} catch (InterruptedException e) {
|
||||
logger.info("==============================睡眠100s");
|
||||
}
|
||||
}
|
||||
//决策引擎调用次数每天趋势 按天统计次数
|
||||
QueryWrapper<TMonitorEngine> monitorEngineQueryWrapper = new QueryWrapper<>();
|
||||
monitorEngineQueryWrapper.eq("engine_version_id",versionId);
|
||||
//统计今天
|
||||
monitorEngineQueryWrapper.le("create_time", new SimpleDateFormat("yyyy-MM-dd").format(DateUtils.addDays(new Date(),1)));
|
||||
monitorEngineQueryWrapper.ge("create_time", new SimpleDateFormat("yyyy-MM-dd").format(DateUtils.addDays(new Date(),0)));
|
||||
Integer countNum = monitorEngineMapper.selectCount(monitorEngineQueryWrapper);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(countNum));
|
||||
}
|
||||
insertIntoDB(engineCalls);
|
||||
}
|
||||
|
||||
/**
|
||||
* 表格 引擎调用执行结果 统计
|
||||
*/
|
||||
private void AnalyseDecisionResultCount() {
|
||||
//决策引擎调用次数每天趋势 按天统计次数
|
||||
//统计今天
|
||||
List<AnalyseDecisionResult> analyseDecisionResults = new ArrayList<>();
|
||||
List<EngineResultSetDTO> engineResultSetList = engineVersionMapper.countDecisionResult();
|
||||
for (int i = 0; i < engineResultSetList.size(); i++) {
|
||||
EngineResultSetDTO engineResultSet = engineResultSetList.get(i);
|
||||
buildEngineResultModels(engineResultSet,analyseDecisionResults);
|
||||
}
|
||||
analyseDecisionResultService.saveBatch(analyseDecisionResults);
|
||||
}
|
||||
|
||||
private void buildEngineResultModels(EngineResultSetDTO decisionResult, List<AnalyseDecisionResult> analyseDecisionResults) {
|
||||
AnalyseDecisionResult analyseDecisionResult = new AnalyseDecisionResult();
|
||||
analyseDecisionResult.setCallDate(decisionResult.getCallDate());
|
||||
analyseDecisionResult.setResult(decisionResult.getResult());
|
||||
//引擎id
|
||||
analyseDecisionResult.setEngineId(decisionResult.getEngineId());
|
||||
analyseDecisionResult.setEngineName(decisionResult.getEngineName());
|
||||
analyseDecisionResult.setEngineDescription(null);
|
||||
//引擎版本id
|
||||
analyseDecisionResult.setVersionId(decisionResult.getEngineVersion());
|
||||
analyseDecisionResult.setOrganId(decisionResult.getOrganId());
|
||||
analyseDecisionResult.setCreateUserId(Long.valueOf(1));
|
||||
analyseDecisionResult.setUpdateUserId(Long.valueOf(1));
|
||||
analyseDecisionResult.setCreateTime(new Date());
|
||||
analyseDecisionResult.setUpdateTime(new Date());
|
||||
//引擎执行结果
|
||||
analyseDecisionResult.setResult(decisionResult.getResult());
|
||||
analyseDecisionResult.setResultCount(decisionResult.getTotal());
|
||||
analyseDecisionResults.add(analyseDecisionResult);
|
||||
}
|
||||
|
||||
public void insertIntoDB( List<AnalyseEngineCall> engineCalls){
|
||||
// CompletableFuture.runAsync(()->{
|
||||
analyseEngineCallService.saveBatch(engineCalls);
|
||||
// },threadPoolTaskExecutor);
|
||||
}
|
||||
/**
|
||||
* 根据业务类型 组装业务对象
|
||||
* @param engineCalls
|
||||
* @param num
|
||||
*/
|
||||
private void buildModels(Engine engine1, Long versionId, List<AnalyseEngineCall> engineCalls, Long num) {
|
||||
//组装统计信息数组
|
||||
AnalyseEngineCall analyseEngineCall = new AnalyseEngineCall();
|
||||
analyseEngineCall.setEngineId(engine1.getId());
|
||||
analyseEngineCall.setEngineName(engine1.getName());
|
||||
analyseEngineCall.setEngineDescription(engine1.getDescription());
|
||||
analyseEngineCall.setVersionId(versionId);
|
||||
analyseEngineCall.setVersionCode(null);
|
||||
analyseEngineCall.setCallCount(num);
|
||||
analyseEngineCall.setOrganId(engine1.getOrganId());
|
||||
analyseEngineCall.setCreateUserId(Long.valueOf(1));
|
||||
analyseEngineCall.setUpdateUserId(Long.valueOf(1));
|
||||
analyseEngineCall.setCreateTime(new Date());
|
||||
analyseEngineCall.setUpdateTime(new Date());
|
||||
analyseEngineCall.setCallDate(new Date());
|
||||
engineCalls.add(analyseEngineCall);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseDecisionResultMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseDecisionResult;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseDecisionResultService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (AnalyseDecisionResult)表服务实现类
|
||||
*/
|
||||
@Service("analyseDecisionResultService")
|
||||
public class AnalyseDecisionResultServiceImpl extends ServiceImpl<AnalyseDecisionResultMapper, AnalyseDecisionResult> implements AnalyseDecisionResultService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseDecisionResultMapper mapper;
|
||||
@Override
|
||||
public List<List<AnalyseDecisionResult>> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseDecisionResult> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseDecisionResult::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseDecisionResult::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseDecisionResult::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseDecisionResult::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseDecisionResult::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseDecisionResult::getCallDate);
|
||||
List<AnalyseDecisionResult> analyseDecisionResults = mapper.selectList(wrapper);
|
||||
Map<String,List<AnalyseDecisionResult>> map = new HashMap<>();
|
||||
for (AnalyseDecisionResult item : analyseDecisionResults) {
|
||||
List<AnalyseDecisionResult> list = null;
|
||||
String key = item.getResult();
|
||||
if (map.containsKey(key)){
|
||||
list = map.get(key);
|
||||
}else {
|
||||
list= new ArrayList<>();
|
||||
}
|
||||
list.add(item);
|
||||
map.put(key,list);
|
||||
}
|
||||
List<List<AnalyseDecisionResult>> result = new ArrayList<>(map.values());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseDecisionTablesMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseDecisionTables;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseDecisionTablesService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (AnalyseDecisionTables)表服务实现类
|
||||
*/
|
||||
@Service("analyseDecisonTablesService")
|
||||
public class AnalyseDecisionTablesServiceImpl extends ServiceImpl<AnalyseDecisionTablesMapper, AnalyseDecisionTables> implements AnalyseDecisionTablesService {
|
||||
@Autowired
|
||||
private AnalyseDecisionTablesMapper mapper;
|
||||
|
||||
@Override
|
||||
public List<List<List<AnalyseDecisionTables>>> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseDecisionTables> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseDecisionTables::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseDecisionTables::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseDecisionTables::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseDecisionTables::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseDecisionTables::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseDecisionTables::getCallDate);
|
||||
List<AnalyseDecisionTables> analyseDecisionTables = mapper.selectList(wrapper);
|
||||
Map<String,Map<String,List<AnalyseDecisionTables>>> map = new HashMap<>();
|
||||
|
||||
for (AnalyseDecisionTables item : analyseDecisionTables) {
|
||||
List<AnalyseDecisionTables> list = null;
|
||||
String versionKey = String.valueOf(item.getDecisonTablesId())+"|"+String.valueOf(item.getDecisonTablesVersionId());
|
||||
String resultKey = item.getResult();
|
||||
Map<String,List<AnalyseDecisionTables>> temp =null;
|
||||
if (map.containsKey(versionKey)){
|
||||
temp = map.get(versionKey);
|
||||
}else {
|
||||
temp = new HashMap<>();
|
||||
}
|
||||
if (temp.containsKey(resultKey)){
|
||||
list = temp.get(resultKey);
|
||||
}else {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
list.add(item);
|
||||
temp.put(resultKey,list);
|
||||
map.put(versionKey,temp);
|
||||
}
|
||||
List<List<List<AnalyseDecisionTables>>> result = new ArrayList<>();
|
||||
for (Map<String, List<AnalyseDecisionTables>> value : map.values()) {
|
||||
result.add(new ArrayList<>(value.values()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseEngineCallMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineCall;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineCallService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (AnalyseEngineCall)表服务实现类
|
||||
*/
|
||||
@Service("analyseEngineCallService")
|
||||
public class AnalyseEngineCallServiceImpl extends ServiceImpl<AnalyseEngineCallMapper, AnalyseEngineCall> implements AnalyseEngineCallService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseEngineCallMapper mapper;
|
||||
@Override
|
||||
public List<AnalyseEngineCall> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseEngineCall> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseEngineCall::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseEngineCall::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseEngineCall::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseEngineCall::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseEngineCall::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseEngineCall::getCallDate);
|
||||
List<AnalyseEngineCall> result = mapper.selectList(wrapper);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseEngineNodeMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineNode;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineNodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (AnalyseEngineNode)表服务实现类
|
||||
*/
|
||||
@Service("analyseEngineNodeService")
|
||||
public class AnalyseEngineNodeServiceImpl extends ServiceImpl<AnalyseEngineNodeMapper, AnalyseEngineNode> implements AnalyseEngineNodeService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseEngineNodeMapper mapper;
|
||||
@Override
|
||||
public List<List<AnalyseEngineNode>> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseEngineNode> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseEngineNode::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseEngineNode::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseEngineNode::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseEngineNode::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseEngineNode::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseEngineNode::getCallDate);
|
||||
List<AnalyseEngineNode> AnalyseEngineNodes = mapper.selectList(wrapper);
|
||||
Map<String,List<AnalyseEngineNode>> map = new HashMap<>();
|
||||
for (AnalyseEngineNode item : AnalyseEngineNodes) {
|
||||
List<AnalyseEngineNode> list = null;
|
||||
String key = String.valueOf(item.getNodeId());
|
||||
if (map.containsKey(key)){
|
||||
list = map.get(key);
|
||||
}else {
|
||||
list= new ArrayList<>();
|
||||
}
|
||||
list.add(item);
|
||||
map.put(key,list);
|
||||
}
|
||||
List<List<AnalyseEngineNode>> result = map.values().stream().collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseEngineSummaryMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineSummary;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseEngineSummaryVo;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineSummaryService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.utils.constant.AnalyseConst;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* (TAnalyseEngineSummary)表服务实现类
|
||||
*/
|
||||
@Service("tAnalyseEngineSummaryService")
|
||||
public class AnalyseEngineSummaryServiceImpl extends ServiceImpl<AnalyseEngineSummaryMapper, AnalyseEngineSummary> implements AnalyseEngineSummaryService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseEngineSummaryMapper summaryMapper;
|
||||
|
||||
@Override
|
||||
public Map<String, AnalyseEngineSummaryVo> getAnalyseData(AnalyseRequestParam param) {
|
||||
Map<String, AnalyseEngineSummaryVo> result = new HashMap<>();
|
||||
Date now = new Date();
|
||||
Date yesterday = this.dateAdd(now,-1);
|
||||
for (String key : AnalyseConst.KEYS) {
|
||||
AnalyseEngineSummary curData = this.getDataByEndDate(param.getVersionId(), key, now, false);
|
||||
long curCount = 0L;
|
||||
if (curData!=null){
|
||||
curCount = curData.getStatisticsCount();
|
||||
}
|
||||
AnalyseEngineSummary lastData = this.getDataByEndDate(param.getVersionId(), key, yesterday, false);
|
||||
long lastCount = 0L;
|
||||
if (lastData!=null&&lastData.getStatisticsCount()!=null){
|
||||
lastCount = lastData.getStatisticsCount();
|
||||
}
|
||||
AnalyseEngineSummary lastTotalData = this.getDataByEndDate(param.getVersionId(), key, yesterday, true);
|
||||
long lastTatol = 0L;
|
||||
if (lastTotalData!=null){
|
||||
lastTatol = lastTotalData.getStatisticsCount();
|
||||
}
|
||||
result.put(key,new AnalyseEngineSummaryVo(curCount, lastCount,lastTatol));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
//获取指定时间所在日期的指定类型数据
|
||||
private AnalyseEngineSummary getDataByEndDate(Long versionId,String dimension, Date end,boolean istotal){
|
||||
LambdaQueryWrapper<AnalyseEngineSummary> wrapper = this.createWrapper(versionId, dimension, end);
|
||||
if (istotal){
|
||||
wrapper.lt(AnalyseEngineSummary::getCreateTime,this.clearTime(this.dateAdd(end,1)));
|
||||
}else {
|
||||
wrapper.le(AnalyseEngineSummary::getCreateTime,end);
|
||||
}
|
||||
wrapper.orderByDesc(AnalyseEngineSummary::getCreateTime);
|
||||
return this.getOne(wrapper,false);
|
||||
}
|
||||
//构造查询wrapper
|
||||
private LambdaQueryWrapper<AnalyseEngineSummary> createWrapper(Long versionId,String dimension, Date end){
|
||||
LambdaQueryWrapper<AnalyseEngineSummary> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseEngineSummary::getOrganId, SessionManager.getLoginAccount().getOrganId());
|
||||
wrapper.eq(AnalyseEngineSummary::getStatisticsDimension,dimension);
|
||||
wrapper.eq(AnalyseEngineSummary::getEngineVersionId, versionId);
|
||||
Date start = this.clearTime(end);
|
||||
wrapper.ge(AnalyseEngineSummary::getCreateTime,start);
|
||||
return wrapper;
|
||||
}
|
||||
//清除时间信息
|
||||
private Date clearTime(Date date){
|
||||
LocalDate localDate=date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
|
||||
Date result=java.sql.Date.valueOf(localDate);
|
||||
return result;
|
||||
}
|
||||
//增加日期
|
||||
private Date dateAdd(Date date,Integer integer){
|
||||
Calendar c =new GregorianCalendar();
|
||||
c.setTime(date);
|
||||
c.add(Calendar.DATE,integer);
|
||||
return c.getTime();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseRuleMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseRule;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseRuleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (AnalyseRule)表服务实现类
|
||||
*/
|
||||
@Service("analyseRuleService")
|
||||
public class AnalyseRuleServiceImpl extends ServiceImpl<AnalyseRuleMapper, AnalyseRule> implements AnalyseRuleService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseRuleMapper mapper;
|
||||
@Override
|
||||
public List<List<AnalyseRule>> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseRule> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseRule::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseRule::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseRule::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseRule::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseRule::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseRule::getCallDate);
|
||||
List<AnalyseRule> AnalyseRules = mapper.selectList(wrapper);
|
||||
Map<String,List<AnalyseRule>> map = new HashMap<>();
|
||||
for (AnalyseRule item : AnalyseRules) {
|
||||
List<AnalyseRule> list = null;
|
||||
String key = String.valueOf(item.getRuleId())+"|"+String.valueOf(item.getRuleVersionId());
|
||||
if (map.containsKey(key)){
|
||||
list = map.get(key);
|
||||
}else {
|
||||
list= new ArrayList<>();
|
||||
}
|
||||
list.add(item);
|
||||
map.put(key,list);
|
||||
}
|
||||
List<List<AnalyseRule>> result = new ArrayList<>(map.values());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseScorecardMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseScorecard;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseScorecardService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (AnalyseScorecard)表服务实现类
|
||||
*/
|
||||
@Service("tAnalyseScorecardService")
|
||||
public class AnalyseScorecardServiceImpl extends ServiceImpl<AnalyseScorecardMapper, AnalyseScorecard> implements AnalyseScorecardService {
|
||||
|
||||
@Autowired
|
||||
private AnalyseScorecardMapper mapper;
|
||||
|
||||
@Override
|
||||
public List<List<List<AnalyseScorecard>>> getAnalyseData(AnalyseRequestParam param) {
|
||||
LambdaQueryWrapper<AnalyseScorecard> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(AnalyseScorecard::getEngineId,param.getEngineId());
|
||||
wrapper.eq(AnalyseScorecard::getVersionId,param.getVersionId());
|
||||
wrapper.eq(AnalyseScorecard::getOrganId,param.getUser().getOrganId());
|
||||
wrapper.ge(AnalyseScorecard::getCallDate,param.getStart());
|
||||
wrapper.lt(AnalyseScorecard::getCallDate,param.getEnd());
|
||||
wrapper.orderByAsc(AnalyseScorecard::getCallDate);
|
||||
List<AnalyseScorecard> AnalyseScorecard = mapper.selectList(wrapper);
|
||||
Map<String, Map<String,List<AnalyseScorecard>>> map = new HashMap<>();
|
||||
|
||||
for (AnalyseScorecard item : AnalyseScorecard) {
|
||||
List<AnalyseScorecard> list = null;
|
||||
String versionKey = String.valueOf(item.getScorecardId())+"|"+String.valueOf(item.getScorecardVersionId());
|
||||
String resultKey = item.getResult();
|
||||
Map<String,List<AnalyseScorecard>> temp =null;
|
||||
if (map.containsKey(versionKey)){
|
||||
temp = map.get(versionKey);
|
||||
}else {
|
||||
temp = new HashMap<>();
|
||||
}
|
||||
if (temp.containsKey(resultKey)){
|
||||
list = temp.get(resultKey);
|
||||
}else {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
list.add(item);
|
||||
temp.put(resultKey,list);
|
||||
map.put(versionKey,temp);
|
||||
}
|
||||
List<List<List<AnalyseScorecard>>> result = new ArrayList<>();
|
||||
for (Map<String, List<AnalyseScorecard>> value : map.values()) {
|
||||
result.add(new ArrayList<>(value.values()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseData;
|
||||
import com.fibo.ddp.common.model.analyse.vo.AnalyseRequestParam;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.service.analyse.*;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
@Service
|
||||
public class AnalyseServiceImpl implements AnalyseService {
|
||||
@Autowired
|
||||
private AnalyseDecisionResultService decisionResultService;
|
||||
@Autowired
|
||||
private AnalyseDecisionTablesService analyseDecisionTablesService;
|
||||
@Autowired
|
||||
private AnalyseEngineCallService engineCallService;
|
||||
@Autowired
|
||||
private AnalyseEngineNodeService engineNodeService;
|
||||
@Autowired
|
||||
private AnalyseRuleService analyseRuleService;
|
||||
@Autowired
|
||||
private AnalyseScorecardService analyseScorecardService;
|
||||
// @Autowired
|
||||
// private AnalyseEngineSummaryService analyseEngineSummaryService;
|
||||
@Override
|
||||
public AnalyseData getAnalyseData(AnalyseRequestParam param) {
|
||||
param = initParam(param);
|
||||
AnalyseData analyseData = new AnalyseData();
|
||||
analyseData.setDecisionResultList(decisionResultService.getAnalyseData(param));
|
||||
analyseData.setDecisionTablesList(analyseDecisionTablesService.getAnalyseData(param));
|
||||
analyseData.setCallCountList(engineCallService.getAnalyseData(param));
|
||||
analyseData.setEngineNodeList(engineNodeService.getAnalyseData(param));
|
||||
analyseData.setRuleList(analyseRuleService.getAnalyseData(param));
|
||||
analyseData.setScorecardList(analyseScorecardService.getAnalyseData(param));
|
||||
// analyseData.setEngineSummary(analyseEngineSummaryService.getAnalyseData(inputParam));
|
||||
return analyseData;
|
||||
}
|
||||
private AnalyseRequestParam initParam(AnalyseRequestParam param){
|
||||
if (param==null
|
||||
||param.getEngineId()==null
|
||||
||param.getVersionId()==null
|
||||
||param.getStart()==null
|
||||
||param.getEnd()==null){
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(),ErrorCodeEnum.PARAMS_EXCEPTION.getMessage());
|
||||
}
|
||||
param.setUser(SessionManager.getLoginAccount());
|
||||
Calendar c =new GregorianCalendar();
|
||||
c.setTime(param.getEnd());
|
||||
c.add(Calendar.DATE,1);
|
||||
param.setEnd(c.getTime());
|
||||
return param;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
package com.fibo.ddp.common.service.analyse.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.fibo.ddp.common.dao.analyse.AnalyseEngineCallMapper;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineMapper;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineVersionMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorEngineMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorNodeMapper;
|
||||
import com.fibo.ddp.common.dao.monitor.decisionflow.TMonitorStrategyMapper;
|
||||
import com.fibo.ddp.common.model.analyse.AnalyseEngineSummary;
|
||||
import com.fibo.ddp.common.model.enginex.risk.Engine;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineVersion;
|
||||
import com.fibo.ddp.common.model.monitor.decisionflow.TMonitorEngine;
|
||||
import com.fibo.ddp.common.model.monitor.decisionflow.TMonitorNode;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineCallService;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineNodeService;
|
||||
import com.fibo.ddp.common.service.analyse.AnalyseEngineSummaryService;
|
||||
import com.fibo.ddp.common.service.analyse.StatisticsService;
|
||||
import com.fibo.ddp.common.utils.constant.AnalyseConst;
|
||||
import com.spring4all.spring.boot.starter.hbase.api.HbaseTemplate;
|
||||
import org.apache.commons.lang3.time.StopWatch;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.client.Scan;
|
||||
import org.apache.hadoop.hbase.client.coprocessor.AggregationClient;
|
||||
import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter;
|
||||
import org.apache.hadoop.hbase.filter.CompareFilter;
|
||||
import org.apache.hadoop.hbase.filter.Filter;
|
||||
import org.apache.hadoop.hbase.filter.FilterList;
|
||||
import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class StatisticsServiceImpl implements StatisticsService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
private EngineVersionMapper engineVersionMapper;
|
||||
@Autowired
|
||||
private EngineMapper engineMapper;
|
||||
@Autowired
|
||||
private AnalyseEngineCallMapper analyseEngineCallMapper;
|
||||
@Autowired
|
||||
private AnalyseEngineCallService analyseEngineCallService;
|
||||
@Autowired
|
||||
private AnalyseEngineSummaryService analyseEngineSummaryService;
|
||||
@Autowired
|
||||
private AnalyseEngineNodeService analyseEngineNodeService;
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
@Autowired
|
||||
private TMonitorEngineMapper monitorEngineMapper;
|
||||
@Autowired
|
||||
private TMonitorNodeMapper monitorNodeMapper;
|
||||
@Autowired
|
||||
private TMonitorStrategyMapper monitorStrategyMapper;
|
||||
@Autowired
|
||||
private HbaseTemplate hbaseTemplate;
|
||||
private final String MONITOR_DECISION_FLOW = "monitor_decision_flow";
|
||||
private final String MONITOR_NODE = "monitor_node";
|
||||
private final String BASE_INFO = "base_info";
|
||||
private final String ENGINE_VERSION_ID = "engine_version_id";
|
||||
private final String NODE_TYPE = "node_type";
|
||||
|
||||
@Override
|
||||
public void statisticData() {
|
||||
// AnalyseEngineSummaryCountHBase();
|
||||
//引擎概况
|
||||
AnalyseEngineSummaryCountMysql();
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* 决策引擎调用次数统计
|
||||
*/
|
||||
private void AnalyseEngineSummaryCountHBase() {
|
||||
//查引擎版本表 按 引擎id ,引擎版本Id,组织id 来进行分组
|
||||
List<EngineVersion> engineVersions = engineVersionMapper.selectAll();
|
||||
//循环统计 统计结果放数组中里
|
||||
List<AnalyseEngineSummary> engineCalls = new ArrayList<>();
|
||||
for (int i = 0; i < engineVersions.size(); i++) {
|
||||
EngineVersion engineVersion = engineVersions.get(i);
|
||||
Long engineId = engineVersion.getEngineId();
|
||||
Long versionId = engineVersion.getVersionId();
|
||||
Engine engine1 = engineMapper.selectById(engineId);
|
||||
if(engine1==null){
|
||||
continue;
|
||||
}
|
||||
if(i%20==0){
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(Long.valueOf("5"));//等待时
|
||||
} catch (InterruptedException e) {
|
||||
logger.info("==============================睡眠100s");
|
||||
}
|
||||
}
|
||||
//引擎调用
|
||||
Long countNum = rowCount(BASE_INFO,ENGINE_VERSION_ID,MONITOR_DECISION_FLOW,versionId+"","");
|
||||
buildModels(engine1,versionId,engineCalls,countNum, AnalyseConst.ENGINE_CALL);
|
||||
//节点命中
|
||||
Long countNumNode = rowCount(BASE_INFO,ENGINE_VERSION_ID,MONITOR_NODE,versionId+"","");
|
||||
buildModels(engine1,versionId,engineCalls,countNumNode,AnalyseConst.NODE_HIT);
|
||||
//评分卡命中
|
||||
Long scoredNodeNum = rowCount(BASE_INFO,ENGINE_VERSION_ID,MONITOR_NODE,versionId+"",AnalyseConst.SCORECARD);
|
||||
buildModels(engine1,versionId,engineCalls,scoredNodeNum,AnalyseConst.SCORECARD);
|
||||
//决策表命中
|
||||
Long decisionTableNum = rowCount(BASE_INFO,ENGINE_VERSION_ID,MONITOR_NODE,versionId+"",AnalyseConst.DECISION_TABLES);
|
||||
buildModels(engine1,versionId,engineCalls,decisionTableNum,AnalyseConst.DECISION_TABLES);
|
||||
//规则集合下的规则?命中
|
||||
Long ruleNum = rowCount(BASE_INFO,ENGINE_VERSION_ID,MONITOR_NODE,versionId+"",AnalyseConst.RULE_HIT);
|
||||
buildModels(engine1,versionId,engineCalls,ruleNum,AnalyseConst.RULE_HIT);
|
||||
System.out.println("===========================decisionCallCount:版本号 "+versionId+" 计数 "+countNum);
|
||||
}
|
||||
insertIntoDB(engineCalls);
|
||||
logger.info("=======================================>需要插入:{}行",engineCalls.size());
|
||||
// if(CollectionUtil.isNotNullOrEmpty(engineCalls)){
|
||||
// //分批入库,每批500个吧
|
||||
// for (int i = 0; i < engineCalls.size(); i++) {
|
||||
// if(i!=0 && (i%500==0)){
|
||||
// insertIntoDB(engineCalls.subList((i/500-1)*500,i-1));
|
||||
// }
|
||||
// //处理 不足五百的情况
|
||||
// if(engineCalls.size()%500>0 && i==engineCalls.size()-1){
|
||||
// //最后一批不足五百
|
||||
// if(engineCalls.size()/500>0){
|
||||
// insertIntoDB(engineCalls.subList((engineCalls.size()/500-1)*500,engineCalls.size()-1));
|
||||
// //第一批就不足五百
|
||||
// }else if(engineCalls.size()/500==0){
|
||||
// insertIntoDB(engineCalls.subList(0,engineCalls.size()-1));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据业务类型 组装业务对象
|
||||
* @param engineCalls
|
||||
* @param countNumNode
|
||||
* @param type
|
||||
*/
|
||||
private void buildModels(Engine engine1,Long versionId,List<AnalyseEngineSummary> engineCalls, Long countNumNode,String type) {
|
||||
//组装统计信息数组
|
||||
AnalyseEngineSummary engineSummary = new AnalyseEngineSummary();
|
||||
engineSummary.setEngineVersionId(versionId);
|
||||
engineSummary.setEngineName(engine1.getName());
|
||||
engineSummary.setStatisticsDimension(type);
|
||||
engineSummary.setStatisticsCount(countNumNode);
|
||||
engineSummary.setOrganId(engine1.getOrganId());
|
||||
engineSummary.setCreateTime(new Date());
|
||||
engineSummary.setUpdateTime(new Date());
|
||||
engineCalls.add(engineSummary);
|
||||
}
|
||||
|
||||
public void insertIntoDB( List<AnalyseEngineSummary> engineCalls){
|
||||
// CompletableFuture.runAsync(()->{
|
||||
analyseEngineSummaryService.saveBatch(engineCalls);
|
||||
|
||||
// },threadPoolTaskExecutor);
|
||||
}
|
||||
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return hbaseTemplate.getConfiguration();
|
||||
}
|
||||
|
||||
public long rowCount(String family,String column,String tableName,String versionId,String flag) {
|
||||
long rowCount = 0;
|
||||
Configuration conf = getConfiguration();
|
||||
Scan scan = new Scan();
|
||||
// scan.addColumn("base_info".getBytes(),"engine_version_id".getBytes());
|
||||
Filter filter1 = new SingleColumnValueFilter(Bytes.toBytes(family), Bytes.toBytes(column), CompareFilter.CompareOp.EQUAL, JSON.toJSONString(versionId).getBytes());
|
||||
FilterList filterList = new FilterList();
|
||||
if(flag.equals(AnalyseConst.SCORECARD)){
|
||||
Filter filter2 = new SingleColumnValueFilter(Bytes.toBytes(family), Bytes.toBytes(NODE_TYPE), CompareFilter.CompareOp.EQUAL, JSON.toJSONString("4").getBytes());
|
||||
filterList.addFilter(filter2);
|
||||
}
|
||||
if(flag.equals(AnalyseConst.DECISION_TABLES)){
|
||||
Filter filter = new SingleColumnValueFilter(Bytes.toBytes(family), Bytes.toBytes(NODE_TYPE), CompareFilter.CompareOp.EQUAL, JSON.toJSONString("16").getBytes());
|
||||
filterList.addFilter(filter);
|
||||
}
|
||||
if(flag.equals(AnalyseConst.RULE_HIT)){
|
||||
Filter filter = new SingleColumnValueFilter(Bytes.toBytes(family), Bytes.toBytes(NODE_TYPE), CompareFilter.CompareOp.EQUAL, JSON.toJSONString("2").getBytes());
|
||||
filterList.addFilter(filter);
|
||||
}
|
||||
filterList.addFilter(filter1);
|
||||
scan.setFilter(filterList);
|
||||
|
||||
//以下的方式可用
|
||||
// ValueFilter valueFilter = new ValueFilter(CompareFilter.CompareOp.EQUAL,new BinaryComparator(JSON.toJSONString("507").getBytes()));
|
||||
// scan.setFilter(valueFilter);
|
||||
//提高RPC通信时长
|
||||
conf.setLong("hbase.rpc.timeout", 600000);
|
||||
//设置Scan缓存
|
||||
conf.setLong("hbase.client.scanner.caching", 1000);
|
||||
Configuration configuration = HBaseConfiguration.create(conf);
|
||||
AggregationClient aggregationClient = new AggregationClient(configuration);
|
||||
try
|
||||
{
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
rowCount = aggregationClient.rowCount(TableName.valueOf(tableName), new LongColumnInterpreter(), scan);
|
||||
System.out.println("RowCount: " + rowCount);
|
||||
stopWatch.stop();
|
||||
System.out.println("统计耗时:" +stopWatch.getTime()/1000 +"s");
|
||||
}
|
||||
catch (Throwable e)
|
||||
{
|
||||
logger.info("==========decisionCallCount 统计出错",e);
|
||||
}
|
||||
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 决策引擎概况 统计
|
||||
*/
|
||||
private void AnalyseEngineSummaryCountMysql() {
|
||||
//查引擎版本表 按 引擎id ,引擎版本Id,组织id 来进行分组
|
||||
List<EngineVersion> engineVersions = engineVersionMapper.selectAll();
|
||||
//循环统计 统计结果放数组中里
|
||||
List<AnalyseEngineSummary> engineCalls = new ArrayList<>();
|
||||
for (int i = 0; i < engineVersions.size(); i++) {
|
||||
EngineVersion engineVersion = engineVersions.get(i);
|
||||
Long engineId = engineVersion.getEngineId();
|
||||
Long versionId = engineVersion.getVersionId();
|
||||
Engine engine1 = engineMapper.selectById(engineId);
|
||||
if(engine1==null){
|
||||
continue;
|
||||
}
|
||||
if(i%20==0){
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(Long.valueOf("5"));//等待时
|
||||
} catch (InterruptedException e) {
|
||||
logger.info("==============================睡眠100s");
|
||||
}
|
||||
}
|
||||
//引擎调用(查询Mysql 表 t_monitor_engine 统计该版本id 对应的监控记录条数)
|
||||
QueryWrapper<TMonitorEngine> monitorEngineQueryWrapper = new QueryWrapper<>();
|
||||
monitorEngineQueryWrapper.eq("engine_version_id",versionId);
|
||||
Integer countNum = monitorEngineMapper.selectCount(monitorEngineQueryWrapper);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(countNum),AnalyseConst.ENGINE_CALL);
|
||||
//节点命中
|
||||
QueryWrapper<TMonitorNode> monitorNodeQueryWrapper = new QueryWrapper<>();
|
||||
monitorNodeQueryWrapper.eq("engine_version_id",versionId);
|
||||
Integer countNumNode = monitorNodeMapper.selectCount(monitorNodeQueryWrapper);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(countNumNode),AnalyseConst.NODE_HIT);
|
||||
//评分卡命中
|
||||
QueryWrapper<TMonitorNode> monitorNodeQueryWrapper1 = new QueryWrapper<>();
|
||||
monitorNodeQueryWrapper1.eq("engine_version_id",versionId);
|
||||
monitorNodeQueryWrapper1.eq("node_type",4);
|
||||
Integer scoredNodeNum = monitorNodeMapper.selectCount(monitorNodeQueryWrapper1);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(scoredNodeNum),AnalyseConst.SCORECARD);
|
||||
//决策表命中
|
||||
QueryWrapper<TMonitorNode> monitorNodeQueryWrapper2 = new QueryWrapper<>();
|
||||
monitorNodeQueryWrapper2.eq("engine_version_id",versionId);
|
||||
monitorNodeQueryWrapper2.eq("node_type",16);
|
||||
Integer decisionTableNum = monitorNodeMapper.selectCount(monitorNodeQueryWrapper2);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(decisionTableNum),AnalyseConst.DECISION_TABLES);
|
||||
//规则集合下的规则?命中
|
||||
QueryWrapper<TMonitorNode> monitorNodeQueryWrapper3 = new QueryWrapper<>();
|
||||
monitorNodeQueryWrapper3.eq("engine_version_id",versionId);
|
||||
monitorNodeQueryWrapper3.eq("node_type",2);
|
||||
Integer ruleNum = monitorNodeMapper.selectCount(monitorNodeQueryWrapper3);
|
||||
buildModels(engine1,versionId,engineCalls,Long.valueOf(ruleNum),AnalyseConst.RULE_HIT);
|
||||
System.out.println("===========================decisionCallCount:版本号 "+versionId+" 计数 "+countNum);
|
||||
}
|
||||
insertIntoDB(engineCalls);
|
||||
logger.info("=======================================>需要插入:{}行",engineCalls.size());
|
||||
// if(CollectionUtil.isNotNullOrEmpty(engineCalls)){
|
||||
// //分批入库,每批500个吧
|
||||
// for (int i = 0; i < engineCalls.size(); i++) {
|
||||
// if(i!=0 && (i%500==0)){
|
||||
// insertIntoDB(engineCalls.subList((i/500-1)*500,i-1));
|
||||
// }
|
||||
// //处理 不足五百的情况
|
||||
// if(engineCalls.size()%500>0 && i==engineCalls.size()-1){
|
||||
// //最后一批不足五百
|
||||
// if(engineCalls.size()/500>0){
|
||||
// insertIntoDB(engineCalls.subList((engineCalls.size()/500-1)*500,engineCalls.size()-1));
|
||||
// //第一批就不足五百
|
||||
// }else if(engineCalls.size()/500==0){
|
||||
// insertIntoDB(engineCalls.subList(0,engineCalls.size()-1));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.approval;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.approval.ApprovalConfig;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.common.requestParam.StatusParam;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
/**
|
||||
* (ApprovalConfig)表服务接口
|
||||
*/
|
||||
public interface ApprovalConfigService extends IService<ApprovalConfig> {
|
||||
|
||||
boolean addApprovalConfig(ApprovalConfig entity);
|
||||
|
||||
PageInfo<ApprovalConfig> queryList(QueryListParam<ApprovalConfig> param);
|
||||
|
||||
boolean updateApprovalStatus(StatusParam<ApprovalConfig> statusParam);
|
||||
//校验是否需要审批
|
||||
boolean checkApproval(String approvalType);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.approval;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.approval.Approval;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.common.requestParam.StatusParam;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
/**
|
||||
* (Approval)表服务接口
|
||||
*/
|
||||
public interface ApprovalService extends IService<Approval> {
|
||||
|
||||
boolean addApproval(Approval entity);
|
||||
|
||||
PageInfo<Approval> queryList(QueryListParam<Approval> param);
|
||||
|
||||
boolean updateApplyStatus(StatusParam<Approval> statusParam);
|
||||
|
||||
boolean updateStatus(StatusParam statusParam);
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.fibo.ddp.common.service.approval.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.approval.ApprovalConfigMapper;
|
||||
import com.fibo.ddp.common.model.approval.ApprovalConfig;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.common.requestParam.StatusParam;
|
||||
import com.fibo.ddp.common.service.approval.ApprovalConfigService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.utils.constant.ApprovalConsts;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (ApprovalConfig)表服务实现类
|
||||
*/
|
||||
@Service("approvalConfigService")
|
||||
public class ApprovalConfigServiceImpl extends ServiceImpl<ApprovalConfigMapper, ApprovalConfig> implements ApprovalConfigService {
|
||||
@Resource
|
||||
private ApprovalConfigMapper approvalConfigMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addApprovalConfig(ApprovalConfig entity) {
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
this.initEntity(entity, 0);
|
||||
boolean insert = this.saveOrUpdate(entity);
|
||||
return insert;
|
||||
}
|
||||
|
||||
private void initEntity(ApprovalConfig entity, int type) {
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
|
||||
switch (type) {
|
||||
//新增
|
||||
case 0:
|
||||
if (entity.getApprovalStatus() == null) {
|
||||
entity.setApprovalStatus(ApprovalConsts.ApprovalStatus.OFF);
|
||||
}
|
||||
if (loginAccount != null) {
|
||||
if (entity.getCreateUserId() == null) {
|
||||
entity.setCreateUserId(loginAccount.getUserId());
|
||||
}
|
||||
if (entity.getOrganId() == null) {
|
||||
entity.setOrganId(loginAccount.getOrganId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
//修改
|
||||
case 1:
|
||||
if (loginAccount != null) {
|
||||
if (entity.getCreateUserId() == null) {
|
||||
entity.setCreateUserId(loginAccount.getUserId());
|
||||
}
|
||||
if (entity.getUpdateUserId() == null) {
|
||||
entity.setUpdateUserId(loginAccount.getUserId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<ApprovalConfig> queryList(QueryListParam<ApprovalConfig> param) {
|
||||
int pageNum = param.getPageNum();
|
||||
int pageSize = param.getPageSize();
|
||||
if (pageNum > 0 && pageSize > 0) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
}
|
||||
LambdaQueryWrapper<ApprovalConfig> wrapper = this.createWrapper(param.getEntity());
|
||||
List<ApprovalConfig> list = this.list(wrapper);
|
||||
PageInfo<ApprovalConfig> pageInfo = new PageInfo<>(list);
|
||||
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<ApprovalConfig> createWrapper(ApprovalConfig entity) {
|
||||
LambdaQueryWrapper<ApprovalConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
if (loginAccount.getOrganId() != 1) {
|
||||
wrapper.eq(ApprovalConfig::getOrganId, loginAccount.getOrganId());
|
||||
}
|
||||
if (entity != null) {
|
||||
if (entity.getId() != null) {
|
||||
wrapper.eq(ApprovalConfig::getId, entity.getId());
|
||||
}
|
||||
if (entity.getApprovalStatus() != null) {
|
||||
wrapper.eq(ApprovalConfig::getApprovalStatus, entity.getApprovalStatus());
|
||||
} else {
|
||||
wrapper.ne(ApprovalConfig::getApprovalStatus, ApprovalConsts.ApprovalStatus.DELETE);
|
||||
}
|
||||
if (entity.getCreateUserId() != null) {
|
||||
wrapper.eq(ApprovalConfig::getCreateUserId, entity.getCreateUserId());
|
||||
}
|
||||
if (entity.getUpdateUserId() != null) {
|
||||
wrapper.eq(ApprovalConfig::getUpdateUserId, entity.getUpdateUserId());
|
||||
}
|
||||
} else {
|
||||
wrapper.ne(ApprovalConfig::getApprovalStatus, ApprovalConsts.ApprovalStatus.DELETE);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateApprovalStatus(StatusParam<ApprovalConfig> statusParam) {
|
||||
List<ApprovalConfig> oldList = this.list(createWrapper(null));
|
||||
Map<String, ApprovalConfig> map = new HashMap<>();
|
||||
if (oldList != null && !oldList.isEmpty()) {
|
||||
map = oldList.stream().collect(Collectors.toMap(ApprovalConfig::getApprovalType, item -> {
|
||||
return item;
|
||||
}));
|
||||
}
|
||||
List<ApprovalConfig> list = statusParam.getList();
|
||||
List<ApprovalConfig> updateList = new ArrayList<>();
|
||||
int update = 0;
|
||||
if (list != null && !list.isEmpty()) {
|
||||
for (ApprovalConfig approvalConfig : list) {
|
||||
ApprovalConfig old = map.get(approvalConfig.getApprovalType());
|
||||
if (old != null) {
|
||||
old.setApprovalStatus(statusParam.getStatus());
|
||||
updateList.add(old);
|
||||
} else {
|
||||
approvalConfig.setApprovalStatus(statusParam.getStatus());
|
||||
this.initEntity(approvalConfig, 0);
|
||||
updateList.add(approvalConfig);
|
||||
}
|
||||
}
|
||||
update = approvalConfigMapper.insertOrUpdateBatch(updateList);
|
||||
}
|
||||
|
||||
return update > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkApproval(String approvalType) {
|
||||
LambdaQueryWrapper<ApprovalConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(ApprovalConfig::getOrganId, SessionManager.getLoginAccount().getOrganId());
|
||||
wrapper.eq(ApprovalConfig::getApprovalType, approvalType);
|
||||
ApprovalConfig approvalConfig = this.getOne(wrapper, false);
|
||||
if (approvalConfig != null && approvalConfig.getApprovalStatus() == ApprovalConsts.ApprovalStatus.ON) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
package com.fibo.ddp.common.service.approval.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.approval.ApprovalMapper;
|
||||
import com.fibo.ddp.common.model.approval.Approval;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.common.requestParam.StatusParam;
|
||||
import com.fibo.ddp.common.service.approval.ApprovalService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.enginex.risk.EngineVersionService;
|
||||
import com.fibo.ddp.common.utils.constant.ApprovalConsts;
|
||||
import com.fibo.ddp.common.utils.constant.StatusConst;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (Approval)表服务实现类
|
||||
*/
|
||||
@Service("approvalService")
|
||||
public class ApprovalServiceImpl extends ServiceImpl<ApprovalMapper, Approval> implements ApprovalService {
|
||||
@Resource
|
||||
private ApprovalMapper approvalMapper;
|
||||
@Resource
|
||||
private EngineVersionService engineVersionService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addApproval(Approval entity) {
|
||||
if (entity == null) {
|
||||
return false;
|
||||
}
|
||||
this.initEntity(entity, 0);
|
||||
boolean insert = this.saveOrUpdate(entity);
|
||||
return insert;
|
||||
}
|
||||
|
||||
private void initEntity(Approval entity, int type) {
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
if (entity==null){
|
||||
entity = new Approval();
|
||||
}
|
||||
switch (type) {
|
||||
//新增
|
||||
case 0:
|
||||
if (entity.getApplyStatus() == null) {
|
||||
entity.setApplyStatus(ApprovalConsts.ApplyStatus.WAIT);
|
||||
}
|
||||
if (entity.getStatus() == null) {
|
||||
entity.setStatus(StatusConst.STATUS_ENABLED);
|
||||
}
|
||||
if (entity.getCreateTime() != null) {
|
||||
entity.setCreateTime(new Date());
|
||||
}
|
||||
if (loginAccount!=null){
|
||||
if (entity.getCreateUserId() == null) {
|
||||
entity.setCreateUserId(loginAccount.getUserId());
|
||||
}
|
||||
if (StringUtils.isBlank(entity.getCreateUserName())) {
|
||||
entity.setCreateUserName(loginAccount.getNickName());
|
||||
}
|
||||
if (entity.getOrganId()==null){
|
||||
entity.setOrganId(loginAccount.getOrganId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
//修改审批状态,需要一并执行修改该的内容
|
||||
case 1:
|
||||
if (entity.getApplyStatus()!= ApprovalConsts.ApplyStatus.CANCEL){
|
||||
if (entity.getApprovalTime() == null) {
|
||||
entity.setApprovalTime(new Date());
|
||||
}
|
||||
if (loginAccount!=null){
|
||||
if (entity.getApprovalUserId() == null) {
|
||||
entity.setApprovalUserId(loginAccount.getUserId());
|
||||
}
|
||||
if (StringUtils.isBlank(entity.getApprovalUserName())) {
|
||||
entity.setApprovalUserName(loginAccount.getNickName());
|
||||
}
|
||||
}
|
||||
}
|
||||
//修改
|
||||
case 2:
|
||||
if (entity.getUpdateTime() == null) {
|
||||
entity.setUpdateTime(new Date());
|
||||
}
|
||||
if (loginAccount!=null){
|
||||
if (entity.getUpdateUserId() == null) {
|
||||
entity.setUpdateUserId(loginAccount.getUserId());
|
||||
}
|
||||
if (StringUtils.isBlank(entity.getUpdateUserName())) {
|
||||
entity.setUpdateUserName(loginAccount.getNickName());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Approval> queryList(QueryListParam<Approval> param) {
|
||||
int pageNum = param.getPageNum();
|
||||
int pageSize = param.getPageSize();
|
||||
if (pageNum > 0 && pageSize > 0) {
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
}
|
||||
LambdaQueryWrapper<Approval> wrapper = this.createWrapper(param.getEntity());
|
||||
wrapper.orderByDesc(Approval::getId);
|
||||
List<Approval> list = this.list(wrapper);
|
||||
PageInfo<Approval> pageInfo = new PageInfo<>(list);
|
||||
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateApplyStatus(StatusParam<Approval> statusParam) {
|
||||
LambdaQueryWrapper<Approval> updateWrapper = new LambdaQueryWrapper<>();
|
||||
updateWrapper.in(Approval::getId, statusParam.getIds());
|
||||
Approval approval = new Approval();
|
||||
approval.setApplyStatus(statusParam.getStatus());
|
||||
initEntity(approval,1);
|
||||
//修改状态
|
||||
boolean update = this.update(approval, updateWrapper);
|
||||
if (update) {
|
||||
//处理申请相关的逻辑
|
||||
handlerApplyByType(statusParam.getList(), statusParam.getStatus());
|
||||
}
|
||||
return update;
|
||||
}
|
||||
|
||||
private boolean handlerApplyByType(List<Approval> list, int status) {
|
||||
for (Approval approval : list) {
|
||||
try {
|
||||
String applyDetail = approval.getApplyDetail();
|
||||
JSONObject jsonObject = JSON.parseObject(applyDetail);
|
||||
switch (approval.getApplyType()) {
|
||||
//决策流版本发布
|
||||
case ApprovalConsts.ApprovalType.DECISION_FLOW_VERSION_DEPLOY:
|
||||
long engineVersionId = jsonObject.getLongValue("engineVersionId");
|
||||
engineVersionService.approvalCallBack(engineVersionId, status);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateStatus(StatusParam statusParam) {
|
||||
LambdaQueryWrapper<Approval> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Approval::getId,statusParam.getIds());
|
||||
Approval approval = new Approval();
|
||||
approval.setStatus(statusParam.getStatus());
|
||||
boolean update = this.update(approval, wrapper);
|
||||
return update;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<Approval> createWrapper(Approval entity) {
|
||||
LambdaQueryWrapper<Approval> wrapper = new LambdaQueryWrapper<>();
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
if (loginAccount.getOrganId()!=1){
|
||||
wrapper.eq(Approval::getOrganId, loginAccount.getOrganId());
|
||||
}
|
||||
if (entity != null) {
|
||||
if (entity.getId() != null) {
|
||||
wrapper.eq(Approval::getId, entity.getId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getApplyType())) {
|
||||
wrapper.eq(Approval::getApplyType, entity.getApplyType());
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getCreateUserName())) {
|
||||
wrapper.eq(Approval::getCreateUserName, entity.getCreateUserName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getApprovalUserName())) {
|
||||
wrapper.eq(Approval::getApprovalUserName, entity.getApprovalUserName());
|
||||
}
|
||||
if (entity.getApplyStatus()!=null){
|
||||
wrapper.eq(Approval::getApplyStatus,entity.getApplyStatus());
|
||||
}
|
||||
if (entity.getStatus() != null) {
|
||||
wrapper.eq(Approval::getStatus, entity.getStatus());
|
||||
} else {
|
||||
wrapper.eq(Approval::getStatus, StatusConst.STATUS_ENABLED);
|
||||
}
|
||||
if (entity.getCreateUserId()!=null) {
|
||||
if (entity.getCreateUserId()==0L){
|
||||
wrapper.eq(Approval::getCreateUserId, loginAccount.getUserId());
|
||||
}else {
|
||||
wrapper.eq(Approval::getCreateUserId,entity.getCreateUserId());
|
||||
}
|
||||
|
||||
}
|
||||
if (entity.getQueryStartTime()!=null){
|
||||
wrapper.ge(Approval::getCreateTime,entity.getQueryStartTime());
|
||||
}
|
||||
if (entity.getQueryEndTime()!=null){
|
||||
wrapper.le(Approval::getCreateTime,entity.getQueryEndTime());
|
||||
}
|
||||
} else {
|
||||
wrapper.eq(Approval::getStatus, StatusConst.STATUS_ENABLED);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private boolean checkAuthority(SysUser sysUser) {
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.fibo.ddp.common.service.authx.dictionary;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.authx.dictionary.Dictionary;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* (Dictionary)表服务接口
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-15 15:08:04
|
||||
*/
|
||||
public interface DictionaryService extends IService<Dictionary> {
|
||||
|
||||
Dictionary queryByKey(String key);
|
||||
|
||||
PageInfo<Dictionary> queryList(QueryListParam<Dictionary> param);
|
||||
|
||||
boolean saveBatchDictionary(Collection<Dictionary> dictionaries);
|
||||
|
||||
boolean update(Dictionary param);
|
||||
|
||||
Map<String, Dictionary> refreshCache();
|
||||
|
||||
boolean deleteByIds(List<Long> ids);
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.fibo.ddp.common.service.authx.dictionary.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.dictionary.DictionaryMapper;
|
||||
import com.fibo.ddp.common.model.authx.dictionary.Dictionary;
|
||||
import com.fibo.ddp.common.model.authx.dictionary.DictionaryCacheManager;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
|
||||
import com.fibo.ddp.common.service.authx.dictionary.DictionaryService;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (Dictionary)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-15 15:08:05
|
||||
*/
|
||||
@Service("dictionaryService")
|
||||
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements DictionaryService {
|
||||
private static boolean useCache = false;
|
||||
private static final String useCacheKey = "useCache";
|
||||
private static final String useCacheOn = "on";
|
||||
@Resource
|
||||
private DictionaryMapper dictionaryMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Dictionary queryByKey(String dictKey) {
|
||||
if (StringUtils.isBlank(dictKey)) {
|
||||
return null;
|
||||
}
|
||||
if (useCache) {
|
||||
return DictionaryCacheManager.getByKey(dictKey);
|
||||
}
|
||||
LambdaQueryWrapper<Dictionary> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Dictionary::getDictKey, dictKey);
|
||||
return dictionaryMapper.selectOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo<Dictionary> queryList(QueryListParam<Dictionary> param) {
|
||||
QueryListParam.checkIsPage(param);
|
||||
if (useCache) {
|
||||
return DictionaryCacheManager.getByPage(param.getPageSize(), param.getPageNum());
|
||||
}
|
||||
if (QueryListParam.checkIsPage(param)) {
|
||||
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
PageInfo<Dictionary> pageInfo = new PageInfo<>(this.list());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveBatchDictionary(Collection<Dictionary> dictionaries) {
|
||||
checkDictionaries(dictionaries);
|
||||
boolean result = dictionaryMapper.insertOrUpdateBatch(dictionaries) > 0;
|
||||
if (useCache) {
|
||||
DictionaryCacheManager.addCache(dictionaries.stream().filter(item -> item.getId() != null).collect(Collectors.toList()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(Dictionary param) {
|
||||
checkDictionary(param);
|
||||
boolean result = this.updateById(param);
|
||||
if (useCache) {
|
||||
DictionaryCacheManager.updateOrAddCache(param);
|
||||
}
|
||||
if (useCacheKey.equals(param.getDictKey())){
|
||||
refreshCache();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Map<String, Dictionary> refreshCache() {
|
||||
useCache = false;
|
||||
Dictionary dictionary = this.queryByKey(useCacheKey);
|
||||
if (dictionary != null && useCacheOn.equals(dictionary.getDictValue())) {
|
||||
useCache = true;
|
||||
}
|
||||
DictionaryCacheManager.clearCache();
|
||||
if (useCache) {
|
||||
DictionaryCacheManager.addCache(this.list());
|
||||
}
|
||||
return DictionaryCacheManager.getAllCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteByIds(List<Long> ids) {
|
||||
boolean result = this.removeByIds(ids);
|
||||
if (useCache) {
|
||||
DictionaryCacheManager.deleteCacheByIds(ids);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean checkDictionaries(Collection<Dictionary> dictionaries) {
|
||||
if (!CollectionUtils.isEmpty(dictionaries)) {
|
||||
dictionaries.forEach(item -> {
|
||||
checkDictionary(item);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkDictionary(Dictionary dictionary) {
|
||||
if (dictionary == null || StringUtils.isBlank(dictionary.getDictKey())) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "新增字典变量的key不能为空");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
|
||||
package com.fibo.ddp.common.service.authx.system;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.authx.system.SysMenu;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SysMenuService extends IService<SysMenu> {
|
||||
/**
|
||||
* 查询所有资源
|
||||
* @return
|
||||
*/
|
||||
public List<SysMenu> getAllSysMenu(SysMenu entity);
|
||||
/**
|
||||
* 查询单条资源
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SysMenu findById(long id);
|
||||
/**
|
||||
* 新增资源
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
public int createSysMenu(SysMenu sysMenu);
|
||||
/**
|
||||
* 修改资源
|
||||
* @param sysMenu
|
||||
* @return
|
||||
*/
|
||||
public int updateSysMenu(SysMenu sysMenu);
|
||||
/**
|
||||
* 修改资源状态
|
||||
* @param id
|
||||
* @param idList
|
||||
* @return
|
||||
*/
|
||||
public int updateStatus(@Param("status") int status, @Param("list") List<Integer> list);
|
||||
/**
|
||||
* 保存角色菜单关系(实现修改)
|
||||
*/
|
||||
public int insertRoleMenu(@Param("roleId") long roleId, @Param("list") List<Integer> list);
|
||||
/**
|
||||
* 分配资源树
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
public List<SysMenu> findTreeList(SysMenu entity);
|
||||
/**
|
||||
* 获取所有启用资源
|
||||
* @return
|
||||
*/
|
||||
public List<SysMenu> getAllValidMenu(SysMenu entity);
|
||||
/**
|
||||
* 删除角色菜单关系(实现修改)
|
||||
*/
|
||||
public int deleteRoleMenu(long roleId);
|
||||
/**
|
||||
* 验证唯一性
|
||||
*/
|
||||
public List<SysMenu> validateMenuOnly(SysMenu sysMenu);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.fibo.ddp.common.service.authx.system;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.authx.system.SysOrganization;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface SysOrganizationService extends IService<SysOrganization> {
|
||||
/**
|
||||
* 查询所有公司
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<SysOrganization> getAllSysOrganization();
|
||||
|
||||
/**
|
||||
* 获取所有启用公司
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<SysOrganization> getAllValidOrgan();
|
||||
|
||||
/**
|
||||
* 查询单个公司
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SysOrganization findById(long id);
|
||||
|
||||
/**
|
||||
* 创建公司
|
||||
*
|
||||
* @param SysOrganization
|
||||
* @return
|
||||
*/
|
||||
public int createSysOrganization(SysOrganization SysOrganization);
|
||||
|
||||
/**
|
||||
* 修改公司
|
||||
*
|
||||
* @param SysOrganization
|
||||
* @return
|
||||
*/
|
||||
public int updateSysOrganization(SysOrganization SysOrganization);
|
||||
|
||||
/**
|
||||
* 修改公司状态(停用/启用、删除)
|
||||
*
|
||||
* @param states
|
||||
* @return
|
||||
*/
|
||||
public int updateStatus(@Param("status") int status, @Param("list") List<Integer> list);
|
||||
|
||||
/**
|
||||
* 验证唯一性
|
||||
*/
|
||||
public List<SysOrganization> validateOrganOnly(SysOrganization SysOrganization);
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.fibo.ddp.common.service.authx.system;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.authx.system.SysRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface SysRoleService extends IService<SysRole> {
|
||||
/**
|
||||
* 获取本组织所有角色
|
||||
* @param organId
|
||||
* @return
|
||||
*/
|
||||
public List<SysRole> getAllSysRole(long organId);
|
||||
/**
|
||||
* 获取所有角色
|
||||
*/
|
||||
public List<SysRole> getAllRoles();
|
||||
/**
|
||||
* 获取本组织启用的角色
|
||||
* @param organId
|
||||
* @return
|
||||
*/
|
||||
public List<SysRole> getAllValidRole(@Param("organId") long organId, @Param("author") String author);
|
||||
/**
|
||||
* 查询本组织的单个用户
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SysRole findById(@Param("userId") long id, @Param("organId") long organId);
|
||||
/**
|
||||
* 查询单个角色
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SysRole findByAId(long id);
|
||||
/**
|
||||
* 创建本组织角色
|
||||
* @param sysRole
|
||||
* @return
|
||||
*/
|
||||
public int createSysRole(SysRole sysRole);
|
||||
/**
|
||||
* 修改本公司角色
|
||||
* @param sysRole
|
||||
* @return
|
||||
*/
|
||||
public int updateSysRole(SysRole sysRole);
|
||||
|
||||
/**
|
||||
* 修改角色状态(启用、停用、删除)
|
||||
* @param id
|
||||
* @param idList
|
||||
* @return
|
||||
*/
|
||||
public int updateStatus(@Param("status") int status, @Param("list") List<Integer> list);
|
||||
/**
|
||||
* 根据角色查询角色所在公司
|
||||
*/
|
||||
public long getOrganByRoleId(long roleId);
|
||||
/**
|
||||
* 验证角色唯一性
|
||||
*/
|
||||
public List<SysRole> validateRoleOnly(SysRole sysRole);
|
||||
/**
|
||||
* 查询公司管理员角色id
|
||||
*/
|
||||
public List<SysRole> getOrganRoleByAuthor(SysRole sysRole);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
package com.fibo.ddp.common.service.authx.system;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public interface SysUserService extends IService<SysUser> {
|
||||
/**
|
||||
* 查询搜索用户
|
||||
*/
|
||||
public List<SysUser> getAllUsers(SysUser sysUser);
|
||||
/**
|
||||
* 查询本组织单个用户
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public SysUser findById(SysUser sysUser);
|
||||
/**
|
||||
* 创建本公司用户
|
||||
* @param sysUser
|
||||
* @return
|
||||
*/
|
||||
public long createSysUser(SysUser sysUser);
|
||||
/**
|
||||
* 修改本公司用户
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public int updateSysUser(SysUser user);
|
||||
/**
|
||||
* 修改用户状态(停用/启用)
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public int updateStates(@Param("status") int status, @Param("list") List<Integer> list);
|
||||
/**
|
||||
* 通过用户id查询角色
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
public SysUser findRoleByUserId(long userId);
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
public int updatePassword(SysUser sysUser);
|
||||
|
||||
/**
|
||||
* 本公司账号员工编号唯一性
|
||||
*/
|
||||
public List<SysUser> validateUserOnly(SysUser sysUser);
|
||||
|
||||
SysUser login(String account,String password);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.fibo.ddp.common.service.authx.system.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysMenuMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysMenu;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.service.authx.system.SysMenuService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements SysMenuService {
|
||||
@Autowired
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
/**
|
||||
* 查询所有资源
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> getAllSysMenu(SysMenu entity) {
|
||||
return sysMenuMapper.getAllSysMenu(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单条资源
|
||||
*/
|
||||
@Override
|
||||
public SysMenu findById(long id) {
|
||||
return sysMenuMapper.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增资源
|
||||
*/
|
||||
@Override
|
||||
public int createSysMenu(SysMenu sysMenu) {
|
||||
//获取登录人信息
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
//分配者
|
||||
long userId = sysUser.getUserId();
|
||||
sysMenu.setUserId(userId);
|
||||
return sysMenuMapper.createSysMenu(sysMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改资源
|
||||
*/
|
||||
@Override
|
||||
public int updateSysMenu(SysMenu sysMenu) {
|
||||
return sysMenuMapper.updateSysMenu(sysMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改资源状态
|
||||
*/
|
||||
@Override
|
||||
public int updateStatus(int status, List<Integer> list) {
|
||||
return sysMenuMapper.updateStatus(status, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用资源
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> getAllValidMenu(SysMenu entity) {
|
||||
return sysMenuMapper.getAllValidMenu(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分配资源树
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> findTreeList(SysMenu entity) {
|
||||
return sysMenuMapper.findTreeList(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存、修改资源树(实现修改)
|
||||
*/
|
||||
@Override
|
||||
public int insertRoleMenu(long roleId, List<Integer> list) {
|
||||
//先删除原关系
|
||||
sysMenuMapper.deleteRoleMenu(roleId);
|
||||
//保存菜单角色关系
|
||||
int insertNum = sysMenuMapper.insertRoleMenu(roleId, list);
|
||||
return insertNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除资源树
|
||||
*/
|
||||
@Override
|
||||
public int deleteRoleMenu(long roleId) {
|
||||
return sysMenuMapper.deleteRoleMenu(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证唯一性
|
||||
*/
|
||||
@Override
|
||||
public List<SysMenu> validateMenuOnly(SysMenu sysMenu) {
|
||||
return sysMenuMapper.validateMenuOnly(sysMenu);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.fibo.ddp.common.service.authx.system.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysOrganizationMapper;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysRoleMapper;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysUserMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysOrganization;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.service.authx.system.SysOrganizationService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMapper,SysOrganization> implements SysOrganizationService {
|
||||
@Autowired
|
||||
private SysOrganizationMapper sysOrganizationMapper;
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
/**
|
||||
* 查询公司
|
||||
*/
|
||||
@Override
|
||||
public List<SysOrganization> getAllSysOrganization() {
|
||||
return sysOrganizationMapper.getAllSysOrganization();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个公司
|
||||
*/
|
||||
@Override
|
||||
public SysOrganization findById(long id) {
|
||||
return sysOrganizationMapper.findById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建公司
|
||||
*/
|
||||
@Override
|
||||
public int createSysOrganization(SysOrganization SysOrganization) {
|
||||
//获取登录人信息(超级管理员)
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
String nickName = sysUser.getNickName();
|
||||
SysOrganization.setAuthor(nickName);
|
||||
//生成token唯一标识
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
SysOrganization.setToken(uuid);
|
||||
return sysOrganizationMapper.createSysOrganization(SysOrganization);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改公司
|
||||
*/
|
||||
@Override
|
||||
public int updateSysOrganization(SysOrganization SysOrganization) {
|
||||
return sysOrganizationMapper.updateSysOrganization(SysOrganization);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量修改公司状态
|
||||
*/
|
||||
@Override
|
||||
public int updateStatus(int status, List<Integer> list) {
|
||||
//删除、停用、启用每个公司下的所有角色
|
||||
sysRoleMapper.deleteRolesByOrgans(status, list);
|
||||
//删除、停用、启用每个公司下的所有账号
|
||||
sysUserMapper.deleteUsersByOrgans(status, list);
|
||||
//删除、停用、启用每个公司下的所有用户角色关系
|
||||
sysUserMapper.deleteUserRoleByOrgan(status, list);
|
||||
//删除、停用、启用公司
|
||||
int num = sysOrganizationMapper.updateStatus(status, list);
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有启用公司
|
||||
*/
|
||||
@Override
|
||||
public List<SysOrganization> getAllValidOrgan() {
|
||||
return sysOrganizationMapper.getAllValidOrgan();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证唯一性
|
||||
*/
|
||||
@Override
|
||||
public List<SysOrganization> validateOrganOnly(
|
||||
SysOrganization SysOrganization) {
|
||||
return sysOrganizationMapper.validateOrganOnly(SysOrganization);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.fibo.ddp.common.service.authx.system.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysRoleMapper;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysUserMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysRole;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.service.authx.system.SysRoleService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper,SysRole> implements SysRoleService {
|
||||
@Autowired
|
||||
private SysRoleMapper sysRoleMapper;
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
/**
|
||||
* 获取本组织所有角色
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> getAllSysRole(long organId) {
|
||||
return sysRoleMapper.getAllSysRole(organId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有角色
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> getAllRoles() {
|
||||
return sysRoleMapper.getAllRoles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本组织的单个角色
|
||||
*/
|
||||
@Override
|
||||
public SysRole findById(long id, long organId) {
|
||||
return sysRoleMapper.findById(id, organId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询单个角色
|
||||
*/
|
||||
@Override
|
||||
public SysRole findByAId(long id) {
|
||||
return sysRoleMapper.findByAId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建本公司的角色
|
||||
*/
|
||||
@Override
|
||||
public int createSysRole(SysRole sysRole) {
|
||||
return sysRoleMapper.createSysRole(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改本公司角色
|
||||
*/
|
||||
@Override
|
||||
public int updateSysRole(SysRole sysRole) {
|
||||
//获取管理员所在公司
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
long organId = sysUser.getOrganId();
|
||||
if (organId != 1) {
|
||||
//修改本公司角色
|
||||
sysRole.setOrganId(organId);
|
||||
}
|
||||
return sysRoleMapper.updateSysRole(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改角色状态(启用、停用、删除)
|
||||
*/
|
||||
@Override
|
||||
public int updateStatus(int status, List<Integer> list) {
|
||||
//查询角色下的账号id
|
||||
List<Long> listu = sysUserMapper.getBatchUserIdsByRoleId(list);
|
||||
//批量删除角色关联账号
|
||||
if (listu != null && listu.size() > 0) {
|
||||
sysUserMapper.deleteUsersByIds(status, listu);
|
||||
}
|
||||
//批量删除角色账号关系
|
||||
sysUserMapper.deleteBatchUserRole(status, list);
|
||||
//批量删除角色
|
||||
int num = sysRoleMapper.updateStatus(status, list);
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色查询公司
|
||||
*/
|
||||
@Override
|
||||
public long getOrganByRoleId(long roleId) {
|
||||
return sysRoleMapper.getOrganByRoleId(roleId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证角色唯一性
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> validateRoleOnly(SysRole sysRole) {
|
||||
return sysRoleMapper.validateRoleOnly(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询公司管理员角色id
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> getOrganRoleByAuthor(SysRole sysRole) {
|
||||
return sysRoleMapper.getOrganRoleByAuthor(sysRole);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取公司启用角色
|
||||
*/
|
||||
@Override
|
||||
public List<SysRole> getAllValidRole(long organId, String author) {
|
||||
return sysRoleMapper.getAllValidRole(organId, author);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.fibo.ddp.common.service.authx.system.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysUserMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.service.authx.system.SysUserService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.utils.common.MD5;
|
||||
import com.fibo.ddp.common.utils.constant.StatusConst;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Service
|
||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||
@Autowired
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
/**
|
||||
* 查询搜索用户
|
||||
*/
|
||||
@Override
|
||||
public List<SysUser> getAllUsers(SysUser sysUser) {
|
||||
return sysUserMapper.getAllUsers(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询本组织单个用户
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public SysUser findById(SysUser sysUser) {
|
||||
return sysUserMapper.findById(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建用户
|
||||
*/
|
||||
@Override
|
||||
public long createSysUser(SysUser sysUser) {
|
||||
long num = 0;
|
||||
//密码加密
|
||||
String password = MD5.GetMD5Code("111111");
|
||||
sysUser.setPassword(password);
|
||||
//创建人
|
||||
SysUser user = SessionManager.getLoginAccount();
|
||||
String nickName = user.getNickName();
|
||||
sysUser.setAuthor(nickName);
|
||||
//创建用户并返回id
|
||||
// sysUserMapper.createSysUser(sysUser);
|
||||
sysUser.setStatus(StatusConst.STATUS_ENABLED);
|
||||
sysUser.setBirth(new Date());
|
||||
sysUserMapper.insert(sysUser);
|
||||
long uId = sysUser.getUserId();
|
||||
long roleId = sysUser.getSysRole().getRoleId();
|
||||
long orgaId = sysUser.getOrganId();
|
||||
if (uId != 0 && roleId != 0) {
|
||||
//添加表关系
|
||||
num = sysUserMapper.insertUserRole(uId, roleId, orgaId);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改本公司用户
|
||||
*/
|
||||
@Override
|
||||
public int updateSysUser(SysUser sysUser) {
|
||||
int num = 0;
|
||||
//修改用户
|
||||
int updateNum = sysUserMapper.updateSysUser(sysUser);
|
||||
//修改用户角色关系
|
||||
if (updateNum == 1) {
|
||||
num = sysUserMapper.updateUserRole(sysUser);
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户状态
|
||||
*/
|
||||
@Override
|
||||
public int updateStates(int status, List<Integer> list) {
|
||||
return sysUserMapper.updateStates(status, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户id查询角色
|
||||
*/
|
||||
@Override
|
||||
public SysUser findRoleByUserId(long userId) {
|
||||
return sysUserMapper.findRoleByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
@Override
|
||||
public int updatePassword(SysUser sysUser) {
|
||||
//获取登录人id
|
||||
// SysUser sysUser = SessionManager.getLoginAccount();
|
||||
// long userId = sysUser.getUserId();
|
||||
//密码加密
|
||||
String password = MD5.GetMD5Code(sysUser.getPassword());
|
||||
sysUser.setPassword(password);
|
||||
// sysUser.setUserId(userId);
|
||||
return sysUserMapper.updatePassword(sysUser);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本公司账号员工编号唯一性
|
||||
*/
|
||||
@Override
|
||||
public List<SysUser> validateUserOnly(SysUser sysUser) {
|
||||
return sysUserMapper.validateUserOnly(sysUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser login(String account, String password) {
|
||||
LambdaUpdateWrapper<SysUser> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.eq(SysUser::getAccount, account)
|
||||
.eq(SysUser::getPassword, password);
|
||||
List<SysUser> list = this.list(wrapper);
|
||||
if (list.size() == 1) {
|
||||
return list.get(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.fibo.ddp.common.service.cignacmb;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.cignacmb.BusinessEventLog;
|
||||
import com.fibo.ddp.common.model.cignacmb.request.EventLogParam;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.EventLogResponse;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
/**
|
||||
* 事件调用记录(BusinessEventLog)表服务接口
|
||||
*/
|
||||
public interface BusinessEventLogService extends IService<BusinessEventLog> {
|
||||
|
||||
PageInfo<EventLogResponse> getEventLogList(EventLogParam param);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.fibo.ddp.common.service.cignacmb;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.cignacmb.BusinessRuleLog;
|
||||
import com.fibo.ddp.common.model.cignacmb.request.RuleLogParam;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.EventLogDetailResponse;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.RuleLogResponse;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 规则执行记录(BusinessRuleLog)表服务接口
|
||||
*/
|
||||
public interface BusinessRuleLogService extends IService<BusinessRuleLog> {
|
||||
|
||||
PageInfo<RuleLogResponse> getRuleLogList(RuleLogParam param);
|
||||
|
||||
List<EventLogDetailResponse> queryByIds(List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.fibo.ddp.common.service.cignacmb;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.cignacmb.TBusinessRuleRel;
|
||||
import com.fibo.ddp.common.model.cignacmb.req.BusinessRuleRelReq;
|
||||
import com.fibo.ddp.common.model.common.ResponseEntityDto;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 业务类型与规则关联表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author oldRose
|
||||
* @since 2021-11-10
|
||||
*/
|
||||
public interface ITBusinessRuleRelService extends IService<TBusinessRuleRel> {
|
||||
|
||||
ResponseEntityDto<?> addBusinessRuleRel(BusinessRuleRelReq param);
|
||||
|
||||
ResponseEntityDto<?> editBusinessRuleRel(BusinessRuleRelReq param);
|
||||
|
||||
ResponseEntityDto<?> detailBusinessRuleRel(BusinessRuleRelReq param);
|
||||
|
||||
ResponseEntityDto<?> deleteBusinessRuleRel(BusinessRuleRelReq param);
|
||||
|
||||
ResponseEntityDto<?> pageList(BusinessRuleRelReq param);
|
||||
|
||||
ResponseEntityDto<?> queryByBusinessType(BusinessRuleRelReq param);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.fibo.ddp.common.service.cignacmb.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.cignacmb.BusinessEventLogMapper;
|
||||
import com.fibo.ddp.common.model.cignacmb.BusinessEventLog;
|
||||
import com.fibo.ddp.common.model.cignacmb.request.EventLogParam;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.EventLogResponse;
|
||||
import com.fibo.ddp.common.service.cignacmb.BusinessEventLogService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 事件调用记录(BusinessEventLog)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class BusinessEventLogServiceImpl extends ServiceImpl<BusinessEventLogMapper, BusinessEventLog> implements BusinessEventLogService {
|
||||
|
||||
@Autowired
|
||||
private BusinessEventLogMapper eventLogMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<EventLogResponse> getEventLogList(EventLogParam param) {
|
||||
Long organId = SessionManager.getSession().getSysUser().getOrganId();
|
||||
param.setOrganId(organId);
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
List<EventLogResponse> eventLogResponses = eventLogMapper.queryAllByLimit(param);
|
||||
PageInfo<EventLogResponse> pageInfo = new PageInfo<>(eventLogResponses);
|
||||
return pageInfo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.fibo.ddp.common.service.cignacmb.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.cignacmb.BusinessRuleLogMapper;
|
||||
import com.fibo.ddp.common.model.cignacmb.BusinessRuleLog;
|
||||
import com.fibo.ddp.common.model.cignacmb.request.RuleLogParam;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.EventLogDetailResponse;
|
||||
import com.fibo.ddp.common.model.cignacmb.response.RuleLogResponse;
|
||||
import com.fibo.ddp.common.service.cignacmb.BusinessRuleLogService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 规则执行记录(BusinessRuleLog)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class BusinessRuleLogServiceImpl extends ServiceImpl<BusinessRuleLogMapper, BusinessRuleLog> implements BusinessRuleLogService {
|
||||
|
||||
@Autowired
|
||||
private BusinessRuleLogMapper ruleLogMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo<RuleLogResponse> getRuleLogList(RuleLogParam param) {
|
||||
Long organId = SessionManager.getSession().getSysUser().getOrganId();
|
||||
param.setOrganId(organId);
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
List<RuleLogResponse> ruleLogResponses = ruleLogMapper.queryAllByLimit(param);
|
||||
PageInfo<RuleLogResponse> pageInfo = new PageInfo<>(ruleLogResponses);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EventLogDetailResponse> queryByIds(List<String> ids) {
|
||||
return ruleLogMapper.queryByIds(ids);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
package com.fibo.ddp.common.service.cignacmb.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.cignacmb.TBusinessRuleRelMapper;
|
||||
import com.fibo.ddp.common.model.cignacmb.TBusinessRuleRel;
|
||||
import com.fibo.ddp.common.model.cignacmb.req.BusinessRuleRelReq;
|
||||
import com.fibo.ddp.common.model.cignacmb.vo.BusinessRuleRelVO;
|
||||
import com.fibo.ddp.common.model.common.ResponseEntityBuilder;
|
||||
import com.fibo.ddp.common.model.common.ResponseEntityDto;
|
||||
import com.fibo.ddp.common.service.cignacmb.ITBusinessRuleRelService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.utils.util.StringUtil;
|
||||
import com.fibo.ddp.common.utils.constant.RuleInfoConstants;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 业务类型与规则关联表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author oldRose
|
||||
* @since 2021-11-10
|
||||
*/
|
||||
@Service("iTBusinessRuleRelService")
|
||||
public class TBusinessRuleRelServiceImpl extends ServiceImpl<TBusinessRuleRelMapper, TBusinessRuleRel> implements ITBusinessRuleRelService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> addBusinessRuleRel(BusinessRuleRelReq param) {
|
||||
try {
|
||||
//参数校验
|
||||
checkParam(param);
|
||||
TBusinessRuleRel businessRuleRel = new TBusinessRuleRel();
|
||||
//组件规则信息
|
||||
buildModel(param,businessRuleRel);
|
||||
//插入
|
||||
this.save(businessRuleRel);
|
||||
} catch (Exception e) {
|
||||
logger.info("新增业务类型和规则关联 记录出错");
|
||||
return ResponseEntityBuilder.buildErrorResponse("999999999",e.getMessage());
|
||||
}
|
||||
return ResponseEntityBuilder.buildNormalResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* 组件实体
|
||||
* @param param
|
||||
*/
|
||||
private void buildModel(BusinessRuleRelReq param,TBusinessRuleRel businessRuleRel) {
|
||||
BeanUtils.copyProperties(param,businessRuleRel);
|
||||
//组件规则信息
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put(RuleInfoConstants.BLACK_LIST,param.getBlacklist());
|
||||
jsonObject.put(RuleInfoConstants.THRESHOLD,param.getThreshold());
|
||||
jsonObject.put(RuleInfoConstants.MUTEX,param.getMutex());
|
||||
jsonObject.put(RuleInfoConstants.MERGE,param.getMerge());
|
||||
jsonObject.put(RuleInfoConstants.INTERCEPT,param.getIntercept());
|
||||
businessRuleRel.setRuleInfo(JSON.toJSONString(jsonObject));
|
||||
businessRuleRel.setStatus(1);
|
||||
businessRuleRel.setCreator(Long.valueOf(1));
|
||||
businessRuleRel.setCreateTime(new Date());
|
||||
businessRuleRel.setUpdateTime(new Date());
|
||||
businessRuleRel.setOrganId(SessionManager.getLoginAccount().getOrganId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查参数
|
||||
* @param param
|
||||
*/
|
||||
private void checkParam(BusinessRuleRelReq param) throws Exception {
|
||||
if(param == null){
|
||||
throw new Exception("参数不能为空", new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getBusinessName())){
|
||||
throw new Exception("业务类型名称不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getBusinessChildCode())){
|
||||
throw new Exception("业务类型编码不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getBusinessChildName())){
|
||||
throw new Exception("业务子类型名称不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getBusinessChildCode())){
|
||||
throw new Exception("业务子类型编码不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getSendType())){
|
||||
throw new Exception("发送方式不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getIsUnsubscribe())){
|
||||
throw new Exception("是否取消订阅 不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getEventType())){
|
||||
throw new Exception("事件类型 不能为空",new Throwable());
|
||||
}
|
||||
if(StringUtil.isBlank(param.getIsManualIntervention())){
|
||||
throw new Exception("是否人工干预 不能为空",new Throwable());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> editBusinessRuleRel(BusinessRuleRelReq param) {
|
||||
//参数校验
|
||||
if(param.getId()==null){
|
||||
return ResponseEntityBuilder.buildErrorResponse("999999","id必须传,不能为空");
|
||||
}
|
||||
try {
|
||||
checkParam(param);
|
||||
//组件规则信息
|
||||
TBusinessRuleRel businessRuleRel = new TBusinessRuleRel();
|
||||
buildModel(param,businessRuleRel);
|
||||
this.saveOrUpdate(businessRuleRel);
|
||||
} catch (Exception e) {
|
||||
logger.info("编辑业务类型与规则关联表 出错");
|
||||
return ResponseEntityBuilder.buildErrorResponse("999999999",e.getMessage());
|
||||
}
|
||||
return ResponseEntityBuilder.buildNormalResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> detailBusinessRuleRel(BusinessRuleRelReq param) {
|
||||
//参数校验
|
||||
if(param.getId()==null){
|
||||
return ResponseEntityBuilder.buildErrorResponse("999999","id必须传,不能为空");
|
||||
}
|
||||
TBusinessRuleRel businessRuleRel = this.getById(param.getId());
|
||||
//获取出ruleInfo,循环拿出规则,方便展示
|
||||
String ruleInfo = businessRuleRel.getRuleInfo();
|
||||
JSONObject jsonObject = JSON.parseObject(ruleInfo);
|
||||
JSONArray blacklist = JSONArray.parseArray(jsonObject.get("blacklist")+"");
|
||||
JSONArray threshold = JSONArray.parseArray(jsonObject.get("threshold")+"");
|
||||
JSONArray mutex = JSONArray.parseArray(jsonObject.get("mutex")+"");
|
||||
JSONArray merge = JSONArray.parseArray(jsonObject.get("merge")+"");
|
||||
JSONArray intercept = JSONArray.parseArray(jsonObject.get("intercept")+"");
|
||||
//提取到对应的id 查出规则
|
||||
BusinessRuleRelVO businessRuleRelVO = new BusinessRuleRelVO();
|
||||
BeanUtils.copyProperties(businessRuleRel,businessRuleRelVO);
|
||||
businessRuleRelVO.setBlackList(blacklist);
|
||||
businessRuleRelVO.setThresholdList(threshold);
|
||||
businessRuleRelVO.setMutexList(mutex);
|
||||
businessRuleRelVO.setMergeList(merge);
|
||||
businessRuleRelVO.setInterceptList(intercept);
|
||||
return ResponseEntityBuilder.buildNormalResponse(businessRuleRel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> deleteBusinessRuleRel(BusinessRuleRelReq param) {
|
||||
//参数校验
|
||||
if(param.getId()==null){
|
||||
return ResponseEntityBuilder.buildErrorResponse("999999","id必须传,不能为空");
|
||||
}
|
||||
//删除
|
||||
QueryWrapper<TBusinessRuleRel> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("userId",param.getId());
|
||||
TBusinessRuleRel businessRuleRel = new TBusinessRuleRel();
|
||||
businessRuleRel.setStatus(0);
|
||||
this.update(businessRuleRel,queryWrapper);
|
||||
return ResponseEntityBuilder.buildNormalResponse();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> pageList(BusinessRuleRelReq param) {
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
QueryWrapper<TBusinessRuleRel> queryWrapper = new QueryWrapper<>();
|
||||
buildQueryWrapper(queryWrapper, param);
|
||||
List<TBusinessRuleRel> businessRuleRelList = this.list(queryWrapper);
|
||||
PageInfo<TBusinessRuleRel> pageInfo = new PageInfo<>(businessRuleRelList);
|
||||
pageInfo.setList(businessRuleRelList);
|
||||
return ResponseEntityBuilder.buildNormalResponse(pageInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseEntityDto<?> queryByBusinessType(BusinessRuleRelReq param) {
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
//根据业务类型查询对应规则(对外接口)
|
||||
QueryWrapper<TBusinessRuleRel> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("business_code",param.getBusinessCode());
|
||||
queryWrapper.eq("business_child_code",param.getBusinessChildCode());
|
||||
List<TBusinessRuleRel> businessRuleRelList = this.list(queryWrapper);
|
||||
PageInfo<TBusinessRuleRel> pageInfo = new PageInfo<>(businessRuleRelList);
|
||||
pageInfo.setList(businessRuleRelList);
|
||||
return ResponseEntityBuilder.buildNormalResponse(pageInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组建查询条件
|
||||
*
|
||||
* @param queryWrapper
|
||||
* @param param
|
||||
*/
|
||||
private void buildQueryWrapper(QueryWrapper<TBusinessRuleRel> queryWrapper, BusinessRuleRelReq param) {
|
||||
queryWrapper.eq("status",1);
|
||||
//更新时间倒序查询
|
||||
queryWrapper.orderByDesc("update_time");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.fibo.ddp.common.service.common;
|
||||
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* session 包装类
|
||||
*/
|
||||
@Data
|
||||
public class AccountSessionWrap {
|
||||
public AccountSessionWrap(String ip, String requestUri) {
|
||||
init(null, ip, requestUri);
|
||||
}
|
||||
|
||||
public AccountSessionWrap(SysUser sysUser, String ip, String requestUri) {
|
||||
init(sysUser, ip, requestUri);
|
||||
}
|
||||
|
||||
private void init(SysUser sysUser, String ip, String requestUri) {
|
||||
setSysUser(sysUser);
|
||||
setIp(ip);
|
||||
setRequestUri(requestUri);
|
||||
}
|
||||
|
||||
/** session */
|
||||
private SysUser sysUser;
|
||||
private String ip;
|
||||
private String requestUri;
|
||||
/** 请求唯一标识 */
|
||||
private String traceId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
package com.fibo.ddp.common.service.common;
|
||||
|
||||
import com.fibo.ddp.common.model.common.ExcelModel;
|
||||
import com.fibo.ddp.common.model.common.ExcelSheetModel;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ClassName:ExcelUtil</br>
|
||||
* Description: Excel实用类
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class ExcelUtil {
|
||||
|
||||
/**
|
||||
* exportExcel:导出excel
|
||||
*
|
||||
* @param out 输出流
|
||||
* @param exlType 导出格式
|
||||
* @param headers 表头信息
|
||||
* @param list 要导出的数据
|
||||
* @return cell
|
||||
*
|
||||
*/
|
||||
public static <T> void exportExcel(OutputStream out, String exlType, String[] headers, String[] classNames, List<T> list) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
|
||||
Workbook workbook;
|
||||
if (exlType.equalsIgnoreCase("xlsx")) {
|
||||
// 2007以上
|
||||
workbook = new SXSSFWorkbook(200);
|
||||
} else {
|
||||
// 97-2003
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
|
||||
Sheet sheet = workbook.createSheet("title");
|
||||
for (short i = 0; i < headers.length; i++) {
|
||||
if (i == headers.length - 1 || i == headers.length - 2) {
|
||||
sheet.setColumnWidth(i, 50 * 256);
|
||||
} else {
|
||||
sheet.setColumnWidth(i, 25 * 256);
|
||||
}
|
||||
}
|
||||
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
CellStyle cellStyle1 = workbook.createCellStyle();
|
||||
|
||||
Font font = workbook.createFont();
|
||||
Font font1 = workbook.createFont();
|
||||
|
||||
//微软雅黑,字体10,加粗,背景灰色
|
||||
font.setFontName("微软雅黑");
|
||||
font.setFontHeight((short) 240);
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
cellStyle.setFont(font);
|
||||
cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // 指定单元格居中对齐
|
||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
|
||||
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
||||
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||
cellStyle.setWrapText(true);
|
||||
cellStyle.setBorderBottom(CellStyle.BORDER_THIN); // 设置单无格的边框为粗体
|
||||
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
|
||||
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
|
||||
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
|
||||
|
||||
//微软雅黑,字体10,加粗,背景灰色
|
||||
font1.setFontName("微软雅黑");
|
||||
font1.setFontHeight((short) 240);
|
||||
cellStyle1.setFont(font1);
|
||||
cellStyle1.setAlignment(CellStyle.ALIGN_LEFT); // 指定单元格居中对齐
|
||||
cellStyle1.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
|
||||
cellStyle1.setWrapText(true);
|
||||
cellStyle1.setBorderBottom(CellStyle.BORDER_THIN); // 设置单无格的边框为粗体
|
||||
cellStyle1.setBorderLeft(CellStyle.BORDER_THIN);
|
||||
cellStyle1.setBorderRight(CellStyle.BORDER_THIN);
|
||||
cellStyle1.setBorderTop(CellStyle.BORDER_THIN);
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
row.setHeight((short) 400);
|
||||
|
||||
for (short i = 0; i < headers.length; i++) {
|
||||
Cell cell = row.createCell(i);
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell.setCellValue(headers[i]);
|
||||
}
|
||||
Iterator<T> it = list.iterator();
|
||||
int index = 0;
|
||||
while (it.hasNext()) {
|
||||
index++;
|
||||
row = sheet.createRow(index);
|
||||
row.setHeight((short) 800);
|
||||
T t = it.next();
|
||||
if (null != t) {
|
||||
for (int j = 0; j < headers.length; j++) {
|
||||
Cell cell = row.createCell(j);
|
||||
Field field = t.getClass().getDeclaredField(classNames[j]);
|
||||
field.setAccessible(true);
|
||||
Class valType = field.getType();
|
||||
|
||||
cell.setCellStyle(cellStyle1);
|
||||
if ("java.lang.String"
|
||||
.equalsIgnoreCase(valType.getName())) {
|
||||
cell.setCellValue((String) field.get(t));
|
||||
} else if ("java.lang.Integer"
|
||||
.equalsIgnoreCase(valType.getName())
|
||||
|| "int".equalsIgnoreCase(valType.getName())) {
|
||||
cell.setCellValue((Integer) field.get(t));
|
||||
} else if ("java.lang.Double"
|
||||
.equalsIgnoreCase(valType.getName())
|
||||
|| "double".equalsIgnoreCase(valType.getName())) {
|
||||
cell.setCellValue((Double) field.get(t) == null
|
||||
? 0
|
||||
: (Double) field.get(t));
|
||||
} else if ("java.lang.Long"
|
||||
.equalsIgnoreCase(valType.getName())
|
||||
|| "long".equalsIgnoreCase(valType.getName())) {
|
||||
cell.setCellValue((Long) field.get(t) == null
|
||||
? 0
|
||||
: (Long) field.get(t));
|
||||
} else if ("java.util.Date"
|
||||
.equalsIgnoreCase(valType.getName())) {
|
||||
if (null == field.get(t)) {
|
||||
cell.setCellValue("");
|
||||
} else {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(
|
||||
"yyyy/MM/dd");
|
||||
cell.setCellValue(sdf.format((Date) field.get(t)));
|
||||
}
|
||||
}
|
||||
field.setAccessible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
out = null;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (out != null)
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理单元格格式
|
||||
*
|
||||
* @param cell
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
public static String formatCell(Cell cell) {
|
||||
if (cell == null) {
|
||||
return "";
|
||||
}
|
||||
switch (cell.getCellType()) {
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
//日期格式的处理
|
||||
if (HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
return sdf.format(HSSFDateUtil.getJavaDate(cell.getNumericCellValue())).toString();
|
||||
}
|
||||
|
||||
return String.valueOf(cell.getNumericCellValue());
|
||||
|
||||
//字符串
|
||||
case Cell.CELL_TYPE_STRING:
|
||||
return cell.getStringCellValue();
|
||||
|
||||
// 公式
|
||||
case Cell.CELL_TYPE_FORMULA:
|
||||
return cell.getCellFormula();
|
||||
|
||||
// 空白
|
||||
case Cell.CELL_TYPE_BLANK:
|
||||
return "";
|
||||
|
||||
// 布尔取值
|
||||
case Cell.CELL_TYPE_BOOLEAN:
|
||||
return cell.getBooleanCellValue() + "";
|
||||
|
||||
//错误类型
|
||||
case Cell.CELL_TYPE_ERROR:
|
||||
return cell.getErrorCellValue() + "";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static void exportExcelTemplate(OutputStream out, ExcelModel model) throws SecurityException, IllegalArgumentException {
|
||||
Workbook workbook;
|
||||
if ("xlsx".equalsIgnoreCase(model.getType())) {
|
||||
// 2007以上
|
||||
workbook = new XSSFWorkbook();
|
||||
} else {
|
||||
// 97-2003
|
||||
workbook = new HSSFWorkbook();
|
||||
}
|
||||
List<ExcelSheetModel> sheets = model.getSheets();
|
||||
if (sheets == null && sheets.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (ExcelSheetModel info : sheets) {
|
||||
Sheet sheet = workbook.createSheet(info.getSheetName());
|
||||
int headerSize = info.getHeaders().size();
|
||||
for (short i = 0; i < headerSize; i++) {
|
||||
if (i == headerSize - 1 || i == headerSize - 2) {
|
||||
sheet.setColumnWidth(i, 50 * 256);
|
||||
} else {
|
||||
sheet.setColumnWidth(i, 25 * 256);
|
||||
}
|
||||
}
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
CellStyle cellStyle1 = workbook.createCellStyle();
|
||||
|
||||
Font font = workbook.createFont();
|
||||
Font font1 = workbook.createFont();
|
||||
|
||||
//微软雅黑,字体10,加粗,背景灰色
|
||||
font.setFontName("微软雅黑");
|
||||
font.setFontHeight((short) 240);
|
||||
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
cellStyle.setFont(font);
|
||||
cellStyle.setAlignment(CellStyle.ALIGN_CENTER); // 指定单元格居中对齐
|
||||
cellStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
|
||||
cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
||||
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||
cellStyle.setWrapText(true);
|
||||
cellStyle.setBorderBottom(CellStyle.BORDER_THIN); // 设置单无格的边框为粗体
|
||||
cellStyle.setBorderLeft(CellStyle.BORDER_THIN);
|
||||
cellStyle.setBorderRight(CellStyle.BORDER_THIN);
|
||||
cellStyle.setBorderTop(CellStyle.BORDER_THIN);
|
||||
|
||||
//微软雅黑,字体10,加粗,背景灰色
|
||||
font1.setFontName("微软雅黑");
|
||||
font1.setFontHeight((short) 240);
|
||||
cellStyle1.setFont(font1);
|
||||
cellStyle1.setAlignment(CellStyle.ALIGN_LEFT); // 指定单元格居中对齐
|
||||
cellStyle1.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
|
||||
cellStyle1.setWrapText(true);
|
||||
cellStyle1.setBorderBottom(CellStyle.BORDER_THIN); // 设置单无格的边框为粗体
|
||||
cellStyle1.setBorderLeft(CellStyle.BORDER_THIN);
|
||||
cellStyle1.setBorderRight(CellStyle.BORDER_THIN);
|
||||
cellStyle1.setBorderTop(CellStyle.BORDER_THIN);
|
||||
|
||||
Row row = sheet.createRow(0);
|
||||
row.setHeight((short) 400);
|
||||
|
||||
for (short i = 0; i < headerSize; i++) {
|
||||
Cell cell = row.createCell(i);
|
||||
cell.setCellStyle(cellStyle);
|
||||
cell.setCellValue(info.getHeaders().get(i));
|
||||
}
|
||||
List<List> data = info.getData();
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
List oneRow = data.get(i);
|
||||
row = sheet.createRow(i+1);
|
||||
for (int j = 0; j < oneRow.size(); j++) {
|
||||
Object cellData = oneRow.get(j);
|
||||
Cell cell = row.createCell(j);
|
||||
cell.setCellStyle(cellStyle1);
|
||||
cell.setCellValue(cellData.toString());
|
||||
}
|
||||
}
|
||||
try {
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
out.close();
|
||||
out = null;
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (out != null)
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.fibo.ddp.common.service.common;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
|
||||
/**
|
||||
* session管理类
|
||||
*/
|
||||
public class SessionManager {
|
||||
|
||||
private static TransmittableThreadLocal<AccountSessionWrap> session = new TransmittableThreadLocal<AccountSessionWrap>() {
|
||||
|
||||
};
|
||||
|
||||
public static AccountSessionWrap getSession() {
|
||||
return session.get();
|
||||
}
|
||||
|
||||
public static void setSession(AccountSessionWrap conn) {
|
||||
session.set(conn);
|
||||
}
|
||||
|
||||
public static SysUser getLoginAccount(){
|
||||
if(getSession() != null){
|
||||
return getSession().getSysUser();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.common.message.send;
|
||||
|
||||
public interface EmailService {
|
||||
/**
|
||||
* 发送邮件方法
|
||||
* @param to 收件人邮件地址
|
||||
* @param subject 主题
|
||||
* @param content 邮件内容
|
||||
*/
|
||||
public void sendHtmlMail(String to, String subject, String content);
|
||||
|
||||
/**
|
||||
* 发送模板邮件方法
|
||||
* @param to 收件人邮件地址
|
||||
* @param subject 主题
|
||||
* @param templateName 模板名称
|
||||
* @param context 追加参数集合
|
||||
*/
|
||||
// public void sendTemplateMail(String to, String subject, String templateName, Context context);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.fibo.ddp.common.service.common.message.send.impl;
|
||||
|
||||
import com.fibo.ddp.common.service.common.message.send.EmailService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
@Service("emailService")
|
||||
@Slf4j
|
||||
public class EmailServiceImpl implements EmailService {
|
||||
|
||||
@Resource
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
@Value("${spring.mail.username}")
|
||||
private String fromAddr;
|
||||
|
||||
@Override
|
||||
public void sendHtmlMail(String to, String subject, String content) {
|
||||
log.info("开始发送邮件,to:{}, subject:{}, content:{}", to, subject, content);
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
try {
|
||||
//true表示需要创建一个multipart message
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message,true, "utf-8");
|
||||
helper.setFrom(fromAddr);
|
||||
String[] split = to.split(",");
|
||||
helper.setTo(split);
|
||||
helper.setSubject(subject);
|
||||
helper.setText(content,true);
|
||||
mailSender.send(message);
|
||||
log.info("邮件发送成功");
|
||||
}catch (Exception e){
|
||||
log.error("邮件发送失败",e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getFromAddr() {
|
||||
return fromAddr;
|
||||
}
|
||||
|
||||
public void setFromAddr(String fromAddr) {
|
||||
this.fromAddr = fromAddr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fibo.ddp.common.service.common.message.template;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.AppTemplate;
|
||||
|
||||
/**
|
||||
* APP推送模板表(AppTemplate)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
public interface AppTemplateService extends IService<AppTemplate> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fibo.ddp.common.service.common.message.template;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.MessageSendRecord;
|
||||
|
||||
/**
|
||||
* 消息发送记录表(MessageSendRecord)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
public interface MessageSendRecordService extends IService<MessageSendRecord> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fibo.ddp.common.service.common.message.template;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.SmsTemplate;
|
||||
|
||||
/**
|
||||
* 短信模板表(SmsTemplate)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
public interface SmsTemplateService extends IService<SmsTemplate> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fibo.ddp.common.service.common.message.template;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.WebhookTemplate;
|
||||
|
||||
/**
|
||||
* webhook模板表(WebhookTemplate)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:12:03
|
||||
*/
|
||||
public interface WebhookTemplateService extends IService<WebhookTemplate> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fibo.ddp.common.service.common.message.template;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.WechatTemplate;
|
||||
|
||||
/**
|
||||
* 微信服务号模板表(WechatTemplate)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
public interface WechatTemplateService extends IService<WechatTemplate> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.common.message.template.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.AppTemplate;
|
||||
import com.fibo.ddp.common.dao.common.message.template.AppTemplateMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.service.common.message.template.AppTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* APP推送模板表(AppTemplate)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
@Service
|
||||
public class AppTemplateServiceImpl extends ServiceImpl<AppTemplateMapper, AppTemplate> implements AppTemplateService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.common.message.template.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.MessageSendRecord;
|
||||
import com.fibo.ddp.common.dao.common.message.template.MessageSendRecordMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.service.common.message.template.MessageSendRecordService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 消息发送记录表(MessageSendRecord)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
@Service
|
||||
public class MessageSendRecordServiceImpl extends ServiceImpl<MessageSendRecordMapper, MessageSendRecord> implements MessageSendRecordService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.common.message.template.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.SmsTemplate;
|
||||
import com.fibo.ddp.common.dao.common.message.template.SmsTemplateMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.service.common.message.template.SmsTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 短信模板表(SmsTemplate)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
@Service
|
||||
public class SmsTemplateServiceImpl extends ServiceImpl<SmsTemplateMapper, SmsTemplate> implements SmsTemplateService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.common.message.template.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.WebhookTemplate;
|
||||
import com.fibo.ddp.common.dao.common.message.template.WebhookTemplateMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.service.common.message.template.WebhookTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* webhook模板表(WebhookTemplate)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:12:03
|
||||
*/
|
||||
@Service
|
||||
public class WebhookTemplateServiceImpl extends ServiceImpl<WebhookTemplateMapper, WebhookTemplate> implements WebhookTemplateService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.common.message.template.impl;
|
||||
|
||||
import com.fibo.ddp.common.model.common.message.template.entity.WechatTemplate;
|
||||
import com.fibo.ddp.common.dao.common.message.template.WechatTemplateMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.service.common.message.template.WechatTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 微信服务号模板表(WechatTemplate)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:11:16
|
||||
*/
|
||||
@Service
|
||||
public class WechatTemplateServiceImpl extends ServiceImpl<WechatTemplateMapper, WechatTemplate> implements WechatTemplateService {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.fibo.ddp.common.service.common.runner;
|
||||
|
||||
import com.alibaba.ttl.TransmittableThreadLocal;
|
||||
|
||||
/**
|
||||
* session管理类
|
||||
*/
|
||||
public class RunnerSessionManager {
|
||||
private static TransmittableThreadLocal<SessionData> session = new TransmittableThreadLocal<SessionData>() {
|
||||
|
||||
};
|
||||
|
||||
public static SessionData getSession() {
|
||||
return session.get();
|
||||
}
|
||||
|
||||
public static void setSession(SessionData conn) {
|
||||
session.set(conn);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.fibo.ddp.common.service.common.runner;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class SessionData {
|
||||
|
||||
private Long organId; // 组织id
|
||||
private Long engineId; // 引擎id
|
||||
private Integer reqType;//请求类型
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.datax.cache;
|
||||
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface DataXCacheService {
|
||||
Map queryForChange(Map<String, String> param, long time);
|
||||
|
||||
Map queryChangeInfo();
|
||||
|
||||
void notifyCondion();
|
||||
|
||||
boolean sendChangeToWeb();
|
||||
|
||||
void initRedisSub();
|
||||
|
||||
void pushRedisSub(String channel,String message);
|
||||
|
||||
String refreshCacheInfo(String changeName);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.datax.cache;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* ClassName:DataXChange <br/>
|
||||
* Description: 日志操作类型注解. <br/>
|
||||
*/
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface DataXChange {
|
||||
|
||||
public String changeName() default "";
|
||||
|
||||
public String changeType() default "update";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.fibo.ddp.common.service.datax.cache;
|
||||
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class DataXChangeAspect {
|
||||
@Autowired
|
||||
private DataXCacheService dataXCacheService;
|
||||
|
||||
private HttpServletRequest request = null;
|
||||
|
||||
@Pointcut("@annotation(com.fibo.ddp.common.service.datax.cache.DataXChange))")
|
||||
public void controllerAspect() {
|
||||
}
|
||||
@AfterReturning(pointcut = "controllerAspect() && @annotation(dataXChange)", returning = "returnValue")
|
||||
public void doAfter(JoinPoint joinPoint,DataXChange dataXChange, Object returnValue) {
|
||||
String changeName = dataXChange.changeName();
|
||||
System.out.println(changeName);
|
||||
dataXCacheService.refreshCacheInfo(changeName);
|
||||
dataXCacheService.pushRedisSub(null,dataXChange.changeName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
55
ddp/ddp-common/ddp-service/src/main/java/com/fibo/ddp/common/service/datax/cache/Subscriber.java
vendored
Normal file
55
ddp/ddp-common/ddp-service/src/main/java/com/fibo/ddp/common/service/datax/cache/Subscriber.java
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.fibo.ddp.common.service.datax.cache;
|
||||
|
||||
import com.fibo.ddp.common.model.datax.consts.DataXCacheConst;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.JedisPubSub;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class Subscriber extends JedisPubSub {
|
||||
@Autowired
|
||||
private DataXCacheService dataXCacheService;
|
||||
|
||||
public Subscriber() {
|
||||
}
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
log.info(String.format("receive redis published message, channel %s, message %s", channel, message));
|
||||
if (DataXCacheConst.DATAX_PUBSUB_CACHE_REDIS_CHANNEL.equals(channel)){
|
||||
dataXCacheService.notifyCondion();
|
||||
dataXCacheService.sendChangeToWeb();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPMessage(String pattern, String channel, String message) {
|
||||
|
||||
log.info(String.format("receive redis published message, channel %s, message %s", channel, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSubscribe(String channel, int subscribedChannels) {
|
||||
log.info(String.format("subscribe redis channel success, channel %s, subscribedChannels %d",
|
||||
channel, subscribedChannels));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnsubscribe(String channel, int subscribedChannels) {
|
||||
log.info(String.format("unsubscribe redis channel, channel %s, subscribedChannels %d",
|
||||
channel, subscribedChannels));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPUnsubscribe(String pattern, int subscribedChannels) {
|
||||
log.info(String.format("unsubscribe redis channel, pattern %s, subscribedChannels %d",
|
||||
pattern, subscribedChannels));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPSubscribe(String pattern, int subscribedChannels) {
|
||||
log.info(String.format("subscribe redis channel success, pattern %s, subscribedChannels %d",
|
||||
pattern, subscribedChannels));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.fibo.ddp.common.service.datax.cache.impl;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fibo.ddp.common.model.datax.consts.DataXCacheConst;
|
||||
import com.fibo.ddp.common.service.datax.cache.DataXCacheService;
|
||||
import com.fibo.ddp.common.service.datax.cache.Subscriber;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import com.fibo.ddp.common.utils.util.SnowFlakUtil;
|
||||
import com.fibo.ddp.common.utils.websocket.constant.SendToWebConst;
|
||||
import com.fibo.ddp.common.utils.websocket.manager.MyWebSocketSessionManager;
|
||||
import com.fibo.ddp.common.utils.websocket.model.vo.SendToWebModel;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@Service
|
||||
public class DataXCacheServiceImpl implements DataXCacheService {
|
||||
@Autowired
|
||||
private RedisManager redisManager;
|
||||
//等待的锁
|
||||
private static final ReentrantLock lock = new ReentrantLock();
|
||||
//锁的等待队列
|
||||
private static final Condition condition = lock.newCondition();
|
||||
//监听缓存改变通知的redis单线程线程池
|
||||
private static final ExecutorService redisSingleExecutor = Executors.newSingleThreadExecutor();
|
||||
//订阅者
|
||||
@Autowired
|
||||
private Subscriber subscriber;
|
||||
|
||||
@Override
|
||||
public Map queryForChange(Map<String, String> param, long time) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<String> changeList = new ArrayList<>();
|
||||
Map<String, String> cacheMap = queryChangeInfo();
|
||||
handlerChangeList(param,cacheMap,changeList);
|
||||
//双重检查
|
||||
if (changeList.isEmpty()) {
|
||||
try {
|
||||
lock.lock();
|
||||
cacheMap = queryChangeInfo();
|
||||
handlerChangeList(param,cacheMap,changeList);
|
||||
if (changeList.isEmpty()){
|
||||
condition.await(time, TimeUnit.SECONDS);
|
||||
cacheMap = queryChangeInfo();
|
||||
handlerChangeList(param,cacheMap,changeList);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
result.put(DataXCacheConst.DATAX_CACHE_CHANGE_LIST_KEY, changeList);
|
||||
result.put(DataXCacheConst.DATAX_CACHE_INFO_KEY, cacheMap);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Map<String, String> queryChangeInfo() {
|
||||
Map<String, String> result = redisManager.hgetAll(DataXCacheConst.DATAX_WEB_CACHE_REDIS_KEY);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void handlerChangeList(Map<String,String> paramMap,Map<String,String> cacheMap,List<String> changeList){
|
||||
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
|
||||
String cacheValue = cacheMap.get(entry.getKey());
|
||||
String paramValue = entry.getValue();
|
||||
if (paramValue != null && !paramValue.equals(cacheValue)) {
|
||||
//匹配到有更新,添加到更新列表中
|
||||
changeList.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void notifyCondion(){
|
||||
try {
|
||||
lock.lock();
|
||||
condition.signalAll();
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean sendChangeToWeb() {
|
||||
Map<String, String> map = queryChangeInfo();
|
||||
MyWebSocketSessionManager.sendTextToWeb(JSON.toJSONString(new SendToWebModel(SendToWebConst.DATAX_CACHE_CHANGE,map)));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initRedisSub() {
|
||||
redisSingleExecutor.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
redisManager.subscribe(subscriber,DataXCacheConst.DATAX_PUBSUB_CACHE_REDIS_CHANNEL);
|
||||
}
|
||||
});
|
||||
for (String type : DataXCacheConst.Type.TYPE_LIST) {
|
||||
redisManager.hsetnx(DataXCacheConst.DATAX_WEB_CACHE_REDIS_KEY,type, SnowFlakUtil.snowflakeIdStr());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushRedisSub(String channel,String message) {
|
||||
if (StringUtils.isBlank(channel)){
|
||||
channel = DataXCacheConst.DATAX_PUBSUB_CACHE_REDIS_CHANNEL;
|
||||
}
|
||||
redisManager.publish(channel,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String refreshCacheInfo(String changeName) {
|
||||
redisManager.hset(DataXCacheConst.DATAX_WEB_CACHE_REDIS_KEY,changeName, SnowFlakUtil.snowflakeIdStr());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.fibo.ddp.common.service.datax.datainterface;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datainterface.InterfaceInfo;
|
||||
import com.fibo.ddp.common.model.datax.datainterface.vo.InterfaceVo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface InterfaceService extends IService<InterfaceInfo> {
|
||||
InterfaceVo getInterfaceById(Long id);
|
||||
|
||||
PageInfo queryByEntity(QueryListParam<InterfaceInfo> param);
|
||||
|
||||
InterfaceVo inserInterfaceInfo(InterfaceVo interfaceVo);
|
||||
|
||||
InterfaceVo updateInterfaceInfo(InterfaceVo interfaceVo);
|
||||
|
||||
//更新接口
|
||||
boolean updateStatus(Long[] ids, Integer status);
|
||||
|
||||
//删除接口
|
||||
Boolean deleteInterfaceInfo(InterfaceVo interfaceVo);
|
||||
|
||||
//http请求
|
||||
String getHttpResponse(InterfaceInfo interfaceInfo);
|
||||
|
||||
// runner
|
||||
InterfaceInfo getInterfaceById(Integer id);
|
||||
|
||||
/**
|
||||
* 接口请求
|
||||
* @param interfaceInfo
|
||||
* @param inputParam
|
||||
* @param callType
|
||||
* @return
|
||||
*/
|
||||
String getHttpResponse(InterfaceInfo interfaceInfo, Map<String, Object> inputParam, Integer callType);
|
||||
|
||||
/**
|
||||
* 解析接口指标
|
||||
* @param parseStr
|
||||
* @param jsonStr
|
||||
* @return
|
||||
*/
|
||||
String interfaceParseField(String parseStr, String jsonStr);
|
||||
}
|
||||
@@ -0,0 +1,345 @@
|
||||
package com.fibo.ddp.common.service.datax.datainterface.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysUserMapper;
|
||||
import com.fibo.ddp.common.dao.canal.TableEnum;
|
||||
import com.fibo.ddp.common.dao.datax.datainterface.InterfaceMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datainterface.InterfaceInfo;
|
||||
import com.fibo.ddp.common.model.datax.datainterface.vo.InterfaceVo;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datainterface.InterfaceService;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import com.fibo.ddp.common.service.redis.RedisUtils;
|
||||
import com.fibo.ddp.common.utils.constant.Constants;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.fibo.ddp.common.utils.util.runner.DictVariableUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
import org.springframework.web.client.AsyncRestTemplate;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@Service
|
||||
public class InterfaceServiceImpl extends ServiceImpl<InterfaceMapper, InterfaceInfo> implements InterfaceService {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
@Autowired
|
||||
InterfaceMapper interfaceMapper;
|
||||
|
||||
@Autowired
|
||||
SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Autowired(required = false)
|
||||
private AsyncRestTemplate asyncRestTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisManager redisManager;
|
||||
|
||||
// 业务逻辑是否使用缓存
|
||||
@Value("${switch.use.cache}")
|
||||
private String cacheSwitch;
|
||||
|
||||
@Override
|
||||
public String getHttpResponse(InterfaceInfo interfaceInfo) {
|
||||
|
||||
String result = this.getHttpResponse(interfaceInfo, new HashMap<>(), null);
|
||||
return result;
|
||||
|
||||
// HttpHeaders httpHeaders = new HttpHeaders();
|
||||
// // 设置请求头
|
||||
// httpHeaders.setContentType(MediaType.APPLICATION_JSON);
|
||||
// // 封装请求体
|
||||
// JSONObject body = JSONObject.parseObject(JSONObject.toJSONString(interfaceInfo));
|
||||
// // 封装参数和头信息
|
||||
// HttpEntity<JSONObject> httpEntity = new HttpEntity(body, httpHeaders);
|
||||
// String url = runnerUrl + "/manager/invokeInterface";
|
||||
// ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
|
||||
// return responseEntity.getBody();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteInterfaceInfo(InterfaceVo interfaceVo) {
|
||||
interfaceMapper.deleteById(interfaceVo.getId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceVo updateInterfaceInfo(InterfaceVo interfaceVo) {
|
||||
InterfaceInfo interfaceInfo = new InterfaceInfo();
|
||||
BeanUtils.copyProperties(interfaceVo, interfaceInfo);
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
//设置创建者和修改者id
|
||||
interfaceInfo.setModifier(sysUser.getUserId());
|
||||
interfaceMapper.updateById(interfaceInfo);
|
||||
return interfaceVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateStatus(Long[] ids, Integer status) {
|
||||
int updateNum = interfaceMapper.updateStatus(ids, status);
|
||||
if (updateNum > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//添加接口信息
|
||||
@Override
|
||||
public InterfaceVo inserInterfaceInfo(InterfaceVo interfaceVo) {
|
||||
//拷贝VO到Info对象
|
||||
InterfaceInfo interfaceInfo = new InterfaceInfo();
|
||||
BeanUtils.copyProperties(interfaceVo, interfaceInfo);
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
//设置创建者和修改者id
|
||||
interfaceInfo.setCreator(sysUser.getUserId());
|
||||
interfaceInfo.setModifier(sysUser.getUserId());
|
||||
interfaceInfo.setOrganId(sysUser.getOrganId());
|
||||
interfaceInfo.setStatus(1);
|
||||
//插入并获取insert后实体对象返回id
|
||||
boolean save = this.save(interfaceInfo);
|
||||
if (!save) {
|
||||
throw new ApiException(ErrorCodeEnum.INTERFACE_SAVE_ERROR.getCode(), ErrorCodeEnum.INTERFACE_SAVE_ERROR.getMessage());
|
||||
}
|
||||
return interfaceVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo queryByEntity(QueryListParam<InterfaceInfo> interfaceListParam) {
|
||||
InterfaceInfo interfaceInfo = interfaceListParam.getEntity();
|
||||
Integer pageNo = interfaceListParam.getPageNum();
|
||||
Integer pageSize = interfaceListParam.getPageSize();
|
||||
if (pageNo > 0 && pageSize > 0) {
|
||||
PageHelper.startPage(pageNo, pageSize);
|
||||
}
|
||||
Wrapper<InterfaceInfo> wrapper = createWrapper(interfaceListParam.getEntity());
|
||||
List<InterfaceInfo> interfaceList = interfaceMapper.selectList(wrapper);
|
||||
PageInfo pageInfo = new PageInfo(interfaceList);
|
||||
// 级联操作完成拼装
|
||||
List<InterfaceVo> interfaceVos = new ArrayList<>();
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
for (InterfaceInfo info : interfaceList) {
|
||||
InterfaceVo interfaceVo = new InterfaceVo();
|
||||
BeanUtils.copyProperties(info, interfaceVo);
|
||||
interfaceVo.setUsername(sysUser.getNickName());
|
||||
//设置创建者昵称
|
||||
interfaceVo.setCreatorName(sysUserMapper.findNickNameById(info.getCreator()));
|
||||
//设置修改者昵称
|
||||
interfaceVo.setModifierName(sysUserMapper.findNickNameById(info.getModifier()));
|
||||
interfaceVos.add(interfaceVo);
|
||||
}
|
||||
pageInfo.setList(interfaceVos);
|
||||
|
||||
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceVo getInterfaceById(Long id) {
|
||||
InterfaceInfo info = interfaceMapper.selectById(id);
|
||||
InterfaceVo interfaceVo = new InterfaceVo();
|
||||
BeanUtils.copyProperties(info, interfaceVo);
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
interfaceVo.setUsername(sysUser.getNickName());
|
||||
//设置创建者昵称
|
||||
interfaceVo.setCreatorName(sysUserMapper.findNickNameById(info.getCreator()));
|
||||
//设置修改者昵称
|
||||
interfaceVo.setModifierName(sysUserMapper.findNickNameById(info.getModifier()));
|
||||
return interfaceVo;
|
||||
}
|
||||
|
||||
//创建查询器
|
||||
private Wrapper<InterfaceInfo> createWrapper(InterfaceInfo query) {
|
||||
LambdaQueryWrapper<InterfaceInfo> wrapper = new LambdaQueryWrapper<>();
|
||||
if (query != null) {
|
||||
if (StringUtils.isNotBlank(query.getName())) {
|
||||
wrapper.like(InterfaceInfo::getName, query.getName());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getMethod())) {
|
||||
wrapper.eq(InterfaceInfo::getMethod, query.getMethod());
|
||||
}
|
||||
if (StringUtils.isNotBlank(query.getUrl())) {
|
||||
wrapper.eq(InterfaceInfo::getUrl, query.getUrl());
|
||||
}
|
||||
if (query.getStatus() != null) {
|
||||
wrapper.eq(InterfaceInfo::getStatus, query.getStatus());
|
||||
} else {
|
||||
wrapper.ne(InterfaceInfo::getStatus, -1);
|
||||
}
|
||||
} else {
|
||||
wrapper.ne(InterfaceInfo::getStatus, -1);
|
||||
}
|
||||
wrapper.orderByDesc(InterfaceInfo::getId);
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InterfaceInfo getInterfaceById(Integer id) {
|
||||
InterfaceInfo interfaceInfo = null;
|
||||
if(Constants.switchFlag.ON.equals(cacheSwitch)){
|
||||
String key = RedisUtils.getPrimaryKey(TableEnum.T_FIELD_INTERFACE, id);
|
||||
interfaceInfo = redisManager.getByPrimaryKey(key, InterfaceInfo.class);
|
||||
} else {
|
||||
interfaceInfo = interfaceMapper.selectById(id);
|
||||
}
|
||||
return interfaceInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHttpResponse(InterfaceInfo interfaceInfo, Map<String, Object> inputParam, Integer callType) {
|
||||
if(callType == null){
|
||||
callType = 2; // 1为异步,2为同步
|
||||
}
|
||||
|
||||
String url = interfaceInfo.getUrl();
|
||||
ResponseEntity<String> responseEntity = null;
|
||||
ListenableFuture<ResponseEntity<String>> listenableFuture = null;
|
||||
String bindParam = interfaceInfo.getBindParam();
|
||||
if (StringUtils.isNotBlank(bindParam)){
|
||||
JSONObject param = JSON.parseObject(bindParam);
|
||||
JSONArray dictVariable = param.getJSONArray("dictVariable");
|
||||
for (int i = 0; i < dictVariable.size(); i++) {
|
||||
JSONObject jsonObject = dictVariable.getJSONObject(i);
|
||||
Object value = DictVariableUtils.getValueFromJsonObject(jsonObject);
|
||||
inputParam.put(jsonObject.getString("key"),value);
|
||||
}
|
||||
JSONArray variable = param.getJSONArray("variable");
|
||||
for (int i = 0; i < variable.size(); i++) {
|
||||
JSONObject jsonObject = variable.getJSONObject(i);
|
||||
if (!inputParam.containsKey(jsonObject.getString("key"))){
|
||||
inputParam.put(jsonObject.getString("key"),jsonObject.get("value"));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// 请求参数中的变量赋值
|
||||
String requestBody = setRequestBodyParams(interfaceInfo.getRequestBody(), inputParam);
|
||||
if(HttpMethod.POST.name().equals(interfaceInfo.getMethod())){
|
||||
HttpHeaders httpHeaders = new HttpHeaders();
|
||||
// 设置请求头
|
||||
httpHeaders.setAll(JSONObject.parseObject(interfaceInfo.getRequestHeaders(), Map.class));
|
||||
// 封装请求体
|
||||
JSONObject body = JSONObject.parseObject(requestBody);
|
||||
// 封装参数和头信息
|
||||
HttpEntity<JSONObject> httpEntity = new HttpEntity(body, httpHeaders);
|
||||
// 发送请求
|
||||
if(callType == 2){
|
||||
responseEntity = restTemplate.postForEntity(url, httpEntity, String.class);
|
||||
} else {
|
||||
listenableFuture = asyncRestTemplate.postForEntity(url, httpEntity, String.class);
|
||||
}
|
||||
|
||||
} else if(HttpMethod.GET.name().equals(interfaceInfo.getMethod())){
|
||||
// 封装uri地址路径变量
|
||||
Map<String, Object> uriVariables = new HashMap<>();
|
||||
if(StringUtils.isNotBlank(requestBody)){
|
||||
uriVariables = JSONObject.parseObject(requestBody, Map.class);
|
||||
}
|
||||
// 发送请求
|
||||
if(callType == 2){
|
||||
responseEntity = restTemplate.getForEntity(url, String.class, uriVariables);
|
||||
} else {
|
||||
listenableFuture = asyncRestTemplate.getForEntity(url, String.class, uriVariables);
|
||||
}
|
||||
}
|
||||
|
||||
String result = null;
|
||||
if(responseEntity != null && HttpStatus.OK.equals(responseEntity.getStatusCode())){
|
||||
result = responseEntity.getBody();
|
||||
}
|
||||
|
||||
if(listenableFuture != null){
|
||||
listenableFuture.addCallback(new ListenableFutureCallback<ResponseEntity<String>>() {
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
logger.info("异步接口调用失败", throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(ResponseEntity<String> stringResponseEntity) {
|
||||
String result = stringResponseEntity.getBody();
|
||||
logger.info("异步接口调用成功,result:{}", result);
|
||||
}
|
||||
});
|
||||
}
|
||||
logger.info("【请求接口源完成】 url:{},requestMethod:{}, request:{}, response:{}",url,interfaceInfo.getMethod(),requestBody,result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String setRequestBodyParams(String requestBody, Map<String, Object> inputParam){
|
||||
if(StringUtils.isBlank(requestBody) || inputParam == null){
|
||||
return "";
|
||||
}
|
||||
// 添加动态参数
|
||||
Pattern pattern = Pattern.compile("\\{[a-zA-Z0-9_\u4e00-\u9fa5()()-]+\\}");
|
||||
Matcher matcher = pattern.matcher(requestBody);
|
||||
while (matcher.find()) {
|
||||
String matchStr = matcher.group(0);
|
||||
String param = matchStr.replace("{", "").replace("}", "");
|
||||
// 动态参数从变量池获取
|
||||
requestBody = requestBody.replace(matchStr, String.valueOf(inputParam.get(param)));
|
||||
}
|
||||
return requestBody;
|
||||
}
|
||||
|
||||
@Override //解析接口指标
|
||||
public String interfaceParseField(String parseStr, String jsonStr) {
|
||||
JSONObject json = null;
|
||||
try {
|
||||
json = JSONObject.parseObject(jsonStr);
|
||||
} catch (Exception e) {
|
||||
JSONArray jsonArray = JSONArray.parseArray(jsonStr);
|
||||
json = jsonArray.getJSONObject(0);
|
||||
}
|
||||
|
||||
if(parseStr.contains(".[]")){
|
||||
parseStr = parseStr.replace(".[]", "[]");
|
||||
}
|
||||
String[] strArr = parseStr.split("\\.");
|
||||
for(int i = 0; i < strArr.length - 1; i++){
|
||||
if(strArr[i].contains("[]")){
|
||||
strArr[i] = strArr[i].replace("[]", "");
|
||||
JSONArray jsonArray = json.getJSONArray(strArr[i]);
|
||||
json = jsonArray.getJSONObject(0);
|
||||
}else{
|
||||
json = json.getJSONObject(strArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
String value = null;
|
||||
if(json != null){
|
||||
value = json.getString(strArr[strArr.length - 1]);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.fibo.ddp.common.service.datax.datamanage;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldCall;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldCallLog;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.request.FieldCallParam;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (FieldCallLog)表服务接口
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-08 14:18:29
|
||||
*/
|
||||
public interface FieldCallLogService extends IService<FieldCallLog> {
|
||||
|
||||
PageInfo queryFieldCallList(QueryListParam<FieldCallParam> param);
|
||||
|
||||
PageInfo queryFieldCallLogList(QueryListParam<FieldCallParam> param);
|
||||
|
||||
List<FieldCall> queryFieldCallCountList(FieldCallParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.fibo.ddp.common.service.datax.datamanage;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.UpdateFolderParam;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.Field;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FieldService extends IService<Field> {
|
||||
/**
|
||||
* createField:(插入新字段). <br/>
|
||||
*
|
||||
* @param fieldVo 字段实体类
|
||||
* @return 字段插入成功
|
||||
*/
|
||||
public boolean createField(Field fieldVo, Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* isExists:(查找字段是否存在). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 存在的记录条数
|
||||
*/
|
||||
public int isExists(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* isExistsFieldType:(查找字段类型是否存在). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 存在的记录条数
|
||||
*/
|
||||
public int isExistsFieldType(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* updateField:(修改字段内容). <br/>
|
||||
*
|
||||
* @param fieldVo 字段实体类
|
||||
* @return 更新成功
|
||||
*/
|
||||
public boolean updateField(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* findByFieldType:(按照字段类型查找字段列表). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 更新成功
|
||||
*/
|
||||
public List<Field> findByFieldType(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* findByFieldId:(根据Id查找字段). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 字段列表
|
||||
*/
|
||||
public Field findByFieldId(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* findByUser:(查找用户可用字段). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 字段类型列表
|
||||
*/
|
||||
public List<Field> findByUser(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* updateStatus:(单个或批量更新用户字段关系). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 插入成功
|
||||
*/
|
||||
public Map<String, Object> updateStatus(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* checkField:(公共方法:检查字段是否被引用). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 结果集合
|
||||
*/
|
||||
public Map<String, Object> checkField(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* getSourceField:(公共方法:检查字段的所有构成字段). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return
|
||||
*/
|
||||
public String getSourceField(String fieldIds, String fieldId);
|
||||
|
||||
/**
|
||||
* importExcel:(导入excel). <br/>
|
||||
*
|
||||
* @param url
|
||||
* @param paramMap 参数集合
|
||||
* @return 导入成功
|
||||
*/
|
||||
Map<String, Object> importExcel(String url, Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* getFieldList:(获取组织的所有字段). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return
|
||||
*/
|
||||
public List<Field> getFieldList(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* bindEngineField:(根据传入的engineId和字段id找到一连串的字段并绑定关系). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 是否创建成功
|
||||
*/
|
||||
public boolean bindEngineField(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* getField:(根据引擎和字段中文名找出引擎所用字段对象). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 字段对象
|
||||
*/
|
||||
public String getField(String fieldIds, String usedFieldId, String engineId);
|
||||
|
||||
/**
|
||||
* 查找某字段被引用的字段id并拼成逗号分隔的字符串
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAllFieldTypeId(String ids, String pid, String engineId);
|
||||
|
||||
/**
|
||||
* 查找某字段类型所有的<父类型>拼成逗号分隔的字符串
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getAllParentFieldTypeId(String ids, String id, String engineId);
|
||||
|
||||
int updateFieldFolder(UpdateFolderParam param);
|
||||
|
||||
String getFieldEnById(Long id);
|
||||
|
||||
List<Field> queryByIds(Collection<Long> ids);
|
||||
|
||||
List<Field> queryByEns(Collection<String> ens);
|
||||
|
||||
List<Field> queryByOrganAndCns(Collection<String> cns, Long organId);
|
||||
|
||||
void sqlFieldCheck(Map map);
|
||||
|
||||
int countFieldByOrganId(Long organId);
|
||||
|
||||
List<Map<String, Object>> countFieldGroupByType(Long organId);
|
||||
|
||||
// runner
|
||||
Field queryById(Long id);
|
||||
|
||||
List<Field> findFieldByIdsbyorganId(Long organId, List<Long> ids);
|
||||
|
||||
List<Field> selectFieldListByEns(List<String> fieldEnList);
|
||||
|
||||
Field findByFieldEnbyorganId(Long organId, String fieldEn);
|
||||
|
||||
Field findByFieldCnbyorganId(Long organId, String fieldCn);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.fibo.ddp.common.service.datax.datamanage;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldType;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.request.FieldTreeParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FieldTypeService extends IService<FieldType> {
|
||||
|
||||
/**
|
||||
* getFieldTypeList:(查找用户的字段类型列表). 支持查询组织通用字段类型、子类型 支持查询引擎自定义字段类型、子类型 <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 字段类型列表
|
||||
*/
|
||||
public List<FieldType> getFieldTypeList(Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* createFieldType:(新增字段类型). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 插入成功
|
||||
*/
|
||||
public boolean createFieldType(FieldType fieldTypeVo, Map<String, Object> paramMap);
|
||||
|
||||
/**
|
||||
* updateFieldType:(更新字段类型名). <br/>
|
||||
*
|
||||
* @param paramMap 参数集合
|
||||
* @return 更新成功
|
||||
*/
|
||||
public boolean updateFieldType(FieldTreeParam param);
|
||||
|
||||
|
||||
List<FieldType> getTreeList(FieldTreeParam param);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.fibo.ddp.common.service.datax.datamanage.imp;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.datax.datamanage.FieldCallLogMapper;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldCall;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldCallLog;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.request.FieldCallParam;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datamanage.FieldCallLogService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (FieldCallLog)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-08 14:18:29
|
||||
*/
|
||||
@Service("fieldCallLogService")
|
||||
public class FieldCallLogServiceImpl extends ServiceImpl<FieldCallLogMapper, FieldCallLog> implements FieldCallLogService {
|
||||
@Resource
|
||||
private FieldCallLogMapper fieldCallLogMapper;
|
||||
|
||||
@Override
|
||||
public PageInfo queryFieldCallList(QueryListParam<FieldCallParam> param) {
|
||||
if (param.getPageNum() > 0 && param.getPageSize() > 0) {
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
setOrganId(param.getEntity());
|
||||
List<FieldCall> fieldCallList = fieldCallLogMapper.findFieldCallList(param.getEntity());
|
||||
PageInfo<FieldCall> pageInfo = new PageInfo<>(fieldCallList);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo queryFieldCallLogList(QueryListParam<FieldCallParam> param) {
|
||||
if (param.getPageNum() > 0 && param.getPageSize() > 0) {
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
setOrganId(param.getEntity());
|
||||
List<FieldCallLog> fieldCallLogs = fieldCallLogMapper.findFieldCallLogList(param.getEntity());
|
||||
PageInfo<FieldCallLog> pageInfo = new PageInfo<>(fieldCallLogs);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldCall> queryFieldCallCountList(FieldCallParam param) {
|
||||
setOrganId(param);
|
||||
List<FieldCall> fieldCallCountList = fieldCallLogMapper.findFieldCallCountList(param);
|
||||
return fieldCallCountList;
|
||||
}
|
||||
|
||||
private void setOrganId(FieldCallParam param) {
|
||||
Long organId = SessionManager.getLoginAccount().getOrganId();
|
||||
param.setOrganId(organId);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
package com.fibo.ddp.common.service.datax.datamanage.imp;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.datax.datamanage.FieldTypeMapper;
|
||||
import com.fibo.ddp.common.dao.datax.datamanage.FieldTypeUserMapper;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.FieldType;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.request.FieldTreeParam;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datamanage.FieldTypeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class FieldTypeServiceImp extends ServiceImpl<FieldTypeMapper, FieldType> implements FieldTypeService {
|
||||
@Autowired
|
||||
private FieldTypeMapper fieldTypeMapper;
|
||||
@Autowired
|
||||
private FieldTypeUserMapper fieldTypeUserMapper;
|
||||
|
||||
@Override
|
||||
public List<FieldType> getFieldTypeList(Map<String, Object> paramMap) {
|
||||
return fieldTypeMapper.getFieldTypeList(paramMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createFieldType(FieldType fieldTypeVo,
|
||||
Map<String, Object> paramMap) {
|
||||
// 检查字段类型是否存在
|
||||
if (fieldTypeMapper.createFieldType(fieldTypeVo)) {
|
||||
paramMap.put("fieldTypeId", fieldTypeVo.getId());
|
||||
if (fieldTypeUserMapper.createFieldTypeUserRel(paramMap)) {
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateFieldType(FieldTreeParam param) {
|
||||
param.setOrganId(SessionManager.getLoginAccount().getOrganId());
|
||||
param.setUserId(SessionManager.getLoginAccount().getUserId());
|
||||
fieldTypeMapper.updateFieldType(param);
|
||||
fieldTypeUserMapper.updateFieldTypeUserRel(param);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FieldType> getTreeList(FieldTreeParam param) {
|
||||
param.setOrganId(SessionManager.getLoginAccount().getOrganId());
|
||||
param.setUserId(SessionManager.getLoginAccount().getUserId());
|
||||
List<FieldType> fieldTypes = fieldTypeMapper.selectFieldTypeList(param);
|
||||
List<FieldType> collect = fieldTypes.stream().filter(fieldType -> fieldType.getParentId() == 0).collect(Collectors.toList());
|
||||
for (FieldType fieldType : collect) {
|
||||
fieldType.setChildren(this.assembleTreeList(fieldTypes, fieldType));
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
||||
private FieldType[] assembleTreeList(List<FieldType> fieldTypes, FieldType root) {
|
||||
List<FieldType> children = new ArrayList();
|
||||
for (FieldType fieldType : fieldTypes) {
|
||||
if (fieldType.getParentId().equals(root.getId())) {
|
||||
fieldType.setChildren(this.assembleTreeList(fieldTypes, fieldType));
|
||||
children.add(fieldType);
|
||||
}
|
||||
}
|
||||
if (children.size() == 0) {
|
||||
return new FieldType[0];
|
||||
}
|
||||
return children.toArray(new FieldType[children.size()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.fibo.ddp.common.service.datax.datasource;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.datax.datasource.DataSource;
|
||||
import com.fibo.ddp.common.model.datax.datasource.request.DataSourceListParam;
|
||||
import com.fibo.ddp.common.model.datax.datasource.vo.DataSourceVo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface DataSourceService extends IService<DataSource> {
|
||||
|
||||
Integer saveDataSource(DataSourceVo dataSource);
|
||||
|
||||
Integer updateDataSource(DataSourceVo dataSource);
|
||||
|
||||
DataSourceVo getDataSourceById(Integer id);
|
||||
|
||||
Map<String, Object> getDataSourceList(DataSourceListParam param);
|
||||
|
||||
Integer deleteDataSourceById(Integer id);
|
||||
|
||||
// runner
|
||||
DataSource getDataSourceByIdRunner(Integer id);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.fibo.ddp.common.service.datax.datasource;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datasource.MqSource;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (MqSource)表服务接口
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-20 13:31:51
|
||||
*/
|
||||
public interface MqSourceService extends IService<MqSource> {
|
||||
|
||||
MqSource queryById(Long id);
|
||||
|
||||
PageInfo queryList(QueryListParam<MqSource> param);
|
||||
|
||||
MqSource add(MqSource param);
|
||||
|
||||
MqSource update(MqSource param);
|
||||
|
||||
boolean updateStatus(List<Long> ids, Integer status);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package com.fibo.ddp.common.service.datax.datasource.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.authx.system.SysUserMapper;
|
||||
import com.fibo.ddp.common.dao.canal.TableEnum;
|
||||
import com.fibo.ddp.common.dao.datax.datasource.DataSourceMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.datax.datasource.DataSource;
|
||||
import com.fibo.ddp.common.model.datax.datasource.request.DataSourceListParam;
|
||||
import com.fibo.ddp.common.model.datax.datasource.vo.DataSourceVo;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datasource.DataSourceService;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import com.fibo.ddp.common.service.redis.RedisUtils;
|
||||
import com.fibo.ddp.common.utils.constant.Constants;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class DataSourceServiceImpl extends ServiceImpl<DataSourceMapper, DataSource> implements DataSourceService {
|
||||
|
||||
@Resource
|
||||
public DataSourceMapper dataSourceMapper;
|
||||
|
||||
@Resource
|
||||
public SysUserMapper sysUserMapper;
|
||||
|
||||
@Autowired
|
||||
private RedisManager redisManager;
|
||||
|
||||
// 业务逻辑是否使用缓存
|
||||
@Value("${switch.use.cache}")
|
||||
private String cacheSwitch;
|
||||
|
||||
@Override
|
||||
public Integer saveDataSource(DataSourceVo dataSourceVo) {
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
Long organId = sysUser.getOrganId();
|
||||
DataSource dataSource = new DataSource();
|
||||
BeanUtils.copyProperties(dataSourceVo, dataSource);
|
||||
dataSource.setCreator(sysUser.getUserId());
|
||||
dataSource.setModifier(sysUser.getUserId());
|
||||
dataSource.setOrganId(organId);
|
||||
return dataSourceMapper.insert(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer updateDataSource(DataSourceVo dataSourceVo) {
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
DataSource dataSource = new DataSource();
|
||||
BeanUtils.copyProperties(dataSourceVo, dataSource);
|
||||
dataSource.setModifier(sysUser.getUserId());
|
||||
return dataSourceMapper.updateById(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSourceVo getDataSourceById(Integer id) {
|
||||
DataSource dataSource = dataSourceMapper.selectById(id);
|
||||
DataSourceVo dataSourceVo = new DataSourceVo();
|
||||
BeanUtils.copyProperties(dataSource, dataSourceVo);
|
||||
SysUser creator = sysUserMapper.findUserById(dataSource.getCreator());
|
||||
SysUser modifier = sysUserMapper.findUserById(dataSource.getModifier());
|
||||
dataSourceVo.setCreatorName(creator.getAccount());
|
||||
dataSourceVo.setModifierName(modifier.getAccount());
|
||||
return dataSourceVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDataSourceList(DataSourceListParam param) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
LambdaQueryWrapper<DataSource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DataSource::getStatus, 1);
|
||||
if(param.getTypeList()!=null&&!param.getTypeList().isEmpty()){
|
||||
queryWrapper.in(DataSource::getType, param.getTypeList());
|
||||
}
|
||||
queryWrapper.orderByDesc(DataSource::getUpdateTime);
|
||||
if (param.getPageNo()>0 && param.getPageSize()>0){
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
}
|
||||
List<DataSource> dataSourceList = dataSourceMapper.selectList(queryWrapper);
|
||||
PageInfo pageInfo = new PageInfo<>(dataSourceList);
|
||||
pageInfo.setList(null);
|
||||
result.put("pager", pageInfo);
|
||||
|
||||
List<DataSourceVo> dataSourceVoList = new ArrayList<>();
|
||||
for (DataSource dataSource : dataSourceList) {
|
||||
DataSourceVo dataSourceVo = new DataSourceVo();
|
||||
BeanUtils.copyProperties(dataSource, dataSourceVo);
|
||||
SysUser creator = sysUserMapper.findUserById(dataSource.getCreator());
|
||||
SysUser modifier = sysUserMapper.findUserById(dataSource.getModifier());
|
||||
dataSourceVo.setCreatorName(creator.getAccount());
|
||||
dataSourceVo.setModifierName(modifier.getAccount());
|
||||
dataSourceVoList.add(dataSourceVo);
|
||||
}
|
||||
result.put("data", dataSourceVoList);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer deleteDataSourceById(Integer id) {
|
||||
DataSource dataSource = new DataSource();
|
||||
dataSource.setId(id);
|
||||
dataSource.setStatus(0);
|
||||
return dataSourceMapper.updateById(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getDataSourceByIdRunner(Integer id) {
|
||||
DataSource dataSource = null;
|
||||
if(Constants.switchFlag.ON.equals(cacheSwitch)){
|
||||
String key = RedisUtils.getPrimaryKey(TableEnum.T_FIELD_DATA_SOURCE, id);
|
||||
dataSource = redisManager.getByPrimaryKey(key, DataSource.class);
|
||||
} else {
|
||||
dataSource = this.getById(id);
|
||||
}
|
||||
return dataSource;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.fibo.ddp.common.service.datax.datasource.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.datax.datasource.MqSourceMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.datax.datasource.MqSource;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datasource.MqSourceService;
|
||||
import com.fibo.ddp.common.utils.constant.StatusConst;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (MqSource)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-20 13:31:51
|
||||
*/
|
||||
@Service("fieldMqSourceService")
|
||||
public class MqSourceServiceImpl extends ServiceImpl<MqSourceMapper, MqSource> implements MqSourceService {
|
||||
@Resource
|
||||
private MqSourceMapper mqSourceMapper;
|
||||
|
||||
@Override
|
||||
public MqSource queryById(Long id) {
|
||||
if (id == null || id < 1) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "参数异常:id错误");
|
||||
}
|
||||
MqSource result = this.getById(id);
|
||||
if (result == null || result.getStatus() == -1) {
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageInfo queryList(QueryListParam<MqSource> param) {
|
||||
if (QueryListParam.checkIsPage(param)) {
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
LambdaQueryWrapper<MqSource> wrapper = createWrapper(param.getEntity());
|
||||
PageInfo<MqSource> pageInfo = new PageInfo<>(this.list(wrapper));
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MqSource add(MqSource param) {
|
||||
if (param == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "参数错误,添加消息队列源失败");
|
||||
}
|
||||
init(param);
|
||||
param.setCreator(param.getModifier());
|
||||
boolean save = this.save(param);
|
||||
MqSource result = null;
|
||||
if (save) {
|
||||
result = this.queryById(param.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MqSource update(MqSource param) {
|
||||
if (param == null || param.getId() == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "参数错误:修改消息队列源失败");
|
||||
}
|
||||
init(param);
|
||||
boolean save = this.updateById(param);
|
||||
MqSource result = null;
|
||||
if (save) {
|
||||
result = this.queryById(param.getId());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(List<Long> ids, Integer status) {
|
||||
LambdaUpdateWrapper<MqSource> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.in(MqSource::getId, ids);
|
||||
MqSource mqSource = new MqSource();
|
||||
mqSource.setStatus(status);
|
||||
mqSource.setModifier(SessionManager.getLoginAccount().getUserId());
|
||||
return this.update(mqSource, wrapper);
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<MqSource> createWrapper(MqSource entity) {
|
||||
LambdaQueryWrapper<MqSource> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(MqSource::getOrganId, SessionManager.getLoginAccount().getOrganId());
|
||||
wrapper.orderByDesc(MqSource::getId);
|
||||
if (entity == null) {
|
||||
wrapper.ne(MqSource::getStatus, StatusConst.STATUS_DELETE);
|
||||
return wrapper;
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getType())) {
|
||||
wrapper.eq(MqSource::getType, entity.getType());
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getName())) {
|
||||
wrapper.like(MqSource::getName, entity.getName());
|
||||
}
|
||||
if (entity.getStatus() != null) {
|
||||
wrapper.eq(MqSource::getStatus, entity.getStatus());
|
||||
} else {
|
||||
wrapper.ne(MqSource::getStatus, StatusConst.STATUS_DELETE);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
private void init(MqSource mqSource) {
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
mqSource.setStatus(1);
|
||||
mqSource.setOrganId(loginAccount.getOrganId());
|
||||
mqSource.setModifier(loginAccount.getUserId());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.fibo.ddp.common.service.datax.home;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface HomeService {
|
||||
|
||||
Map<String, Object> getIndexInfo();
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.fibo.ddp.common.service.datax.home.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.datax.datainterface.InterfaceInfo;
|
||||
import com.fibo.ddp.common.model.datax.datasource.DataSource;
|
||||
import com.fibo.ddp.common.model.monitor.logger.Logger;
|
||||
import com.fibo.ddp.common.service.cignacmb.BusinessEventLogService;
|
||||
import com.fibo.ddp.common.service.cignacmb.ITBusinessRuleRelService;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.datax.datamanage.FieldService;
|
||||
import com.fibo.ddp.common.service.datax.datainterface.InterfaceService;
|
||||
import com.fibo.ddp.common.service.datax.datasource.DataSourceService;
|
||||
import com.fibo.ddp.common.service.datax.home.HomeService;
|
||||
import com.fibo.ddp.common.service.monitor.logger.LogService;
|
||||
import com.fibo.ddp.common.service.strategyx.collectionrule.ListOperationService;
|
||||
import com.fibo.ddp.common.utils.util.DataHelp;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("dataXService")
|
||||
public class DataXHomeServiceImpl implements HomeService {
|
||||
@Autowired
|
||||
LogService logService;
|
||||
@Autowired
|
||||
BusinessEventLogService businessEventLogService;
|
||||
@Autowired
|
||||
ListOperationService listOperationService;
|
||||
@Autowired
|
||||
ITBusinessRuleRelService itBusinessRuleRelService;
|
||||
@Autowired
|
||||
FieldService fieldService;
|
||||
@Autowired
|
||||
DataSourceService dataSourceService;
|
||||
@Autowired
|
||||
InterfaceService interfaceService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getIndexInfo() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
Long organId = sysUser.getOrganId();
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("organId", organId);
|
||||
|
||||
|
||||
// 查询首页上次登录时间
|
||||
List<Date> lastLoginTimeList = logService.getLastLoginInfo(sysUser.getUserId());
|
||||
Date lastLoginTime = lastLoginTimeList.size() > 1 ? lastLoginTimeList.get(1) : lastLoginTimeList.get(0);
|
||||
|
||||
// 查询首页当天活动日志
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("organId", organId);
|
||||
param.put("startDate", DataHelp.getDay());
|
||||
param.put("endDate", DataHelp.getNowDate());
|
||||
PageHelper.startPage(1, 6);
|
||||
List<Logger> logList = logService.getLogList(param);
|
||||
logList = logList.stream().filter(item -> item.getOpType() != null && item.getOpType().startsWith("log")).collect(Collectors.toList());
|
||||
map.put("lastLoginTime", lastLoginTime);
|
||||
map.put("logList", logList);
|
||||
map.put("databaseCount", getDataBaseCount(organId));
|
||||
map.put("interfaceCount", getInterfaceCount(organId));
|
||||
map.put("fieldTypeGroup", getFieldTypeGroup(organId));
|
||||
map.put("fieldCount", getFieldNum(organId));
|
||||
return map;
|
||||
}
|
||||
|
||||
private int getInterfaceCount(Long organId) {
|
||||
LambdaQueryWrapper<InterfaceInfo> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(InterfaceInfo::getOrganId, organId);
|
||||
wrapper.ne(InterfaceInfo::getStatus, -1);
|
||||
return interfaceService.count(wrapper);
|
||||
}
|
||||
|
||||
private int getDataBaseCount(Long organId) {
|
||||
LambdaQueryWrapper<DataSource> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(DataSource::getOrganId, organId);
|
||||
wrapper.ne(DataSource::getStatus, -1);
|
||||
return dataSourceService.count(wrapper);
|
||||
}
|
||||
|
||||
private int getFieldNum(Long organId) {
|
||||
return fieldService.countFieldByOrganId(organId);
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> getFieldTypeGroup(Long organId) {
|
||||
return fieldService.countFieldGroupByType(organId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.fibo.ddp.common.service.datax.runner;
|
||||
|
||||
import com.fibo.ddp.common.model.datax.datamanage.Field;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CommonService {
|
||||
|
||||
boolean getFieldByIds(List<Long> ids, Map<String, Object> inputParam);
|
||||
|
||||
/**
|
||||
* 获取引擎节点所需的指标
|
||||
* @param fields
|
||||
* @param inputParam
|
||||
* @return
|
||||
*/
|
||||
boolean getEngineField(List<Field> fields, Map<String, Object> inputParam);
|
||||
|
||||
Map<String,Object> getFields(List<Field> fields, Map<String, Object> inputParam);
|
||||
|
||||
/**
|
||||
* 获取衍生指标
|
||||
* @param inputParam
|
||||
*/
|
||||
void getFieldResult(Map<String, Object> inputParam);
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.fibo.ddp.common.service.datax.runner;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.datax.datasource.DataSource;
|
||||
import com.fibo.ddp.common.service.datax.runner.redis.RedisKSessionPool;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DataBaseReSource {
|
||||
|
||||
private static RedisKSessionPool redisKSessionPool;
|
||||
|
||||
private static RedisManager redisManager;
|
||||
|
||||
@Autowired
|
||||
public DataBaseReSource(RedisKSessionPool redisKSessionPool, RedisManager redisManager) {
|
||||
DataBaseReSource.redisKSessionPool = redisKSessionPool;
|
||||
DataBaseReSource.redisManager = redisManager;
|
||||
}
|
||||
|
||||
public static final DruidDataSource getDataSource(String driverClassName, String url , String username, String passWord){
|
||||
DruidDataSource dynamicDataSource = new DruidDataSource();
|
||||
dynamicDataSource.setDriverClassName(driverClassName);
|
||||
dynamicDataSource.setUrl(url);
|
||||
dynamicDataSource.setUsername(username);
|
||||
dynamicDataSource.setPassword(passWord);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
|
||||
public static final class MySql {
|
||||
public static final String type = "MySQL";
|
||||
public static final String driverClassName="com.mysql.cj.jdbc.Driver";
|
||||
public static final String urlPrefix="jdbc:mysql://";
|
||||
public static final String urlPostfix ="?characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull";
|
||||
public static DruidDataSource getDataSource( DataSource dataSource){
|
||||
String url = urlPrefix + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDbName() + urlPostfix;
|
||||
DruidDataSource dynamicDataSource = DataBaseReSource.getDataSource(driverClassName, url, dataSource.getUserName(), dataSource.getPassword());
|
||||
return dynamicDataSource;
|
||||
}
|
||||
}
|
||||
public static final class Oracle {
|
||||
public static final String type = "Oracle";
|
||||
public static final String driverClassName="oracle.jdbc.driver.OracleDriver";
|
||||
public static final String urlPrefix="jdbc:oracle:thin:@";
|
||||
public static DruidDataSource getDataSource( DataSource dataSource){
|
||||
String url = urlPrefix + dataSource.getHost() + ":" + dataSource.getPort() + ":" + dataSource.getDbName();
|
||||
String username = dataSource.getUserName();
|
||||
String passWord = dataSource.getPassword();
|
||||
DruidDataSource dynamicDataSource = DataBaseReSource.getDataSource(driverClassName, url, username, passWord);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
public static final class SqlServer {
|
||||
public static final String type = "SqlServer";
|
||||
public static final String driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
|
||||
public static final String urlPrefix="jdbc:sqlserver://";
|
||||
public static final String DBNamePrefix=";DatabaseName=";
|
||||
public static DruidDataSource getDataSource( DataSource dataSource){
|
||||
String url = urlPrefix + dataSource.getHost() + ":" + dataSource.getPort() + DBNamePrefix + dataSource.getDbName();
|
||||
String username = dataSource.getUserName();
|
||||
String passWord = dataSource.getPassword();
|
||||
DruidDataSource dynamicDataSource = DataBaseReSource.getDataSource(driverClassName, url, username, passWord);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
|
||||
}
|
||||
public static final class DB2 {
|
||||
public static final String type = "DB2";
|
||||
public static final String driverClassName="com.ibm.db2.jcc.DB2Driver";
|
||||
public static final String urlPrefix="jdbc:db2://";
|
||||
public static DruidDataSource getDataSource( DataSource dataSource){
|
||||
String url = urlPrefix + dataSource.getHost() + ":" + dataSource.getPort() + "/" + dataSource.getDbName();
|
||||
String username = dataSource.getUserName();
|
||||
String passWord = dataSource.getPassword();
|
||||
DruidDataSource dynamicDataSource = DataBaseReSource.getDataSource(driverClassName, url, username, passWord);
|
||||
return dynamicDataSource;
|
||||
}
|
||||
}
|
||||
public static final class Redis {
|
||||
public static final String type = "Redis";
|
||||
|
||||
public static Jedis getDataSource(DataSource dataSource,String keyMd5){
|
||||
Jedis jedis = null;
|
||||
redisManager.set(keyMd5, JSON.toJSONString(dataSource), 120);
|
||||
try {
|
||||
jedis = redisKSessionPool.borrowObject(keyMd5);
|
||||
} catch (Exception e) {
|
||||
log.error("获取jedis连接失败,Md5Key:{},dataSource:{}",keyMd5,dataSource);
|
||||
throw new ApiException(ErrorCodeEnum.GET_REDIS_SOURCE_ERROR.getCode(), ErrorCodeEnum.GET_REDIS_SOURCE_ERROR.getMessage());
|
||||
}
|
||||
return jedis;
|
||||
}
|
||||
public static void closeJedis(Jedis jedis){
|
||||
//关闭链接
|
||||
try {
|
||||
jedis.close();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public static final class HiveConst{
|
||||
public static final String type = "Hive";
|
||||
public static final String driverClassName="";
|
||||
|
||||
}
|
||||
public static final class SparkConst{
|
||||
public static final String type = "HSpark";
|
||||
public static final String driverClassName="";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,656 @@
|
||||
package com.fibo.ddp.common.service.datax.runner;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.datax.datamanage.Field;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineNode;
|
||||
import com.fibo.ddp.common.model.enginex.runner.ExpressionParam;
|
||||
import com.fibo.ddp.common.service.datax.datamanage.FieldService;
|
||||
import com.fibo.ddp.common.utils.common.MD5;
|
||||
import com.fibo.ddp.common.utils.constant.runner.ParamTypeConst;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.fibo.ddp.common.utils.util.runner.JevalUtil;
|
||||
import com.fibo.ddp.common.utils.util.runner.StrUtils;
|
||||
import com.fibo.ddp.common.utils.util.runner.jeval.EvaluationException;
|
||||
import com.fibo.ddp.common.utils.util.runner.jeval.Evaluator;
|
||||
import com.fibo.ddp.common.utils.util.runner.jeval.function.math.Groovy;
|
||||
import com.fibo.ddp.common.utils.util.runner.jeval.function.math.Python;
|
||||
import com.fibo.ddp.common.utils.util.strategyx.DataCleanUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
//底层执行的工具类
|
||||
@Component
|
||||
public class ExecuteUtils {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExecuteUtils.class);
|
||||
private static Groovy groovy;
|
||||
private static CommonService commonService;
|
||||
private static Python python;
|
||||
private static FieldService fieldService;
|
||||
|
||||
@Autowired
|
||||
public ExecuteUtils(Groovy groovy, CommonService commonService, Python python, FieldService fieldService) {
|
||||
ExecuteUtils.groovy = groovy;
|
||||
ExecuteUtils.commonService = commonService;
|
||||
ExecuteUtils.python = python;
|
||||
ExecuteUtils.fieldService = fieldService;
|
||||
}
|
||||
|
||||
//获取基本单元的执行结果
|
||||
public final static boolean getExpressionResult(ExpressionParam expressionParam, Map<String, Object> params) {
|
||||
//如果是规则的条件的话,判断是否为叶子节点,如果不是则直接返回false
|
||||
if (expressionParam.getConditionType() != null && expressionParam.getConditionType() != 2) {
|
||||
return false;
|
||||
}
|
||||
String operator = expressionParam.getOperator();
|
||||
|
||||
//获取第二个参数的类型
|
||||
Integer variableType = expressionParam.getVariableType();
|
||||
//给每个参数取值
|
||||
Object paramOne = getValueByKey(2, params, expressionParam.getFieldEn(), null);
|
||||
//默认为常量
|
||||
Object paramTwo = getValueByKey(variableType, params, expressionParam.getFieldValue(), null);
|
||||
|
||||
if (paramOne == null || "".equals(paramOne) || paramTwo == null || "".equals(paramTwo)) {
|
||||
return false;
|
||||
}
|
||||
return getCondResult(operator, paramOne, paramTwo);
|
||||
}
|
||||
|
||||
//传入两个参数和一个操作符进行比对获取结果
|
||||
public final static boolean getCondResult(String operator, Object paramOne, Object paramTwo) {
|
||||
boolean result = false;
|
||||
Double numOne = StrUtils.strToDouble(paramOne.toString());
|
||||
Double numTwo = StrUtils.strToDouble(paramTwo.toString());
|
||||
switch (operator) {
|
||||
//数值之间的比较
|
||||
case "==":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = numOne.equals(numTwo);
|
||||
} else if (paramOne != null && paramTwo != null) {
|
||||
result = paramOne.toString().equals(paramTwo.toString());
|
||||
}
|
||||
break;
|
||||
case "!=":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = !numOne.equals(numTwo);
|
||||
} else if (paramOne != null && paramTwo != null) {
|
||||
result = !paramOne.toString().equals(paramTwo.toString());
|
||||
}
|
||||
break;
|
||||
case ">":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = numOne > numTwo;
|
||||
}
|
||||
break;
|
||||
case "<":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = numOne < numTwo;
|
||||
}
|
||||
break;
|
||||
case ">=":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = numOne >= numTwo;
|
||||
}
|
||||
break;
|
||||
case "<=":
|
||||
if (numOne != null && numTwo != null) {
|
||||
result = numOne <= numTwo;
|
||||
}
|
||||
break;
|
||||
//字符串之间的比较
|
||||
case "equals":
|
||||
result = paramOne.toString().equals(paramTwo.toString());
|
||||
break;
|
||||
case "not equals":
|
||||
result = !paramOne.toString().equals(paramTwo.toString());
|
||||
break;
|
||||
case "contains":
|
||||
result = paramOne.toString().contains(paramTwo.toString());
|
||||
break;
|
||||
case "not contains":
|
||||
result = !paramOne.toString().contains(paramTwo.toString());
|
||||
break;
|
||||
case "regex":
|
||||
Pattern pattern = Pattern.compile(paramTwo.toString());
|
||||
Matcher matcher = pattern.matcher(paramOne.toString());
|
||||
result = matcher.find();
|
||||
break;
|
||||
case "in":
|
||||
if (paramTwo instanceof List) {
|
||||
List list = (List) paramTwo;
|
||||
result = list.contains(paramOne);
|
||||
} else if (paramTwo instanceof Map) {
|
||||
Map map = (Map) paramTwo;
|
||||
result = map.containsKey(paramOne);
|
||||
}
|
||||
break;
|
||||
case "not in":
|
||||
if (paramTwo instanceof List) {
|
||||
List list = (List) paramTwo;
|
||||
result = !list.contains(paramOne);
|
||||
} else if (paramTwo instanceof Map) {
|
||||
Map map = (Map) paramTwo;
|
||||
result = !map.containsKey(paramOne);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//根据key,分不同类型取出值
|
||||
public final static Object getValueByKey(Integer variableType, Map<String, Object> params, String paramKey, List<JSONObject> list) {
|
||||
Object result = paramKey;
|
||||
if (variableType != null) {
|
||||
switch (variableType) {
|
||||
case ParamTypeConst
|
||||
.CONSTANT:
|
||||
//常量类型
|
||||
result = paramKey;
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.VARIABLE:
|
||||
//变量类型
|
||||
result = getObjFromMap(params, paramKey);
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.CUSTOM:
|
||||
//自定义脚本类型
|
||||
if (list == null || list.isEmpty()) {
|
||||
result = getObjFromScript(params, paramKey);
|
||||
} else {
|
||||
result = getObjFromScript(params, paramKey, list);
|
||||
}
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.REGEX:
|
||||
//正则表达式类型
|
||||
result = getObjFromRegex(params, paramKey);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//从map中取值
|
||||
public final static Object getObjFromMap(Map<String, Object> input, String key) {
|
||||
if (StringUtils.isBlank(key)) {
|
||||
return "";
|
||||
}
|
||||
if (input == null) {
|
||||
input = new ConcurrentHashMap<>();
|
||||
}
|
||||
String[] array = key.split("\\.");
|
||||
//如果当前变量池中未找到此变量则需要获取
|
||||
if (input.get(array[0]) == null && !array[0].startsWith("%")) {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add(array[0]);
|
||||
boolean result = getFieldToInputByEns(strings, input);
|
||||
if (!result) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
return getObjFromMap(input, array);
|
||||
}
|
||||
|
||||
//从map中找到需要的对象并返回
|
||||
public final static Object getObjFromMap(Map<String, Object> input, String[] array) {
|
||||
if (array.length == 1) {
|
||||
Object o = input.get(array[0]);
|
||||
if (o == null) {
|
||||
return "";
|
||||
}
|
||||
return o;
|
||||
}
|
||||
Map map = input;
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
String childKey = array[i];
|
||||
//判断是否能找到key
|
||||
if (map.containsKey(childKey)) {
|
||||
Object o = map.get(childKey);
|
||||
if (i == array.length - 1) {
|
||||
return map.get(childKey);
|
||||
}
|
||||
//如果是数组取length
|
||||
if (i == array.length - 2) {
|
||||
if ("length()".equals(array[array.length - 1])) {
|
||||
return JSON.toJavaObject(JSON.parseObject(JSON.toJSONString(o)), ArrayList.class).size();
|
||||
}
|
||||
}
|
||||
//未找到最后一个数组元素则将其识别为map
|
||||
map = JSON.toJavaObject(JSON.parseObject(JSON.toJSONString(o)), Map.class);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//根据入参map,通过公式和groovy计算出返回结果
|
||||
public final static Object getObjFromScript(Map<String, Object> input, String fieldValue) {
|
||||
JSONObject formulaJson = JSON.parseObject(fieldValue);
|
||||
//找到脚本中引用的字段,放入data中
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
Object farr = formulaJson.get("farr");
|
||||
List<Long> fieldIds = new ArrayList<>();
|
||||
//字段cn为key,字段en为value
|
||||
Map<String, Field> fieldMap = new HashMap<>();
|
||||
if (farr != null && !"".equals(farr)) {
|
||||
List<Field> fieldList = JSONArray.parseArray(JSON.toJSONString(farr), Field.class);
|
||||
for (Field field : fieldList) {
|
||||
String fieldCn = field.getFieldCn();
|
||||
String fieldEn = field.getFieldEn();
|
||||
if (fieldCn != null && fieldEn != null && !"".equals(fieldCn) && !"".equals(fieldEn)) {
|
||||
fieldMap.put(fieldCn, field);
|
||||
}
|
||||
fieldIds.add(field.getId());
|
||||
}
|
||||
}
|
||||
if (fieldIds.size() > 0) {
|
||||
getFieldToInputByIds(fieldIds, input);
|
||||
}
|
||||
Object result = executeScript(formulaJson, fieldMap, input);
|
||||
return result;
|
||||
}
|
||||
|
||||
//处理集合中的特殊自定义
|
||||
private final static Object getObjFromScript(Map<String, Object> input, String fieldValue, List<JSONObject> current) {
|
||||
JSONObject formulaJson = JSON.parseObject(fieldValue);
|
||||
//找到脚本中引用的字段,放入data中
|
||||
Object farr = formulaJson.get("farr");
|
||||
List<Long> fieldIds = new ArrayList<>();
|
||||
//字段cn为key,字段en为value
|
||||
Map<String, Field> fieldMap = new HashMap<>();
|
||||
if (farr != null && !"".equals(farr)) {
|
||||
List<JSONObject> fieldList = JSONArray.parseArray(JSON.toJSONString(farr), JSONObject.class);
|
||||
String inputParamStr = JSON.toJSONString(input);
|
||||
for (JSONObject jsonObject : fieldList) {
|
||||
String fieldCn = jsonObject.getString("fieldCn");
|
||||
String fieldEn = jsonObject.getString("fieldEn");
|
||||
Field field = new Field();
|
||||
field.setFieldEn(fieldEn);
|
||||
field.setFieldCn(fieldCn);
|
||||
field.setValueType(jsonObject.getInteger("valueType"));
|
||||
Object thisFieldEnValue = null;
|
||||
if (fieldCn != null && fieldEn != null && !"".equals(fieldCn) && !"".equals(fieldEn)) {
|
||||
fieldMap.put(fieldCn, field);
|
||||
}
|
||||
if (jsonObject.containsKey("temp") && jsonObject.getBoolean("temp")) {
|
||||
continue;
|
||||
}
|
||||
Long id = jsonObject.getLong("id");
|
||||
if (!jsonObject.containsKey("paramList")) {
|
||||
if (id != null) {
|
||||
fieldIds.add(id);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
//存在paramList证明是参数绑定过的需要单个字段取出
|
||||
JSONArray paramList = jsonObject.getJSONArray("paramList");
|
||||
//input中根据fieldEn和绑定参数设置了缓存,此缓存需要规则中管理缓存层级。
|
||||
String thisFieldEnKey = MD5.GetMD5Code(fieldEn + ":" + paramList.toJSONString());
|
||||
if (input.containsKey(thisFieldEnKey)) {
|
||||
thisFieldEnValue = input.get(thisFieldEnKey);
|
||||
} else {
|
||||
Map<String, Object> temp = JSON.parseObject(inputParamStr, Map.class);
|
||||
for (int i = 0; i < paramList.size(); i++) {
|
||||
JSONObject param = paramList.getJSONObject(i);
|
||||
String paramEn = param.getString("en");
|
||||
String paramValue = param.getString("value");
|
||||
switch (param.getIntValue("type")) {
|
||||
case ParamTypeConst.CONSTANT:
|
||||
temp.put(paramEn, paramValue);
|
||||
break;
|
||||
case ParamTypeConst.VARIABLE:
|
||||
temp.put(paramEn, DataCleanUtils.getObjByKeyAndJson(current.get(0), paramValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
getFieldToInputByIds(Arrays.asList(id), temp);
|
||||
thisFieldEnValue = temp.get(fieldEn);
|
||||
input.put(thisFieldEnKey, thisFieldEnValue);
|
||||
}
|
||||
input.put(fieldEn, thisFieldEnValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (!fieldIds.isEmpty()) {
|
||||
getFieldToInputByIds(fieldIds, input);
|
||||
}
|
||||
//取出groovy脚本
|
||||
Object result = executeScript(formulaJson, fieldMap, input);
|
||||
return result;
|
||||
}
|
||||
|
||||
//对正则取值
|
||||
public final static Object getObjFromRegex(Map<String, Object> input, String fieldValue) {
|
||||
String result = fieldValue;
|
||||
//校验是否使用了字段如果使用了则需要替换为值
|
||||
Pattern pattern = Pattern.compile("@[a-zA-Z0-9_\u4e00-\u9fa5()()-]+@");
|
||||
Matcher matcher = pattern.matcher(fieldValue);
|
||||
while (matcher.find()) {
|
||||
String fieldEn = matcher.group().replace("@", "");
|
||||
Object value = ExecuteUtils.getObjFromMap(input, fieldEn);
|
||||
String valueStr = "";
|
||||
if (value != null) {
|
||||
valueStr = value.toString();
|
||||
}
|
||||
result = result.replace("@" + fieldEn + "@", valueStr);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//执行自定义脚本
|
||||
private final static Object executeScript(JSONObject formulaJson, Map<String, Field> fieldMap, Map<String, Object> input) {
|
||||
String formula = formulaJson.getString("formula");
|
||||
//替换掉特殊的字符
|
||||
formula = formula.replace(">", ">"); //3>=6 && 3< 12
|
||||
formula = formula.replace("<", "<");
|
||||
//正则匹配自定义中用到的变量对其进行替换
|
||||
Pattern pattern = Pattern.compile("@[a-zA-Z0-9_\u4e00-\u9fa5()()-]+@");
|
||||
Matcher matcher = pattern.matcher(formula);
|
||||
String subexp = formula;
|
||||
String exp = "";
|
||||
int j = 0;
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
while (matcher.find()) {
|
||||
String fieldCN = matcher.group(0).replace("@", "");
|
||||
Field subField = fieldMap.get(fieldCN);
|
||||
if (subField == null) {
|
||||
return "";
|
||||
}
|
||||
String fieldEn = subField.getFieldEn();
|
||||
String v = "";
|
||||
v = "" + input.get(fieldEn);
|
||||
data.put(fieldEn, input.get(fieldEn));
|
||||
if (subexp.contains("def main")) {
|
||||
// groovy脚本替换为动态参数
|
||||
v = "_['" + fieldEn + "']";
|
||||
exp += subexp.substring(j, matcher.end()).replace("@" + fieldCN + "@", v);
|
||||
} else {
|
||||
if (subField.getValueType() == 1 || subField.getValueType() == 4) {
|
||||
exp += subexp.substring(j, matcher.end()).replace("@" + fieldCN + "@", v);
|
||||
} else {
|
||||
exp += subexp.substring(j, matcher.end()).replace("@" + fieldCN + "@", "'" + v + "'");
|
||||
}
|
||||
}
|
||||
j = matcher.end();
|
||||
}
|
||||
|
||||
|
||||
exp += formula.substring(j, formula.length());
|
||||
Evaluator evaluator = new Evaluator();
|
||||
Object result = "";
|
||||
try {
|
||||
if (exp.contains("def main")) {
|
||||
// 执行groovy脚本
|
||||
|
||||
logger.warn("groovy:{},{}", exp, data);
|
||||
result = groovy.executeForObject(exp, data);
|
||||
} else if (exp.contains("def python_main(_):")) {
|
||||
//执行python脚本
|
||||
result = python.executeForObject(exp, data);
|
||||
} else {
|
||||
//执行公式
|
||||
result = evaluator.evaluate(exp);
|
||||
}
|
||||
if (result.toString().startsWith("'")) {
|
||||
//字符串
|
||||
result = result.toString().replace("'", "");
|
||||
} else {
|
||||
//数值
|
||||
if (StrUtils.isNum(result.toString())) {
|
||||
String[] split = result.toString().split("\\.");
|
||||
if (split.length > 1 && StrUtils.strToLong(split[1]) > 0) {
|
||||
result = StrUtils.strToDouble(result.toString());
|
||||
} else {
|
||||
result = StrUtils.strToLong(split[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (EvaluationException e) {
|
||||
logger.error("自定义执行异常", e);
|
||||
throw new ApiException(ErrorCodeEnum.RUNNER_CUSTOM_ERROR.getCode(), ErrorCodeEnum.RUNNER_CUSTOM_ERROR.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//对groovy脚本执行结果进一步处理
|
||||
public static Map handleGroovyResult(Map map) {
|
||||
|
||||
Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Object> entry = iterator.next();
|
||||
if (entry.getKey().startsWith("_['") && entry.getKey().endsWith("']")) {
|
||||
map.remove(entry.getKey());
|
||||
String key = entry.getKey().replace("_['", "").replace("']", "");
|
||||
map.put(key, entry.getValue());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
//调用commonService根据ens取参数
|
||||
public static boolean getFieldToInputByEns(List<String> fieldEns, Map<String, Object> input) {
|
||||
boolean result = commonService.getEngineField(fieldService.selectFieldListByEns(fieldEns), input);
|
||||
return result;
|
||||
}
|
||||
//调用commonService根据ids取参数
|
||||
private static boolean getFieldToInputByIds(List<Long> ids, Map<String, Object> input) {
|
||||
boolean result = commonService.getFieldByIds(ids, input);
|
||||
return result;
|
||||
}
|
||||
|
||||
// 解析nodeJson
|
||||
public final static List<Map> getExecuteListFromNodeJson(EngineNode engineNode) {
|
||||
JSONObject nodeJson = JSON.parseObject(engineNode.getNodeJson());
|
||||
String strategyStr = null;
|
||||
switch (engineNode.getNodeType()) {
|
||||
case 2://规则集
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONObject("executeGroup").get("strategyList"));
|
||||
break;
|
||||
case 4://评分卡
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONArray("scorecardList"));
|
||||
break;
|
||||
case 5://名单库
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONArray("listDbList"));
|
||||
break;
|
||||
case 15://模型
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONArray("modelList"));
|
||||
break;
|
||||
case 16://决策表
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONArray("decisionTableList"));
|
||||
break;
|
||||
case 17://决策树
|
||||
strategyStr = JSON.toJSONString(nodeJson.getJSONArray("decisionTreeList"));
|
||||
break;
|
||||
|
||||
}
|
||||
List<Map> maps = JSON.parseArray(strategyStr, Map.class);
|
||||
return maps;
|
||||
}
|
||||
|
||||
//获取执行用的id列表
|
||||
public final static List<Long> getExecuteIdList(EngineNode engineNode, String idKey) {
|
||||
List<Map> maps = ExecuteUtils.getExecuteListFromNodeJson(engineNode);
|
||||
List<Long> executeIdList = new ArrayList<>();
|
||||
if (maps != null && maps.size() > 0) {
|
||||
for (Map map : maps) {
|
||||
if (map.containsKey(idKey)) {
|
||||
Object o = map.get(idKey);
|
||||
if (o != null) {
|
||||
Long id = StrUtils.strToLong(String.valueOf(o));
|
||||
if (id != null) {
|
||||
executeIdList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return executeIdList;
|
||||
}
|
||||
|
||||
//判断终止条件是否满足,满足则结束
|
||||
public final static void terminalCondition(EngineNode engineNode, Map<String, Object> inputParam, Map<String, Object> outMap, Map<String, Object> variablesMap) {
|
||||
if (StringUtils.isBlank(engineNode.getNodeScript())) {
|
||||
return;
|
||||
}
|
||||
JSONObject nodeScript = JSONObject.parseObject(engineNode.getNodeScript());
|
||||
JSONObject terminationInfo = nodeScript.getJSONObject("terminationInfo");
|
||||
JSONArray selectedRule = terminationInfo.getJSONArray("selectedRule");
|
||||
if(selectedRule == null || selectedRule.isEmpty()){
|
||||
return;
|
||||
}
|
||||
|
||||
String conditions = terminationInfo.getString("conditions");
|
||||
Map<String, Integer> fieldTypeMap = terminationInfo.getObject("fieldTypeMap", Map.class);
|
||||
JevalUtil.convertVariables(fieldTypeMap, variablesMap);
|
||||
// 判断终止条件
|
||||
boolean result = false;
|
||||
try {
|
||||
result = JevalUtil.evaluateBoolean(conditions, variablesMap);
|
||||
} catch (EvaluationException e) {
|
||||
logger.error("终止条件执行异常,执行内容:{},参数:{}", conditions, variablesMap);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (result) {
|
||||
Object outValue = "";
|
||||
JSONObject output = terminationInfo.getJSONObject("output");
|
||||
String fieldValue = output.getString("fieldValue");
|
||||
String fieldCode = output.getString("fieldCode");
|
||||
int variableType = output.getInteger("variableType");
|
||||
switch (variableType) {
|
||||
case 1:
|
||||
outValue = fieldValue;
|
||||
break;
|
||||
case 2:
|
||||
outValue = ExecuteUtils.getObjFromMap(inputParam, fieldValue);
|
||||
break;
|
||||
case 3:
|
||||
outValue = ExecuteUtils.getObjFromScript(inputParam, fieldValue);
|
||||
break;
|
||||
}
|
||||
// 输出终止结果
|
||||
if (outValue == null) {
|
||||
outValue = "";
|
||||
}
|
||||
if (outValue instanceof String) {
|
||||
outMap.put("result", outValue);
|
||||
} else {
|
||||
outMap.put("result", JSONObject.toJSON(outValue));
|
||||
}
|
||||
if (StringUtils.isNotBlank(fieldCode)) {
|
||||
inputParam.put(fieldCode, outValue);
|
||||
}
|
||||
engineNode.setNextNodes(null);
|
||||
}
|
||||
}
|
||||
|
||||
//根据key,分不同类型取出值
|
||||
public final static Object getValueByKeyYiHao(Integer variableType, Map<String, Object> params, String paramKey, JSONObject collectionObject) {
|
||||
Object result = paramKey;
|
||||
if (variableType != null) {
|
||||
switch (variableType) {
|
||||
case ParamTypeConst
|
||||
.CONSTANT:
|
||||
//常量类型
|
||||
result = paramKey;
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.VARIABLE:
|
||||
//变量类型
|
||||
result = getObjFromMap(params, paramKey);
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.CUSTOM:
|
||||
//自定义脚本类型
|
||||
result = getObjFromScriptYiHao(paramKey, collectionObject);
|
||||
break;
|
||||
case ParamTypeConst
|
||||
.REGEX:
|
||||
//正则表达式类型
|
||||
result = getObjFromRegex(params, paramKey);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//处理集合中的特殊自定义
|
||||
private final static Object getObjFromScriptYiHao(String outputValue, JSONObject collectionObject) {
|
||||
JSONObject formulaJson = JSON.parseObject(outputValue);
|
||||
Object farr = formulaJson.get("farr");
|
||||
Map<String, Object> fieldMap = new HashMap<>();
|
||||
if (farr != null && !"".equals(farr)) {
|
||||
List<JSONObject> fieldList = JSONArray.parseArray(JSON.toJSONString(farr), JSONObject.class);
|
||||
for (JSONObject jsonObject : fieldList) {
|
||||
String fieldCn = jsonObject.getString("fieldCn");
|
||||
String fieldEn = jsonObject.getString("fieldEn");
|
||||
Object opValue = DataCleanUtils.getObjByKeyAndJson(collectionObject, fieldEn);
|
||||
fieldMap.put(fieldCn, opValue);
|
||||
}
|
||||
}
|
||||
//取出groovy脚本
|
||||
Object result = executeScriptYiHao(formulaJson, fieldMap);
|
||||
return result;
|
||||
}
|
||||
|
||||
//执行自定义脚本
|
||||
private final static Object executeScriptYiHao(JSONObject formulaJson, Map<String, Object> fieldMap) {
|
||||
String formula = formulaJson.getString("formula");
|
||||
//替换掉特殊的字符
|
||||
formula = formula.replace(">", ">"); //3>=6 && 3< 12
|
||||
formula = formula.replace("<", "<");
|
||||
//正则匹配自定义中用到的变量对其进行替换
|
||||
Pattern pattern = Pattern.compile("@[a-zA-Z0-9_\u4e00-\u9fa5()()-]+@");
|
||||
Matcher matcher = pattern.matcher(formula);
|
||||
String subexp = formula;
|
||||
String exp = "";
|
||||
int j = 0;
|
||||
while (matcher.find()) {
|
||||
String fieldCn = matcher.group(0).replace("@", "");
|
||||
Object fieldCnValue = fieldMap.get(fieldCn);
|
||||
if (fieldCnValue == null) {
|
||||
return "";
|
||||
}
|
||||
exp += subexp.substring(j, matcher.end()).replace("@" + fieldCn + "@", fieldCnValue.toString());
|
||||
j = matcher.end();
|
||||
}
|
||||
|
||||
exp += formula.substring(j, formula.length());
|
||||
Evaluator evaluator = new Evaluator();
|
||||
Object result = "";
|
||||
try {
|
||||
//执行公式
|
||||
result = evaluator.evaluate(exp);
|
||||
|
||||
if (result.toString().startsWith("'")) {
|
||||
//字符串
|
||||
result = result.toString().replace("'", "");
|
||||
} else {
|
||||
//数值
|
||||
if (StrUtils.isNum(result.toString())) {
|
||||
String[] split = result.toString().split("\\.");
|
||||
if (split.length > 1 && StrUtils.strToLong(split[1]) > 0) {
|
||||
result = StrUtils.strToDouble(result.toString());
|
||||
} else {
|
||||
result = StrUtils.strToLong(split[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (EvaluationException e) {
|
||||
logger.error("自定义执行异常", e);
|
||||
throw new ApiException(ErrorCodeEnum.RUNNER_CUSTOM_ERROR.getCode(), ErrorCodeEnum.RUNNER_CUSTOM_ERROR.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.fibo.ddp.common.service.datax.runner;
|
||||
|
||||
public class FieldTypeConsts {
|
||||
public static String BASICS = "basics";
|
||||
public static String CONST = "const";
|
||||
public static String DATABASE = "database";
|
||||
public static String INTERFACE = "interface";
|
||||
public static String DERIVE = "derive";
|
||||
public static Long DERIVE_SOURCE_ID = 0L;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,17 @@
|
||||
package com.fibo.ddp.common.service.datax.runner.mysql;
|
||||
|
||||
public class DataSourceContextHolder {
|
||||
private static final ThreadLocal<String> contextHolder = new ThreadLocal<String>();
|
||||
|
||||
public static synchronized void setDBType(String dbType){
|
||||
contextHolder.set(dbType);
|
||||
}
|
||||
|
||||
public static String getDBType(){
|
||||
return contextHolder.get();
|
||||
}
|
||||
|
||||
public static void clearDBType(){
|
||||
contextHolder.remove();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.fibo.ddp.common.service.datax.runner.mysql;
|
||||
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DynamicDataSource extends AbstractRoutingDataSource {
|
||||
private static DynamicDataSource instance;
|
||||
private static byte[] lock=new byte[0];
|
||||
private static Map<Object,Object> dataSourceMap=new HashMap<Object, Object>();
|
||||
|
||||
@Override
|
||||
public void setTargetDataSources(Map<Object, Object> targetDataSources) {
|
||||
super.setTargetDataSources(targetDataSources);
|
||||
dataSourceMap.putAll(targetDataSources);
|
||||
super.afterPropertiesSet();// 必须添加该句,否则新添加数据源无法识别到
|
||||
}
|
||||
|
||||
public Map<Object, Object> getDataSourceMap() {
|
||||
return dataSourceMap;
|
||||
}
|
||||
|
||||
public static synchronized DynamicDataSource getInstance(){
|
||||
if(instance==null){
|
||||
synchronized (lock){
|
||||
if(instance==null){
|
||||
instance=new DynamicDataSource();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
//必须实现其方法
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DataSourceContextHolder.getDBType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.fibo.ddp.common.service.datax.runner.redis;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.fibo.ddp.common.model.datax.datasource.DataSource;
|
||||
import com.fibo.ddp.common.service.redis.RedisManager;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.pool2.BaseKeyedPooledObjectFactory;
|
||||
import org.apache.commons.pool2.PooledObject;
|
||||
import org.apache.commons.pool2.impl.DefaultPooledObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisShardInfo;
|
||||
|
||||
/**
|
||||
* kSession工厂类
|
||||
*/
|
||||
@Component
|
||||
public class RedisKSessionFactory extends BaseKeyedPooledObjectFactory<String, Jedis> {
|
||||
|
||||
@Autowired
|
||||
private RedisManager redisManager;
|
||||
|
||||
@Override
|
||||
public Jedis create(String key) throws Exception {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
// long start = System.currentTimeMillis();
|
||||
String json = redisManager.get(key);
|
||||
if(json == null){
|
||||
throw new Exception("create jedis kSession fail, key is "+ key + ", ruleString is null!");
|
||||
}
|
||||
DataSource dataSource = JSON.parseObject(json, DataSource.class);
|
||||
String userName = dataSource.getUserName();
|
||||
if (StringUtils.isBlank(userName)){
|
||||
userName = "root";
|
||||
}
|
||||
JedisShardInfo jedisShardInfo = new JedisShardInfo( dataSource.getHost(),Integer.valueOf(dataSource.getPort()),3000,userName);
|
||||
jedisShardInfo.setPassword(dataSource.getPassword());
|
||||
jedis = new Jedis(jedisShardInfo);
|
||||
jedis.select(Integer.valueOf(dataSource.getDbName()));
|
||||
|
||||
// long end = System.currentTimeMillis();
|
||||
// System.out.println("------------------jedis连接创建耗时:" + (end - start) + " ----------------------");
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
return jedis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PooledObject<Jedis> wrap(Jedis kSession) {
|
||||
return new DefaultPooledObject<Jedis>(kSession);
|
||||
}
|
||||
|
||||
public void setRedisManager(RedisManager redisManager) {
|
||||
this.redisManager = redisManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.fibo.ddp.common.service.datax.runner.redis;
|
||||
|
||||
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
|
||||
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
/**
|
||||
* kSession连接池
|
||||
*/
|
||||
@Component
|
||||
public class RedisKSessionPool implements InitializingBean {
|
||||
|
||||
private GenericKeyedObjectPool<String, Jedis> pool;
|
||||
|
||||
@Autowired
|
||||
private RedisKSessionFactory kSessionFactory;
|
||||
|
||||
/**
|
||||
* 初始化方法
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
initPool();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化连接池
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public void initPool() throws Exception {
|
||||
GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
|
||||
poolConfig.setMaxTotalPerKey(200);
|
||||
poolConfig.setMaxIdlePerKey(50);
|
||||
poolConfig.setMinIdlePerKey(5);
|
||||
poolConfig.setMaxTotal(2000);
|
||||
this.pool = new GenericKeyedObjectPool(kSessionFactory, poolConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个连接对象
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Jedis borrowObject(String key) throws Exception {
|
||||
return pool.borrowObject(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 归还一个连接对象
|
||||
* @param
|
||||
*/
|
||||
public void returnObject(String key, Jedis kSession) {
|
||||
if(kSession != null){
|
||||
pool.returnObject(key, kSession);
|
||||
}
|
||||
}
|
||||
|
||||
public void setkSessionFactory(RedisKSessionFactory kSessionFactory) {
|
||||
this.kSessionFactory = kSessionFactory;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineNode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 存储版本模型的信息包括(使用的参数,节点的位置,节点的执行逻辑)(EngineNode)表服务接口
|
||||
* @since 2021-12-22 17:32:09
|
||||
*/
|
||||
public interface EngineNodeServiceV3 extends IService<EngineNode>{
|
||||
|
||||
List<EngineNode> queryNodeListByVersion(Long versionId);
|
||||
|
||||
boolean saveStartNode(Long versionId);
|
||||
|
||||
boolean updateStatus(List<Long> ids, Integer status);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.enginex.risk.Engine;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (Engine)表服务接口
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-22 13:28:08
|
||||
*/
|
||||
public interface EngineServiceV3 extends IService<Engine> {
|
||||
|
||||
PageInfo queryList(QueryListParam<Engine> param);
|
||||
|
||||
boolean updateStatus(List<Long> ids, Integer status);
|
||||
|
||||
Engine addEngine(Engine engine);
|
||||
|
||||
Engine updateEngine(Engine engine);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.EngineVersionContent;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.vo.EngineVersionContentVo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (EngineVersionContent)表服务接口
|
||||
* @since 2021-12-23 10:21:08
|
||||
*/
|
||||
public interface EngineVersionContentService extends IService<EngineVersionContent>{
|
||||
|
||||
EngineVersionContentVo queryById(Long versionId);
|
||||
List<EngineVersionContentVo> queryByIds(Collection<Long> versionIds);
|
||||
boolean addVersionContent(EngineVersionContentVo versionContent);
|
||||
boolean updateVersionContent(EngineVersionContentVo versionContent);
|
||||
boolean deleteVersionContent(EngineVersionContent versionContent);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineVersion;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 不同场景下的多个模型版本(EngineVersion)表服务接口
|
||||
*
|
||||
* @since 2021-12-22 14:39:33
|
||||
*/
|
||||
public interface EngineVersionServiceV3 extends IService<EngineVersion> {
|
||||
|
||||
EngineVersion queryById(Long versionId);
|
||||
|
||||
PageInfo queryList(QueryListParam<EngineVersion> param);
|
||||
List<EngineVersion> queryByEngineIds(Collection<Long> engineIds);
|
||||
List<EngineVersion> queryByEngineId(Long engineId);
|
||||
|
||||
boolean addEngineVersion(EngineVersion param);
|
||||
|
||||
boolean copyEngineVersion(Long versionId);
|
||||
|
||||
/**
|
||||
* 假删,修改状态
|
||||
*/
|
||||
boolean updateStatus(List<Long> ids, Integer status);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineNodeMapper;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineNode;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineNodeServiceV3;
|
||||
import com.fibo.ddp.common.utils.constant.enginex.NodeTypeEnum;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 存储版本模型的信息包括(使用的参数,节点的位置,节点的执行逻辑)(EngineNode)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-22 17:32:09
|
||||
*/
|
||||
@Service("engineNodeServiceV3")
|
||||
public class EngineNodeServiceV3Impl extends ServiceImpl<EngineNodeMapper, EngineNode> implements EngineNodeServiceV3 {
|
||||
|
||||
@Override
|
||||
public List<EngineNode> queryNodeListByVersion(Long versionId) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean saveStartNode(Long versionId) {
|
||||
EngineNode node = new EngineNode();
|
||||
node.setNodeX(200D);
|
||||
node.setNodeY(200D);
|
||||
node.setNodeName("开始");
|
||||
node.setNodeOrder(1);
|
||||
node.setNodeType(NodeTypeEnum.START.getValue());
|
||||
node.setNodeCode("ND_START");
|
||||
node.setParams("{\"arr_linkId\":\"\",\"dataId\":\"-1\",\"url\":\"/Riskmanage/resource/images/decision/start.png\",\"type\":\"1\"}");
|
||||
node.setVersionId(versionId);
|
||||
// 直接插入节点
|
||||
return this.save(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateStatus(List<Long> ids,Integer statu) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.enginex.risk.Engine;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineVersion;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineServiceV3;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineVersionServiceV3;
|
||||
import com.fibo.ddp.common.utils.constant.StatusConst;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (Engine)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-22 13:28:09
|
||||
*/
|
||||
@Service("engineServiceV3")
|
||||
public class EngineServiceV3Impl extends ServiceImpl<EngineMapper, Engine> implements EngineServiceV3 {
|
||||
|
||||
@Autowired
|
||||
private EngineVersionServiceV3 engineVersionServiceV3;
|
||||
|
||||
@Override
|
||||
public PageInfo queryList(QueryListParam<Engine> param) {
|
||||
if (QueryListParam.checkIsPage(param)) {
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
LambdaQueryWrapper<Engine> wrapper = createWrapper(param.getEntity());
|
||||
PageInfo<Engine> pageInfo = new PageInfo<>(this.list(wrapper));
|
||||
if(pageInfo.getSize()!=0){
|
||||
List<Long> bootEngineIds = engineVersionServiceV3.
|
||||
queryByEngineIds(pageInfo.getList().stream().map(Engine::getId).collect(Collectors.toList()))
|
||||
.stream().filter(item -> {
|
||||
return item.getBootState() == 1;
|
||||
}).map(EngineVersion::getEngineId).distinct().collect(Collectors.toList());
|
||||
for (Engine Engine : pageInfo.getList()) {
|
||||
if (bootEngineIds.contains(Engine.getId())){
|
||||
Engine.setRunStatus(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Engine addEngine(Engine engine) {
|
||||
initEngine(engine);
|
||||
boolean saveEngine = this.save(engine);
|
||||
if (saveEngine) {
|
||||
//保存成功添加版本
|
||||
EngineVersion version = new EngineVersion();
|
||||
version.setEngineId(engine.getId());
|
||||
version.setVersion(0);
|
||||
version.setEngineType(engine.getEngineType());
|
||||
boolean saveVersion = engineVersionServiceV3.addEngineVersion(version);
|
||||
if (!saveVersion) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(),"新增引擎添加默认版本失败");
|
||||
}
|
||||
return engine;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Engine updateEngine(Engine engine) {
|
||||
if (engine != null && engine.getId() != null){
|
||||
boolean result = this.updateById(engine);
|
||||
return engine;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateStatus(List<Long> ids, Integer status) {
|
||||
LambdaUpdateWrapper<Engine> wrapper = new LambdaUpdateWrapper<>();
|
||||
wrapper.in(Engine::getId, ids);
|
||||
Engine Engine = new Engine();
|
||||
Engine.setStatus(status);
|
||||
Engine.setCreator(SessionManager.getLoginAccount().getUserId());
|
||||
return this.update(Engine, wrapper);
|
||||
}
|
||||
|
||||
|
||||
private void initEngine(Engine engine) {
|
||||
if (engine == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "新增引擎不能为nll");
|
||||
}
|
||||
SysUser sysUser = SessionManager.getLoginAccount();
|
||||
engine.setOrganId(sysUser.getOrganId());
|
||||
engine.setCreator(sysUser.getUserId());
|
||||
engine.setStatus(StatusConst.STATUS_ENABLED);
|
||||
}
|
||||
|
||||
|
||||
private LambdaQueryWrapper<Engine> createWrapper(Engine entity) {
|
||||
LambdaQueryWrapper<Engine> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(Engine::getId);
|
||||
wrapper.eq(Engine::getOrganId, SessionManager.getLoginAccount().getOrganId());
|
||||
if (entity == null) {
|
||||
wrapper.ne(Engine::getStatus, StatusConst.STATUS_DELETE);
|
||||
return wrapper;
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getCode())) {
|
||||
wrapper.eq(Engine::getCode, entity.getCode());
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getEngineType())) {
|
||||
wrapper.like(Engine::getEngineType, entity.getEngineType());
|
||||
}
|
||||
if (entity.getStatus() != null) {
|
||||
wrapper.eq(Engine::getStatus, entity.getStatus());
|
||||
} else {
|
||||
wrapper.ne(Engine::getStatus, StatusConst.STATUS_DELETE);
|
||||
}
|
||||
if (StringUtils.isNotBlank(entity.getName())) {
|
||||
wrapper.like(Engine::getName, entity.getName());
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.dataflow.EngineVersionContentMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.EngineVersionContent;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.vo.DataFlowEngineContentVo;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.vo.DataFlowNodeVo;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.vo.EngineVersionContentVo;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.dto.AudienceNodeDto;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.dto.TargetSettingNodeDto;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.dto.TouchConfigNodeDto;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.vo.MarketingEngineContentVo;
|
||||
import com.fibo.ddp.common.model.strategyx.baserule.BaseRule;
|
||||
import com.fibo.ddp.common.model.strategyx.baserule.BaseRuleTypeEnum;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineVersionContentService;
|
||||
import com.fibo.ddp.common.service.strategyx.baserule.BaseRuleService;
|
||||
import com.fibo.ddp.common.utils.constant.enginex.EngineContentConst;
|
||||
import com.fibo.ddp.common.utils.constant.enginex.EngineTypeConst;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (EngineVersionContent)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-23 10:21:08
|
||||
*/
|
||||
@Service("engineVersionContentService")
|
||||
public class EngineVersionContentServiceImpl extends ServiceImpl<EngineVersionContentMapper, EngineVersionContent> implements EngineVersionContentService {
|
||||
|
||||
@Resource
|
||||
private EngineVersionContentMapper engineVersionContentMapper;
|
||||
@Resource
|
||||
private BaseRuleService baseRuleService;
|
||||
|
||||
@Override
|
||||
public EngineVersionContentVo queryById(Long versionId) {
|
||||
if (versionId == null) {
|
||||
return null;
|
||||
}
|
||||
EngineVersionContent engineVersionContent = this.getById(versionId);
|
||||
EngineVersionContentVo engineVersionContentVo = queryDetail(engineVersionContent);
|
||||
return engineVersionContentVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EngineVersionContentVo> queryByIds(Collection<Long> versionIds) {
|
||||
if (CollectionUtils.isEmpty(versionIds)) {
|
||||
return null;
|
||||
}
|
||||
List<EngineVersionContent> engineVersionContents = engineVersionContentMapper.selectBatchIds(versionIds);
|
||||
List<EngineVersionContentVo> engineVersionContentVos = new ArrayList<>();
|
||||
for (EngineVersionContent engineVersionContent : engineVersionContents) {
|
||||
EngineVersionContentVo engineVersionContentVo = queryDetail(engineVersionContent);
|
||||
engineVersionContentVos.add(engineVersionContentVo);
|
||||
}
|
||||
return engineVersionContentVos;
|
||||
}
|
||||
|
||||
private EngineVersionContentVo queryDetail(EngineVersionContent engineVersionContent) {
|
||||
EngineVersionContentVo engineVersionContentVo = new EngineVersionContentVo();
|
||||
if (engineVersionContent == null) {
|
||||
return engineVersionContentVo;
|
||||
}
|
||||
BeanUtils.copyProperties(engineVersionContent, engineVersionContentVo);
|
||||
String engineContent = engineVersionContent.getEngineContent();
|
||||
String engineType = engineVersionContent.getEngineType();
|
||||
switch (engineType) {
|
||||
case EngineTypeConst
|
||||
.DATA_FLOW_ENGINE:
|
||||
if (StringUtils.isNotBlank(engineContent)){
|
||||
engineVersionContentVo.setDataFlowEngineContentVo(JSON.parseObject(engineContent,DataFlowEngineContentVo.class));
|
||||
}else {
|
||||
engineVersionContentVo.setDataFlowEngineContentVo(new DataFlowEngineContentVo());
|
||||
}
|
||||
DataFlowEngineContentVo dataFlowEngineContentVo = engineVersionContentVo.getDataFlowEngineContentVo();
|
||||
if (dataFlowEngineContentVo == null) {
|
||||
break;
|
||||
}
|
||||
List<DataFlowNodeVo> nodeList = dataFlowEngineContentVo.getNodeList();
|
||||
if (CollectionUtils.isEmpty(nodeList)) {
|
||||
break;
|
||||
}
|
||||
for (DataFlowNodeVo dataFlowNodeVo : nodeList) {
|
||||
Long baseRuleId = dataFlowNodeVo.getBaseRuleId();
|
||||
if (baseRuleId != null) {
|
||||
BaseRule baseRule = baseRuleService.queryById(baseRuleId);
|
||||
dataFlowNodeVo.setBaseRule(baseRule);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EngineTypeConst.MARKETING_ENGINE:
|
||||
assemblyMarketingEngineContent(engineContent, engineVersionContentVo);
|
||||
break;
|
||||
}
|
||||
return engineVersionContentVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装营销引擎content
|
||||
* @param engineContent 引擎内容
|
||||
* @param engineVersionContentVo 组装后返回对象
|
||||
*/
|
||||
private void assemblyMarketingEngineContent(String engineContent, EngineVersionContentVo engineVersionContentVo) {
|
||||
if (StringUtils.isNotBlank(engineContent)) {
|
||||
MarketingEngineContentVo marketingEngineContentVo = JSONObject.parseObject(engineContent, MarketingEngineContentVo.class);
|
||||
// 受众用户节点
|
||||
AudienceNodeDto audienceNodeDto = marketingEngineContentVo.getAudienceNodeDto();
|
||||
BaseRule baseRule = baseRuleService.queryById(audienceNodeDto.getBaseRuleId());
|
||||
audienceNodeDto.setBaseRule(baseRule);
|
||||
// 触达配置节点
|
||||
List<TouchConfigNodeDto> touchConfigNodeDtoList = marketingEngineContentVo.getTouchConfigNodeDtoList();
|
||||
for (TouchConfigNodeDto touchConfigNodeDto : touchConfigNodeDtoList) {
|
||||
BaseRule userSelectRule = baseRuleService.queryById(touchConfigNodeDto.getUserSelectRuleId());
|
||||
touchConfigNodeDto.setUserSelectRule(userSelectRule);
|
||||
}
|
||||
// 目标设置节点
|
||||
TargetSettingNodeDto targetSettingNodeDto = marketingEngineContentVo.getTargetSettingNodeDto();
|
||||
BaseRule primaryRule = baseRuleService.queryById(targetSettingNodeDto.getPrimaryRuleId());
|
||||
targetSettingNodeDto.setPrimaryRule(primaryRule);
|
||||
BaseRule secondaryRule = baseRuleService.queryById(targetSettingNodeDto.getSecondaryRuleId());
|
||||
targetSettingNodeDto.setSecondaryRule(secondaryRule);
|
||||
|
||||
engineVersionContentVo.setMarketingEngineContentVo(marketingEngineContentVo);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean addVersionContent(EngineVersionContentVo versionContent) {
|
||||
boolean save = false;
|
||||
if (checkContent(versionContent)) {
|
||||
versionContent.setCreateUserId(SessionManager.getLoginAccount().getUserId());
|
||||
save = this.save(versionContent);
|
||||
}
|
||||
return save;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public boolean updateVersionContent(EngineVersionContentVo versionContent) {
|
||||
boolean update = false;
|
||||
if (checkContent(versionContent)) {
|
||||
versionContent.setUpdateUserId(SessionManager.getLoginAccount().getUserId());
|
||||
//修改时处理基础信息
|
||||
updateBaseInfo(versionContent);
|
||||
update = engineVersionContentMapper.updateById(versionContent) > 0;
|
||||
}
|
||||
return update;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteVersionContent(EngineVersionContent versionContent) {
|
||||
if (null != versionContent && null != versionContent.getEngineVersionId()) {
|
||||
return this.removeById(versionContent.getEngineVersionId());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean checkContent(EngineVersionContentVo versionContent) {
|
||||
if (versionContent == null || versionContent.getEngineVersionId() == null || StringUtils.isBlank(versionContent.getEngineType())) {
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.isBlank(versionContent.getEngineContent())) {
|
||||
DataFlowEngineContentVo engineContentVo = new DataFlowEngineContentVo();
|
||||
versionContent.setEngineContent(JSON.toJSONString(engineContentVo));
|
||||
}
|
||||
versionContent.setUpdateUserId(SessionManager.getLoginAccount().getUserId());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateBaseInfo(EngineVersionContentVo versionContent) {
|
||||
String engineType = versionContent.getEngineType();
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
switch (engineType) {
|
||||
case EngineTypeConst
|
||||
.DATA_FLOW_ENGINE:
|
||||
DataFlowEngineContentVo engineContentVo = versionContent.getDataFlowEngineContentVo();
|
||||
EngineVersionContentVo old = this.queryById(versionContent.getEngineVersionId());
|
||||
DataFlowEngineContentVo dataFlowEngineContentVo = old.getDataFlowEngineContentVo();
|
||||
if (dataFlowEngineContentVo != null) {
|
||||
List<DataFlowNodeVo> nodeList = dataFlowEngineContentVo.getNodeList();
|
||||
if (CollectionUtils.isNotEmpty(nodeList)) {
|
||||
List<Long> baseRuleIds = new ArrayList<>();
|
||||
for (DataFlowNodeVo dataFlowNodeVo : nodeList) {
|
||||
baseRuleIds.add(dataFlowNodeVo.getBaseRuleId());
|
||||
}
|
||||
baseRuleService.deleteBaseRuleByIds(baseRuleIds);
|
||||
}
|
||||
}
|
||||
if (engineContentVo != null) {
|
||||
List<DataFlowNodeVo> nodeList = engineContentVo.getNodeList();
|
||||
if (CollectionUtils.isNotEmpty(nodeList)) {
|
||||
for (DataFlowNodeVo node : nodeList) {
|
||||
BaseRule baseRule = node.getBaseRule();
|
||||
if (baseRule != null) {
|
||||
baseRule.setRuleType(BaseRuleTypeEnum.DATA_FLOW_ENGINE.getType());
|
||||
baseRule.setCreateUserId(loginAccount.getUserId());
|
||||
baseRule.setOrganId(loginAccount.getOrganId());
|
||||
boolean b = baseRuleService.insertBaseRule(baseRule);
|
||||
if (b) {
|
||||
node.setBaseRuleId(baseRule.getId());
|
||||
} else {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "数据流引擎节点条件块保存失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
versionContent.setEngineContent(JSON.toJSONString(engineContentVo));
|
||||
}
|
||||
break;
|
||||
case EngineTypeConst.MARKETING_ENGINE:
|
||||
handleMarketingEngineContent(versionContent);
|
||||
versionContent.setEngineContent(JSON.toJSONString(versionContent.getMarketingEngineContentVo()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理营销引擎内容修改
|
||||
* @param versionContent
|
||||
*/
|
||||
private void handleMarketingEngineContent(EngineVersionContentVo versionContent) {
|
||||
// 先删除原条件
|
||||
EngineVersionContentVo old = this.queryById(versionContent.getEngineVersionId());
|
||||
if (old != null) {
|
||||
MarketingEngineContentVo dbContentVo = old.getMarketingEngineContentVo();
|
||||
List<Long> baseRuleIds = new ArrayList<>();
|
||||
// 受众用户节点
|
||||
baseRuleIds.add(dbContentVo.getAudienceNodeDto().getBaseRuleId());
|
||||
// 触达配置节点
|
||||
for (TouchConfigNodeDto touchConfigNodeDto : dbContentVo.getTouchConfigNodeDtoList()) {
|
||||
baseRuleIds.add(touchConfigNodeDto.getUserSelectRuleId());
|
||||
}
|
||||
// 目标设置节点
|
||||
baseRuleIds.add(dbContentVo.getTargetSettingNodeDto().getPrimaryRuleId());
|
||||
baseRuleIds.add(dbContentVo.getTargetSettingNodeDto().getSecondaryRuleId());
|
||||
baseRuleService.deleteBaseRuleByIds(baseRuleIds);
|
||||
}
|
||||
|
||||
// 重新保存新条件
|
||||
MarketingEngineContentVo marketingEngineContentVo = versionContent.getMarketingEngineContentVo();
|
||||
// 受众用户节点
|
||||
AudienceNodeDto audienceNodeDto = marketingEngineContentVo.getAudienceNodeDto();
|
||||
BaseRule baseRule = audienceNodeDto.getBaseRule();
|
||||
audienceNodeDto.setBaseRuleId(saveMarketingEngineBaseRule(baseRule));
|
||||
audienceNodeDto.setBaseRule(null);
|
||||
// 触达配置节点
|
||||
List<TouchConfigNodeDto> touchConfigNodeDtoList = marketingEngineContentVo.getTouchConfigNodeDtoList();
|
||||
for (TouchConfigNodeDto touchConfigNodeDto : touchConfigNodeDtoList) {
|
||||
BaseRule userSelectRule = touchConfigNodeDto.getUserSelectRule();
|
||||
touchConfigNodeDto.setUserSelectRuleId(saveMarketingEngineBaseRule(userSelectRule));
|
||||
touchConfigNodeDto.setUserSelectRule(null);
|
||||
}
|
||||
// 目标设置节点
|
||||
TargetSettingNodeDto targetSettingNodeDto = marketingEngineContentVo.getTargetSettingNodeDto();
|
||||
BaseRule primaryRule = targetSettingNodeDto.getPrimaryRule();
|
||||
targetSettingNodeDto.setPrimaryRuleId(saveMarketingEngineBaseRule(primaryRule));
|
||||
targetSettingNodeDto.setPrimaryRule(null);
|
||||
BaseRule secondaryRule = targetSettingNodeDto.getSecondaryRule();
|
||||
targetSettingNodeDto.setSecondaryRuleId(saveMarketingEngineBaseRule(secondaryRule));
|
||||
targetSettingNodeDto.setSecondaryRule(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存营销引擎条件
|
||||
* @param baseRule
|
||||
* @return
|
||||
*/
|
||||
private Long saveMarketingEngineBaseRule(BaseRule baseRule){
|
||||
if (baseRule != null) {
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
baseRule.setRuleType(BaseRuleTypeEnum.MARKETING_ENGINE.getType());
|
||||
baseRule.setOrganId(loginAccount.getOrganId());
|
||||
baseRule.setCreateUserId(loginAccount.getUserId());
|
||||
boolean result = baseRuleService.insertBaseRule(baseRule);
|
||||
if (!result) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "营销引擎节点条件块保存失败");
|
||||
}
|
||||
}
|
||||
return baseRule.getId();
|
||||
}
|
||||
|
||||
private void handlerEngineScript(EngineVersionContentVo versionContent) {
|
||||
if (versionContent != null && StringUtils.isNotBlank(versionContent.getEngineContent())) {
|
||||
//拼装执行条件
|
||||
JSONObject engineJson = JSON.parseObject(versionContent.getEngineContent());
|
||||
JSONArray nodeList = engineJson.getJSONArray(EngineContentConst.NODE_LIST_KEY);
|
||||
for (int i = 0; i < nodeList.size(); i++) {
|
||||
JSONObject node = nodeList.getJSONObject(i);
|
||||
String nodeType = node.getString(EngineContentConst.DataFlowEngine.NODE_TYPE);
|
||||
switch (nodeType) {
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.BEGIN:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.WHERE:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.OR:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.WITHIN:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.NEXT:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.FOLLOWED_BY:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.ONE_OR_MORE:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.TIMES:
|
||||
|
||||
break;
|
||||
case EngineContentConst
|
||||
.DataFlowEngine
|
||||
.NodeType.TIMES_OR_MORE:
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
package com.fibo.ddp.common.service.enginex.dataflow.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.risk.EngineVersionMapper;
|
||||
import com.fibo.ddp.common.model.authx.system.SysUser;
|
||||
import com.fibo.ddp.common.model.common.enums.ErrorCodeEnum;
|
||||
import com.fibo.ddp.common.model.common.requestParam.QueryListParam;
|
||||
import com.fibo.ddp.common.model.enginex.dataflow.vo.EngineVersionContentVo;
|
||||
import com.fibo.ddp.common.model.enginex.risk.EngineVersion;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineNodeServiceV3;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineVersionContentService;
|
||||
import com.fibo.ddp.common.service.enginex.dataflow.EngineVersionServiceV3;
|
||||
import com.fibo.ddp.common.utils.constant.StatusConst;
|
||||
import com.fibo.ddp.common.utils.constant.enginex.EngineTypeConst;
|
||||
import com.fibo.ddp.common.utils.exception.ApiException;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 不同场景下的多个模型版本(EngineVersion)表服务实现类
|
||||
*
|
||||
* @author jgp
|
||||
* @since 2021-12-22 14:39:33
|
||||
*/
|
||||
@Service("engineVersionServiceV3")
|
||||
public class EngineVersionServiceV3Impl extends ServiceImpl<EngineVersionMapper, EngineVersion> implements EngineVersionServiceV3 {
|
||||
|
||||
@Autowired
|
||||
private EngineNodeServiceV3 engineNodeServiceV3;
|
||||
@Autowired
|
||||
private EngineVersionContentService engineVersionContentService;
|
||||
|
||||
/**
|
||||
* 根据主表获取完整信息:包含子表内容
|
||||
*
|
||||
* @param versionId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public EngineVersion queryById(Long versionId) {
|
||||
if (versionId == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "参数异常:版本id为空");
|
||||
}
|
||||
EngineVersion result = this.getById(versionId);
|
||||
if (result != null) {
|
||||
this.queryDetailInfoSetToParam(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询列表根据入参决定是否分页
|
||||
*
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageInfo queryList(QueryListParam<EngineVersion> param) {
|
||||
if (QueryListParam.checkIsPage(param)) {
|
||||
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
||||
}
|
||||
LambdaQueryWrapper<EngineVersion> wrapper = this.createWrapper(param.getEntity());
|
||||
PageInfo pageInfo = new PageInfo<>(this.list(wrapper));
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EngineVersion> queryByEngineIds(Collection<Long> engineIds) {
|
||||
LambdaQueryWrapper<EngineVersion> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(EngineVersion::getEngineId,engineIds);
|
||||
wrapper.ne(EngineVersion::getStatus, StatusConst.STATUS_DELETE);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EngineVersion> queryByEngineId(Long engineId) {
|
||||
LambdaQueryWrapper<EngineVersion> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EngineVersion::getEngineId,engineId);
|
||||
wrapper.ne(EngineVersion::getStatus,StatusConst.STATUS_DELETE);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态,用于假删
|
||||
*
|
||||
* @param ids
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean updateStatus(List<Long> ids, Integer status) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个引擎的版本
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public synchronized boolean addEngineVersion(EngineVersion param) {
|
||||
if (param == null
|
||||
|| param.getEngineId() == null
|
||||
|| StringUtils.isBlank(param.getEngineType())) {
|
||||
return false;
|
||||
}
|
||||
EngineVersion engineVersion = this.getLatestEngineSubVersion(param);
|
||||
|
||||
Integer subVersion = engineVersion == null || engineVersion.getSubVersion() == null ? 0 : engineVersion.getSubVersion() + 1; // 子版本 +1
|
||||
//无论引擎是否正在运行,皆在此版本下创建子版本
|
||||
param.setBootState(0);
|
||||
param.setCreateTime(new Date().toString());
|
||||
param.setSubVersion(subVersion);
|
||||
this.initEngine(param);
|
||||
boolean saveVersionResult = this.save(param);
|
||||
boolean result = false;
|
||||
if (saveVersionResult) {
|
||||
result =this.addDetailInfo(param);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 赋值一个引擎版本
|
||||
*
|
||||
* @param versionId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean copyEngineVersion(Long versionId) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增修改初始化
|
||||
*
|
||||
* @param EngineVersion
|
||||
*/
|
||||
private void initEngine(EngineVersion EngineVersion) {
|
||||
if (EngineVersion == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "引擎版本不能为nll");
|
||||
}
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
EngineVersion.setLatestTime(new Date().toString());
|
||||
EngineVersion.setLayout(0);
|
||||
EngineVersion.setLatestUser(loginAccount.getUserId());
|
||||
EngineVersion.setUserId(loginAccount.getUserId());
|
||||
EngineVersion.setStatus(StatusConst.STATUS_ENABLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
private LambdaQueryWrapper<EngineVersion> createWrapper(EngineVersion entity) {
|
||||
LambdaQueryWrapper<EngineVersion> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.orderByDesc(EngineVersion::getVersionId);
|
||||
if (entity == null || entity.getEngineId() == null) {
|
||||
throw new ApiException(ErrorCodeEnum.PARAMS_EXCEPTION.getCode(), "查询引擎版本需要引擎id");
|
||||
}
|
||||
if (entity.getStatus() != null) {
|
||||
wrapper.eq(EngineVersion::getStatus, entity.getStatus());
|
||||
} else {
|
||||
wrapper.ne(EngineVersion::getStatus, StatusConst.STATUS_DELETE);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最后一个子版本用于新版本自增
|
||||
*
|
||||
* @param entity
|
||||
* @return
|
||||
*/
|
||||
private EngineVersion getLatestEngineSubVersion(EngineVersion entity) {
|
||||
LambdaQueryWrapper<EngineVersion> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EngineVersion::getEngineId, entity.getEngineId());
|
||||
wrapper.eq(EngineVersion::getVersion, entity.getVersion());
|
||||
wrapper.orderByDesc(EngineVersion::getSubVersion);
|
||||
return this.getOne(wrapper, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数查出子级内容并且装配
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
private boolean queryDetailInfoSetToParam(EngineVersion param) {
|
||||
boolean result = false;
|
||||
if (param == null || StringUtils.isBlank(param.getEngineType())) {
|
||||
return result;
|
||||
}
|
||||
result = true;
|
||||
switch (param.getEngineType()){
|
||||
case EngineTypeConst
|
||||
.RULE_ENGINE:
|
||||
param.setEngineNodeList(engineNodeServiceV3.queryNodeListByVersion(param.getVersionId()));
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.RISK_CONTROL_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.DATA_FLOW_ENGINE:
|
||||
param.setEngineVersionContent(engineVersionContentService.queryById(param.getVersionId()));
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.PERSONAS_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.MARKETING_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.WARNING_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.SCORING_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.LOGIC_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.QUESTIONNAIRE_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.PAGE_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.MATCHING_ENGINE:
|
||||
break;
|
||||
default:
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加子级详情表的内容
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
private boolean addDetailInfo(EngineVersion param) {
|
||||
boolean result = false;
|
||||
if (param == null || StringUtils.isBlank(param.getEngineType())) {
|
||||
return result;
|
||||
}
|
||||
SysUser loginAccount = SessionManager.getLoginAccount();
|
||||
EngineVersionContentVo engineVersionContent;
|
||||
switch (param.getEngineType()){
|
||||
case EngineTypeConst
|
||||
.RULE_ENGINE:
|
||||
result = engineNodeServiceV3.saveStartNode(param.getVersionId());
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.RISK_CONTROL_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.DATA_FLOW_ENGINE:
|
||||
case EngineTypeConst
|
||||
.PERSONAS_ENGINE:
|
||||
case EngineTypeConst
|
||||
.MARKETING_ENGINE:
|
||||
engineVersionContent = new EngineVersionContentVo();
|
||||
engineVersionContent.setEngineVersionId(param.getVersionId());
|
||||
engineVersionContent.setEngineType(param.getEngineType());
|
||||
engineVersionContent.setCreateUserId(loginAccount.getUserId());
|
||||
result = engineVersionContentService.addVersionContent(engineVersionContent);
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.WARNING_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.SCORING_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.LOGIC_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.QUESTIONNAIRE_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.PAGE_ENGINE:
|
||||
break;
|
||||
case EngineTypeConst
|
||||
.MATCHING_ENGINE:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeDateResult;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 营销引擎节点当天结果表(MarketingEngineNodeDateResult)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
public interface MarketingEngineNodeDateResultService extends IService<MarketingEngineNodeDateResult> {
|
||||
|
||||
List<MarketingEngineNodeDateResult> getNodeDateResultByDate(Integer engineVersionId, Date startDate, Date endDate);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 营销引擎节点结果表(MarketingEngineNodeResult)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
public interface MarketingEngineNodeResultService extends IService<MarketingEngineNodeResult> {
|
||||
|
||||
List<MarketingEngineNodeResult> getNodeResultByVersionId(Integer engineVersionId);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineResult;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.vo.MarketingDataResultReqVo;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.vo.MarketingDataResultRspVo;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.vo.MarketingListResultReqVo;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
/**
|
||||
* 营销引擎结果表(MarketingEngineResult)表服务接口
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
public interface MarketingEngineResultService extends IService<MarketingEngineResult> {
|
||||
|
||||
PageInfo<MarketingEngineResult> getListByPage(MarketingListResultReqVo param);
|
||||
|
||||
MarketingDataResultRspVo getEngineDataByDate(MarketingDataResultReqVo param);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.marketing.MarketingEngineNodeDateResultMapper;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeDateResult;
|
||||
import com.fibo.ddp.common.service.enginex.marketing.MarketingEngineNodeDateResultService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 营销引擎节点当天结果表(MarketingEngineNodeDateResult)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
@Service
|
||||
public class MarketingEngineNodeDateResultServiceImpl extends ServiceImpl<MarketingEngineNodeDateResultMapper, MarketingEngineNodeDateResult> implements MarketingEngineNodeDateResultService {
|
||||
|
||||
@Override
|
||||
public List<MarketingEngineNodeDateResult> getNodeDateResultByDate(Integer engineVersionId, Date startDate, Date endDate) {
|
||||
LambdaQueryWrapper<MarketingEngineNodeDateResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MarketingEngineNodeDateResult::getEngineVersionId, engineVersionId);
|
||||
if (startDate != null && endDate != null) {
|
||||
queryWrapper.between(MarketingEngineNodeDateResult::getCurrentDate, startDate, endDate);
|
||||
}
|
||||
List<MarketingEngineNodeDateResult> list = this.list(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.marketing.MarketingEngineNodeResultMapper;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeResult;
|
||||
import com.fibo.ddp.common.service.enginex.marketing.MarketingEngineNodeResultService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 营销引擎节点结果表(MarketingEngineNodeResult)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
@Service
|
||||
public class MarketingEngineNodeResultServiceImpl extends ServiceImpl<MarketingEngineNodeResultMapper, MarketingEngineNodeResult> implements MarketingEngineNodeResultService {
|
||||
|
||||
@Override
|
||||
public List<MarketingEngineNodeResult> getNodeResultByVersionId(Integer engineVersionId) {
|
||||
LambdaQueryWrapper<MarketingEngineNodeResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MarketingEngineNodeResult::getEngineVersionId, engineVersionId);
|
||||
List<MarketingEngineNodeResult> list = this.list(queryWrapper);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
package com.fibo.ddp.common.service.enginex.marketing.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.fibo.ddp.common.dao.enginex.marketing.MarketingEngineResultMapper;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeDateResult;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineNodeResult;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.entity.MarketingEngineResult;
|
||||
import com.fibo.ddp.common.model.enginex.marketing.vo.*;
|
||||
import com.fibo.ddp.common.service.common.SessionManager;
|
||||
import com.fibo.ddp.common.service.enginex.marketing.MarketingEngineNodeDateResultService;
|
||||
import com.fibo.ddp.common.service.enginex.marketing.MarketingEngineNodeResultService;
|
||||
import com.fibo.ddp.common.service.enginex.marketing.MarketingEngineResultService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 营销引擎结果表(MarketingEngineResult)表服务实现类
|
||||
*
|
||||
* @author andy.wang
|
||||
* @since 2022-01-07 18:13:24
|
||||
*/
|
||||
@Service
|
||||
public class MarketingEngineResultServiceImpl extends ServiceImpl<MarketingEngineResultMapper, MarketingEngineResult> implements MarketingEngineResultService {
|
||||
|
||||
@Autowired
|
||||
private MarketingEngineNodeDateResultService nodeDateResultService;
|
||||
@Autowired
|
||||
private MarketingEngineNodeResultService nodeResultService;
|
||||
|
||||
@Override
|
||||
public PageInfo<MarketingEngineResult> getListByPage(MarketingListResultReqVo param) {
|
||||
Long organId = SessionManager.getLoginAccount().getOrganId();
|
||||
PageHelper.startPage(param.getPageNo(), param.getPageSize());
|
||||
LambdaQueryWrapper<MarketingEngineResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MarketingEngineResult::getOrganId, organId);
|
||||
String searchKey = param.getSearchKey();
|
||||
if (StringUtils.isNotBlank(searchKey)) {
|
||||
queryWrapper.and(i -> i.like(MarketingEngineResult::getEngineId, searchKey).or()
|
||||
.like(MarketingEngineResult::getEngineName, searchKey));
|
||||
}
|
||||
List<MarketingEngineResult> list = this.list(queryWrapper);
|
||||
PageInfo<MarketingEngineResult> pageInfo = new PageInfo<>(list);
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarketingDataResultRspVo getEngineDataByDate(MarketingDataResultReqVo param) {
|
||||
MarketingDataResultRspVo marketingDataResultRspVo = null;
|
||||
Integer engineVersionId = param.getEngineVersionId();
|
||||
Date startDate = param.getStartDate();
|
||||
Date endDate = param.getEndDate();
|
||||
if (startDate != null && endDate != null) {
|
||||
// 根据时间维度查询引擎统计数据
|
||||
marketingDataResultRspVo = getEngineResultByDate(engineVersionId, startDate, endDate);
|
||||
} else {
|
||||
// 从表中查询引擎统计好的数据
|
||||
marketingDataResultRspVo = getEngineResultByVersionId(engineVersionId);
|
||||
}
|
||||
return marketingDataResultRspVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从表中查询引擎统计好的数据
|
||||
*
|
||||
* @param engineVersionId
|
||||
* @return
|
||||
*/
|
||||
public MarketingDataResultRspVo getEngineResultByVersionId(Integer engineVersionId) {
|
||||
MarketingDataResultRspVo dataResultRspVo = new MarketingDataResultRspVo();
|
||||
LambdaQueryWrapper<MarketingEngineResult> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MarketingEngineResult::getEngineVersionId, engineVersionId);
|
||||
List<MarketingEngineResult> list = this.list(queryWrapper);
|
||||
if (list != null && !list.isEmpty()) {
|
||||
MarketingEngineResult engineResult = list.get(0);
|
||||
dataResultRspVo = JSONObject.parseObject(JSONObject.toJSONString(engineResult), MarketingDataResultRspVo.class);
|
||||
List<MarketingEngineNodeResult> nodeResultList = nodeResultService.getNodeResultByVersionId(engineVersionId);
|
||||
List<MarketingEngineNodeDateResult> nodeDateResultList = nodeDateResultService.getNodeDateResultByDate(engineVersionId, null, null);
|
||||
Map<Integer, List<MarketingEngineNodeDateResult>> nodeDateResultMap = nodeDateResultList.stream().collect(Collectors.groupingBy(item -> item.getNodeId()));
|
||||
List<MarketingNodeResultRspVo> nodeResultRspVoList = new ArrayList<>();
|
||||
// 组装引擎节点中按天的统计信息
|
||||
for (MarketingEngineNodeResult nodeResult : nodeResultList) {
|
||||
MarketingNodeResultRspVo nodeResultRspVo = JSONObject.parseObject(JSONObject.toJSONString(nodeResult), MarketingNodeResultRspVo.class);
|
||||
Integer nodeId = nodeResult.getNodeId();
|
||||
if (nodeDateResultMap != null && nodeDateResultMap.containsKey(nodeId)) {
|
||||
List<MarketingEngineNodeDateResult> engineNodeDateResults = nodeDateResultMap.get(nodeId);
|
||||
List<MarketingNodeDateResultRspVo> nodeDateResultRspVoList = JSONObject.parseArray(JSONObject.toJSONString(engineNodeDateResults), MarketingNodeDateResultRspVo.class);
|
||||
nodeResultRspVo.setNodeDateResultRspVoList(nodeDateResultRspVoList);
|
||||
}
|
||||
nodeResultRspVoList.add(nodeResultRspVo);
|
||||
}
|
||||
dataResultRspVo.setNodeResultRspVoList(nodeResultRspVoList);
|
||||
}
|
||||
return dataResultRspVo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间维度查询引擎统计数据
|
||||
*
|
||||
* @param engineVersionId
|
||||
* @param startDate
|
||||
* @param endDate
|
||||
* @return
|
||||
*/
|
||||
public MarketingDataResultRspVo getEngineResultByDate(Integer engineVersionId, Date startDate, Date endDate) {
|
||||
MarketingDataResultRspVo dataResultRspVo = new MarketingDataResultRspVo();
|
||||
List<MarketingEngineNodeDateResult> nodeDateResultList = nodeDateResultService.getNodeDateResultByDate(engineVersionId, startDate, endDate);
|
||||
if (nodeDateResultList != null && nodeDateResultList.isEmpty()) {
|
||||
List<MarketingNodeResultRspVo> nodeResultRspVoList = new ArrayList<>();
|
||||
int engineEnterNum = 0;
|
||||
int engineTouchNum = 0;
|
||||
int engineCompleteNum = 0;
|
||||
Map<Integer, List<MarketingEngineNodeDateResult>> nodeDateResultMap = nodeDateResultList.stream().collect(Collectors.groupingBy(item -> item.getNodeId()));
|
||||
for (Integer nodeId : nodeDateResultMap.keySet()) {
|
||||
MarketingNodeResultRspVo nodeResultRspVo = new MarketingNodeResultRspVo();
|
||||
List<MarketingEngineNodeDateResult> engineNodeDateResults = nodeDateResultMap.get(nodeId);
|
||||
int enterNum = 0;
|
||||
int touchNum = 0;
|
||||
int completeNum = 0;
|
||||
for (MarketingEngineNodeDateResult nodeDateResult : engineNodeDateResults) {
|
||||
enterNum += nodeDateResult.getEnterNum();
|
||||
touchNum += nodeDateResult.getTouchNum();
|
||||
completeNum += nodeDateResult.getCompleteNum();
|
||||
}
|
||||
float completeRate = completeNum / enterNum;
|
||||
nodeResultRspVo.setNodeId(nodeId);
|
||||
nodeResultRspVo.setEnterNum(enterNum);
|
||||
nodeResultRspVo.setTouchNum(touchNum);
|
||||
nodeResultRspVo.setCompleteNum(completeNum);
|
||||
nodeResultRspVo.setCompleteRate(completeRate);
|
||||
List<MarketingNodeDateResultRspVo> nodeDateResultRspVoList = JSONObject.parseArray(JSONObject.toJSONString(engineNodeDateResults), MarketingNodeDateResultRspVo.class);
|
||||
nodeResultRspVo.setNodeDateResultRspVoList(nodeDateResultRspVoList);
|
||||
nodeResultRspVoList.add(nodeResultRspVo);
|
||||
|
||||
engineEnterNum += enterNum;
|
||||
engineTouchNum += touchNum;
|
||||
engineCompleteNum += completeNum;
|
||||
}
|
||||
float engineCompleteRate = engineCompleteNum / engineEnterNum;
|
||||
dataResultRspVo.setEngineVersionId(engineVersionId);
|
||||
dataResultRspVo.setEnterNum(engineEnterNum);
|
||||
dataResultRspVo.setTouchNum(engineTouchNum);
|
||||
dataResultRspVo.setCompleteNum(engineCompleteNum);
|
||||
dataResultRspVo.setCompleteRate(engineCompleteRate);
|
||||
dataResultRspVo.setNodeResultRspVoList(nodeResultRspVoList);
|
||||
}
|
||||
return dataResultRspVo;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user