Commit 30ada97d by 刘泽志

动态解析模板

parent c8e10b26
...@@ -26,6 +26,10 @@ import io.swagger.annotations.Api; ...@@ -26,6 +26,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows; import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -34,6 +38,10 @@ import org.springframework.util.ObjectUtils; ...@@ -34,6 +38,10 @@ import org.springframework.util.ObjectUtils;
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.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -110,8 +118,19 @@ public class DataImportController { ...@@ -110,8 +118,19 @@ public class DataImportController {
@ApiOperation("删除模板") @ApiOperation("删除模板")
public AjaxResult deleteTemplate(@RequestParam String templateId) { public AjaxResult deleteTemplate(@RequestParam String templateId) {
dataImportService.removeById(templateId); dataImportService.removeById(templateId);
//TODO 需要删除字段以及其字段关联的规则与其它数据 excelDataService.remove(Wrappers.lambdaQuery(ExcelData.class).eq(ExcelData::getTemplateId, templateId));
dataFieldService.remove(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<String> idList = new ArrayList<>();
idList.add(templateId);
if (!CollectionUtils.isEmpty(list)) {
final List<String> fieldIdList = list.stream().map(DataField::getId).collect(Collectors.toList());
dataFieldService.remove(Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, templateId));
idList.addAll(fieldIdList);
}
bindRuleService.remove(Wrappers.lambdaQuery(BindRule.class).in(BindRule::getDataId, idList));
//TODO 已经删除:模板,字段,模板与字段关联的规则信息,模板文件表 未删除: 模板规则信息
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -260,7 +279,7 @@ public class DataImportController { ...@@ -260,7 +279,7 @@ public class DataImportController {
@ApiOperation("删除字段") @ApiOperation("删除字段")
public AjaxResult deleteField(@RequestParam String fieldId) { public AjaxResult deleteField(@RequestParam String fieldId) {
dataFieldService.removeById(fieldId); dataFieldService.removeById(fieldId);
//TODO 需要删除其字段关联的规则与其它数据 bindRuleService.remove(Wrappers.lambdaQuery(BindRule.class).eq(BindRule::getDataId, fieldId));
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -312,6 +331,7 @@ public class DataImportController { ...@@ -312,6 +331,7 @@ public class DataImportController {
@ApiOperation("删除规则") @ApiOperation("删除规则")
public AjaxResult deleteRule(@RequestParam String ruleId) { public AjaxResult deleteRule(@RequestParam String ruleId) {
dataRuleService.removeById(ruleId); dataRuleService.removeById(ruleId);
bindRuleService.remove(Wrappers.lambdaQuery(BindRule.class).eq(BindRule::getRuleId, ruleId));
return AjaxResult.success(); return AjaxResult.success();
} }
...@@ -413,5 +433,49 @@ public class DataImportController { ...@@ -413,5 +433,49 @@ public class DataImportController {
return AjaxResult.success(); return AjaxResult.success();
} }
@IgnoreWebSecurity
@GetMapping("/field/reset")
@ApiOperation("根据基础模板重置字段")
public AjaxResult resetField(@RequestParam String excelId) {
final ExcelData excelData = excelDataService.getById(excelId);
final LambdaQueryWrapper<DataField> wrapper = Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, excelData.getTemplateId());
final List<DataField> list = dataFieldService.list(wrapper);
if (!CollectionUtils.isEmpty(list)) {
final List<String> fieldIdList = list.stream().map(DataField::getId).collect(Collectors.toList());
bindRuleService.remove(Wrappers.lambdaQuery(BindRule.class).in(BindRule::getDataId, fieldIdList));
}
dataFieldService.remove(Wrappers.lambdaQuery(DataField.class).eq(DataField::getTemplateId, excelData.getTemplateId()));
try (InputStream is = new ByteArrayInputStream(excelData.getFile()); Workbook workbook = WorkbookFactory.create(is)) {
final Sheet sheet = workbook.getSheetAt(0);
final int rows = sheet.getLastRowNum() + 1;
List<DataField> fieldList = new ArrayList<>();
for (int i = 1; i < rows; i++) {
final Row row = sheet.getRow(i);
String code = DiConfig.getValue(row.getCell(1));
String title = DiConfig.getValue(row.getCell(2));
String unit = DiConfig.getValue(row.getCell(4));
if (StringUtils.isAllBlank(code, title, unit)) {
continue;
}
if (StringUtils.equals(code, "代码") || StringUtils.equals(title, "指标名称") || StringUtils.equals(unit, "计量单位")) {
continue;
}
final DataField dataField = new DataField();
dataField.setTemplateId(excelData.getTemplateId());
dataField.setCode(code);
dataField.setTitle(title);
dataField.setUnit(unit);
dataField.setCoordinate("F," + (i + 1));
dataField.setSort(i + 1);
dataField.createField();
fieldList.add(dataField);
}
dataFieldService.saveBatch(fieldList);
} catch (IOException e) {
throw new RuntimeException(e);
}
return AjaxResult.success();
}
} }
package com.tbyf.his.web.dataImport.core; package com.tbyf.his.web.dataImport.core;
import com.tbyf.his.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.util.NumberToTextConverter;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
...@@ -13,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -13,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @date 2023/2/9 9:22 * @date 2023/2/9 9:22
*/ */
@Configuration @Configuration
@Slf4j
public class DiConfig { public class DiConfig {
@Autowired @Autowired
...@@ -20,6 +32,10 @@ public class DiConfig { ...@@ -20,6 +32,10 @@ public class DiConfig {
public static final Map<String, RuleValidator> VALIDATOR_MAP = new ConcurrentHashMap<>(8); public static final Map<String, RuleValidator> VALIDATOR_MAP = new ConcurrentHashMap<>(8);
public static final List<String> WORD = Arrays.asList(
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
);
@PostConstruct @PostConstruct
public void init() { public void init() {
final Map<String, RuleValidator> validatorMap = applicationContext.getBeansOfType(RuleValidator.class); final Map<String, RuleValidator> validatorMap = applicationContext.getBeansOfType(RuleValidator.class);
...@@ -36,4 +52,73 @@ public class DiConfig { ...@@ -36,4 +52,73 @@ public class DiConfig {
return VALIDATOR_MAP.get(DiConstants.SERVICE_PREFIX + mode); return VALIDATOR_MAP.get(DiConstants.SERVICE_PREFIX + mode);
} }
public static int getIndex(String word) {
for (int i = 0; i < WORD.size(); i++) {
if (StringUtils.equals(word, WORD.get(i))) {
return i;
}
}
return -1;
}
public static String getWord(int index) {
return WORD.get(index);
}
/**
* 获取单元格的值
*
* @param cell
* @return
*/
public static String getValue(Cell cell) {
if (cell == null || "".equals(cell.toString().trim())) {
return "";
}
String cellString = "";
final CellType type = cell.getCellType();
switch (type) {
case STRING:
cellString = trim(cell.getRichStringCellValue().getString());
break;
case BOOLEAN:
cellString = String.valueOf(cell.getBooleanCellValue());
break;
case FORMULA:
final FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
cellString = evaluator.evaluate(cell).getStringValue().trim();
break;
case NUMERIC:
final short format = cell.getCellStyle().getDataFormat();
if (DateUtil.isCellDateFormatted(cell)) {
// 日期格式
SimpleDateFormat sdf = null;
if (format == 20 || format == 32) {
sdf = new SimpleDateFormat("HH:mm");
cellString = sdf.format(cell.getDateCellValue());
} else if (format == 14 || format == 31 || format == 57 || format == 58) {
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
sdf = new SimpleDateFormat("yyyy-MM-dd");
double value = cell.getNumericCellValue();
Date date = org.apache.poi.ss.usermodel.DateUtil
.getJavaDate(value);
cellString = sdf.format(date);
} else {// 日期
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
cellString = sdf.format(cell.getDateCellValue());
}
} else {
cellString = NumberToTextConverter.toText(cell.getNumericCellValue());
}
break;
default:
break;
}
return cellString;
}
public static String trim(String text) {
return text.replaceAll("(\\u00A0+| )", "").trim();
}
} }
...@@ -4,10 +4,17 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -4,10 +4,17 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.tbyf.his.common.utils.StringUtils;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.SneakyThrows;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import java.io.Serializable; import java.io.Serializable;
...@@ -55,4 +62,27 @@ public class DataField implements Serializable { ...@@ -55,4 +62,27 @@ public class DataField implements Serializable {
@TableField("field") @TableField("field")
private String field; private String field;
@SneakyThrows
public void createField() {
if (StringUtils.equals(title, "统一社会信用代码")) {
field = "UNIFIED_CODE";
} else if (StringUtils.equals(title, "组织机构代码")) {
field = "ORG_CODE";
} else if (StringUtils.equals(title, "机构名称")) {
field = "ORG_NAME";
} else {
final HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < title.length(); i++) {
final String[] array = PinyinHelper.toHanyuPinyinStringArray(title.charAt(i), format);
if (array != null && array.length > 0) {
field = array[0].charAt(0) + "" + sort;
break;
}
}
}
}
} }
# 项目相关配置 # 项目相关配置
guopx: guopx:
# 名称 # 名称
name: commonservice name: commonservice
# 版本 # 版本
version: 1.0.0 version: 1.0.0
# 版权年份 # 版权年份
copyrightYear: 2023 copyrightYear: 2023
# 实例演示开关 # 实例演示开关
demoEnabled: false demoEnabled: false
# 文件路径 示例( Windows配置D:/guopx/uploadPath,Linux配置 /home/guopx/uploadPath) # 文件路径 示例( Windows配置D:/guopx/uploadPath,Linux配置 /home/guopx/uploadPath)
profile: /home/his/uploadPath profile: /home/his/uploadPath
# 获取ip地址开关 # 获取ip地址开关
addressEnabled: false addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证 # 验证码类型 math 数组计算 char 字符验证
captchaType: math captchaType: math
# 开发环境配置 # 开发环境配置
server: server:
# 服务器的HTTP端口,默认为8080 # 服务器的HTTP端口,默认为8080
port: 28081 port: 28081
servlet: servlet:
# 应用的访问路径 # 应用的访问路径
context-path: / context-path: /
tomcat: tomcat:
# tomcat的URI编码 # tomcat的URI编码
uri-encoding: UTF-8 uri-encoding: UTF-8
# 连接数满后的排队数,默认为100 # 连接数满后的排队数,默认为100
accept-count: 1000 accept-count: 1000
threads: threads:
# tomcat最大线程数,默认为200 # tomcat最大线程数,默认为200
max: 800 max: 800
# Tomcat启动初始化的线程数,默认值10 # Tomcat启动初始化的线程数,默认值10
min-spare: 10 min-spare: 10
# 日志配置 # 日志配置
logging: logging:
level: level:
com.tbyf.his.**.mapper: error com.tbyf.his.**.mapper: error
org.springframework: error org.springframework: error
# Spring配置 # Spring配置
spring: spring:
# 资源信息 # 资源信息
messages: messages:
# 国际化资源文件路径 # 国际化资源文件路径
basename: i18n/messages basename: i18n/messages
profiles: profiles:
active: druid active: druid
# 文件上传 # 文件上传
servlet: servlet:
multipart: multipart:
# 单个文件大小 # 单个文件大小
max-file-size: 1024MB max-file-size: 1024MB
# 设置总上传的文件大小 # 设置总上传的文件大小
max-request-size: 4096MB max-request-size: 4096MB
# 服务模块 # 服务模块
devtools: devtools:
restart: restart:
# 热部署开关 # 热部署开关
enabled: false enabled: false
# redis 配置 # redis 配置
redisEnable: false redisEnable: false
redis: redis:
# 地址 # 地址
# host: 81.68.90.14 # host: 81.68.90.14
host: 127.0.0.1 host: 127.0.0.1
# 端口,默认为6379 # 端口,默认为6379
port: 16378 port: 16378
# port: 6379 # port: 6379
# port: 6379 # port: 6379
# 数据库索引 # 数据库索引
database: 0 database: 0
# 密码 # 密码
password: afJmdkaW07xR password: afJmdkaW07xR
# 连接超时时间 # 连接超时时间
timeout: 3000 timeout: 3000
lettuce: lettuce:
pool: pool:
# 连接池中的最小空闲连接 # 连接池中的最小空闲连接
min-idle: 0 min-idle: 0
# 连接池中的最大空闲连接 # 连接池中的最大空闲连接
max-idle: 8 max-idle: 8
# 连接池的最大数据库连接数 # 连接池的最大数据库连接数
max-active: 8 max-active: 8
# #连接池最大阻塞等待时间(使用负值表示没有限制) # #连接池最大阻塞等待时间(使用负值表示没有限制)
max-wait: -1ms max-wait: -1ms
#json返回全部字段 #json返回全部字段
# jackson: # jackson:
# default-property-inclusion: always # default-property-inclusion: always
# token配置 # token配置
token: token:
# 令牌自定义标识 # 令牌自定义标识
header: Authorization header: Authorization
# 令牌密钥 # 令牌密钥
secret: abcdefghijklmnopqrstuvwxyz secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期(默认30分钟) # 令牌有效期(默认30分钟)
expireTime: 120 expireTime: 120
# MyBatis配置 # MyBatis配置
mybatis: mybatis:
# 搜索指定包别名 # 搜索指定包别名
typeAliasesPackage: com.tbyf.his.**.domain typeAliasesPackage: com.tbyf.his.**.domain
# 配置mapper的扫描,找到所有的mapper.xml映射文件 # 配置mapper的扫描,找到所有的mapper.xml映射文件
mapperLocations: classpath*:mapper/**/*Mapper.xml mapperLocations: classpath*:mapper/**/*Mapper.xml
# 加载全局的配置文件 # 加载全局的配置文件
configLocation: classpath:mybatis/mybatis-config.xml configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件 # PageHelper分页插件
pagehelper: pagehelper:
# helperDialect: mysql 单数据库配置方式 # helperDialect: mysql 单数据库配置方式
reasonable: false reasonable: false
supportMethodsArguments: true supportMethodsArguments: true
params: count=countSql params: count=countSql
# 默认false,当为true时,自动检验适合的数据库 # 默认false,当为true时,自动检验适合的数据库
autoDialect: true autoDialect: true
# 同时支持mysql和oracle分页 # 同时支持mysql和oracle分页
autoRuntimeDialect: true autoRuntimeDialect: true
# Swagger配置 # Swagger配置
swagger: swagger:
# 是否开启swagger # 是否开启swagger
enabled: true enabled: true
# 请求前缀 # 请求前缀
pathMapping: pathMapping:
# pathMapping: /dev-api # pathMapping: /dev-api
springfox: springfox:
documentation: documentation:
swagger: swagger:
use-model-v3=false: false use-model-v3=false: false
# 防止XSS攻击 # 防止XSS攻击
xss: xss:
# 过滤开关 # 过滤开关
enabled: true enabled: true
# 排除链接(多个用逗号分隔) # 排除链接(多个用逗号分隔)
excludes: /system/notice excludes: /system/notice
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
#CAS #CAS
cas: cas:
server: server:
host: host:
#CAS服务地址 #CAS服务地址
url: http://192.168.0.150:38080/cas url: http://192.168.0.150:38080/cas
#CAS服务登录地址 #CAS服务登录地址
login_url: ${cas.server.host.url}/login login_url: ${cas.server.host.url}/login
#CAS服务登出地址 #CAS服务登出地址
logout_url: ${cas.server.host.url}/logout?service=${app.server.host.url} logout_url: ${cas.server.host.url}/logout?service=${app.server.host.url}
# 应用访问地址 # 应用访问地址
app: app:
#开启cas #开启cas
casEnable: false casEnable: false
server: server:
host: host:
url: http://192.168.0.150:${server.port} url: http://192.168.0.150:${server.port}
#应用登录地址 #应用登录地址
login_url: / login_url: /
#应用登出地址 #应用登出地址
logout_url: /logout logout_url: /logout
#前端登录地址 #前端登录地址
web_url: http://192.168.0.150:8081/index web_url: http://192.168.0.150:8081/index
#短信推送参数 #短信推送参数
shortMessage: shortMessage:
appid: wx682d527dd7a46d99 appid: wx682d527dd7a46d99
type: ywtz type: ywtz
msgUrl: http://172.16.9.118:10176/xxx msgUrl: http://172.16.9.118:10176/xxx
#集成平台数据源id #集成平台数据源id
manageData: manageData:
dataSourceId: 10 dataSourceId: 10
h2cache: h2cache:
enabled: false enabled: false
ehcache: ehcache:
filePath: ehcache.xml filePath: ehcache.xml
shared: true shared: true
redis: redis:
config-list[0]: config-list[0]:
cache-name: "sys_dict:" cache-name: "sys_dict:"
ttl: 1800 ttl: 1800
use-prefix: true use-prefix: true
disable-null-values: true disable-null-values: true
config-list[1]: config-list[1]:
cache-name: "login_tokens:" cache-name: "login_tokens:"
ttl: 86400 ttl: 86400
use-prefix: true use-prefix: true
disable-null-values: true disable-null-values: true
config-list[2]: config-list[2]:
cache-name: "captcha_codes:" cache-name: "captcha_codes:"
ttl: 180 ttl: 180
use-prefix: true use-prefix: true
disable-null-values: true disable-null-values: true
config-list[3]: config-list[3]:
cache-name: "repeat_submit:" cache-name: "repeat_submit:"
ttl: 10 ttl: 10
use-prefix: true use-prefix: true
disable-null-values: true disable-null-values: true
config-list[4]: config-list[4]:
cache-name: "rate_limit:" cache-name: "rate_limit:"
ttl: 60 ttl: 60
use-prefix: true use-prefix: true
disable-null-values: true disable-null-values: true
# config-list[5]: # config-list[5]:
# cache-name: "sys_config:" # cache-name: "sys_config:"
# ttl: 60 # ttl: 60
# use-prefix: true # use-prefix: true
# disable-null-values: true # disable-null-values: true
tx: tx:
SecretId: AKIDsYyLVP3RYOyHJ4YlhMksjJcASUFjxuZx SecretId: AKIDsYyLVP3RYOyHJ4YlhMksjJcASUFjxuZx
SecretKey: 8zZs0rRkmZ5KIzQaT5QUGlzwc1A2dx0m SecretKey: 8zZs0rRkmZ5KIzQaT5QUGlzwc1A2dx0m
SdkAppId: 1400526481 SdkAppId: 1400526481
SignName: 武汉市第九医院 SignName: 武汉市第九医院
adapter: adapter:
syncPath: http://192.168.0.153:15001/datacenter/rpc/webservice/SubscriptionService?wsdl syncPath: http://192.168.0.153:15001/datacenter/rpc/webservice/SubscriptionService?wsdl
sourceId: Adapt sourceId: Adapt
...@@ -47,6 +47,11 @@ ...@@ -47,6 +47,11 @@
<artifactId>mybatis-plus-extension</artifactId> <artifactId>mybatis-plus-extension</artifactId>
<version>3.5.0</version> <version>3.5.0</version>
</dependency> </dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
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