pigeon

小记

最近做持续的自动集成工具,例如数据模型好api接口模型的自动化生产,Code提交自动检查,合并代码到打包分支自动打包等等
我们需要实时监控这些自动化的过程是否按预期完成了自己的任务,如果出现一些错误,或者需求要在完成任务之后提醒开发者。 所以我就开发了一个基于公司内部通信系统的一个小型的消息通知管理中心。 虽然之前断断续续有学写一些golang的东西,但是一直没有成型的作品,这是继上次做的个人实践项目之后,第一个在公司内部产生实际效益的服务。

主要功能

本服务的主要功能是用于 给不同的服务配置不同的消息类型和接收人。最终会根据调用通知群组id发送给不同的接受对象。 简单的实现了

  1. 组员的增删改查
  2. 群组的增删改查
  3. 消息应用的增删改查
  4. 组员和群组的关系的增删
  5. 群组和消息应用直之间的关系增删
  6. 应用版本号的tag自增接口(额外需求,与前面几个接口无关)

接口 json请求格式(application/json)

  1. /adduse               POST

    //添加用户 
    {
     "mail":"jack@meituan.com",
     "mobile":"18792289",
     "user_name":"jack"
    }

  2. /deleteuser           POST

    //删除用户 
    {
     "user_name":"jack"
    }

  3. /users             GET

    //用户列表


  4. /addgroup          POST

    //添加群组
    {
     "group_name":"商户前端",
     "type":1,
     "group_id":"merchant_mci000011",
     "app_name":"点评管家",
     "app_id":1
    }

  5. /updategroup       POST

    //更新群组信息
    {
     "group_name":"商户前端html",
     "type":1,
     "group_id":"merchant_mci000011",
     "app_name":"点评管家",
     "app_id":"28fa3c968b438fb71c8d7825af609591"
    }

  6. /addgcrow          POST

    //添加群组成员
    {
     "group_id":"merchant_mci",
     "user_name":"erfeng.cheng"
    }

  7. /deletecrow        POST

    //删除群组成员
    {
     "group_id":"merchant_mci",
     "user_name":"erfeng.cheng"
    }

  8. /grcrows           POST

    //批量关联群组成员
    {
     "group_id":"merchant",
     "users":[
     "erfeng.cheng"
     ]
    }

  9.  /grouplist        GET

    //群组列表

  10. /group/:group_id  GET

    //群组信息

  11. /addapp           POST

    //添加消息应用
    {
     "pub_id":"1372264",
     "app_key":"029507",
     "app_secret":"232alkalalalalallala",
     "app_name":"点评管家-通知"
    }

  12. /apps             GET

    //消息应用列表


  13. /sendmsg          POST

    //发送消息
    {
     "title":"test",
     "content":"1.首页\n2.微海报",
     "receivers":["erfeng.cheng"],
     "group_id":"merchant"
    }

  14. /getversiontag?app_name=merchant_model&version=7.1.0  GET      

    //获取版本号自增tag 每次调用会自增1  

SQL脚本 (不同的table之前数据未做同步,可能出现关联过的用户在用户表中已被删除的情况)

# ************************************************************
# Sequel Pro SQL dump
# Version 4096
#
# http://www.sequelpro.com/
# http://code.google.com/p/sequel-pro/
#
# Host: 10.66.3.50 (MySQL 5.7.20)
# Database: pigeon
# Generation Time: 2017-12-13 13:28:43 +0000
# ************************************************************


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


# Dump of table p_app_info
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_app_info`;

CREATE TABLE `p_app_info` (
  `uid` int(3) unsigned NOT NULL AUTO_INCREMENT,
  `pub_id` varchar(12) NOT NULL DEFAULT '',
  `app_key` varchar(16) NOT NULL DEFAULT '',
  `app_secret` varchar(32) NOT NULL DEFAULT '',
  `app_name` varchar(20) NOT NULL DEFAULT '',
  `app_id` varchar(32) NOT NULL DEFAULT '',
  PRIMARY KEY (`uid`),
  UNIQUE KEY `pub_id` (`pub_id`),
  UNIQUE KEY `app_key` (`app_key`),
  UNIQUE KEY `app_secret` (`app_secret`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `p_app_info` WRITE;
/*!40000 ALTER TABLE `p_app_info` DISABLE KEYS */;

INSERT INTO `p_app_info` (`uid`, `pub_id`, `app_key`, `app_secret`, `app_name`, `app_id`)
VALUES
    (5,'137441864','02210uU17507','b13fdda68c0034eefea16cb1','点评管家-通知','28fa3c968c8d7825af609591');

/*!40000 ALTER TABLE `p_app_info` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table p_bussiness
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_bussiness`;

CREATE TABLE `p_bussiness` (
  `bid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `bis_type` int(2) NOT NULL,
  `group_id` int(11) NOT NULL,
  `bis_name` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`bid`),
  UNIQUE KEY `bis_type` (`bis_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



# Dump of table p_group
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_group`;

CREATE TABLE `p_group` (
  `gid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `group_id` varchar(30) NOT NULL DEFAULT '',
  `group_name` varchar(20) NOT NULL DEFAULT '',
  `type` int(2) NOT NULL DEFAULT '0',
  `app_id` varchar(32) NOT NULL DEFAULT '',
  `app_name` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`gid`),
  UNIQUE KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `p_group` WRITE;
/*!40000 ALTER TABLE `p_group` DISABLE KEYS */;

INSERT INTO `p_group` (`gid`, `group_id`, `group_name`, `type`, `app_id`, `app_name`)
VALUES
    (23,'merchant','点评管家-通知',0,'28fa3c968b438af609591','点评管家-通知');

/*!40000 ALTER TABLE `p_group` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table p_group_user_relation
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_group_user_relation`;

CREATE TABLE `p_group_user_relation` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `group_id` varchar(30) NOT NULL DEFAULT '',
  `user_name` varchar(18) NOT NULL DEFAULT '',
  `unique_key` varchar(40) NOT NULL DEFAULT '',
  `group_name` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `unique_key` (`unique_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `p_group_user_relation` WRITE;
/*!40000 ALTER TABLE `p_group_user_relation` DISABLE KEYS */;

INSERT INTO `p_group_user_relation` (`id`, `group_id`, `user_name`, `unique_key`, `group_name`)
VALUES
    (76,'merchant','Jack','Jackmerchant','点评管家');

/*!40000 ALTER TABLE `p_group_user_relation` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table p_message
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_message`;

CREATE TABLE `p_message` (
  `mid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `group_id` int(11) NOT NULL,
  `m_type` int(1) NOT NULL,
  `text` varchar(500) NOT NULL DEFAULT '',
  `body` varchar(500) DEFAULT '',
  `status` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`mid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;



# Dump of table p_user
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_user`;

CREATE TABLE `p_user` (
  `uid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_name` varchar(18) NOT NULL DEFAULT '',
  `mail` varchar(50) DEFAULT '',
  `mobile` varchar(13) DEFAULT '',
  PRIMARY KEY (`uid`),
  UNIQUE KEY `username` (`user_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `p_user` WRITE;
/*!40000 ALTER TABLE `p_user` DISABLE KEYS */;

INSERT INTO `p_user` (`uid`, `user_name`, `mail`, `mobile`)
VALUES
    (1,'Jack','Jack@mail.com','13223232223');

/*!40000 ALTER TABLE `p_user` ENABLE KEYS */;
UNLOCK TABLES;


# Dump of table p_version_tag
# ------------------------------------------------------------

DROP TABLE IF EXISTS `p_version_tag`;

CREATE TABLE `p_version_tag` (
  `uid` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `tag` int(4) NOT NULL DEFAULT '1',
  `version` varchar(10) NOT NULL DEFAULT '',
  `app_name` varchar(32) NOT NULL DEFAULT '',
  `unique_key` varchar(32) NOT NULL DEFAULT '',
  PRIMARY KEY (`uid`),
  UNIQUE KEY `unique_key` (`unique_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

LOCK TABLES `p_version_tag` WRITE;
/*!40000 ALTER TABLE `p_version_tag` DISABLE KEYS */;

INSERT INTO `p_version_tag` (`uid`, `tag`, `version`, `app_name`, `unique_key`)
VALUES
    (9,38,'7.1.0','MTAStaticModels','19b92d56eaa94a58f48e6f58a1498d12');

/*!40000 ALTER TABLE `p_version_tag` ENABLE KEYS */;
UNLOCK TABLES;



/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
源码地址在我的github上,适合初学者

源码地址