|
|
|
@ -12,10 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.boot.test.context.SpringBootTest; |
|
|
|
import org.springframework.test.context.junit4.SpringRunner; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.*; |
|
|
|
|
|
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|
|
|
@ -35,6 +32,8 @@ public class LineChartForInventoryTest { |
|
|
|
* @param id 带查询库存id |
|
|
|
*/ |
|
|
|
public RestResponse getInventoryApplication(Integer id) { |
|
|
|
// 获取当前物料的库存数据
|
|
|
|
Inventory inventoryById = materialService.findInventoryById(id); |
|
|
|
// 获取本月至今的日期
|
|
|
|
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow(); |
|
|
|
// 获取至今的日期名称
|
|
|
|
@ -43,21 +42,61 @@ public class LineChartForInventoryTest { |
|
|
|
List<Long> dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class); |
|
|
|
// 获取当前物料的入库总额与数量
|
|
|
|
Map<String, Object> seriesForApplicationIn = depositoryRecordService.getApplicationByMaterial(id, dayTimeSpaces, 1); |
|
|
|
|
|
|
|
Object amountItemForIn = seriesForApplicationIn.get("amountItem"); |
|
|
|
Object countItemForIn = seriesForApplicationIn.get("countItem"); |
|
|
|
// 将入库总额项目转为map类型
|
|
|
|
Map<String, Object> countItemForInMapString = ObjectFormatUtil.objToMap(countItemForIn, String.class, Object.class); |
|
|
|
// 获取入库总额data并转为list类型
|
|
|
|
List<Double> amountListForIn = ObjectFormatUtil.objToList(countItemForInMapString.get("data"), Double.class); |
|
|
|
|
|
|
|
// 获取当前物料的出库总额与数量
|
|
|
|
Map<String, Object> seriesForApplicationOut = depositoryRecordService.getApplicationByMaterial(id, dayTimeSpaces, 2); |
|
|
|
|
|
|
|
Object amountItemForOut = seriesForApplicationOut.get("amountItem"); |
|
|
|
Object countItemForOut = seriesForApplicationOut.get("countItem"); |
|
|
|
|
|
|
|
// 将出库总额项目转为map类型
|
|
|
|
Map<String, Object> countItemForOutMapString = ObjectFormatUtil.objToMap(countItemForOut, String.class, Object.class); |
|
|
|
// 获取出库总额data并转为list类型
|
|
|
|
List<Double> amountListForOut = ObjectFormatUtil.objToList(countItemForOutMapString.get("data"), Double.class); |
|
|
|
// 定义库存数量列表
|
|
|
|
List<Object> inventoryCountList = new ArrayList<>(); |
|
|
|
// 定义库存总额列表
|
|
|
|
List<Object> inventoryAmountList = new ArrayList<>(); |
|
|
|
// 获取当前库存
|
|
|
|
double inventory = inventoryById.getQuantity() / 100.0; |
|
|
|
// 获取当前物料单价
|
|
|
|
Double price = inventoryById.getPrice(); |
|
|
|
// 获取当前物料总额
|
|
|
|
double amount = ObjectFormatUtil.multiply(inventory, price); |
|
|
|
// 添加
|
|
|
|
inventoryAmountList.add(amount); |
|
|
|
inventoryCountList.add(inventory); |
|
|
|
for (int i = amountListForOut.size() - 1; i > 0; i--) { |
|
|
|
// 获取当前日期下的库存 库存 = 库存 + 出库 - 入库
|
|
|
|
inventory = ObjectFormatUtil.subtract(ObjectFormatUtil.sum(inventory, amountListForOut.get(i)), amountListForIn.get(i)); |
|
|
|
inventoryCountList.add(inventory); |
|
|
|
inventoryAmountList.add(ObjectFormatUtil.multiply(inventory, price)); |
|
|
|
} |
|
|
|
// 反转
|
|
|
|
Collections.reverse(inventoryAmountList); |
|
|
|
Collections.reverse(inventoryCountList); |
|
|
|
Map<String, Object> countItemForInventory = depositoryRecordService.createStackedAreaChartSeriesItem("count", inventoryCountList); |
|
|
|
Map<String, Object> amountItemForInventory = depositoryRecordService.createStackedAreaChartSeriesItem("count", inventoryAmountList); |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
result.put("amountItemForIn",amountItemForIn); |
|
|
|
result.put("countItemForIn",countItemForIn); |
|
|
|
result.put("amountItemForOut",amountItemForOut); |
|
|
|
result.put("countItemForOut",countItemForOut); |
|
|
|
result.put("dayNames",dayNames); |
|
|
|
|
|
|
|
result.put("amountItemForIn", amountItemForIn); |
|
|
|
result.put("countItemForIn", countItemForIn); |
|
|
|
result.put("amountItemForOut", amountItemForOut); |
|
|
|
result.put("countItemForOut", countItemForOut); |
|
|
|
Map<String, List<String>> legendItem = new HashMap<>(); |
|
|
|
List<String> legends = new ArrayList<>(); |
|
|
|
legends.add("count"); |
|
|
|
legends.add("amount"); |
|
|
|
legendItem.put("data", legends); |
|
|
|
result.put("legend", legendItem); |
|
|
|
result.put("dayNames", dayNames); |
|
|
|
result.put("countItemForInventory",countItemForInventory); |
|
|
|
result.put("amountItemForInventory",amountItemForInventory); |
|
|
|
return new RestResponse(result); |
|
|
|
} |
|
|
|
|
|
|
|
|