Commit 02c07e5e by 刘泽志

功能完善

parent 1714bdb0
...@@ -37,4 +37,13 @@ CREATE TABLE T0801_TCMHOSP_BACKUP AS ...@@ -37,4 +37,13 @@ CREATE TABLE T0801_TCMHOSP_BACKUP AS
SELECT * SELECT *
FROM T0801_TCMHOSP; FROM T0801_TCMHOSP;
```
```
需要固定的字段 必须选填
ORG_NAME 机构名称
ORG_CODE 组织机构代码
AREA_NUMBER_CODE 行政区划代码
UNIFORM_CREDIT_NUMBER 统一社会信用代码
MAILING_ADDRESS / ADDRESS_OF_ORG 通信地址/医院类型模板的地址
``` ```
\ No newline at end of file
...@@ -9,7 +9,6 @@ import com.tbyf.his.common.annotation.IgnoreWebSecurity; ...@@ -9,7 +9,6 @@ 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.core.page.TableDataInfo; import com.tbyf.his.common.core.page.TableDataInfo;
import com.tbyf.his.common.core.text.StrFormatter; import com.tbyf.his.common.core.text.StrFormatter;
import com.tbyf.his.common.exception.base.BaseException;
import com.tbyf.his.common.utils.StringUtils; 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.DataImportUtils; import com.tbyf.his.web.dataImport.DataImportUtils;
...@@ -218,6 +217,13 @@ public class DataFieldController { ...@@ -218,6 +217,13 @@ public class DataFieldController {
@PostMapping("/meta") @PostMapping("/meta")
@ApiOperation("元字段新增") @ApiOperation("元字段新增")
public AjaxResult addMetaField(@RequestBody @Validated MetaField field) { public AjaxResult addMetaField(@RequestBody @Validated MetaField field) {
field.setFieldType(field.getFieldType().toUpperCase());
final LambdaQueryWrapper<MetaField> wrapper = Wrappers.lambdaQuery(MetaField.class)
.eq(MetaField::getFieldName, field.getFieldName());
final long count = metaFieldService.count(wrapper);
if (count > 0) {
return AjaxResult.error("不能新增相同名称的字段");
}
metaFieldService.save(field); metaFieldService.save(field);
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -226,6 +232,9 @@ public class DataFieldController { ...@@ -226,6 +232,9 @@ public class DataFieldController {
@PostMapping("/meta/update") @PostMapping("/meta/update")
@ApiOperation("修改元字段") @ApiOperation("修改元字段")
public AjaxResult updateMeatField(@RequestBody @Validated MetaField field) { public AjaxResult updateMeatField(@RequestBody @Validated MetaField field) {
if (StringUtils.isNotBlank(field.getFieldType())) {
field.setFieldType(field.getFieldType().toUpperCase());
}
metaFieldService.updateById(field); metaFieldService.updateById(field);
return AjaxResult.success(); return AjaxResult.success();
} }
......
...@@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSON; ...@@ -4,11 +4,14 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.core.page.TableDataInfo;
import com.tbyf.his.common.utils.StringUtils; 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.AddDictParam; import com.tbyf.his.web.dataImport.domain.param.AddDictParam;
import com.tbyf.his.web.dataImport.domain.param.QueryAreaParam;
import com.tbyf.his.web.dataImport.domain.param.UpdateDictParam; import com.tbyf.his.web.dataImport.domain.param.UpdateDictParam;
import com.tbyf.his.web.dataImport.entity.DataDict; import com.tbyf.his.web.dataImport.entity.DataDict;
import com.tbyf.his.web.dataImport.service.DataDictService; import com.tbyf.his.web.dataImport.service.DataDictService;
...@@ -63,9 +66,30 @@ public class DictDataController { ...@@ -63,9 +66,30 @@ public class DictDataController {
} }
@IgnoreWebSecurity @IgnoreWebSecurity
@GetMapping("/area")
@ApiOperation("机构查询")
public TableDataInfo searchArea(QueryAreaParam param) {
final LambdaQueryWrapper<DataDict> wrapper = Wrappers.lambdaQuery(DataDict.class);
wrapper.eq(DataDict::getType, "area")
.like(StringUtils.isNotBlank(param.getValue()), DataDict::getValue, param.getValue())
.like(StringUtils.isNotBlank(param.getLabel()), DataDict::getLabel, param.getLabel());
Page<DataDict> page = Page.of(param.getPageNum(), param.getPageSize());
page = dictService.page(page, wrapper);
return param.convert(page);
}
@IgnoreWebSecurity
@PostMapping("") @PostMapping("")
@ApiOperation("新增字典") @ApiOperation("新增字典")
public AjaxResult addDict(@RequestBody AddDictParam param) { public AjaxResult addDict(@RequestBody AddDictParam param) {
// 查询是否有重复
final LambdaQueryWrapper<DataDict> wrapper = Wrappers.lambdaQuery(DataDict.class)
.eq(DataDict::getType, param.getType())
.eq(DataDict::getValue, param.getValue());
final long count = dictService.count(wrapper);
if (count > 0) {
return AjaxResult.error("新增相同的字典值");
}
DataDict dict = new DataDict(); DataDict dict = new DataDict();
BeanUtils.copyProperties(param, dict); BeanUtils.copyProperties(param, dict);
dictService.save(dict); dictService.save(dict);
...@@ -95,138 +119,138 @@ public class DictDataController { ...@@ -95,138 +119,138 @@ public class DictDataController {
@ApiOperation("导入行政区划信息") @ApiOperation("导入行政区划信息")
public AjaxResult importArea() { public AjaxResult importArea() {
List<DataDict> dictList = new ArrayList<>(); List<DataDict> dictList = new ArrayList<>();
Map<String,String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("420000","湖北省"); map.put("420000", "湖北省");
map.put("420100","武汉市"); map.put("420100", "武汉市");
map.put("420102","江岸区"); map.put("420102", "江岸区");
map.put("420103","江汉区"); map.put("420103", "江汉区");
map.put("420104","硚口区"); map.put("420104", "硚口区");
map.put("420105","汉阳区"); map.put("420105", "汉阳区");
map.put("420106","武昌区"); map.put("420106", "武昌区");
map.put("420107","青山区"); map.put("420107", "青山区");
map.put("420117","新洲区"); map.put("420117", "新洲区");
map.put("420112","东西湖区"); map.put("420112", "东西湖区");
map.put("420113","汉南区"); map.put("420113", "汉南区");
map.put("420114","蔡甸区"); map.put("420114", "蔡甸区");
map.put("420115","江夏区"); map.put("420115", "江夏区");
map.put("420116","黄陂区"); map.put("420116", "黄陂区");
map.put("420111","洪山区"); map.put("420111", "洪山区");
//map.put("420111"," 洪山区(东湖风景区)"); //map.put("420111"," 洪山区(东湖风景区)");
//map.put("420111","洪山区(东湖高新区)"); //map.put("420111","洪山区(东湖高新区)");
map.put("420200","黄石市"); map.put("420200", "黄石市");
map.put("420202","黄石港区"); map.put("420202", "黄石港区");
map.put("420203","西塞山区"); map.put("420203", "西塞山区");
map.put("420204","下陆区"); map.put("420204", "下陆区");
map.put("420205","铁山区"); map.put("420205", "铁山区");
map.put("420222","阳新县"); map.put("420222", "阳新县");
map.put("420281","大冶市"); map.put("420281", "大冶市");
map.put("420300","十堰市"); map.put("420300", "十堰市");
map.put("420303","张湾区"); map.put("420303", "张湾区");
map.put("420322","郧西县"); map.put("420322", "郧西县");
map.put("420323","竹山县"); map.put("420323", "竹山县");
map.put("420324","竹溪县"); map.put("420324", "竹溪县");
map.put("420325","房县"); map.put("420325", "房县");
map.put("420304","郧阳区"); map.put("420304", "郧阳区");
map.put("420302","茅箭区"); map.put("420302", "茅箭区");
//map.put("420302","茅箭区(开发区)"); //map.put("420302","茅箭区(开发区)");
map.put("420381","丹江口市"); map.put("420381", "丹江口市");
//map.put("420381"," 丹江口市(武当山特区)"); //map.put("420381"," 丹江口市(武当山特区)");
map.put("420500","宜昌市"); map.put("420500", "宜昌市");
map.put("420502","西陵区"); map.put("420502", "西陵区");
map.put("420503","伍家岗区"); map.put("420503", "伍家岗区");
map.put("420504","点军区"); map.put("420504", "点军区");
map.put("420505","猇亭区"); map.put("420505", "猇亭区");
map.put("420506","夷陵区"); map.put("420506", "夷陵区");
map.put("420525","远安县"); map.put("420525", "远安县");
map.put("420526","兴山县"); map.put("420526", "兴山县");
map.put("420527","秭归县"); map.put("420527", "秭归县");
map.put("420581","宜都市"); map.put("420581", "宜都市");
map.put("420528","长阳土家族自治县"); map.put("420528", "长阳土家族自治县");
map.put("420529","五峰土家族自治县"); map.put("420529", "五峰土家族自治县");
map.put("420582","当阳市"); map.put("420582", "当阳市");
map.put("420583","枝江市"); map.put("420583", "枝江市");
map.put("420600","襄阳市"); map.put("420600", "襄阳市");
map.put("420602","襄城区"); map.put("420602", "襄城区");
map.put("420606","樊城区"); map.put("420606", "樊城区");
//map.put("420606","樊城区(高新区)"); //map.put("420606","樊城区(高新区)");
map.put("420607","襄州区"); map.put("420607", "襄州区");
map.put("420624","南漳县"); map.put("420624", "南漳县");
map.put("420625","谷城县"); map.put("420625", "谷城县");
map.put("420626","保康县"); map.put("420626", "保康县");
map.put("420682","老河口市"); map.put("420682", "老河口市");
map.put("420683","枣阳市"); map.put("420683", "枣阳市");
map.put("420684","宜城市"); map.put("420684", "宜城市");
map.put("420700","鄂州市"); map.put("420700", "鄂州市");
map.put("420702","梁子湖区"); map.put("420702", "梁子湖区");
map.put("420703","华容区"); map.put("420703", "华容区");
map.put("420704","鄂城区"); map.put("420704", "鄂城区");
//map.put("420704","鄂城区(社管办)"); //map.put("420704","鄂城区(社管办)");
map.put("420800","荆门市"); map.put("420800", "荆门市");
map.put("420802","东宝区"); map.put("420802", "东宝区");
map.put("420804","掇刀区"); map.put("420804", "掇刀区");
map.put("420822","沙洋县"); map.put("420822", "沙洋县");
map.put("420881","钟祥市"); map.put("420881", "钟祥市");
map.put("420882","京山市"); map.put("420882", "京山市");
map.put("420900","孝感市"); map.put("420900", "孝感市");
map.put("420902","孝南区"); map.put("420902", "孝南区");
map.put("420921","孝昌县"); map.put("420921", "孝昌县");
map.put("420922","大悟县"); map.put("420922", "大悟县");
map.put("420923","云梦县"); map.put("420923", "云梦县");
map.put("420981","应城市"); map.put("420981", "应城市");
map.put("420982","安陆市"); map.put("420982", "安陆市");
map.put("420984","汉川市"); map.put("420984", "汉川市");
map.put("421000","荆州市"); map.put("421000", "荆州市");
map.put("421002","沙市区"); map.put("421002", "沙市区");
//map.put("421002","沙市区(开发区)"); //map.put("421002","沙市区(开发区)");
map.put("421003","荆州区"); map.put("421003", "荆州区");
map.put("421022","公安县"); map.put("421022", "公安县");
map.put("421024","江陵县"); map.put("421024", "江陵县");
//map.put("421024","江陵县(开发区)"); //map.put("421024","江陵县(开发区)");
map.put("421081","石首市"); map.put("421081", "石首市");
map.put("421083","洪湖市"); map.put("421083", "洪湖市");
map.put("421087","松滋市"); map.put("421087", "松滋市");
map.put("421088","监利市"); map.put("421088", "监利市");
map.put("421100","黄冈市"); map.put("421100", "黄冈市");
map.put("421102","黄州区"); map.put("421102", "黄州区");
map.put("421121","团风县"); map.put("421121", "团风县");
map.put("421122","红安县"); map.put("421122", "红安县");
map.put("421123","罗田县"); map.put("421123", "罗田县");
map.put("421124","英山县"); map.put("421124", "英山县");
map.put("421125","浠水县"); map.put("421125", "浠水县");
map.put("421126","蕲春县"); map.put("421126", "蕲春县");
map.put("421127","黄梅县"); map.put("421127", "黄梅县");
map.put("421181","麻城市"); map.put("421181", "麻城市");
map.put("421182","武穴市"); map.put("421182", "武穴市");
map.put("421200","咸宁市"); map.put("421200", "咸宁市");
map.put("421202","咸安区"); map.put("421202", "咸安区");
map.put("421221","嘉鱼县"); map.put("421221", "嘉鱼县");
map.put("421222","通城县"); map.put("421222", "通城县");
map.put("421223","崇阳县"); map.put("421223", "崇阳县");
map.put("421224","通山县"); map.put("421224", "通山县");
map.put("421281","赤壁市"); map.put("421281", "赤壁市");
map.put("421300","随州市"); map.put("421300", "随州市");
map.put("421303","曾都区"); map.put("421303", "曾都区");
map.put("421321","随县"); map.put("421321", "随县");
map.put("421381","广水市"); map.put("421381", "广水市");
map.put("422800","恩施土家族苗族自治州"); map.put("422800", "恩施土家族苗族自治州");
map.put("422801","恩施市"); map.put("422801", "恩施市");
map.put("422802","利川市"); map.put("422802", "利川市");
map.put("422822","建始县"); map.put("422822", "建始县");
map.put("422823","巴东县"); map.put("422823", "巴东县");
map.put("422825","宣恩县"); map.put("422825", "宣恩县");
map.put("422826","咸丰县"); map.put("422826", "咸丰县");
map.put("422827","来凤县"); map.put("422827", "来凤县");
map.put("422828","鹤峰县"); map.put("422828", "鹤峰县");
map.put("429004","仙桃市"); map.put("429004", "仙桃市");
map.put("429005","潜江市"); map.put("429005", "潜江市");
map.put("429006","天门市"); map.put("429006", "天门市");
map.put("429021","神农架林区"); map.put("429021", "神农架林区");
map.forEach((key, value)->{ map.forEach((key, value) -> {
DataDict dict = new DataDict(); DataDict dict = new DataDict();
dict.setType("area").setValue(key).setLabel(value); dict.setType("area").setValue(key).setLabel(value);
dictList.add(dict); dictList.add(dict);
}); });
dictService.remove(Wrappers.lambdaQuery(DataDict.class).eq(DataDict::getType,"area")); dictService.remove(Wrappers.lambdaQuery(DataDict.class).eq(DataDict::getType, "area"));
dictService.saveBatch(dictList); dictService.saveBatch(dictList);
return AjaxResult.success(); return AjaxResult.success();
} }
......
...@@ -150,6 +150,9 @@ public class ExcelDataController { ...@@ -150,6 +150,9 @@ public class ExcelDataController {
.eq(DataDict::getType, "area")); .eq(DataDict::getType, "area"));
DataTemplate template = dataTemplateService.getById(excelData.getTemplateId()); DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
String sql = "SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'"; String sql = "SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME,MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'";
if (StringUtils.equals("中医类医院", template.getOrgName())) {
sql = "SELECT ROWCODE, '{}' AS ORG_TYPE,ORG_NAME, ADDRESS_OF_ORG AS MAILING_ADDRESS,AREA_NUMBER_CODE FROM {} WHERE YEAROOFDATARECORD='{}年'";
}
try { try {
DataSourceService.switchDb(template.getDataSourceId()); DataSourceService.switchDb(template.getDataSourceId());
List<AreaDict> areaDictList = jdbcTemplate.query( List<AreaDict> areaDictList = jdbcTemplate.query(
...@@ -167,10 +170,11 @@ public class ExcelDataController { ...@@ -167,10 +170,11 @@ public class ExcelDataController {
return true; return true;
} }
final Optional<DataDict> first = areaList.stream().filter(item -> StringUtils.equals(item.getValue(), area.getAREA_NUMBER_CODE())).findFirst(); final Optional<DataDict> first = areaList.stream().filter(item -> StringUtils.equals(item.getValue(), area.getAREA_NUMBER_CODE())).findFirst();
return !first.map(dataDict -> area.getORG_NAME().startsWith(dataDict.getLabel())).orElse(true); return first.map(dataDict -> !area.getORG_NAME().startsWith(dataDict.getLabel())).orElse(true);
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
areaDictList.sort(Comparator.comparingInt(x -> x.getAREA_NUMBER_CODE().hashCode()));
return AjaxResult.success(areaDictList); return AjaxResult.success(areaDictList);
} finally { } finally {
DataSourceService.switchDefault(); DataSourceService.switchDefault();
...@@ -188,6 +192,9 @@ public class ExcelDataController { ...@@ -188,6 +192,9 @@ public class ExcelDataController {
.eq(ExcelData::getYear, area.getYear()) .eq(ExcelData::getYear, area.getYear())
.eq(ExcelData::getType, "1"), false); .eq(ExcelData::getType, "1"), false);
DataTemplate template = dataTemplateService.getById(excelData.getTemplateId()); DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
if (StringUtils.equals("中医类医院", template.getOrgName())) {
sql = "UPDATE {} SET ORG_NAME = '{}' ,ADDRESS_OF_ORG='{}',AREA_NUMBER_CODE='{}' WHERE ROWCODE = '{}'";
}
try { try {
DataSourceService.switchDb(template.getDataSourceId()); DataSourceService.switchDb(template.getDataSourceId());
jdbcTemplate.execute(StrFormatter.format(sql, jdbcTemplate.execute(StrFormatter.format(sql,
......
package com.tbyf.his.web.dataImport.domain.param;
import com.tbyf.his.web.dataImport.domain.ParamMp;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* @author lzz
* @date 2023/1/10 17:01
*/
@EqualsAndHashCode(callSuper = true)
@Data
@Accessors(chain = true)
@ApiModel(value = "查询机构", description = "查询机构")
public class QueryAreaParam extends ParamMp {
@ApiModelProperty(value = "区域编码")
private String value;
@ApiModelProperty(value = "区域名称")
private String label;
}
...@@ -37,7 +37,7 @@ public class UpdateFieldParam implements Serializable { ...@@ -37,7 +37,7 @@ public class UpdateFieldParam implements Serializable {
private String coordinate; private String coordinate;
@ApiModelProperty(value = "排序字段") @ApiModelProperty(value = "排序字段")
private Integer sort = 0; private Integer sort;
@ApiModelProperty(value = "数据库字段名") @ApiModelProperty(value = "数据库字段名")
private String field; private String field;
......
...@@ -6,24 +6,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -6,24 +6,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tbyf.his.common.annotation.DataSource; import com.tbyf.his.common.annotation.DataSource;
import com.tbyf.his.common.enums.DataSourceType; import com.tbyf.his.common.enums.DataSourceType;
import com.tbyf.his.common.utils.StringUtils; import com.tbyf.his.common.utils.StringUtils;
import com.tbyf.his.web.dataImport.DataImportUtils;
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.vo.CreateFieldVO; import com.tbyf.his.web.dataImport.domain.vo.CreateFieldVO;
import com.tbyf.his.web.dataImport.domain.vo.DataFieldVO; import com.tbyf.his.web.dataImport.domain.vo.DataFieldVO;
import com.tbyf.his.web.dataImport.domain.vo.VerifyVO; import com.tbyf.his.web.dataImport.domain.vo.VerifyVO;
import com.tbyf.his.web.dataImport.entity.DataField; import com.tbyf.his.web.dataImport.entity.DataField;
import com.tbyf.his.web.dataImport.entity.DataTemplate; import com.tbyf.his.web.dataImport.entity.DataTemplate;
import com.tbyf.his.web.dataImport.entity.MetaField;
import com.tbyf.his.web.dataImport.mapper.DataFieldMapper; import com.tbyf.his.web.dataImport.mapper.DataFieldMapper;
import com.tbyf.his.web.dataImport.service.DataFieldService; import com.tbyf.his.web.dataImport.service.DataFieldService;
import com.tbyf.his.web.dataImport.service.DataTemplateService; import com.tbyf.his.web.dataImport.service.DataTemplateService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RegExUtils;
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 java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
...@@ -64,18 +59,34 @@ public class DataFieldServiceImpl extends ServiceImpl<DataFieldMapper, DataField ...@@ -64,18 +59,34 @@ public class DataFieldServiceImpl extends ServiceImpl<DataFieldMapper, DataField
if (StringUtils.isBlank(field.getTitle())) { if (StringUtils.isBlank(field.getTitle())) {
return; return;
} }
Optional<DataField> fieldOptional = fieldMatchList.stream().filter(item -> { // 先进行字段与code双匹配
Optional<DataField> optional = fieldMatchList.stream().filter(item -> {
// 1.先判断两个是否相等 // 1.先判断两个是否相等
if (StringUtils.equals(item.getTitle().trim(), field.getTitle().trim())) { if (StringUtils.equals(item.getTitle().trim(), field.getTitle().trim())
&& StringUtils.equals(item.getCode(), field.getCode())) {
return true; return true;
} }
// 去除五角星号再判断 // 去除五角星号再判断
return StringUtils.equals(item.getTitle().replaceAll("★","").replaceAll(":","").trim(), return StringUtils.equals(item.getTitle().replaceAll("★", "").replaceAll(":", "").trim(),
field.getTitle().replaceAll("★","").replaceAll(":","").trim()); field.getTitle().replaceAll("★", "").replaceAll(":", "").trim())
&& StringUtils.equals(item.getCode(), field.getCode());
}).findFirst(); }).findFirst();
fieldOptional.ifPresent(f ->{ if (optional.isPresent()) {
field.setField(f.getField()); field.setField(optional.get().getField());
}); } else {
Optional<DataField> fieldOptional = fieldMatchList.stream().filter(item -> {
// 1.先判断两个是否相等
if (StringUtils.equals(item.getTitle().trim(), field.getTitle().trim())) {
return true;
}
// 去除五角星号再判断
return StringUtils.equals(item.getTitle().replaceAll("★", "").replaceAll(":", "").trim(),
field.getTitle().replaceAll("★", "").replaceAll(":", "").trim());
}).findFirst();
fieldOptional.ifPresent(f -> {
field.setField(f.getField());
});
}
} }
@Override @Override
......
...@@ -7,6 +7,7 @@ import com.tbyf.his.common.annotation.DataSource; ...@@ -7,6 +7,7 @@ import com.tbyf.his.common.annotation.DataSource;
import com.tbyf.his.common.annotation.Excel; import com.tbyf.his.common.annotation.Excel;
import com.tbyf.his.common.core.text.StrFormatter; import com.tbyf.his.common.core.text.StrFormatter;
import com.tbyf.his.common.enums.DataSourceType; import com.tbyf.his.common.enums.DataSourceType;
import com.tbyf.his.common.exception.base.BaseException;
import com.tbyf.his.common.utils.StringUtils; import com.tbyf.his.common.utils.StringUtils;
import com.tbyf.his.web.dataImport.DataImportUtils; import com.tbyf.his.web.dataImport.DataImportUtils;
import com.tbyf.his.web.dataImport.core.*; import com.tbyf.his.web.dataImport.core.*;
...@@ -75,7 +76,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -75,7 +76,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
try { try {
DataSourceService.switchDb(template.getDataSourceId()); DataSourceService.switchDb(template.getDataSourceId());
// 需要先清空临时表的数据,按照年份 // 需要先清空临时表的数据,按照年份
dataList = jdbcTemplate.query(StrFormatter.format(sqlTemplate, fieldSql, template.getTableName(), template.getYear() + "年"), new StringColumnRowMapper()); dataList = jdbcTemplate.query(StrFormatter.format(sqlTemplate, fieldSql, template.getTableName() + "_TEMP", template.getYear() + "年"), new StringColumnRowMapper());
// 解析数据到values里面 // 解析数据到values里面
for (VerifyVO verifyVO : verifyList) { for (VerifyVO verifyVO : verifyList) {
dataList.forEach(map -> { dataList.forEach(map -> {
...@@ -458,6 +459,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -458,6 +459,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
@Override @Override
public void importData(ExcelData excelData) { public void importData(ExcelData excelData) {
long startTime = System.currentTimeMillis();
final DataTemplate template = dataTemplateService.getById(excelData.getTemplateId()); final DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
// 获取元字段与所有校验对象 // 获取元字段与所有校验对象
List<VerifyVO> verifyList = dataTemplateService.getVerify(template.getId()); List<VerifyVO> verifyList = dataTemplateService.getVerify(template.getId());
...@@ -480,18 +482,52 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -480,18 +482,52 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
} }
vo.setCoordinate(s); vo.setCoordinate(s);
} }
int a = 0; // 整数位长度
int b = 0; // 小数位长度
int l = 0; // 字段长度
if (StringUtils.containsIgnoreCase(vo.getFieldType(), "NUMBER")) {
final String[] numbers = vo.getFieldType().replaceAll("NUMBER", "")
.replaceAll("\\(", "")
.replaceAll("\\)", "")
.split(",");
b = Integer.parseInt(numbers[1]);
a = Integer.parseInt(numbers[0]) - b;
} else if (StringUtils.containsIgnoreCase(vo.getFieldType(), "VARCHAR2")) {
l = Integer.parseInt(vo.getFieldType().replaceAll("VARCHAR2", "")
.replaceAll("\\(", "")
.replaceAll("\\)", ""));
}
final String[] coords = vo.getCoordinate().split(","); final String[] coords = vo.getCoordinate().split(",");
// TODO 这里减1的原因是excel表名的行号1实际上的下标为0 // TODO 这里减1的原因是excel表名的行号1实际上的下标为0
int rowStart = Integer.parseInt(coords[1]) - 1; int rowStart = Integer.parseInt(coords[1]) - 1;
final Row row = sheet.getRow(rowStart); final Row row = sheet.getRow(rowStart);
for (Integer column : columnList) { for (Integer column : columnList) {
try { final Cell cell = row.getCell(column, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
final Cell cell = row.getCell(column, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL); final String cellValue = DiConfig.getValue(cell);
vo.addValue(DiConfig.getValue(cell)); if (StringUtils.containsIgnoreCase(vo.getFieldType(), "NUMBER")) {
} catch (Exception ignore) { // i是整数位长度
int i = cellValue.indexOf(".");
if (i == -1) {
i = cellValue.length();
}
int k = cellValue.length() - i - 1;
if (i > a || k > b) {
throw new BaseException(
StrFormatter.format("字段数据:[{}],字段类型:[{}],字段名称:[{}],数据精度异常,请修改数据元与数据库相对应字段信息",
cellValue, vo.getFieldType(), vo.getFieldName(), cellValue));
}
} else if (StringUtils.containsIgnoreCase(vo.getFieldType(), "VARCHAR2")) {
if (l < cellValue.length()) {
throw new BaseException(
StrFormatter.format("字段数据:[{}],字段类型:[{}],字段名称:[{}],数据长度不足,请修改数据元与数据库相对应字段信息",
cellValue, vo.getFieldType(), vo.getFieldName(), cellValue));
}
} }
vo.addValue(cellValue);
} }
} }
log.info("解析数据用时:[{}]", System.currentTimeMillis() - startTime);
startTime = System.currentTimeMillis();
// 直接导入临时表 // 直接导入临时表
String insertSql = "INSERT INTO {}(" + verifyList.stream() String insertSql = "INSERT INTO {}(" + verifyList.stream()
.map(VerifyVO::getFieldName).collect(Collectors.joining(",")) .map(VerifyVO::getFieldName).collect(Collectors.joining(","))
...@@ -512,9 +548,12 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData ...@@ -512,9 +548,12 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
// 需要先清空临时表的数据,按照年份 // 需要先清空临时表的数据,按照年份
jdbcTemplate.execute(StrFormatter.format("DELETE FROM {} WHERE YEAROOFDATARECORD = '{}'" jdbcTemplate.execute(StrFormatter.format("DELETE FROM {} WHERE YEAROOFDATARECORD = '{}'"
, template.getTableName() + "_TEMP", template.getYear() + "年")); , template.getTableName() + "_TEMP", template.getYear() + "年"));
jdbcTemplate.batchUpdate(sqlArr); jdbcTemplate.batchUpdate(sqlArr);
} catch (Exception e) { log.info("导入数据用时:[{}]", System.currentTimeMillis() - startTime);
throw new RuntimeException(e); } catch (Throwable e) {
log.error("数据导入错误", e);
throw new BaseException(e.getCause().getMessage());
} finally { } finally {
DataSourceService.switchDefault(); DataSourceService.switchDefault();
} }
......
...@@ -46,7 +46,7 @@ spring: ...@@ -46,7 +46,7 @@ spring:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages
profiles: profiles:
active: druid active: zyy
# 文件上传 # 文件上传
servlet: servlet:
multipart: multipart:
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
and mf.field_name like concat('%', #{param.field}, '%') and mf.field_name like concat('%', #{param.field}, '%')
</if> </if>
</where> </where>
order by df.sort
</select> </select>
<select id="listFieldMatchList" resultType="com.tbyf.his.web.dataImport.entity.DataField"> <select id="listFieldMatchList" resultType="com.tbyf.his.web.dataImport.entity.DataField">
......
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