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
dc6cc14d
Commit
dc6cc14d
authored
May 07, 2022
by
神话
Browse files
解决分批出入库状态切换的bug
parent
cf55cba2
Changes
5
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/controller/DepotItemController.java
View file @
dc6cc14d
...
...
@@ -212,7 +212,7 @@ public class DepotItemController {
item
.
put
(
"operNumber"
,
diEx
.
getOperNumber
());
item
.
put
(
"basicNumber"
,
diEx
.
getBasicNumber
());
item
.
put
(
"preNumber"
,
diEx
.
getOperNumber
());
//原数量
item
.
put
(
"finishNumber"
,
depotItemService
.
getFinishNumber
(
diEx
.
getMaterialId
(),
diEx
.
getHeaderId
(),
unitInfo
,
materialUnit
));
//已入库|已出库
item
.
put
(
"finishNumber"
,
depotItemService
.
getFinishNumber
(
diEx
.
getMaterial
Extend
Id
(),
diEx
.
getHeaderId
(),
unitInfo
,
materialUnit
));
//已入库|已出库
item
.
put
(
"unitPrice"
,
diEx
.
getUnitPrice
());
item
.
put
(
"taxUnitPrice"
,
diEx
.
getTaxUnitPrice
());
item
.
put
(
"allPrice"
,
diEx
.
getAllPrice
());
...
...
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotItemMapperEx.java
View file @
dc6cc14d
...
...
@@ -140,8 +140,14 @@ public interface DepotItemMapperEx {
@Param
(
"depotList"
)
List
<
Long
>
depotList
);
BigDecimal
getFinishNumber
(
@Param
(
"mId"
)
Long
mId
,
@Param
(
"meId"
)
Long
meId
,
@Param
(
"linkNumber"
)
String
linkNumber
,
@Param
(
"goToType"
)
String
goToType
);
BigDecimal
getRealFinishNumber
(
@Param
(
"meId"
)
Long
meId
,
@Param
(
"linkNumber"
)
String
linkNumber
,
@Param
(
"currentHeaderId"
)
Long
currentHeaderId
,
@Param
(
"goToType"
)
String
goToType
);
List
<
DepotItemVoBatchNumberList
>
getBatchNumberList
(
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java
View file @
dc6cc14d
...
...
@@ -311,8 +311,14 @@ public class DepotHeadService {
BusinessConstants
.
SUB_TYPE_SALES
.
equals
(
depotHead
.
getSubType
()))
||
(
BusinessConstants
.
DEPOTHEAD_TYPE_OTHER
.
equals
(
depotHead
.
getType
())
&&
BusinessConstants
.
SUB_TYPE_REPLAY
.
equals
(
depotHead
.
getSubType
())))
{
String
status
=
BusinessConstants
.
BILLS_STATUS_AUDIT
;
//查询除当前单据之外的关联单据列表
List
<
DepotHead
>
exceptCurrentList
=
getListByLinkNumberExceptCurrent
(
depotHead
.
getLinkNumber
(),
depotHead
.
getNumber
());
if
(
exceptCurrentList
!=
null
&&
exceptCurrentList
.
size
()>
0
)
{
status
=
BusinessConstants
.
BILLS_STATUS_SKIPING
;
}
DepotHead
dh
=
new
DepotHead
();
dh
.
setStatus
(
BusinessConstants
.
BILLS_STATUS_AUDIT
);
dh
.
setStatus
(
status
);
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andNumberEqualTo
(
depotHead
.
getLinkNumber
());
depotHeadMapper
.
updateByExampleSelective
(
dh
,
example
);
...
...
@@ -661,6 +667,20 @@ public class DepotHeadService {
return
resList
;
}
/**
* 查询除当前单据之外的关联单据列表
* @param linkNumber
* @param number
* @return
* @throws Exception
*/
public
List
<
DepotHead
>
getListByLinkNumberExceptCurrent
(
String
linkNumber
,
String
number
)
throws
Exception
{
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andLinkNumberEqualTo
(
linkNumber
).
andNumberNotEqualTo
(
number
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
return
depotHeadMapper
.
selectByExample
(
example
);
}
/**
* 新增单据主表及单据子表信息
* @param beanJson
...
...
@@ -726,7 +746,7 @@ public class DepotHeadService {
if
(
list
!=
null
)
{
Long
headId
=
list
.
get
(
0
).
getId
();
/**入库和出库处理单据子表信息*/
depotItemService
.
saveDetials
(
rows
,
headId
,
request
);
depotItemService
.
saveDetials
(
rows
,
headId
,
"add"
,
request
);
}
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
depotHead
.
getNumber
()).
toString
(),
...
...
@@ -787,7 +807,7 @@ public class DepotHeadService {
}
}
/**入库和出库处理单据子表信息*/
depotItemService
.
saveDetials
(
rows
,
depotHead
.
getId
(),
request
);
depotItemService
.
saveDetials
(
rows
,
depotHead
.
getId
(),
"update"
,
request
);
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
depotHead
.
getNumber
()).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java
View file @
dc6cc14d
...
...
@@ -11,6 +11,7 @@ import com.jsh.erp.datasource.vo.DepotItemVo4Stock;
import
com.jsh.erp.datasource.vo.DepotItemVoBatchNumberList
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.depotHead.DepotHeadService
;
import
com.jsh.erp.service.materialExtend.MaterialExtendService
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.material.MaterialService
;
...
...
@@ -48,11 +49,13 @@ public class DepotItemService {
@Resource
private
MaterialExtendService
materialExtendService
;
@Resource
SerialNumberMapperEx
serialNumberMapperEx
;
private
SerialNumberMapperEx
serialNumberMapperEx
;
@Resource
private
DepotHeadService
depotHeadService
;
@Resource
private
DepotHeadMapper
depotHeadMapper
;
@Resource
SerialNumberService
serialNumberService
;
private
SerialNumberService
serialNumberService
;
@Resource
private
UserService
userService
;
@Resource
...
...
@@ -221,7 +224,7 @@ public class DepotItemService {
List
<
DepotItem
>
list
=
null
;
try
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
);
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
)
;
list
=
depotItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
...
...
@@ -229,6 +232,51 @@ public class DepotItemService {
return
list
;
}
/**
* 查询当前单据中指定商品的明细信息
* @param headerId
* @param meId
* @return
* @throws Exception
*/
public
DepotItem
getItemByHeaderIdAndMaterial
(
Long
headerId
,
Long
meId
)
throws
Exception
{
DepotItem
depotItem
=
new
DepotItem
();
try
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
).
andMaterialExtendIdEqualTo
(
meId
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotItem
>
list
=
depotItemMapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
depotItem
=
list
.
get
(
0
);
}
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
depotItem
;
}
/**
* 查询被关联订单中指定商品的明细信息
* @param linkNumber
* @param meId
* @return
* @throws Exception
*/
public
DepotItem
getPreItemByHeaderIdAndMaterial
(
String
linkNumber
,
Long
meId
)
throws
Exception
{
DepotItem
depotItem
=
new
DepotItem
();
try
{
DepotHead
depotHead
=
depotHeadService
.
getDepotHead
(
linkNumber
);
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
depotHead
.
getId
()).
andMaterialExtendIdEqualTo
(
meId
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotItem
>
list
=
depotItemMapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
depotItem
=
list
.
get
(
0
);
}
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
depotItem
;
}
public
List
<
DepotItemVo4WithInfoEx
>
getDetailList
(
Long
headerId
)
throws
Exception
{
List
<
DepotItemVo4WithInfoEx
>
list
=
null
;
try
{
...
...
@@ -336,7 +384,7 @@ public class DepotItemService {
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
saveDetials
(
String
rows
,
Long
headerId
,
HttpServletRequest
request
)
throws
Exception
{
public
void
saveDetials
(
String
rows
,
Long
headerId
,
String
actionType
,
HttpServletRequest
request
)
throws
Exception
{
//查询单据主表信息
DepotHead
depotHead
=
depotHeadMapper
.
selectByPrimaryKey
(
headerId
);
//获得当前操作人
...
...
@@ -391,12 +439,12 @@ public class DepotItemService {
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"sku"
)))
{
depotItem
.
setSku
(
rowObj
.
getString
(
"sku"
));
}
//以下进行单位换算
Unit
unitInfo
=
materialService
.
findUnit
(
materialExtend
.
getMaterialId
());
//查询计量单位信息
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"operNumber"
)))
{
depotItem
.
setOperNumber
(
rowObj
.
getBigDecimal
(
"operNumber"
));
String
unit
=
rowObj
.
get
(
"unit"
).
toString
();
BigDecimal
oNumber
=
rowObj
.
getBigDecimal
(
"operNumber"
);
//以下进行单位换算
Unit
unitInfo
=
materialService
.
findUnit
(
materialExtend
.
getMaterialId
());
//查询计量单位信息
if
(
StringUtil
.
isNotEmpty
(
unitInfo
.
getName
()))
{
String
basicUnit
=
unitInfo
.
getBasicUnit
();
//基本单位
if
(
unit
.
equals
(
basicUnit
))
{
//如果等于基本单位
...
...
@@ -415,13 +463,30 @@ public class DepotItemService {
//如果数量+已完成数量<原订单数量,代表该单据状态为未全部完成出入库(判断前提是存在关联订单)
if
(
StringUtil
.
isNotEmpty
(
depotHead
.
getLinkNumber
())
&&
StringUtil
.
isExist
(
rowObj
.
get
(
"preNumber"
))
&&
StringUtil
.
isExist
(
rowObj
.
get
(
"finishNumber"
)))
{
BigDecimal
preNumber
=
rowObj
.
getBigDecimal
(
"preNumber"
);
BigDecimal
finishNumber
=
rowObj
.
getBigDecimal
(
"finishNumber"
);
if
(
depotItem
.
getOperNumber
().
add
(
finishNumber
).
compareTo
(
preNumber
)<
0
)
{
billStatus
=
BusinessConstants
.
BILLS_STATUS_SKIPING
;
}
else
if
(
depotItem
.
getOperNumber
().
add
(
finishNumber
).
compareTo
(
preNumber
)>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE
,
String
.
format
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG
,
barCode
));
if
(
"add"
.
equals
(
actionType
))
{
//在新增模式进行状态赋值
BigDecimal
preNumber
=
rowObj
.
getBigDecimal
(
"preNumber"
);
BigDecimal
finishNumber
=
rowObj
.
getBigDecimal
(
"finishNumber"
);
if
(
depotItem
.
getOperNumber
().
add
(
finishNumber
).
compareTo
(
preNumber
)<
0
)
{
billStatus
=
BusinessConstants
.
BILLS_STATUS_SKIPING
;
}
else
if
(
depotItem
.
getOperNumber
().
add
(
finishNumber
).
compareTo
(
preNumber
)>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE
,
String
.
format
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG
,
barCode
));
}
}
else
if
(
"update"
.
equals
(
actionType
))
{
//在更新模式进行状态赋值
String
unit
=
rowObj
.
get
(
"unit"
).
toString
();
Long
preHeaderId
=
depotHeadService
.
getDepotHead
(
depotHead
.
getLinkNumber
()).
getId
();
//前一个单据的数量
BigDecimal
preNumber
=
getPreItemByHeaderIdAndMaterial
(
depotHead
.
getLinkNumber
(),
depotItem
.
getMaterialExtendId
()).
getOperNumber
();
//除去此单据之外的已入库|已出库
BigDecimal
realFinishNumber
=
getRealFinishNumber
(
depotItem
.
getMaterialExtendId
(),
preHeaderId
,
headerId
,
unitInfo
,
unit
);
if
(
depotItem
.
getOperNumber
().
add
(
realFinishNumber
).
compareTo
(
preNumber
)<
0
)
{
billStatus
=
BusinessConstants
.
BILLS_STATUS_SKIPING
;
}
else
if
(
depotItem
.
getOperNumber
().
add
(
realFinishNumber
).
compareTo
(
preNumber
)>
0
)
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_CODE
,
String
.
format
(
ExceptionConstants
.
DEPOT_HEAD_NUMBER_NEED_EDIT_FAILED_MSG
,
barCode
));
}
}
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"unitPrice"
)))
{
...
...
@@ -719,7 +784,7 @@ public class DepotItemService {
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
BigDecimal
getFinishNumber
(
Long
mId
,
Long
headerId
,
Unit
unitInfo
,
String
materialUnit
)
{
public
BigDecimal
getFinishNumber
(
Long
m
e
Id
,
Long
headerId
,
Unit
unitInfo
,
String
materialUnit
)
{
String
goToType
=
""
;
DepotHead
depotHead
=
depotHeadMapper
.
selectByPrimaryKey
(
headerId
);
String
linkNumber
=
depotHead
.
getNumber
();
//订单号
...
...
@@ -729,7 +794,41 @@ public class DepotItemService {
if
(
BusinessConstants
.
SUB_TYPE_SALES_ORDER
.
equals
(
depotHead
.
getSubType
()))
{
goToType
=
BusinessConstants
.
SUB_TYPE_SALES
;
}
BigDecimal
count
=
depotItemMapperEx
.
getFinishNumber
(
mId
,
linkNumber
,
goToType
);
BigDecimal
count
=
depotItemMapperEx
.
getFinishNumber
(
meId
,
linkNumber
,
goToType
);
//根据多单位情况进行数量的转换
if
(
materialUnit
.
equals
(
unitInfo
.
getOtherUnit
())
&&
unitInfo
.
getRatio
()
!=
0
)
{
count
=
count
.
divide
(
BigDecimal
.
valueOf
(
unitInfo
.
getRatio
()),
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
if
(
materialUnit
.
equals
(
unitInfo
.
getOtherUnitTwo
())
&&
unitInfo
.
getRatioTwo
()
!=
0
)
{
count
=
count
.
divide
(
BigDecimal
.
valueOf
(
unitInfo
.
getRatioTwo
()),
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
if
(
materialUnit
.
equals
(
unitInfo
.
getOtherUnitThree
())
&&
unitInfo
.
getRatioThree
()
!=
0
)
{
count
=
count
.
divide
(
BigDecimal
.
valueOf
(
unitInfo
.
getRatioThree
()),
2
,
BigDecimal
.
ROUND_HALF_UP
);
}
return
count
;
}
/**
* 除去此单据之外的已入库|已出库
* @param meId
* @param preHeaderId
* @param currentHeaderId
* @param unitInfo
* @param materialUnit
* @return
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
BigDecimal
getRealFinishNumber
(
Long
meId
,
Long
preHeaderId
,
Long
currentHeaderId
,
Unit
unitInfo
,
String
materialUnit
)
{
String
goToType
=
""
;
DepotHead
depotHead
=
depotHeadMapper
.
selectByPrimaryKey
(
preHeaderId
);
String
linkNumber
=
depotHead
.
getNumber
();
//订单号
if
(
BusinessConstants
.
SUB_TYPE_PURCHASE_ORDER
.
equals
(
depotHead
.
getSubType
()))
{
goToType
=
BusinessConstants
.
SUB_TYPE_PURCHASE
;
}
if
(
BusinessConstants
.
SUB_TYPE_SALES_ORDER
.
equals
(
depotHead
.
getSubType
()))
{
goToType
=
BusinessConstants
.
SUB_TYPE_SALES
;
}
BigDecimal
count
=
depotItemMapperEx
.
getRealFinishNumber
(
meId
,
linkNumber
,
currentHeaderId
,
goToType
);
//根据多单位情况进行数量的转换
if
(
materialUnit
.
equals
(
unitInfo
.
getOtherUnit
())
&&
unitInfo
.
getRatio
()
!=
0
)
{
count
=
count
.
divide
(
BigDecimal
.
valueOf
(
unitInfo
.
getRatio
()),
2
,
BigDecimal
.
ROUND_HALF_UP
);
...
...
jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml
View file @
dc6cc14d
...
...
@@ -550,7 +550,7 @@
<select
id=
"getFinishNumber"
resultType=
"java.math.BigDecimal"
>
select ifnull(sum(di.basic_number),0) from jsh_depot_item di
where di.material_id=#{mId}
where di.material_
extend_
id=#{m
e
Id}
and ifnull(di.delete_flag,'0') !='1'
and di.header_id
in
...
...
@@ -559,7 +559,25 @@
where
dh.link_number=#{linkNumber}
and ifnull(dh.delete_flag,'0') !='1'
<if
test=
"goToType != null"
>
<if
test=
"goToType != null and goToType !=''"
>
and dh.sub_type=#{goToType}
</if>
)
</select>
<select
id=
"getRealFinishNumber"
resultType=
"java.math.BigDecimal"
>
select ifnull(sum(di.basic_number),0) from jsh_depot_item di
where di.material_extend_id=#{meId}
and ifnull(di.delete_flag,'0') !='1'
and di.header_id
in
(
select dh.id from jsh_depot_head dh
where
dh.link_number=#{linkNumber}
and dh.id!=#{currentHeaderId}
and ifnull(dh.delete_flag,'0') !='1'
<if
test=
"goToType != null and goToType !=''"
>
and dh.sub_type=#{goToType}
</if>
)
...
...
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