Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不是太高的手
SPTools
提交
39b83f90
S
SPTools
项目概览
不是太高的手
/
SPTools
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SPTools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
39b83f90
编写于
9月 08, 2020
作者:
Z
zhipeng.zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化经纬度查询
上级
3553c412
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
138 addition
and
31 deletion
+138
-31
pom.xml
pom.xml
+5
-0
src/main/java/com/tools/common/excel/ExcelUtil.java
src/main/java/com/tools/common/excel/ExcelUtil.java
+74
-0
src/main/java/com/tools/common/excel/User.java
src/main/java/com/tools/common/excel/User.java
+38
-0
src/main/java/com/tools/common/util/BaiDuMapUtils.java
src/main/java/com/tools/common/util/BaiDuMapUtils.java
+21
-30
src/main/java/com/tools/module/app/web/DingController.java
src/main/java/com/tools/module/app/web/DingController.java
+0
-1
未找到文件。
pom.xml
浏览文件 @
39b83f90
...
...
@@ -186,6 +186,11 @@
<artifactId>
fastjson
</artifactId>
<version>
1.2.73
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
<version>
2.2.6
</version>
</dependency>
</dependencies>
<build>
<finalName>
picture-bed
</finalName>
...
...
src/main/java/com/tools/common/excel/ExcelUtil.java
0 → 100644
浏览文件 @
39b83f90
package
com.tools.common.excel
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.style.HorizontalCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URLEncoder
;
import
java.util.List
;
/**
* Excel 工具类
*/
public
class
ExcelUtil
{
/**
* 导出 Excel :一个 sheet,带表头.
* @param response HttpServletResponse
* @param data 数据 list,每个元素为一个 BaseRowModel
* @param fileName 导出的文件名
* @param sheetName 导入文件的 sheet 名
* @param model 映射实体类,Excel 模型
* @throws Exception 异常
*/
public
static
void
writeExcel
(
HttpServletResponse
response
,
List
<?
extends
Object
>
data
,
String
fileName
,
String
sheetName
,
Class
model
)
throws
Exception
{
/**
* 头的策略 设置表头居中对齐
*/
WriteCellStyle
headWriteCellStyle
=
new
WriteCellStyle
();
headWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
CENTER
);
/**
* 内容的策略 设置内容靠左对齐
*/
WriteCellStyle
contentWriteCellStyle
=
new
WriteCellStyle
();
contentWriteCellStyle
.
setHorizontalAlignment
(
HorizontalAlignment
.
LEFT
);
HorizontalCellStyleStrategy
horizontalCellStyleStrategy
=
new
HorizontalCellStyleStrategy
(
headWriteCellStyle
,
contentWriteCellStyle
);
EasyExcel
.
write
(
getOutputStream
(
fileName
,
response
),
model
)
.
excelType
(
ExcelTypeEnum
.
XLSX
)
.
sheet
(
sheetName
)
.
registerWriteHandler
(
horizontalCellStyleStrategy
)
.
registerWriteHandler
(
new
LongestMatchColumnWidthStyleStrategy
())
.
doWrite
(
data
);
}
/**
* 导出文件时为Writer生成OutputStream.
* @param fileName 文件名
* @param response response
* @return ""
*/
private
static
OutputStream
getOutputStream
(
String
fileName
,
HttpServletResponse
response
)
throws
Exception
{
try
{
fileName
=
URLEncoder
.
encode
(
fileName
,
"UTF-8"
);
response
.
setContentType
(
"application/vnd.ms-excel"
);
response
.
setCharacterEncoding
(
"utf8"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment; filename="
+
fileName
+
".xlsx"
);
response
.
setHeader
(
"Pragma"
,
"public"
);
response
.
setHeader
(
"Cache-Control"
,
"no-store"
);
response
.
addHeader
(
"Cache-Control"
,
"max-age=0"
);
return
response
.
getOutputStream
();
}
catch
(
IOException
e
)
{
throw
new
Exception
(
"导出excel表格失败!"
,
e
);
}
}
}
\ No newline at end of file
src/main/java/com/tools/common/excel/User.java
0 → 100644
浏览文件 @
39b83f90
package
com.tools.common.excel
;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.alibaba.excel.annotation.write.style.ContentRowHeight
;
import
com.alibaba.excel.metadata.BaseRowModel
;
import
com.alibaba.excel.metadata.BasicParameter
;
import
lombok.Data
;
import
java.io.Serializable
;
@Data
@ColumnWidth
(
22
)
@ContentRowHeight
(
15
)
public
class
User
implements
Serializable
{
/**
* value: 表头名称
* index: 列的号, 0表示第一列
*
*/
/**
* 入库时间
*/
@ExcelProperty
(
value
=
"姓名"
,
index
=
0
)
private
String
name
;
/**
* 供应商
*/
@ExcelProperty
(
value
=
"年龄"
,
index
=
1
)
private
String
age
;
/**
* 纸筒编号
*/
@ExcelProperty
(
value
=
"性别"
,
index
=
2
)
private
String
sex
;
}
src/main/java/com/tools/common/util/BaiDuMapUtils.java
浏览文件 @
39b83f90
...
...
@@ -6,13 +6,11 @@ import com.tools.common.model.Result;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.http.*
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLConnection
;
import
java.text.DecimalFormat
;
import
java.util.HashMap
;
import
java.util.Map
;
...
...
@@ -27,9 +25,11 @@ public class BaiDuMapUtils {
static
Logger
logger
=
LoggerFactory
.
getLogger
(
BaiDuMapUtils
.
class
);
static
String
AK
=
"
888
"
;
static
String
AK
=
"
*****************
"
;
static
String
SN
=
"888"
;
static
String
SN
=
"*****************"
;
static
String
STATUS
=
"status"
;
public
static
void
main
(
String
[]
args
)
{
String
dom
=
"北京王府井"
;
...
...
@@ -44,12 +44,22 @@ public class BaiDuMapUtils {
public
static
Result
getCoordinate
(
String
address
)
{
if
(
address
!=
null
&&
!
""
.
equals
(
address
))
{
address
=
address
.
replaceAll
(
"\\s*"
,
""
).
replace
(
"#"
,
"栋"
);
String
url
=
"http://api.map.baidu.com/geocoding/v3/?address="
+
address
+
"&output=json&ak="
+
AK
+
"&SN="
+
SN
;
String
json
=
loadJSON
(
url
);
String
url
=
"http://api.map.baidu.com/geocoding/v3"
;
RestTemplate
client
=
new
RestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
MultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<>();
params
.
add
(
"address"
,
address
);
params
.
add
(
"output"
,
"json"
);
params
.
add
(
"ak"
,
AK
);
params
.
add
(
"sn"
,
SN
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
requestEntity
=
new
HttpEntity
<>(
params
,
headers
);
ResponseEntity
<
String
>
response
=
client
.
exchange
(
url
,
HttpMethod
.
POST
,
requestEntity
,
String
.
class
);
String
json
=
response
.
getBody
();
logger
.
info
(
"位置信息:{}"
,
json
);
if
(
StringUtils
.
isNotBlank
(
json
))
{
JSONObject
obj
=
JSONObject
.
parseObject
(
json
);
if
(
SystemConstant
.
CODE_0
.
equals
(
obj
.
getString
(
"status"
)))
{
if
(
SystemConstant
.
CODE_0
.
equals
(
obj
.
getString
(
STATUS
)))
{
/**
* 经度
*/
...
...
@@ -73,23 +83,4 @@ public class BaiDuMapUtils {
return
Result
.
error
();
}
}
public
static
String
loadJSON
(
String
url
)
{
StringBuilder
json
=
new
StringBuilder
();
try
{
URL
oracle
=
new
URL
(
url
);
URLConnection
yc
=
oracle
.
openConnection
();
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
yc
.
getInputStream
(),
"UTF-8"
));
String
inputLine
;
while
((
inputLine
=
in
.
readLine
())
!=
null
)
{
json
.
append
(
inputLine
);
}
in
.
close
();
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
json
.
toString
();
}
}
src/main/java/com/tools/module/app/web/DingController.java
浏览文件 @
39b83f90
...
...
@@ -8,7 +8,6 @@ import com.tools.module.app.entity.AppDingUser;
import
com.tools.module.app.service.AppDingService
;
import
com.tools.module.app.service.AppDingUserService
;
import
io.swagger.annotations.Api
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录