database.sql 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. 
  2. CREATE DATABASE IF NOT EXISTS database
  3. DEFAULT CHARACTER SET utf8
  4. DEFAULT COLLATE utf8_general_ci;
  5. SET FOREIGN_KEY_CHECKS=0;
  6. -- ----------------------------
  7. -- Table structure for censor
  8. -- ----------------------------
  9. DROP TABLE IF EXISTS `censor`;
  10. CREATE TABLE `censor` (
  11. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  12. `name` varchar(200) DEFAULT NULL,
  13. `time` timestamp NULL DEFAULT NULL,
  14. PRIMARY KEY (`id`)
  15. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
  16. -- ----------------------------
  17. -- Records of censor
  18. -- ----------------------------
  19. INSERT INTO `censor` VALUES ('1', '河南储备物资管理局三三九处', '2019-08-29 08:18:38');
  20. -- ----------------------------
  21. -- Table structure for client
  22. -- ----------------------------
  23. DROP TABLE IF EXISTS `client`;
  24. CREATE TABLE `client` (
  25. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  26. `name` varchar(200) DEFAULT NULL,
  27. `time` timestamp NULL DEFAULT NULL,
  28. PRIMARY KEY (`id`)
  29. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
  30. -- ----------------------------
  31. -- Records of client
  32. -- ----------------------------
  33. INSERT INTO `client` VALUES ('1', '河南晨铭', '2019-08-29 08:29:27');
  34. -- ----------------------------
  35. -- Table structure for config
  36. -- ----------------------------
  37. DROP TABLE IF EXISTS `config`;
  38. CREATE TABLE `config` (
  39. `id` int(11) NOT NULL AUTO_INCREMENT,
  40. `key` varchar(50) NOT NULL,
  41. `value` varchar(100) NOT NULL,
  42. `remark` varchar(100) DEFAULT NULL,
  43. PRIMARY KEY (`id`)
  44. ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
  45. -- ----------------------------
  46. -- Records of config
  47. -- ----------------------------
  48. INSERT INTO `config` VALUES ('1', 'FeetWeight20', '2300', '20尺集装箱毛重');
  49. INSERT INTO `config` VALUES ('2', 'FeetWeight40', '3800', '40尺集装箱尺寸');
  50. INSERT INTO `config` VALUES ('3', 'DriverSetCaseNumber', '0', '驾驶员输入箱号');
  51. INSERT INTO `config` VALUES ('4', 'PaperKind', '9', '纸张大小');
  52. INSERT INTO `config` VALUES ('5', 'Orientation', '1', '纸张方向');
  53. INSERT INTO `config` VALUES ('6', 'Top', '0.6', '上边距');
  54. INSERT INTO `config` VALUES ('7', 'Left', '1.5', '下边距');
  55. INSERT INTO `config` VALUES ('8', 'Right', '1.5', '右边距');
  56. INSERT INTO `config` VALUES ('9', 'Bottom', '0.6', '下边距');
  57. -- ----------------------------
  58. -- Table structure for device
  59. -- ----------------------------
  60. DROP TABLE IF EXISTS `device`;
  61. CREATE TABLE `device` (
  62. `id` int(10) NOT NULL AUTO_INCREMENT,
  63. `ip` varchar(20) DEFAULT NULL,
  64. `name` varchar(50) DEFAULT NULL,
  65. `port` int(10) DEFAULT NULL,
  66. `time` timestamp NULL DEFAULT NULL,
  67. `code` varchar(5) DEFAULT NULL COMMENT 'IP地址最后一组',
  68. PRIMARY KEY (`id`)
  69. ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
  70. -- ----------------------------
  71. -- Records of device
  72. -- ----------------------------
  73. INSERT INTO `device` VALUES ('1', '192.168.1.10', '1号起重机', '502', '2019-08-13 15:20:33', '10');
  74. -- ----------------------------
  75. -- Table structure for driver
  76. -- ----------------------------
  77. DROP TABLE IF EXISTS `driver`;
  78. CREATE TABLE `driver` (
  79. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  80. `code` int(10) DEFAULT NULL,
  81. `name` varchar(50) DEFAULT NULL,
  82. `time` timestamp NULL DEFAULT NULL,
  83. PRIMARY KEY (`id`)
  84. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
  85. -- ----------------------------
  86. -- Records of driver
  87. -- ----------------------------
  88. INSERT INTO `driver` VALUES ('1', '1', '张三', '2019-08-22 16:20:24');
  89. INSERT INTO `driver` VALUES ('2', '2', '李四', '2019-08-22 16:20:26');
  90. -- ----------------------------
  91. -- Table structure for operator
  92. -- ----------------------------
  93. DROP TABLE IF EXISTS `operator`;
  94. CREATE TABLE `operator` (
  95. `id` smallint(5) NOT NULL AUTO_INCREMENT,
  96. `name` varchar(20) NOT NULL,
  97. `truename` varchar(20) DEFAULT NULL,
  98. `pwd` varchar(50) DEFAULT NULL,
  99. `time` timestamp NULL DEFAULT NULL,
  100. `role` smallint(1) DEFAULT '1' COMMENT ' 1 普通用户 2 管理员',
  101. PRIMARY KEY (`id`)
  102. ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
  103. -- ----------------------------
  104. -- Records of operator
  105. -- ----------------------------
  106. INSERT INTO `operator` VALUES ('1', 'admin', '管理员', '46f94c8de14fb36680850768ff1b7f2a', '2019-08-16 15:46:45', '2');
  107. -- ----------------------------
  108. -- Table structure for printset
  109. -- ----------------------------
  110. DROP TABLE IF EXISTS `printset`;
  111. CREATE TABLE `printset` (
  112. `id` int(11) NOT NULL AUTO_INCREMENT,
  113. `fieldname` varchar(20) DEFAULT NULL,
  114. `cellcoord` varchar(20) DEFAULT NULL,
  115. `displayname` varchar(20) DEFAULT NULL,
  116. `Inuse` bit(1) DEFAULT NULL,
  117. PRIMARY KEY (`id`)
  118. ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8;
  119. -- ----------------------------
  120. -- Records of printset
  121. -- ----------------------------
  122. INSERT INTO `printset` VALUES ('1', 'Number', 'B4,G4', '序号', 1);
  123. INSERT INTO `printset` VALUES ('2', 'NormType', 'B5,G5', '规格', 1);
  124. INSERT INTO `printset` VALUES ('3', 'Operator', 'D5,I5', '司磅员', 1);
  125. INSERT INTO `printset` VALUES ('4', 'CaseNumber', 'B6,G6', '箱号', 1);
  126. INSERT INTO `printset` VALUES ('5', 'Time', 'B7,G7', '日期', '1');
  127. INSERT INTO `printset` VALUES ('6', 'Censor', 'B8,G8', '检测单位', 1);
  128. INSERT INTO `printset` VALUES ('7', 'Client', 'B9,G9', '客户', 1);
  129. INSERT INTO `printset` VALUES ('8', 'GrossWeight', 'B10,G10', '毛重',1);
  130. INSERT INTO `printset` VALUES ('9', 'TareWeight', 'B11,G11', '皮重', 1);
  131. INSERT INTO `printset` VALUES ('10', 'NetWeight', 'D11,I11', '净重', 1);
  132. INSERT INTO `printset` VALUES ('11', 'State', 'A12,F12', '状态', 1);
  133. INSERT INTO `printset` VALUES ('12', 'PrintTime', 'C12,H12', '打印时间', 1);
  134. INSERT INTO `printset` VALUES ('13', 'Device', 'A3,F3', '设备名称', 1);
  135. -- ----------------------------
  136. -- Table structure for record
  137. -- ----------------------------
  138. DROP TABLE IF EXISTS `record`;
  139. CREATE TABLE `record` (
  140. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  141. `number` varchar(20) DEFAULT NULL,
  142. `time` timestamp NULL DEFAULT NULL,
  143. `casenumber` varchar(50) DEFAULT NULL,
  144. `censor` varchar(200) DEFAULT NULL,
  145. `client` varchar(200) DEFAULT NULL,
  146. `operator` varchar(50) DEFAULT NULL,
  147. `driver` varchar(50) DEFAULT NULL,
  148. `grossweight` int(10) unsigned DEFAULT NULL,
  149. `tareweight` int(10) unsigned DEFAULT NULL,
  150. `netweight` int(10) unsigned DEFAULT NULL,
  151. `normtype` varchar(10) DEFAULT NULL,
  152. `deviationX` int(10) DEFAULT NULL,
  153. `deviationY` int(10) NOT NULL,
  154. `deviationweight` int(10) DEFAULT NULL,
  155. `remark` varchar(200) DEFAULT NULL,
  156. `state` varchar(10) DEFAULT NULL,
  157. `type` smallint(1) DEFAULT NULL COMMENT '插入方式 1 自动 2手动',
  158. `lamp` smallint(1) DEFAULT '1' COMMENT '指示灯',
  159. `device` varchar(50) DEFAULT NULL COMMENT '设备名称',
  160. PRIMARY KEY (`id`)
  161. ) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8;
  162. -- ----------------------------
  163. -- Table structure for srcdat
  164. -- ----------------------------
  165. DROP TABLE IF EXISTS `srcdat`;
  166. CREATE TABLE `srcdat` (
  167. `time` timestamp NULL DEFAULT NULL,
  168. `ch0` varchar(50) DEFAULT NULL COMMENT '箱号',
  169. `ch1` smallint(5) DEFAULT NULL COMMENT '操作员',
  170. `ch2` int(10) DEFAULT NULL COMMENT '总重',
  171. `ch3` smallint(5) DEFAULT NULL COMMENT '偏心X',
  172. `ch4` smallint(5) DEFAULT NULL COMMENT '偏心Y',
  173. `ch5` smallint(5) DEFAULT NULL COMMENT '偏重',
  174. `ch6` int(10) DEFAULT NULL COMMENT '角重1',
  175. `ch7` int(10) DEFAULT NULL COMMENT '角重2',
  176. `ch8` int(11) DEFAULT NULL COMMENT '角重3',
  177. `ch9` int(10) DEFAULT NULL COMMENT '角重4',
  178. `ch10` smallint(5) DEFAULT NULL COMMENT '规格 0-20尺 1-40尺',
  179. `ch11` smallint(5) DEFAULT NULL COMMENT '0不合格 1 合格 2 无效',
  180. `ch12` smallint(5) DEFAULT NULL COMMENT '设备IP最后一组数字'
  181. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  182. DROP TRIGGER IF EXISTS `tri_insert_srcdat`;
  183. DELIMITER ;;
  184. CREATE TRIGGER `tri_insert_srcdat` AFTER INSERT ON `srcdat` FOR EACH ROW BEGIN
  185. DECLARE v_tare,v_net INT DEFAULT 0;DECLARE v_number,v_driver,v_state VARCHAR(20);DECLARE v_isopen SMALLINT;DECLARE v_device VARCHAR(50);
  186. SET v_isopen=(SELECT config.value from config where config.key='DriverSetCaseNumber');
  187. IF v_isopen=1 THEN
  188. SET v_tare= (SELECT CASE WHEN new.ch10=20 THEN (select config.value from config where config.key='FeetWeight20') ELSE (select config.value from config where config.key='FeetWeight40') END);
  189. SET v_net= new.ch2-v_tare;
  190. SET v_number=(SELECT CONCAT(DATE_FORMAT(NOW(),'%Y%m%d'),LPAD((COUNT(1)+1),5,0)) from record where time>DATE(NOW()));
  191. SET v_driver=(SELECT driver.name from driver where driver.id=new.ch1);
  192. SET v_state=(SELECT CASE WHEN new.ch11=0 THEN '不合格' WHEN new.ch11=1 THEN '合格' ELSE '无效' END);
  193. SET v_device=(SELECT device.name from device WHERE device.code=new.ch12);
  194. INSERT INTO record (number,time,casenumber,driver,grossweight,tareweight,netweight,normtype,deviationX,deviationY,deviationweight,state,type,device)VALUES(v_number,new.time,new.ch0,v_driver,new.ch2,v_tare,v_net,CONCAT(new.ch10,'英尺'),new.ch3,new.ch4,new.ch5,v_state,1,v_device);
  195. END IF;
  196. END
  197. ;;
  198. DELIMITER ;