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
ad9ee39c
Commit
ad9ee39c
authored
May 14, 2022
by
季圣华
Browse files
优化商品的excel导入
parent
b4db7c67
Changes
12
Show whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/constants/ExceptionConstants.java
View file @
ad9ee39c
...
@@ -305,6 +305,27 @@ public class ExceptionConstants {
...
@@ -305,6 +305,27 @@ public class ExceptionConstants {
//抱歉,文件扩展名必须为xls
//抱歉,文件扩展名必须为xls
public
static
final
int
MATERIAL_EXTENSION_ERROR_CODE
=
8000009
;
public
static
final
int
MATERIAL_EXTENSION_ERROR_CODE
=
8000009
;
public
static
final
String
MATERIAL_EXTENSION_ERROR_MSG
=
"抱歉,文件扩展名必须为xls"
;
public
static
final
String
MATERIAL_EXTENSION_ERROR_MSG
=
"抱歉,文件扩展名必须为xls"
;
//名称为空
public
static
final
int
MATERIAL_NAME_EMPTY_CODE
=
8000010
;
public
static
final
String
MATERIAL_NAME_EMPTY_MSG
=
"第%s行名称为空"
;
//基本单位为空
public
static
final
int
MATERIAL_UNIT_EMPTY_CODE
=
8000011
;
public
static
final
String
MATERIAL_UNIT_EMPTY_MSG
=
"第%s行基本单位为空"
;
//状态格式错误
public
static
final
int
MATERIAL_ENABLED_ERROR_CODE
=
8000012
;
public
static
final
String
MATERIAL_ENABLED_ERROR_MSG
=
"第%s行状态格式错误"
;
//单次导入超出1000条
public
static
final
int
MATERIAL_IMPORT_OVER_LIMIT_CODE
=
8000013
;
public
static
final
String
MATERIAL_IMPORT_OVER_LIMIT_MSG
=
"抱歉,单次导入不能超出1000条"
;
//基础重量格式错误
public
static
final
int
MATERIAL_WEIGHT_NOT_DECIMAL_CODE
=
8000014
;
public
static
final
String
MATERIAL_WEIGHT_NOT_DECIMAL_MSG
=
"第%s行基础重量格式错误"
;
//保质期格式错误
public
static
final
int
MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE
=
8000015
;
public
static
final
String
MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG
=
"第%s行保质期格式错误"
;
//比例格式错误
public
static
final
int
MATERIAL_RATIO_NOT_INTEGER_CODE
=
8000016
;
public
static
final
String
MATERIAL_RATIO_NOT_INTEGER_MSG
=
"第%s行比例格式错误"
;
/**
/**
* 单据信息
* 单据信息
* type = 85
* type = 85
...
...
jshERP-boot/src/main/java/com/jsh/erp/controller/DepotController.java
View file @
ad9ee39c
...
@@ -179,7 +179,7 @@ public class DepotController {
...
@@ -179,7 +179,7 @@ public class DepotController {
DepotEx
de
=
new
DepotEx
();
DepotEx
de
=
new
DepotEx
();
if
(
mId
!=
0
)
{
if
(
mId
!=
0
)
{
BigDecimal
initStock
=
materialService
.
getInitStock
(
mId
,
depot
.
getId
());
BigDecimal
initStock
=
materialService
.
getInitStock
(
mId
,
depot
.
getId
());
BigDecimal
currentStock
=
materialService
.
getCurrentStock
(
mId
,
depot
.
getId
());
BigDecimal
currentStock
=
materialService
.
getCurrentStock
ByMaterialIdAndDepotId
(
mId
,
depot
.
getId
());
de
.
setInitStock
(
initStock
);
de
.
setInitStock
(
initStock
);
de
.
setCurrentStock
(
currentStock
);
de
.
setCurrentStock
(
currentStock
);
MaterialInitialStock
materialInitialStock
=
materialService
.
getSafeStock
(
mId
,
depot
.
getId
());
MaterialInitialStock
materialInitialStock
=
materialService
.
getSafeStock
(
mId
,
depot
.
getId
());
...
...
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialCurrentStockMapperEx.java
0 → 100644
View file @
ad9ee39c
package
com.jsh.erp.datasource.mappers
;
import
com.jsh.erp.datasource.entities.MaterialCurrentStock
;
import
com.jsh.erp.datasource.entities.MaterialCurrentStockExample
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
MaterialCurrentStockMapperEx
{
int
batchInsert
(
List
<
MaterialCurrentStock
>
list
);
List
<
MaterialCurrentStock
>
getCurrentStockMapByIdList
(
@Param
(
"materialIdList"
)
List
<
Long
>
materialIdList
);
}
\ No newline at end of file
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialInitialStockMapperEx.java
0 → 100644
View file @
ad9ee39c
package
com.jsh.erp.datasource.mappers
;
import
com.jsh.erp.datasource.entities.MaterialCurrentStock
;
import
com.jsh.erp.datasource.entities.MaterialInitialStock
;
import
com.jsh.erp.datasource.entities.MaterialInitialStockExample
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
MaterialInitialStockMapperEx
{
int
batchInsert
(
List
<
MaterialInitialStock
>
list
);
}
\ No newline at end of file
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/MaterialMapperEx.java
View file @
ad9ee39c
...
@@ -19,15 +19,13 @@ import java.util.Map;
...
@@ -19,15 +19,13 @@ import java.util.Map;
public
interface
MaterialMapperEx
{
public
interface
MaterialMapperEx
{
List
<
MaterialVo4Unit
>
selectByConditionMaterial
(
List
<
MaterialVo4Unit
>
selectByConditionMaterial
(
@Param
(
"barCode"
)
String
barCode
,
@Param
(
"materialParam"
)
String
materialParam
,
@Param
(
"name"
)
String
name
,
@Param
(
"standard"
)
String
standard
,
@Param
(
"model"
)
String
model
,
@Param
(
"color"
)
String
color
,
@Param
(
"color"
)
String
color
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enabled"
)
String
enabled
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"mpList"
)
String
mpList
,
@Param
(
"mpList"
)
String
mpList
,
...
@@ -35,19 +33,19 @@ public interface MaterialMapperEx {
...
@@ -35,19 +33,19 @@ public interface MaterialMapperEx {
@Param
(
"rows"
)
Integer
rows
);
@Param
(
"rows"
)
Integer
rows
);
Long
countsByMaterial
(
Long
countsByMaterial
(
@Param
(
"barCode"
)
String
barCode
,
@Param
(
"materialParam"
)
String
materialParam
,
@Param
(
"name"
)
String
name
,
@Param
(
"standard"
)
String
standard
,
@Param
(
"model"
)
String
model
,
@Param
(
"color"
)
String
color
,
@Param
(
"color"
)
String
color
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enabled"
)
String
enabled
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"mpList"
)
String
mpList
);
@Param
(
"mpList"
)
String
mpList
);
Long
insertSelectiveEx
(
Material
record
);
List
<
Unit
>
findUnitList
(
@Param
(
"mId"
)
Long
mId
);
List
<
Unit
>
findUnitList
(
@Param
(
"mId"
)
Long
mId
);
List
<
MaterialVo4Unit
>
findById
(
@Param
(
"id"
)
Long
id
);
List
<
MaterialVo4Unit
>
findById
(
@Param
(
"id"
)
Long
id
);
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialComponent.java
View file @
ad9ee39c
...
@@ -34,38 +34,34 @@ public class MaterialComponent implements ICommonQuery {
...
@@ -34,38 +34,34 @@ public class MaterialComponent implements ICommonQuery {
private
List
<?>
getMaterialList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
private
List
<?>
getMaterialList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
barCode
=
StringUtil
.
getInfo
(
search
,
"barCode"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
standard
=
StringUtil
.
getInfo
(
search
,
"standard"
);
String
model
=
StringUtil
.
getInfo
(
search
,
"model"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enabled
=
StringUtil
.
getInfo
(
search
,
"enabled"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
return
materialService
.
select
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
return
materialService
.
select
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
categoryId
,
mpList
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
categoryId
,
mpList
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
}
@Override
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
barCode
=
StringUtil
.
getInfo
(
search
,
"barCode"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
standard
=
StringUtil
.
getInfo
(
search
,
"standard"
);
String
model
=
StringUtil
.
getInfo
(
search
,
"model"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enabled
=
StringUtil
.
getInfo
(
search
,
"enabled"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
return
materialService
.
countMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
return
materialService
.
countMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
categoryId
,
mpList
);
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
categoryId
,
mpList
);
}
}
@Override
@Override
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java
View file @
ad9ee39c
...
@@ -64,8 +64,12 @@ public class MaterialService {
...
@@ -64,8 +64,12 @@ public class MaterialService {
@Resource
@Resource
private
MaterialInitialStockMapper
materialInitialStockMapper
;
private
MaterialInitialStockMapper
materialInitialStockMapper
;
@Resource
@Resource
private
MaterialInitialStockMapperEx
materialInitialStockMapperEx
;
@Resource
private
MaterialCurrentStockMapper
materialCurrentStockMapper
;
private
MaterialCurrentStockMapper
materialCurrentStockMapper
;
@Resource
@Resource
private
MaterialCurrentStockMapperEx
materialCurrentStockMapperEx
;
@Resource
private
DepotService
depotService
;
private
DepotService
depotService
;
@Resource
@Resource
private
MaterialExtendService
materialExtendService
;
private
MaterialExtendService
materialExtendService
;
...
@@ -107,8 +111,8 @@ public class MaterialService {
...
@@ -107,8 +111,8 @@ public class MaterialService {
return
list
;
return
list
;
}
}
public
List
<
MaterialVo4Unit
>
select
(
String
barCode
,
String
n
am
e
,
String
standard
,
String
model
,
String
color
,
public
List
<
MaterialVo4Unit
>
select
(
String
materialPar
am
,
String
color
,
String
weight
,
String
expiryNum
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enabled
,
String
remark
,
String
categoryId
,
String
mpList
,
int
offset
,
int
rows
)
String
remark
,
String
categoryId
,
String
mpList
,
int
offset
,
int
rows
)
throws
Exception
{
throws
Exception
{
String
[]
mpArr
=
new
String
[]{};
String
[]
mpArr
=
new
String
[]{};
...
@@ -122,12 +126,13 @@ public class MaterialService {
...
@@ -122,12 +126,13 @@ public class MaterialService {
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
}
}
list
=
materialMapperEx
.
selectByConditionMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
list
=
materialMapperEx
.
selectByConditionMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
idList
,
mpList
,
offset
,
rows
);
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
idList
,
mpList
,
offset
,
rows
);
if
(
null
!=
list
)
{
if
(
null
!=
list
&&
list
.
size
()>
0
)
{
Map
<
Long
,
BigDecimal
>
currentStockMap
=
getCurrentStockMapByMaterialList
(
list
);
for
(
MaterialVo4Unit
m
:
list
)
{
for
(
MaterialVo4Unit
m
:
list
)
{
m
.
setMaterialOther
(
getMaterialOtherByParam
(
mpArr
,
m
));
m
.
setMaterialOther
(
getMaterialOtherByParam
(
mpArr
,
m
));
m
.
setStock
(
depotItemService
.
getStockByParam
(
null
,
m
.
getId
(),
null
,
null
));
m
.
setStock
(
currentStockMap
.
get
(
m
.
getId
()
));
resList
.
add
(
m
);
resList
.
add
(
m
);
}
}
}
}
...
@@ -137,8 +142,8 @@ public class MaterialService {
...
@@ -137,8 +142,8 @@ public class MaterialService {
return
resList
;
return
resList
;
}
}
public
Long
countMaterial
(
String
barCode
,
String
n
am
e
,
String
standard
,
String
model
,
String
color
,
public
Long
countMaterial
(
String
materialPar
am
,
String
color
,
String
weight
,
String
expiryNum
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enabled
,
String
remark
,
String
categoryId
,
String
mpList
)
throws
Exception
{
String
remark
,
String
categoryId
,
String
mpList
)
throws
Exception
{
Long
result
=
null
;
Long
result
=
null
;
try
{
try
{
...
@@ -146,8 +151,8 @@ public class MaterialService {
...
@@ -146,8 +151,8 @@ public class MaterialService {
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
}
}
result
=
materialMapperEx
.
countsByMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
result
=
materialMapperEx
.
countsByMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
idList
,
mpList
);
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
idList
,
mpList
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
JshException
.
readFail
(
logger
,
e
);
}
}
...
@@ -159,15 +164,8 @@ public class MaterialService {
...
@@ -159,15 +164,8 @@ public class MaterialService {
Material
m
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Material
.
class
);
Material
m
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Material
.
class
);
m
.
setEnabled
(
true
);
m
.
setEnabled
(
true
);
try
{
try
{
Long
mId
=
null
;
materialMapperEx
.
insertSelectiveEx
(
m
);
materialMapper
.
insertSelective
(
m
);
Long
mId
=
m
.
getId
();
JSONArray
meArr
=
obj
.
getJSONArray
(
"meList"
);
JSONObject
tempJson
=
meArr
.
getJSONObject
(
0
);
String
basicBarCode
=
tempJson
.
getString
(
"barCode"
);
List
<
Material
>
materials
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getStandard
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
if
(
materials
!=
null
&&
materials
.
size
()>
0
)
{
mId
=
materials
.
get
(
0
).
getId
();
}
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
mId
,
"insert"
);
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
mId
,
"insert"
);
if
(
obj
.
get
(
"stock"
)!=
null
)
{
if
(
obj
.
get
(
"stock"
)!=
null
)
{
JSONArray
stockArr
=
obj
.
getJSONArray
(
"stock"
);
JSONArray
stockArr
=
obj
.
getJSONArray
(
"stock"
);
...
@@ -459,6 +457,7 @@ public class MaterialService {
...
@@ -459,6 +457,7 @@ public class MaterialService {
public
BaseResponseInfo
importExcel
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
public
BaseResponseInfo
importExcel
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
BaseResponseInfo
info
=
new
BaseResponseInfo
();
BaseResponseInfo
info
=
new
BaseResponseInfo
();
try
{
try
{
Long
beginTime
=
System
.
currentTimeMillis
();
//文件扩展名只能为xls
//文件扩展名只能为xls
String
fileName
=
file
.
getOriginalFilename
();
String
fileName
=
file
.
getOriginalFilename
();
if
(
StringUtil
.
isNotEmpty
(
fileName
))
{
if
(
StringUtil
.
isNotEmpty
(
fileName
))
{
...
@@ -472,7 +471,14 @@ public class MaterialService {
...
@@ -472,7 +471,14 @@ public class MaterialService {
Sheet
src
=
workbook
.
getSheet
(
0
);
Sheet
src
=
workbook
.
getSheet
(
0
);
List
<
Depot
>
depotList
=
depotService
.
getDepot
();
List
<
Depot
>
depotList
=
depotService
.
getDepot
();
int
depotCount
=
depotList
.
size
();
int
depotCount
=
depotList
.
size
();
Map
<
String
,
Long
>
depotMap
=
parseDepotToMap
(
depotList
);
User
user
=
userService
.
getCurrentUser
();
List
<
MaterialWithInitStock
>
mList
=
new
ArrayList
<>();
List
<
MaterialWithInitStock
>
mList
=
new
ArrayList
<>();
//单次导入超出1000条
if
(
src
.
getRows
()>
1002
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_IMPORT_OVER_LIMIT_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_IMPORT_OVER_LIMIT_MSG
));
}
for
(
int
i
=
2
;
i
<
src
.
getRows
();
i
++)
{
for
(
int
i
=
2
;
i
<
src
.
getRows
();
i
++)
{
String
name
=
ExcelUtils
.
getContent
(
src
,
i
,
0
);
//名称
String
name
=
ExcelUtils
.
getContent
(
src
,
i
,
0
);
//名称
String
standard
=
ExcelUtils
.
getContent
(
src
,
i
,
1
);
//规格
String
standard
=
ExcelUtils
.
getContent
(
src
,
i
,
1
);
//规格
...
@@ -480,10 +486,18 @@ public class MaterialService {
...
@@ -480,10 +486,18 @@ public class MaterialService {
String
color
=
ExcelUtils
.
getContent
(
src
,
i
,
3
);
//颜色
String
color
=
ExcelUtils
.
getContent
(
src
,
i
,
3
);
//颜色
String
categoryName
=
ExcelUtils
.
getContent
(
src
,
i
,
4
);
//类别
String
categoryName
=
ExcelUtils
.
getContent
(
src
,
i
,
4
);
//类别
String
weight
=
ExcelUtils
.
getContent
(
src
,
i
,
5
);
//基础重量(kg)
String
weight
=
ExcelUtils
.
getContent
(
src
,
i
,
5
);
//基础重量(kg)
String
expiryNum
=
ExcelUtils
.
getContent
(
src
,
i
,
6
);
//保质期
String
expiryNum
=
ExcelUtils
.
getContent
(
src
,
i
,
6
);
//保质期
(天)
String
unit
=
ExcelUtils
.
getContent
(
src
,
i
,
7
);
//基本单位
String
unit
=
ExcelUtils
.
getContent
(
src
,
i
,
7
);
//基本单位
//校验名称、单位是否为空
//名称为空
if
(
StringUtil
.
isNotEmpty
(
name
)
&&
StringUtil
.
isNotEmpty
(
unit
))
{
if
(
StringUtil
.
isEmpty
(
name
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_NAME_EMPTY_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_NAME_EMPTY_MSG
,
i
+
1
));
}
//基本单位为空
if
(
StringUtil
.
isEmpty
(
unit
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_UNIT_EMPTY_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_UNIT_EMPTY_MSG
,
i
+
1
));
}
MaterialWithInitStock
m
=
new
MaterialWithInitStock
();
MaterialWithInitStock
m
=
new
MaterialWithInitStock
();
m
.
setName
(
name
);
m
.
setName
(
name
);
m
.
setStandard
(
standard
);
m
.
setStandard
(
standard
);
...
@@ -494,9 +508,19 @@ public class MaterialService {
...
@@ -494,9 +508,19 @@ public class MaterialService {
m
.
setCategoryId
(
categoryId
);
m
.
setCategoryId
(
categoryId
);
}
}
if
(
StringUtil
.
isNotEmpty
(
weight
))
{
if
(
StringUtil
.
isNotEmpty
(
weight
))
{
m
.
setWeight
(
BigDecimal
.
valueOf
(
Long
.
parseLong
(
weight
)));
//校验基础重量是否是数字(含小数)
if
(!
StringUtil
.
isPositiveBigDecimal
(
weight
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_WEIGHT_NOT_DECIMAL_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_WEIGHT_NOT_DECIMAL_MSG
,
i
+
1
));
}
m
.
setWeight
(
new
BigDecimal
(
weight
));
}
}
if
(
StringUtil
.
isNotEmpty
(
expiryNum
))
{
if
(
StringUtil
.
isNotEmpty
(
expiryNum
))
{
//校验保质期是否是正整数
if
(!
StringUtil
.
isPositiveLong
(
expiryNum
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_EXPIRY_NUM_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_EXPIRY_NUM_NOT_INTEGER_MSG
,
i
+
1
));
}
m
.
setExpiryNum
(
Integer
.
parseInt
(
expiryNum
));
m
.
setExpiryNum
(
Integer
.
parseInt
(
expiryNum
));
}
}
String
manyUnit
=
ExcelUtils
.
getContent
(
src
,
i
,
8
);
//副单位
String
manyUnit
=
ExcelUtils
.
getContent
(
src
,
i
,
8
);
//副单位
...
@@ -510,6 +534,11 @@ public class MaterialService {
...
@@ -510,6 +534,11 @@ public class MaterialService {
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
16
);
//状态
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
16
);
//状态
String
enableSerialNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
17
);
//序列号
String
enableSerialNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
17
);
//序列号
String
enableBatchNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
18
);
//批号
String
enableBatchNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
18
);
//批号
//状态格式错误
if
(!
"1"
.
equals
(
enabled
)
&&
!
"0"
.
equals
(
enabled
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_ENABLED_ERROR_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_ENABLED_ERROR_MSG
,
i
+
1
));
}
//校验基础条码是否是正整数
//校验基础条码是否是正整数
if
(!
StringUtil
.
isPositiveLong
(
barCode
))
{
if
(!
StringUtil
.
isPositiveLong
(
barCode
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
...
@@ -530,6 +559,11 @@ public class MaterialService {
...
@@ -530,6 +559,11 @@ public class MaterialService {
basicObj
.
put
(
"lowDecimal"
,
lowDecimal
);
basicObj
.
put
(
"lowDecimal"
,
lowDecimal
);
materialExObj
.
put
(
"basic"
,
basicObj
);
materialExObj
.
put
(
"basic"
,
basicObj
);
if
(
StringUtil
.
isNotEmpty
(
manyUnit
)
&&
StringUtil
.
isNotEmpty
(
ratio
)){
//多单位
if
(
StringUtil
.
isNotEmpty
(
manyUnit
)
&&
StringUtil
.
isNotEmpty
(
ratio
)){
//多单位
//校验比例是否是正整数
if
(!
StringUtil
.
isPositiveLong
(
ratio
.
trim
()))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_RATIO_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_RATIO_NOT_INTEGER_MSG
,
i
+
1
));
}
Long
unitId
=
unitService
.
getUnitIdByParam
(
unit
,
manyUnit
,
Integer
.
parseInt
(
ratio
.
trim
()));
Long
unitId
=
unitService
.
getUnitIdByParam
(
unit
,
manyUnit
,
Integer
.
parseInt
(
ratio
.
trim
()));
if
(
unitId
!=
null
)
{
if
(
unitId
!=
null
)
{
m
.
setUnitId
(
unitId
);
m
.
setUnitId
(
unitId
);
...
@@ -564,38 +598,20 @@ public class MaterialService {
...
@@ -564,38 +598,20 @@ public class MaterialService {
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_CODE
,
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_MSG
,
barCode
));
String
.
format
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_MSG
,
barCode
));
}
}
//缓存各个仓库的库存信息
m
.
setStockMap
(
getStockMapCache
(
src
,
depotCount
,
depotMap
,
i
));
Map
<
Long
,
BigDecimal
>
stockMap
=
new
HashMap
<>();
for
(
int
j
=
1
;
j
<=
depotCount
;
j
++)
{
int
col
=
18
+
j
;
if
(
col
<
src
.
getColumns
()){
String
depotName
=
ExcelUtils
.
getContent
(
src
,
1
,
col
);
//获取仓库名称
if
(
StringUtil
.
isNotEmpty
(
depotName
))
{
Long
depotId
=
depotService
.
getIdByName
(
depotName
);
if
(
depotId
!=
0L
){
String
stockStr
=
ExcelUtils
.
getContent
(
src
,
i
,
col
);
if
(
StringUtil
.
isNotEmpty
(
stockStr
))
{
stockMap
.
put
(
depotId
,
parseBigDecimalEx
(
stockStr
));
}
}
}
}
}
m
.
setStockMap
(
stockMap
);
mList
.
add
(
m
);
mList
.
add
(
m
);
}
}
}
List
<
Long
>
deleteStockMaterialIdList
=
new
ArrayList
<>();
Long
mId
=
0L
;
List
<
MaterialCurrentStock
>
insertCurrentStockMaterialList
=
new
ArrayList
<>();
List
<
MaterialInitialStock
>
insertInitialStockMaterialList
=
new
ArrayList
<>();
for
(
MaterialWithInitStock
m:
mList
)
{
for
(
MaterialWithInitStock
m:
mList
)
{
Long
mId
=
0L
;
//判断该商品是否存在,如果不存在就新增,如果存在就更新
//判断该商品是否存在,如果不存在就新增,如果存在就更新
String
basicBarCode
=
getBasicBarCode
(
m
);
String
basicBarCode
=
getBasicBarCode
(
m
);
List
<
Material
>
materials
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getStandard
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
List
<
Material
>
materials
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getStandard
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
if
(
materials
.
size
()<=
0
)
{
if
(
materials
.
size
()
==
0
)
{
materialMapper
.
insertSelective
(
m
);
materialMapperEx
.
insertSelectiveEx
(
m
);
List
<
Material
>
newList
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getStandard
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
mId
=
m
.
getId
();
if
(
newList
.
size
()>
0
)
{
mId
=
newList
.
get
(
0
).
getId
();
}
}
else
{
}
else
{
mId
=
materials
.
get
(
0
).
getId
();
mId
=
materials
.
get
(
0
).
getId
();
String
materialJson
=
JSON
.
toJSONString
(
m
);
String
materialJson
=
JSON
.
toJSONString
(
m
);
...
@@ -603,54 +619,49 @@ public class MaterialService {
...
@@ -603,54 +619,49 @@ public class MaterialService {
material
.
setId
(
mId
);
material
.
setId
(
mId
);
materialMapper
.
updateByPrimaryKeySelective
(
material
);
materialMapper
.
updateByPrimaryKeySelective
(
material
);
}
}
//给商品新增条码与价格相关信息
//给商品新增或更新条码与价格相关信息
User
user
=
userService
.
getCurrentUser
();
JSONObject
materialExObj
=
m
.
getMaterialExObj
();
JSONObject
materialExObj
=
m
.
getMaterialExObj
();
if
(
StringUtil
.
isExist
(
materialExObj
.
get
(
"basic"
))){
insertOrUpdateMaterialExtend
(
materialExObj
,
"basic"
,
"1"
,
mId
,
user
);
String
basicStr
=
materialExObj
.
getString
(
"basic"
);
insertOrUpdateMaterialExtend
(
materialExObj
,
"other"
,
"0"
,
mId
,
user
);
MaterialExtend
basicMaterialExtend
=
JSONObject
.
parseObject
(
basicStr
,
MaterialExtend
.
class
);
//给商品更新库存
basicMaterialExtend
.
setMaterialId
(
mId
);
deleteStockMaterialIdList
.
add
(
mId
);
basicMaterialExtend
.
setDefaultFlag
(
"1"
);
basicMaterialExtend
.
setCreateTime
(
new
Date
());
basicMaterialExtend
.
setUpdateTime
(
System
.
currentTimeMillis
());
basicMaterialExtend
.
setCreateSerial
(
user
.
getLoginName
());
basicMaterialExtend
.
setUpdateSerial
(
user
.
getLoginName
());
Long
meId
=
materialExtendService
.
selectIdByMaterialIdAndDefaultFlag
(
mId
,
"1"
);
changeMaterialExtend
(
mId
,
basicMaterialExtend
,
meId
);
}
if
(
StringUtil
.
isExist
(
materialExObj
.
get
(
"other"
)))
{
String
otherStr
=
materialExObj
.
getString
(
"other"
);
MaterialExtend
otherMaterialExtend
=
JSONObject
.
parseObject
(
otherStr
,
MaterialExtend
.
class
);
otherMaterialExtend
.
setMaterialId
(
mId
);
otherMaterialExtend
.
setDefaultFlag
(
"0"
);
otherMaterialExtend
.
setCreateTime
(
new
Date
());
otherMaterialExtend
.
setUpdateTime
(
System
.
currentTimeMillis
());
otherMaterialExtend
.
setCreateSerial
(
user
.
getLoginName
());
otherMaterialExtend
.
setUpdateSerial
(
user
.
getLoginName
());
Long
meId
=
materialExtendService
.
selectIdByMaterialIdAndDefaultFlag
(
mId
,
"0"
);
changeMaterialExtend
(
mId
,
otherMaterialExtend
,
meId
);
}
//给商品初始化库存getAllListWithStock
Map
<
Long
,
BigDecimal
>
stockMap
=
m
.
getStockMap
();
Map
<
Long
,
BigDecimal
>
stockMap
=
m
.
getStockMap
();
Long
depotId
=
null
;
for
(
Depot
depot:
depotList
){
for
(
Depot
depot:
depotList
){
depotId
=
depot
.
getId
();
Long
depotId
=
depot
.
getId
();
BigDecimal
stock
=
stockMap
.
get
(
depot
.
getId
());
BigDecimal
stock
=
stockMap
.
get
(
depot
.
getId
());
//初始库存-先清除再插入
MaterialInitialStockExample
example
=
new
MaterialInitialStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
mId
).
andDepotIdEqualTo
(
depot
.
getId
());
materialInitialStockMapper
.
deleteByExample
(
example
);
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
//新增初始库存
//新增初始库存
insertInitialStockByMaterialAndDepot
(
depotId
,
mId
,
stock
,
null
,
null
);
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
MaterialInitialStock
materialInitialStock
=
new
MaterialInitialStock
();
materialInitialStock
.
setMaterialId
(
mId
);
materialInitialStock
.
setDepotId
(
depotId
);
materialInitialStock
.
setNumber
(
stock
);
insertInitialStockMaterialList
.
add
(
materialInitialStock
);
}
}
//新增或更新当前库存
//新增或更新当前库存
insertOrUpdateCurrentStockByMaterialAndDepot
(
depotId
,
mId
,
stock
);
Long
billCount
=
depotItemService
.
getCountByMaterialAndDepot
(
mId
,
depotId
);
if
(
billCount
==
0
)
{
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
MaterialCurrentStock
materialCurrentStock
=
new
MaterialCurrentStock
();
materialCurrentStock
.
setMaterialId
(
mId
);
materialCurrentStock
.
setDepotId
(
depotId
);
materialCurrentStock
.
setCurrentNumber
(
stock
);
insertCurrentStockMaterialList
.
add
(
materialCurrentStock
);
}
}
}
else
{
depotItemService
.
updateCurrentStockFun
(
mId
,
depotId
);
}
}
}
}
//批量更新库存
batchDeleteInitialStockByMaterialList
(
deleteStockMaterialIdList
);
materialInitialStockMapperEx
.
batchInsert
(
insertInitialStockMaterialList
);
batchDeleteCurrentStockByMaterialList
(
deleteStockMaterialIdList
);
materialCurrentStockMapperEx
.
batchInsert
(
insertCurrentStockMaterialList
);
logService
.
insertLog
(
"商品"
,
logService
.
insertLog
(
"商品"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_IMPORT
).
append
(
mList
.
size
()).
append
(
BusinessConstants
.
LOG_DATA_UNIT
).
toString
(),
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_IMPORT
).
append
(
mList
.
size
()).
append
(
BusinessConstants
.
LOG_DATA_UNIT
).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
Long
endTime
=
System
.
currentTimeMillis
();
logger
.
info
(
"导入耗时:{}"
,
endTime
-
beginTime
);
info
.
code
=
200
;
info
.
code
=
200
;
info
.
data
=
"导入成功"
;
info
.
data
=
"导入成功"
;
}
catch
(
BusinessRunTimeException
e
)
{
}
catch
(
BusinessRunTimeException
e
)
{
...
@@ -664,27 +675,71 @@ public class MaterialService {
...
@@ -664,27 +675,71 @@ public class MaterialService {
return
info
;
return
info
;
}
}
private
Map
<
String
,
Long
>
parseDepotToMap
(
List
<
Depot
>
depotList
)
{
Map
<
String
,
Long
>
map
=
new
HashMap
<>();
for
(
Depot
depot:
depotList
)
{
map
.
put
(
depot
.
getName
(),
depot
.
getId
());
}
return
map
;
}
/**
* 缓存各个仓库的库存信息
* @param src
* @param depotCount
* @param depotMap
* @param i
* @return
* @throws Exception
*/
private
Map
<
Long
,
BigDecimal
>
getStockMapCache
(
Sheet
src
,
int
depotCount
,
Map
<
String
,
Long
>
depotMap
,
int
i
)
throws
Exception
{
Map
<
Long
,
BigDecimal
>
stockMap
=
new
HashMap
<>();
for
(
int
j
=
1
;
j
<=
depotCount
;
j
++)
{
int
col
=
18
+
j
;
if
(
col
<
src
.
getColumns
()){
String
depotName
=
ExcelUtils
.
getContent
(
src
,
1
,
col
);
//获取仓库名称
if
(
StringUtil
.
isNotEmpty
(
depotName
))
{
Long
depotId
=
depotMap
.
get
(
depotName
);
if
(
depotId
!=
0L
){
String
stockStr
=
ExcelUtils
.
getContent
(
src
,
i
,
col
);
if
(
StringUtil
.
isNotEmpty
(
stockStr
))
{
stockMap
.
put
(
depotId
,
parseBigDecimalEx
(
stockStr
));
}
}
}
}
}
return
stockMap
;
}
/**
* 给商品新增或更新条码与价格相关信息
* @param materialExObj
* @param type
* @param defaultFlag
* @param mId
* @param user
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
changeMaterialExtend
(
Long
mId
,
MaterialExtend
materialExtend
,
Long
meId
)
{
public
void
insertOrUpdateMaterialExtend
(
JSONObject
materialExObj
,
String
type
,
String
defaultFlag
,
Long
mId
,
User
user
)
{
if
(
StringUtil
.
isExist
(
materialExObj
.
get
(
type
))){
String
basicStr
=
materialExObj
.
getString
(
type
);
MaterialExtend
materialExtend
=
JSONObject
.
parseObject
(
basicStr
,
MaterialExtend
.
class
);
materialExtend
.
setMaterialId
(
mId
);
materialExtend
.
setDefaultFlag
(
defaultFlag
);
materialExtend
.
setCreateTime
(
new
Date
());
materialExtend
.
setUpdateTime
(
System
.
currentTimeMillis
());
materialExtend
.
setCreateSerial
(
user
.
getLoginName
());
materialExtend
.
setUpdateSerial
(
user
.
getLoginName
());
Long
meId
=
materialExtendService
.
selectIdByMaterialIdAndDefaultFlag
(
mId
,
defaultFlag
);
if
(
meId
==
0L
){
if
(
meId
==
0L
){
//校验条码是否存在
List
<
MaterialVo4Unit
>
materialList
=
getMaterialByBarCode
(
materialExtend
.
getBarCode
());
if
(
materialList
!=
null
&&
materialList
.
size
()>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_MSG
,
materialExtend
.
getBarCode
()));
}
materialExtendMapper
.
insertSelective
(
materialExtend
);
materialExtendMapper
.
insertSelective
(
materialExtend
);
}
else
{
}
else
{
//校验条码是否存在:检查除此商品之外是否还有这个条码,有则返回列表
List
<
MaterialVo4Unit
>
materialList
=
getMaterialByBarCodeAndWithOutMId
(
materialExtend
.
getBarCode
(),
mId
);
if
(
materialList
!=
null
&&
materialList
.
size
()>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_EXISTS_MSG
,
materialExtend
.
getBarCode
()));
}
materialExtend
.
setId
(
meId
);
materialExtend
.
setId
(
meId
);
materialExtendMapper
.
updateByPrimaryKeySelective
(
materialExtend
);
materialExtendMapper
.
updateByPrimaryKeySelective
(
materialExtend
);
}
}
}
}
}
public
String
getBasicBarCode
(
MaterialWithInitStock
m
)
{
public
String
getBasicBarCode
(
MaterialWithInitStock
m
)
{
String
barCode
=
""
;
String
barCode
=
""
;
...
@@ -700,14 +755,14 @@ public class MaterialService {
...
@@ -700,14 +755,14 @@ public class MaterialService {
/**
/**
* 根据条件返回产品列表
* 根据条件返回产品列表
* @param name
* @param name
* @param standard
* @param model
* @param model
* @param color
* @param color
* @param standard
* @param unit
* @param unit
* @param unitId
* @param unitId
* @return
* @return
*/
*/
private
List
<
Material
>
getMaterialListByParam
(
String
name
,
String
model
,
String
color
,
String
standard
,
String
unit
,
Long
unitId
,
String
basicBarCode
)
throws
Exception
{
private
List
<
Material
>
getMaterialListByParam
(
String
name
,
String
standard
,
String
model
,
String
color
,
String
unit
,
Long
unitId
,
String
basicBarCode
)
throws
Exception
{
List
<
Material
>
list
=
new
ArrayList
<>();
List
<
Material
>
list
=
new
ArrayList
<>();
MaterialExample
example
=
new
MaterialExample
();
MaterialExample
example
=
new
MaterialExample
();
MaterialExample
.
Criteria
criteria
=
example
.
createCriteria
();
MaterialExample
.
Criteria
criteria
=
example
.
createCriteria
();
...
@@ -730,10 +785,11 @@ public class MaterialService {
...
@@ -730,10 +785,11 @@ public class MaterialService {
criteria
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
criteria
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
list
=
materialMapper
.
selectByExample
(
example
);
list
=
materialMapper
.
selectByExample
(
example
);
if
(
list
.
size
()==
0
)
{
if
(
list
.
size
()==
0
)
{
//如果通过组合条件没有查到
改
商品,则通过条码再查一次
//如果通过组合条件没有查到
该
商品,则通过条码再查一次
MaterialExtend
materialExtend
=
materialExtendService
.
getInfoByBarCode
(
basicBarCode
);
MaterialExtend
materialExtend
=
materialExtendService
.
getInfoByBarCode
(
basicBarCode
);
if
(
materialExtend
!=
null
&&
materialExtend
.
getMaterialId
()!=
null
)
{
if
(
materialExtend
!=
null
&&
materialExtend
.
getMaterialId
()!=
null
)
{
Material
material
=
getMaterial
(
materialExtend
.
getMaterialId
());
Material
material
=
new
Material
();
material
.
setId
(
materialExtend
.
getMaterialId
());
list
.
add
(
material
);
list
.
add
(
material
);
}
}
}
}
...
@@ -762,19 +818,6 @@ public class MaterialService {
...
@@ -762,19 +818,6 @@ public class MaterialService {
materialInitialStockMapper
.
insertSelective
(
materialInitialStock
);
//存入初始库存
materialInitialStockMapper
.
insertSelective
(
materialInitialStock
);
//存入初始库存
}
}
/**
* 删除当前库存
* @param depotId
* @param mId
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
deleteCurrentStockByMaterialAndDepot
(
Long
depotId
,
Long
mId
){
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
example
.
createCriteria
().
andDepotIdEqualTo
(
depotId
).
andMaterialIdEqualTo
(
mId
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
materialCurrentStockMapper
.
deleteByExample
(
example
);
}
/**
/**
* 写入当前库存
* 写入当前库存
* @param depotId
* @param depotId
...
@@ -791,22 +834,25 @@ public class MaterialService {
...
@@ -791,22 +834,25 @@ public class MaterialService {
}
}
/**
/**
* 新增或更新当前库存
* 批量删除初始库存
* @param depotId
* @param mIdList
* @param mId
* @param stock
*/
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
insertOrUpdateCurrentStockByMaterialAndDepot
(
Long
depotId
,
Long
mId
,
BigDecimal
stock
){
public
void
batchDeleteInitialStockByMaterialList
(
List
<
Long
>
mIdList
){
Long
billCount
=
depotItemService
.
getCountByMaterialAndDepot
(
mId
,
depotId
);
MaterialInitialStockExample
example
=
new
MaterialInitialStockExample
();
if
(
billCount
==
0
)
{
example
.
createCriteria
().
andMaterialIdIn
(
mIdList
);
deleteCurrentStockByMaterialAndDepot
(
depotId
,
mId
);
materialInitialStockMapper
.
deleteByExample
(
example
);
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
insertCurrentStockByMaterialAndDepot
(
depotId
,
mId
,
stock
);
}
}
else
{
depotItemService
.
updateCurrentStockFun
(
mId
,
depotId
);
}
}
/**
* 批量删除当前库存
* @param mIdList
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
batchDeleteCurrentStockByMaterialList
(
List
<
Long
>
mIdList
){
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
example
.
createCriteria
().
andMaterialIdIn
(
mIdList
);
materialCurrentStockMapper
.
deleteByExample
(
example
);
}
}
public
List
<
MaterialVo4Unit
>
getMaterialEnableSerialNumberList
(
String
q
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
public
List
<
MaterialVo4Unit
>
getMaterialEnableSerialNumberList
(
String
q
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
...
@@ -898,7 +944,7 @@ public class MaterialService {
...
@@ -898,7 +944,7 @@ public class MaterialService {
* @param depotId
* @param depotId
* @return
* @return
*/
*/
public
BigDecimal
getCurrentStock
(
Long
materialId
,
Long
depotId
)
{
public
BigDecimal
getCurrentStock
ByMaterialIdAndDepotId
(
Long
materialId
,
Long
depotId
)
{
BigDecimal
stock
=
BigDecimal
.
ZERO
;
BigDecimal
stock
=
BigDecimal
.
ZERO
;
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
materialId
).
andDepotIdEqualTo
(
depotId
)
example
.
createCriteria
().
andMaterialIdEqualTo
(
materialId
).
andDepotIdEqualTo
(
depotId
)
...
@@ -912,6 +958,24 @@ public class MaterialService {
...
@@ -912,6 +958,24 @@ public class MaterialService {
return
stock
;
return
stock
;
}
}
/**
* 根据商品列表获取当前库存Map
* @param list
* @return
*/
public
Map
<
Long
,
BigDecimal
>
getCurrentStockMapByMaterialList
(
List
<
MaterialVo4Unit
>
list
)
{
Map
<
Long
,
BigDecimal
>
map
=
new
HashMap
<>();
List
<
Long
>
materialIdList
=
new
ArrayList
<>();
for
(
MaterialVo4Unit
materialVo4Unit:
list
)
{
materialIdList
.
add
(
materialVo4Unit
.
getId
());
}
List
<
MaterialCurrentStock
>
mcsList
=
materialCurrentStockMapperEx
.
getCurrentStockMapByIdList
(
materialIdList
);
for
(
MaterialCurrentStock
materialCurrentStock:
mcsList
)
{
map
.
put
(
materialCurrentStock
.
getMaterialId
(),
materialCurrentStock
.
getCurrentNumber
());
}
return
map
;
}
/**
/**
* 根据商品和仓库获取安全库存信息
* 根据商品和仓库获取安全库存信息
* @param materialId
* @param materialId
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/materialExtend/MaterialExtendService.java
View file @
ad9ee39c
...
@@ -347,7 +347,7 @@ public class MaterialExtendService {
...
@@ -347,7 +347,7 @@ public class MaterialExtendService {
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
Long
selectIdByMaterialIdAndDefaultFlag
(
Long
materialId
,
String
defaultFlag
)
throws
Exception
{
public
Long
selectIdByMaterialIdAndDefaultFlag
(
Long
materialId
,
String
defaultFlag
)
{
Long
id
=
0L
;
Long
id
=
0L
;
MaterialExtendExample
example
=
new
MaterialExtendExample
();
MaterialExtendExample
example
=
new
MaterialExtendExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
materialId
).
andDefaultFlagEqualTo
(
defaultFlag
)
example
.
createCriteria
().
andMaterialIdEqualTo
(
materialId
).
andDefaultFlagEqualTo
(
defaultFlag
)
...
...
jshERP-boot/src/main/java/com/jsh/erp/utils/StringUtil.java
View file @
ad9ee39c
...
@@ -8,6 +8,7 @@ import java.math.BigDecimal;
...
@@ -8,6 +8,7 @@ import java.math.BigDecimal;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.*
;
import
java.util.regex.Pattern
;
/**
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
* @author jishenghua qq752718920 2018-10-7 15:26:27
...
@@ -316,6 +317,24 @@ public class StringUtil {
...
@@ -316,6 +317,24 @@ public class StringUtil {
}
}
}
}
/**
* 判断对象是否为数字(含小数)
* @param str
* @return
*/
public
static
boolean
isPositiveBigDecimal
(
String
str
){
Pattern
pattern
=
Pattern
.
compile
(
"[0-9]*"
);
if
(
str
.
indexOf
(
"."
)>
0
){
//判断是否有小数点
if
(
str
.
indexOf
(
"."
)==
str
.
lastIndexOf
(
"."
)
&&
str
.
split
(
"\\."
).
length
==
2
){
//判断是否只有一个小数点
return
pattern
.
matcher
(
str
.
replace
(
"."
,
""
)).
matches
();
}
else
{
return
false
;
}
}
else
{
return
pattern
.
matcher
(
str
).
matches
();
}
}
/**
/**
* sql注入过滤,保障sql的安全执行
* sql注入过滤,保障sql的安全执行
* @param originStr
* @param originStr
...
...
jshERP-boot/src/main/resources/mapper_xml/MaterialCurrentStockMapperEx.xml
0 → 100644
View file @
ad9ee39c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.jsh.erp.datasource.mappers.MaterialCurrentStockMapperEx"
>
<insert
id=
"batchInsert"
parameterType=
"java.util.List"
>
insert into jsh_material_current_stock (material_id, depot_id, current_number)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.materialId,jdbcType=BIGINT}, #{item.depotId,jdbcType=BIGINT},#{item.currentNumber,jdbcType=DECIMAL})
</foreach >
</insert>
<select
id=
"getCurrentStockMapByIdList"
resultType=
"com.jsh.erp.datasource.entities.MaterialCurrentStock"
>
select material_id, sum(current_number) current_number from jsh_material_current_stock
where 1=1
and ifnull(delete_flag,'0') !='1'
and material_id in
<foreach
collection=
"materialIdList"
item=
"materialId"
index=
"index"
separator=
","
open=
"("
close=
")"
>
#{materialId}
</foreach>
group by material_id
</select>
</mapper>
\ No newline at end of file
jshERP-boot/src/main/resources/mapper_xml/MaterialInitialStockMapperEx.xml
0 → 100644
View file @
ad9ee39c
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.jsh.erp.datasource.mappers.MaterialInitialStockMapperEx"
>
<insert
id=
"batchInsert"
parameterType=
"java.util.List"
>
insert into jsh_material_initial_stock (material_id, depot_id, number)
values
<foreach
collection=
"list"
item=
"item"
separator=
","
>
(#{item.materialId,jdbcType=BIGINT}, #{item.depotId,jdbcType=BIGINT},#{item.number,jdbcType=DECIMAL})
</foreach >
</insert>
</mapper>
\ No newline at end of file
jshERP-boot/src/main/resources/mapper_xml/MaterialMapperEx.xml
View file @
ad9ee39c
...
@@ -39,21 +39,9 @@
...
@@ -39,21 +39,9 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
where 1=1
and me.default_flag=1
and me.default_flag=1
<if
test=
"barCode != null and barCode !=''"
>
<if
test=
"materialParam != null and materialParam !=''"
>
<bind
name=
"bindBarCode"
value=
"'%'+barCode+'%'"
/>
<bind
name=
"bindKey"
value=
"'%'+materialParam+'%'"
/>
and me.bar_code like #{bindBarCode}
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if
test=
"name != null and name !=''"
>
<bind
name=
"bindName"
value=
"'%'+name+'%'"
/>
and m.name like #{bindName}
</if>
<if
test=
"standard != null and standard !=''"
>
<bind
name=
"bindStandard"
value=
"'%'+standard+'%'"
/>
and m.standard like #{bindStandard}
</if>
<if
test=
"model != null and model !=''"
>
<bind
name=
"bindModel"
value=
"'%'+model+'%'"
/>
and m.model like #{bindModel}
</if>
</if>
<if
test=
"color != null and color !=''"
>
<if
test=
"color != null and color !=''"
>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
...
@@ -71,6 +59,9 @@
...
@@ -71,6 +59,9 @@
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
and m.enable_batch_number = #{enableBatchNumber}
and m.enable_batch_number = #{enableBatchNumber}
</if>
</if>
<if
test=
"enabled != null"
>
and m.enabled = #{enabled}
</if>
<if
test=
"remark != null and remark !=''"
>
<if
test=
"remark != null and remark !=''"
>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
and m.remark like #{bindRemark}
and m.remark like #{bindRemark}
...
@@ -97,21 +88,9 @@
...
@@ -97,21 +88,9 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
WHERE 1=1
WHERE 1=1
and me.default_flag=1
and me.default_flag=1
<if
test=
"barCode != null and barCode !=''"
>
<if
test=
"materialParam != null and materialParam !=''"
>
<bind
name=
"bindBarCode"
value=
"'%'+barCode+'%'"
/>
<bind
name=
"bindKey"
value=
"'%'+materialParam+'%'"
/>
and me.bar_code like #{bindBarCode}
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if
test=
"name != null and name !=''"
>
<bind
name=
"bindName"
value=
"'%'+name+'%'"
/>
and m.name like #{bindName}
</if>
<if
test=
"standard != null and standard !=''"
>
<bind
name=
"bindStandard"
value=
"'%'+standard+'%'"
/>
and m.standard like #{bindStandard}
</if>
<if
test=
"model != null and model !=''"
>
<bind
name=
"bindModel"
value=
"'%'+model+'%'"
/>
and m.model like #{bindModel}
</if>
</if>
<if
test=
"color != null and color !=''"
>
<if
test=
"color != null and color !=''"
>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
...
@@ -129,6 +108,9 @@
...
@@ -129,6 +108,9 @@
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
and m.enable_batch_number = #{enableBatchNumber}
and m.enable_batch_number = #{enableBatchNumber}
</if>
</if>
<if
test=
"enabled != null and enabled !=''"
>
and m.enabled = #{enabled}
</if>
<if
test=
"remark != null and remark !=''"
>
<if
test=
"remark != null and remark !=''"
>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
and m.remark like #{bindRemark}
and m.remark like #{bindRemark}
...
@@ -142,6 +124,140 @@
...
@@ -142,6 +124,140 @@
and ifnull(m.delete_flag,'0') !='1'
and ifnull(m.delete_flag,'0') !='1'
</select>
</select>
<insert
id=
"insertSelectiveEx"
parameterType=
"com.jsh.erp.datasource.entities.Material"
useGeneratedKeys=
"true"
keyProperty=
"id"
>
insert into jsh_material
<trim
prefix=
"("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
id,
</if>
<if
test=
"categoryId != null"
>
category_id,
</if>
<if
test=
"name != null"
>
name,
</if>
<if
test=
"mfrs != null"
>
mfrs,
</if>
<if
test=
"model != null"
>
model,
</if>
<if
test=
"standard != null"
>
standard,
</if>
<if
test=
"color != null"
>
color,
</if>
<if
test=
"unit != null"
>
unit,
</if>
<if
test=
"remark != null"
>
remark,
</if>
<if
test=
"imgName != null"
>
img_name,
</if>
<if
test=
"unitId != null"
>
unit_id,
</if>
<if
test=
"expiryNum != null"
>
expiry_num,
</if>
<if
test=
"weight != null"
>
weight,
</if>
<if
test=
"enabled != null"
>
enabled,
</if>
<if
test=
"otherField1 != null"
>
other_field1,
</if>
<if
test=
"otherField2 != null"
>
other_field2,
</if>
<if
test=
"otherField3 != null"
>
other_field3,
</if>
<if
test=
"enableSerialNumber != null"
>
enable_serial_number,
</if>
<if
test=
"enableBatchNumber != null"
>
enable_batch_number,
</if>
<if
test=
"tenantId != null"
>
tenant_id,
</if>
<if
test=
"deleteFlag != null"
>
delete_flag,
</if>
</trim>
<trim
prefix=
"values ("
suffix=
")"
suffixOverrides=
","
>
<if
test=
"id != null"
>
#{id,jdbcType=BIGINT},
</if>
<if
test=
"categoryId != null"
>
#{categoryId,jdbcType=BIGINT},
</if>
<if
test=
"name != null"
>
#{name,jdbcType=VARCHAR},
</if>
<if
test=
"mfrs != null"
>
#{mfrs,jdbcType=VARCHAR},
</if>
<if
test=
"model != null"
>
#{model,jdbcType=VARCHAR},
</if>
<if
test=
"standard != null"
>
#{standard,jdbcType=VARCHAR},
</if>
<if
test=
"color != null"
>
#{color,jdbcType=VARCHAR},
</if>
<if
test=
"unit != null"
>
#{unit,jdbcType=VARCHAR},
</if>
<if
test=
"remark != null"
>
#{remark,jdbcType=VARCHAR},
</if>
<if
test=
"imgName != null"
>
#{imgName,jdbcType=VARCHAR},
</if>
<if
test=
"unitId != null"
>
#{unitId,jdbcType=BIGINT},
</if>
<if
test=
"expiryNum != null"
>
#{expiryNum,jdbcType=INTEGER},
</if>
<if
test=
"weight != null"
>
#{weight,jdbcType=DECIMAL},
</if>
<if
test=
"enabled != null"
>
#{enabled,jdbcType=BIT},
</if>
<if
test=
"otherField1 != null"
>
#{otherField1,jdbcType=VARCHAR},
</if>
<if
test=
"otherField2 != null"
>
#{otherField2,jdbcType=VARCHAR},
</if>
<if
test=
"otherField3 != null"
>
#{otherField3,jdbcType=VARCHAR},
</if>
<if
test=
"enableSerialNumber != null"
>
#{enableSerialNumber,jdbcType=VARCHAR},
</if>
<if
test=
"enableBatchNumber != null"
>
#{enableBatchNumber,jdbcType=VARCHAR},
</if>
<if
test=
"tenantId != null"
>
#{tenantId,jdbcType=BIGINT},
</if>
<if
test=
"deleteFlag != null"
>
#{deleteFlag,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select
id=
"findUnitList"
resultType=
"com.jsh.erp.datasource.entities.Unit"
>
<select
id=
"findUnitList"
resultType=
"com.jsh.erp.datasource.entities.Unit"
>
select u.* from jsh_unit u
select u.* from jsh_unit u
left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
left join jsh_material m on m.unit_id=u.id and ifnull(m.delete_flag,'0') !='1'
...
...
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