|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import edp.core.exception.NotFoundException;
|
|
|
import edp.core.exception.ServerException;
|
|
|
import edp.core.utils.SqlUtils;
|
|
|
+import edp.davinci.core.enums.LogNameEnum;
|
|
|
import edp.davinci.dao.QualityAuditorMapper;
|
|
|
import edp.davinci.dao.QualityTaskMapper;
|
|
|
import edp.davinci.dao.SourceMapper;
|
|
@@ -16,6 +17,8 @@ import edp.davinci.service.DataSubjectService;
|
|
|
import edp.davinci.service.QualityAuditorService;
|
|
|
import edp.davinci.service.QualityTaskService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -29,6 +32,7 @@ import java.util.Map;
|
|
|
@Service("qualityTaskService")
|
|
|
public class QualityTaskServiceImpl implements QualityTaskService
|
|
|
{
|
|
|
+ private static final Logger optLogger = LoggerFactory.getLogger(LogNameEnum.BUSINESS_OPERATION.getName());
|
|
|
@Autowired
|
|
|
private QualityTaskMapper qualityTaskMapper;
|
|
|
|
|
@@ -91,6 +95,12 @@ public class QualityTaskServiceImpl implements QualityTaskService
|
|
|
String metadataConfig = qualityTask.getMetadataConfig();
|
|
|
|
|
|
JSONArray jsonArray = JSONObject.parseArray(metadataConfig);
|
|
|
+
|
|
|
+ // 稽核
|
|
|
+ QualityAuditor qualityAuditor = new QualityAuditor();
|
|
|
+ qualityAuditor.setAuditorTime(new Date());
|
|
|
+ qualityAuditor.setTaskId(qualityTask.getId());
|
|
|
+
|
|
|
// 遍历JSONArray
|
|
|
for (Iterator<Object> iterator = jsonArray.iterator(); iterator.hasNext(); )
|
|
|
{
|
|
@@ -113,57 +123,81 @@ public class QualityTaskServiceImpl implements QualityTaskService
|
|
|
{
|
|
|
throw new ServerException("id 为 " + subjectId + " 数据规则不存在 ");
|
|
|
}
|
|
|
- StringBuilder sql = new StringBuilder(view.getSql());
|
|
|
+ JSONObject ruleConfig = JSONObject.parseObject(dataRules.getRuleConfig());
|
|
|
String inspectionType = dataRules.getInspectionType();
|
|
|
- QualityAuditor qualityAuditor = new QualityAuditor();
|
|
|
- qualityAuditor.setAuditorTime(new Date());
|
|
|
|
|
|
- // 符合条件的
|
|
|
+ StringBuilder sql = new StringBuilder("select * from (" + view.getSql() + " ) v where 1 =1 ");
|
|
|
List<Map<String, Object>> result = sqlUtils.query4List(sql.toString(), -1);
|
|
|
-
|
|
|
if (dataRules.getRuleType().equalsIgnoreCase("not_null"))
|
|
|
{
|
|
|
// 非空
|
|
|
+ sql.append(" and ");
|
|
|
+ sql.append("v." + fieldName + " is not null ");
|
|
|
|
|
|
}
|
|
|
if (dataRules.getRuleType().equalsIgnoreCase("range"))
|
|
|
{
|
|
|
// 值域
|
|
|
-
|
|
|
+ sql.append(" and ");
|
|
|
+ sql.append("v." + fieldName + " > " + ruleConfig.get("from"));
|
|
|
+ sql.append("v." + fieldName + " < " + ruleConfig.get("to"));
|
|
|
}
|
|
|
if (dataRules.getRuleType().equalsIgnoreCase("length"))
|
|
|
{
|
|
|
// 长度
|
|
|
-
|
|
|
+ sql.append(" and len(v.");
|
|
|
+ sql.append(fieldName + ") < " + ruleConfig.get("length"));
|
|
|
}
|
|
|
if (dataRules.getRuleType().equalsIgnoreCase("date_format"))
|
|
|
{
|
|
|
// 日期格式
|
|
|
+ sql.append(" and ");
|
|
|
+ sql.append(fieldName + " is not null ");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 符合条件的
|
|
|
+ List<Map<String, Object>> newResult = sqlUtils.query4List(sql.toString(), -1);
|
|
|
|
|
|
+ // 计算
|
|
|
+ if (result == null || newResult == null)
|
|
|
+ {
|
|
|
+ throw new ServerException("稽核数据不存在;sql:" + sql);
|
|
|
}
|
|
|
- if (inspectionType.equalsIgnoreCase("integrity"))
|
|
|
- { // 完整性
|
|
|
|
|
|
- qualityAuditor.setIntegrityCorrect(1);
|
|
|
+ if (result.size() == 0)
|
|
|
+ {
|
|
|
+
|
|
|
+ throw new ServerException("稽核数据不存在;sql:" + sql);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (inspectionType.equalsIgnoreCase("integrity"))
|
|
|
+ {
|
|
|
+ // 完整性
|
|
|
+ qualityAuditor.setIntegrityCorrect(newResult.size());
|
|
|
qualityAuditor.setIntegrityError(1);
|
|
|
}
|
|
|
if (inspectionType.equalsIgnoreCase("uniformity"))
|
|
|
- { // 一致性
|
|
|
+ {
|
|
|
+ // 一致性
|
|
|
qualityAuditor.setUniformityCorrect(1);
|
|
|
qualityAuditor.setUniformityError(1);
|
|
|
}
|
|
|
if (inspectionType.equalsIgnoreCase("normative"))
|
|
|
- { // 规范性
|
|
|
+ {
|
|
|
+ // 规范性
|
|
|
qualityAuditor.setNormativeCorrect(1);
|
|
|
qualityAuditor.setNormativeError(1);
|
|
|
}
|
|
|
if (inspectionType.equalsIgnoreCase("accuracy"))
|
|
|
- { // 准确性
|
|
|
+ {
|
|
|
+ // 准确性
|
|
|
qualityAuditor.setAccuracyCorrect(1);
|
|
|
qualityAuditor.setAccuracyError(1);
|
|
|
}
|
|
|
- qualityAuditorMapper.insert(qualityAuditor);
|
|
|
}
|
|
|
+
|
|
|
+ qualityAuditorMapper.insert(qualityAuditor);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private Source getSource(Long id)
|