111 lines
4.7 KiB
Python
111 lines
4.7 KiB
Python
import json
|
|
import logging
|
|
from odoo import http, fields
|
|
from odoo.http import request, Response
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
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,
|
|
})
|
|
file_list = []
|
|
pdf = ['application/pdf']
|
|
for file in data.documents_ids:
|
|
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
|
file_url = f"http://view.officeapps.live.com/op/view.aspx?src=https://oa.thtzjt.com/web/content/office_preview/{file.id}"
|
|
if file.mimetype in pdf:
|
|
file_url = f"{base_url}/web/content/preview/{file.id}"
|
|
file_list.append({
|
|
'file_url': file_url,
|
|
'file_name': file.name,
|
|
})
|
|
result = {
|
|
'id': data.id,
|
|
'title': data.name,
|
|
'code': data.code,
|
|
'create_date1': fields.Date.to_string(data.create_date1),
|
|
'notice_text': data.notice_text1 if data.notice_text1 else ' ',
|
|
'documents': documents,
|
|
'user_name': data.users_id.name,
|
|
'read_number': data.read_number,
|
|
'file_list': file_list
|
|
}
|
|
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):
|
|
_logger.info(f"-----/yuthon/notice/list---接口收到响应-----{kwargs}--")
|
|
user_id = request.env['res.users'].sudo().search([('id', '=', kwargs.get('employee_id'))])
|
|
notice_ids = request.env['yuthon.notice'].sudo().search([('users_ids', 'in', user_id.id), ('notice_state', '=', 'yes')])
|
|
_logger.info(f"-----相关公告数量{len(notice_ids)}--")
|
|
data_list = []
|
|
for notice in notice_ids:
|
|
result = {
|
|
'id': notice.id,
|
|
'create_date1': fields.Date.to_string(notice.create_date1) if notice.create_date1 else None,
|
|
'users_id': notice.users_id.name,
|
|
'name': notice.name,
|
|
'state': 'no'
|
|
}
|
|
data_list.append(result)
|
|
return json.dumps({'data': data_list, 'code': 200, 'message': 'success'})
|
|
|
|
@http.route('/yuthon/notice/detail', methods=['POST'], type='http', auth='none', csrf=False)
|
|
def yuthon_notice_detail(self, **kwargs):
|
|
notice = request.env['yuthon.notice'].sudo().search([('id', '=', kwargs.get('id'))])
|
|
file_list = []
|
|
pdf = ['application/pdf']
|
|
for file in notice.documents_ids:
|
|
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
|
file_url = f"http://view.officeapps.live.com/op/view.aspx?src=https://oa.thtzjt.com/web/content/office_preview/{file.id}"
|
|
if file.mimetype in pdf:
|
|
file_url = f"{base_url}/web/content/preview/{file.id}"
|
|
file_list.append({
|
|
'file_url': file_url,
|
|
'file_name': file.name,
|
|
})
|
|
result = {
|
|
'id': notice.id,
|
|
'create_date': fields.Date.to_string(notice.create_date) if notice.create_date1 else None,
|
|
'users_id': notice.users_id.name,
|
|
'title': notice.name,
|
|
'read_number': '0',
|
|
'notice_text': notice.notice_text1,
|
|
'file_list': file_list,
|
|
'is_notice_roger': notice.is_notice_roger,
|
|
}
|
|
return json.dumps({
|
|
'code': 200,
|
|
'message': 'success',
|
|
'data': result
|
|
})
|
|
|
|
@http.route('/yuthon/notice/confirm', methods=['POST'], type='http', auth='none', csrf=False)
|
|
def yuthon_notice_confirm(self, **kwargs):
|
|
notice_id = kwargs.get('id')
|
|
employee_id = kwargs.get('employee_id')
|
|
confirm_id = request.env['yuthon.confirm.users'].sudo().search([('notice_id', '=', int(notice_id)), ('employee_id.user_id', '=', employee_id)])
|
|
confirm_id.write({'state': 'yes'})
|
|
return json.dumps({'code': 200, 'message': 'OK'})
|
|
|
|
|