Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
promotion-common
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
promotion
promotion-common
Commits
73e30a5f
提交
73e30a5f
authored
9月 04, 2024
作者:
000516
提交者:
Coding
9月 04, 2024
浏览文件
操作
浏览文件
下载
差异文件
添加工具类:读取excel;更新RedisKey;返回R对象修改;Long对象处理
添加工具类:读取excel;更新RedisKey;返回R对象修改;Long对象处理
上级
7f80f1ca
77ab6228
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
227 行增加
和
3 行删除
+227
-3
pom.xml
pom.xml
+17
-2
ReadExcelUtils.java
...com/wangxiaolu/promotion/common/excel/ReadExcelUtils.java
+152
-0
RedisKeys.java
...java/com/wangxiaolu/promotion/common/redis/RedisKeys.java
+5
-1
RedisCache.java
...wangxiaolu/promotion/common/redis/service/RedisCache.java
+25
-0
NumberUtils.java
...ava/com/wangxiaolu/promotion/common/util/NumberUtils.java
+12
-0
R.java
...main/java/com/wangxiaolu/promotion/result/basedata/R.java
+6
-0
RCode.java
.../java/com/wangxiaolu/promotion/result/basedata/RCode.java
+10
-0
没有找到文件。
pom.xml
浏览文件 @
73e30a5f
...
@@ -5,14 +5,14 @@
...
@@ -5,14 +5,14 @@
<parent>
<parent>
<groupId>
com.wangxiaolu
</groupId>
<groupId>
com.wangxiaolu
</groupId>
<artifactId>
wangxiaolu-promotion-parent
</artifactId>
<artifactId>
wangxiaolu-promotion-parent
</artifactId>
<version>
0.0.
1
</version>
<version>
0.0.
2
</version>
</parent>
</parent>
<groupId>
com.wangxiaolu
</groupId>
<groupId>
com.wangxiaolu
</groupId>
<artifactId>
wangxiaolu-promotion-common
</artifactId>
<artifactId>
wangxiaolu-promotion-common
</artifactId>
<version>
0.0.
1
</version>
<version>
0.0.
2
</version>
<name>
wangxiaolu-promotion-common
</name>
<name>
wangxiaolu-promotion-common
</name>
<description>
wangxiaolu-promotion-common
</description>
<description>
wangxiaolu-promotion-common
</description>
...
@@ -113,6 +113,21 @@
...
@@ -113,6 +113,21 @@
<scope>
import
</scope>
<scope>
import
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
${poi-ooxml.version}
</version>
</dependency>
<!-- 读取大量excel数据时使用 -->
<!-- https://mvnrepository.com/artifact/com.monitorjbl/xlsx-streamer -->
<dependency>
<groupId>
com.monitorjbl
</groupId>
<artifactId>
xlsx-streamer
</artifactId>
<version>
${xlsx-streamer.version}
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
src/main/java/com/wangxiaolu/promotion/common/excel/ReadExcelUtils.java
0 → 100644
浏览文件 @
73e30a5f
package
com
.
wangxiaolu
.
promotion
.
common
.
excel
;
import
cn.hutool.core.date.DatePattern
;
import
com.wangxiaolu.promotion.exception.DataException
;
import
com.wangxiaolu.promotion.result.basedata.RCode
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.util.*
;
/**
* @author : liqiulin
* @date : 2024-08-16 15
* @describe :读取Excel
*/
public
class
ReadExcelUtils
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ReadExcelUtils
.
class
);
private
Workbook
wb
;
private
Sheet
sheet
;
private
Row
row
;
public
ReadExcelUtils
(
String
filepath
)
{
if
(
filepath
==
null
)
{
throw
new
DataException
(
RCode
.
READ_FILE_PATH_NULL_ERROR
);
}
String
ext
=
filepath
.
substring
(
filepath
.
lastIndexOf
(
"."
));
try
{
InputStream
is
=
new
FileInputStream
(
filepath
);
if
(
".xls"
.
equals
(
ext
))
{
wb
=
new
HSSFWorkbook
(
is
);
}
else
if
(
".xlsx"
.
equals
(
ext
))
{
wb
=
new
XSSFWorkbook
(
is
);
}
else
{
throw
new
DataException
(
RCode
.
EXCEL_IS_XLS_OR_XLSX_FILE
);
}
}
catch
(
FileNotFoundException
e
)
{
logger
.
error
(
"FileNotFoundException"
,
e
);
throw
new
DataException
(
RCode
.
READ_EXCEL_NULL_ERROR
);
}
catch
(
IOException
e
)
{
logger
.
error
(
"IOException"
,
e
);
throw
new
DataException
(
RCode
.
READ_EXCEL_NULL_ERROR
);
}
}
/**
* 读取Excel表格表头的内容
*
* @return String 表头内容的数组
* @author zengwendong
*/
public
String
[]
readTitle
()
{
if
(
wb
==
null
)
{
throw
new
DataException
(
"Workbook对象为空!"
);
}
sheet
=
wb
.
getSheetAt
(
0
);
row
=
sheet
.
getRow
(
0
);
// 标题总列数
int
colNum
=
row
.
getPhysicalNumberOfCells
();
System
.
out
.
println
(
"colNum:"
+
colNum
);
String
[]
title
=
new
String
[
colNum
];
for
(
int
i
=
0
;
i
<
colNum
;
i
++)
{
// title[i] = getStringCellValue(row.getCell((short) i));
title
[
i
]
=
row
.
getCell
(
i
).
getStringCellValue
();
}
return
title
;
}
/**
* 读取Excel数据内容
*
* @return Map 包含单元格数据内容的Map对象
* @author zengwendong
*/
public
Map
<
Integer
,
List
<
Object
>>
readContent
(){
if
(
wb
==
null
)
{
throw
new
DataException
(
"Workbook对象为空!"
);
}
sheet
=
wb
.
getSheetAt
(
0
);
int
rowNum
=
sheet
.
getLastRowNum
();
Map
<
Integer
,
List
<
Object
>>
content
=
new
HashMap
<>(
rowNum
*
2
);
row
=
sheet
.
getRow
(
0
);
int
colNum
=
row
.
getPhysicalNumberOfCells
();
// 正文内容应该从第二行开始,第一行为表头的标题
for
(
int
i
=
1
;
i
<=
rowNum
;
i
++)
{
row
=
sheet
.
getRow
(
i
);
int
j
=
0
;
List
<
Object
>
cellValues
=
new
ArrayList
<>(
rowNum
*
2
);
while
(
j
<
colNum
)
{
Object
obj
=
getCellFormatValue
(
row
.
getCell
(
j
));
cellValues
.
add
(
obj
);
j
++;
}
// 如果row没有值,则停止解析
Set
vset
=
new
HashSet
(
cellValues
);
if
(
vset
.
size
()
<=
1
){
return
content
;
}
content
.
put
(
i
,
cellValues
);
}
return
content
;
}
/**
* 根据Cell类型设置数据
*
* @param cell
* @return
* @author zengwendong
*/
private
Object
getCellFormatValue
(
Cell
cell
)
{
Object
cellvalue
=
""
;
//判断是否为null或空串
if
(
cell
==
null
||
cell
.
toString
().
trim
().
equals
(
""
))
{
return
""
;
}
CellType
cellType
=
cell
.
getCellType
();
switch
(
cellType
)
{
case
STRING:
cellvalue
=
cell
.
getStringCellValue
();
break
;
case
NUMERIC:
if
(
DateUtil
.
isCellDateFormatted
(
cell
))
{
cellvalue
=
cell
.
getDateCellValue
();
}
else
{
BigDecimal
number
=
new
BigDecimal
(
cell
.
getNumericCellValue
());
cellvalue
=
number
.
toPlainString
();
}
break
;
default
:
return
""
;
}
return
cellvalue
;
}
}
\ No newline at end of file
src/main/java/com/wangxiaolu/promotion/common/redis/RedisKeys.java
浏览文件 @
73e30a5f
...
@@ -16,6 +16,10 @@ public interface RedisKeys {
...
@@ -16,6 +16,10 @@ public interface RedisKeys {
* 促销员小程序用户登录信息:token
* 促销员小程序用户登录信息:token
*/
*/
TEMPORARY_TOKEN
(
"user:login_token:temporary:"
),
TEMPORARY_TOKEN
(
"user:login_token:temporary:"
),
/**
* 组织数据 - 客户类数据 - 经销商
*/
DEALER_HAVE_LIST
(
"user:clientele:dealer_all"
),
;
;
String
key
;
String
key
;
...
@@ -42,7 +46,7 @@ public interface RedisKeys {
...
@@ -42,7 +46,7 @@ public interface RedisKeys {
@Getter
@Getter
enum
ExportKeys
{
enum
ExportKeys
{
/**
/**
*
促销员暂存上报记录单元
*
导出
*/
*/
ACTIVITY_REPORTED_PUSH_FEISHU_SHEET
(
"export:activity_feishu:sheet_row_num:sheet-"
),
ACTIVITY_REPORTED_PUSH_FEISHU_SHEET
(
"export:activity_feishu:sheet_row_num:sheet-"
),
FEISHU_TENANT_TOKEN_ACTIVITY_ROBOT_1
(
"export:feishu_tenant_token:activity_robot_1"
),
FEISHU_TENANT_TOKEN_ACTIVITY_ROBOT_1
(
"export:feishu_tenant_token:activity_robot_1"
),
...
...
src/main/java/com/wangxiaolu/promotion/common/redis/service/RedisCache.java
浏览文件 @
73e30a5f
...
@@ -3,10 +3,15 @@ package com.wangxiaolu.promotion.common.redis.service;
...
@@ -3,10 +3,15 @@ package com.wangxiaolu.promotion.common.redis.service;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.HashOperations
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.SetOperations
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.data.redis.core.ValueOperations
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
@Component
@Component
...
@@ -89,6 +94,25 @@ public class RedisCache {
...
@@ -89,6 +94,25 @@ public class RedisCache {
return
JSONObject
.
parseArray
(
val
);
return
JSONObject
.
parseArray
(
val
);
}
}
public
void
putAllHash
(
String
key
,
Map
<
Object
,
Object
>
values
)
{
redisTemplate
.
opsForHash
().
putAll
(
key
,
values
);
}
public
String
getHash
(
String
key
,
String
hashKey
){
Object
o
=
redisTemplate
.
opsForHash
().
get
(
key
,
hashKey
);
return
o
.
toString
();
}
public
Map
<
Object
,
Object
>
getAllHash
(
String
key
){
Map
<
Object
,
Object
>
entries
=
redisTemplate
.
opsForHash
().
entries
(
key
);
return
entries
;
}
public
Set
<
Object
>
getHashKeys
(
String
key
){
Set
<
Object
>
keys
=
redisTemplate
.
opsForHash
().
keys
(
key
);
return
keys
;
}
/**
/**
* 获取一个值,并将val json化
* 获取一个值,并将val json化
*/
*/
...
@@ -101,6 +125,7 @@ public class RedisCache {
...
@@ -101,6 +125,7 @@ public class RedisCache {
}
}
private
String
valToJson
(
Object
o
)
{
private
String
valToJson
(
Object
o
)
{
return
JSONObject
.
toJSONString
(
o
);
return
JSONObject
.
toJSONString
(
o
);
}
}
...
...
src/main/java/com/wangxiaolu/promotion/common/util/NumberUtils.java
浏览文件 @
73e30a5f
package
com
.
wangxiaolu
.
promotion
.
common
.
util
;
package
com
.
wangxiaolu
.
promotion
.
common
.
util
;
import
com.wangxiaolu.promotion.exception.DataException
;
import
com.wangxiaolu.promotion.result.basedata.RCode
;
import
java.util.Objects
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
...
@@ -16,4 +20,12 @@ public class NumberUtils {
...
@@ -16,4 +20,12 @@ public class NumberUtils {
Matcher
m
=
pattern
.
matcher
(
str
);
Matcher
m
=
pattern
.
matcher
(
str
);
return
Integer
.
parseInt
(
m
.
replaceAll
(
""
).
trim
());
return
Integer
.
parseInt
(
m
.
replaceAll
(
""
).
trim
());
}
}
public
static
boolean
notNull
(
int
num
){
return
num
>
0
;
}
public
static
boolean
isNull
(
Long
value
){
return
Objects
.
isNull
(
value
)
||
value
<=
0L
;
}
}
}
src/main/java/com/wangxiaolu/promotion/result/basedata/R.java
浏览文件 @
73e30a5f
...
@@ -85,4 +85,10 @@ public class R {
...
@@ -85,4 +85,10 @@ public class R {
public
static
R
success
()
{
public
static
R
success
()
{
return
new
R
();
return
new
R
();
}
}
public
static
R
fail
()
{
return
new
R
(
RCode
.
FAILED
,
null
);
}
public
static
R
fail
(
Object
data
)
{
return
new
R
(
RCode
.
FAILED
,
data
);
}
}
}
src/main/java/com/wangxiaolu/promotion/result/basedata/RCode.java
浏览文件 @
73e30a5f
...
@@ -17,6 +17,7 @@ public enum RCode implements StatusCode {
...
@@ -17,6 +17,7 @@ public enum RCode implements StatusCode {
FAILED
(
1001
,
"请求失败"
),
FAILED
(
1001
,
"请求失败"
),
PARAM_ERROR
(
1002
,
"参数错误"
),
PARAM_ERROR
(
1002
,
"参数错误"
),
RESPONSE_PACK_ERROR
(
1003
,
"包装R失败"
),
RESPONSE_PACK_ERROR
(
1003
,
"包装R失败"
),
SELECT_PARAMS_ERROR
(
1004
,
"查询条件错误"
),
/**
/**
* 业务统一编码(不分模块)
* 业务统一编码(不分模块)
...
@@ -28,6 +29,9 @@ public enum RCode implements StatusCode {
...
@@ -28,6 +29,9 @@ public enum RCode implements StatusCode {
STATUS_UPDATE_ERROR
(
2003
,
"当前状态不可修改"
),
STATUS_UPDATE_ERROR
(
2003
,
"当前状态不可修改"
),
DATA_NOT_HAVE_ERROR
(
2004
,
"数据不存在"
),
DATA_NOT_HAVE_ERROR
(
2004
,
"数据不存在"
),
DATA_TOO_MANY_ERROR
(
2005
,
"唯一数据存在多条"
),
DATA_TOO_MANY_ERROR
(
2005
,
"唯一数据存在多条"
),
READ_EXCEL_NULL_ERROR
(
2006
,
"表格为空或格式错误,请上传正确的文件"
),
READ_FILE_PATH_NULL_ERROR
(
2007
,
"文件读取失败,未获取到有效地址"
),
EXCEL_IS_XLS_OR_XLSX_FILE
(
2008
,
"请上传xls或xlsx表格文件"
),
/**
/**
* user
* user
...
@@ -78,6 +82,12 @@ public enum RCode implements StatusCode {
...
@@ -78,6 +82,12 @@ public enum RCode implements StatusCode {
CLOCK_DATA_NOT_HAVE_ERROR
(
4022
,
"打卡记录不存在"
),
CLOCK_DATA_NOT_HAVE_ERROR
(
4022
,
"打卡记录不存在"
),
/**
* manage-模块异常
* 5000+
*/
ACTIVITY_PLAN_MONTH_HAS
(
5000
,
"本月活动计划已上传,请删除后再次上传"
),
/**
/**
* 腾讯云
* 腾讯云
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论