Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
chejia-smart-service
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 559f325b
authored
Mar 24, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]列表展示
1 parent
1ddc864a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
29 deletions
src/main/java/com/glsx/smart/controller/ProductController.java
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
src/main/java/com/glsx/smart/dao/entity/SmartProductType.java
src/main/java/com/glsx/smart/service/SmartProductService.java
src/main/java/com/glsx/smart/service/impl/SmartProductServiceImpl.java
src/main/resources/mapper/SmartProductMapper.xml
src/main/java/com/glsx/smart/controller/ProductController.java
View file @
559f325
...
@@ -84,7 +84,7 @@ public class ProductController {
...
@@ -84,7 +84,7 @@ public class ProductController {
*/
*/
@RequestMapping
(
value
=
"/getProductAndCategory"
,
@RequestMapping
(
value
=
"/getProductAndCategory"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
public
JSONObject
getProductAndCategory
()
{
public
String
getProductAndCategory
()
{
log
.
info
(
"$$$$ /product/getProductAndCategory..."
);
log
.
info
(
"$$$$ /product/getProductAndCategory..."
);
return
productService
.
getProductAndCategory
();
return
productService
.
getProductAndCategory
();
}
}
...
...
src/main/java/com/glsx/smart/dao/entity/SmartProduct.java
View file @
559f325
...
@@ -6,6 +6,7 @@ import javax.persistence.Id;
...
@@ -6,6 +6,7 @@ import javax.persistence.Id;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
javax.persistence.Transient
;
import
java.util.Date
;
import
java.util.Date
;
import
com.glsx.smart.pojo.BaseDTO
;
import
com.glsx.smart.pojo.BaseDTO
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -31,6 +32,12 @@ public class SmartProduct extends BaseDTO {
...
@@ -31,6 +32,12 @@ public class SmartProduct extends BaseDTO {
private
String
iconUrl
;
private
String
iconUrl
;
/**
/**
* 图标 url
*/
@Transient
private
String
categoryKey
;
/**
* 产品类型名称
* 产品类型名称
*/
*/
@Transient
@Transient
...
...
src/main/java/com/glsx/smart/dao/entity/SmartProductType.java
View file @
559f325
...
@@ -7,6 +7,7 @@ import javax.persistence.GeneratedValue;
...
@@ -7,6 +7,7 @@ import javax.persistence.GeneratedValue;
import
javax.persistence.GenerationType
;
import
javax.persistence.GenerationType
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.persistence.Transient
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -73,6 +74,12 @@ public class SmartProductType extends BaseDTO {
...
@@ -73,6 +74,12 @@ public class SmartProductType extends BaseDTO {
private
Long
updateBy
;
private
Long
updateBy
;
/**
/**
* 图标 url
*/
@Transient
private
String
iconUrl
;
/**
* 内容列表
* 内容列表
*/
*/
private
List
<
SmartDeviceOrder
>
contentList
;
private
List
<
SmartDeviceOrder
>
contentList
;
...
...
src/main/java/com/glsx/smart/service/SmartProductService.java
View file @
559f325
...
@@ -23,7 +23,7 @@ public interface SmartProductService {
...
@@ -23,7 +23,7 @@ public interface SmartProductService {
SmartProduct
getById
(
Long
id
);
SmartProduct
getById
(
Long
id
);
JSONObject
getProductAndCategory
();
String
getProductAndCategory
();
Boolean
save
(
SmartProduct
product
);
Boolean
save
(
SmartProduct
product
);
...
...
src/main/java/com/glsx/smart/service/impl/SmartProductServiceImpl.java
View file @
559f325
package
com
.
glsx
.
smart
.
service
.
impl
;
package
com
.
glsx
.
smart
.
service
.
impl
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.
Set
;
import
java.util.
stream.Collectors
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.TypeReference
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.glsx.smart.dao.entity.SmartDeviceOrder
;
import
com.glsx.smart.dao.entity.SmartDeviceOrder
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartProduct
;
import
com.glsx.smart.dao.entity.SmartSysCode
;
import
com.glsx.smart.dao.mapper.SmartDeviceOrderMapper
;
import
com.glsx.smart.dao.mapper.SmartDeviceOrderMapper
;
import
com.glsx.smart.dao.mapper.SmartProductMapper
;
import
com.glsx.smart.dao.mapper.SmartProductMapper
;
import
com.glsx.smart.dao.mapper.SmartProductTypeMapper
;
import
com.glsx.smart.dao.mapper.SmartSysCodeMapper
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.BusinessException
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.exception.ResultEnum
;
import
com.glsx.smart.pojo.DjApiDTO
;
import
com.glsx.smart.pojo.DjApiDTO
;
...
@@ -22,6 +24,7 @@ import com.glsx.smart.service.BaseService;
...
@@ -22,6 +24,7 @@ import com.glsx.smart.service.BaseService;
import
com.glsx.smart.service.SmartProductService
;
import
com.glsx.smart.service.SmartProductService
;
import
com.glsx.smart.utils.DjApiInvoker
;
import
com.glsx.smart.utils.DjApiInvoker
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -43,6 +46,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -43,6 +46,9 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
private
SmartDeviceOrderMapper
deviceOrderMapper
;
private
SmartDeviceOrderMapper
deviceOrderMapper
;
@Autowired
@Autowired
private
SmartSysCodeMapper
smartSysCodeMapper
;
@Autowired
private
DjApiInvoker
djApiInvoker
;
private
DjApiInvoker
djApiInvoker
;
/**
/**
...
@@ -97,29 +103,39 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
...
@@ -97,29 +103,39 @@ public class SmartProductServiceImpl extends BaseService implements SmartProduct
* @return 结果
* @return 结果
*/
*/
@Override
@Override
public
JSONObject
getProductAndCategory
()
{
public
String
getProductAndCategory
()
{
JSONObject
result
=
new
JSONObject
();
SmartSysCode
smartSysCode
=
new
SmartSysCode
();
List
<
SmartProduct
>
productList
=
productMapper
.
getAllProductList
();
smartSysCode
.
setDictType
(
"smart_device"
);
for
(
SmartProduct
product
:
productList
)
{
List
<
SmartSysCode
>
list
=
smartSysCodeMapper
.
getList
(
smartSysCode
);
// 产品的一二级分类放在 remark 中
List
<
SmartProduct
>
allProductList
=
productMapper
.
getAllProductList
();
String
[]
categories
=
product
.
getRemark
().
split
(
","
);
List
<
Map
<
String
,
Object
>>
objectMap
=
new
ArrayList
<>();
String
category1
=
categories
[
0
];
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
String
category2
=
categories
[
1
];
List
<
SmartSysCode
>
firstlist
=
list
.
stream
().
filter
(
index
->
index
.
getLevel
()
==
0
).
collect
(
Collectors
.
toList
());
// 按照一级分类给二级分类分组
List
<
SmartSysCode
>
twolist
=
list
.
stream
().
filter
(
index
->
index
.
getLevel
()
==
1
).
collect
(
Collectors
.
toList
());
if
(!
result
.
containsKey
(
category1
))
{
firstlist
.
forEach
(
index
->{
result
.
put
(
category1
,
new
HashSet
<>());
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
}
map
.
put
(
"title"
,
index
.
getDictValue
());
Set
<
Object
>
set
=
result
.
getObject
(
category1
,
new
TypeReference
<
Set
<
Object
>>()
{});
List
<
Map
<
String
,
Object
>>
mapArrayList
=
new
ArrayList
<>();
set
.
add
(
category2
);
List
<
SmartSysCode
>
collect
=
twolist
.
stream
().
filter
(
inx
->
inx
.
getParentKey
().
equals
(
index
.
getDictKey
())).
collect
(
Collectors
.
toList
());
result
.
put
(
category1
,
set
);
collect
.
forEach
(
in
->{
Map
<
String
,
Object
>
stringObjectMap
=
new
HashMap
<>();
// 按照二级分类给产品分组
stringObjectMap
.
put
(
"title"
,
in
.
getDictValue
());
if
(!
result
.
containsKey
(
category2
))
{
List
<
SmartProduct
>
smartProducts
=
allProductList
.
stream
().
filter
(
pro
->
pro
.
getCategoryKey
().
equals
(
in
.
getDictKey
())).
collect
(
Collectors
.
toList
());
result
.
put
(
category2
,
new
JSONArray
());
List
<
Map
<
String
,
Object
>>
converlist
=
smartProducts
.
stream
().
map
(
sma
->
{
}
Map
<
String
,
Object
>
converMap
=
new
HashMap
<>();
result
.
getJSONArray
(
category2
).
add
(
product
);
converMap
.
put
(
"name"
,
sma
.
getProductName
());
}
converMap
.
put
(
"icon"
,
sma
.
getIconUrl
());
return
result
;
converMap
.
put
(
"typeId"
,
sma
.
getTypeId
());
return
converMap
;
}).
collect
(
Collectors
.
toList
());
stringObjectMap
.
put
(
"list"
,
converlist
);
mapArrayList
.
add
(
stringObjectMap
);
});
map
.
put
(
"list"
,
mapArrayList
);
objectMap
.
add
(
map
);
});
}
return
JSONObject
.
toJSONString
(
objectMap
);
}
}
/**
/**
...
...
src/main/resources/mapper/SmartProductMapper.xml
View file @
559f325
...
@@ -84,6 +84,7 @@
...
@@ -84,6 +84,7 @@
sp.create_by, sp.update_time, sp.update_by,
sp.create_by, sp.update_time, sp.update_by,
concat(ssc.parent_key, ',', spt.category_key) remark,
concat(ssc.parent_key, ',', spt.category_key) remark,
ssf.url iconUrl,
ssf.url iconUrl,
spt.category_key as categoryKey,
spt.type_name typeName
spt.type_name typeName
from smart_product sp
from smart_product sp
left join smart_product_type spt on spt.id = sp.type_id
left join smart_product_type spt on spt.id = sp.type_id
...
...
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