Commit 02c07e5e by 刘泽志

功能完善

parent 1714bdb0
......@@ -37,4 +37,13 @@ CREATE TABLE T0801_TCMHOSP_BACKUP AS
SELECT *
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;
import com.tbyf.his.common.core.domain.AjaxResult;
import com.tbyf.his.common.core.page.TableDataInfo;
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.bean.BeanUtils;
import com.tbyf.his.web.dataImport.DataImportUtils;
......@@ -218,6 +217,13 @@ public class DataFieldController {
@PostMapping("/meta")
@ApiOperation("元字段新增")
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);
return AjaxResult.success();
}
......@@ -226,6 +232,9 @@ public class DataFieldController {
@PostMapping("/meta/update")
@ApiOperation("修改元字段")
public AjaxResult updateMeatField(@RequestBody @Validated MetaField field) {
if (StringUtils.isNotBlank(field.getFieldType())) {
field.setFieldType(field.getFieldType().toUpperCase());
}
metaFieldService.updateById(field);
return AjaxResult.success();
}
......
......@@ -150,6 +150,9 @@ public class ExcelDataController {
.eq(DataDict::getType, "area"));
DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
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 {
DataSourceService.switchDb(template.getDataSourceId());
List<AreaDict> areaDictList = jdbcTemplate.query(
......@@ -167,10 +170,11 @@ public class ExcelDataController {
return true;
}
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());
}
areaDictList.sort(Comparator.comparingInt(x -> x.getAREA_NUMBER_CODE().hashCode()));
return AjaxResult.success(areaDictList);
} finally {
DataSourceService.switchDefault();
......@@ -188,6 +192,9 @@ public class ExcelDataController {
.eq(ExcelData::getYear, area.getYear())
.eq(ExcelData::getType, "1"), false);
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 {
DataSourceService.switchDb(template.getDataSourceId());
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 {
private String coordinate;
@ApiModelProperty(value = "排序字段")
private Integer sort = 0;
private Integer sort;
@ApiModelProperty(value = "数据库字段名")
private String field;
......
......@@ -6,24 +6,19 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tbyf.his.common.annotation.DataSource;
import com.tbyf.his.common.enums.DataSourceType;
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.vo.CreateFieldVO;
import com.tbyf.his.web.dataImport.domain.vo.DataFieldVO;
import com.tbyf.his.web.dataImport.domain.vo.VerifyVO;
import com.tbyf.his.web.dataImport.entity.DataField;
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.service.DataFieldService;
import com.tbyf.his.web.dataImport.service.DataTemplateService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RegExUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
......@@ -64,18 +59,34 @@ public class DataFieldServiceImpl extends ServiceImpl<DataFieldMapper, DataField
if (StringUtils.isBlank(field.getTitle())) {
return;
}
Optional<DataField> fieldOptional = fieldMatchList.stream().filter(item -> {
// 先进行字段与code双匹配
Optional<DataField> optional = fieldMatchList.stream().filter(item -> {
// 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 StringUtils.equals(item.getTitle().replaceAll("★","").replaceAll(":","").trim(),
field.getTitle().replaceAll("★","").replaceAll(":","").trim());
return StringUtils.equals(item.getTitle().replaceAll("★", "").replaceAll(":", "").trim(),
field.getTitle().replaceAll("★", "").replaceAll(":", "").trim())
&& StringUtils.equals(item.getCode(), field.getCode());
}).findFirst();
fieldOptional.ifPresent(f ->{
field.setField(f.getField());
});
if (optional.isPresent()) {
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
......
......@@ -7,6 +7,7 @@ import com.tbyf.his.common.annotation.DataSource;
import com.tbyf.his.common.annotation.Excel;
import com.tbyf.his.common.core.text.StrFormatter;
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.web.dataImport.DataImportUtils;
import com.tbyf.his.web.dataImport.core.*;
......@@ -75,7 +76,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
try {
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里面
for (VerifyVO verifyVO : verifyList) {
dataList.forEach(map -> {
......@@ -458,6 +459,7 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
@Override
public void importData(ExcelData excelData) {
long startTime = System.currentTimeMillis();
final DataTemplate template = dataTemplateService.getById(excelData.getTemplateId());
// 获取元字段与所有校验对象
List<VerifyVO> verifyList = dataTemplateService.getVerify(template.getId());
......@@ -480,18 +482,52 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
}
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(",");
// TODO 这里减1的原因是excel表名的行号1实际上的下标为0
int rowStart = Integer.parseInt(coords[1]) - 1;
final Row row = sheet.getRow(rowStart);
for (Integer column : columnList) {
try {
final Cell cell = row.getCell(column, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
vo.addValue(DiConfig.getValue(cell));
} catch (Exception ignore) {
final Cell cell = row.getCell(column, Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
final String cellValue = DiConfig.getValue(cell);
if (StringUtils.containsIgnoreCase(vo.getFieldType(), "NUMBER")) {
// 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()
.map(VerifyVO::getFieldName).collect(Collectors.joining(","))
......@@ -512,9 +548,12 @@ public class ExcelDataServiceImpl extends ServiceImpl<ExcelDataMapper, ExcelData
// 需要先清空临时表的数据,按照年份
jdbcTemplate.execute(StrFormatter.format("DELETE FROM {} WHERE YEAROOFDATARECORD = '{}'"
, template.getTableName() + "_TEMP", template.getYear() + "年"));
jdbcTemplate.batchUpdate(sqlArr);
} catch (Exception e) {
throw new RuntimeException(e);
log.info("导入数据用时:[{}]", System.currentTimeMillis() - startTime);
} catch (Throwable e) {
log.error("数据导入错误", e);
throw new BaseException(e.getCause().getMessage());
} finally {
DataSourceService.switchDefault();
}
......
......@@ -46,7 +46,7 @@ spring:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: druid
active: zyy
# 文件上传
servlet:
multipart:
......
......@@ -40,6 +40,7 @@
and mf.field_name like concat('%', #{param.field}, '%')
</if>
</where>
order by df.sort
</select>
<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