Commit 8f0037e0 by guibin

添加获取车间工作时间接口

parent 7fb1f750
...@@ -3,10 +3,47 @@ from odoo import http ...@@ -3,10 +3,47 @@ from odoo import http
from odoo.http import request from odoo.http import request
from odoo.addons.roke_mes_three_colour_light.controller.main import RokeMesThreeColourLight from odoo.addons.roke_mes_three_colour_light.controller.main import RokeMesThreeColourLight
import os import os
import math
from datetime import datetime, time
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) BASE_DIR = os.path.dirname(os.path.dirname(__file__))
templateloader = FileSystemLoader(searchpath=BASE_DIR + "/static/src/view") templateloader = FileSystemLoader(searchpath=BASE_DIR + "/static/src/view")
env = Environment(loader=templateloader) env = Environment(loader=templateloader)
class ThtProject(http.Controller):
@http.route('/tht/get/equipment/working_time', type='json', auth="none", csrf=False, cors='*')
def get_equipment_working_time(self, **kwargs):
jsonrequest = http.request.jsonrequest
plant_name = jsonrequest.get("plant_name", False)
domain = [("code", "!=", False)]
if plant_name:
domain.append(("plant_id.name", "=", plant_name))
equipment_ids = http.request.env['roke.mes.equipment'].sudo().search(domain)
today = datetime.now()
start_working_time_list = []
end_working_time_list = []
wait_time_list = []
plant_ids = equipment_ids.mapped("plant_id")
for plant_id in plant_ids:
config_id = http.request.env['plant.working.time.config'].sudo().search([("plant_id", "=", plant_id.id)], limit=1)
for item in equipment_ids.filtered(lambda x: x.plant_id == plant_id):
start_hour = math.floor(config_id.start_time)
start_working_time_list.append({
item.code: datetime.combine(today, time(start_hour, int((config_id.start_time - start_hour) * 60))).strftime("%Y-%m-%d %H:%M:%S")
})
end_hour = math.floor(config_id.end_time)
end_working_time_list.append({
item.code: datetime.combine(today, time(end_hour, int((config_id.end_time - end_hour) * 60))).strftime("%Y-%m-%d %H:%M:%S")
})
wait_time_list.append({
item.code: config_id.wait_time
})
return {"state": "success", "msgs": "获取数据成功!",
"start_working_time_list": start_working_time_list,
"end_working_time_list": end_working_time_list,
"wait_time_list": wait_time_list}
class RokeMesThreeColourLightExt(RokeMesThreeColourLight): class RokeMesThreeColourLightExt(RokeMesThreeColourLight):
#重写 #重写
@http.route("/roke/three_color_light/device_state_list", type="http", auth='none', cors='*', csrf=False) @http.route("/roke/three_color_light/device_state_list", type="http", auth='none', cors='*', csrf=False)
......
...@@ -401,19 +401,21 @@ ...@@ -401,19 +401,21 @@
// 发送请求获取计划运行时间 // 发送请求获取计划运行时间
const response = await axios({ const response = await axios({
method: "post", method: "post",
url: this.dwsURL + "/roke/workstation/equipment/get_plan_time", url: this.dwsURL + "/tht/get/equipment/working_time",
data: {}, data: {},
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
}); });
// 处理JSON-RPC格式的响应 // 处理JSON-RPC格式的响应
if (response.data && response.data.result && response.data.result.code === 0) { if (response.data && response.data.result && response.data.result.state === "success") {
// 获取计划运行时间数据 // 获取计划运行时间数据
const planTimeList = response.data.result.data || {}; const start_working_time_list = response.data.result.start_working_time_list || [];
const end_working_time_list = response.data.result.end_working_time_list || [];
const wait_time_list = response.data.result.wait_time_list || [];
// 调用设备状态接口 // 调用设备状态接口
await this.getDeviceStateList(planTimeList); await this.getDeviceStateList(start_working_time_list, end_working_time_list, wait_time_list);
return planTimeList; return start_working_time_list, end_working_time_list, wait_time_list;
} else { } else {
const errorMsg = response.data.result const errorMsg = response.data.result
? response.data.result.message ? response.data.result.message
...@@ -458,16 +460,18 @@ ...@@ -458,16 +460,18 @@
}, },
// 获取设备状态列表 // 获取设备状态列表
async getDeviceStateList(planTimeList) { async getDeviceStateList(start_working_time_list, end_working_time_list, wait_time_list) {
try { try {
// 使用CORS代理 // 使用CORS代理
// 发送请求获取设备状态 // 发送请求获取设备状态
const response = await axios({ const response = await axios({
method: "POST", method: "POST",
url: this.baseURL + "/public/device_efficiency/device_state_list", url: this.baseURL + "/public/device_efficiency/device_working_time_state_list",
data: { data: {
factory_code: this.factoryCode, factory_code: this.factoryCode,
plan_time_list: planTimeList, start_working_time_list: start_working_time_list,
end_working_time_list: end_working_time_list,
wait_time_list: wait_time_list,
}, },
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment