| | |
| | | import com.walker.infrastructure.utils.NumberGenerator; |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | |
| | |
| | | /** |
| | | * 统一出入库 |
| | | */ |
| | | public CheckWarehouseResult[] unifyCheck(CheckWarehouseParam param) { |
| | | public List<CheckWarehouseResult> unifyCheck(CheckWarehouseParam param) { |
| | | // TODO: 10/10/2023 此处加了唯一锁,会影响性能,思考是否有更合适的办法 |
| | | try { |
| | | Assert.notNull(param, "wareHouse param can not null !"); |
| | | Assert.notNull(param.getWarehouseId(), "wareHouse id can not null"); |
| | | CheckWarehouseResult[] result; |
| | | synchronized (param.getWarehouseId()) { |
| | | List<CheckWarehouseResult> results; |
| | | |
| | | String key = param.getWarehouseId().toString() + param.getModelId().toString(); |
| | | |
| | | /** |
| | | * 此处将同一个仓库下的同一个型号上锁,不同仓库、不同型号不受影响。 |
| | | */ |
| | | synchronized (key) { |
| | | if (param.getIsCheckIn()) { |
| | | result = new CheckWarehouseResult[]{checkin(param)}; |
| | | results = new ArrayList<>(); |
| | | results.add(checkin(param)); |
| | | } else { |
| | | result = checkout(param); |
| | | results = checkout(param); |
| | | } |
| | | } |
| | | return result; |
| | | return results; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | throw new RuntimeException(e.getMessage()); |
| | |
| | | /** |
| | | * 出库 |
| | | */ |
| | | private CheckWarehouseResult[] checkout(CheckWarehouseParam param) { |
| | | private List<CheckWarehouseResult> checkout(CheckWarehouseParam param) { |
| | | //查询出指定仓库、指定型号,状态为正常的的库存物品,按照采购时间倒叙、价格倒叙排列 |
| | | String sql = "SELECT\n" + |
| | | " * \n" + |
| | | "FROM\n" + |
| | |
| | | parameter.add("WAREHOUSE_ID",param.getWarehouseId()) |
| | | .add("BASE_GOODS_MODELS_ID",param.getModelId()); |
| | | List<WhGoods> goodsList = select(sql,parameter,new WhGoods()); |
| | | List<CheckWarehouseResult> resultList = new ArrayList<>(); |
| | | |
| | | int shengyu = param.getCount(); |
| | | |
| | | for (WhGoods goods : goodsList){ |
| | | if (shengyu <= 0 ) break; |
| | | |
| | | //如果库存数量大于出库数量,直接减库存 |
| | | if (shengyu <= goods.getWhCount()){ |
| | | shengyu = 0; |
| | | |
| | | CheckWarehouseResult result = new CheckWarehouseResult(); |
| | | result.setWhGoods(goods); |
| | | result.setInitial_count(goods.getWhCount()); |
| | | goods.setWhCount(goods.getWhCount() - param.getCount()); |
| | | result.setEnd_count(goods.getWhCount()); |
| | | resultList.add(result); |
| | | |
| | | //如果减库存后,库存数为0,则变更状态为已删除 |
| | | if (goods.getWhCount() == 0){ |
| | | goods.setStates(0); |
| | | } |
| | | update(goods); |
| | | |
| | | //如果是调拨出库 2:调拨,3:报废 |
| | | if (param.getOutput_type() == 2 || param.getOutput_type() == 3){ |
| | | WhGoods nGoods = new WhGoods(); |
| | | BeanUtils.copyProperties(goods,nGoods); |
| | | //变更状态为调拨 |
| | | nGoods.setStates(param.getOutput_type()); |
| | | nGoods.setWhCount(param.getCount()); |
| | | nGoods.setId(NumberGenerator.getLongSequenceNumber()); |
| | | insert(nGoods); |
| | | |
| | | CheckWarehouseResult nresult = new CheckWarehouseResult(); |
| | | nresult.setWhGoods(nGoods); |
| | | nresult.setInitial_count(0); |
| | | nresult.setEnd_count(nresult.getEnd_count()); |
| | | resultList.add(nresult); |
| | | } |
| | | |
| | | return resultList; |
| | | |
| | | } |
| | | |
| | | //如果库存数量小于出库数量,则需要几个库存物品一起出库。 |
| | | |
| | | CheckWarehouseResult result = new CheckWarehouseResult(); |
| | | result.setInitial_count(goods.getWhCount()); |
| | | result.setEnd_count(0); |
| | | result.setWhGoods(goods); |
| | | resultList.add(result); |
| | | |
| | | shengyu = param.getCount() - goods.getWhCount(); |
| | | if (shengyu < 0){ |
| | | throw new RuntimeException("出库时,计算错误"); |
| | | } |
| | | goods.setWhCount(0); |
| | | goods.setStates(0); |
| | | update(goods); |
| | | } |
| | | |
| | | |
| | | |
| | | return null; |
| | | throw new RuntimeException("出库时,计算错误"); |
| | | } |
| | | |
| | | private BaseWarehouse getWarehouse(long id){ |
| | |
| | | goods.setBaseGoodsModelsId(procureModel.getBaseGoodsModelsId()); |
| | | goods.setBaseGoodsModelsName(procureModel.getBaseGoodsModelsName()); |
| | | goods.setWhCount(procureModel.getCounts()); |
| | | goods.setTransferCount(0); |
| | | goods.setAllCount(procureModel.getCounts()); |
| | | goods.setFirstInputCode(param.getFirstInputCode()); |
| | | goods.setFirstInputType(param.getFirst_input_type()); |
| | | goods.setFirstInputHisId(NumberGenerator.getLongSequenceNumber()); |
| | |
| | | CheckWarehouseResult result = new CheckWarehouseResult(); |
| | | result.setWhGoods(goods); |
| | | result.setInitial_count(0); |
| | | result.setEnd_count(goods.getAllCount()); |
| | | result.setEnd_count(goods.getWhCount()); |
| | | return result; |
| | | //零星入库 |
| | | } else if (param.getFirst_input_type() ==2){ |
| | |
| | | WhGoods newGoods = new WhGoods(); |
| | | newGoods.setId(goods.getId()); |
| | | newGoods.setWhCount(result.getEnd_count()); |
| | | newGoods.setAllCount(goods.getAllCount() + param.getCount()); |
| | | newGoods.setStates(1); |
| | | newGoods.setBackDate(DateUtil.getCurrentDateFor14()); |
| | | this.update(newGoods); |