4 changed files with 261 additions and 0 deletions
@ -0,0 +1,24 @@ |
|||
package org.nl.wms.warehouse_management.enums; |
|||
|
|||
/** |
|||
* @author Liuyx |
|||
* @date 2025年05月23日 |
|||
* @desc 仓储常量 |
|||
*/ |
|||
public class IOSConstant { |
|||
|
|||
/** |
|||
* 更新库存状态:加可用 |
|||
*/ |
|||
public final static String UPDATE_IVT_TYPE_ADD_CANUSE = "1"; |
|||
|
|||
/** |
|||
* 更新库存状态:加冻结减可用 |
|||
*/ |
|||
public final static String UPDATE_IVT_TYPE_ADD_FROZEN = "2"; |
|||
|
|||
/** |
|||
* 更新库存状态:减冻结 |
|||
*/ |
|||
public final static String UPDATE_IVT_TYPE_SUB_FROZEN = "3"; |
|||
} |
@ -0,0 +1,42 @@ |
|||
package org.nl.wms.warehouse_management.enums; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.common.utils.MapOf; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 出入库枚举类 |
|||
* |
|||
* @author Liuxy |
|||
* @Date 2025/05/23 |
|||
*/ |
|||
@AllArgsConstructor |
|||
@Getter |
|||
public enum IOSEnum { |
|||
|
|||
// 更新库存类型
|
|||
UPDATE_IVT_TYPE(MapOf.of("入库", "1", "出库", "2")), |
|||
; |
|||
|
|||
private Map<String, String> code; |
|||
|
|||
public String code(String desc) { |
|||
String code = this.getCode().get(desc); |
|||
if (StringUtils.isNotEmpty(code)) { |
|||
return code; |
|||
} |
|||
throw new BadRequestException(this.name() + "对应类型" + desc + "未定义"); |
|||
} |
|||
|
|||
public String check(String code) { |
|||
for (Map.Entry<String, String> entry : this.getCode().entrySet()) |
|||
if (entry.getValue().equals("code")) { |
|||
return entry.getValue(); |
|||
} |
|||
throw new BadRequestException(this.name() + "对应类型" + code + "未定义"); |
|||
} |
|||
} |
@ -0,0 +1,190 @@ |
|||
package org.nl.wms.warehouse_management.service.util; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.NumberUtil; |
|||
import cn.hutool.core.util.ObjectUtil; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import org.nl.common.exception.BadRequestException; |
|||
import org.nl.common.utils.IdUtil; |
|||
import org.nl.common.utils.SecurityUtils; |
|||
import org.nl.wms.basedata_manage.service.IMdPbStoragevehicleextService; |
|||
import org.nl.wms.basedata_manage.service.dao.MdPbStoragevehicleext; |
|||
import org.nl.wms.warehouse_management.enums.IOSConstant; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
|
|||
/** |
|||
* @author Liuyx |
|||
* @date 2025年05月23日 |
|||
* @desc 更新库存工具类 |
|||
*/ |
|||
@Component |
|||
public class UpdateIvtUtils { |
|||
|
|||
/** |
|||
* 载具扩展属性服务 |
|||
*/ |
|||
@Autowired |
|||
private IMdPbStoragevehicleextService iMdPbStoragevehicleextService; |
|||
|
|||
/** |
|||
* 更新库存 |
|||
* @param where: { |
|||
* type: 1-加可用,2-加冻结减可用,3-减冻结 |
|||
* storagevehicle_code: 载具编码 |
|||
* material_id: 物料标识 |
|||
* pcsn: 批次 |
|||
* qty_unit_id: 计量单位标识 |
|||
* qty_unit_name: 计量单位名称 |
|||
* change_qty: 变动数量 |
|||
* remark: 备注 |
|||
* } |
|||
*/ |
|||
public void updateIvt(JSONObject where) { |
|||
// 数据校验
|
|||
checkData(where); |
|||
String type = where.getString("type"); |
|||
switch (type) { |
|||
case IOSConstant.UPDATE_IVT_TYPE_ADD_CANUSE : |
|||
// 加可用
|
|||
updateAddCanuseIvt(where); |
|||
break; |
|||
case IOSConstant.UPDATE_IVT_TYPE_ADD_FROZEN : |
|||
// 加冻结减可用
|
|||
updateAddFrozenIvt(where); |
|||
break; |
|||
case IOSConstant.UPDATE_IVT_TYPE_SUB_FROZEN : |
|||
// 减冻结
|
|||
updateSubFrozenIvt(where); |
|||
break; |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 数据校验 |
|||
* @param where 输入参数 |
|||
*/ |
|||
private void checkData(JSONObject where) { |
|||
if (ObjectUtil.isEmpty(where.getString("type"))) { |
|||
throw new BadRequestException("变动类型不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("storagevehicle_code"))) { |
|||
throw new BadRequestException("载具编码不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("material_id"))) { |
|||
throw new BadRequestException("物料标识不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("pcsn"))) { |
|||
throw new BadRequestException("批次不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("qty_unit_id"))) { |
|||
throw new BadRequestException("计量单位标识不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("qty_unit_name"))) { |
|||
throw new BadRequestException("计量单位名称不能为空!"); |
|||
} |
|||
if (ObjectUtil.isEmpty(where.getString("change_qty"))) { |
|||
throw new BadRequestException("变动数量不能为空!"); |
|||
} |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 加可用 |
|||
* @param where 输入参数 |
|||
*/ |
|||
private void updateAddCanuseIvt(JSONObject where) { |
|||
// 判断当前载具是否有物料
|
|||
MdPbStoragevehicleext extDao = iMdPbStoragevehicleextService.getOne( |
|||
new QueryWrapper<MdPbStoragevehicleext>().lambda() |
|||
.eq(MdPbStoragevehicleext::getStoragevehicle_code, where.getString("storagevehicle_code")) |
|||
); |
|||
if (ObjectUtil.isNotEmpty(extDao)) { |
|||
throw new BadRequestException("当前载具【"+extDao.getStoragevehicle_code()+"】已存在库存物料,请检查数据!"); |
|||
} |
|||
|
|||
// 插入数据
|
|||
MdPbStoragevehicleext extParamDao = JSONObject.parseObject(JSONObject.toJSONString(where), MdPbStoragevehicleext.class); |
|||
extParamDao.setStoragevehicleext_id(IdUtil.getStringId()); |
|||
extParamDao.setCanuse_qty(where.getBigDecimal("change_qty")); |
|||
extParamDao.setFrozen_qty(BigDecimal.valueOf(0)); |
|||
extParamDao.setInsert_time(DateUtil.now()); |
|||
extParamDao.setUpdate_optid(SecurityUtils.getCurrentUserId()); |
|||
extParamDao.setUpdate_optname(SecurityUtils.getCurrentNickName()); |
|||
extParamDao.setUpdate_time(DateUtil.now()); |
|||
iMdPbStoragevehicleextService.save(extParamDao); |
|||
} |
|||
|
|||
/** |
|||
* 加冻结减可用 |
|||
* @param where 输入参数 |
|||
*/ |
|||
private void updateAddFrozenIvt(JSONObject where) { |
|||
// 找当前托盘物料库存
|
|||
MdPbStoragevehicleext extDao = iMdPbStoragevehicleextService.getOne( |
|||
new QueryWrapper<MdPbStoragevehicleext>().lambda() |
|||
.eq(MdPbStoragevehicleext::getStoragevehicle_code, where.getString("storagevehicle_code")) |
|||
.eq(MdPbStoragevehicleext::getMaterial_id, where.getString("material_id")) |
|||
.eq(MdPbStoragevehicleext::getPcsn, where.getString("pcsn")) |
|||
); |
|||
if (ObjectUtil.isEmpty(extDao)) { |
|||
throw new BadRequestException("当前载具【"+extDao.getStoragevehicle_code()+"】不存在相关物料批次库存,请检查数据!"); |
|||
} |
|||
// 减可用数
|
|||
double canuse_qty = NumberUtil.sub(extDao.getCanuse_qty(), where.getDoubleValue("change_qty")).doubleValue(); |
|||
if (canuse_qty < 0) { |
|||
throw new BadRequestException("可用数不能为负数,请检查变动数量!当前可用数为【"+extDao.getCanuse_qty()+"】当前变动数为【"+where.getDoubleValue("change_qty")+"】"); |
|||
} |
|||
// 加冻结数
|
|||
double frozen_qty = NumberUtil.add(extDao.getFrozen_qty(), where.getDoubleValue("change_qty")).doubleValue(); |
|||
|
|||
extDao.setCanuse_qty(BigDecimal.valueOf(canuse_qty)); |
|||
extDao.setFrozen_qty(BigDecimal.valueOf(frozen_qty)); |
|||
extDao.setUpdate_optid(SecurityUtils.getCurrentUserId()); |
|||
extDao.setUpdate_optname(SecurityUtils.getCurrentNickName()); |
|||
extDao.setUpdate_time(DateUtil.now()); |
|||
extDao.setRemark(where.getString("remark")); |
|||
iMdPbStoragevehicleextService.updateById(extDao); |
|||
} |
|||
|
|||
/** |
|||
* 减冻结(如果可用数和冻结数都为空则删除数据) |
|||
* @param where 输入参数 |
|||
*/ |
|||
private void updateSubFrozenIvt(JSONObject where) { |
|||
// 找当前托盘物料库存
|
|||
MdPbStoragevehicleext extDao = iMdPbStoragevehicleextService.getOne( |
|||
new QueryWrapper<MdPbStoragevehicleext>().lambda() |
|||
.eq(MdPbStoragevehicleext::getStoragevehicle_code, where.getString("storagevehicle_code")) |
|||
.eq(MdPbStoragevehicleext::getMaterial_id, where.getString("material_id")) |
|||
.eq(MdPbStoragevehicleext::getPcsn, where.getString("pcsn")) |
|||
); |
|||
if (ObjectUtil.isEmpty(extDao)) { |
|||
throw new BadRequestException("当前载具【"+extDao.getStoragevehicle_code()+"】不存在相关物料批次库存,请检查数据!"); |
|||
} |
|||
// 减冻结
|
|||
double frozen_qty = NumberUtil.sub(extDao.getFrozen_qty(), where.getDoubleValue("change_qty")).doubleValue(); |
|||
if (frozen_qty < 0) { |
|||
throw new BadRequestException("冻结数不能为负数,请检查变动数量!当前冻结数为【"+extDao.getFrozen_qty()+"】当前变动数为【"+where.getDoubleValue("change_qty")+"】"); |
|||
} |
|||
|
|||
// 如果可用数和冻结数都为零则删除数据
|
|||
if (frozen_qty == 0 && extDao.getCanuse_qty().doubleValue() == 0) { |
|||
iMdPbStoragevehicleextService.removeById(extDao); |
|||
} else { |
|||
extDao.setFrozen_qty(BigDecimal.valueOf(frozen_qty)); |
|||
extDao.setUpdate_optid(SecurityUtils.getCurrentUserId()); |
|||
extDao.setUpdate_optname(SecurityUtils.getCurrentNickName()); |
|||
extDao.setUpdate_time(DateUtil.now()); |
|||
extDao.setRemark(where.getString("remark")); |
|||
iMdPbStoragevehicleextService.updateById(extDao); |
|||
} |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue