Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
c1b76766
提交
c1b76766
authored
12月 12, 2020
作者:
吴德鹏
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update activity
上级
7f1bb22f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
119 行增加
和
12 行删除
+119
-12
ActivityController.java
...m/example/afrishop_v3/controllers/ActivityController.java
+115
-9
OrderController.java
.../com/example/afrishop_v3/controllers/OrderController.java
+4
-3
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/ActivityController.java
浏览文件 @
c1b76766
package
com
.
example
.
afrishop_v3
.
controllers
;
import
com.alibaba.fastjson.JSONObject
;
import
com.example.afrishop_v3.base.Result
;
import
com.example.afrishop_v3.enums.ResultCodeEnum
;
import
com.example.afrishop_v3.models.Activity
;
import
com.example.afrishop_v3.models.TbCfCartRecordR
;
import
com.example.afrishop_v3.models.TbCfStationItem
;
import
com.example.afrishop_v3.repository.ActivityRepository
;
import
com.example.afrishop_v3.repository.TbCfCartRecordRRepository
;
import
com.example.afrishop_v3.repository.TbCfStationItemRepository
;
import
org.checkerframework.checker.units.qual.A
;
import
org.springframework.data.domain.Example
;
import
org.springframework.data.domain.ExampleMatcher
;
import
com.example.afrishop_v3.vo.Condition
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.web.bind.annotation.*
;
import
java.math.BigDecimal
;
import
java.text.DateFormat
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.Future
;
/**
* @Auther: wudepeng
...
...
@@ -32,10 +30,12 @@ public class ActivityController {
private
final
ActivityRepository
activityRepository
;
private
final
TbCfStationItemRepository
itemRepository
;
private
final
TbCfCartRecordRRepository
cartRecordRRepository
;
public
ActivityController
(
ActivityRepository
activityRepository
,
TbCfStationItemRepository
itemRepository
)
{
public
ActivityController
(
ActivityRepository
activityRepository
,
TbCfStationItemRepository
itemRepository
,
TbCfCartRecordRRepository
cartRecordRRepository
)
{
this
.
activityRepository
=
activityRepository
;
this
.
itemRepository
=
itemRepository
;
this
.
cartRecordRRepository
=
cartRecordRRepository
;
}
@GetMapping
(
"/getAllActivity"
)
...
...
@@ -60,7 +60,8 @@ public class ActivityController {
//全场活动
if
(
activityRepository
.
existsByUseType
(
1
))
{
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
activity
=
fullList
.
get
(
0
);
if
(
fullList
!=
null
&&
fullList
.
size
()
>
0
)
activity
=
fullList
.
get
(
0
);
}
//商品分类活动
...
...
@@ -135,5 +136,110 @@ public class ActivityController {
return
t
;
}
@GetMapping
(
"/caculateCartDiscount"
)
public
Result
caculateCartDiscount
(
@RequestBody
String
[]
cartIds
)
{
// Activity activity = null;
// List<Activity> activityList = new ArrayList<>();
BigDecimal
itemPrice
=
BigDecimal
.
ZERO
;
BigDecimal
lessAmount
=
BigDecimal
.
ZERO
;
String
discount
=
null
;
int
itemCount
=
0
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
for
(
String
cartId
:
cartIds
)
{
Optional
<
TbCfCartRecordR
>
byId
=
cartRecordRRepository
.
findById
(
cartId
);
if
(
byId
.
isPresent
())
{
TbCfCartRecordR
cart
=
byId
.
get
();
itemPrice
=
itemPrice
.
add
(
cart
.
getItemPrice
());
itemCount
+=
cart
.
getItemNum
();
// String itemId = cart.getItemId();
// activity = checkActivity(itemId);
// activityList.add(activity);
}
}
if
(
activityRepository
.
existsByUseType
(
1
))
{
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
Activity
activity
=
fullList
.
get
(
0
);
String
type
=
activity
.
getType
().
toString
();
List
<
Condition
>
conList
=
JSONObject
.
parseArray
(
activity
.
getCondition
(),
Condition
.
class
);
Collections
.
sort
(
conList
,
Comparator
.
comparing
(
Condition:
:
getKey
));
// BigDecimal finalItemPrice = itemPrice;
if
(
"1"
.
equals
(
type
)
||
"2"
.
equals
(
type
))
{
for
(
Condition
con
:
conList
)
{
double
key
=
con
.
getKey
();
BigDecimal
threshold
=
new
BigDecimal
(
key
);
double
value
=
con
.
getValue
();
discount
=
String
.
valueOf
(
value
);
if
(
itemPrice
.
compareTo
(
threshold
)
<
0
)
{
lessAmount
=
threshold
.
subtract
(
itemPrice
);
map
.
put
(
"discount"
,
discount
);
map
.
put
(
"lessAmount"
,
lessAmount
);
}
break
;
}
}
else
if
(
"3"
.
equals
(
type
))
{
for
(
Condition
con
:
conList
)
{
int
key
=
(
int
)
con
.
getKey
();
double
value
=
con
.
getValue
();
discount
=
String
.
valueOf
(
value
);
if
(
itemCount
<
key
)
{
map
.
put
(
"discount"
,
discount
);
map
.
put
(
"lessAmount"
,
key
-
itemCount
);
}
break
;
}
}
}
return
new
Result
(
map
);
}
public
Activity
checkActivity
(
String
itemId
)
{
Result
result
=
new
Result
();
Activity
activity
=
null
;
DateFormat
df
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
//全场活动
if
(
activityRepository
.
existsByUseType
(
1
))
{
List
<
Activity
>
fullList
=
activityRepository
.
findAllByUseType
(
1
);
activity
=
fullList
.
get
(
0
);
}
//商品分类活动
if
(
activityRepository
.
existsByUseType
(
2
))
{
Optional
<
TbCfStationItem
>
byId
=
itemRepository
.
findById
(
itemId
);
if
(
byId
.
isPresent
())
{
TbCfStationItem
item
=
byId
.
get
();
String
category1
=
item
.
getItemCategory
();
String
category2
=
item
.
getItemCategorytwo
();
String
category3
=
item
.
getItemDescritionId
();
String
con2
=
category1
+
","
+
category2
;
String
con3
=
category1
+
","
+
category2
+
","
+
category3
;
List
<
Activity
>
activityList
=
activityRepository
.
findAllByUseType
(
2
);
List
<
Activity
>
actList
=
new
ArrayList
<>();
for
(
Activity
act2
:
activityList
)
{
if
(
category1
.
equals
(
act2
.
getCategoryId
()))
{
act2
.
setOrder
(
3
);
actList
.
add
(
act2
);
}
if
(
con2
.
equals
(
act2
.
getCategoryId
()))
{
act2
.
setOrder
(
2
);
actList
.
add
(
act2
);
}
if
(
con3
.
equals
(
act2
.
getCategoryId
()))
{
act2
.
setOrder
(
1
);
actList
.
add
(
act2
);
}
}
Collections
.
sort
(
actList
,
Comparator
.
comparing
(
Activity:
:
getOrder
));
if
(
actList
.
size
()
>
0
&&
actList
!=
null
)
activity
=
actList
.
get
(
0
);
}
}
return
activity
;
}
}
src/main/java/com/example/afrishop_v3/controllers/OrderController.java
浏览文件 @
c1b76766
...
...
@@ -23,6 +23,7 @@ import java.io.IOException;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.net.URISyntaxException
;
import
java.text.ParseException
;
import
java.time.Duration
;
import
java.util.*
;
import
java.util.concurrent.ExecutionException
;
...
...
@@ -101,7 +102,7 @@ public class OrderController extends Controller {
@RequestParam
(
value
=
"itemSku"
,
defaultValue
=
""
)
String
itemSku
,
@RequestParam
(
value
=
"itemSkuId"
,
required
=
false
)
String
itemSkuId
,
@RequestParam
(
value
=
"toitableId"
,
required
=
false
)
String
toitableId
,
@RequestParam
(
value
=
"open"
,
required
=
false
)
boolean
open
)
{
@RequestParam
(
value
=
"open"
,
required
=
false
)
boolean
open
)
throws
ParseException
{
TbCfOrder
order
=
new
TbCfOrder
();
...
...
@@ -150,7 +151,7 @@ public class OrderController extends Controller {
@PostMapping
(
"/settle"
)
public
Result
<
TbCfOrder
>
settleAccount
(
@RequestBody
String
[]
ids
,
@RequestParam
(
value
=
"toitableId"
,
required
=
false
)
String
toitableId
,
@RequestParam
(
value
=
"open"
,
required
=
false
)
boolean
open
)
{
@RequestParam
(
value
=
"open"
,
required
=
false
)
boolean
open
)
throws
ParseException
{
//String userId = user.userId();
List
<
TbCfCartRecordR
>
allByUserId
=
cartRepository
.
findAllByCartRecordIdIn
(
ids
);
BigDecimal
orderPrice
=
BigDecimal
.
ZERO
;
...
...
@@ -206,7 +207,7 @@ public class OrderController extends Controller {
@RequestParam
(
value
=
"itemSkuId"
,
required
=
false
)
String
itemSkuId
,
@RequestParam
(
value
=
"orderSource"
,
required
=
false
)
Integer
orderSource
,
@RequestParam
(
value
=
"open"
,
required
=
false
)
boolean
open
)
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
)
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
,
ParseException
{
TbCfUserInfo
user
=
this
.
user
.
user
();
String
userId
=
user
.
getUserId
();
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论