作者 唐旭辉

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

# Conflicts:
#	controllers/common.go
#	controllers/company.go
#	models/user_company.go
#	protocol/company.go
#	protocol/message.go
#	routers/router.go
#	services/company/user.go
@@ -5,10 +5,7 @@ import ( @@ -5,10 +5,7 @@ import (
5 "oppmg/common/log" 5 "oppmg/common/log"
6 "oppmg/protocol" 6 "oppmg/protocol"
7 servecompany "oppmg/services/company" 7 servecompany "oppmg/services/company"
8 - "oppmg/storage/redisdata"  
9 - "oppmg/utils"  
10 "strconv" 8 "strconv"
11 - "strings"  
12 ) 9 )
13 10
14 type CompanyController struct { 11 type CompanyController struct {
@@ -229,35 +226,13 @@ func (c *CompanyController) UserAdd() { @@ -229,35 +226,13 @@ func (c *CompanyController) UserAdd() {
229 msg = protocol.BadRequestParam("1") 226 msg = protocol.BadRequestParam("1")
230 return 227 return
231 } 228 }
232 - name := []rune(strings.TrimSpace(param.Name))  
233 - if len(name) == 0 {  
234 - msg = protocol.BadRequestParam("10035")  
235 - return  
236 - }  
237 - if len(name) > 10 {  
238 - msg = protocol.BadRequestParam("10034")  
239 - return  
240 - }  
241 - ok := utils.PhoneMatch.MatchString(param.Phone)  
242 - if !ok {  
243 - msg = protocol.BadRequestParam("10036")  
244 - return  
245 - }  
246 - if len(param.Departments) == 0 {  
247 - msg = protocol.BadRequestParam("10037")  
248 - return  
249 - }  
250 - if len(param.Roles) == 0 {  
251 - msg = protocol.BadRequestParam("10038")  
252 - return  
253 - }  
254 param.CompanyId = c.GetCompanyId() 229 param.CompanyId = c.GetCompanyId()
255 err := servecompany.UserAdd(param) 230 err := servecompany.UserAdd(param)
256 msg = protocol.NewReturnResponse(nil, err) 231 msg = protocol.NewReturnResponse(nil, err)
257 return 232 return
258 } 233 }
259 234
260 -//UserEdit 编辑用户 235 +//UserAdd 添加用户
261 //@Router /user/edit [post] 236 //@Router /user/edit [post]
262 func (c *CompanyController) UserEdit() { 237 func (c *CompanyController) UserEdit() {
263 var msg *protocol.ResponseMessage 238 var msg *protocol.ResponseMessage
@@ -270,24 +245,6 @@ func (c *CompanyController) UserEdit() { @@ -270,24 +245,6 @@ func (c *CompanyController) UserEdit() {
270 msg = protocol.BadRequestParam("1") 245 msg = protocol.BadRequestParam("1")
271 return 246 return
272 } 247 }
273 - name := []rune(strings.TrimSpace(param.Name))  
274 - if len(name) == 0 {  
275 - msg = protocol.BadRequestParam("10035")  
276 - return  
277 - }  
278 - if len(name) > 10 {  
279 - msg = protocol.BadRequestParam("10034")  
280 - return  
281 - }  
282 -  
283 - if len(param.Departments) == 0 {  
284 - msg = protocol.BadRequestParam("10037")  
285 - return  
286 - }  
287 - if len(param.Roles) == 0 {  
288 - msg = protocol.BadRequestParam("10038")  
289 - return  
290 - }  
291 param.CompanyId = c.GetCompanyId() 248 param.CompanyId = c.GetCompanyId()
292 err := servecompany.UserEdit(param) 249 err := servecompany.UserEdit(param)
293 msg = protocol.NewReturnResponse(nil, err) 250 msg = protocol.NewReturnResponse(nil, err)
@@ -46,6 +46,35 @@ func (this *TemplateController) TemplateAdd() { @@ -46,6 +46,35 @@ func (this *TemplateController) TemplateAdd() {
46 return 46 return
47 } 47 }
48 48
  49 +//TemplateGet
  50 +//@router /templateGet [post]
  51 +func (this *TemplateController) TemplateGet() {
  52 + var msg *protocol.ResponseMessage
  53 + defer func() {
  54 + this.ResposeJson(msg)
  55 + }()
  56 + var request *protocol.TemplateGetRequest
  57 +
  58 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  59 + log.Error("json 解析失败", err)
  60 + msg = protocol.BadRequestParam("1")
  61 + return
  62 + }
  63 + uid := this.GetUserId()
  64 + companyId := this.GetCompanyId()
  65 + if companyId <= 0 {
  66 + log.Debug("companyId:%d err", companyId)
  67 + msg = protocol.BadRequestParam("1")
  68 + return
  69 + }
  70 + if b, m := this.Valid(request); !b {
  71 + msg = m
  72 + return
  73 + }
  74 + rsp, err := audit.TemplateGet(uid, companyId, request)
  75 + msg = protocol.NewReturnResponse(rsp, err)
  76 +}
  77 +
49 //TemplateUpdate 78 //TemplateUpdate
50 //@router /templateUpdate [post] 79 //@router /templateUpdate [post]
51 func (this *TemplateController) TemplateUpdate() { 80 func (this *TemplateController) TemplateUpdate() {
@@ -83,7 +112,7 @@ func (this *TemplateController) TemplateList() { @@ -83,7 +112,7 @@ func (this *TemplateController) TemplateList() {
83 defer func() { 112 defer func() {
84 this.ResposeJson(msg) 113 this.ResposeJson(msg)
85 }() 114 }()
86 - var request *protocol.TemplateUpdateRequest 115 + var request *protocol.TemplateListRequest
87 116
88 if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { 117 if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
89 log.Error("json 解析失败", err) 118 log.Error("json 解析失败", err)
@@ -101,7 +130,65 @@ func (this *TemplateController) TemplateList() { @@ -101,7 +130,65 @@ func (this *TemplateController) TemplateList() {
101 msg = m 130 msg = m
102 return 131 return
103 } 132 }
104 - rsp, err := audit.TemplateUpdate(uid, companyId, request) 133 + rsp, err := audit.TemplateList(uid, companyId, request)
  134 + msg = protocol.NewReturnResponse(rsp, err)
  135 + return
  136 +}
  137 +
  138 +//TemplateEditVisible
  139 +//@router /templateEditVisible [post]
  140 +func (this *TemplateController) TemplateEditVisible() {
  141 + var msg *protocol.ResponseMessage
  142 + defer func() {
  143 + this.ResposeJson(msg)
  144 + }()
  145 + var request *protocol.TemplateEditVisibleRequest
  146 +
  147 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  148 + log.Error("json 解析失败", err)
  149 + msg = protocol.BadRequestParam("1")
  150 + return
  151 + }
  152 + uid := this.GetUserId()
  153 + companyId := this.GetCompanyId()
  154 + if companyId <= 0 {
  155 + log.Debug("companyId:%d err", companyId)
  156 + msg = protocol.BadRequestParam("1")
  157 + return
  158 + }
  159 + if b, m := this.Valid(request); !b {
  160 + msg = m
  161 + return
  162 + }
  163 + rsp, err := audit.TemplateEditVisible(uid, companyId, request)
105 msg = protocol.NewReturnResponse(rsp, err) 164 msg = protocol.NewReturnResponse(rsp, err)
  165 +}
  166 +
  167 +//TemplateOperateCategory
  168 +//@router /templateOperateCategory [post]
  169 +func (this *TemplateController) TemplateOperateCategory() {
  170 + var msg *protocol.ResponseMessage
  171 + defer func() {
  172 + this.ResposeJson(msg)
  173 + }()
  174 + var request *protocol.TemplateOperateCategoryRequest
  175 +
  176 + if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil {
  177 + log.Error("json 解析失败", err)
  178 + msg = protocol.BadRequestParam("1")
  179 + return
  180 + }
  181 + uid := this.GetUserId()
  182 + companyId := this.GetCompanyId()
  183 + if companyId <= 0 {
  184 + log.Debug("companyId:%d err", companyId)
  185 + msg = protocol.BadRequestParam("1")
106 return 186 return
  187 + }
  188 + if b, m := this.Valid(request); !b {
  189 + msg = m
  190 + return
  191 + }
  192 + rsp, err := audit.TemplateOperateCategory(uid, companyId, request)
  193 + msg = protocol.NewReturnResponse(rsp, err)
107 } 194 }
@@ -82,3 +82,14 @@ func DeleteAuditForm(id int) (err error) { @@ -82,3 +82,14 @@ func DeleteAuditForm(id int) (err error) {
82 } 82 }
83 return 83 return
84 } 84 }
  85 +
  86 +// GetAuditFormById retrieves AuditForm by Id. Returns error if
  87 +// Id doesn't exist
  88 +func GetAuditFormByTemplateId(id int) (v []*AuditForm, err error) {
  89 + o := orm.NewOrm()
  90 + sql := `select * from audit_form where audit_template_id =? and enable_status=1 order by sort_num`
  91 + if _, err = o.Raw(sql, id).QueryRows(&v); err == nil {
  92 + return v, nil
  93 + }
  94 + return nil, err
  95 +}
@@ -18,12 +18,23 @@ type AuditTemplate struct { @@ -18,12 +18,23 @@ type AuditTemplate struct {
18 NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"` 18 NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"`
19 SortNum int `orm:"column(sort_num)" description:"自定义排序编号"` 19 SortNum int `orm:"column(sort_num)" description:"自定义排序编号"`
20 VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "` 20 VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "`
  21 + VisibleObject string `orm:"column(visible_object)" description:"可见的对象 部门 指定人 json"`
21 EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"` 22 EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"`
22 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` 23 CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
23 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` 24 UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
24 - Example string `orm:"column(examplte);null" description:"示例"` 25 + Example string `orm:"column(example);null" description:"示例"`
25 } 26 }
26 27
  28 +const (
  29 + VisibleTypeAll = 0
  30 + VisibleTypeDepartment = 1
  31 +)
  32 +
  33 +const (
  34 + VisibleObject_Department = 1
  35 + VisibleObject_User = 2
  36 +)
  37 +
27 func (t *AuditTemplate) TableName() string { 38 func (t *AuditTemplate) TableName() string {
28 return "audit_template" 39 return "audit_template"
29 } 40 }
@@ -80,3 +91,14 @@ func DeleteAuditTemplate(id int64) (err error) { @@ -80,3 +91,14 @@ func DeleteAuditTemplate(id int64) (err error) {
80 } 91 }
81 return 92 return
82 } 93 }
  94 +
  95 +func GetAuditTemplateByTypeId(chanceTypeId int) (v []*AuditTemplate, err error) {
  96 + o := orm.NewOrm()
  97 + _, err = o.QueryTable(&AuditTemplate{}).
  98 + Filter("chance_type_id", chanceTypeId).All(&v)
  99 +
  100 + if err == orm.ErrNoRows {
  101 + return v, nil
  102 + }
  103 + return
  104 +}
@@ -74,10 +74,10 @@ func DeleteChanceType(id int) (err error) { @@ -74,10 +74,10 @@ func DeleteChanceType(id int) (err error) {
74 return 74 return
75 } 75 }
76 76
77 -func GetChanceTypeAll() (v []*ChanceType, err error) { 77 +func GetChanceTypeByCompany(companyId int) (v []*ChanceType, err error) {
78 o := orm.NewOrm() 78 o := orm.NewOrm()
79 - sql := "select * from chance_type "  
80 - if _, err = o.Raw(sql).QueryRows(&v); err == nil { 79 + sql := "select * from chance_type where company_id=?"
  80 + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil {
81 return 81 return
82 } 82 }
83 return 83 return
@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 type Company struct { 10 type Company struct {
11 Id int64 `orm:"column(id);auto"` 11 Id int64 `orm:"column(id);auto"`
12 Name string `orm:"column(name);size(40)"` 12 Name string `orm:"column(name);size(40)"`
13 - AdminId int64 `orm:"column(admin_id)"` 13 + Admin_id int64 `orm:"column(admin_id)"`
14 CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"` 14 CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now"`
15 UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` 15 UpdateAt time.Time `orm:"column(update_at);type(timestamp)"`
16 DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` 16 DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"`
@@ -75,6 +75,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { @@ -75,6 +75,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager {
75 return managesdata 75 return managesdata
76 } 76 }
77 77
  78 +func (t *Department) GetMembers() []protocol.DepartmentMember {
  79 + ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id))
  80 + if err != nil {
  81 + log.Error(err.Error())
  82 + return nil
  83 + }
  84 + users, err := getUserNameByIds(ids)
  85 + if err != nil {
  86 + log.Error("GetUserNameByIds err :%s", err)
  87 + return nil
  88 + }
  89 + managesdata := []protocol.DepartmentMember{}
  90 + for _, v := range users {
  91 + m := protocol.DepartmentMember{
  92 + Id: v.Id, Name: v.NickName,
  93 + }
  94 + managesdata = append(managesdata, m)
  95 + }
  96 + return managesdata
  97 +}
  98 +
78 // AddDepartment insert a new Department into database and returns 99 // AddDepartment insert a new Department into database and returns
79 // last inserted Id on success. 100 // last inserted Id on success.
80 func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { 101 func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) {
@@ -154,3 +175,15 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) { @@ -154,3 +175,15 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) {
154 All(&result) 175 All(&result)
155 return result, err 176 return result, err
156 } 177 }
  178 +
  179 +func GetDepartmentByIds(departmentIds []int64) ([]Department, error) {
  180 + var (
  181 + result []Department
  182 + err error
  183 + )
  184 + o := orm.NewOrm()
  185 + _, err = o.QueryTable(&Department{}).
  186 + Filter("id__in", departmentIds).
  187 + All(&result)
  188 + return result, err
  189 +}
@@ -62,9 +62,7 @@ func AddUser(m *User, om ...orm.Ormer) (id int64, err error) { @@ -62,9 +62,7 @@ func AddUser(m *User, om ...orm.Ormer) (id int64, err error) {
62 } else { 62 } else {
63 o = orm.NewOrm() 63 o = orm.NewOrm()
64 } 64 }
65 - m.DeleteAt = time.Unix(0, 0)  
66 - m.EnableStatus = USER_ENABLE_YES  
67 - m.CreateAt = time.Now() 65 +
68 id, err = o.Insert(m) 66 id, err = o.Insert(m)
69 return 67 return
70 } 68 }
@@ -82,17 +80,16 @@ func GetUserById(id int64) (v *User, err error) { @@ -82,17 +80,16 @@ func GetUserById(id int64) (v *User, err error) {
82 80
83 // UpdateUser updates User by Id and returns error if 81 // UpdateUser updates User by Id and returns error if
84 // the record to be updated doesn't exist 82 // the record to be updated doesn't exist
85 -func UpdateUserById(m *User, col []string, om ...orm.Ormer) (err error) {  
86 - var o orm.Ormer  
87 - if len(om) == 0 {  
88 - o = orm.NewOrm()  
89 - } else {  
90 - o = om[0]  
91 - } 83 +func UpdateUserById(m *User) (err error) {
  84 + o := orm.NewOrm()
  85 + v := User{Id: m.Id}
  86 + // ascertain id exists in the database
  87 + if err = o.Read(&v); err == nil {
92 var num int64 88 var num int64
93 - if num, err = o.Update(m, col...); err == nil { 89 + if num, err = o.Update(m); err == nil {
94 fmt.Println("Number of records updated in database:", num) 90 fmt.Println("Number of records updated in database:", num)
95 } 91 }
  92 + }
96 return 93 return
97 } 94 }
98 95
1 -package models  
2 -  
3 -import (  
4 - "errors"  
5 - "fmt"  
6 - "oppmg/common/log"  
7 - "time"  
8 -  
9 - "github.com/astaxie/beego/orm"  
10 -)  
11 -  
12 -type UserCompany struct {  
13 - Id int64 `orm:"column(id);auto" description:"唯一标识"`  
14 - CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`  
15 - UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`  
16 - ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"`  
17 - CommentTotal int `orm:"column(comment_total)" description:"发表评论总数"`  
18 - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`  
19 - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`  
20 - Enable int8 `orm:"column(enable)"`  
21 - DeleteAt time.Time `orm:"column(delete_at)"`  
22 -}  
23 -  
24 -func (t *UserCompany) TableName() string {  
25 - return "user_company"  
26 -}  
27 -  
28 -//用户的公司是否有效  
29 -const (  
30 - USERCOMPANY_ENABLE_YES int8 = 1 //有效  
31 - USERCOMPANY_ENABLE_NO int8 = 2 // 无效  
32 -)  
33 -  
34 -func (t *UserCompany) IsEnable() bool {  
35 - switch t.Enable {  
36 - case USERCOMPANY_ENABLE_YES:  
37 - return true  
38 - case USERCOMPANY_ENABLE_NO:  
39 - return false  
40 - }  
41 - return false  
42 -}  
43 -  
44 -func (t *UserCompany) IsDelete() bool {  
45 - log.Debug("deleteTime:%d", t.DeleteAt.Unix())  
46 - if t.DeleteAt.Unix() > 0 {  
47 - return true  
48 - }  
49 - return false  
50 -}  
51 -  
52 -func init() {  
53 - orm.RegisterModel(new(UserCompany))  
54 -}  
55 -  
56 -// AddUserCompany insert a new UserCompany into database and returns  
57 -// last inserted Id on success.  
58 -func AddUserCompany(m *UserCompany, o orm.Ormer) (id int64, err error) {  
59 - m.CreateAt = time.Now()  
60 - m.DeleteAt = time.Unix(0, 0)  
61 - m.UpdateAt = time.Now()  
62 - m.Enable = USERCOMPANY_ENABLE_YES  
63 - id, err = o.Insert(m)  
64 - return  
65 -}  
66 -  
67 -// UpdateUserCompany updates UserCompany by Id and returns error if  
68 -// the record to be updated doesn't exist  
69 -func UpdateUserCompanyById(m *UserCompany) (err error) {  
70 - o := orm.NewOrm()  
71 - v := UserCompany{Id: m.Id}  
72 - // ascertain id exists in the database  
73 - if err = o.Read(&v); err == nil {  
74 - var num int64  
75 - if num, err = o.Update(m); err == nil {  
76 - fmt.Println("Number of records updated in database:", num)  
77 - }  
78 - }  
79 - return  
80 -}  
81 -  
82 -func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) {  
83 - o := orm.NewOrm()  
84 - var data []*UserCompany  
85 - _, err := o.QueryTable(&UserCompany{}).  
86 - Filter("user_id", userid).  
87 - Filter("company_id", companyId).  
88 - Filter("delete_at", 0).  
89 - All(&data)  
90 - if err != nil {  
91 - return nil, err  
92 - }  
93 - if len(data) == 0 {  
94 - return nil, errors.New("UserCompany not found")  
95 - }  
96 - return data[0], nil  
97 -}  
98 -  
99 -func ExistUserCompany(userid int64, companyId int64) bool {  
100 - o := orm.NewOrm()  
101 - ok := o.QueryTable(&UserCompany{}).  
102 - Filter("user_id", userid).  
103 - Filter("company_id", companyId).  
104 - Filter("delete_at", 0).  
105 - Exist()  
106 - return ok  
107 -}  
108 -  
109 -func EnableUserCompany(userid int64, companyid int64) error {  
110 - o := orm.NewOrm()  
111 - _, err := o.QueryTable(&UserCompany{}).  
112 - Filter("user_id", userid).  
113 - Filter("company_id", companyid).Update(orm.Params{  
114 - "enable": USERCOMPANY_ENABLE_YES,  
115 - "delete_at": 0,  
116 - })  
117 - return err  
118 -}  
@@ -86,18 +86,29 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { @@ -86,18 +86,29 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) {
86 } 86 }
87 return 87 return
88 } 88 }
89 -func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) { 89 +
  90 +// DeleteUserDepartment deletes UserDepartment by Id and returns error if
  91 +// the record to be deleted doesn't exist
  92 +func DeleteUserDepartment(id int64) (err error) {
90 o := orm.NewOrm() 93 o := orm.NewOrm()
91 - var (  
92 - err error  
93 - result []*UserDepartment  
94 - )  
95 - _, err = o.QueryTable(&UserDepartment{}).  
96 - Filter("user_id", userid).  
97 - Filter("company_id", companyid).  
98 - Filter("enable_status", 1).  
99 - All(&result)  
100 - return result, err 94 + v := UserDepartment{Id: id}
  95 + // ascertain id exists in the database
  96 + if err = o.Read(&v); err == nil {
  97 + var num int64
  98 + if num, err = o.Delete(&UserDepartment{Id: id}); err == nil {
  99 + fmt.Println("Number of records deleted in database:", num)
  100 + }
  101 + }
  102 + return
  103 +}
  104 +
  105 +func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) {
  106 + o := orm.NewOrm()
  107 + sql := "select user_id from user_department where company_id=? and department_id =?"
  108 + if _, err = o.Raw(sql, companyId, dId).QueryRows(&v); err != nil {
  109 + return
  110 + }
  111 + return
101 } 112 }
102 113
103 func CountUserDepartByDepart(departid int64) (int64, error) { 114 func CountUserDepartByDepart(departid int64) (int64, error) {
@@ -61,18 +61,45 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { @@ -61,18 +61,45 @@ func AddUserPosition(m *UserPosition) (id int64, err error) {
61 return 61 return
62 } 62 }
63 63
64 -func GetUserPosition(userid, companyid int64) ([]*UserPosition, error) { 64 +// GetUserPositionById retrieves UserPosition by Id. Returns error if
  65 +// Id doesn't exist
  66 +func GetUserPositionById(id int64) (v *UserPosition, err error) {
65 o := orm.NewOrm() 67 o := orm.NewOrm()
66 - var (  
67 - err error  
68 - result []*UserPosition  
69 - )  
70 - _, err = o.QueryTable(&UserPosition{}).  
71 - Filter("user_id", userid).  
72 - Filter("company_id", companyid).  
73 - Filter("enable_status", 1).  
74 - All(&result)  
75 - return result, err 68 + v = &UserPosition{Id: id}
  69 + if err = o.Read(v); err == nil {
  70 + return v, nil
  71 + }
  72 + return nil, err
  73 +}
  74 +
  75 +// UpdateUserPosition updates UserPosition by Id and returns error if
  76 +// the record to be updated doesn't exist
  77 +func UpdateUserPositionById(m *UserPosition) (err error) {
  78 + o := orm.NewOrm()
  79 + v := UserPosition{Id: m.Id}
  80 + // ascertain id exists in the database
  81 + if err = o.Read(&v); err == nil {
  82 + var num int64
  83 + if num, err = o.Update(m); err == nil {
  84 + fmt.Println("Number of records updated in database:", num)
  85 + }
  86 + }
  87 + return
  88 +}
  89 +
  90 +// DeleteUserPosition deletes UserPosition by Id and returns error if
  91 +// the record to be deleted doesn't exist
  92 +func DeleteUserPosition(id int64) (err error) {
  93 + o := orm.NewOrm()
  94 + v := UserPosition{Id: id}
  95 + // ascertain id exists in the database
  96 + if err = o.Read(&v); err == nil {
  97 + var num int64
  98 + if num, err = o.Delete(&UserPosition{Id: id}); err == nil {
  99 + fmt.Println("Number of records deleted in database:", num)
  100 + }
  101 + }
  102 + return
76 } 103 }
77 104
78 func CountUserPositionByPosition(positionid int64) (int64, error) { 105 func CountUserPositionByPosition(positionid int64) (int64, error) {
@@ -59,18 +59,45 @@ func AddUserRole(m *UserRole) (id int64, err error) { @@ -59,18 +59,45 @@ func AddUserRole(m *UserRole) (id int64, err error) {
59 return 59 return
60 } 60 }
61 61
62 -func GetUserRole(userid, companyid int64) ([]*UserRole, error) { 62 +// GetUserRoleById retrieves UserRole by Id. Returns error if
  63 +// Id doesn't exist
  64 +func GetUserRoleById(id int) (v *UserRole, err error) {
63 o := orm.NewOrm() 65 o := orm.NewOrm()
64 - var (  
65 - err error  
66 - result []*UserRole  
67 - )  
68 - _, err = o.QueryTable(&UserRole{}).  
69 - Filter("user_id", userid).  
70 - Filter("company_id", companyid).  
71 - Filter("enable_status", 1).  
72 - All(&result)  
73 - return result, err 66 + v = &UserRole{Id: id}
  67 + if err = o.Read(v); err == nil {
  68 + return v, nil
  69 + }
  70 + return nil, err
  71 +}
  72 +
  73 +// UpdateUserRole updates UserRole by Id and returns error if
  74 +// the record to be updated doesn't exist
  75 +func UpdateUserRoleById(m *UserRole) (err error) {
  76 + o := orm.NewOrm()
  77 + v := UserRole{Id: m.Id}
  78 + // ascertain id exists in the database
  79 + if err = o.Read(&v); err == nil {
  80 + var num int64
  81 + if num, err = o.Update(m); err == nil {
  82 + fmt.Println("Number of records updated in database:", num)
  83 + }
  84 + }
  85 + return
  86 +}
  87 +
  88 +// DeleteUserRole deletes UserRole by Id and returns error if
  89 +// the record to be deleted doesn't exist
  90 +func DeleteUserRole(id int) (err error) {
  91 + o := orm.NewOrm()
  92 + v := UserRole{Id: id}
  93 + // ascertain id exists in the database
  94 + if err = o.Read(&v); err == nil {
  95 + var num int64
  96 + if num, err = o.Delete(&UserRole{Id: id}); err == nil {
  97 + fmt.Println("Number of records deleted in database:", num)
  98 + }
  99 + }
  100 + return
74 } 101 }
75 102
76 func CountUserRoleByRole(roleid int64) (int64, error) { 103 func CountUserRoleByRole(roleid int64) (int64, error) {
@@ -16,7 +16,7 @@ type InputElement struct { @@ -16,7 +16,7 @@ type InputElement struct {
16 Lable string `json:"lable"` //标题 16 Lable string `json:"lable"` //标题
17 InputType string `json:"inputType"` //输入类型 17 InputType string `json:"inputType"` //输入类型
18 Required int `json:"required"` //是否必填 18 Required int `json:"required"` //是否必填
19 - CurrentValue string `json:"value"` //"当前填写的值" 19 + CurrentValue string `json:"-"` //"当前填写的值"
20 SectionType int8 `json:"sectionType"` 20 SectionType int8 `json:"sectionType"`
21 21
22 ValueList string `json:"-"` //输入候选值 value_list 22 ValueList string `json:"-"` //输入候选值 value_list
@@ -106,9 +106,10 @@ type TemplateUpdateResponse struct { @@ -106,9 +106,10 @@ type TemplateUpdateResponse struct {
106 type TemplateListRequest struct { 106 type TemplateListRequest struct {
107 } 107 }
108 type TemplateListResponse struct { 108 type TemplateListResponse struct {
  109 + List []*TemplateList `json:"list"`
109 } 110 }
110 111
111 -type ChanceType struct { 112 +type TemplateList struct {
112 Id int `json:"id"` 113 Id int `json:"id"`
113 Name string `json:"name"` 114 Name string `json:"name"`
114 Icon string `json:"icon"` 115 Icon string `json:"icon"`
@@ -127,7 +128,33 @@ type TemplateItem struct { @@ -127,7 +128,33 @@ type TemplateItem struct {
127 } 128 }
128 129
129 type VisibleObject struct { 130 type VisibleObject struct {
  131 + Id string `json:"id"`
  132 + Name string `json:"name",omitempty`
  133 + Type int `json:"type"` //1:部门 2:指定人员
  134 +}
  135 +
  136 +/*TemplateEditVisible */
  137 +type TemplateEditVisibleRequest struct {
  138 + Id int `json:"id"` //模板编号
  139 + VisibleObject []VisibleObject `json:"visibleObject" valid:"Required"`
  140 +}
  141 +type TemplateEditVisibleResponse struct {
  142 +}
  143 +
  144 +/*TemplateAddCategory */
  145 +type TemplateOperateCategoryRequest struct {
130 Id int `json:"id"` 146 Id int `json:"id"`
131 - Name string `json:"name,omitempty"`  
132 - Type int //1:部门 2:指定人员 147 + Name string `json:"name"`
  148 + Icon string `json:"icon"`
  149 +}
  150 +type TemplateOperateCategoryResponse struct {
  151 +}
  152 +
  153 +/*TemplateGet */
  154 +type TemplateGetRequest struct {
  155 + Id int `json:"id" valid:"Required"`
  156 +}
  157 +type TemplateGetResponse struct {
  158 + Template Template `json:"template"`
  159 + Example string `json:"example"` //示例`
133 } 160 }
@@ -19,7 +19,7 @@ type BulletinReleaseRequest struct { @@ -19,7 +19,7 @@ type BulletinReleaseRequest struct {
19 AllowClose int `json:"allow_close"` 19 AllowClose int `json:"allow_close"`
20 //AllowCondition int `json:"allow_condition"` 20 //AllowCondition int `json:"allow_condition"`
21 QuestionSwitch int `json:"question_switch"` 21 QuestionSwitch int `json:"question_switch"`
22 - Receiver []string `json:"receiver" valid:"Required"` 22 + Receiver []VisibleObject `json:"receiver" valid:"Required"`
23 Question Question `json:"question"` 23 Question Question `json:"question"`
24 Cover Cover `json:"cover" valid:"Required"` 24 Cover Cover `json:"cover" valid:"Required"`
25 } 25 }
@@ -57,7 +57,7 @@ type BulletinItem struct { @@ -57,7 +57,7 @@ type BulletinItem struct {
57 Type int8 `json:"type"` 57 Type int8 `json:"type"`
58 Title string `json:"title"` 58 Title string `json:"title"`
59 Status int8 `json:"status"` 59 Status int8 `json:"status"`
60 - Receiver []Receiver `json:"receiver" valid:"Required"` 60 + Receiver []VisibleObject `json:"receiver" valid:"Required"`
61 CreateAt string `json:"time"` 61 CreateAt string `json:"time"`
62 } 62 }
63 63
@@ -73,7 +73,7 @@ type GetBulletinResponse struct { @@ -73,7 +73,7 @@ type GetBulletinResponse struct {
73 AllowClose int `json:"allow_close"` 73 AllowClose int `json:"allow_close"`
74 //AllowCondition int `json:"allow_condition"` 74 //AllowCondition int `json:"allow_condition"`
75 QuestionSwitch int `json:"question_switch"` 75 QuestionSwitch int `json:"question_switch"`
76 - Receiver []Receiver `json:"receiver" valid:"Required"` 76 + Receiver []VisibleObject `json:"receiver" valid:"Required"`
77 Question Question `json:"question"` 77 Question Question `json:"question"`
78 Cover Cover `json:"cover" valid:"Required"` 78 Cover Cover `json:"cover" valid:"Required"`
79 } 79 }
@@ -92,7 +92,7 @@ type UpdateBulletinRequest struct { @@ -92,7 +92,7 @@ type UpdateBulletinRequest struct {
92 AllowClose int `json:"allow_close"` 92 AllowClose int `json:"allow_close"`
93 //AllowCondition int `json:"allow_condition"` 93 //AllowCondition int `json:"allow_condition"`
94 QuestionSwitch int `json:"question_switch"` 94 QuestionSwitch int `json:"question_switch"`
95 - Receiver []string `json:"receiver" valid:"Required"` 95 + Receiver []VisibleObject `json:"receiver" valid:"Required"`
96 Question Question `json:"question"` 96 Question Question `json:"question"`
97 Cover Cover `json:"cover" valid:"Required"` 97 Cover Cover `json:"cover" valid:"Required"`
98 } 98 }
@@ -12,26 +12,3 @@ type ResponsePageInfo struct { @@ -12,26 +12,3 @@ type ResponsePageInfo struct {
12 CurrentPage int `json:"pageNumber"` 12 CurrentPage int `json:"pageNumber"`
13 // ListData interface{} `json:"list"` 13 // ListData interface{} `json:"list"`
14 } 14 }
15 -  
16 -// DepartmentBase下拉选择列表-部门  
17 -type DepartmentBase struct {  
18 - Id int64 `json:"id" orm:"column(id)"`  
19 - Name string `json:"name" orm:"column(name)"`  
20 - ParentId int64 `json:"parent_id" orm:"column(parent_id)"`  
21 -}  
22 -  
23 -//RoleBase 下拉选择列表-角色  
24 -type RoleBase struct {  
25 - Id int64 `json:"id" orm:"column(id)"`  
26 - Name string `json:"name" orm:"column(name)"`  
27 - IsDefault int8 `json:"is_default" orm:"column(is_default)"`  
28 - ParentId int64 `json:"parent_id" orm:"column(pid)"`  
29 - Types int8 `json:"types" orm:"column(types)"`  
30 -}  
31 -  
32 -//PositionBase 下拉选择列表-职位  
33 -type PositionBase struct {  
34 - Id int64 `json:"id" orm:"column(id)"`  
35 - Name string `json:"name" orm:"column(name)"`  
36 - ParentId int64 `json:"parent_id" orm:"column(parent_id)"`  
37 -}  
@@ -17,6 +17,11 @@ type DepartmentManager struct { @@ -17,6 +17,11 @@ type DepartmentManager struct {
17 Name string `json:"name"` 17 Name string `json:"name"`
18 } 18 }
19 19
  20 +type DepartmentMember struct {
  21 + Id int64 `json:"id"`
  22 + Name string `json:"name"`
  23 +}
  24 +
20 //RequestDepartmentEdit 编辑 25 //RequestDepartmentEdit 编辑
21 type RequestDepartmentEdit struct { 26 type RequestDepartmentEdit struct {
22 ID int64 `json:"id"` 27 ID int64 `json:"id"`
@@ -90,7 +95,6 @@ type RequestUserEdit struct { @@ -90,7 +95,6 @@ type RequestUserEdit struct {
90 type RequestUserList struct { 95 type RequestUserList struct {
91 RequestPageInfo 96 RequestPageInfo
92 NickName string `json:"nick_name"` 97 NickName string `json:"nick_name"`
93 - Companyid int64 `json:"company_id"`  
94 } 98 }
95 99
96 //ResponseUserList 响应的用户列表 100 //ResponseUserList 响应的用户列表
@@ -21,11 +21,6 @@ var errmessge ErrorMap = map[string]string{ @@ -21,11 +21,6 @@ var errmessge ErrorMap = map[string]string{
21 "10031": "无效角色", 21 "10031": "无效角色",
22 "10032": "无效部门", 22 "10032": "无效部门",
23 "10033": "无效职位", 23 "10033": "无效职位",
24 - "10034": "名字限制10个字符以内",  
25 - "10035": "名字是必填项",  
26 - "10036": "请输入正确的手机格式",  
27 - "10037": "用户的部门必填",  
28 - "10038": "用户的角色必填",  
29 "10039": "用户已存在", 24 "10039": "用户已存在",
30 } 25 }
31 26
@@ -12,7 +12,7 @@ func init() { @@ -12,7 +12,7 @@ func init() {
12 nsV1 := beego.NewNamespace("v1", 12 nsV1 := beego.NewNamespace("v1",
13 beego.NSBefore(middleware.AllowOption), 13 beego.NSBefore(middleware.AllowOption),
14 beego.NSBefore(middleware.LogRequestData), 14 beego.NSBefore(middleware.LogRequestData),
15 - //beego.NSBefore(middleware.AuthToken), 15 + beego.NSBefore(middleware.AuthToken),
16 beego.NSNamespace("/department", 16 beego.NSNamespace("/department",
17 beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"), 17 beego.NSRouter("/list", &controllers.CompanyController{}, "post:DepartmentList"),
18 beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"), 18 beego.NSRouter("/add", &controllers.CompanyController{}, "post:DepartmentAdd"),
@@ -35,10 +35,10 @@ func init() { @@ -35,10 +35,10 @@ func init() {
35 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"), 35 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"),
36 ), 36 ),
37 beego.NSNamespace("/user", 37 beego.NSNamespace("/user",
38 - beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), 38 + // beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
39 beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"), 39 beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"),
40 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), 40 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"),
41 - beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), 41 + // beego.NSRouter("/delete", &controllers.CompanyController{}, "post:PositionDelete"),
42 ), 42 ),
43 beego.NSNamespace("/auth", 43 beego.NSNamespace("/auth",
44 beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), 44 beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"),
@@ -51,10 +51,13 @@ func init() { @@ -51,10 +51,13 @@ func init() {
51 beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"), 51 beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"),
52 beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), 52 beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"),
53 ), 53 ),
54 - beego.NSNamespace("/common",  
55 - beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"),  
56 - beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"),  
57 - beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), 54 + beego.NSNamespace("/template",
  55 + beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
  56 + beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"),
  57 + beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"),
  58 + beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"),
  59 + beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"),
  60 + beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"),
58 ), 61 ),
59 ) 62 )
60 63
  1 +package agg
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + orm2 "github.com/astaxie/beego/orm"
  7 + "oppmg/common/log"
  8 + "oppmg/models"
  9 + "oppmg/protocol"
  10 + "strconv"
  11 +)
  12 +
  13 +func getUsers(jsonData string) (v []models.User, err error) {
  14 + var vObjs []protocol.VisibleObject
  15 + var ids []int64
  16 + var id int64
  17 + if err = json.Unmarshal([]byte(jsonData), &vObjs); err != nil {
  18 + return
  19 + }
  20 + for i := 0; i < len(vObjs); i++ {
  21 + if vObjs[i].Type != models.VisibleObject_User {
  22 + continue
  23 + }
  24 + if id, err = strconv.ParseInt(vObjs[i].Id, 10, 64); err != nil {
  25 + return
  26 + }
  27 + if id == 0 {
  28 + continue
  29 + }
  30 + ids = append(ids, id)
  31 + }
  32 + if len(ids) == 0 {
  33 + return
  34 + }
  35 + return models.GetUserNameByIds(ids)
  36 +}
  37 +
  38 +func getDepartments(jsonData string) (v []models.Department, err error) {
  39 + var vObjs []protocol.VisibleObject
  40 + var ids []int64
  41 + var id int64
  42 + if err = json.Unmarshal([]byte(jsonData), &vObjs); err != nil {
  43 + return
  44 + }
  45 + for i := 0; i < len(vObjs); i++ {
  46 + if vObjs[i].Type != models.VisibleObject_Department {
  47 + continue
  48 + }
  49 + if id, err = strconv.ParseInt(vObjs[i].Id, 10, 64); err != nil {
  50 + return
  51 + }
  52 + if id == 0 {
  53 + continue
  54 + }
  55 + ids = append(ids, id)
  56 + }
  57 + if len(ids) == 0 {
  58 + return
  59 + }
  60 + return models.GetDepartmentByIds(ids)
  61 +}
  62 +
  63 +func GetVisibleObject(jsonData string) (v []protocol.VisibleObject, err error) {
  64 + var (
  65 + users []models.User
  66 + departments []models.Department
  67 + )
  68 + if len(jsonData) == 0 {
  69 + return
  70 + }
  71 + if departments, err = getDepartments(jsonData); err != nil && err != orm2.ErrNoRows {
  72 + log.Error(err.Error())
  73 + return
  74 + }
  75 + for i := range departments {
  76 + v = append(v, protocol.VisibleObject{
  77 + Id: fmt.Sprintf("%v", departments[i].Id),
  78 + Name: departments[i].Name,
  79 + Type: models.VisibleObject_Department,
  80 + })
  81 + }
  82 + if users, err = getUsers(jsonData); err != nil && err != orm2.ErrNoRows {
  83 + log.Error(err.Error())
  84 + return
  85 + }
  86 + for i := range users {
  87 + v = append(v, protocol.VisibleObject{
  88 + Id: fmt.Sprintf("%v", users[i].Id),
  89 + Name: users[i].NickName,
  90 + Type: models.VisibleObject_User,
  91 + })
  92 + }
  93 +
  94 + return
  95 +}
@@ -2,16 +2,19 @@ package audit @@ -2,16 +2,19 @@ package audit
2 2
3 import ( 3 import (
4 "database/sql" 4 "database/sql"
  5 + "encoding/json"
5 "fmt" 6 "fmt"
6 orm2 "github.com/astaxie/beego/orm" 7 orm2 "github.com/astaxie/beego/orm"
7 "oppmg/common/log" 8 "oppmg/common/log"
8 "oppmg/models" 9 "oppmg/models"
9 "oppmg/protocol" 10 "oppmg/protocol"
  11 + "oppmg/services/agg"
10 "oppmg/utils" 12 "oppmg/utils"
11 "strings" 13 "strings"
12 "time" 14 "time"
13 ) 15 )
14 16
  17 +//添加模板
15 func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) { 18 func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) {
16 var ( 19 var (
17 auditForm *models.AuditForm 20 auditForm *models.AuditForm
@@ -27,6 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs @@ -27,6 +30,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
27 //模板 30 //模板
28 { 31 {
29 template = &models.AuditTemplate{ 32 template = &models.AuditTemplate{
  33 + ChanceTypeId: request.Template.ChanceTypeId,
30 CompanyId: int(companyId), 34 CompanyId: int(companyId),
31 Name: request.Template.Name, 35 Name: request.Template.Name,
32 Doc: request.Template.Doc, 36 Doc: request.Template.Doc,
@@ -74,6 +78,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs @@ -74,6 +78,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
74 return 78 return
75 } 79 }
76 80
  81 +//模板更新
77 func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) { 82 func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) {
78 var ( 83 var (
79 template *models.AuditTemplate 84 template *models.AuditTemplate
@@ -176,8 +181,158 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input @@ -176,8 +181,158 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input
176 return 181 return
177 } 182 }
178 183
  184 +//模板列表
179 func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) { 185 func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) {
180 - var () 186 + var (
  187 + chanceTypes []*models.ChanceType
  188 + templates []*models.AuditTemplate
  189 + )
  190 + if chanceTypes, err = models.GetChanceTypeByCompany(int(companyId)); err != nil {
  191 + log.Error("get:%v msg:%v", companyId, err.Error())
  192 + return
  193 + }
181 rsp = &protocol.TemplateListResponse{} 194 rsp = &protocol.TemplateListResponse{}
  195 + for i := 0; i < len(chanceTypes); i++ {
  196 + t := chanceTypes[i]
  197 + item := &protocol.TemplateList{
  198 + Id: t.Id,
  199 + Name: t.Name,
  200 + Icon: t.Icon,
  201 + }
  202 + rsp.List = append(rsp.List, item)
  203 + if templates, err = models.GetAuditTemplateByTypeId(t.Id); err != nil {
  204 + log.Error(err.Error())
  205 + continue
  206 + }
  207 + for j := range templates {
  208 + temp := templates[j]
  209 + var vObj []protocol.VisibleObject
  210 + //TODO:可见
  211 + //1.检查可见性
  212 +
  213 + //2.可见对象 VisibleObject
  214 + if temp.VisibleType == models.VisibleTypeDepartment {
  215 + if vObj, err = agg.GetVisibleObject(temp.VisibleObject); err != nil {
  216 + log.Error(err.Error())
  217 + return
  218 + }
  219 + }
  220 + tempItem := &protocol.TemplateItem{
  221 + Id: temp.Id,
  222 + Name: temp.Name,
  223 + Doc: temp.Doc,
  224 + Icon: temp.Icon,
  225 + EnableStatus: temp.EnableStatus,
  226 + Sort: temp.SortNum,
  227 + VisibleType: temp.VisibleType,
  228 + VisibleObject: vObj,
  229 + }
  230 + item.Templates = append(item.Templates, tempItem)
  231 + }
  232 + }
  233 +
  234 + return
  235 +}
  236 +
  237 +//编辑可见范围
  238 +func TemplateEditVisible(uid, companyId int64, request *protocol.TemplateEditVisibleRequest) (rsp *protocol.TemplateEditVisibleResponse, err error) {
  239 + var (
  240 + template *models.AuditTemplate
  241 + data []byte
  242 + )
  243 + rsp = &protocol.TemplateEditVisibleResponse{}
  244 + if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
  245 + log.Error(err.Error())
  246 + return
  247 + }
  248 + if template.CompanyId != int(companyId) {
  249 + err = protocol.NewErrWithMessage("10027")
  250 + log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, template.CompanyId)
  251 + return
  252 + }
  253 + if data, err = json.Marshal(request.VisibleObject); err != nil {
  254 + log.Error(err.Error())
  255 + return
  256 + }
  257 + if err = utils.UpdateTableByMap(template, map[string]interface{}{"VisibleObject": string(data)}); err != nil {
  258 + log.Error(err.Error())
  259 + return
  260 + }
  261 + return
  262 +}
  263 +
  264 +//操作一级分类
  265 +func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOperateCategoryRequest) (rsp *protocol.TemplateOperateCategoryResponse, err error) {
  266 + var (
  267 + chanceType *models.ChanceType
  268 + )
  269 + rsp = &protocol.TemplateOperateCategoryResponse{}
  270 + if request.Id > 0 { //编辑
  271 + if chanceType, err = models.GetChanceTypeById(request.Id); err != nil {
  272 + log.Error(err.Error())
  273 + return
  274 + }
  275 + if chanceType.CompanyId != int(companyId) {
  276 + err = protocol.NewErrWithMessage("10027")
  277 + log.Error("template_id:%v companyId:%v want:%v not equal.", request.Id, companyId, chanceType.CompanyId)
  278 + }
  279 + if err = utils.UpdateTableByMap(chanceType, map[string]interface{}{"Name": request.Name, "Icon": request.Icon, "UpdateAt": time.Now()}); err != nil {
  280 + log.Error(err.Error())
  281 + return
  282 + }
  283 + return
  284 + }
  285 + chanceType = &models.ChanceType{
  286 + Name: request.Name,
  287 + Icon: request.Icon,
  288 + CompanyId: int(companyId),
  289 + CreateAt: time.Now(),
  290 + UpdateAt: time.Now(),
  291 + }
  292 + if _, err = models.AddChanceType(chanceType); err != nil {
  293 + log.Error(err.Error())
  294 + }
  295 + return
  296 +}
  297 +
  298 +//获取模板详情
  299 +func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rsp *protocol.TemplateGetResponse, err error) {
  300 + var (
  301 + template *models.AuditTemplate
  302 + auditForm []*models.AuditForm
  303 + )
  304 + rsp = &protocol.TemplateGetResponse{}
  305 + if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil {
  306 + log.Error("template_id:%v 不存在 ,err:%v", request.Id, err.Error())
  307 + return
  308 + }
  309 +
  310 + {
  311 + rsp.Template = protocol.Template{
  312 + Id: template.Id,
  313 + ChanceTypeId: template.ChanceTypeId,
  314 + Name: template.Name,
  315 + Doc: template.Doc,
  316 + Icon: template.Icon,
  317 + }
  318 + rsp.Example = template.Example
  319 +
  320 + if auditForm, err = models.GetAuditFormByTemplateId(int(template.Id)); err != nil {
  321 + if err == sql.ErrNoRows {
  322 + err = nil
  323 + }
  324 + return
  325 + }
  326 + for i := range auditForm {
  327 + input := auditForm[i]
  328 + rsp.Template.InputList = append(rsp.Template.InputList, &protocol.InputElement{
  329 + Id: input.Id,
  330 + Sort: input.SortNum,
  331 + Lable: input.InputType,
  332 + Required: int(input.Required),
  333 + SectionType: input.Section,
  334 + })
  335 + }
  336 + }
182 return 337 return
183 } 338 }
@@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
6 "oppmg/common/log" 6 "oppmg/common/log"
7 "oppmg/models" 7 "oppmg/models"
8 "oppmg/protocol" 8 "oppmg/protocol"
9 - "strconv" 9 + "oppmg/services/agg"
10 "time" 10 "time"
11 ) 11 )
12 12
@@ -110,7 +110,7 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( @@ -110,7 +110,7 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
110 Status: int8(bulletin.Status), 110 Status: int8(bulletin.Status),
111 CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"), 111 CreateAt: bulletin.CreateAt.Format("2006-01-02 15:04:05"),
112 } 112 }
113 - if item.Receiver, err = getUsersName(bulletin.Receiver); err != nil { 113 + if item.Receiver, err = agg.GetVisibleObject(bulletin.Receiver); err != nil {
114 log.Error(err.Error()) 114 log.Error(err.Error())
115 continue 115 continue
116 } 116 }
@@ -120,36 +120,6 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( @@ -120,36 +120,6 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) (
120 return 120 return
121 } 121 }
122 122
123 -func getUsers(idsstr string) (v []models.User, err error) {  
124 - var idlist []string  
125 - var ids []int64  
126 - var id int64  
127 - if err = json.Unmarshal([]byte(idsstr), &idlist); err != nil {  
128 - return  
129 - }  
130 - for i := 0; i < len(idlist); i++ {  
131 - if id, err = strconv.ParseInt(idlist[i], 10, 64); err != nil {  
132 - return  
133 - }  
134 - ids = append(ids, id)  
135 - }  
136 - return models.GetUserNameByIds(ids)  
137 -}  
138 -  
139 -func getUsersName(idsStr string) (v []protocol.Receiver, err error) {  
140 - var users []models.User  
141 - if users, err = getUsers(idsStr); err != nil {  
142 - return  
143 - }  
144 - for i := range users {  
145 - v = append(v, protocol.Receiver{  
146 - Id: users[i].Id,  
147 - NickName: users[i].NickName,  
148 - })  
149 - }  
150 - return  
151 -}  
152 -  
153 //公告详情 123 //公告详情
154 func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) (rsp *protocol.GetBulletinResponse, err error) { 124 func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) (rsp *protocol.GetBulletinResponse, err error) {
155 var ( 125 var (
@@ -195,7 +165,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) @@ -195,7 +165,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest)
195 return 165 return
196 } 166 }
197 } 167 }
198 - if rsp.Receiver, err = getUsersName(bulletin.Receiver); err != nil { 168 + if rsp.Receiver, err = agg.GetVisibleObject(bulletin.Receiver); err != nil {
199 log.Error(err.Error()) 169 log.Error(err.Error())
200 return 170 return
201 } 171 }
1 -package common  
2 -  
3 -import (  
4 - "fmt"  
5 - "oppmg/common/log"  
6 - "oppmg/models"  
7 - "oppmg/protocol"  
8 - "oppmg/utils"  
9 -)  
10 -  
11 -func SelectorDepartment(companyid int64) []protocol.DepartmentBase {  
12 - const dataSql string = `SELECT id,name,parent_id FROM department WHERE company_id = ? AND delete_at = 0`  
13 - var (  
14 - err error  
15 - departs []protocol.DepartmentBase  
16 - )  
17 - err = utils.ExecuteQueryAll(&departs, dataSql, companyid)  
18 - if err != nil {  
19 - e := fmt.Errorf("EXECUTE SQL err:%s", err)  
20 - log.Error(e.Error())  
21 - }  
22 - return departs  
23 -}  
24 -  
25 -func SelectorRoleAll(companyid int64) []protocol.RoleBase {  
26 - const datasql string = `SELECT id,pid,name,types,is_default FROM role WHERE company_id = ? AND delete_at =0`  
27 - var (  
28 - err error  
29 - roles []protocol.RoleBase  
30 - )  
31 - err = utils.ExecuteQueryAll(&roles, datasql, companyid)  
32 - if err != nil {  
33 - e := fmt.Errorf("EXECUTE SQL err:%s", err)  
34 - log.Error(e.Error())  
35 - }  
36 - return roles  
37 -}  
38 -  
39 -func FilterRoleAll(adminid int64, companyid int64, list []protocol.RoleBase) []protocol.RoleBase {  
40 - var (  
41 - newlist []protocol.RoleBase  
42 - admingoroupId int64  
43 - )  
44 - companyInfo, err := models.GetCompanyById(companyid)  
45 - if err != nil {  
46 - e := fmt.Errorf("GetCompanyById(%d) err:%s", companyid, err)  
47 - log.Error(e.Error())  
48 - return newlist  
49 - }  
50 - if companyInfo.AdminId == adminid {  
51 - return list  
52 - }  
53 - for _, v := range list {  
54 - if v.IsDefault == models.ROLE_DEFAULR && v.Types == models.ROLETYPES_GROUP {  
55 - admingoroupId = v.Id  
56 - }  
57 - }  
58 - for k, v := range list {  
59 - if v.Id == admingoroupId || v.ParentId == admingoroupId {  
60 - continue  
61 - }  
62 -  
63 - newlist = append(newlist, list[k])  
64 - }  
65 - return newlist  
66 -}  
67 -  
68 -func FilterRoleGroup(adminid int64, companyid int64, list []protocol.RoleBase) []protocol.RoleBase {  
69 - var (  
70 - newlist []protocol.RoleBase  
71 - )  
72 - companyInfo, err := models.GetCompanyById(companyid)  
73 - if err != nil {  
74 - e := fmt.Errorf("GetCompanyById(%d) err:%s", companyid, err)  
75 - log.Error(e.Error())  
76 - return newlist  
77 - }  
78 - if companyInfo.AdminId != adminid {  
79 - for k, v := range list {  
80 - if v.Types == models.ROLETYPES_GROUP && v.IsDefault == models.ROLE_DEFAULR_NOT {  
81 - newlist = append(newlist, list[k])  
82 - }  
83 - }  
84 - return newlist  
85 - }  
86 - for k, v := range list {  
87 - if v.Types == models.ROLETYPES_GROUP {  
88 - newlist = append(newlist, list[k])  
89 - }  
90 - }  
91 - return newlist  
92 -}  
93 -  
94 -func SelectorPosition(companyid int64) []protocol.PositionBase {  
95 - const datasql string = `SELECT id,parent_id,name FROM position WHERE company_id =? AND delete_at =0`  
96 - var (  
97 - err error  
98 - positions []protocol.PositionBase  
99 - )  
100 - err = utils.ExecuteQueryAll(&positions, datasql, companyid)  
101 - if err != nil {  
102 - e := fmt.Errorf("EXECUTE SQL err:%s", err)  
103 - log.Error(e.Error())  
104 - }  
105 - return positions  
106 -  
107 -}  
@@ -308,6 +308,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro @@ -308,6 +308,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro
308 var manage []protocol.DepartmentManager 308 var manage []protocol.DepartmentManager
309 manage = v.GetManages() 309 manage = v.GetManages()
310 depart.Manages = manage 310 depart.Manages = manage
  311 + depart.Members = v.GetMembers()
311 departs = append(departs, depart) 312 departs = append(departs, depart)
312 } 313 }
313 314
@@ -161,27 +161,21 @@ func validCompanyUser(companyid int64, phone string) error { @@ -161,27 +161,21 @@ func validCompanyUser(companyid int64, phone string) error {
161 func registUser(userIn *models.User, companyid int64, o orm.Ormer) error { 161 func registUser(userIn *models.User, companyid int64, o orm.Ormer) error {
162 var ( 162 var (
163 err error 163 err error
164 - usrData *models.User 164 + // usrData *models.User
165 ) 165 )
166 - usrData, err = models.GetUserByPhone(userIn.Phone) 166 + _, err = models.GetUserByPhone(userIn.Phone)
  167 + if err == nil {
  168 + return nil
  169 + }
167 if err != nil && err != orm.ErrNoRows { 170 if err != nil && err != orm.ErrNoRows {
168 return err 171 return err
169 } 172 }
170 if err == orm.ErrNoRows { 173 if err == orm.ErrNoRows {
171 - //用户不存在 添加用户  
172 _, err := models.AddUser(userIn, o) 174 _, err := models.AddUser(userIn, o)
173 if err != nil { 175 if err != nil {
174 return err 176 return err
175 } 177 }
176 } 178 }
177 - if err == nil {  
178 - // 用户存在,更新用户  
179 - usrData.NickName = userIn.NickName  
180 - err = models.UpdateUserById(usrData, []string{"NickName"}, o)  
181 - if err != nil {  
182 - return err  
183 - }  
184 - }  
185 musercompany := &models.UserCompany{ 179 musercompany := &models.UserCompany{
186 CompanyId: companyid, 180 CompanyId: companyid,
187 UserId: userIn.Id, 181 UserId: userIn.Id,
@@ -375,25 +369,7 @@ func UserEdit(param protocol.RequestUserEdit) error { @@ -375,25 +369,7 @@ func UserEdit(param protocol.RequestUserEdit) error {
375 return nil 369 return nil
376 } 370 }
377 371
378 -func UserDelete(userid, companyid int64) error {  
379 - ok := models.ExistUserCompany(userid, companyid)  
380 - if !ok {  
381 - e := fmt.Errorf("ExistUserCompany(userid, companyid) [%d,%d] ==false ", userid, companyid)  
382 - log.Error(e.Error())  
383 - return protocol.NewErrWithMessage("1")  
384 - }  
385 - o := orm.NewOrm()  
386 - _, err := o.QueryTable(&models.UserCompany{}).  
387 - Filter("user_id", userid).  
388 - Filter("company_id").  
389 - Update(orm.Params{  
390 - "delete_at": time.Now().String(),  
391 - })  
392 - if err != nil {  
393 - e := fmt.Errorf("UserDelete err:%s", err)  
394 - log.Error(e.Error())  
395 - return protocol.NewErrWithMessage("1")  
396 - } 372 +func UserDelete(param protocol.RequestUserAdd) error {
397 return nil 373 return nil
398 } 374 }
399 375
@@ -64,11 +64,4 @@ func ExistLoginToken(userid int64) bool { @@ -64,11 +64,4 @@ func ExistLoginToken(userid int64) bool {
64 return false 64 return false
65 } 65 }
66 66
67 -func DeleteLoginToken(userid int64) error {  
68 - client := redis.GetRedis()  
69 - key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_TOKEN, userid)  
70 - err:=client.Del(key).Err()  
71 - return err  
72 -}  
73 -  
74 //消息发布订阅 67 //消息发布订阅
  1 +package utils
1 -package utils  
2 -  
3 -import (  
4 - "regexp"  
5 -)  
6 -  
7 -var (  
8 - PhoneMatch, _ = regexp.Compile(`^1[0-9]{10}$`)  
9 - EmailMatch, _ = regexp.Compile(`^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$`)  
10 - ChineseMatch, _ = regexp.Compile(`[\u4e00-\u9fa5]`)  
11 -)