diff --git a/apps/drug/views.py b/apps/drug/views.py index 3024012..73f780b 100644 --- a/apps/drug/views.py +++ b/apps/drug/views.py @@ -198,10 +198,14 @@ def get_durg_record(): @token_auth.login_required def drug_ban_user_list(): seach_user = request.values.get("seach_user") + drug_id = request.values.get("drug_id") page = int(request.values.get("page", 1)) page_size = int(request.values.get("page_size", 10)) page_param = PageParam(page, page_size) - data_list = BllUserMedicament().get_user_jin_medicament(seach_user=seach_user, page_param=page_param) + data_list = BllUserMedicament().get_user_jin_medicament( + seach_user=seach_user, page_param=page_param, + drug_id=drug_id + ) return jsonify(Utils.true_return(data={"data": Utils.msyql_table_model(data_list), "total_count": page_param.totalRecords})) # 确认禁用 @@ -216,21 +220,21 @@ def drug_ban_user_confirm(): else: return jsonify(Utils.false_return()) -# 获取用户禁用试剂列表 -@drug_router.route("/user_ban_drug_list", methods=["GET", "POST"]) -@token_auth.login_required -def get_user_ban_drug_list(): - user_id = request.values.get("user_id") - data_list = BllUserMedicament().get_user_drug_name(user_id) - return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list))) +# # 获取用户禁用试剂列表 +# @drug_router.route("/user_ban_drug_list", methods=["GET", "POST"]) +# @token_auth.login_required +# def get_user_ban_drug_list(): +# user_id = request.values.get("user_id") +# data_list = BllUserMedicament().get_user_drug_name(user_id) +# return jsonify(Utils.true_return(data=Utils.msyql_table_model(data_list))) # 取消禁用试剂 @drug_router.route("/user_ban_relieve", methods=["GET", "POST"]) @token_auth.login_required def user_ban_relieve(): user_id = request.values.get("user_id") - drug_list = request.values.get("drug_list") - data = BllUserMedicament().del_user_ban_drug(user_id=user_id, drug_list=drug_list) + drug_id = request.values.get("drug_id") + data = BllUserMedicament().del_user_ban_drug(user_id=user_id, drug_id=drug_id) if data: return jsonify(Utils.true_return(msg="删除成功")) else: diff --git a/db_logic/user_medicament.py b/db_logic/user_medicament.py index f896466..d6bc1df 100644 --- a/db_logic/user_medicament.py +++ b/db_logic/user_medicament.py @@ -32,7 +32,7 @@ class BllUserMedicament(Repository): else: return True - def get_user_jin_medicament(self, seach_user, page_param): + def get_user_jin_medicament(self, seach_user, drug_id, page_param): filter_base = "" if seach_user: filter_base += f" real_name like '%{seach_user}%'" @@ -40,13 +40,12 @@ class BllUserMedicament(Repository): filter_base = f" where {filter_base}" sql_all = f""" - select - a.user_id, b.real_name, b.role_name, group_concat(c.`name`) drug_name - from rms_user_medicament as a - LEFT JOIN (select real_name, user_id, role_name from rms_user {filter_base}) - as b on a.user_id=b.user_id - LEFT JOIN rms_medicament_variety as c on a.drug_id=c.variety_id - GROUP BY a.user_id + select + a.user_id, a.real_name, a.role_name, + CASE WHEN b.id is not null THEN 1 else 0 END status_type + from (select * from rms_user {filter_base}) as a + LEFT JOIN (select id, user_id, drug_id from rms_user_medicament WHERE drug_id='{drug_id}') + as b on a.user_id=b.user_id """ try: count_number = len(self.execute(sql_all).fetchall()) @@ -64,15 +63,19 @@ class BllUserMedicament(Repository): """ return self.execute(sql_all).fetchall() - def del_user_ban_drug(self, user_id, drug_list): + def del_user_ban_drug(self, user_id, drug_id): try: - data_list = self.findList(and_( - EntityUserMedicament.user_id==user_id, - EntityUserMedicament.drug_id.in_(eval(drug_list)) - )).all() - for i in data_list: - self.session.delete(i) - self.session.commit() + self.delete(and_( + EntityUserMedicament.user_id == user_id, + EntityUserMedicament.drug_id == drug_id + )) + # data_list = self.findList(and_( + # EntityUserMedicament.user_id==user_id, + # EntityUserMedicament.drug_id.in_(eval(drug_list)) + # )).all() + # for i in data_list: + # self.session.delete(i) + # self.session.commit() return True except: return False