作者 唐旭辉

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

1 /*.exe 1 /*.exe
2 /*.exe~ 2 /*.exe~
3 /log/*.log 3 /log/*.log
  4 +*.log
  5 +.idea
  6 +oppmg
1 -### 接口完成进度 1 +### 阶段一接口完成进度
2 2
3 | 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 | 3 | 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
4 | ---------------- | -------- | ---------- | -------------------------- | -------- | 4 | ---------------- | -------- | ---------- | -------------------------- | -------- |
5 -| 登录获取 token | 完成 | 2018/12/11 | /auth/login | post |  
6 -| 短信验证码 | 未开始 | | |  
7 -| 刷新 token | 完成 | 2018/12/11 | /v1/auth/refresh_token | get |  
8 -| 切换公司 | 完成 | 2018/12/11 | /v1/auth/change_company | post |  
9 -| 获取个人基础数据 | (暂停) | | /v1/auth/me | get |  
10 -| 获取角色列表 | 完成 | | /v1/rbac/role | get |  
11 -| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role/add | post |  
12 -| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role/edit | post |  
13 -| 删除角色 | 完成 | 2019.12.04 | /v1/rbac/role/delete | post |  
14 -| 添加角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/add | post |  
15 -| 编辑角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/edit | post |  
16 -| 删除角色组 | 完成 | 2019.12.04 | /v1/rbac/role_group/delete | post |  
17 -| 获取部门列表 | 完成 | 2019.12.5 | /v1/department | get |  
18 -| 添加部门 | 完成 | 2019.11.28 | /v1/department/add | post |  
19 -| 编辑部门 | 完成 | 2019.11.29 | /v1/department/edit | post |  
20 -| 删除部门 | 完成 | 2019.12.2 | /v1/department/delete | post |  
21 -| 获取职位列表 | 进行中 | | /v1/position | get |  
22 -| 添加职位 | 完成 | 2019.12.2 | /v1/position/add | post |  
23 -| 编辑职位 | 完成 | 2019.12.2 | /v1/position/edit | post |  
24 -| 删除职位 | 完成 | 2019.12.2 | /v1/position/delete | post |  
25 -| 添加员工 | 未开始 | | /v1/company/user | post |  
26 -| 编辑员工 | 未开始 | | /v1/company/user | post |  
27 -| 删除员工 | 未开始 | | /v1/company/user | post | 5 +|登录-登录获取 token | 待调试 | 2018/12/11 | /auth/login | post |
  6 +|登录-短信验证码 | 未开始 | | |
  7 +|登录-刷新 token | 待调试 | 2018/12/11 | /v1/auth/refresh_token | get |
  8 +|登录-切换公司 | 待调试 | 2018/12/11 | /v1/auth/change_company | post |
  9 +|获取个人基础数据 | (暂停) | | /v1/auth/me | get |
  10 +|角色-获取角色列表 | 待调试 | | /v1/rbac/role | get |
  11 +|角色-添加角色 | 待调试 | 2019.11.26 | /v1/rbac/role/add | post |
  12 +|角色-编辑角色 | 待调试 | 2019.11.26 | /v1/rbac/role/edit | post |
  13 +|角色-删除角色 | 待调试 | 2019.12.04 | /v1/rbac/role/delete | post |
  14 +|角色-添加角色组 | 待调试 | 2019.12.04 | /v1/rbac/role_group/add | post |
  15 +|角色-编辑角色组 | 待调试 | 2019.12.04 | /v1/rbac/role_group/edit | post |
  16 +|角色-删除角色组 | 待调试 | 2019.12.04 | /v1/rbac/role_group/delete | post |
  17 +|组织架构设置-获取部门列表 | 待调试 | 2019.12.5 | /v1/department | get |
  18 +|组织架构设置-添加部门 | 待调试 | 2019.11.28 | /v1/department/add | post |
  19 +|组织架构设置-编辑部门 | 待调试 | 2019.11.29 | /v1/department/edit | post |
  20 +|组织架构设置-删除部门 | 待调试 | 2019.12.2 | /v1/department/delete | post |
  21 +|职位管理-获取职位列表 | 进行中 | | /v1/position | get |
  22 +|职位管理-添加职位 | 待调试 | 2019.12.2 | /v1/position/add | post |
  23 +|职位管理-编辑职位 | 待调试 | 2019.12.2 | /v1/position/edit | post |
  24 +|职位管理-删除职位 | 待调试 | 2019.12.2 | /v1/position/delete | post |
  25 +|员工管理-添加员工 | 未开始 | | /v1/company/user | post |
  26 +|员工管理-编辑员工 | 未开始 | | /v1/company/user | post |
  27 +|员工管理-删除员工 | 未开始 | | /v1/company/user | post |
  28 +| 机会模板管理-列表 | 进行中 | | | |
  29 +| 机会模板管理-添加 | 未开始 | | | |
  30 +| 机会模板管理-更新 | 未开始 | | | |
  31 +| 机会模板管理-修改公开状态 | 未开始 | | | |
  32 +| 机会模板管理-一级模板 | 未开始 | | | |
  33 +| 配置-评分模式设置 | 未开始 | | | |
28 | 公告管理 | 未开始 | | | | 34 | 公告管理 | 未开始 | | | |
29 -| 公告管理 | 未开始 | | | |  
30 -| 公告管理 | 未开始 | | | |  
31 -| 机会&审批 模板 | 未开始 | | | |  
32 -| 机会&审批 模板 | 未开始 | | | |  
33 -| 机会&审批 模板 | 未开始 | | | |  
34 -| 机会&审批 模板 | 未开始 | | | |  
35 -| 机会类型设置 | 未开始 | | | |  
36 -| 机会类型设置 | 未开始 | | | |  
37 -| 机会类型设置 | 未开始 | | | |  
38 -| 机会类型设置 | 未开始 | | | | 35 +
@@ -17,12 +17,12 @@ mysql_host = "${MYSQL_HOST||115.29.205.99}" @@ -17,12 +17,12 @@ mysql_host = "${MYSQL_HOST||115.29.205.99}"
17 mysql_port = "${MYSQL_PORT||3306}" 17 mysql_port = "${MYSQL_PORT||3306}"
18 mysql_db_name = "${MYSQL_DB_NAME||opportunity}" 18 mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
19 ##redis相关配置 19 ##redis相关配置
20 -redis_add_port = "127.0.0.1:6379"  
21 -redis_auth = "" 20 +redis_add_port = "192.168.100.102:6379"
  21 +redis_auth = "123456"
22 ##log相关配置 22 ##log相关配置
23 ##out_put:"console","file" 23 ##out_put:"console","file"
24 log_output = "file" 24 log_output = "file"
25 -log_filename = "${aliyun_logs_access||./log/ability.log}" 25 +log_filename = "${aliyun_logs_access||ability.log}"
26 log_level = "${LOG_LEVEL||error}" 26 log_level = "${LOG_LEVEL||error}"
27 27
28 ##统一用户中心相关配置 28 ##统一用户中心相关配置
@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "oppmg/common/log" 5 "oppmg/common/log"
6 "oppmg/protocol" 6 "oppmg/protocol"
7 "oppmg/services/bulletin" 7 "oppmg/services/bulletin"
8 - "strconv"  
9 ) 8 )
10 9
11 type BulletinController struct { 10 type BulletinController struct {
@@ -13,7 +12,7 @@ type BulletinController struct { @@ -13,7 +12,7 @@ type BulletinController struct {
13 } 12 }
14 13
15 //BulletinRelease 14 //BulletinRelease
16 -//@router /release [post] 15 +//@router /add [post]
17 func (this *BulletinController) BulletinRelease() { 16 func (this *BulletinController) BulletinRelease() {
18 var msg *protocol.ResponseMessage 17 var msg *protocol.ResponseMessage
19 defer func() { 18 defer func() {
@@ -74,33 +73,28 @@ func (this *BulletinController) BulletinList() { @@ -74,33 +73,28 @@ func (this *BulletinController) BulletinList() {
74 } 73 }
75 74
76 //GetBulletin 75 //GetBulletin
  76 +//@router /get [post]
77 func (this *BulletinController) GetBulletin() { 77 func (this *BulletinController) GetBulletin() {
78 var msg *protocol.ResponseMessage 78 var msg *protocol.ResponseMessage
79 defer func() { 79 defer func() {
80 this.ResposeJson(msg) 80 this.ResposeJson(msg)
81 }() 81 }()
82 var request *protocol.GetBulletinRequest 82 var request *protocol.GetBulletinRequest
83 - //if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {  
84 - // log.Error("json 解析失败", err)  
85 - // msg = protocol.BadRequestParam("1")  
86 - // return  
87 - //}  
88 - //if b, m := this.Valid(request); !b {  
89 - // msg = m  
90 - // return  
91 - //}  
92 - param := this.Ctx.Input.Param(":id")  
93 - id, _ := strconv.ParseInt(param, 10, 64)  
94 - if id == 0 { 83 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  84 + log.Error("json 解析失败", err)
95 msg = protocol.BadRequestParam("1") 85 msg = protocol.BadRequestParam("1")
96 return 86 return
97 } 87 }
  88 + if b, m := this.Valid(request); !b {
  89 + msg = m
  90 + return
  91 + }
98 companyId := this.GetCompanyId() 92 companyId := this.GetCompanyId()
99 if companyId <= 0 { 93 if companyId <= 0 {
100 msg = protocol.BadRequestParam("1") 94 msg = protocol.BadRequestParam("1")
101 return 95 return
102 } 96 }
103 - rsp, err := bulletin.GetBulletin(int(id), companyId, request) 97 + rsp, err := bulletin.GetBulletin(request.Id, companyId, request)
104 msg = protocol.NewReturnResponse(rsp, err) 98 msg = protocol.NewReturnResponse(rsp, err)
105 } 99 }
106 100
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "oppmg/common/log"
  6 + "oppmg/protocol"
  7 + "oppmg/services/audit"
  8 +)
  9 +
  10 +type TemplateController struct {
  11 + BaseController
  12 +}
  13 +
  14 +//TemplateAdd
  15 +//@router /templateAdd [post]
  16 +func (this *TemplateController) TemplateAdd() {
  17 + var msg *protocol.ResponseMessage
  18 + defer func() {
  19 + this.ResposeJson(msg)
  20 + }()
  21 + var request *protocol.TemplateAddRequest
  22 +
  23 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  24 + log.Error("json 解析失败", err)
  25 + msg = protocol.BadRequestParam("1")
  26 + return
  27 + }
  28 + uid := this.GetUserId()
  29 + companyId := this.GetCompanyId()
  30 + if companyId <= 0 {
  31 + log.Debug("companyId:%d err", companyId)
  32 + msg = protocol.BadRequestParam("1")
  33 + return
  34 + }
  35 + //if !(request.Type == 1 || request.Type == 2) {
  36 + // msg = protocol.BadRequestParam("1")
  37 + // log.Error("type error :%v", request.Type)
  38 + // return
  39 + //}
  40 + if b, m := this.Valid(request); !b {
  41 + msg = m
  42 + return
  43 + }
  44 + rsp, err := audit.TemplateAdd(uid, companyId, request)
  45 + msg = protocol.NewReturnResponse(rsp, err)
  46 + return
  47 +}
  48 +
  49 +//TemplateUpdate
  50 +//@router /templateUpdate [post]
  51 +func (this *TemplateController) TemplateUpdate() {
  52 + var msg *protocol.ResponseMessage
  53 + defer func() {
  54 + this.ResposeJson(msg)
  55 + }()
  56 + var request *protocol.TemplateUpdateRequest
  57 +
  58 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  59 + log.Error("json 解析失败", err)
  60 + msg = protocol.BadRequestParam("1")
  61 + return
  62 + }
  63 + uid := this.GetUserId()
  64 + companyId := this.GetCompanyId()
  65 + if companyId <= 0 {
  66 + log.Debug("companyId:%d err", companyId)
  67 + msg = protocol.BadRequestParam("1")
  68 + return
  69 + }
  70 + if b, m := this.Valid(request); !b {
  71 + msg = m
  72 + return
  73 + }
  74 + rsp, err := audit.TemplateUpdate(uid, companyId, request)
  75 + msg = protocol.NewReturnResponse(rsp, err)
  76 + return
  77 +}
  78 +
  79 +//TemplateList
  80 +//@router /templateList [post]
  81 +func (this *TemplateController) TemplateList() {
  82 + var msg *protocol.ResponseMessage
  83 + defer func() {
  84 + this.ResposeJson(msg)
  85 + }()
  86 + var request *protocol.TemplateUpdateRequest
  87 +
  88 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  89 + log.Error("json 解析失败", err)
  90 + msg = protocol.BadRequestParam("1")
  91 + return
  92 + }
  93 + uid := this.GetUserId()
  94 + companyId := this.GetCompanyId()
  95 + if companyId <= 0 {
  96 + log.Debug("companyId:%d err", companyId)
  97 + msg = protocol.BadRequestParam("1")
  98 + return
  99 + }
  100 + if b, m := this.Valid(request); !b {
  101 + msg = m
  102 + return
  103 + }
  104 + rsp, err := audit.TemplateUpdate(uid, companyId, request)
  105 + msg = protocol.NewReturnResponse(rsp, err)
  106 + return
  107 +}
@@ -40,6 +40,9 @@ var AuthToken = func(ctx *context.Context) { @@ -40,6 +40,9 @@ var AuthToken = func(ctx *context.Context) {
40 accesstoken := ctx.Input.Header(protocol.HeaderAccessToken) 40 accesstoken := ctx.Input.Header(protocol.HeaderAccessToken)
41 refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken) 41 refreshToken := ctx.Input.Header(protocol.HeaderRefreshToken)
42 mtoken, err = serveauth.ValidJWTToken(accesstoken) 42 mtoken, err = serveauth.ValidJWTToken(accesstoken)
  43 + if beego.BConfig.RunMode != "prod" {
  44 + return
  45 + }
43 if err == nil { 46 if err == nil {
44 storetoken, err = redisdata.GetLoginToken(mtoken.UID) 47 storetoken, err = redisdata.GetLoginToken(mtoken.UID)
45 if err != nil { 48 if err != nil {
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type AuditForm struct {
  11 + Id int `orm:"column(id);auto" description:"唯一编号"`
  12 + CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
  13 + AuditTemplateId int `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
  14 + Section int8 `orm:"column(section)" description:"输入项所属的版块(1.基础,2.附加)"`
  15 + SortNum int `orm:"column(sort_num)" description:"排序"`
  16 + Label string `orm:"column(label);size(100)" description:"标题"`
  17 + InputType string `orm:"column(input_type);size(50)" description:"输入类型 text"`
  18 + ValueList string `orm:"column(value_list);size(255)" description:"可选值列表"`
  19 + Required int8 `orm:"column(required)" description:"是否必填:【0:否】【1:是】"`
  20 + CurrentValue string `orm:"column(current_value);size(255)" description:"实际填写的值"`
  21 + Disable int8 `orm:"column(disable);null" description:"显示隐藏:【0:显示】【1:隐藏】"`
  22 + Step string `orm:"column(step);size(30)" description:"步进,输入类型是range时生效 "`
  23 + Placeholder string `orm:"column(placeholder);size(40)" description:"输入提示"`
  24 + CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
  25 + DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"更新时间"`
  26 + EnableStatus int8 `orm:"column(enable_status);null" description:"有效状态 0:无效 1:有效 "`
  27 +}
  28 +
  29 +func (t *AuditForm) TableName() string {
  30 + return "audit_form"
  31 +}
  32 +
  33 +func init() {
  34 + orm.RegisterModel(new(AuditForm))
  35 +}
  36 +
  37 +// AddAuditForm insert a new AuditForm into database and returns
  38 +// last inserted Id on success.
  39 +func AddAuditForm(m *AuditForm) (id int64, err error) {
  40 + o := orm.NewOrm()
  41 + id, err = o.Insert(m)
  42 + return
  43 +}
  44 +
  45 +// GetAuditFormById retrieves AuditForm by Id. Returns error if
  46 +// Id doesn't exist
  47 +func GetAuditFormById(id int) (v *AuditForm, err error) {
  48 + o := orm.NewOrm()
  49 + v = &AuditForm{Id: id}
  50 + if err = o.Read(v); err == nil {
  51 + return v, nil
  52 + }
  53 + return nil, err
  54 +}
  55 +
  56 +// UpdateAuditForm updates AuditForm by Id and returns error if
  57 +// the record to be updated doesn't exist
  58 +func UpdateAuditFormById(m *AuditForm) (err error) {
  59 + o := orm.NewOrm()
  60 + v := AuditForm{Id: m.Id}
  61 + // ascertain id exists in the database
  62 + if err = o.Read(&v); err == nil {
  63 + var num int64
  64 + if num, err = o.Update(m); err == nil {
  65 + fmt.Println("Number of records updated in database:", num)
  66 + }
  67 + }
  68 + return
  69 +}
  70 +
  71 +// DeleteAuditForm deletes AuditForm by Id and returns error if
  72 +// the record to be deleted doesn't exist
  73 +func DeleteAuditForm(id int) (err error) {
  74 + o := orm.NewOrm()
  75 + v := AuditForm{Id: id}
  76 + // ascertain id exists in the database
  77 + if err = o.Read(&v); err == nil {
  78 + var num int64
  79 + if num, err = o.Delete(&AuditForm{Id: id}); err == nil {
  80 + fmt.Println("Number of records deleted in database:", num)
  81 + }
  82 + }
  83 + return
  84 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type AuditTemplate struct {
  11 + Id int64 `orm:"column(id);auto" description:"唯一编号"`
  12 + CompanyId int `orm:"column(company_id)" description:"公司id"`
  13 + ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"`
  14 + Name string `orm:"column(name);size(20)" description:"子分类名称"`
  15 + Doc string `orm:"column(doc);size(255)" description:"说明"`
  16 + Icon string `orm:"column(icon);size(255)" description:"图标"`
  17 + NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
  18 + NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
  19 + SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
  20 + VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
  21 + EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
  22 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  23 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  24 + Example string `orm:"column(examplte);null" description:"示例"`
  25 +}
  26 +
  27 +func (t *AuditTemplate) TableName() string {
  28 + return "audit_template"
  29 +}
  30 +
  31 +func init() {
  32 + orm.RegisterModel(new(AuditTemplate))
  33 +}
  34 +
  35 +// AddAuditTemplate insert a new AuditTemplate into database and returns
  36 +// last inserted Id on success.
  37 +func AddAuditTemplate(m *AuditTemplate) (id int64, err error) {
  38 + o := orm.NewOrm()
  39 + id, err = o.Insert(m)
  40 + return
  41 +}
  42 +
  43 +// GetAuditTemplateById retrieves AuditTemplate by Id. Returns error if
  44 +// Id doesn't exist
  45 +func GetAuditTemplateById(id int64) (v *AuditTemplate, err error) {
  46 + o := orm.NewOrm()
  47 + v = &AuditTemplate{Id: id}
  48 + if err = o.Read(v); err == nil {
  49 + return v, nil
  50 + }
  51 + return nil, err
  52 +}
  53 +
  54 +// UpdateAuditTemplate updates AuditTemplate by Id and returns error if
  55 +// the record to be updated doesn't exist
  56 +func UpdateAuditTemplateById(m *AuditTemplate) (err error) {
  57 + o := orm.NewOrm()
  58 + v := AuditTemplate{Id: m.Id}
  59 + // ascertain id exists in the database
  60 + if err = o.Read(&v); err == nil {
  61 + var num int64
  62 + if num, err = o.Update(m); err == nil {
  63 + fmt.Println("Number of records updated in database:", num)
  64 + }
  65 + }
  66 + return
  67 +}
  68 +
  69 +// DeleteAuditTemplate deletes AuditTemplate by Id and returns error if
  70 +// the record to be deleted doesn't exist
  71 +func DeleteAuditTemplate(id int64) (err error) {
  72 + o := orm.NewOrm()
  73 + v := AuditTemplate{Id: id}
  74 + // ascertain id exists in the database
  75 + if err = o.Read(&v); err == nil {
  76 + var num int64
  77 + if num, err = o.Delete(&AuditTemplate{Id: id}); err == nil {
  78 + fmt.Println("Number of records deleted in database:", num)
  79 + }
  80 + }
  81 + return
  82 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type ChanceType struct {
  11 + Id int `orm:"column(id);auto"`
  12 + Name string `orm:"column(name);size(50)" description:"机会类型名称"`
  13 + Icon string `orm:"column(icon);size(500);null" description:"图标地址"`
  14 + CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
  15 + SortNum int `orm:"column(sort_num);null" description:"序号 公司下的序号"`
  16 + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间 "`
  17 + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间 "`
  18 +}
  19 +
  20 +func (t *ChanceType) TableName() string {
  21 + return "chance_type"
  22 +}
  23 +
  24 +func init() {
  25 + orm.RegisterModel(new(ChanceType))
  26 +}
  27 +
  28 +// AddChanceType insert a new ChanceType into database and returns
  29 +// last inserted Id on success.
  30 +func AddChanceType(m *ChanceType) (id int64, err error) {
  31 + o := orm.NewOrm()
  32 + id, err = o.Insert(m)
  33 + return
  34 +}
  35 +
  36 +// GetChanceTypeById retrieves ChanceType by Id. Returns error if
  37 +// Id doesn't exist
  38 +func GetChanceTypeById(id int) (v *ChanceType, err error) {
  39 + o := orm.NewOrm()
  40 + v = &ChanceType{Id: id}
  41 + if err = o.Read(v); err == nil {
  42 + return v, nil
  43 + }
  44 + return nil, err
  45 +}
  46 +
  47 +// UpdateChanceType updates ChanceType by Id and returns error if
  48 +// the record to be updated doesn't exist
  49 +func UpdateChanceTypeById(m *ChanceType) (err error) {
  50 + o := orm.NewOrm()
  51 + v := ChanceType{Id: m.Id}
  52 + // ascertain id exists in the database
  53 + if err = o.Read(&v); err == nil {
  54 + var num int64
  55 + if num, err = o.Update(m); err == nil {
  56 + fmt.Println("Number of records updated in database:", num)
  57 + }
  58 + }
  59 + return
  60 +}
  61 +
  62 +// DeleteChanceType deletes ChanceType by Id and returns error if
  63 +// the record to be deleted doesn't exist
  64 +func DeleteChanceType(id int) (err error) {
  65 + o := orm.NewOrm()
  66 + v := ChanceType{Id: id}
  67 + // ascertain id exists in the database
  68 + if err = o.Read(&v); err == nil {
  69 + var num int64
  70 + if num, err = o.Delete(&ChanceType{Id: id}); err == nil {
  71 + fmt.Println("Number of records deleted in database:", num)
  72 + }
  73 + }
  74 + return
  75 +}
  76 +
  77 +func GetChanceTypeAll() (v []*ChanceType, err error) {
  78 + o := orm.NewOrm()
  79 + sql := "select * from chance_type "
  80 + if _, err = o.Raw(sql).QueryRows(&v); err == nil {
  81 + return
  82 + }
  83 + return
  84 +}
@@ -11,14 +11,17 @@ const ( @@ -11,14 +11,17 @@ const (
11 11
12 //InputElement 自定义表单项 12 //InputElement 自定义表单项
13 type InputElement struct { 13 type InputElement struct {
14 - Sort int `json:"sort"` //排序  
15 - Lable string `json:"lable"` //标题  
16 - InputType string `json:"input_type"` //输入类型  
17 - ValueList string `json:"value_list"` //输入候选值  
18 - Required bool `json:"required"` //是否必填  
19 - Placeholder string `json:"Placeholder"` //帮助用户填写输入字段的提示  
20 - Disable bool `json:"disable"` //"显示隐藏",  
21 - CurrentValue string `json:"current_value"` //"当前填写的值" 14 + Id int `json:"id"`
  15 + Sort int `json:"sort"` //排序
  16 + Lable string `json:"lable"` //标题
  17 + InputType string `json:"inputType"` //输入类型
  18 + Required int `json:"required"` //是否必填
  19 + CurrentValue string `json:"value"` //"当前填写的值"
  20 + SectionType int8 `json:"sectionType"`
  21 +
  22 + ValueList string `json:"-"` //输入候选值 value_list
  23 + Placeholder string `json:"-"` //帮助用户填写输入字段的提示 Placeholder
  24 + Disable bool `json:"-"` //"显示隐藏",
22 } 25 }
23 26
24 //自定义表单 27 //自定义表单
@@ -72,3 +75,59 @@ func (input ValidateInputRedio) ValidateInput() error { @@ -72,3 +75,59 @@ func (input ValidateInputRedio) ValidateInput() error {
72 func (input ValidateInputRedio) ValidateConfig() error { 75 func (input ValidateInputRedio) ValidateConfig() error {
73 return nil 76 return nil
74 } 77 }
  78 +
  79 +/***********审核模板管理**********/
  80 +/*TemplateAdd */
  81 +type TemplateAddRequest struct {
  82 + Template Template `json:"template"`
  83 + Example string `json:"example"` //示例
  84 +}
  85 +type TemplateAddResponse struct {
  86 +}
  87 +
  88 +type Template struct {
  89 + Id int64 `json:"id"` //创建时 0
  90 + ChanceTypeId int `json:"chanceTypeId"` //机会类型编号
  91 + Name string `json:"name"`
  92 + Doc string `json:"doc"`
  93 + Icon string `json:"icon"`
  94 + InputList []*InputElement `json:"inputList"`
  95 +}
  96 +
  97 +/*TemplateUpdate */
  98 +type TemplateUpdateRequest struct {
  99 + Template Template `json:"template"`
  100 + Example string `json:"example"` //示例`
  101 +}
  102 +type TemplateUpdateResponse struct {
  103 +}
  104 +
  105 +/*TemplateList */
  106 +type TemplateListRequest struct {
  107 +}
  108 +type TemplateListResponse struct {
  109 +}
  110 +
  111 +type ChanceType struct {
  112 + Id int `json:"id"`
  113 + Name string `json:"name"`
  114 + Icon string `json:"icon"`
  115 + Templates []*TemplateItem `json:"templates"`
  116 +}
  117 +
  118 +type TemplateItem struct {
  119 + Id int64 `json:"id"` //创建时 0
  120 + Name string `json:"name"`
  121 + Doc string `json:"doc"`
  122 + Icon string `json:"icon"`
  123 + EnableStatus int8 `json:"enableStatus"` //禁用状态
  124 + Sort int `json:"sort"` //序号
  125 + VisibleType int8 `json:"visibleType"`
  126 + VisibleObject []VisibleObject `json:"visibleObject"`
  127 +}
  128 +
  129 +type VisibleObject struct {
  130 + Id int `json:"id"`
  131 + Name string `json:"name,omitempty"`
  132 + Type int //1:部门 2:指定人员
  133 +}
@@ -45,7 +45,7 @@ type BulletinReleaseResponse struct { @@ -45,7 +45,7 @@ type BulletinReleaseResponse struct {
45 type BulletinListRequest struct { 45 type BulletinListRequest struct {
46 Status int8 `json:"status"` //1:待上架 2:上架 46 Status int8 `json:"status"` //1:待上架 2:上架
47 Page int `json:"page"` 47 Page int `json:"page"`
48 - PageSize int `json:"page_size"` 48 + PageSize int `json:"pageSize"`
49 } 49 }
50 type BulletinListResponse struct { 50 type BulletinListResponse struct {
51 List []*BulletinItem `json:"list"` 51 List []*BulletinItem `json:"list"`
@@ -63,6 +63,7 @@ type BulletinItem struct { @@ -63,6 +63,7 @@ type BulletinItem struct {
63 63
64 /*GetBulletin */ 64 /*GetBulletin */
65 type GetBulletinRequest struct { 65 type GetBulletinRequest struct {
  66 + Id int `json:"id"`
66 } 67 }
67 type GetBulletinResponse struct { 68 type GetBulletinResponse struct {
68 Id int `json:"id"` 69 Id int `json:"id"`
@@ -47,7 +47,7 @@ func init() { @@ -47,7 +47,7 @@ func init() {
47 beego.NSNamespace("/bulletin", 47 beego.NSNamespace("/bulletin",
48 beego.NSRouter("/add", &controllers.BulletinController{}, "post:BulletinRelease"), 48 beego.NSRouter("/add", &controllers.BulletinController{}, "post:BulletinRelease"),
49 beego.NSRouter("/list", &controllers.BulletinController{}, "post:BulletinList"), 49 beego.NSRouter("/list", &controllers.BulletinController{}, "post:BulletinList"),
50 - beego.NSRouter("/:id([0-9]+)", &controllers.BulletinController{}, "get:GetBulletin"), 50 + beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"),
51 beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), 51 beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"),
52 ), 52 ),
53 beego.NSNamespace("common", 53 beego.NSNamespace("common",
  1 +package audit
  2 +
  3 +import (
  4 + "database/sql"
  5 + "fmt"
  6 + orm2 "github.com/astaxie/beego/orm"
  7 + "oppmg/common/log"
  8 + "oppmg/models"
  9 + "oppmg/protocol"
  10 + "oppmg/utils"
  11 + "strings"
  12 + "time"
  13 +)
  14 +
  15 +func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) {
  16 + var (
  17 + auditForm *models.AuditForm
  18 + template *models.AuditTemplate
  19 + templateId int64
  20 + )
  21 + //判断机会类型是否存在
  22 + if _, err = models.GetChanceTypeById(request.Template.ChanceTypeId); err != nil {
  23 + log.Error("chance_type_id:%v 不存在 ,err:%v", request.Template.ChanceTypeId, err.Error())
  24 + return
  25 + }
  26 + orm := orm2.NewOrm()
  27 + //模板
  28 + {
  29 + template = &models.AuditTemplate{
  30 + CompanyId: int(companyId),
  31 + Name: request.Template.Name,
  32 + Doc: request.Template.Doc,
  33 + Icon: request.Template.Icon,
  34 + NoApprover: 1, //TODO:配置
  35 + SortNum: 0,
  36 + VisibleType: int8(0),
  37 + EnableStatus: 1,
  38 + Example: request.Example,
  39 + CreateAt: time.Now(),
  40 + UpdateAt: time.Now(),
  41 + }
  42 + if templateId, err = orm.Insert(template); err != nil {
  43 + log.Error(err.Error())
  44 + orm.Rollback()
  45 + return
  46 + }
  47 + }
  48 + //表单
  49 + {
  50 + for i := range request.Template.InputList {
  51 + input := request.Template.InputList[i]
  52 + auditForm = &models.AuditForm{
  53 + CompanyId: int(companyId),
  54 + AuditTemplateId: int(templateId),
  55 + Section: input.SectionType,
  56 + SortNum: input.Sort,
  57 + Label: input.Lable,
  58 + InputType: input.InputType,
  59 + Required: int8(input.Required),
  60 + CreateAt: time.Now(),
  61 + EnableStatus: 1,
  62 + }
  63 + if _, err = orm.Insert(auditForm); err != nil {
  64 + log.Error(err.Error())
  65 + orm.Rollback()
  66 + return
  67 + }
  68 + }
  69 + }
  70 + //审核配置
  71 +
  72 + orm.Commit()
  73 + rsp = &protocol.TemplateAddResponse{}
  74 + return
  75 +}
  76 +
  77 +func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) {
  78 + var (
  79 + template *models.AuditTemplate
  80 +
  81 + sql1 = `update audit_form set enable_status=0,delete_at=now() where audit_template_id=? and id not in(%v)`
  82 + ids []string
  83 + )
  84 + //TODO:判断是否有在进行的机会
  85 + //判断机会类型是否存在
  86 + if _, err = models.GetChanceTypeById(request.Template.ChanceTypeId); err != nil {
  87 + log.Error("chance_type_id:%v 不存在 ,err:%v", request.Template.ChanceTypeId, err.Error())
  88 + return
  89 + }
  90 + if template, err = models.GetAuditTemplateById(request.Template.Id); err != nil {
  91 + log.Error("template_id:%v 不存在 ,err:%v", request.Template.Id, err.Error())
  92 + return
  93 + }
  94 + orm := orm2.NewOrm()
  95 + //模板
  96 + {
  97 + template.Name = request.Template.Name
  98 + template.Doc = request.Template.Doc
  99 + template.Icon = request.Template.Icon
  100 + template.NoApprover = 1
  101 + template.Example = request.Example
  102 + template.UpdateAt = time.Now()
  103 + if err = models.UpdateAuditTemplateById(template); err != nil {
  104 + log.Error(err.Error())
  105 + orm.Rollback()
  106 + return
  107 + }
  108 + }
  109 + //表单
  110 + {
  111 + for i := range request.Template.InputList {
  112 + input := request.Template.InputList[i]
  113 + if input.Id == 0 {
  114 + continue
  115 + }
  116 + ids = append(ids, fmt.Sprintf("%v", input.Id))
  117 + }
  118 + if err = utils.ExecuteSQLWithOrmer(orm, fmt.Sprintf(sql1, strings.Join(ids, ",")), template.Id); err != nil {
  119 + log.Error(err.Error())
  120 + orm.Rollback()
  121 + return
  122 + }
  123 + for i := range request.Template.InputList {
  124 + input := request.Template.InputList[i]
  125 + if err = insertOrUpdateInput(orm, companyId, int(template.Id), input); err != nil {
  126 + log.Error(err.Error())
  127 + orm.Rollback()
  128 + }
  129 + }
  130 + }
  131 + //审核配置
  132 +
  133 + orm.Commit()
  134 + rsp = &protocol.TemplateUpdateResponse{}
  135 + return
  136 +}
  137 +
  138 +//更新 或 插入表单
  139 +func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input *protocol.InputElement) (err error) {
  140 + var (
  141 + auditForm *models.AuditForm
  142 + )
  143 + if input.Id == 0 {
  144 + auditForm = &models.AuditForm{
  145 + CompanyId: int(companyId),
  146 + AuditTemplateId: int(templateId),
  147 + Section: input.SectionType,
  148 + SortNum: input.Sort,
  149 + Label: input.Lable,
  150 + InputType: input.InputType,
  151 + Required: int8(input.Required),
  152 + CreateAt: time.Now(),
  153 + EnableStatus: 1,
  154 + }
  155 + if _, err = orm.Insert(auditForm); err != nil {
  156 + log.Error(err.Error())
  157 + }
  158 + return
  159 + }
  160 + if auditForm, err = models.GetAuditFormById(input.Id); err != nil {
  161 + if err == sql.ErrNoRows {
  162 + err = nil
  163 + }
  164 + return
  165 + }
  166 + {
  167 + updateMap := map[string]interface{}{
  168 + "Label": input.Lable,
  169 + "InputType": input.InputType,
  170 + "Required": int8(input.Required),
  171 + }
  172 + if err = utils.UpdateTableByMapWithOrmer(orm, auditForm, updateMap); err != nil {
  173 + return
  174 + }
  175 + }
  176 + return
  177 +}
  178 +
  179 +func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) {
  180 + var ()
  181 + rsp = &protocol.TemplateListResponse{}
  182 + return
  183 +}
1 package utils 1 package utils
2 2
3 import ( 3 import (
  4 + "errors"
4 "fmt" 5 "fmt"
5 "oppmg/common/log" 6 "oppmg/common/log"
6 "oppmg/protocol" 7 "oppmg/protocol"
  8 + "reflect"
7 "strings" 9 "strings"
8 10
9 "github.com/astaxie/beego/orm" 11 "github.com/astaxie/beego/orm"
@@ -125,3 +127,110 @@ func (q *QueryDataByPage) Query(result interface{}) (pageinfo protocol.ResponseP @@ -125,3 +127,110 @@ func (q *QueryDataByPage) Query(result interface{}) (pageinfo protocol.ResponseP
125 } 127 }
126 return protocol.ResponsePageInfo{CurrentPage: q.offset, TotalPage: total}, nil 128 return protocol.ResponsePageInfo{CurrentPage: q.offset, TotalPage: total}, nil
127 } 129 }
  130 +
  131 +// 更新指定表的几个列
  132 +func UpdateTableByMap(tabeleStruct interface{}, changeMap map[string]interface{}) error {
  133 + if reflect.TypeOf(tabeleStruct).Kind() != reflect.Ptr {
  134 + err := errors.New("UpdateTableByMap: tableStruct must ptr")
  135 + log.Error(err.Error())
  136 + return err
  137 + }
  138 + if len(changeMap) < 1 {
  139 + log.Info("changeMap is nil")
  140 + return nil
  141 + }
  142 + o := orm.NewOrm()
  143 + changeColumn := make([]string, 0, len(changeMap))
  144 + for i, v := range changeMap {
  145 + changeColumn = append(changeColumn, i)
  146 + if err := SetStructValueByType(tabeleStruct, i, v); err != nil {
  147 + log.Error("err:%v key:%v value:%v", err.Error(), i, v)
  148 + return err
  149 + }
  150 + }
  151 + num, err := o.Update(tabeleStruct, changeColumn...)
  152 + if err != nil {
  153 + log.Error(err.Error())
  154 + return err
  155 + }
  156 + log.Info(fmt.Sprintf("UpdateTableByMap: table:%s effect records:%d column:%v", GetTableName(tabeleStruct), num, changeColumn))
  157 + return nil
  158 +}
  159 +
  160 +func UpdateTableByMapWithOrmer(o orm.Ormer, tabeleStruct interface{}, changeMap map[string]interface{}) error {
  161 + if reflect.TypeOf(tabeleStruct).Kind() != reflect.Ptr {
  162 + err := errors.New("UpdateTableByMap: tableStruct must ptr")
  163 + log.Error(err.Error())
  164 + return err
  165 + }
  166 + if len(changeMap) < 1 {
  167 + log.Info("changeMap is nil")
  168 + return nil
  169 + }
  170 + changeColumn := make([]string, 0, len(changeMap))
  171 + for i, v := range changeMap {
  172 + changeColumn = append(changeColumn, i)
  173 + if err := SetStructValueByType(tabeleStruct, i, v); err != nil {
  174 + log.Error("err:%v key:%v value:%v", err.Error(), i, v)
  175 + return err
  176 + }
  177 + }
  178 + num, err := o.Update(tabeleStruct, changeColumn...)
  179 + if err != nil {
  180 + log.Error(err.Error())
  181 + return err
  182 + }
  183 + log.Info(fmt.Sprintf("UpdateTableByMap: table:%s effect records:%d column:%v", GetTableName(tabeleStruct), num, changeColumn))
  184 + return nil
  185 +}
  186 +
  187 +// 通过反射调用结构对应的TableName函数,达到返回表名的目的
  188 +func GetTableName(tableStruct interface{}) string {
  189 + m := reflect.ValueOf(tableStruct).MethodByName("TableName")
  190 + if m.IsValid() && m.Kind() == reflect.Func {
  191 + re := m.Call(nil)
  192 + for _, v := range re {
  193 + if v.IsValid() {
  194 + return v.String()
  195 + }
  196 + }
  197 + }
  198 + return "unknown"
  199 +}
  200 +
  201 +// 此函数将指定的结构体成员值更新到结构体中
  202 +func SetStructValueByType(s interface{}, columnType string, columnValue interface{}) error {
  203 + columnValueV := reflect.ValueOf(columnValue)
  204 + var setValue reflect.Value
  205 + var flag = false
  206 + v := reflect.ValueOf(s)
  207 + for i, n := 0, v.Elem().NumField(); i < n; i++ {
  208 + if v.Elem().Type().Field(i).Name == columnType {
  209 + setValue = v.Elem().Field(i)
  210 + flag = true
  211 + break
  212 + }
  213 + }
  214 + if !flag {
  215 + return errors.New("struct is not type:")
  216 + } else if !setValue.CanSet() {
  217 + return errors.New("setValue.CanSet is false")
  218 + } else if setValue.Kind() != columnValueV.Kind() {
  219 + return errors.New("struct field and value of type is error")
  220 + }
  221 + switch columnValueV.Kind() {
  222 + case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int, reflect.Int64:
  223 + setValue.SetInt(int64(columnValueV.Int()))
  224 + case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
  225 + setValue.SetUint(uint64(columnValueV.Uint()))
  226 + case reflect.Float32, reflect.Float64:
  227 + setValue.SetFloat(float64(columnValueV.Float()))
  228 + case reflect.String:
  229 + setValue.SetString(columnValueV.String())
  230 + case reflect.Struct:
  231 + setValue.Set(columnValueV)
  232 + default:
  233 + return errors.New("columnValue err for:" + columnType)
  234 + }
  235 + return nil
  236 +}
@@ -311,7 +311,7 @@ token 的响应内容 @@ -311,7 +311,7 @@ token 的响应内容
311 { 311 {
312 "code": 0, 312 "code": 0,
313 "msg": "成功", 313 "msg": "成功",
314 - "data": 314 + "data":null
315 } 315 }
316 ``` 316 ```
317 317
@@ -521,12 +521,14 @@ obj.status 状态 0-所有 1-下架 2-上架 @@ -521,12 +521,14 @@ obj.status 状态 0-所有 1-下架 2-上架
521 521
522 ### 公告详情 522 ### 公告详情
523 523
524 -- 请求路径 :/v1/bulletin/:id  
525 -- 请求方式 :get 524 +- 请求路径 :/v1/bulletin/get
  525 +- 请求方式 :post
526 - 请求 json: 526 - 请求 json:
527 527
528 ```json 528 ```json
529 -{} 529 +{
  530 + "id":5
  531 +}
530 ``` 532 ```
531 533
532 ``` 534 ```