|
|
import logging
|
|
|
|
|
|
from django.db.models import Q
|
|
|
from django.utils.decorators import method_decorator
|
|
|
from drf_yasg import openapi
|
|
|
from drf_yasg.utils import swagger_auto_schema
|
|
|
from rest_framework import viewsets
|
|
|
from basic_info.models import WarehouseModel
|
|
|
|
|
|
from ERP_5.apps.basic_info.serializer.warehouse_serializer import WarehouseSerializer, WarehouseSearchSerializer
|
|
|
from ERP_5.utils.paginations import GlobalPagination
|
|
|
from ERP_5.utils.base_views import MultipleDestroyMixin, MultipleOpenMixin
|
|
|
|
|
|
logger = logging.getLogger('my')
|
|
|
|
|
|
param1 = openapi.Parameter(name='name', type=openapi.TYPE_STRING, description="名称的关键字", in_=openapi.IN_QUERY)
|
|
|
param2 = openapi.Parameter(name='remark', type=openapi.TYPE_STRING, description="备注关键字", in_=openapi.IN_QUERY)
|
|
|
|
|
|
|
|
|
@method_decorator(name='list', decorator=swagger_auto_schema(
|
|
|
manual_parameters=[param1, param2],
|
|
|
operation_description="仓库的搜索过滤")
|
|
|
)
|
|
|
class WarehouseView(viewsets.ModelViewSet, MultipleDestroyMixin, MultipleOpenMixin):
|
|
|
"""
|
|
|
create:
|
|
|
仓库信息--新增
|
|
|
|
|
|
仓库信息新增, status: 201(成功), return: 新增仓库信息信息
|
|
|
|
|
|
destroy:
|
|
|
仓库信息--删除
|
|
|
|
|
|
仓库信息删除, status: 204(成功), return: None
|
|
|
|
|
|
multiple_delete:
|
|
|
仓库信息--批量删除,必传json参数:ids=[1,2,3,4...]
|
|
|
|
|
|
仓库信息批量删除, status: 204(成功), return: None
|
|
|
|
|
|
multiple_open:
|
|
|
仓库信息--批量启用或者禁用,必传(json)参数:ids=[1,2,3,4...](列表中可以只有一个),is_open=1/0
|
|
|
|
|
|
{
|
|
|
"ids":[1,2],
|
|
|
"is_open":"0"
|
|
|
}
|
|
|
is_open=1表示禁用,is_open=0表示启用,
|
|
|
仓库信息批量启用或者禁用, status: 204(成功), return: None
|
|
|
|
|
|
update:
|
|
|
仓库信息--修改,一般用于修改多个属性
|
|
|
|
|
|
仓库信息修改, status: 200(成功), return: 修改后的仓库信息信息
|
|
|
|
|
|
partial_update:
|
|
|
仓库信息--局部修改(一般修改一个属性),可以传参任意属性的值,服务器会修改指定的属性值
|
|
|
|
|
|
仓库信息局部修改, status: 200(成功), return: 修改后的仓库信息信息
|
|
|
|
|
|
list:
|
|
|
仓库信息--获取分页列表,可选json参数:name(名称),remark(描述关键字)
|
|
|
|
|
|
{
|
|
|
"name":"长沙",
|
|
|
"remark":"xxxx"
|
|
|
}
|
|
|
仓库信息列表信息, status: 200(成功), return: 仓库信息信息列表
|
|
|
|
|
|
retrieve:
|
|
|
查询某一个仓库信息
|
|
|
|
|
|
查询指定ID的仓库信息, status: 200(成功), return: 用户仓库信息
|
|
|
"""
|
|
|
|
|
|
queryset = WarehouseModel.objects.all()
|
|
|
serializer_class = WarehouseSerializer
|
|
|
pagination_class = GlobalPagination
|
|
|
|
|
|
def get_queryset(self):
|
|
|
if self.action == 'list': # 过滤查询
|
|
|
# 获取请求参数(在json中):name,phone, mobile
|
|
|
name = self.request.data.get('name', None)
|
|
|
remark = self.request.data.get('remark', None)
|
|
|
query = Q()
|
|
|
if name:
|
|
|
query.add(Q(name__contains=name), 'AND') # 多条件组合
|
|
|
if remark:
|
|
|
query.add(Q(remark__contains=remark), 'AND')
|
|
|
return WarehouseModel.objects.filter(query).all()
|
|
|
else:
|
|
|
return WarehouseModel.objects.all()
|
|
|
|
|
|
def get_serializer_class(self):
|
|
|
if self.action == 'list': # 过滤查询 ,设置新的序列化器
|
|
|
return WarehouseSearchSerializer
|
|
|
else:
|
|
|
return WarehouseSerializer
|