#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @Date:2022/07/29 09:03:39 ''' from flask import Blueprint, jsonify, request from Common.Utils import Utils, PageParam from Common.auth import token_auth from db_logic.client import BllClient from db_logic.medicament_record import BllMedicamentRecord from db_logic.medicament_template import BllMedicamentTemplate from db_logic.meidcament_variety import BllMedicamentVariety from db_logic.humiture_record import BllHumitureRecord from db_logic.medicament import BllMedicament from models.client_models import EntityClient from models.medicament_models import EntityMedicament, EntityMedicamentRecord, EntityMedicamentTemplate, EntityMedicamentVariety from models.humiture_models import EntityHumitureRecord client_router = Blueprint("client", __name__) # 查看client列表 @client_router.route("/client_list", methods=["POST"]) @token_auth.login_required def get_client_list(): data = BllClient().get_all_client_list() data_list = Utils.msyql_table_model(data) return jsonify(Utils.true_return(data={"data_list": data_list})) # 查看列表 @client_router.route("/get_list", methods=["GET","POST"]) # @token_auth.login_required def getclient_list(): seach_word = request.values.get("seach_word") page = request.values.get("page", 1) page_size = request.values.get("page_size", 100) page_param = PageParam(int(page), int(page_size)) data = BllClient().get_client_seach( seach_word=seach_word, page_param=page_param ) data_list = Utils.msyql_table_model(data) return jsonify(Utils.true_return(data={"data_list": data_list, "total_count": page_param.totalRecords})) # 新增and编辑 @client_router.route("/add_or_update", methods=["GET", "POST"]) @token_auth.login_required def client_add_update(): finds = [ "client_title", "client_code", "client_type", "place", "filter_production_date", "filter_shelf_life_warning_value", "contact_people_name", "contact_phone", "description" ] client_id = request.values.get("client_id") obj = BllClient().findEntity( EntityClient.client_code == request.values.get("client_code") ) if client_id: client_obj = BllClient().findEntity( EntityClient.client_id==client_id ) if obj: if client_obj.client_id != obj.client_id: return jsonify(Utils.false_return()) for i in finds: setattr(client_obj, i, request.values.get(i)) BllClient().update(client_obj) return jsonify(Utils.true_return(msg="修改成功")) else: if obj: return jsonify(Utils.false_return(msg="柜体需要不能重复")) client_obj = EntityClient() for i in finds: setattr(client_obj, i, request.values.get(i)) BllClient().insert(client_obj) return jsonify(Utils.true_return(msg="添加成功")) # 锁定或解锁柜体 @client_router.route("/update_status", methods=["GET", "POST"]) @token_auth.login_required def update_status(): status_type = request.values.get("status_type") client_id = request.values.get("client_id") obj = BllClient() client_obj = obj.findEntity(EntityClient.client_id == client_id) if client_obj: client_obj.is_enabled=status_type obj.update(client_obj) return jsonify(Utils.true_return(msg="修改成功")) else: return jsonify(Utils.false_return("柜体不存在")) # 删除柜体 @client_router.route("/del", methods=["GET", "POST"]) # @token_auth.login_required def client_del(): client_id = request.values.get("client_id") drug_obj = BllMedicament().findEntity(EntityMedicament.client_id == client_id) if drug_obj: return jsonify(Utils.false_return(msg="请先删除柜体内试剂数据")) else: BllClient().delete(EntityClient.client_id==client_id) BllMedicamentRecord().delete(EntityMedicamentRecord.client_id == client_id) BllMedicamentTemplate().delete(EntityMedicamentTemplate.client_id == client_id) BllHumitureRecord().delete(EntityHumitureRecord.client_id == client_id) return jsonify(Utils.true_return(msg="删除成功")) # 清空所有需删除表数据 # rms_user_medicament, rms_medicament_variety, # rms_medicament_template,rms_medicament_record, # rms_medicament_extend,rms_medicament, rms_humiture_record # 清空指定柜体需删除 # rms_medicament_template,rms_medicament_record,rms_medicament, rms_humiture_record @client_router.route("/client_empty", methods=["GET", "POST"]) def client_empty(): client_id = request.values.get("client_id") if client_id: BllMedicament().delete(EntityMedicament.client_id == client_id) BllMedicamentRecord().delete(EntityMedicamentRecord.client_id == client_id) BllMedicamentTemplate().delete(EntityMedicamentTemplate.client_id == client_id) BllHumitureRecord().delete(EntityHumitureRecord.client_id == client_id) else: BllClient().empty_table_info() return jsonify(Utils.true_return()) # 分配抽屉权限展示 @client_router.route("/get_drawer_power", methods=["GET", "POST"]) def get_client_drawer_power(): drawer_id = request.values.get("drawer_id") # 分配抽屉权限 @client_router.route("/set_drawer_power", methods=["GET", "POST"]) def set_client_drawer_power(): drawer_id = request.values.get("drawer_id")