package com.highdatas.mdm.service.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.highdatas.mdm.entity.TQualityRule; import com.highdatas.mdm.mapper.TQualityRuleMapper; import com.highdatas.mdm.pojo.CodeMsg; import com.highdatas.mdm.pojo.Result; import com.highdatas.mdm.service.ITQualityRuleService; import com.highdatas.mdm.service.MasterDataService; import com.highdatas.mdm.util.Constant; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; /** *

* 规则表 服务实现类 *

* * @author kimi * @since 2019-12-18 */ @Service public class TQualityRuleServiceImpl extends ServiceImpl implements ITQualityRuleService { @Autowired MasterDataService masterDataService; @Override public Result rule(String tableName, String field, String ruleId) { if (StringUtils.isEmpty(field)) { return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED); } TQualityRule tQualityRule = selectOne(new EntityWrapper().eq("rule_id", ruleId)); if (tQualityRule == null) { return Result.error(CodeMsg.SELECT_ERROR_NOTFOUND); } String[] split = field.split(Constant.COMMA_TRIM); List collect = Arrays.stream(split).collect(Collectors.toList()); Result result = masterDataService.selectList(tableName, collect); JSONObject object = (JSONObject)result.getData(); List> datas = (List>) object.get("grid"); String codeContent = tQualityRule.getCodeContent(); int total = datas.size(); int matched = 0; for (Map data : datas) { if (data == null) { continue; } String tableVal = String.valueOf(data.get(field)); boolean matches = Pattern.matches(codeContent, tableVal); if (matches) { matched++; } } HashMap resultMap = new HashMap<>(); resultMap.put("total", total); resultMap.put("matched", matched); return Result.success(resultMap); } }