作者 yangfu

Merge remote-tracking branch 'origin/dev' into test

... ... @@ -104,11 +104,11 @@ func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSi
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content,approve_data,review_status from chance
where user_id=? and company_id=? and review_status in (?) and (?=0 or id>?)
where user_id=? and company_id=? and review_status in (?) and (?=0 or id<?)
order by create_at desc
limit ?
) a left JOIN chance_data b on a.id =b.chance_id`
//update_at
sqlCount := fmt.Sprintf(`select count(0) from (
select id,user_id,create_at,source_content from chance
where user_id=? and company_id=? and review_status in (%v)
... ... @@ -129,7 +129,7 @@ func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64,
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.source_content,b.enable_status,b.review_status from (
select id,approve_time,approve_data,uid,chance_id,approve_message,create_at process_create_time
from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id>?)
from audit_flow_process where uid=? and enable_status =1 and review_status in (%v) and (?=0 or id<?)
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.chance_id =b.chance_id
order by process_create_time desc
... ... @@ -152,7 +152,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int,
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id>?) and enable_status=1
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
order by create_at desc
limit ?
) a left JOIN chance_data b on a.id =b.chance_id`
... ... @@ -177,7 +177,7 @@ order by create_at desc
func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id>?) and user_id =? and enable_status=1
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&2)>0
)a left outer join chance b on a.source_id = b.id
... ... @@ -200,7 +200,7 @@ limit ?`)
func GetChanceThumbUp(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id>?) and user_id =? and enable_status=1
select id collect_id,source_id,create_at collect_time from chance_favorite where (0=? or id<?) and user_id =? and enable_status=1
and source_type=1
and (mark_flag&1)>0
)a left outer join chance b on a.source_id = b.id
... ... @@ -227,7 +227,7 @@ from (
select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from (
select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment
where user_id =? and (?=0 or id>?)
where user_id =? and (?=0 or id<?)
)a left outer join chance b on a.source_id = b.id and source_type=1
)a left outer join chance_data b on a.source_id = b.chance_id and source_type = 1
)a left outer join comment b on a.source_id = b.id and a.source_type=2
... ...
... ... @@ -81,13 +81,16 @@ func DeleteChanceFavorite(id int64) (err error) {
//按1.用户id 2.公司id 3.标记类型 4.机会类型编号 5.最后编号 6.页数
//获取用户点赞收藏机会
func GetChanceFavorites(userId, companyId int64, markFlag, sourceType int, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
func GetChanceFavorites(userId, companyId int64, markFlag, sourceType int, sourceId int64, lastId int64, pageSize int) (v []*ChanceFavorite, total int, err error) {
sql := mybeego.NewSqlExutor().Table("chance_favorite").Order("create_at desc")
sql.Where(fmt.Sprintf("user_id=%d", userId))
sql.Where(fmt.Sprintf("company_id=%d", companyId))
if sourceType > 0 {
sql.Where(fmt.Sprintf("source_type=%d", sourceType))
}
if sourceId > 0 {
sql.Where(fmt.Sprintf("source_id=%d", sourceId))
}
if markFlag > 0 {
sql.Where(fmt.Sprintf("mark_flag&%d>0", markFlag))
}
... ... @@ -95,7 +98,7 @@ func GetChanceFavorites(userId, companyId int64, markFlag, sourceType int, lastI
sql.Limit(0, pageSize)
}
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
sql.Where(fmt.Sprintf("id<%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
return
... ...
... ... @@ -94,7 +94,7 @@ func GetComments(userId int64, sourceType int, sourceId int64, lastId int64, pag
sql.Limit(0, pageSize)
}
if lastId > 0 {
sql.Where(fmt.Sprintf("id>%d", lastId))
sql.Where(fmt.Sprintf("id<%d", lastId))
}
if total, err = sql.Querys(&v); err == nil {
if total == 0 {
... ...
... ... @@ -16,7 +16,6 @@ type Department struct {
Relation string `orm:"column(relation);size(400)" description:"父子级关系树"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Member int `orm:"column(member)" description:"成员数量"`
Managers string `orm:"column(managers);null" description:"部门负责人id列表 json 数组 [ ]"`
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type Role struct {
Id int `orm:"column(id);auto" description:"编号"`
Pid int `orm:"column(pid)" description:"关联的上级组id"`
Types int8 `orm:"column(types)" description:"类型【1:角色】【2:角色组】"`
Name string `orm:"column(name);size(30)" description:"角色名称"`
CompanyId int `orm:"column(company_id)" description:"表company.id 编号"`
Descript string `orm:"column(descript);size(255)" description:"描述"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
IsDefault int8 `orm:"column(is_default)" description:"是否是默认项【0:不是默认】【1:是默认】"`
}
func (t *Role) TableName() string {
return "role"
}
func init() {
orm.RegisterModel(new(Role))
}
// AddRole insert a new Role into database and returns
// last inserted Id on success.
func AddRole(m *Role) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetRoleById retrieves Role by Id. Returns error if
// Id doesn't exist
func GetRoleById(id int) (v *Role, err error) {
o := orm.NewOrm()
v = &Role{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRole updates Role by Id and returns error if
// the record to be updated doesn't exist
func UpdateRoleById(m *Role) (err error) {
o := orm.NewOrm()
v := Role{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
}
// DeleteRole deletes Role by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRole(id int) (err error) {
o := orm.NewOrm()
v := Role{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&Role{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -181,7 +181,7 @@ func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data from (
select id,company_id,receive_user_id,message,source_id,is_read
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id>?) and msg_type=?
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.source_id = b.id
)a left outer join chance_data b on a.source_id =b.chance_id
order by a.create_at desc
... ... @@ -206,7 +206,7 @@ func GetChanceCommentMsg(uid, lastId int64, pageSize int, msgType int, v interfa
select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status from (
select id,message content,source_type,source_id,create_at comment_time from user_msg
where receive_user_id =? and (?=0 or id>?) and msg_type=?
where receive_user_id =? and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.source_id = b.id and source_type=1
)a left outer join chance_data b on a.source_id = b.chance_id and source_type = 1
)a left outer join comment b on a.source_id = b.id and a.source_type=2
... ...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type UserRole struct {
Id int `orm:"column(id);auto"`
RoleId int `orm:"column(role_id)"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 2:无效"`
CompanyId int64 `orm:"column(company_id)"`
UserCompanyId int64 `orm:"column(user_company_id)" description:"表user_company的id"`
}
func (t *UserRole) TableName() string {
return "user_role"
}
func init() {
orm.RegisterModel(new(UserRole))
}
// AddUserRole insert a new UserRole into database and returns
// last inserted Id on success.
func AddUserRole(m *UserRole) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetUserRoleById retrieves UserRole by Id. Returns error if
// Id doesn't exist
func GetUserRoleById(id int) (v *UserRole, err error) {
o := orm.NewOrm()
v = &UserRole{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserRole updates UserRole by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserRoleById(m *UserRole) (err error) {
o := orm.NewOrm()
v := UserRole{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
}
// DeleteUserRole deletes UserRole by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserRole(id int) (err error) {
o := orm.NewOrm()
v := UserRole{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserRole{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetUserRolesById(roleId int) (v []*UserRole, err error) {
o := orm.NewOrm()
sql := `
select * from user_role where role_id =? and enable_status =1`
if _, err = o.Raw(sql, roleId).QueryRows(&v); err == nil {
return
}
return
}
... ...
... ... @@ -57,6 +57,9 @@ var errmessge ErrorMap = map[int]string{
5510: "评分配置不存在,请联系管理员",
5511: "发现分计算不一致,请重新提交",
//评论相关
5601: "评论不存在",
}
const (
... ...
... ... @@ -198,7 +198,11 @@ func GetIncrementSql(table string, column string, incre int, id int64) *utils.Sq
var sql *bytes.Buffer
sql = bytes.NewBuffer(nil)
sql.WriteString(fmt.Sprintf("update %s set %s=%s+%d ", table, column, column, incre))
if incre > 0 {
sql.WriteString(fmt.Sprintf(" where id=%d", id))
} else {
sql.WriteString(fmt.Sprintf(" where id=%d and %v>0", id, column))
}
return &utils.SqlData{
Sql: sql.String(),
}
... ...
... ... @@ -27,6 +27,7 @@ func Favorite(header *protocol.RequestHeader, request *protocol.FavoriteRequest)
header.CompanyId,
request.ObjectType,
request.ChanceType,
0,
request.LastId,
request.PageSize)
if err != nil {
... ... @@ -62,10 +63,13 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
exists bool
chanceFavoirte *models.ChanceFavorite
chance *models.Chance
comment *models.Comment
chanceType int
incre int = 1
table string = "comment"
message string = protocol.MessageZanComment
sourceId int64
userId int64
)
rsp = &protocol.SympathyActionResponse{}
if chanceFavoirte, err = models.GetChanceFavorite(header.UserId, header.CompanyId, request.Id, request.SourceType); err != nil && err != orm.ErrNoRows {
... ... @@ -75,11 +79,26 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
if request.SourceType == protocol.SourceTypeChance {
message = protocol.MessageZanChance
if chance, err = models.GetChanceById(request.Id); err != nil {
log.Error("机会不存在", err)
log.Error(request.Id, "机会不存在", err)
err = protocol.NewErrWithMessage(5101)
return
}
sourceId = chance.Id
userId = chance.UserId
chanceType = chance.ChanceTypeId
table = "chance"
} else if request.SourceType == protocol.SourceTypeComment {
if comment, err = models.GetCommentById(request.Id); err != nil {
log.Error(request.Id, "评论不存在", err)
err = protocol.NewErrWithMessage(5601)
return
}
sourceId = comment.Id
userId = comment.UserId
} else {
log.Error(request.SourceType, "type error")
err = protocol.NewErrWithMessage(2)
return
}
if chanceFavoirte != nil {
exists = true
... ... @@ -137,10 +156,10 @@ END:
if request.SympathyType == protocol.UnMarkFlag {
incre = -1
//删除点赞消息
agg.DeleteSendedMsg(chance.Id, protocol.SourceTypeChance, chance.UserId, protocol.MsgTypeThumbUp)
agg.DeleteSendedMsg(sourceId, request.SourceType, userId, protocol.MsgTypeThumbUp)
} else {
//发送点赞消息
agg.SendMsg(chance.UserId, fmt.Sprintf("%v", chance.UserId), chance.CompanyId, chance.Id, 1, message, protocol.MsgTypeThumbUp)
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, 1, message, protocol.MsgTypeThumbUp)
}
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
//
... ... @@ -290,7 +309,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
}
//4.查询审核配置
//5.生成审核流
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, chance.DepartmentId, template.Id, auditConfig); err != nil {
log.Error(err)
orm.Rollback()
return
... ... @@ -628,7 +647,7 @@ func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64,
}
//生成审批流
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, relatedDeparmentId int64, templateId int64, auditConfig *protocol.AuditConfig) (v []*models.AuditFlowProcess, err error) {
var (
configs []*models.AuditFlowConfig
IsSpecailAuditFlow bool = false
... ... @@ -637,6 +656,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
company *models.Company
roleName string
approver *models.User
roleId []int
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
... ... @@ -659,6 +679,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
groupId = config.AuditGroupId
continue
}
if config.FlowType == protocol.FlowTypeSpecail {
if len(config.FromSpecialUser) > 0 {
if err = json.Unmarshal([]byte(config.FromSpecialUser), &ids); err != nil {
log.Error(err)
... ... @@ -672,6 +693,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
}
}
}
}
if IsSpecailAuditFlow {
break
}
... ... @@ -704,19 +726,29 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
var userIds []int64
switch config.AuditFlowType {
case protocol.AuditByDepartmentor:
if userIds, err = getDepartmentors(header); err != nil {
if userIds, err = getDepartmentors(header, relatedDeparmentId); err != nil {
log.Error(err)
return
}
break
case protocol.AuditByUser:
if err = json.Unmarshal([]byte(config.ToUser), &userIds); err != nil {
log.Error(err)
return
}
break
case protocol.AuditByRole:
//roleName="" //TODO:角色
if e := json.Unmarshal([]byte(config.ToRole), &roleId); e == nil {
if userIds, err = getRoleUsers(header, roleId[0]); err != nil {
log.Error(err)
return
}
} else {
log.Error(config.ToRole, e)
}
break
}
if len(userIds) == 0 { //当前步骤没有用户 默认一个空审核人
userIds = append(userIds, 0)
}
... ... @@ -725,12 +757,15 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
uid = company.AdminId
}
if uid == header.Uid { //审核人自己 转交给管理员
if uid == 0 {
uid = company.AdminId
}
if uid == header.UserId { //审核人自己 转交给管理员
log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
uid = company.AdminId
}
if approver, err = models.GetUserByUcid(uid); err != nil {
log.Error(err)
log.Error(uid, err)
return
}
item := &models.AuditFlowProcess{
... ... @@ -769,33 +804,52 @@ func resolveActionType(t uint) string {
}
//获取部门长用户列表
func getDepartmentors(header *protocol.RequestHeader) (ids []int64, err error) {
func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
var (
departments []*protocol.Department
departments *models.Department
)
if err = models.GetUserDepartments(header.Uid, header.CompanyId, &departments); err != nil {
log.Error(err)
//if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
// log.Error(header.UserId,header.CompanyId,err)
// return
//}
if departments, err = models.GetDepartmentById(int(relatedDeparmentId)); err != nil {
log.Error(relatedDeparmentId, err)
return
}
for i := 0; i < len(departments); i++ {
d := departments[i]
//部门长存在
if len(d.ManagerString) > 0 {
if len(departments.Managers) > 0 {
var tmpIds []int64
if err = json.Unmarshal([]byte(d.ManagerString), &tmpIds); err == nil && len(ids) > 0 {
if err = json.Unmarshal([]byte(departments.Managers), &tmpIds); err == nil {
if len(tmpIds) > 0 {
ids = append(ids, tmpIds...)
continue
}
}
}
//部门长不存在
if d.PId == 0 {
if len(ids) == 0 {
ids = append(ids, 0)
continue
} else {
ids = append(ids, getParentDepartmentors(d.PId)...)
}
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids))
return
}
//获取角色ids
func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err error) {
var (
userRole []*models.UserRole
)
if userRole, err = models.GetUserRolesById(roleId); err != nil {
log.Error(roleId, err)
if err == orm.ErrNoRows {
err = nil
}
}
for i := range userRole {
ids = append(ids, userRole[i].UserCompanyId)
}
if len(ids) == 0 {
ids = append(ids, 0)
}
log.Info(fmt.Sprintf("生成机会审批流-角色:role_id:%v ids:%v", roleId, ids))
return
}
... ... @@ -888,7 +942,10 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
}
commItem.ReviewStatus = chance.ReviewStatus
if request.ReviewStatus == protocol.ReviewStatusPass {
jsonUnmarshal(chance.ApproveData, &commItem.ApproveData)
var approveData protocol.ApproveData
jsonUnmarshal(chance.ApproveData, &approveData)
//commItem.ApproveData = approveData //TODO:删除不需要
commItem.Score = approveData.Score
}
rsp.List = append(rsp.List, commItem)
}
... ...
... ... @@ -134,7 +134,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
total int
exists bool
)
if comments, total, err = models.GetComments(header.UserId, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
if comments, total, err = models.GetComments(0, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
log.Error(err)
return
}
... ... @@ -172,7 +172,7 @@ func Thumbsups(header *protocol.RequestHeader, request *protocol.ThumbsupsReques
baseUserInfo *protocol.BaseUserInfo
)
rsp = &protocol.ThumbsupsResponse{}
if favorites, total, err = models.GetChanceFavorites(header.UserId, header.CompanyId, protocol.MarkFlagZan, request.SourceType, request.LastId, request.PageSize); err != nil {
if favorites, total, err = models.GetChanceFavorites(header.UserId, header.CompanyId, protocol.MarkFlagZan, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ...