Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(key): 钥匙管理板块 #17

Merged
merged 10 commits into from
Jun 19, 2024
5 changes: 3 additions & 2 deletions backend/app/api/v1/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ async def set_db_conn(data: DbInfo, request: Request):
@router.post("/dutyLogs/search", summary="查询操作日志")
async def search_operation_logs(
data: dict,
depart: str = Query("glb", description="部门"),
area: str = Query("glb", description="区域"),
metaType: str = Query("tool", description="工具类型"),
page: int = Query(1, description="页码"),
pageSize: int = Query(10, description="每页数量"),
):
q = Q(depart__contains=depart)
q = Q(Q(area__contains=area), Q(type__contains=metaType))
status = data.get("status")
operatingTime: list = data.get("operatingTime")
if status:
Expand Down
64 changes: 39 additions & 25 deletions backend/app/api/v1/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ async def login_access_token(credentials: CredentialsSchema):
async def refresh_token(refreshToken: refreshTokenSchema):
try:
payload = decode_access_token(refreshToken.refreshToken)
if payload.exp.timestamp() < datetime.now().timestamp():
raise ExpiredSignatureError
except ExpiredSignatureError:
return FailAuth(msg="refreshToken已过期")
access_token_expires = timedelta(minutes=settings.JWT_ACCESS_TOKEN_EXPIRE_MINUTES)
Expand Down Expand Up @@ -130,31 +132,43 @@ async def get_user_menu():
parent_menu_dict["meta"]["showLink"] = parent_menu_dict["showLink"]
parent_menu_dict["meta"]["rank"] = parent_menu_dict["rank"]

for menu in menus:
if menu.parentId == parent_menu.id:
# roles = await menu.roles.all().values_list("code", flat=True)
children_menu = await menu.to_dict()
children_menu["meta"] = {}
children_menu["meta"]["title"] = children_menu["title"]
children_menu["meta"]["icon"] = children_menu["icon"]
children_menu["meta"]["extraIcon"] = children_menu["extraIcon"]
children_menu["meta"]["showLink"] = children_menu["showLink"]
children_menu["meta"]["showParent"] = children_menu["showParent"]
# children_menu["meta"]["roles"] = roles
children_menu["meta"]["auths"] = children_menu["auths"]
children_menu["meta"]["keepAlive"] = children_menu["keepAlive"]
children_menu["meta"]["frameSrc"] = children_menu["frameSrc"]
children_menu["meta"]["frameLoading"] = children_menu["frameLoading"]
children_menu["meta"]["frameLoading"] = children_menu["frameLoading"]
children_menu["meta"]["hiddenTag"] = children_menu["hiddenTag"]
children_menu["meta"]["dynamicLevel"] = children_menu["dynamicLevel"]
children_menu["meta"]["activePath"] = children_menu["activePath"]
children_menu["meta"]["transition"] = {}
children_menu["meta"]["transition"]["name"] = children_menu["transitionName"]
children_menu["meta"]["transition"]["enterTransition"] = children_menu["enterTransition"]
children_menu["meta"]["transition"]["leaveTransition"] = children_menu["leaveTransition"]

parent_menu_dict["children"].append(children_menu)
async def menuTree(parent_menu_dict: dict) -> dict:
for menu in menus:
if menu.parentId == parent_menu_dict["id"]:
# roles = await menu.roles.all().values_list("code", flat=True)
children_menu = await menu.to_dict()
children_menu["children"] = []
children_menu["meta"] = {}
children_menu["meta"]["title"] = children_menu["title"]
children_menu["meta"]["icon"] = children_menu["icon"]
children_menu["meta"]["extraIcon"] = children_menu["extraIcon"]
children_menu["meta"]["showLink"] = children_menu["showLink"]
children_menu["meta"]["showParent"] = children_menu["showParent"]
# children_menu["meta"]["roles"] = roles
children_menu["meta"]["auths"] = children_menu["auths"]
children_menu["meta"]["keepAlive"] = children_menu["keepAlive"]
children_menu["meta"]["frameSrc"] = children_menu["frameSrc"]
children_menu["meta"]["frameLoading"] = children_menu["frameLoading"]
children_menu["meta"]["frameLoading"] = children_menu["frameLoading"]
children_menu["meta"]["hiddenTag"] = children_menu["hiddenTag"]
children_menu["meta"]["dynamicLevel"] = children_menu["dynamicLevel"]
children_menu["meta"]["activePath"] = children_menu["activePath"]
children_menu["meta"]["transition"] = {}
children_menu["meta"]["transition"]["name"] = children_menu["transitionName"]
children_menu["meta"]["transition"]["enterTransition"] = children_menu["enterTransition"]
children_menu["meta"]["transition"]["leaveTransition"] = children_menu["leaveTransition"]

parent_menu_dict["children"].append(children_menu)

parent_menu_dict["children"].sort(key=lambda x: x["rank"])
if len(parent_menu_dict["children"]) == 0:
del parent_menu_dict["children"]
return parent_menu_dict
for i, v in enumerate(parent_menu_dict["children"]):
parent_menu_dict["children"][i] = await menuTree(v)
return parent_menu_dict

parent_menu_dict = await menuTree(parent_menu_dict)
res.append(parent_menu_dict)
return Success(data=res)

Expand Down
7 changes: 4 additions & 3 deletions backend/app/api/v1/home/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ async def get_home_list(
returnStatus: Union[bool, None] = Query(None, description="归还批准状态")
):
if returnStatus is None:
q = Q(Q(material__depart=area), Q(borrowApproveStatus=borrowedStatus))
q = Q(Q(material__area=area), Q(borrowApproveStatus=borrowedStatus))
else:
q = Q(Q(material__depart=area), Q(borrowApproveWhether=borrowWhether), Q(returnApproveStatus=returnStatus))
q = Q(Q(material__area=area), Q(borrowApproveWhether=borrowWhether), Q(returnApproveStatus=returnStatus))
total, objs = await borrowedController.list(page=page, page_size=pageSize, search=q)
data = [await obj.to_dict(m2m=True) for obj in objs]
data = [await obj.to_dict(m2m=True, exclude_fields=["password"]) for obj in objs]
return SuccessExtra(data=data, total=total, currentPage=page, pageSize=pageSize)


Expand All @@ -45,6 +45,7 @@ async def create_borrowed(data: CreateBorrowedInfo):
item["phone"] = data.phone
item["userDepart"] = data.depart
item["uuid"] = data.uuid
item["reason"] = data.reason
obj: Borrowed = await borrowedController.create(obj_in=item)
material.borrowed += obj.borrowing
await material.save()
Expand Down
59 changes: 35 additions & 24 deletions backend/app/api/v1/material/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@


@router.post("/dutyOver", summary="接班")
async def duty_over(data: DutyOverInfo):
async def duty_over(
data: DutyOverInfo,
area: str = Query("glb", description="区域"),
metaType: str = Query("", description="物资类型")
):
note = await dutyNotesController.create(data.materialNote)
await dutyLogController.create_all(data.materialData, note)
onDutyInfo = OnDutyInfo()
await onDutyInfo.setGlbDutyInfo(data.dutyPerson, data.dutyPersonDepart, data.dutyDate)
onDutyInfo.setDutyInfo(area, metaType, data.dutyPerson, data.dutyPersonDepart)

result = {
"dutyPerson": data.dutyPerson,
Expand All @@ -34,26 +38,27 @@ async def duty_over(data: DutyOverInfo):

@router.get("/meta", summary="获取物资源数据")
async def get_meta(
depart: str = Query("glb", description="物资部门"),
area: str = Query("glb", description="物资区域"),
metaType: str = Query("", description="物资类型"),
page: int = Query(1, description="页码"),
page_size: int = Query(1000, description="每页数量"),
pageSize: int = Query(1000, description="每页数量"),
name: str = Query("", description="物资名称"),
):
q = Q(depart__contains=depart)
q = Q(Q(area__contains=area), Q(type__contains=metaType))
if name:
q &= Q(name__contains=name)

total, material_objs = await materialController.list(page=page, page_size=page_size, search=q)
total, material_objs = await materialController.list(page=page, page_size=pageSize, search=q)
data = [await obj.to_dict() for obj in material_objs]
return SuccessExtra(msg="物资数据获取成功", data=data, total=total, page=page, page_size=page_size)
return SuccessExtra(msg="物资数据获取成功", data=data, total=total, page=page, pageSize=pageSize)


@router.get("/all_meta", summary="获取所有物资源数据")
async def get_all_meta(depart: str = Query("glb", description="物资部门")):
q = Q()
if depart:
q &= Q(depart__contains=depart)

async def get_all_meta(
area: str = Query("glb", description="物资区域"),
metaType: str = Query("tool", description="物资类型")
):
q = Q(Q(area__contains=area), Q(type__contains=metaType))
material_objs = await materialController.all(search=q)
data = [await obj.to_dict() for obj in material_objs]
return Success(data=data)
Expand All @@ -62,7 +67,7 @@ async def get_all_meta(depart: str = Query("glb", description="物资部门")):
@router.post("/add_meta", summary="添加或修改物资源数据")
async def add_meta(data: Union[MaterialCreate, MaterialUpdate]):
if hasattr(data, "id"):
result: Material = await materialController.update(data.id, data.update_dict())
result: Material = await materialController.update(data.id, data)
else:
data: dict = data.model_dump()
data["uuid"] = generate_uuid(data["name"])
Expand All @@ -85,24 +90,30 @@ async def delete_meta(data: dict[str, list[int]]):
return Success(msg="删除成功")


@router.get("/glb_duty_info", summary="获取隔离办值班信息")
async def get_glb_duty_info():
@router.get("/duty_info", summary="获取隔离办值班信息")
async def get_duty_info(
area: str = Query("glb", description="物资区域"),
metaType: str = Query("", description="物资类型"),
):
info = OnDutyInfo()
data = await info.getGlbDutyInfo()
data = info.getDutyInfo(area, metaType)
return Success(data=data)


@router.get("/glb_attention", summary="获取隔离办物资注意事项")
async def get_glb_attention():
q = Q(depart__contains="glb")
q = Q(area__contains="glb")
total, note_objs = await materialAttentionController.list(page=1, page_size=100, search=q)
data = [await obj.to_dict() for obj in note_objs]
return Success(msg="隔离办注意事项", data=data)


@router.get("/glb_latest_note", summary="获取隔离办最近一条备注")
async def get_glb_latest_note():
q = Q(depart__contains="glb")
@router.get("/latest_note", summary="获取最近一条备注")
async def get_latest_note(
area: str = Query("glb", description="物资区域"),
metaType: str = Query("tool", description="物资类型")
):
q = Q(Q(area__contains=area), Q(type__contains=metaType))
data = await dutyNotesController.latest(search=q)
if data:
data = await data.to_dict()
Expand All @@ -117,7 +128,7 @@ async def get_fk_list(
page_size: int = Query(1000, description="每页数量"),
name: str = Query("", description="物资名称")
):
q = Q(depart__contains="fk")
q = Q(area__contains="fk")
if name:
q &= Q(name__contains=name)

Expand All @@ -132,7 +143,7 @@ async def get_fk_list(
page_size: int = Query(1000, description="每页数量"),
name: str = Query("", description="物资名称")
):
q = Q(depart__contains="wk")
q = Q(area__contains="wk")
if name:
q &= Q(name__contains=name)

Expand All @@ -143,7 +154,7 @@ async def get_fk_list(

@router.get("/duty_over_list/list", summary="获取接班清单")
async def get_duty_over_list(area: str = Query("glb", description="部门")):
q = Q(depart__contains=area)
q = Q(area__contains=area)
total, duty_over_list_objs = await dutyOverListController.list(page=1, page_size=1000, search=q)
data = [await obj.to_dict() for obj in duty_over_list_objs]
return SuccessExtra(msg="接班清单获取成功", data=data, total=total, page=1, pageSize=1000)
Expand All @@ -155,7 +166,7 @@ async def update_duty_over_list(data: list[dict], area: str = Query("glb", descr
if item.get("id"):
await dutyOverListController.update(item["id"], item)
else:
item["depart"] = area
item["area"] = area
await dutyOverListController.create(item)
return Success(msg="更新成功")

Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/v1/menus/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

@router.get("/tree", summary="查看菜单树")
async def menu_tree():
parent_menus = await menu_controller.model.filter(parent_id=0).order_by("order")
parent_menus = await menu_controller.model.filter(parent_id=0).order_by("rank")
res_menu = []
for menu in parent_menus:
child_menu = await menu_controller.model.filter(parent_id=menu.id).order_by("order")
child_menu = await menu_controller.model.filter(parent_id=menu.id).order_by("rank")
menu_dict = await menu.to_dict()
menu_dict["children"] = [await obj.to_dict() for obj in child_menu]
res_menu.append(menu_dict)
Expand Down
16 changes: 16 additions & 0 deletions backend/app/controllers/area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding=utf-8
# @FileName :area.py
# @Time :2024/6/9 上午9:53
# @Author :dayezi
from app.core.crud import CRUDBase

from app.models import MaterialArea
from app.schemas.area import MaterialAreaCreate, MaterialAreaUpdate


class MaterialAreaController(CRUDBase[MaterialArea, MaterialAreaCreate, MaterialAreaUpdate]):
def __init__(self):
super().__init__(model=MaterialArea)


areaController = MaterialAreaController()
16 changes: 16 additions & 0 deletions backend/app/controllers/materialType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding=utf-8
# @FileName :materialType.py
# @Time :2024/6/7 下午3:30
# @Author :dayezi
from app.core.crud import CRUDBase

from app.models import MaterialType
from app.schemas.materialType import MaterialTypeCreate, MaterialTypeUpdate


class MaterialTypeController(CRUDBase[MaterialType, MaterialTypeCreate, MaterialTypeUpdate]):
def __init__(self):
super().__init__(model=MaterialType)


materialTypeController = MaterialTypeController()
2 changes: 2 additions & 0 deletions backend/app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
from .material import *
from .dutyLog import *
from .borrowed import *
from .materialType import *
from .area import *
18 changes: 18 additions & 0 deletions backend/app/models/area.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding=utf-8
# @FileName :area.py
# @Time :2024/6/7 下午3:25
# @Author :dayezi
from tortoise import fields

from .base import BaseModel, TimestampMixin, UUIDModel


class MaterialArea(BaseModel, TimestampMixin, UUIDModel):
key = fields.CharField(max_length=20, description="物资区域关键字")
name = fields.CharField(max_length=50, description="物资区域名称")

class Meta:
table = "material_area"

class PydanticMeta:
exclude = "id"
1 change: 1 addition & 0 deletions backend/app/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def to_dict(self, m2m: bool = False, exclude_fields: list[str] | None = No
if isinstance(v, datetime)
)
value.update((k, str(v)) for k, v in value.items() if isinstance(v, UUID))
value.pop("password", "xxx") # 删除用户模型中的密码字段
d[field] = values
return d

Expand Down
1 change: 1 addition & 0 deletions backend/app/models/borrowed.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Borrowed(BaseModel, UUIDModel):
uuid = fields.UUIDField(pk=False, description="借用人uuid")
phone = fields.CharField(max_length=20, description="借用人手机号")
userDepart = fields.CharField(max_length=20, description="借用人部门")
reason = fields.CharField(max_length=200, description="借用原因")
borrowTime = fields.DatetimeField(auto_now_add=True, description="借用时间")
borrowApproveStatus = fields.BooleanField(default=False, description="借用审批状态,False为未审批,True未已审批")
borrowApproveWhether = fields.BooleanField(null=True, description="借用通过状态,False为驳回,True为通过")
Expand Down
14 changes: 8 additions & 6 deletions backend/app/models/dutyLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ class DutyLog(BaseModel):
"""
值班日志
"""
position = fields.CharField(max_length=20, null=False, description="位置")
type = fields.CharField(max_length=20, description="物资类型")
area = fields.CharField(max_length=20, null=False, description="物资所在区域")
name = fields.CharField(max_length=50, null=False, description="名称")
position = fields.CharField(max_length=20, null=False, description="位置")
model = fields.CharField(max_length=20, null=False, description="型号")
number = fields.IntField(max_length=20, null=False, description="数量")
nowNumber = fields.IntField(max_length=20,null=False, description="当前数量")
nowNumber = fields.IntField(max_length=20, null=False, description="当前数量")
dutyPerson = fields.CharField(max_length=20, null=False, description="当班人员")
dutyPersonDepart = fields.CharField(max_length=20, null=False, description="当班人员部门")
depart = fields.CharField(max_length=20, null=False, description="部门")
dutyDate = fields.DatetimeField(auto_now_add=True, description="交班时间")
dutyNote: fields.ForeignKeyRelation["DutyNotes"] = fields.ForeignKeyField("models.DutyNotes",
related_name="duty_log", null=True)
Expand All @@ -28,20 +29,21 @@ class Meta:
table = "dutyLogs"

class PydanticMeta:
exclude = ("id",)
exclude = ("id", "dutyDate")


class DutyNotes(BaseModel):
"""值班日志备注"""
note = fields.CharField(max_length=510, null=False, description="备注")
depart = fields.CharField(max_length=255, null=False, description="部门")
type = fields.CharField(max_length=20, null=False, description="类型")
area = fields.CharField(max_length=20, null=False, description="区域")
dutyDate = fields.DatetimeField(auto_now_add=True, description="交班时间")
dutyLog: fields.ReverseRelation["DutyLog"]

class Meta:
table = "dutyNotes"

class PydanticMeta:
exclude = ("id",)
exclude = ("id", "dutyDate")


Loading
Loading