作者 yangfu

公告直接发布,发布给所有人

... ... @@ -19,7 +19,7 @@ mysql_db_name = "${MYSQL_DB_NAME||opportunity_dev}"
##redis相关配置
redis_add = "${REDIS_HOST||127.0.0.1}"
redis_add_port = "${REDIS_PORT||6379}"
redis_auth = ""
redis_auth = "123456"
##log相关配置
##out_put:"console","file"
log_output = "file"
... ...
... ... @@ -24,6 +24,7 @@ type Bulletin struct {
//AllowCondition int8 `orm:"column(allow_condition);null" description:"关闭条件 (1(bit 0):公告内容查看完 2(bit 1):回答完问题)"`
CompanyId int64 `orm:"column(company_id);null" description:"公司Id"`
Status int8 `orm:"column(status)" description:"状态 1-下架 2-上架"`
AllPeople int8 `orm:"column(all_people);null" description:"是否是所有人 0:否 1:是"`
}
func (t *Bulletin) TableName() string {
... ...
... ... @@ -143,3 +143,15 @@ func GetUserCompanyReal(ids []int64) ([]UserCompany, error) {
All(&data)
return data, err
}
//获取公司的所有人员
func GetUserCompanyAll(companyId int64) (v []*UserCompany, err error) {
o := orm.NewOrm()
sql := `select a.*,b.nick_name from (
select id,user_id from user_company where company_id=? and enable=1
)a inner join user b on a.user_id = b.id`
if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -20,7 +20,7 @@ type BulletinReleaseRequest struct {
//AllowCondition int `json:"allow_condition"`
QuestionSwitch int `json:"question_switch"`
Receiver []VisibleObject `json:"receiver"`
SendToAll int `json:"send_to_all"` //所有人 1:是 0:否
AllPeo int8 `json:"allPeo"` //所有人 1:是 0:否
Question Question `json:"question"`
Cover Cover `json:"cover"`
IsPublish int `json:"is_publish"` //是否直接发布 0:否 1:直接发布
... ... @@ -70,6 +70,7 @@ type GetBulletinResponse struct {
Title string `json:"title" valid:"Required"`
Content string `json:"content" valid:"Required"`
AllowClose int `json:"allow_close"`
AllPeo int8 `json:"allPeo"` //所有人 1:是 0:否
//AllowCondition int `json:"allow_condition"`
QuestionSwitch int `json:"question_switch"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
... ... @@ -90,10 +91,12 @@ type UpdateBulletinRequest struct {
Content string `json:"content" valid:"Required"`
AllowClose int `json:"allow_close"`
//AllowCondition int `json:"allow_condition"`
AllPeo int8 `json:"allPeo"` //所有人 1:是 0:否
QuestionSwitch int `json:"question_switch"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
Question Question `json:"question"`
Cover Cover `json:"cover" valid:"Required"`
IsPublish int `json:"is_publish"` //是否直接发布 0:否 1:直接发布
}
type UpdateBulletinResponse struct {
}
... ...
... ... @@ -160,10 +160,12 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques
log.Error("template_id:%v 不存在 ,err:%v", request.Template.Id, err.Error())
return
}
if template.Name != request.Template.Name {
if _, err = models.GetAuditTemplateByName(companyId, request.Template.Name); err == nil {
err = protocol.NewErrWithMessage("10271")
return
}
}
orm := orm2.NewOrm()
//模板
{
... ...
... ... @@ -45,6 +45,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ
CreateAt: time.Now(),
UpdateAt: time.Now(),
Status: status,
AllPeople: request.AllPeo,
}
orm := orm2.NewOrm()
... ... @@ -85,7 +86,7 @@ func BulletinRelease(uid, companyId int64, request *protocol.BulletinReleaseRequ
}
//TODO:发送公告消息
if request.IsPublish == 1 {
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(id), bulletin.Title); err != nil {
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(id), bulletin.Title, request.AllPeo); err != nil {
log.Error(err.Error())
orm.Rollback()
return
... ... @@ -136,14 +137,24 @@ func getBulletinReceiverIds(orm orm2.Ormer, receivers []protocol.VisibleObject,
}
//发送公告消息
func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string) (err error) {
func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, companyId int64, sourceId int64, message string, allPeople int8) (err error) {
var (
ids []int64
sended = make(map[int64]int64)
)
if allPeople == 1 {
if userCompanys, e := models.GetUserCompanyAll(companyId); e == nil {
for i := range userCompanys {
ids = append(ids, userCompanys[i].Id)
}
} else {
log.Error("%v %v", companyId, e.Error())
}
} else {
if ids, err = getBulletinReceiverIds(orm, receivers, companyId, sourceId, message); err != nil {
return
}
}
for i := range ids {
if _, ok := sended[ids[i]]; ok {
continue
... ... @@ -256,6 +267,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest)
Title: bulletin.Title,
Content: bulletin.Content,
AllowClose: int(bulletin.AllowClose),
AllPeo: bulletin.AllPeople,
//AllowCondition: int(bulletin.AllowCondition),
Cover: protocol.Cover(bulletin.Cover),
Question: protocol.Question{
... ... @@ -377,6 +389,14 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
}
}
orm := orm2.NewOrm()
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
if err = sendBulletinUserMsg(orm, request.Receiver, companyId, int64(bulletin.Id), bulletin.Title, request.AllPeo); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
}
return
}
... ... @@ -419,7 +439,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest)
}
if request.CmdType == protocol.BulletinRelease { //上架
status = protocol.BulletinRelease
if err = sendBulletinUserMsg(orm, receiver, companyId, int64(bulletin.Id), bulletin.Title); err != nil {
if err = sendBulletinUserMsg(orm, receiver, companyId, int64(bulletin.Id), bulletin.Title, bulletin.AllPeople); err != nil {
log.Error(err.Error())
orm.Rollback()
return
... ...