Commit 0cee0a3f by yubin

修库存 出库单排行榜

parent 7494b209
......@@ -4,11 +4,9 @@ import java.util.*;
import java.util.stream.Collectors;
import com.ruoyi.common.annotation.SerialExecution;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.inventory.domain.InboundOrderItems;
import com.ruoyi.inventory.domain.OutboundOrderItems;
import com.ruoyi.inventory.domain.OutboundOrderLog;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.inventory.domain.*;
import com.ruoyi.inventory.domain.TO.StocktakeItemsTo;
import com.ruoyi.inventory.domain.vo.InventoryExceedWarnVO;
import com.ruoyi.inventory.domain.vo.InventorySummaryVO;
......@@ -20,7 +18,6 @@ import org.apache.commons.lang3.SystemUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.inventory.mapper.InventoryMapper;
import com.ruoyi.inventory.domain.Inventory;
import com.ruoyi.inventory.service.IInventoryService;
/**
......@@ -38,6 +35,12 @@ public class InventoryServiceImpl implements IInventoryService
private OutboundOrderLogMapper outboundOrderLogMapper;;
@Autowired
private OutboundOrderItemsMapper outboundOrderItemsMapper;
@Autowired
private OutboundOrdersServiceImpl outboundOrderMapper;
@Autowired
private InventoryTransactionsServiceImpl insertInventoryTransactions;
/**
......@@ -146,11 +149,36 @@ public class InventoryServiceImpl implements IInventoryService
OutboundOrderLog outboundOrderLog = outboundOrderLogMapper.selectOutboundOrderLogById(outboundOrderItem.getId());
Inventory inventory =inventoryMapper.selectInventoryById(outboundOrderLog.getInventoryId());
String quantity = String.valueOf(inventory.getQuantity());
inventory.setQuantity(inventory.getQuantity()-outboundOrderItem.getActualQuantity());
if (inventory.getQuantity()==0){
inventory.setInventoryStatus(0l);
}
updateInventory(inventory);
// 库存操作表插入数据
InventoryTransactions transactions = new InventoryTransactions();
transactions.setId(IdUtils.simpleUUID());
transactions.setTransactionType(2L);// 事务类型-盘点
transactions.setInventoryId(inventory.getId()); // 库存表Id
transactions.setReferenceId(outboundOrderItem.getOutboundOrderId()); //关联单号,相当于主记录-盘点主表
transactions.setReferenceItemId(outboundOrderItem.getId()); // 盘点子表id
transactions.setMaterialId(outboundOrderItem.getMaterialId());
transactions.setWarehouseId(outboundOrderItem.getWarehouseId());
transactions.setLocationId(outboundOrderItem.getLocationId());
OutboundOrders outboundOrders = outboundOrderMapper.selectOutboundOrdersById(outboundOrderItem.getWarehouseId());
transactions.setOwnerId(outboundOrders.getOwnerId());
transactions.setQuantityBefore(Long.valueOf(quantity));// 变更前数量
transactions.setQuantityAfter(inventory.getQuantity());// 变更后数量
transactions.setQuantityChange(outboundOrderItem.getActualQuantity());
Date nowDate = new Date();
transactions.setTransactionTime(nowDate);
transactions.setOperatedBy(SystemUtils.getUserName());
int inventoryTransactions = insertInventoryTransactions.insertInventoryTransactions(transactions);
if (inventoryTransactions < 0) {
return -1;
}
}
RefreshInventory(inventoryIds);
}
......
......@@ -252,7 +252,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from materials as m
left join inbound_order_items as ioi
on m.id = ioi.material_id
left join inbound_order as io
left join inbound_orders as io
on io.id = ioi.inbound_order_id
and io.order_status = 2
group by m.id, m.material_name
......
......@@ -555,26 +555,29 @@ and inventory_status = '1'
<select id="selectInventoryTopTenByAmount" resultType="java.util.Map">
select
m.material_name as name,
sum(i.quantity)*i.unit_price as value
from inventory i
left join materials m on i.material_id = m.id
where i.is_used = 1 and i.unit_price >0 and i.last_inbound_time &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(i.quantity)*i.unit_price desc
m.material_name as name,
IFNULL(sum(i.quantity) * IFNULL(i.unit_price, 0), 0) as value
from materials m
left join inventory i on i.material_id = m.id
and i.is_used = 1
and i.unit_price > 0
and i.last_inbound_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.id, m.material_name
order by value desc, m.material_name asc
</select>
<!-- 按数量统计库存前10(含无入库记录的物料) -->
<select id="selectInventoryTopTenByQuantity" resultType="java.util.Map">
select
m.material_name as name,
sum(i.quantity) as value
from inventory i
left join materials m on i.material_id = m.id
where i.is_used = 1 and i.last_inbound_time &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(i.quantity) desc
m.material_name as name,
IFNULL(sum(i.quantity), 0) as value
from materials m
left join inventory i on i.material_id = m.id
and i.is_used = 1
and i.last_inbound_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.id, m.material_name
order by value desc, m.material_name asc
</select>
</mapper>
\ No newline at end of file
......@@ -308,29 +308,32 @@
<select id="SelectOutboundOrdersMaterialsTopTenByQuantity" resultType="java.util.Map">
select
m.material_name as name,
sum(ooi.actual_quantity) as value
from outbound_order_items ooi
left join materials m on ooi.material_id = m.id
where ooi.is_used = 1 and ooi.shipped_at &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and ooi.shipped_at &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(ooi.actual_quantity) desc
sum(IFNULL(ooi.actual_quantity, 0)) as value
from materials m
left join outbound_order_items ooi
on ooi.material_id = m.id
and ooi.is_used = 1
and ooi.shipped_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01 00:00:00')
and ooi.shipped_at &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01 00:00:00')
group by m.id, m.material_name
order by value desc
limit 10;
</select>
<select id="SelectOutboundOrdersMaterialsTopTenByAmount" resultType="java.util.Map">
select
m.material_name as name,
sum(ooi.actual_quantity)*ooi.unit_price as value
from outbound_order_items ooi
left join materials m on ooi.material_id = m.id
where ooi.is_used = 1 and ooi.shipped_at &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and ooi.shipped_at &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(ooi.actual_quantity) desc
limit 10;
m.material_name as name,
sum(IFNULL(ooi.actual_quantity, 0) * IFNULL(ooi.unit_price, 0)) as value
from materials m
left join outbound_order_items ooi
on ooi.material_id = m.id
and ooi.is_used = 1
and ooi.shipped_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01 00:00:00')
and ooi.shipped_at &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01 00:00:00')
group by m.id, m.material_name
order by value desc
limit 10;
</select>
<select id="outboundOrdersCount" resultType="String">
select count(*) from outbound_orders where is_used = 1 and order_status=2 and inbound_date &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and inbound_date &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论