diff --git a/Common/GaoPaiYi.py b/Common/GaoPaiYi.py index a8e147a..04efd12 100644 --- a/Common/GaoPaiYi.py +++ b/Common/GaoPaiYi.py @@ -3,6 +3,7 @@ import time import json import uuid import sys +import os # 获取分辨率索引 url = "http://localhost:6543/GetAllDisplayInfo" @@ -16,19 +17,23 @@ param={ class GaoPaiYi(): - path = "/home/yanyi/Project/MainManage" # 默认存储地址 + # path = "/home/yanyi/Project/MainManage/img" # 默认存储地址 + path = os.path.join(os.getcwd(), "img") + if not os.path.exists(path): + os.umask(0) + os.makedirs(path) def __init__(self): pass - def getPic(self,path=''): + def getPic(self): try: - if path: - self.path = path + # 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)) #print(json.loads(res.text)['data']) # print(json.loads(res.text)['code']=='0') if json.loads(res.text)['returnCode']!=0: @@ -43,7 +48,7 @@ class GaoPaiYi(): #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"]} + 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']} @@ -60,5 +65,5 @@ class GaoPaiYi(): if __name__ =="__main__": path= '/tmp' - pic_url = GaoPaiYi().getPic(path) - print(pic_url) + # pic_url = GaoPaiYi().getPic(path) + # print(pic_url) diff --git a/Common/Utils.py b/Common/Utils.py index cda8045..a4d895e 100644 --- a/Common/Utils.py +++ b/Common/Utils.py @@ -34,6 +34,9 @@ class Utils(object): else: new_code = bar_code return bar_code, new_code + + def getDrugUnitCode(num): + return f"{Utils.get_file_name_datetime()[:8]}{(3-len(str(num+1)))* '0' + str(num+1)}" #MD5加密78 def MD5(str): @@ -298,6 +301,10 @@ class Utils(object): return data +if __name__ == '__main__': + a = Utils.get_file_name_datetime()[:4] + print(a) + #分页参数模型 class PageParam(object): def __init__(self, curPage, pageRows, totalRecords=None, orderType=None, orderField=None,): diff --git a/Common/create_barcode.py b/Common/create_barcode.py index 1ef5dc4..ac0f448 100644 --- a/Common/create_barcode.py +++ b/Common/create_barcode.py @@ -73,7 +73,8 @@ class CreateBarcode: def create_drug_lobel_code(self, **kwargs): a = Code128Encoder( - kwargs.get("code_number"), + # kwargs.get("code_number"), + "111", options={ 'ttf_font': os.path.join(os.getcwd(),'arial.ttf'), 'label_border': 0, 'height': 15, 'bottom_border': 0,'ttf_fontsize':0, @@ -82,6 +83,7 @@ class CreateBarcode: file_name = os.path.join(self.code_path, str(uuid.uuid4()) + '.png') + print(file_name) a.save(file_name, bar_width=1) kwargs["file_path"] = file_name self.printer_drug_label(**kwargs) @@ -89,44 +91,42 @@ class CreateBarcode: def printer_drug_label(self, **kwargs): a = QApplication([]) document = QTextDocument() - #TODO 添加溶剂 + #

html = """ Report -

-

- 珠海市食品药品检验所
- 名称: {}
+

+

+ 华润三九制药
+ 试剂名称: {}
+ 级别: {}
+ 批号: {}
编号: {}
- 浓度: {}   溶剂: {}
- 配置日期: {}
- 有 效 期:{}
- 配 置 人:{}
+ 货位号: {}

""".format( - kwargs.get("name"), - kwargs.get("code_number"), kwargs.get("purity"), - kwargs.get("solvent"), - kwargs.get("start_time")[:10], - kwargs.get("end_time")[:10], - kwargs.get("user_name"), + kwargs.get("standard_code"), + kwargs.get("remark12"), + kwargs.get("cell_position_code"), kwargs.get("file_path"), ) document.setHtml(html) printer = QPrinter() printer.setPageSize(QPagedPaintDevice.Custom) - printer.setPaperSize(QSizeF(60.0,40.0),QPrinter.Millimeter) + # printer.setPaperSize(QSizeF(60.0,40.0),QPrinter.Millimeter) + 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(6, 2, 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)) diff --git a/Common/read_excel.py b/Common/read_excel.py index 29516c7..5a401b2 100644 --- a/Common/read_excel.py +++ b/Common/read_excel.py @@ -24,7 +24,7 @@ class ReadExcel: value = self.ws['{}'.format('C' + str(key))].value self.template_list.append(value) return self.template_list - elif self.ws['A1'].value == '单位编号' and self.ws['B1'].value == '产品编号': + elif self.ws['A1'].value == '申购单编号' and self.ws['B1'].value == '采购单编号': drug_list = [] # lineIndex = 0 try: @@ -39,16 +39,24 @@ class ReadExcel: } # TODO 添加供应商修改 + # key_list = [ + # "unit_code", "remark2", "category", + # "speci", "name", "english_name", + # "purity", "cas_number", "standard_code", + # "net_weight", "net_weight_unit", "export_count", + # "production_date", "shelf_life", "expiration_date", + # "price", "is_supervise", "remain", + # "manufacturer", "distributor", "storage_condition", "remark9" + # ] key_list = [ - "unit_code", "remark2", "category", - "speci", "name", "english_name", - "purity", "cas_number", "standard_code", - "net_weight", "net_weight_unit", "export_count", - "production_date", "shelf_life", "expiration_date", - "price", "is_supervise", "remain", - "manufacturer", "distributor", "storage_condition", "remark9" + "remark7", "remark8", "category", "remark9", + "name", "english_name","purity","cas_number","standard_code", + "unit_code","speci","net_weight_unit", "export_count","remark6", + "production_date", "shelf_life", "expiration_date", + "price", "is_supervise", "remain", "manufacturer", + "storage_condition", "remark10" ] - v_list = list("ABCDEFGHIJKLNOPQRSTUVW") + v_list = list("ABCDEFGHIJKLMNOPQRSTUVW") # 采用列表和字母对应的两个列表,进行循环的方式写入字典,简化代码量 @@ -104,6 +112,7 @@ class ReadExcel: drug_template_dict["func_type"] = func_type drug_template_dict["total"] = drug_template_dict.get("remain") + drug_template_dict["net_weight"] = drug_template_dict.get("speci") drug_list.append(drug_template_dict) self.template_list.append(json.dumps(drug_list)) diff --git a/apps/drug/views.py b/apps/drug/views.py index 9fff909..31c90cd 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -4,7 +4,8 @@ @Date:2022/07/26 11:19:30 ''' import datetime -from flask import jsonify, request, g +import os +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 @@ -14,10 +15,14 @@ from db_logic.medicament import BllMedicament from db_logic.medicament_record import BllMedicamentRecord from db_logic.msds import BllMsDs from db_logic.user_medicament import BllUserMedicament -from models.medicament_models import EntityMedicament +from db_logic.medicament_relation_image import BllMedicamentRelationImage +from models.medicament_models import EntityMedicament, EntityMedicamentRelationImage from models.client_models import EntityClient from Common.Utils import DrugStatus, PageParam, Utils from Common.auth import token_auth +from db_logic.user_temporary_auth import BllUserTemporaryAuth +from Common.GaoPaiYi import GaoPaiYi + drug_router = Blueprint("drug", __name__) @@ -117,6 +122,12 @@ def drug_return(): drug_info.client_id = place # user_info = BllUser().findEntity(EntityUser.user_id == user_id) user_info = g.current_user + + user_id = user_info.user_id + user_id_pt = user_id + BllUserTemporaryAuth().create_temporary_auth(user_ids=[user_id, user_id_pt], client_id=drug_info.client_id) + + BllMedicament().drugReturn(drug_info, BllClient().findEntity(drug_info.client_id), user_info) data = Utils.true_return(msg="药剂归还成功", data=Utils.to_dict(drug_info)) return jsonify(data) @@ -342,6 +353,98 @@ def get_dangerous_list(): return jsonify(Utils.true_return(data={"data_list": Utils.msyql_table_model(data_list), "total_cout": page_param.totalRecords})) +# 图片上传接口 +@drug_router.route("/save_drug_img", methods=["POST"]) +# @token_auth.login_required +def save_drug_img_info(): + # 药剂类别 + variety_id = request.values.get("variety_id") + medicament_id = request.values.get("medicament_id") + file_base64 = request.files.get("file") + # try: + gaopaiyi_obj = GaoPaiYi() + img_path = f"{Utils.UUID()}.jpg" + file_base64.save(os.path.join(gaopaiyi_obj.path, img_path)) + # 根据条码查询试剂信息 + drug_info = BllMedicament().findEntity( + EntityMedicament.medicament_id == medicament_id) + + obj = EntityMedicamentRelationImage( + name=drug_info.name, + variety_id=variety_id, + medicament_id=medicament_id, + pic_url=img_path, + create_date=Utils.get_str_datetime(), + ) + BllMedicamentRelationImage().insert(obj) + return jsonify(Utils.true_return(msg="上传成功")) + + +# 读取文件返回 +@drug_router.route("/get_img_info/", methods=["GET"]) +def get_drug_img(img_path): + return send_from_directory(GaoPaiYi().path, img_path) + +# 高拍仪接口 +@drug_router.route("/use_gaopaiyi", methods=["GET", "POST"]) +@token_auth.login_required +def use_gaopaiyi(): + # 药剂类别 + variety_id = request.values.get("variety_id") + medicament_id = request.values.get("medicament_id") + + pic_data = GaoPaiYi().getPic() + if pic_data['code'] == 0: + + # 根据条码查询试剂信息 + drug_info = BllMedicament().findEntity( + EntityMedicament.medicament_id == medicament_id) + + obj = EntityMedicamentRelationImage( + name=drug_info.name, + variety_id=variety_id, + medicament_id=medicament_id, + pic_url=pic_data['path'], + create_date=Utils.get_str_datetime(), + ) + BllMedicamentRelationImage().insert(obj) + data = Utils.true_return(msg="高拍仪拍照成功") + else: + data = Utils.false_return(msg=pic_data['msg']) + return jsonify(data) + +# 获取药剂图片列表 + + +@drug_router.route("/get_medicament_image", methods=["GET", "POST"]) +# @token_auth.login_required +def get_medicament_image(): + # 药剂类别 + variety_id = request.values.get("variety_id") + medicament_id = request.values.get("medicament_id") + + data_list = BllMedicamentRelationImage().findList( + EntityMedicamentRelationImage.variety_id == variety_id).all() + # data_list = Utils.resultAlchemyData(data_list) + data = Utils.true_return(msg='获取成功', data=data_list) + return jsonify(data) + +# 删除药剂图片 +@drug_router.route("/del_medicament_image", methods=["GET", "POST"]) +@token_auth.login_required +def del_medicament_image(): + # 药剂类别 + image_id = request.values.get("image_id") + + data_obj = BllMedicamentRelationImage().findEntity( + EntityMedicamentRelationImage.image_id == image_id) + if data_obj: + BllMedicamentRelationImage().delete( + EntityMedicamentRelationImage.image_id == image_id) + data = Utils.true_return(msg='删除成功') + else: + data = Utils.false_return(msg='未找到该图片') + return jsonify(data) diff --git a/apps/drug_template/views.py b/apps/drug_template/views.py index 3bf372b..aaa674f 100644 --- a/apps/drug_template/views.py +++ b/apps/drug_template/views.py @@ -24,7 +24,7 @@ from models.client_models import EntityClient from models.medicament_models import EntityMedicament, EntityMedicamentTemplate from Common.auth import token_auth from Common.create_barcode import CreateBarcode - +from db_logic.user_temporary_auth import BllUserTemporaryAuth tmp_router = Blueprint("drug_tmplate", __name__) @@ -110,7 +110,7 @@ def bind_tmp_input_db(): customer_id=customer_id, drug_info=drug_info, user_info=user_info ) - + num = BllMedicament().execute(f"select count(*) num from rms_medicament where name like '%{drug_info.get('name')}%' and remark12 like '%{Utils.get_file_name_datetime()[:4]}%'").fetchone().num remain_num = drug_info.get("remain", 0) if not remain_num: remain_num = drug_info.get("total") @@ -130,6 +130,7 @@ def bind_tmp_input_db(): # "status":1, "remain": remain_num, "func_type": func_type, + "remark12":Utils.getDrugUnitCode(num) } if len(bar_code) > 10: new_dict["status"] = 5 @@ -144,6 +145,15 @@ def bind_tmp_input_db(): new_dict[i] = value drug_entity = EntityMedicament(**new_dict) try: + # if func_type in [1,2]: + # # 打印标签 + # obj = CreateBarcode() + # obj.create_drug_lobel_code(**new_dict) + # user_id = user_info.user_id + # user_id_pt = request.values.get("user_id_pt", '34306da6-0f11-11ed-ba01-009027e3906b') + # BllUserTemporaryAuth().create_temporary_auth(user_ids=[user_id, user_id_pt], client_id=client_id) + obj = CreateBarcode() + obj.create_drug_lobel_code(**new_dict) BllMedicament().drugPutIn( drug_entity, BllClient().findEntity(EntityClient.client_id==client_id), @@ -353,3 +363,14 @@ def drug_group_list(): data = BllMedicament().drug_group_info_list() data_list = Utils.msyql_table_model(data) return jsonify(Utils.true_return(data=data_list)) + + +# 获取试剂可入库的柜子和层 +@tmp_router.route("/enter_db_client_list", methods=["POST"]) +def drug_enter_db_client_list(): + func_type = request.values.get("func_type") + drug_name = request.values.get("drug_name") + if not drug_name: + drug_name = '' + data = BllMedicament().get_drug_save_db_info(drug_name=drug_name, func_type=func_type) + return jsonify(Utils.true_return(data=data)) \ No newline at end of file diff --git a/apps/report/utils_base.py b/apps/report/utils_base.py index dc7d3e2..1d3171c 100644 --- a/apps/report/utils_base.py +++ b/apps/report/utils_base.py @@ -14,14 +14,19 @@ from apps.report.dows_utils import dows_flie def get_finds_list(tp): dic = { - "1": ["name", "cas_number", "speci", "purity", "count_number", "sum_remain"], + # put_in_user_name,category,expiration_date + "1": ["name", "cas_number", "speci", "purity", "count_number", "sum_remain", "manufacturer", "category", "put_in_user_name", "expiration_date"], "2": ['name', 'manufacturer', 'distributor', 'purity', 'cas_number', 'speci', 'remain', 'net_weight', 'net_weight_unit', 'price', 'production_date', 'expiration_date', 'shelf_life', 'unit_code', 'remark2', 'category', 'standard_code', 'storage_condition', 'remark9', 'put_in_user_name', 'put_in_date'], + # "2": ["name", "bar_code", "purity", "speci", "manufacturer", "count_number", "status", "put_in_date", "put_in_user_name", "client_name"], "3": ['name', 'unit_code', 'bar_code', 'remark2', 'speci', 'remain', 'purity', 'cas_number', 'production_date', 'expiration_date', 'shelf_life', 'price', 'net_weight', 'net_weight_unit', 'put_in_date', 'manufacturer', 'storage_condition', 'remark9', 'category', 'standard_code', 'put_in_user_name', 'status', 'by_user_name', 'client_name'], "4": ["name", "purity", "cas_number", "enter_stock", "in_stock", "up_stock", "no_stock"], "5": ["name", "purity", "cas_number", "speci", "on_in", "use_num", "use_level", "ratio"], "6": ["create_user_name", "role_name", "use_num", "use_amount", "ratio"], "7": ["name", "purity", "cas_number", "speci", "new_on", "sum_tp2", "sum_tp3"], + "8": ["name", "unit_code", "bar_code", "purity", "cas_number", "use_quantity", "status", "create_date", "create_user_name", "client_name"], + # "8": ["bar_code", "name", "category", "speci", "purity", "", "", "remain", "put_in_user_name", "by_user_name", "", "status", "client_name", "by_user_date"], + "9": ["client_name", "place", "day_date", "avg_wd", "avg_sd", "avg_voc"], "10": ["day_date", "wd", "sd", "voc",], "11": ["name","code_number","unit_code","start_time","end_time","purity","capacity","basis","doc_log","user_name"], @@ -31,14 +36,16 @@ def get_finds_list(tp): def get_finds_name_list(tp): dic = { - "1": ["试剂名称", "CAS码", "规格", "纯度", "在库剩余数量(瓶)", "在库剩余总质量(g)"], + "1": ["试剂名称", "CAS码", "规格", "纯度", "在库剩余数量(瓶)", "生产厂家", "试剂分类(易制毒、易制爆、剧毒品)", "入库人", "过期时间"], "2": ['试剂名称', '生产厂商', '供应商', '纯度', 'CAS码', '规格', '余量', '净含量', '单位', '价格', '生产日期', '过期日期', '保质期', '单位编号', '产品编号', '类别', '批号', '存储条件', '密度', '入库操作人', '入库时间'], + # "2": ["试剂名称", "试剂编码", "纯度", "规格", "生产厂商", "入库数量", "目前在库状态", "入库时间", "入库人员", "入库终端"], "3": ['试剂名称', '单位编号', '试剂编码', '产品编号', '规格', '余量', '纯度', 'CAS码', '生产日期', '过期日期', '保质期', '价格', '净含量', '单位', '入库日期', '生产厂商', '存储条件', '密度', '类别', '批号', '试剂管理人', '状态', '最后使用人', '所属终端'], "4": ["试剂名称", "纯度", "CAS码", "入库数量", "当前在库数量", "当前借出数量", "消耗数量"], "5": ["试剂名称", "纯度", "CAS码", "规格", "库存量(瓶)", "使用次数", "总用量(g)", "占用百分比"], "6": ["用户名称", "用户身份","使用次数","总用量(g)","占用百分比(%)"], "7": ["用户名称", "纯度", "CAS码", "规格", "当前库存总量", "领用次数", "归还次数"], "8": ["试剂名称", "单位编号", "试剂编码", "纯度", "CAS码", "用量", "状态", "操作时间", "操作人员", "所属终端"], + # "8": ["药剂编码", "试剂名称", "类别", "规格", "纯度", "用量(重量)", "用量(体积)液体自动换算", "当前余量", "试剂管理员", "试剂领用人", "操作类型", "目前状态", "柜体名称", "记录时间"], "9": ["柜体名称", "所处位置", "日期", "温度(平均值)", "湿度(平均值)", "VOC(平均值)"], "10": ["时间", "温度", "湿度", "VO含量"], diff --git a/apps/temporary_auth/views.py b/apps/temporary_auth/views.py new file mode 100644 index 0000000..3cba9c2 --- /dev/null +++ b/apps/temporary_auth/views.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +''' +@Date: 2022/12/14 15:17:57 +''' +import sys +sys.path.append('.') + +import json +from flask import Blueprint, request, jsonify, g + +from db_logic.user_temporary_auth import BllUserTemporaryAuth +from db_logic.user_apply import BllUserApply +from db_logic.medicament import BllMedicament +from db_logic.client import BllClient +from db_logic.user import BllUser +from models.client_models import EntityClient +from models.power_models import EntityUserApply, EntityUserTemporaryAuth +from Common.Utils import Utils, PageParam +from Common.auth import token_auth + +temporary_bp = Blueprint("temporary_auth", __name__) + + + +# 获取试剂分组列表 +@temporary_bp.route("/get_drug_group_list", methods=["POST"]) +def get_use_drug_list(): + client_id = request.values.get("client_id") + page = request.values.get("page") + page_size = request.values.get("page_size") + page_param = PageParam(int(page), int(page_size)) + data = BllMedicament().use_drug_info_list(client_id=client_id, page_param=page_param) + data_list = Utils.msyql_table_model(data_list=data) + return jsonify(Utils.true_return(data={"data_list":data_list, "total_count": page_param.totalRecords})) + + +# 创建申请记录 +@temporary_bp.route("/add", methods=["POST"]) +def user_apply_log(): + user_id = request.values.get("user_id") + user_id_pt = request.values.get("user_id_pt") + drug_name = request.values.get("drug_name") + drug_num = request.values.get("drug_num") + client_id = request.values.get("client_id") + func_type = request.values.get("func_type") + use_doc = request.values.get("use_doc") + try: + client_code = BllClient().findEntity(EntityClient.client_id==client_id).client_code + except: + client_code = '' + obj = EntityUserApply( + user_id = user_id, + user_id_pt = user_id_pt, + drug_name = drug_name, + drug_num = drug_num, + create_date = Utils.get_str_datetime(), + is_solve = 0, + client_id = client_id, + func_type=func_type, + client_code=client_code, + use_doc=use_doc + ) + BllUserApply().insert(obj) + return jsonify(Utils.true_return()) + +# 展示 +@temporary_bp.route("/get_list", methods=["POST"]) +# @token_auth.login_required +def get_info_list(): + client_id = request.values.get("client_id") + func_type = request.values.get("func_type") + page = request.values.get("page") + page_size = request.values.get("page_size") + page_param = PageParam(int(page), int(page_size)) + data = BllUserApply().get_list_info(client_id=client_id, func_type=func_type, page_param=page_param) + user_list = BllUser().findList() + user_dict = {} + for i in user_list: + user_dict[i.user_id] = i.real_name + data_list = [] + for i in data: + i_dict = dict(i._mapping) + i_dict['user_name'] = user_dict.get(i_dict["user_id"]) + i_dict["user_name_pt"] = user_dict.get(i_dict["user_id_pt"]) + i_dict["solve_user_name"] = user_dict.get(i_dict["solve_user_id"], '') + i_dict["solve_user_pt_name"] = user_dict.get(i_dict["solve_user_id_pt"], '') + data_list.append(i_dict) + return jsonify(Utils.true_return(data= {"data_list":data_list, "total_count": page_param.totalRecords})) + +# 删除 +@temporary_bp.route("/del", methods=["POST"]) +@token_auth.login_required +def del_user_apply(): + user_json = request.values.get("user_ids") + user_id_list = user_json.split(",") + for i in user_id_list: + BllUserApply().delete(EntityUserApply.id==i) + return jsonify(Utils.true_return()) + +# 处理消息 +@temporary_bp.route("/update_solve", methods=["POST"]) +@token_auth.login_required +def solve_apply(): + apply_id =request.values.get("id") + user_id = request.values.get("user_id") + user_id_pt = request.values.get("user_id_pt") + obj = BllUserApply().findEntity(EntityUserApply.id == apply_id) + if obj.is_solve == 1: + return jsonify(Utils.false_return(msg="已受理,无需重复受理")) + obj.is_solve = 1 + obj.solve_date = Utils.get_str_datetime() + obj.solve_user_id = user_id + obj.solve_user_id_pt = user_id_pt + BllUserTemporaryAuth().create_temporary_auth(user_ids=[obj.user_id, obj.user_pt], client_id=obj.client_id) + BllUserApply().update(obj) + return jsonify(Utils.true_return()) diff --git a/config/SystemConfig.py b/config/SystemConfig.py index 3625be0..ae61f6a 100644 --- a/config/SystemConfig.py +++ b/config/SystemConfig.py @@ -4,7 +4,9 @@ import configparser class SystemConfig: config = configparser.ConfigParser() - configPath = os.getcwd() + '/config/system.conf' + configPath = os.getcwd() + "/local_conf.conf" + if not os.path.exists(configPath): + configPath = os.getcwd() + '/config/system.conf' config.read(configPath) @classmethod diff --git a/config/server.py b/config/server.py index 9032240..729a36e 100644 --- a/config/server.py +++ b/config/server.py @@ -73,6 +73,7 @@ def register_blueprints(app: New_flask): from apps.monitor.views import monitor_router from apps.drug_form.views import drug_form_router from apps.stock_record.views import stock_router + from apps.temporary_auth.views import temporary_bp # 主概览相关 app.register_blueprint(home_router, url_prefix="/api/home") @@ -98,6 +99,8 @@ def register_blueprints(app: New_flask): # 库存盘点相关 app.register_blueprint(stock_router, url_prefix="/api/stock") + # 申请 + app.register_blueprint(temporary_bp, url_prefix="/api/temporary_auth") def create_app(): app = Flask(__name__) diff --git a/db_logic/medicament.py b/db_logic/medicament.py index e02d479..e5cefa9 100644 --- a/db_logic/medicament.py +++ b/db_logic/medicament.py @@ -26,6 +26,36 @@ class BllMedicament(Repository): entity.remark30 = '0' return super().update(entity) + # 获取可入库层数据 + def get_drug_save_db_info(self, drug_name, func_type): + sql_all = f""" + + select name, IFNULL(num,0) number, c.client_id, cell_code, cell_speci from ( + select cell_code, a.client_id, cell_speci, client_name from ( + select * from rms_client_cell + ) a LEFT JOIN( + select client_id, client_name from rms_client + ) b on a.client_id = b.client_id + ) c LEFT JOIN( + select NAME, client_id, flow_position_code, count(*) num from rms_medicament where `name` like '%{drug_name}%' and status=1, func_type={func_type} GROUP BY client_id, flow_position_code + ) d on c.client_id=d.client_id and c.cell_code=d.flow_position_code + + HAVING number < 40 + """ + data = self.execute(sql_all).fetchall() + data_dict = {} + for i in data: + if i.client_id in data_dict.keys(): + data_dict[i.client_id]["client_cell"].append(i.cell_speci) + else: + data_dict[i.client_id]["client_id"] = i.client_id + data_dict[i.client_id]["client_name"] = i.client_name + data_dict[i.client_id]["client_cell"] = [i.cell_speci] + data_list = [] + for k,v in data_dict.items(): + data_list.append(v) + return data_list + # 获取离保质期最近的同类药剂 def getDrugNearExpired(self, varietyId, customerId): drugList = self.findList( @@ -326,7 +356,7 @@ class BllMedicament(Repository): select DISTINCT `name`, speci, cas_number,net_weight_unit, purity, manufacturer, distributor, net_weight, net_weight_unit, - client_id, + client_id, put_in_user_name,category,expiration_date sum(CASE WHEN `status`=1 THEN 1 ELSE 0 END) count_number, sum(CASE WHEN `status`=1 THEN remain ELSE 0 END) sum_remain @@ -387,7 +417,10 @@ class BllMedicament(Repository): # filter_base1 += f"where client_speci='{client_speci}'" sql_all = f""" select a.*,b.client_name from ( - select * from rms_medicament {filter_base} + select + name, english_name,bar_code,manufacturer,speci,remain,purity,production_date,shelf_life,expiration_date,put_in_date,put_in_user_name, + status,by_user_name,client_id, count(*) count_number + from rms_medicament {filter_base} ) a LEFT JOIN( select client_id,client_name from rms_client {filter_base1} ) b on a.client_id=b.client_id @@ -495,6 +528,24 @@ class BllMedicament(Repository): """ return self.execute(sql_all).fetchall() + # 可领用试剂列表 + def use_drug_info_list(self, client_id, page_param): + sql_all = f""" + select + `name`, speci, purity, count(*) drug_num, manufacturer, distributor + from + rms_medicament WHERE `status`=1 and client_id='{client_id}' + GROUP BY + `name`, speci, purity + """ + try: + count_number = self.execute(f"select count(*) num from ({sql_all}) a").fetchone().num + except Exception: + count_number = 0 + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() def inster_log_shiji(self): import random diff --git a/db_logic/medicament_relation_image.py b/db_logic/medicament_relation_image.py new file mode 100644 index 0000000..8f8aacf --- /dev/null +++ b/db_logic/medicament_relation_image.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +''' +@Date:2022/08/12 15:12:42 +''' +import sys +sys.path.append('.') + +from db_logic.db_base import Repository + +from models.medicament_models import EntityMedicamentRelationImage + +from Common.Utils import Utils + + +#药剂品种业务逻辑类 +class BllMedicamentRelationImage(Repository): + def __init__(self, entityType=EntityMedicamentRelationImage): + super().__init__(entityType) + + diff --git a/db_logic/user_apply.py b/db_logic/user_apply.py new file mode 100644 index 0000000..930ba45 --- /dev/null +++ b/db_logic/user_apply.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +''' +@Date: 2022/12/14 15:15:48 +''' +import sys +sys.path.append('.') + + +from db_logic.db_base import Repository +from models.power_models import EntityUserApply +from Common.Utils import Utils + +class BllUserApply(Repository): + + def __init__(self, entityType=EntityUserApply): + super().__init__(entityType) + + def get_list_info(self, client_id, func_type, page_param): + fileter_base = "" + if client_id: + fileter_base += f" client_id='{client_id}'" + if func_type: + if fileter_base: + fileter_base += " and " + fileter_base += f" func_type={func_type}" + if fileter_base: + fileter_base = f" where {fileter_base}" + + sql_all = f""" + select a.*, b.client_name from ( + select * from rms_user_apply {fileter_base} + ) a LEFT JOIN ( + select * from rms_client + ) b on a.client_id=b.client_id + order by a.create_date desc + """ + try: + count_number = self.execute(f"select count(*) num from rms_user_apply {fileter_base} order by create_date desc").fetchone().num + except Exception: + count_number = 0 + if page_param: + page_param.totalRecords = count_number + sql_all = Utils.sql_paging_assemble(sql_all, page_param) + return self.execute(sql_all).fetchall() diff --git a/db_logic/user_temporary_auth.py b/db_logic/user_temporary_auth.py new file mode 100644 index 0000000..8fee817 --- /dev/null +++ b/db_logic/user_temporary_auth.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +''' +@Date: 2022/12/14 15:14:59 +''' +import sys +sys.path.append('.') + + +import datetime +from sqlalchemy import and_ +from Common.Utils import Utils +from db_logic.db_base import Repository +from models.power_models import EntityUserTemporaryAuth +from db_logic.client import BllClient +from models.client_models import EntityClient + +class BllUserTemporaryAuth(Repository): + + def __init__(self, entityType=EntityUserTemporaryAuth): + super().__init__(entityType) + + def create_temporary_auth(self, user_ids, client_id): + try: + client_code = BllClient().findEntity(EntityClient.client_id == client_id).client_code + except: + client_code = '' + for user_id in user_ids: + obj = self.findEntity( + and_( + self.entityType.user_id == user_id, client_id== client_id + ) + ) + end_date = str(datetime.datetime.now() + datetime.timedelta(minutes=10))[:-7] + if obj: + obj.create_date = Utils.get_str_datetime() + obj.end_date = end_date + obj.client_id = client_id + obj.client_code = client_code + self.update(obj) + else: + obj = self.entityType() + obj.user_id=user_id + obj.create_date = Utils.get_str_datetime() + obj.end_date = end_date + obj.client_id = client_id + obj.client_code = client_code + self.insert(obj) diff --git a/demo.py b/demo.py index f9ad727..57e3cf7 100644 --- a/demo.py +++ b/demo.py @@ -27,8 +27,6 @@ def picture_shoot(image_name='img.png', image_path=r'C:/local_project/imgs') -> print("保存" + image_name + "成功!") break cap.release() - cv2.destroyAllWindows() - - + cv2.destroyAllWindows() if __name__ == '__main__': picture_shoot() \ No newline at end of file diff --git a/models/medicament_models.py b/models/medicament_models.py index 8151fdc..ef8c501 100644 --- a/models/medicament_models.py +++ b/models/medicament_models.py @@ -306,6 +306,27 @@ class EntityMedicamentMotherLiquor(Base): unit_code = Column(Text, comment="单位编号") +class EntityMedicamentRelationImage(Base): + __tablename__ = "rms_medicament_relation_image" + __table_args__ = ( + { + "comment": "药剂关联图片" + } + ) + image_id = Column(String(50), primary_key=True, comment="ID", default=get_uuid) + name = Column(String(50), comment="药剂名称") + variety_id = Column(String(50), comment="药剂类别Id") + medicament_id = Column(String(50), comment="药剂Id") + pic_url = Column(String(200), comment="图片路径") + create_date = Column(String(50), comment="创建日期") + remark1 = Column(String(50), comment='扩展字段1') + remark2 = Column(String(50), comment='扩展字段2') + remark3 = Column(String(50), comment='扩展字段3') + remark4 = Column(String(50), comment='扩展字段4') + is_add = Column(Integer, comment="", default=0) + + + if __name__ == '__main__': drug_info = {} diff --git a/models/power_models.py b/models/power_models.py index 1b05896..8d9c8bd 100644 --- a/models/power_models.py +++ b/models/power_models.py @@ -5,7 +5,7 @@ ''' import sys sys.path.append(".") -from sqlalchemy import Column, String, Integer +from sqlalchemy import Column, String, Integer, Text from models.models_base import Base, get_uuid @@ -58,6 +58,47 @@ class EntityModuleRelation(Base): create_user_name = Column(String(50), comment="创建用户名称") is_add = Column(Integer, comment="", default=0) + +class EntityUserTemporaryAuth(Base): + __tablename__ = 'rms_user_temporary_auth' + __table_args__ = ( + { + "comment": "用户临时权限表" + } + ) + 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="创建时间") + end_date = Column(String(50), comment="权限结束时间") + is_add = Column(Integer, comment="是否同步", default=0) + client_id = Column(String(50), comment="柜子id") + client_code = Column(String(50), comment="柜子code") + +class EntityUserApply(Base): + __tablename__ = "rms_user_apply" + __table_args__ = ( + { + "comment": "用户领用申请表" + } + ) + id = Column(String(50), primary_key=True, comment="id", default=get_uuid) + user_id = Column(String(50), comment="用户id") + user_id_pt = Column(String(50), comment="陪同用户id") + drug_name = Column(String(50), comment="试剂名称") + drug_num = Column(Integer, comment="试剂数量", default=0) + create_date = Column(String(50), comment="申请时间") + use_num = Column(Integer, comment="领用数量", default=0) + user_close = Column(Integer, comment="是否取消", default=0) + is_solve = Column(Integer, comment="是否处理", default=0) + solve_date = Column(String(50), comment="受理时间") + solve_user_id = Column(String(50), comment="受理人") + solve_user_id_pt = Column(String(50), comment="受理人") + client_id = Column(String(50), comment="柜子id") + client_code = Column(String(50), comment="柜子code") + func_type = Column(Integer, comment="类型") + use_doc = Column(Text, comment="类型") + + # if __name__ == '__main__': # from sqlalchemy import create_engine # from config.SystemConfig import SystemConfig