Commit 225ba05e by 龚桂斌

合并分支 'tht-project' 到 'master'

Tht project

查看合并请求 !18
parents 6f51b7e9 ed5de1a0
...@@ -28,10 +28,15 @@ ...@@ -28,10 +28,15 @@
'views/views.xml', 'views/views.xml',
'views/templates.xml', 'views/templates.xml',
'views/plant_working_time_config.xml', 'views/plant_working_time_config.xml',
'views/big_screen.xml',
'views/assets.xml',
'views/menus.xml', 'views/menus.xml',
], ],
# only loaded in demonstration mode # only loaded in demonstration mode
'demo': [ 'demo': [
'demo/demo.xml', 'demo/demo.xml',
], ],
'qweb': [
'static/src/xml/*.xml',
]
} }
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from . import controllers from . import controllers
from . import big_screen
\ No newline at end of file
# -*- coding: utf-8 -*-
from odoo import http, fields
from odoo.http import request
from odoo.addons.roke_mes_three_colour_light.controller.main import RokeMesThreeColourLight
import os
import math
from datetime import datetime, time
from jinja2 import Environment, FileSystemLoader
import logging
import requests
import json
_logger = logging.getLogger(__name__)
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
templateloader = FileSystemLoader(searchpath=BASE_DIR + "/static")
env = Environment(loader=templateloader)
dws_platform_url ='https://dws-platform.xbg.rokeris.com/dev-api/public/device'
# dws_platform_url = 'http://localhost/dev-api/public/device'
headers = {
'Content-Type': 'application/json',
}
class ResMesBigScreen(http.Controller):
@http.route('/roke/tht/expected_process', type='http', auth='public', csrf=False, cors="*")
def roke_expected_process_module(self, **kwargs):
template = env.get_template('html/big_screen/view/expected_process.html')
html = template.render({})
return html
@http.route('/roke/tht/cook_process', type='http', auth='public', csrf=False, cors="*")
def roke_cook_process_module(self, **kwargs):
template = env.get_template('html/big_screen/view/cook_process.html')
html = template.render({})
return html
def search_equipments(self, data_acquisition_code='', plant_name='', category_name=''):
"""查询设备"""
domain = []
if data_acquisition_code:
domain.append(('data_acquisition_code', 'in', data_acquisition_code))
# 构建查询条件
if plant_name:
domain.append(('plant_id.name', '=', plant_name))
if category_name:
domain.append(('category_id.name', '=', category_name))
# 查询设备
equipments = http.request.env['roke.mes.equipment'].sudo().search(domain)
# 构造响应数据
equipment_list = [{
'id': eq.id,
'device_name': eq.name,
'device_code': eq.code,
'data_acquisition_code': eq.data_acquisition_code,
'category': eq.category_id.name if eq.category_id else '',
'plant_name': eq.plant_id.name if eq.plant_id else '',
} for eq in equipments]
return equipment_list
def common_dws_interface(self, body=None, url='', cate=''):
"""获取大屏数据"""
plant_name = body.get("plant_name", '')
today = body.get("today", '')
device_code_list = body.get("device_code_list", [])
# if not today:
# today = fields.Date.today().strftime('%Y-%m-%d')
category_name = body.get("category_name",'')
# 构建查询条件
if device_code_list:
equipment_list = device_code_list
else:
equipment_list = self.search_equipments(plant_name=plant_name, category_name=category_name)
try:
api_path = dws_platform_url + url
payload = {
"plant_name": plant_name,
"today": today,
"category_name": category_name,
"device_code_list": equipment_list
}
if cate:
payload.update({"cate": cate})
res = requests.post(api_path, data=json.dumps(payload), headers=headers, )
res_json = res.json()
return res_json
except Exception as e:
_logger.error(e)
return {
"code": 100,
"msg": str(e),
"data": {
},
"success": False,
"time": fields.Datetime.now()
}
@http.route('/big_screen_count', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False,
cors='*')
def big_screen_count(self):
"""获取大屏数据"""
body = http.request.jsonrequest
return self.common_dws_interface(body, '/big_screen_count')
@http.route('/big_screen_today', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False,
cors='*')
def big_screen_today(self):
body = http.request.jsonrequest
return self.common_dws_interface(body, '/big_screen_today')
@http.route('/get_jiedongji_temperature', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False,
cors="*")
def get_jiedongji_temperature(self):
body = http.request.jsonrequest
return self.common_dws_interface(body, '/get_real_time_device_data', cate="解冻机")
@http.route('/get_qiekuaiji_data', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False, cors="*")
def get_qiekuaiji_data(self):
body = http.request.jsonrequest
device_code_list = body.get('device_code_list')
try:
api_path = dws_platform_url + '/get_qiekuaiji_data'
payload = {
"device_code_list": device_code_list
}
res = requests.post(api_path, data=json.dumps(payload), headers=headers, )
res_json = res.json()
return res_json
except Exception as e:
_logger.error(e)
return {
"code": 100,
"msg": str(e),
"data": {
},
"success": False,
"time": fields.Datetime.now()
}
@http.route('/get_yanxunlu_data', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False, cors="*")
def get_yanxunlu_data(self):
body = http.request.jsonrequest
return self.common_dws_interface(body, '/get_real_time_device_data', cate="烟熏炉")
@http.route('/get_lashengmo_data', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False, cors="*")
def get_lashengmo_data(self):
body = http.request.jsonrequest
return self.common_dws_interface(body, '/get_real_time_device_data', cate="拉伸膜包装机")
@http.route('/get_lishibaozhuang_data', type='json', methods=['POST', 'OPTIONS'], auth="none", csrf=False, cors="*")
def get_lishibaozhuang_data(self):
body = http.request.jsonrequest
return self.common_dws_interface(body, '/get_real_time_device_data', cate="制袋包装机")
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
odoo.define('tht_project.cook_process', function (require) {
"use strict";
const AbstractAction = require('web.AbstractAction');
const core = require('web.core');
const QWeb = core.qweb;
const session = require('web.session');
const Dialog = require("web.Dialog");
const CookProcessTemplate = AbstractAction.extend({
template: 'CookProcessTemplate',
start: async function () {
await this._super(...arguments);
let self = this;
window.addEventListener("message", function (event) {
});
},
});
core.action_registry.add('tht_project.cook_process', CookProcessTemplate);
return CookProcessTemplate;
});
odoo.define('tht_project.expected_process', function (require) {
"use strict";
const AbstractAction = require('web.AbstractAction');
const core = require('web.core');
const QWeb = core.qweb;
const session = require('web.session');
const Dialog = require("web.Dialog");
const ExpectedProcessTemplate = AbstractAction.extend({
template: 'ExpectedProcessTemplate',
start: async function () {
await this._super(...arguments);
let self = this;
window.addEventListener("message", function (event) {
});
},
});
core.action_registry.add('tht_project.expected_process', ExpectedProcessTemplate);
return ExpectedProcessTemplate;
});
...@@ -526,17 +526,24 @@ ...@@ -526,17 +526,24 @@
if (!deviceStateData || !Array.isArray(deviceStateData)) { if (!deviceStateData || !Array.isArray(deviceStateData)) {
return; return;
} }
const codeToSeqMap = {};
this.allEquipmentData.forEach(equip => {
codeToSeqMap[equip.code] = equip.sequence;
});
// 获取当前车间下的设备 code 列表 // 获取当前车间下的设备 code 列表
const validCodes = this.allEquipmentData const validCodes = this.allEquipmentData
.filter(e => !this.selectedWorkshop || e.plant_name === this.selectedWorkshop) .filter(e => !this.selectedWorkshop || e.plant_name === this.selectedWorkshop)
.map(e => e.code); .map(e => e.code);
// 过滤掉不属于当前车间的设备 // 过滤掉不属于当前车间的设备
const filteredDevices = deviceStateData.filter(d => const filteredDevices = deviceStateData.filter(d =>
!this.selectedWorkshop || validCodes.includes(d.code) !this.selectedWorkshop || validCodes.includes(d.code)
); ).map(device => ({
...device,
seq: codeToSeqMap[device.code] || Number.MAX_SAFE_INTEGER // 如果找不到 seq,默认排最后
}));
// 将API返回的数据转换为页面所需的格式 // 将API返回的数据转换为页面所需的格式
this.deviceList = filteredDevices.map((device) => { this.deviceList = filteredDevices.map((device) => {
...@@ -553,7 +560,9 @@ ...@@ -553,7 +560,9 @@
} }
// 计算持续时间的显示格式 // 计算持续时间的显示格式
let durationText = "0" let durationText = "0"
if (device.duration_hours !== undefined) { durationText = this.formatTime(Number(device.duration_hours * 3600)) } if (device.duration_hours !== undefined) {
durationText = this.formatTime(Number(device.duration_hours * 3600))
}
let run_seconds = "0" let run_seconds = "0"
if (device.run_seconds !== undefined) run_seconds = this.formatTime(Number(device.run_seconds)) if (device.run_seconds !== undefined) run_seconds = this.formatTime(Number(device.run_seconds))
...@@ -596,8 +605,8 @@ ...@@ -596,8 +605,8 @@
yellow_seconds: yellow_seconds, yellow_seconds: yellow_seconds,
red_seconds: red_seconds red_seconds: red_seconds
} }
}); }).sort((a, b) => (codeToSeqMap[a.code] || Number.MAX_SAFE_INTEGER)
this.deviceList = this.deviceList.filter((device) => device) - (codeToSeqMap[b.code] || Number.MAX_SAFE_INTEGER));
}, },
formatTime(seconds) { formatTime(seconds) {
......
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="CookProcessTemplate">
<iframe id="cook_process_template_iframe" src="/roke/tht/cook_process" frameBorder="no" width="100%" height="100%"/>
</t>
</templates>
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="ExpectedProcessTemplate">
<iframe id="expected_process_template_iframe" src="/roke/tht/expected_process" frameBorder="no" width="100%" height="100%"/>
</t>
</templates>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="tht_project_assets_backend" name="tht_project_assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/tht_project/static/src/js/expected_process.js"/>
<script type="text/javascript" src="/tht_project/static/src/js/cook_process.js"/>
</xpath>
</template>
</odoo>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="action_expected_process" model="ir.actions.client">
<field name="name">预料工序看板</field>
<field name="tag">tht_project.expected_process</field>
<field name="target">current</field>
</record>
<record id="action_cook_process" model="ir.actions.client">
<field name="name">成型工序看板</field>
<field name="tag">tht_project.cook_process</field>
<field name="target">current</field>
</record>
<!-- <menuitem id="roke_mes_equipment_kanban" name="设备看板" sequence="31"-->
<!-- parent="roke_mes_equipment.roke_mes_equipment_main_menu"-->
<!-- active="1"/>-->
<menuitem id="roke_mes_expected_process" name="预料看板" sequence="10"
action="action_expected_process" active="1"/>
<menuitem id="roke_mes_cook_process" name="成型工序" sequence="20"
action="action_cook_process" active="1"/>
</data>
</odoo>
\ No newline at end of file
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
<xpath expr="//field[@name='workshop_id']" position="after"> <xpath expr="//field[@name='workshop_id']" position="after">
<field name="data_acquisition_code"/> <field name="data_acquisition_code"/>
</xpath> </xpath>
<xpath expr="//field[@name='work_center_id']" position="after">
<field name="sequence"/>
</xpath>
</field> </field>
</record> </record>
<record id="view_roke_mes_equipment_tree_tht" model="ir.ui.view"> <record id="view_roke_mes_equipment_tree_tht" model="ir.ui.view">
......
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