# -*- coding: utf-8 -*- import json import math import logging import datetime from odoo import http, tools from .tool import MakeResponse _logger = logging.getLogger(__name__) class highQualitySolutions(http.Controller): @http.route(['/high_quality_solutions'], type='http', auth="public", website=True) def list(self, **kw): return http.request.render('tx_cms_upgrade.highQualitySolutions', {}) @http.route(['/high_quality_solutions_data', '/high_quality_solutions_data/page/'], type='http', auth="public", website=True) def listData(self, technical_id=0, industry_id=0, page=1, **kw): solutions_obj = http.request.env["tx.high.quality.solutions"].sudo() _post_per_page = 9 page = int(page) technicalList = [] industryList = [] technical_id = int(technical_id) industry_id = int(industry_id) technical_ids = solutions_obj.technical_ids.sudo().search([("code", "=", "TF")])._get_dict_values() for index, item in enumerate(technical_ids): item["active"] = True if item["id"] == technical_id else False technicalList.append(item) industry_ids = solutions_obj.industry_ids.sudo().search([("code", "=", "IF")])._get_dict_values() for index, item in enumerate(industry_ids): item["active"] = True if item["id"] == industry_id else False industryList.append(item) domain = [] if industry_id: domain.append(("industry_ids", "in", [industry_id])) if technical_id: domain.append(("technical_ids", "in", [technical_id])) solutionsAll = solutions_obj.search(domain) pager = tools.lazy( lambda: http.request.website.pager(url='/high_quality_solutions_data', total=solutionsAll.__len__(), page=page, step=_post_per_page, scope=_post_per_page, url_args=kw)) solutionsData = solutionsAll[(page - 1) * _post_per_page:page * _post_per_page] records = [] for solutions in solutionsData: records.append({ "id": solutions.id, "recommend": solutions.recommend, "imgUrl": http.request.website.image_url(solutions, 'img'), "name": solutions.name, "companyName": solutions.company_name, "createDate": f"""{solutions.create_date.year}年{solutions.create_date.month}月{solutions.create_date.day}日""", "briefIntroduction": str(solutions.brief_introduction), "technicalIds": [technical_id.name for technical_id in solutions.technical_ids], }) return MakeResponse.success({ "technicalList": technicalList, "industryList": industryList, "records": records, "technical_id": technical_id, "industry_id": industry_id, "pager": pager._value, }) @http.route('/high_quality_solutions_details/', type='http', auth="public", website=True) def object(self, obj, **kw): return http.request.render('tx_cms_upgrade.highQualitySolutionsDetails', { 'object': obj }) @http.route('/high_quality_solutions/details', methods=['get'], auth='public', website=True) def record_details(self, recordId, **kw): record_obj = http.request.env["tx.high.quality.solutions"].sudo() obj = record_obj.sudo().browse([int(recordId)]) return MakeResponse.success({ "name": obj.name, "briefIntroduction": obj.brief_introduction, "technicalList": [technical_id.name for technical_id in obj.technical_ids], "imgUrl": http.request.website.image_url(obj, 'img'), "companyName": obj.company_name, "content": obj.content, }) # 有数了 -- 优质方案 列表 @http.route("/tx_base/api/plan/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*") def scenes_list(self, **kw): params = json.loads(http.request.httprequest.data.decode("utf-8")) page_num = params.get("pageNum", 1) page_size = params.get("pageSize", 10) plan_name = params.get("planName", "") technical_type = params.get("technicalType", []) industry_type = params.get("industryType", []) model_obj = http.request.env["tx.high.quality.solutions"].sudo() records = [] domain = [] if technical_type.__len__(): domain.append(("technical_ids", "in", technical_type)) if industry_type.__len__(): domain.append(("industry_ids", "in", industry_type)) if plan_name: domain.append(("name", "like", f"%{plan_name}%")) total = model_obj.search_count(domain) offset = (page_num - 1) * page_size if page_num > 1 else 0 dataAll = model_obj.search(domain, offset, page_size) for data in dataAll: records.append({ "id": data.id, "planAvatar": f"""{data.get_base_url()}{http.request.website.image_url(data, 'img')}""", "planName": f"{data.name}", "planDescription": data.brief_introduction, "company": data.company_name, "technicalType": ",".join([technical_id.name for technical_id in data.technical_ids]), }) pages = math.ceil(total / page_size) return MakeResponse.opontekr_success(records, total, pages) # 有数了 -- 精细服务 详情 @http.route("/tx_base/api/plan/info", methods=['GET'], auth='public', csrf=False, website=True, cors="*") def record_info(self, **kwargs): try: planId = kwargs.get("planId", False) model_obj = http.request.env["tx.high.quality.solutions"].sudo() record = model_obj.search([("id", "=", planId)]) data = { "createTime": record.create_date.strftime("%Y-%m-%d") if record.create_date else datetime.date.today().strftime("%Y-%m-%d"), "planName": record.name, "planDescription": record.brief_introduction, "technicalType": ",".join([technical_id.name for technical_id in record.technical_ids]), "company": record.company_name, "planAvatar": f"""{record.get_base_url()}{http.request.website.image_url(record, 'img')}""", "productDtoList": [{"name": line.name, "content": line.content} for line in record.line_ids] } return MakeResponse.success(data) except Exception as e: _logger.error(e) return MakeResponse.error("参数错误")