From 1ea822c8faf1a8434793a30050b9f25fd774c87c Mon Sep 17 00:00:00 2001 From: 13507605001 Date: Fri, 9 Dec 2022 18:02:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=93=E5=AD=98=E7=9B=98=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/stock_record/views.py | 59 ++++++++++++++++++++++++++++++++----- config/server.py | 5 +++- db_logic/medicament.py | 8 +++++ db_logic/stock_record.py | 59 ++++++++++++++++++++++++------------- models/client_models.py | 2 +- models/medicament_models.py | 3 +- 6 files changed, 105 insertions(+), 31 deletions(-) diff --git a/apps/stock_record/views.py b/apps/stock_record/views.py index a58ab5e..09d4cd4 100644 --- a/apps/stock_record/views.py +++ b/apps/stock_record/views.py @@ -6,13 +6,14 @@ import sys sys.path.append('.') - +import json from flask import jsonify, request, g, Blueprint from Common.Utils import PageParam, Utils from Common.auth import token_auth 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__) @@ -23,26 +24,70 @@ stock_router = Blueprint("stock_record", __name__) # @token_auth.login_required def get_stock_record_list(): client_id = request.values.get("client_id") + func_type = request.values.get("func_type") page = request.values.get("page", 1) page_size = request.values.get("page_size", 10) 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) 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"]) @token_auth.login_required def set_stock_record(): client_id = request.values.get("client_id") 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( client_id=client_id, client_code=client_code, - user_info=g.current_user + user_info=g.current_user, + func_type=func_type, + medicament_info=medicament_info, ) 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: - 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}")) \ No newline at end of file diff --git a/config/server.py b/config/server.py index b2b208a..9032240 100644 --- a/config/server.py +++ b/config/server.py @@ -72,6 +72,7 @@ def register_blueprints(app: New_flask): from apps.power.views import power_router from apps.monitor.views import monitor_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") @@ -94,7 +95,9 @@ def register_blueprints(app: New_flask): # 获取自定义表单 app.register_blueprint(drug_form_router, url_prefix="/api/drug_form") - + + # 库存盘点相关 + app.register_blueprint(stock_router, url_prefix="/api/stock") def create_app(): app = Flask(__name__) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index 349a060..e7ca758 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -485,6 +485,14 @@ class BllMedicament(Repository): group by `name`, speci, purity """ 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): import random diff --git a/db_logic/stock_record.py b/db_logic/stock_record.py index c4debfa..7a551e1 100644 --- a/db_logic/stock_record.py +++ b/db_logic/stock_record.py @@ -19,51 +19,68 @@ class BllStockRecord(Repository): 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 = "" 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: filter_base = f" where {filter_base} " 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: - 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: count_number = 0 page_param.totalRecords = count_number page_sql = Utils.sql_paging_assemble(sql_all, page_param) 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: - total_num = 0 - for i in data_list: - total_num += int(i["stock_num"]) 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, - 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) return True except Exception as error: - print(error) - return False + return error + 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() diff --git a/models/client_models.py b/models/client_models.py index 4a84b2f..d29e8e9 100644 --- a/models/client_models.py +++ b/models/client_models.py @@ -52,7 +52,7 @@ class EntityClient(Base): parent_id = Column(Integer, comment='父级Id') # 父级ID description = Column(String(200), comment='备注') # 备注 is_add = Column(Integer, comment='是否添加', default=0) - + func_type = Column(Integer, comment='试剂柜类型', default=0) class EntityClientCellUser(Base): __tablename__ = "rms_client_cell_user" diff --git a/models/medicament_models.py b/models/medicament_models.py index ff2dc97..8151fdc 100644 --- a/models/medicament_models.py +++ b/models/medicament_models.py @@ -274,12 +274,13 @@ class EntityStockRecord(Base): id = Column(String(50), primary_key=True, comment="ID", default=get_uuid) user_id = Column(String(50), comment="用户id") create_date = Column(String(50), comment="时间") - total = Column(Integer, comment="总数") + user_name = Column(String(50), comment="用户名称") client_code = Column(String(50), comment="柜子码") client_id = Column(String(50), comment="柜子id") medicament_info = Column(Text, comment="试剂详情") is_add = Column(Integer, default=0) + func_type = Column(Integer, default=0) class EntityMedicamentMotherLiquor(Base): __tablename__ = "rms_medicament_mother_liquor"