Skip to content

Commit

Permalink
优化采购统计和销售统计的查询逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
jishenghua committed Mar 9, 2023
1 parent 336d818 commit bf8d660
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -478,22 +478,23 @@ public BaseResponseInfo buyIn(@RequestParam("currentPage") Integer currentPage,
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
try {
String [] creatorArray = depotHeadService.getCreatorArray(roleType);
List<Long> depotList = depotService.parseDepotList(null);
Boolean amountApprovalFlag = systemConfigService.getAmountApprovalFlag();
List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBugOrSale(StringUtil.toNull(materialParam),
"buy", beginTime, endTime, creatorArray, amountApprovalFlag, (currentPage-1)*pageSize, pageSize);
"buy", beginTime, endTime, creatorArray, depotList, amountApprovalFlag, (currentPage-1)*pageSize, pageSize);
String[] mpArr = mpList.split(",");
int total = depotItemService.getListWithBugOrSaleCount(StringUtil.toNull(materialParam),
"buy", beginTime, endTime, creatorArray, amountApprovalFlag);
"buy", beginTime, endTime, creatorArray, depotList, amountApprovalFlag);
map.put("total", total);
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
BigDecimal InSum = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, "number");
BigDecimal OutSum = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, "number");
BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, "price");
BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, "price");
BigDecimal InSum = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, depotList, "number");
BigDecimal OutSum = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList, "number");
BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "采购", diEx.getMId(), beginTime, endTime, creatorArray, depotList, "price");
BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "采购退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList, "price");
BigDecimal InOutSumPrice = InSumPrice.subtract(OutSumPrice);
item.put("barCode", diEx.getBarCode());
item.put("materialName", diEx.getMName());
Expand Down Expand Up @@ -551,26 +552,27 @@ public BaseResponseInfo saleOut(@RequestParam("currentPage") Integer currentPage
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
try {
String [] creatorArray = depotHeadService.getCreatorArray(roleType);
List<Long> depotList = depotService.parseDepotList(null);
Boolean amountApprovalFlag = systemConfigService.getAmountApprovalFlag();
List<DepotItemVo4WithInfoEx> dataList = depotItemService.getListWithBugOrSale(StringUtil.toNull(materialParam),
"sale", beginTime, endTime, creatorArray, amountApprovalFlag, (currentPage-1)*pageSize, pageSize);
"sale", beginTime, endTime, creatorArray, depotList, amountApprovalFlag, (currentPage-1)*pageSize, pageSize);
String[] mpArr = mpList.split(",");
int total = depotItemService.getListWithBugOrSaleCount(StringUtil.toNull(materialParam),
"sale", beginTime, endTime, creatorArray, amountApprovalFlag);
"sale", beginTime, endTime, creatorArray, depotList, amountApprovalFlag);
map.put("total", total);
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
BigDecimal OutSumRetail = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray,"number");
BigDecimal OutSum = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray,"number");
BigDecimal InSumRetail = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray,"number");
BigDecimal InSum = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray,"number");
BigDecimal OutSumRetailPrice = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray,"price");
BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray,"price");
BigDecimal InSumRetailPrice = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray,"price");
BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray,"price");
BigDecimal OutSumRetail = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"number");
BigDecimal OutSum = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"number");
BigDecimal InSumRetail = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"number");
BigDecimal InSum = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"number");
BigDecimal OutSumRetailPrice = depotItemService.buyOrSale("出库", "零售", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"price");
BigDecimal OutSumPrice = depotItemService.buyOrSale("出库", "销售", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"price");
BigDecimal InSumRetailPrice = depotItemService.buyOrSale("入库", "零售退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"price");
BigDecimal InSumPrice = depotItemService.buyOrSale("入库", "销售退货", diEx.getMId(), beginTime, endTime, creatorArray, depotList,"price");
BigDecimal OutInSumPrice = (OutSumRetailPrice.add(OutSumPrice)).subtract(InSumRetailPrice.add(InSumPrice));
item.put("barCode", diEx.getBarCode());
item.put("materialName", diEx.getMName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Long countsByDepotItem(
@Param("remark") String remark);

List<DepotItemVo4DetailByTypeAndMId> findDetailByDepotIdsAndMaterialIdList(
@Param("depotIdArray") String[] depotIdArray,
@Param("depotIdArray") Long[] depotIdArray,
@Param("sku") String sku,
@Param("batchNumber") String batchNumber,
@Param("number") String number,
Expand All @@ -41,7 +41,7 @@ List<DepotItemVo4DetailByTypeAndMId> findDetailByDepotIdsAndMaterialIdList(
@Param("rows") Integer rows);

Long findDetailByDepotIdsAndMaterialIdCount(
@Param("depotIdArray") String[] depotIdArray,
@Param("depotIdArray") Long[] depotIdArray,
@Param("sku") String sku,
@Param("batchNumber") String batchNumber,
@Param("number") String number,
Expand All @@ -68,6 +68,7 @@ List<DepotItemVo4WithInfoEx> getListWithBugOrSale(
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("creatorArray") String[] creatorArray,
@Param("depotList") List<Long> depotList,
@Param("amountApprovalFlag") Boolean amountApprovalFlag,
@Param("offset") Integer offset,
@Param("rows") Integer rows);
Expand All @@ -78,6 +79,7 @@ int getListWithBugOrSaleCount(
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("creatorArray") String[] creatorArray,
@Param("depotList") List<Long> depotList,
@Param("amountApprovalFlag") Boolean amountApprovalFlag);

BigDecimal buyOrSaleNumber(
Expand All @@ -87,6 +89,7 @@ BigDecimal buyOrSaleNumber(
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("creatorArray") String[] creatorArray,
@Param("depotList") List<Long> depotList,
@Param("sumType") String sumType);

BigDecimal buyOrSalePrice(
Expand All @@ -96,6 +99,7 @@ BigDecimal buyOrSalePrice(
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("creatorArray") String[] creatorArray,
@Param("depotList") List<Long> depotList,
@Param("sumType") String sumType);

BigDecimal inOrOutPrice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,12 @@ public int checkIsNameExist(Long id, String name)throws Exception {

public List<DepotItemVo4DetailByTypeAndMId> findDetailByDepotIdsAndMaterialIdList(String depotIds, String sku, String batchNumber,
String number, String beginTime, String endTime, Long mId, int offset, int rows)throws Exception {
String [] depotIdArray = null;
Long depotId = null;
if(StringUtil.isNotEmpty(depotIds)) {
depotIdArray = depotIds.split(",");
depotId = Long.parseLong(depotIds);
}
List<Long> depotList = depotService.parseDepotList(depotId);
Long[] depotIdArray = StringUtil.listToLongArray(depotList);
List<DepotItemVo4DetailByTypeAndMId> list =null;
try{
list = depotItemMapperEx.findDetailByDepotIdsAndMaterialIdList(depotIdArray, sku, batchNumber, number, beginTime, endTime, mId, offset, rows);
Expand All @@ -191,10 +193,12 @@ public List<DepotItemVo4DetailByTypeAndMId> findDetailByDepotIdsAndMaterialIdLis

public Long findDetailByDepotIdsAndMaterialIdCount(String depotIds, String sku, String batchNumber,
String number, String beginTime, String endTime, Long mId)throws Exception {
String [] depotIdArray = null;
Long depotId = null;
if(StringUtil.isNotEmpty(depotIds)) {
depotIdArray = depotIds.split(",");
depotId = Long.parseLong(depotIds);
}
List<Long> depotList = depotService.parseDepotList(depotId);
Long[] depotIdArray = StringUtil.listToLongArray(depotList);
Long result =null;
try{
result = depotItemMapperEx.findDetailByDepotIdsAndMaterialIdCount(depotIdArray, sku, batchNumber, number, beginTime, endTime, mId);
Expand Down Expand Up @@ -314,35 +318,35 @@ public int findByAllCount(String materialParam, String endTime)throws Exception
}

public List<DepotItemVo4WithInfoEx> getListWithBugOrSale(String materialParam, String billType,
String beginTime, String endTime, String[] creatorArray, Boolean amountApprovalFlag, Integer offset, Integer rows)throws Exception {
String beginTime, String endTime, String[] creatorArray, List<Long> depotList, Boolean amountApprovalFlag, Integer offset, Integer rows)throws Exception {
List<DepotItemVo4WithInfoEx> list =null;
try{
list = depotItemMapperEx.getListWithBugOrSale(materialParam, billType, beginTime, endTime, creatorArray, amountApprovalFlag, offset, rows);
list = depotItemMapperEx.getListWithBugOrSale(materialParam, billType, beginTime, endTime, creatorArray, depotList, amountApprovalFlag, offset, rows);
}catch(Exception e){
JshException.readFail(logger, e);
}
return list;
}

public int getListWithBugOrSaleCount(String materialParam, String billType,
String beginTime, String endTime, String[] creatorArray, Boolean amountApprovalFlag)throws Exception {
String beginTime, String endTime, String[] creatorArray, List<Long> depotList, Boolean amountApprovalFlag)throws Exception {
int result=0;
try{
result = depotItemMapperEx.getListWithBugOrSaleCount(materialParam, billType, beginTime, endTime, creatorArray, amountApprovalFlag);
result = depotItemMapperEx.getListWithBugOrSaleCount(materialParam, billType, beginTime, endTime, creatorArray, depotList, amountApprovalFlag);
}catch(Exception e){
JshException.readFail(logger, e);
}
return result;
}

public BigDecimal buyOrSale(String type, String subType, Long MId, String beginTime, String endTime,
String[] creatorArray, String sumType) throws Exception{
String[] creatorArray, List<Long> depotList, String sumType) throws Exception{
BigDecimal result= BigDecimal.ZERO;
try{
if (SUM_TYPE.equals(sumType)) {
result= depotItemMapperEx.buyOrSaleNumber(type, subType, MId, beginTime, endTime, creatorArray, sumType);
result= depotItemMapperEx.buyOrSaleNumber(type, subType, MId, beginTime, endTime, creatorArray, depotList, sumType);
} else {
result= depotItemMapperEx.buyOrSalePrice(type, subType, MId, beginTime, endTime, creatorArray, sumType);
result= depotItemMapperEx.buyOrSalePrice(type, subType, MId, beginTime, endTime, creatorArray, depotList, sumType);
}
}catch(Exception e){
JshException.readFail(logger, e);
Expand Down
24 changes: 24 additions & 0 deletions jshERP-boot/src/main/resources/mapper_xml/DepotItemMapperEx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@
</foreach>
)
</if>
<if test="depotList.size()>0">
and di.depot_id in
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="amountApprovalFlag">
and dh.status = '1'
</if>
Expand Down Expand Up @@ -417,6 +423,12 @@
</foreach>
)
</if>
<if test="depotList.size()>0">
and di.depot_id in
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test="amountApprovalFlag">
and dh.status = '1'
</if>
Expand All @@ -438,6 +450,12 @@
</foreach>
)
</if>
<if test="depotList.size()>0">
and di.depot_id in
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
and ifnull(dh.delete_flag,'0') !='1'
and ifnull(di.delete_flag,'0') !='1'
</select>
Expand All @@ -456,6 +474,12 @@
</foreach>
)
</if>
<if test="depotList.size()>0">
and di.depot_id in
<foreach collection="depotList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
and ifnull(dh.delete_flag,'0') !='1'
and ifnull(di.delete_flag,'0') !='1'
</select>
Expand Down

0 comments on commit bf8d660

Please sign in to comment.