第11节 入库管理库存操作
    实现当增加本次入库数量时库存会相应减少(库存=库存-入库数量)
    (1)添加库存字段以及本次入库字段(字段名为:storeCount),并为本次入库字段添加计数器组件(变量名为:scope.row.currentAdd
    image.png
    (2)回到数据源:批量保存明细接口中,修改代码
    image.png
    第一部分代码:
    //查询产品表,主要是为了查询库存
    var selectProductSql = select * from mes.wms_product where id = #{id}
    //更新产品表
    var updateProductSql = update mes.wms_product set count = count - #{currentAdd} where id = #{id} and count >= #{currentAdd}//库存=库存-入库数量,并且库存>=入库数量
    第二部分代码:
    var currentAdd = item.currentAdd||0;
    MC.log(currentAdd);
    //修改产品表中的库存数量
    var obj = db.findOne(selectProductSql,{id:item.productId})
    var successCount = db.update(updateProductSql,{currentAdd,id:item.productId})
    if(successCount<=0){
    MC.error(obj.productName+”库存不足”);//抛出异常自动回滚
    }
    完成以上操作,点击运行,验证功能实现
    image.png
    image.png
    image.png