Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
wangxiaolu-link-module-bi
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
sfa
wangxiaolu-link-module-bi
Commits
6973513a
提交
6973513a
authored
12月 10, 2024
作者:
吕本才
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
货需导入
上级
98db7ec1
隐藏空白字符变更
内嵌
并排
正在显示
13 个修改的文件
包含
824 行增加
和
2 行删除
+824
-2
pom.xml
pom.xml
+6
-0
EcGoodsSupplyDemandListener.java
.../link/bi/config/listener/EcGoodsSupplyDemandListener.java
+375
-0
EcGoodsSupplyDemandCoreController.java
...bi/controller/core/EcGoodsSupplyDemandCoreController.java
+40
-0
IEcGoodsSupplyDemandDao.java
.../java/com/link/bi/domain/dao/IEcGoodsSupplyDemandDao.java
+18
-0
EcGoodsSupplyDemandDaoImpl.java
...m/link/bi/domain/dao/impl/EcGoodsSupplyDemandDaoImpl.java
+38
-0
ProductDaoImpl.java
...main/java/com/link/bi/domain/dao/impl/ProductDaoImpl.java
+2
-1
EcGoodsSupplyDemand.java
...n/java/com/link/bi/domain/entity/EcGoodsSupplyDemand.java
+115
-0
EcGoodsSupplyDemandMapper.java
.../com/link/bi/domain/mapper/EcGoodsSupplyDemandMapper.java
+21
-0
IEcGoodsSupplyDemandService.java
...java/com/link/bi/service/IEcGoodsSupplyDemandService.java
+24
-0
IProductService.java
src/main/java/com/link/bi/service/IProductService.java
+3
-0
EcGoodsSupplyDemandServiceImpl.java
.../link/bi/service/impl/EcGoodsSupplyDemandServiceImpl.java
+91
-0
ProductServiceImpl.java
...ain/java/com/link/bi/service/impl/ProductServiceImpl.java
+8
-1
EcGoodsSupplyDemandMapper.xml
src/main/resources/mapper/bi/EcGoodsSupplyDemandMapper.xml
+83
-0
没有找到文件。
pom.xml
浏览文件 @
6973513a
...
...
@@ -91,6 +91,12 @@
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/link/bi/config/listener/EcGoodsSupplyDemandListener.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
config
.
listener
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.NumberUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.read.metadata.holder.ReadRowHolder
;
import
com.alibaba.excel.util.ListUtils
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
com.link.bi.pojo.response.PrdInfoDto
;
import
com.link.bi.service.IEcGoodsSupplyDemandService
;
import
com.sfa.common.core.exception.ServiceException
;
import
com.sfa.common.core.utils.DateUtils
;
import
com.sfa.common.core.utils.StringUtils
;
import
com.sfa.common.core.utils.poi.ExcelUtil
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
java.sql.Date
;
import
java.text.ParseException
;
import
java.time.LocalDate
;
import
java.time.format.DateTimeFormatter
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
// 定义Excel数据处理的监听器
@Data
@Slf4j
public
class
EcGoodsSupplyDemandListener
extends
AnalysisEventListener
<
Map
<
Integer
,
String
>>
{
private
static
final
int
ROW_BATCH_SIZE
=
10
;
private
static
final
int
DEFAULT_INDEX
=
14
;
private
static
int
total
=
0
;
// 存储前五行的数据
private
List
<
String
[]>
titleHeaders
=
new
ArrayList
<>();
// 存储解析后的完整数据
private
List
<
Map
<
Integer
,
String
>>
dataList
=
new
ArrayList
<>(
ROW_BATCH_SIZE
);
// 存储每批次的完整数据
private
List
<
EcGoodsSupplyDemand
>
demandList
=
new
ArrayList
<>(
ROW_BATCH_SIZE
);
// 存储错误记录信息
private
List
<
String
>
errorInfos
=
ListUtils
.
newArrayList
();
private
List
<
String
>
warnInfos
=
ListUtils
.
newArrayList
();
private
IEcGoodsSupplyDemandService
service
;
private
List
<
PrdInfoDto
>
prdInfoDtos
;
private
Integer
year
;
public
EcGoodsSupplyDemandListener
(
IEcGoodsSupplyDemandService
service
,
List
<
PrdInfoDto
>
prdInfoDtos
,
Integer
year
)
{
this
.
service
=
service
;
this
.
year
=
year
;
this
.
prdInfoDtos
=
prdInfoDtos
;
}
/**
* 前4行需要放到表头
*
* @param headMap
* @param context
*/
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
)
{
// 可以在此处验证表头
// if(ObjectUtil.isEmpty(headMap.get(0))){
// throw new ServiceException("第一行表头日期错误");
// }
// 将前五行的数据设置到当前行数据对象中
String
[]
rowData
=
new
String
[
headMap
.
size
()];
for
(
Map
.
Entry
<
Integer
,
String
>
entry
:
headMap
.
entrySet
())
{
rowData
[
entry
.
getKey
()]
=
entry
.
getValue
();
}
titleHeaders
.
add
(
rowData
);
}
/**
* 读取Excel数据时的回调方法
* 每行都会都一次 这里可以处理每行数据,包括使用标题头的数据进行计算
* 例如,您可以在这里根据标题头的数据来计算或修改data对象的属性
*
* @param rowData
* @param context
*/
@Override
public
void
invoke
(
Map
<
Integer
,
String
>
rowData
,
AnalysisContext
context
)
{
// 可以在这里对数据进行一些预处理或验证
ReadRowHolder
readRowHolder
=
context
.
readRowHolder
();
Integer
rowNumber
=
readRowHolder
.
getRowIndex
()
+
1
;
// 校验 商品编码-短码是否有值 --关联查询出系列
String
prdCode
=
rowData
.
get
(
1
);
if
(
ObjectUtil
.
isNotEmpty
(
prdCode
)
&&
!
NumberUtil
.
isNumber
(
prdCode
))
{
errorInfos
.
add
(
"第 "
+
rowNumber
+
"行商品编码格式不正确"
);
return
;
}
// 校验 格式是否是数字
Integer
startYear
=
year
;
if
(
ObjectUtil
.
isEmpty
(
year
))
{
startYear
=
DateUtil
.
thisYear
();
}
// 根据入参计算开始的列??? 根据titleHeaders的年月计算开始保存修改的列
Integer
indexStart_ByTitleHeaders
=
getIndexByTitleHeaders
(
titleHeaders
,
startYear
,
DEFAULT_INDEX
);
Integer
endYear
=
startYear
+
1
;
Integer
indexEnd_ByTitleHeaders
=
getIndexByTitleHeaders
(
titleHeaders
,
endYear
,
indexStart_ByTitleHeaders
);
for
(
int
i
=
indexStart_ByTitleHeaders
;
i
<
indexEnd_ByTitleHeaders
;
i
++)
{
if
(
ObjectUtil
.
isNotEmpty
(
rowData
.
get
(
i
))
&&
!
NumberUtil
.
isNumber
(
rowData
.
get
(
i
)))
{
errorInfos
.
add
(
"第 "
+
rowNumber
+
"行第 "
+
i
+
" 列数据格式不正确"
);
}
}
// 校验渠道列:平台 1 天猫; 2 抖音; 3 拼多多; 4 京东; 5 私域; 6 分销; 7 线下; 8 样品; 9 团购; 10 其他;
// String channel = "1天猫; 2抖音; 3拼多多;4京东;5私域;6分销;7线下;8样品;9团购;10其他;";
// if(ObjectUtil.isNotEmpty(rowData.get(11)) && channel.contains(rowData.get(11))){
// errorInfos.add("第 "+rowNumber + "行第 "+11+" 列数据格式不正确");
// throw new ServiceException("第 "+rowNumber + "行第 "+11+" 列数据格式不正确");
// }
// 将当前行数据添加到列表中
dataList
.
add
(
rowData
);
}
/**
* 解析完成后回调方法
* @param analysisContext
*/
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
analysisContext
)
{
log
.
info
(
"数据解析完成,dataList.size:{}"
,
dataList
.
size
());
if
(
warnInfos
.
size
()>
0
){
log
.
warn
(
"警告记录:{}"
,
JSONUtil
.
toJsonStr
(
warnInfos
));
}
// 存储错误记录
if
(
errorInfos
.
size
()>
0
){
log
.
error
(
"解析错误记录:{}"
,
JSONUtil
.
toJsonStr
(
errorInfos
));
throw
new
ServiceException
(
"解析错误:"
+
JSONUtil
.
toJsonStr
(
errorInfos
));
}
// 分批次入库数据
if
(!
dataList
.
isEmpty
())
{
// 先删除
service
.
deleteByYear
(
year
);
// 批量插入数据
List
<
Map
<
Integer
,
String
>>
convertList
=
new
ArrayList
();
for
(
int
i
=
0
;
i
<
dataList
.
size
();
i
++)
{
convertList
.
add
(
dataList
.
get
(
i
));
if
(
convertList
.
size
()
>=
ROW_BATCH_SIZE
)
{
saveDemandList
(
convertList
);
convertList
.
clear
();
}
}
if
(
convertList
.
size
()
>
0
)
{
saveDemandList
(
convertList
);
convertList
.
clear
();
}
}
}
/**
* 保存数据
* @param dataList
*/
private
void
saveDemandList
(
List
<
Map
<
Integer
,
String
>>
dataList
)
{
// 转换成实体类
List
<
EcGoodsSupplyDemand
>
demandArrayList
=
new
ArrayList
<>();
try
{
demandArrayList
=
convert
(
dataList
,
titleHeaders
);
demandArrayList
.
addAll
(
demandArrayList
);
demandList
.
addAll
(
demandArrayList
);
}
catch
(
ParseException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
throw
new
RuntimeException
(
e
);
}
// service.saveBatch(demandArrayList, demandArrayList.size());
service
.
batchSaveEcGoodsSupplyDemands
(
demandArrayList
);
total
+=
demandArrayList
.
size
();
log
.
info
(
"已处理{}条数据"
,
total
);
}
private
List
<
EcGoodsSupplyDemand
>
convert
(
List
<
Map
<
Integer
,
String
>>
dataList
,
List
<
String
[]>
titleHeaders
)
throws
ParseException
{
List
<
EcGoodsSupplyDemand
>
demands
=
new
ArrayList
<>();
// 转换成实体类
for
(
int
i
=
0
;
i
<
dataList
.
size
();
i
++)
{
Map
<
Integer
,
String
>
rowDataMap
=
dataList
.
get
(
i
);
// 为啥rowDataMap.size() titleHeaders 是270列? 但是242列后面都是空的
// 校验 格式是否是数字
Integer
startYear
=
year
;
if
(
ObjectUtil
.
isEmpty
(
year
))
{
startYear
=
DateUtil
.
thisYear
();
}
// 根据入参计算开始的列??? 根据titleHeaders的年月计算开始保存修改的列
Integer
indexStart_ByTitleHeaders
=
getIndexByTitleHeaders
(
titleHeaders
,
startYear
,
DEFAULT_INDEX
);
Integer
endYear
=
startYear
+
1
;
Integer
indexEnd_ByTitleHeaders
=
getIndexByTitleHeaders
(
titleHeaders
,
endYear
,
indexStart_ByTitleHeaders
);
// 前14列公共使用 从15列开始
for
(
int
j
=
indexStart_ByTitleHeaders
;
j
<
indexEnd_ByTitleHeaders
;
j
++)
{
// 表头是空的,不再取数据了 记录一下日志 不记录到表格了吧
if
(
ObjectUtil
.
isEmpty
(
titleHeaders
.
get
(
0
)[
j
]))
{
log
.
error
(
j
+
"列表头为空,不再导入当前列数据"
);
warnInfos
.
add
(
ExcelUtil
.
convertToExcelColumn
(
j
)
+
"列表头为空"
);
continue
;
}
EcGoodsSupplyDemand
demand
=
new
EcGoodsSupplyDemand
();
Long
value
=
Optional
.
ofNullable
(
rowDataMap
.
get
(
j
))
.
filter
(
ObjectUtil:
:
isNotEmpty
)
.
map
(
str
->
str
.
replace
(
","
,
""
).
replace
(
"("
,
"-"
).
replace
(
")"
,
""
))
.
map
(
Long:
:
parseLong
)
.
orElse
(
null
);
// demand取出integerStringMap的值,设置各个字段的值
demand
.
setSupplyDemandAmount
(
value
);
// 类型 设置 1年 2月 3周 4日
demand
.
setReportDateType
(
getSupplyDemandType
(
titleHeaders
,
j
));
// 周类型的 设置周数
if
(
ObjectUtil
.
isNotEmpty
(
demand
.
getReportDateType
()))
{
if
(
demand
.
getReportDateType
().
equals
(
3L
))
{
DateTimeFormatter
inputFormatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy/M/d"
);
demand
.
setReportDateBegin
(
Date
.
valueOf
(
LocalDate
.
parse
(
titleHeaders
.
get
(
1
)[
j
],
inputFormatter
)));
demand
.
setReportDateEnd
(
Date
.
valueOf
(
LocalDate
.
parse
(
titleHeaders
.
get
(
1
)[
j
],
inputFormatter
)));
demand
.
setWeek
(
DateUtils
.
calculateWeekNumber
(
LocalDate
.
parse
(
titleHeaders
.
get
(
1
)[
j
],
inputFormatter
)));
demand
.
setYear
(
getYearFromHead
(
titleHeaders
,
j
,
demand
.
getReportDateType
()));
demand
.
setMonth
(
getMonthFromHead
(
titleHeaders
,
j
,
demand
.
getReportDateType
()));
}
if
(
demand
.
getReportDateType
().
equals
(
2L
))
{
demand
.
setMonth
(
getMonthFromHead
(
titleHeaders
,
j
,
demand
.
getReportDateType
()));
demand
.
setYear
(
getYearFromHead
(
titleHeaders
,
j
,
demand
.
getReportDateType
()));
}
if
(
demand
.
getReportDateType
().
equals
(
1L
))
{
demand
.
setYear
(
getYearFromHead
(
titleHeaders
,
j
,
demand
.
getReportDateType
()));
}
}
// 关联产品信息表
demand
.
setPlatform
(
rowDataMap
.
get
(
11
));
demand
.
setPlatformId
(
StringUtils
.
getNumberFromStr
(
rowDataMap
.
get
(
11
)));
demand
.
setPrdCode
(
rowDataMap
.
get
(
1
));
demand
.
setPrdName
(
rowDataMap
.
get
(
12
));
// 暂时不存
demand
.
setPrdStatus
(
1L
);
// 同步商品表
demand
.
setSeries
(
getSeriesByPrdCode
(
demand
.
getPrdCode
()));
demand
.
setSeriesId
(
getSeriesIdByPrdCode
(
demand
.
getPrdCode
()));
// 69
demand
.
setPrdBarcode
(
rowDataMap
.
get
(
0
));
demands
.
add
(
demand
);
}
}
return
demands
;
}
/**
* 根据年份获取目标年份的数据下标
* @param titleHeaders
* @param targetYear
* @param startIndex
* @return
*/
private
Integer
getIndexByTitleHeaders
(
List
<
String
[]>
titleHeaders
,
Integer
targetYear
,
Integer
startIndex
)
{
// 根据入参的年份 只考虑当年的数据更新和插入
int
result
=
startIndex
;
for
(
int
j
=
startIndex
;
j
<
titleHeaders
.
get
(
0
).
length
;
j
++)
{
if
(
ObjectUtil
.
isEmpty
(
titleHeaders
.
get
(
0
)[
j
])
||
titleHeaders
.
get
(
0
)[
j
].
contains
(
String
.
valueOf
(
targetYear
)))
{
result
=
j
;
break
;
}
}
return
result
;
}
/**
* 从产品信息中获取大类信息
* @param prdCode
* @return
*/
private
String
getSeriesByPrdCode
(
String
prdCode
)
{
for
(
int
i
=
0
;
i
<
prdInfoDtos
.
size
();
i
++)
{
if
(
prdInfoDtos
.
get
(
i
).
getPrdCode
().
equals
(
prdCode
))
{
return
prdInfoDtos
.
get
(
i
).
getSeries
();
}
}
return
null
;
}
/**
* 从产品信息中获取大类Id信息
* @param prdCode
* @return
*/
private
Integer
getSeriesIdByPrdCode
(
String
prdCode
)
{
for
(
int
i
=
0
;
i
<
prdInfoDtos
.
size
();
i
++)
{
if
(
prdInfoDtos
.
get
(
i
).
getPrdCode
().
equals
(
prdCode
))
{
return
prdInfoDtos
.
get
(
i
).
getSeriesId
();
}
}
return
null
;
}
/**
* 从表头信息中获取月份信息
* @param titleHeaders
* @param j
* @param reportDateType
* @return
*/
private
Long
getMonthFromHead
(
List
<
String
[]>
titleHeaders
,
int
j
,
Long
reportDateType
)
{
// 获取月份 统计日期类型:1年 2月 3周 4日
if
(
reportDateType
.
equals
(
2L
))
{
String
dateStr
=
titleHeaders
.
get
(
1
)[
j
];
return
Long
.
valueOf
(
dateStr
.
replace
(
"月"
,
""
));
}
String
dateStr
=
titleHeaders
.
get
(
0
)[
j
];
if
(
reportDateType
.
equals
(
3L
))
{
return
Long
.
valueOf
(
dateStr
.
substring
(
4
,
6
));
}
return
null
;
}
/**
* 从表头信息中获取年份信息
* @param titleHeaders
* @param j
* @param reportDateType
* @return
*/
private
Long
getYearFromHead
(
List
<
String
[]>
titleHeaders
,
int
j
,
Long
reportDateType
)
{
// 获取年份 统计日期类型:1年 2月 3周 4日
String
dateStr
=
titleHeaders
.
get
(
0
)[
j
];
if
(
reportDateType
.
equals
(
2L
)
||
reportDateType
.
equals
(
1L
))
{
return
Long
.
valueOf
(
dateStr
);
}
if
(
reportDateType
.
equals
(
3L
))
{
return
Long
.
valueOf
(
dateStr
.
substring
(
0
,
4
));
}
return
null
;
}
/**
* 根据表头获取统计日期类型
* 统计日期类型:1年 2月 3周 4日
* @param titleHeaders
* @param j
* @return
*/
private
Long
getSupplyDemandType
(
List
<
String
[]>
titleHeaders
,
int
j
)
{
// 设置当前的类型 周 月类型的数据暂时不用
String
s1
=
titleHeaders
.
get
(
0
)[
j
];
String
startStr
=
titleHeaders
.
get
(
1
)[
j
];
if
(
ObjectUtil
.
isNotEmpty
(
s1
))
{
if
(
s1
.
length
()
==
4
)
{
if
(
ObjectUtil
.
isNotEmpty
(
startStr
)
&&
startStr
.
contains
(
"月"
))
{
// 如果是月份
return
2L
;
}
else
{
// 如果是年份
return
1L
;
}
}
else
if
(
s1
.
length
()
==
6
&&
ObjectUtil
.
isNotEmpty
(
startStr
))
{
return
3L
;
}
}
log
.
error
(
"当前titleHeaders列:{},没有匹配的类型"
,
j
);
return
null
;
}
}
src/main/java/com/link/bi/controller/core/EcGoodsSupplyDemandCoreController.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
controller
.
core
;
import
com.link.bi.service.IEcGoodsSupplyDemandService
;
import
com.sfa.common.core.web.controller.BaseController
;
import
com.sfa.common.log.annotation.Log
;
import
com.sfa.common.log.enums.BusinessType
;
import
com.sfa.common.security.annotation.RequiresPermissions
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
/**
* 电商-货物供需Controller
*
* @author admin
* @date 2024-12-05
*/
@RestController
@RequestMapping
(
"/demand/core"
)
public
class
EcGoodsSupplyDemandCoreController
extends
BaseController
{
@Autowired
private
IEcGoodsSupplyDemandService
ecGoodsSupplyDemandService
;
/**
* 导出电商-货物供需列表
*/
@RequiresPermissions
(
"bi:demand:import"
)
@Log
(
title
=
"电商-货物供需"
,
businessType
=
BusinessType
.
IMPORT
)
@PostMapping
(
"/import"
)
public
String
importData
(
HttpServletResponse
response
,
MultipartFile
file
,
Integer
year
)
{
ecGoodsSupplyDemandService
.
importData
(
file
,
year
);
return
"导入货需数据完成"
;
}
}
src/main/java/com/link/bi/domain/dao/IEcGoodsSupplyDemandDao.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
domain
.
dao
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
java.util.List
;
/**
* @author : liqiulin
* @date : 2024-11-21 16
* @describe :
*/
public
interface
IEcGoodsSupplyDemandDao
{
void
batchSaveEcGoodsSupplyDemands
(
List
<
EcGoodsSupplyDemand
>
demandList
);
Integer
deleteByYear
(
Integer
year
);
}
src/main/java/com/link/bi/domain/dao/impl/EcGoodsSupplyDemandDaoImpl.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
domain
.
dao
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.link.bi.domain.dao.IEcGoodsSupplyDemandDao
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
com.link.bi.domain.mapper.EcGoodsSupplyDemandMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* @author : liqiulin
* @date : 2024-11-21 16
* @describe :
*/
@Service
public
class
EcGoodsSupplyDemandDaoImpl
implements
IEcGoodsSupplyDemandDao
{
@Autowired
EcGoodsSupplyDemandMapper
mapper
;
@Override
public
void
batchSaveEcGoodsSupplyDemands
(
List
<
EcGoodsSupplyDemand
>
demandList
)
{
mapper
.
batchSaveEcGoodsSupplyDemands
(
demandList
);
}
@Override
public
Integer
deleteByYear
(
Integer
year
)
{
Integer
delete
=
mapper
.
delete
(
new
LambdaQueryWrapper
<
EcGoodsSupplyDemand
>()
.
eq
(
EcGoodsSupplyDemand:
:
getYear
,
year
));
System
.
out
.
println
(
"删除"
+
delete
+
"条数据"
);
return
delete
;
}
}
src/main/java/com/link/bi/domain/dao/impl/ProductDaoImpl.java
浏览文件 @
6973513a
package
com
.
link
.
bi
.
domain
.
dao
.
impl
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.link.bi.domain.dao.IProductDao
;
...
...
@@ -63,7 +64,7 @@ public class ProductDaoImpl implements IProductDao {
@Override
public
List
<
PrdInfoDto
>
selectListByCodes
(
List
<
String
>
prdCodes
)
{
List
<
PrdInfo
>
prdInfos
=
prdInfoMapper
.
selectList
(
new
LambdaQueryWrapper
<
PrdInfo
>().
in
(
PrdInfo:
:
getPrdCode
,
prdCodes
));
List
<
PrdInfo
>
prdInfos
=
prdInfoMapper
.
selectList
(
new
LambdaQueryWrapper
<
PrdInfo
>().
in
(
ObjectUtil
.
isNotEmpty
(
prdCodes
),
PrdInfo:
:
getPrdCode
,
prdCodes
));
return
BeanUtils
.
transitionDtos
(
prdInfos
,
PrdInfoDto
.
class
);
}
}
src/main/java/com/link/bi/domain/entity/EcGoodsSupplyDemand.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
domain
.
entity
;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableField
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
com.sfa.common.core.annotation.Excel
;
import
lombok.Data
;
import
java.util.Date
;
/**
* 电商-货物供需对象 ec_goods_supply_demand
*
* @author admin
* @date 2024-12-05
*/
@TableName
(
value
=
"ec_goods_supply_demand"
)
@Data
public
class
EcGoodsSupplyDemand
{
@TableField
(
exist
=
false
)
private
static
final
long
serialVersionUID
=
1L
;
/** 主键id */
@TableId
(
type
=
IdType
.
AUTO
)
private
Long
supplyDemandId
;
/** 年 */
@Excel
(
name
=
"年"
)
private
Long
year
;
/** 月 */
@Excel
(
name
=
"月"
)
private
Long
month
;
/** 周 */
@Excel
(
name
=
"周"
)
private
Integer
week
;
/** 统计日期类型:1年 2月 3周 4日 */
@Excel
(
name
=
"统计日期类型:1年 2月 3周 4日"
)
private
Long
reportDateType
;
/** 统计日期开始时间 */
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@Excel
(
name
=
"统计日期开始时间"
,
width
=
30
,
dateFormat
=
"yyyy-MM-dd"
)
private
Date
reportDateBegin
;
/** 统计日期结束时间 */
@JsonFormat
(
pattern
=
"yyyy-MM-dd"
)
@Excel
(
name
=
"统计日期结束时间"
,
width
=
30
,
dateFormat
=
"yyyy-MM-dd"
)
private
Date
reportDateEnd
;
/** 商品/货品编码 */
@Excel
(
name
=
"商品/货品编码"
)
private
String
prdCode
;
/** 商品/货品名称 */
@Excel
(
name
=
"商品/货品名称"
)
private
String
prdName
;
/** 商品条码,69码 */
@Excel
(
name
=
"商品条码,69码"
)
private
String
prdBarcode
;
/** 商品/货品状态 */
@Excel
(
name
=
"商品/货品状态"
)
private
Long
prdStatus
;
/** 商品系列id */
@Excel
(
name
=
"商品系列id"
)
private
Integer
seriesId
;
/** 商品系列 */
@Excel
(
name
=
"商品系列"
)
private
String
series
;
/** 平台id */
@Excel
(
name
=
"平台id"
)
private
Long
platformId
;
/** platform平台:1 天猫; 2 抖音; 3 拼多多; 4 京东; 5 私域; 6 分销; 7 线下; 8 样品; 9 团购; 10 其他; */
@Excel
(
name
=
"platform平台:1 天猫; 2 抖音; 3 拼多多; 4 京东; 5 私域; 6 分销; 7 线下; 8 样品; 9 团购; 10 其他;"
)
private
String
platform
;
/** 货需数量 */
@Excel
(
name
=
"货需数量"
)
// 做校验下 是否为正整数
private
Long
supplyDemandAmount
;
@Excel
(
name
=
"创建时间"
)
private
Date
createTime
;
/** 创建人id */
@Excel
(
name
=
"创建人id"
)
private
Long
createUserId
;
/** 创建人 */
@Excel
(
name
=
"创建人"
)
private
String
createBy
;
/** 修改人id */
@Excel
(
name
=
"修改人id"
)
private
Long
updateUserId
;
/** 修改人 */
@Excel
(
name
=
"修改人"
)
private
Long
updateBy
;
@Excel
(
name
=
"修改时间"
)
private
Date
updateTime
;
}
src/main/java/com/link/bi/domain/mapper/EcGoodsSupplyDemandMapper.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
domain
.
mapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.springframework.stereotype.Repository
;
import
java.util.List
;
/**
* 电商-货物供需Mapper接口
*
* @author admin
* @date 2024-12-05
*/
@Repository
@Mapper
public
interface
EcGoodsSupplyDemandMapper
extends
BaseMapper
<
EcGoodsSupplyDemand
>
{
void
batchSaveEcGoodsSupplyDemands
(
List
<
EcGoodsSupplyDemand
>
demandList
);
}
src/main/java/com/link/bi/service/IEcGoodsSupplyDemandService.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
service
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
/**
* 电商-货物供需Service接口
*
* @author admin
* @date 2024-12-05
*/
public
interface
IEcGoodsSupplyDemandService
extends
IService
<
EcGoodsSupplyDemand
>
{
List
<
EcGoodsSupplyDemand
>
importData
(
MultipartFile
ecGoodsSupplyDemand
,
Integer
year
);
// 批量保存
void
batchSaveEcGoodsSupplyDemands
(
List
<
EcGoodsSupplyDemand
>
demandList
);
void
deleteByYear
(
Integer
year
);
}
src/main/java/com/link/bi/service/IProductService.java
浏览文件 @
6973513a
package
com
.
link
.
bi
.
service
;
import
com.link.bi.pojo.request.ProductVo
;
import
com.link.bi.pojo.response.PrdInfoDto
;
import
com.sfa.common.core.web.domain.PageInfo
;
import
java.util.List
;
...
...
@@ -15,4 +16,6 @@ public interface IProductService {
PageInfo
productPage
(
ProductVo
productVo
);
List
<
PrdInfoDto
>
selectListByCodes
(
List
<
String
>
codeLists
);
}
src/main/java/com/link/bi/service/impl/EcGoodsSupplyDemandServiceImpl.java
0 → 100644
浏览文件 @
6973513a
package
com
.
link
.
bi
.
service
.
impl
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.link.bi.config.listener.EcGoodsSupplyDemandListener
;
import
com.link.bi.domain.dao.IEcGoodsSupplyDemandDao
;
import
com.link.bi.domain.entity.EcGoodsSupplyDemand
;
import
com.link.bi.domain.mapper.EcGoodsSupplyDemandMapper
;
import
com.link.bi.pojo.response.PrdInfoDto
;
import
com.link.bi.service.IEcGoodsSupplyDemandService
;
import
com.link.bi.service.IProductService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 电商-货物供需Service业务层处理
*
* @author admin
* @date 2024-12-05
*/
@Service
@Slf4j
public
class
EcGoodsSupplyDemandServiceImpl
extends
ServiceImpl
<
EcGoodsSupplyDemandMapper
,
EcGoodsSupplyDemand
>
implements
IEcGoodsSupplyDemandService
{
@Autowired
IEcGoodsSupplyDemandDao
demandDao
;
@Autowired
IProductService
productService
;
@Override
public
List
<
EcGoodsSupplyDemand
>
importData
(
MultipartFile
multipartFile
,
Integer
year
)
{
// 上传并解析excel
File
file
=
transferToFile
(
multipartFile
);
List
<
String
>
codeLists
=
new
ArrayList
<>();
List
<
PrdInfoDto
>
prdInfoDtos
=
productService
.
selectListByCodes
(
codeLists
);
// 创建EcGoodsSupplyDemandListener实例
EcGoodsSupplyDemandListener
listener
=
new
EcGoodsSupplyDemandListener
(
this
,
prdInfoDtos
,
year
);
// 读取文件内容
EasyExcel
.
read
(
file
,
listener
).
ignoreEmptyRow
(
true
)
.
headRowNumber
(
4
).
sheet
(
"电商-需求"
).
doRead
();
// 获取读取到的数据
List
<
EcGoodsSupplyDemand
>
data
=
listener
.
getDemandList
();
return
data
;
}
public
File
transferToFile
(
MultipartFile
multipartFile
)
{
// 选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。
File
file
=
null
;
try
{
String
originalFilename
=
multipartFile
.
getOriginalFilename
();
String
[]
filename
=
originalFilename
.
split
(
"\\."
);
file
=
File
.
createTempFile
(
filename
[
0
],
filename
[
1
]
+
"."
);
multipartFile
.
transferTo
(
file
);
file
.
deleteOnExit
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
log
.
error
(
e
.
getMessage
(),
e
);
}
return
file
;
//————————————————
//
// 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
//
// 原文链接:https://blog.csdn.net/qq_42383970/article/details/120201524
}
// 批量保存
@Override
public
void
batchSaveEcGoodsSupplyDemands
(
List
<
EcGoodsSupplyDemand
>
demandList
)
{
demandDao
.
batchSaveEcGoodsSupplyDemands
(
demandList
);
}
@Override
public
void
deleteByYear
(
Integer
year
)
{
if
(
ObjectUtil
.
isEmpty
(
year
))
{
year
=
DateUtil
.
thisYear
();
}
demandDao
.
deleteByYear
(
year
);
}
}
src/main/java/com/link/bi/service/impl/ProductServiceImpl.java
浏览文件 @
6973513a
...
...
@@ -3,6 +3,7 @@ package com.link.bi.service.impl;
import
com.link.bi.domain.dao.IProductDao
;
import
com.link.bi.domain.wq.ProductWq
;
import
com.link.bi.pojo.request.ProductVo
;
import
com.link.bi.pojo.response.PrdInfoDto
;
import
com.link.bi.service.IProductService
;
import
com.sfa.common.core.web.domain.PageInfo
;
import
org.springframework.beans.BeanUtils
;
...
...
@@ -30,8 +31,14 @@ public class ProductServiceImpl implements IProductService {
@Override
public
PageInfo
productPage
(
ProductVo
productVo
)
{
ProductWq
qw
=
new
ProductWq
();
BeanUtils
.
copyProperties
(
productVo
,
qw
);
BeanUtils
.
copyProperties
(
productVo
,
qw
);
qw
.
setPrdNameLike
(
productVo
.
getPrdName
());
return
productDao
.
productPage
(
qw
);
}
@Override
public
List
<
PrdInfoDto
>
selectListByCodes
(
List
<
String
>
prdCodes
)
{
List
<
PrdInfoDto
>
prdInfos
=
productDao
.
selectListByCodes
(
prdCodes
);
return
prdInfos
;
}
}
src/main/resources/mapper/bi/EcGoodsSupplyDemandMapper.xml
0 → 100644
浏览文件 @
6973513a
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.link.bi.domain.mapper.EcGoodsSupplyDemandMapper"
>
<resultMap
type=
"com.link.bi.domain.entity.EcGoodsSupplyDemand"
id=
"EcGoodsSupplyDemandResult"
>
<result
property=
"supplyDemandId"
column=
"supply_demand_id"
/>
<result
property=
"year"
column=
"year"
/>
<result
property=
"month"
column=
"month"
/>
<result
property=
"week"
column=
"week"
/>
<result
property=
"reportDateType"
column=
"report_date_type"
/>
<result
property=
"reportDateBegin"
column=
"report_date_begin"
/>
<result
property=
"reportDateEnd"
column=
"report_date_end"
/>
<result
property=
"prdCode"
column=
"prd_code"
/>
<result
property=
"prdName"
column=
"prd_name"
/>
<result
property=
"prdBarcode"
column=
"prd_barcode"
/>
<result
property=
"prdStatus"
column=
"prd_status"
/>
<result
property=
"seriesId"
column=
"series_id"
/>
<result
property=
"series"
column=
"series"
/>
<result
property=
"platformId"
column=
"platform_id"
/>
<result
property=
"platform"
column=
"platform"
/>
<result
property=
"supplyDemandAmount"
column=
"supply_demand_amount"
/>
<result
property=
"createBy"
column=
"create_by"
/>
<result
property=
"createUserId"
column=
"create_user_id"
/>
<result
property=
"createTime"
column=
"create_time"
/>
<result
property=
"updateBy"
column=
"update_by"
/>
<result
property=
"updateUserId"
column=
"update_user_id"
/>
<result
property=
"updateTime"
column=
"update_time"
/>
</resultMap>
<sql
id=
"selectEcGoodsSupplyDemandVo"
>
select supply_demand_id, year, month, week, report_date_type, report_date_begin, report_date_end, prd_code, prd_name, prd_barcode, prd_status, series_id, series, platform_id, platform, supply_demand_amount, create_by, create_user_id, create_time, update_by, update_user_id, update_time
from ec_goods_supply_demand
</sql>
<select
id=
"selectEcGoodsSupplyDemandList"
parameterType=
"com.link.bi.domain.entity.EcGoodsSupplyDemand"
resultMap=
"EcGoodsSupplyDemandResult"
>
<include
refid=
"selectEcGoodsSupplyDemandVo"
/>
<where>
<if
test=
"year != null "
>
and year = #{year}
</if>
<if
test=
"month != null "
>
and month = #{month}
</if>
<if
test=
"week != null "
>
and week = #{week}
</if>
<if
test=
"reportDateType != null "
>
and report_date_type = #{reportDateType}
</if>
<if
test=
"reportDateBegin != null "
>
and report_date_begin = #{reportDateBegin}
</if>
<if
test=
"reportDateEnd != null "
>
and report_date_end = #{reportDateEnd}
</if>
<if
test=
"prdCode != null and prdCode != ''"
>
and prd_code = #{prdCode}
</if>
<if
test=
"prdName != null and prdName != ''"
>
and prd_name like concat('%', #{prdName}, '%')
</if>
<if
test=
"prdBarcode != null and prdBarcode != ''"
>
and prd_barcode = #{prdBarcode}
</if>
<if
test=
"prdStatus != null "
>
and prd_status = #{prdStatus}
</if>
<if
test=
"seriesId != null "
>
and series_id = #{seriesId}
</if>
<if
test=
"series != null and series != ''"
>
and series = #{series}
</if>
<if
test=
"platformId != null "
>
and platform_id = #{platformId}
</if>
<if
test=
"platform != null and platform != ''"
>
and platform = #{platform}
</if>
<if
test=
"supplyDemandAmount != null "
>
and supply_demand_amount = #{supplyDemandAmount}
</if>
<if
test=
"createUserId != null "
>
and create_user_id = #{createUserId}
</if>
<if
test=
"updateUserId != null "
>
and update_user_id = #{updateUserId}
</if>
</where>
</select>
<select
id=
"selectEcGoodsSupplyDemandById"
parameterType=
"Long"
resultMap=
"EcGoodsSupplyDemandResult"
>
<include
refid=
"selectEcGoodsSupplyDemandVo"
/>
where supply_demand_id = #{supplyDemandId}
</select>
<insert
id=
"batchSaveEcGoodsSupplyDemands"
parameterType=
"java.util.List"
>
insert into ec_goods_supply_demand
(year, month, week, report_date_type, report_date_begin, report_date_end, prd_code,
prd_name, prd_barcode, prd_status, series_id, series, platform_id, platform,
supply_demand_amount, create_user_id, update_user_id)
values
<foreach
collection=
"list"
item=
"item"
index=
"index"
separator=
","
>
( #{item.year}, #{item.month}, #{item.week}, #{item.reportDateType}, #{item.reportDateBegin},
#{item.reportDateEnd}, #{item.prdCode}, #{item.prdName}, #{item.prdBarcode}, #{item.prdStatus},
#{item.seriesId},
#{item.series}, #{item.platformId}, #{item.platform}, #{item.supplyDemandAmount}, #{item.createUserId},
#{item.updateUserId})
</foreach>
</insert>
</mapper>
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论