Commit b7332f33 by zhangtw

入库导入直接确定入库

首页入库统计Top10改成已入库的物料
修改了库存unitWeight为Double(与表对应)
parent 9c9e7e00
......@@ -89,14 +89,18 @@ public class InboundOrdersController extends BaseController
inboundItem.setPackageWeight(inboundItem.getWeight() * (inboundItem.getActualQuantity() / inboundItem.getActualPackages()));
inboundItem.setUnitWeight(inboundItem.getWeight() * (inboundItem.getActualQuantity() / inboundItem.getActualPackages()));
inboundItem.setLabelColorName((String) colorDictMap.get(inboundItem.getLabelColor()+""));
if (inboundItem.getOrderStatus() == 1) {
inboundItem.setRelocation(inboundItem.getRemark());
}else if (inboundItem.getOrderStatus() == 2) {
inboundItem.setFinishedLocation(inboundItem.getRemark());
}else if (inboundItem.getOrderStatus() == 3) {
inboundItem.setRemarkTrdc(inboundItem.getRemark());
inboundItem.setFinishedSystemNo(inboundItem.getSystemNo());
inboundItem.setFinishedOrderId(inboundItem.getOrderId());
switch (inboundItem.getOrderTypeId()) {
case "1":
inboundItem.setRelocation(inboundItem.getRemark());
break;
case "2":
inboundItem.setFinishedLocation(inboundItem.getRemark());
break;
case "3":
inboundItem.setRemarkTrdc(inboundItem.getRemark());
inboundItem.setFinishedSystemNo(inboundItem.getSystemNo());
inboundItem.setFinishedOrderId(inboundItem.getOrderId());
break;
}
}
}
......
......@@ -275,7 +275,7 @@ public class InventoryController extends BaseController
inventory.setLocationId(location.getId());
inventory.setQuantity(qty == null ? 0 : qty.longValue());
inventory.setLockedQuantity(0L);
inventory.setUnitWeight(unitWeight == null ? null : Math.round(unitWeight));
inventory.setUnitWeight(unitWeight);
inventory.setTotalWeight(totalWeight == null ? null : Math.round(totalWeight));
inventory.setInventoryStatus(1L);
inventory.setIsUsed(1L);
......
......@@ -74,7 +74,7 @@ public class InboundOrderItems extends BaseEntity
/** 单价 */
@Excel(name = "单价")
private Long unitPrice;
private Double unitPrice;
/** 状态1-待收货 2-部分收货 3-已完成 暂无用 */
// @Excel(name = "状态")
......@@ -106,6 +106,10 @@ public class InboundOrderItems extends BaseEntity
/** 排序号 */
// @Excel(name = "排序号")
private String updateUserCode;
/** 单件重量 */
private Double packageWeight;
/** 单位重量 */
private Double unitWeight;
public void setId(String id)
{
......@@ -237,14 +241,12 @@ public class InboundOrderItems extends BaseEntity
return voucherNumber;
}
public void setUnitPrice(Long unitPrice)
{
this.unitPrice = unitPrice;
public Double getUnitPrice() {
return unitPrice;
}
public Long getUnitPrice()
{
return unitPrice;
public void setUnitPrice(Double unitPrice) {
this.unitPrice = unitPrice;
}
public void setItemStatus(Long itemStatus)
......@@ -341,6 +343,22 @@ public class InboundOrderItems extends BaseEntity
this.labelQuantity = labelQuantity;
}
public Double getUnitWeight() {
return unitWeight;
}
public void setUnitWeight(Double unitWeight) {
this.unitWeight = unitWeight;
}
public Double getPackageWeight() {
return packageWeight;
}
public void setPackageWeight(Double packageWeight) {
this.packageWeight = packageWeight;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
......
......@@ -72,7 +72,7 @@ public class Inventory extends BaseEntity
/** 单位重量 */
@Excel(name = "单位重量")
private Long unitWeight;
private Double unitWeight;
/** 总重量 暂无用 */
@Excel(name = "总重量 暂无用")
......@@ -181,4 +181,23 @@ public class Inventory extends BaseEntity
private Double unitPrice;
private String inboundOrderId;
public Inventory() {
}
/**
* 入库导入批量新增库存映射字段
* */
public Inventory(Long inventoryType, String orderId,String materialId, String batchId, String warehousesId, String locationId, String ownerId, Long quantity, Double unitWeight, Long inventoryStatus, Double unitPrice) {
this.inventoryType = inventoryType;
this.orderId = orderId;
this.materialId = materialId;
this.batchId = batchId;
this.warehousesId = warehousesId;
this.locationId = locationId;
this.ownerId = ownerId;
this.quantity = quantity;
this.unitWeight = unitWeight;
this.inventoryStatus = inventoryStatus;
this.unitPrice = unitPrice;
}
}
......@@ -187,4 +187,6 @@ public class InboundItemsTO extends BaseEntity {
private String updateUserCode;
private Integer orderStatus;
private String orderTypeId;
}
\ No newline at end of file
......@@ -12,6 +12,7 @@ import com.ruoyi.inventory.domain.*;
import com.ruoyi.inventory.domain.TO.InboundItemsTO;
import com.ruoyi.inventory.domain.vo.InboundMaterialTotalVO;
import com.ruoyi.inventory.mapper.*;
import com.ruoyi.inventory.service.IInventoryService;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
......@@ -48,7 +49,8 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
private WarehousesMapper warehousesMapper;
@Autowired
private StorageLocationsMapper storageLocationsMapper;
@Autowired
private IInventoryService iInventoryService;
private static final Logger log = LoggerFactory.getLogger(InboundOrdersServiceImpl.class);
/**
......@@ -293,7 +295,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
List<T> voList = entry.getValue();
InboundOrders mainDO = null;
List<InboundOrderItems> itemDOList = new ArrayList<>();
List<Inventory> inventoryList = new ArrayList<>();
try {
// 4.1 处理主表(每个入库单号只处理一次主表)
T firstVO = voList.get(0); // 取第一条VO的主表信息
......@@ -344,7 +346,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
mainDO.setSortNo(0L);
}
if (mainDO.getOrderStatus() == null) {
mainDO.setOrderStatus(1L); // 默认草稿状态
mainDO.setOrderStatus(2L); // 默认草稿状态
}
// ========== 货主查询(反射获取ownerId) ==========
......@@ -376,6 +378,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
for (T vo : voList) {
try {
InboundOrderItems itemDO = new InboundOrderItems();
// 反射复制子表字段(物料相关)
BeanUtils.copyProperties(vo, itemDO,
"orderId", "systemNo", "orderTypeId", "batchId"); // 排除主表字段
......@@ -470,6 +473,20 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
itemDO.setLocationId(locationId);
}
itemDOList.add(itemDO);
Inventory inventoryDO = new Inventory(
Long.parseLong(mainDO.getOrderTypeId()),
orderId,
itemDO.getMaterialId(),
batchId,
itemDO.getWarehouseId(),
itemDO.getLocationId(),
mainDO.getOwnerId(),
itemDO.getActualQuantity(),
itemDO.getPackageWeight() / itemDO.getActualPackages(),
1L,
itemDO.getUnitPrice()
);
inventoryList.add(inventoryDO);
} catch (Exception e) {
// 单个明细失败:仅统计,不影响整单
totalItemFailure++;
......@@ -492,10 +509,12 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
// 4.3 批量插入明细
if (!CollectionUtils.isEmpty(itemDOList)) {
int itemSuccess = inboundOrdersMapper.batchInboundOrderItems(itemDOList);
if (itemSuccess != itemDOList.size()) {
int inventorySuccess = iInventoryService.insertInventoryList(inventoryList);
if (itemSuccess != itemDOList.size() && itemSuccess != inventorySuccess) {
// 批量插入部分失败,主动回滚事务
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
throw new ServiceException("明细批量插入失败,成功" + itemSuccess + "条,总" + itemDOList.size() + "条");
}
totalItemSuccess += itemSuccess;
successMsg.append(String.format("入库单号【%s】成功导入%d条物料明细;\n", orderId, itemSuccess));
......@@ -507,7 +526,7 @@ public class InboundOrdersServiceImpl implements IInboundOrdersService
totalItemFailure += voList.size();
failureMsg.append(String.format("入库单号【%s】处理失败:%s;\n", orderId, e.getMessage()));
// 打印异常栈,方便调试
log.error("导入入库单【{}】失败", orderId, e);
log.error("导入【{}】批次的入库单【{}】失败", orderId, batchId, e);
// 整单失败回滚
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
}
......
......@@ -94,7 +94,7 @@ public class InventoryServiceImpl implements IInventoryService
}
/**
* 批量库存
* 批量新增库存
*
* @param inventoryList 库存
* @return 结果
......@@ -108,6 +108,7 @@ public class InventoryServiceImpl implements IInventoryService
inventory.setId(UUID.randomUUID().toString());
inventory.setCreateBy(SystemUtils.getUserName());
inventory.setCreateUserCode(SystemUtils.getUserName());
inventory.setIsUsed(1L);
createInventoryInboundLog(inventory,inventory.getQuantity(),inventory.getCreateUserCode(),inventory.getCreateTime());
count = inventoryMapper.insertInventory(inventory);
}
......@@ -224,10 +225,17 @@ public class InventoryServiceImpl implements IInventoryService
// 新建实体,查看该物料在库存中数量,避免其他条件干扰
Inventory inventoryBefore = new Inventory();
inventoryBefore.setMaterialId(inventory.getMaterialId());
inventoryBefore = inventoryMapper.selectInventory(inventoryBefore);
if (inventoryBefore == null) {
List<Inventory> inventoryList = inventoryMapper.selectInventoryList(inventoryBefore);
if (inventoryList == null) {
inventoryBefore = new Inventory();
inventoryBefore.setQuantity(0L);
}else{
Long quantity = 0L;
for (Inventory inventoryItem : inventoryList) {
quantity += inventoryItem.getQuantity();
}
inventoryBefore.setQuantity(quantity);
}
transactions.setQuantityBefore(inventoryBefore.getQuantity());
transactions.setQuantityAfter(inventory.getQuantity() + addQty);
......
......@@ -253,36 +253,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result column="total_money" property="totalMoney" jdbcType="DECIMAL"/>
</resultMap>
<select id="countInboundMaterialQuantity" resultMap="InboundMaterialTotalResultMap" parameterType="String">
SELECT t.material_name, t.total_quantity
FROM (
SELECT m.material_name,
COALESCE(SUM(ioi.actual_quantity), 0) as total_quantity
FROM materials as m
LEFT JOIN inbound_order_items as ioi ON m.id = ioi.material_id
LEFT JOIN inbound_orders as io ON io.id = ioi.inbound_order_id AND io.order_status = 2
WHERE m.is_used = 1 AND m.is_active = 1
GROUP BY m.id, m.material_name
ORDER BY total_quantity DESC
LIMIT 10
) t
ORDER BY t.total_quantity ASC;
select t.material_name,t.total_quantity from (
SELECT
m.material_name,
COALESCE(SUM(ioi.actual_quantity), 0) AS total_quantity
FROM materials AS m
LEFT JOIN (
SELECT ioi.material_id, ioi.actual_quantity
FROM
inbound_order_items AS ioi
INNER JOIN
inbound_orders AS io
ON
io.id = ioi.inbound_order_id
AND
io.order_status = 2
) AS ioi ON m.id = ioi.material_id
WHERE
m.is_used = 1
AND
m.is_active = 1
GROUP BY
m.id, m.material_name
ORDER BY
total_quantity DESC
) as t
order by total_quantity asc
</select>
<select id="countInboundMaterialMoney" resultMap="InboundMaterialTotalResultMap" parameterType="String">
select t.material_name,t.total_money
from(
select m.material_name,
COALESCE(sum(ioi.actual_quantity * ioi.unit_price), 0) as total_money
from materials as m
left join inbound_order_items as ioi
on m.id = ioi.material_id
left join inbound_orders as io
on io.id = ioi.inbound_order_id
and io.order_status = 2
where m.is_used = 1 and m.is_active = 1
group by m.id
order by total_money desc
limit 10
) t
SELECT
m.material_name,
COALESCE(SUM(ioi.actual_quantity * ioi.unit_price), 0) AS total_money
FROM materials AS m
LEFT JOIN (
SELECT ioi.material_id, ioi.actual_quantity,ioi.unit_price
FROM
inbound_order_items AS ioi
INNER JOIN
inbound_orders AS io
ON
io.id = ioi.inbound_order_id
AND
io.order_status = 2
) AS ioi ON m.id = ioi.material_id
WHERE
m.is_used = 1
AND
m.is_active = 1
GROUP BY
m.id, m.material_name
ORDER BY
total_money DESC
) as t
order by total_money asc
</select>
......@@ -294,7 +318,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
m.total_weight, sl.location_name, ioi.warehouse_id,
ioi.label_color, ioi.voucher_number, m.storage_temperature,
m.hazard_id, io.order_id, io.system_no, io.owner_id,
ioi.label_quantity, io.order_type, io.order_status, ioi.remark
ioi.label_quantity, io.order_type, io.order_type_id, ioi.remark
from materials as m
inner join inbound_order_items as ioi on ioi.material_id = m.id
inner join inbound_orders as io on ioi.inbound_order_id = io.id
......@@ -333,6 +357,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result column="owner_id" property="ownerId" />
<result column="label_quantity" property="labelQuantity" />
<result column="order_type" property="orderType" />
<result column="order_status" property="orderStatus"/>
<result column="order_type_id" property="orderTypeId"/>
</resultMap>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论