调整access表

This commit is contained in:
曹前明 2022-06-25 16:32:29 +08:00
parent 9f83de4813
commit a2e96c4c53
5 changed files with 70 additions and 7 deletions

View File

@ -0,0 +1,42 @@
# Generated by Django 3.2.12 on 2022-06-25 08:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('am', '0004_auto_20220625_1058'),
]
operations = [
migrations.RemoveField(
model_name='access',
name='post',
),
migrations.RemoveField(
model_name='area',
name='posts_access',
),
migrations.AddField(
model_name='access',
name='obj',
field=models.CharField(blank=True, max_length=50, null=True, unique=True, verbose_name='关联对象'),
),
migrations.AddField(
model_name='access',
name='obj_cate',
field=models.CharField(default='employee', help_text='employee/post', max_length=20, verbose_name='对象类型'),
preserve_default=False,
),
migrations.AddField(
model_name='area',
name='is_hidden',
field=models.BooleanField(default=False, verbose_name='隐藏围栏用'),
),
migrations.AlterField(
model_name='area',
name='type',
field=models.PositiveSmallIntegerField(choices=[(10, '固定'), (20, '临时作业')], default=10, verbose_name='区域类型'),
),
]

View File

@ -1,5 +1,7 @@
from django.db import models
from apps.hrm.models import Employee
from apps.system.models import Post, User
from apps.utils.constants import ObjCate
from apps.utils.models import CommonADModel, CommonBModel
# Create your models here.
@ -22,7 +24,7 @@ class Area(CommonBModel):
AREA_TYPE_TEMP = 20
AREA_TYPE_CHOICES = (
(10, '固定'),
(20, '临时')
(20, '临时作业')
)
name = models.CharField('名称', max_length=20)
type = models.PositiveSmallIntegerField('区域类型', default=10, choices=AREA_TYPE_CHOICES)
@ -32,10 +34,10 @@ class Area(CommonBModel):
visitor_yes = models.BooleanField('准许访客人员', default=False)
remployee_yes = models.BooleanField('准许相关方人员', default=False)
employee_yes = models.BooleanField('准许全部员工', default=True)
posts_access = models.ManyToManyField(Post, through='am.access')
count_people_min = models.PositiveIntegerField('最小人员数', default=0)
count_people_max = models.PositiveIntegerField('最大人员数', default=1000)
count_people = models.PositiveIntegerField('当前人数', default=0)
is_hidden = models.BooleanField('隐藏围栏用', default=False)
third_info = models.JSONField('三方信息', default=dict,
null=False, blank=True)
@ -45,7 +47,7 @@ class Area(CommonBModel):
class Access(CommonADModel):
"""
岗位准入权限
入禁入权限(动态变化)
"""
ACCESS_IN_YES = 10
ACCESS_IN_NO = 20
@ -53,8 +55,9 @@ class Access(CommonADModel):
(ACCESS_IN_YES, '准入'),
(ACCESS_IN_NO, '禁入')
)
type = models.PositiveSmallIntegerField('准入类型', choices=ACCESS_CHOICE)
area = models.ForeignKey(Area, verbose_name='关联区域',
on_delete=models.CASCADE)
post = models.ForeignKey(Post, verbose_name='关联岗位',
on_delete=models.CASCADE)
obj_cate = models.CharField('对象类型', max_length=20, help_text='employee/post')
obj = models.CharField('关联对象', unique=True, max_length=50, null=True, blank=True)

View File

@ -1,6 +1,8 @@
from apps.am.models import Area
from apps.hrm.models import Employee
from apps.system.models import User
from apps.third.clients import xxClient
from apps.third.tapis import xxapis
@ -59,7 +61,8 @@ class EcmService:
"""
# 判断区域是否超员
area = Area.objects.filter(third_info__xx_rail__id=data['railId']).first()
if area:
ep = Employee.objects.filter(third_info__xx_userId=data['userId']).first()
if area and area.type == Area.AREA_TYPE_FIX: # 如果是固定区域
json = {"railId": data['railId'], "type": ""}
_, res = xxClient.request(**xxapis['rail_ibeacon_list'], json=json)
total_count = res['totalCount']
@ -73,3 +76,10 @@ class EcmService:
area.count_people_min = total_count
area.save()
pass
# 判断有无进入权限
if ep.type == 'employee' and area.employee_yes:
return
elif ep.type == 'remployee' and area.remployee_yes:
return
elif ep.type == 'visitor' and area.visitor_yes:
return

View File

@ -1,6 +1,7 @@
from django.db import models
from apps.am.models import Area
import uuid
from apps.utils.constants import ObjCate
from apps.utils.models import BaseModel
# Create your models here.
@ -37,6 +38,8 @@ class TDevice(BaseModel):
verbose_name='所在区', null=True, blank=True)
areas = models.ManyToManyField(Area, verbose_name='覆盖区',
related_name='tareas')
obj_cate = models.CharField('对象类型', max_length=20, help_text='employee/...')
obj = models.CharField('绑定对象', unique=True, max_length=50, null=True, blank=True)
is_clock = models.BooleanField('是否打卡设备', default=False)
third_info = models.JSONField('三方信息', default=dict,
null=False, blank=True)

View File

@ -1,4 +1,9 @@
from django.db import models
EXCLUDE_FIELDS_BASE = ['create_time', 'update_time', 'is_deleted']
EXCLUDE_FIELDS = ['create_time', 'update_time', 'is_deleted', 'create_by', 'update_by']
class ObjCate(models.IntegerChoices):
EMPLOYEE = 10, '个人'
POST = 20, '岗位'