package com.consum.base.core;
|
|
import com.consum.base.core.param.BaseWarehouseParam;
|
import com.consum.base.core.param.DepBackWarehouseParam;
|
import com.consum.base.core.utils.SqlParameter;
|
import com.consum.base.core.utils.SuperMap;
|
import com.consum.base.core.utils.DateUtil;
|
import com.consum.model.po.*;
|
import com.walker.infrastructure.utils.NumberGenerator;
|
import com.walker.jdbc.service.BaseServiceImpl;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 进出库 业务处 类
|
*/
|
@Service
|
public class WarehouseBusinessService extends BaseServiceImpl {
|
|
|
@Autowired
|
private WarehouseCoreService coreService;
|
|
/**
|
* 执行采购入库
|
* 第一步:通过采购单【WH_FORM_PROCURE】查询采购单型号【WH_FORM_PROCURE_MODEL】数据
|
* 第二步:组织CheckWarehouseParam,调用WarehouseCoreService.unifyCheck()执行入库
|
* 第三步:更新采购单型号【WH_FORM_PROCURE_MODEL】库存物品编号字段及主表WH_FORM_PROCURE状态信息
|
* 第四步:更新 进出库流水(仓库)【WH_GOODS_DETAILS】
|
* @param procure
|
*/
|
public void doProcure(WhFormProcure procure){
|
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_PROCURE_MODEL A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_PROCURE_ID = :PROCURE_ID";
|
|
List<WhFormProcureModel> modelList = this.select(sql,new SqlParameter().put("PROCURE_ID",procure.getId()),new WhFormProcureModel());
|
|
for (WhFormProcureModel model : modelList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(true);
|
param.setWarehouseId(procure.getId());
|
param.setCount(model.getCounts());
|
param.setFirstInputCode(model.getId().toString());
|
param.setFirst_input_type(1);
|
param.setModelId(model.getBaseGoodsModelsId());
|
CheckWarehouseResult result = coreService.unifyCheck(param).get(0);
|
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setId(result.getWhGoods().getFirstInputHisId());
|
details.setBusinessFormId(procure.getId());
|
details.setBusinessFormCode(procure.getBusinessFormCode());
|
details.setBusinessFormName(procure.getWarehouseName() + "采购入库单:" + details.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(1);
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(param.getWarehouseId());
|
details.setWarehouseName(procure.getWarehouseName());
|
details.setClassification(1);
|
details.setOperatorId(procure.getOperatorId2());
|
details.setOperatorName(procure.getOperatorName2());
|
details.setDealTime(procure.getIncomeTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
|
this.insert(details);
|
|
|
model.setInWhGoodsDetailsId(details.getId());
|
update(model);
|
|
procure.setStates(2);
|
update(procure);
|
}
|
}
|
public void doOutPut(WhFormOutput output){
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_OUTPUT_GOODS A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_OUTPUT_ID = :OUTPUT_ID";
|
|
List<WhFormOutputGoods> goodsList = this.select(sql,new SqlParameter()
|
.put("OUTPUT_ID",output.getId()),new WhFormOutputGoods());
|
|
for (WhFormOutputGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(false);
|
param.setWarehouseId(output.getWarehouseId());
|
param.setModelId(goods.getBaseGoodsModelsId());
|
param.setCount(goods.getCounts());
|
|
List<CheckWarehouseResult> results = coreService.unifyCheck(param);
|
for (CheckWarehouseResult result : results){
|
WhFormOutputModel model = new WhFormOutputModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setCounts(result.getInitial_count() - result.getEnd_count());
|
model.setOutWhGoodsDetailsId(result.getWhGoods().getId());
|
model.setWhGoodsId(result.getWhGoods().getId());
|
model.setWhFormOutputId(output.getId());
|
model.setWhFormOutputGoodsId(goods.getId());
|
insert(model);
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(output.getId());
|
details.setBusinessFormCode(output.getBusinessFormCode());
|
details.setBusinessFormName("出库单:" + output.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(2);
|
details.setThisCount(result.getInitial_count() - result.getEnd_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(3);
|
details.setOperatorId(output.getOperatorId());
|
details.setOperatorName(output.getOperatorName());
|
details.setDealTime(output.getDealTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
}
|
}
|
}
|
|
|
/**
|
* 执行调拨出库操作
|
* 1. 通过调拨单【WH_FORM_TRANSFER】、调拨单物品【WH_FORM_TRANSFER_GOODS】组织CheckWarehouseParam
|
* 2. 调用调用WarehouseCoreService.unifyCheck()执行出库
|
* 3. 更新进出库流水(仓库)【WH_GOODS_DETAILS】
|
* 4. 更新调拨单【WH_FORM_TRANSFER】为待接收,更新调拨单物品【WH_FORM_TRANSFER_MODEL】出库流水ID
|
* @param transfer
|
*/
|
public void doTransferOutPut(WhFormTransfer transfer){
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_TRANSFER_GOODS A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_TRANSFER_ID = :TRANSFER_ID";
|
|
List<WhFormTransferGoods> goodsList = this.select(sql,new SqlParameter()
|
.put("TRANSFER_ID",transfer.getId()),new WhFormTransferGoods());
|
|
for (WhFormTransferGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(false);
|
param.setWarehouseId(transfer.getOutWarehouseId());
|
param.setCount(goods.getCounts());
|
List<CheckWarehouseResult> results = coreService.unifyCheck(param);
|
for (CheckWarehouseResult result : results){
|
WhFormTransferModel model = new WhFormTransferModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setWhFormTransferId(transfer.getId());
|
model.setWorehouseCount(result.getInitial_count());
|
model.setCounts(result.getInitial_count() - result.getEnd_count());
|
model.setOutWhGoodsDetailsId(result.getWhGoods().getId());
|
model.setWhFormTransferGoodsId(goods.getId());
|
insert(model);
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(transfer.getId());
|
details.setBusinessFormCode(transfer.getBusinessFormCode());
|
details.setBusinessFormName("调拨出库单:" + transfer.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(2);
|
details.setThisCount(result.getInitial_count() - result.getEnd_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(5);
|
details.setOperatorId(transfer.getOperatorId());
|
details.setOperatorName(transfer.getOperatorName());
|
details.setDealTime(transfer.getOutputTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
}
|
}
|
}
|
|
/**
|
* 执行调拨入库操作
|
* 1. 通过调拨单【WH_FORM_TRANSFER】、调拨单物品【WH_FORM_TRANSFER_GOODS】组织CheckWarehouseParam
|
* 2. 调用调用WarehouseCoreService.unifyCheck()执行出库
|
* 3. 更新进出库流水(仓库)【WH_GOODS_DETAILS】
|
* 4. 更新调拨单【WH_FORM_TRANSFER】为已入库,,更新调拨单物品【WH_FORM_TRANSFER_MODEL】入库流水ID
|
* @param transfer
|
*/
|
public void doTransferInPut(WhFormTransfer transfer){
|
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_TRANSFER_MODEL A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_TRANSFER_ID = :TRANSFER_ID";
|
|
List<WhFormTransferModel> modelsList = this.select(sql,new SqlParameter()
|
.put("TRANSFER_ID",transfer.getId()),new WhFormTransferModel());
|
|
for (WhFormTransferModel model : modelsList) {
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(true);
|
param.setWarehouseId(transfer.getInWarehouseId());
|
param.setCount(model.getCounts());
|
param.setWh_goods_id(model.getWhGoodsId());
|
CheckWarehouseResult result = coreService.unifyCheck(param).get(0);
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(transfer.getId());
|
details.setBusinessFormCode(transfer.getBusinessFormCode());
|
details.setBusinessFormName("调拨入库单:" + transfer.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(1);
|
details.setThisCount(result.getEnd_count()-result.getInitial_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(4);
|
details.setOperatorId(transfer.getOperatorId2());
|
details.setOperatorName(transfer.getOperatorName2());
|
details.setDealTime(transfer.getIninputTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
|
model.setInWhGoodsDetailsId(details.getId());
|
update(model);
|
}
|
}
|
|
/**
|
* 报废单
|
* @param scrapped
|
*/
|
public void doScrapped(WhFormScrapped scrapped){
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_SCRAPPED_GOODS A \n" +
|
"WHERE\n" +
|
" A.DEP_FORM_SCRAPPED_ID = :SCRAPPED_ID";
|
|
List<WhFormScrappedGoods> goodsList = this.select(sql,new SqlParameter()
|
.put("SCRAPPED_ID",scrapped.getId()),new WhFormScrappedGoods());
|
|
for (WhFormScrappedGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(false);
|
param.setWarehouseId(scrapped.getWarehouseId());
|
param.setCount(goods.getCounts());
|
List<CheckWarehouseResult> results = coreService.unifyCheck(param);
|
for (CheckWarehouseResult result : results){
|
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(scrapped.getId());
|
details.setBusinessFormCode(scrapped.getBusinessFormCode());
|
details.setBusinessFormName("报废单:" + scrapped.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(2);
|
details.setThisCount(result.getInitial_count() - result.getEnd_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(10);
|
details.setOperatorId(scrapped.getOperatorId());
|
details.setOperatorName(scrapped.getOperatorName());
|
details.setDealTime(scrapped.getDealTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
|
|
WhFormScrappedModel model = new WhFormScrappedModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setCounts(result.getWhGoods().getWhCount());
|
model.setScrappedCode(goods.getScrappedCode());
|
model.setScrappedName(goods.getScrappedName());
|
model.setDepGoodsDetailsId(details.getId());
|
model.setDepFormScrappedId(scrapped.getId());
|
model.setWhGoodsId(result.getWhGoods().getId());
|
model.setWhFormScrappedGoodsId(goods.getId());
|
insert(model);
|
}
|
}
|
}
|
|
/**
|
* 创建盘点任务,创建盘点任务时,根据当时时间会将库存数据冻结一份放入待盘点单。
|
* 1.从库存物品【WH_GOODS】中按照仓库将数据放入盘点单物品【WH_FORM_INVENTORY_GOODS】,主要是
|
* 期初数量INIT_COUNTS,和 库存物品编号WH_GOODS_ID字段
|
* @param inventory
|
*/
|
public void createInventoryForm(WhFormInventory inventory){
|
String sql =
|
"SELECT\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" SUM( b.WH_COUNT ) AS WH_COUNT,\n" +
|
" b.BASE_GOODS_MODELS_ID,\n" +
|
" b.BASE_GOODS_MODELS_NAME,\n" +
|
" b.UNIT \n" +
|
"FROM\n" +
|
" (\n" +
|
" SELECT\n" +
|
" ID \n" +
|
" FROM\n" +
|
" BASE_GOODS_MODELS m \n" +
|
" WHERE\n" +
|
" STATES != 3 \n" +
|
" AND EXISTS ( SELECT 1 FROM BASE_GOODS_TEMPLATE t WHERE t.ID = m.GOODS_TEMPLATES_ID AND t.STATES != 3 ) \n" +
|
" ) a\n" +
|
" LEFT JOIN wh_goods b ON a.ID = b.BASE_GOODS_MODELS_ID \n" +
|
"WHERE\n" +
|
" b.STATES = 1 \n" +
|
" AND b.WAREHOUSE_ID =:WAREHOUSE_ID \n" +
|
"GROUP BY\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" b.BASE_GOODS_MODELS_ID,\n" +
|
" b.BASE_GOODS_MODELS_NAME";
|
|
List<WhGoods> goodsList = select(sql,new SqlParameter().add("WAREHOUSE_ID",inventory.getWarehouseId()));
|
List<WhFormInventoryGoods> list = new ArrayList<>();
|
for (WhGoods goods : goodsList) {
|
WhFormInventoryGoods inventoryGoods = new WhFormInventoryGoods();
|
inventoryGoods.setId(NumberGenerator.getLongSequenceNumber());
|
inventoryGoods.setWhFormInventoryId(inventory.getId());
|
inventoryGoods.setBaseGoodsTemplateId(goods.getBaseGoodsTemplateId());
|
inventoryGoods.setGoodsTemplateName(goods.getGoodsTemplateName());
|
inventoryGoods.setUnit(goods.getUnit());
|
inventoryGoods.setBaseGoodsModelsId(goods.getBaseGoodsModelsId());
|
inventoryGoods.setBaseGoodsModelsName(goods.getBaseGoodsModelsName());
|
inventoryGoods.setInitCounts(goods.getWhCount());
|
inventoryGoods.setInitCounts(null);
|
inventoryGoods.setErrorCounts(null);
|
inventoryGoods.setInventoryResult(1);
|
list.add(inventoryGoods);
|
}
|
insertBatch(list);
|
|
}
|
|
/**
|
* 盘点出库
|
* @param inventory
|
*/
|
public void doInventoryOutput(WhFormInventory inventory){
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_INVENTORY_GOODS A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_INVENTORY_ID = :INVENTORY_ID \n" +
|
" AND A.INVENTORY_RESULT =3 ";
|
|
List<WhFormInventoryGoods> goodsList = this.select(sql,new SqlParameter()
|
.put("INVENTORY_ID",inventory.getId()),new WhFormInventoryGoods());
|
|
for (WhFormInventoryGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(false);
|
param.setWarehouseId(inventory.getWarehouseId());
|
param.setCount(goods.getErrorCounts());
|
param.setModelId(goods.getBaseGoodsModelsId());
|
param.setOutput_type(3);
|
List<CheckWarehouseResult> results = coreService.unifyCheck(param);
|
for (CheckWarehouseResult result : results){
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(inventory.getId());
|
details.setBusinessFormCode(inventory.getBusinessFormCode());
|
details.setBusinessFormName("盘点出单:" + inventory.getBusinessFormCode());
|
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(2);
|
details.setThisCount(result.getInitial_count() - result.getEnd_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(9);
|
details.setOperatorId(inventory.getOperatorId());
|
details.setOperatorName(inventory.getOperatorName());
|
details.setDealTime(inventory.getStopTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
|
|
WhFormInventoryModel model = new WhFormInventoryModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setCounts(result.getWhGoods().getWhCount());
|
model.setWhFormInventoryId(inventory.getId());
|
model.setInventoryResult(3);
|
model.setWhGoodsDetailsId(details.getId());
|
model.setWhFormInventoryGoodsId(goods.getId());
|
model.setWhGoodsId(result.getWhGoods().getId());
|
insert(model);
|
}
|
}
|
}
|
|
/**
|
* 盘点入库
|
* @param inventory
|
*/
|
public void doInventoryInput(WhFormInventory inventory){
|
String sql = "SELECT\n" +
|
" * \n" +
|
"FROM\n" +
|
" WH_FORM_INVENTORY_GOODS A \n" +
|
"WHERE\n" +
|
" A.WH_FORM_INVENTORY_ID = :INVENTORY_ID \n" +
|
" AND A.INVENTORY_RESULT =2 ";
|
|
List<WhFormInventoryGoods> goodsList = this.select(sql,new SqlParameter()
|
.put("INVENTORY_ID",inventory.getId()),new WhFormInventoryGoods());
|
|
for (WhFormInventoryGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(true);
|
param.setWarehouseId(inventory.getWarehouseId());
|
param.setCount(goods.getErrorCounts());
|
param.setModelId(goods.getBaseGoodsModelsId());
|
param.setFirst_input_type(3);
|
CheckWarehouseResult result = coreService.unifyCheck(param).get(0);
|
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setBusinessFormId(inventory.getId());
|
details.setBusinessFormCode(inventory.getBusinessFormCode());
|
details.setBusinessFormName("盘点入库单:" + inventory.getBusinessFormCode());
|
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(1);
|
details.setThisCount(result.getEnd_count()-result.getInitial_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(8);
|
details.setOperatorId(inventory.getOperatorId());
|
details.setOperatorName(inventory.getOperatorName());
|
details.setDealTime(inventory.getStopTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
|
|
WhFormInventoryModel model = new WhFormInventoryModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setCounts(result.getWhGoods().getWhCount());
|
model.setWhFormInventoryId(inventory.getId());
|
model.setInventoryResult(3);
|
model.setWhGoodsDetailsId(details.getId());
|
model.setWhFormInventoryGoodsId(goods.getId());
|
model.setWhGoodsId(result.getWhGoods().getId());
|
insert(model);
|
}
|
}
|
|
/**
|
* 统一处理库存预警(定时任务调用服务)
|
* 计划:每天中午13:00、晚上1:00执行两次
|
*/
|
public void insertWarning(){
|
|
String sql = "SELECT\n" +
|
" SUM(b.WH_COUNT) AS WH_COUNT,\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" b.WAREHOUSE_ID,\n" +
|
" a.UPPER_LIMIT,\n" +
|
" a.LOWER_LIMIT \n" +
|
"FROM\n" +
|
" WH_WARNING_CONFIG a\n" +
|
" LEFT JOIN wh_goods b ON a.BASE_GOODS_TEMPLATE_ID = b.BASE_GOODS_TEMPLATE_ID \n" +
|
"WHERE\n" +
|
" a.BASE_WAREHOUSE_ID = b.WAREHOUSE_ID \n" +
|
" AND b.STATES = 1 \n" +
|
" AND a.GOODS_TYPE=1\n" +
|
" AND ( a.UPPER_LIMIT <= WH_COUNT OR a.LOWER_LIMIT >= WH_COUNT ) \n" +
|
"GROUP BY\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" b.WAREHOUSE_ID,\n" +
|
" a.UPPER_LIMIT,\n" +
|
" a.LOWER_LIMIT";
|
|
List<Map> goodslist = select(sql,new SqlParameter());
|
|
sql = "SELECT\n" +
|
" SUM(b.WH_COUNT) AS WH_COUNT,\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" b.BASE_GOODS_MODELS_ID,\n" +
|
" b.BASE_GOODS_MODELS_NAME,\n" +
|
" b.WAREHOUSE_ID,\n" +
|
" a.UPPER_LIMIT,\n" +
|
" a.LOWER_LIMIT \n" +
|
"FROM\n" +
|
" WH_WARNING_CONFIG a\n" +
|
" LEFT JOIN wh_goods b ON a.BASE_GOODS_MODELS_ID = b.BASE_GOODS_MODELS_ID \n" +
|
"WHERE\n" +
|
" a.BASE_WAREHOUSE_ID = b.WAREHOUSE_ID \n" +
|
" AND b.STATES = 1 \n" +
|
" AND a.GOODS_TYPE=2\n" +
|
" AND ( a.UPPER_LIMIT <= WH_COUNT OR a.LOWER_LIMIT >= WH_COUNT ) \n" +
|
"GROUP BY\n" +
|
" b.BASE_GOODS_TEMPLATE_ID,\n" +
|
" b.GOODS_TEMPLATE_NAME,\n" +
|
" b.BASE_GOODS_MODELS_ID,\n" +
|
" b.BASE_GOODS_MODELS_NAME,\n" +
|
" b.WAREHOUSE_ID,\n" +
|
" a.UPPER_LIMIT,\n" +
|
" a.LOWER_LIMIT";
|
|
List<Map> modeslist = select(sql,new SqlParameter());
|
|
List<Map> list = new ArrayList<>();
|
list.addAll(goodslist);
|
list.addAll(modeslist);
|
|
List<WhWarning> warningList = new ArrayList<>();
|
for (Map map : list) {
|
SuperMap superMap = new SuperMap(map);
|
BaseWarehouse warehouse = get(new BaseWarehouse(),"ID=?",new Object[]{superMap.get("WAREHOUSE_ID")});
|
|
WhWarning warning = new WhWarning();
|
warning.setId(NumberGenerator.getLongSequenceNumber());
|
warning.setBaseWarehouseId(warehouse.getId());
|
warning.setBaseWarehouseName(warehouse.getWarehouseName());
|
warning.setBaseGoodsTemplateId(superMap.getLong("BASE_GOODS_TEMPLATE_ID"));
|
warning.setBaseGoodsTemplateName(superMap.getString("GOODS_TEMPLATE_NAME"));
|
if (superMap.getString("BASE_GOODS_MODELS_ID") == null){
|
warning.setGoodsType(1);
|
} else {
|
warning.setBaseGoodsModelsId(superMap.getLong("BASE_GOODS_MODELS_ID"));
|
warning.setBaseGoodsModelsName(superMap.getString("BASE_GOODS_MODELS_NAME"));
|
warning.setGoodsType(2);
|
}
|
|
int whCount = superMap.getInteger("WH_COUNT");
|
int upCount = superMap.getInteger("UPPER_LIMIT");
|
int lowCount = superMap.getInteger("LOWER_LIMIT");
|
|
if (whCount >= upCount){
|
warning.setWarningType(1);
|
}
|
if (whCount<=lowCount){
|
warning.setWarningType(2);
|
}
|
|
warning.setUpperLimit(upCount);
|
warning.setLowerLimit(lowCount);
|
warning.setWarehouseCount(whCount);
|
warning.setStates(1);
|
warning.setWarningTime(DateUtil.getCurrentDateFor14());
|
warning.setAgencyId(warehouse.getAgencyId());
|
warning.setAgencyName(warehouse.getAgencyName());
|
|
warningList.add(warning);
|
}
|
|
insertBatch(warningList);
|
}
|
|
public void doDepBack(String depFormBackId){
|
|
DepFormBack back = get(new DepFormBack(),"ID=?",new Object[]{depFormBackId});
|
|
String sql = "SELECT\n" +
|
" B.*,\n" +
|
" A.BACK_COUNTS, \n" +
|
" A.ID AS DEP_FORM_BACK_GOODS_ID \n" +
|
"FROM\n" +
|
" DEP_FORM_BACK_GOODS A\n" +
|
" LEFT JOIN DEP_FORM_LENDING_GOODS B ON A.DEP_FORM_LENDING_GOODS_ID = B.ID \n" +
|
"WHERE\n" +
|
" A.DEP_FORM_BACK_ID = :DEP_FORM_BACK_ID \n" +
|
" AND A.WAREHOUSE_ID = B.WAREHOUSE_ID \n" +
|
" AND A.WAREHOUSE_ID = :WAREHOUSE_ID";
|
|
List<Map> list = select(sql,new SqlParameter("DEP_FORM_BACK_ID",back.getId()).add("WAREHOUSE_ID",back.getWarehouseId()));
|
|
for (Map myMap : list) {
|
SuperMap map = new SuperMap(myMap);
|
|
CheckUsingParam param = new CheckUsingParam();
|
param.setIsCheckIn(false);
|
param.setLending_id(map.getLong("DEP_FORM_LENDING_ID"));
|
param.setModel_id(map.getLong("BASE_GOODS_MODELS_ID"));
|
param.setUser_name(map.getString("GOODS_USER_NAME"));
|
|
List<CheckUsingResult> resultList = coreService.unifyUsingCheck(param);
|
for (CheckUsingResult result : resultList) {
|
BaseWarehouseParam param1 = new DepBackWarehouseParam();
|
param1.setIsCheckIn(true);
|
param1.setWarehouseId(result.getLendingModel().getWarehouseId());
|
param1.setModelId(result.getLendingModel().getBaseGoodsModelsId());
|
param1.setCount(result.getEnd_count() - result.getInitial_count());
|
param1.setFirst_input_type(4);
|
|
//入库并存入流水
|
CheckWarehouseResult result1 = coreService.unifyCheck(param1).get(0);
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setId(result1.getWhGoods().getFirstInputHisId());
|
details.setBusinessFormId(back.getId());
|
details.setBusinessFormCode(back.getBusinessFormCode());
|
details.setBusinessFormName(back.getWarehouseName() + "返库入库单:" + details.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(1);
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(back.getWarehouseId());
|
details.setWarehouseName(back.getWarehouseName());
|
details.setClassification(1);
|
details.setOperatorId(back.getOperatorId());
|
details.setOperatorName(back.getOperatorName());
|
details.setDealTime(back.getDealTime());
|
details.setWhGoodsId(result1.getWhGoods().getId());
|
|
this.insert(details);
|
|
|
//存入在用流水
|
UsingGoodsHis his = new UsingGoodsHis();
|
his.setId(NumberGenerator.getLongSequenceNumber());
|
his.setBusinessFormId(back.getId());
|
his.setBusinessFormCode(back.getBusinessFormCode());
|
his.setBusinessFormName("返库单:" + back.getBusinessFormCode());
|
his.setClassification(3);
|
his.setOperatorId(back.getOperatorId());
|
his.setOperatorName(back.getOperatorName());
|
his.setDealTime(back.getDealTime());
|
his.setDepFormLendingModelId(result.getLendingModel().getId());
|
his.setDepFormLendingGoodsId(result.getLendingModel().getDepFormLendingGoodsId());
|
his.setDepFormLendingId(result.getLendingModel().getDepFormLendingId());
|
his.setWhGoodsId(result.getLendingModel().getWhGoodsId());
|
his.setInitialCount(result.getInitial_count());
|
his.setEndCount(result.getEnd_count());
|
his.setWarehouseId(back.getWarehouseId());
|
his.setWarehouseName(back.getWarehouseName());
|
his.setDepartmentId(back.getDepartmentId());
|
his.setDepartmentName(back.getDepartmentName());
|
insert(his);
|
|
DepFormBackModel model = new DepFormBackModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setDepFormBackGoodsId(map.getLong("DEP_FORM_BACK_GOODS_ID"));
|
model.setDepFormBackId(back.getId());
|
model.setWhGoodsDetailsId(result1.getWh_goods_detail_id());
|
model.setUsingGoodsHisId(his.getId());
|
model.setWhGoodsId(his.getWhGoodsId());
|
model.setCounts(his.getThisCount());
|
model.setDepFormLendingModelId(his.getDepFormLendingModelId());
|
model.setDepFormLendingGoodsId(his.getDepFormLendingGoodsId());
|
model.setDepFormLendingId(his.getDepFormLendingId());
|
model.setWhGoodsId(his.getWhGoodsId());
|
insert(model);
|
}
|
|
}
|
|
|
}
|
|
|
/**
|
* 部门物品分发
|
*/
|
public void doDepLending(DepFormLending lending){
|
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());
|
|
for (DepFormLendingGoods goods : goodsList){
|
BaseWarehouseParam param = new BaseWarehouseParam();
|
param.setIsCheckIn(false);
|
param.setWarehouseId(lending.getWarehouseId());
|
param.setModelId(goods.getBaseGoodsModelsId());
|
param.setCount(goods.getCounts());
|
|
//首先从机构仓库出库
|
List<CheckWarehouseResult> results = coreService.unifyCheck(param);
|
for (CheckWarehouseResult result : results){
|
WhGoodsDetails details = new WhGoodsDetails();
|
details.setId(NumberGenerator.getLongSequenceNumber());
|
details.setBusinessFormId(lending.getId());
|
details.setBusinessFormCode(lending.getBusinessFormCode());
|
details.setBusinessFormName("分发单:" + lending.getBusinessFormCode());
|
details.setInitialCount(result.getInitial_count());
|
details.setThisType(2);
|
details.setThisCount(result.getInitial_count() - result.getEnd_count());
|
details.setEndCount(result.getEnd_count());
|
details.setWarehouseId(result.getWhGoods().getWarehouseId());
|
details.setWarehouseName(result.getWhGoods().getWarehouseName());
|
details.setClassification(11);
|
details.setOperatorId(lending.getOperatorId());
|
details.setOperatorName(lending.getOperatorName());
|
details.setDealTime(lending.getDealTime());
|
details.setWhGoodsId(result.getWhGoods().getId());
|
this.insert(details);
|
|
//回填出库流水ID,用于分发时使用
|
result.setWh_goods_detail_id(details.getId());
|
}
|
|
CheckUsingParam usingParam = new CheckUsingParam();
|
usingParam.setIsCheckIn(true);
|
usingParam.setInput_type(1);
|
usingParam.setOutputList(results);
|
|
List<CheckUsingResult> usingResults = coreService.unifyUsingCheck(usingParam);
|
for (CheckUsingResult usingResult : usingResults) {
|
UsingGoodsHis his = new UsingGoodsHis();
|
his.setId(NumberGenerator.getLongSequenceNumber());
|
his.setBusinessFormId(lending.getId());
|
his.setBusinessFormCode(lending.getBusinessFormCode());
|
his.setBusinessFormName("分发单:" + lending.getBusinessFormCode());
|
his.setClassification(1);
|
his.setOperatorId(lending.getOperatorId());
|
his.setOperatorName(lending.getOperatorName());
|
his.setDealTime(lending.getDealTime());
|
his.setDepFormLendingModelId(usingResult.getLendingModel().getId());
|
his.setDepFormLendingGoodsId(usingResult.getLendingModel().getDepFormLendingGoodsId());
|
his.setDepFormLendingId(lending.getId());
|
his.setWhGoodsId(usingResult.getLendingModel().getWhGoodsId());
|
his.setInitialCount(usingResult.getInitial_count());
|
his.setEndCount(usingResult.getEnd_count());
|
his.setWarehouseId(lending.getWarehouseId());
|
his.setWarehouseName(lending.getWarehouseName());
|
his.setDepartmentId(lending.getDepartmentId());
|
his.setDepartmentName(lending.getDepartmentName());
|
insert(his);
|
}
|
}
|
}
|
|
public void doDepScrapped(String dep_form_scrapped_id){
|
|
DepFormScrapped scrapped = get(new DepFormScrapped(),"ID=?",new Object[]{dep_form_scrapped_id});
|
|
String sql = "SELECT\n" +
|
" B.*,\n" +
|
" A.SCRAPPED_COUNTS, \n" +
|
" A.ID AS DEP_FORM_SCRAPPED_GOODS_ID \n" +
|
"FROM\n" +
|
" DEP_FORM_SCRAPPED_GOODS A\n" +
|
" LEFT JOIN DEP_FORM_LENDING_GOODS B ON A.DEP_FORM_LENDING_GOODS_ID = B.ID \n" +
|
"WHERE\n" +
|
" A.DEP_FORM_SCRAPPED_ID = :DEP_FORM_SCRAPPED_ID \n" +
|
" AND A.WAREHOUSE_ID = B.WAREHOUSE_ID \n" +
|
" AND A.WAREHOUSE_ID = :WAREHOUSE_ID";
|
|
List<Map> list = select(sql,new SqlParameter("DEP_FORM_SCRAPPED_ID",scrapped.getId()).add("WAREHOUSE_ID",scrapped.getWarehouseId()));
|
for (Map _map : list) {
|
SuperMap map = new SuperMap(_map);
|
|
CheckUsingParam param = new CheckUsingParam();
|
param.setIsCheckIn(false);
|
param.setOutputCount(map.getInteger("SCRAPPED_COUNTS"));
|
param.setLending_id(map.getLong("DEP_FORM_LENDING_ID"));
|
param.setModel_id(map.getLong("BASE_GOODS_MODELS_ID"));
|
param.setUser_name(map.getString("GOODS_USER_NAME"));
|
|
List<CheckUsingResult> resultList = coreService.unifyUsingCheck(param);
|
|
for (CheckUsingResult result : resultList) {
|
|
//存入在用流水
|
UsingGoodsHis his = new UsingGoodsHis();
|
his.setId(NumberGenerator.getLongSequenceNumber());
|
his.setBusinessFormId(scrapped.getId());
|
his.setBusinessFormCode(scrapped.getBusinessFormCode());
|
his.setBusinessFormName("部门报废单:" + scrapped.getBusinessFormCode());
|
his.setClassification(4);
|
his.setOperatorId(scrapped.getOperatorId());
|
his.setOperatorName(scrapped.getOperatorName());
|
his.setDealTime(scrapped.getDealTime());
|
his.setDepFormLendingModelId(result.getLendingModel().getId());
|
his.setDepFormLendingGoodsId(result.getLendingModel().getDepFormLendingGoodsId());
|
his.setDepFormLendingId(result.getLendingModel().getDepFormLendingId());
|
his.setWhGoodsId(result.getLendingModel().getWhGoodsId());
|
his.setInitialCount(result.getInitial_count());
|
his.setEndCount(result.getEnd_count());
|
his.setWarehouseId(scrapped.getWarehouseId());
|
his.setWarehouseName(scrapped.getWarehouseName());
|
his.setDepartmentId(scrapped.getDepartmentId());
|
his.setDepartmentName(scrapped.getDepartmentName());
|
insert(his);
|
|
|
DepFormScrappedModel model = new DepFormScrappedModel();
|
model.setId(NumberGenerator.getLongSequenceNumber());
|
model.setDepFormScrappedGoodsId(map.getLong("DEP_FORM_SCRAPPED_GOODS_ID"));
|
model.setScrappedCode(map.getString("SCRAPPED_CODE"));
|
model.setScrappedName(map.getString("SCRAPPED_NAME"));
|
model.setUsingGoodsHisId(his.getId());
|
model.setDepFormScrappedId(scrapped.getId());
|
model.setWhGoodsId(his.getWhGoodsId());
|
model.setScrappedCounts(his.getThisCount());
|
model.setInitCount(his.getInitialCount());
|
model.setDepFormLendingModelId(his.getDepFormLendingModelId());
|
model.setDepFormLendingGoodsId(his.getDepFormLendingGoodsId());
|
model.setDepFormLendingId(his.getDepFormLendingId());
|
insert(model);
|
}
|
}
|
}
|
|
/**
|
* 用于变更物品使用人后,更新库存物品使用人信息。
|
* @param dep_form_lending_goods_user_id
|
*/
|
public void changeUser(Long dep_form_lending_goods_user_id){
|
DepFormLendingGoodsUser user = get(new DepFormLendingGoodsUser(),"ID=?",new Object[]{dep_form_lending_goods_user_id});
|
DepFormLendingGoods goods = get(new DepFormLendingGoods(),"ID=?",new Object[]{user.getDepFormLendingGoodsId()});
|
|
|
String sql =
|
"UPDATE DEP_FORM_LENDING_MODEL \n" +
|
"SET NOW_USER_NAME =:NOW_USER_NAME,\n" +
|
"NOW_USER_PHONE =:NOW_USER_PHONE \n" +
|
"WHERE\n" +
|
" DEP_FORM_LENDING_GOODS_ID =:DEP_FORM_LENDING_GOODS_ID \n" +
|
" AND BASE_GOODS_MODELS_ID =:BASE_GOODS_MODELS_ID \n" +
|
" AND NOW_USER_NAME =:OLD_USER_NAME\n" +
|
" AND USING_COUNT > 0";
|
|
List<SqlParameter> parameterList = new ArrayList<>();
|
List<DepFormLendingModel> modelList = select(new DepFormLendingModel(),"DEP_FORM_LENDING_GOODS_ID=?",new Object[]{goods.getId()});
|
for (DepFormLendingModel model : modelList) {
|
if (model.getUsingCount() == 0) continue;
|
SqlParameter parameter = new SqlParameter();
|
parameter.add("NOW_USER_NAME",user.getNowUserName())
|
.add("NOW_USER_PHONE",user.getNowUserPhone())
|
.add("DEP_FORM_LENDING_GOODS_ID",goods.getId())
|
.add("BASE_GOODS_MODELS_ID",goods.getBaseGoodsModelsId())
|
.add("OLD_USER_NAME",goods.getGoodsUserName());
|
parameterList.add(parameter);
|
}
|
execBatchUpdate(sql,parameterList);
|
}
|
}
|