作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !1
... ... @@ -2,11 +2,13 @@ package controllers
import (
"encoding/json"
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
serveaudit "oppmg/services/audit"
servecommon "oppmg/services/common"
serverbac "oppmg/services/rbac"
"strconv"
"time"
)
... ... @@ -23,22 +25,32 @@ func (c *AuditController) AuditList() {
c.ResposeJson(msg)
}()
var param protocol.RequestAuditList
param.Status = -1
param.ReviewStatus = -1
param.PublishStatus = -1
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
beginTime, err := time.Parse("2006-01-02", param.CreateTimeBeginS)
beginTime, err := time.ParseInLocation("2006-01-02", param.CreateTimeBeginS, time.Local)
if err == nil && len(param.CreateTimeBeginS) > 0 {
param.CreateTimeBegin = beginTime.Unix()
}
endTime, err := time.Parse("2006-01-02", param.CreateTimeEndS)
endTime, err := time.ParseInLocation("2006-01-02", param.CreateTimeEndS, time.Local)
if err == nil && len(param.CreateTimeEndS) > 0 {
param.CreateTimeEnd = endTime.Unix() + 864399
param.CreateTimeEnd = endTime.Unix() + 86399
}
fmt.Println(err, param.CreateTimeBegin, param.CreateTimeEnd)
if len(param.StatusS) > 0 {
param.Status, _ = strconv.Atoi(param.StatusS)
}
if len(param.ReviewStatusS) > 0 {
param.ReviewStatus, _ = strconv.Atoi(param.ReviewStatusS)
}
if len(param.PublishStatusS) > 0 {
param.PublishStatus, _ = strconv.Atoi(param.PublishStatusS)
}
param.Status, _ = strconv.Atoi(param.StatusS)
param.ReviewStatus, _ = strconv.Atoi(param.ReviewStatusS)
param.PublishStatus, _ = strconv.Atoi(param.PublishStatusS)
uid := c.GetUserId()
companyId := c.GetCompanyId()
list, err := serveaudit.GetAuditList(param, companyId, uid)
... ... @@ -53,7 +65,7 @@ func (c *AuditController) AuditListBefore() {
defer func() {
c.ResposeJson(msg)
}()
// uid := c.GetUserId()
uid := c.GetUserId()
companyId := c.GetCompanyId()
templatelist := servecommon.SelectGetTemplateList(companyId)
chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
... ... @@ -61,6 +73,10 @@ func (c *AuditController) AuditListBefore() {
publicStatus := models.ChancePublishStatusMap
Status := models.ChanceStatusMap
reviewStatus := models.ChanceReviewStatusMap
var (
auditPermission serverbac.OptionOpportunity
)
auditPermission = serveaudit.GetPermissionInAuditPage(uid, companyId)
data := map[string]interface{}{
"template": templatelist,
"chance_type": chanceTypeList,
... ... @@ -68,6 +84,7 @@ func (c *AuditController) AuditListBefore() {
"enable_status": Status,
"review_status": reviewStatus,
"department": departmentList,
"permission": auditPermission,
}
msg = protocol.NewReturnResponse(data, nil)
return
... ...
... ... @@ -104,10 +104,10 @@ func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error)
return
}
func GetAuditTemplateByCode(companyId int64, code string) (v *ChanceType, err error) {
func GetAuditTemplateByCode(companyId int64, code string, chanceTypeId int) (v *ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where binary code=? and company_id=?"
if err = o.Raw(sql, code, companyId).QueryRow(&v); err == nil {
sql := "select * from audit_template where binary code=? and company_id=? and chance_type_id=?"
if err = o.Raw(sql, code, companyId, chanceTypeId).QueryRow(&v); err == nil {
return
}
return
... ...
... ... @@ -56,8 +56,8 @@ func GetBulletinById(id int) (v *Bulletin, err error) {
// UpdateBulletin updates Bulletin by Id and returns error if
// the record to be updated doesn't exist
func UpdateBulletinById(m *Bulletin) (err error) {
o := orm.NewOrm()
func UpdateBulletinById(o orm.Ormer, m *Bulletin) (err error) {
//o := orm.NewOrm()
v := Bulletin{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
... ...
... ... @@ -46,8 +46,8 @@ func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) {
// UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if
// the record to be updated doesn't exist
func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {
o := orm.NewOrm()
func UpdateBulletinQuestionById(o orm.Ormer, m *BulletinQuestion) (err error) {
//o := orm.NewOrm()
v := BulletinQuestion{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
... ...
... ... @@ -33,8 +33,15 @@ const (
SourceTypeBulletin = 3
)
//列表是否展示(公告列表)
const (
SqlDeleteUserMsg = "delete from user_msg where company_id=? and msg_type=? and source_id=?"
Public = 1 //公开
NoPublic = 0 //不公开
)
const (
SqlDeleteUserMsg = "delete from user_msg where company_id=? and msg_type=? and source_id=?"
SqlUpdateUserMsgPublic = "update user_msg set is_public=? where company_id=? and msg_type=? and source_id=?"
)
func (t *UserMsg) TableName() string {
... ... @@ -94,6 +101,17 @@ func DeleteUserMsg(id int64) (err error) {
return
}
//获取userMsg
func GetUserMsgBy(userCompanyId int64, msgType int, sourceType int, sourceId int64) (v *UserMsg, err error) {
sql := "select * from user_msg where receive_user_id=? and msg_type=? and source_type=? and source_id=?"
o := orm.NewOrm()
if err = o.Raw(sql, userCompanyId, msgType, sourceType, sourceId).QueryRow(&v); err != nil {
//log.Error(err.Error())
return
}
return
}
func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sourceId int64, message string) *UserMsg {
return &UserMsg{
Id: utils.GenerateIDBySonyflake(),
... ... @@ -104,5 +122,6 @@ func NewUserMsg(companId, userCompanyId int64, msgType int, sourceType int, sour
SourceId: sourceId,
Message: message,
CreateAt: time.Now(),
IsPublic: Public,
}
}
... ...
... ... @@ -237,7 +237,7 @@ type RequestAuditList struct {
ReviewStatus int `json:"-"` //
ReviewStatusS string `json:"review_status"` //
Status int `json:"-"` //关闭状态
StatusS string `json:"enable_status"` //关闭状态
StatusS string `json:"status"` //关闭状态
DepartmentID int `json:"department_id"` //提交部门
CreateTimeBegin int64 `json:"-"` //
CreateTimeBeginS string `json:"create_time_begin"`
... ...
... ... @@ -2,6 +2,7 @@ package audit
import (
"encoding/json"
"errors"
"fmt"
"oppmg/common/log"
"oppmg/models"
... ... @@ -21,7 +22,7 @@ type SqlData struct {
AuditTemplateId int64 `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
PublishStatus int `orm:"column(publish_status)"`
CreateAt string `orm:"column(create_at)`
CreateAt string `orm:"column(create_at)"`
ReviewStatus int8 `orm:"column(review_status)"`
Status int8 `orm:"column(status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
... ... @@ -29,6 +30,35 @@ type SqlData struct {
Code string `orm:"column(code)"`
}
func getAuditUserHasPermission(userid int64, usercompanyid int64) (
serverabc.PermissionOptionObject, error) {
var permissionObject serverabc.PermissionOptionObject
var err error
if ok := redisdata.ExistUserPermission(userid); !ok {
//尝试重数据库获取
log.Debug("从数据库读取权限")
permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从数据库未获得对应权限 :%s", err)
return nil, err
}
if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
return nil, errors.New("can not found object")
} else {
permissionObject = v
}
} else {
//使用缓存
log.Debug("从缓存读取权限")
permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从缓存未获得对应权限 :%s", err)
return nil, err
}
}
return permissionObject, nil
}
//根据权限获取机会列表
func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) string {
/*
... ... @@ -63,32 +93,38 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st
permissionObject serverabc.PermissionOptionObject
err error
)
//获取权限
if ok := redisdata.ExistUserPermission(userid); !ok {
//尝试重数据库获取
log.Debug("从数据库读取权限")
permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从数据库未获得对应权限 :%s", err)
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
} else {
permissionObject = v
}
} else {
//使用缓存
log.Debug("从缓存读取权限")
permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
if err != nil {
log.Debug("从缓存未获得对应权限 :%s", err)
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
//---------------------------------
if permissionObject, err = getAuditUserHasPermission(userid, usercompanyid); err != nil {
unionsql = sql1 + " UNION " + sql2
return fmt.Sprintf(allsql, unionsql)
}
// //获取权限
// if ok := redisdata.ExistUserPermission(userid); !ok {
// //尝试重数据库获取
// log.Debug("从数据库读取权限")
// permissionMap, err := serverabc.GetUserPermission(usercompanyid, serverabc.M_SYSTEM_OPPORTUNITY)
// if err != nil {
// log.Debug("从数据库未获得对应权限 :%s", err)
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// }
// if v, ok := permissionMap[serverabc.M_SYSTEM_OPPORTUNITY]; !ok {
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// } else {
// permissionObject = v
// }
// } else {
// //使用缓存
// log.Debug("从缓存读取权限")
// permissionObject, err = redisdata.GetUserPermission(userid, serverabc.M_SYSTEM_OPPORTUNITY)
// if err != nil {
// log.Debug("从缓存未获得对应权限 :%s", err)
// unionsql = sql1 + " UNION " + sql2
// return fmt.Sprintf(allsql, unionsql)
// }
// }
// -------------------------
var (
usrPermission *serverabc.OptionOpportunity
ok bool
... ... @@ -475,3 +511,43 @@ func ForbidChanceEnableStatus(chanceid int64, companyid int64) error {
}
return nil
}
//获取用户在机会管理中的权限
func GetPermissionInAuditPage(userid int64, companyid int64) serverabc.OptionOpportunity {
var (
option serverabc.OptionOpportunity
err error
ucompany *models.UserCompany
companyinfo *models.Company
)
companyinfo, err = models.GetCompanyById(companyid)
if err != nil {
log.Error("GetCompanyById err:%s", err)
return option
}
if companyinfo.AdminId == userid {
option = serverabc.OptionOpportunity{
Check: serverabc.OpportunityCheckLv4,
EditSorce: 1,
EditPublicStatus: 1,
CloseChance: 1,
EditChance: 1,
}
return option
}
ucompany, err = models.GetUserCompanyBy(userid, companyid)
if err != nil {
log.Error("获取用户数据失败:GetUserCompanyBy err:%s", err)
return option
}
permissionobj, err := getAuditUserHasPermission(userid, ucompany.Id)
if err != nil {
return option
}
if v, ok := permissionobj.(*serverabc.OptionOpportunity); ok {
option = *v
option.CheckMap = nil
option.CheckOption = nil
}
return option
}
... ...
... ... @@ -30,7 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
err = protocol.NewErrWithMessage("10065")
return
}
if _, err = models.GetAuditTemplateByCode(companyId, request.Template.Code); err == nil {
if _, err = models.GetAuditTemplateByCode(companyId, request.Template.Code, request.Template.ChanceTypeId); err == nil {
err = protocol.NewErrWithMessage("10064")
return
}
... ... @@ -823,7 +823,7 @@ func ValidFormList(inputs []*protocol.InputElement) (msg *protocol.ResponseMessa
msg = protocol.BadRequestParam("10285")
return
}
if countBasic >= 10 || countExtral >= 10 {
if countBasic > 10 || countExtral > 10 {
msg = protocol.BadRequestParam("10274")
return
}
... ...
... ... @@ -200,7 +200,7 @@ func LoginAuthByUCenter(account, password string) (
ucompany, err := models.GetUserCompanyBy(userdata.Id, companyid)
if err != nil {
log.Error("获取user_company失败;%s", err)
return logintoken, protocol.NewErrWithMessage("1")
return logintoken, protocol.NewErrWithMessage("10022")
}
usercompanyid = ucompany.Id
logintoken, _ = GenerateAuthToken(userdata.Id, companyid, usercompanyid)
... ... @@ -528,6 +528,7 @@ func ValidUserPermission(urlPath string, userid int64, companyid int64) bool {
permissionObj, err = redisdata.GetUserPermission(userid, permissionbase.CodeName)
if err != nil {
//尝试从 数据库取权限 TODO
log.Error("未取到权限数据 err:%s", err)
return false
}
... ...
... ... @@ -169,15 +169,24 @@ func sendBulletinUserMsg(orm orm2.Ormer, receivers []protocol.VisibleObject, com
return
}
}
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.Public, companyId, models.MsgTypeBulletin, sourceId); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
for i := range ids {
if _, ok := sended[ids[i]]; ok {
continue
}
sended[ids[i]] = ids[i]
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
if _, err = orm.Insert(msg); err != nil {
log.Error(err.Error())
return
//这条消息不存在,插入一条消息
if _, e := models.GetUserMsgBy(ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId); e != nil && e == orm2.ErrNoRows {
msg := models.NewUserMsg(companyId, ids[i], models.MsgTypeBulletin, models.SourceTypeBulletin, sourceId, message)
if _, err = orm.Insert(msg); err != nil {
orm.Rollback()
log.Error(err.Error())
return
}
}
}
return
... ... @@ -345,6 +354,17 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
log.Error(err.Error())
return
}
orm := orm2.NewOrm()
orm.Begin()
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
}
}
//update
{
bulletin.Title = request.Title
... ... @@ -360,8 +380,10 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
if request.IsPublish == 1 && bulletin.Status == protocol.BulletinUnRelease {
bulletin.Status = protocol.BulletinRelease
}
if err = models.UpdateBulletinById(bulletin); err != nil {
if err = models.UpdateBulletinById(orm, bulletin); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
}
... ... @@ -371,6 +393,7 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
validQuestion(&request.Question)
if err != nil && err != orm2.ErrNoRows {
log.Error(err.Error())
orm.Rollback()
return
}
if err == nil {
... ... @@ -388,8 +411,9 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
bulletinQuestion.Content = string(questionContent)
bulletinQuestion.Type = int8(request.Question.Type)
bulletinQuestion.UpdateAt = time.Now()
if err = models.UpdateBulletinQuestionById(bulletinQuestion); err != nil {
if err = models.UpdateBulletinQuestionById(orm, bulletinQuestion); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
}
... ... @@ -403,22 +427,16 @@ func UpdateBulletin(companyId int64, request *protocol.UpdateBulletinRequest) (r
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
_, err = models.AddBulletinQuestion(bulletinQuestion)
_, err = orm.Insert(bulletinQuestion)
if err != nil {
orm.Rollback()
log.Error("添加问题失败:%s", err)
return
}
}
}
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
}
}
orm.Commit()
return
}
... ... @@ -453,7 +471,7 @@ func OperateBulletin(companyId int64, request *protocol.OperateBulletinRequest)
orm.Begin()
if request.CmdType == protocol.BulletinUnRelease { //下架
status = protocol.BulletinUnRelease
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteUserMsg, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlUpdateUserMsgPublic, models.NoPublic, companyId, models.MsgTypeBulletin, bulletin.Id); err != nil {
log.Error(err.Error())
orm.Rollback()
return
... ...
... ... @@ -477,7 +477,7 @@ func UserDelete(userCompanyids []int64, companyid int64) error {
ids []int64
)
for _, v := range updateIds {
if v.Id == companyInfo.AdminId {
if v.UserId == companyInfo.AdminId {
return protocol.NewErrWithMessage("10071")
}
ids = append(ids, v.Id)
... ...
... ... @@ -123,7 +123,7 @@ var (
func NewOptionOpportunity() PermissionOptionObject {
return &OptionOpportunity{
Check: OpportunityCheckLv1,
Check: OpportunityCheckLv2,
CheckMap: make(map[int]int),
CheckOption: &CheckOpp{
Departments: []CheckDeparment{},
... ...
... ... @@ -6,7 +6,6 @@ import (
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
)
... ... @@ -334,23 +333,19 @@ func GetRoleHasRole(roleid int64, companyid int64) ([]protocol.RoleHasUser, erro
return roleuserlist, protocol.NewErrWithMessage("1")
}
var (
ucid []string
datasql string = `SELECT user_company_id FROM user_role
WHERE company_id=? AND role_id =? AND enable_status = 1`
datasql2 string = `SELECT a.nick_name,b.id AS user_company_id FROM user AS a,user_company AS b
WHERE a.id= b.user_id AND b.id IN(?)`
datasql2 string = `SELECT a.nick_name,b.id AS user_company_id
FROM user AS a
JOIN user_company AS b ON a.id=b.user_id
JOIN user_role AS c ON b.id= c.user_company_id
WHERE c.company_id=?
AND c.role_id =?
AND c.enable_status = 1
AND b.enable = 1 AND b.delete_at = 0 `
)
err = utils.ExecuteQueryAll(&ucid, datasql, companyid, roleid)
err = utils.ExecuteQueryAll(&roleuserlist, datasql2, companyid, roleid)
if err != nil {
log.Error("获取用户id失败:%s", err)
return roleuserlist, protocol.NewErrWithMessage("1")
}
if len(ucid) == 0 {
return roleuserlist, nil
}
err = utils.ExecuteQueryAll(&roleuserlist, datasql2, strings.Join(ucid, ","))
if err != nil {
log.Error("获取用户时间失败;%s", err)
log.Error("获取用户数据失败;%s", err)
}
return roleuserlist, nil
}
... ...