/*
 Navicat Premium Data Transfer

 Source Server         : Mysql--A本地
 Source Server Type    : MySQL
 Source Server Version : 50731
 Source Host           : localhost:3306
 Source Schema         : mycrm

 Target Server Type    : MySQL
 Target Server Version : 50731
 File Encoding         : 65001

 Date: 15/01/2025 01:28:55
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for tb_admin
-- ----------------------------
DROP TABLE IF EXISTS `tb_admin`;
CREATE TABLE `tb_admin`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `dm` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `admin_dm`(`dm`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_cpxx
-- ----------------------------
DROP TABLE IF EXISTS `tb_cpxx`;
CREATE TABLE `tb_cpxx`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cpmc` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `bz` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `tb_cpxx_cpmc`(`cpmc`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_dqtx
-- ----------------------------
DROP TABLE IF EXISTS `tb_dqtx`;
CREATE TABLE `tb_dqtx`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `khid` int(11) NOT NULL,
  `rqs` date NOT NULL,
  `rqe` date NOT NULL,
  `je` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `photo1` mediumblob NULL,
  `photo2` mediumblob NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `tb_dqtx`(`khid`) USING BTREE,
  CONSTRAINT `fk_dqtx_khid` FOREIGN KEY (`khid`) REFERENCES `tb_kehu` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 33 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_gjfs
-- ----------------------------
DROP TABLE IF EXISTS `tb_gjfs`;
CREATE TABLE `tb_gjfs`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `gjfs` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `gjfs_fs`(`gjfs`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_gjjl
-- ----------------------------
DROP TABLE IF EXISTS `tb_gjjl`;
CREATE TABLE `tb_gjjl`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `khid` int(11) NOT NULL,
  `fsid` int(11) NOT NULL,
  `usid` int(11) NOT NULL,
  `gjnr` varchar(1000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `rq` datetime(6) NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `gjjl_only`(`khid`, `fsid`, `usid`, `gjnr`, `rq`) USING BTREE,
  INDEX `fk_usid`(`usid`) USING BTREE,
  INDEX `fk_fsid`(`fsid`) USING BTREE,
  CONSTRAINT `fk_fsid` FOREIGN KEY (`fsid`) REFERENCES `tb_gjfs` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `fk_khid` FOREIGN KEY (`khid`) REFERENCES `tb_kehu` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
  CONSTRAINT `fk_usid` FOREIGN KEY (`usid`) REFERENCES `tb_user` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 11999 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_kehu
-- ----------------------------
DROP TABLE IF EXISTS `tb_kehu`;
CREATE TABLE `tb_kehu`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '客户id',
  `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '客户姓名',
  `bz` varchar(8000) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  `pq` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '片区',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `kehu_name`(`name`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 207 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_pda
-- ----------------------------
DROP TABLE IF EXISTS `tb_pda`;
CREATE TABLE `tb_pda`  (
  `ID` int(10) NOT NULL AUTO_INCREMENT COMMENT '授权ID',
  `KHID` int(10) NOT NULL COMMENT '客户ID',
  `STATE` int(1) UNSIGNED ZEROFILL NOT NULL COMMENT '状态 1停止 0正常',
  `JZSJ` datetime NOT NULL COMMENT '截止日期',
  `EIDVERSION` int(1) NOT NULL COMMENT 'EID版本',
  `PRODUCT` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '产品 MDAQ MWMS MIPOS',
  `EID` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '密钥',
  `MEID` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '设备ID',
  `OptDate` datetime NOT NULL COMMENT '首次授权时间',
  `BZ` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
  `LastSJ` datetime NULL DEFAULT NULL COMMENT '最近在线时间',
  PRIMARY KEY (`ID`) USING BTREE,
  UNIQUE INDEX `PDA_ONLY`(`KHID`, `PRODUCT`, `MEID`) USING BTREE COMMENT '授权唯一性',
  CONSTRAINT `FK_PDA_KHID` FOREIGN KEY (`KHID`) REFERENCES `tb_kehu` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = 'PDA授权信息记录表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for tb_user
-- ----------------------------
DROP TABLE IF EXISTS `tb_user`;
CREATE TABLE `tb_user`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `dm` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `pwd` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `tybj` int(1) UNSIGNED ZEROFILL NOT NULL,
  `photo` mediumblob NULL,
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `user_dm`(`dm`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 12 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for tb_zsk
-- ----------------------------
DROP TABLE IF EXISTS `tb_zsk`;
CREATE TABLE `tb_zsk`  (
  `QuestionId` int(11) NOT NULL,
  `Subject` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  `Solution` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL,
  `Product` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `ProductModule` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `FunctionalModule` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `Creater` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
  `CreateTime` datetime NULL DEFAULT NULL,
  PRIMARY KEY (`QuestionId`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Function structure for getFirstHanZiCode
-- ----------------------------
DROP FUNCTION IF EXISTS `getFirstHanZiCode`;
delimiter ;;
CREATE FUNCTION `getFirstHanZiCode`(in_string VARCHAR(100))
 RETURNS varchar(100) CHARSET utf8
BEGIN
#定义临时字符串变量，用于接收函数中传递进来的字符串值，这里是in_string
DECLARE tmp_str VARCHAR(100) CHARSET gbk DEFAULT '' ; 
#定义临时字符串变量，用于存放函数中传递进来的字符串值的第一个字符
DECLARE tmp_char VARCHAR(2) CHARSET gbk DEFAULT '';
#tmp_str的长度
DECLARE tmp_loc SMALLINT DEFAULT 0;
#初始化，将in_string赋给tmp_str
SET tmp_str = in_string;
#获取tmp_str最左端的首个字符，注意这里是获取首个字符，该字符可能是汉字，也可能不是。
SET tmp_char = LEFT(tmp_str,1);
#获取字符的编码范围的位置，为了确认汉字拼音首字母是那一个
SET tmp_loc=INTERVAL(CONV(HEX(tmp_char),16,10),
0xB0A1,0xB0C5,0xB2C1,0xB4EE,0xB6EA,0xB7A2,0xB8C1,0xB9FE,0xBBF7,0xBFA6,0xC0AC,0xC2E8,0xC4C3,0xC5B6,0xC5BE,0xC6DA,0xC8BB,0xC8F6,0xCBFA,0xCDDA ,0xCEF4,0xD1B9,0xD4D1);
#判断左端首个字符是多字节还是单字节字符，要是多字节则认为是汉字且作以下拼音获取，要是单字节则不处理。如果是多字节字符但是不在对应的编码范围之内，即对应的不是大写字母则也不做处理，这样数字或者特殊字符就保持原样了
IF (LENGTH(tmp_char)>1 AND tmp_loc>0 AND tmp_loc<24) THEN
SELECT ELT(tmp_loc,'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P','Q','R','S','T','W','X','Y','Z') INTO tmp_char; #获得汉字拼音首字符
END IF;
RETURN tmp_char;#返回汉字拼音首字符
END
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
