Commit d995a3204ae1c6ee60e978e1227f8d39eafd6057
1 parent
9959dff8
库存概况性能优化
Signed-off-by: TanYibin <5491541@qq.com>
Showing
5 changed files
with
91 additions
and
83 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/home/controller/HomePageViewController.java
@@ -42,8 +42,11 @@ import javax.annotation.Resource; | @@ -42,8 +42,11 @@ import javax.annotation.Resource; | ||
42 | import javax.servlet.http.HttpServletRequest; | 42 | import javax.servlet.http.HttpServletRequest; |
43 | 43 | ||
44 | import java.math.BigDecimal; | 44 | import java.math.BigDecimal; |
45 | +import java.text.ParseException; | ||
45 | import java.text.SimpleDateFormat; | 46 | import java.text.SimpleDateFormat; |
46 | import java.util.*; | 47 | import java.util.*; |
48 | +import java.util.concurrent.ExecutionException; | ||
49 | +import java.util.concurrent.TimeoutException; | ||
47 | import java.util.stream.Collectors; | 50 | import java.util.stream.Collectors; |
48 | 51 | ||
49 | /** | 52 | /** |
@@ -62,9 +65,13 @@ public class HomePageViewController { | @@ -62,9 +65,13 @@ public class HomePageViewController { | ||
62 | /** | 65 | /** |
63 | * 库存概况 | 66 | * 库存概况 |
64 | * @return | 67 | * @return |
68 | + * @throws TimeoutException | ||
69 | + * @throws ExecutionException | ||
70 | + * @throws InterruptedException | ||
71 | + * @throws ParseException | ||
65 | */ | 72 | */ |
66 | @RequestMapping(value = "/deliveringAmount", method = {RequestMethod.PUT, RequestMethod.POST}) | 73 | @RequestMapping(value = "/deliveringAmount", method = {RequestMethod.PUT, RequestMethod.POST}) |
67 | - public Result<String> deliveringAmount(HttpServletRequest request) { | 74 | + public Result<String> deliveringAmount(HttpServletRequest request) throws ParseException, InterruptedException, ExecutionException, TimeoutException { |
68 | return homePageViewService.deliveringAmount(request); | 75 | return homePageViewService.deliveringAmount(request); |
69 | } | 76 | } |
70 | 77 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/home/service/HomePageViewService.java
@@ -6,7 +6,10 @@ import org.jeecg.modules.wms.config.location.entity.Location; | @@ -6,7 +6,10 @@ import org.jeecg.modules.wms.config.location.entity.Location; | ||
6 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 6 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
7 | 7 | ||
8 | import java.io.Serializable; | 8 | import java.io.Serializable; |
9 | +import java.text.ParseException; | ||
9 | import java.util.Collection; | 10 | import java.util.Collection; |
11 | +import java.util.concurrent.ExecutionException; | ||
12 | +import java.util.concurrent.TimeoutException; | ||
10 | 13 | ||
11 | import javax.servlet.http.HttpServletRequest; | 14 | import javax.servlet.http.HttpServletRequest; |
12 | 15 | ||
@@ -18,7 +21,7 @@ import javax.servlet.http.HttpServletRequest; | @@ -18,7 +21,7 @@ import javax.servlet.http.HttpServletRequest; | ||
18 | */ | 21 | */ |
19 | public interface HomePageViewService { | 22 | public interface HomePageViewService { |
20 | 23 | ||
21 | - Result<String> deliveringAmount(HttpServletRequest request); | 24 | + Result<String> deliveringAmount(HttpServletRequest request) throws ParseException, InterruptedException, ExecutionException, TimeoutException; |
22 | 25 | ||
23 | Result<String> inventoryUtilization(HttpServletRequest request); | 26 | Result<String> inventoryUtilization(HttpServletRequest request); |
24 | 27 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/home/service/impl/HomePageViewServiceImpl.java
1 | package org.jeecg.modules.wms.home.service.impl; | 1 | package org.jeecg.modules.wms.home.service.impl; |
2 | 2 | ||
3 | -import cn.hutool.core.util.ArrayUtil; | ||
4 | -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
5 | -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
6 | -import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||
7 | -import com.baomidou.mybatisplus.extension.service.IService; | ||
8 | -import com.github.abel533.echarts.Option; | ||
9 | -import com.github.abel533.echarts.axis.Axis; | ||
10 | -import com.github.abel533.echarts.axis.CategoryAxis; | ||
11 | -import com.github.abel533.echarts.axis.ValueAxis; | ||
12 | -import com.github.abel533.echarts.code.*; | ||
13 | -import com.github.abel533.echarts.json.GsonUtil; | ||
14 | -import com.github.abel533.echarts.series.Line; | ||
15 | -import com.github.abel533.echarts.series.Pie; | ||
16 | -import com.github.abel533.echarts.style.itemstyle.Normal; | 3 | +import java.math.BigDecimal; |
4 | +import java.text.ParseException; | ||
5 | +import java.text.SimpleDateFormat; | ||
6 | +import java.util.ArrayList; | ||
7 | +import java.util.Arrays; | ||
8 | +import java.util.Date; | ||
9 | +import java.util.HashMap; | ||
10 | +import java.util.LinkedHashMap; | ||
11 | +import java.util.List; | ||
12 | +import java.util.Map; | ||
13 | +import java.util.concurrent.ExecutionException; | ||
14 | +import java.util.concurrent.Future; | ||
15 | +import java.util.concurrent.TimeUnit; | ||
16 | +import java.util.concurrent.TimeoutException; | ||
17 | +import java.util.stream.Collectors; | ||
18 | + | ||
19 | +import javax.annotation.Resource; | ||
20 | +import javax.servlet.http.HttpServletRequest; | ||
21 | + | ||
17 | import org.jeecg.common.api.vo.Result; | 22 | import org.jeecg.common.api.vo.Result; |
18 | import org.jeecg.modules.system.entity.SysDictItem; | 23 | import org.jeecg.modules.system.entity.SysDictItem; |
19 | import org.jeecg.modules.system.service.impl.SysDictItemServiceImpl; | 24 | import org.jeecg.modules.system.service.impl.SysDictItemServiceImpl; |
20 | import org.jeecg.modules.wms.config.location.entity.Location; | 25 | import org.jeecg.modules.wms.config.location.entity.Location; |
21 | import org.jeecg.modules.wms.config.location.service.impl.LocationServiceImpl; | 26 | import org.jeecg.modules.wms.config.location.service.impl.LocationServiceImpl; |
22 | import org.jeecg.modules.wms.home.service.HomePageViewService; | 27 | import org.jeecg.modules.wms.home.service.HomePageViewService; |
23 | - | ||
24 | import org.jeecg.modules.wms.home.support.ChartData; | 28 | import org.jeecg.modules.wms.home.support.ChartData; |
25 | import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail; | 29 | import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryDetail; |
26 | import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryHeader; | 30 | import org.jeecg.modules.wms.inventory.inventoryHeader.entity.InventoryHeader; |
27 | import org.jeecg.modules.wms.inventory.inventoryHeader.service.impl.InventoryDetailServiceImpl; | 31 | import org.jeecg.modules.wms.inventory.inventoryHeader.service.impl.InventoryDetailServiceImpl; |
28 | import org.jeecg.modules.wms.inventory.inventoryHeader.service.impl.InventoryHeaderServiceImpl; | 32 | import org.jeecg.modules.wms.inventory.inventoryHeader.service.impl.InventoryHeaderServiceImpl; |
29 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; | 33 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; |
30 | -import org.jeecg.modules.wms.inventory.inventoryTransaction.service.impl.InventoryTransactionServiceImpl; | ||
31 | -import org.jeecg.modules.wms.receipt.receiptHeader.entity.ReceiptHeader; | 34 | +import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; |
32 | import org.jeecg.modules.wms.receipt.receiptHeader.service.impl.ReceiptHeaderServiceImpl; | 35 | import org.jeecg.modules.wms.receipt.receiptHeader.service.impl.ReceiptHeaderServiceImpl; |
33 | -import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentHeader; | ||
34 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.impl.ShipmentHeaderServiceImpl; | 36 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.impl.ShipmentHeaderServiceImpl; |
35 | -import org.jeecg.modules.wms.task.taskHeader.entity.TaskDetail; | ||
36 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 37 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
37 | import org.jeecg.modules.wms.task.taskHeader.service.impl.TaskDetailServiceImpl; | 38 | import org.jeecg.modules.wms.task.taskHeader.service.impl.TaskDetailServiceImpl; |
38 | import org.jeecg.modules.wms.task.taskHeader.service.impl.TaskHeaderServiceImpl; | 39 | import org.jeecg.modules.wms.task.taskHeader.service.impl.TaskHeaderServiceImpl; |
39 | import org.jeecg.utils.HuahengJwtUtil; | 40 | import org.jeecg.utils.HuahengJwtUtil; |
40 | -import org.jeecg.utils.StringUtils; | ||
41 | import org.jeecg.utils.constant.QuantityConstant; | 41 | import org.jeecg.utils.constant.QuantityConstant; |
42 | import org.jeecg.utils.support.Convert; | 42 | import org.jeecg.utils.support.Convert; |
43 | import org.springframework.stereotype.Service; | 43 | import org.springframework.stereotype.Service; |
44 | 44 | ||
45 | -import javax.annotation.Resource; | ||
46 | -import javax.servlet.http.HttpServletRequest; | 45 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
46 | +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||
47 | +import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||
48 | +import com.github.abel533.echarts.Option; | ||
49 | +import com.github.abel533.echarts.axis.Axis; | ||
50 | +import com.github.abel533.echarts.axis.CategoryAxis; | ||
51 | +import com.github.abel533.echarts.axis.ValueAxis; | ||
52 | +import com.github.abel533.echarts.code.LegendType; | ||
53 | +import com.github.abel533.echarts.code.Orient; | ||
54 | +import com.github.abel533.echarts.code.PointerType; | ||
55 | +import com.github.abel533.echarts.code.SeriesType; | ||
56 | +import com.github.abel533.echarts.code.Trigger; | ||
57 | +import com.github.abel533.echarts.json.GsonUtil; | ||
58 | +import com.github.abel533.echarts.series.Line; | ||
59 | +import com.github.abel533.echarts.series.Pie; | ||
60 | +import com.github.abel533.echarts.style.itemstyle.Normal; | ||
47 | 61 | ||
48 | -import java.math.BigDecimal; | ||
49 | -import java.text.SimpleDateFormat; | ||
50 | -import java.util.*; | ||
51 | -import java.util.stream.Collectors; | 62 | +import cn.hutool.core.date.DateUtil; |
63 | +import cn.hutool.core.util.ArrayUtil; | ||
52 | 64 | ||
53 | /** | 65 | /** |
54 | * @Description: 任务表 | 66 | * @Description: 任务表 |
@@ -87,60 +99,23 @@ public class HomePageViewServiceImpl implements HomePageViewService { | @@ -87,60 +99,23 @@ public class HomePageViewServiceImpl implements HomePageViewService { | ||
87 | HomePageViewService homePageViewService; | 99 | HomePageViewService homePageViewService; |
88 | 100 | ||
89 | @Resource | 101 | @Resource |
90 | - InventoryTransactionServiceImpl inventoryTransactionServiceImpl; | 102 | + IInventoryTransactionService inventoryTransactionService; |
91 | 103 | ||
92 | @Override | 104 | @Override |
93 | - public Result<String> deliveringAmount(HttpServletRequest request) { | ||
94 | - // 通过库存交易记录来查询 | ||
95 | - LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
96 | - HuahengJwtUtil.setWarehouseCode(inventoryTransactionLambdaQueryWrapper, InventoryTransaction.class, request); | ||
97 | - inventoryTransactionLambdaQueryWrapper.select(InventoryTransaction::getCreateTime, InventoryTransaction::getQty, InventoryTransaction::getType); | ||
98 | - List<InventoryTransaction> inventoryTransactions = inventoryTransactionServiceImpl.list(inventoryTransactionLambdaQueryWrapper); | ||
99 | - | ||
100 | - // 查询出库单的7天出库量 | ||
101 | - List<InventoryTransaction> shipmentHeaders = new ArrayList<>(); | ||
102 | - shipmentHeaders.addAll(inventoryTransactions); | ||
103 | - shipmentHeaders.removeIf(Inventory -> Inventory.getType() != 20); | ||
104 | - LinkedHashMap<String, String> list = new LinkedHashMap<>(); | ||
105 | - | ||
106 | - for (int i = 6; i >= 0; i--) { | ||
107 | - String today = new SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * i).toString(); | ||
108 | - List<InventoryTransaction> collect = shipmentHeaders.stream() | ||
109 | - .filter(shipmentHeader -> new SimpleDateFormat("yyyy-MM-dd").format(shipmentHeader.getCreateTime()).toString().contains(today)) | ||
110 | - .collect(Collectors.toList()); | ||
111 | - if (collect.size() != 0) { | ||
112 | - BigDecimal sum = new BigDecimal(0); | ||
113 | - for (InventoryTransaction item : collect) { | ||
114 | - sum = sum.add(item.getQty()); | ||
115 | - } | ||
116 | - list.put(today, String.valueOf(sum)); | ||
117 | - } else { | ||
118 | - list.put(today, "0"); | ||
119 | - } | ||
120 | - } | ||
121 | - | ||
122 | - // 查询入库单的7天入库量 | ||
123 | - List<InventoryTransaction> receiptHeaders = new ArrayList<>(); | ||
124 | - receiptHeaders.addAll(inventoryTransactions); | ||
125 | - receiptHeaders.removeIf(Inventory -> Inventory.getType() != 10); | ||
126 | - LinkedHashMap<String, String> list2 = new LinkedHashMap<>(); | 105 | + public Result<String> deliveringAmount(HttpServletRequest request) throws ParseException, InterruptedException, ExecutionException, TimeoutException { |
106 | + Long dateTime = new Date().getTime(); | ||
107 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
108 | + LinkedHashMap<String, Future<BigDecimal>> shipmentQuantityMap = new LinkedHashMap<String, Future<BigDecimal>>(); | ||
109 | + LinkedHashMap<String, Future<BigDecimal>> receiptQuantityMap = new LinkedHashMap<String, Future<BigDecimal>>(); | ||
110 | + // 查询出库单的7天出库量/入库量 | ||
127 | for (int i = 6; i >= 0; i--) { | 111 | for (int i = 6; i >= 0; i--) { |
128 | - List<InventoryTransaction> receiptHeadersCop = receiptHeaders; | ||
129 | - String today = new SimpleDateFormat("yyyy-MM-dd").format(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * i).toString(); | ||
130 | - List<InventoryTransaction> collect = receiptHeadersCop.stream() | ||
131 | - .filter(ReceiptHeader -> new SimpleDateFormat("yyyy-MM-dd").format(ReceiptHeader.getCreateTime()).toString().contains(today)) | ||
132 | - .collect(Collectors.toList()); | ||
133 | - if (collect.size() != 0) { | ||
134 | - BigDecimal sum = new BigDecimal(0); | ||
135 | - for (InventoryTransaction item : collect) { | ||
136 | - sum = sum.add(item.getQty()); | ||
137 | - } | ||
138 | - list2.put(today, String.valueOf(sum)); | ||
139 | - } else { | ||
140 | - list2.put(today, "0"); | ||
141 | - } | 112 | + String startTime = simpleDateFormat.format(dateTime - (1000 * 60 * 60 * 24) * i); |
113 | + String endTime = simpleDateFormat.format(DateUtil.offsetDay(simpleDateFormat.parse(startTime), 1)); | ||
114 | + shipmentQuantityMap.put(startTime, | ||
115 | + inventoryTransactionService.asyncCalculateInventory(startTime, endTime, QuantityConstant.INVENTORY_TRANSACTION_SHIPMENT)); | ||
116 | + receiptQuantityMap.put(startTime, | ||
117 | + inventoryTransactionService.asyncCalculateInventory(startTime, endTime, QuantityConstant.INVENTORY_TRANSACTION_RECEIPT)); | ||
142 | } | 118 | } |
143 | - | ||
144 | Option option = new Option(); | 119 | Option option = new Option(); |
145 | option.tooltip().trigger(Trigger.axis).axisPointer().type(PointerType.cross); | 120 | option.tooltip().trigger(Trigger.axis).axisPointer().type(PointerType.cross); |
146 | option.grid().setLeft("3%"); | 121 | option.grid().setLeft("3%"); |
@@ -158,17 +133,17 @@ public class HomePageViewServiceImpl implements HomePageViewService { | @@ -158,17 +133,17 @@ public class HomePageViewServiceImpl implements HomePageViewService { | ||
158 | axis.boundaryGap(false); | 133 | axis.boundaryGap(false); |
159 | Line line = new Line(); | 134 | Line line = new Line(); |
160 | line.setName("发货量"); | 135 | line.setName("发货量"); |
161 | - for (String key : list.keySet()) { | 136 | + for (String key : shipmentQuantityMap.keySet()) { |
162 | Object o1 = key; | 137 | Object o1 = key; |
163 | - Object o2 = list.get(key); | 138 | + Object o2 = shipmentQuantityMap.get(key).get(10000, TimeUnit.MILLISECONDS); |
164 | axis.data().add(o1); | 139 | axis.data().add(o1); |
165 | line.data().add(o2); | 140 | line.data().add(o2); |
166 | } | 141 | } |
167 | Line line2 = new Line(); | 142 | Line line2 = new Line(); |
168 | line2.setName("收货量"); | 143 | line2.setName("收货量"); |
169 | - for (String key : list2.keySet()) { | 144 | + for (String key : receiptQuantityMap.keySet()) { |
170 | Object o1 = key; | 145 | Object o1 = key; |
171 | - Object o2 = list2.get(key); | 146 | + Object o2 = receiptQuantityMap.get(key).get(10000, TimeUnit.MILLISECONDS); |
172 | line2.data().add(o2); | 147 | line2.data().add(o2); |
173 | } | 148 | } |
174 | option.setxAxis(Arrays.asList(axis)); | 149 | option.setxAxis(Arrays.asList(axis)); |
@@ -346,7 +321,7 @@ public class HomePageViewServiceImpl implements HomePageViewService { | @@ -346,7 +321,7 @@ public class HomePageViewServiceImpl implements HomePageViewService { | ||
346 | LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper = Wrappers.lambdaQuery(); | 321 | LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper = Wrappers.lambdaQuery(); |
347 | HuahengJwtUtil.setWarehouseCode(inventoryTransactionLambdaQueryWrapper, InventoryTransaction.class, request); | 322 | HuahengJwtUtil.setWarehouseCode(inventoryTransactionLambdaQueryWrapper, InventoryTransaction.class, request); |
348 | inventoryTransactionLambdaQueryWrapper.select(InventoryTransaction::getType, InventoryTransaction::getQty).gt(InventoryTransaction::getCreateTime, today); | 323 | inventoryTransactionLambdaQueryWrapper.select(InventoryTransaction::getType, InventoryTransaction::getQty).gt(InventoryTransaction::getCreateTime, today); |
349 | - List<InventoryTransaction> inventoryTransactions = inventoryTransactionServiceImpl.list(inventoryTransactionLambdaQueryWrapper); | 324 | + List<InventoryTransaction> inventoryTransactions = inventoryTransactionService.list(inventoryTransactionLambdaQueryWrapper); |
350 | BigDecimal receiptQty = BigDecimal.ZERO; | 325 | BigDecimal receiptQty = BigDecimal.ZERO; |
351 | BigDecimal shipmentQty = BigDecimal.ZERO; | 326 | BigDecimal shipmentQty = BigDecimal.ZERO; |
352 | 327 |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/inventory/inventoryTransaction/service/IInventoryTransactionService.java
@@ -3,7 +3,10 @@ package org.jeecg.modules.wms.inventory.inventoryTransaction.service; | @@ -3,7 +3,10 @@ package org.jeecg.modules.wms.inventory.inventoryTransaction.service; | ||
3 | import com.baomidou.mybatisplus.extension.service.IService; | 3 | import com.baomidou.mybatisplus.extension.service.IService; |
4 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; | 4 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; |
5 | 5 | ||
6 | +import java.math.BigDecimal; | ||
7 | +import java.text.ParseException; | ||
6 | import java.util.List; | 8 | import java.util.List; |
9 | +import java.util.concurrent.Future; | ||
7 | 10 | ||
8 | /** | 11 | /** |
9 | * @Description: 库存交易记录 | 12 | * @Description: 库存交易记录 |
@@ -14,5 +17,7 @@ import java.util.List; | @@ -14,5 +17,7 @@ import java.util.List; | ||
14 | public interface IInventoryTransactionService extends IService<InventoryTransaction> { | 17 | public interface IInventoryTransactionService extends IService<InventoryTransaction> { |
15 | 18 | ||
16 | boolean batchSave(List<InventoryTransaction> inventoryTransactionList); | 19 | boolean batchSave(List<InventoryTransaction> inventoryTransactionList); |
20 | + | ||
21 | + Future<BigDecimal> asyncCalculateInventory(String startTime, String endTime, Integer type) throws ParseException; | ||
17 | 22 | ||
18 | } | 23 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/inventory/inventoryTransaction/service/impl/InventoryTransactionServiceImpl.java
@@ -3,11 +3,18 @@ package org.jeecg.modules.wms.inventory.inventoryTransaction.service.impl; | @@ -3,11 +3,18 @@ package org.jeecg.modules.wms.inventory.inventoryTransaction.service.impl; | ||
3 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; | 3 | import org.jeecg.modules.wms.inventory.inventoryTransaction.entity.InventoryTransaction; |
4 | import org.jeecg.modules.wms.inventory.inventoryTransaction.mapper.InventoryTransactionMapper; | 4 | import org.jeecg.modules.wms.inventory.inventoryTransaction.mapper.InventoryTransactionMapper; |
5 | import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; | 5 | import org.jeecg.modules.wms.inventory.inventoryTransaction.service.IInventoryTransactionService; |
6 | +import org.springframework.scheduling.annotation.Async; | ||
7 | +import org.springframework.scheduling.annotation.AsyncResult; | ||
6 | import org.springframework.stereotype.Service; | 8 | import org.springframework.stereotype.Service; |
7 | 9 | ||
10 | +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||
11 | +import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||
8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 12 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
9 | 13 | ||
14 | +import java.math.BigDecimal; | ||
15 | +import java.text.ParseException; | ||
10 | import java.util.List; | 16 | import java.util.List; |
17 | +import java.util.concurrent.Future; | ||
11 | 18 | ||
12 | /** | 19 | /** |
13 | * @Description: 库存交易记录 | 20 | * @Description: 库存交易记录 |
@@ -22,4 +29,15 @@ public class InventoryTransactionServiceImpl extends ServiceImpl<InventoryTransa | @@ -22,4 +29,15 @@ public class InventoryTransactionServiceImpl extends ServiceImpl<InventoryTransa | ||
22 | public boolean batchSave(List<InventoryTransaction> inventoryTransactionList) { | 29 | public boolean batchSave(List<InventoryTransaction> inventoryTransactionList) { |
23 | return this.saveBatch(inventoryTransactionList); | 30 | return this.saveBatch(inventoryTransactionList); |
24 | } | 31 | } |
32 | + | ||
33 | + @Async | ||
34 | + @Override | ||
35 | + public Future<BigDecimal> asyncCalculateInventory(String startTime, String endTime, Integer type) { | ||
36 | + LambdaQueryWrapper<InventoryTransaction> inventoryTransactionLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
37 | + inventoryTransactionLambdaQueryWrapper.select(InventoryTransaction::getCreateTime, InventoryTransaction::getQty, InventoryTransaction::getType) | ||
38 | + .ge(InventoryTransaction::getCreateTime, startTime).lt(InventoryTransaction::getCreateTime, endTime).eq(InventoryTransaction::getType, type); | ||
39 | + List<InventoryTransaction> inventoryTransactions = list(inventoryTransactionLambdaQueryWrapper); | ||
40 | + BigDecimal shipmentResult = inventoryTransactions.stream().map(InventoryTransaction::getQty).reduce(BigDecimal.ZERO, BigDecimal::add); | ||
41 | + return new AsyncResult<>(shipmentResult); | ||
42 | + } | ||
25 | } | 43 | } |