1、pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.20.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cb.tool</groupId>
<artifactId>analyse</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>analyse</name>
<description>analyse tool</description> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>
<commons-lang3.version>3.6</commons-lang3.version>
<fastjson.version>1.2.31</fastjson.version>
</properties> <dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.31</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency> <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency> <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency> <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency> <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency> <dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- start https -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- end https --> <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.3</version>
</dependency> <dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.0</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency> <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency> <dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency> </dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<!-- maven打包插件 end -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>analyse</warName>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>application.yml</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
</build> </project>

2、controller层

@RequestMapping("/sumUpdate")
@ResponseBody
public String updateDealSumInfo() { realTimeDealService.updateDealSumInfo();
return "sumUpdate ok";
}

3、service层

@Override
public void updateDealSumInfo() {
String dirPath = PropConfig.getXls();
File dir = new File(dirPath);
File[] fs = dir.listFiles();
StringBuilder sb=new StringBuilder();
if (fs != null) {
for (File f : fs) {
if (f.isFile()) {
String fName = f.getName().split("\\.")[0]; HSSFWorkbook workbook = null;
FileInputStream excelFileInputStream = null;
try {
excelFileInputStream = new FileInputStream(dirPath + f.getName());
workbook = new HSSFWorkbook(excelFileInputStream);
HSSFSheet sheet1 = workbook.getSheetAt(0);
HashMap<String, Integer> keyMap = new HashMap<>();
getTitleIndex(sheet1, keyMap);
int lastRowNum = sheet1.getLastRowNum();
HashMap<String, String> nameMap=new HashMap();
HashMap<String, String> codeMap=new HashMap();
for (int i = 1; i <=lastRowNum; i++) { // i=1 : from 2th row exclude titile
HSSFRow row = sheet1.getRow(i);
String hosopt_name = getCellStrVal(row.getCell(keyMap.get("hosopt_name")));
if(!nameMap.containsKey(hosopt_name)){
nameMap.put(hosopt_name,"1");
}else {
continue;
}
String pinyin = HanyuPinyinHelper.getFirstLettersUp(hosopt_name);
if(!codeMap.containsKey(pinyin)){
codeMap.put(pinyin,pinyin);
}else {
codeMap.put(pinyin,pinyin+i);
}
pinyin=codeMap.get(pinyin);
sb.append("insert into oi_hos_custom_opt(`hosopt_name`, `spell_code`, `cust_code`) values('")
.append(hosopt_name).append("','").append(pinyin).append("','").append(pinyin).append("');").append("\r\n");
}
} catch (IOException e) {
logger.error("read excel error", e);
} finally {
if (excelFileInputStream != null) {
try {
excelFileInputStream.close();
} catch (IOException e) {
logger.error("excelFileInputStream close error");
}
}
}
}
}
}
System.out.println(sb.toString());
}
private void getTitleIndex(HSSFSheet sheet1, HashMap<String, Integer> keyMap) {
HSSFRow firstRow = sheet1.getRow(0);
short firstCellNum = firstRow.getFirstCellNum();
short lastCellNum = firstRow.getLastCellNum();
for (int i = firstCellNum; i <= lastCellNum; i++) {
String cellStrVal = getCellStrVal(firstRow.getCell(i));
if (cellStrVal.equals("手术名称")) {
keyMap.put("hosopt_name", i);
}
}
}

4、工具类

package cb.tool.analyse.util;

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 net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; public class HanyuPinyinHelper { /**
* 将文字转为汉语拼音
* @param ChineseLanguage 要转成拼音的中文
*/
public static String toHanyuPinyin(String ChineseLanguage){
char[] cl_chars = ChineseLanguage.trim().toCharArray();
String hanyupinyin = "";
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);// 输出拼音全部小写
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调
defaultFormat.setVCharType(HanyuPinyinVCharType.WITH_V) ;
try {
for (int i=0; i<cl_chars.length; i++){
if (String.valueOf(cl_chars[i]).matches("[\u4e00-\u9fa5]+")){// 如果字符是中文,则将中文转为汉语拼音
hanyupinyin += PinyinHelper.toHanyuPinyinStringArray(cl_chars[i], defaultFormat)[0];
} else {// 如果字符不是中文,则不转换
hanyupinyin += cl_chars[i];
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
System.out.println("字符不能转成汉语拼音");
}
return hanyupinyin;
} public static String getFirstLettersUp(String ChineseLanguage){
return getFirstLetters(ChineseLanguage ,HanyuPinyinCaseType.UPPERCASE);
} public static String getFirstLettersLo(String ChineseLanguage){
return getFirstLetters(ChineseLanguage ,HanyuPinyinCaseType.LOWERCASE);
} public static String getFirstLetters(String ChineseLanguage,HanyuPinyinCaseType caseType) {
char[] cl_chars = ChineseLanguage.trim().toCharArray();
String hanyupinyin = "";
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(caseType);// 输出拼音全部大写
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调
try {
for (int i = 0; i < cl_chars.length; i++) {
String str = String.valueOf(cl_chars[i]);
if (str.matches("[\u4e00-\u9fa5]+")) {// 如果字符是中文,则将中文转为汉语拼音,并取第一个字母
hanyupinyin += PinyinHelper.toHanyuPinyinStringArray(cl_chars[i], defaultFormat)[0].substring(0, 1);
} else if (str.matches("[0-9]+")) {// 如果字符是数字,取数字
hanyupinyin += cl_chars[i];
} else if (str.matches("[a-zA-Z]+")) {// 如果字符是字母,取字母
hanyupinyin += cl_chars[i];
} else {// 否则不转换
hanyupinyin += cl_chars[i];//如果是标点符号的话,带着
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
System.out.println("字符不能转成汉语拼音");
}
return hanyupinyin;
} public static String getPinyinString(String ChineseLanguage){
char[] cl_chars = ChineseLanguage.trim().toCharArray();
String hanyupinyin = "";
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);// 输出拼音全部大写
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调
try {
for (int i = 0; i < cl_chars.length; i++) {
String str = String.valueOf(cl_chars[i]);
if (str.matches("[\u4e00-\u9fa5]+")) {// 如果字符是中文,则将中文转为汉语拼音,并取第一个字母
hanyupinyin += PinyinHelper.toHanyuPinyinStringArray(
cl_chars[i], defaultFormat)[0];
} else if (str.matches("[0-9]+")) {// 如果字符是数字,取数字
hanyupinyin += cl_chars[i];
} else if (str.matches("[a-zA-Z]+")) {// 如果字符是字母,取字母 hanyupinyin += cl_chars[i];
} else {// 否则不转换
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
System.out.println("字符不能转成汉语拼音");
}
return hanyupinyin;
}
/**
* 取第一个汉字的第一个字符
* @Title: getFirstLetter
* @Description: TODO
* @return String
* @throws
*/
public static String getFirstLetter(String ChineseLanguage){
char[] cl_chars = ChineseLanguage.trim().toCharArray();
String hanyupinyin = "";
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);// 输出拼音全部大写
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调
try {
String str = String.valueOf(cl_chars[0]);
if (str.matches("[\u4e00-\u9fa5]+")) {// 如果字符是中文,则将中文转为汉语拼音,并取第一个字母
hanyupinyin = PinyinHelper.toHanyuPinyinStringArray(
cl_chars[0], defaultFormat)[0].substring(0, 1);;
} else if (str.matches("[0-9]+")) {// 如果字符是数字,取数字
hanyupinyin += cl_chars[0];
} else if (str.matches("[a-zA-Z]+")) {// 如果字符是字母,取字母 hanyupinyin += cl_chars[0];
} else {// 否则不转换 }
} catch (BadHanyuPinyinOutputFormatCombination e) {
System.out.println("字符不能转成汉语拼音");
}
return hanyupinyin;
} public static void main(String[] args) {
System.out.println(HanyuPinyinHelper.toHanyuPinyin("中秋节"));
}
}

5、配置文件:

file:
xls: E:\myFiles\data\a\

从excel中转存sql的更多相关文章

  1. 在Excel中使用SQL语句查询和筛选

    本文转自:http://blog.sina.com.cn/s/blog_5fc375650102e1g5.html 今天在微博上看到@数据分析精选 分享的一篇文章,是关于<在Excel中使用SQ ...

  2. Excel下用SQL语句实现AVEDEV函数功能

    Excel下AVEDEV函数返回一组数据点到其算术平均值的绝对偏差的平均值. AVEDEV 是对一组数据中变化性的度量.最常见的应用就是统计平均分差. 但是如果在Excel中写SQL进行一些复杂的统计 ...

  3. Excel数据生成Sql语句的方法

    选中想要生成的列,套用表格格式,选中表包含标题的选项确定,然后在最右边的一列第二行处,点击函数功能,选择CONCATENATE,在文本里输入想要的结构即可  代码如下 复制代码 ,=CONCATENA ...

  4. Excel 中使用sql语句查询

    将Excel连接Oracle数据库 Excel选项板中"数据"—"自其他来源"下拉菜单中有有个可以连接其它数据库的选项"来自数据连接向导"和 ...

  5. 将Excel导出为SQL语句

    需求说明:公司做项目前进行需求分析,确定表结构后需要建表,如果照着表格去敲,那就太麻烦了,所以想到了自动生成SQL语句. 思路大概就是:解析Excel,拼接SQL语句,输出SQL文件. 第三方jar包 ...

  6. Excel导入MS SQL SERVER 操作

    关于Excel导入到sql操作的相关问题总结: 一.大批量数据导入 方法1.从Excel大批量数据导入时我们可以使用sql里面有一个batch copy的功能 方法2.在sql中建一个table ty ...

  7. 通过Excel生成批量SQL语句

    项目中有时会遇到这样的要求:用户给发过来一些数据,要我们直接给存放到数据库里面,有的是Insert,有的是Update等等,少量的数据我们可以采取最原始的办法,也就是在SQL里面用Insert int ...

  8. 在EXCEL中使用SQL语句查询

    SQL语句在数据库使用中十分重要. 在EXCEL中可以不打开工作簿,就获取数据,对多工作簿操作很用,也很快. 对大量数据处理,比循环快很多,但是比词典方法还有点距离(可惜我还没有学会词典). 对数据库 ...

  9. [转]在Excel中使用SQL语句实现精确查询

    本文转自:http://blog.sina.com.cn/s/blog_5fc375650102e1g5.html 今天在微博上看到@数据分析精选 分享的一篇文章,是关于<在Excel中使用SQ ...

随机推荐

  1. 微软官方 Github 上的 EF 示例项目 EntityFramework.Docs

    项目地址:https://github.com/aspnet/EntityFramework.Docs/tree/master/samples/core 谢谢浏览!

  2. Java 函数式编程—@FunctionalInterface----functional interface

    单一函数接口,可以使用拉姆达表达式的形式具体化和实例化. 本质是将接口函数签名化. 如定义了一个函数式接口如下: @FunctionalInterface interface GreetingServ ...

  3. WPF-介绍一款能够自动格式化XAML界面代码的的插件

    因为之前有小伙伴问格式化XAMl的快捷键按钮,所以在这里分享一款格式化XAMl的插件,非常好用. 直接在工具-->扩展和更新里搜索XamlStyler下载安装即可. 安装后按CTRL+S保存后就 ...

  4. JavaScript的闭包特性如何给循环中的对象添加事件(一)

    初学者经常碰到的,即获取HTML元素集合,循环给元素添加事件.在事件响应函数中(event handler)获取对应的索引.但每次获取的都是最后一次循环的索引.原因是初学者并未理解JavaScript ...

  5. WebApi使用Unity实现IOC

    最近在学习ASP.NET MVC,使用Unity作为依赖注入容器.分别在WebAPI和MVC中使用.这篇文章介绍WebAPI,MVC的在下篇文章中介绍.下面是学习的一点经验. 一 IOC简单介绍 Io ...

  6. JS读取xml

    xml文件 <?xml version="1.0" encoding="utf-8"?> <root> <data id=&quo ...

  7. curl sftp libcurl 功能使用

    #include <curl/curl.h> #undef DISABLE_SSH_AGENT struct FtpFile { const char *filename; FILE *s ...

  8. ios官方demo

    http://developer.apple.com/iphone/library/samplecode/Reachability/Reachability.ziphttp://developer.a ...

  9. vue学习指南:第十篇(详细) - Vue的 动画

    Vue 提供了一些不同的过度效果,主要根 v-if v-show 动态组件 1. Vue给动画分了6个过程,在css中,扮演6个类, 1.  .v-enter定义动画的开始状态 2.  .v-ente ...

  10. 转:oracle 体系结构

    前几天面试的时候面试官才问过我ORACLE的体系结构,让我在一张白纸上画出来.回头想想当时答得还不错,大部分内容都描述出来了,呵呵,刚才在网上看到一篇讲解ORACLE体系结构的文章,觉得不错,转过来存 ...