134 lines
4.8 KiB
Python
134 lines
4.8 KiB
Python
import base64
|
|
import json
|
|
|
|
from odoo import http, fields
|
|
from odoo.http import request
|
|
from urllib.parse import quote
|
|
|
|
|
|
class YuthonNotice(http.Controller):
|
|
|
|
@http.route('/yuthon/yuthon/notice', methods=['POST'], type='http', auth='none', csrf=False)
|
|
def index(self, **kwargs):
|
|
id = kwargs.get('id')
|
|
|
|
data = request.env['yuthon.notice'].sudo().search([("id", "=", int(id))])
|
|
documents = []
|
|
for document in data.documents_ids:
|
|
documents.append({
|
|
'id': document.id,
|
|
'name': document.name,
|
|
'url': document.url,
|
|
'type': document.type,
|
|
'file_size': document.file_size,
|
|
'file_size_display':document.file_size_display,
|
|
'mimetype': document.mimetype,
|
|
'datas': document.datas.decode('utf-8') if document.datas else None,
|
|
})
|
|
|
|
result = {
|
|
'id': data.id,
|
|
'title': data.name,
|
|
'code': data.code,
|
|
'create_date1': fields.Date.to_string(data.create_date1),
|
|
'notice_text': data.notice_text,
|
|
'documents':documents,
|
|
'user_name':data.users_id.name,
|
|
'read_number': data.read_number,
|
|
}
|
|
return json.dumps({
|
|
'data':result,
|
|
'code':200,
|
|
'message':'success'
|
|
})
|
|
|
|
@http.route('/yuthon/notice/list', methods=['POST'], type='http', auth='none', csrf=False)
|
|
def yuthon_notice_list(self, **kwargs):
|
|
user_id = kwargs.get('users_id') # 按创建人筛选
|
|
domain = []
|
|
if user_id:
|
|
user_id_int = int(user_id)
|
|
domain.append(('users_id', '=', user_id_int))
|
|
notice_data = request.env['yuthon.notice'].sudo().search(domain)
|
|
result_list = []
|
|
urgency_map = {'normal': '普件', 'urgent': '急件', 'emergency': '特急件'}
|
|
for notice in notice_data:
|
|
department_list = []
|
|
file_list = []
|
|
for attach in notice.documents_ids:
|
|
file_url = 'http://view.officeapps.live.com/op/view.aspx?src=' + quote('https://oa.thtzjt.com' + '/web/content/office_preview/' + str(attach.id))
|
|
file_list.append({'file_url': file_url, 'file_name': attach.display_name})
|
|
result = {
|
|
'id': notice.id,
|
|
'title': notice.name,
|
|
'code': notice.code,
|
|
'notice_text': notice.notice_text,
|
|
'create_date1': fields.Date.to_string(notice.create_date1),
|
|
'user_name': notice.users_id.name,
|
|
'read_number': notice.read_number or 0,
|
|
'department_ids': department_list,
|
|
'file_list': file_list,
|
|
'urgency_level': notice.urgency_level,
|
|
'urgency_name': urgency_map.get(notice.urgency_level, ''),
|
|
}
|
|
result_list.append(result)
|
|
return json.dumps({
|
|
'data': result_list,
|
|
'code': 200,
|
|
'message': 'success'
|
|
})
|
|
|
|
|
|
@http.route('/yuthon/notice/record', methods=['POST'], type='http', auth='none', csrf=False)
|
|
def yuthon_notice_record(self, **kwargs):
|
|
id = kwargs.get('id')
|
|
|
|
data = request.env['yuthon.notice'].sudo().search([("id", "=", int(id))])
|
|
|
|
department_list = []
|
|
for dept in data.department_ids:
|
|
department_list.append({
|
|
'id': dept.id,
|
|
'name': dept.name,
|
|
})
|
|
|
|
role_group_list = [
|
|
{'id': group.id, 'name': group.name} # res.groups的name字段是角色组名称
|
|
for group in data.users_role_group_ids
|
|
]
|
|
|
|
file_list = []
|
|
for attach in data.documents_ids:
|
|
attach_id = request.env['ir.attachment'].sudo().search([('id', '=', attach.id)])
|
|
file_url = 'http://view.officeapps.live.com/op/view.aspx?src=' + quote('https://oa.thtzjt.com' + '/web/content/office_preview/' + str(attach_id.id))
|
|
file_list.append({
|
|
'file_url': file_url,
|
|
'file_name': attach_id.display_name,
|
|
})
|
|
|
|
urgency_map = {'normal': '普件','urgent': '急件','emergency': '特急件',}
|
|
|
|
urgency_name = urgency_map.get(data.urgency_level)
|
|
|
|
result = {
|
|
'id': data.id,
|
|
'title': data.name,
|
|
'code': data.code,
|
|
'notice_text': data.notice_text,
|
|
'create_date1': fields.Date.to_string(data.create_date1),
|
|
'user_name': data.users_id.name,
|
|
'read_number': data.read_number,
|
|
'department_ids': department_list,
|
|
'users_role_group_ids': role_group_list,
|
|
'file_list': file_list,
|
|
'urgency_name': urgency_name,
|
|
}
|
|
return json.dumps({
|
|
'data':result,
|
|
'code':200,
|
|
'message':'success'
|
|
})
|
|
|
|
|
|
|