Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
541843a9
Commit
541843a9
authored
Feb 27, 2023
by
weijiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下单时校验订单中sku数量
parent
cb6da3e2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
37 deletions
+49
-37
soss-system/src/main/java/com/soss/system/service/impl/ShopGoodsServiceImpl.java
+49
-37
No files found.
soss-system/src/main/java/com/soss/system/service/impl/ShopGoodsServiceImpl.java
View file @
541843a9
package
com
.
soss
.
system
.
service
.
impl
;
package
com
.
soss
.
system
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.soss.common.exception.ServiceException
;
import
com.soss.common.exception.ServiceException
;
import
com.soss.system.domain.Machine
;
import
com.soss.system.domain.*
;
import
com.soss.system.domain.ShopGoods
;
import
com.soss.system.domain.Spec
;
import
com.soss.system.domain.SpecRule
;
import
com.soss.system.domain.vo.orderTaking.SkuVo
;
import
com.soss.system.domain.vo.orderTaking.SkuVo
;
import
com.soss.system.mapper.*
;
import
com.soss.system.mapper.*
;
import
com.soss.system.service.IShopGoodsService
;
import
com.soss.system.service.IShopGoodsService
;
...
@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -13,10 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
/**
/**
...
@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
...
@@ -118,18 +113,15 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
return
null
;
return
null
;
}
}
Map
<
Long
,
SpecRule
>
selloutRules
=
new
HashMap
<>();
Set
<
Long
>
selloutRules
=
new
HashSet
<>();
Map
<
Long
,
SpecRule
>
sellinRules
=
new
HashMap
<>();
Set
<
Long
>
sellinRules
=
new
HashSet
<>();
List
<
SkuVo
>
selloutSkus
=
skuMap
.
get
(
"2"
);
List
<
SkuVo
>
selloutSkus
=
skuMap
.
get
(
"2"
);
if
(!
CollectionUtils
.
isEmpty
(
selloutSkus
))
{
if
(!
CollectionUtils
.
isEmpty
(
selloutSkus
))
{
selloutSkus
.
forEach
(
skuVo
->
{
selloutSkus
.
forEach
(
skuVo
->
{
List
<
SpecRule
>
rules
=
JSON
.
parseArray
(
skuVo
.
getRulesString
(),
SpecRule
.
class
);
List
<
SpecRule
>
rules
=
JSON
.
parseArray
(
skuVo
.
getRulesString
(),
SpecRule
.
class
);
if
(!
CollectionUtils
.
isEmpty
(
rules
))
{
if
(!
CollectionUtils
.
isEmpty
(
rules
))
{
rules
.
forEach
(
rule
->
{
rules
.
forEach
(
rule
->
selloutRules
.
add
(
rule
.
getId
()));
rule
.
setState
(
2
);
selloutRules
.
put
(
rule
.
getId
(),
rule
);
});
}
}
});
});
}
}
...
@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
...
@@ -139,42 +131,62 @@ public class ShopGoodsServiceImpl implements IShopGoodsService {
sellinSkus
.
forEach
(
skuVo
->
{
sellinSkus
.
forEach
(
skuVo
->
{
List
<
SpecRule
>
rules
=
JSON
.
parseArray
(
skuVo
.
getRulesString
(),
SpecRule
.
class
);
List
<
SpecRule
>
rules
=
JSON
.
parseArray
(
skuVo
.
getRulesString
(),
SpecRule
.
class
);
if
(!
CollectionUtils
.
isEmpty
(
rules
))
{
if
(!
CollectionUtils
.
isEmpty
(
rules
))
{
rules
.
forEach
(
rule
->
{
rules
.
forEach
(
rule
->
sellinRules
.
add
(
rule
.
getId
()));
rule
.
setState
(
1
);
sellinRules
.
put
(
rule
.
getId
(),
rule
);
});
}
}
});
});
}
}
// 从售罄sku选项列表中删除 未售罄sku选项
// 从售罄sku选项列表中删除 未售罄sku选项
sellinRules
.
values
().
forEach
(
rule
->
selloutRules
.
remove
(
rule
.
getId
()));
sellinRules
.
forEach
(
sellinId
->
selloutRules
.
remove
(
sellinId
));
Map
<
Long
,
List
<
SpecRule
>>
selloutRulesBySpec
=
selloutRules
.
values
().
stream
().
collect
(
Collectors
.
groupingBy
(
SpecRule:
:
getSpecId
));
Map
<
Long
,
List
<
SpecRule
>>
sellinRulesBySpec
=
sellinRules
.
values
().
stream
().
collect
(
Collectors
.
groupingBy
(
SpecRule:
:
getSpecId
));
List
<
Long
>
specIds
=
new
ArrayList
<>();
Goods
goods
=
goodsMapper
.
selectGoodsById
(
goodsId
);
specIds
.
addAll
(
sellinRules
.
values
().
stream
().
map
(
SpecRule:
:
getSpecId
).
collect
(
Collectors
.
toList
()));
if
(
goods
==
null
)
{
specIds
.
addAll
(
selloutRules
.
values
().
stream
().
map
(
SpecRule:
:
getSpecId
).
collect
(
Collectors
.
toList
()));
// 构建返回数据
List
<
Spec
>
specVos
=
specMapper
.
selectSpecByIds
(
specIds
);
if
(
CollectionUtils
.
isEmpty
(
specVos
))
{
return
null
;
return
null
;
}
}
specVos
.
forEach
(
spec
->
{
List
<
Spec
>
specs
=
JSONArray
.
parseArray
(
goods
.
getSpec
(),
Spec
.
class
);
if
(
CollectionUtils
.
isEmpty
(
spec
.
getSpecRules
()
))
{
if
(
CollectionUtils
.
isEmpty
(
specs
))
{
spec
.
setSpecRules
(
new
ArrayList
<>())
;
return
specs
;
}
}
if
(!
CollectionUtils
.
isEmpty
(
sellinRulesBySpec
.
get
(
spec
.
getId
())))
{
specs
.
forEach
(
spec
->
{
spec
.
getSpecRules
().
addAll
(
sellinRulesBySpec
.
get
(
spec
.
getId
()));
List
<
SpecRule
>
rules
=
spec
.
getSpecRules
();
if
(
CollectionUtils
.
isEmpty
(
rules
))
{
return
;
}
}
if
(!
CollectionUtils
.
isEmpty
(
selloutRulesBySpec
.
get
(
spec
.
getId
())))
{
rules
.
forEach
(
rule
->
{
spec
.
getSpecRules
().
addAll
(
selloutRulesBySpec
.
get
(
spec
.
getId
()));
if
(
sellinRules
.
contains
(
rule
.
getId
()))
{
rule
.
setState
(
1
);
}
else
{
rule
.
setState
(
0
);
}
}
});
});
});
// Map<Long, List<SpecRule>> selloutRulesBySpec = selloutRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
// Map<Long, List<SpecRule>> sellinRulesBySpec = sellinRules.values().stream().collect(Collectors.groupingBy(SpecRule::getSpecId));
//
// List<Long> specIds = new ArrayList<>();
// specIds.addAll(sellinRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
// specIds.addAll(selloutRules.values().stream().map(SpecRule::getSpecId).collect(Collectors.toList()));
//
// // 构建返回数据
// List<Spec> specVos = specMapper.selectSpecByIds(specIds);
// if (CollectionUtils.isEmpty(specVos)) {
// return null;
// }
// specVos.forEach(spec -> {
// if (CollectionUtils.isEmpty(spec.getSpecRules())) {
// spec.setSpecRules(new ArrayList<>());
// }
// if (!CollectionUtils.isEmpty(sellinRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(sellinRulesBySpec.get(spec.getId()));
// }
// if (!CollectionUtils.isEmpty(selloutRulesBySpec.get(spec.getId()))) {
// spec.getSpecRules().addAll(selloutRulesBySpec.get(spec.getId()));
// }
// });
return
spec
Vo
s
;
return
specs
;
}
}
public
Boolean
updateShopGoodsSpecState
(
Long
shopId
,
Long
goodsId
,
Long
ruleId
,
Integer
state
)
{
public
Boolean
updateShopGoodsSpecState
(
Long
shopId
,
Long
goodsId
,
Long
ruleId
,
Integer
state
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment