作者 yangfu

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

package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type AuditFlowLog struct {
Id int `orm:"column(id);auto" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id)" description:"表chance.id 所属机会编号"`
Content string `orm:"column(content);size(500)" description:"内容 json"`
ApproveUserId int64 `orm:"column(approve_user_id)" description:"审核人用户编号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
Code int `orm:"column(code)" description:"消息编码"`
}
func (t *AuditFlowLog) TableName() string {
return "audit_flow_log"
}
func init() {
orm.RegisterModel(new(AuditFlowLog))
}
// AddAuditFlowLog insert a new AuditFlowLog into database and returns
// last inserted Id on success.
func AddAuditFlowLog(m *AuditFlowLog) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetAuditFlowLogById retrieves AuditFlowLog by Id. Returns error if
// Id doesn't exist
func GetAuditFlowLogById(id int) (v *AuditFlowLog, err error) {
o := orm.NewOrm()
v = &AuditFlowLog{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateAuditFlowLog updates AuditFlowLog by Id and returns error if
// the record to be updated doesn't exist
func UpdateAuditFlowLogById(m *AuditFlowLog) (err error) {
o := orm.NewOrm()
v := AuditFlowLog{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
}
// DeleteAuditFlowLog deletes AuditFlowLog by Id and returns error if
// the record to be deleted doesn't exist
func DeleteAuditFlowLog(id int) (err error) {
o := orm.NewOrm()
v := AuditFlowLog{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&AuditFlowLog{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -131,10 +131,9 @@ func GetAuditFlowProcessList(chanceId int64) (v []*AuditFlowProcess, err error)
}
//删除机会时关闭所有审核信息
func CloseAuditFlowProcess(chanceId int64) (err error) {
o := orm.NewOrm()
func CloseAuditFlowProcess(orm orm.Ormer, chanceId int64) (err error) {
sql := "update audit_flow_process set enable_status =0,is_active=0,update_at=now() where chance_id=?"
if err = utils.ExecuteSQLWithOrmer(o, sql, chanceId); err != nil {
if err = utils.ExecuteSQLWithOrmer(orm, sql, chanceId); err != nil {
return
}
return
... ... @@ -154,7 +153,7 @@ func GetAuditFlowProcessApproved(chanceId int64, level int) (v *[]AuditFlowProce
func GetAuditFlowProcessByReview(chanceId int64, level int, reviewStatus int) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where chance_id=? and level=? and is_active=1 and review_status=? and enable_status=1"
if err = o.Raw(sql, chanceId, level, reviewStatus).QueryRow(&v); err != nil {
if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, level, reviewStatus); err != nil {
return
}
return
... ...
... ... @@ -12,6 +12,7 @@ type AuditTemplate struct {
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型编号"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Code string `orm:"column(code);size(50);null" description:"编码"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
... ...
... ... @@ -32,6 +32,8 @@ type Chance struct {
PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
ApproveData string `orm:"column(approve_data)" description:"审核数据 冗余"`
AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
Code string `orm:"column(code)" description:"机会编码 一级编码+二级编码"`
}
func (t *Chance) TableName() string {
... ... @@ -103,7 +105,7 @@ func DeleteChance(id int64) (err error) {
func GetChanceMyChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,speechs,videos
from (
select id,user_id,create_at,source_content,approve_data,review_status from chance
select id,user_id,create_at,update_at,approve_time chance_approve_time,source_content,approve_data,review_status from chance
where user_id=? and company_id=? and review_status in (?) and (?=0 or id<?)
order by create_at desc
limit ?
... ... @@ -112,7 +114,6 @@ limit ?
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)
order by create_at desc
) a left JOIN chance_data b on a.id =b.chance_id`, utils.JoinInt8s(reviewStatus, ","))
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, cid); err != nil {
return
... ... @@ -127,7 +128,7 @@ order by create_at desc
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, 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.source_content,b.enable_status,b.review_status from (
select a.*,b.user_id,b.source_content,b.enable_status,b.review_status,b.create_at,b.update_at,b.approve_time chance_approve_time 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<?)
)a left outer join chance b on a.chance_id = b.id
... ... @@ -177,7 +178,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,chance_id 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
... ... @@ -208,7 +209,7 @@ and (mark_flag&1)>0
order by collect_time desc
limit ?`)
sqlCount := `select count(0) from chance_favorite where user_id =? and enable_status=1 and (mark_flag&1)>0`
sqlCount := `select count(0) from chance_favorite where user_id =? and enable_status=1 and (mark_flag&1)>0 and source_type=1`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid); err != nil {
return
}
... ... @@ -220,6 +221,15 @@ limit ?`)
return
}
//我点赞的
func GetChanceThumbup(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sqlCount := `select count(0) from chance_favorite where user_id =? and enable_status=1 and (mark_flag&1)>0 and source_type=1`
if err = utils.ExecuteQueryOne(&total, sqlCount, uid); err != nil {
return
}
return
}
//我的评论
func GetChanceComment(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id
... ...
... ... @@ -20,6 +20,7 @@ type ChanceFavorite struct {
EnableStatus int `orm:"column(enable_status)" description:"1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"删除时间"`
ChanceId int64 `orm:"column(chance_id)" description:"机会编号"`
}
func (t *ChanceFavorite) TableName() string {
... ...
... ... @@ -9,6 +9,7 @@ import (
type ChanceType struct {
Id int `orm:"column(id);auto" json:"id"`
Name string `orm:"column(name);size(50)" description:"机会类型名称" json:"name"`
Code string `orm:"column(code);size(50);null" description:"编码"`
Icon string `orm:"column(icon);size(500);null" description:"图标地址" json:"icon"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号" json:"-"`
SortNum int `orm:"column(sort_num);null" description:"序号 公司下的序号" json:"-"`
... ...
... ... @@ -92,7 +92,7 @@ func GetUserCompanyByUserId(uid int64, companyId int64) (v *UserCompany, err err
//获取公司信息
func GetUserCompanyBy(id int64, companyId int64) (v *UserCompany, err error) {
o := orm.NewOrm()
sql := "select * from user_company where id=? and company_id=? and enable=1" //
sql := "select * from user_company where id=? and company_id=? " //and enable=1
if err = o.Raw(sql, id, companyId).QueryRow(&v); err == nil {
return v, nil
}
... ...
... ... @@ -20,6 +20,7 @@ type UserMsg struct {
IsPublic int8 `orm:"column(is_public)" description:"1:公开 0:不公开"`
IsRead int8 `orm:"column(is_read)" description:"1:已读 0:未读"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
ChanceId int64 `orm:"column(chance_id)" description:"机会编号"`
}
const (
... ... @@ -105,9 +106,9 @@ func DeleteUserMsg(id int64) (err error) {
func GetUserMsgTotals(userId int64, companyId int64, msgType int, v interface{}) (err error) {
o := orm.NewOrm()
sql := `select COUNT(*) as total,msg_type from user_msg
where (msg_type & ?)>0 and receive_user_id = ? and is_public=1 and is_read=0 and company_id=?
where (msg_type & ?)>0 and receive_user_id = ? and is_read=0 and company_id=?
GROUP BY msg_type`
if _, err = o.Raw(sql, msgType, userId, companyId).QueryRows(v); err == nil {
if err = utils.ExecuteQueryAllWithOrmer(o, v, sql, msgType, userId, companyId); err == nil {
return
}
return
... ... @@ -180,11 +181,11 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
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
select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time
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
order by a.msg_time desc
LIMIT ?`
sqlCount := `select count(0)
... ... @@ -205,12 +206,12 @@ func GetChanceCommentMsg(uid, lastId int64, pageSize int, msgType int, v interfa
sql := `select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id 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 from (
select id,message content,source_type,source_id,create_at comment_time from user_msg
select id,message content,source_type,source_id,is_read,create_at comment_time,chance_id from user_msg
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
order by create_at desc
order by a.comment_time desc
LIMIT ?`
sqlCount := `select count(0)
... ...
... ... @@ -73,6 +73,7 @@ type SympathyActionRequest struct {
SourceType int `json:"sourceType" valid:"Required"` //protocol.SourceType //1.机会 2.评论
Id int64 `json:"id" valid:"Required"` //机会编号 / 评论编号
SympathyType int `json:"sympathyType"` //1:标记 0:取消标记
ChanceId int64 `json:"chanceId"` //机会编号
}
type SympathyActionResponse struct {
}
... ... @@ -132,7 +133,7 @@ type ChanceUpdateRequest struct {
Speechs []Speech `json:"speechs"`
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
RelatedDepartment int64 `json:"relatedDepartments" valid:"Required"`
RelatedDepartment int64 `json:"relatedDepartments"`
IsPublish bool `json:"isPublish"` //是否重新发布
}
... ... @@ -184,6 +185,8 @@ type ChanceItemOrm struct {
Id int64 `orm:"column(id)"`
Uid int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
... ... @@ -207,6 +210,9 @@ type MyApproveChanceResponse struct {
//我的审核机会列表
type ChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
UpdateTime time.Time `orm:"column(update_at)"`
ChanceApproveTime time.Time `orm:"column(chance_approve_time)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
... ... @@ -295,6 +301,9 @@ type ChanceCollectItemOrm struct {
CollectId int64 `orm:"column(collect_id)"` //收藏id
CollectTime time.Time `orm:"column(collect_time)"` //收藏时间
//chance_id
//ChanceId int64 `orm:"column(id)"`
}
//机会池收藏列表项
... ... @@ -323,7 +332,7 @@ type ChanceThumbUpItemOrm struct {
//我的评论
type ChanceCommentItemOrm struct {
//ChanceId int64 `orm:"column(id)"`
ChanceId int64 `orm:"column(chance_id)"`
Uid int64 `orm:"column(chance_user_id)"`
CreateTime time.Time `orm:"column(create_at)"`
SourceContent string `orm:"column(source_content)"`
... ... @@ -349,6 +358,7 @@ type ChanceCommentItemOrm struct {
//评论对象类型
SourceType int `orm:"column(source_type)"`
SourceId int64 `orm:"column(source_id)"`
IsRead int64 `orm:"column(is_read)"`
}
/*ChanceDetail 机会详情*/
... ... @@ -518,10 +528,43 @@ type CommonListItem struct {
ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
ReviewStatus int `json:"reviewStatus"` //审核状态
ChanceId int64 `json:"chanceId"` //机会编号
}
type MsgCommonListItem struct {
MsgId int64 `json:"msgId"` //消息id
Chance ChanceItem `json:"chance,omitempty"` //机会详情
//ChanceData interface{} `json:"statisticData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData
//Approve interface{} `json:"approve,omitempty"` //审核人 审核信息(时间) Approve
//ApproveData interface{} `json:"approveData,omitempty"` //审核数据(公开状态 评分) ApproveData
Message interface{} `json:"message,omitempty"` //消息
CommentData interface{} `json:"commentData,omitempty"` //评论
CollectData interface{} `json:"collectData,omitempty"` //收藏数据
ThumbUpData interface{} `json:"thumbUpData,omitempty"` //点赞数据
//我审核的-通过
Score interface{} `json:"score,omitempty"`
//模板
//ChanceType interface{} `json:"chanceType,omitempty"` //机会类型
//ChanceTemplate interface{} `json:"template,omitempty"` //机会模板
//我评论的 评论数据
CommentedData interface{} `json:"commentedData,omitempty"`
SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论
ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭
ReviewStatus int `json:"reviewStatus"` //审核状态
IsRead bool `json:"isRead"`
ChanceId int64 `json:"chanceId"` //机会编号
}
type ChanceItem struct {
Id int64 `json:"id"`
CreateTime int64 `json:"createTime"`
CreateTimeCopy int64 `json:"createTimeCopy"`
UpdateTime int64 `json:"updateTime"`
ApproveTime int64 `json:"approveTime"`
Provider *BaseUserInfo `json:"provider"`
FormList []*Form `json:"formList" valid:"Required"`
Speechs []Speech `json:"speechs"`
... ... @@ -548,6 +591,7 @@ type ThumbUpData struct {
Id int64 `json:"id"`
Content string `json:"content"` //点赞内容
ThumbUpTime int64 `json:"thumbUpTime"` //收藏时间
//IsRead bool `json:"is_read"` //是否已读
}
//评论内容
... ... @@ -555,4 +599,6 @@ type CommentData struct {
Id int64 `json:"id"` //评论编号
Content string `json:"content"` //评论内容
CommentTime int64 `json:"commentTime"` //评论时间
//IsRead bool `json:"isRead"` //是否已读
Provider interface{} `json:"provider,omitempty"`
}
... ...
... ... @@ -68,7 +68,7 @@ type Comments struct {
ViewTotal int `json:"pageViewTotal"`
CommentTotal int `json:"commentTotal"`
ZanTotal int `json:"thumbsupTotal"`
IsZan int `json:"isThumbsUp"` //0:未点赞 1:点赞
IsZan bool `json:"isThumbsUp"` //0:未点赞 1:点赞
}
type Thumbups struct {
... ...
... ... @@ -43,6 +43,7 @@ var errmessge ErrorMap = map[int]string{
5204: "评分或者公开状态不能为空",
5205: "机会未审核通过,不能修改评分或者公开状态",
5206: "未找到审批节点或者无权限",
5207: "公司管理员未设置",
//模板相关
5301: "机会模板不存在",
... ... @@ -125,7 +126,7 @@ type UserMsg struct {
MsgId int64 `json:"msgId"`
BulletinId int64 `json:"-"`
SourceType int `json:"msgType"`
Content string `json:"content"`
Content string `json:"title"`
CreateAt int64 `json:"msgTime"`
IsRead int `json:"isRead"`
//机会 //评论
... ... @@ -222,7 +223,7 @@ type MsgChanceApproveRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceApproveResponse struct {
List []CommonListItem `json:"list"`
List []MsgCommonListItem `json:"list"`
Total int `json:"total"`
}
... ... @@ -232,7 +233,7 @@ type MsgChanceSubmitRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceSubmitResponse struct {
List []CommonListItem `json:"list"`
List []MsgCommonListItem `json:"list"`
Total int `json:"total"`
}
... ... @@ -242,7 +243,7 @@ type MsgChanceCommentRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceCommentResponse struct {
List []CommonListItem `json:"list"`
List []MsgCommonListItem `json:"list"`
Total int `json:"total"`
}
... ... @@ -252,7 +253,7 @@ type MsgChanceThumbUpRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
}
type MsgChanceThumbUpResponse struct {
List []CommonListItem `json:"list"`
List []MsgCommonListItem `json:"list"`
Total int `json:"total"`
}
... ... @@ -272,7 +273,7 @@ type MsgChanceApproveItemOrm struct {
CreateTime time.Time `orm:"column(create_at)"`
Message string `orm:"column(message)"`
IsRead int64 `orm:"column(isRead)"`
ChanceId int64 `orm:"column(source_id)"` // 机会id
ChanceId int64 `orm:"column(chance_id)"` // 机会id
//EnableStatus int `orm:"column(enable_status)"`
}
... ...
... ... @@ -51,6 +51,7 @@ func SendApproveMsg(receiverId int64, name string, companyId int64, chanceId int
SourceType: protocol.SourceTypeChance,
IsPublic: 0,
CreateAt: time.Now(),
ChanceId: chanceId,
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
... ... @@ -110,11 +111,11 @@ func SendApprovedMsg(receiverId int64, name string, companyId int64, chanceId in
return
}
format = fmt.Sprintf(format, chanceType.Name)
return SendMsg(receiverId, name, companyId, chanceId, protocol.SourceTypeChance, format, msgType)
return SendMsg(receiverId, name, companyId, chanceId, protocol.SourceTypeChance, format, msgType, chanceId)
}
//发送消息
func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sourceType int, message string, msgType int) (err error) {
func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sourceType int, message string, msgType int, chanceId int64) (err error) {
var (
userMsg *models.UserMsg
)
... ... @@ -128,6 +129,7 @@ func SendMsg(receiverId int64, name string, companyId int64, sourceId int64, sou
SourceType: sourceType,
IsPublic: 0,
CreateAt: time.Now(),
ChanceId: chanceId,
}
if _, err = models.AddUserMsg(userMsg); err != nil {
return
... ... @@ -151,3 +153,27 @@ func logMsg(msg *models.UserMsg, name string) {
log.Info(fmt.Sprintf("发送消息 消息类型:%v Receiver:%v(%v) Message:%v SourceId:%v SourceType:%v",
msg.MsgType, msg.ReceiveUserId, name, msg.Message, msg.SourceId, msg.SourceType))
}
//保查审核日志
func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) {
var (
message string
ok bool
)
if message, ok = protocol.ApproveLog[code]; !ok {
err = fmt.Errorf("approve log not exists code:%v", code)
return
}
message = fmt.Sprintf(message, param...)
if _, err = orm.Insert(&models.AuditFlowLog{
ChanceId: chanceId,
Content: message,
ApproveUserId: userId,
CreateAt: time.Now(),
Code: code,
}); err != nil {
log.Error(err)
}
log.Debug(fmt.Sprintf("保存审核日志: code:%v userId:%v chanceId:%v message:%v", code, userId, chanceId, message))
return
}
... ...
package agg
import (
"encoding/json"
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
)
//模块编号
const (
M_ENTERPRISE string = "ENTERPRISE" //企业基础设置
M_SYSTEM string = "SYSTEM" //系统设置
M_SYSTEM_OPPORTUNITY string = "SYSTEM_OPPORTUNITY" //机会管理
M_ENTERPRISE_PROFILE string = "ENTERPRISE_PROFILE" //企业信息维护
M_ENTERPRISE_ORGANIZATION string = "ENTERPRISE_ORGANIZATION" //组织架构设置
M_ENTERPRISE_EMPLOYEE_POST string = "ENTERPRISE_EMPLOYEE-POST" //员工职位设置
M_ENTERPRISE_EMPLOYEE_ROLE string = "ENTERPRISE_EMPLOYEE-ROLE" //员工角色/权限设置
M_ENTERPRISE_EMPLOYEE string = "ENTERPRISE_EMPLOYEE" //员工设置
M_SYSTEM_OPPORTUNITY_TEMPLATE string = "SYSTEM_OPPORTUNITY-TEMPLATE" //机会模板管理
M_SYSTEM_RATING string = "SYSTEM_RATING" //评分模式设置
M_SYSTEM_ANNOUNCEMENT string = "SYSTEM_ANNOUNCEMENT" //公告管理
)
type CodeToObject func() PermissionOptionObject
var CodePermissionObject = map[string]CodeToObject{
M_ENTERPRISE_ORGANIZATION: NewPermissionOptionBase, //公司组织架构设置
M_ENTERPRISE_EMPLOYEE_POST: NewPermissionOptionBase, //公司职务管理
M_ENTERPRISE_EMPLOYEE_ROLE: NewPermissionOptionBase, //员工角色/权限设置
M_ENTERPRISE_EMPLOYEE: NewPermissionOptionBase, //公司员工管理
M_ENTERPRISE: NewPermissionOptionBase, //企业基础设置(大节点)
M_SYSTEM: NewPermissionOptionBase, //系统设置(大节点)
M_ENTERPRISE_PROFILE: NewPermissionOptionBase, //企业信息维护
M_SYSTEM_OPPORTUNITY_TEMPLATE: NewPermissionOptionBase, //机会模板管理
M_SYSTEM_RATING: NewPermissionOptionBase, //评分模式
M_SYSTEM_OPPORTUNITY: NewOptionOpportunity, //机会管理
M_SYSTEM_ANNOUNCEMENT: NewPermissionOptionBase, //公告管理
}
type PermissionOptionObject interface {
// StringUnmarshal(string) error
// ObjectMarshal() string
GetValidFunc(string) func(UserObject) bool
MergeObject(string) error
}
type UserObject struct {
UserId int64 `json:"user_id"`
CompanyId int64 `json:"company_id"`
UserCompanyId int64 `json:"user_company_id"`
}
//PermissionOptionBase 基本权限
type PermissionOptionBase struct {
Check int8 `json:"check"`
}
var (
_ PermissionOptionObject = &PermissionOptionBase{}
)
func NewPermissionOptionBase() PermissionOptionObject {
return &PermissionOptionBase{
Check: 1,
}
}
func (p *PermissionOptionBase) ValidDefault(obj UserObject) bool {
if p.Check == 1 {
return true
}
return false
}
//GetValidFunc PermissionOptionBase 接口实现
func (p *PermissionOptionBase) GetValidFunc(k string) func(UserObject) bool {
m := map[string]func(UserObject) bool{
"default": p.ValidDefault,
}
if _, ok := m[k]; ok {
return m[k]
}
return nil
}
func (p *PermissionOptionBase) MergeObject(jsonString string) error {
var obj PermissionOptionBase
err := json.Unmarshal([]byte(jsonString), &obj)
if err != nil {
return err
}
if obj.Check > p.Check {
p.Check = obj.Check
}
return nil
}
// //StringUnmarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) StringUnmarshal(s string) error {
// err := json.Unmarshal([]byte(s), p)
// return err
// }
// //ObjectMarshal PermissionOptionBase 接口实现
// func (p *PermissionOptionBase) ObjectMarshal() string {
// bt, err := json.Marshal(p)
// if err != nil {
// return ""
// }
// return string(bt)
// }
/*
机会管理模块
CheckOpp
CheckDeparment
OptionOpportunity
*/
//CheckDeparment 特殊的查看条件设定中关于部门的设定
type CheckDeparment struct {
Id int64 `json:"id"`
Name string `json:"name,omitempty"`
Wait int `json:"wait"`
OpenAll int `json:"open_all"`
OpenDepart int `json:"open_depart"`
}
//CheckOpp 特殊的查看条件设定
type CheckOpp struct {
Departments []CheckDeparment `json:"departments"`
}
//OptionOpportunity 机会管理 高级权限设置
type OptionOpportunity struct {
Check int `json:"check"`
CheckMap map[int]int `json:"-"`
CheckOption CheckOpp `json:"check_option"`
EditSorce int `json:"edit_sorce"`
EditPublicStatus int `json:"edit_public_status"`
CloseChance int `json:"close_chance"`
EditChance int `json:"edit_chance"`
}
/*
机会管理高级设置中的 check
1:禁止查看所有机会:禁止查看所有机会(除自己提交过的机会及可执行审核操作的机会)
2:仅查看自己部门和公开机会:查看对自己部门公开的机会+公司公开的机会
3:特定部门的机会:自由配置选定部门的待审核、公司公开、部门公开的机会+查看对自己部门公开的机会
4:查看所有机会:查看所有部门的待审核机会、公开机会及部门公开机会
*/
const (
OpportunityCheckLv1 int = 1
OpportunityCheckLv2 int = 2
OpportunityCheckLv3 int = 3
OpportunityCheckLv4 int = 4
)
var (
_ PermissionOptionObject = &OptionOpportunity{}
)
func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
Check: OpportunityCheckLv4,
CheckMap: make(map[int]int),
CheckOption: CheckOpp{
Departments: []CheckDeparment{},
},
}
}
//GetValidFunc PermissionOptionBase 接口实现
func (p *OptionOpportunity) GetValidFunc(k string) func(UserObject) bool {
m := map[string]func(UserObject) bool{
"check": p.ValidCheck,
}
if _, ok := m[k]; ok {
return m[k]
}
return nil
}
//MergeObject PermissionOptionBase 接口实现
func (p *OptionOpportunity) MergeObject(jsonString string) error {
var obj OptionOpportunity
err := json.Unmarshal([]byte(jsonString), &obj)
if err != nil {
return err
}
if p.CheckMap == nil {
p.CheckMap = make(map[int]int)
}
p.CheckMap[obj.Check] = 1
departMap := make(map[int64]*CheckDeparment)
for k := range p.CheckOption.Departments {
i := p.CheckOption.Departments[k].Id
departMap[i] = &p.CheckOption.Departments[k]
}
//列表合并
for k := range obj.CheckOption.Departments {
i := obj.CheckOption.Departments[k].Id
if _, ok := departMap[i]; ok {
if obj.CheckOption.Departments[k].OpenAll > departMap[i].OpenAll {
departMap[i].OpenAll = obj.CheckOption.Departments[k].OpenAll
}
if obj.CheckOption.Departments[k].OpenDepart > departMap[i].OpenDepart {
departMap[i].OpenDepart = obj.CheckOption.Departments[k].OpenDepart
}
if obj.CheckOption.Departments[k].Wait > departMap[i].Wait {
departMap[i].Wait = obj.CheckOption.Departments[k].Wait
}
} else {
departMap[i] = &obj.CheckOption.Departments[k]
}
}
p.CheckOption.Departments = make([]CheckDeparment, 0)
for k := range departMap {
p.CheckOption.Departments = append(p.CheckOption.Departments, *departMap[k])
}
if obj.CloseChance > p.CloseChance {
p.CloseChance = obj.CloseChance
}
if obj.EditPublicStatus > p.EditPublicStatus {
p.EditPublicStatus = obj.EditPublicStatus
}
if obj.EditSorce > p.EditSorce {
p.EditSorce = obj.EditSorce
}
if obj.EditChance > p.EditChance {
p.EditChance = obj.EditChance
}
return nil
}
func (p *OptionOpportunity) ValidCheck(obj UserObject) bool {
if p.Check > 0 {
return true
}
return false
}
func (p *OptionOpportunity) ValidEditSorce(obj UserObject) bool {
if p.EditSorce > 0 {
return true
}
return false
}
func (p *OptionOpportunity) ValidEditPublicStatus(obj UserObject) bool {
if p.EditPublicStatus > 0 {
return true
}
return false
}
func GetUserPermission(userCompanyid int64) (map[string]PermissionOptionObject, error) {
type CodeOpptionData struct {
Code string `orm:"column(code)"`
Opption string `orm:"column(opption)"`
}
const datasql string = `SELECT a.code,a.opption
FROM role_menu AS a
JOIN user_role AS b ON a.role_id = b.role_id
JOIN role AS c ON a.role_id = c.id
WHERE b.user_company_id=? AND c.delete_at =0`
var (
data []CodeOpptionData
err error
objMap = make(map[string]PermissionOptionObject)
)
err = utils.ExecuteQueryAll(&data, datasql, userCompanyid)
if err != nil {
e := fmt.Errorf("EXCUTE SQL ERR:%s", err)
return nil, e
}
for _, v := range data {
if _, ok := objMap[v.Code]; ok {
err = objMap[v.Code].MergeObject(v.Opption)
if err != nil {
log.Warn(err.Error())
}
continue
}
if fn, ok := CodePermissionObject[v.Code]; ok {
obj := fn()
if err = json.Unmarshal([]byte(v.Opption), obj); err != nil {
log.Debug("解析权限配置option 失败%s", err)
}
objMap[v.Code] = obj
} else {
log.Error("未知code:%s", v.Code)
}
}
return objMap, nil
}
... ...
... ... @@ -15,6 +15,7 @@ import (
"opp/models"
"opp/protocol"
"opp/services/agg"
"strings"
"time"
)
... ... @@ -320,6 +321,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
{
mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
mapProcess["ApproveTime"] = time.Now()
mapProcess["IsActive"] = int8(0)
mapChance["ApproveTime"] = time.Now()
if request.ReviewStatus == protocol.ReviewStatusPass {
mapProcess["BasicScore"] = request.ApproveData.Score.BasicScore
mapProcess["ExtraScore"] = request.ApproveData.Score.ExtraScore
... ... @@ -408,6 +411,11 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
}
}
}
if err = saveApproveMsgByApproveData(orm, request.ReviewStatus, chance, request.ApproveData); err != nil {
orm.Rollback()
log.Error("发送审核日志失败", err)
return
}
if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
orm.Rollback()
... ... @@ -465,6 +473,40 @@ func ProcessIntegrate(header *protocol.RequestHeader, request *ProcessIntegrateR
return
}
//发送审核日志
func saveApproveMsgByApproveData(orm orm.Ormer, reviewStatus int, chance *models.Chance, approveData protocol.ApproveData) (err error) {
var (
parames = make([]interface{}, 0)
code = 0
)
if reviewStatus == protocol.ReviewStatusReturn {
//发送退回日志
code = 3
}
if reviewStatus == protocol.ReviewStatusPass {
//发送通过日志
score := approveData.Score
parames = append(parames, []interface{}{score.BasicScore, score.ExtraScore, score.ValueScore}...)
if approveData.PublicData.PublishStatus == protocol.PublicToCompany {
code = 4
}
if approveData.PublicData.PublishStatus == protocol.PublicToDepartment {
code = 5
var department []string
for i := range approveData.PublicData.VisibleObjects {
v := approveData.PublicData.VisibleObjects[i]
department = append(department, v.Name)
}
parames = append(parames, strings.Join(department, ","))
}
}
if err = agg.SaveApproveLog(orm, code, chance.UserId, chance.Id, parames...); err != nil {
log.Error(err)
return
}
return
}
//系统审核状态转为审核类型 reviewStatus - > approveType
func ConverReviewStatus(reviewStatus int) (approveType int) {
if reviewStatus == protocol.ReviewStatusPass {
... ... @@ -513,7 +555,7 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
if item.ReviewStatus != protocol.ReviewStatusAuditging {
item.ApproveTime = process.ApproveTime.Unix() * 1000
}
switch item.ApproveWay {
switch item.ApproveType {
case protocol.AuditByDepartmentor:
break
case protocol.AuditByUser:
... ...
... ... @@ -12,6 +12,7 @@ import (
"opp/models"
"opp/protocol"
"opp/services/agg"
"strings"
"time"
)
... ... @@ -76,13 +77,18 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
log.Error(err)
return
}
if request.SourceType == protocol.SourceTypeChance {
message = protocol.MessageZanChance
if chance, err = models.GetChanceById(request.Id); err != nil {
if chance, err = models.GetChanceById(request.ChanceId); err != nil {
log.Error(request.Id, "机会不存在", err)
err = protocol.NewErrWithMessage(5101)
return
}
if request.SourceType == protocol.SourceTypeChance {
message = protocol.MessageZanChance
//if chance, err = models.GetChanceById(request.Id); err != nil {
// log.Error(request.Id, "机会不存在", err)
// err = protocol.NewErrWithMessage(5101)
// return
//}
sourceId = chance.Id
userId = chance.UserId
chanceType = chance.ChanceTypeId
... ... @@ -140,6 +146,7 @@ func SympathyAction(header *protocol.RequestHeader, request *protocol.SympathyAc
ChanceType: chanceType,
CreateAt: time.Now(),
EnableStatus: 1,
ChanceId: request.ChanceId,
}
if _, err = models.AddChanceFavorite(chanceFavoirte); err != nil {
log.Error(err)
... ... @@ -159,7 +166,9 @@ END:
agg.DeleteSendedMsg(sourceId, request.SourceType, userId, protocol.MsgTypeThumbUp)
} else {
//发送点赞消息
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, 1, message, protocol.MsgTypeThumbUp)
if header.UserId != userId {
agg.SendMsg(userId, fmt.Sprintf("%v", userId), header.CompanyId, request.Id, request.SourceType, message, protocol.MsgTypeThumbUp, request.ChanceId)
}
}
if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSql(table, "zan_total", incre, request.Id)) {
//
... ... @@ -336,6 +345,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
AuditLevel: 1,
ReviewStatus: protocol.ReviewStatusAuditging,
DepartmentId: request.RelatedDepartment,
Code: fmt.Sprintf("%v%v", chanceType.Code, template.Code),
}
if _, err = orm.Insert(chance); err != nil {
log.Error(err)
... ... @@ -403,6 +413,12 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
return
}
}
//发送提交日志
if err = agg.SaveApproveLog(orm, 1, header.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
rsp = &protocol.ChanceSubmitResponse{}
... ... @@ -448,14 +464,19 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
//}
if _, e := models.GetAuditFlowProcessByReview(request.Id, 0, protocol.ReviewStatusWait); e == nil {
request.IsPublish = true
updateMap["DepartmentId"] = request.RelatedDepartment
//log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v",request.IsPublish,chance.ReviewStatus,chance.UserId==header.UserId))
} else {
log.Info(fmt.Sprintf("机会编辑 chance_id:%v chance.review_status:%v 无待处理 审核数据", request.Id, chance.ReviewStatus))
}
} else {
request.IsPublish = false
log.Info(fmt.Sprintf("机会编辑 is_publish:%v chance.review_status:%v 是否是本人:%v", request.IsPublish, chance.ReviewStatus, chance.UserId == header.UserId))
}
//TODO:非本人 1.需要验证角色权限 2是否是审核人 3.是否是本人 (目前本人才可以审核)
if chance.UserId != header.Uid {
if chance.UserId != header.UserId {
err = protocol.NewErrWithMessage(5206)
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.Uid, chance.Id))
log.Error(fmt.Sprintf("user:%v 无权限操作机会 chance:%v", header.UserId, chance.Id))
return
}
//1.模板是否存在
... ... @@ -474,7 +495,6 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
updateMap["AuditTemplateConfig"] = common.AssertJson(auditConfig)
updateMap["Content"] = request.Content
updateMap["SourceContent"] = common.AssertJson(request.FormList)
updateMap["DepartmentId"] = request.RelatedDepartment
if err = utils.UpdateTableByMapWithOrmer(orm, &models.Chance{Id: chance.Id}, updateMap); err != nil {
log.Error(err)
... ... @@ -560,6 +580,12 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate
}
}
}
//发送提交日志
if err = agg.SaveApproveLog(orm, 1, chance.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
}
}
orm.Commit()
... ... @@ -620,12 +646,43 @@ func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.Chanc
}
}
}
if err = saveApproveMsgChangePublic(orm, chance, request.PublicData); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
//TODO:添加log
rsp = &protocol.ChanceChangePublishResponse{}
return
}
//发送审核日志
func saveApproveMsgChangePublic(orm orm.Ormer, chance *models.Chance, approveData protocol.PublicData) (err error) {
var (
parames = make([]interface{}, 0)
code = 0
)
if approveData.PublishStatus == protocol.PublicToCompany {
code = 7
}
if approveData.PublishStatus == protocol.PublicToDepartment {
code = 8
var department []string
for i := range approveData.VisibleObjects {
v := approveData.VisibleObjects[i]
department = append(department, v.Name)
}
parames = append(parames, strings.Join(department, ","))
}
if err = agg.SaveApproveLog(orm, code, chance.UserId, chance.Id, parames...); err != nil {
log.Error(err)
return
}
return
}
//修改评分
func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceChangeScoreRequest) (rsp *protocol.ChanceChangeScoreResponse, err error) {
var (
... ... @@ -667,6 +724,17 @@ func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceC
orm.Rollback()
return
}
//修改评分日志
if err = agg.SaveApproveLog(orm, 9, chance.UserId, chance.Id, request.Score.BasicScore, request.Score.ExtraScore, request.Score.ValueScore); err != nil {
log.Error(err)
return
}
//if err = agg.SaveApproveLog(orm,9,chance.UserId,chance.Id,request.Score.BasicScore,request.Score.ExtraScore,request.Score.ValueScore);err!=nil{
// log.Error(err)
// return
//}
orm.Commit()
rsp = &protocol.ChanceChangeScoreResponse{
DiscoveryScore: result.DiscoveryScore,
... ... @@ -781,6 +849,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
approver *models.User
roleIds []int
roleId int
admin *models.UserCompany
)
if configs, err = models.GetAuditFlowConfigsLevel(templateId, 1); err != nil {
if err == orm.ErrNoRows {
... ... @@ -842,8 +911,16 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
if company.AdminId == 0 {
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
err = protocol.NewErrWithMessage(5207)
return
}
if admin, err = models.GetUserCompanyByUserId(company.AdminId, header.CompanyId); err != nil {
err = fmt.Errorf("GenAuditFlowProcess:company.admin is not set")
err = protocol.NewErrWithMessage(5207)
return
}
//3.生成审核列表
for i := range configs {
config := configs[i]
... ... @@ -882,14 +959,14 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, related
for j := 0; j < len(userIds); j++ {
uid := userIds[j]
if uid == 0 && auditConfig.NoApprover == protocol.NoApproverToAdmin { //审批人为空 转交给管理员
uid = company.AdminId
uid = admin.Id
}
if uid == 0 {
uid = company.AdminId
uid = admin.Id
}
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
uid = admin.Id
}
if approver, err = models.GetUserByUcid(uid); err != nil {
log.Error(uid, err)
... ... @@ -935,6 +1012,7 @@ func resolveActionType(t uint) string {
func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) {
var (
departments *models.Department
lastDepartmentId int
)
//if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil {
// log.Error(header.UserId,header.CompanyId,err)
... ... @@ -944,19 +1022,37 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64)
log.Error(relatedDeparmentId, err)
return
}
//部门长
for {
if len(departments.Managers) > 0 {
var tmpIds []int64
if err = json.Unmarshal([]byte(departments.Managers), &tmpIds); err == nil {
if e := json.Unmarshal([]byte(departments.Managers), &tmpIds); e == nil {
if len(tmpIds) > 0 {
ids = append(ids, tmpIds...)
}
break
} else {
log.Error(e)
}
//break
}
if departments.ParentId != 0 {
//relatedDeparmentId = int64departments.ParentId
lastDepartmentId = departments.ParentId
if departments, err = models.GetDepartmentById(int(departments.ParentId)); err != nil {
log.Error(relatedDeparmentId, err)
err = nil
break
}
} else {
break
}
}
//部门长不存在
if len(ids) == 0 {
ids = append(ids, 0)
}
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v", relatedDeparmentId, departments.Managers, ids))
log.Info(fmt.Sprintf("生成机会审批流-部门:department_id:%v managers:%v ids:%v last_department_id:%v", relatedDeparmentId, departments.Managers, ids, lastDepartmentId))
return
}
... ... @@ -1060,6 +1156,11 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
Id: chance.Id,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ApproveTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
... ... @@ -1187,8 +1288,15 @@ func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApprove
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
UpdateTime: chance.UpdateTime.Unix() * 1000,
ApproveTime: chance.ChanceApproveTime.Unix() * 1000,
//CreateTime:chance.c
//CreateTime: chance.CreateTime.Unix() * 1000,
}
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
... ... @@ -1287,6 +1395,7 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
Id: chance.CollectId,
CollectTime: chance.CollectTime.Unix() * 1000,
}
//commItem.ChanceId = chance.ChanceId
}
rsp.List = append(rsp.List, commItem)
}
... ... @@ -1614,15 +1723,26 @@ func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDelete
err = protocol.NewErrWithMessage(5202)
return
}
if err = utils.UpdateTableByMap(chance, map[string]interface{}{
orm := orm.NewOrm()
orm.Begin()
//发送提交日志
if err = agg.SaveApproveLog(orm, 2, chance.UserId, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
if err = utils.UpdateTableByMapWithOrmer(orm, chance, map[string]interface{}{
"EnableStatus": int8(0),
}); err != nil {
log.Error(err)
orm.Rollback()
return
}
if err = models.CloseAuditFlowProcess(chance.Id); err != nil {
if err = models.CloseAuditFlowProcess(orm, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
orm.Commit()
return
}
... ...
... ... @@ -74,7 +74,7 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest)
return
}
}
if err = agg.SendMsg(recevierId, "", header.CompanyId, sourceId, request.SourceType, request.Content, protocol.MsgTypeComment); err != nil {
if err = agg.SendMsg(recevierId, "", header.CompanyId, sourceId, request.SourceType, request.Content, protocol.MsgTypeComment, request.Id); err != nil {
log.Error(err)
orm.Rollback()
return
... ... @@ -140,6 +140,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
}
rsp = &protocol.CommentsResponse{
Total: total,
Comments: make([]*protocol.Comments, 0),
}
for i := range comments {
comment := comments[i]
... ... @@ -155,9 +156,10 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest)
ViewTotal: comment.ViewTotal,
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
IsZan: false,
}
if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists {
item.IsZan = 1
item.IsZan = true
}
rsp.Comments = append(rsp.Comments, item)
}
... ... @@ -221,9 +223,10 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm
ViewTotal: comment.ViewTotal,
ZanTotal: comment.ZanTotal,
CommentTotal: comment.CommentTotal,
IsZan: false,
}
if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists {
rsp.Comment.IsZan = 1
rsp.Comment.IsZan = true
}
return
}
... ...
... ... @@ -15,9 +15,43 @@ import (
)
func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCenterRequest) (rsp *protocol.MessageCenterResponse, err error) {
var ()
var (
list []*protocol.MessageTotal
interactionCount int
)
rsp = &protocol.MessageCenterResponse{}
if request.MsgType&protocol.MsgTypeInteraction > 0 {
if request.MsgType&protocol.MsgTypeThumbUp == 0 {
request.MsgType |= protocol.MsgTypeThumbUp
}
if request.MsgType&protocol.MsgTypeComment == 0 {
request.MsgType |= protocol.MsgTypeComment
}
if request.MsgType&protocol.MsgTypeAuditBy == 0 {
request.MsgType |= protocol.MsgTypeAuditBy
}
}
err = models.GetUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &rsp.Totals)
for i := range rsp.Totals {
item := rsp.Totals[i]
if item.MsgType == protocol.MsgTypeThumbUp {
interactionCount += item.MsgTotal
continue
}
if item.MsgType == protocol.MsgTypeComment {
interactionCount += item.MsgTotal
continue
}
if item.MsgType == protocol.MsgTypeAuditBy {
interactionCount += item.MsgTotal
continue
}
list = append(list, item)
}
if interactionCount > 0 {
list = append(list, &protocol.MessageTotal{MsgType: protocol.MsgTypeInteraction, MsgTotal: interactionCount})
}
rsp.Totals = list
return
}
... ... @@ -215,13 +249,14 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
rsp = &protocol.MsgChanceApproveResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
... ... @@ -239,7 +274,6 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
var approveData *protocol.ApproveData
... ... @@ -248,8 +282,11 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
commItem.Score = approveData.Score
}
}
commItem.MsgId = chance.Id
//审核完有审核数据
commItem.Message = chance.Message
commItem.IsRead = chance.IsRead == 1
commItem.ChanceId = chance.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -273,13 +310,14 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
rsp = &protocol.MsgChanceSubmitResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
... ... @@ -297,7 +335,6 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
var approveData *protocol.ApproveData
... ... @@ -306,8 +343,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
commItem.Score = approveData.Score
}
}
commItem.IsRead = chance.IsRead == 1
//审核完有审核数据
commItem.Message = chance.Message
commItem.MsgId = chance.Id
commItem.ChanceId = chance.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -331,7 +371,7 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
rsp = &protocol.MsgChanceCommentResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
... ... @@ -360,10 +400,16 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
commItem.CommentData = protocol.CommentData{
... ... @@ -371,7 +417,10 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
}
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.ChanceId = chance.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -395,14 +444,15 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
rsp = &protocol.MsgChanceThumbUpResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
commItem := protocol.CommonListItem{}
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
} else {
}
if provider, err = agg.GetUserBaseInfo(chance.Uid, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
... ... @@ -420,14 +470,19 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
commItem.ThumbUpData = protocol.ThumbUpData{
... ... @@ -435,7 +490,10 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
ThumbUpTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
}
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.ChanceId = chance.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ...
... ... @@ -89,7 +89,7 @@ func UploadFile(request *protocol.FileRequest) (rsp *protocol.FileResponse, err
log.Error(err)
return
}
rsp.Paths = append(rsp.Paths, filepath.Join(virtualPath, filename))
rsp.Paths = append(rsp.Paths, virtualPath+"/"+filename)
ResizeImage(request.FileType, sourcePath, prefix, subfix, f)
}
return
... ...