Skip to content

Commit

Permalink
Merge pull request #11 from pylover7/feature/adminUI
Browse files Browse the repository at this point in the history
feat(adminUI): update adminUI
  • Loading branch information
pylover7 authored Apr 15, 2024
2 parents 0e991d9 + b80177c commit 07f3843
Show file tree
Hide file tree
Showing 36 changed files with 855 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple\

COPY --from=frontend /app/frontend/dist /app/frontend
ADD mm.conf /etc/nginx/sites-available/mm.conf
RUN rm -f /etc/nginx/sites-enabled/default \
RUN rm -f /etc/nginx/sites-enabled/default \
&& ln -s /etc/nginx/sites-available/mm.conf /etc/nginx/sites-enabled/

ENV LANG=zh_CN.UTF-8
Expand Down
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<h1 align="center"> MaterialManager </h1>
<div align="center">

![GitHub commit activity](https://img.shields.io/github/commit-activity/m/pylover7/MaterialManager)
![GitHub License](https://img.shields.io/github/license/pylover7/MaterialManager)
[![wakatime](https://wakatime.com/badge/user/1d39df6a-cef0-41f7-a903-ef4b9dd13fb0/project/018c41f2-4f38-4875-b72b-1a79d2352c7d.svg)](https://wakatime.com/badge/user/1d39df6a-cef0-41f7-a903-ef4b9dd13fb0/project/018c41f2-4f38-4875-b72b-1a79d2352c7d)

</div>
Expand All @@ -14,13 +16,27 @@
构建镜像

```bash
docker build -t material-manager:0.0.1 .
docker build -t material-manager:0.0.2 .
```

启动容器

```bash
docker run -d --restart=always --name=material-manager -p 8080:80 material-manager
docker run -d --restart=always --name=material-manager -p 8080:80 material-manager:0.0.2
```

访问 http://localhost:8080/ 即可

## Status

![Alt](https://repobeats.axiom.co/api/embed/f700028c26f06ec181e8a12028e1f01d5e1b782d.svg "Repobeats analytics image")

## Star History

<a href="https://star-history.com/#pylover7/MaterialManager&Date">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=pylover7/MaterialManager&type=Date&theme=dark" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=pylover7/MaterialManager&type=Date" />
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=pylover7/MaterialManager&type=Date" />
</picture>
</a>
1 change: 1 addition & 0 deletions backend/app/api/v1/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async def login_access_token(credentials: CredentialsSchema):

data = JWTOut(
username=user.username,
depart=user.depart,
roles=["admin"],
accessToken=create_access_token(
data=JWTPayload(
Expand Down
46 changes: 40 additions & 6 deletions backend/app/api/v1/material/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

from app.controllers.material import materialController, materialAttentionController
from app.controllers.dutyLog import dutyLogController, dutyNotesController
from app.schemas.base import Success, SuccessExtra
from app.models import Material
from app.schemas.base import Success, SuccessExtra, Fail
from app.schemas.dutyLog import DutyOverInfo
from app.utils.onDutyInfo import OnDutyInfo
from app.schemas.material import MaterialCreate, MaterialUpdate
from app.utils.password import generate_uuid

logger = logging.getLogger(__name__)

Expand All @@ -28,19 +31,46 @@ async def duty_over(data: DutyOverInfo):
return Success(data=result)


@router.get("/glb_list", summary="获取隔离办物资列表")
async def get_glb_list(
@router.get("/meta", summary="获取物资源数据")
async def get_meta(
depart: str = Query("glb", description="物资部门"),
page: int = Query(1, description="页码"),
page_size: int = Query(1000, description="每页数量"),
name: str = Query("", description="物资名称"),
):
q = Q(depart__contains="glb")
q = Q(depart__contains=depart)
if name:
q &= Q(name__contains=name)

total, material_objs = await materialController.list(page=page, page_size=page_size, 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, page_size=page_size)


@router.post("/add_meta", summary="添加或修改物资源数据")
async def add_meta(data: MaterialCreate | MaterialUpdate):
if hasattr(data, "id"):
result: Material = await materialController.update(data.id, data.update_dict())
else:
data: MaterialCreate = data.create_dict()
data["uuid"] = generate_uuid(data["name"])
result: Material = await materialController.create(data)
result = await result.to_dict()
if result:
return Success(data=result)
else:
return Fail(msg="数据写入失败!")


@router.delete("/delete", summary="删除物资源数据")
async def delete_meta(data: dict[str, list[int]]):
for id in data["idList"]:
try:
await materialController.remove(id)
except Exception as e:
logger.error(f"删除物资项失败,ID为{id}")
return Fail(msg=f"删除物资项部分失败: {e}")
return Success(msg="删除成功")


@router.get("/glb_duty_info", summary="获取隔离办值班信息")
Expand All @@ -62,7 +92,11 @@ async def get_glb_attention():
async def get_glb_latest_note():
q = Q(depart__contains="glb")
data = await dutyNotesController.latest(search=q)
return Success(data=await data.to_dict())
if data:
data = await data.to_dict()
else:
data = ""
return Success(data=data)


@router.get("/fk_material", summary="查看辅控物资列表")
Expand Down
1 change: 1 addition & 0 deletions backend/app/core/init_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ async def init_superuser():
await user_controller.create(
UserCreate(
username="admin",
depart="管理部",
email="[email protected]",
password="admin123456",
is_active=True,
Expand Down
1 change: 1 addition & 0 deletions backend/app/models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class User(BaseModel, TimestampMixin):
email = fields.CharField(max_length=255, unique=True, description="邮箱")
phone = fields.CharField(max_length=20, null=True, description="电话")
password = fields.CharField(max_length=128, null=True, description="密码")
depart = fields.CharField(max_length=20, null=True, description="部门")
is_active = fields.BooleanField(default=True, description="是否激活")
is_superuser = fields.BooleanField(default=False, description="是否为超级管理员")
last_login = fields.DatetimeField(null=True, description="最后登录时间")
Expand Down
16 changes: 8 additions & 8 deletions backend/app/models/dutyLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ class DutyLog(BaseModel):
"""
值班日志
"""
position = fields.CharField(max_length=255, null=False, description="位置")
name = fields.CharField(max_length=255, null=False, description="名称")
model = fields.CharField(max_length=255, null=False, description="型号")
number = fields.CharField(max_length=255, null=False, description="数量")
position = fields.CharField(max_length=20, null=False, description="位置")
name = fields.CharField(max_length=50, null=False, description="名称")
model = fields.CharField(max_length=20, null=False, description="型号")
number = fields.CharField(max_length=20, null=False, description="数量")
nowNumber = fields.IntField(null=False, description="当前数量")
dutyPerson = fields.CharField(max_length=255, null=False, description="当班人员")
dutyPersonDepart = fields.CharField(max_length=255, null=False, description="当班人员部门")
depart = fields.CharField(max_length=255, 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="交班时间")

class Meta:
table = "duty_log"


class DutyNotes(BaseModel):
note = fields.CharField(max_length=255, null=False, description="备注")
note = fields.CharField(max_length=510, null=False, description="备注")
depart = fields.CharField(max_length=255, null=False, description="部门")
dutyDate = fields.DatetimeField(auto_now_add=True, description="交班时间")
14 changes: 7 additions & 7 deletions backend/app/models/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@


class Material(BaseModel, TimestampMixin, UUIDModel):
name = fields.CharField(max_length=100, unique=True, description="物资名字")
model = fields.CharField(max_length=100, null=True, description="物资型号")
position = fields.CharField(max_length=100, description="物资位置")
number = fields.CharField(max_length=100, description="物资数量")
depart = fields.CharField(max_length=100, description="物资所属部门")
name = fields.CharField(max_length=50, description="物资名字")
model = fields.CharField(max_length=20, null=True, description="物资型号")
position = fields.CharField(max_length=50, description="物资位置")
number = fields.IntField(description="物资数量")
depart = fields.CharField(max_length=20, description="物资所属部门")

class Meta:
table = "material"


class AttentionNote(BaseModel, TimestampMixin, UUIDModel):
note = fields.CharField(max_length=100, description="事项")
depart = fields.CharField(max_length=100, description="所属部门")
note = fields.CharField(max_length=255, description="事项")
depart = fields.CharField(max_length=20, description="所属部门")

class Meta:
table = "attention_note"
4 changes: 4 additions & 0 deletions backend/app/schemas/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ class CredentialsSchema(BaseModel):
username: str = Field(..., description="用户名称", example="admin")
password: str = Field(..., description="密码", example="admin123456")


class refreshTokenSchema(BaseModel):
refreshToken: str = Field(..., description="刷新令牌", example="eyJhbGciOiJIUzUxMiJ9.newAdminRefresh")


class JWTReOut(BaseModel):
accessToken: str
refreshToken: str
expires: str


class JWTOut(BaseModel):
username: str
depart: str
roles: list[str]
accessToken: str
refreshToken: str
Expand Down
10 changes: 6 additions & 4 deletions backend/app/schemas/material.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
from typing import Optional

from pydantic import BaseModel, Field
from uuid import UUID


class Material(BaseModel):
id: int
name: Optional[str] = None
model: Optional[str] = None
position: Optional[str] = None
number: Optional[str] = None
number: Optional[int] = None
depart: Optional[str] = None


class MaterialCreate(BaseModel):
name: str = Field(description="物资名字")
model: str = Field(description="物资型号")
position: str = Field(description="物资位置")
number: str = Field(description="物资数量")
number: int = Field(description="物资数量")
depart: str = Field(description="物资所属部门")
uuid: UUID = None

def create_dict(self):
# 创建字典
Expand All @@ -29,11 +31,11 @@ class MaterialUpdate(BaseModel):
name: str = Field(description="物资名字")
model: str = Field(description="物资型号")
position: str = Field(description="物资位置")
number: str = Field(description="物资数量")
number: int = Field(description="物资数量")

def update_dict(self):
# 更新字典
return self.model_dump(exclude_unset=True, exclude={"id"})
return self.model_dump(exclude_unset=True, exclude={"id", "uuid"})


class AttentionNote(BaseModel):
Expand Down
2 changes: 2 additions & 0 deletions backend/app/schemas/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BaseUser(BaseModel):
id: int
email: Optional[EmailStr] = None
username: Optional[str] = None
depart: Optional[str] = None
is_active: Optional[bool] = True
is_superuser: Optional[bool] = False
created_at: Optional[datetime]
Expand All @@ -19,6 +20,7 @@ class BaseUser(BaseModel):
class UserCreate(BaseModel):
email: EmailStr = Field(example="[email protected]")
username: str = Field(example="admin")
depart: str = Field(example="管理部")
password: str = Field(example="123456")
is_active: Optional[bool] = True
is_superuser: Optional[bool] = False
Expand Down
4 changes: 2 additions & 2 deletions backend/app/utils/dutyInfo.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[glb]
dutyperson = admin
dutypersondepart =
takeovertime = 2024-4-13 15:43:56
dutypersondepart = 管理部
takeovertime = 2024-04-13 20:24:12

[wk]
dutyperson = admin
Expand Down
7 changes: 7 additions & 0 deletions backend/app/utils/password.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from passlib import pwd
from passlib.context import CryptContext
import uuid
import time

pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")

Expand All @@ -14,3 +16,8 @@ def get_password_hash(password: str) -> str:

def generate_password() -> str:
return pwd.genword()


def generate_uuid(name: str) -> uuid.UUID:
name = name + str(time.time_ns())
return uuid.uuid5(uuid.NAMESPACE_DNS, name)
2 changes: 1 addition & 1 deletion frontend/public/platform-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Version": "0.0.1",
"Version": "0.0.2",
"Title": "MaterialManager",
"FixedHeader": true,
"HiddenSideBar": false,
Expand Down
Loading

0 comments on commit 07f3843

Please sign in to comment.