库存盘点

duizhaopin
13507605001 2 years ago
parent 0971dd71e9
commit 1ea822c8fa

@ -6,13 +6,14 @@
import sys import sys
sys.path.append('.') sys.path.append('.')
import json
from flask import jsonify, request, g, Blueprint from flask import jsonify, request, g, Blueprint
from Common.Utils import PageParam, Utils from Common.Utils import PageParam, Utils
from Common.auth import token_auth from Common.auth import token_auth
from db_logic.stock_record import BllStockRecord from db_logic.stock_record import BllStockRecord
from db_logic.medicament import BllMedicament
from models.medicament_models import EntityStockRecord
stock_router = Blueprint("stock_record", __name__) stock_router = Blueprint("stock_record", __name__)
@ -23,26 +24,70 @@ stock_router = Blueprint("stock_record", __name__)
# @token_auth.login_required # @token_auth.login_required
def get_stock_record_list(): def get_stock_record_list():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
func_type = request.values.get("func_type")
page = request.values.get("page", 1) page = request.values.get("page", 1)
page_size = request.values.get("page_size", 10) page_size = request.values.get("page_size", 10)
page_param = PageParam(int(page), int(page_size)) page_param = PageParam(int(page), int(page_size))
data_list = BllStockRecord().get_list_info(client_id=client_id, page_param=page_param) data_list = BllStockRecord().get_list_info(client_id=client_id, page_param=page_param, func_type=func_type)
data_list = Utils.msyql_table_model(data_list) data_list = Utils.msyql_table_model(data_list)
return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords})) return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords}))
# 获取盘点用户输入界面
@stock_router.route("/get_drug_list", methods=["POST"])
def get_drug_group_list():
client_id = request.values.get("client_id")
data = BllMedicament().get_drug_stock_info(client_id=client_id)
data_list = [{"name":i.name, "input_num":0} for i in data]
return jsonify(Utils.true_return(data=data_list))
# 盘点库单 # 盘点库单
@stock_router.route("/set_stock", methods=["POST"]) @stock_router.route("/set_stock", methods=["POST"])
@token_auth.login_required @token_auth.login_required
def set_stock_record(): def set_stock_record():
client_id = request.values.get("client_id") client_id = request.values.get("client_id")
client_code = request.values.get("client_code") client_code = request.values.get("client_code")
stock_info = request.values.get("stock_info")
func_type = request.values.get("func_type")
stock_info = json.loads(stock_info)
drug_info = BllMedicament().get_drug_stock_info(client_id=client_id)
drug_info_list = Utils.msyql_table_model(drug_info)
medicament_info = []
for i in drug_info_list:
new_dict = {**i}
new_dict["input_num"] = int(stock_info.get(i["name"], 0))
new_dict['difference_num'] = int(stock_info.get(i["name"], 0)) - int(i["stock_num"])
medicament_info.append(new_dict)
data = BllStockRecord().set_stock_info( data = BllStockRecord().set_stock_info(
client_id=client_id, client_id=client_id,
client_code=client_code, client_code=client_code,
user_info=g.current_user user_info=g.current_user,
func_type=func_type,
medicament_info=medicament_info,
) )
if data: if data:
return jsonify(Utils.true_return()) return jsonify(Utils.true_return(msg="录入成功!"))
else:
return jsonify(Utils.false_return(msg=data))
# 展示判断数据
@stock_router.route("/get_stock_info", methods=["POST"])
def stock_info():
stock_id = request.values.get("id")
obj = BllStockRecord().findEntity(EntityStockRecord.id==stock_id)
if obj:
data = json.loads(obj.medicament_info)
return jsonify(Utils.true_return(data=data))
else: else:
return jsonify(Utils.false_return()) return jsonify(Utils.false_return(msg="信息有误!"))
# 展示判断数据
@stock_router.route("/del_stock", methods=["POST"])
def del_stock_info():
stock_id = request.values.get("id")
try:
BllStockRecord().delete(EntityStockRecord.id==stock_id)
return jsonify(Utils.true_return())
except Exception as error:
return jsonify(Utils.false_return(msg=f"信息有误:{error}"))

@ -72,6 +72,7 @@ def register_blueprints(app: New_flask):
from apps.power.views import power_router from apps.power.views import power_router
from apps.monitor.views import monitor_router from apps.monitor.views import monitor_router
from apps.drug_form.views import drug_form_router from apps.drug_form.views import drug_form_router
from apps.stock_record.views import stock_router
# 主概览相关 # 主概览相关
app.register_blueprint(home_router, url_prefix="/api/home") app.register_blueprint(home_router, url_prefix="/api/home")
@ -95,6 +96,8 @@ def register_blueprints(app: New_flask):
# 获取自定义表单 # 获取自定义表单
app.register_blueprint(drug_form_router, url_prefix="/api/drug_form") app.register_blueprint(drug_form_router, url_prefix="/api/drug_form")
# 库存盘点相关
app.register_blueprint(stock_router, url_prefix="/api/stock")
def create_app(): def create_app():
app = Flask(__name__) app = Flask(__name__)

@ -486,6 +486,14 @@ class BllMedicament(Repository):
""" """
return self.execute(sql_all).fetchall() return self.execute(sql_all).fetchall()
# 库存盘点获取分组后的试剂信息数据
def get_drug_stock_info(self, client_id):
sql_all = f"""
select count(*) stock_num, `name`, speci, purity from rms_medicament where client_id= '{client_id}' group by `name`, speci, purity
"""
return self.execute(sql_all).fetchall()
def inster_log_shiji(self): def inster_log_shiji(self):
import random import random
name_list = ["", "硫酸", "氧化钠"] name_list = ["", "硫酸", "氧化钠"]

@ -19,51 +19,68 @@ class BllStockRecord(Repository):
return super().__init__(entityType) return super().__init__(entityType)
def get_list_info(self, page_param, client_id): def get_list_info(self, page_param, client_id, func_type):
filter_base = "" filter_base = ""
if client_id: if client_id:
filter_base += f" client_id='{client_id}' " filter_base += f" client_id='{client_id}' "
if func_type:
if filter_base:
filter_base += " and "
filter_base += f"func_type={func_type}"
if filter_base: if filter_base:
filter_base = f" where {filter_base} " filter_base = f" where {filter_base} "
sql_all = f""" sql_all = f"""
select * from rms_stock_record {filter_base} SELECT a.*, client_name FROM (
select * from `rms_stock_record` {filter_base}
) a LEFT JOIN(
select client_name, client_id from rms_client
) b on a.client_id=b.client_id
order by create_date desc
""" """
try: try:
count_number = len(self.execute(sql_all).fetchall()) # count_number = len(self.execute(sql_all).fetchall())
count_number = self.execute(f"select count(*) num from rms_stock_record {filter_base} ").fetchone().num
except: except:
count_number = 0 count_number = 0
page_param.totalRecords = count_number page_param.totalRecords = count_number
page_sql = Utils.sql_paging_assemble(sql_all, page_param) page_sql = Utils.sql_paging_assemble(sql_all, page_param)
return self.execute(page_sql).fetchall() return self.execute(page_sql).fetchall()
def set_stock_info(self, client_id, client_code, user_info): def set_stock_info(self, client_id, client_code, user_info, func_type, medicament_info):
# 查询当前在库试剂信息 # 查询当前在库试剂信息
sql_base1 = f"""
select name,purity,speci,count(*) stock_num
from rms_medicament where client_id='{client_id}' and `status`=1 GROUP BY `name`,purity,speci
"""
data_list = Utils.msyql_table_model(self.execute(sql_base1).fetchall())
try: try:
total_num = 0
for i in data_list:
total_num += int(i["stock_num"])
obj = EntityStockRecord( obj = EntityStockRecord(
user_id=user_info.user_id,
create_date=Utils.get_str_datetime(),
total=total_num,
client_code=client_code,
client_id=client_id, client_id=client_id,
medicament_info=json.dumps(data_list) client_code=client_code,
func_type=func_type,
create_date=Utils.get_str_datetime(),
medicament_info=json.dumps(medicament_info),
user_id=user_info.user_id,
user_name=user_info.real_name
) )
self.insert(obj) self.insert(obj)
return True return True
except Exception as error: except Exception as error:
print(error) return error
return False
def inster_test_stock(self):
data_list = []
for i in range(4, 101):
obj = EntityStockRecord(
client_id='1c39cb24-07f8-11ed-abd4-f47b094925e1',
client_code=6,
func_type=1,
create_date=Utils.get_str_datetime(),
medicament_info='',
user_id='4cea74ee-0d8b-11ed-943e-f47b094925e1',
user_name=i
)
data_list.append(obj)
self.insert_many(data_list)
if __name__ == '__main__':
BllStockRecord().inster_test_stock()

@ -52,7 +52,7 @@ class EntityClient(Base):
parent_id = Column(Integer, comment='父级Id') # 父级ID parent_id = Column(Integer, comment='父级Id') # 父级ID
description = Column(String(200), comment='备注') # 备注 description = Column(String(200), comment='备注') # 备注
is_add = Column(Integer, comment='是否添加', default=0) is_add = Column(Integer, comment='是否添加', default=0)
func_type = Column(Integer, comment='试剂柜类型', default=0)
class EntityClientCellUser(Base): class EntityClientCellUser(Base):
__tablename__ = "rms_client_cell_user" __tablename__ = "rms_client_cell_user"

@ -274,12 +274,13 @@ class EntityStockRecord(Base):
id = Column(String(50), primary_key=True, comment="ID", default=get_uuid) id = Column(String(50), primary_key=True, comment="ID", default=get_uuid)
user_id = Column(String(50), comment="用户id") user_id = Column(String(50), comment="用户id")
create_date = Column(String(50), comment="时间") create_date = Column(String(50), comment="时间")
total = Column(Integer, comment="总数") user_name = Column(String(50), comment="用户名称")
client_code = Column(String(50), comment="柜子码") client_code = Column(String(50), comment="柜子码")
client_id = Column(String(50), comment="柜子id") client_id = Column(String(50), comment="柜子id")
medicament_info = Column(Text, comment="试剂详情") medicament_info = Column(Text, comment="试剂详情")
is_add = Column(Integer, default=0) is_add = Column(Integer, default=0)
func_type = Column(Integer, default=0)
class EntityMedicamentMotherLiquor(Base): class EntityMedicamentMotherLiquor(Base):
__tablename__ = "rms_medicament_mother_liquor" __tablename__ = "rms_medicament_mother_liquor"

Loading…
Cancel
Save