SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for adjustcruc
-- ----------------------------
DROP TABLE IF EXISTS `adjustcruc`;
CREATE TABLE `adjustcruc` (
  `mesmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `crucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`mesmoname`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='04_坩埚信息修正表';

-- ----------------------------
-- Table structure for allfeedingdetail
-- ----------------------------
DROP TABLE IF EXISTS `allfeedingdetail`;
CREATE TABLE `allfeedingdetail` (
  `feeding_task_id` bigint DEFAULT NULL,
  `mesmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpmodel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `moprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `moproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `feeding_task_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `stovetype` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `stovetypedesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `rx` int DEFAULT NULL,
  `finishmark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `finishmarkdesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cruciblesn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `prodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `proddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `material_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `material_type1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `level` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `serial_no` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `weight` decimal(10,2) DEFAULT NULL,
  `stovetime` datetime DEFAULT NULL,
  `mfgdate` datetime DEFAULT NULL,
  `month` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `factory` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate3` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `material_level` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `subprod` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='05_工单配料明细表';

-- ----------------------------
-- Table structure for dict
-- ----------------------------
DROP TABLE IF EXISTS `dict`;
CREATE TABLE `dict` (
  `id` int NOT NULL AUTO_INCREMENT,
  `cate` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `dictkey` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `value1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='03_字典表';

-- ----------------------------
-- Table structure for eqponstatuslogs
-- ----------------------------
DROP TABLE IF EXISTS `eqponstatuslogs`;
CREATE TABLE `eqponstatuslogs` (
  `eqpid` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpname` varchar(200) COLLATE utf8mb4_general_ci NOT NULL,
  `event` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eventtime` datetime NOT NULL,
  `eventid` varchar(200) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `savedate` datetime DEFAULT NULL COMMENT '归档时间',
  `eventtype` varchar(5) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '事件类型：1 报料，2 加料，3 开副室，4 晶棒产出，5 拆清',
  `eventstatus` varchar(5) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '事件状态',
  `rx` varchar(5) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '加次',
  `mesmoname` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'MES炉次号',
  KEY `eqponstatuslogs_eqpname_eventtime_eqpid_index` (`eqpname`,`eventtime` DESC,`eqpid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='06_炉台运行日志表';

-- ----------------------------
-- Table structure for eqponstovestatus
-- ----------------------------
DROP TABLE IF EXISTS `eqponstovestatus`;
CREATE TABLE `eqponstovestatus` (
  `area` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area1` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpid` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `mesmoname` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpmodel` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpstatus` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crusize` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `subprod` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `firststovetime` datetime DEFAULT NULL COMMENT '初投时间',
  `lastreporttime` datetime DEFAULT NULL,
  `laststovetime` datetime DEFAULT NULL,
  `lastopentime` datetime DEFAULT NULL,
  `lastouttime` datetime DEFAULT NULL,
  `finishtime` datetime DEFAULT NULL,
  `lastchaiqingtime` datetime DEFAULT NULL,
  `savedate` datetime DEFAULT NULL COMMENT '归档时间',
  `mfgdate` datetime DEFAULT NULL COMMENT '归档日期',
  `eventstatus` int DEFAULT NULL COMMENT '事件状态'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='07_炉台开启日志表';

-- ----------------------------
-- Table structure for equipment
-- ----------------------------
DROP TABLE IF EXISTS `equipment`;
CREATE TABLE `equipment` (
  `序号` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `site` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `eqpmodel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpname` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '旧炉号',
  PRIMARY KEY (`eqpid`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='01_炉台基础属性信息表';

-- ----------------------------
-- Table structure for mesmodailyyield
-- ----------------------------
DROP TABLE IF EXISTS `mesmodailyyield`;
CREATE TABLE `mesmodailyyield` (
  `mesmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'MES工单/炉次号',
  `erpmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'ERP工单号',
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '炉台号',
  `area` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '车间',
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '片区',
  `mfgdate` datetime DEFAULT NULL COMMENT '归档时间-以完结出炉时间',
  `finishdate` datetime DEFAULT NULL COMMENT '完结时间',
  `moprod` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工单产品',
  `moprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工单产品物料编码',
  `moproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工单物料描述',
  `stovetime` datetime DEFAULT NULL COMMENT '初投时间',
  `crusize` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '热场尺寸',
  `crucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '坩埚厂商',
  `cruciblesn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '坩埚编码',
  `adjustcruciblecode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修正后的坩埚简称编码',
  `adjustcrucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修正后的坩埚简称',
  `totalstoveweight` decimal(10,3) DEFAULT NULL COMMENT '投炉总重',
  `totaloutweight` decimal(10,3) DEFAULT NULL COMMENT '出炉总重',
  `totallength` int DEFAULT NULL COMMENT '总出炉长度',
  `totalqclength` int DEFAULT NULL COMMENT '总检验合格长度',
  `rod` decimal(10,3) DEFAULT NULL COMMENT '圆棒折重系数',
  `totalqcweight` decimal(10,3) DEFAULT NULL COMMENT '总出炉有效重量-圆棒',
  `totaldays` decimal(10,3) DEFAULT NULL COMMENT '工单运行时长',
  `mostatus` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'MES中工单状态',
  UNIQUE KEY `mesmodailyyield_mesmoname_uindex` (`mesmoname` DESC) USING BTREE,
  UNIQUE KEY `mesmodailyyield_pk` (`mesmoname`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='08_完结工单产量表';

-- ----------------------------
-- Table structure for mostatus
-- ----------------------------
DROP TABLE IF EXISTS `mostatus`;
CREATE TABLE `mostatus` (
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `MESmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `ERPmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `prodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `proddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crusize` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `stovetime` datetime DEFAULT NULL,
  `feeding_task_id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucible` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cruciblesn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `subprod` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `mostatus` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `mostatusdesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `finish_time` datetime DEFAULT NULL,
  `runtime` decimal(10,2) DEFAULT NULL,
  `rx` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `prodtype` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`MESmoname`) USING BTREE,
  KEY `MoName` (`MESmoname`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='09_工单状态表，用于抽取工单在制表';

-- ----------------------------
-- Table structure for outputtargetsetting
-- ----------------------------
DROP TABLE IF EXISTS `outputtargetsetting`;
CREATE TABLE `outputtargetsetting` (
  `id` int NOT NULL AUTO_INCREMENT,
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `mfgdate` datetime DEFAULT NULL,
  `targetmodel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crusize` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `prod` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `crucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `outputb` decimal(10,3) DEFAULT NULL,
  `outputc` decimal(10,3) DEFAULT NULL,
  `updateby` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `updatetime` datetime DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=572176 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='10_排产表';

-- ----------------------------
-- Table structure for prod
-- ----------------------------
DROP TABLE IF EXISTS `prod`;
CREATE TABLE `prod` (
  `code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `round` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `square` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate3` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `rodtosquare` decimal(10,3) DEFAULT NULL COMMENT '圆折方',
  PRIMARY KEY (`code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='02_产品规格属性表';

-- ----------------------------
-- Table structure for product
-- ----------------------------
DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
  `prodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `proddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `level` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate3` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`prodname`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='03_物料编码属性表';

-- ----------------------------
-- Table structure for recyclematerialouput
-- ----------------------------
DROP TABLE IF EXISTS `recyclematerialouput`;
CREATE TABLE `recyclematerialouput` (
  `lotsn` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  `prodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `proddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `prodtype` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `level` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `resistivity` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `weight` double DEFAULT NULL,
  `cate1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `cate3` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `mfgdate` datetime DEFAULT NULL,
  `month` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`lotsn`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='11_循环料产出表';

-- ----------------------------
-- Table structure for siteonlinecrucibleyield
-- ----------------------------
DROP TABLE IF EXISTS `siteonlinecrucibleyield`;
CREATE TABLE `siteonlinecrucibleyield` (
  `mfgdate` datetime DEFAULT NULL COMMENT '计产日期',
  `crystalbarno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '晶编',
  `eqpid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '炉台号',
  `area` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '车间',
  `area1` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '片区',
  `eqpmodel` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '炉型',
  `outlength` decimal(10,2) DEFAULT NULL COMMENT '出炉长度',
  `outweight` decimal(10,2) DEFAULT NULL COMMENT '出炉重量',
  `outtime` datetime DEFAULT NULL COMMENT '出炉时间',
  `qclength` decimal(10,2) DEFAULT NULL COMMENT '有效长度',
  `qcweight` decimal(10,2) DEFAULT NULL COMMENT '有效重量',
  `qctime` datetime DEFAULT NULL COMMENT 'qc时间',
  `crucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '坩埚厂家',
  `crusize` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '热场尺寸',
  `crunum` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '坩埚编码',
  `lastcrystalbarno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '上一棒晶编',
  `lastouttime` datetime DEFAULT NULL COMMENT '上一棒时间',
  `timeinterval` decimal(10,2) DEFAULT NULL COMMENT '生产时间',
  `crudesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '坩埚物料描述',
  `prod` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品简称',
  `subprod` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '产品规格',
  `erpmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'ERP工单号',
  `mesmoname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT 'MES工单号',
  `savedate` datetime DEFAULT NULL COMMENT '归档时间',
  `moprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工单产品编码',
  `moproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '工单物料描述',
  `actualprodname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '实际生产的物料编码',
  `actualproddesc` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `feeding_task_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '配料的任务id，用来匹配炉次的首次投炉日期',
  `hair_rod_coefficient` decimal(10,2) DEFAULT NULL COMMENT '毛棒折重系数',
  `round_rod_coefficient` decimal(10,2) DEFAULT NULL COMMENT '圆棒折重系数',
  `hair_square_rod_coefficient` decimal(10,2) DEFAULT NULL COMMENT '毛方棒折重系数',
  `stovetime` datetime DEFAULT NULL COMMENT '该炉次的首次投炉日期',
  `adjustcrucible` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修正的坩埚厂商\n\n使用运营的数据修正',
  `adjustcruciblecode` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修正的坩埚厂商代码，简称，使用2-3位字母',
  `squareqcweight` decimal(10,2) DEFAULT NULL COMMENT 'Qc长度折方棒重量',
  PRIMARY KEY (`crystalbarno`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='12_在线产量单产明细表';

-- ----------------------------
-- Table structure for updatelog
-- ----------------------------
DROP TABLE IF EXISTS `updatelog`;
CREATE TABLE `updatelog` (
  `id` int NOT NULL AUTO_INCREMENT,
  `tablename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `updatetime` datetime DEFAULT NULL,
  `status` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  `remark` varchar(400) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;

-- ----------------------------
-- Procedure structure for SyncMesData_every_12_hours
-- ----------------------------
DROP PROCEDURE IF EXISTS `SyncMesData_every_12_hours`;
delimiter ;;
CREATE PROCEDURE `SyncMesData_every_12_hours`()
BEGIN
#REPLACE into mes_sync.mes_job SELECT * from mes_origin.mes_job;
#REPLACE into mes_sync.erp_job_mtl_manage_task SELECT * from mes_origin.erp_job_mtl_manage_task;
#REPLACE into mes_sync.erp_job_mtl_manage_detail SELECT * from mes_origin.erp_job_mtl_manage_detail;
#REPLACE into mes_sync.erp_job_mtl SELECT * from mes_origin.erp_job_mtl;
#REPLACE into mes_sync.mes_job_recipe SELECT * from mes_origin.mes_job_recipe;
#REPLACE into mes_sync.mes_material SELECT * from mes_origin.mes_material;
#REPLACE into mes_sync.erp_job_opr SELECT * from mes_origin.erp_job_opr;
#REPLACE into mes_sync.mes_mother_alloy_task SELECT * from mes_origin.mes_mother_alloy_task;
#REPLACE into mes_sync.mes_mother_alloy SELECT * from mes_origin.mes_mother_alloy;
#REPLACE into mes_sync.mes_vehicle_feed_task SELECT * from mes_origin.mes_vehicle_feed_task;
#REPLACE into mes_sync.mes_task_send_erp SELECT * from mes_origin.mes_task_send_erp;
#REPLACE into mes_sync.mes_sub_chamber_task SELECT * from mes_origin.mes_sub_chamber_task;
#REPLACE into mes_sync.mes_seedcrystal_change SELECT * from mes_origin.mes_seedcrystal_change;
#REPLACE into mes_sync.mes_surplus_collect_task SELECT * from mes_origin.mes_surplus_collect_task;
#REPLACE into mes_sync.mes_surplus SELECT * from mes_origin.mes_surplus;
#REPLACE into mes_sync.mes_surplus_confirm_task SELECT * from mes_origin.mes_surplus_confirm_task;
#REPLACE into mes_sync.mes_vehicle_crystal SELECT * from mes_origin.mes_vehicle_crystal;
#REPLACE into mes_sync.mes_dismantle_task SELECT * from mes_origin.mes_dismantle_task;
#REPLACE into mes_sync.mes_dismantle_thermal SELECT * from mes_origin.mes_dismantle_thermal;
#REPLACE into mes_sync.mes_draw_line_task SELECT * from mes_origin.mes_draw_line_task;
#REPLACE into mes_sync.mes_round_bar_label SELECT * from mes_origin.mes_round_bar_label;
#REPLACE into mes_sync.mes_truncation_task SELECT * from mes_origin.mes_truncation_task;
#REPLACE into mes_sync.mes_resistance_gauging_task SELECT * from mes_origin.mes_resistance_gauging_task;
#REPLACE into mes_sync.mes_oxygen_carbon_detection_task SELECT * from mes_origin.mes_oxygen_carbon_detection_task;
#REPLACE into mes_sync.mes_specimen SELECT * from mes_origin.mes_specimen;
#REPLACE into mes_sync.mes_electrical_performance_task SELECT * from mes_origin.mes_electrical_performance_task;
#REPLACE into mes_sync.mes_square_task SELECT * from mes_origin.mes_square_task;
#REPLACE into mes_sync.mes_roll_rub_task SELECT * from mes_origin.mes_roll_rub_task;
#REPLACE into mes_sync.mes_multi_cut SELECT * from mes_origin.mes_multi_cut;
#REPLACE into mes_sync.mes_seed_crystal_machine_task SELECT * from mes_origin.mes_seed_crystal_machine_task;
#REPLACE into mes_sync.mes_seed_crystal SELECT * from mes_origin.mes_seed_crystal;
REPLACE into mes_sync.mes_recycle_material_storage SELECT * from mes_origin.mes_recycle_material_storage;
#REPLACE into mes_sync.mes_split_storage SELECT * from mes_origin.mes_split_storage;
#REPLACE into mes_sync.mes_pre_clean SELECT * from mes_origin.mes_pre_clean;
#REPLACE into mes_sync.mes_washable_silicon_qc_task SELECT * from mes_origin.mes_washable_silicon_qc_task;
#REPLACE into mes_sync.mes_recycle_material_storage_detail SELECT * from mes_origin.mes_recycle_material_storage_detail;
#REPLACE into mes_sync.mes_silicon_clean_task SELECT * from mes_origin.mes_silicon_clean_task;
#REPLACE into mes_sync.mes_silicon_clean_soak SELECT * from mes_origin.mes_silicon_clean_soak;
#REPLACE into mes_sync.mes_silicon_clean_soak_manage SELECT * from mes_origin.mes_silicon_clean_soak_manage;
#REPLACE into mes_sync.mes_silicon_clean_auto SELECT * from mes_origin.mes_silicon_clean_auto;
#REPLACE into mes_sync.mes_silicon_clean_fracture SELECT * from mes_origin.mes_silicon_clean_fracture;
#REPLACE into mes_sync.mes_magnet_choice SELECT * from mes_origin.mes_magnet_choice;
#REPLACE into mes_sync.mes_disposable_qc_task SELECT * from mes_origin.mes_disposable_qc_task;
#REPLACE into mes_sync.mes_crystal_flow SELECT * from mes_origin.mes_crystal_flow;
#REPLACE into mes_sync.mes_order_tracing SELECT * from mes_origin.mes_order_tracing;
#REPLACE into mes_sync.mes_device SELECT * from mes_origin.mes_device;
#REPLACE into mes_sync.mes_device_attribute SELECT * from mes_origin.mes_device_attribute;
#REPLACE into mes_sync.mes_turnover_container SELECT * from mes_origin.mes_turnover_container;
#REPLACE into mes_sync.mes_abnormal_feedback SELECT * from mes_origin.mes_abnormal_feedback;
#REPLACE into mes_sync.sys_package_version_manage SELECT * from mes_origin.sys_package_version_manage;
#REPLACE into mes_sync.mes_packing_detail SELECT * from mes_origin.mes_packing_detail;
#REPLACE into mes_sync.raipiot_log_error SELECT * from mes_origin.raipiot_log_error;
#REPLACE into mes_sync.mes_electrical_performance_task_log SELECT * from mes_origin.mes_electrical_performance_task_log;
#REPLACE into mes_sync.mes_work_order SELECT * from mes_origin.mes_work_order;
REPLACE into mes_sync.yz_mes_spec SELECT * from mes_origin.yz_mes_spec;
REPLACE into mes_sync.yz_mes_spec_value SELECT * from mes_origin.yz_mes_spec_value;
#REPLACE into mes_sync.raipiot_log_api SELECT * from mes_origin.raipiot_log_api;
#REPLACE into mes_sync.mes_work_order_job_detail SELECT * from mes_origin.mes_work_order_job_detail;
#REPLACE into mes_sync.mes_mother_alloy_bind SELECT * from mes_origin.mes_mother_alloy_bind;
#REPLACE into mes_sync.mes_schedule SELECT * from mes_origin.mes_schedule;
#REPLACE into mes_sync.mes_thermal_field_material SELECT * from mes_origin.mes_thermal_field_material;
#REPLACE into mes_sync.mes_work_order_job_half SELECT * from mes_origin.mes_work_order_job_half;
#REPLACE into mes_sync.mes_work_order_job SELECT * from mes_origin.mes_work_order_job;
#REPLACE into mes_sync.raipiot_log_usual SELECT * from mes_origin.raipiot_log_usual;
#REPLACE into mes_sync.sys_dict_type SELECT * from mes_origin.sys_dict_type;
#REPLACE into mes_sync.mes_dict SELECT * from mes_origin.mes_dict;
#REPLACE into mes_sync.sys_dict_data SELECT * from mes_origin.sys_dict_data;
update reportdata.prod set rodtosquare = round/square;
END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for SyncMesData_every_2_hours
-- ----------------------------
DROP PROCEDURE IF EXISTS `SyncMesData_every_2_hours`;
delimiter ;;
CREATE PROCEDURE `SyncMesData_every_2_hours`()
  COMMENT '每两小时从MES数据库归档一次数据'
BEGIN
replace into mes_sync.mes_sub_chamber_task SELECT * from mes_origin.mes_sub_chamber_task;
REPLACE into mes_sync.mes_report_task SELECT * from mes_origin.mes_report_task;
REPLACE into mes_sync.mes_crystal_order SELECT * from mes_origin.mes_crystal_order;
REPLACE into mes_sync.mes_poi_formula SELECT * from mes_origin.mes_poi_formula;
REPLACE into mes_sync.mes_feeding_task SELECT * from mes_origin.mes_feeding_task;
REPLACE into mes_sync.mes_feeding_detail SELECT * from mes_origin.mes_feeding_detail;
REPLACE into mes_sync.mes_transport_task SELECT * from mes_origin.mes_transport_task;
REPLACE into mes_sync.mes_furnace_task SELECT * from mes_origin.mes_furnace_task;
REPLACE into mes_sync.mes_furnace_detail SELECT * from mes_origin.mes_furnace_detail;
REPLACE into mes_sync.mes_stick_task SELECT * from mes_origin.mes_stick_task;
REPLACE into mes_sync.mes_production SELECT * from mes_origin.mes_production;
REPLACE into mes_sync.mes_round_bar SELECT * from mes_origin.mes_round_bar;
REPLACE into mes_sync.mes_round_bar_status SELECT * from mes_origin.mes_round_bar_status;
REPLACE into mes_sync.mes_roll_rub_quality_task SELECT * from mes_origin.mes_roll_rub_quality_task;
REPLACE into mes_sync.mes_square SELECT * from mes_origin.mes_square;
REPLACE into mes_sync.mes_lifting_box_task SELECT * from mes_origin.mes_lifting_box_task;
REPLACE into mes_sync.mes_packing_task SELECT * from mes_origin.mes_packing_task;
REPLACE into mes_sync.erp_job_mtl_confirm SELECT * from mes_origin.erp_job_mtl_confirm;
REPLACE into mes_sync.erp_job_mtl_send SELECT * from mes_origin.erp_job_mtl_send;
REPLACE into mes_sync.mes_draw_line_task SELECT * from mes_origin.mes_draw_line_task;
REPLACE into mes_sync.mes_disposable_qc_task SELECT * from mes_origin.mes_disposable_qc_task;
REPLACE into mes_sync.mes_dismantle_task SELECT * from mes_origin.mes_dismantle_task;

set global sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateAllfeedingdetail
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateAllfeedingdetail`;
delimiter ;;
CREATE PROCEDURE `UpdateAllfeedingdetail`()
  COMMENT '更新工单配料明细表'
BEGIN
DELETE from reportdata.allfeedingdetail;
replace into reportdata.allfeedingdetail(`month`,mfgdate,mesmoname,eqpid,moprodname,moproddesc,
	subprod,rx,stovetype,stovetypedesc,stovetime,prodname,proddesc,material_type,factory,serial_no,weight,
	cate1,cate2,cate3,material_level,type,area,area1,eqpmodel,feeding_task_code)
SELECT
	CONCAT('M',DATE_FORMAT(DATE_add(ft.update_time,interval -510 MINUTE),'%m')) `month`,
	DATE_FORMAT(DATE_add(ft.update_time,interval -510 MINUTE),'%Y-%m-%d') mfgdate,
	ft.order_no mesmoname,
	ft.stove_no eqpid,
	ft.product_no moprodname,
	ft.product_name moproddesc,
	case when LOCATE('自产',ft.product_name) >0 then mid(ft.product_name,LOCATE('自产',ft.product_name)+3,6)
		when LOCATE('代工',ft.product_name) >0 then mid(ft.product_name,LOCATE('代工',ft.product_name)+3,6) end subprod,
	ft.feeding_times rx,
	ft.type stovetype,
	case when ft.type = '1' then '初装'
		when ft.type = '2' then '二加' end stovetypedesc,
	ft.update_time stovetime,
	fd.material_no prodname,
	fd.material_name proddesc,
	fd.material_type,
	fd.factory,
	fd.batch_no serial_no,
	fd.weight,
	p.cate1,
	p.cate2,
	p.cate3,
	p.`level`,
	p.type,
	eq.area,
	eq.area1,
	eq.eqpmodel,
	ft.feeding_task_code
	from  mes_sync.mes_furnace_task ft
	right join mes_sync.mes_feeding_detail fd on(ft.feeding_task_id = fd.feeding_task_id and fd.material_type = '2')
	left join reportdata.product p on (fd.material_no = p.prodname)
	left join reportdata.Equipment eq on (ft.stove_no = eq.eqpid)
	where ft.`status` = '3';
END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateEqpOnStoveStatusLog
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateEqpOnStoveStatusLog`;
delimiter ;;
CREATE PROCEDURE `UpdateEqpOnStoveStatusLog`()
  COMMENT '更新开炉记录日志表'
BEGIN
DROP TABLE IF EXISTS `eqponstovestatustmp`;
create table eqponstovestatustmp
(
    area             varchar(50),
    area1            varchar(50),
    eqpid            varchar(50),
    mesmoname        varchar(50),
    eqpmodel         varchar(50),
    eqpstatus        varchar(50),
    crusize          varchar(50),
    subprod          varchar(50),
    firststovetime   datetime,
    lastreporttime   datetime,
    laststovetime    datetime,
    lastopentime     datetime,
    lastouttime      datetime,
    finishtime       datetime,
    lastchaiqingtime datetime
);
replace into eqponstovestatustmp(area, area1, eqpid, eqpmodel)
select area, area1, eqpid, eqpmodel
from reportdata.equipment;

###更新最新有执行记录的工单
update eqponstovestatustmp es
    left join
    (select eql.eqpid, substring(eql.eventid, 1, 10) mesmoname, max(eql.eventtime)
     from eqponstatuslogs eql
     left join reportdata.mostatus mo on (eql.mesmoname = mo.MESmoname)
     where mo.mostatus = '0'
     group by eql.eqpid) b on (es.eqpid = b.eqpid)
set es.mesmoname = b.mesmoname;

##1 报料，2 加料，3 开副室，4 晶棒产出，5 拆清
update eqponstovestatustmp eqs
left join
    (select mesmoname, min(eventtime) stovetime
     from eqponstatuslogs
     where eventtype = '加料'
     group by mesmoname) eql on eqs.mesmoname = eql.mesmoname
set eqs.firststovetime = eql.stovetime;

update eqponstovestatustmp eqs
    left join
    (select es.eqpid,
            epl.mesmoname,
            max(case when eventtype = '报料' then eventtime end) lastreporttime,
            max(case when eventtype = '加料' then eventtime end) laststovetime,
            max(case when eventtype = '开副室' then eventtime end) lastopentime,
            max(case when eventtype = '晶棒产出' then eventtime end) lastouttime,
            max(case when eventtype = '拆清' then eventtime end) lastchaiqingtime,
            case when substring(eventid,13,1) = 'W' then eventtime end    finishtime
     from eqponstatuslogs es
              inner join eqponstovestatustmp epl on (substring(es.eventid, 1, 10) = epl.mesmoname)
     group by es.eqpid) b on (eqs.eqpid = b.eqpid)
set eqs.lastreporttime   = b.lastreporttime,
    eqs.laststovetime    = b.laststovetime,
    eqs.lastopentime     = b.lastopentime,
    eqs.lastouttime      = b.lastouttime,
    eqs.lastchaiqingtime = b.lastchaiqingtime,
    eqs.finishtime       = b.finishtime;

###有工单、有投入、未产出
update eqponstovestatustmp
set eqpstatus = '投料后未产出'
where 1 = 1
  and laststovetime is not null
  and lastouttime is null
  and mesmoname is not null
  and laststovetime >= date_format(date_sub(now(), interval 20 day), '%Y-%m-%d');

###无工单、无投入、无产出、无报料
update eqponstovestatustmp
set eqpstatus = '完结后未报料'
where 1 = 1
  and laststovetime is null
  and lastouttime is null
  and mesmoname is null;

###循环段产出中
update eqponstovestatustmp
set eqpstatus = '循环段产出中'
where 1 = 1
  and laststovetime is not null
  and lastouttime is not null
  and mesmoname is not null
  and lastouttime >= date_format(date_sub(now(), interval 4 day), '%Y-%m-%d');

###工单异常
update eqponstovestatustmp
set eqpstatus = '工单异常'
where 1 = 1
  and lastouttime <= date_format(date_sub(now(), interval 25 day), '%Y-%m-%d');

###工单异常
update eqponstovestatustmp
set eqpstatus = '报料未投炉'
where 1 = 1
  and lastreporttime is not null
  and mesmoname is not null
  and lastouttime is null
  and laststovetime is null;

###报料异常
update eqponstovestatustmp
set eqpstatus = '报料异常'
where 1 = 1
  and lastreporttime is not null
  and laststovetime is null
  and lastreporttime <= date_format(date_sub(now(), interval 3 day), '%Y-%m-%d');

###拆清异常
update eqponstovestatustmp
set eqpstatus = '拆清异常'
where 1 = 1
  and lastouttime is not null
  and lastchaiqingtime is null
  and lastouttime <= date_format(date_sub(now(), interval 5 day), '%Y-%m-%d');


###运行异常
update eqponstovestatustmp
set eqpstatus = '拉棒时间超3天'
where 1 = 1
  and laststovetime is not null
  and laststovetime <= date_format(date_sub(now(), interval 3 day), '%Y-%m-%d');

update eqponstovestatustmp esp
inner join mes_sync.mes_crystal_order mco on (esp.mesmoname = mco.order_no)
inner join reportdata.mostatus mo on (esp.mesmoname = mo.MESmoname)
set esp.crusize = mco.thermal_field,esp.subprod = mo.subprod;

insert into eqponstovestatus(
    area,
    area1,
    eqpid,
    mesmoname,
    eqpmodel,
    eqpstatus,
    crusize,
    subprod,
    firststovetime,
    lastreporttime,
    laststovetime,
    lastopentime,
    lastouttime,
    finishtime,
    lastchaiqingtime
)
select *
from eqponstovestatustmp;


update eqponstovestatus set savedate = now() where savedate is null;
update eqponstovestatus set mfgdate = date_format(now()-8.5/24,'%Y-%m-%d') where mfgdate is null;
drop table eqponstovestatustmp;
END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateEqpStatusLogs
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateEqpStatusLogs`;
delimiter ;;
CREATE PROCEDURE `UpdateEqpStatusLogs`(in begindate datetime, in enddate datetime)
  COMMENT '更新炉台运行日志表'
BEGIN
    ##1 报料，2 加料，3 开副室，4 晶棒产出，5 拆清
    if begindate = '2000-01-01 01:00:00' then
        set begindate = dATE_FORMAT(
                date_add(DATE_SUB(dATE_FORMAT(now() - 8.5 / 24, '%Y-%m-%d'), interval 1 day), interval 510 minute),
                '%Y-%m-%d %k:%i:%s');
    end if;

    set @logmaxtdate =
            (select dATE_FORMAT(date_add(dATE_FORMAT(max(eventtime) - 8.5 / 24, '%Y-%m-%d'), interval 510 minute),
                                '%Y-%m-%d %k:%i:%s')
             from eqponstatuslogs);

    if @logmaxtdate < begindate then
        set begindate = @logmaxtdate;
    end if;

    if enddate = '2000-01-01 01:00:00' then
        set enddate = dATE_FORMAT(date_add(dATE_FORMAT(now() - 8.5 / 24, '%Y-%m-%d'), interval 510 minute),
                                  '%Y-%m-%d %k:%i:%s');
    end if;

###报料记录
    insert into eqponstatuslogs(eqpname, event, eventtime, eventid, eqpid, eventtype, rx, eventstatus,mesmoname)
    select substring(crystal_code, 5, 5) eqpname,
           case
               when report_type = '1' then '初装报料'
               when report_type = '2' then concat(substring(task_code, 13, 1), '次加料报料')
               else '' end               event,
           update_time,
           task_code,
           eq.eqpid,
           '报料',
           case
               when report_type = '1' then '0'
               when report_type = '2' then substring(task_code, 13, 1)
               else '' end               rx,
           '已完成', #状态 1:待处理、2:进行中 3:已完成 4:暂停
            substring(task_code, 1, 10)
    from mes_sync.mes_report_task mrt
             left join reportdata.equipment eq on (substring(mrt.crystal_code, 5, 5) = eq.eqpname)
    where update_time between begindate and enddate
    order by create_time desc;


###加料记录
    insert into eqponstatuslogs(eqpname, eqpid, event, eventtime, eventid, eventtype, rx, eventstatus, mesmoname)
    SELECT substring(order_no, 5, 5)                                                             eqpname,
           stove_no,
           case
               when feeding_task_code like '%CZ%' then '初装加料'
               when feeding_task_code like '%JL%' then concat(substring(feeding_task_code, 13, 1), '加次第',
                                                              right(task_code, 1), '桶加料') end event,
           ft.update_time,
           feeding_task_code,
           '加料',
           case
               when feeding_task_code like '%CZ%' then '0'
               else substring(feeding_task_code, 13, 1) end                                      rx,
           case
               when ft.status = 1 then '待处理'
               when ft.status = 2 then '进行中'
               when ft.status = 3 then '已完成'
               when ft.status = 4 then '暂停' end, #状态 1:待处理、2:进行中 3:已完成 4:暂停
           substring(feeding_task_code, 1, 10)
    from mes_sync.mes_furnace_task ft
             right join mes_sync.mes_feeding_detail fd
                        on (ft.feeding_task_id = fd.feeding_task_id and fd.material_type = '2')
    where 1 = 1
      and ft.update_time between begindate and enddate;


###开副室记录
    insert into eqponstatuslogs(eqpname, eqpid, event, eventtime, eventid, eventtype, rx, eventstatus, mesmoname)
    select substring(order_no, 5, 5)                                               eqpname,
           stove_no,
           concat(
                   case
                       when type = 0 then ''
                       when type = 1 then '正常取棒'
                       when type = 2 then '断棒'
                       when type = 3 then '余料提出' end,
                   '/开副室/', case when cold_stoking = 0 then '焖炉' else '' end) event,#物料类型 1:正常取棒  2:断棒 3:拉晶余料
           opening_time,
           code,
           '开副室',
           substring(code, 11, 1),
           '已完成',
           substring(code, 1, 10)
    from mes_sync.mes_sub_chamber_task
    where 1 = 1
      and delete_flag = '0'
      and opening_time between begindate and enddate;

###晶棒产出
    insert into eqponstatuslogs(eqpname, eqpid, event, eventtime, eventid, eventtype, rx, eventstatus, mesmoname)
    select substring(order_no, 5, 5) eqpname,
           stove_no,
           concat(right(code, 3), '晶棒产出'),
           update_time,
           code,
           '产出晶棒',
           substring(code, 11, 1),
           case
               when is_transport = 0 then '未质检'
               when is_transport = 1 then '已质检' end,
           substring(code, 1, 10)
    from mes_sync.mes_production
    where update_time between begindate and enddate;

###拆清
    insert into eqponstatuslogs(eqpname, eqpid, event, eventtime, eventid, eventtype, rx, eventstatus, mesmoname)
    select substring(order_no, 5, 5) eqpname,
           stove_no,
           '拆清',
           update_time,
           order_no,
           '拆清',
           '99',
           case
               when status = 1 then '待处理'
               when status = 2 then '进行中'
               when status = 3 then '已完成' end,
           order_no
    from mes_sync.mes_dismantle_task
    where 1 = 1
      and update_time between begindate and enddate
      and status = '3';


##更新归档时间
    update eqponstatuslogs
    set savedate = now()
    where eventtime between begindate and enddate;
end
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateMesMoDailyYield
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateMesMoDailyYield`;
delimiter ;;
CREATE PROCEDURE `UpdateMesMoDailyYield`()
  COMMENT '更新完结工单产量表'
BEGIN
###建立临时表处理数据
DROP TABLE IF EXISTS mesmodailyyieldtemp;
CREATE TABLE mesmodailyyieldtemp
(
    mesmoname          varchar(255)   not null comment 'MES工单/炉次号',
    erpmoname          varchar(255)   null comment 'ERP工单号',
    eqpid              varchar(255)   not null comment '炉台号',
    area               varchar(255)   null comment '车间',
    area1              varchar(255)   null comment '片区',
    mfgdate            datetime       null comment '归档时间-以完结出炉时间',
    finishdate         datetime       null comment '完结时间',
    moprod             varchar(255)   null comment '工单产品',
    moprodname         varchar(255)   null comment '工单产品物料编码',
    moproddesc         varchar(255)   null comment '工单物料描述',
    stovetime          datetime       null comment '初投时间',
    crusize            varchar(255)   null comment '热场尺寸',
    crucible           varchar(255)   null comment '坩埚厂商',
    cruciblesn         varchar(255)   null comment '坩埚编码',
    adjustcruciblecode varchar(255)   null comment '修正后的坩埚简称编码',
    adjustcrucible     varchar(255)   null comment '修正后的坩埚简称',
    totalstoveweight   decimal(10, 3) null comment '投炉总重',
    totaloutweight     decimal(10, 3) null comment '出炉总重',
    totallength        int            null comment '出炉长度',
    totalqclength      int            null comment '出炉检验有效长度',
    rod                decimal(10, 3) null comment '圆棒折重系数',
    totalqcweight      decimal(10, 3) null comment '总出炉有效重量-圆棒',
    totaldays          decimal(10, 3) null comment '工单运行时长',
    mostatus           varchar(5)     null comment 'MES中工单状态'
);

##拉取MES工单的清单，剔除已关闭和待排产的部分
replace into mesmodailyyieldtemp(mesmoname, eqpid, erpmoname, mostatus, moprodname, moproddesc)
select distinct order_no, stove_no, job_code, status, material_code, material_name
from mes_sync.mes_crystal_order
where 1 = 1
  and status <> '2' ##已关闭
  and status <> '0' ##待排产
order by order_no;

###更新初投日期及片区信息
update mesmodailyyieldtemp mmd
    inner join reportdata.mostatus mo on mmd.mesmoname = mo.MESmoname
    inner join reportdata.equipment eq on mmd.eqpid = eq.eqpid
set mmd.stovetime  = mo.stovetime,
    mmd.moprod     = mo.subprod,
    mmd.area       = eq.area,
    mmd.area1      = eq.area1,
    mmd.finishdate = mo.finish_time
where 1=1;

### 从投炉表中更新坩埚等信息
update mesmodailyyieldtemp mmd
    left join
    (SELECT distinct ft.order_no                                       mesmoname,
                     fd.factory                                        crucible,
                     fd.serial_no                                      cruciblesn,
                     replace(substring(material_name, 1, 3), '吋', '') crusize
     from mes_sync.mes_furnace_task ft
              right join mes_sync.mes_feeding_detail fd
                         on (ft.feeding_task_id = fd.feeding_task_id and fd.material_type = '1')) cru on (mmd.mesmoname = cru.mesmoname)
set mmd.cruciblesn = cru.cruciblesn,
    mmd.crucible   = cru.crucible,
    mmd.crusize    = cru.crusize
where 1=1;


###更新工单运行时间
update mesmodailyyieldtemp mmd
set mmd.totaldays = datediff(finishdate, stovetime)
where 1 = 1
  and mmd.finishdate is not null
  and mmd.stovetime is not null;

###更新完结计产时间
update mesmodailyyieldtemp mmd
set mmd.mfgdate = DATE_FORMAT(DATE_add(mmd.finishdate, interval -510 MINUTE), '%Y-%m-%d')
where mfgdate is null;

##处理坩埚厂商乱码
update mesmodailyyieldtemp mmd
    INNER JOIN reportdata.adjustcruc ac on (mmd.mesmoname = ac.mesmoname)
set mmd.adjustcrucible = ac.crucible
where mmd.adjustcrucible is null;
##根据坩埚
update mesmodailyyieldtemp mmd
    INNER JOIN reportdata.dict d on (mmd.adjustcrucible = d.dictkey and d.cate = 'cruccode')
set mmd.adjustcruciblecode = d.value
where 1=1;
update mesmodailyyieldtemp mmd
    INNER JOIN reportdata.dict d on (mmd.crucible = d.dictkey and d.cate = 'crucname')
set mmd.adjustcruciblecode = d.value,
    mmd.adjustcrucible     = d.value1
where 1=1;

####修正部分佑鑫坩埚
update mesmodailyyieldtemp mmd
set adjustcrucible     = '佑鑫',
    adjustcruciblecode = 'YX'
where 1 = 1
  and cruciblesn like 'D%'
  and adjustcruciblecode is null;

####修正部分硕日坩埚
update mesmodailyyieldtemp mmd
set adjustcrucible     = '硕日',
    adjustcruciblecode = 'SR'
where 1 = 1
  and cruciblesn like 'SR%'
  and adjustcruciblecode is null;

update mesmodailyyieldtemp mmd
    left join
    (SELECT ft.order_no    mesmoname,
            sum(fd.weight) stoveweight
     from mes_sync.mes_furnace_task ft
              right join mes_sync.mes_feeding_detail fd
                         on (ft.feeding_task_id = fd.feeding_task_id and fd.material_type = '2')
     group by ft.order_no) d on (mmd.mesmoname = d.mesmoname)
set mmd.totalstoveweight = d.stoveweight
where 1=1;

update mesmodailyyieldtemp mmd
    left join
    (select order_no mesmoname, sum(weight) outweight, sum(length) 'length'
     from mes_sync.mes_production
     group by order_no) t on (mmd.mesmoname = t.mesmoname)
set mmd.totallength    = t.length,
    mmd.totaloutweight = t.outweight
where 1=1;


###更新圆棒有效长度
update mesmodailyyieldtemp mmd
    INNER JOIN (select substring(production_code, 1, 10) mesmoname, sum(draw_length) qclength
                FROM mes_sync.mes_round_bar
                where right(code, 1) = '0'
                group by substring(production_code, 1, 10)) ps on (mmd.mesmoname = ps.mesmoname)
set mmd.totalqclength = ps.qclength
where mmd.totalqclength is null;


###更新折重系数
update mesmodailyyieldtemp mmd
    INNER JOIN mes_sync.yz_mes_spec yms on (mmd.moprod = yms.spec_code)
set mmd.rod = yms.hair_rod_coefficient
where mmd.rod is null;

###更新折重系数——MES中未维护的使用自己维护的补充
update mesmodailyyieldtemp mmd
    INNER JOIN reportdata.prod p on (mmd.moprod = p.code)
set mmd.rod = p.round
where mmd.rod is null;

###WFSY技术实验规格
update mesmodailyyieldtemp mmd
INNER JOIN
(
select distinct substring(moprodname, 1, 5) subprod, rod
 from mesmodailyyieldtemp
 where rod is not null
) p on (substring(mmd.moprodname,1,5) = p.subprod)
set mmd.rod = p.rod
where mmd.moprod = 'WFSY' and mmd.rod is null;

###折算圆棒有效重量
update mesmodailyyieldtemp mmd
set mmd.totalqcweight = mmd.totalqclength / mmd.rod
where totalqcweight is null;

replace into reportdata.mesmodailyyield
select *
from mesmodailyyieldtemp
order by mfgdate desc;

DROP TABLE mesmodailyyieldtemp;

END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateMostatus
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateMostatus`;
delimiter ;;
CREATE PROCEDURE `UpdateMostatus`()
BEGIN

REPLACE into reportdata.Mostatus(area1,MESmoname,ERPmoname,eqpid,prodname,proddesc,crusize,stovetime,feeding_task_id,crucible,subprod,mostatus,mostatusdesc,finish_time,runtime)
select left(ft.stove_no,1) area1,ft.order_no MESmoname,co.job_code ERPmoname,ft.stove_no eqpid,ft.product_no prodname,ft.product_name proddesc, co.thermal_field crusize,ft.update_time stovetime,ft.feeding_task_id,fd.factory crucible,
case when LOCATE('自产',product_name) >0 then mid(product_name,LOCATE('自产',product_name)+3,6)
		when LOCATE('代工',product_name) >0 then mid(product_name,LOCATE('代工',product_name)+3,6) end subprod,
co.finish_flag mostatus,
case when co.finish_flag = '1' then '完结'
	when co.finish_flag = '0' then '非完结' end mostatusdesc,
case when co.finish_flag = '1' then f.max_time end finish_time,
case when co.finish_flag = '1' then datediff(f.max_time,ft.update_time) end rutime
from mes_sync.mes_furnace_task ft
LEFT JOIN mes_sync.mes_crystal_order co on(ft.order_no = co.order_no)
LEFT JOIN mes_sync.mes_feeding_detail fd on(ft.feeding_task_id = fd.feeding_task_id and fd.material_type = '1')
left join
	(
		SELECT DISTINCT order_no,min(finish_rod) finish_rod FROM mes_sync.`mes_stick_task` GROUP BY order_no
			) st on (ft.order_no = st.order_no)
left join
	(
	SELECT DISTINCT order_no,max(create_time) max_time from mes_sync.mes_production GROUP BY order_no
	) f on(f.order_no = ft.order_no)
where 1=1
and ft.`status` = '3'	# 已正常投炉
and ft.type = '1'  #初装
and fd.material_type = '1' #material_type为'1'的是坩埚
order by ft.create_time desc;


##该炉台有新工单的，即使上一棒未完结的，也更新成完结
update reportdata.mostatus mo,(SELECT eqpid,max(stovetime) newtime from reportdata.mostatus group by eqpid) st
set mo.mostatusdesc = '完结' ,mo.mostatus = '1'
where 1=1
and mo.eqpid = st.eqpid
and mo.stovetime < st.newtime;


##异常完结的更新完结时间及运行时间
update reportdata.mostatus mo
    inner join (SELECT DISTINCT order_no, max(create_time) max_time, max(substring(code, 11, 1)) rx
               from mes_sync.mes_production
               GROUP BY order_no) f on (mo.MESmoname = f.order_no
                                            and mo.finish_time is null
                                            and mo.mostatus = '1')
set mo.finish_time = f.max_time,
    mo.mostatus = '1',
    mo.mostatusdesc = '完结',
    mo.runtime     = datediff(f.max_time, mo.stovetime);



##更新20天前未完结的
update reportdata.mostatus mo
    inner join (SELECT DISTINCT order_no, max(create_time) max_time, max(substring(code, 11, 1)) rx
               from mes_sync.mes_production
               GROUP BY order_no) f on (mo.MESmoname = f.order_no
                                            and mo.finish_time is null
                                            and mo.mostatus = '0'
                                            and mo.stovetime <date_format(date_sub(now(), interval 20 day), '%Y-%m-%d'))
set mo.finish_time = f.max_time,
    mo.mostatus = '1',
    mo.mostatusdesc = '完结',
    mo.runtime     = datediff(f.max_time, mo.stovetime);

update reportdata.mostatus mo
inner join
(
select DISTINCT mesmoname,rx from reportdata.allfeedingdetail
)af on(mo.mesmoname = af.mesmoname)
set mo.rx=af.rx ;


END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateRecyclematerialouput
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateRecyclematerialouput`;
delimiter ;;
CREATE PROCEDURE `UpdateRecyclematerialouput`()
  COMMENT '更新循环料产出表'
BEGIN
replace into reportdata.recyclematerialouput(lotsn,prodname,proddesc,prodtype,level,
	resistivity,weight,cate1,type,cate2,cate3,update_time,mfgdate,month)
SELECT order_no lotsn,
material_code prodname,
material_name proddesc,
replace(replace(product_type,'（',''),'）','') prodtype,
material_type level,
resistivity,
weight,
pd.cate1,
pd.type,
pd.cate2,
pd.cate3,
update_time,
DATE_FORMAT(DATE_add(ms.update_time,interval -510 MINUTE),'%Y-%m-%d') mfgdate,
CONCAT('M',DATE_FORMAT(DATE_add(ms.update_time,interval -510 MINUTE),'%m')) `month`
FROM mes_sync.mes_recycle_material_storage  ms
left join reportdata.product pd on (ms.material_code = pd.prodname)
and substring(material_code,6,1) = '1'
where `status` = '2';
END
;;
delimiter ;

-- ----------------------------
-- Procedure structure for UpdateSiteOnlineYield
-- ----------------------------
DROP PROCEDURE IF EXISTS `UpdateSiteOnlineYield`;
delimiter ;;
CREATE PROCEDURE `UpdateSiteOnlineYield`()
  COMMENT '更新产量表存储过称'
BEGIN
replace into reportdata.siteonlinecrucibleyield(crystalbarno,MESmoname,eqpid,actualprodname,actualproddesc,outweight,outlength,outtime)
SELECT code,order_no,stove_no,product_no,product_name,weight,length,update_time
from mes_sync.mes_production mp
order by update_time;

##更新炉台信息
UPDATE reportdata.siteonlinecrucibleyield sy
inner join reportdata.equipment eq on sy.eqpid = eq.eqpid
set sy.area = eq.area,sy.area1= eq.area1,sy.eqpmodel=eq.eqpmodel
where sy.eqpmodel is null;

##更新坩埚信息
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.mes_crystal_order co
on sy.mesmoname = co.order_no
set sy.erpmoname = co.job_code,sy.moprodname = co.material_code,sy.moproddesc = co.material_name,sy.crusize = co.thermal_field
where sy.crusize is null;

##更新工单相关信息
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.mostatus mo on (sy.mesmoname = mo.MESmoname)
set sy.crucible = mo.crucible,sy.crunum = mo.cruciblesn,sy.crudesc = mo.crucproddesc,sy.subprod = mo.subprod,sy.stovetime=mo.stovetime
where sy.crucible is null;

###更新折重系数
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.yz_mes_spec yms on(sy.subprod = yms.spec_code)
set sy.hair_rod_coefficient = yms.hair_rod_coefficient,sy.round_rod_coefficient = yms.round_rod_coefficient
where sy.hair_rod_coefficient is null or sy.round_rod_coefficient is null or sy.hair_square_rod_coefficient is null;

###更新折重系数——MES中未维护的使用自己维护的补充
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.prod p on(sy.subprod = p.code)
set sy.hair_rod_coefficient = p.round,sy.hair_square_rod_coefficient = p.square
where sy.hair_rod_coefficient is null or sy.round_rod_coefficient is null or sy.hair_square_rod_coefficient is null;

###更新有效长度
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN (
SELECT
	production_code,sum(draw_length) qclength
 FROM mes_sync.mes_round_bar
where right(code,1) = '0'
group by production_code
)ps on (sy.crystalbarno = ps.production_code)
set sy.qclength = ps.qclength
where sy.qclength is null;

##更新QC时间及计产日期
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN mes_sync.mes_draw_line_task dlt on (sy.crystalbarno = dlt.hairy_rod_crystal_code and dlt.`status` = '3')
set sy.qctime = dlt.update_time,
sy.mfgdate = DATE_FORMAT(DATE_add(dlt.update_time,interval -510 MINUTE),'%Y-%m-%d')
where sy.qctime is null;

##更新QC重量
UPDATE reportdata.siteonlinecrucibleyield set qcweight = qclength/hair_rod_coefficient where qcweight is null;
UPDATE reportdata.siteonlinecrucibleyield set squareqcweight = qclength/hair_square_rod_coefficient where squareqcweight is null;

######建临时表处理两棒工序时间########################################
DROP TEMPORARY TABLE IF EXISTS crystalbarno;
CREATE TEMPORARY TABLE crystalbarno (
id int,
idd varchar(100),
eqpid VARCHAR(100),
crystalbarno varchar(200),
outtime datetime,
lastcrystalbarno VARCHAR(200),
lastouttime datetime
);
insert into crystalbarno(id,idd,eqpid,crystalbarno,outtime)
SELECT
	ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc) id,
	CONCAT(stove_no,'-',ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc)) idd,
	stove_no,code, UPDATE_time
	from mes_sync.mes_production;
UPDATE crystalbarno cy
INNER JOIN
(
	SELECT
	ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc) -1 id,
	CONCAT(stove_no,'-',ROW_NUMBER() over(partition by stove_no order by UPDATE_time desc)-1) idd,
	stove_no,code, UPDATE_time
	from mes_sync.mes_production
) mp on (cy.idd = mp.idd)
set cy.lastouttime = mp.UPDATE_time,cy.lastcrystalbarno = mp.code;
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN crystalbarno cr on (sy.crystalbarno = cr.crystalbarno)
set sy.lastcrystalbarno = cr.lastcrystalbarno,sy.lastouttime = cr.lastouttime
where sy.lastcrystalbarno is null;
DROP TEMPORARY TABLE crystalbarno;
######删除临时表########################################


###更新运行时间
UPDATE reportdata.siteonlinecrucibleyield sy
set timeinterval = timestampdiff(second,lastouttime,outtime) / (24 * 60 * 60)
where timeinterval is null;

###更新首棒停炉时间过长的运行时间
UPDATE reportdata.siteonlinecrucibleyield sy
set timeinterval = timestampdiff(second,stovetime,outtime) / (24 * 60 * 60) + 8/24
where 1=1
and datediff(stovetime,lastouttime) >= 18/24
and crystalbarno like '%11N';

##处理坩埚厂商乱码
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.adjustcruc ac on (sy.mesmoname = ac.mesmoname)
set sy.adjustcrucible = ac.crucible
where sy.adjustcrucible is null;
##根据坩埚
UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.dict d on (sy.adjustcrucible = d.dictkey and d.cate = 'cruccode')
set sy.adjustcruciblecode = d.value;

UPDATE reportdata.siteonlinecrucibleyield sy
INNER JOIN reportdata.dict d on (sy.crucible = d.dictkey and d.cate = 'crucname')
set sy.adjustcruciblecode = d.value,sy.adjustcrucible = d.value1;

END
;;
delimiter ;

-- ----------------------------
-- Event structure for SyncMesData_every_12_hours
-- ----------------------------
DROP EVENT IF EXISTS `SyncMesData_every_12_hours`;
delimiter ;;
CREATE EVENT `SyncMesData_every_12_hours`
ON SCHEDULE
EVERY '6' HOUR STARTS '2023-08-10 08:35:00'
COMMENT '每6小时更新重要的表'
DO call reportdata.SyncMesData_every_12_hours()
;;
delimiter ;

-- ----------------------------
-- Event structure for SyncMesData_every_2_hours
-- ----------------------------
DROP EVENT IF EXISTS `SyncMesData_every_2_hours`;
delimiter ;;
CREATE EVENT `SyncMesData_every_2_hours`
ON SCHEDULE
EVERY '2' HOUR STARTS '2023-08-10 08:35:00'
COMMENT '每两小时更新重要的表'
DO call reportdata.SyncMesData_every_2_hours()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateAllfeedingdetail_4_hours
-- ----------------------------
DROP EVENT IF EXISTS `UpdateAllfeedingdetail_4_hours`;
delimiter ;;
CREATE EVENT `UpdateAllfeedingdetail_4_hours`
ON SCHEDULE
EVERY '4' HOUR STARTS '2023-07-08 08:40:00'
ON COMPLETION PRESERVE
COMMENT '归档配料明细'
DO call reportdata.UpdateAllfeedingdetail()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateEqpOnStoveStatusLog
-- ----------------------------
DROP EVENT IF EXISTS `UpdateEqpOnStoveStatusLog`;
delimiter ;;
CREATE EVENT `UpdateEqpOnStoveStatusLog`
ON SCHEDULE
EVERY '1' DAY STARTS '2023-08-10 08:45:00'
COMMENT '每天归档炉台日志'
DO call UpdateEqpOnStoveStatusLog()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateEqpStatusLog_1_day
-- ----------------------------
DROP EVENT IF EXISTS `UpdateEqpStatusLog_1_day`;
delimiter ;;
CREATE EVENT `UpdateEqpStatusLog_1_day`
ON SCHEDULE
EVERY '1' DAY STARTS '2023-08-10 08:40:00'
COMMENT '每天归档炉台日志'
DO call UpdateEqpStatusLogs('2000-01-01 01:00:00','2000-01-01 01:00:00')
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateMesMoDailyYield_2_hours
-- ----------------------------
DROP EVENT IF EXISTS `UpdateMesMoDailyYield_2_hours`;
delimiter ;;
CREATE EVENT `UpdateMesMoDailyYield_2_hours`
ON SCHEDULE
EVERY '2' HOUR STARTS '2023-07-08 08:40:00'
ON COMPLETION PRESERVE
COMMENT '归档完结工单产量明细'
DO call reportdata.UpdateMesMoDailyYield()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateMostatus_half_hours
-- ----------------------------
DROP EVENT IF EXISTS `UpdateMostatus_half_hours`;
delimiter ;;
CREATE EVENT `UpdateMostatus_half_hours`
ON SCHEDULE
EVERY '30' MINUTE STARTS '2023-08-10 08:35:00'
DO call reportdata.UpdateMostatus()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateRecyclematerialoutput_1_hours
-- ----------------------------
DROP EVENT IF EXISTS `UpdateRecyclematerialoutput_1_hours`;
delimiter ;;
CREATE EVENT `UpdateRecyclematerialoutput_1_hours`
ON SCHEDULE
EVERY '1' HOUR STARTS '2023-08-10 08:35:00'
COMMENT '更新循环料产出'
DO call reportdata.UpdateRecyclematerialouput()
;;
delimiter ;

-- ----------------------------
-- Event structure for UpdateSiteOnlineYield_1_hours
-- ----------------------------
DROP EVENT IF EXISTS `UpdateSiteOnlineYield_1_hours`;
delimiter ;;
CREATE EVENT `UpdateSiteOnlineYield_1_hours`
ON SCHEDULE
EVERY '1' HOUR STARTS '2023-08-10 08:40:00'
ON COMPLETION PRESERVE
COMMENT '更新产量'
DO call reportdata.UpdateSiteOnlineYield()
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
