Commit b0f6c5ac by 刘泽志

已经完成字段与规则同步,需要改造的:

1:自动生成表
2:导入四舍五入测试
3:插入sql更新
4:导入数据要先清除本年度数据
5:机构字典
parent 4b6184fa
...@@ -14,10 +14,7 @@ import com.tbyf.his.web.dataImport.domain.param.AddFieldParam; ...@@ -14,10 +14,7 @@ import com.tbyf.his.web.dataImport.domain.param.AddFieldParam;
import com.tbyf.his.web.dataImport.domain.param.QueryFieldParam; import com.tbyf.his.web.dataImport.domain.param.QueryFieldParam;
import com.tbyf.his.web.dataImport.domain.param.QueryMetaFieldParam; import com.tbyf.his.web.dataImport.domain.param.QueryMetaFieldParam;
import com.tbyf.his.web.dataImport.domain.param.UpdateFieldParam; import com.tbyf.his.web.dataImport.domain.param.UpdateFieldParam;
import com.tbyf.his.web.dataImport.entity.BindRule; import com.tbyf.his.web.dataImport.entity.*;
import com.tbyf.his.web.dataImport.entity.DataField;
import com.tbyf.his.web.dataImport.entity.ExcelData;
import com.tbyf.his.web.dataImport.entity.MetaField;
import com.tbyf.his.web.dataImport.service.*; import com.tbyf.his.web.dataImport.service.*;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -55,6 +52,9 @@ public class DataFieldController { ...@@ -55,6 +52,9 @@ public class DataFieldController {
private BindRuleService bindRuleService; private BindRuleService bindRuleService;
@Autowired @Autowired
private DataTemplateService dataTemplateService;
@Autowired
private ExcelDataService excelDataService; private ExcelDataService excelDataService;
@Autowired @Autowired
...@@ -110,11 +110,19 @@ public class DataFieldController { ...@@ -110,11 +110,19 @@ public class DataFieldController {
@IgnoreWebSecurity @IgnoreWebSecurity
@GetMapping("/reset") @GetMapping("/reset")
@ApiOperation("根据基础模板重置字段") @ApiOperation("根据基础模板重置字段")
public AjaxResult resetField(@RequestParam String excelId) { public AjaxResult resetField(@RequestParam String excelId, @RequestParam(required = false) String year) {
final ExcelData excelData = excelDataService.getById(excelId); final ExcelData excelData = excelDataService.getById(excelId);
// 获取待匹配的字段 // 获取元字段列表
final List<MetaField> metaFields = metaFieldService.list(); final List<MetaField> metaFields = metaFieldService.list();
List<DataField> fieldMatchList = dataFieldService.listFieldMatchList(excelData.getTemplateId()); // 获取需要同步的字段列表
List<DataField> fieldMatchList = null;
if (StringUtils.isNotBlank(year)) {
DataTemplate template = dataTemplateService.getOne(Wrappers.lambdaQuery(DataTemplate.class)
.eq(DataTemplate::getYear, year).eq(DataTemplate::getOrgName, excelData.getOrgName()), false);
fieldMatchList = dataFieldService.list(Wrappers.lambdaQuery(DataField.class)
.eq(DataField::getTemplateId, template.getId()).isNotNull(DataField::getField));
}
// 删除掉之前的模板信息
final LambdaQueryWrapper<DataField> wrapper = Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, excelData.getTemplateId()); final LambdaQueryWrapper<DataField> wrapper = Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, excelData.getTemplateId());
final List<DataField> list = dataFieldService.list(wrapper); final List<DataField> list = dataFieldService.list(wrapper);
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
......
...@@ -18,9 +18,11 @@ import com.tbyf.his.web.dataImport.domain.param.UpdateRuleParam; ...@@ -18,9 +18,11 @@ import com.tbyf.his.web.dataImport.domain.param.UpdateRuleParam;
import com.tbyf.his.web.dataImport.entity.BindRule; import com.tbyf.his.web.dataImport.entity.BindRule;
import com.tbyf.his.web.dataImport.entity.DataField; import com.tbyf.his.web.dataImport.entity.DataField;
import com.tbyf.his.web.dataImport.entity.DataRule; import com.tbyf.his.web.dataImport.entity.DataRule;
import com.tbyf.his.web.dataImport.entity.DataTemplate;
import com.tbyf.his.web.dataImport.service.BindRuleService; import com.tbyf.his.web.dataImport.service.BindRuleService;
import com.tbyf.his.web.dataImport.service.DataFieldService; import com.tbyf.his.web.dataImport.service.DataFieldService;
import com.tbyf.his.web.dataImport.service.DataRuleService; import com.tbyf.his.web.dataImport.service.DataRuleService;
import com.tbyf.his.web.dataImport.service.DataTemplateService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -30,8 +32,7 @@ import org.springframework.util.CollectionUtils; ...@@ -30,8 +32,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Collections; import java.util.*;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -53,6 +54,9 @@ public class DataRuleController { ...@@ -53,6 +54,9 @@ public class DataRuleController {
@Autowired @Autowired
private DataFieldService dataFieldService; private DataFieldService dataFieldService;
@Autowired
private DataTemplateService dataTemplateService;
@IgnoreWebSecurity @IgnoreWebSecurity
@GetMapping("") @GetMapping("")
@ApiOperation("规则查询") @ApiOperation("规则查询")
...@@ -174,4 +178,96 @@ public class DataRuleController { ...@@ -174,4 +178,96 @@ public class DataRuleController {
return AjaxResult.success(); return AjaxResult.success();
} }
@IgnoreWebSecurity
@GetMapping("/sync/year")
@ApiOperation("根据年份同步规则")
public AjaxResult syncRuleByYear(@RequestParam String templateId, @RequestParam String year) {
// 查询两个模板
DataTemplate sourceTemplate = dataTemplateService.getById(templateId);
DataTemplate targetTemplate = dataTemplateService.getOne(Wrappers.lambdaQuery(DataTemplate.class).eq(DataTemplate::getYear, year).eq(DataTemplate::getOrgName, sourceTemplate.getOrgName()), false);
List<DataField> fieldList = dataFieldService.list(Wrappers.lambdaQuery(DataField.class)
.eq(DataField::getTemplateId, sourceTemplate.getId())
.isNotNull(DataField::getField)
.select(DataField::getField, DataField::getId));
List<DataField> targetFieldList = dataFieldService.list(Wrappers.lambdaQuery(DataField.class)
.eq(DataField::getTemplateId, targetTemplate.getId())
.isNotNull(DataField::getField)
.select(DataField::getField, DataField::getId));
if (!CollectionUtils.isEmpty(fieldList)) {
List<BindRule> rules = new ArrayList<>();
List<BindRule> sourceBindList = bindRuleService.queryRuleList(sourceTemplate.getId());
List<BindRule> targetBindList = bindRuleService.queryRuleList(targetTemplate.getId());
// 字段规则同步
if (!CollectionUtils.isEmpty(targetBindList)) {
for (BindRule targetRule : targetBindList) {
Optional<DataField> first = fieldList.stream().filter(df -> StringUtils.equals(df.getField(), targetRule.getDataId())).findFirst();
if (first.isPresent()) {
boolean match = sourceBindList.stream()
.anyMatch(br -> StringUtils.equals(br.getDataId(), targetRule.getDataId()) && StringUtils.equals(br.getRuleId(), targetRule.getRuleId()));
if (!match) {
rules.add(new BindRule(first.get().getId(), targetRule.getRuleId()));
}
}
}
}
// 模板规则同步
List<DataRule> sourceRules = dataRuleService.queryTemplateRules(sourceTemplate.getId());
List<DataRule> targetRules = dataRuleService.queryTemplateRules(targetTemplate.getId());
if (!CollectionUtils.isEmpty(targetRules)) {
List<DataRule> datas = new ArrayList<>();
root:
for (DataRule targetRule : targetRules) {
String[] split = targetRule.getContent().split("=");
String[] split1 = split[0].split(",");
String[] split2 = split[1].split(",");
for (int i = 0; i < split1.length; i++) {
int finalI = i;
Optional<DataField> first = targetFieldList.stream().filter(item -> StringUtils.equals(item.getId(), split1[finalI])).findFirst();
if (first.isPresent()) {
Optional<DataField> first1 = fieldList.stream().filter(item -> StringUtils.equals(item.getField(), first.get().getField())).findFirst();
if (first1.isPresent()) {
split1[i] = first1.get().getId();
} else {
continue root;
}
} else {
continue root;
}
}
for (int j = 0; j < split2.length; j++) {
int finalI = j;
Optional<DataField> first = targetFieldList.stream().filter(item -> StringUtils.equals(item.getId(), split2[finalI])).findFirst();
if (first.isPresent()) {
Optional<DataField> first1 = fieldList.stream().filter(item -> StringUtils.equals(item.getField(), first.get().getField())).findFirst();
if (first1.isPresent()) {
split2[j] = first1.get().getId();
} else {
continue root;
}
} else {
continue root;
}
}
targetRule.setId(null);
targetRule.setContent(String.join(",", split1) + "=" + String.join(",", split2));
datas.add(targetRule);
}
if (!CollectionUtils.isEmpty(datas)) {
dataRuleService.saveBatch(datas);
datas.forEach(item -> {
BindRule rule = new BindRule();
rule.setDataId(sourceTemplate.getId())
.setRuleId(item.getId());
rules.add(rule);
});
}
}
if (!CollectionUtils.isEmpty(rules)) {
bindRuleService.saveBatch(rules);
}
}
return AjaxResult.success();
}
} }
...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tbyf.his.common.annotation.IgnoreWebSecurity; import com.tbyf.his.common.annotation.IgnoreWebSecurity;
import com.tbyf.his.common.core.domain.AjaxResult; import com.tbyf.his.common.core.domain.AjaxResult;
import com.tbyf.his.common.utils.StringUtils;
import com.tbyf.his.common.utils.bean.BeanUtils; import com.tbyf.his.common.utils.bean.BeanUtils;
import com.tbyf.his.web.dataImport.domain.param.*; import com.tbyf.his.web.dataImport.domain.param.*;
import com.tbyf.his.web.dataImport.entity.*; import com.tbyf.his.web.dataImport.entity.*;
...@@ -32,7 +33,7 @@ import java.util.stream.Collectors; ...@@ -32,7 +33,7 @@ import java.util.stream.Collectors;
public class DataTemplateController { public class DataTemplateController {
@Autowired @Autowired
private DataTemplateService dataImportService; private DataTemplateService dataTemplateService;
@Autowired @Autowired
private DataFieldService dataFieldService; private DataFieldService dataFieldService;
...@@ -50,7 +51,7 @@ public class DataTemplateController { ...@@ -50,7 +51,7 @@ public class DataTemplateController {
@GetMapping() @GetMapping()
@ApiOperation("模板查询") @ApiOperation("模板查询")
public AjaxResult queryTemplate(@Validated QueryTemplateParam param) { public AjaxResult queryTemplate(@Validated QueryTemplateParam param) {
return AjaxResult.success(dataImportService.queryTemplate(param)); return AjaxResult.success(dataTemplateService.queryTemplate(param));
} }
@IgnoreWebSecurity @IgnoreWebSecurity
...@@ -82,7 +83,7 @@ public class DataTemplateController { ...@@ -82,7 +83,7 @@ public class DataTemplateController {
DataTemplate template = new DataTemplate(); DataTemplate template = new DataTemplate();
BeanUtils.copyProperties(param, template); BeanUtils.copyProperties(param, template);
template.initAdd(); template.initAdd();
dataImportService.save(template); dataTemplateService.save(template);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -93,7 +94,7 @@ public class DataTemplateController { ...@@ -93,7 +94,7 @@ public class DataTemplateController {
DataTemplate template = new DataTemplate(); DataTemplate template = new DataTemplate();
BeanUtils.copyProperties(param, template); BeanUtils.copyProperties(param, template);
template.initAdd(); template.initAdd();
dataImportService.updateById(template); dataTemplateService.updateById(template);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -101,7 +102,7 @@ public class DataTemplateController { ...@@ -101,7 +102,7 @@ public class DataTemplateController {
@GetMapping("/template/delete") @GetMapping("/template/delete")
@ApiOperation("删除模板") @ApiOperation("删除模板")
public AjaxResult deleteTemplate(@RequestParam String templateId) { public AjaxResult deleteTemplate(@RequestParam String templateId) {
dataImportService.removeById(templateId); dataTemplateService.removeById(templateId);
excelDataService.remove(Wrappers.lambdaQuery(ExcelData.class).eq(ExcelData::getTemplateId, templateId)); excelDataService.remove(Wrappers.lambdaQuery(ExcelData.class).eq(ExcelData::getTemplateId, templateId));
final LambdaQueryWrapper<DataField> wrapper = Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, templateId); final LambdaQueryWrapper<DataField> wrapper = Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, templateId);
final List<DataField> list = dataFieldService.list(wrapper); final List<DataField> list = dataFieldService.list(wrapper);
...@@ -154,4 +155,16 @@ public class DataTemplateController { ...@@ -154,4 +155,16 @@ public class DataTemplateController {
return AjaxResult.success(); return AjaxResult.success();
} }
@IgnoreWebSecurity
@PostMapping("/otherYears")
@ApiOperation("查询此类型模板的其它年份列表")
public AjaxResult queryOtherYears(@RequestBody @Validated DataTemplate template) {
LambdaQueryWrapper<DataTemplate> queryWrapper = Wrappers.lambdaQuery(DataTemplate.class)
.eq(DataTemplate::getOrgName, template.getOrgName())
.ne(DataTemplate::getYear, template.getYear())
.select(DataTemplate::getYear);
List<DataTemplate> list = dataTemplateService.list(queryWrapper);
return AjaxResult.success(list.stream().filter(item-> StringUtils.isNotBlank(item.getYear())).map(DataTemplate::getYear).collect(Collectors.toList()));
}
} }
...@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.TableField; ...@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
...@@ -18,6 +20,8 @@ import java.io.Serializable; ...@@ -18,6 +20,8 @@ import java.io.Serializable;
@Accessors(chain = true) @Accessors(chain = true)
@TableName(value = "bind_rule", autoResultMap = true) @TableName(value = "bind_rule", autoResultMap = true)
@ApiModel(value = "数据规则绑定表", description = "数据规则绑定表") @ApiModel(value = "数据规则绑定表", description = "数据规则绑定表")
@AllArgsConstructor
@NoArgsConstructor
public class BindRule implements Serializable { public class BindRule implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
......
...@@ -3,10 +3,19 @@ package com.tbyf.his.web.dataImport.mapper; ...@@ -3,10 +3,19 @@ package com.tbyf.his.web.dataImport.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tbyf.his.web.dataImport.entity.BindRule; import com.tbyf.his.web.dataImport.entity.BindRule;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:22 * @date 2023/2/7 11:22
*/ */
public interface BindRuleMapper extends BaseMapper<BindRule> { public interface BindRuleMapper extends BaseMapper<BindRule> {
/**
* 查询此模板下面的所有规则
* @param templateId
* @return
*/
List<BindRule> queryRuleList(String templateId);
} }
...@@ -3,10 +3,19 @@ package com.tbyf.his.web.dataImport.mapper; ...@@ -3,10 +3,19 @@ package com.tbyf.his.web.dataImport.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tbyf.his.web.dataImport.entity.DataRule; import com.tbyf.his.web.dataImport.entity.DataRule;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:22 * @date 2023/2/7 11:22
*/ */
public interface DataRuleMapper extends BaseMapper<DataRule> { public interface DataRuleMapper extends BaseMapper<DataRule> {
/**
* 查询全部模板规则
* @param templateId
* @return
*/
List<DataRule> queryTemplateRules(String templateId);
} }
...@@ -3,10 +3,20 @@ package com.tbyf.his.web.dataImport.service; ...@@ -3,10 +3,20 @@ package com.tbyf.his.web.dataImport.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tbyf.his.web.dataImport.entity.BindRule; import com.tbyf.his.web.dataImport.entity.BindRule;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:23 * @date 2023/2/7 11:23
*/ */
public interface BindRuleService extends IService<BindRule> { public interface BindRuleService extends IService<BindRule> {
/**
* 查询此模板下面的所有规则
* @param templateId
* @return
*/
List<BindRule> queryRuleList(String templateId);
} }
...@@ -3,10 +3,21 @@ package com.tbyf.his.web.dataImport.service; ...@@ -3,10 +3,21 @@ package com.tbyf.his.web.dataImport.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.tbyf.his.web.dataImport.entity.DataRule; import com.tbyf.his.web.dataImport.entity.DataRule;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:23 * @date 2023/2/7 11:23
*/ */
public interface DataRuleService extends IService<DataRule> { public interface DataRuleService extends IService<DataRule> {
/**
* 查询全部模板规则
* @param templateId
* @return
*/
List<DataRule> queryTemplateRules(String templateId);
} }
...@@ -7,8 +7,11 @@ import com.tbyf.his.web.dataImport.entity.BindRule; ...@@ -7,8 +7,11 @@ import com.tbyf.his.web.dataImport.entity.BindRule;
import com.tbyf.his.web.dataImport.mapper.BindRuleMapper; import com.tbyf.his.web.dataImport.mapper.BindRuleMapper;
import com.tbyf.his.web.dataImport.service.BindRuleService; import com.tbyf.his.web.dataImport.service.BindRuleService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:24 * @date 2023/2/7 11:24
...@@ -17,4 +20,12 @@ import org.springframework.stereotype.Service; ...@@ -17,4 +20,12 @@ import org.springframework.stereotype.Service;
@Service @Service
@DataSource(DataSourceType.MASTER) @DataSource(DataSourceType.MASTER)
public class BindRuleServiceImpl extends ServiceImpl<BindRuleMapper, BindRule> implements BindRuleService { public class BindRuleServiceImpl extends ServiceImpl<BindRuleMapper, BindRule> implements BindRuleService {
@Autowired
private BindRuleMapper bindRuleMapper;
@Override
public List<BindRule> queryRuleList(String templateId) {
return bindRuleMapper.queryRuleList(templateId);
}
} }
...@@ -16,7 +16,9 @@ import lombok.extern.slf4j.Slf4j; ...@@ -16,7 +16,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -41,38 +43,52 @@ public class DataFieldServiceImpl extends ServiceImpl<DataFieldMapper, DataField ...@@ -41,38 +43,52 @@ public class DataFieldServiceImpl extends ServiceImpl<DataFieldMapper, DataField
@Override @Override
public void fieldMatch(List<MetaField> list, DataField field, List<DataField> fieldMatchList) { public void fieldMatch(List<MetaField> list, DataField field, List<DataField> fieldMatchList) {
// 先查询元字段里面有没有相互匹配的 if (StringUtils.isBlank(field.getTitle())) {
final Optional<MetaField> first = list.stream().filter(item -> {
if (StringUtils.isNotBlank(item.getFieldComment())) {
return field.getTitle().contains(item.getFieldComment());
}
return false;
}).findFirst();
if (first.isPresent()) {
field.setField(first.get().getId());
return; return;
} }
MetaField metaField = null;
DataField dataField = null;
if (!CollectionUtils.isEmpty(list)) {
list.forEach(item -> {
if (StringUtils.isNotBlank(item.getFieldComment())) {
item.setRatio(DataImportUtils.getSimilarityRatio(field.getTitle(), item.getFieldComment()));
} else {
item.setRatio(0);
}
});
Optional<MetaField> max = list.stream().max(Comparator.comparing(MetaField::getRatio));
if (max.isPresent()) {
metaField = max.get();
}
}
if (!CollectionUtils.isEmpty(fieldMatchList)) { if (!CollectionUtils.isEmpty(fieldMatchList)) {
fieldMatchList.forEach(item -> { fieldMatchList.forEach(item -> {
item.setRatio(item.getSimilarityRatio(field)); if (StringUtils.isNotBlank(item.getTitle())) {
item.setRatio(DataImportUtils.getSimilarityRatio(field.getTitle(), item.getTitle()));
} else {
item.setRatio(0);
}
}); });
final Optional<DataField> max = fieldMatchList.stream().max(Comparator.comparing(DataField::getRatio)); Optional<DataField> max = fieldMatchList.stream().max(Comparator.comparing(DataField::getRatio));
if (max.isPresent()) { if (max.isPresent()) {
if (max.get().getRatio() > 2.2) { dataField = max.get();
field.setField(max.get().getId());
return;
}
} }
} }
list.forEach(item -> { if (metaField == null) {
if (StringUtils.isNotBlank(field.getTitle()) && StringUtils.isNotBlank(item.getFieldComment())) { if (dataField != null && dataField.getRatio() > 0.3) {
item.setRatio(DataImportUtils.getSimilarityRatio(field.getTitle(), item.getFieldComment())); field.setField(dataField.getField());
} }
}); } else {
final Optional<MetaField> max = list.stream().max(Comparator.comparing(MetaField::getRatio)); if (dataField == null) {
if (max.isPresent()) { if (metaField.getRatio() > 0.3) {
if (max.get().getRatio() > 0.5) { field.setField(metaField.getId());
field.setField(max.get().getId()); }
} else {
if (dataField.getRatio() >= metaField.getRatio()) {
field.setField(dataField.getField());
} else {
field.setField(metaField.getId());
}
} }
} }
} }
......
...@@ -7,8 +7,11 @@ import com.tbyf.his.web.dataImport.entity.DataRule; ...@@ -7,8 +7,11 @@ import com.tbyf.his.web.dataImport.entity.DataRule;
import com.tbyf.his.web.dataImport.mapper.DataRuleMapper; import com.tbyf.his.web.dataImport.mapper.DataRuleMapper;
import com.tbyf.his.web.dataImport.service.DataRuleService; import com.tbyf.his.web.dataImport.service.DataRuleService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* @author lzz * @author lzz
* @date 2023/2/7 11:24 * @date 2023/2/7 11:24
...@@ -17,4 +20,11 @@ import org.springframework.stereotype.Service; ...@@ -17,4 +20,11 @@ import org.springframework.stereotype.Service;
@Service @Service
@DataSource(DataSourceType.MASTER) @DataSource(DataSourceType.MASTER)
public class DataRuleServiceImpl extends ServiceImpl<DataRuleMapper, DataRule> implements DataRuleService { public class DataRuleServiceImpl extends ServiceImpl<DataRuleMapper, DataRule> implements DataRuleService {
@Autowired
private DataRuleMapper dataRuleMapper;
@Override
public List<DataRule> queryTemplateRules(String templateId) {
return dataRuleMapper.queryTemplateRules(templateId);
}
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tbyf.his.web.dataImport.mapper.BindRuleMapper">
<select id="queryRuleList" resultType="com.tbyf.his.web.dataImport.entity.BindRule">
select df.field as dataId, br.rule_id as ruleId
from data_field df
left join bind_rule br on df.id = br.data_id
where df.template_id = #{templateId}
and br.rule_id is not null
and df.field is not null
</select>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tbyf.his.web.dataImport.mapper.DataRuleMapper">
<select id="queryTemplateRules" resultType="com.tbyf.his.web.dataImport.entity.DataRule">
select dr.*
from data_template dt
left join bind_rule br on dt.id = br.data_id
left join data_rule dr on br.rule_id = dr.id
where dt.id = #{templateId}
and dr.id is not null
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment