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
Hide 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 {
//抱歉,文件扩展名必须为xls
public
static
final
int
MATERIAL_EXTENSION_ERROR_CODE
=
8000009
;
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
...
...
jshERP-boot/src/main/java/com/jsh/erp/controller/DepotController.java
View file @
ad9ee39c
...
...
@@ -179,7 +179,7 @@ public class DepotController {
DepotEx
de
=
new
DepotEx
();
if
(
mId
!=
0
)
{
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
.
setCurrentStock
(
currentStock
);
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;
public
interface
MaterialMapperEx
{
List
<
MaterialVo4Unit
>
selectByConditionMaterial
(
@Param
(
"barCode"
)
String
barCode
,
@Param
(
"name"
)
String
name
,
@Param
(
"standard"
)
String
standard
,
@Param
(
"model"
)
String
model
,
@Param
(
"materialParam"
)
String
materialParam
,
@Param
(
"color"
)
String
color
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enabled"
)
String
enabled
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"mpList"
)
String
mpList
,
...
...
@@ -35,19 +33,19 @@ public interface MaterialMapperEx {
@Param
(
"rows"
)
Integer
rows
);
Long
countsByMaterial
(
@Param
(
"barCode"
)
String
barCode
,
@Param
(
"name"
)
String
name
,
@Param
(
"standard"
)
String
standard
,
@Param
(
"model"
)
String
model
,
@Param
(
"materialParam"
)
String
materialParam
,
@Param
(
"color"
)
String
color
,
@Param
(
"weight"
)
String
weight
,
@Param
(
"expiryNum"
)
String
expiryNum
,
@Param
(
"enableSerialNumber"
)
String
enableSerialNumber
,
@Param
(
"enableBatchNumber"
)
String
enableBatchNumber
,
@Param
(
"enabled"
)
String
enabled
,
@Param
(
"remark"
)
String
remark
,
@Param
(
"idList"
)
List
<
Long
>
idList
,
@Param
(
"mpList"
)
String
mpList
);
Long
insertSelectiveEx
(
Material
record
);
List
<
Unit
>
findUnitList
(
@Param
(
"mId"
)
Long
mId
);
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 {
private
List
<?>
getMaterialList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
barCode
=
StringUtil
.
getInfo
(
search
,
"barCode"
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
standard
=
StringUtil
.
getInfo
(
search
,
"standard"
);
String
model
=
StringUtil
.
getInfo
(
search
,
"model"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enabled
=
StringUtil
.
getInfo
(
search
,
"enabled"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
return
materialService
.
select
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
categoryId
,
mpList
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
return
materialService
.
select
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
categoryId
,
mpList
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
categoryId
=
StringUtil
.
getInfo
(
search
,
"categoryId"
);
String
barCode
=
StringUtil
.
getInfo
(
search
,
"barCode"
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
standard
=
StringUtil
.
getInfo
(
search
,
"standard"
);
String
model
=
StringUtil
.
getInfo
(
search
,
"model"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
color
=
StringUtil
.
getInfo
(
search
,
"color"
);
String
weight
=
StringUtil
.
getInfo
(
search
,
"weight"
);
String
expiryNum
=
StringUtil
.
getInfo
(
search
,
"expiryNum"
);
String
enableSerialNumber
=
StringUtil
.
getInfo
(
search
,
"enableSerialNumber"
);
String
enableBatchNumber
=
StringUtil
.
getInfo
(
search
,
"enableBatchNumber"
);
String
enabled
=
StringUtil
.
getInfo
(
search
,
"enabled"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
mpList
=
StringUtil
.
getInfo
(
search
,
"mpList"
);
return
materialService
.
countMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
categoryId
,
mpList
);
return
materialService
.
countMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
categoryId
,
mpList
);
}
@Override
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/material/MaterialService.java
View file @
ad9ee39c
...
...
@@ -64,8 +64,12 @@ public class MaterialService {
@Resource
private
MaterialInitialStockMapper
materialInitialStockMapper
;
@Resource
private
MaterialInitialStockMapperEx
materialInitialStockMapperEx
;
@Resource
private
MaterialCurrentStockMapper
materialCurrentStockMapper
;
@Resource
private
MaterialCurrentStockMapperEx
materialCurrentStockMapperEx
;
@Resource
private
DepotService
depotService
;
@Resource
private
MaterialExtendService
materialExtendService
;
...
...
@@ -107,8 +111,8 @@ public class MaterialService {
return
list
;
}
public
List
<
MaterialVo4Unit
>
select
(
String
barCode
,
String
n
am
e
,
String
standard
,
String
model
,
String
color
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
public
List
<
MaterialVo4Unit
>
select
(
String
materialPar
am
,
String
color
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enabled
,
String
remark
,
String
categoryId
,
String
mpList
,
int
offset
,
int
rows
)
throws
Exception
{
String
[]
mpArr
=
new
String
[]{};
...
...
@@ -122,12 +126,13 @@ public class MaterialService {
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
}
list
=
materialMapperEx
.
selectByConditionMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
idList
,
mpList
,
offset
,
rows
);
if
(
null
!=
list
)
{
list
=
materialMapperEx
.
selectByConditionMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
idList
,
mpList
,
offset
,
rows
);
if
(
null
!=
list
&&
list
.
size
()>
0
)
{
Map
<
Long
,
BigDecimal
>
currentStockMap
=
getCurrentStockMapByMaterialList
(
list
);
for
(
MaterialVo4Unit
m
:
list
)
{
m
.
setMaterialOther
(
getMaterialOtherByParam
(
mpArr
,
m
));
m
.
setStock
(
depotItemService
.
getStockByParam
(
null
,
m
.
getId
(),
null
,
null
));
m
.
setStock
(
currentStockMap
.
get
(
m
.
getId
()
));
resList
.
add
(
m
);
}
}
...
...
@@ -137,8 +142,8 @@ public class MaterialService {
return
resList
;
}
public
Long
countMaterial
(
String
barCode
,
String
n
am
e
,
String
standard
,
String
model
,
String
color
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
public
Long
countMaterial
(
String
materialPar
am
,
String
color
,
String
weight
,
String
expiryNum
,
String
enableSerialNumber
,
String
enableBatchNumber
,
String
enabled
,
String
remark
,
String
categoryId
,
String
mpList
)
throws
Exception
{
Long
result
=
null
;
try
{
...
...
@@ -146,8 +151,8 @@ public class MaterialService {
if
(
StringUtil
.
isNotEmpty
(
categoryId
)){
idList
=
getListByParentId
(
Long
.
parseLong
(
categoryId
));
}
result
=
materialMapperEx
.
countsByMaterial
(
barCode
,
name
,
standard
,
model
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
remark
,
idList
,
mpList
);
result
=
materialMapperEx
.
countsByMaterial
(
materialParam
,
color
,
weight
,
expiryNum
,
enableSerialNumber
,
enableBatchNumber
,
enabled
,
remark
,
idList
,
mpList
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
...
...
@@ -159,15 +164,8 @@ public class MaterialService {
Material
m
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Material
.
class
);
m
.
setEnabled
(
true
);
try
{
Long
mId
=
null
;
materialMapper
.
insertSelective
(
m
);
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
();
}
materialMapperEx
.
insertSelectiveEx
(
m
);
Long
mId
=
m
.
getId
();
materialExtendService
.
saveDetials
(
obj
,
obj
.
getString
(
"sortList"
),
mId
,
"insert"
);
if
(
obj
.
get
(
"stock"
)!=
null
)
{
JSONArray
stockArr
=
obj
.
getJSONArray
(
"stock"
);
...
...
@@ -459,6 +457,7 @@ public class MaterialService {
public
BaseResponseInfo
importExcel
(
MultipartFile
file
,
HttpServletRequest
request
)
throws
Exception
{
BaseResponseInfo
info
=
new
BaseResponseInfo
();
try
{
Long
beginTime
=
System
.
currentTimeMillis
();
//文件扩展名只能为xls
String
fileName
=
file
.
getOriginalFilename
();
if
(
StringUtil
.
isNotEmpty
(
fileName
))
{
...
...
@@ -472,7 +471,14 @@ public class MaterialService {
Sheet
src
=
workbook
.
getSheet
(
0
);
List
<
Depot
>
depotList
=
depotService
.
getDepot
();
int
depotCount
=
depotList
.
size
();
Map
<
String
,
Long
>
depotMap
=
parseDepotToMap
(
depotList
);
User
user
=
userService
.
getCurrentUser
();
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
++)
{
String
name
=
ExcelUtils
.
getContent
(
src
,
i
,
0
);
//名称
String
standard
=
ExcelUtils
.
getContent
(
src
,
i
,
1
);
//规格
...
...
@@ -480,122 +486,132 @@ public class MaterialService {
String
color
=
ExcelUtils
.
getContent
(
src
,
i
,
3
);
//颜色
String
categoryName
=
ExcelUtils
.
getContent
(
src
,
i
,
4
);
//类别
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
);
//基本单位
//校验名称、单位是否为空
if
(
StringUtil
.
isNotEmpty
(
name
)
&&
StringUtil
.
isNotEmpty
(
unit
))
{
MaterialWithInitStock
m
=
new
MaterialWithInitStock
();
m
.
setName
(
name
);
m
.
setStandard
(
standard
);
m
.
setModel
(
model
);
m
.
setColor
(
color
);
Long
categoryId
=
materialCategoryService
.
getCategoryIdByName
(
categoryName
);
if
(
null
!=
categoryId
){
m
.
setCategoryId
(
categoryId
);
}
if
(
StringUtil
.
isNotEmpty
(
weight
))
{
m
.
setWeight
(
BigDecimal
.
valueOf
(
Long
.
parseLong
(
weight
)));
}
if
(
StringUtil
.
isNotEmpty
(
expiryNum
))
{
m
.
setExpiryNum
(
Integer
.
parseInt
(
expiryNum
));
}
String
manyUnit
=
ExcelUtils
.
getContent
(
src
,
i
,
8
);
//副单位
String
barCode
=
ExcelUtils
.
getContent
(
src
,
i
,
9
);
//基础条码
String
manyBarCode
=
ExcelUtils
.
getContent
(
src
,
i
,
10
);
//副条码
String
ratio
=
ExcelUtils
.
getContent
(
src
,
i
,
11
);
//比例
String
purchaseDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
12
);
//采购价
String
commodityDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
13
);
//零售价
String
wholesaleDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
14
);
//销售价
String
lowDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
15
);
//最低售价
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
16
);
//状态
String
enableSerialNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
17
);
//序列号
String
enableBatchNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
18
);
//批号
//校验基础条码是否是正整数
if
(!
StringUtil
.
isPositiveLong
(
barCode
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_MSG
,
barCode
));
}
//校验副条码是否是正整数
if
(
StringUtil
.
isNotEmpty
(
manyBarCode
)
&&
!
StringUtil
.
isPositiveLong
(
manyBarCode
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_MSG
,
manyBarCode
));
//名称为空
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
();
m
.
setName
(
name
);
m
.
setStandard
(
standard
);
m
.
setModel
(
model
);
m
.
setColor
(
color
);
Long
categoryId
=
materialCategoryService
.
getCategoryIdByName
(
categoryName
);
if
(
null
!=
categoryId
){
m
.
setCategoryId
(
categoryId
);
}
if
(
StringUtil
.
isNotEmpty
(
weight
))
{
//校验基础重量是否是数字(含小数)
if
(!
StringUtil
.
isPositiveBigDecimal
(
weight
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_WEIGHT_NOT_DECIMAL_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_WEIGHT_NOT_DECIMAL_MSG
,
i
+
1
));
}
JSONObject
materialExObj
=
new
JSONObject
();
JSONObject
basicObj
=
new
JSONObject
();
basicObj
.
put
(
"barCode"
,
barCode
);
basicObj
.
put
(
"commodityUnit"
,
unit
);
basicObj
.
put
(
"purchaseDecimal"
,
purchaseDecimal
);
basicObj
.
put
(
"commodityDecimal"
,
commodityDecimal
);
basicObj
.
put
(
"wholesaleDecimal"
,
wholesaleDecimal
);
basicObj
.
put
(
"lowDecimal"
,
lowDecimal
);
materialExObj
.
put
(
"basic"
,
basicObj
);
if
(
StringUtil
.
isNotEmpty
(
manyUnit
)
&&
StringUtil
.
isNotEmpty
(
ratio
)){
//多单位
Long
unitId
=
unitService
.
getUnitIdByParam
(
unit
,
manyUnit
,
Integer
.
parseInt
(
ratio
.
trim
()));
if
(
unitId
!=
null
)
{
m
.
setUnitId
(
unitId
);
}
else
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_UNIT_MATE_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_UNIT_MATE_MSG
,
manyBarCode
));
}
JSONObject
otherObj
=
new
JSONObject
();
otherObj
.
put
(
"barCode"
,
manyBarCode
);
otherObj
.
put
(
"commodityUnit"
,
manyUnit
);
otherObj
.
put
(
"purchaseDecimal"
,
parsePrice
(
purchaseDecimal
,
ratio
));
otherObj
.
put
(
"commodityDecimal"
,
parsePrice
(
commodityDecimal
,
ratio
));
otherObj
.
put
(
"wholesaleDecimal"
,
parsePrice
(
wholesaleDecimal
,
ratio
));
otherObj
.
put
(
"lowDecimal"
,
parsePrice
(
lowDecimal
,
ratio
));
materialExObj
.
put
(
"other"
,
otherObj
);
}
else
{
m
.
setUnit
(
unit
);
m
.
setWeight
(
new
BigDecimal
(
weight
));
}
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
.
setMaterialExObj
(
materialExObj
);
m
.
setEnabled
(
"1"
.
equals
(
enabled
));
if
(
StringUtil
.
isNotEmpty
(
enableSerialNumber
)
&&
"1"
.
equals
(
enableSerialNumber
))
{
m
.
setEnableSerialNumber
(
"1"
);
}
else
{
m
.
setEnableSerialNumber
(
"0"
);
m
.
setExpiryNum
(
Integer
.
parseInt
(
expiryNum
));
}
String
manyUnit
=
ExcelUtils
.
getContent
(
src
,
i
,
8
);
//副单位
String
barCode
=
ExcelUtils
.
getContent
(
src
,
i
,
9
);
//基础条码
String
manyBarCode
=
ExcelUtils
.
getContent
(
src
,
i
,
10
);
//副条码
String
ratio
=
ExcelUtils
.
getContent
(
src
,
i
,
11
);
//比例
String
purchaseDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
12
);
//采购价
String
commodityDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
13
);
//零售价
String
wholesaleDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
14
);
//销售价
String
lowDecimal
=
ExcelUtils
.
getContent
(
src
,
i
,
15
);
//最低售价
String
enabled
=
ExcelUtils
.
getContent
(
src
,
i
,
16
);
//状态
String
enableSerialNumber
=
ExcelUtils
.
getContent
(
src
,
i
,
17
);
//序列号
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
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_MSG
,
barCode
));
}
//校验副条码是否是正整数
if
(
StringUtil
.
isNotEmpty
(
manyBarCode
)
&&
!
StringUtil
.
isPositiveLong
(
manyBarCode
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_BARCODE_NOT_INTEGER_MSG
,
manyBarCode
));
}
JSONObject
materialExObj
=
new
JSONObject
();
JSONObject
basicObj
=
new
JSONObject
();
basicObj
.
put
(
"barCode"
,
barCode
);
basicObj
.
put
(
"commodityUnit"
,
unit
);
basicObj
.
put
(
"purchaseDecimal"
,
purchaseDecimal
);
basicObj
.
put
(
"commodityDecimal"
,
commodityDecimal
);
basicObj
.
put
(
"wholesaleDecimal"
,
wholesaleDecimal
);
basicObj
.
put
(
"lowDecimal"
,
lowDecimal
);
materialExObj
.
put
(
"basic"
,
basicObj
);
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
));
}
if
(
StringUtil
.
isNotEmpty
(
enableBatchNumber
)
&&
"1"
.
equals
(
enableBatchNumber
))
{
m
.
setEnableBatchNumber
(
"1"
);
Long
unitId
=
unitService
.
getUnitIdByParam
(
unit
,
manyUnit
,
Integer
.
parseInt
(
ratio
.
trim
()));
if
(
unitId
!=
null
)
{
m
.
setUnitId
(
unitId
);
}
else
{
m
.
setEnableBatchNumber
(
"0"
);
}
if
(
"1"
.
equals
(
enableSerialNumber
)
&&
"1"
.
equals
(
enableBatchNumber
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_MSG
,
barCode
));
}
//缓存各个仓库的库存信息
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
));
}
}
}
}
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_UNIT_MATE_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_UNIT_MATE_MSG
,
manyBarCode
));
}
m
.
setStockMap
(
stockMap
);
mList
.
add
(
m
);
JSONObject
otherObj
=
new
JSONObject
();
otherObj
.
put
(
"barCode"
,
manyBarCode
);
otherObj
.
put
(
"commodityUnit"
,
manyUnit
);
otherObj
.
put
(
"purchaseDecimal"
,
parsePrice
(
purchaseDecimal
,
ratio
));
otherObj
.
put
(
"commodityDecimal"
,
parsePrice
(
commodityDecimal
,
ratio
));
otherObj
.
put
(
"wholesaleDecimal"
,
parsePrice
(
wholesaleDecimal
,
ratio
));
otherObj
.
put
(
"lowDecimal"
,
parsePrice
(
lowDecimal
,
ratio
));
materialExObj
.
put
(
"other"
,
otherObj
);
}
else
{
m
.
setUnit
(
unit
);
}
m
.
setMaterialExObj
(
materialExObj
);
m
.
setEnabled
(
"1"
.
equals
(
enabled
));
if
(
StringUtil
.
isNotEmpty
(
enableSerialNumber
)
&&
"1"
.
equals
(
enableSerialNumber
))
{
m
.
setEnableSerialNumber
(
"1"
);
}
else
{
m
.
setEnableSerialNumber
(
"0"
);
}
if
(
StringUtil
.
isNotEmpty
(
enableBatchNumber
)
&&
"1"
.
equals
(
enableBatchNumber
))
{
m
.
setEnableBatchNumber
(
"1"
);
}
else
{
m
.
setEnableBatchNumber
(
"0"
);
}
if
(
"1"
.
equals
(
enableSerialNumber
)
&&
"1"
.
equals
(
enableBatchNumber
))
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_ENABLE_MUST_ONE_MSG
,
barCode
));
}
m
.
setStockMap
(
getStockMapCache
(
src
,
depotCount
,
depotMap
,
i
));
mList
.
add
(
m
);
}
Long
mId
=
0L
;
List
<
Long
>
deleteStockMaterialIdList
=
new
ArrayList
<>();
List
<
MaterialCurrentStock
>
insertCurrentStockMaterialList
=
new
ArrayList
<>();
List
<
MaterialInitialStock
>
insertInitialStockMaterialList
=
new
ArrayList
<>();
for
(
MaterialWithInitStock
m:
mList
)
{
Long
mId
=
0L
;
//判断该商品是否存在,如果不存在就新增,如果存在就更新
String
basicBarCode
=
getBasicBarCode
(
m
);
List
<
Material
>
materials
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getStandard
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
if
(
materials
.
size
()<=
0
)
{
materialMapper
.
insertSelective
(
m
);
List
<
Material
>
newList
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getStandard
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
if
(
newList
.
size
()>
0
)
{
mId
=
newList
.
get
(
0
).
getId
();
}
List
<
Material
>
materials
=
getMaterialListByParam
(
m
.
getName
(),
m
.
getStandard
(),
m
.
getModel
(),
m
.
getColor
(),
m
.
getUnit
(),
m
.
getUnitId
(),
basicBarCode
);
if
(
materials
.
size
()
==
0
)
{
materialMapperEx
.
insertSelectiveEx
(
m
);
mId
=
m
.
getId
();
}
else
{
mId
=
materials
.
get
(
0
).
getId
();
String
materialJson
=
JSON
.
toJSONString
(
m
);
...
...
@@ -603,54 +619,49 @@ public class MaterialService {
material
.
setId
(
mId
);
materialMapper
.
updateByPrimaryKeySelective
(
material
);
}
//给商品新增条码与价格相关信息
User
user
=
userService
.
getCurrentUser
();
//给商品新增或更新条码与价格相关信息
JSONObject
materialExObj
=
m
.
getMaterialExObj
();
if
(
StringUtil
.
isExist
(
materialExObj
.
get
(
"basic"
))){
String
basicStr
=
materialExObj
.
getString
(
"basic"
);
MaterialExtend
basicMaterialExtend
=
JSONObject
.
parseObject
(
basicStr
,
MaterialExtend
.
class
);
basicMaterialExtend
.
setMaterialId
(
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
insertOrUpdateMaterialExtend
(
materialExObj
,
"basic"
,
"1"
,
mId
,
user
);
insertOrUpdateMaterialExtend
(
materialExObj
,
"other"
,
"0"
,
mId
,
user
);
//给商品更新库存
deleteStockMaterialIdList
.
add
(
mId
);
Map
<
Long
,
BigDecimal
>
stockMap
=
m
.
getStockMap
();
Long
depotId
=
null
;
for
(
Depot
depot:
depotList
){
depotId
=
depot
.
getId
();
Long
depotId
=
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
);
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
(
"商品"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_IMPORT
).
append
(
mList
.
size
()).
append
(
BusinessConstants
.
LOG_DATA_UNIT
).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
Long
endTime
=
System
.
currentTimeMillis
();
logger
.
info
(
"导入耗时:{}"
,
endTime
-
beginTime
);
info
.
code
=
200
;
info
.
data
=
"导入成功"
;
}
catch
(
BusinessRunTimeException
e
)
{
...
...
@@ -664,25 +675,69 @@ public class MaterialService {
return
info
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
changeMaterialExtend
(
Long
mId
,
MaterialExtend
materialExtend
,
Long
meId
)
{
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
()));
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
));
}
}
}
}
materialExtendMapper
.
insertSelective
(
materialExtend
);
}
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
()));
}
return
stockMap
;
}
/**
* 给商品新增或更新条码与价格相关信息
* @param materialExObj
* @param type
* @param defaultFlag
* @param mId
* @param user
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
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
){
materialExtendMapper
.
insertSelective
(
materialExtend
);
}
else
{
materialExtend
.
setId
(
meId
);
materialExtendMapper
.
updateByPrimaryKeySelective
(
materialExtend
);
}
materialExtend
.
setId
(
meId
);
materialExtendMapper
.
updateByPrimaryKeySelective
(
materialExtend
);
}
}
...
...
@@ -700,14 +755,14 @@ public class MaterialService {
/**
* 根据条件返回产品列表
* @param name
* @param standard
* @param model
* @param color
* @param standard
* @param unit
* @param unitId
* @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
<>();
MaterialExample
example
=
new
MaterialExample
();
MaterialExample
.
Criteria
criteria
=
example
.
createCriteria
();
...
...
@@ -730,10 +785,11 @@ public class MaterialService {
criteria
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
list
=
materialMapper
.
selectByExample
(
example
);
if
(
list
.
size
()==
0
)
{
//如果通过组合条件没有查到
改
商品,则通过条码再查一次
//如果通过组合条件没有查到
该
商品,则通过条码再查一次
MaterialExtend
materialExtend
=
materialExtendService
.
getInfoByBarCode
(
basicBarCode
);
if
(
materialExtend
!=
null
&&
materialExtend
.
getMaterialId
()!=
null
)
{
Material
material
=
getMaterial
(
materialExtend
.
getMaterialId
());
Material
material
=
new
Material
();
material
.
setId
(
materialExtend
.
getMaterialId
());
list
.
add
(
material
);
}
}
...
...
@@ -762,19 +818,6 @@ public class MaterialService {
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
...
...
@@ -791,22 +834,25 @@ public class MaterialService {
}
/**
* 新增或更新当前库存
* @param depotId
* @param mId
* @param stock
* 批量删除初始库存
* @param mIdList
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
insertOrUpdateCurrentStockByMaterialAndDepot
(
Long
depotId
,
Long
mId
,
BigDecimal
stock
){
Long
billCount
=
depotItemService
.
getCountByMaterialAndDepot
(
mId
,
depotId
);
if
(
billCount
==
0
)
{
deleteCurrentStockByMaterialAndDepot
(
depotId
,
mId
);
if
(
stock
!=
null
&&
stock
.
compareTo
(
BigDecimal
.
ZERO
)!=
0
)
{
insertCurrentStockByMaterialAndDepot
(
depotId
,
mId
,
stock
);
}
}
else
{
depotItemService
.
updateCurrentStockFun
(
mId
,
depotId
);
}
public
void
batchDeleteInitialStockByMaterialList
(
List
<
Long
>
mIdList
){
MaterialInitialStockExample
example
=
new
MaterialInitialStockExample
();
example
.
createCriteria
().
andMaterialIdIn
(
mIdList
);
materialInitialStockMapper
.
deleteByExample
(
example
);
}
/**
* 批量删除当前库存
* @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
{
...
...
@@ -898,7 +944,7 @@ public class MaterialService {
* @param depotId
* @return
*/
public
BigDecimal
getCurrentStock
(
Long
materialId
,
Long
depotId
)
{
public
BigDecimal
getCurrentStock
ByMaterialIdAndDepotId
(
Long
materialId
,
Long
depotId
)
{
BigDecimal
stock
=
BigDecimal
.
ZERO
;
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
materialId
).
andDepotIdEqualTo
(
depotId
)
...
...
@@ -912,6 +958,24 @@ public class MaterialService {
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
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/materialExtend/MaterialExtendService.java
View file @
ad9ee39c
...
...
@@ -347,7 +347,7 @@ public class MaterialExtendService {
}
@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
;
MaterialExtendExample
example
=
new
MaterialExtendExample
();
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;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
import
java.util.regex.Pattern
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
...
...
@@ -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的安全执行
* @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 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
where 1=1
and me.default_flag=1
<if
test=
"barCode != null and barCode !=''"
>
<bind
name=
"bindBarCode"
value=
"'%'+barCode+'%'"
/>
and me.bar_code like #{bindBarCode}
</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
test=
"materialParam != null and materialParam !=''"
>
<bind
name=
"bindKey"
value=
"'%'+materialParam+'%'"
/>
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if
test=
"color != null and color !=''"
>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
...
...
@@ -71,6 +59,9 @@
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
and m.enable_batch_number = #{enableBatchNumber}
</if>
<if
test=
"enabled != null"
>
and m.enabled = #{enabled}
</if>
<if
test=
"remark != null and remark !=''"
>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
and m.remark like #{bindRemark}
...
...
@@ -97,21 +88,9 @@
left JOIN jsh_material_category mc on m.category_id = mc.id and ifnull(mc.delete_Flag,'0') !='1'
WHERE 1=1
and me.default_flag=1
<if
test=
"barCode != null and barCode !=''"
>
<bind
name=
"bindBarCode"
value=
"'%'+barCode+'%'"
/>
and me.bar_code like #{bindBarCode}
</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
test=
"materialParam != null and materialParam !=''"
>
<bind
name=
"bindKey"
value=
"'%'+materialParam+'%'"
/>
and (me.bar_code like #{bindKey} or m.name like #{bindKey} or m.standard like #{bindKey} or m.model like #{bindKey})
</if>
<if
test=
"color != null and color !=''"
>
<bind
name=
"bindColor"
value=
"'%'+color+'%'"
/>
...
...
@@ -129,6 +108,9 @@
<if
test=
"enableBatchNumber != null and enableBatchNumber !=''"
>
and m.enable_batch_number = #{enableBatchNumber}
</if>
<if
test=
"enabled != null and enabled !=''"
>
and m.enabled = #{enabled}
</if>
<if
test=
"remark != null and remark !=''"
>
<bind
name=
"bindRemark"
value=
"'%'+remark+'%'"
/>
and m.remark like #{bindRemark}
...
...
@@ -142,6 +124,140 @@
and ifnull(m.delete_flag,'0') !='1'
</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 u.* from jsh_unit u
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