From 2e7d691e24275131cf6471e254b9f0efd747de1d Mon Sep 17 00:00:00 2001 From: 13507605001 Date: Fri, 30 Dec 2022 15:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Common/GaoPaiYi.py | 141 +++++++++++++++++++++++++------- Common/create_barcode.py | 10 +-- apps/drug/views.py | 30 +++++-- apps/drug_template/views.py | 2 +- apps/monitor/views.py | 4 +- apps/report/views.py | 6 +- apps/temporary_auth/views.py | 6 +- db_logic/user_temporary_auth.py | 6 +- models/power_models.py | 1 + 10 files changed, 158 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 12a83b5..011dc2e 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ MANIFEST .vscode/* runserver_log/ img +local_conf.conf # PyInstaller # Usually these files are written by a python script from a template diff --git a/Common/GaoPaiYi.py b/Common/GaoPaiYi.py index 04efd12..2d3d096 100644 --- a/Common/GaoPaiYi.py +++ b/Common/GaoPaiYi.py @@ -4,17 +4,36 @@ import json import uuid import sys import os +import threading # 获取分辨率索引 url = "http://localhost:6543/GetAllDisplayInfo" param={ "dev_idx":"0", } + #res = requests.get(url = url) #print(json.loads(res.text)) #print(json.loads(res.text)['data']) # print(json.loads(res.text)['code']=='0') - +import inspect +import ctypes +# 关闭线程 +def _async_raise(tid, exctype): + """raises the exception, performs cleanup if needed""" + tid = ctypes.c_long(tid) + if not inspect.isclass(exctype): + exctype = type(exctype) + res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype)) + if res == 0: + raise ValueError("invalid thread id") + elif res != 1: + # """if it returns a number greater than one, you're in trouble, + # and you should call it again with exc=NULL to revert the effect""" + ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None) + raise SystemError("PyThreadState_SetAsyncExc failed") +def stop_thread(thread): + _async_raise(thread.ident, SystemExit) class GaoPaiYi(): # path = "/home/yanyi/Project/MainManage/img" # 默认存储地址 @@ -24,46 +43,112 @@ class GaoPaiYi(): os.makedirs(path) def __init__(self): pass - + def openCamera(self): + try: + url = 'http://127.0.0.1:6543/video=stream&camidx=0' + param={} + header ={'Content-Type':'application/json;charset=utf-8'} + res = requests.get(url = url,data=json.dumps(param),headers=header,timeout=10) + print(json.loads(res.text)) + print(json.loads(res.text)['filepath']) + print('打开相机:::',json.loads(res.text)['code']) + except Exception as e: + print(e) + return {'code': -1, 'msg': e} + + # win 版本 def getPic(self): try: - # if path: - # self.path = path - #print('----------预览视频-------------------------') - # 打開視頻 - url = "http://localhost:6543/StartPreview?dev_idx=0&res_id=0&pixfmt=pixfmt" - res = requests.get(url = url) - # print(json.loads(res.text)) - #print(json.loads(res.text)['data']) - # print(json.loads(res.text)['code']=='0') - if json.loads(res.text)['returnCode']!=0: - return {'code':-1,'msg':"打开视频失败"} + p = threading.Thread(target=self.openCamera) + p.start() time.sleep(2) + # 摄像头拍照 + url = 'http://127.0.0.1:6543/video=grabimage' + # url = 'https://restapi.getui.com/v2/h8m8bkLRUG6C313Xw8sNV8/auth' + param = { + "filepath": f"{self.path}\\{str(uuid.uuid1())}.jpg", + "rotate": "90", #// 图像旋转角度,90的整数倍,默认:"0" + "deskew": "0", #// 纠偏(主头有效),参数:0:不纠偏;1:纠偏 + "deskewval":"0", #// 纠偏像素值:正常给0,正数时多裁,负数时少裁 + "camidx": "0", #// 摄像头索引,参数:0:主头;1:副头 + "ColorMode": "0", #// 色彩模式,图片保存本地时调用。0:彩色 1:灰色 2:黑白 3:白纸印章 4:去背景色(普通文件) 5:去背景色(身份证) + "quality": "0", #// 图片质量,图片保存本地调用 - #print('----------拍照-------------------------',__file__) - # 打開視頻 - url = "http://localhost:6543/getPic?savepath="+self.path+"&quality=80" - res = requests.get(url = url) - - #print(json.loads(res.text)['data']["path"]) - #print(json.loads(res.text)['returnCode']==0) /home/yanyi/Project/MainManage/img/2022-9-9 15-36-35.jpg - if json.loads(res.text)['returnCode']==0: - res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['data']["path"].split("/")[-1]} + # 。0:默认质量;1:高质量;2:较高质量;3:中质量;4:较低质量;5:低质量 + "bAutoAdjust":"1", #// 是否自动摆正: 0:不摆正 1:摆正 + "bIsPrint1to1":"", #// 是否1:1打印 + "watermark": { + "pos": "", #// 水印在图像中的位置,0:左上;1:右上;2:左下;3:右下;4:中间 + "content": "", #// 水印内容,必须utf-8编码,当水印内容为空,将当前时间作为水印 + "transparency": "", #// 透明度,0~255,0:完全透明;255:不透明 + "fontsize": "", #// 字体大小,默认:32 + "font": "", #// 字体 + "color": "" # // 水印颜色,colorname + } + } + header ={'Content-Type':'application/json;charset=utf-8'} + res = requests.post(url = url,data=json.dumps(param),headers=header) + print(json.loads(res.text).get('filepath')) + if json.loads(res.text)['code'] == "0": + res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['filepath'].split("\\")[-1]} else: - res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['returnCode']} - - #print('----------关闭视频-------------------------') - url = "http://localhost:6543/StopPreview?dev_idx=0" - res = requests.get(url = url) + res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['code']} + print(res_data) + # 关闭摄像头 + url = 'http://127.0.0.1:6543/video=close' + param = {"camidx":"0"} + header = {'Content-Type': 'application/json;charset=utf-8'} + res = requests.post(url=url, data=json.dumps(param), headers=header,timeout=10) + print('关闭摄像头:::::::',json.loads(res.text)['code']) + stop_thread(thread=p) return res_data - except Exception as e : + except Exception as e: print('报错信息: ' + e + ' ,File: ' + __file__ + ', Line ' + str(sys._getframe().f_lineno)) return {'code':-1,'msg':e} + # # linux 版本 + # def getPic(self): + # try: + # # if path: + # # self.path = path + # #print('----------预览视频-------------------------') + # # 打開視頻 + # url = "http://localhost:6543/StartPreview?dev_idx=0&res_id=0&pixfmt=pixfmt" + # res = requests.get(url = url) + # # print(json.loads(res.text)) + # #print(json.loads(res.text)['data']) + # # print(json.loads(res.text)['code']=='0') + # if json.loads(res.text)['returnCode']!=0: + # return {'code':-1,'msg':"打开视频失败"} + # time.sleep(2) + + # #print('----------拍照-------------------------',__file__) + # # 打開視頻 + # url = "http://localhost:6543/getPic?savepath="+self.path+"&quality=80" + # res = requests.get(url = url) + + # #print(json.loads(res.text)['data']["path"]) + # #print(json.loads(res.text)['returnCode']==0) /home/yanyi/Project/MainManage/img/2022-9-9 15-36-35.jpg + # if json.loads(res.text)['returnCode']==0: + # res_data = {'code':0,'msg':"图片保存成功","path":json.loads(res.text)['data']["path"].split("/")[-1]} + # else: + # res_data= {'code':-1, 'msg':"图片保存失败", "path":json.loads(res.text)['returnCode']} + + # #print('----------关闭视频-------------------------') + # url = "http://localhost:6543/StopPreview?dev_idx=0" + # res = requests.get(url = url) + + # return res_data + + # except Exception as e : + # print('报错信息: ' + e + ' ,File: ' + __file__ + ', Line ' + str(sys._getframe().f_lineno)) + # return {'code':-1,'msg':e} if __name__ =="__main__": + obj = GaoPaiYi() + obj.getPic() path= '/tmp' # pic_url = GaoPaiYi().getPic(path) # print(pic_url) diff --git a/Common/create_barcode.py b/Common/create_barcode.py index ac0f448..24b20c0 100644 --- a/Common/create_barcode.py +++ b/Common/create_barcode.py @@ -100,14 +100,14 @@ class CreateBarcode:

- 华润三九制药
+ 华润三九制药
试剂名称: {}
级别: {}
批号: {}
编号: {}
货位号: {}
-

+

""".format( @@ -125,8 +125,8 @@ class CreateBarcode: printer.setPaperSize(QSizeF(30.0,18.0),QPrinter.Millimeter) # printer.setPaperSize(QSizeF(30.0,50.0),QPrinter.Millimeter) # 设置纸张到条码的边距 左上下右 - # printer.setPageMargins(6, 2, 0, 0, QPrinter.Millimeter) - printer.setPageMargins(20, 20, 0, 0, QPrinter.Millimeter) + printer.setPageMargins(6, 3, 0, 0, QPrinter.Millimeter) + # printer.setPageMargins(20, 20, 0, 0, QPrinter.Millimeter) document.setPageSize(QSizeF(printer.pageRect().size())) #document.setPageSize(QSizeF(50.0,30.0)) @@ -134,7 +134,7 @@ class CreateBarcode: print('正在打印中。。。。') document.print_(printer) print('打印完成。。') - # os.remove(file_name) + os.remove(kwargs.get("file_path")) if __name__ == '__main__': diff --git a/apps/drug/views.py b/apps/drug/views.py index 96becf8..e8c415a 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -9,7 +9,7 @@ from flask import jsonify, request, g, send_from_directory from flask import Blueprint from db_logic.client import BllClient from db_logic.dangerous import BllDangerous - +from sqlalchemy import and_ from db_logic.medicament import BllMedicament from db_logic.medicament_record import BllMedicamentRecord @@ -370,7 +370,8 @@ def save_drug_img_info(): # 根据条码查询试剂信息 drug_info = BllMedicament().findEntity( EntityMedicament.medicament_id == medicament_id) - + if not drug_info: + return jsonify(Utils.false_return(msg="试剂信息有误")) obj = EntityMedicamentRelationImage( name=drug_info.name, variety_id=variety_id, @@ -416,8 +417,6 @@ def use_gaopaiyi(): return jsonify(data) # 获取药剂图片列表 - - @drug_router.route("/get_medicament_image", methods=["GET", "POST"]) # @token_auth.login_required def get_medicament_image(): @@ -426,7 +425,7 @@ def get_medicament_image(): medicament_id = request.values.get("medicament_id") data_list = BllMedicamentRelationImage().findList( - EntityMedicamentRelationImage.variety_id == variety_id).all() + EntityMedicamentRelationImage.medicament_id == medicament_id).all() # data_list = Utils.resultAlchemyData(data_list) data = Utils.true_return(msg='获取成功', data=data_list) return jsonify(data) @@ -461,4 +460,23 @@ def get_stay_putin_list(): data = BllMedicament().get_drug_type_list(status=int(status), client_id=client_id, page_param=page_param, user=g.current_user) data_list = Utils.msyql_table_model(data) - return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords})) \ No newline at end of file + return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords})) + +# 更改试剂状态 +@drug_router.route("/update_drug_status", methods=["POST"]) +@token_auth.login_required +def update_drug_status(): + bar_code = request.values.get("bar_code") + status = request.values.get("status") + bar_code, new_code = Utils.get_bar_code_reverse(bar_code=bar_code) + obj = BllMedicament().findEntity( + and_( + EntityMedicament.bar_code == bar_code, + EntityMedicament.bar_code == new_code + ) + ) + if not obj: + return jsonify(Utils.false_return(msg="试剂信息有误")) + obj.status = status + BllMedicament().update(obj) + return jsonify(Utils.true_return(msg="修改成功")) \ No newline at end of file diff --git a/apps/drug_template/views.py b/apps/drug_template/views.py index ed124f2..db6cf6a 100644 --- a/apps/drug_template/views.py +++ b/apps/drug_template/views.py @@ -162,7 +162,7 @@ def bind_tmp_input_db(): BllClient().findEntity(EntityClient.client_id==drug_entity.client_id), user_info ) - return jsonify(Utils.true_return(msg="药剂入库成功")) + return jsonify(Utils.true_return(msg="药剂入库成功", data=Utils.to_dict(drug_entity))) except Exception as error: return jsonify(Utils.false_return(msg="数据异常,入库失败: %s" % error)) diff --git a/apps/monitor/views.py b/apps/monitor/views.py index 15e6cf4..6016165 100644 --- a/apps/monitor/views.py +++ b/apps/monitor/views.py @@ -24,7 +24,7 @@ monitor_router = Blueprint('monitor', __name__) def get_day_monitor(): client_id = request.values.get("client_id") # TODO 添加房间筛选 - client_place = request.values.get("client_place") + client_place = request.values.get("place") start_time = request.values.get("start_time") end_time = request.values.get("end_time") page = request.values.get("page", 1) @@ -62,7 +62,7 @@ def get_day_monitor(): def get_day_monitor_info(): client_id = request.values.get("client_id") # TODO 添加房间筛选 - client_place = request.values.get("client_place") + client_place = request.values.get("place") start_time = request.values.get("start_time") end_time = request.values.get("end_time") page = request.values.get("page", 1) diff --git a/apps/report/views.py b/apps/report/views.py index 996f655..43f5fbd 100644 --- a/apps/report/views.py +++ b/apps/report/views.py @@ -67,7 +67,7 @@ def get_stock_data_info(): page = int(request.values.get('page', 1)) page_size = int(request.values.get('page_size', 15)) # TODO 添加房间筛选 - client_place = request.values.get("client_place") + client_place = request.values.get("palce") client_id = request.values.get("client_id") page_param = PageParam(page, page_size) @@ -117,7 +117,7 @@ def drun_input_info(): customer_id = None client_id = request.values.get("client_id") # TODO 添加房间筛选 - client_place = request.values.get("client_place") + client_place = request.values.get("place") # 分页处理 page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) @@ -328,7 +328,7 @@ def drug_log_type_info(): page_param = PageParam(page, page_size) # TODO 添加房间筛选 - client_place = request.values.get("client_place") + client_place = request.values.get("place") client_id = request.values.get("client_id") # 报表数据 diff --git a/apps/temporary_auth/views.py b/apps/temporary_auth/views.py index 1c0ae9d..e6191bd 100644 --- a/apps/temporary_auth/views.py +++ b/apps/temporary_auth/views.py @@ -137,6 +137,7 @@ def solve_apply(): # user_id = request.values.get("user_id") user_id = g.current_user.user_id # user_id_pt = request.values.get("user_id_pt") + t = request.values.get("t") obj = BllUserApply().findEntity(EntityUserApply.id == apply_id) if obj.is_solve == 1: return jsonify(Utils.false_return(msg="已受理,无需重复受理")) @@ -147,8 +148,9 @@ def solve_apply(): if user_id == obj.solve_user_id: return jsonify(Utils.false_return(msg="不能位同一人审批")) obj.solve_user_id_pt=user_id - obj.is_solve == 1 - BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_id_pt], auth_type=2) + obj.is_solve = 1 + obj.time_hour=t + BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_id_pt], auth_type=2, t=t) obj.solve_date = Utils.get_str_datetime() # obj.solve_user_id = user_id # obj.solve_user_id_pt = user_id_pt diff --git a/db_logic/user_temporary_auth.py b/db_logic/user_temporary_auth.py index cebf221..2c216a9 100644 --- a/db_logic/user_temporary_auth.py +++ b/db_logic/user_temporary_auth.py @@ -20,13 +20,15 @@ class BllUserTemporaryAuth(Repository): def __init__(self, entityType=EntityUserTemporaryAuth): super().__init__(entityType) - def create_temporary_auth(self, user_ids, auth_type): + def create_temporary_auth(self, user_ids, auth_type, t=None): # try: # client_code = BllClient().findEntity(EntityClient.client_id == client_id).client_code # except: # client_code = '' + if not t: + t = 8 for user_id in user_ids: - end_date = str(datetime.datetime.now() + datetime.timedelta(minutes=10))[:-7] + end_date = str(datetime.datetime.now() + datetime.timedelta(hours=int(t)))[:-7] obj = self.entityType() obj.user_id=user_id obj.create_date = Utils.get_str_datetime() diff --git a/models/power_models.py b/models/power_models.py index 0adb1af..6ea8b5b 100644 --- a/models/power_models.py +++ b/models/power_models.py @@ -93,6 +93,7 @@ class EntityUserApply(Base): solve_user_id_pt = Column(String(50), comment="受理人") func_type = Column(Integer, comment="类型") use_doc = Column(Text, comment="类型") + time_hour = Column(String(50), comment="时间小时") # drug_name = Column(String(50), comment="试剂名称")