作者 yangfu

Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev

# Conflicts:
#	models/user_company.go
#	services/auth/auth.go
模板管理
package controllers
import (
"encoding/json"
"oppmg/common/log"
"oppmg/protocol"
servecommon "oppmg/services/common"
)
//公共接口
type CommonController struct {
BaseController
}
func (c *CommonController) URLMapping() {
}
//SelectorDepartment 下拉列表 -部门
//@router /department [post]
func (c *CommonController) SelectorDepartment() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
departs := servecommon.SelectorDepartment(companyid)
msg = protocol.NewReturnResponse(departs, nil)
return
}
//SelectorRole 下拉列表 -角色
//@router /role [post]
func (c *CommonController) SelectorRole() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
For string `json:"for"`
}
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()
userid := c.GetUserId()
if companyid <= 0 || userid <= 0 {
msg = protocol.BadRequestParam("1")
return
}
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)
}
msg = protocol.NewReturnResponse(roles, nil)
return
}
//SelectorPosition 下拉列表 -职位
//@router /position [post]
func (c *CommonController) SelectorPosition() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
departs := servecommon.SelectorPosition(companyid)
msg = protocol.NewReturnResponse(departs, nil)
return
}
... ... @@ -5,10 +5,7 @@ import (
"oppmg/common/log"
"oppmg/protocol"
servecompany "oppmg/services/company"
"oppmg/storage/redisdata"
"oppmg/utils"
"strconv"
"strings"
)
type CompanyController struct {
... ... @@ -229,35 +226,13 @@ func (c *CompanyController) UserAdd() {
msg = protocol.BadRequestParam("1")
return
}
name := []rune(strings.TrimSpace(param.Name))
if len(name) == 0 {
msg = protocol.BadRequestParam("10035")
return
}
if len(name) > 10 {
msg = protocol.BadRequestParam("10034")
return
}
ok := utils.PhoneMatch.MatchString(param.Phone)
if !ok {
msg = protocol.BadRequestParam("10036")
return
}
if len(param.Departments) == 0 {
msg = protocol.BadRequestParam("10037")
return
}
if len(param.Roles) == 0 {
msg = protocol.BadRequestParam("10038")
return
}
param.CompanyId = c.GetCompanyId()
err := servecompany.UserAdd(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
//UserEdit 编辑用户
//UserAdd 添加用户
//@Router /user/edit [post]
func (c *CompanyController) UserEdit() {
var msg *protocol.ResponseMessage
... ... @@ -270,95 +245,8 @@ func (c *CompanyController) UserEdit() {
msg = protocol.BadRequestParam("1")
return
}
name := []rune(strings.TrimSpace(param.Name))
if len(name) == 0 {
msg = protocol.BadRequestParam("10035")
return
}
if len(name) > 10 {
msg = protocol.BadRequestParam("10034")
return
}
if len(param.Departments) == 0 {
msg = protocol.BadRequestParam("10037")
return
}
if len(param.Roles) == 0 {
msg = protocol.BadRequestParam("10038")
return
}
param.CompanyId = c.GetCompanyId()
err := servecompany.UserEdit(param)
msg = protocol.NewReturnResponse(nil, err)
return
}
//UserDelete 删除用户
//@Router /user/delete [post]
func (c *CompanyController) UserDelete() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
Userid int64 `json:"user_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()
err := servecompany.UserDelete(param.Userid, companyId)
if err == nil {
e := redisdata.DeleteLoginToken(param.Userid)
if e != nil {
log.Error(e.Error())
}
}
msg = protocol.NewReturnResponse(nil, err)
return
}
//UserEdit 禁用、启用用户 TODO
//@Router /user/enable [post]
func (c *CompanyController) UserEnable() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestUserEdit
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
param.CompanyId = c.GetCompanyId()
err := servecompany.UserEdit(param)
redisdata.DeleteLoginToken(0)
msg = protocol.NewReturnResponse(nil, err)
return
}
//UserEdit用户列表
//@Router /user/list [post]
func (c *CompanyController) UserList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
var param protocol.RequestUserList
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败 err:%s", err)
msg = protocol.BadRequestParam("1")
return
}
param.Companyid = c.GetCompanyId()
result, err := servecompany.UserList(param)
msg = protocol.NewPageDataResponse(result, err)
return
}
... ...
... ... @@ -46,6 +46,35 @@ func (this *TemplateController) TemplateAdd() {
return
}
//TemplateGet
//@router /templateGet [post]
func (this *TemplateController) TemplateGet() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateGetRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
rsp, err := audit.TemplateGet(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
}
//TemplateUpdate
//@router /templateUpdate [post]
func (this *TemplateController) TemplateUpdate() {
... ... @@ -83,7 +112,7 @@ func (this *TemplateController) TemplateList() {
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateUpdateRequest
var request *protocol.TemplateListRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
... ... @@ -101,7 +130,65 @@ func (this *TemplateController) TemplateList() {
msg = m
return
}
rsp, err := audit.TemplateUpdate(uid, companyId, request)
rsp, err := audit.TemplateList(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
return
}
//TemplateEditVisible
//@router /templateEditVisible [post]
func (this *TemplateController) TemplateEditVisible() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateEditVisibleRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
rsp, err := audit.TemplateEditVisible(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
}
//TemplateOperateCategory
//@router /templateOperateCategory [post]
func (this *TemplateController) TemplateOperateCategory() {
var msg *protocol.ResponseMessage
defer func() {
this.ResposeJson(msg)
}()
var request *protocol.TemplateOperateCategoryRequest
if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
uid := this.GetUserId()
companyId := this.GetCompanyId()
if companyId <= 0 {
log.Debug("companyId:%d err", companyId)
msg = protocol.BadRequestParam("1")
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
rsp, err := audit.TemplateOperateCategory(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
}
... ...
... ... @@ -82,3 +82,14 @@ func DeleteAuditForm(id int) (err error) {
}
return
}
// GetAuditFormById retrieves AuditForm by Id. Returns error if
// Id doesn't exist
func GetAuditFormByTemplateId(id int) (v []*AuditForm, err error) {
o := orm.NewOrm()
sql := `select * from audit_form where audit_template_id =? and enable_status=1 order by sort_num`
if _, err = o.Raw(sql, id).QueryRows(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -8,22 +8,33 @@ import (
)
type AuditTemplate struct {
Id int64 `orm:"column(id);auto" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Example string `orm:"column(examplte);null" description:"示例"`
Id int64 `orm:"column(id);auto" description:"唯一编号"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"`
Name string `orm:"column(name);size(20)" description:"子分类名称"`
Doc string `orm:"column(doc);size(255)" description:"说明"`
Icon string `orm:"column(icon);size(255)" description:"图标"`
NoticeType int8 `orm:"column(notice_type)" description:"通知方式"`
NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
VisibleObject string `orm:"column(visible_object)" description:"可见的对象 部门 指定人 json"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
Example string `orm:"column(example);null" description:"示例"`
}
const (
VisibleTypeAll = 0
VisibleTypeDepartment = 1
)
const (
VisibleObject_Department = 1
VisibleObject_User = 2
)
func (t *AuditTemplate) TableName() string {
return "audit_template"
}
... ... @@ -80,3 +91,14 @@ func DeleteAuditTemplate(id int64) (err error) {
}
return
}
func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error) {
o := orm.NewOrm()
_, err = o.QueryTable(&AuditTemplate{}).
Filter("chance_type_id", chanceTypeId).All(&v)
if err == orm.ErrNoRows {
return v, nil
}
return
}
... ...
... ... @@ -74,10 +74,10 @@ func DeleteChanceType(id int) (err error) {
return
}
func GetChanceTypeAll() (v []*ChanceType, err error) {
func GetChanceTypeByCompany(companyId int) (v []*ChanceType, err error) {
o := orm.NewOrm()
sql := "select * from chance_type "
if _, err = o.Raw(sql).QueryRows(&v); err == nil {
sql := "select * from chance_type where company_id=?"
if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
return
}
return
... ...
... ... @@ -10,7 +10,7 @@ import (
type Company struct {
Id int64 `orm:"column(id);auto"`
Name string `orm:"column(name);size(40)"`
AdminId int64 `orm:"column(admin_id)"`
Admin_id int64 `orm:"column(admin_id)"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
... ...
... ... @@ -76,6 +76,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager {
return managesdata
}
func (t *Department) GetMembers() []protocol.DepartmentMember {
ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id))
if err != nil {
log.Error(err.Error())
return nil
}
users, err := getUserNameByIds(ids)
if err != nil {
log.Error("GetUserNameByIds err :%s", err)
return nil
}
managesdata := []protocol.DepartmentMember{}
for _, v := range users {
m := protocol.DepartmentMember{
Id: v.Id, Name: v.NickName,
}
managesdata = append(managesdata, m)
}
return managesdata
}
// AddDepartment insert a new Department into database and returns
// last inserted Id on success.
func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) {
... ... @@ -155,3 +176,15 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) {
All(&result)
return result, err
}
func GetDepartmentByIds(departmentIds []int64) ([]Department, error) {
var (
result []Department
err error
)
o := orm.NewOrm()
_, err = o.QueryTable(&Department{}).
Filter("id__in", departmentIds).
All(&result)
return result, err
}
... ...
... ... @@ -62,9 +62,7 @@ func AddUser(m *User, om ...orm.Ormer) (id int64, err error) {
} else {
o = orm.NewOrm()
}
m.DeleteAt = time.Unix(0, 0)
m.EnableStatus = USER_ENABLE_YES
m.CreateAt = time.Now()
id, err = o.Insert(m)
return
}
... ... @@ -82,16 +80,15 @@ func GetUserById(id int64) (v *User, err error) {
// UpdateUser updates User by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserById(m *User, col []string, om ...orm.Ormer) (err error) {
var o orm.Ormer
if len(om) == 0 {
o = orm.NewOrm()
} else {
o = om[0]
}
var num int64
if num, err = o.Update(m, col...); err == nil {
fmt.Println("Number of records updated in database:", num)
func UpdateUserById(m *User) (err error) {
o := orm.NewOrm()
v := User{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
}
... ...
... ... @@ -92,23 +92,3 @@ func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) {
}
return data[0], nil
}
func ExistUserCompany(userid int64, companyId int64) bool {
o := orm.NewOrm()
ok := o.QueryTable(&UserCompany{}).
Filter("UserId", userid).
Filter("CompanyId", companyId).
Exist()
return ok
}
func EnableUserCompany(userid int64, companyid int64) error {
o := orm.NewOrm()
_, err := o.QueryTable(&UserCompany{}).
Filter("UserId", userid).
Filter("CompanyId", companyid).Update(orm.Params{
"enable": USERCOMPANY_ENABLE_YES,
"delete_at": 0,
})
return err
}
... ...
... ... @@ -85,16 +85,27 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) {
}
return
}
func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) {
// DeleteUserDepartment deletes UserDepartment by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserDepartment(id int64) (err error) {
o := orm.NewOrm()
v := UserDepartment{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserDepartment{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) {
o := orm.NewOrm()
var (
err error
result []*UserDepartment
)
_, err = o.QueryTable(&UserDepartment{}).
Filter("user_id", userid).
Filter("company_id", companyid).
Filter("enable_status", 1).
All(&result)
return result, err
sql := "select user_id from user_department where company_id=? and department_id =?"
if _, err = o.Raw(sql, companyId, dId).QueryRows(&v); err != nil {
return
}
return
}
... ...
... ... @@ -60,16 +60,43 @@ func AddUserPosition(m *UserPosition) (id int64, err error) {
return
}
func GetUserPosition(userid, companyid int64) ([]*UserPosition, error) {
// GetUserPositionById retrieves UserPosition by Id. Returns error if
// Id doesn't exist
func GetUserPositionById(id int64) (v *UserPosition, err error) {
o := orm.NewOrm()
var (
err error
result []*UserPosition
)
_, err = o.QueryTable(&UserPosition{}).
Filter("user_id", userid).
Filter("company_id", companyid).
Filter("enable_status", 1).
All(&result)
return result, err
v = &UserPosition{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserPosition updates UserPosition by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserPositionById(m *UserPosition) (err error) {
o := orm.NewOrm()
v := UserPosition{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
}
// DeleteUserPosition deletes UserPosition by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserPosition(id int64) (err error) {
o := orm.NewOrm()
v := UserPosition{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserPosition{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -58,16 +58,43 @@ func AddUserRole(m *UserRole) (id int64, err error) {
return
}
func GetUserRole(userid, companyid int64) ([]*UserRole, error) {
// GetUserRoleById retrieves UserRole by Id. Returns error if
// Id doesn't exist
func GetUserRoleById(id int) (v *UserRole, err error) {
o := orm.NewOrm()
var (
err error
result []*UserRole
)
_, err = o.QueryTable(&UserRole{}).
Filter("user_id", userid).
Filter("company_id", companyid).
Filter("enable_status", 1).
All(&result)
return result, err
v = &UserRole{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateUserRole updates UserRole by Id and returns error if
// the record to be updated doesn't exist
func UpdateUserRoleById(m *UserRole) (err error) {
o := orm.NewOrm()
v := UserRole{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
}
// DeleteUserRole deletes UserRole by Id and returns error if
// the record to be deleted doesn't exist
func DeleteUserRole(id int) (err error) {
o := orm.NewOrm()
v := UserRole{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&UserRole{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -16,7 +16,7 @@ type InputElement struct {
Lable string `json:"lable"` //标题
InputType string `json:"inputType"` //输入类型
Required int `json:"required"` //是否必填
CurrentValue string `json:"value"` //"当前填写的值"
CurrentValue string `json:"-"` //"当前填写的值"
SectionType int8 `json:"sectionType"`
ValueList string `json:"-"` //输入候选值 value_list
... ... @@ -106,9 +106,10 @@ type TemplateUpdateResponse struct {
type TemplateListRequest struct {
}
type TemplateListResponse struct {
List []*TemplateList `json:"list"`
}
type ChanceType struct {
type TemplateList struct {
Id int `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
... ... @@ -127,7 +128,33 @@ type TemplateItem struct {
}
type VisibleObject struct {
Id string `json:"id"`
Name string `json:"name",omitempty`
Type int `json:"type"` //1:部门 2:指定人员
}
/*TemplateEditVisible */
type TemplateEditVisibleRequest struct {
Id int `json:"id"` //模板编号
VisibleObject []VisibleObject `json:"visibleObject" valid:"Required"`
}
type TemplateEditVisibleResponse struct {
}
/*TemplateAddCategory */
type TemplateOperateCategoryRequest struct {
Id int `json:"id"`
Name string `json:"name,omitempty"`
Type int //1:部门 2:指定人员
Name string `json:"name"`
Icon string `json:"icon"`
}
type TemplateOperateCategoryResponse struct {
}
/*TemplateGet */
type TemplateGetRequest struct {
Id int `json:"id" valid:"Required"`
}
type TemplateGetResponse struct {
Template Template `json:"template"`
Example string `json:"example"` //示例`
}
... ...
... ... @@ -18,10 +18,10 @@ type BulletinReleaseRequest struct {
Content string `json:"content" valid:"Required"`
AllowClose int `json:"allow_close"`
//AllowCondition int `json:"allow_condition"`
QuestionSwitch int `json:"question_switch"`
Receiver []string `json:"receiver" valid:"Required"`
Question Question `json:"question"`
Cover Cover `json:"cover" valid:"Required"`
QuestionSwitch int `json:"question_switch"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
Question Question `json:"question"`
Cover Cover `json:"cover" valid:"Required"`
}
type Question struct {
Id int `json:"id"`
... ... @@ -53,12 +53,12 @@ type BulletinListResponse struct {
}
type BulletinItem struct {
Id int `json:"id"`
Type int8 `json:"type"`
Title string `json:"title"`
Status int8 `json:"status"`
Receiver []Receiver `json:"receiver" valid:"Required"`
CreateAt string `json:"time"`
Id int `json:"id"`
Type int8 `json:"type"`
Title string `json:"title"`
Status int8 `json:"status"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
CreateAt string `json:"time"`
}
/*GetBulletin */
... ... @@ -72,10 +72,10 @@ type GetBulletinResponse struct {
Content string `json:"content" valid:"Required"`
AllowClose int `json:"allow_close"`
//AllowCondition int `json:"allow_condition"`
QuestionSwitch int `json:"question_switch"`
Receiver []Receiver `json:"receiver" valid:"Required"`
Question Question `json:"question"`
Cover Cover `json:"cover" valid:"Required"`
QuestionSwitch int `json:"question_switch"`
Receiver []VisibleObject `json:"receiver" valid:"Required"`
Question Question `json:"question"`
Cover Cover `json:"cover" valid:"Required"`
}
type Receiver struct {
... ...
... ... @@ -12,26 +12,3 @@ type ResponsePageInfo struct {
CurrentPage int `json:"pageNumber"`
// ListData interface{} `json:"list"`
}
// DepartmentBase下拉选择列表-部门
type DepartmentBase struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
ParentId int64 `json:"parent_id" orm:"column(parent_id)"`
}
//RoleBase 下拉选择列表-角色
type RoleBase struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
IsDefault int8 `json:"is_default" orm:"column(is_default)"`
ParentId int64 `json:"parent_id" orm:"column(pid)"`
Types int8 `json:"types" orm:"column(types)"`
}
//PositionBase 下拉选择列表-职位
type PositionBase struct {
Id int64 `json:"id" orm:"column(id)"`
Name string `json:"name" orm:"column(name)"`
ParentId int64 `json:"parent_id" orm:"column(parent_id)"`
}
... ...
... ... @@ -17,6 +17,11 @@ type DepartmentManager struct {
Name string `json:"name"`
}
type DepartmentMember struct {
Id int64 `json:"id"`
Name string `json:"name"`
}
//RequestDepartmentEdit 编辑
type RequestDepartmentEdit struct {
ID int64 `json:"id"`
... ... @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct {
Name string `json:"name"` //部门名字
ParantID int64 `json:"parant_id"` //父级部门Id
Manages []DepartmentManager `json:"manages"` //部门管理员
Members []DepartmentMember `json:"members"` //部门成员
Member int `json:"member"` //成员数
}
... ... @@ -89,8 +95,7 @@ type RequestUserEdit struct {
//RequestUserList 获取用户列表
type RequestUserList struct {
RequestPageInfo
NickName string `json:"nick_name"`
Companyid int64 `json:"company_id"`
NickName string `json:"nick_name"`
}
//ResponseUserList 响应的用户列表
... ... @@ -100,10 +105,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)"`
Id int64 `json:"id"`
NickName string `json:"nick_name"`
Position string `json:"position"`
Role string `json:"role"`
Department string `json:"department"`
Status int8 `json:"status"`
}
... ...
... ... @@ -21,11 +21,6 @@ var errmessge ErrorMap = map[string]string{
"10031": "无效角色",
"10032": "无效部门",
"10033": "无效职位",
"10034": "名字限制10个字符以内",
"10035": "名字是必填项",
"10036": "请输入正确的手机格式",
"10037": "用户的部门必填",
"10038": "用户的角色必填",
}
//错误码转换 ,兼容需要
... ...
... ... @@ -12,7 +12,7 @@ func init() {
nsV1 := beego.NewNamespace("v1",
beego.NSBefore(middleware.AllowOption),
beego.NSBefore(middleware.LogRequestData),
//beego.NSBefore(middleware.AuthToken),
beego.NSBefore(middleware.AuthToken),
beego.NSNamespace("/department",
beego.NSRouter("/list", &controllers.CompanyController{}, "get:DepartmentList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"),
... ... @@ -35,10 +35,10 @@ func init() {
beego.NSRouter("/role", &controllers.RbacController{}, "get:RoleList"),
),
beego.NSNamespace("/user/",
beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
// beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"),
beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"),
beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"),
// beego.NSRouter("/delete", &controllers.CompanyController{}, "post:PositionDelete"),
),
beego.NSNamespace("/auth",
beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"),
... ... @@ -50,10 +50,13 @@ func init() {
beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"),
beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"),
),
beego.NSNamespace("common",
beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"),
beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),
beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"),
beego.NSNamespace("/template",
beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"),
beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"),
beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"),
beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"),
beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"),
),
)
... ...
package agg
import (
"encoding/json"
"fmt"
orm2 "github.com/astaxie/beego/orm"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"strconv"
)
func getUsers(jsonData string) (v []models.User, err error) {
var vObjs []protocol.VisibleObject
var ids []int64
var id int64
if err = json.Unmarshal([]byte(jsonData), &vObjs); err != nil {
return
}
for i := 0; i < len(vObjs); i++ {
if vObjs[i].Type != models.VisibleObject_User {
continue
}
if id, err = strconv.ParseInt(vObjs[i].Id, 10, 64); err != nil {
return
}
if id == 0 {
continue
}
ids = append(ids, id)
}
if len(ids) == 0 {
return
}
return models.GetUserNameByIds(ids)
}
func getDepartments(jsonData string) (v []models.Department, err error) {
var vObjs []protocol.VisibleObject
var ids []int64
var id int64
if err = json.Unmarshal([]byte(jsonData), &vObjs); err != nil {
return
}
for i := 0; i < len(vObjs); i++ {
if vObjs[i].Type != models.VisibleObject_Department {
continue
}
if id, err = strconv.ParseInt(vObjs[i].Id, 10, 64); err != nil {
return
}
if id == 0 {
continue
}
ids = append(ids, id)
}
if len(ids) == 0 {
return
}
return models.GetDepartmentByIds(ids)
}
func GetVisibleObject(jsonData string) (v []protocol.VisibleObject, err error) {
var (
users []models.User
departments []models.Department
)
if len(jsonData) == 0 {
return
}
if departments, err = getDepartments(jsonData); err != nil && err != orm2.ErrNoRows {
log.Error(err.Error())
return
}
for i := range departments {
v = append(v, protocol.VisibleObject{
Id: fmt.Sprintf("%v", departments[i].Id),
Name: departments[i].Name,
Type: models.VisibleObject_Department,
})
}
if users, err = getUsers(jsonData); err != nil && err != orm2.ErrNoRows {
log.Error(err.Error())
return
}
for i := range users {
v = append(v, protocol.VisibleObject{
Id: fmt.Sprintf("%v", users[i].Id),
Name: users[i].NickName,
Type: models.VisibleObject_User,
})
}
return
}
... ...
... ... @@ -2,16 +2,19 @@ package audit
import (
"database/sql"
"encoding/json"
"fmt"
orm2 "github.com/astaxie/beego/orm"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/services/agg"
"oppmg/utils"
"strings"
"time"
)
//添加模板
func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) {
var (
auditForm *models.AuditForm
... ... @@ -27,6 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
//模板
{
template = &models.AuditTemplate{
ChanceTypeId: request.Template.ChanceTypeId,
CompanyId: int(companyId),
Name: request.Template.Name,
Doc: request.Template.Doc,
... ... @@ -74,6 +78,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
return
}
//模板更新
func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) {
var (
template *models.AuditTemplate
... ... @@ -176,8 +181,158 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input
return
}
//模板列表
func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) {
var ()
var (
chanceTypes []*models.ChanceType
templates []*models.AuditTemplate
)
if chanceTypes, err = models.GetChanceTypeByCompany(int(companyId)); err != nil {
log.Error("get:%v msg:%v", companyId, err.Error())
return
}
rsp = &protocol.TemplateListResponse{}
for i := 0; i < len(chanceTypes); i++ {
t := chanceTypes[i]
item := &protocol.TemplateList{
Id: t.Id,
Name: t.Name,
Icon: t.Icon,
}
rsp.List = append(rsp.List, item)
if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
log.Error(err.Error())
continue
}
for j := range templates {
temp := templates[j]
var vObj []protocol.VisibleObject
//TODO:可见
//1.检查可见性
//2.可见对象 VisibleObject
if temp.VisibleType == models.VisibleTypeDepartment {
if vObj, err = agg.GetVisibleObject(temp.VisibleObject); err != nil {
log.Error(err.Error())
return
}
}
tempItem := &protocol.TemplateItem{
Id: temp.Id,
Name: temp.Name,
Doc: temp.Doc,
Icon: temp.Icon,
EnableStatus: temp.EnableStatus,
Sort: temp.SortNum,
VisibleType: temp.VisibleType,
VisibleObject: vObj,
}
item.Templates = append(item.Templates, tempItem)
}
}
return
}
//编辑可见范围
func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVisibleRequest) (rsp *protocol.TemplateEditVisibleResponse, err error) {
var (
template *models.AuditTemplate
data []byte
)
rsp = &protocol.TemplateEditVisibleResponse{}
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
log.Error(err.Error())
return
}
if template.CompanyId != int(companyId) {
err = protocol.NewErrWithMessage("10027")
log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, template.CompanyId)
return
}
if data, err = json.Marshal(request.VisibleObject); err != nil {
log.Error(err.Error())
return
}
if err = utils.UpdateTableByMap(template, map[string]interface{}{"VisibleObject": string(data)}); err != nil {
log.Error(err.Error())
return
}
return
}
//操作一级分类
func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) {
var (
chanceType *models.ChanceType
)
rsp = &protocol.TemplateOperateCategoryResponse{}
if request.Id > 0 { //编辑
if chanceType, err = models.GetChanceTypeById(request.Id); err != nil {
log.Error(err.Error())
return
}
if chanceType.CompanyId != int(companyId) {
err = protocol.NewErrWithMessage("10027")
log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId)
}
if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "UpdateAt": time.Now()}); err != nil {
log.Error(err.Error())
return
}
return
}
chanceType = &models.ChanceType{
Name: request.Name,
Icon: request.Icon,
CompanyId: int(companyId),
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if _, err = models.AddChanceType(chanceType); err != nil {
log.Error(err.Error())
}
return
}
//获取模板详情
func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) {
var (
template *models.AuditTemplate
auditForm []*models.AuditForm
)
rsp = &protocol.TemplateGetResponse{}
if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error())
return
}
{
rsp.Template = protocol.Template{
Id: template.Id,
ChanceTypeId: template.ChanceTypeId,
Name: template.Name,
Doc: template.Doc,
Icon: template.Icon,
}
rsp.Example = template.Example
if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil {
if err == sql.ErrNoRows {
err = nil
}
return
}
for i := range auditForm {
input := auditForm[i]
rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{
Id: input.Id,
Sort: input.SortNum,
Lable: input.InputType,
Required: int(input.Required),
SectionType: input.Section,
})
}
}
return
}
... ...
... ... @@ -6,7 +6,7 @@ import (
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"strconv"
"oppmg/services/agg"
"time"
)
... ... @@ -110,7 +110,7 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
Status: int8(bulletin.Status),
CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
}
if item.Receiver, err = getUsersName(bulletin.Receiver); err != nil {
if item.Receiver, err = agg.GetVisibleObject(bulletin.Receiver); err != nil {
log.Error(err.Error())
continue
}
... ... @@ -120,36 +120,6 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
return
}
func getUsers(idsstr string) (v []models.User, err error) {
var idlist []string
var ids []int64
var id int64
if err = json.Unmarshal([]byte(idsstr), &idlist); err != nil {
return
}
for i := 0; i < len(idlist); i++ {
if id, err = strconv.ParseInt(idlist[i], 10, 64); err != nil {
return
}
ids = append(ids, id)
}
return models.GetUserNameByIds(ids)
}
func getUsersName(idsStr string) (v []protocol.Receiver, err error) {
var users []models.User
if users, err = getUsers(idsStr); err != nil {
return
}
for i := range users {
v = append(v, protocol.Receiver{
Id: users[i].Id,
NickName: users[i].NickName,
})
}
return
}
//公告详情
func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) (rsp *protocol.GetBulletinResponse, err error) {
var (
... ... @@ -195,7 +165,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest)
return
}
}
if rsp.Receiver, err = getUsersName(bulletin.Receiver); err != nil {
if rsp.Receiver, err = agg.GetVisibleObject(bulletin.Receiver); err != nil {
log.Error(err.Error())
return
}
... ...
package common
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
)
func SelectorDepartment(companyid int64) []protocol.DepartmentBase {
const dataSql string = `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0`
var (
err error
departs []protocol.DepartmentBase
)
err = utils.ExecuteQueryAll(&departs, dataSql, companyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return departs
}
func SelectorRoleAll(companyid int64) []protocol.RoleBase {
const datasql string = `SELECT id,pid,name,types,is_default FROM role WHERE company_id = ? AND delete_at =0`
var (
err error
roles []protocol.RoleBase
)
err = utils.ExecuteQueryAll(&roles, datasql, companyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return roles
}
func FilterRoleAll(adminid int64, companyid int64, list []protocol.RoleBase) []protocol.RoleBase {
var (
newlist []protocol.RoleBase
admingoroupId int64
)
companyInfo, err := models.GetCompanyById(companyid)
if err != nil {
e := fmt.Errorf("GetCompanyById(%d) err:%s", companyid, err)
log.Error(e.Error())
return newlist
}
if companyInfo.AdminId == adminid {
return list
}
for _, v := range list {
if v.IsDefault == models.ROLE_DEFAULR && v.Types == models.ROLETYPES_GROUP {
admingoroupId = v.Id
}
}
for k, v := range list {
if v.Id == admingoroupId || v.ParentId == admingoroupId {
continue
}
newlist = append(newlist, list[k])
}
return newlist
}
func FilterRoleGroup(adminid int64, companyid int64, list []protocol.RoleBase) []protocol.RoleBase {
var (
newlist []protocol.RoleBase
)
companyInfo, err := models.GetCompanyById(companyid)
if err != nil {
e := fmt.Errorf("GetCompanyById(%d) err:%s", companyid, err)
log.Error(e.Error())
return newlist
}
if companyInfo.AdminId != adminid {
for k, v := range list {
if v.Types == models.ROLETYPES_GROUP && v.IsDefault == models.ROLE_DEFAULR_NOT {
newlist = append(newlist, list[k])
}
}
return newlist
}
for k, v := range list {
if v.Types == models.ROLETYPES_GROUP {
newlist = append(newlist, list[k])
}
}
return newlist
}
func SelectorPosition(companyid int64) []protocol.PositionBase {
const datasql string = `SELECT id,parent_id,name FROM position WHERE company_id =? AND delete_at =0`
var (
err error
positions []protocol.PositionBase
)
err = utils.ExecuteQueryAll(&positions, datasql, companyid)
if err != nil {
e := fmt.Errorf("EXECUTE SQL err:%s", err)
log.Error(e.Error())
}
return positions
}
... ... @@ -355,6 +355,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
var manage []protocol.DepartmentManager
manage = v.GetManages()
depart.Manages = manage
depart.Members = v.GetMembers()
departs = append(departs, depart)
}
... ...
... ... @@ -137,41 +137,32 @@ func validCompanyPosition(companyid int64, positionid []int64) error {
//registUser 注册用户
func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
var (
err error
usrData *models.User
err error
// usrData *models.User
)
usrData, err = models.GetUserByPhone(userIn.Phone)
_, err = models.GetUserByPhone(userIn.Phone)
if err == nil {
return nil
}
if err != nil && err != orm.ErrNoRows {
return err
}
if err == orm.ErrNoRows {
//用户不存在 添加用户
_, err := models.AddUser(userIn, o)
if err != nil {
return err
}
}
if err == nil {
// 用户存在,更新用户
usrData.NickName = userIn.NickName
err = models.UpdateUserById(usrData, []string{"NickName"}, o)
if err != nil {
return err
}
}
musercompany := &models.UserCompany{
CompanyId: companyid,
UserId: userIn.Id,
}
ok := models.ExistUserCompany(usrData.Id, companyid)
if !ok {
_, err = models.AddUserCompany(musercompany, o)
if err != nil {
return err
}
_, err = models.AddUserCompany(musercompany, o)
if err != nil {
return err
}
err = models.EnableUserCompany(usrData.Id, companyid)
return err
//更新
return nil
}
func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error {
... ... @@ -347,77 +338,10 @@ func UserEdit(param protocol.RequestUserEdit) error {
return nil
}
func UserDelete(userid, companyid int64) error {
ok := models.ExistUserCompany(userid, companyid)
if !ok {
e := fmt.Errorf("ExistUserCompany(userid, companyid) [%d,%d] ==false ", userid, companyid)
log.Error(e.Error())
return protocol.NewErrWithMessage("1")
}
o := orm.NewOrm()
_, err := o.QueryTable(&models.UserCompany{}).
Filter("user_id", userid).
Filter("company_id").
Update(orm.Params{
"delete_at": time.Now().String(),
})
if err != nil {
e := fmt.Errorf("UserDelete err:%s", err)
log.Error(e.Error())
return protocol.NewErrWithMessage("1")
}
func UserDelete(param protocol.RequestUserAdd) error {
return nil
}
func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) {
datasql := `SELECT 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 `
countSql := `SELECT count(*)
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 `
var (
whereString string
cond []interface{}
)
cond = append(cond, param.Companyid)
if len(param.NickName) > 0 {
whereString += ` AND b.nick_name LIKE ? `
likeCond := "%" + param.NickName + "%"
cond = append(cond, likeCond)
}
var (
result []protocol.UserListItem
pageInfo protocol.ResponsePageInfo
err error
responseData protocol.ResponseUserList
)
p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString)
p.AddParam(cond...)
p.LimitPage(param.PageIndex, param.PageSize)
pageInfo, err = p.Query(&result)
if err != nil {
e := fmt.Errorf("page data err:%s", err)
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)
// }
responseData.ResponsePageInfo = pageInfo
responseData.List = result
return responseData, nil
}
func GetUserDepartment(user int64, companyid int64) {
}
func GetUserPosition(user int64, companyid int64) {
func UserList() error {
return nil
}
... ...
... ... @@ -64,11 +64,4 @@ func ExistLoginToken(userid int64) bool {
return false
}
func DeleteLoginToken(userid int64) error {
client := redis.GetRedis()
key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)
err:=client.Del(key).Err()
return err
}
//消息发布订阅
... ...
package utils
... ...
package utils
import (
"regexp"
)
var (
PhoneMatch, _ = regexp.Compile(`^1[0-9]{10}$`)
EmailMatch, _ = regexp.Compile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$`)
ChineseMatch, _ = regexp.Compile(`[\u4e00-\u9fa5]`)
)