2 changed files with 170 additions and 2 deletions
@ -1,4 +1,154 @@ |
|||||
package com.galaxis.rcs.inv; |
package com.galaxis.rcs.inv; |
||||
|
|
||||
|
import com.galaxis.rcs.common.entity.LccInvLpn; |
||||
|
import com.querydsl.core.util.StringUtils; |
||||
|
import org.clever.data.jdbc.DaoFactory; |
||||
|
import org.clever.data.jdbc.QueryDSL; |
||||
|
|
||||
|
import java.sql.Date; |
||||
|
|
||||
|
import static com.galaxis.rcs.common.query.QLccInvLpn.lccInvLpn; |
||||
|
import static com.galaxis.rcs.common.query.QLccInvLedger.lccInvLedger; |
||||
|
|
||||
public class InvManager { |
public class InvManager { |
||||
|
private static final QueryDSL queryDSL = DaoFactory.getQueryDSL(); |
||||
|
|
||||
|
/** |
||||
|
* 记录库存 |
||||
|
* @param envId 环境ID |
||||
|
* @param lpn 容器号 |
||||
|
* @param locCode 库位号 |
||||
|
* @param layerIndex 堆叠层 |
||||
|
* @param qty 数量 >0 增加数量 <0 减数量 |
||||
|
* @param qtyIn 入库数量 >0 减数量 <0 减数量 |
||||
|
* @param qtyOut 出库数量 >0 减数量 <0 减数量 |
||||
|
*/ |
||||
|
public static void invSave(Long envId, String lpn, String locCode, Integer layerIndex, int qty, int qtyIn, int qtyOut) { |
||||
|
if (envId == null || envId <= 0 |
||||
|
|| lpn == null || StringUtils.isNullOrEmpty(lpn) || lpn.equals("N/A") |
||||
|
|| locCode == null || StringUtils.isNullOrEmpty(locCode) || locCode.equals("N/A") |
||||
|
|| layerIndex == null || layerIndex < 0) { |
||||
|
throw new RuntimeException("库存记录时,关键参数值不对"); |
||||
|
} |
||||
|
if (qty == 0 && qtyIn == 0 && qtyOut == 0) { |
||||
|
throw new RuntimeException("库存记录时,变化数量不能都为0"); |
||||
|
} |
||||
|
if (qtyIn != 0 && qtyOut != 0) { |
||||
|
throw new RuntimeException("库存记录时,不能同时为入库和出库"); |
||||
|
} |
||||
|
if (qty > 1 || qty < -1) { |
||||
|
throw new RuntimeException("库存记录时,数量变化值只能为0、1、-1"); |
||||
|
} |
||||
|
if (qtyIn > 1 || qtyIn < -1) { |
||||
|
throw new RuntimeException("库存记录时,预占数量变化值只能为0、1、-1"); |
||||
|
} |
||||
|
if (qtyOut > 1 || qtyOut < -1) { |
||||
|
throw new RuntimeException("库存记录时,预扣数量变化值只能为0、1、-1"); |
||||
|
} |
||||
|
if (qty == 1 && qtyIn == 1) { |
||||
|
throw new RuntimeException("库存记录时,数量增加时不能增加预占数量"); |
||||
|
} |
||||
|
if (qty == -1 && qtyOut == 1) { |
||||
|
throw new RuntimeException("库存记录时,数量扣减时不能对其增加预扣"); |
||||
|
} |
||||
|
|
||||
|
LccInvLpn lccInvLpnData = queryDSL.select(lccInvLpn) |
||||
|
.from(lccInvLpn) |
||||
|
.where(lccInvLpn.envId.eq(envId).and(lccInvLpn.locCode.eq(locCode)).and(lccInvLpn.lpn.eq(lpn))) |
||||
|
.fetchFirst(); |
||||
|
|
||||
|
if (lccInvLpnData != null) { |
||||
|
if ((lccInvLpnData.getQty() == 1 && qtyIn > 0) || (lccInvLpnData.getQty() == 1 && qty > 0)) { |
||||
|
throw new RuntimeException("库存记录时,当前货位有货, 不能放货或者准备放货"); |
||||
|
} else if ((lccInvLpnData.getQty() == 0 && qtyOut > 0) || (lccInvLpnData.getQty() == 0 && qty < 0)) { |
||||
|
throw new RuntimeException("库存记录时,当前货位无货, 不能取货或者准备取货"); |
||||
|
} else if (lccInvLpnData.getQtyIn() > 0 && qtyIn > 0) { |
||||
|
throw new RuntimeException("库存记录时,当前货位有预占, 不能准备放货"); |
||||
|
} else if (lccInvLpnData.getQtyOut() > 0 && qtyOut > 0) { |
||||
|
throw new RuntimeException("库存记录时,当前货位有预扣, 不能准备取货"); |
||||
|
} |
||||
|
} else { |
||||
|
if (qty < 0 || qtyIn < 0 || qtyOut < 0) { |
||||
|
throw new RuntimeException("没有找到原始库存,不能扣减数量"); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
queryDSL.beginTX(status -> { |
||||
|
if (lccInvLpnData != null) { |
||||
|
queryDSL.update(lccInvLpn) |
||||
|
.set(lccInvLpn.qty, lccInvLpn.qty.add(qty)) |
||||
|
.set(lccInvLpn.qtyIn, lccInvLpn.qtyIn.add(qtyIn)) |
||||
|
.set(lccInvLpn.qtyOut, lccInvLpn.qtyOut.add(qtyOut)) |
||||
|
.set(lccInvLpn.layerIndex, layerIndex) |
||||
|
// .set(lccInvLpn.updateAt, )
|
||||
|
.where(lccInvLpn.envId.eq(envId).and(lccInvLpn.locCode.eq(locCode)).and(lccInvLpn.lpn.eq(lpn))) |
||||
|
.execute(); |
||||
|
} else { |
||||
|
queryDSL.insert(lccInvLpn) |
||||
|
.set(lccInvLpn.envId, envId) |
||||
|
.set(lccInvLpn.lpn, lpn) |
||||
|
.set(lccInvLpn.locCode, locCode) |
||||
|
.set(lccInvLpn.layerIndex, layerIndex) |
||||
|
.set(lccInvLpn.qty, qty) |
||||
|
.set(lccInvLpn.qtyIn, qtyIn) |
||||
|
.set(lccInvLpn.qtyOut, qtyOut) |
||||
|
.execute(); |
||||
|
} |
||||
|
|
||||
|
// 记录账页
|
||||
|
queryDSL.insert(lccInvLedger) |
||||
|
.set(lccInvLedger.envId, envId) |
||||
|
.set(lccInvLedger.lpn, lpn) |
||||
|
.set(lccInvLedger.locCode, locCode) |
||||
|
.set(lccInvLedger.layerIndex, layerIndex) |
||||
|
.set(lccInvLedger.qtyChange, qty) |
||||
|
.set(lccInvLedger.qtyInChange, qtyIn) |
||||
|
.set(lccInvLedger.qtyOutChange, qtyOut) |
||||
|
.set(lccInvLedger.ledgerType, "记账") |
||||
|
.set(lccInvLedger.ledgerRemark, "N/A") |
||||
|
.execute(); |
||||
|
|
||||
|
// 删除所有数量预占预扣都为0的库存
|
||||
|
queryDSL.delete(lccInvLpn).where(lccInvLpn.qty.eq(0).and(lccInvLpn.qtyIn.eq(0)).and(lccInvLpn.qtyOut.eq(0))).execute(); |
||||
|
}); |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 记录库存 |
||||
|
* @param envId 环境ID |
||||
|
* @param lpn 容器号 |
||||
|
* @param locCode 库位号 |
||||
|
* @param qty 数量 >0 减数量 <0 减数量 |
||||
|
* @param qtyIn 入库数量 >0 减数量 <0 减数量 |
||||
|
* @param qtyOut 出库数量 >0 减数量 <0 减数量 |
||||
|
*/ |
||||
|
public static void invSave(Long envId, String lpn, String locCode, int qty, int qtyIn, int qtyOut) { |
||||
|
invSave(envId, lpn, locCode, 0, qty, qtyIn, qtyOut); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存库存 |
||||
|
* @param envId 环境ID |
||||
|
* @param lpn 容器号 |
||||
|
* @param locCode 库位号 |
||||
|
* @param layerIndex 堆叠层 |
||||
|
* @param qty 数量 >0 减数量 <0 减数量 |
||||
|
*/ |
||||
|
public static void invSave(Long envId, String lpn, String locCode, int layerIndex, int qty) { |
||||
|
invSave(envId, lpn, locCode, layerIndex, qty, 0, 0); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 保存库存 |
||||
|
* @param envId 环境ID |
||||
|
* @param lpn 容器号 |
||||
|
* @param locCode 库位号 |
||||
|
* @param qty 数量 >0 减数量 <0 减数量 |
||||
|
*/ |
||||
|
public static void invSave(Long envId, String lpn, String locCode, int qty) { |
||||
|
invSave(envId, lpn, locCode, 0, qty, 0, 0); |
||||
|
} |
||||
|
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue