作者 yangfu

发布机会

... ... @@ -29,9 +29,10 @@
|我审核的机会| | | v1/chance/chances|
|机会详情| | | v1/chance/detail|
|待抓住机会列表| | |v1/chance/chances|
|提交机会| | |v1/chance/submit|
|部门列表-全部| | |v1/department/departments|
|部门列表-用户| | |v1/department/userDepartments|
|机会类型|进行中| |v1/chance/chanceType|
|模板列表|进行中| |v1/chance/templates|
|提交机会|进行中| |v1/chance/submit|
|部门列表|完成|2019.12.3|v1/department/departments|
|配置-机会类型| | |v1/config/chanceType|
|配置-评分| | |v1/config/score|
|机会审核| | |v1/chance/audit|
... ...
... ... @@ -139,28 +139,90 @@ func (this *ChanceController) CommentDetailsMulti() {
msg = protocol.NewReturnResponse(chance.CommentDetailsMulti(header, request))
}
//SympathyAction
//@router /sympathyAction [post]
func(this *ChanceController)SympathyAction(){
func (this *ChanceController) SympathyAction() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SympathyActionRequest
if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b,m :=this.Valid(request);!b{
if b, m := this.Valid(request); !b {
msg = m
return
}
if !(request.SourceType==protocol.SourceType_Chance || request.SourceType==protocol.SourceType_Comment){
if !(request.SourceType == protocol.SourceType_Chance || request.SourceType == protocol.SourceType_Comment) {
msg = protocol.BadRequestParam(2)
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SympathyAction(header,request))
msg = protocol.NewReturnResponse(chance.SympathyAction(header, request))
}
//ChanceType
//@router /chanceType [post]
func (this *ChanceController) ChanceType() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceTypeRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceType(header, request))
}
//Templates
//@router /templates [post]
func (this *ChanceController) Templates() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.TemplatesRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.Templates(header, request))
}
//ChanceSubmit
//@router /chanceSubmit [post]
func (this *ChanceController) ChanceSubmit() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceSubmitRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceSubmit(header, request))
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditFlowConfig struct {
Id int `orm:"column(id);pk" description:"唯一编号"`
AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
AuditGroupId int64 `orm:"column(audit_group_id)" description:"审核组id (同一个审批批次)"`
Level int `orm:"column(level)" description:"审批层级顺序,审批步骤 第几步"`
AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色 4.特殊审核人 "`
FromSpecialUser string `orm:"column(from_special_user)" description:"特殊指定的审批单发起人"`
ToRole string `orm:"column(to_role);null" description:"指定角色"`
ToUser string `orm:"column(to_user);null" description:"指定人"`
FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"`
ActionType uint `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}
func (t *AuditFlowConfig) TableName() string {
return "audit_flow_config"
}
func init() {
orm.RegisterModel(new(AuditFlowConfig))
}
// AddAuditFlowConfig insert a new AuditFlowConfig into database and returns
// last inserted Id on success.
func AddAuditFlowConfig(m *AuditFlowConfig) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditFlowConfigById retrieves AuditFlowConfig by Id. Returns error if
// Id doesn't exist
func GetAuditFlowConfigById(id int) (v *AuditFlowConfig, err error) {
o := orm.NewOrm()
v = &AuditFlowConfig{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditFlowConfig updates AuditFlowConfig by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFlowConfigById(m *AuditFlowConfig) (err error) {
o := orm.NewOrm()
v := AuditFlowConfig{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAuditFlowConfig deletes AuditFlowConfig by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditFlowConfig(id int) (err error) {
o := orm.NewOrm()
v := AuditFlowConfig{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditFlowConfig{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetAuditFlowConfigs(auditTemplateId int64, groupId int64) (v []*AuditFlowConfig, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_config where audit_template_id=? and audit_group_id=? order by level"
if _, err = o.Raw(sql, auditTemplateId, groupId).QueryRows(&v); err == nil {
return
}
return
}
func GetAuditFlowConfigsLevel(auditTemplateId int64, level int) (v []*AuditFlowConfig, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_config where audit_template_id=? and level=?"
if _, err = o.Raw(sql, auditTemplateId, level).QueryRows(&v); err == nil {
return
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditFlowProcess struct {
Id int64 `orm:"column(id);pk" description:"唯一标识"`
ChanceId int64 `orm:"column(chance_id)" description:"实例id,关联chance表id"`
Uid int64 `orm:"column(uid)" description:"用户id(审批人)"`
Level int `orm:"column(level)" description:"审批步骤"`
IsActive int8 `orm:"column(is_active)" description:"是否激活"`
ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:审核中 1:被退回 2:已通过 3.自动通过 "`
AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色 4.特殊审核人"`
FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"`
ActionType int `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 (被驳回以后,未完成的审核置为无效)"`
}
func (t *AuditFlowProcess) TableName() string {
return "audit_flow_process"
}
func init() {
orm.RegisterModel(new(AuditFlowProcess))
}
// AddAuditFlowProcess insert a new AuditFlowProcess into database and returns
// last inserted Id on success.
func AddAuditFlowProcess(m *AuditFlowProcess) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditFlowProcessById retrieves AuditFlowProcess by Id. Returns error if
// Id doesn't exist
func GetAuditFlowProcessById(id int64) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
v = &AuditFlowProcess{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditFlowProcess updates AuditFlowProcess by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFlowProcessById(m *AuditFlowProcess) (err error) {
o := orm.NewOrm()
v := AuditFlowProcess{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAuditFlowProcess deletes AuditFlowProcess by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditFlowProcess(id int64) (err error) {
o := orm.NewOrm()
v := AuditFlowProcess{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditFlowProcess{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditForm struct {
Id int `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
AuditTemplateId int `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
Section int8 `orm:"column(section)" description:"输入项所属的版块(1.基础,2.附加)"`
SortNum int `orm:"column(sort_num)" description:"排序"`
Label string `orm:"column(label);size(100)" description:"标题"`
InputType string `orm:"column(input_type);size(50)" description:"输入类型"`
ValueList string `orm:"column(value_list);size(255)" description:"可选值列表"`
Required int8 `orm:"column(required)" description:"是否必填:【0:否】【1:是】"`
CurrentValue string `orm:"column(current_value);size(255)" description:"实际填写的值"`
Disable int8 `orm:"column(disable);null" description:"显示隐藏:【0:显示】【1:隐藏】"`
Step string `orm:"column(step);size(30)" description:"步进,输入类型是range时生效 "`
Placeholder string `orm:"column(placeholder);size(40)" description:"输入提示"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"更新时间"`
EnableStatus int8 `orm:"column(enable_status);null" description:"有效状态 0:无效 1:有效 "`
}
func (t *AuditForm) TableName() string {
return "audit_form"
}
func init() {
orm.RegisterModel(new(AuditForm))
}
// AddAuditForm insert a new AuditForm into database and returns
// last inserted Id on success.
func AddAuditForm(m *AuditForm) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditFormById retrieves AuditForm by Id. Returns error if
// Id doesn't exist
func GetAuditFormById(id int) (v *AuditForm, err error) {
o := orm.NewOrm()
v = &AuditForm{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditForm updates AuditForm by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFormById(m *AuditForm) (err error) {
o := orm.NewOrm()
v := AuditForm{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAuditForm deletes AuditForm by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditForm(id int) (err error) {
o := orm.NewOrm()
v := AuditForm{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditForm{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetAuditForms(companyId int64, auditTemplateId int64) (v []*AuditForm, err error) {
o := orm.NewOrm()
sql := `select * from audit_form where company_id=? and audit_template_id=? and enable_status=1
order by section,sort_num
`
if _, err = o.Raw(sql, companyId, auditTemplateId).QueryRows(&v); err == nil {
return
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditTemplate struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceType int `orm:"column(chance_type)" description:"机会类型"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
}
func (t *AuditTemplate) TableName() string {
return "audit_template"
}
func init() {
orm.RegisterModel(new(AuditTemplate))
}
// AddAuditTemplate insert a new AuditTemplate into database and returns
// last inserted Id on success.
func AddAuditTemplate(m *AuditTemplate) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditTemplateById retrieves AuditTemplate by Id. Returns error if
// Id doesn't exist
func GetAuditTemplateById(id int64) (v *AuditTemplate, err error) {
o := orm.NewOrm()
v = &AuditTemplate{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditTemplate updates AuditTemplate by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditTemplateById(m *AuditTemplate) (err error) {
o := orm.NewOrm()
v := AuditTemplate{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteAuditTemplate deletes AuditTemplate by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditTemplate(id int64) (err error) {
o := orm.NewOrm()
v := AuditTemplate{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditTemplate{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetAuditTemplates(companyId int64, chanceType int) (v []*AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where company_id=? and chance_type=? and enable_status=1"
if _, err = o.Raw(sql, companyId, chanceType).QueryRows(&v); err == nil {
return
}
return
}
... ...
... ... @@ -13,16 +13,26 @@ import (
type Chance struct {
Id int64 `orm:"column(id);pk" description:"id 主键"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户id"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司id"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门id"`
ChanceType int `orm:"column(chance_type)" description:"表cfg_chance_type.id 机会类型 1:产品 2:渠道 3.客户 4.区域 5.其他 "`
Content string `orm:"column(content)" description:"内容"`
ViewTotal int `orm:"column(view_total)" description:"浏览总数"`
ChanceType int `orm:"column(chance_type)" description:"表chance_type.id 机会类型 "`
AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"`
Content string `orm:"column(content)" description:"格式化后的文本内容"`
SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"`
ViewTotal int `orm:"column(view_total)" description:"查看总数"`
CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
ZanTotal int `orm:"column(zan_total)" description:"点赞总数"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待审核 1:被退回 2:已通过 3:草稿箱"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:待处理 1:待审核 2:被退回 3:已通过 "`
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
}
func (t *Chance) TableName() string {
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceImage struct {
Id int64 `orm:"column(id);auto" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Path string `orm:"column(path);size(500)" description:"路径"`
W int `orm:"column(w);null" description:"宽"`
H int `orm:"column(h);null" description:"高"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
}
func (t *ChanceImage) TableName() string {
return "chance_image"
}
func init() {
orm.RegisterModel(new(ChanceImage))
}
// AddChanceImage insert a new ChanceImage into database and returns
// last inserted Id on success.
func AddChanceImage(m *ChanceImage) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceImageById retrieves ChanceImage by Id. Returns error if
// Id doesn't exist
func GetChanceImageById(id int64) (v *ChanceImage, err error) {
o := orm.NewOrm()
v = &ChanceImage{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceImage updates ChanceImage by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceImageById(m *ChanceImage) (err error) {
o := orm.NewOrm()
v := ChanceImage{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceImage deletes ChanceImage by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceImage(id int64) (err error) {
o := orm.NewOrm()
v := ChanceImage{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceImage{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceSpeech struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
Duration int `orm:"column(duration);null" description:"秒数"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会编号"`
Path string `orm:"column(path);size(500);null" description:"语音路径"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
}
func (t *ChanceSpeech) TableName() string {
return "chance_speech"
}
func init() {
orm.RegisterModel(new(ChanceSpeech))
}
// AddChanceSpeech insert a new ChanceSpeech into database and returns
// last inserted Id on success.
func AddChanceSpeech(m *ChanceSpeech) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceSpeechById retrieves ChanceSpeech by Id. Returns error if
// Id doesn't exist
func GetChanceSpeechById(id int64) (v *ChanceSpeech, err error) {
o := orm.NewOrm()
v = &ChanceSpeech{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceSpeech updates ChanceSpeech by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceSpeechById(m *ChanceSpeech) (err error) {
o := orm.NewOrm()
v := ChanceSpeech{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceSpeech deletes ChanceSpeech by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceSpeech(id int64) (err error) {
o := orm.NewOrm()
v := ChanceSpeech{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceSpeech{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type ChanceType struct {
Id int `orm:"column(id);auto" json:"id"`
Name string `orm:"column(name);size(50)" description:"机会类型名称" json:"name"`
Icon string `orm:"column(icon);size(500);null" description:"图标地址" json:"icon"`
}
func (t *ChanceType) TableName() string {
return "chance_type"
}
func init() {
orm.RegisterModel(new(ChanceType))
}
// AddChanceType insert a new ChanceType into database and returns
// last inserted Id on success.
func AddChanceType(m *ChanceType) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceTypeById retrieves ChanceType by Id. Returns error if
// Id doesn't exist
func GetChanceTypeById(id int) (v *ChanceType, err error) {
o := orm.NewOrm()
v = &ChanceType{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceType updates ChanceType by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceTypeById(m *ChanceType) (err error) {
o := orm.NewOrm()
v := ChanceType{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceType deletes ChanceType by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceType(id int) (err error) {
o := orm.NewOrm()
v := ChanceType{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceType{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetChanceTypeAll() (v []*ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from chance_type "
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
return
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceVideo struct {
Id int64 `orm:"column(id);auto"`
ChanceId int64 `orm:"column(chance_id);null" description:"表chance.id 机会id"`
Path string `orm:"column(path);size(500);null" description:"路径"`
Cover string `orm:"column(cover);size(500);null" description:"封面"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
}
func (t *ChanceVideo) TableName() string {
return "chance_video"
}
func init() {
orm.RegisterModel(new(ChanceVideo))
}
// AddChanceVideo insert a new ChanceVideo into database and returns
// last inserted Id on success.
func AddChanceVideo(m *ChanceVideo) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceVideoById retrieves ChanceVideo by Id. Returns error if
// Id doesn't exist
func GetChanceVideoById(id int64) (v *ChanceVideo, err error) {
o := orm.NewOrm()
v = &ChanceVideo{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceVideo updates ChanceVideo by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceVideoById(m *ChanceVideo) (err error) {
o := orm.NewOrm()
v := ChanceVideo{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceVideo deletes ChanceVideo by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceVideo(id int64) (err error) {
o := orm.NewOrm()
v := ChanceVideo{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceVideo{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -73,14 +73,13 @@ func DeleteUserDepartment(id int64) (err error) {
return
}
func GetUserDepartments(userId int64, companyId int64, v interface{}) (err error) {
o := orm.NewOrm()
sql := `
select a.department_id,b.name
select a.department_id,b.name,b.parent_id,b.managers
from user_department a INNER JOIN department b on a.department_id = b.id
where a.user_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
if _, err = o.Raw(sql,userId, companyId).QueryRows(v); err == nil {
if _, err = o.Raw(sql, userId, companyId).QueryRows(v); err == nil {
return
}
return
... ...
package models
import (
"errors"
"fmt"
"reflect"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -54,84 +51,6 @@ func GetUsersById(id int64) (v *User, err error) {
return nil, err
}
// GetAllUsers retrieves all Users matches certain condition. Returns empty list if
// no records exist
func GetAllUser(query map[string]string, fields []string, sortby []string, order []string,
offset int64, limit int64) (ml []interface{}, err error) {
o := orm.NewOrm()
qs := o.QueryTable(new(User))
// query k=v
for k, v := range query {
// rewrite dot-notation to Object__Attribute
k = strings.Replace(k, ".", "__", -1)
if strings.Contains(k, "isnull") {
qs = qs.Filter(k, (v == "true" || v == "1"))
} else {
qs = qs.Filter(k, v)
}
}
// order by:
var sortFields []string
if len(sortby) != 0 {
if len(sortby) == len(order) {
// 1) for each sort field, there is an associated order
for i, v := range sortby {
orderby := ""
if order[i] == "desc" {
orderby = "-" + v
} else if order[i] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
qs = qs.OrderBy(sortFields...)
} else if len(sortby) != len(order) && len(order) == 1 {
// 2) there is exactly one order, all the sorted fields will be sorted by this order
for _, v := range sortby {
orderby := ""
if order[0] == "desc" {
orderby = "-" + v
} else if order[0] == "asc" {
orderby = v
} else {
return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
}
sortFields = append(sortFields, orderby)
}
} else if len(sortby) != len(order) && len(order) != 1 {
return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
}
} else {
if len(order) != 0 {
return nil, errors.New("Error: unused 'order' fields")
}
}
var l []User
qs = qs.OrderBy(sortFields...)
if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
if len(fields) == 0 {
for _, v := range l {
ml = append(ml, v)
}
} else {
// trim unused fields
for _, v := range l {
m := make(map[string]interface{})
val := reflect.ValueOf(v)
for _, fname := range fields {
m[fname] = val.FieldByName(fname).Interface()
}
ml = append(ml, m)
}
}
return ml, nil
}
return nil, err
}
// UpdateUsers updates Users by Id and returns error if
// the record to be updated doesn't exist
func UpdateUsersById(m *User) (err error) {
... ... @@ -179,3 +98,12 @@ func GetUserByMobile(mobile string) (v *User, err error) {
}
return nil, err
}
func GetUserByRole(roleId int) (v []*User, err error) {
o := orm.NewOrm()
sql := `select * from user where is_kefu = 1 and enable_status=1`
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
package protocol
import "opp/models"
const (
MarkFlag_Zan = 1
MarkFlag_Collect = 2
)
const(
UnMarkFlag =0
const (
UnMarkFlag = 0
MarkFlag = 1 //是否标记 /点赞 /收藏
)
const (
AuditFlowType_Departmentor = iota + 1 //部门长
AuditFlowType_User //指定用户
AuditFlowType_Role //指定角色
AuditFlowType_SpecailUser //特殊人员
)
const (
FlowType_Normal = iota + 1
FlowType_Specail
)
const (
NoApprover_Pass = 1
NoApprover_ToAdmin = 2
)
const (
StaticType_Question = 1 << iota
StaticType_Question2
)
/*Favorite */
type FavoriteRequest struct {
ObjectType int `json:"object_type" valid:"Required"` //收藏 点赞
... ... @@ -28,7 +52,7 @@ type ChanceFavorite struct {
Favorite interface{} `json:"favorite"`
}
type Chance struct {
type ChanceDetail struct {
Id int64 `json:"id"`
Provider *BaseUserInfo `json:"provider"`
IsCollect bool `json:"is_collect"`
... ... @@ -45,7 +69,6 @@ type Chance struct {
ZanTotal int `json:"zan_total"`
}
/*SympathyAction */
type SympathyActionRequest struct {
MarkType int `json:"mark_type" valid:"Required"` // 1.赞 2.收藏
... ... @@ -55,3 +78,67 @@ type SympathyActionRequest struct {
}
type SympathyActionResponse struct {
}
/*ChanceType */
type ChanceTypeRequest struct {
}
type ChanceTypeResponse struct {
List []*models.ChanceType `json:"list"`
}
/*Templates */
type TemplatesRequest struct {
ChanceType int `json:"chance_type" valid:"Required"`
}
type TemplatesResponse struct {
Templates []*Template `json:"list"`
}
type Template struct {
Id int64 `json:"id"`
Name string `json:"name"`
Doc string `json:"doc"`
Icon string `json:"icon"`
FormList []*Form `json:"form_list"`
}
type Form struct {
Id int `json:"id"`
Lable string `json:"name"`
InputType string `json:"input_type"`
SectionType int8 `json:"section_type"`
Value string `json:"value"`
Required int8 `json:"required"`
}
type ChanceSubmitRequest struct {
AuditTemplateId int64 `json:"audit_template_id" valid:"Required"`
Content string `json:"content" valid:"Required"`
FormList []*Form `json:"form_list" valid:"Required"`
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
RelatedDepartment int64 `json:"related_departments" valid:"Required"`
}
type ChanceSubmitResponse struct {
}
type Speech struct {
Path string `json:"path"`
Duration int `json:"duration"`
}
type Picture struct {
Path string `json:"path"`
W int `json:"w"`
H int `json:"h"`
}
type Video struct {
Path string `json:"path"`
Cover string `json:"cover"` //封面
Duration int `json:"duration"`
}
type AuditConfig struct {
NoApprover int8 `json:"no_approver"` //审核人空时:【1:自动通过】【2:转交给管理员】
}
... ...
... ... @@ -14,8 +14,10 @@ type DepartmentsResponse struct {
}
type Department struct {
DepartmentId int `orm:"column(department_id) json:"id"`
Name string `orm:"column(name) json:"name"`
PId int `orm:"column(pid) json:"-"`
DepartmentId int `orm:"column(department_id)" json:"id"`
Name string `orm:"column(name)" json:"name"`
PId int `orm:"column(parent_id)" json:"-"`
ManagerString string `orm:"column(managers)" json:"-"`
Managers []int `json:"-"`
Departments []*Department `json:"departments,omitempty"`
}
... ...
... ... @@ -57,6 +57,22 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceSubmit",
Router: `/chanceSubmit`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceType",
Router: `/chanceType`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
AllowHTTPMethods: []string{"post"},
... ... @@ -111,6 +127,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "Templates",
Router: `/templates`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
... ...
... ... @@ -67,7 +67,7 @@ func GetUserBaseInfo(uid int64, companyId int64) (v *protocol.BaseUserInfo, err
return
}
func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error) {
func GetChance(chanceId int64, companyId int64) (v *protocol.ChanceDetail, err error) {
var (
c *models.Chance
baseUserInfo *protocol.BaseUserInfo
... ... @@ -79,7 +79,7 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error)
if baseUserInfo, err = GetUserBaseInfo(c.UserId, companyId); err != nil {
return
}
v = &protocol.Chance{
v = &protocol.ChanceDetail{
Id: c.Id,
Provider: baseUserInfo,
... ... @@ -92,12 +92,12 @@ func GetChance(chanceId int64, companyId int64) (v *protocol.Chance, err error)
return
}
func GetIncrementSql(table string,column string,incre int,id int64)(*utils.SqlData){
func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData {
var sql *bytes.Buffer
sql = bytes.NewBuffer(nil)
sql.WriteString(fmt.Sprintf("update %s set %s=%s+%d ",table,column,column,incre))
sql.WriteString(fmt.Sprintf(" where id=%d",id))
sql.WriteString(fmt.Sprintf("update %s set %s=%s+%d ", table, column, column, incre))
sql.WriteString(fmt.Sprintf(" where id=%d", id))
return &utils.SqlData{
Sql:sql.String(),
Sql: sql.String(),
}
}
... ...
package chance
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
... ... @@ -16,7 +18,7 @@ import (
func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest) (rsp *protocol.FavoriteResponse, err error) {
var (
favorites []*models.ChanceFavorite
chance *protocol.Chance
chance *protocol.ChanceDetail
)
rsp = &protocol.FavoriteResponse{}
favorites, rsp.Total, err = repository.ChanceFavorite.GetChanceFavorites(
... ... @@ -54,7 +56,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
}
//点赞/收藏 取消点赞/收藏
func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyActionRequest)(rsp *protocol.SympathyActionResponse,err error){
func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyActionRequest) (rsp *protocol.SympathyActionResponse, err error) {
var (
exists bool
chanceFavoirte *models.ChanceFavorite
... ... @@ -63,78 +65,454 @@ func SympathyAction(header *protocol.RequestHeader,request *protocol.SympathyAct
incre int = 1
table string = "comment"
)
rsp =&protocol.SympathyActionResponse{}
if chanceFavoirte,err = repository.ChanceFavorite.GetChanceFavorite(header.Uid,header.CompanyId,request.Id,request.SourceType);err!=nil && err!=orm.ErrNoRows{
rsp = &protocol.SympathyActionResponse{}
if chanceFavoirte, err = repository.ChanceFavorite.GetChanceFavorite(header.Uid, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
log.Error(err)
return
}
if request.SourceType == protocol.SourceType_Chance{
if chance,err = repository.Chance.GetChanceById(request.Id);err!=nil{
log.Error("机会不存在",err)
if request.SourceType == protocol.SourceType_Chance {
if chance, err = repository.Chance.GetChanceById(request.Id); err != nil {
log.Error("机会不存在", err)
return
}
chanceType = chance.ChanceType
table = "chance"
}
if chanceFavoirte!=nil{
if chanceFavoirte != nil {
exists = true
if request.MarkType ==protocol.MarkFlag_Zan {
if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)==0{
if request.MarkType == protocol.MarkFlag_Zan {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) == 0 {
err = protocol.NewSuccessWithMessage("已经取消赞,不能重复取消赞")
return
}
if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Zan)>0{
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Zan) > 0 {
err = protocol.NewSuccessWithMessage("已经赞,不能重复点赞")
return
}
}else if (request.MarkType==protocol.MarkFlag_Collect){
if request.SympathyType==protocol.UnMarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)==0{
} else if request.MarkType == protocol.MarkFlag_Collect {
if request.SympathyType == protocol.UnMarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) == 0 {
err = protocol.NewSuccessWithMessage("已经取消收藏,不能重复取消收藏")
return
}
if request.SympathyType==protocol.MarkFlag && (chanceFavoirte.MarkFlag & protocol.MarkFlag_Collect)>0{
if request.SympathyType == protocol.MarkFlag && (chanceFavoirte.MarkFlag&protocol.MarkFlag_Collect) > 0 {
err = protocol.NewSuccessWithMessage("已经收藏,不能重复收藏")
return
}
}
}
if exists{
if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid,header.CompanyId,request.Id,1<<(uint(request.MarkType-1)));err!=nil{
log.Error(request.MarkType,err)
if exists {
if err = repository.ChanceFavorite.UpdateChanceFavorite(header.Uid, header.CompanyId, request.Id, 1<<(uint(request.MarkType-1))); err != nil {
log.Error(request.MarkType, err)
return
}
goto END
}
//add
chanceFavoirte = &models.ChanceFavorite{
Id:idgen.Next(),
UserId:header.Uid,
CompanyId:header.CompanyId,
MarkFlag:request.SympathyType,
SourceType:request.SourceType,
SourceId:request.Id,
ChanceType:chanceType,
CreateAt:time.Now(),
EnableStatus:1,
Id: idgen.Next(),
UserId: header.Uid,
CompanyId: header.CompanyId,
MarkFlag: request.SympathyType,
SourceType: request.SourceType,
SourceId: request.Id,
ChanceType: chanceType,
CreateAt: time.Now(),
EnableStatus: 1,
}
if _,err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte);err!=nil{
if _, err = repository.ChanceFavorite.AddChanceFavorite(chanceFavoirte); err != nil {
log.Error(err)
return
}else{
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v",header.Uid,request.Id,request.SympathyType))
} else {
log.Debug(fmt.Sprintf("SympathyAction user:%d id:%d sympathy:%v", header.Uid, request.Id, request.SympathyType))
goto END
}
END:
END:
{
if request.MarkType!=protocol.MarkFlag_Zan {
if request.MarkType != protocol.MarkFlag_Zan {
return
}
if request.SympathyType==protocol.UnMarkFlag{
if request.SympathyType == protocol.UnMarkFlag {
incre = -1
}
if !utils.ExecuteSqlByRoll(true,agg.GetIncrementSql(table,"zan_total",incre,request.Id)){
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
//
}
}
return
}
//机会类型
func ChanceType(header *protocol.RequestHeader, request *protocol.ChanceTypeRequest) (rsp *protocol.ChanceTypeResponse, err error) {
var ()
rsp = &protocol.ChanceTypeResponse{}
if rsp.List, err = models.GetChanceTypeAll(); err != nil {
return
}
return
}
//获取机会对应的模板列表
func Templates(header *protocol.RequestHeader, request *protocol.TemplatesRequest) (rsp *protocol.TemplatesResponse, err error) {
var (
templates []*models.AuditTemplate
forms []*models.AuditForm
)
rsp = &protocol.TemplatesResponse{}
if templates, err = models.GetAuditTemplates(header.CompanyId, request.ChanceType); err != nil {
log.Error(err)
return
}
if len(templates) == 0 {
return
}
for i := range templates {
item := templates[i]
//TODO:检查模板可见
//
//查询表单
if forms, err = models.GetAuditForms(header.CompanyId, item.Id); err != nil {
continue
}
template := &protocol.Template{
Id: item.Id,
Name: item.Name,
Icon: item.Icon,
Doc: item.Doc,
FormList: make([]*protocol.Form, len(forms)),
}
for j := range forms {
form := forms[j]
template.FormList[j] = &protocol.Form{
Id: form.Id,
Lable: form.Label,
Value: "",
InputType: form.InputType,
SectionType: form.Section,
Required: form.Required,
}
}
rsp.Templates = append(rsp.Templates, template)
}
return
}
func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.AuditTemplate) (result bool, err error) {
//if template.VisibleType ==
return
}
//提交机会
func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
var (
template *models.AuditTemplate
chance *models.Chance
auditConfig *protocol.AuditConfig
auditFlows []*models.AuditFlowProcess
)
//1.模板是否存在
if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
log.Error(err)
return
}
auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover}
orm := orm.NewOrm()
orm.Begin()
//2.检查模板是否有权限
//3.添加机会 添加文件
chance = &models.Chance{
Id: idgen.Next(),
UserId: header.Uid,
CompanyId: header.CompanyId,
ChanceType: template.ChanceType,
AuditTemplateId: template.Id,
AuditTemplateConfig: common.AssertJson(auditConfig),
Content: request.Content,
SourceContent: common.AssertJson(request.FormList),
EnableStatus: 1,
CreateAt: time.Now(),
UpdateAt: time.Now(),
AuditLevel: 1,
DepartmentId: request.RelatedDepartment,
}
if _, err = orm.Insert(chance); err != nil {
log.Error(err)
orm.Rollback()
return
}
//4.查询审核配置
//5.生成审核流
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
log.Error(err)
orm.Rollback()
return
}
for i := 0; i < len(auditFlows); i++ {
if _, err = orm.Insert(auditFlows[i]); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
//6.文件
for _, v := range GenSpeechs(chance.Id, request.Speechs) {
if _, err = orm.Insert(v); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
for _, v := range GenVideos(chance.Id, request.Videos) {
if _, err = orm.Insert(v); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
for _, v := range GenImages(chance.Id, request.Pictures) {
if _, err = orm.Insert(v); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
orm.Commit()
//6.激活审核流
//TODO:7.发送消息通知给审核人(审核消息)
rsp = &protocol.ChanceSubmitResponse{}
return
}
//生成审批流
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
var (
configs []*models.AuditFlowConfig
IsSpecailAuditFlow bool = false
ids []int64
groupId int64
company *models.Company
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
log.Error(err)
return
}
//1.检查是否是特殊审核人
for i := range configs {
config := configs[i]
if groupId == 0 && config.FlowType == protocol.FlowType_Normal {
groupId = config.AuditGroupId
continue
}
if len(config.FromSpecialUser) > 0 {
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
log.Error(err)
return
}
for j := range ids {
if ids[j] == header.Uid {
groupId = config.AuditGroupId
IsSpecailAuditFlow = true
break
}
}
}
if IsSpecailAuditFlow {
break
}
}
if groupId == 0 {
err = fmt.Errorf("group_id=0 template_id:%v", templateId)
log.Error(err)
return
}
//2.查询特定的审核列表
if configs, err = models.GetAuditFlowConfigs(templateId, groupId); err != nil {
log.Error(err)
return
}
if company, err = repository.Company.GetCompanyById(header.CompanyId); err != nil {
log.Error(err)
return
}
if company.AdminId == 0 {
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
return
}
//3.生成审核列表
for i := range configs {
config := configs[i]
var userIds []int64
switch config.AuditFlowType {
case protocol.AuditFlowType_Departmentor:
if userIds, err = getDepartmentors(header); err != nil {
log.Error(err)
return
}
case protocol.AuditFlowType_User:
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
log.Error(err)
return
}
case protocol.AuditFlowType_Role:
}
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
userIds = append(userIds, 0)
}
for j := 0; j < len(userIds); j++ {
uid := userIds[j]
if uid == 0 && auditConfig.NoApprover == protocol.NoApprover_ToAdmin { //审批人为空 转交给管理员
uid = company.AdminId
}
if uid == header.Uid { //审核人自己 转交给管理员
log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
uid = company.AdminId
}
item := &models.AuditFlowProcess{
Id: idgen.Next(),
ChanceId: chanceId,
Uid: uid,
Level: config.Level,
CreateAt: time.Now(),
UpdateAt: time.Now(),
AuditFlowType: config.AuditFlowType,
FlowType: config.FlowType,
ActionType: int(config.ActionType),
EnableStatus: 1,
}
//if uid==0 && auditConfig.NoApprover==1{//审批人为空 自动通过
// item.
//}
if config.Level == 1 {
item.IsActive = 1
//通知 user_msg
}
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)))
v = append(v, item)
}
}
return
}
func resolveActionType(t uint) string {
if t == 1 {
return "or"
}
if t == 2 {
return "and"
}
return fmt.Sprintf("%v", t)
}
//获取部门长用户列表
func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
var (
departments []*protocol.Department
)
if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &departments); err != nil {
log.Error(err)
return
}
for i := 0; i < len(departments); i++ {
d := departments[i]
//部门长存在
if len(d.ManagerString) > 0 {
var tmpIds []int64
if err = json.Unmarshal([]byte(d.ManagerString), &tmpIds); err == nil && len(ids) > 0 {
ids = append(ids, tmpIds...)
continue
}
}
//部门长不存在
if d.PId == 0 {
ids = append(ids, 0)
continue
} else {
ids = append(ids, getParentDepartmentors(d.PId)...)
}
}
return
}
//递归寻找上一级部门长
func getParentDepartmentors(pid int) (ids []int64) {
var (
department *models.Department
err error
)
if department.ParentId == 0 {
return
}
if department, err = repository.Department.GetDepartmentById(pid); err != nil {
log.Error(err)
return
}
if len(department.Managers) != 0 {
if err = json.Unmarshal([]byte(department.Managers), &ids); err == nil && len(ids) > 0 {
return
}
}
return getParentDepartmentors(department.ParentId)
}
////获取角色对应用户列表
//func getRolesUser(header *protocol.RequestHeader,toRoles string)(ids []int64){
// var roles []int
// if err :=json.Unmarshal([]byte(toRoles),&roles);err!=nil{
// log.Error(err)
// return
// }
// for i:=range roles{
//
// }
// return
//}
func GenSpeechs(id int64, objs []protocol.Speech) (v []*models.ChanceSpeech) {
for i := range objs {
v = append(v, &models.ChanceSpeech{
Id: idgen.Next(),
Duration: objs[i].Duration,
Path: objs[i].Path,
ChanceId: id,
CreateAt: time.Now(),
})
}
return
}
func GenVideos(id int64, objs []protocol.Video) (v []*models.ChanceVideo) {
for i := range objs {
v = append(v, &models.ChanceVideo{
Id: idgen.Next(),
Path: objs[i].Path,
ChanceId: id,
Cover: objs[i].Cover,
CreateAt: time.Now(),
})
}
return
}
func GenImages(id int64, objs []protocol.Picture) (v []*models.ChanceImage) {
for i := range objs {
v = append(v, &models.ChanceImage{
Id: idgen.Next(),
Path: objs[i].Path,
ChanceId: id,
W: objs[i].W,
H: objs[i].H,
CreateAt: time.Now(),
})
}
return
}
... ...
package department
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/models"
... ... @@ -10,6 +11,7 @@ import (
func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) {
var (
departments []*models.Department
tmpDepartment = &protocol.Department{Departments: []*protocol.Department{}}
)
rsp = &protocol.DepartmentsResponse{}
switch request.Type {
... ... @@ -18,17 +20,11 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
log.Error(err)
return
}
//rsp.Departments =
for i := range departments {
var newD *protocol.Department = &protocol.Department{
DepartmentId: departments[i].Id,
Name: departments[i].Name,
}
if departments[i].ParentId == 0 {
rsp.Departments = append(rsp.Departments, newD)
}
item := departments[i]
walkDepartment(tmpDepartment, item)
}
rsp.Departments = tmpDepartment.Departments
case protocol.DepartmentUser:
if err = repository.UserDepartment.GetUserDepartment(header.Uid, header.CompanyId, &rsp.Departments); err != nil {
log.Error(err)
... ... @@ -40,29 +36,24 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
return
}
//
//func setDepartment(departments *[]models.Department)[]*protocol.Department{
// var departments []*protocol.Department
// for i :=range dfrom{
//
// var newD *protocol.Department = &protocol.Department{
// DepartmentId:dfrom[i].Id,
// Name:dfrom[i].Name,
// }
//
// }
//
// if dfrom.ParentId ==0{
//
// }
// if len(department)>0{
// for i:=range department{
// if department[i].DepartmentId == dfrom.ParentId{
// department[i].Departments = append(department[i].Departments,newD)
// return nil
// }
// return setDepartment(department[i].Departments,dfrom)
// }
// }
// return nil
//}
//遍历部门
func walkDepartment(to *protocol.Department, dfrom *models.Department) (err error) {
var newD *protocol.Department = &protocol.Department{
DepartmentId: dfrom.Id,
Name: dfrom.Name,
Departments: []*protocol.Department{},
}
if len(dfrom.Managers) > 0 {
if err = json.Unmarshal([]byte(dfrom.Managers), &newD.Managers); err != nil {
log.Error(err, dfrom.Id, dfrom.Managers)
return
}
}
if to.DepartmentId == dfrom.ParentId {
to.Departments = append(to.Departments, newD)
}
for i := range to.Departments {
walkDepartment(to.Departments[i], dfrom)
}
return nil
}
... ...