Commit c8062cfd by DESKTOP-E0VCCBD\zedan

update

parent 4b46d3b0
...@@ -10,7 +10,7 @@ async def check_low_stock_and_notify(): ...@@ -10,7 +10,7 @@ async def check_low_stock_and_notify():
async with AsyncSession() as db: # หรือ Depends(get_db) async with AsyncSession() as db: # หรือ Depends(get_db)
# 1) หาอุปกรณ์ใกล้หมดในทุกโปรเจ็กต์ # 1) หาอุปกรณ์ใกล้หมดในทุกโปรเจ็กต์
stmt = select(ProjectEquipment).where( stmt = select(ProjectEquipment).where(
ProjectEquipment.quantity_in_project <= ProjectEquipment.low_stock_threshold ProjectEquipment.quantity_in_project <= 5
) )
res = await db.execute(stmt) res = await db.execute(stmt)
lows = res.scalars().all() lows = res.scalars().all()
...@@ -33,12 +33,12 @@ async def check_low_stock_and_notify(): ...@@ -33,12 +33,12 @@ async def check_low_stock_and_notify():
notif = Notification( notif = Notification(
projectId=pe.projectId, projectId=pe.projectId,
equipmentId=pe.equipmentId, equipmentId=pe.equipmentId,
message=f"อุปกรณ์ {pe.equipmentId} ในโครงการ {pe.projectId} เหลือน้อยกว่า {pe.low_stock_threshold}" message=f"อุปกรณ์ {pe.equipmentId} ในโครงการ {pe.projectId} เหลือน้อยกว่า 5"
) )
db.add(notif) db.add(notif)
await db.commit() await db.commit()
def start_notification_scheduler(): def start_notification_scheduler():
scheduler = AsyncIOScheduler() scheduler = AsyncIOScheduler()
scheduler.add_job(check_low_stock_and_notify, "interval", hours=24) # ทุก 24 ชม. scheduler.add_job(check_low_stock_and_notify, "interval", minutes=1) # ทุก 24 ชม.
scheduler.start() scheduler.start()
...@@ -152,15 +152,14 @@ export class HomeInstallerComponent { ...@@ -152,15 +152,14 @@ export class HomeInstallerComponent {
type: 'datetime', type: 'datetime',
}, },
}; };
companyId: string = ''; projectId = ""
constructor(private el: ElementRef, private renderer: Renderer2, private cdr: ChangeDetectorRef, private userService: UserService, public translate: TranslateService, private tokenService: TokenService, private ProjectService: ProjectService, private EquipmentService: EquipmentService, private DashboardService: DashboardService, private route: ActivatedRoute,private comService: ProjectService) { constructor(private el: ElementRef, private renderer: Renderer2, private cdr: ChangeDetectorRef, private userService: UserService, public translate: TranslateService, private tokenService: TokenService, private projectService: ProjectService, private EquipmentService: EquipmentService, private DashboardService: DashboardService, private route: ActivatedRoute,private comService: ProjectService) {
this.companyId = this.route.snapshot.paramMap.get('companyId')!; this.projectId = this.route.snapshot.paramMap.get('projectId')!;
this.comService.getById(this.companyId).subscribe(result => { this.projectService.getById(this.projectId).subscribe(result => {
console.log("SAVEEE") console.log("SAVEEE")
this.tokenService.saveSelectCompany(result); this.tokenService.saveSelectCompany(result);
// this.router.navigate(["/company"]); // this.router.navigate(["/company"]);
}) })
this.chartOptions9 = { this.chartOptions9 = {
series: [ series: [
{ {
...@@ -920,7 +919,7 @@ export class HomeInstallerComponent { ...@@ -920,7 +919,7 @@ export class HomeInstallerComponent {
this.itemsList = result this.itemsList = result
this.updatePagedItems() this.updatePagedItems()
}) })
this.ProjectService.getLists().subscribe(result => { this.projectService.getLists().subscribe(result => {
this.projectList = result this.projectList = result
}) })
this.EquipmentService.getLists().subscribe(result => { this.EquipmentService.getLists().subscribe(result => {
......
...@@ -152,7 +152,7 @@ export class NavService implements OnDestroy { ...@@ -152,7 +152,7 @@ export class NavService implements OnDestroy {
{ headTitle: 'จัดการโครงการ' }, { headTitle: 'จัดการโครงการ' },
{ {
icon: 'home', icon: 'home',
path: '/company/home/:projectId', path: '/company/home/'+this.tokenService.getSelectCompany().projectId,
title: 'หน้าแรก', title: 'หน้าแรก',
type: 'link', type: 'link',
selected: false, selected: false,
...@@ -205,7 +205,7 @@ export class NavService implements OnDestroy { ...@@ -205,7 +205,7 @@ export class NavService implements OnDestroy {
// { headTitle: 'User Management' } // { headTitle: 'User Management' }
{ {
icon: 'home', icon: 'home',
path: '/company/home/:projectId', path: '/company/home/'+this.tokenService.getSelectCompany().projectId,
title: 'หน้าแรก', title: 'หน้าแรก',
type: 'link', type: 'link',
selected: false, selected: false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment