优化单据的额查询列表的逻辑,提高查询速度(继续优化)

This commit is contained in:
季圣华
2022-11-23 23:34:43 +08:00
parent 95ead95c8f
commit 43111edc54
9 changed files with 195 additions and 66 deletions

View File

@@ -3,6 +3,7 @@ package com.jsh.erp.datasource.mappers;
import com.jsh.erp.datasource.entities.AccountHead; import com.jsh.erp.datasource.entities.AccountHead;
import com.jsh.erp.datasource.entities.AccountHeadExample; import com.jsh.erp.datasource.entities.AccountHeadExample;
import com.jsh.erp.datasource.entities.AccountHeadVo4ListEx; import com.jsh.erp.datasource.entities.AccountHeadVo4ListEx;
import com.jsh.erp.datasource.entities.AccountItem;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -58,6 +59,9 @@ public interface AccountHeadMapperEx {
List<AccountHead> getAccountHeadListByHandsPersonIds(@Param("handsPersonIds") String[] handsPersonIds); List<AccountHead> getAccountHeadListByHandsPersonIds(@Param("handsPersonIds") String[] handsPersonIds);
List<AccountItem> getFinancialBillNoByBillIdList(
@Param("idList") List<Long> idList);
List<AccountHead> getFinancialBillNoByBillId( List<AccountHead> getFinancialBillNoByBillId(
@Param("billId") Long billId); @Param("billId") Long billId);
} }

View File

@@ -57,11 +57,11 @@ public interface DepotHeadMapperEx {
@Param("accountId") Long accountId, @Param("accountId") Long accountId,
@Param("remark") String remark); @Param("remark") String remark);
String findMaterialsListByHeaderId( List<MaterialsListVo> findMaterialsListMapByHeaderIdList(
@Param("id") Long id); @Param("idList") List<Long> idList);
BigDecimal getMaterialCountByHeaderId( List<MaterialCountVo> getMaterialCountListByHeaderIdList(
@Param("id") Long id); @Param("idList") List<Long> idList);
List<DepotHeadVo4InDetail> findInOutDetail( List<DepotHeadVo4InDetail> findInOutDetail(
@Param("beginTime") String beginTime, @Param("beginTime") String beginTime,

View File

@@ -1,26 +1,26 @@
package com.jsh.erp.datasource.vo; package com.jsh.erp.datasource.vo;
import java.math.BigDecimal; import java.math.BigDecimal;
public class FinishDepositVo { public class FinishDepositVo {
private String number; private String number;
private BigDecimal finishDeposit; private BigDecimal finishDeposit;
public String getNumber() { public String getNumber() {
return number; return number;
} }
public void setNumber(String number) { public void setNumber(String number) {
this.number = number; this.number = number;
} }
public BigDecimal getFinishDeposit() { public BigDecimal getFinishDeposit() {
return finishDeposit; return finishDeposit;
} }
public void setFinishDeposit(BigDecimal finishDeposit) { public void setFinishDeposit(BigDecimal finishDeposit) {
this.finishDeposit = finishDeposit; this.finishDeposit = finishDeposit;
} }
} }

View File

@@ -0,0 +1,26 @@
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;
}
}

View File

@@ -0,0 +1,24 @@
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;
}
}

View File

@@ -402,6 +402,10 @@ public class AccountHeadService {
return resList; return resList;
} }
public List<AccountItem> getFinancialBillNoByBillIdList(List<Long> idList) {
return accountHeadMapperEx.getFinancialBillNoByBillIdList(idList);
}
public List<AccountHead> getFinancialBillNoByBillId(Long billId) { public List<AccountHead> getFinancialBillNoByBillId(Long billId) {
return accountHeadMapperEx.getFinancialBillNoByBillId(billId); return accountHeadMapperEx.getFinancialBillNoByBillId(billId);
} }

View File

@@ -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, 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 { 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> resList = new ArrayList<>();
List<DepotHeadVo4List> list=new ArrayList<>();
try{ try{
String [] depotArray = getDepotArray(subType); String [] depotArray = getDepotArray(subType);
String [] creatorArray = getCreatorArray(roleType); String [] creatorArray = getCreatorArray(roleType);
@@ -119,7 +118,7 @@ public class DepotHeadService {
Map<Long,String> accountMap = accountService.getAccountMap(); Map<Long,String> accountMap = accountService.getAccountMap();
beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME); beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME);
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_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); materialParam, organId, organArray, creator, depotId, depotArray, accountId, remark, offset, rows);
if (null != list) { if (null != list) {
List<Long> idList = new ArrayList<>(); List<Long> idList = new ArrayList<>();
@@ -130,7 +129,10 @@ public class DepotHeadService {
} }
//通过批量查询去构造map //通过批量查询去构造map
Map<String,BigDecimal> finishDepositMap = getFinishDepositMapByNumberList(numberList); Map<String,BigDecimal> finishDepositMap = getFinishDepositMapByNumberList(numberList);
Map<Long,Integer> financialBillNoMap = getFinancialBillNoMapByBillIdList(idList);
Map<String,Integer> billSizeMap = getBillSizeMapByLinkNumberList(numberList); Map<String,Integer> billSizeMap = getBillSizeMapByLinkNumberList(numberList);
Map<Long,String> materialsListMap = findMaterialsListMapByHeaderIdList(idList);
Map<Long,BigDecimal> materialCountListMap = getMaterialCountListMapByHeaderIdList(idList);
for (DepotHeadVo4List dh : list) { for (DepotHeadVo4List dh : list) {
if(accountMap!=null && StringUtil.isNotEmpty(dh.getAccountIdList()) && StringUtil.isNotEmpty(dh.getAccountMoneyList())) { if(accountMap!=null && StringUtil.isNotEmpty(dh.getAccountIdList()) && StringUtil.isNotEmpty(dh.getAccountMoneyList())) {
String accountStr = accountService.getAccountStrByIdAndMoney(accountMap, dh.getAccountIdList(), dh.getAccountMoneyList()); String accountStr = accountService.getAccountStrByIdAndMoney(accountMap, dh.getAccountIdList(), dh.getAccountMoneyList());
@@ -153,15 +155,20 @@ public class DepotHeadService {
if(dh.getDeposit() == null) { if(dh.getDeposit() == null) {
dh.setDeposit(BigDecimal.ZERO); 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 discountLastMoney = dh.getDiscountLastMoney()!=null?dh.getDiscountLastMoney():BigDecimal.ZERO;
BigDecimal otherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():BigDecimal.ZERO; BigDecimal otherMoney = dh.getOtherMoney()!=null?dh.getOtherMoney():BigDecimal.ZERO;
BigDecimal changeAmount = dh.getChangeAmount()!=null?dh.getChangeAmount():BigDecimal.ZERO; BigDecimal changeAmount = dh.getChangeAmount()!=null?dh.getChangeAmount():BigDecimal.ZERO;
dh.setDebt(discountLastMoney.add(otherMoney).subtract((dh.getDeposit().add(changeAmount)))); dh.setDebt(discountLastMoney.add(otherMoney).subtract((dh.getDeposit().add(changeAmount))));
//是否有付款单或收款单 //是否有付款单或收款单
int financialBillNoSize = accountHeadService.getFinancialBillNoByBillId(dh.getId()).size(); if(financialBillNoMap!=null) {
dh.setHasFinancialFlag(financialBillNoSize>0); Integer financialBillNoSize = financialBillNoMap.get(dh.getId());
dh.setHasFinancialFlag(financialBillNoSize!=null && financialBillNoSize>0);
}
//是否有退款单 //是否有退款单
if(billSizeMap!=null) { if(billSizeMap!=null) {
Integer billListSize = billSizeMap.get(dh.getNumber()); Integer billListSize = billSizeMap.get(dh.getNumber());
@@ -174,9 +181,13 @@ public class DepotHeadService {
dh.setOperTimeStr(getCenternTime(dh.getOperTime())); 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)) { if(StringUtil.isNotEmpty(purchaseStatus)) {
dh.setOrganName("****"); dh.setOrganName("****");
@@ -309,6 +320,15 @@ public class DepotHeadService {
return billListMap; 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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertDepotHead(JSONObject obj, HttpServletRequest request)throws Exception { public int insertDepotHead(JSONObject obj, HttpServletRequest request)throws Exception {
DepotHead depotHead = JSONObject.parseObject(obj.toJSONString(), DepotHead.class); DepotHead depotHead = JSONObject.parseObject(obj.toJSONString(), DepotHead.class);
@@ -528,24 +548,22 @@ public class DepotHeadService {
return result; return result;
} }
public String findMaterialsListByHeaderId(Long id)throws Exception { public Map<Long,String> findMaterialsListMapByHeaderIdList(List<Long> idList)throws Exception {
String result = null; List<MaterialsListVo> list = depotHeadMapperEx.findMaterialsListMapByHeaderIdList(idList);
try{ Map<Long,String> materialsListMap = new HashMap<>();
result = depotHeadMapperEx.findMaterialsListByHeaderId(id); for(MaterialsListVo materialsListVo : list){
}catch(Exception e){ materialsListMap.put(materialsListVo.getHeaderId(), materialsListVo.getMaterialsList());
JshException.readFail(logger, e);
} }
return result; return materialsListMap;
} }
private BigDecimal getMaterialCountByHeaderId(Long id) { public Map<Long,BigDecimal> getMaterialCountListMapByHeaderIdList(List<Long> idList)throws Exception {
BigDecimal result = null; List<MaterialCountVo> list = depotHeadMapperEx.getMaterialCountListByHeaderIdList(idList);
try{ Map<Long,BigDecimal> materialCountListMap = new HashMap<>();
result = depotHeadMapperEx.getMaterialCountByHeaderId(id); for(MaterialCountVo materialCountVo : list){
}catch(Exception e){ materialCountListMap.put(materialCountVo.getHeaderId(), materialCountVo.getMaterialCount());
JshException.readFail(logger, e);
} }
return result; return materialCountListMap;
} }
public List<DepotHeadVo4InDetail> findInOutDetail(String beginTime, String endTime, String type, String [] creatorArray, 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 { public List<DepotHeadVo4List> getDetailByNumber(String number)throws Exception {
List<DepotHeadVo4List> resList = new ArrayList<DepotHeadVo4List>(); List<DepotHeadVo4List> resList = new ArrayList<DepotHeadVo4List>();
List<DepotHeadVo4List> list = null;
try{ try{
Map<Long,String> personMap = personService.getPersonMap(); Map<Long,String> personMap = personService.getPersonMap();
Map<Long,String> accountMap = accountService.getAccountMap(); Map<Long,String> accountMap = accountService.getAccountMap();
list = depotHeadMapperEx.getDetailByNumber(number); List<DepotHeadVo4List> list = depotHeadMapperEx.getDetailByNumber(number);
if (null != list) { 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) { for (DepotHeadVo4List dh : list) {
if(accountMap!=null && StringUtil.isNotEmpty(dh.getAccountIdList()) && StringUtil.isNotEmpty(dh.getAccountMoneyList())) { if(accountMap!=null && StringUtil.isNotEmpty(dh.getAccountIdList()) && StringUtil.isNotEmpty(dh.getAccountMoneyList())) {
String accountStr = accountService.getAccountStrByIdAndMoney(accountMap, dh.getAccountIdList(), dh.getAccountMoneyList()); String accountStr = accountService.getAccountStrByIdAndMoney(accountMap, dh.getAccountIdList(), dh.getAccountMoneyList());
@@ -760,16 +787,23 @@ public class DepotHeadService {
dh.setTotalPrice(dh.getTotalPrice().abs()); dh.setTotalPrice(dh.getTotalPrice().abs());
} }
//是否有付款单或收款单 //是否有付款单或收款单
int financialBillNoSize = accountHeadService.getFinancialBillNoByBillId(dh.getId()).size(); if(financialBillNoMap!=null) {
dh.setHasFinancialFlag(financialBillNoSize>0); Integer financialBillNoSize = financialBillNoMap.get(dh.getId());
dh.setHasFinancialFlag(financialBillNoSize!=null && financialBillNoSize>0);
}
//是否有退款单 //是否有退款单
int billListSize = getBillListByLinkNumber(dh.getNumber()).size(); if(billSizeMap!=null) {
dh.setHasBackFlag(billListSize>0); Integer billListSize = billSizeMap.get(dh.getNumber());
dh.setHasBackFlag(billListSize!=null && billListSize>0);
}
if(StringUtil.isNotEmpty(dh.getSalesMan())) { if(StringUtil.isNotEmpty(dh.getSalesMan())) {
dh.setSalesManStr(personService.getPersonByMapAndIds(personMap,dh.getSalesMan())); dh.setSalesManStr(personService.getPersonByMapAndIds(personMap,dh.getSalesMan()));
} }
dh.setOperTimeStr(getCenternTime(dh.getOperTime())); 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()); dh.setCreatorName(userService.getUser(dh.getCreator()).getUsername());
resList.add(dh); resList.add(dh);
} }
@@ -1159,6 +1193,12 @@ public class DepotHeadService {
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME); endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
List<DepotHeadVo4List> list=depotHeadMapperEx.debtList(organId, type, subType, creatorArray, status, number, beginTime, endTime, materialParam, depotArray); List<DepotHeadVo4List> list=depotHeadMapperEx.debtList(organId, type, subType, creatorArray, status, number, beginTime, endTime, materialParam, depotArray);
if (null != list) { 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) { for (DepotHeadVo4List dh : list) {
if(dh.getChangeAmount() != null) { if(dh.getChangeAmount() != null) {
dh.setChangeAmount(dh.getChangeAmount().abs()); dh.setChangeAmount(dh.getChangeAmount().abs());
@@ -1198,7 +1238,10 @@ public class DepotHeadService {
dh.setFinishDebt(finishDebt); dh.setFinishDebt(finishDebt);
//待收欠款 //待收欠款
dh.setDebt(needDebt.subtract(allBillDebt).subtract(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); resList.add(dh);
} }
} }

View File

@@ -189,10 +189,23 @@
and ifnull(delete_flag,'0') !='1' and ifnull(delete_flag,'0') !='1'
</select> </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 id="getFinancialBillNoByBillId" resultType="com.jsh.erp.datasource.entities.AccountHead">
select ah.bill_no from jsh_account_head ah 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' 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' and ifnull(ah.delete_flag,'0') !='1'
</select> </select>
</mapper> </mapper>

View File

@@ -243,18 +243,32 @@
and ifnull(dh.delete_Flag,'0') !='1') tb and ifnull(dh.delete_Flag,'0') !='1') tb
</select> </select>
<select id="findMaterialsListByHeaderId" resultType="java.lang.String"> <select id="findMaterialsListMapByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialsListVo">
select group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as mName select jsh_depot_item.header_id, group_concat(concat(jsh_material.name,' ',ifnull(jsh_material.standard,''),' ',ifnull(jsh_material.model,''))) as materialsList
from jsh_depot_item 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' 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' and ifnull(jsh_depot_item.delete_flag,'0') !='1'
group by jsh_depot_item.header_id
</select> </select>
<select id="getMaterialCountByHeaderId" resultType="java.math.BigDecimal"> <select id="getMaterialCountListByHeaderIdList" resultType="com.jsh.erp.datasource.vo.MaterialCountVo">
select sum(oper_number) from jsh_depot_item select header_id, sum(oper_number) materialCount from jsh_depot_item
where header_id = #{id} 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' and ifnull(delete_flag,'0') !='1'
group by header_id
</select> </select>
<select id="findInOutDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap"> <select id="findInOutDetail" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
@@ -965,6 +979,7 @@
</foreach> </foreach>
</if> </if>
and ifnull(dh.delete_flag,'0') !='1' and ifnull(dh.delete_flag,'0') !='1'
group by dh.link_number
</select> </select>
<select id="getFinishDepositByNumberExceptCurrent" resultType="java.math.BigDecimal"> <select id="getFinishDepositByNumberExceptCurrent" resultType="java.math.BigDecimal">