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
be3a882d
Commit
be3a882d
authored
Jun 20, 2021
by
季圣华
Browse files
给商品条码增加重复校验
parent
bc90059c
Changes
5
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java
View file @
be3a882d
...
...
@@ -284,6 +284,9 @@ public class ExceptionConstants {
//商品库存不足
public
static
final
int
MATERIAL_STOCK_NOT_ENOUGH_CODE
=
8000004
;
public
static
final
String
MATERIAL_STOCK_NOT_ENOUGH_MSG
=
"商品:%s库存不足"
;
//商品条码重复
public
static
final
int
MATERIAL_BARCODE_EXISTS_CODE
=
8000005
;
public
static
final
String
MATERIAL_BARCODE_EXISTS_MSG
=
"商品条码:%s重复"
;
/**
* 单据信息
* type = 85
...
...
jshERP-boot/src/main/java/com/jsh/erp/controller/MaterialExtendController.java
View file @
be3a882d
...
...
@@ -81,4 +81,27 @@ public class MaterialExtendController {
}
return
res
;
}
@GetMapping
(
value
=
"/checkIsBarCodeExist"
)
public
BaseResponseInfo
checkIsBarCodeExist
(
@RequestParam
(
"id"
)
Long
id
,
@RequestParam
(
"barCode"
)
String
barCode
,
HttpServletRequest
request
)
throws
Exception
{
BaseResponseInfo
res
=
new
BaseResponseInfo
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
try
{
int
exist
=
materialExtendService
.
checkIsBarCodeExist
(
id
,
barCode
);
if
(
exist
>
0
)
{
map
.
put
(
"status"
,
true
);
}
else
{
map
.
put
(
"status"
,
false
);
}
res
.
code
=
200
;
res
.
data
=
map
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
res
.
code
=
500
;
res
.
data
=
"获取数据失败"
;
}
return
res
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java
View file @
be3a882d
...
...
@@ -173,7 +173,7 @@ public class MaterialService {
if
(
materials
!=
null
&&
materials
.
size
()>
0
)
{
mId
=
materials
.
get
(
0
).
getId
();
}
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
mId
);
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
mId
,
"insert"
);
if
(
obj
.
get
(
"stock"
)!=
null
)
{
JSONArray
stockArr
=
obj
.
getJSONArray
(
"stock"
);
for
(
int
i
=
0
;
i
<
stockArr
.
size
();
i
++)
{
...
...
@@ -190,7 +190,11 @@ public class MaterialService {
logService
.
insertLog
(
"商品"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
m
.
getName
()).
toString
(),
request
);
return
1
;
}
catch
(
Exception
e
){
}
catch
(
BusinessRunTimeException
ex
)
{
throw
new
BusinessRunTimeException
(
ex
.
getCode
(),
ex
.
getMessage
());
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
return
0
;
}
...
...
@@ -204,7 +208,7 @@ public class MaterialService {
if
(
material
.
getUnitId
()
==
null
)
{
materialMapperEx
.
setUnitIdToNull
(
material
.
getId
());
}
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
material
.
getId
());
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
material
.
getId
()
,
"update"
);
if
(
obj
.
get
(
"stock"
)!=
null
)
{
JSONArray
stockArr
=
obj
.
getJSONArray
(
"stock"
);
for
(
int
i
=
0
;
i
<
stockArr
.
size
();
i
++)
{
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/materialExtend/MaterialExtendComponent.java
View file @
be3a882d
...
...
@@ -59,7 +59,7 @@ public class MaterialExtendComponent implements ICommonQuery {
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
materialExtendService
.
checkIsExist
(
id
,
name
)
;
return
0
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/materialExtend/MaterialExtendService.java
View file @
be3a882d
...
...
@@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSONArray;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.MaterialExtend
;
import
com.jsh.erp.datasource.entities.MaterialExtendExample
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.mappers.MaterialExtendMapper
;
import
com.jsh.erp.datasource.mappers.MaterialExtendMapperEx
;
import
com.jsh.erp.datasource.vo.MaterialExtendVo4List
;
import
com.jsh.erp.exception.BusinessParamCheckingException
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.redis.RedisService
;
...
...
@@ -77,7 +80,7 @@ public class MaterialExtendService {
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
String
saveDetials
(
JSONObject
obj
,
String
sortList
,
Long
materialId
)
throws
Exception
{
public
String
saveDetials
(
JSONObject
obj
,
String
sortList
,
Long
materialId
,
String
type
)
throws
Exception
{
HttpServletRequest
request
=
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
JSONArray
meArr
=
obj
.
getJSONArray
(
"meList"
);
JSONArray
insertedJson
=
new
JSONArray
();
...
...
@@ -85,22 +88,29 @@ public class MaterialExtendService {
JSONArray
deletedJson
=
new
JSONArray
();
List
<
String
>
barCodeList
=
new
ArrayList
<>();
if
(
null
!=
meArr
)
{
for
(
int
i
=
0
;
i
<
meArr
.
size
();
i
++)
{
JSONObject
tempJson
=
meArr
.
getJSONObject
(
i
);
String
barCode
=
tempJson
.
getString
(
"barCode"
);
barCodeList
.
add
(
barCode
);
MaterialExtend
materialExtend
=
getInfoByBarCode
(
barCode
);
if
(
materialExtend
.
getBarCode
()
==
null
){
if
(
"insert"
.
equals
(
type
)){
for
(
int
i
=
0
;
i
<
meArr
.
size
();
i
++)
{
JSONObject
tempJson
=
meArr
.
getJSONObject
(
i
);
insertedJson
.
add
(
tempJson
);
}
else
{
updatedJson
.
add
(
tempJson
);
}
}
List
<
MaterialExtend
>
materialExtendList
=
getMeListByBarCodeAndMid
(
barCodeList
,
materialId
);
for
(
MaterialExtend
meObj:
materialExtendList
)
{
JSONObject
deleteObj
=
new
JSONObject
();
deleteObj
.
put
(
"id"
,
meObj
.
getId
());
deletedJson
.
add
(
deleteObj
);
}
else
if
(
"update"
.
equals
(
type
)){
for
(
int
i
=
0
;
i
<
meArr
.
size
();
i
++)
{
JSONObject
tempJson
=
meArr
.
getJSONObject
(
i
);
String
barCode
=
tempJson
.
getString
(
"barCode"
);
barCodeList
.
add
(
barCode
);
MaterialExtend
materialExtend
=
getInfoByBarCode
(
barCode
);
if
(
materialExtend
.
getBarCode
()
==
null
)
{
insertedJson
.
add
(
tempJson
);
}
else
{
updatedJson
.
add
(
tempJson
);
}
}
List
<
MaterialExtend
>
materialExtendList
=
getMeListByBarCodeAndMid
(
barCodeList
,
materialId
);
for
(
MaterialExtend
meObj
:
materialExtendList
)
{
JSONObject
deleteObj
=
new
JSONObject
();
deleteObj
.
put
(
"id"
,
meObj
.
getId
());
deletedJson
.
add
(
deleteObj
);
}
}
}
JSONArray
sortJson
=
JSONArray
.
parseArray
(
sortList
);
...
...
@@ -110,7 +120,13 @@ public class MaterialExtendService {
JSONObject
tempInsertedJson
=
JSONObject
.
parseObject
(
insertedJson
.
getString
(
i
));
materialExtend
.
setMaterialId
(
materialId
);
if
(
StringUtils
.
isNotEmpty
(
tempInsertedJson
.
getString
(
"barCode"
)))
{
materialExtend
.
setBarCode
(
tempInsertedJson
.
getString
(
"barCode"
));
int
exist
=
checkIsBarCodeExist
(
0L
,
tempInsertedJson
.
getString
(
"barCode"
));
if
(
exist
>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_MSG
,
tempInsertedJson
.
getString
(
"barCode"
)));
}
else
{
materialExtend
.
setBarCode
(
tempInsertedJson
.
getString
(
"barCode"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
tempInsertedJson
.
getString
(
"commodityUnit"
)))
{
materialExtend
.
setCommodityUnit
(
tempInsertedJson
.
getString
(
"commodityUnit"
));
...
...
@@ -147,7 +163,13 @@ public class MaterialExtendService {
MaterialExtend
materialExtend
=
new
MaterialExtend
();
materialExtend
.
setId
(
tempUpdatedJson
.
getLong
(
"id"
));
if
(
StringUtils
.
isNotEmpty
(
tempUpdatedJson
.
getString
(
"barCode"
)))
{
materialExtend
.
setBarCode
(
tempUpdatedJson
.
getString
(
"barCode"
));
int
exist
=
checkIsBarCodeExist
(
tempUpdatedJson
.
getLong
(
"id"
),
tempUpdatedJson
.
getString
(
"barCode"
));
if
(
exist
>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_MSG
,
tempUpdatedJson
.
getString
(
"barCode"
)));
}
else
{
materialExtend
.
setBarCode
(
tempUpdatedJson
.
getString
(
"barCode"
));
}
}
if
(
StringUtils
.
isNotEmpty
(
tempUpdatedJson
.
getString
(
"commodityUnit"
)))
{
materialExtend
.
setCommodityUnit
(
tempUpdatedJson
.
getString
(
"commodityUnit"
));
...
...
@@ -233,10 +255,10 @@ public class MaterialExtendService {
return
res
;
}
public
int
checkIsExist
(
Long
id
,
String
MaterialExtendNam
e
)
throws
Exception
{
public
int
checkIs
BarCode
Exist
(
Long
id
,
String
barCod
e
)
throws
Exception
{
MaterialExtendExample
example
=
new
MaterialExtendExample
();
MaterialExtendExample
.
Criteria
criteria
=
example
.
createCriteria
();
criteria
.
andBarCodeEqualTo
(
MaterialExtendNam
e
);
criteria
.
andBarCodeEqualTo
(
barCod
e
);
if
(
id
>
0
)
{
criteria
.
andIdNotEqualTo
(
id
);
}
...
...
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