| | |
| | | import com.walker.jdbc.service.BaseServiceImpl; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.security.core.parameters.P; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.Assert; |
| | | |
| | |
| | | WhGoods_mapper mapper = new WhGoods_mapper(goods); |
| | | System.out.println(mapper.getInsertSql_().getParameters()); |
| | | System.out.println(mapper.getInsertSql_().getSql()); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 统一出入库 |
| | | */ |
| | | public List<CheckUsingResult> unifyUsingCheck(CheckUsingParam param) { |
| | | // TODO: 10/10/2023 此处加了唯一锁,会影响性能,思考是否有更合适的办法 |
| | | try { |
| | | |
| | | List<CheckUsingResult> results; |
| | | |
| | | |
| | | String key = param.getLending_id(); |
| | | |
| | | /** |
| | | * 此处将同一个仓库下的同一个型号上锁,不同仓库、不同型号不受影响。 |
| | | */ |
| | | synchronized (key) { |
| | | if (param.getIsCheckIn()) { |
| | | results = checkUsingIn(param); |
| | | } else { |
| | | results = checkUsingOut(param); |
| | | } |
| | | } |
| | | return results; |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | throw new RuntimeException(e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 在用物品出库 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | private List<CheckUsingResult> checkUsingOut(CheckUsingParam param){ |
| | | |
| | | String sql = "SELECT\n" + |
| | | " * \n" + |
| | | "FROM\n" + |
| | | " DEP_FORM_LENDING_MODEL a \n" + |
| | | "WHERE\n" + |
| | | " a.BASE_GOODS_MODELS_ID =:MODEL_ID \n" + |
| | | " AND DEP_FORM_LENDING_ID =:LENDING_ID \n" + |
| | | " AND USING_COUNT > 0\n" + |
| | | "ORDER BY\n" + |
| | | " PROCURE_DATE ASC PRICE DESC"; |
| | | |
| | | List<DepFormLendingModel> modelsList = this.select(sql,new SqlParameter("MODEL_ID", param.getModel_id()) |
| | | .put("LENDING_ID",param.getLending_id()),new DepFormLendingModel()); |
| | | |
| | | List<CheckUsingResult> resultList = new ArrayList<>(); |
| | | |
| | | int shengyu = param.getOutputCount(); |
| | | for (DepFormLendingModel model : modelsList) { |
| | | |
| | | CheckUsingResult result = new CheckUsingResult(); |
| | | |
| | | DepFormLendingGoods goods = get(new DepFormLendingGoods(),"id=?",new Object[]{model.getDepFormLendingGoodsId()}); |
| | | //如果当前持有人持有物品数量大于出库数量,则直接减掉数量即可。 |
| | | if (model.getUsingCount() > shengyu){ |
| | | result.setInitial_count(model.getUsingCount()); |
| | | result.setLendingModel(model); |
| | | model.setUsingCount(model.getCounts() - param.getOutputCount()); |
| | | result.setEnd_count(model.getUsingCount()); |
| | | update(model); |
| | | resultList.add(result); |
| | | |
| | | goods.setUsingCount(goods.getUsingCount() - param.getOutputCount()); |
| | | update(goods); |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | shengyu = shengyu - model.getUsingCount(); |
| | | goods.setUsingCount(goods.getUsingCount() - model.getUsingCount()); |
| | | |
| | | result.setInitial_count(model.getUsingCount()); |
| | | result.setLendingModel(model); |
| | | model.setUsingCount(0); |
| | | result.setEnd_count(0); |
| | | update(model); |
| | | resultList.add(result); |
| | | |
| | | update(goods); |
| | | } |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * 在用物品入 |
| | | * @param param |
| | | * @return |
| | | */ |
| | | private List<CheckUsingResult> checkUsingIn(CheckUsingParam param){ |
| | | |
| | | DepFormLending lending = get(new DepFormLending(),"id=?",new Object[]{param.getLending_id()}); |
| | | |
| | | String sql = "SELECT\n" + |
| | | " * \n" + |
| | | "FROM\n" + |
| | | " DEP_FORM_LENDING_GOODS A \n" + |
| | | "WHERE\n" + |
| | | " A.DEP_FORM_LENDING_ID = :LENDING_ID"; |
| | | |
| | | List<DepFormLendingGoods> goodsList = this.select(sql,new SqlParameter() |
| | | .put("LENDING_ID",lending.getId()),new DepFormLendingGoods()); |
| | | |
| | | List<CheckUsingResult> resultList = new ArrayList<>(); |
| | | |
| | | for (DepFormLendingGoods goods : goodsList) { |
| | | for (CheckWarehouseResult output : param.getOutputList()) { |
| | | //如果出库的型号与分发单里的型号相同 |
| | | if (goods.getBaseGoodsModelsId().longValue() == output.getWhGoods().getBaseGoodsModelsId().longValue()){ |
| | | DepFormLendingModel model = new DepFormLendingModel(); |
| | | model.setId(NumberGenerator.getLongSequenceNumber()); |
| | | model.setCounts(goods.getCounts()); |
| | | model.setDepFormLendingGoodsId(goods.getId()); |
| | | model.setDepFormLendingId(goods.getDepFormLendingId()); |
| | | model.setWhGoodsDetailsId(output.getWh_goods_detail_id()); |
| | | model.setNowUserName(goods.getGoodsUserName()); |
| | | model.setNowUserPhone(goods.getGoodsUserPhone()); |
| | | model.setWhGoodsId(output.getWhGoods().getId()); |
| | | //当前可使用数量 |
| | | model.setUsingCount(model.getCounts()); |
| | | model.setWarehouseId(output.getWhGoods().getWarehouseId()); |
| | | model.setWarehouseName(output.getWhGoods().getWarehouseName()); |
| | | model.setAgencyId(lending.getAgencyId()); |
| | | model.setAgencyName(lending.getAgencyName()); |
| | | model.setDepartmentId(lending.getDepartmentId()); |
| | | model.setDepartmentName(lending.getDepartmentName()); |
| | | insert(model); |
| | | |
| | | CheckUsingResult result = new CheckUsingResult(); |
| | | result.setLendingModel(model); |
| | | result.setInitial_count(0); |
| | | result.setEnd_count(output.getInitial_count()-output.getEnd_count()); |
| | | resultList.add(result); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return resultList; |
| | | } |
| | | |
| | | /** |
| | | * 出库 |
| | | */ |
| | | private List<CheckWarehouseResult> checkout(CheckWarehouseParam param) { |