作者 唐旭辉

新增接口

... ... @@ -6,6 +6,7 @@ import (
"oppmg/common/log"
"oppmg/protocol"
servecommon "oppmg/services/common"
serverbac "oppmg/services/rbac"
)
//公共接口
... ... @@ -162,3 +163,23 @@ func (c *CommonController) DefaultImage() {
msg = protocol.NewReturnResponse(data, nil)
return
}
func (c *CommonController) SelectorRoleUser() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
RoleId int64 `json:"role_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
list, err := serverbac.GetRoleHasRole(param.RoleId, companyid)
msg = protocol.NewReturnResponse(list, err)
return
}
... ...
... ... @@ -30,16 +30,7 @@ func (c *MyController) ResetPassword() {
msg = protocol.BadRequestParam("1")
return
}
companyid := c.GetCompanyId()
userId := c.GetUserId()
if companyid <= 0 {
msg = protocol.BadRequestParam("1")
return
}
if userId <= 0 {
msg = protocol.BadRequestParam("1")
return
}
err := usermy.ResetPasswordBySms(param.Phone, param.NewPwd, param.ConfirmPwd)
msg = protocol.NewReturnResponse(nil, err)
return
... ...
... ... @@ -59,3 +59,8 @@ type UserInfoBase struct {
Phone string `json:"phone"`
Status int8 `json:"status"`
}
type RoleHasUser struct {
UserCompanyId int64 `json:"user_company_id" orm:"column(user_company_id)"`
Name string `json:"name" orm:"column(nick_name)"`
}
... ...
... ... @@ -74,6 +74,7 @@ func init() {
beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
beego.NSRouter("/user_and_department", &controllers.CommonController{}, "post:SelectorUserAndDepart"),
beego.NSRouter("/default_image", &controllers.CommonController{}, "post:DefaultImage"),
beego.NSRouter("/role/user", &controllers.CommonController{}, "post:SelectorRoleUser"),
),
beego.NSNamespace("/template",
beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
... ... @@ -91,9 +92,7 @@ func init() {
beego.NSNamespace("/upload",
beego.NSRouter("/image", &controllers.UploadController{}, "post:UploadImage"),
),
beego.NSNamespace("/my",
beego.NSRouter("/reset_password", &controllers.MyController{}, "post:ResetPassword"),
),
beego.NSNamespace("/config",
beego.NSRouter("/score", &controllers.ConfigController{}, "post:ConfigScore"),
beego.NSRouter("/score/get", &controllers.ConfigController{}, "post:GetConfigScore"),
... ... @@ -112,6 +111,7 @@ func init() {
beego.NSRouter("/login_sms", &controllers.AuthController{}, "post:LoginSms"),
beego.NSRouter("/sms_code", &controllers.AuthController{}, "post:SmsCode"),
beego.NSRouter("/sms_code/check", &controllers.AuthController{}, "post:SmsCodeCheck"),
beego.NSRouter("/reset_password", &controllers.MyController{}, "post:ResetPassword"),
)
nsUcenter := beego.NewNamespace("/ucenter",
beego.NSBefore(middleware.LogRequestData),
... ...
... ... @@ -6,15 +6,17 @@ import (
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
)
type SqlData struct {
Id int64 `orm:"column(id)"`
UserId int64 `orm:"column(user_id)"`
DepartmentId int64 `orm:"column(department_id)"`
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);type(timestamp)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)"`
ReviewStatus int `orm:"column(review_status)"`
EnableStatus int `orm:"column(enable_status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
... ... @@ -39,7 +41,7 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re
List: make([]protocol.RspAuditList, 0),
}
dataStart := (param.PageIndex - 1) * param.PageSize
datasql.WriteString(`SELECT user_id,department_id,audit_template_id,chance_type_id
datasql.WriteString(`SELECT id,user_id,department_id,audit_template_id,chance_type_id
,publish_status,create_at,review_status,enable_status
,discovery_score,comment_total
FROM chance
... ... @@ -60,7 +62,17 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re
return returnData, nil
}
for _, v := range data {
item := protocol.RspAuditList{}
t := v.CreateAt.Unix()
item := protocol.RspAuditList{
Id: v.Id,
EnableStatus: v.EnableStatus,
PublishStatus: v.PublishStatus,
}
if t < 0 {
item.CreateTime = 0
} else {
item.CreateTime = t
}
if u, err := models.GetUserById(v.UserId); err == nil {
item.UserName = u.NickName
}
... ... @@ -71,7 +83,6 @@ func GetAuditList(param protocol.RequestAuditList, companyid int64) (protocol.Re
item.TemplateName = at.Name
item.Code = at.Code
}
if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil {
item.ChanceType = ct.Name
}
... ...
... ... @@ -6,6 +6,7 @@ import (
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
)
... ... @@ -305,3 +306,40 @@ func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) {
err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP)
return roles, err
}
func GetRoleHasRole(roleid int64, companyid int64) ([]protocol.RoleHasUser, error) {
var (
roleinfo *models.Role
err error
roleuserlist = make([]protocol.RoleHasUser, 0)
)
roleinfo, err = models.GetRoleById(roleid)
if err != nil {
log.Error("获取角色数据失败:%s", err)
return roleuserlist, protocol.NewErrWithMessage("1")
}
if roleinfo.CompanyId != companyid {
log.Error("角色公司不匹配")
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(?)`
)
err = utils.ExecuteQueryAll(&ucid, datasql, 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)
}
return roleuserlist, nil
}
... ...