def get_idi_realtime_connect_dict(self): return { get_store().get_kpi_monitor_msg_post_key(): get_store().get_kpi_monitor_msg_post_url(), get_store().get_scheduling_instruction_key(): get_store().get_scheduling_instruction_url(), }
async def post_update_plan(next_plan, current_plan): try: url = get_store().get_update_plan_url() all_data = get_context("all_data") plan_quality = all_data["data_collection"]["plan_quality"] client = HttpClient(AsyncHTTPClient(max_clients=1000)) data = [] # if current_plan: # data.append({ # "plan_no": current_plan, # "status": 3, # 2表示进行中,3表示暂停,4表示已完工 # "progress_detail": # 仅更新状态为暂停和已完工时传合格数和不合格数,对于进行中没有这个字段 # { # "qualified_count": plan_quality.get(next_plan,{}).get("positive_num",0), # "unqualified_count": plan_quality.get(next_plan,{}).get("negative_num",0) # } # } # ) data.append({ "plan_no": next_plan, "status": 2, # 2表示进行中,3表示暂停,4表示已完工 "progress_detail": # 仅更新状态为暂停和已完工时传合格数和不合格数,对于进行中没有这个字段 { "qualified_count": plan_quality.get(next_plan,{}).get("positive_num",0), "unqualified_count": plan_quality.get(next_plan,{}).get("negative_num",0) } }) res = await client.post(url, data=data) get_logger().info("post_update_plan data~~~~~~~~~~~~~~~~~~~~:%s", data) get_logger().debug("post_update_plan res~~~~~~~~~~~~~~~~~~~~:%s", res) client.close() except Exception as e: get_logger().error("post_update_plan error :%s", e)
async def get_idi_data(tag_code_list, start_time, end_time, org="organization_xldq"): logger = get_logger() logger.debug( "get_idi_data start,tag_code_list info:%s,start_time:%s,end_time:%s", tag_code_list, start_time, end_time) try: if isinstance(start_time, datetime): start_time = start_time.strftime(date_format) end_time = end_time.strftime(date_format) url = get_store().get_idi_url() data = [{ "code": tag_code, "start_time": start_time, "end_time": end_time, } for tag_code in tag_code_list] logger.debug("idi request url:%s", url) logger.debug("idi request data:%s", data) res = await get_data(url, {org: data}) logger.debug("idi res data:%s", res) return res[org] if res else {} except Exception as e: traceback.print_exc() logger.error("get_idi_data error:%s", e) return {}
async def get_on_duty_person_list(self, product_line_code): # 获取在岗所有人员编码列表 on_duty_person_list = [] url = '{}/api/attendance_manage/pipeline/{}/on_work_info'.format( get_store().get_attendence_management_app_url(), product_line_code) response = await send_request(url, None, 'GET') if response: response_body = json.loads(response.body.decode('utf-8')) if response_body['code'] == MesCode.success: on_duty_person_list = response_body['data'] return on_duty_person_list
async def get_plan_data_list(self, product_line_code, process_code): plan_data_list = [] url = '{}/api/monitor/production_plan_data/{}/{}'.format( get_store().get_production_monitor_app_url(), product_line_code, process_code) response = await send_request(url, None, 'GET') if response: response_body = json.loads(response.body.decode('utf-8')) if response_body['code'] == MesCode.success: plan_data_list = response_body['data'] return plan_data_list
async def get_attendance_data(product_line): try: global all_data target_url = get_store().get_onwork_attendance_url() client = HttpClient(AsyncHTTPClient(max_clients=1000)) attendance_data = await client.get(target_url.format(product_line), data={}) get_logger().debug("get_attendance_data~~~~~~~~~~~~~~~~~~~~:%s", attendance_data.data) client.close() return attendance_data.data except Exception as e: get_logger().error("get_attendance_data error:%s",e) return {}
async def get_working_hour_info(person_info=None): # 从考勤模块获取工时 try: store = get_store() report_module_url = store.data['data']['api']['working_hour'] client = HttpClient(AsyncHTTPClient(max_clients=1000)) report_data = await client.post(report_module_url, data=person_info) client.close() return report_data.data except Exception as e: get_logger().exception(e) raise Exception('考勤信息获取失败')
async def get_process(self, product_line): try: target_url = get_store().get_onwork_attendance_url() client = HttpClient(AsyncHTTPClient(max_clients=1000)) attendance_data = await client.get(target_url.format(product_line), data={}) client.close() attendance_response = attendance_data.data self.send_response_data(MesCode.success, attendance_response, 'success get data') except Exception as e: self.send_response_data(MesCode.fail, None, str(e))
async def get_report_info(): # 从报工模块获取当月信息 # TODO:报工模块将会返回具体到天的报工量,对应的计算接口需要调整 try: store = get_store() report_module_url = store.data['data']['api']['report'] client = HttpClient(AsyncHTTPClient(max_clients=1000)) report_data = await client.get(report_module_url, data={}) client.close() return report_data.data except Exception as e: get_logger().exception(e) raise Exception('报工信息获取失败')
async def send_real_data(data_dict,org="organization_xldq"): logger = get_logger() try: url = get_store().get_kpi_monitor_msg_post_url() client = HttpClient() data = { "kpi_realtime":{"data":[data_dict],"org":org}, } # logger.info("send real_data~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:%s", data) res = await client.post(url,data=data) # logger.info("send_real_data res:%s",res) except Exception as e: logger.error("send real data error,message:%s,error:%s", data_dict, e)
async def get_plan_info(product_line="product_line_6t90"): try: logger = get_logger() url = get_store().get_dispatched_plan_url() % product_line logger.info("get_plan_info url:%s", url) res = await get_data(url) """ :[{'plan_no': '11111', 'sequence': 1, 'material_name': 'T901H40ADC12V 4脚 永能标', 'material_code': 'materiel_t901h40adc12v4_ynb', 'plan_count': 1000, 'qualified_count': 0, 'unqualified_count': 0}] """ logger.info("get_plan_info data:%s,url:%s", res, url) return [{ "planId": i["plan_no"], "sequence": i["sequence"], "planProduct": i["material_name"], "productCode": i["material_code"], "planNum": i["plan_count"] } for i in res] except Exception as e: logger.error("get_plan_info error:%s", e) return []
async def post_data(message): logger = get_logger() # logger.info("start post_data~~~~~~~~~~~~~~~~~~~~~~") product_line = "product_line_6t90" try: url = get_store().get_idi_server_wsurl() tag_map_dict = get_tag_map_dict() value = message["value"] timestamp = timstamp_to_str(message["ts"]) code = tag_map_dict[message["tag"]] status_map_dict = get_status_code_map(product_line) logger.info("status_map_dict~~~~~~~~~~~~~~~~~~~~~~~:%s",status_map_dict) if code in status_map_dict: process_code = status_map_dict[code] await send_change_flag(product_line, [process_code], value) logger.debug("tag_map_dict:%s",tag_map_dict) data_dict = { "code": code , "value": value, "timestamp": timestamp , } try: data = { "organization_xldq": [data_dict] } logger.info("post data~~~~~~~~:%s,url:%s",data,url) await idi_send_data(IdiMesType.idi_tag_data,data) except Exception as e: traceback.print_exc() logger.error("post data error,message:%s,error:%s", message, e) # try: # await send_real_data(data_dict) # pass # except Exception as e: # logger.error("send real data error,message:%s,error:%s", data_dict, e) except Exception as e: logger.error("post data error,message:%s,error:%s",message,e)
def get_idi_history_connect_dict(self): return { get_store().get_idi_server_wskey(): get_store().get_idi_server_wsurl() }