18 changed files with 809 additions and 553 deletions
@ -0,0 +1,67 @@ |
|||||
|
package com.dreamchaser.depository_manage.entity; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* 拆单库存记录(视图) |
||||
|
*/ |
||||
|
@Data |
||||
|
public class SplitInventoryView { |
||||
|
/** |
||||
|
* 拆单库存id |
||||
|
*/ |
||||
|
private Integer id; |
||||
|
/** |
||||
|
* 拆单记录 |
||||
|
*/ |
||||
|
private Integer sid; |
||||
|
/** |
||||
|
* 库存库位映射id |
||||
|
*/ |
||||
|
private Integer mpId; |
||||
|
/** |
||||
|
* 拆单库存数 |
||||
|
*/ |
||||
|
private Integer siQuantity; |
||||
|
/** |
||||
|
* 拆单物料id |
||||
|
*/ |
||||
|
private Integer mid; |
||||
|
/** |
||||
|
* 所处仓库id |
||||
|
*/ |
||||
|
private Integer depositoryId; |
||||
|
/** |
||||
|
* 库存id |
||||
|
*/ |
||||
|
private Integer iid; |
||||
|
/** |
||||
|
* 库位id |
||||
|
*/ |
||||
|
private Integer pid; |
||||
|
/** |
||||
|
* 拆单记录状态 |
||||
|
*/ |
||||
|
private Integer sstate; |
||||
|
/** |
||||
|
* 当前拆单记录的进制 |
||||
|
*/ |
||||
|
private Integer scale; |
||||
|
/** |
||||
|
* 旧单位 |
||||
|
*/ |
||||
|
private String oldUnit ; |
||||
|
/** |
||||
|
* 新单位 |
||||
|
*/ |
||||
|
private String newUnit; |
||||
|
/** |
||||
|
* 物料名称 |
||||
|
*/ |
||||
|
private String mname ; |
||||
|
/** |
||||
|
* 仓库名称 |
||||
|
*/ |
||||
|
private String dname ; |
||||
|
|
||||
|
} |
||||
@ -1,111 +0,0 @@ |
|||||
package com.dreamchaser.depository_manage; |
|
||||
|
|
||||
import com.dreamchaser.depository_manage.entity.Inventory; |
|
||||
import com.dreamchaser.depository_manage.pojo.RestResponse; |
|
||||
import com.dreamchaser.depository_manage.service.DepositoryRecordService; |
|
||||
import com.dreamchaser.depository_manage.service.MaterialService; |
|
||||
import com.dreamchaser.depository_manage.utils.DateUtil; |
|
||||
import com.dreamchaser.depository_manage.utils.ObjectFormatUtil; |
|
||||
import org.junit.Test; |
|
||||
import org.junit.runner.RunWith; |
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||
import org.springframework.boot.test.context.SpringBootTest; |
|
||||
import org.springframework.test.context.junit4.SpringRunner; |
|
||||
|
|
||||
import java.util.*; |
|
||||
import java.util.concurrent.*; |
|
||||
|
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
|
||||
@RunWith(SpringRunner.class) |
|
||||
public class LineChartForInventoryTest { |
|
||||
|
|
||||
|
|
||||
@Autowired |
|
||||
private MaterialService materialService; |
|
||||
|
|
||||
@Autowired |
|
||||
private DepositoryRecordService depositoryRecordService; |
|
||||
|
|
||||
/** |
|
||||
* 用于获取当前物料的本月出入库记录 |
|
||||
* |
|
||||
* @param id 带查询库存id |
|
||||
*/ |
|
||||
public RestResponse getInventoryApplication(Integer id) { |
|
||||
// 获取当前物料的库存数据
|
|
||||
Inventory inventoryById = materialService.findInventoryById(id); |
|
||||
// 获取本月至今的日期
|
|
||||
Map<String, Object> monthBeginToNow = DateUtil.getMonthBeginToNow(); |
|
||||
// 获取至今的日期名称
|
|
||||
List<String> dayNames = ObjectFormatUtil.objToList(monthBeginToNow.get("dayName"), String.class); |
|
||||
// 获取至今的日期时间戳
|
|
||||
List<Long> dayTimeSpaces = ObjectFormatUtil.objToList(monthBeginToNow.get("dayTimeSpace"), Long.class); |
|
||||
dayTimeSpaces.add(Calendar.getInstance().getTimeInMillis()); |
|
||||
// 获取当前物料的入库总额与数量
|
|
||||
Map<String, Object> seriesForApplicationIn = depositoryRecordService.getApplicationByMaterial(id, dayTimeSpaces, 1,true,null); |
|
||||
|
|
||||
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,true,null); |
|
||||
|
|
||||
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); |
|
||||
System.out.println(countItemForIn); |
|
||||
System.out.println(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); |
|
||||
} |
|
||||
|
|
||||
|
|
||||
@Test |
|
||||
public void Test() { |
|
||||
getInventoryApplication(3537); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue