Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev
# Conflicts: # models/user_company.go # services/auth/auth.go 模板管理
正在显示
28 个修改的文件
包含
620 行增加
和
595 行删除
controllers/common.go
已删除
100644 → 0
| 1 | -package controllers | ||
| 2 | - | ||
| 3 | -import ( | ||
| 4 | - "encoding/json" | ||
| 5 | - "oppmg/common/log" | ||
| 6 | - "oppmg/protocol" | ||
| 7 | - servecommon "oppmg/services/common" | ||
| 8 | -) | ||
| 9 | - | ||
| 10 | -//公共接口 | ||
| 11 | -type CommonController struct { | ||
| 12 | - BaseController | ||
| 13 | -} | ||
| 14 | - | ||
| 15 | -func (c *CommonController) URLMapping() { | ||
| 16 | - | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | -//SelectorDepartment 下拉列表 -部门 | ||
| 20 | -//@router /department [post] | ||
| 21 | -func (c *CommonController) SelectorDepartment() { | ||
| 22 | - var msg *protocol.ResponseMessage | ||
| 23 | - defer func() { | ||
| 24 | - c.ResposeJson(msg) | ||
| 25 | - }() | ||
| 26 | - companyid := c.GetCompanyId() | ||
| 27 | - departs := servecommon.SelectorDepartment(companyid) | ||
| 28 | - | ||
| 29 | - msg = protocol.NewReturnResponse(departs, nil) | ||
| 30 | - return | ||
| 31 | -} | ||
| 32 | - | ||
| 33 | -//SelectorRole 下拉列表 -角色 | ||
| 34 | -//@router /role [post] | ||
| 35 | -func (c *CommonController) SelectorRole() { | ||
| 36 | - | ||
| 37 | - var msg *protocol.ResponseMessage | ||
| 38 | - defer func() { | ||
| 39 | - c.ResposeJson(msg) | ||
| 40 | - }() | ||
| 41 | - type Parameter struct { | ||
| 42 | - For string `json:"for"` | ||
| 43 | - } | ||
| 44 | - var param Parameter | ||
| 45 | - if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 46 | - log.Error("json 解析失败 err:%s", err) | ||
| 47 | - msg = protocol.BadRequestParam("1") | ||
| 48 | - return | ||
| 49 | - } | ||
| 50 | - companyid := c.GetCompanyId() | ||
| 51 | - userid := c.GetUserId() | ||
| 52 | - if companyid <= 0 || userid <= 0 { | ||
| 53 | - msg = protocol.BadRequestParam("1") | ||
| 54 | - return | ||
| 55 | - } | ||
| 56 | - var roles []protocol.RoleBase | ||
| 57 | - switch param.For { | ||
| 58 | - case "user": | ||
| 59 | - list := servecommon.SelectorRoleAll(companyid) | ||
| 60 | - roles = servecommon.FilterRoleAll(userid, companyid, list) | ||
| 61 | - case "role": | ||
| 62 | - list := servecommon.SelectorRoleAll(companyid) | ||
| 63 | - roles = servecommon.FilterRoleGroup(userid, companyid, list) | ||
| 64 | - case "all": | ||
| 65 | - roles = servecommon.SelectorRoleAll(companyid) | ||
| 66 | - default: | ||
| 67 | - roles = servecommon.SelectorRoleAll(companyid) | ||
| 68 | - } | ||
| 69 | - msg = protocol.NewReturnResponse(roles, nil) | ||
| 70 | - return | ||
| 71 | - | ||
| 72 | -} | ||
| 73 | - | ||
| 74 | -//SelectorPosition 下拉列表 -职位 | ||
| 75 | -//@router /position [post] | ||
| 76 | -func (c *CommonController) SelectorPosition() { | ||
| 77 | - var msg *protocol.ResponseMessage | ||
| 78 | - defer func() { | ||
| 79 | - c.ResposeJson(msg) | ||
| 80 | - }() | ||
| 81 | - companyid := c.GetCompanyId() | ||
| 82 | - departs := servecommon.SelectorPosition(companyid) | ||
| 83 | - | ||
| 84 | - msg = protocol.NewReturnResponse(departs, nil) | ||
| 85 | - return | ||
| 86 | -} |
| @@ -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,95 +245,8 @@ func (c *CompanyController) UserEdit() { | @@ -270,95 +245,8 @@ 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) |
| 294 | return | 251 | return |
| 295 | } | 252 | } |
| 296 | - | ||
| 297 | -//UserDelete 删除用户 | ||
| 298 | -//@Router /user/delete [post] | ||
| 299 | -func (c *CompanyController) UserDelete() { | ||
| 300 | - var msg *protocol.ResponseMessage | ||
| 301 | - defer func() { | ||
| 302 | - c.ResposeJson(msg) | ||
| 303 | - }() | ||
| 304 | - type Parameter struct { | ||
| 305 | - Userid int64 `json:"user_id"` | ||
| 306 | - } | ||
| 307 | - var param Parameter | ||
| 308 | - if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 309 | - log.Error("json 解析失败 err:%s", err) | ||
| 310 | - msg = protocol.BadRequestParam("1") | ||
| 311 | - return | ||
| 312 | - } | ||
| 313 | - companyId := c.GetCompanyId() | ||
| 314 | - err := servecompany.UserDelete(param.Userid, companyId) | ||
| 315 | - if err == nil { | ||
| 316 | - e := redisdata.DeleteLoginToken(param.Userid) | ||
| 317 | - if e != nil { | ||
| 318 | - log.Error(e.Error()) | ||
| 319 | - } | ||
| 320 | - } | ||
| 321 | - msg = protocol.NewReturnResponse(nil, err) | ||
| 322 | - return | ||
| 323 | -} | ||
| 324 | - | ||
| 325 | -//UserEdit 禁用、启用用户 TODO | ||
| 326 | -//@Router /user/enable [post] | ||
| 327 | -func (c *CompanyController) UserEnable() { | ||
| 328 | - var msg *protocol.ResponseMessage | ||
| 329 | - defer func() { | ||
| 330 | - c.ResposeJson(msg) | ||
| 331 | - }() | ||
| 332 | - var param protocol.RequestUserEdit | ||
| 333 | - if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 334 | - log.Error("json 解析失败 err:%s", err) | ||
| 335 | - msg = protocol.BadRequestParam("1") | ||
| 336 | - return | ||
| 337 | - } | ||
| 338 | - | ||
| 339 | - param.CompanyId = c.GetCompanyId() | ||
| 340 | - err := servecompany.UserEdit(param) | ||
| 341 | - redisdata.DeleteLoginToken(0) | ||
| 342 | - msg = protocol.NewReturnResponse(nil, err) | ||
| 343 | - return | ||
| 344 | -} | ||
| 345 | - | ||
| 346 | -//UserEdit用户列表 | ||
| 347 | -//@Router /user/list [post] | ||
| 348 | -func (c *CompanyController) UserList() { | ||
| 349 | - var msg *protocol.ResponseMessage | ||
| 350 | - defer func() { | ||
| 351 | - c.ResposeJson(msg) | ||
| 352 | - }() | ||
| 353 | - var param protocol.RequestUserList | ||
| 354 | - if err := json.Unmarshal(c.Ctx.Input.RequestBody, ¶m); err != nil { | ||
| 355 | - log.Error("json 解析失败 err:%s", err) | ||
| 356 | - msg = protocol.BadRequestParam("1") | ||
| 357 | - return | ||
| 358 | - } | ||
| 359 | - | ||
| 360 | - param.Companyid = c.GetCompanyId() | ||
| 361 | - result, err := servecompany.UserList(param) | ||
| 362 | - msg = protocol.NewPageDataResponse(result, err) | ||
| 363 | - return | ||
| 364 | -} |
| @@ -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) |
| 105 | msg = protocol.NewReturnResponse(rsp, err) | 134 | msg = protocol.NewReturnResponse(rsp, err) |
| 106 | return | 135 | return |
| 107 | } | 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) | ||
| 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") | ||
| 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) | ||
| 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 | +} |
| @@ -8,22 +8,33 @@ import ( | @@ -8,22 +8,33 @@ import ( | ||
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | type AuditTemplate struct { | 10 | type AuditTemplate struct { |
| 11 | - Id int64 `orm:"column(id);auto" description:"唯一编号"` | ||
| 12 | - CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
| 13 | - ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"` | ||
| 14 | - Name string `orm:"column(name);size(20)" description:"子分类名称"` | ||
| 15 | - Doc string `orm:"column(doc);size(255)" description:"说明"` | ||
| 16 | - Icon string `orm:"column(icon);size(255)" description:"图标"` | ||
| 17 | - NoticeType int8 `orm:"column(notice_type)" description:"通知方式"` | ||
| 18 | - NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"` | ||
| 19 | - SortNum int `orm:"column(sort_num)" description:"自定义排序编号"` | ||
| 20 | - VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "` | ||
| 21 | - EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"` | ||
| 22 | - CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
| 23 | - UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
| 24 | - Example string `orm:"column(examplte);null" description:"示例"` | 11 | + Id int64 `orm:"column(id);auto" description:"唯一编号"` |
| 12 | + CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
| 13 | + ChanceTypeId int `orm:"column(chance_type_id)" description:"机会类型 chance_type.id"` | ||
| 14 | + Name string `orm:"column(name);size(20)" description:"子分类名称"` | ||
| 15 | + Doc string `orm:"column(doc);size(255)" description:"说明"` | ||
| 16 | + Icon string `orm:"column(icon);size(255)" description:"图标"` | ||
| 17 | + NoticeType int8 `orm:"column(notice_type)" description:"通知方式"` | ||
| 18 | + NoApprover int8 `orm:"column(no_approver)" description:"审核人空时:【1:自动通过】【2:转交给管理员】"` | ||
| 19 | + SortNum int `orm:"column(sort_num)" description:"自定义排序编号"` | ||
| 20 | + VisibleType int8 `orm:"column(visible_type)" description:"可见范围 0:所有人 1:指定部门 "` | ||
| 21 | + VisibleObject string `orm:"column(visible_object)" description:"可见的对象 部门 指定人 json"` | ||
| 22 | + EnableStatus int8 `orm:"column(enable_status)" description:"是否有效 1:有效 0:无效"` | ||
| 23 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
| 24 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" 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)"` |
| @@ -76,6 +76,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | @@ -76,6 +76,27 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | ||
| 76 | return managesdata | 76 | return managesdata |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | +func (t *Department) GetMembers() []protocol.DepartmentMember { | ||
| 80 | + ids, err := GetUserDepartmentIds(int(t.CompanyId), int(t.Id)) | ||
| 81 | + if err != nil { | ||
| 82 | + log.Error(err.Error()) | ||
| 83 | + return nil | ||
| 84 | + } | ||
| 85 | + users, err := getUserNameByIds(ids) | ||
| 86 | + if err != nil { | ||
| 87 | + log.Error("GetUserNameByIds err :%s", err) | ||
| 88 | + return nil | ||
| 89 | + } | ||
| 90 | + managesdata := []protocol.DepartmentMember{} | ||
| 91 | + for _, v := range users { | ||
| 92 | + m := protocol.DepartmentMember{ | ||
| 93 | + Id: v.Id, Name: v.NickName, | ||
| 94 | + } | ||
| 95 | + managesdata = append(managesdata, m) | ||
| 96 | + } | ||
| 97 | + return managesdata | ||
| 98 | +} | ||
| 99 | + | ||
| 79 | // AddDepartment insert a new Department into database and returns | 100 | // AddDepartment insert a new Department into database and returns |
| 80 | // last inserted Id on success. | 101 | // last inserted Id on success. |
| 81 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { | 102 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { |
| @@ -155,3 +176,15 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) { | @@ -155,3 +176,15 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) { | ||
| 155 | All(&result) | 176 | All(&result) |
| 156 | return result, err | 177 | return result, err |
| 157 | } | 178 | } |
| 179 | + | ||
| 180 | +func GetDepartmentByIds(departmentIds []int64) ([]Department, error) { | ||
| 181 | + var ( | ||
| 182 | + result []Department | ||
| 183 | + err error | ||
| 184 | + ) | ||
| 185 | + o := orm.NewOrm() | ||
| 186 | + _, err = o.QueryTable(&Department{}). | ||
| 187 | + Filter("id__in", departmentIds). | ||
| 188 | + All(&result) | ||
| 189 | + return result, err | ||
| 190 | +} |
| @@ -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,16 +80,15 @@ func GetUserById(id int64) (v *User, err error) { | @@ -82,16 +80,15 @@ 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 | - } | ||
| 92 | - var num int64 | ||
| 93 | - if num, err = o.Update(m, col...); err == nil { | ||
| 94 | - fmt.Println("Number of records updated in database:", num) | 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 { | ||
| 88 | + var num int64 | ||
| 89 | + if num, err = o.Update(m); err == nil { | ||
| 90 | + fmt.Println("Number of records updated in database:", num) | ||
| 91 | + } | ||
| 95 | } | 92 | } |
| 96 | return | 93 | return |
| 97 | } | 94 | } |
| @@ -92,23 +92,3 @@ func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) { | @@ -92,23 +92,3 @@ func GetUserCompanyBy(userid int64, companyId int64) (*UserCompany, error) { | ||
| 92 | } | 92 | } |
| 93 | return data[0], nil | 93 | return data[0], nil |
| 94 | } | 94 | } |
| 95 | - | ||
| 96 | -func ExistUserCompany(userid int64, companyId int64) bool { | ||
| 97 | - o := orm.NewOrm() | ||
| 98 | - ok := o.QueryTable(&UserCompany{}). | ||
| 99 | - Filter("UserId", userid). | ||
| 100 | - Filter("CompanyId", companyId). | ||
| 101 | - Exist() | ||
| 102 | - return ok | ||
| 103 | -} | ||
| 104 | - | ||
| 105 | -func EnableUserCompany(userid int64, companyid int64) error { | ||
| 106 | - o := orm.NewOrm() | ||
| 107 | - _, err := o.QueryTable(&UserCompany{}). | ||
| 108 | - Filter("UserId", userid). | ||
| 109 | - Filter("CompanyId", companyid).Update(orm.Params{ | ||
| 110 | - "enable": USERCOMPANY_ENABLE_YES, | ||
| 111 | - "delete_at": 0, | ||
| 112 | - }) | ||
| 113 | - return err | ||
| 114 | -} |
| @@ -85,16 +85,27 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | @@ -85,16 +85,27 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | ||
| 85 | } | 85 | } |
| 86 | return | 86 | return |
| 87 | } | 87 | } |
| 88 | -func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) { | 88 | + |
| 89 | +// DeleteUserDepartment deletes UserDepartment by Id and returns error if | ||
| 90 | +// the record to be deleted doesn't exist | ||
| 91 | +func DeleteUserDepartment(id int64) (err error) { | ||
| 92 | + o := orm.NewOrm() | ||
| 93 | + v := UserDepartment{Id: id} | ||
| 94 | + // ascertain id exists in the database | ||
| 95 | + if err = o.Read(&v); err == nil { | ||
| 96 | + var num int64 | ||
| 97 | + if num, err = o.Delete(&UserDepartment{Id: id}); err == nil { | ||
| 98 | + fmt.Println("Number of records deleted in database:", num) | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + return | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +func GetUserDepartmentIds(companyId, dId int) (v []int64, err error) { | ||
| 89 | o := orm.NewOrm() | 105 | o := orm.NewOrm() |
| 90 | - var ( | ||
| 91 | - err error | ||
| 92 | - result []*UserDepartment | ||
| 93 | - ) | ||
| 94 | - _, err = o.QueryTable(&UserDepartment{}). | ||
| 95 | - Filter("user_id", userid). | ||
| 96 | - Filter("company_id", companyid). | ||
| 97 | - Filter("enable_status", 1). | ||
| 98 | - All(&result) | ||
| 99 | - return result, err | 106 | + sql := "select user_id from user_department where company_id=? and department_id =?" |
| 107 | + if _, err = o.Raw(sql, companyId, dId).QueryRows(&v); err != nil { | ||
| 108 | + return | ||
| 109 | + } | ||
| 110 | + return | ||
| 100 | } | 111 | } |
| @@ -60,16 +60,43 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | @@ -60,16 +60,43 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | ||
| 60 | return | 60 | return |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -func GetUserPosition(userid, companyid int64) ([]*UserPosition, error) { | 63 | +// GetUserPositionById retrieves UserPosition by Id. Returns error if |
| 64 | +// Id doesn't exist | ||
| 65 | +func GetUserPositionById(id int64) (v *UserPosition, err error) { | ||
| 64 | o := orm.NewOrm() | 66 | o := orm.NewOrm() |
| 65 | - var ( | ||
| 66 | - err error | ||
| 67 | - result []*UserPosition | ||
| 68 | - ) | ||
| 69 | - _, err = o.QueryTable(&UserPosition{}). | ||
| 70 | - Filter("user_id", userid). | ||
| 71 | - Filter("company_id", companyid). | ||
| 72 | - Filter("enable_status", 1). | ||
| 73 | - All(&result) | ||
| 74 | - return result, err | 67 | + v = &UserPosition{Id: id} |
| 68 | + if err = o.Read(v); err == nil { | ||
| 69 | + return v, nil | ||
| 70 | + } | ||
| 71 | + return nil, err | ||
| 72 | +} | ||
| 73 | + | ||
| 74 | +// UpdateUserPosition updates UserPosition by Id and returns error if | ||
| 75 | +// the record to be updated doesn't exist | ||
| 76 | +func UpdateUserPositionById(m *UserPosition) (err error) { | ||
| 77 | + o := orm.NewOrm() | ||
| 78 | + v := UserPosition{Id: m.Id} | ||
| 79 | + // ascertain id exists in the database | ||
| 80 | + if err = o.Read(&v); err == nil { | ||
| 81 | + var num int64 | ||
| 82 | + if num, err = o.Update(m); err == nil { | ||
| 83 | + fmt.Println("Number of records updated in database:", num) | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +// DeleteUserPosition deletes UserPosition by Id and returns error if | ||
| 90 | +// the record to be deleted doesn't exist | ||
| 91 | +func DeleteUserPosition(id int64) (err error) { | ||
| 92 | + o := orm.NewOrm() | ||
| 93 | + v := UserPosition{Id: id} | ||
| 94 | + // ascertain id exists in the database | ||
| 95 | + if err = o.Read(&v); err == nil { | ||
| 96 | + var num int64 | ||
| 97 | + if num, err = o.Delete(&UserPosition{Id: id}); err == nil { | ||
| 98 | + fmt.Println("Number of records deleted in database:", num) | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + return | ||
| 75 | } | 102 | } |
| @@ -58,16 +58,43 @@ func AddUserRole(m *UserRole) (id int64, err error) { | @@ -58,16 +58,43 @@ func AddUserRole(m *UserRole) (id int64, err error) { | ||
| 58 | return | 58 | return |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | -func GetUserRole(userid, companyid int64) ([]*UserRole, error) { | 61 | +// GetUserRoleById retrieves UserRole by Id. Returns error if |
| 62 | +// Id doesn't exist | ||
| 63 | +func GetUserRoleById(id int) (v *UserRole, err error) { | ||
| 62 | o := orm.NewOrm() | 64 | o := orm.NewOrm() |
| 63 | - var ( | ||
| 64 | - err error | ||
| 65 | - result []*UserRole | ||
| 66 | - ) | ||
| 67 | - _, err = o.QueryTable(&UserRole{}). | ||
| 68 | - Filter("user_id", userid). | ||
| 69 | - Filter("company_id", companyid). | ||
| 70 | - Filter("enable_status", 1). | ||
| 71 | - All(&result) | ||
| 72 | - return result, err | 65 | + v = &UserRole{Id: id} |
| 66 | + if err = o.Read(v); err == nil { | ||
| 67 | + return v, nil | ||
| 68 | + } | ||
| 69 | + return nil, err | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +// UpdateUserRole updates UserRole by Id and returns error if | ||
| 73 | +// the record to be updated doesn't exist | ||
| 74 | +func UpdateUserRoleById(m *UserRole) (err error) { | ||
| 75 | + o := orm.NewOrm() | ||
| 76 | + v := UserRole{Id: m.Id} | ||
| 77 | + // ascertain id exists in the database | ||
| 78 | + if err = o.Read(&v); err == nil { | ||
| 79 | + var num int64 | ||
| 80 | + if num, err = o.Update(m); err == nil { | ||
| 81 | + fmt.Println("Number of records updated in database:", num) | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + return | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +// DeleteUserRole deletes UserRole by Id and returns error if | ||
| 88 | +// the record to be deleted doesn't exist | ||
| 89 | +func DeleteUserRole(id int) (err error) { | ||
| 90 | + o := orm.NewOrm() | ||
| 91 | + v := UserRole{Id: id} | ||
| 92 | + // ascertain id exists in the database | ||
| 93 | + if err = o.Read(&v); err == nil { | ||
| 94 | + var num int64 | ||
| 95 | + if num, err = o.Delete(&UserRole{Id: id}); err == nil { | ||
| 96 | + fmt.Println("Number of records deleted in database:", num) | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + return | ||
| 73 | } | 100 | } |
| @@ -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 | } |
| @@ -18,10 +18,10 @@ type BulletinReleaseRequest struct { | @@ -18,10 +18,10 @@ type BulletinReleaseRequest struct { | ||
| 18 | Content string `json:"content" valid:"Required"` | 18 | Content string `json:"content" valid:"Required"` |
| 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"` | ||
| 22 | - Receiver []string `json:"receiver" valid:"Required"` | ||
| 23 | - Question Question `json:"question"` | ||
| 24 | - Cover Cover `json:"cover" valid:"Required"` | 21 | + QuestionSwitch int `json:"question_switch"` |
| 22 | + Receiver []VisibleObject `json:"receiver" valid:"Required"` | ||
| 23 | + Question Question `json:"question"` | ||
| 24 | + Cover Cover `json:"cover" valid:"Required"` | ||
| 25 | } | 25 | } |
| 26 | type Question struct { | 26 | type Question struct { |
| 27 | Id int `json:"id"` | 27 | Id int `json:"id"` |
| @@ -53,12 +53,12 @@ type BulletinListResponse struct { | @@ -53,12 +53,12 @@ type BulletinListResponse struct { | ||
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | type BulletinItem struct { | 55 | type BulletinItem struct { |
| 56 | - Id int `json:"id"` | ||
| 57 | - Type int8 `json:"type"` | ||
| 58 | - Title string `json:"title"` | ||
| 59 | - Status int8 `json:"status"` | ||
| 60 | - Receiver []Receiver `json:"receiver" valid:"Required"` | ||
| 61 | - CreateAt string `json:"time"` | 56 | + Id int `json:"id"` |
| 57 | + Type int8 `json:"type"` | ||
| 58 | + Title string `json:"title"` | ||
| 59 | + Status int8 `json:"status"` | ||
| 60 | + Receiver []VisibleObject `json:"receiver" valid:"Required"` | ||
| 61 | + CreateAt string `json:"time"` | ||
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | /*GetBulletin */ | 64 | /*GetBulletin */ |
| @@ -72,10 +72,10 @@ type GetBulletinResponse struct { | @@ -72,10 +72,10 @@ type GetBulletinResponse struct { | ||
| 72 | Content string `json:"content" valid:"Required"` | 72 | Content string `json:"content" valid:"Required"` |
| 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"` | ||
| 76 | - Receiver []Receiver `json:"receiver" valid:"Required"` | ||
| 77 | - Question Question `json:"question"` | ||
| 78 | - Cover Cover `json:"cover" valid:"Required"` | 75 | + QuestionSwitch int `json:"question_switch"` |
| 76 | + Receiver []VisibleObject `json:"receiver" valid:"Required"` | ||
| 77 | + Question Question `json:"question"` | ||
| 78 | + Cover Cover `json:"cover" valid:"Required"` | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | type Receiver struct { | 81 | type Receiver struct { |
| @@ -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"` |
| @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct { | @@ -36,6 +41,7 @@ type ResponseDepartmentInfo struct { | ||
| 36 | Name string `json:"name"` //部门名字 | 41 | Name string `json:"name"` //部门名字 |
| 37 | ParantID int64 `json:"parant_id"` //父级部门Id | 42 | ParantID int64 `json:"parant_id"` //父级部门Id |
| 38 | Manages []DepartmentManager `json:"manages"` //部门管理员 | 43 | Manages []DepartmentManager `json:"manages"` //部门管理员 |
| 44 | + Members []DepartmentMember `json:"members"` //部门成员 | ||
| 39 | Member int `json:"member"` //成员数 | 45 | Member int `json:"member"` //成员数 |
| 40 | } | 46 | } |
| 41 | 47 | ||
| @@ -89,8 +95,7 @@ type RequestUserEdit struct { | @@ -89,8 +95,7 @@ type RequestUserEdit struct { | ||
| 89 | //RequestUserList 获取用户列表 | 95 | //RequestUserList 获取用户列表 |
| 90 | type RequestUserList struct { | 96 | type RequestUserList struct { |
| 91 | RequestPageInfo | 97 | RequestPageInfo |
| 92 | - NickName string `json:"nick_name"` | ||
| 93 | - Companyid int64 `json:"company_id"` | 98 | + NickName string `json:"nick_name"` |
| 94 | } | 99 | } |
| 95 | 100 | ||
| 96 | //ResponseUserList 响应的用户列表 | 101 | //ResponseUserList 响应的用户列表 |
| @@ -100,10 +105,10 @@ type ResponseUserList struct { | @@ -100,10 +105,10 @@ type ResponseUserList struct { | ||
| 100 | } | 105 | } |
| 101 | 106 | ||
| 102 | type UserListItem struct { | 107 | type UserListItem struct { |
| 103 | - UserId int64 `json:"user_id" orm:"column(user_id)"` | ||
| 104 | - NickName string `json:"nick_name" orm:"column(nick_name)"` | ||
| 105 | - Positions string `json:"positions" orm:"-"` | ||
| 106 | - Roles string `json:"roles" orm:"-"` | ||
| 107 | - Departments string `json:"departments" orm:"-"` | ||
| 108 | - Enable int8 `json:"enable" orm:"column(enable)"` | 108 | + Id int64 `json:"id"` |
| 109 | + NickName string `json:"nick_name"` | ||
| 110 | + Position string `json:"position"` | ||
| 111 | + Role string `json:"role"` | ||
| 112 | + Department string `json:"department"` | ||
| 113 | + Status int8 `json:"status"` | ||
| 109 | } | 114 | } |
| @@ -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 | } | 24 | } |
| 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{}, "get:DepartmentList"), | 17 | beego.NSRouter("/list", &controllers.CompanyController{}, "get: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", &controllers.RbacController{}, "get:RoleList"), | 35 | beego.NSRouter("/role", &controllers.RbacController{}, "get: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"), |
| @@ -50,10 +50,13 @@ func init() { | @@ -50,10 +50,13 @@ func init() { | ||
| 50 | beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"), | 50 | beego.NSRouter("/get", &controllers.BulletinController{}, "post:GetBulletin"), |
| 51 | beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), | 51 | beego.NSRouter("/update", &controllers.BulletinController{}, "post:UpdateBulletin"), |
| 52 | ), | 52 | ), |
| 53 | - beego.NSNamespace("common", | ||
| 54 | - beego.NSRouter("/department", &controllers.CommonController{}, "post:SelectorDepartment"), | ||
| 55 | - beego.NSRouter("/role", &controllers.CommonController{}, "post:SelectorRole"), | ||
| 56 | - beego.NSRouter("/position", &controllers.CommonController{}, "post:SelectorPosition"), | 53 | + beego.NSNamespace("/template", |
| 54 | + beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"), | ||
| 55 | + beego.NSRouter("/list", &controllers.TemplateController{}, "post:TemplateList"), | ||
| 56 | + beego.NSRouter("/get", &controllers.TemplateController{}, "post:TemplateGet"), | ||
| 57 | + beego.NSRouter("/update", &controllers.TemplateController{}, "post:TemplateUpdate"), | ||
| 58 | + beego.NSRouter("/editVisible", &controllers.TemplateController{}, "post:TemplateEditVisible"), | ||
| 59 | + beego.NSRouter("/operateCategory", &controllers.TemplateController{}, "post:TemplateOperateCategory"), | ||
| 57 | ), | 60 | ), |
| 58 | ) | 61 | ) |
| 59 | 62 |
services/agg/common.go
0 → 100644
| 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 | } |
services/common/selector.go
已删除
100644 → 0
| 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 | -} |
| @@ -355,6 +355,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -355,6 +355,7 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | ||
| 355 | var manage []protocol.DepartmentManager | 355 | var manage []protocol.DepartmentManager |
| 356 | manage = v.GetManages() | 356 | manage = v.GetManages() |
| 357 | depart.Manages = manage | 357 | depart.Manages = manage |
| 358 | + depart.Members = v.GetMembers() | ||
| 358 | departs = append(departs, depart) | 359 | departs = append(departs, depart) |
| 359 | } | 360 | } |
| 360 | 361 |
| @@ -137,41 +137,32 @@ func validCompanyPosition(companyid int64, positionid []int64) error { | @@ -137,41 +137,32 @@ func validCompanyPosition(companyid int64, positionid []int64) error { | ||
| 137 | //registUser 注册用户 | 137 | //registUser 注册用户 |
| 138 | func registUser(userIn *models.User, companyid int64, o orm.Ormer) error { | 138 | func registUser(userIn *models.User, companyid int64, o orm.Ormer) error { |
| 139 | var ( | 139 | var ( |
| 140 | - err error | ||
| 141 | - usrData *models.User | 140 | + err error |
| 141 | + // usrData *models.User | ||
| 142 | ) | 142 | ) |
| 143 | - usrData, err = models.GetUserByPhone(userIn.Phone) | 143 | + _, err = models.GetUserByPhone(userIn.Phone) |
| 144 | + if err == nil { | ||
| 145 | + return nil | ||
| 146 | + } | ||
| 144 | if err != nil && err != orm.ErrNoRows { | 147 | if err != nil && err != orm.ErrNoRows { |
| 145 | return err | 148 | return err |
| 146 | } | 149 | } |
| 147 | if err == orm.ErrNoRows { | 150 | if err == orm.ErrNoRows { |
| 148 | - //用户不存在 添加用户 | ||
| 149 | _, err := models.AddUser(userIn, o) | 151 | _, err := models.AddUser(userIn, o) |
| 150 | if err != nil { | 152 | if err != nil { |
| 151 | return err | 153 | return err |
| 152 | } | 154 | } |
| 153 | } | 155 | } |
| 154 | - if err == nil { | ||
| 155 | - // 用户存在,更新用户 | ||
| 156 | - usrData.NickName = userIn.NickName | ||
| 157 | - err = models.UpdateUserById(usrData, []string{"NickName"}, o) | ||
| 158 | - if err != nil { | ||
| 159 | - return err | ||
| 160 | - } | ||
| 161 | - } | ||
| 162 | musercompany := &models.UserCompany{ | 156 | musercompany := &models.UserCompany{ |
| 163 | CompanyId: companyid, | 157 | CompanyId: companyid, |
| 164 | UserId: userIn.Id, | 158 | UserId: userIn.Id, |
| 165 | } | 159 | } |
| 166 | - ok := models.ExistUserCompany(usrData.Id, companyid) | ||
| 167 | - if !ok { | ||
| 168 | - _, err = models.AddUserCompany(musercompany, o) | ||
| 169 | - if err != nil { | ||
| 170 | - return err | ||
| 171 | - } | 160 | + _, err = models.AddUserCompany(musercompany, o) |
| 161 | + if err != nil { | ||
| 162 | + return err | ||
| 172 | } | 163 | } |
| 173 | - err = models.EnableUserCompany(usrData.Id, companyid) | ||
| 174 | - return err | 164 | + //更新 |
| 165 | + return nil | ||
| 175 | } | 166 | } |
| 176 | 167 | ||
| 177 | func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error { | 168 | func editUserDepart(userid int64, companyid int64, departids []int64, o orm.Ormer) error { |
| @@ -347,77 +338,10 @@ func UserEdit(param protocol.RequestUserEdit) error { | @@ -347,77 +338,10 @@ func UserEdit(param protocol.RequestUserEdit) error { | ||
| 347 | return nil | 338 | return nil |
| 348 | } | 339 | } |
| 349 | 340 | ||
| 350 | -func UserDelete(userid, companyid int64) error { | ||
| 351 | - ok := models.ExistUserCompany(userid, companyid) | ||
| 352 | - if !ok { | ||
| 353 | - e := fmt.Errorf("ExistUserCompany(userid, companyid) [%d,%d] ==false ", userid, companyid) | ||
| 354 | - log.Error(e.Error()) | ||
| 355 | - return protocol.NewErrWithMessage("1") | ||
| 356 | - } | ||
| 357 | - o := orm.NewOrm() | ||
| 358 | - _, err := o.QueryTable(&models.UserCompany{}). | ||
| 359 | - Filter("user_id", userid). | ||
| 360 | - Filter("company_id"). | ||
| 361 | - Update(orm.Params{ | ||
| 362 | - "delete_at": time.Now().String(), | ||
| 363 | - }) | ||
| 364 | - if err != nil { | ||
| 365 | - e := fmt.Errorf("UserDelete err:%s", err) | ||
| 366 | - log.Error(e.Error()) | ||
| 367 | - return protocol.NewErrWithMessage("1") | ||
| 368 | - } | 341 | +func UserDelete(param protocol.RequestUserAdd) error { |
| 369 | return nil | 342 | return nil |
| 370 | } | 343 | } |
| 371 | 344 | ||
| 372 | -func UserList(param protocol.RequestUserList) (protocol.ResponseUserList, error) { | ||
| 373 | - | ||
| 374 | - datasql := `SELECT a.company_id,a.user_id,a.enable, b.phone,b.nick_name | ||
| 375 | - FROM user_company AS a | ||
| 376 | - LEFT JOIN user AS b ON a.user_id = b.id | ||
| 377 | - WHERE a.company_id=? AND a.delete_at = 0 ` | ||
| 378 | - countSql := `SELECT count(*) | ||
| 379 | - FROM user_company AS a | ||
| 380 | - LEFT JOIN user AS b ON a.user_id = b.id | ||
| 381 | - WHERE a.company_id=? AND a.delete_at = 0 ` | ||
| 382 | - var ( | ||
| 383 | - whereString string | ||
| 384 | - cond []interface{} | ||
| 385 | - ) | ||
| 386 | - cond = append(cond, param.Companyid) | ||
| 387 | - if len(param.NickName) > 0 { | ||
| 388 | - whereString += ` AND b.nick_name LIKE ? ` | ||
| 389 | - likeCond := "%" + param.NickName + "%" | ||
| 390 | - cond = append(cond, likeCond) | ||
| 391 | - } | ||
| 392 | - var ( | ||
| 393 | - result []protocol.UserListItem | ||
| 394 | - pageInfo protocol.ResponsePageInfo | ||
| 395 | - err error | ||
| 396 | - responseData protocol.ResponseUserList | ||
| 397 | - ) | ||
| 398 | - p := utils.NewQueryDataByPage(countSql+whereString, datasql+whereString) | ||
| 399 | - p.AddParam(cond...) | ||
| 400 | - p.LimitPage(param.PageIndex, param.PageSize) | ||
| 401 | - pageInfo, err = p.Query(&result) | ||
| 402 | - if err != nil { | ||
| 403 | - e := fmt.Errorf("page data err:%s", err) | ||
| 404 | - log.Error(e.Error()) | ||
| 405 | - return responseData, protocol.NewErrWithMessage("0") | ||
| 406 | - } | ||
| 407 | - // for k, v := range result { | ||
| 408 | - // positions, _ := models.GetUserPosition(v.UserId, param.Companyid) | ||
| 409 | - // departments, _ := models.GetUserDepartment(v.UserId, param.Companyid) | ||
| 410 | - // roles, _ := models.GetUserRole(v.UserId, param.Companyid) | ||
| 411 | - // } | ||
| 412 | - responseData.ResponsePageInfo = pageInfo | ||
| 413 | - responseData.List = result | ||
| 414 | - return responseData, nil | ||
| 415 | -} | ||
| 416 | - | ||
| 417 | -func GetUserDepartment(user int64, companyid int64) { | ||
| 418 | - | ||
| 419 | -} | ||
| 420 | - | ||
| 421 | -func GetUserPosition(user int64, companyid int64) { | ||
| 422 | - | 345 | +func UserList() error { |
| 346 | + return nil | ||
| 423 | } | 347 | } |
| @@ -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 | //消息发布订阅 |
utils/jwt.go
0 → 100644
| 1 | +package utils |
-
请 注册 或 登录 后发表评论