作者 唐旭辉

日常提交

... ... @@ -26,6 +26,7 @@ type MyConfig struct {
var MConfig *MyConfig
func RestMyConfig() *MyConfig {
fmt.Println("初始化config")
mysqlHost := beego.AppConfig.String("mysql_host")
mysqlPort := beego.AppConfig.String("mysql_port")
mysqlUser := beego.AppConfig.String("mysql_user")
... ...
... ... @@ -2,6 +2,7 @@ package log
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/logs"
)
... ... @@ -67,6 +68,7 @@ func (config LoggerFile) Name() string {
var logger *logs.BeeLogger
func ResetLog(config SetLoggerConfig, funcCall bool) {
fmt.Println("初始化log")
logger = logs.GetBeeLogger()
out := config.Name()
logconf := config.MarshalString()
... ...
... ... @@ -2,6 +2,7 @@ package redis
import (
"fmt"
"oppmg/common/log"
"github.com/go-redis/redis"
)
... ... @@ -18,6 +19,7 @@ const (
var RedisClient *redis.Client
func SetRedis(addr string, password string, db int) {
log.Info("初始化redis")
RedisClient = redis.NewClient(&redis.Options{
Addr: addr,
Password: password,
... ...
#app的名称
appname = ability
#运行模式
runmode =${ProRunMode||dev}
runmode =${ProRunMode||local}
#是否自动渲染页面
autorender = false
#是否复制请求body
... ...
... ... @@ -2,32 +2,34 @@
config_name = "local"
#----beego的默认配置 开始---
#端口号
httpport = 8081
httpport = 8080
#开启应用内监控
EnableAdmin = true
EnableAdmin = false
AdminPort = 8088
##---beego的默认配置 结束---
#---beego的默认配置 结束---
#---自定义配置 开始----
#数据库连接
# sqlconn = "root:root@tcp(127.0.0.1:3306)/ability_display?charset=utf8&loc=Asia%2FShanghai"
##数据库连接
# sqlconn ="${MYSQL_CONN||root:sutianxia2015@tcp(115.29.205.99:3306)/opportunity?charset=utf8&loc=Asia%2FShanghai}"
mysql_user = "${MYSQL_USER||root}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
mysql_host = "${MYSQL_HOST||115.29.205.99}"
mysql_port = "${MYSQL_PORT||3306}"
mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
#redis相关配置
##redis相关配置
redis_add_port = "127.0.0.1:6379"
redis_auth = ""
#log相关配置
#out_put:"console","file"
##log相关配置
##out_put:"console","file"
log_output = "file"
#
log_filename = "./log/ability.log"
# maxlines =
# maxsize =
# daily =
# maxdays =
# rotate =
log_level = "debug"
log_filename = "${aliyun_logs_access||ability.log}"
log_level = "${LOG_LEVEL||error}"
##统一用户中心相关配置
ucenter_check_alt = "rsF0pL!6DwjBO735"
ucenter_base_url = "http://suplus-ucenter-dev.fjmaimaimai.com"
ucenter_app_key = "39aefef9e22744a3b2d2d3791824ae7b"
ucenter_secret = "39aefef9e22744a3b2d2d3791824ae7b"
# 审批流程修改 消息发布
message_publish = "audit_change"
#---自定义配置 结束----
\ No newline at end of file
... ...
... ... @@ -96,7 +96,7 @@ func (c *AuthController) ChangeCompany() {
return
}
//me
//Me
//@router /me [get]
func (c *AuthController) Me() {
var msg *protocol.ResponseMessage
... ...
... ... @@ -56,12 +56,15 @@ func (c *CommonController) SelectorRole() {
var roles []protocol.RoleBase
switch param.For {
case "user":
//编辑用户时
list := servecommon.SelectorRoleAll(companyid)
roles = servecommon.FilterRoleAll(userid, companyid, list)
case "role":
//编辑角色时
list := servecommon.SelectorRoleAll(companyid)
roles = servecommon.FilterRoleGroup(userid, companyid, list)
case "all":
//无特殊规则时
roles = servecommon.SelectorRoleAll(companyid)
default:
roles = servecommon.SelectorRoleAll(companyid)
... ...
... ... @@ -362,3 +362,6 @@ func (c *CompanyController) UserList() {
msg = protocol.NewPageDataResponse(result, err)
return
}
//Regist
// func
... ...
... ... @@ -30,13 +30,14 @@ func (c *RbacController) RoleAdd() {
msg = protocol.BadRequestParam("1")
return
}
param.Types = models.ROLETYPES_ROLE
param.CompanyID = c.GetCompanyId()
if param.CompanyID <= 0 {
log.Error("param.CompanyID <= 0")
msg = protocol.BadRequestParam("1")
return
}
param.Types = models.ROLETYPES_ROLE
r, err := serverbac.RoleAdd(param)
msg = protocol.NewReturnResponse(r, err)
return
... ...
... ... @@ -87,6 +87,8 @@ spec:
value: "stdout"
- name: aliyun_logs_access
value: "/opt/logs/oppmg.log"
- name: aliyun_logs_access
value: "/var/www/opp/file"
volumes:
- name: accesslogs
emptyDir: {}
... ...
... ... @@ -20,7 +20,6 @@ type Department struct {
Relation string `orm:"column(relation);size(1024)" 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:"成员数量"`
Manages string `orm:"column(managers)" description:"部门负责人id列表 json 数组 []"`
}
... ...
... ... @@ -18,7 +18,6 @@ type Position struct {
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
EnableStatus string `orm:"column(enable_status);size(255)" description:"有效状态 1:有效 0:无效"`
Member int `orm:"column(member)"`
}
func (t *Position) TableName() string {
... ...
package models
import (
"fmt"
"github.com/astaxie/beego/orm"
)
type RoleRelated struct {
Id int `orm:"column(id);pk"`
RoleId int64 `orm:"column(role_id)"`
UserId int64 `orm:"column(user_id)"`
}
func (t *RoleRelated) TableName() string {
return "role_related"
}
func init() {
orm.RegisterModel(new(RoleRelated))
}
// AddRoleRelated insert a new RoleRelated into database and returns
// last inserted Id on success.
func AddRoleRelated(m *RoleRelated) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetRoleRelatedById retrieves RoleRelated by Id. Returns error if
// Id doesn't exist
func GetRoleRelatedById(id int) (v *RoleRelated, err error) {
o := orm.NewOrm()
v = &RoleRelated{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateRoleRelated updates RoleRelated by Id and returns error if
// the record to be updated doesn't exist
func UpdateRoleRelatedById(m *RoleRelated) (err error) {
o := orm.NewOrm()
v := RoleRelated{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
}
// DeleteRoleRelated deletes RoleRelated by Id and returns error if
// the record to be deleted doesn't exist
func DeleteRoleRelated(id int) (err error) {
o := orm.NewOrm()
v := RoleRelated{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&RoleRelated{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func CountRoleRelatedByUser(roleid int64) (int64, error) {
var (
cnt int64
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&RoleRelated{}).
Filter("role_id", roleid).
Count()
return cnt, err
}
... ... @@ -59,6 +59,7 @@ func AddUserCompany(m *UserCompany, o orm.Ormer) (id int64, err error) {
m.CreateAt = time.Now()
m.DeleteAt = time.Unix(0, 0)
m.UpdateAt = time.Now()
m.Enable = USERCOMPANY_ENABLE_YES
id, err = o.Insert(m)
return
}
... ... @@ -81,8 +82,10 @@ func UpdateUserCompanyById(m *UserCompany) (err error) {
func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) {
o := orm.NewOrm()
var data []*UserCompany
_, err := o.QueryTable(&UserCompany{}).Filter("UserId", userid).
Filter("CompanyId", companyId).
_, err := o.QueryTable(&UserCompany{}).
Filter("user_id", userid).
Filter("company_id", companyId).
Filter("delete_at", 0).
All(&data)
if err != nil {
return nil, err
... ... @@ -96,8 +99,9 @@ func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) {
func ExistUserCompany(userid int64, companyId int64) bool {
o := orm.NewOrm()
ok := o.QueryTable(&UserCompany{}).
Filter("UserId", userid).
Filter("CompanyId", companyId).
Filter("user_id", userid).
Filter("company_id", companyId).
Filter("delete_at", 0).
Exist()
return ok
}
... ... @@ -105,8 +109,8 @@ func ExistUserCompany(userid int64, companyId int64) bool {
func EnableUserCompany(userid int64, companyid int64) error {
o := orm.NewOrm()
_, err := o.QueryTable(&UserCompany{}).
Filter("UserId", userid).
Filter("CompanyId", companyid).Update(orm.Params{
Filter("user_id", userid).
Filter("company_id", companyid).Update(orm.Params{
"enable": USERCOMPANY_ENABLE_YES,
"delete_at": 0,
})
... ...
... ... @@ -8,12 +8,13 @@ import (
)
type UserDepartment struct {
Id int64 `orm:"column(id);auto" description:"主键"`
UserId int64 `orm:"column(user_id)" description:"用户id"`
CompanyId int64 `orm:"column(company_id)" description:"公司id"`
DepartmentId int64 `orm:"column(department_id)" description:"部门id"`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
Id int64 `orm:"column(id);auto" description:"主键"`
UserId int64 `orm:"column(user_id)" description:"用户id"`
CompanyId int64 `orm:"column(company_id)" description:"公司id"`
DepartmentId int64 `orm:"column(department_id)" description:"部门id"`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
UserCompanyId int64 `orm:"column(user_company_id)"`
}
func (t *UserDepartment) TableName() string {
... ... @@ -98,3 +99,16 @@ func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) {
All(&result)
return result, err
}
func CountUserDepartByDepart(departid int64) (int64, error) {
var (
cnt int64
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&UserDepartment{}).
Filter("department_id", departid).
Filter("enable_status", 1).
Count()
return cnt, err
}
... ...
... ... @@ -8,12 +8,13 @@ import (
)
type UserPosition struct {
Id int64 `orm:"column(id);pk" description:"唯一键值"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
PositionId int64 `orm:"column(position_id)" description:"表position.id 职位编号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 2:无效"`
Id int64 `orm:"column(id);pk" description:"唯一键值"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
PositionId int64 `orm:"column(position_id)" description:"表position.id 职位编号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 2:无效"`
UserCompanyId int64 `orm:"column(user_company_id)"`
}
func (t *UserPosition) TableName() string {
... ... @@ -73,3 +74,16 @@ func GetUserPosition(userid, companyid int64) ([]*UserPosition, error) {
All(&result)
return result, err
}
func CountUserPositionByPosition(positionid int64) (int64, error) {
var (
cnt int64
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&UserPosition{}).
Filter("position_id", positionid).
Filter("enable_status", 1).
Count()
return cnt, err
}
... ...
... ... @@ -7,11 +7,12 @@ import (
)
type UserRole struct {
Id int `orm:"column(id);pk"`
RoleId int64 `orm:"column(role_id)"`
UserId int64 `orm:"column(user_id)"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
Id int `orm:"column(id);pk"`
RoleId int64 `orm:"column(role_id)"`
UserId int64 `orm:"column(user_id)"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
UserCompanyId int64 `orm:"column(user_company_id)"`
}
func (t *UserRole) TableName() string {
... ... @@ -71,3 +72,16 @@ func GetUserRole(userid, companyid int64) ([]*UserRole, error) {
All(&result)
return result, err
}
func CountUserRoleByRole(roleid int64) (int64, error) {
var (
cnt int64
err error
)
o := orm.NewOrm()
cnt, err = o.QueryTable(&UserRole{}).
Filter("role_id", roleid).
Filter("enable_status", 1).
Count()
return cnt, err
}
... ...
... ... @@ -36,12 +36,12 @@ type ResponseDepartmentInfo struct {
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Member int `json:"member"` //成员数
Member int64 `json:"member"` //成员数
}
//ResponseDepartmentList ....
type ResponseDepartmentList struct {
List []ResponseDepartmentInfo
List []ResponseDepartmentInfo `json:"list"`
}
//RequestPositionAdd 添加职位
... ... @@ -100,10 +100,10 @@ type ResponseUserList struct {
}
type UserListItem struct {
UserId int64 `json:"user_id" orm:"column(user_id)"`
NickName string `json:"nick_name" orm:"column(nick_name)"`
Positions string `json:"positions" orm:"-"`
Roles string `json:"roles" orm:"-"`
Departments string `json:"departments" orm:"-"`
Enable int8 `json:"enable" orm:"column(enable)"`
UserCompanydId int64 `json:"user_company_id" orm:"column(user_company_id)"`
NickName string `json:"nick_name" orm:"column(nick_name)"`
Positions string `json:"positions" orm:"-"`
Roles string `json:"roles" orm:"-"`
Departments string `json:"departments" orm:"-"`
Enable int8 `json:"enable" orm:"column(enable)"`
}
... ...
... ... @@ -26,6 +26,7 @@ var errmessge ErrorMap = map[string]string{
"10036": "请输入正确的手机格式",
"10037": "用户的部门必填",
"10038": "用户的角色必填",
"10039": "用户已存在",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -6,7 +6,7 @@ type RequestRoleAdd struct {
Pid int64 `json:"pid"`
Name string `json:"name"`
Types int8 `json:"types"`
Descript string `json:"descript"`
// Descript string `json:"descript"`
}
//RequestRoleDelete 删除一个角色数据
... ...
... ... @@ -14,13 +14,13 @@ func init() {
beego.NSBefore(middleware.LogRequestData),
//beego.NSBefore(middleware.AuthToken),
beego.NSNamespace("/department",
beego.NSRouter("/list", &controllers.CompanyController{}, "get:DepartmentList"),
beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"),
beego.NSRouter("/edit", &controllers.CompanyController{}, "post:DepartmentUpdate"),
beego.NSRouter("/delete", &controllers.CompanyController{}, "post:DepartmentDelete"),
),
beego.NSNamespace("position",
beego.NSRouter("/list", &controllers.CompanyController{}, "get:PositionList"),
beego.NSRouter("/list", &controllers.CompanyController{}, "post:PositionList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:PositionAdd"),
beego.NSRouter("/edit", &controllers.CompanyController{}, "post:PositionEdit"),
beego.NSRouter("/delete", &controllers.CompanyController{}, "post:PositionDelete"),
... ... @@ -32,9 +32,9 @@ func init() {
beego.NSRouter("/role_group/add", &controllers.RbacController{}, "post:RoleGroupAdd"),
beego.NSRouter("/role_group/edit", &controllers.RbacController{}, "post:RoleGroupUpdate"),
beego.NSRouter("/role_group/delete", &controllers.RbacController{}, "post:RoleGroupDelete"),
beego.NSRouter("/role", &controllers.RbacController{}, "get:RoleList"),
beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"),
),
beego.NSNamespace("/user/",
beego.NSNamespace("/user",
beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"),
beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"),
... ... @@ -42,7 +42,8 @@ func init() {
),
beego.NSNamespace("/auth",
beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"),
beego.NSRouter("/refresh_token", &controllers.AuthController{}, "get:RefreshToken"),
beego.NSRouter("/refresh_token", &controllers.AuthController{}, "post:RefreshToken"),
beego.NSRouter("/me", &controllers.AuthController{}, "post:Me"),
),
beego.NSNamespace("/bulletin",
beego.NSRouter("/add", &controllers.BulletinController{}, "post:BulletinRelease"),
... ... @@ -50,7 +51,7 @@ func init() {
beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"),
beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"),
),
beego.NSNamespace("common",
beego.NSNamespace("/common",
beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"),
beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),
beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
... ...
... ... @@ -45,7 +45,6 @@ func DepartmentAdd(param protocol.RequestDepartmentAdd) (protocol.ResponseDepart
CreateAt: time.Now(),
UpdateAt: time.Now(),
ParentId: param.ParentID,
Member: 0,
}
departmentAdd.SetManages(param.Managers)
o := orm.NewOrm()
... ... @@ -207,61 +206,6 @@ func departmentRelationUpdate(departUpdate *models.Department, newparent *models
return nil
}
//DepartmentDelete 部门删除,删除整个分枝
// func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
// var (
// departDelete *models.Department
// err error
// )
// departDelete, err = models.GetDepartmentById(param.ID)
// if err != nil {
// e := fmt.Errorf("GetDepartmentById err:%s", err)
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// if departDelete.CompanyId != param.CompanyID {
// e := fmt.Errorf("departDelete.CompanyId != param.CompanyID")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// const (
// //获取部门子集 锁数据 select ... for update,
// dataSql0 string = `SELECT id,relation,member FROM department WHERE relation LIKE ? AND delete_at = 0 FOR UPDATE`
// dataSql2 string = `update department set delete_at=? where relation LIKE ?`
// )
// var (
// departSubset []models.Department
// relationLike string = departDelete.Relation + "%"
// nowTime string = time.Now().String()
// )
// o := orm.NewOrm()
// o.Begin()
// err = utils.ExecuteQueryAllWithOrmer(o, &departSubset, dataSql0, relationLike)
// if err != nil {
// o.Rollback()
// e := fmt.Errorf("")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// for _, v := range departSubset {
// if v.Member > 0 {
// o.Rollback()
// e := fmt.Errorf("Member > 0 ")
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// }
// err = utils.ExecuteSQLWithOrmer(o, dataSql2, nowTime, relationLike)
// if err != nil {
// o.Rollback()
// e := fmt.Errorf("EXECUTE SQL err:%s", err)
// log.Error(e.Error())
// return protocol.NewErrWithMessage("1", e)
// }
// o.Commit()
// return nil
// }
func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
//检查是否可以被删除
var (
... ... @@ -301,7 +245,12 @@ func DepartmentDelete(param protocol.RequestDepartmentDelete) error {
return protocol.NewErrWithMessage("1", e)
}
for _, subset := range departSubset {
if subset.Member > 0 {
cnt, err := models.CountUserDepartByDepart(subset.Id)
if err != nil {
log.Error("CountUserDepartByDepart err:%s", err)
return protocol.NewErrWithMessage("1")
}
if cnt > 0 {
e := fmt.Errorf("user in department,relation:%s", subset.Relation)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
... ... @@ -347,9 +296,13 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
return nil, protocol.NewErrWithMessage("1", err)
}
for _, v := range departmodels {
cnt, err := models.CountUserDepartByDepart(v.Id)
if err != nil {
log.Error("CountUserDepartByDepart err:%s", err)
}
depart := protocol.ResponseDepartmentInfo{
ID: v.Id, CompanyID: v.CompanyId,
Name: v.Name, Member: v.Member,
Name: v.Name, Member: cnt,
ParantID: v.ParentId,
}
var manage []protocol.DepartmentManager
... ...
... ... @@ -218,7 +218,7 @@ func PositionDelete(param protocol.RequestPositionDelete) error {
var p *models.Position
p, err := models.GetPositionById(id)
if err != nil {
e := fmt.Errorf("GetPositionById(%d)", id)
e := fmt.Errorf("GetPositionById(%d) err:%s", id, err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
}
... ... @@ -240,10 +240,15 @@ func PositionDelete(param protocol.RequestPositionDelete) error {
return protocol.NewErrWithMessage("1", e)
}
for _, subset := range positionsubset {
if subset.Member > 0 {
cnt, err := models.CountUserPositionByPosition(subset.Id)
if err != nil {
log.Error("CountUserPositionByPosition err:%s", err)
return protocol.NewErrWithMessage("1")
}
if cnt > 0 {
e := fmt.Errorf("user in position,relation:%s", subset.Relation)
log.Error(e.Error())
return protocol.NewErrWithMessage("1", e)
return protocol.NewErrWithMessage("10011", e)
}
if _, ok := toDelete[subset.Id]; ok {
delete(toDelete, subset.Id)
... ...
... ... @@ -6,6 +6,7 @@ import (
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
"strings"
"time"
"github.com/astaxie/beego/orm"
... ... @@ -16,6 +17,11 @@ func UserAdd(param protocol.RequestUserAdd) error {
userm *models.User
err error
)
//校验用户
err = validCompanyUser(param.CompanyId, param.Phone)
if err != nil {
return err
}
//校验角色
err = validCompanyRole(param.CompanyId, param.Roles)
if err != nil {
... ... @@ -134,6 +140,23 @@ func validCompanyPosition(companyid int64, positionid []int64) error {
return nil
}
func validCompanyUser(companyid int64, phone string) error {
userdata, err := models.GetUserByPhone(phone)
if err == orm.ErrNoRows {
return nil
}
if err != nil {
log.Error("database operate fail:%s", err)
return protocol.NewErrWithMessage("1")
}
ok := models.ExistUserCompany(userdata.Id, companyid)
if ok {
protocol.NewErrWithMessage("10039")
}
return nil
}
//registUser 注册用户
func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
var (
... ... @@ -163,15 +186,15 @@ func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
CompanyId: companyid,
UserId: userIn.Id,
}
ok := models.ExistUserCompany(usrData.Id, companyid)
if !ok {
_, err = models.AddUserCompany(musercompany, o)
if err != nil {
return err
}
// ok := models.ExistUserCompany(usrData.Id, companyid)
// if !ok {
_, err = models.AddUserCompany(musercompany, o)
if err != nil {
return err
}
err = models.EnableUserCompany(usrData.Id, companyid)
return err
// }
// err = models.EnableUserCompany(usrData.Id, companyid)
return nil
}
func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error {
... ... @@ -257,7 +280,7 @@ func editUserRole(userid int64, companyid int64, roleids []int64, o orm.Ormer) e
addRoleIds []int64
)
dataSql := `SELECT role_id FROM user_role WHERE enable_status=1 AND company_id=? AND user_id=?`
dataSql2 := `UPDATE user_position SET enable_status = 2 WHERE company_id =? AND user_id=? AND role_id=?`
dataSql2 := `UPDATE user_role SET enable_status = 2 WHERE company_id =? AND user_id=? AND role_id=?`
datasql3 := `INSERT INTO user_role (user_id,role_id,company_id,enable_status) VALUES (?,?,?,?)`
err = utils.ExecuteQueryAllWithOrmer(o, &oldRoleIds, dataSql, companyid, userid)
if err != nil {
... ... @@ -291,6 +314,10 @@ func UserEdit(param protocol.RequestUserEdit) error {
userm *models.User
err error
)
err = validCompanyUser(param.CompanyId, param.Phone)
if err != nil {
return err
}
//校验角色
err = validCompanyRole(param.CompanyId, param.Roles)
if err != nil {
... ... @@ -322,6 +349,7 @@ func UserEdit(param protocol.RequestUserEdit) error {
// log.Error("registUser err:%s", err)
// return protocol.NewErrWithMessage("1")
// }
// TODO 用户数据更新
//添加角色
err = editUserRole(userm.Id, param.CompanyId, param.Roles, o)
if err != nil {
... ... @@ -371,7 +399,7 @@ func UserDelete(userid, companyid int64) error {
func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) {
datasql := `SELECT a.company_id,a.user_id,a.enable, b.phone,b.nick_name
datasql := `SELECT a.id as user_company_id,a.company_id,a.user_id,a.enable, b.phone,b.nick_name
FROM user_company AS a
LEFT JOIN user AS b ON a.user_id = b.id
WHERE a.company_id=? AND a.delete_at = 0 `
... ... @@ -404,20 +432,77 @@ func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error)
log.Error(e.Error())
return responseData, protocol.NewErrWithMessage("0")
}
// for k, v := range result {
// positions, _ := models.GetUserPosition(v.UserId, param.Companyid)
// departments, _ := models.GetUserDepartment(v.UserId, param.Companyid)
// roles, _ := models.GetUserRole(v.UserId, param.Companyid)
// }
for k, v := range result {
var (
pname []string
dname []string
rname []string
)
positions := GetUserPosition(v.UserCompanydId)
for i := range positions {
pname = append(pname, positions[i].Name)
}
departments := GetUserDepartment(v.UserCompanydId)
for i := range departments {
dname = append(dname, departments[i].Name)
}
roles := GetUserRole(v.UserCompanydId)
for i := range roles {
rname = append(rname, roles[i].Name)
}
result[k].Departments = strings.Join(dname, ",")
result[k].Positions = strings.Join(pname, ",")
result[k].Roles = strings.Join(rname, ",")
}
responseData.ResponsePageInfo = pageInfo
responseData.List = result
return responseData, nil
}
func GetUserDepartment(user int64, companyid int64) {
func GetUserDepartment(usercompanyid int64) []protocol.DepartmentBase {
const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_department AS a
JOIN department AS b ON a.department_id = b.id
WHERE a.enable_status =1 AND a.user_company_id =? `
var (
err error
data []protocol.DepartmentBase
)
err = utils.ExecuteQueryAll(&data, datasql, usercompanyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return data
}
func GetUserPosition(user int64, companyid int64) {
func GetUserPosition(usercompanyid int64) []protocol.PositionBase {
const datasql string = `SELECT b.name,b.parent_id,b.id FROM user_position AS a
JOIN position AS b ON a.position_id = b.id
WHERE a.enable_status =1 AND a.user_company_id =? `
var (
err error
data []protocol.PositionBase
)
err = utils.ExecuteQueryAll(&data, datasql, usercompanyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return data
}
func GetUserRole(usercompanyid int64) []protocol.RoleBase {
const datasql string = `SELECT b.name,b.pid,b.id FROM user_role AS a
JOIN role AS b ON a.role_id = b.id
WHERE a.enable_status =1 AND a.user_company_id =? `
var (
err error
data []protocol.RoleBase
)
err = utils.ExecuteQueryAll(&data, datasql, usercompanyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return data
}
... ...
... ... @@ -17,7 +17,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error)
CreateAt: nowTime,
Pid: param.Pid,
Types: param.Types,
Descript: param.Descript,
// Descript: param.Descript,
}
if ok := role.ValidateTypes(); !ok {
e := fmt.Errorf("ValidateTypes err")
... ... @@ -66,7 +66,7 @@ func RoleDelete(param protocol.RequestRoleDelete) error {
log.Error(e.Error())
return protocol.NewErrWithMessage("1")
}
cnt, err := models.CountRoleRelatedByUser(param.RoleID)
cnt, err := models.CountUserRoleByRole(param.RoleID)
if err != nil {
log.Error(err.Error())
return protocol.NewErrWithMessage("1")
... ... @@ -99,7 +99,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error
return nil, protocol.NewErrWithMessage("1", e)
}
role.Pid = param.Pid
role.Descript = param.Descript
//role.Descript = param.Descript
role.Name = param.Name
if _, err = role.ValidatePid(); err != nil {
e := fmt.Errorf("ValidatePid err:%s", err)
... ...
... ... @@ -301,7 +301,7 @@ token 的响应内容
```json
{
"id": [1, 2, 3]
"ids": [1, 2, 3]
}
```
... ... @@ -311,7 +311,7 @@ token 的响应内容
{
"code": 0,
"msg": "成功",
"data":null
"data": null
}
```
... ... @@ -384,7 +384,7 @@ token 的响应内容
```json
{
"ids": [1, 23]
"id": 1
}
```
... ... @@ -527,7 +527,7 @@ obj.status 状态 0-所有 1-下架 2-上架
```json
{
"id":5
"id": 5
}
```
... ...