OdooDigitizationService/addons/tx_cms_upgrade/controllers/collection_demand_scenarios.py

400 lines
17 KiB
Python

# -*- coding: utf-8 -*-
import json
import logging
import datetime
import math
import requests
from odoo import http, tools
from .tool import MakeResponse
_logger = logging.getLogger(__name__)
class CollectionDemandScenarios(http.Controller):
@http.route('/collection_demand_scenarios', type='http', auth="public", website=True)
def list(self, **kw):
uid = http.request.uid
if uid == 4:
return http.request.redirect('/web/login')
state = {"draft": "草稿",
"approve": "待审核",
"pass": "通过",
"reject": "驳回"}
records = http.request.env["tx.collection.demand.scenarios"].search([("create_uid", "=", uid)])
return http.request.render('tx_cms_upgrade.collectionDemandScenarios', {"records": records, "state": state})
@http.route('/collection_demand_scenarios/list', type='http', auth="user", website=True)
def record_list(self, **kw):
uid = http.request.uid
if uid == 4:
return http.request.redirect('/web/login')
state = {"draft": "草稿",
"approve": "待审核",
"pass": "通过",
"reject": "驳回"}
data = http.request.env["tx.collection.demand.scenarios"].search([("create_uid", "=", uid)])
records = []
if data.__len__():
for r in data:
records.append({
"id": r.id,
"name": r.name,
"describe": r.describe,
"state": r.state,
"doneDate": r.done_date.__str__(),
})
return MakeResponse.success({
"records": records,
"state": state,
})
@http.route('/collection_demand_scenarios_details/<model("tx.collection.demand.scenarios"):obj>', type='http', auth="public",
website=True)
def collection_demand_scenarios_details(self, obj, **kw):
return http.request.render('tx_cms_upgrade.collectionDemandScenariosDetails', {
'object': obj
})
@http.route('/collection_demand_scenarios/details', methods=['get'], auth='user', website=True)
def record_details(self, recordId, **kw):
record_obj = http.request.env["tx.collection.demand.scenarios"].sudo()
obj = record_obj.sudo().browse([int(recordId)])
return MakeResponse.success({
"name": obj.name,
"companyName": obj.company_name,
"doneDate": obj.done_date.__str__(),
"amount": obj.amount,
"provideCompanyName": obj.provide_company_name,
"describe": obj.describe,
"ask": obj.ask,
"content": obj.content,
})
@http.route('/collection_demand_scenarios/new', type='http', auth="public", website=True)
def listNew(self, **kw):
uid = http.request.uid
if uid == 4:
return http.request.redirect('/web/login')
return http.request.render('tx_cms_upgrade.collectionDemandScenariosNew', {})
@http.route('/collection_demand_scenarios/create/<string:model_name>', type='http', auth="user", methods=['POST'], website=True, csrf=False)
def listCreate(self, model_name, **kw):
uid = http.request.uid
if uid == 4:
return http.request.redirect('/web/login')
data = {
"name": kw.get("name", False),
"describe": kw.get("describe", False),
"content": kw.get("content", False),
"ask": kw.get("ask", False),
"amount": kw.get("amount", False),
}
if kw.get("done_date", False):
data["done_date"] = datetime.datetime.strptime(kw.get("done_date", False), '%Y年%m月%d')
if kw.get("img", False):
data["demand_file"] = kw.get("img", False).read()
data["demand_file_name"] = kw.get("img", False).filename
demand_id = http.request.env["tx.collection.demand.scenarios"].create(data)
return json.dumps({'id': demand_id.id})
@http.route('/tx_base/api/demandConfig/isDemandConfig', type='http', auth="public", methods=['GET'], website=True, csrf=False)
def get_demand_config(self):
result = 2
record_obj = http.request.env["tx.requirement.collection.configuration"].sudo()
obj = record_obj.sudo().search([], limit=1, order="id desc")
if obj.__len__():
result = int(obj.state)
return MakeResponse.success(result)
# 有数了 -- 标杆场景 列表
@http.route("/tx_base/api/demandScene/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def demand_scene_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)
scenes_name = params.get("scenesName", "")
demand_label = params.get("demandLabel", "")
create_by = params.get("createBy", "")
update_by = params.get("updateBy", "")
model_obj = http.request.env["tx.collection.demand.scenarios"].sudo()
records = []
domain = []
if create_by:
user_id = http.request.env.user.sudo().search([("login", "=", create_by)])
if user_id.__len__():
domain.append(("create_uid", "=", user_id.id))
if update_by:
user_id = http.request.env.user.sudo().search([("login", "=", update_by)])
if user_id.__len__():
if domain.__len__():
domain.insert(0, "|")
domain.append(("write_uid", "=", user_id.id))
if demand_label != "":
domain.append(("scenarios_type", "=", f"%{demand_label}%"))
if scenes_name != "":
domain.append(("name", "like", f"%{scenes_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)
state = {
"approve": "1",
"done": "2",
"reject": "3",
}
for data in dataAll:
records.append({
"demandId": data.id,
"demandName": data.name,
"demandLabel": data.scenarios_type,
"demandField": data.sub_territory,
"companyName": data.company_name,
"demandContent": data.describe or "",
"assessmentRequirement": data.ask,
"deliverContent": data.content,
"solutionProvider": data.provide_company_name,
"status": state[data.state],
"finishTime": f"""{data.create_date.strftime("%Y-%m-%d") if data.create_date else datetime.date.today().strftime("%Y-%m-%d")}&{data.done_date.strftime("%Y-%m-%d") if data.done_date else datetime.date.today().strftime("%Y-%m-%d")}""",
})
pages = math.ceil(total / page_size)
return MakeResponse.opontekr_success(records, total, pages)
# 有数了 -- 标杆场景 列表
@http.route("/tx_base/api/demandScene/info", methods=['GET'], auth='public', csrf=False, website=True, cors="*")
def demand_scene_info(self, **kw):
try:
demandId = kw.get("demandId", False)
model_obj = http.request.env["tx.collection.demand.scenarios"].sudo()
record = model_obj.search([("id", "=", int(demandId))], limit=1, order="id desc")
state = {
"approve": "1",
"done": "2",
"reject": "3",
}
data = {
"demandName": record.name,
"demandLabel": record.scenarios_type,
"demandField": record.sub_territory,
"companyName": record.company_name,
"demandContent": record.describe or "",
"assessmentRequirement": record.ask,
"deliverContent": record.content,
"solutionProvider": record.provide_company_name,
"status": state[record.state],
"finishTime": f"""{record.create_date.strftime("%Y-%m-%d") if record.create_date else datetime.date.today().strftime("%Y-%m-%d")}&{record.done_date.strftime("%Y-%m-%d") if record.done_date else datetime.date.today().strftime("%Y-%m-%d")}""",
}
return MakeResponse.success(data)
except Exception as e:
_logger.error(e)
return MakeResponse.error("参数错误")
@http.route("/tx_base/api/demandScene/deleteYsDemandSceneById", methods=['GET'], auth='public', csrf=False, website=True, cors="*")
def delete_demand_scene(self, **kw):
demandId = kw.get("demandId", False)
if demandId:
http.request.env["tx.collection.demand.scenarios"].sudo().search([("id", "=", int(demandId))]).unlink()
return MakeResponse.success("删除成功")
# 有数了 -- 活动热点资讯 列表
@http.route("/tx_base/api/hotInfo/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def hotInfo_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)
model_obj = http.request.env["tx.activity.hotspot.information"].sudo()
records = []
domain = []
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,
"hotAvatar": f"""{data.get_base_url()}{http.request.website.sudo().image_url(data, 'img')}""",
"hotName": f"{data.name}",
"hotContent": data.content,
"createTime": data.create_date.strftime("%Y-%m-%d") if data.create_date else datetime.date.today().strftime("%Y-%m-%d"),
})
pages = math.ceil(total / page_size)
return MakeResponse.opontekr_success(records, total, pages)
# 有数了 -- 活动热点资讯 详情
@http.route("/tx_base/api/hotInfo/info", methods=['GET'], auth='public', csrf=False, website=True, cors="*")
def record_info(self, **kwargs):
try:
hotId = kwargs.get("hotId", False)
model_obj = http.request.env["tx.activity.hotspot.information"].sudo()
record = model_obj.search([("id", "=", hotId)])
data = {
"hotName": f"{record.name}",
"hotContent": record.content,
"createTime": record.create_date.strftime("%Y-%m-%d") if record.create_date else datetime.date.today().strftime("%Y-%m-%d"),
}
return MakeResponse.success(data)
except Exception as e:
_logger.error(e)
return MakeResponse.error("参数错误")
# 有数了 -- 我的场景需求 列表
@http.route("/tx_base/api/scanned/list", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def scanned_list(self, **kwargs):
try:
model_obj = http.request.env["tx.demand.scanned"].sudo()
params = json.loads(http.request.httprequest.data.decode("utf-8"))
create_by = params.get("createBy", "")
update_by = params.get("updateBy", "")
domain = []
if create_by:
user_id = http.request.env.user.sudo().search([("login", "=", create_by)])
if user_id.__len__():
domain.append(("create_uid", "=", user_id.id))
if update_by:
user_id = http.request.env.user.sudo().search([("login", "=", update_by)])
if user_id.__len__():
if domain.__len__():
domain.insert(0, "|")
domain.append(("write_uid", "=", user_id.id))
total = model_obj.search_count(domain)
dataAll = model_obj.search(domain)
for data in dataAll:
data = {
"hotName": f"{data.name}",
"hotContent": data.content,
}
return MakeResponse.success(data)
except Exception as e:
_logger.error(e)
return MakeResponse.error("参数错误")
# 有数了 -- 我的投稿 列表
@http.route("/tx_base/api/myContribution/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)
state = {
"draft": "1",
"done": "2",
"fail": "3",
}
model_obj = http.request.env["tx.my.submission"].sudo()
records = []
domain = []
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,
"name": data.name,
"demandId": data.demand_id.id,
"demandName": data.demand_name,
"companyName": data.company_name,
"natureBusiness": data.nature_business,
"businessCode": data.business_code,
"contactInformation": data.contact_information,
"contactPerson": data.contact_person,
"solutionFileName": data.solution_file_name,
"companyFileName": data.company_file_name,
"status": state[data.state],
"createTime": data.create_date.strftime("%Y-%m-%d") if data.create_date else datetime.date.today().strftime("%Y-%m-%d"),
})
pages = math.ceil(total / page_size)
return MakeResponse.opontekr_success(records, total, pages)
# 有数了 -- 我的投稿 上传
@http.route("/tx_base/api/myContribution/add", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def scenes_add(self, **kw):
model_obj = http.request.env["tx.my.submission"].sudo()
params = json.loads(http.request.httprequest.data.decode("utf-8"))
companyFileId = params.get("companyFileId", False)
solutionFileId = params.get("solutionFileId", False)
demand_id = model_obj.demand_id.search([("name", "=", params["demandName"])])
user_id = model_obj.create_uid.search([("login", "=", params["createBy"])])
submission_id = model_obj.with_user(user_id.id).create({
"demand_id": demand_id.id,
"demand_name": params.get("demandName", False),
"company_name": params.get("companyName", False),
"nature_business": params.get("natureBusiness", False),
"business_code": params.get("businessCode", False),
"contact_information": params.get("contactInformation", False),
"contact_person": params.get("contactPerson", False),
"solution_file_name": params.get("solutionFileName", False),
"company_file_name": params.get("companyFileName", False),
})
company_file_id = http.request.env["ir.attachment"].sudo().browse([companyFileId])
company_file_id.update({
"res_id": submission_id.id,
"res_model": "tx.my.submission",
"res_field": "company_file",
})
solution_file_id = http.request.env["ir.attachment"].sudo().browse([solutionFileId])
solution_file_id.update({
"res_id": submission_id.id,
"res_model": "tx.my.submission",
"res_field": "solution_file",
})
return MakeResponse.success("上传成功")
@http.route("/tx_base/api/scanned/add", methods=['POST'], auth='public', csrf=False, website=True, cors="*")
def scanned_add(self, **kwargs):
try:
params = json.loads(http.request.httprequest.data.decode("utf-8"))
model_obj = http.request.env["tx.demand.scanned"].sudo()
scannedId = params.get('scannedFile', False)
user_id = model_obj.create_uid.search([("login", "=", params["createBy"])])
scanned_id = model_obj.with_user(user_id.id).create({
"company_name": params.get('companyName', False),
"contact_name": params.get('contactName', False),
"contact_position": params.get('contactPosition', False),
"contact_phone": params.get('contactPhone', False),
"scanned_file_name": params.get('scannedFile', False),
})
scanned_file_id = http.request.env["ir.attachment"].sudo().browse([scannedId])
scanned_file_id.update({
"res_id": scanned_id.id,
"res_model": "tx.demand.scanned",
"res_field": "scanned_file",
})
MakeResponse.success("提交成功")
except Exception as e:
_logger.error(e)
return MakeResponse.error("系统错误")