123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- package system
- import (
- "eta_gn/eta_api/global"
- "fmt"
- "strings"
- "time"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type AdminItem struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Password string
- LastUpdatedPasswordTime string `json:"-"`
- Enabled int `description:"1:有效,0:禁用"`
- Email string `description:"系统用户邮箱"`
- LastLoginTime string
- CreatedTime time.Time
- LastUpdatedTime string
- Role string `description:"系统用户角色"`
- Mobile string `description:"手机号"`
- RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
- RoleId int `description:"角色id"`
- RoleName string `description:"角色名称"`
- RoleTypeCode string `description:"角色编码"`
- DepartmentId int `description:"部门id"`
- DepartmentName string `json:"-" description:"部门名称"`
- TeamId int `description:"三级id"`
- GroupId int `description:"分组id"`
- GroupName string `json:"-" description:"分组名称"`
- Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
- Position string `description:"职位"`
- DepartmentGroup string `description:"部门分组"`
- LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
- ResearchGroupName string `description:"研究方向分组名称"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
- TelAreaCode string `description:"手机区号"`
- IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"`
- }
- func GetSysuserList(condition string, pars []interface{}, startSize, pageSize int) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY enabled DESC, last_updated_time DESC, created_time DESC LIMIT ?,?`
- pars = append(pars, startSize)
- pars = append(pars, pageSize)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- func GetSysuserListCount(condition string, pars []interface{}) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM "admin" WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
- return
- }
- type AdminRespItem struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Password string
- LastUpdatedPasswordTime string `json:"-"`
- Enabled int `description:"1:有效,0:禁用"`
- Email string `description:"系统用户邮箱"`
- LastLoginTime string
- CreatedTime time.Time
- LastUpdatedTime string
- Role string `description:"系统用户角色"`
- Mobile string `description:"手机号"`
- RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
- RoleId int `description:"角色id"`
- RoleName string `description:"角色名称"`
- RoleTypeCode string `description:"角色编码"`
- DepartmentId int `description:"部门id"`
- DepartmentName string `json:"-" description:"部门名称"`
- parentId int `description:"父级id"`
- GroupId int `description:"分组id"`
- GroupName string `json:"-" description:"分组名称"`
- Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
- Position string `description:"职位"`
- DepartmentGroup string `description:"部门分组"`
- LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
- }
- type SysuserListResp struct {
- List []*AdminItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type SysuserAddReq struct {
- AdminName string `description:"系统用户名称"`
- AdminAvatar string `description:"用户头像"`
- RealName string `description:"系统用户姓名"`
- Password string `description:"密码"`
- Mobile string `description:"手机号"`
- RoleId int `description:"角色id"`
- DepartmentId int `description:"部门id"`
- GroupId int `description:"分组id"`
- TeamId int `description:"小组id"`
- Enabled int `description:"1:有效,0:禁用"`
- //Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
- Position string `description:"职位"`
- ResearchGroupIds string `description:"研究方向分组IDs"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
- Email string `description:"邮箱"`
- TelAreaCode string `description:"手机区号"`
- IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"`
- }
- func GetSysAdminCount(adminName string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM "admin" WHERE admin_name=? `
- err = global.DEFAULT_DmSQL.Raw(sql, adminName).Scan(&count).Error
- return
- }
- func GetSysAdminByName(adminName string) (item *Admin, err error) {
- sql := `SELECT * FROM "admin" WHERE admin_name=? `
- err = global.DEFAULT_DmSQL.Raw(sql, adminName).First(&item).Error
- return
- }
- func GetSysAdminById(adminId int) (item *Admin, err error) {
- sql := `SELECT * FROM "admin" WHERE admin_id=? `
- err = global.DEFAULT_DmSQL.Raw(sql, adminId).First(&item).Error
- return
- }
- func AddAdmin(item *Admin) (err error) {
- err = global.DEFAULT_DmSQL.Create(item).Error
- return
- }
- type SysuserEditReq struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Mobile string `description:"手机号"`
- RoleId int `description:"角色id"`
- Enabled int `description:"1:有效,0:禁用"`
- Position string `description:"职位"`
- ResearchGroupIds string `description:"研究方向分组IDs"`
- Province string `description:"省"`
- ProvinceCode string `description:"省编码"`
- City string `description:"市"`
- CityCode string `description:"市编码"`
- EmployeeId string `description:"员工工号(钉钉/每刻报销)"`
- Email string `description:"邮箱"`
- TelAreaCode string `description:"手机区号"`
- IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"`
- }
- type SysUserMoveReq struct {
- AdminId int `description:"系统用户id"`
- DepartmentId int `description:"部门id"`
- GroupId int `description:"分组id"`
- TeamId int `description:"小组id"`
- }
- type SysUserResetPassReq struct {
- AdminId int `description:"系统用户id"`
- Password string `description:"密码"`
- RePassword string `description:"重复密码"`
- }
- // SysuserEditEnabledReq 用户状态编辑
- type SysuserEditEnabledReq struct {
- AdminId int `description:"系统用户id"`
- Enabled int `description:"1:有效,0:禁用"`
- }
- // 变更状态
- func EditAdminEnabled(item *Admin) (err error) {
- sql := `UPDATE "admin"
- SET
- last_updated_time = NOW(),enabled=? WHERE admin_id = ? `
- err = global.DEFAULT_DmSQL.Exec(sql, item.Enabled, item.AdminId).Error
- return
- }
- // DisableAdmin 禁用用户
- func DisableAdmin(adminId int) (err error) {
- sql := `UPDATE "admin"
- SET
- last_updated_time = NOW(),disable_time=now(),enabled=0 WHERE admin_id = ? `
- err = global.DEFAULT_DmSQL.Exec(sql, adminId).Error
- return
- }
- type SysuserDeleteReq struct {
- AdminId int `description:"系统用户id"`
- }
- func DeleteSysuser(adminId int) (err error) {
- sql := `DELETE FROM "admin" WHERE admin_id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, adminId).Error
- return
- }
- // GetSysAdminCountByMobile 查询系统中是否存在该手机号(如果有传入用户id,那么排除该用户)
- func GetSysAdminCountByMobile(mobile string, adminId int) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM "admin" WHERE mobile=? `
- if adminId > 0 {
- sql += ` AND admin_id != ` + fmt.Sprint(adminId)
- }
- err = global.DEFAULT_DmSQL.Raw(sql, mobile).First(&count).Error
- return
- }
- func GetSysUserItems(condition string, pars []interface{}) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY last_updated_time DESC `
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
- // GetGroupSysUserList 根据分组id获取系统用户列表
- func GetGroupSysUserList(groupId int) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE group_id=? ORDER BY created_time DESC `
- err = global.DEFAULT_DmSQL.Raw(sql, groupId).Find(&items).Error
- return
- }
- // GetDepartmentGroupSysUserList 根据部门id和分组id获取系统用户列表
- func GetDepartmentGroupSysUserList(departmentId, groupId int, roleTypeCodes string) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE department_id = ? and group_id=? and enabled=1 `
- if roleTypeCodes != "" {
- sql += ` and role_type_code in (` + roleTypeCodes + `) `
- }
- sql += ` ORDER BY created_time asc `
- err = global.DEFAULT_DmSQL.Raw(sql, departmentId, groupId).Find(&items).Error
- return
- }
- // GetGrooupsysUserList 根据大组id和小组id获取系统用户列表
- func GetGrooupsysUserList(groupId int, roleTypeCodes string, enabled int) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE group_id = ? `
- if roleTypeCodes != "" {
- sql += ` and role_type_code in (` + roleTypeCodes + `) `
- }
- if enabled >= 0 {
- sql += fmt.Sprint(` AND enabled=`, enabled, ` `)
- }
- sql += ` ORDER BY created_time asc `
- err = global.DEFAULT_DmSQL.Raw(sql, groupId).Find(&items).Error
- return
- }
- // GetSysAdminByIdSlice 根据账户id列表获取账户信息列表
- func GetSysAdminByIdSlice(adminIdList []string) (items []*Admin, err error) {
- if len(adminIdList) <= 0 {
- return
- }
- sql := `SELECT * FROM "admin" WHERE admin_id in (` + strings.Join(adminIdList, ",") + `) `
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- // GetTeamSysUserList 根据小组id获取系统用户列表
- func GetTeamSysUserList(teamId, enabled int) (items []*AdminItem, err error) {
- sql := `SELECT * FROM "admin" WHERE group_id=? `
- if enabled >= 0 {
- sql += fmt.Sprint(` AND enabled=`, enabled, ` `)
- }
- sql += ` ORDER BY created_time DESC `
- err = global.DEFAULT_DmSQL.Raw(sql, teamId).Find(&items).Error
- return
- }
- func GetGroupIdByParentId(groupId int) (items []*string, err error) {
- sql := `SELECT group_id FROM sys_group WHERE parent_id=? ORDER BY create_time DESC `
- err = global.DEFAULT_DmSQL.Raw(sql, groupId).Find(&items).Error
- return
- }
- type OpenIdList struct {
- OpenId string
- AdminId int
- }
- // GetRaiAdmin 获取权益内部人员(技术组+私募组)
- func GetRaiAdmin() (items []*AdminItem, err error) {
- sql := `SELECT
- admin_id,
- real_name,
- mobile
- FROM
- "admin"
- WHERE
- role_type_code LIKE '%rai%'
- AND group_id NOT IN (19, 10)
- AND enabled = 1
- OR (
- department_name = '产品技术部'
- AND enabled = 1
- )`
- err = global.DEFAULT_DmSQL.Raw(sql).Find(&items).Error
- return
- }
- // SyncRoleData 同步角色数据
- type SyncRoleData struct {
- Source int `description:"来源: 1-CRM; 2-ETA"`
- RoleId int `description:"角色ID"`
- }
- // SyncAdminData 同步用户数据
- type SyncAdminData struct {
- Source int `description:"来源: 1-CRM; 2-ETA"`
- AdminName string `description:"用户名"`
- }
- // SyncDepartmentData 同步部门数据
- type SyncDepartmentData struct {
- Source int `description:"来源: 1-CRM; 2-ETA"`
- DepartmentId int `description:"部门ID"`
- }
- // SyncGroupData 同步分组数据
- type SyncGroupData struct {
- Source int `description:"来源: 1-CRM; 2-ETA"`
- GroupId int `description:"分组ID"`
- }
- // GetSysAdminList 获取admin列表
- func GetSysAdminList(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) {
- fields := "*"
- if len(fieldArr) > 0 {
- fields = strings.Join(fieldArr, ",")
- }
- order := `enabled DESC, last_updated_time DESC`
- if orderRule != "" {
- order = orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM "admin" WHERE 1=1 %s ORDER BY %s`, fields, condition, order)
- err = global.DEFAULT_DmSQL.Raw(sql, pars...).Find(&items).Error
- return
- }
|