Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
e95e1475
Commit
e95e1475
authored
Aug 29, 2022
by
季圣华
Browse files
完善多属性模块的接口
parent
9fd47a6f
Changes
2
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialAttributeController.java
View file @
e95e1475
package
com.jsh.erp.controller
;
package
com.jsh.erp.controller
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.MaterialAttribute
;
import
com.jsh.erp.datasource.entities.MaterialAttribute
;
import
com.jsh.erp.datasource.entities.Person
;
import
com.jsh.erp.service.materialAttribute.MaterialAttributeService
;
import
com.jsh.erp.service.materialAttribute.MaterialAttributeService
;
import
com.jsh.erp.utils.BaseResponseInfo
;
import
com.jsh.erp.utils.BaseResponseInfo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
...
@@ -30,24 +32,45 @@ public class MaterialAttributeController {
...
@@ -30,24 +32,45 @@ public class MaterialAttributeController {
private
MaterialAttributeService
materialAttributeService
;
private
MaterialAttributeService
materialAttributeService
;
/**
/**
* 获取
全部
商品属性
* 获取商品属性
的名称列表
* @param request
* @param request
* @return
* @return
* @throws Exception
*/
*/
@GetMapping
(
"/getAll
"
)
@GetMapping
(
value
=
"/getNameList
"
)
@ApiOperation
(
value
=
"获取
全部
商品属性"
)
@ApiOperation
(
value
=
"获取商品属性
的名称列表
"
)
public
BaseResponseInfo
getAll
(
HttpServletRequest
request
)
throws
Exception
{
public
JSONArray
getNameList
(
HttpServletRequest
request
)
throws
Exception
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
JSONArray
dataArray
=
new
JSONArray
();
try
{
try
{
JSONObject
obj
=
materialAttributeService
.
getAll
();
List
<
MaterialAttribute
>
materialAttributeList
=
materialAttributeService
.
getMaterialAttribute
();
res
.
code
=
200
;
if
(
null
!=
materialAttributeList
)
{
res
.
data
=
obj
;
for
(
MaterialAttribute
materialAttribute
:
materialAttributeList
)
{
JSONObject
item
=
new
JSONObject
();
item
.
put
(
"value"
,
materialAttribute
.
getId
().
toString
());
item
.
put
(
"name"
,
materialAttribute
.
getAttributeName
());
dataArray
.
add
(
item
);
}
}
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
res
.
code
=
500
;
res
.
data
=
"获取数据失败"
;
}
}
return
res
;
return
dataArray
;
}
/**
* 获取id查询属性的值列表
* @param request
* @return
*/
@GetMapping
(
value
=
"/getValueListById"
)
@ApiOperation
(
value
=
"获取id查询属性的值列表"
)
public
JSONArray
getValueListById
(
@RequestParam
(
"id"
)
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
JSONArray
dataArray
=
new
JSONArray
();
try
{
dataArray
=
materialAttributeService
.
getValueArrById
(
id
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
return
dataArray
;
}
}
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/materialAttribute/MaterialAttributeService.java
View file @
e95e1475
...
@@ -164,57 +164,9 @@ public class MaterialAttributeService {
...
@@ -164,57 +164,9 @@ public class MaterialAttributeService {
return
list
==
null
?
0
:
list
.
size
();
return
list
==
null
?
0
:
list
.
size
();
}
}
public
JSONObject
getAll
()
{
public
JSONArray
getValueArrById
(
Long
id
)
{
JSONObject
obj
=
new
JSONObject
();
//属性名
obj
.
put
(
"manyColorName"
,
getNameByField
(
"manyColor"
));
obj
.
put
(
"manySizeName"
,
getNameByField
(
"manySize"
));
obj
.
put
(
"other1Name"
,
getNameByField
(
"other1"
));
obj
.
put
(
"other2Name"
,
getNameByField
(
"other2"
));
obj
.
put
(
"other3Name"
,
getNameByField
(
"other3"
));
//属性值
obj
.
put
(
"manyColorValue"
,
getValueArrByField
(
"manyColor"
));
obj
.
put
(
"manySizeValue"
,
getValueArrByField
(
"manySize"
));
obj
.
put
(
"other1Value"
,
getValueArrByField
(
"other1"
));
obj
.
put
(
"other2Value"
,
getValueArrByField
(
"other2"
));
obj
.
put
(
"other3Value"
,
getValueArrByField
(
"other3"
));
return
obj
;
}
public
MaterialAttribute
getInfoByField
(
String
field
)
{
MaterialAttributeExample
example
=
new
MaterialAttributeExample
();
example
.
createCriteria
().
andAttributeFieldEqualTo
(
field
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
MaterialAttribute
>
list
=
materialAttributeMapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
return
list
.
get
(
0
);
}
else
{
return
null
;
}
}
public
String
getNameByField
(
String
field
)
{
String
res
=
""
;
if
(
"manyColor"
.
equals
(
field
)){
res
=
"多颜色"
;
}
else
if
(
"manySize"
.
equals
(
field
)){
res
=
"多尺寸"
;
}
else
if
(
"other1"
.
equals
(
field
)){
res
=
"自定义1"
;
}
else
if
(
"other2"
.
equals
(
field
)){
res
=
"自定义2"
;
}
else
if
(
"other3"
.
equals
(
field
)){
res
=
"自定义3"
;
}
MaterialAttribute
ma
=
getInfoByField
(
field
);
if
(
ma
!=
null
&&
StringUtil
.
isNotEmpty
(
ma
.
getAttributeName
()))
{
res
=
ma
.
getAttributeName
();
}
return
res
;
}
public
JSONArray
getValueArrByField
(
String
field
)
{
JSONArray
valueArr
=
new
JSONArray
();
JSONArray
valueArr
=
new
JSONArray
();
MaterialAttribute
ma
=
getInfoBy
Field
(
fiel
d
);
MaterialAttribute
ma
=
getInfoBy
Id
(
i
d
);
if
(
ma
!=
null
)
{
if
(
ma
!=
null
)
{
String
value
=
ma
.
getAttributeValue
();
String
value
=
ma
.
getAttributeValue
();
if
(
StringUtil
.
isNotEmpty
(
value
)){
if
(
StringUtil
.
isNotEmpty
(
value
)){
...
@@ -229,4 +181,15 @@ public class MaterialAttributeService {
...
@@ -229,4 +181,15 @@ public class MaterialAttributeService {
}
}
return
valueArr
;
return
valueArr
;
}
}
public
MaterialAttribute
getInfoById
(
Long
id
)
{
MaterialAttributeExample
example
=
new
MaterialAttributeExample
();
example
.
createCriteria
().
andIdEqualTo
(
id
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
MaterialAttribute
>
list
=
materialAttributeMapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
return
list
.
get
(
0
);
}
else
{
return
null
;
}
}
}
}
Write
Preview
Supports
Markdown
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