|
|
|
@ -1,7 +1,16 @@ |
|
|
|
|
from pydoc import pager |
|
|
|
|
|
|
|
|
|
from rest_framework import viewsets |
|
|
|
|
from rest_framework.response import Response |
|
|
|
|
|
|
|
|
|
from product.serializers import * |
|
|
|
|
from django_filters.rest_framework import DjangoFilterBackend |
|
|
|
|
from rest_framework.decorators import action |
|
|
|
|
from product.utils.pagination import PageNumberPagination, CustomPageNumberPagination |
|
|
|
|
import pymysql |
|
|
|
|
from pymysql.cursors import DictCursor |
|
|
|
|
from dingxin_toolbox_drf.settings import CONFIG |
|
|
|
|
from env import * |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here. |
|
|
|
@ -33,6 +42,38 @@ class PrdItemViewSet(viewsets.ModelViewSet): |
|
|
|
|
filterset_fields = ('project',) |
|
|
|
|
pagination_class = CustomPageNumberPagination |
|
|
|
|
|
|
|
|
|
@action(methods=['get'], detail=False, url_path='ax_cloud') |
|
|
|
|
def get_ax_cloud_time(self, request): |
|
|
|
|
# 获取数据 |
|
|
|
|
queryset = self.get_queryset() |
|
|
|
|
|
|
|
|
|
if queryset is not None: |
|
|
|
|
# 获取项目时间 |
|
|
|
|
db_config = CONFIG[ENV]['AX_CLOUD_DB'] |
|
|
|
|
db = { |
|
|
|
|
'host': db_config['HOST'], |
|
|
|
|
'port': db_config['PORT'], |
|
|
|
|
'user': db_config['USER'], |
|
|
|
|
'password': db_config['PASSWORD'], |
|
|
|
|
'db': db_config['NAME'], |
|
|
|
|
} |
|
|
|
|
print(db) |
|
|
|
|
db_conn = pymysql.Connect(**db) |
|
|
|
|
db_cursor = db_conn.cursor(cursor=DictCursor) |
|
|
|
|
sql = "select Shortcut, ModifiedOn from axshare.axshare_ShortcutKey;" |
|
|
|
|
db_cursor.execute(sql) |
|
|
|
|
ax_cloud_data = db_cursor.fetchall() |
|
|
|
|
db_conn.close() |
|
|
|
|
# 遍历数据 |
|
|
|
|
for data in queryset: |
|
|
|
|
shortcut_key = data.prd_doc_link.split(r'/')[-1] |
|
|
|
|
for item in ax_cloud_data: |
|
|
|
|
if item['Shortcut'].lower() == shortcut_key.lower(): |
|
|
|
|
data.update_at = item['ModifiedOn'] |
|
|
|
|
page = self.paginate_queryset(queryset) |
|
|
|
|
serializer = self.get_serializer(page, many=True) |
|
|
|
|
return self.get_paginated_response(serializer.data) |
|
|
|
|
return Response(None) |
|
|
|
|
|
|
|
|
|
class PrdHistoryViewSet(viewsets.ModelViewSet): |
|
|
|
|
# 字段注释 |
|
|
|
|