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
43111edc
Commit
43111edc
authored
Nov 23, 2022
by
季圣华
Browse files
优化单据的额查询列表的逻辑,提高查询速度(继续优化)
parent
95ead95c
Changes
9
Hide whitespace changes
Inline
Side-by-side
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java
View file @
43111edc
...
...
@@ -3,6 +3,7 @@ package com.jsh.erp.datasource.mappers;
import
com.jsh.erp.datasource.entities.AccountHead
;
import
com.jsh.erp.datasource.entities.AccountHeadExample
;
import
com.jsh.erp.datasource.entities.AccountHeadVo4ListEx
;
import
com.jsh.erp.datasource.entities.AccountItem
;
import
org.apache.ibatis.annotations.Param
;
import
java.math.BigDecimal
;
...
...
@@ -58,6 +59,9 @@ public interface AccountHeadMapperEx {
List
<
AccountHead
>
getAccountHeadListByHandsPersonIds
(
@Param
(
"handsPersonIds"
)
String
[]
handsPersonIds
);
List
<
AccountItem
>
getFinancialBillNoByBillIdList
(
@Param
(
"idList"
)
List
<
Long
>
idList
);
List
<
AccountHead
>
getFinancialBillNoByBillId
(
@Param
(
"billId"
)
Long
billId
);
}
\ No newline at end of file
jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java
View file @
43111edc
...
...
@@ -57,11 +57,11 @@ public interface DepotHeadMapperEx {
@Param
(
"accountId"
)
Long
accountId
,
@Param
(
"remark"
)
String
remark
);
String
findMaterialsListByHeaderId
(
@Param
(
"id
"
)
Long
id
);
List
<
MaterialsListVo
>
findMaterialsList
Map
ByHeaderId
List
(
@Param
(
"id
List"
)
List
<
Long
>
id
List
);
BigDecimal
getMaterialCountByHeaderId
(
@Param
(
"id
"
)
Long
id
);
List
<
MaterialCountVo
>
getMaterialCount
List
ByHeaderId
List
(
@Param
(
"id
List"
)
List
<
Long
>
id
List
);
List
<
DepotHeadVo4InDetail
>
findInOutDetail
(
@Param
(
"beginTime"
)
String
beginTime
,
...
...
jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/FinishDepositVo.java
View file @
43111edc
package
com.jsh.erp.datasource.vo
;
import
java.math.BigDecimal
;
public
class
FinishDepositVo
{
private
String
number
;
private
BigDecimal
finishDeposit
;
public
String
getNumber
()
{
return
number
;
}
public
void
setNumber
(
String
number
)
{
this
.
number
=
number
;
}
public
BigDecimal
getFinishDeposit
()
{
return
finishDeposit
;
}
public
void
setFinishDeposit
(
BigDecimal
finishDeposit
)
{
this
.
finishDeposit
=
finishDeposit
;
}
}
package
com.jsh.erp.datasource.vo
;
import
java.math.BigDecimal
;
public
class
FinishDepositVo
{
private
String
number
;
private
BigDecimal
finishDeposit
;
public
String
getNumber
()
{
return
number
;
}
public
void
setNumber
(
String
number
)
{
this
.
number
=
number
;
}
public
BigDecimal
getFinishDeposit
()
{
return
finishDeposit
;
}
public
void
setFinishDeposit
(
BigDecimal
finishDeposit
)
{
this
.
finishDeposit
=
finishDeposit
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/MaterialCountVo.java
0 → 100644
View file @
43111edc
package
com.jsh.erp.datasource.vo
;
import
java.math.BigDecimal
;
public
class
MaterialCountVo
{
private
Long
headerId
;
private
BigDecimal
materialCount
;
public
Long
getHeaderId
()
{
return
headerId
;
}
public
void
setHeaderId
(
Long
headerId
)
{
this
.
headerId
=
headerId
;
}
public
BigDecimal
getMaterialCount
()
{
return
materialCount
;
}
public
void
setMaterialCount
(
BigDecimal
materialCount
)
{
this
.
materialCount
=
materialCount
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/datasource/vo/MaterialsListVo.java
0 → 100644
View file @
43111edc
package
com.jsh.erp.datasource.vo
;
public
class
MaterialsListVo
{
private
Long
headerId
;
private
String
materialsList
;
public
Long
getHeaderId
()
{
return
headerId
;
}
public
void
setHeaderId
(
Long
headerId
)
{
this
.
headerId
=
headerId
;
}
public
String
getMaterialsList
()
{
return
materialsList
;
}
public
void
setMaterialsList
(
String
materialsList
)
{
this
.
materialsList
=
materialsList
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java
View file @
43111edc
...
...
@@ -402,6 +402,10 @@ public class AccountHeadService {
return
resList
;
}
public
List
<
AccountItem
>
getFinancialBillNoByBillIdList
(
List
<
Long
>
idList
)
{
return
accountHeadMapperEx
.
getFinancialBillNoByBillIdList
(
idList
);
}
public
List
<
AccountHead
>
getFinancialBillNoByBillId
(
Long
billId
)
{
return
accountHeadMapperEx
.
getFinancialBillNoByBillId
(
billId
);
}
...
...
jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java
View file @
43111edc
...
...
@@ -108,7 +108,6 @@ public class DepotHeadService {
public
List
<
DepotHeadVo4List
>
select
(
String
type
,
String
subType
,
String
roleType
,
String
hasDebt
,
String
status
,
String
purchaseStatus
,
String
number
,
String
linkNumber
,
String
beginTime
,
String
endTime
,
String
materialParam
,
Long
organId
,
Long
creator
,
Long
depotId
,
Long
accountId
,
String
remark
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
DepotHeadVo4List
>
resList
=
new
ArrayList
<>();
List
<
DepotHeadVo4List
>
list
=
new
ArrayList
<>();
try
{
String
[]
depotArray
=
getDepotArray
(
subType
);
String
[]
creatorArray
=
getCreatorArray
(
roleType
);
...
...
@@ -119,7 +118,7 @@ public class DepotHeadService {
Map
<
Long
,
String
>
accountMap
=
accountService
.
getAccountMap
();
beginTime
=
Tools
.
parseDayToTime
(
beginTime
,
BusinessConstants
.
DAY_FIRST_TIME
);
endTime
=
Tools
.
parseDayToTime
(
endTime
,
BusinessConstants
.
DAY_LAST_TIME
);
list
=
depotHeadMapperEx
.
selectByConditionDepotHead
(
type
,
subType
,
creatorArray
,
hasDebt
,
statusArray
,
purchaseStatusArray
,
number
,
linkNumber
,
beginTime
,
endTime
,
List
<
DepotHeadVo4List
>
list
=
depotHeadMapperEx
.
selectByConditionDepotHead
(
type
,
subType
,
creatorArray
,
hasDebt
,
statusArray
,
purchaseStatusArray
,
number
,
linkNumber
,
beginTime
,
endTime
,
materialParam
,
organId
,
organArray
,
creator
,
depotId
,
depotArray
,
accountId
,
remark
,
offset
,
rows
);
if
(
null
!=
list
)
{
List
<
Long
>
idList
=
new
ArrayList
<>();
...
...
@@ -130,7 +129,10 @@ public class DepotHeadService {
}
//通过批量查询去构造map
Map
<
String
,
BigDecimal
>
finishDepositMap
=
getFinishDepositMapByNumberList
(
numberList
);
Map
<
Long
,
Integer
>
financialBillNoMap
=
getFinancialBillNoMapByBillIdList
(
idList
);
Map
<
String
,
Integer
>
billSizeMap
=
getBillSizeMapByLinkNumberList
(
numberList
);
Map
<
Long
,
String
>
materialsListMap
=
findMaterialsListMapByHeaderIdList
(
idList
);
Map
<
Long
,
BigDecimal
>
materialCountListMap
=
getMaterialCountListMapByHeaderIdList
(
idList
);
for
(
DepotHeadVo4List
dh
:
list
)
{
if
(
accountMap
!=
null
&&
StringUtil
.
isNotEmpty
(
dh
.
getAccountIdList
())
&&
StringUtil
.
isNotEmpty
(
dh
.
getAccountMoneyList
()))
{
String
accountStr
=
accountService
.
getAccountStrByIdAndMoney
(
accountMap
,
dh
.
getAccountIdList
(),
dh
.
getAccountMoneyList
());
...
...
@@ -153,15 +155,20 @@ public class DepotHeadService {
if
(
dh
.
getDeposit
()
==
null
)
{
dh
.
setDeposit
(
BigDecimal
.
ZERO
);
}
dh
.
setFinishDeposit
(
finishDepositMap
.
get
(
dh
.
getNumber
()));
//已经完成的欠款
if
(
finishDepositMap
!=
null
)
{
dh
.
setFinishDeposit
(
finishDepositMap
.
get
(
dh
.
getNumber
())
!=
null
?
finishDepositMap
.
get
(
dh
.
getNumber
())
:
BigDecimal
.
ZERO
);
}
//欠款计算
BigDecimal
discountLastMoney
=
dh
.
getDiscountLastMoney
()!=
null
?
dh
.
getDiscountLastMoney
():
BigDecimal
.
ZERO
;
BigDecimal
otherMoney
=
dh
.
getOtherMoney
()!=
null
?
dh
.
getOtherMoney
():
BigDecimal
.
ZERO
;
BigDecimal
changeAmount
=
dh
.
getChangeAmount
()!=
null
?
dh
.
getChangeAmount
():
BigDecimal
.
ZERO
;
dh
.
setDebt
(
discountLastMoney
.
add
(
otherMoney
).
subtract
((
dh
.
getDeposit
().
add
(
changeAmount
))));
//是否有付款单或收款单
int
financialBillNoSize
=
accountHeadService
.
getFinancialBillNoByBillId
(
dh
.
getId
()).
size
();
dh
.
setHasFinancialFlag
(
financialBillNoSize
>
0
);
if
(
financialBillNoMap
!=
null
)
{
Integer
financialBillNoSize
=
financialBillNoMap
.
get
(
dh
.
getId
());
dh
.
setHasFinancialFlag
(
financialBillNoSize
!=
null
&&
financialBillNoSize
>
0
);
}
//是否有退款单
if
(
billSizeMap
!=
null
)
{
Integer
billListSize
=
billSizeMap
.
get
(
dh
.
getNumber
());
...
...
@@ -174,9 +181,13 @@ public class DepotHeadService {
dh
.
setOperTimeStr
(
getCenternTime
(
dh
.
getOperTime
()));
}
//商品信息简述
dh
.
setMaterialsList
(
findMaterialsListByHeaderId
(
dh
.
getId
()));
if
(
materialsListMap
!=
null
)
{
dh
.
setMaterialsList
(
materialsListMap
.
get
(
dh
.
getId
()));
}
//商品总数量
dh
.
setMaterialCount
(
getMaterialCountByHeaderId
(
dh
.
getId
()));
if
(
materialCountListMap
!=
null
)
{
dh
.
setMaterialCount
(
materialCountListMap
.
get
(
dh
.
getId
()));
}
//以销定购的情况(不能显示销售单据的金额和客户名称)
if
(
StringUtil
.
isNotEmpty
(
purchaseStatus
))
{
dh
.
setOrganName
(
"****"
);
...
...
@@ -309,6 +320,15 @@ public class DepotHeadService {
return
billListMap
;
}
public
Map
<
Long
,
Integer
>
getFinancialBillNoMapByBillIdList
(
List
<
Long
>
idList
)
{
List
<
AccountItem
>
list
=
accountHeadService
.
getFinancialBillNoByBillIdList
(
idList
);
Map
<
Long
,
Integer
>
billListMap
=
new
HashMap
<>();
for
(
AccountItem
accountItem
:
list
){
billListMap
.
put
(
accountItem
.
getBillId
(),
list
.
size
());
}
return
billListMap
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertDepotHead
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
DepotHead
depotHead
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
DepotHead
.
class
);
...
...
@@ -528,24 +548,22 @@ public class DepotHeadService {
return
result
;
}
public
String
findMaterialsListByHeaderId
(
Long
id
)
throws
Exception
{
String
result
=
null
;
try
{
result
=
depotHeadMapperEx
.
findMaterialsListByHeaderId
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
public
Map
<
Long
,
String
>
findMaterialsListMapByHeaderIdList
(
List
<
Long
>
idList
)
throws
Exception
{
List
<
MaterialsListVo
>
list
=
depotHeadMapperEx
.
findMaterialsListMapByHeaderIdList
(
idList
);
Map
<
Long
,
String
>
materialsListMap
=
new
HashMap
<>();
for
(
MaterialsListVo
materialsListVo
:
list
){
materialsListMap
.
put
(
materialsListVo
.
getHeaderId
(),
materialsListVo
.
getMaterialsList
());
}
return
result
;
return
materialsListMap
;
}
private
BigDecimal
getMaterialCountByHeaderId
(
Long
id
)
{
BigDecimal
result
=
null
;
try
{
result
=
depotHeadMapperEx
.
getMaterialCountByHeaderId
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
public
Map
<
Long
,
BigDecimal
>
getMaterialCountListMapByHeaderIdList
(
List
<
Long
>
idList
)
throws
Exception
{
List
<
MaterialCountVo
>
list
=
depotHeadMapperEx
.
getMaterialCountListByHeaderIdList
(
idList
);
Map
<
Long
,
BigDecimal
>
materialCountListMap
=
new
HashMap
<>();
for
(
MaterialCountVo
materialCountVo
:
list
){
materialCountListMap
.
put
(
materialCountVo
.
getHeaderId
(),
materialCountVo
.
getMaterialCount
());
}
return
result
;
return
materialCountListMap
;
}
public
List
<
DepotHeadVo4InDetail
>
findInOutDetail
(
String
beginTime
,
String
endTime
,
String
type
,
String
[]
creatorArray
,
...
...
@@ -734,12 +752,21 @@ public class DepotHeadService {
public
List
<
DepotHeadVo4List
>
getDetailByNumber
(
String
number
)
throws
Exception
{
List
<
DepotHeadVo4List
>
resList
=
new
ArrayList
<
DepotHeadVo4List
>();
List
<
DepotHeadVo4List
>
list
=
null
;
try
{
Map
<
Long
,
String
>
personMap
=
personService
.
getPersonMap
();
Map
<
Long
,
String
>
accountMap
=
accountService
.
getAccountMap
();
list
=
depotHeadMapperEx
.
getDetailByNumber
(
number
);
List
<
DepotHeadVo4List
>
list
=
depotHeadMapperEx
.
getDetailByNumber
(
number
);
if
(
null
!=
list
)
{
List
<
Long
>
idList
=
new
ArrayList
<>();
List
<
String
>
numberList
=
new
ArrayList
<>();
for
(
DepotHeadVo4List
dh
:
list
)
{
idList
.
add
(
dh
.
getId
());
numberList
.
add
(
dh
.
getNumber
());
}
//通过批量查询去构造map
Map
<
Long
,
Integer
>
financialBillNoMap
=
getFinancialBillNoMapByBillIdList
(
idList
);
Map
<
String
,
Integer
>
billSizeMap
=
getBillSizeMapByLinkNumberList
(
numberList
);
Map
<
Long
,
String
>
materialsListMap
=
findMaterialsListMapByHeaderIdList
(
idList
);
for
(
DepotHeadVo4List
dh
:
list
)
{
if
(
accountMap
!=
null
&&
StringUtil
.
isNotEmpty
(
dh
.
getAccountIdList
())
&&
StringUtil
.
isNotEmpty
(
dh
.
getAccountMoneyList
()))
{
String
accountStr
=
accountService
.
getAccountStrByIdAndMoney
(
accountMap
,
dh
.
getAccountIdList
(),
dh
.
getAccountMoneyList
());
...
...
@@ -760,16 +787,23 @@ public class DepotHeadService {
dh
.
setTotalPrice
(
dh
.
getTotalPrice
().
abs
());
}
//是否有付款单或收款单
int
financialBillNoSize
=
accountHeadService
.
getFinancialBillNoByBillId
(
dh
.
getId
()).
size
();
dh
.
setHasFinancialFlag
(
financialBillNoSize
>
0
);
if
(
financialBillNoMap
!=
null
)
{
Integer
financialBillNoSize
=
financialBillNoMap
.
get
(
dh
.
getId
());
dh
.
setHasFinancialFlag
(
financialBillNoSize
!=
null
&&
financialBillNoSize
>
0
);
}
//是否有退款单
int
billListSize
=
getBillListByLinkNumber
(
dh
.
getNumber
()).
size
();
dh
.
setHasBackFlag
(
billListSize
>
0
);
if
(
billSizeMap
!=
null
)
{
Integer
billListSize
=
billSizeMap
.
get
(
dh
.
getNumber
());
dh
.
setHasBackFlag
(
billListSize
!=
null
&&
billListSize
>
0
);
}
if
(
StringUtil
.
isNotEmpty
(
dh
.
getSalesMan
()))
{
dh
.
setSalesManStr
(
personService
.
getPersonByMapAndIds
(
personMap
,
dh
.
getSalesMan
()));
}
dh
.
setOperTimeStr
(
getCenternTime
(
dh
.
getOperTime
()));
dh
.
setMaterialsList
(
findMaterialsListByHeaderId
(
dh
.
getId
()));
//商品信息简述
if
(
materialsListMap
!=
null
)
{
dh
.
setMaterialsList
(
materialsListMap
.
get
(
dh
.
getId
()));
}
dh
.
setCreatorName
(
userService
.
getUser
(
dh
.
getCreator
()).
getUsername
());
resList
.
add
(
dh
);
}
...
...
@@ -1159,6 +1193,12 @@ public class DepotHeadService {
endTime
=
Tools
.
parseDayToTime
(
endTime
,
BusinessConstants
.
DAY_LAST_TIME
);
List
<
DepotHeadVo4List
>
list
=
depotHeadMapperEx
.
debtList
(
organId
,
type
,
subType
,
creatorArray
,
status
,
number
,
beginTime
,
endTime
,
materialParam
,
depotArray
);
if
(
null
!=
list
)
{
List
<
Long
>
idList
=
new
ArrayList
<>();
for
(
DepotHeadVo4List
dh
:
list
)
{
idList
.
add
(
dh
.
getId
());
}
//通过批量查询去构造map
Map
<
Long
,
String
>
materialsListMap
=
findMaterialsListMapByHeaderIdList
(
idList
);
for
(
DepotHeadVo4List
dh
:
list
)
{
if
(
dh
.
getChangeAmount
()
!=
null
)
{
dh
.
setChangeAmount
(
dh
.
getChangeAmount
().
abs
());
...
...
@@ -1198,7 +1238,10 @@ public class DepotHeadService {
dh
.
setFinishDebt
(
finishDebt
);
//待收欠款
dh
.
setDebt
(
needDebt
.
subtract
(
allBillDebt
).
subtract
(
finishDebt
));
dh
.
setMaterialsList
(
findMaterialsListByHeaderId
(
dh
.
getId
()));
//商品信息简述
if
(
materialsListMap
!=
null
)
{
dh
.
setMaterialsList
(
materialsListMap
.
get
(
dh
.
getId
()));
}
resList
.
add
(
dh
);
}
}
...
...
jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml
View file @
43111edc
...
...
@@ -189,10 +189,23 @@
and ifnull(delete_flag,'0') !='1'
</select>
<select
id=
"getFinancialBillNoByBillIdList"
resultType=
"com.jsh.erp.datasource.entities.AccountItem"
>
select ai.bill_id from jsh_account_head ah
left join jsh_account_item ai on ah.id=ai.header_id and ifnull(ai.delete_flag,'0') !='1'
where 1=1
<if
test=
"idList.size()>0"
>
and ai.bill_id in
<foreach
collection=
"idList"
item=
"item"
index=
"index"
separator=
","
open=
"("
close=
")"
>
#{item}
</foreach>
</if>
and ifnull(ah.delete_flag,'0') !='1'
</select>
<select
id=
"getFinancialBillNoByBillId"
resultType=
"com.jsh.erp.datasource.entities.AccountHead"
>
select ah.bill_no from jsh_account_head ah
left join jsh_account_item ai on ah.id=ai.header_id and ifnull(ai.delete_flag,'0') !='1'
where bill_id=#{billId}
where
ai.
bill_id=#{billId}
and ifnull(ah.delete_flag,'0') !='1'
</select>
</mapper>
\ No newline at end of file
jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml
View file @
43111edc
...
...
@@ -243,18 +243,32 @@
and ifnull(dh.delete_Flag,'0') !='1') tb
</select>
<select
id=
"findMaterialsListByHeaderId"
resultType=
"
java.lang.String
"
>
select group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as m
Name
<select
id=
"findMaterialsList
Map
ByHeaderId
List
"
resultType=
"
com.jsh.erp.datasource.vo.MaterialsListVo
"
>
select
jsh_depot_item.header_id,
group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as m
aterialsList
from jsh_depot_item
left join jsh_material on jsh_depot_item.material_id = jsh_material.Id and ifnull(jsh_material.delete_Flag,'0') !='1'
where jsh_depot_item.header_id = #{id}
where 1=1
<if
test=
"idList.size()>0"
>
and jsh_depot_item.header_id in
<foreach
collection=
"idList"
item=
"item"
index=
"index"
separator=
","
open=
"("
close=
")"
>
#{item}
</foreach>
</if>
and ifnull(jsh_depot_item.delete_flag,'0') !='1'
group by jsh_depot_item.header_id
</select>
<select
id=
"getMaterialCountByHeaderId"
resultType=
"java.math.BigDecimal"
>
select sum(oper_number) from jsh_depot_item
where header_id = #{id}
<select
id=
"getMaterialCountListByHeaderIdList"
resultType=
"com.jsh.erp.datasource.vo.MaterialCountVo"
>
select header_id, sum(oper_number) materialCount from jsh_depot_item
where 1=1
<if
test=
"idList.size()>0"
>
and header_id in
<foreach
collection=
"idList"
item=
"item"
index=
"index"
separator=
","
open=
"("
close=
")"
>
#{item}
</foreach>
</if>
and ifnull(delete_flag,'0') !='1'
group by header_id
</select>
<select
id=
"findInOutDetail"
parameterType=
"com.jsh.erp.datasource.entities.DepotItemExample"
resultMap=
"ResultWithInfoExMap"
>
...
...
@@ -965,6 +979,7 @@
</foreach>
</if>
and ifnull(dh.delete_flag,'0') !='1'
group by dh.link_number
</select>
<select
id=
"getFinishDepositByNumberExceptCurrent"
resultType=
"java.math.BigDecimal"
>
...
...
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