baoyubo 1 月之前
父节点
当前提交
31d5eb37de
共有 2 个文件被更改,包括 76 次插入9 次删除
  1. 65 0
      routers/api/dutyManagement/contact.py
  2. 11 9
      routers/api/dutyManagement/schedule.py

+ 65 - 0
routers/api/dutyManagement/contact.py

@@ -284,6 +284,71 @@ async def get_dict_data_by_type(
             'msg': str(e)
         })
 
+@router.get('/user/biglist')
+async def get_dict_data_by_type(
+    dept_parent_id:int =Query(None),
+    keywords:str =Query(None),
+    db: Session = Depends(get_db),
+    body = Depends(remove_xss_json),
+    user_id = Depends(valid_access_token)
+):
+    try:
+        # 根据 dict_type 查询字典数据
+        # dict_data = db.query(SysDictData).filter_by(dict_type=dictType).all()
+        query = db.query(EmergencyContactUser)
+
+        query = query.filter(EmergencyContactUser.del_flag != '2')
+        # 添加查询条件
+        if dept_parent_id:
+            query = query.filter(EmergencyContactUser.department_id==dept_parent_id)
+        if keywords:
+            query = query.filter(or_(EmergencyContactUser.name.like(f'%{keywords}%'),EmergencyContactUser.mobile_phone.like(f'%{keywords}%'),EmergencyContactUser.office_phone.like(f'%{keywords}%')))
+
+        query = query.order_by(EmergencyContactUser.display_order, EmergencyContactUser.update_time.desc())
+
+        # 计算总记录数
+        total_count = query.count()
+
+        # 计算分页
+        user_data = query.all()
+
+        # 转换为字典
+        data_list = []
+        for d in user_data:
+            department = id_get_contact_dept_info(db,d.department_id)
+            if department is None:
+                department=''
+                continue
+            data_list.append({
+                "id": d.id,
+                "name": d.name,
+                "position":d.position,
+                "mobile_phone": d.mobile_phone,
+                "office_phone":d.office_phone,
+                "department_id":d.department_id,
+                "department":department,
+                "display_order":d.display_order,
+                "yzy_unitid":d.yzy_unitid,
+                "userid": d.userid,
+                "createTime": d.create_time.strftime('%Y-%m-%d %H:%M:%S') if d.create_time else ''
+            })
+        # 构建返回结果
+        result = {
+            "total": total_count,
+            "data": data_list,
+            "code": 200,
+            "msg": "查询成功"
+        }
+        return result
+
+    except Exception as e:
+        # 处理异常
+        traceback.print_exc()
+        return JSONResponse(status_code=404, content={
+            'code': 404,
+            'msg': str(e)
+        })
+
 
 @router.get('/user/info/{id}')
 async def get_dict_data_by_type(

+ 11 - 9
routers/api/dutyManagement/schedule.py

@@ -31,7 +31,7 @@ def name_get_user_id(db,keywords):
 def user_id_get_duty_id(db,user_id_list):
     query = db.query(DutyPersonnelArrangement)
     query = query.filter(DutyPersonnelArrangement.del_flag != '2')
-    query = query.filter(DutyPersonnelArrangement.personnel_id._in(user_id_list))
+    query = query.filter(DutyPersonnelArrangement.personnel_id.in_(user_id_list))
     data = query.all()
     return [info.duty_id for info in data]
 
@@ -52,9 +52,9 @@ def user_id_get_info(db,user_id):
 def get_duty_unit_id_list(db):
     query = db.query(SysDictData)
     query = query.filter(SysDictData.del_flag != '2')
-    query = query.filter(SysDictData.dict_value=='duty_unit')
+    query = query.filter(SysDictData.dict_type=='duty_unit')
     data = query.all()
-    return [int(i) for i in data]
+    return [int(i.dict_value) for i in data]
 
 def dept_id_get_duty_unit_id(db,dept_id,duty_unit_id_list):
     if dept_id == 0:
@@ -106,7 +106,7 @@ async def get_dict_data_by_type(
         if keywords:
             user_list= name_get_user_id(db,keywords)
             duty_list = user_id_get_duty_id(db,user_list)
-            query = query.filter(DutySchedule.id._in(duty_list))
+            query = query.filter(DutySchedule.id.in_(duty_list))
 
         if duty_type:
             query = query.filter(DutySchedule.duty_type==duty_type)
@@ -197,7 +197,7 @@ async def get_dict_data_by_type(
         if keywords:
             user_list= name_get_user_id(db,keywords)
             duty_list = user_id_get_duty_id(db,user_list)
-            query = query.filter(DutySchedule.id._in(duty_list))
+            query = query.filter(DutySchedule.id.in_(duty_list))
         if start_time:
             start_time = datetime.strptime(start_time, "%Y-%m-%d").date()
             query = query.filter(DutySchedule.duty_date>=start_time)
@@ -208,8 +208,9 @@ async def get_dict_data_by_type(
             query = query.filter(DutySchedule.duty_unit==duty_unit)
         else:
             now_user_info=user_id_get_user_info(db,user_id)
+            print(user_id,now_user_info.phonenumber,get_duty_unit_id_list(db))
             if now_user_info:
-                query = query.filter(DutySchedule.duty_unit==mobile_phone_get_dept_id(db,now_user_info.phonenumber,get_duty_unit_id_list(db)))
+                query = query.filter(DutySchedule.duty_unit==mobile_phone_get_dept_id(db,mpfun.dec_data(now_user_info.phonenumber),get_duty_unit_id_list(db)))
             else:
                 return {
                     "total": 0,
@@ -224,7 +225,7 @@ async def get_dict_data_by_type(
             DutySchedule.duty_date,
             DutySchedule.shift_type,
             func.max(DutySchedule.update_time).label("latest_create_time")
-        ).group_by(
+        ).filter(DutySchedule.del_flag != '2').group_by(
             DutySchedule.duty_date,
             DutySchedule.shift_type
         ).subquery()
@@ -243,6 +244,7 @@ async def get_dict_data_by_type(
         # 计算分页
         offset = (page - 1) * pageSize
         query = query.order_by(DutySchedule.update_time.desc())
+        print(query)
         duty_data = query.offset(offset).limit(pageSize).all()
 
         # 转换为字典
@@ -323,7 +325,7 @@ async def get_dict_data_by_type(
                               "mobile_phone": contact_info.mobile_phone,
                               "office_phone": contact_info.office_phone,
                               "department_id": contact_info.department_id,
-                              "yzy_userid": contact_info.yzy_userid})
+                              "yzy_userid": contact_info.userid})
         data_list={
             "id": d.id,
             "start_time": d.start_time,
@@ -527,7 +529,7 @@ async def delete_dict_data(
         # 从数据库中获取要删除的 OneShareApiEntity 实例
         id_list = [int(i) for i in id_list.split(',')]
         query = db.query(DutySchedule)
-        query = query.filter(DutySchedule.id._in(id_list))
+        query = query.filter(DutySchedule.id.in_(id_list))
         query = query.filter(DutySchedule.del_flag != '2')
         position_data = query.all()
         # dict_data = db.query(SysDictData).filter(SysDictData.dict_code == dictCode and SysDictData.del_flag != '2').first()