Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
rpc-dj-pe-analysis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dd3fb8ec
authored
Dec 11, 2025
by
蔡茜
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
查询总产值
1 parent
46f2182b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
9 deletions
rpc-dj-pe-analysis/src/main/java/cn/com/glsx/dj/peanalysis/service/BusinessAnalysisService.java
rpc-dj-pe-analysis/src/main/java/cn/com/glsx/dj/peanalysis/utils/DateUtils.java
rpc-dj-pe-analysis/src/main/java/cn/com/glsx/dj/peanalysis/service/BusinessAnalysisService.java
View file @
dd3fb8e
...
@@ -5,9 +5,11 @@ import cn.com.glsx.dj.peanalysis.dto.DataBusinessDTO;
...
@@ -5,9 +5,11 @@ import cn.com.glsx.dj.peanalysis.dto.DataBusinessDTO;
import
cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq
;
import
cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq
;
import
cn.com.glsx.dj.peanalysis.dto.res.output.TotalOutputResponse
;
import
cn.com.glsx.dj.peanalysis.dto.res.output.TotalOutputResponse
;
import
cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper
;
import
cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper
;
import
cn.com.glsx.dj.peanalysis.utils.DateUtils
;
import
cn.com.glsx.dj.peanalysis.utils.response.DataResp
;
import
cn.com.glsx.dj.peanalysis.utils.response.DataResp
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
cn.com.glsx.framework.core.exception.RpcServiceException
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.lang.Pair
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -17,10 +19,9 @@ import org.springframework.transaction.annotation.Propagation;
...
@@ -17,10 +19,9 @@ import org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.math.BigDecimal
;
import
java.util.Arrays
;
import
java.math.RoundingMode
;
import
java.util.Collections
;
import
java.util.*
;
import
java.util.List
;
/**
/**
* bi
* bi
...
@@ -47,23 +48,66 @@ public class BusinessAnalysisService {
...
@@ -47,23 +48,66 @@ public class BusinessAnalysisService {
if
(!
StringUtils
.
isEmpty
(
request
.
getRegionId
()))
{
if
(!
StringUtils
.
isEmpty
(
request
.
getRegionId
()))
{
merchantIds
=
getMerchantIds
(
request
.
getRegionId
());
merchantIds
=
getMerchantIds
(
request
.
getRegionId
());
}
}
TotalOutputResponse
result
=
new
TotalOutputResponse
();
DataBizQueryParamsDTO
queryDataBiz
=
new
DataBizQueryParamsDTO
();
DataBizQueryParamsDTO
queryDataBiz
=
new
DataBizQueryParamsDTO
();
queryDataBiz
.
setBrandIds
(
"-1,-3"
);
queryDataBiz
.
setBrandIds
(
"-1,-3"
);
queryDataBiz
.
setDateType
(
4
);
queryDataBiz
.
setDateType
(
4
);
queryDataBiz
.
setExts
(
null
);
queryDataBiz
.
setExts
(
"merchantId"
);
queryDataBiz
.
setMerchantIds
(
StrUtil
.
join
(
","
,
merchantIds
));
queryDataBiz
.
setMerchantIds
(
StrUtil
.
join
(
","
,
merchantIds
));
queryDataBiz
.
setStartDate
(
request
.
getStartTime
());
queryDataBiz
.
setStartDate
(
request
.
getStartTime
());
queryDataBiz
.
setEndDate
(
request
.
getEndTime
());
queryDataBiz
.
setEndDate
(
request
.
getEndTime
());
queryDataBiz
.
setItemCodes
(
"A0018"
);
TotalOutputResponse
currentOutput
=
getTotalOutput
(
queryDataBiz
);
//计算环比
Pair
<
String
,
String
>
lastPeriodDates
=
DateUtils
.
getLastPeriodDates
(
request
.
getStartTime
(),
request
.
getEndTime
(),
request
.
getCycleType
());
queryDataBiz
.
setStartDate
(
lastPeriodDates
.
getKey
());
queryDataBiz
.
setEndDate
(
lastPeriodDates
.
getValue
());
TotalOutputResponse
lastOutput
=
getTotalOutput
(
queryDataBiz
);
TotalOutputResponse
result
=
new
TotalOutputResponse
();
result
.
setTotalOutput
(
currentOutput
.
getTotalOutput
());
result
.
setStoreCount
(
currentOutput
.
getStoreCount
());
if
(
lastOutput
.
getTotalOutput
().
compareTo
(
BigDecimal
.
ZERO
)
!=
0
)
{
// 环比 = (本期值 - 上期值) / 上期值 × 100%
BigDecimal
chainRatio
=
currentOutput
.
getTotalOutput
()
.
subtract
(
lastOutput
.
getTotalOutput
())
.
divide
(
lastOutput
.
getTotalOutput
(),
4
,
RoundingMode
.
HALF_UP
)
.
multiply
(
new
BigDecimal
(
"100"
));
result
.
setTotalOutputMom
(
chainRatio
.
setScale
(
2
,
RoundingMode
.
HALF_UP
));
}
// 门店数量环比计算(int类型)
if
(
lastOutput
.
getStoreCount
()
!=
0
)
{
// 先将int转换为BigDecimal,再计算
BigDecimal
currentCount
=
new
BigDecimal
(
currentOutput
.
getStoreCount
());
BigDecimal
lastCount
=
new
BigDecimal
(
lastOutput
.
getStoreCount
());
// 环比 = (本期门店数 - 上期门店数) / 上期门店数 × 100%
BigDecimal
chainRatio
=
currentCount
.
subtract
(
lastCount
)
.
divide
(
lastCount
,
4
,
RoundingMode
.
HALF_UP
)
.
multiply
(
new
BigDecimal
(
"100"
));
result
.
setStoreCountMom
(
chainRatio
.
setScale
(
2
,
RoundingMode
.
HALF_UP
));
}
return
result
;
}
queryDataBiz
.
setItemCodes
(
"总产值"
);
public
TotalOutputResponse
getTotalOutput
(
DataBizQueryParamsDTO
queryDataBiz
)
{
TotalOutputResponse
result
=
new
TotalOutputResponse
();
result
.
setTotalOutput
(
BigDecimal
.
ZERO
);
String
jsonBody
=
JSONUtil
.
toJsonStr
(
queryDataBiz
);
String
jsonBody
=
JSONUtil
.
toJsonStr
(
queryDataBiz
);
DataResp
<
List
<
DataBusinessDTO
>>
dataResp
=
getDataStatsService
.
getListDataResp
(
jsonBody
);
DataResp
<
List
<
DataBusinessDTO
>>
dataResp
=
getDataStatsService
.
getListDataResp
(
jsonBody
);
List
<
DataBusinessDTO
>
content
=
dataResp
.
getContent
();
List
<
DataBusinessDTO
>
content
=
dataResp
.
getContent
();
int
i
=
0
;
if
(
CollUtil
.
isNotEmpty
(
content
))
{
if
(
CollUtil
.
isNotEmpty
(
content
))
{
DataBusinessDTO
dataBusinessDTO
=
CollUtil
.
getFirst
(
content
);
for
(
DataBusinessDTO
dataBusinessDTO
:
content
)
{
result
.
setTotalOutput
(
dataBusinessDTO
.
getItemValue
());
if
(
Objects
.
nonNull
(
dataBusinessDTO
.
getItemValue
()))
{
result
.
setTotalOutput
(
result
.
getTotalOutput
().
add
(
dataBusinessDTO
.
getItemValue
()));
i
++;
}
}
}
}
result
.
setStoreCount
(
i
);
return
result
;
return
result
;
}
}
}
}
rpc-dj-pe-analysis/src/main/java/cn/com/glsx/dj/peanalysis/utils/DateUtils.java
0 → 100644
View file @
dd3fb8e
package
cn
.
com
.
glsx
.
dj
.
peanalysis
.
utils
;
import
cn.hutool.core.lang.Pair
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.temporal.ChronoUnit
;
@Slf4j
public
class
DateUtils
{
/**
* 获取上一周期的时间范围(字符串格式)
*
* @param startTime 本期开始时间(字符串)
* @param endTime 本期结束时间(字符串)
* @param dateType 日期类型:1=日, 2=周, 3=月, 0=自定义
* @return Pair<上期开始时间, 上期结束时间>
*/
public
static
Pair
<
String
,
String
>
getLastPeriodDates
(
String
startTime
,
String
endTime
,
Integer
dateType
)
{
if
(
StringUtils
.
isEmpty
(
startTime
)
||
StringUtils
.
isEmpty
(
endTime
))
{
// 返回空值或默认值
return
Pair
.
of
(
""
,
""
);
}
try
{
// 解析字符串为LocalDateTime(根据实际格式调整)
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd"
);
LocalDateTime
start
=
LocalDateTime
.
parse
(
startTime
,
formatter
);
LocalDateTime
end
=
LocalDateTime
.
parse
(
endTime
,
formatter
);
LocalDateTime
lastStart
=
null
;
LocalDateTime
lastEnd
=
null
;
// 根据日期类型计算上一周期
if
(
dateType
==
null
)
{
dateType
=
0
;
// 默认自定义
}
switch
(
dateType
)
{
case
1
:
// 日
lastStart
=
start
.
minusDays
(
1
);
lastEnd
=
end
.
minusDays
(
1
);
break
;
case
2
:
// 周
lastStart
=
start
.
minusWeeks
(
1
);
lastEnd
=
end
.
minusWeeks
(
1
);
break
;
case
3
:
// 月
lastStart
=
start
.
minusMonths
(
1
);
lastEnd
=
end
.
minusMonths
(
1
);
break
;
case
4
:
// 自定义(按天数间隔计算)
long
daysBetween
=
ChronoUnit
.
DAYS
.
between
(
start
,
end
);
lastStart
=
start
.
minusDays
(
daysBetween
+
1
);
lastEnd
=
end
.
minusDays
(
daysBetween
+
1
);
break
;
}
// 格式化为字符串返回
return
Pair
.
of
(
lastStart
.
format
(
formatter
),
lastEnd
.
format
(
formatter
)
);
}
catch
(
Exception
e
)
{
log
.
error
(
"计算上一周期时间失败,startTime: {}, endTime: {}, dateType: {}"
,
startTime
,
endTime
,
dateType
,
e
);
// 返回空值或使用其他默认逻辑
return
Pair
.
of
(
""
,
""
);
}
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment