作者 yangfu

发布机会

@@ -29,9 +29,10 @@ @@ -29,9 +29,10 @@
29 |我审核的机会| | | v1/chance/chances| 29 |我审核的机会| | | v1/chance/chances|
30 |机会详情| | | v1/chance/detail| 30 |机会详情| | | v1/chance/detail|
31 |待抓住机会列表| | |v1/chance/chances| 31 |待抓住机会列表| | |v1/chance/chances|
32 -|提交机会| | |v1/chance/submit|  
33 -|部门列表-全部| | |v1/department/departments|  
34 -|部门列表-用户| | |v1/department/userDepartments| 32 +|机会类型|进行中| |v1/chance/chanceType|
  33 +|模板列表|进行中| |v1/chance/templates|
  34 +|提交机会|进行中| |v1/chance/submit|
  35 +|部门列表|完成|2019.12.3|v1/department/departments|
35 |配置-机会类型| | |v1/config/chanceType| 36 |配置-机会类型| | |v1/config/chanceType|
36 |配置-评分| | |v1/config/score| 37 |配置-评分| | |v1/config/score|
37 |机会审核| | |v1/chance/audit| 38 |机会审核| | |v1/chance/audit|
@@ -139,28 +139,90 @@ func (this *ChanceController) CommentDetailsMulti() { @@ -139,28 +139,90 @@ func (this *ChanceController) CommentDetailsMulti() {
139 msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request)) 139 msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request))
140 } 140 }
141 141
142 -  
143 //SympathyAction 142 //SympathyAction
144 //@router /sympathyAction [post] 143 //@router /sympathyAction [post]
145 -func(this *ChanceController)SympathyAction(){ 144 +func (this *ChanceController) SympathyAction() {
146 var msg *protocol.ResponseMessage 145 var msg *protocol.ResponseMessage
147 defer func() { 146 defer func() {
148 this.Resp(msg) 147 this.Resp(msg)
149 }() 148 }()
150 var request *protocol.SympathyActionRequest 149 var request *protocol.SympathyActionRequest
151 - if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{ 150 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
152 log.Error(err) 151 log.Error(err)
153 msg = protocol.BadRequestParam(1) 152 msg = protocol.BadRequestParam(1)
154 return 153 return
155 } 154 }
156 - if b,m :=this.Valid(request);!b{ 155 + if b, m := this.Valid(request); !b {
157 msg = m 156 msg = m
158 return 157 return
159 } 158 }
160 - if !(request.SourceType==protocol.SourceType_Chance || request.SourceType==protocol.SourceType_Comment){ 159 + if !(request.SourceType == protocol.SourceType_Chance || request.SourceType == protocol.SourceType_Comment) {
161 msg = protocol.BadRequestParam(2) 160 msg = protocol.BadRequestParam(2)
162 return 161 return
163 } 162 }
164 header := controllers.GetRequestHeader(this.Ctx) 163 header := controllers.GetRequestHeader(this.Ctx)
165 - msg = protocol.NewReturnResponse(chance.SympathyAction(header,request)) 164 + msg = protocol.NewReturnResponse(chance.SympathyAction(header, request))
  165 +}
  166 +
  167 +//ChanceType
  168 +//@router /chanceType [post]
  169 +func (this *ChanceController) ChanceType() {
  170 + var msg *protocol.ResponseMessage
  171 + defer func() {
  172 + this.Resp(msg)
  173 + }()
  174 + var request *protocol.ChanceTypeRequest
  175 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  176 + log.Error(err)
  177 + msg = protocol.BadRequestParam(1)
  178 + return
  179 + }
  180 + if b, m := this.Valid(request); !b {
  181 + msg = m
  182 + return
  183 + }
  184 + header := controllers.GetRequestHeader(this.Ctx)
  185 + msg = protocol.NewReturnResponse(chance.ChanceType(header, request))
  186 +}
  187 +
  188 +//Templates
  189 +//@router /templates [post]
  190 +func (this *ChanceController) Templates() {
  191 + var msg *protocol.ResponseMessage
  192 + defer func() {
  193 + this.Resp(msg)
  194 + }()
  195 + var request *protocol.TemplatesRequest
  196 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  197 + log.Error(err)
  198 + msg = protocol.BadRequestParam(1)
  199 + return
  200 + }
  201 + if b, m := this.Valid(request); !b {
  202 + msg = m
  203 + return
  204 + }
  205 + header := controllers.GetRequestHeader(this.Ctx)
  206 + msg = protocol.NewReturnResponse(chance.Templates(header, request))
  207 +}
  208 +
  209 +//ChanceSubmit
  210 +//@router /chanceSubmit [post]
  211 +func (this *ChanceController) ChanceSubmit() {
  212 + var msg *protocol.ResponseMessage
  213 + defer func() {
  214 + this.Resp(msg)
  215 + }()
  216 + var request *protocol.ChanceSubmitRequest
  217 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  218 + log.Error(err)
  219 + msg = protocol.BadRequestParam(1)
  220 + return
  221 + }
  222 + if b, m := this.Valid(request); !b {
  223 + msg = m
  224 + return
  225 + }
  226 + header := controllers.GetRequestHeader(this.Ctx)
  227 + msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
166 } 228 }
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type AuditFlowConfig struct {
  11 + Id int `orm:"column(id);pk" description:"唯一编号"`
  12 + AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
  13 + AuditGroupId int64 `orm:"column(audit_group_id)" description:"审核组id (同一个审批批次)"`
  14 + Level int `orm:"column(level)" description:"审批层级顺序,审批步骤 第几步"`
  15 + AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色 4.特殊审核人 "`
  16 + FromSpecialUser string `orm:"column(from_special_user)" description:"特殊指定的审批单发起人"`
  17 + ToRole string `orm:"column(to_role);null" description:"指定角色"`
  18 + ToUser string `orm:"column(to_user);null" description:"指定人"`
  19 + FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"`
  20 + ActionType uint `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"`
  21 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  22 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  23 +}
  24 +
  25 +func (t *AuditFlowConfig) TableName() string {
  26 + return "audit_flow_config"
  27 +}
  28 +
  29 +func init() {
  30 + orm.RegisterModel(new(AuditFlowConfig))
  31 +}
  32 +
  33 +// AddAuditFlowConfig insert a new AuditFlowConfig into database and returns
  34 +// last inserted Id on success.
  35 +func AddAuditFlowConfig(m *AuditFlowConfig) (id int64, err error) {
  36 + o := orm.NewOrm()
  37 + id, err = o.Insert(m)
  38 + return
  39 +}
  40 +
  41 +// GetAuditFlowConfigById retrieves AuditFlowConfig by Id. Returns error if
  42 +// Id doesn't exist
  43 +func GetAuditFlowConfigById(id int) (v *AuditFlowConfig, err error) {
  44 + o := orm.NewOrm()
  45 + v = &AuditFlowConfig{Id: id}
  46 + if err = o.Read(v); err == nil {
  47 + return v, nil
  48 + }
  49 + return nil, err
  50 +}
  51 +
  52 +// UpdateAuditFlowConfig updates AuditFlowConfig by Id and returns error if
  53 +// the record to be updated doesn't exist
  54 +func UpdateAuditFlowConfigById(m *AuditFlowConfig) (err error) {
  55 + o := orm.NewOrm()
  56 + v := AuditFlowConfig{Id: m.Id}
  57 + // ascertain id exists in the database
  58 + if err = o.Read(&v); err == nil {
  59 + var num int64
  60 + if num, err = o.Update(m); err == nil {
  61 + fmt.Println("Number of records updated in database:", num)
  62 + }
  63 + }
  64 + return
  65 +}
  66 +
  67 +// DeleteAuditFlowConfig deletes AuditFlowConfig by Id and returns error if
  68 +// the record to be deleted doesn't exist
  69 +func DeleteAuditFlowConfig(id int) (err error) {
  70 + o := orm.NewOrm()
  71 + v := AuditFlowConfig{Id: id}
  72 + // ascertain id exists in the database
  73 + if err = o.Read(&v); err == nil {
  74 + var num int64
  75 + if num, err = o.Delete(&AuditFlowConfig{Id: id}); err == nil {
  76 + fmt.Println("Number of records deleted in database:", num)
  77 + }
  78 + }
  79 + return
  80 +}
  81 +
  82 +func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) {
  83 + o := orm.NewOrm()
  84 + sql := "select * from audit_flow_config where audit_template_id=? and audit_group_id=? order by level"
  85 + if _, err = o.Raw(sql, auditTemplateId, groupId).QueryRows(&v); err == nil {
  86 + return
  87 + }
  88 + return
  89 +}
  90 +
  91 +func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) {
  92 + o := orm.NewOrm()
  93 + sql := "select * from audit_flow_config where audit_template_id=? and level=?"
  94 + if _, err = o.Raw(sql, auditTemplateId, level).QueryRows(&v); err == nil {
  95 + return
  96 + }
  97 + return
  98 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type AuditFlowProcess struct {
  11 + Id int64 `orm:"column(id);pk" description:"唯一标识"`
  12 + ChanceId int64 `orm:"column(chance_id)" description:"实例id,关联chance表id"`
  13 + Uid int64 `orm:"column(uid)" description:"用户id(审批人)"`
  14 + Level int `orm:"column(level)" description:"审批步骤"`
  15 + IsActive int8 `orm:"column(is_active)" description:"是否激活"`
  16 + ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
  17 + BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
  18 + ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
  19 + ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
  20 + ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:审核中 1:被退回 2:已通过 3.自动通过 "`
  21 + AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色 4.特殊审核人"`
  22 + FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"`
  23 + ActionType int `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"`
  24 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  25 + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
  26 + EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 (被驳回以后,未完成的审核置为无效)"`
  27 +}
  28 +
  29 +func (t *AuditFlowProcess) TableName() string {
  30 + return "audit_flow_process"
  31 +}
  32 +
  33 +func init() {
  34 + orm.RegisterModel(new(AuditFlowProcess))
  35 +}
  36 +
  37 +// AddAuditFlowProcess insert a new AuditFlowProcess into database and returns
  38 +// last inserted Id on success.
  39 +func AddAuditFlowProcess(m *AuditFlowProcess) (id int64, err error) {
  40 + o := orm.NewOrm()
  41 + id, err = o.Insert(m)
  42 + return
  43 +}
  44 +
  45 +// GetAuditFlowProcessById retrieves AuditFlowProcess by Id. Returns error if
  46 +// Id doesn't exist
  47 +func GetAuditFlowProcessById(id int64) (v *AuditFlowProcess, err error) {
  48 + o := orm.NewOrm()
  49 + v = &AuditFlowProcess{Id: id}
  50 + if err = o.Read(v); err == nil {
  51 + return v, nil
  52 + }
  53 + return nil, err
  54 +}
  55 +
  56 +// UpdateAuditFlowProcess updates AuditFlowProcess by Id and returns error if
  57 +// the record to be updated doesn't exist
  58 +func UpdateAuditFlowProcessById(m *AuditFlowProcess) (err error) {
  59 + o := orm.NewOrm()
  60 + v := AuditFlowProcess{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 +// DeleteAuditFlowProcess deletes AuditFlowProcess by Id and returns error if
  72 +// the record to be deleted doesn't exist
  73 +func DeleteAuditFlowProcess(id int64) (err error) {
  74 + o := orm.NewOrm()
  75 + v := AuditFlowProcess{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(&AuditFlowProcess{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 AuditForm struct {
  11 + Id int `orm:"column(id);pk" 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:"输入类型"`
  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 +}
  85 +
  86 +func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) {
  87 + o := orm.NewOrm()
  88 + sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1
  89 +order by section,sort_num
  90 +`
  91 + if _, err = o.Raw(sql, companyId, auditTemplateId).QueryRows(&v); err == nil {
  92 + return
  93 + }
  94 + return
  95 +}
  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);pk" description:"唯一编号"`
  12 + CompanyId int `orm:"column(company_id)" description:"公司id"`
  13 + ChanceType int `orm:"column(chance_type)" description:"机会类型"`
  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 +}
  25 +
  26 +func (t *AuditTemplate) TableName() string {
  27 + return "audit_template"
  28 +}
  29 +
  30 +func init() {
  31 + orm.RegisterModel(new(AuditTemplate))
  32 +}
  33 +
  34 +// AddAuditTemplate insert a new AuditTemplate into database and returns
  35 +// last inserted Id on success.
  36 +func AddAuditTemplate(m *AuditTemplate) (id int64, err error) {
  37 + o := orm.NewOrm()
  38 + id, err = o.Insert(m)
  39 + return
  40 +}
  41 +
  42 +// GetAuditTemplateById retrieves AuditTemplate by Id. Returns error if
  43 +// Id doesn't exist
  44 +func GetAuditTemplateById(id int64) (v *AuditTemplate, err error) {
  45 + o := orm.NewOrm()
  46 + v = &AuditTemplate{Id: id}
  47 + if err = o.Read(v); err == nil {
  48 + return v, nil
  49 + }
  50 + return nil, err
  51 +}
  52 +
  53 +// UpdateAuditTemplate updates AuditTemplate by Id and returns error if
  54 +// the record to be updated doesn't exist
  55 +func UpdateAuditTemplateById(m *AuditTemplate) (err error) {
  56 + o := orm.NewOrm()
  57 + v := AuditTemplate{Id: m.Id}
  58 + // ascertain id exists in the database
  59 + if err = o.Read(&v); err == nil {
  60 + var num int64
  61 + if num, err = o.Update(m); err == nil {
  62 + fmt.Println("Number of records updated in database:", num)
  63 + }
  64 + }
  65 + return
  66 +}
  67 +
  68 +// DeleteAuditTemplate deletes AuditTemplate by Id and returns error if
  69 +// the record to be deleted doesn't exist
  70 +func DeleteAuditTemplate(id int64) (err error) {
  71 + o := orm.NewOrm()
  72 + v := AuditTemplate{Id: id}
  73 + // ascertain id exists in the database
  74 + if err = o.Read(&v); err == nil {
  75 + var num int64
  76 + if num, err = o.Delete(&AuditTemplate{Id: id}); err == nil {
  77 + fmt.Println("Number of records deleted in database:", num)
  78 + }
  79 + }
  80 + return
  81 +}
  82 +
  83 +func GetAuditTemplates(companyId int64, chanceType int) (v []*AuditTemplate, err error) {
  84 + o := orm.NewOrm()
  85 + sql := "select * from audit_template where company_id=? and chance_type=? and enable_status=1"
  86 + if _, err = o.Raw(sql, companyId, chanceType).QueryRows(&v); err == nil {
  87 + return
  88 + }
  89 + return
  90 +}
@@ -13,16 +13,26 @@ import ( @@ -13,16 +13,26 @@ import (
13 type Chance struct { 13 type Chance struct {
14 Id int64 `orm:"column(id);pk" description:"id 主键"` 14 Id int64 `orm:"column(id);pk" description:"id 主键"`
15 UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"` 15 UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"`
  16 + CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"`
16 DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"` 17 DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"`
17 - ChanceType int `orm:"column(chance_type)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "`  
18 - Content string `orm:"column(content)" description:"内容"`  
19 - ViewTotal int `orm:"column(view_total)" description:"浏览总数"` 18 + ChanceType int `orm:"column(chance_type)" description:"表chance_type.id 机会类型 "`
  19 + AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
  20 + AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"`
  21 + Content string `orm:"column(content)" description:"格式化后的文本内容"`
  22 + SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"`
  23 + ViewTotal int `orm:"column(view_total)" description:"查看总数"`
20 CommentTotal int `orm:"column(comment_total)" description:"评论总数"` 24 CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
21 ZanTotal int `orm:"column(zan_total)" description:"点赞总数"` 25 ZanTotal int `orm:"column(zan_total)" description:"点赞总数"`
22 - ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"` 26 + ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待处理 1:待审核 2:被退回 3:已通过 "`
23 EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "` 27 EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "`
24 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` 28 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
25 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` 29 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  30 + BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
  31 + ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
  32 + ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
  33 + DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
  34 + PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
  35 + AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
26 } 36 }
27 37
28 func (t *Chance) TableName() string { 38 func (t *Chance) TableName() string {
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type ChanceImage struct {
  11 + Id int64 `orm:"column(id);auto" description:"唯一编号"`
  12 + ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
  13 + Path string `orm:"column(path);size(500)" description:"路径"`
  14 + W int `orm:"column(w);null" description:"宽"`
  15 + H int `orm:"column(h);null" description:"高"`
  16 + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
  17 +}
  18 +
  19 +func (t *ChanceImage) TableName() string {
  20 + return "chance_image"
  21 +}
  22 +
  23 +func init() {
  24 + orm.RegisterModel(new(ChanceImage))
  25 +}
  26 +
  27 +// AddChanceImage insert a new ChanceImage into database and returns
  28 +// last inserted Id on success.
  29 +func AddChanceImage(m *ChanceImage) (id int64, err error) {
  30 + o := orm.NewOrm()
  31 + id, err = o.Insert(m)
  32 + return
  33 +}
  34 +
  35 +// GetChanceImageById retrieves ChanceImage by Id. Returns error if
  36 +// Id doesn't exist
  37 +func GetChanceImageById(id int64) (v *ChanceImage, err error) {
  38 + o := orm.NewOrm()
  39 + v = &ChanceImage{Id: id}
  40 + if err = o.Read(v); err == nil {
  41 + return v, nil
  42 + }
  43 + return nil, err
  44 +}
  45 +
  46 +// UpdateChanceImage updates ChanceImage by Id and returns error if
  47 +// the record to be updated doesn't exist
  48 +func UpdateChanceImageById(m *ChanceImage) (err error) {
  49 + o := orm.NewOrm()
  50 + v := ChanceImage{Id: m.Id}
  51 + // ascertain id exists in the database
  52 + if err = o.Read(&v); err == nil {
  53 + var num int64
  54 + if num, err = o.Update(m); err == nil {
  55 + fmt.Println("Number of records updated in database:", num)
  56 + }
  57 + }
  58 + return
  59 +}
  60 +
  61 +// DeleteChanceImage deletes ChanceImage by Id and returns error if
  62 +// the record to be deleted doesn't exist
  63 +func DeleteChanceImage(id int64) (err error) {
  64 + o := orm.NewOrm()
  65 + v := ChanceImage{Id: id}
  66 + // ascertain id exists in the database
  67 + if err = o.Read(&v); err == nil {
  68 + var num int64
  69 + if num, err = o.Delete(&ChanceImage{Id: id}); err == nil {
  70 + fmt.Println("Number of records deleted in database:", num)
  71 + }
  72 + }
  73 + return
  74 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type ChanceSpeech struct {
  11 + Id int64 `orm:"column(id);pk" description:"唯一编号"`
  12 + Duration int `orm:"column(duration);null" description:"秒数"`
  13 + ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
  14 + Path string `orm:"column(path);size(500);null" description:"语音路径"`
  15 + CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
  16 +}
  17 +
  18 +func (t *ChanceSpeech) TableName() string {
  19 + return "chance_speech"
  20 +}
  21 +
  22 +func init() {
  23 + orm.RegisterModel(new(ChanceSpeech))
  24 +}
  25 +
  26 +// AddChanceSpeech insert a new ChanceSpeech into database and returns
  27 +// last inserted Id on success.
  28 +func AddChanceSpeech(m *ChanceSpeech) (id int64, err error) {
  29 + o := orm.NewOrm()
  30 + id, err = o.Insert(m)
  31 + return
  32 +}
  33 +
  34 +// GetChanceSpeechById retrieves ChanceSpeech by Id. Returns error if
  35 +// Id doesn't exist
  36 +func GetChanceSpeechById(id int64) (v *ChanceSpeech, err error) {
  37 + o := orm.NewOrm()
  38 + v = &ChanceSpeech{Id: id}
  39 + if err = o.Read(v); err == nil {
  40 + return v, nil
  41 + }
  42 + return nil, err
  43 +}
  44 +
  45 +// UpdateChanceSpeech updates ChanceSpeech by Id and returns error if
  46 +// the record to be updated doesn't exist
  47 +func UpdateChanceSpeechById(m *ChanceSpeech) (err error) {
  48 + o := orm.NewOrm()
  49 + v := ChanceSpeech{Id: m.Id}
  50 + // ascertain id exists in the database
  51 + if err = o.Read(&v); err == nil {
  52 + var num int64
  53 + if num, err = o.Update(m); err == nil {
  54 + fmt.Println("Number of records updated in database:", num)
  55 + }
  56 + }
  57 + return
  58 +}
  59 +
  60 +// DeleteChanceSpeech deletes ChanceSpeech by Id and returns error if
  61 +// the record to be deleted doesn't exist
  62 +func DeleteChanceSpeech(id int64) (err error) {
  63 + o := orm.NewOrm()
  64 + v := ChanceSpeech{Id: id}
  65 + // ascertain id exists in the database
  66 + if err = o.Read(&v); err == nil {
  67 + var num int64
  68 + if num, err = o.Delete(&ChanceSpeech{Id: id}); err == nil {
  69 + fmt.Println("Number of records deleted in database:", num)
  70 + }
  71 + }
  72 + return
  73 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/orm"
  6 +)
  7 +
  8 +type ChanceType struct {
  9 + Id int `orm:"column(id);auto" json:"id"`
  10 + Name string `orm:"column(name);size(50)" description:"机会类型名称" json:"name"`
  11 + Icon string `orm:"column(icon);size(500);null" description:"图标地址" json:"icon"`
  12 +}
  13 +
  14 +func (t *ChanceType) TableName() string {
  15 + return "chance_type"
  16 +}
  17 +
  18 +func init() {
  19 + orm.RegisterModel(new(ChanceType))
  20 +}
  21 +
  22 +// AddChanceType insert a new ChanceType into database and returns
  23 +// last inserted Id on success.
  24 +func AddChanceType(m *ChanceType) (id int64, err error) {
  25 + o := orm.NewOrm()
  26 + id, err = o.Insert(m)
  27 + return
  28 +}
  29 +
  30 +// GetChanceTypeById retrieves ChanceType by Id. Returns error if
  31 +// Id doesn't exist
  32 +func GetChanceTypeById(id int) (v *ChanceType, err error) {
  33 + o := orm.NewOrm()
  34 + v = &ChanceType{Id: id}
  35 + if err = o.Read(v); err == nil {
  36 + return v, nil
  37 + }
  38 + return nil, err
  39 +}
  40 +
  41 +// UpdateChanceType updates ChanceType by Id and returns error if
  42 +// the record to be updated doesn't exist
  43 +func UpdateChanceTypeById(m *ChanceType) (err error) {
  44 + o := orm.NewOrm()
  45 + v := ChanceType{Id: m.Id}
  46 + // ascertain id exists in the database
  47 + if err = o.Read(&v); err == nil {
  48 + var num int64
  49 + if num, err = o.Update(m); err == nil {
  50 + fmt.Println("Number of records updated in database:", num)
  51 + }
  52 + }
  53 + return
  54 +}
  55 +
  56 +// DeleteChanceType deletes ChanceType by Id and returns error if
  57 +// the record to be deleted doesn't exist
  58 +func DeleteChanceType(id int) (err error) {
  59 + o := orm.NewOrm()
  60 + v := ChanceType{Id: 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.Delete(&ChanceType{Id: id}); err == nil {
  65 + fmt.Println("Number of records deleted in database:", num)
  66 + }
  67 + }
  68 + return
  69 +}
  70 +
  71 +func GetChanceTypeAll() (v []*ChanceType, err error) {
  72 + o := orm.NewOrm()
  73 + sql := "select * from chance_type "
  74 + if _, err = o.Raw(sql).QueryRows(&v); err == nil {
  75 + return
  76 + }
  77 + return
  78 +}
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "github.com/astaxie/beego/orm"
  8 +)
  9 +
  10 +type ChanceVideo struct {
  11 + Id int64 `orm:"column(id);auto"`
  12 + ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会id"`
  13 + Path string `orm:"column(path);size(500);null" description:"路径"`
  14 + Cover string `orm:"column(cover);size(500);null" description:"封面"`
  15 + CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
  16 +}
  17 +
  18 +func (t *ChanceVideo) TableName() string {
  19 + return "chance_video"
  20 +}
  21 +
  22 +func init() {
  23 + orm.RegisterModel(new(ChanceVideo))
  24 +}
  25 +
  26 +// AddChanceVideo insert a new ChanceVideo into database and returns
  27 +// last inserted Id on success.
  28 +func AddChanceVideo(m *ChanceVideo) (id int64, err error) {
  29 + o := orm.NewOrm()
  30 + id, err = o.Insert(m)
  31 + return
  32 +}
  33 +
  34 +// GetChanceVideoById retrieves ChanceVideo by Id. Returns error if
  35 +// Id doesn't exist
  36 +func GetChanceVideoById(id int64) (v *ChanceVideo, err error) {
  37 + o := orm.NewOrm()
  38 + v = &ChanceVideo{Id: id}
  39 + if err = o.Read(v); err == nil {
  40 + return v, nil
  41 + }
  42 + return nil, err
  43 +}
  44 +
  45 +// UpdateChanceVideo updates ChanceVideo by Id and returns error if
  46 +// the record to be updated doesn't exist
  47 +func UpdateChanceVideoById(m *ChanceVideo) (err error) {
  48 + o := orm.NewOrm()
  49 + v := ChanceVideo{Id: m.Id}
  50 + // ascertain id exists in the database
  51 + if err = o.Read(&v); err == nil {
  52 + var num int64
  53 + if num, err = o.Update(m); err == nil {
  54 + fmt.Println("Number of records updated in database:", num)
  55 + }
  56 + }
  57 + return
  58 +}
  59 +
  60 +// DeleteChanceVideo deletes ChanceVideo by Id and returns error if
  61 +// the record to be deleted doesn't exist
  62 +func DeleteChanceVideo(id int64) (err error) {
  63 + o := orm.NewOrm()
  64 + v := ChanceVideo{Id: id}
  65 + // ascertain id exists in the database
  66 + if err = o.Read(&v); err == nil {
  67 + var num int64
  68 + if num, err = o.Delete(&ChanceVideo{Id: id}); err == nil {
  69 + fmt.Println("Number of records deleted in database:", num)
  70 + }
  71 + }
  72 + return
  73 +}
@@ -73,14 +73,13 @@ func DeleteUserDepartment(id int64) (err error) { @@ -73,14 +73,13 @@ func DeleteUserDepartment(id int64) (err error) {
73 return 73 return
74 } 74 }
75 75
76 -  
77 func GetUserDepartments(userId int64, companyId int64, v interface{}) (err error) { 76 func GetUserDepartments(userId int64, companyId int64, v interface{}) (err error) {
78 o := orm.NewOrm() 77 o := orm.NewOrm()
79 sql := ` 78 sql := `
80 -select a.department_id,b.name 79 +select a.department_id,b.name,b.parent_id,b.managers
81 from user_department a INNER JOIN department b on a.department_id = b.id 80 from user_department a INNER JOIN department b on a.department_id = b.id
82 where a.user_id =? and a.company_id =? and enable_status =1 and b.delete_at =0` 81 where a.user_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
83 - if _, err = o.Raw(sql,userId, companyId).QueryRows(v); err == nil { 82 + if _, err = o.Raw(sql, userId, companyId).QueryRows(v); err == nil {
84 return 83 return
85 } 84 }
86 return 85 return
1 package models 1 package models
2 2
3 import ( 3 import (
4 - "errors"  
5 "fmt" 4 "fmt"
6 - "reflect"  
7 - "strings"  
8 "time" 5 "time"
9 6
10 "github.com/astaxie/beego/orm" 7 "github.com/astaxie/beego/orm"
@@ -54,84 +51,6 @@ func GetUsersById(id int64) (v *User, err error) { @@ -54,84 +51,6 @@ func GetUsersById(id int64) (v *User, err error) {
54 return nil, err 51 return nil, err
55 } 52 }
56 53
57 -// GetAllUsers retrieves all Users matches certain condition. Returns empty list if  
58 -// no records exist  
59 -func GetAllUser(query map[string]string, fields []string, sortby []string, order []string,  
60 - offset int64, limit int64) (ml []interface{}, err error) {  
61 - o := orm.NewOrm()  
62 - qs := o.QueryTable(new(User))  
63 - // query k=v  
64 - for k, v := range query {  
65 - // rewrite dot-notation to Object__Attribute  
66 - k = strings.Replace(k, ".", "__", -1)  
67 - if strings.Contains(k, "isnull") {  
68 - qs = qs.Filter(k, (v == "true" || v == "1"))  
69 - } else {  
70 - qs = qs.Filter(k, v)  
71 - }  
72 - }  
73 - // order by:  
74 - var sortFields []string  
75 - if len(sortby) != 0 {  
76 - if len(sortby) == len(order) {  
77 - // 1) for each sort field, there is an associated order  
78 - for i, v := range sortby {  
79 - orderby := ""  
80 - if order[i] == "desc" {  
81 - orderby = "-" + v  
82 - } else if order[i] == "asc" {  
83 - orderby = v  
84 - } else {  
85 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
86 - }  
87 - sortFields = append(sortFields, orderby)  
88 - }  
89 - qs = qs.OrderBy(sortFields...)  
90 - } else if len(sortby) != len(order) && len(order) == 1 {  
91 - // 2) there is exactly one order, all the sorted fields will be sorted by this order  
92 - for _, v := range sortby {  
93 - orderby := ""  
94 - if order[0] == "desc" {  
95 - orderby = "-" + v  
96 - } else if order[0] == "asc" {  
97 - orderby = v  
98 - } else {  
99 - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")  
100 - }  
101 - sortFields = append(sortFields, orderby)  
102 - }  
103 - } else if len(sortby) != len(order) && len(order) != 1 {  
104 - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")  
105 - }  
106 - } else {  
107 - if len(order) != 0 {  
108 - return nil, errors.New("Error: unused 'order' fields")  
109 - }  
110 - }  
111 -  
112 - var l []User  
113 - qs = qs.OrderBy(sortFields...)  
114 - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {  
115 - if len(fields) == 0 {  
116 - for _, v := range l {  
117 - ml = append(ml, v)  
118 - }  
119 - } else {  
120 - // trim unused fields  
121 - for _, v := range l {  
122 - m := make(map[string]interface{})  
123 - val := reflect.ValueOf(v)  
124 - for _, fname := range fields {  
125 - m[fname] = val.FieldByName(fname).Interface()  
126 - }  
127 - ml = append(ml, m)  
128 - }  
129 - }  
130 - return ml, nil  
131 - }  
132 - return nil, err  
133 -}  
134 -  
135 // UpdateUsers updates Users by Id and returns error if 54 // UpdateUsers updates Users by Id and returns error if
136 // the record to be updated doesn't exist 55 // the record to be updated doesn't exist
137 func UpdateUsersById(m *User) (err error) { 56 func UpdateUsersById(m *User) (err error) {
@@ -179,3 +98,12 @@ func GetUserByMobile(mobile string) (v *User, err error) { @@ -179,3 +98,12 @@ func GetUserByMobile(mobile string) (v *User, err error) {
179 } 98 }
180 return nil, err 99 return nil, err
181 } 100 }
  101 +
  102 +func GetUserByRole(roleId int) (v []*User, err error) {
  103 + o := orm.NewOrm()
  104 + sql := `select * from user where is_kefu = 1 and enable_status=1`
  105 + if _, err = o.Raw(sql).QueryRows(&v); err == nil {
  106 + return v, nil
  107 + }
  108 + return nil, err
  109 +}
1 package protocol 1 package protocol
2 2
  3 +import "opp/models"
  4 +
3 const ( 5 const (
4 MarkFlag_Zan = 1 6 MarkFlag_Zan = 1
5 MarkFlag_Collect = 2 7 MarkFlag_Collect = 2
6 ) 8 )
7 9
8 -const(  
9 - UnMarkFlag =0 10 +const (
  11 + UnMarkFlag = 0
10 MarkFlag = 1 //是否标记 /点赞 /收藏 12 MarkFlag = 1 //是否标记 /点赞 /收藏
11 ) 13 )
12 14
  15 +const (
  16 + AuditFlowType_Departmentor = iota + 1 //部门长
  17 + AuditFlowType_User //指定用户
  18 + AuditFlowType_Role //指定角色
  19 + AuditFlowType_SpecailUser //特殊人员
  20 +)
  21 +
  22 +const (
  23 + FlowType_Normal = iota + 1
  24 + FlowType_Specail
  25 +)
  26 +
  27 +const (
  28 + NoApprover_Pass = 1
  29 + NoApprover_ToAdmin = 2
  30 +)
  31 +
  32 +const (
  33 + StaticType_Question = 1 << iota
  34 + StaticType_Question2
  35 +)
  36 +
13 /*Favorite */ 37 /*Favorite */
14 type FavoriteRequest struct { 38 type FavoriteRequest struct {
15 ObjectType int `json:"object_type" valid:"Required"` //收藏 点赞 39 ObjectType int `json:"object_type" valid:"Required"` //收藏 点赞
@@ -28,7 +52,7 @@ type ChanceFavorite struct { @@ -28,7 +52,7 @@ type ChanceFavorite struct {
28 Favorite interface{} `json:"favorite"` 52 Favorite interface{} `json:"favorite"`
29 } 53 }
30 54
31 -type Chance struct { 55 +type ChanceDetail struct {
32 Id int64 `json:"id"` 56 Id int64 `json:"id"`
33 Provider *BaseUserInfo `json:"provider"` 57 Provider *BaseUserInfo `json:"provider"`
34 IsCollect bool `json:"is_collect"` 58 IsCollect bool `json:"is_collect"`
@@ -45,7 +69,6 @@ type Chance struct { @@ -45,7 +69,6 @@ type Chance struct {
45 ZanTotal int `json:"zan_total"` 69 ZanTotal int `json:"zan_total"`
46 } 70 }
47 71
48 -  
49 /*SympathyAction */ 72 /*SympathyAction */
50 type SympathyActionRequest struct { 73 type SympathyActionRequest struct {
51 MarkType int `json:"mark_type" valid:"Required"` // 1.赞 2.收藏 74 MarkType int `json:"mark_type" valid:"Required"` // 1.赞 2.收藏
@@ -55,3 +78,67 @@ type SympathyActionRequest struct { @@ -55,3 +78,67 @@ type SympathyActionRequest struct {
55 } 78 }
56 type SympathyActionResponse struct { 79 type SympathyActionResponse struct {
57 } 80 }
  81 +
  82 +/*ChanceType */
  83 +type ChanceTypeRequest struct {
  84 +}
  85 +type ChanceTypeResponse struct {
  86 + List []*models.ChanceType `json:"list"`
  87 +}
  88 +
  89 +/*Templates */
  90 +type TemplatesRequest struct {
  91 + ChanceType int `json:"chance_type" valid:"Required"`
  92 +}
  93 +type TemplatesResponse struct {
  94 + Templates []*Template `json:"list"`
  95 +}
  96 +
  97 +type Template struct {
  98 + Id int64 `json:"id"`
  99 + Name string `json:"name"`
  100 + Doc string `json:"doc"`
  101 + Icon string `json:"icon"`
  102 + FormList []*Form `json:"form_list"`
  103 +}
  104 +
  105 +type Form struct {
  106 + Id int `json:"id"`
  107 + Lable string `json:"name"`
  108 + InputType string `json:"input_type"`
  109 + SectionType int8 `json:"section_type"`
  110 + Value string `json:"value"`
  111 + Required int8 `json:"required"`
  112 +}
  113 +
  114 +type ChanceSubmitRequest struct {
  115 + AuditTemplateId int64 `json:"audit_template_id" valid:"Required"`
  116 + Content string `json:"content" valid:"Required"`
  117 + FormList []*Form `json:"form_list" valid:"Required"`
  118 + Speechs []Speech `json:"speechs"`
  119 + Pictures []Picture `json:"pictures"`
  120 + Videos []Video `json:"videos"`
  121 + RelatedDepartment int64 `json:"related_departments" valid:"Required"`
  122 +}
  123 +
  124 +type ChanceSubmitResponse struct {
  125 +}
  126 +
  127 +type Speech struct {
  128 + Path string `json:"path"`
  129 + Duration int `json:"duration"`
  130 +}
  131 +type Picture struct {
  132 + Path string `json:"path"`
  133 + W int `json:"w"`
  134 + H int `json:"h"`
  135 +}
  136 +type Video struct {
  137 + Path string `json:"path"`
  138 + Cover string `json:"cover"` //封面
  139 + Duration int `json:"duration"`
  140 +}
  141 +
  142 +type AuditConfig struct {
  143 + NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】
  144 +}
@@ -14,8 +14,10 @@ type DepartmentsResponse struct { @@ -14,8 +14,10 @@ type DepartmentsResponse struct {
14 } 14 }
15 15
16 type Department struct { 16 type Department struct {
17 - DepartmentId int `orm:"column(department_id) json:"id"`  
18 - Name string `orm:"column(name) json:"name"`  
19 - PId int `orm:"column(pid) json:"-"` 17 + DepartmentId int `orm:"column(department_id)" json:"id"`
  18 + Name string `orm:"column(name)" json:"name"`
  19 + PId int `orm:"column(parent_id)" json:"-"`
  20 + ManagerString string `orm:"column(managers)" json:"-"`
  21 + Managers []int `json:"-"`
20 Departments []*Department `json:"departments,omitempty"` 22 Departments []*Department `json:"departments,omitempty"`
21 } 23 }
@@ -57,6 +57,22 @@ func init() { @@ -57,6 +57,22 @@ func init() {
57 57
58 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], 58 beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
59 beego.ControllerComments{ 59 beego.ControllerComments{
  60 + Method: "ChanceSubmit",
  61 + Router: `/chanceSubmit`,
  62 + AllowHTTPMethods: []string{"post"},
  63 + MethodParams: param.Make(),
  64 + Params: nil})
  65 +
  66 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  67 + beego.ControllerComments{
  68 + Method: "ChanceType",
  69 + Router: `/chanceType`,
  70 + AllowHTTPMethods: []string{"post"},
  71 + MethodParams: param.Make(),
  72 + Params: nil})
  73 +
  74 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  75 + beego.ControllerComments{
60 Method: "CommentDetailsMulti", 76 Method: "CommentDetailsMulti",
61 Router: `/commentDetailsMulti`, 77 Router: `/commentDetailsMulti`,
62 AllowHTTPMethods: []string{"post"}, 78 AllowHTTPMethods: []string{"post"},
@@ -111,6 +127,14 @@ func init() { @@ -111,6 +127,14 @@ func init() {
111 MethodParams: param.Make(), 127 MethodParams: param.Make(),
112 Params: nil}) 128 Params: nil})
113 129
  130 + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
  131 + beego.ControllerComments{
  132 + Method: "Templates",
  133 + Router: `/templates`,
  134 + AllowHTTPMethods: []string{"post"},
  135 + MethodParams: param.Make(),
  136 + Params: nil})
  137 +
114 beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"], 138 beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
115 beego.ControllerComments{ 139 beego.ControllerComments{
116 Method: "Company", 140 Method: "Company",
@@ -67,7 +67,7 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err @@ -67,7 +67,7 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
67 return 67 return
68 } 68 }
69 69
70 -func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) { 70 +func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) {
71 var ( 71 var (
72 c *models.Chance 72 c *models.Chance
73 baseUserInfo *protocol.BaseUserInfo 73 baseUserInfo *protocol.BaseUserInfo
@@ -79,7 +79,7 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) @@ -79,7 +79,7 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error)
79 if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil { 79 if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil {
80 return 80 return
81 } 81 }
82 - v = &protocol.Chance{ 82 + v = &protocol.ChanceDetail{
83 Id: c.Id, 83 Id: c.Id,
84 Provider: baseUserInfo, 84 Provider: baseUserInfo,
85 85
@@ -92,12 +92,12 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) @@ -92,12 +92,12 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error)
92 return 92 return
93 } 93 }
94 94
95 -func GetIncrementSql(table string,column string,incre int,id int64)(*utils.SqlData){ 95 +func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData {
96 var sql *bytes.Buffer 96 var sql *bytes.Buffer
97 sql = bytes.NewBuffer(nil) 97 sql = bytes.NewBuffer(nil)
98 - sql.WriteString(fmt.Sprintf("update %s set %s=%s+%d ",table,column,column,incre))  
99 - sql.WriteString(fmt.Sprintf(" where id=%d",id)) 98 + sql.WriteString(fmt.Sprintf("update %s set %s=%s+%d ", table, column, column, incre))
  99 + sql.WriteString(fmt.Sprintf(" where id=%d", id))
100 return &utils.SqlData{ 100 return &utils.SqlData{
101 - Sql:sql.String(), 101 + Sql: sql.String(),
102 } 102 }
103 } 103 }
1 package chance 1 package chance
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "fmt" 5 "fmt"
5 "github.com/astaxie/beego/orm" 6 "github.com/astaxie/beego/orm"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
6 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" 8 "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
7 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 9 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
8 "opp/internal/repository" 10 "opp/internal/repository"
@@ -16,7 +18,7 @@ import ( @@ -16,7 +18,7 @@ import (
16 func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) { 18 func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) {
17 var ( 19 var (
18 favorites []*models.ChanceFavorite 20 favorites []*models.ChanceFavorite
19 - chance *protocol.Chance 21 + chance *protocol.ChanceDetail
20 ) 22 )
21 rsp = &protocol.FavoriteResponse{} 23 rsp = &protocol.FavoriteResponse{}
22 favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites( 24 favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites(
@@ -54,7 +56,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) @@ -54,7 +56,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
54 } 56 }
55 57
56 //点赞/收藏 取消点赞/收藏 58 //点赞/收藏 取消点赞/收藏
57 -func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyActionRequest)(rsp *protocol.SympathyActionResponse,err error){ 59 +func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyActionRequest) (rsp *protocol.SympathyActionResponse, err error) {
58 var ( 60 var (
59 exists bool 61 exists bool
60 chanceFavoirte *models.ChanceFavorite 62 chanceFavoirte *models.ChanceFavorite
@@ -63,78 +65,454 @@ func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyAct @@ -63,78 +65,454 @@ func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyAct
63 incre int = 1 65 incre int = 1
64 table string = "comment" 66 table string = "comment"
65 ) 67 )
66 - rsp =&protocol.SympathyActionResponse{}  
67 - if chanceFavoirte,err = repository.ChanceFavorite.GetChanceFavorite(header.Uid,header.CompanyId,request.Id,request.SourceType);err!=nil && err!=orm.ErrNoRows{ 68 + rsp = &protocol.SympathyActionResponse{}
  69 + if chanceFavoirte, err = repository.ChanceFavorite.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
68 log.Error(err) 70 log.Error(err)
69 return 71 return
70 } 72 }
71 - if request.SourceType == protocol.SourceType_Chance{  
72 - if chance,err = repository.Chance.GetChanceById(request.Id);err!=nil{  
73 - log.Error("机会不存在",err) 73 + if request.SourceType == protocol.SourceType_Chance {
  74 + if chance, err = repository.Chance.GetChanceById(request.Id); err != nil {
  75 + log.Error("机会不存在", err)
74 return 76 return
75 } 77 }
76 chanceType = chance.ChanceType 78 chanceType = chance.ChanceType
77 table = "chance" 79 table = "chance"
78 } 80 }
79 - if chanceFavoirte!=nil{ 81 + if chanceFavoirte != nil {
80 exists = true 82 exists = true
81 - if request.MarkType ==protocol.MarkFlag_Zan {  
82 - if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)==0{ 83 + if request.MarkType == protocol.MarkFlag_Zan {
  84 + if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) == 0 {
83 err = protocol.NewSuccessWithMessage("已经取消赞,不能重复取消赞") 85 err = protocol.NewSuccessWithMessage("已经取消赞,不能重复取消赞")
84 return 86 return
85 } 87 }
86 - if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)>0{ 88 + if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) > 0 {
87 err = protocol.NewSuccessWithMessage("已经赞,不能重复点赞") 89 err = protocol.NewSuccessWithMessage("已经赞,不能重复点赞")
88 return 90 return
89 } 91 }
90 - }else if (request.MarkType==protocol.MarkFlag_Collect){  
91 - if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)==0{ 92 + } else if request.MarkType == protocol.MarkFlag_Collect {
  93 + if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) == 0 {
92 err = protocol.NewSuccessWithMessage("已经取消收藏,不能重复取消收藏") 94 err = protocol.NewSuccessWithMessage("已经取消收藏,不能重复取消收藏")
93 return 95 return
94 } 96 }
95 - if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)>0{ 97 + if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) > 0 {
96 err = protocol.NewSuccessWithMessage("已经收藏,不能重复收藏") 98 err = protocol.NewSuccessWithMessage("已经收藏,不能重复收藏")
97 return 99 return
98 } 100 }
99 } 101 }
100 } 102 }
101 - if exists{  
102 - if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid,header.CompanyId,request.Id,1<<(uint(request.MarkType-1)));err!=nil{  
103 - log.Error(request.MarkType,err) 103 + if exists {
  104 + if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
  105 + log.Error(request.MarkType, err)
104 return 106 return
105 } 107 }
106 goto END 108 goto END
107 } 109 }
108 //add 110 //add
109 chanceFavoirte = &models.ChanceFavorite{ 111 chanceFavoirte = &models.ChanceFavorite{
110 - Id:idgen.Next(),  
111 - UserId:header.Uid,  
112 - CompanyId:header.CompanyId,  
113 - MarkFlag:request.SympathyType,  
114 - SourceType:request.SourceType,  
115 - SourceId:request.Id,  
116 - ChanceType:chanceType,  
117 - CreateAt:time.Now(),  
118 - EnableStatus:1, 112 + Id: idgen.Next(),
  113 + UserId: header.Uid,
  114 + CompanyId: header.CompanyId,
  115 + MarkFlag: request.SympathyType,
  116 + SourceType: request.SourceType,
  117 + SourceId: request.Id,
  118 + ChanceType: chanceType,
  119 + CreateAt: time.Now(),
  120 + EnableStatus: 1,
119 } 121 }
120 - if _,err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte);err!=nil{ 122 + if _, err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte); err != nil {
121 log.Error(err) 123 log.Error(err)
122 return 124 return
123 - }else{  
124 - log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v",header.Uid,request.Id,request.SympathyType)) 125 + } else {
  126 + log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v", header.Uid, request.Id, request.SympathyType))
125 goto END 127 goto END
126 } 128 }
127 - END: 129 +END:
128 { 130 {
129 - if request.MarkType!=protocol.MarkFlag_Zan { 131 + if request.MarkType != protocol.MarkFlag_Zan {
130 return 132 return
131 } 133 }
132 - if request.SympathyType==protocol.UnMarkFlag{ 134 + if request.SympathyType == protocol.UnMarkFlag {
133 incre = -1 135 incre = -1
134 } 136 }
135 - if !utils.ExecuteSqlByRoll(true,agg.GetIncrementSql(table,"zan_total",incre,request.Id)){ 137 + if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
136 // 138 //
137 } 139 }
138 } 140 }
139 return 141 return
140 } 142 }
  143 +
  144 +//机会类型
  145 +func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) {
  146 + var ()
  147 + rsp = &protocol.ChanceTypeResponse{}
  148 + if rsp.List, err = models.GetChanceTypeAll(); err != nil {
  149 + return
  150 + }
  151 + return
  152 +}
  153 +
  154 +//获取机会对应的模板列表
  155 +func Templates(header *protocol.RequestHeader, request *protocol.TemplatesRequest) (rsp *protocol.TemplatesResponse, err error) {
  156 + var (
  157 + templates []*models.AuditTemplate
  158 + forms []*models.AuditForm
  159 + )
  160 + rsp = &protocol.TemplatesResponse{}
  161 + if templates, err = models.GetAuditTemplates(header.CompanyId, request.ChanceType); err != nil {
  162 + log.Error(err)
  163 + return
  164 + }
  165 + if len(templates) == 0 {
  166 + return
  167 + }
  168 + for i := range templates {
  169 + item := templates[i]
  170 + //TODO:检查模板可见
  171 + //
  172 + //查询表单
  173 + if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
  174 + continue
  175 + }
  176 + template := &protocol.Template{
  177 + Id: item.Id,
  178 + Name: item.Name,
  179 + Icon: item.Icon,
  180 + Doc: item.Doc,
  181 + FormList: make([]*protocol.Form, len(forms)),
  182 + }
  183 + for j := range forms {
  184 + form := forms[j]
  185 + template.FormList[j] = &protocol.Form{
  186 + Id: form.Id,
  187 + Lable: form.Label,
  188 + Value: "",
  189 + InputType: form.InputType,
  190 + SectionType: form.Section,
  191 + Required: form.Required,
  192 + }
  193 + }
  194 + rsp.Templates = append(rsp.Templates, template)
  195 + }
  196 + return
  197 +}
  198 +
  199 +func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
  200 + //if template.VisibleType ==
  201 + return
  202 +}
  203 +
  204 +//提交机会
  205 +func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
  206 + var (
  207 + template *models.AuditTemplate
  208 + chance *models.Chance
  209 + auditConfig *protocol.AuditConfig
  210 + auditFlows []*models.AuditFlowProcess
  211 + )
  212 + //1.模板是否存在
  213 + if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
  214 + log.Error(err)
  215 + return
  216 + }
  217 + auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
  218 + orm := orm.NewOrm()
  219 + orm.Begin()
  220 + //2.检查模板是否有权限
  221 +
  222 + //3.添加机会 添加文件
  223 + chance = &models.Chance{
  224 + Id: idgen.Next(),
  225 + UserId: header.Uid,
  226 + CompanyId: header.CompanyId,
  227 + ChanceType: template.ChanceType,
  228 + AuditTemplateId: template.Id,
  229 + AuditTemplateConfig: common.AssertJson(auditConfig),
  230 + Content: request.Content,
  231 + SourceContent: common.AssertJson(request.FormList),
  232 + EnableStatus: 1,
  233 + CreateAt: time.Now(),
  234 + UpdateAt: time.Now(),
  235 + AuditLevel: 1,
  236 + DepartmentId: request.RelatedDepartment,
  237 + }
  238 + if _, err = orm.Insert(chance); err != nil {
  239 + log.Error(err)
  240 + orm.Rollback()
  241 + return
  242 + }
  243 +
  244 + //4.查询审核配置
  245 + //5.生成审核流
  246 + if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
  247 + log.Error(err)
  248 + orm.Rollback()
  249 + return
  250 + }
  251 + for i := 0; i < len(auditFlows); i++ {
  252 + if _, err = orm.Insert(auditFlows[i]); err != nil {
  253 + log.Error(err)
  254 + orm.Rollback()
  255 + return
  256 + }
  257 +
  258 + }
  259 + //6.文件
  260 + for _, v := range GenSpeechs(chance.Id, request.Speechs) {
  261 + if _, err = orm.Insert(v); err != nil {
  262 + log.Error(err)
  263 + orm.Rollback()
  264 + return
  265 + }
  266 + }
  267 + for _, v := range GenVideos(chance.Id, request.Videos) {
  268 + if _, err = orm.Insert(v); err != nil {
  269 + log.Error(err)
  270 + orm.Rollback()
  271 + return
  272 + }
  273 + }
  274 + for _, v := range GenImages(chance.Id, request.Pictures) {
  275 + if _, err = orm.Insert(v); err != nil {
  276 + log.Error(err)
  277 + orm.Rollback()
  278 + return
  279 + }
  280 + }
  281 + orm.Commit()
  282 +
  283 + //6.激活审核流
  284 + //TODO:7.发送消息通知给审核人(审核消息)
  285 + rsp = &protocol.ChanceSubmitResponse{}
  286 + return
  287 +}
  288 +
  289 +//生成审批流
  290 +func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
  291 + var (
  292 + configs []*models.AuditFlowConfig
  293 + IsSpecailAuditFlow bool = false
  294 + ids []int64
  295 + groupId int64
  296 + company *models.Company
  297 + )
  298 + if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
  299 + log.Error(err)
  300 + return
  301 + }
  302 +
  303 + //1.检查是否是特殊审核人
  304 + for i := range configs {
  305 + config := configs[i]
  306 + if groupId == 0 && config.FlowType == protocol.FlowType_Normal {
  307 + groupId = config.AuditGroupId
  308 + continue
  309 + }
  310 + if len(config.FromSpecialUser) > 0 {
  311 + if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
  312 + log.Error(err)
  313 + return
  314 + }
  315 + for j := range ids {
  316 + if ids[j] == header.Uid {
  317 + groupId = config.AuditGroupId
  318 + IsSpecailAuditFlow = true
  319 + break
  320 + }
  321 + }
  322 + }
  323 + if IsSpecailAuditFlow {
  324 + break
  325 + }
  326 + }
  327 +
  328 + if groupId == 0 {
  329 + err = fmt.Errorf("group_id=0 template_id:%v", templateId)
  330 + log.Error(err)
  331 + return
  332 + }
  333 +
  334 + //2.查询特定的审核列表
  335 + if configs, err = models.GetAuditFlowConfigs(templateId, groupId); err != nil {
  336 + log.Error(err)
  337 + return
  338 + }
  339 +
  340 + if company, err = repository.Company.GetCompanyById(header.CompanyId); err != nil {
  341 + log.Error(err)
  342 + return
  343 + }
  344 +
  345 + if company.AdminId == 0 {
  346 + err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
  347 + return
  348 + }
  349 +
  350 + //3.生成审核列表
  351 + for i := range configs {
  352 + config := configs[i]
  353 + var userIds []int64
  354 + switch config.AuditFlowType {
  355 + case protocol.AuditFlowType_Departmentor:
  356 + if userIds, err = getDepartmentors(header); err != nil {
  357 + log.Error(err)
  358 + return
  359 + }
  360 + case protocol.AuditFlowType_User:
  361 + if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
  362 + log.Error(err)
  363 + return
  364 + }
  365 + case protocol.AuditFlowType_Role:
  366 +
  367 + }
  368 + if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
  369 + userIds = append(userIds, 0)
  370 + }
  371 + for j := 0; j < len(userIds); j++ {
  372 + uid := userIds[j]
  373 + if uid == 0 && auditConfig.NoApprover == protocol.NoApprover_ToAdmin { //审批人为空 转交给管理员
  374 + uid = company.AdminId
  375 + }
  376 + if uid == header.Uid { //审核人自己 转交给管理员
  377 + log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
  378 + uid = company.AdminId
  379 + }
  380 + item := &models.AuditFlowProcess{
  381 + Id: idgen.Next(),
  382 + ChanceId: chanceId,
  383 + Uid: uid,
  384 + Level: config.Level,
  385 + CreateAt: time.Now(),
  386 + UpdateAt: time.Now(),
  387 + AuditFlowType: config.AuditFlowType,
  388 + FlowType: config.FlowType,
  389 + ActionType: int(config.ActionType),
  390 + EnableStatus: 1,
  391 + }
  392 + //if uid==0 && auditConfig.NoApprover==1{//审批人为空 自动通过
  393 + // item.
  394 + //}
  395 + if config.Level == 1 {
  396 + item.IsActive = 1
  397 + //通知 user_msg
  398 + }
  399 + log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
  400 + v = append(v, item)
  401 + }
  402 + }
  403 + return
  404 +}
  405 +func resolveActionType(t uint) string {
  406 + if t == 1 {
  407 + return "or"
  408 + }
  409 + if t == 2 {
  410 + return "and"
  411 + }
  412 + return fmt.Sprintf("%v", t)
  413 +}
  414 +
  415 +//获取部门长用户列表
  416 +func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
  417 + var (
  418 + departments []*protocol.Department
  419 + )
  420 + if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &departments); err != nil {
  421 + log.Error(err)
  422 + return
  423 + }
  424 +
  425 + for i := 0; i < len(departments); i++ {
  426 + d := departments[i]
  427 + //部门长存在
  428 + if len(d.ManagerString) > 0 {
  429 + var tmpIds []int64
  430 + if err = json.Unmarshal([]byte(d.ManagerString), &tmpIds); err == nil && len(ids) > 0 {
  431 + ids = append(ids, tmpIds...)
  432 + continue
  433 + }
  434 + }
  435 + //部门长不存在
  436 + if d.PId == 0 {
  437 + ids = append(ids, 0)
  438 + continue
  439 + } else {
  440 + ids = append(ids, getParentDepartmentors(d.PId)...)
  441 + }
  442 + }
  443 + return
  444 +}
  445 +
  446 +//递归寻找上一级部门长
  447 +func getParentDepartmentors(pid int) (ids []int64) {
  448 + var (
  449 + department *models.Department
  450 + err error
  451 + )
  452 + if department.ParentId == 0 {
  453 + return
  454 + }
  455 + if department, err = repository.Department.GetDepartmentById(pid); err != nil {
  456 + log.Error(err)
  457 + return
  458 + }
  459 + if len(department.Managers) != 0 {
  460 + if err = json.Unmarshal([]byte(department.Managers), &ids); err == nil && len(ids) > 0 {
  461 + return
  462 + }
  463 + }
  464 + return getParentDepartmentors(department.ParentId)
  465 +}
  466 +
  467 +////获取角色对应用户列表
  468 +//func getRolesUser(header *protocol.RequestHeader,toRoles string)(ids []int64){
  469 +// var roles []int
  470 +// if err :=json.Unmarshal([]byte(toRoles),&roles);err!=nil{
  471 +// log.Error(err)
  472 +// return
  473 +// }
  474 +// for i:=range roles{
  475 +//
  476 +// }
  477 +// return
  478 +//}
  479 +
  480 +func GenSpeechs(id int64, objs []protocol.Speech) (v []*models.ChanceSpeech) {
  481 + for i := range objs {
  482 + v = append(v, &models.ChanceSpeech{
  483 + Id: idgen.Next(),
  484 + Duration: objs[i].Duration,
  485 + Path: objs[i].Path,
  486 + ChanceId: id,
  487 + CreateAt: time.Now(),
  488 + })
  489 + }
  490 + return
  491 +}
  492 +
  493 +func GenVideos(id int64, objs []protocol.Video) (v []*models.ChanceVideo) {
  494 + for i := range objs {
  495 + v = append(v, &models.ChanceVideo{
  496 + Id: idgen.Next(),
  497 + Path: objs[i].Path,
  498 + ChanceId: id,
  499 + Cover: objs[i].Cover,
  500 + CreateAt: time.Now(),
  501 + })
  502 + }
  503 + return
  504 +}
  505 +
  506 +func GenImages(id int64, objs []protocol.Picture) (v []*models.ChanceImage) {
  507 + for i := range objs {
  508 + v = append(v, &models.ChanceImage{
  509 + Id: idgen.Next(),
  510 + Path: objs[i].Path,
  511 + ChanceId: id,
  512 + W: objs[i].W,
  513 + H: objs[i].H,
  514 + CreateAt: time.Now(),
  515 + })
  516 + }
  517 + return
  518 +}
1 package department 1 package department
2 2
3 import ( 3 import (
  4 + "encoding/json"
4 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" 5 "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
5 "opp/internal/repository" 6 "opp/internal/repository"
6 "opp/models" 7 "opp/models"
@@ -10,6 +11,7 @@ import ( @@ -10,6 +11,7 @@ import (
10 func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { 11 func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) {
11 var ( 12 var (
12 departments []*models.Department 13 departments []*models.Department
  14 + tmpDepartment = &protocol.Department{Departments: []*protocol.Department{}}
13 ) 15 )
14 rsp = &protocol.DepartmentsResponse{} 16 rsp = &protocol.DepartmentsResponse{}
15 switch request.Type { 17 switch request.Type {
@@ -18,17 +20,11 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe @@ -18,17 +20,11 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
18 log.Error(err) 20 log.Error(err)
19 return 21 return
20 } 22 }
21 - //rsp.Departments =  
22 for i := range departments { 23 for i := range departments {
23 - var newD *protocol.Department = &protocol.Department{  
24 - DepartmentId: departments[i].Id,  
25 - Name: departments[i].Name,  
26 - }  
27 - if departments[i].ParentId == 0 {  
28 - rsp.Departments = append(rsp.Departments, newD)  
29 - }  
30 - 24 + item := departments[i]
  25 + walkDepartment(tmpDepartment, item)
31 } 26 }
  27 + rsp.Departments = tmpDepartment.Departments
32 case protocol.DepartmentUser: 28 case protocol.DepartmentUser:
33 if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &rsp.Departments); err != nil { 29 if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &rsp.Departments); err != nil {
34 log.Error(err) 30 log.Error(err)
@@ -40,29 +36,24 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe @@ -40,29 +36,24 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
40 return 36 return
41 } 37 }
42 38
43 -//  
44 -//func setDepartment(departments *[]models.Department)[]*protocol.Department{  
45 -// var departments []*protocol.Department  
46 -// for i :=range dfrom{  
47 -//  
48 -// var newD *protocol.Department = &protocol.Department{  
49 -// DepartmentId:dfrom[i].Id,  
50 -// Name:dfrom[i].Name,  
51 -// }  
52 -//  
53 -// }  
54 -//  
55 -// if dfrom.ParentId ==0{  
56 -//  
57 -// }  
58 -// if len(department)>0{  
59 -// for i:=range department{  
60 -// if department[i].DepartmentId == dfrom.ParentId{  
61 -// department[i].Departments = append(department[i].Departments,newD)  
62 -// return nil  
63 -// }  
64 -// return setDepartment(department[i].Departments,dfrom)  
65 -// }  
66 -// }  
67 -// return nil  
68 -//} 39 +//遍历部门
  40 +func walkDepartment(to *protocol.Department, dfrom *models.Department) (err error) {
  41 + var newD *protocol.Department = &protocol.Department{
  42 + DepartmentId: dfrom.Id,
  43 + Name: dfrom.Name,
  44 + Departments: []*protocol.Department{},
  45 + }
  46 + if len(dfrom.Managers) > 0 {
  47 + if err = json.Unmarshal([]byte(dfrom.Managers), &newD.Managers); err != nil {
  48 + log.Error(err, dfrom.Id, dfrom.Managers)
  49 + return
  50 + }
  51 + }
  52 + if to.DepartmentId == dfrom.ParentId {
  53 + to.Departments = append(to.Departments, newD)
  54 + }
  55 + for i := range to.Departments {
  56 + walkDepartment(to.Departments[i], dfrom)
  57 + }
  58 + return nil
  59 +}