Revert "Merge branch 'dev' of http://gitlab.fjmaimaimai.com/mmm-go/oppmg into dev"
This reverts commit d8dd4bd1, reversing changes made to f1844d0f.
正在显示
26 个修改的文件
包含
356 行增加
和
607 行删除
| @@ -5,7 +5,10 @@ import ( | @@ -5,7 +5,10 @@ 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" | ||
| 8 | "strconv" | 10 | "strconv" |
| 11 | + "strings" | ||
| 9 | ) | 12 | ) |
| 10 | 13 | ||
| 11 | type CompanyController struct { | 14 | type CompanyController struct { |
| @@ -226,13 +229,35 @@ func (c *CompanyController) UserAdd() { | @@ -226,13 +229,35 @@ func (c *CompanyController) UserAdd() { | ||
| 226 | msg = protocol.BadRequestParam("1") | 229 | msg = protocol.BadRequestParam("1") |
| 227 | return | 230 | return |
| 228 | } | 231 | } |
| 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 | + } | ||
| 229 | param.CompanyId = c.GetCompanyId() | 254 | param.CompanyId = c.GetCompanyId() |
| 230 | err := servecompany.UserAdd(param) | 255 | err := servecompany.UserAdd(param) |
| 231 | msg = protocol.NewReturnResponse(nil, err) | 256 | msg = protocol.NewReturnResponse(nil, err) |
| 232 | return | 257 | return |
| 233 | } | 258 | } |
| 234 | 259 | ||
| 235 | -//UserAdd 添加用户 | 260 | +//UserEdit 编辑用户 |
| 236 | //@Router /user/edit [post] | 261 | //@Router /user/edit [post] |
| 237 | func (c *CompanyController) UserEdit() { | 262 | func (c *CompanyController) UserEdit() { |
| 238 | var msg *protocol.ResponseMessage | 263 | var msg *protocol.ResponseMessage |
| @@ -245,6 +270,24 @@ func (c *CompanyController) UserEdit() { | @@ -245,6 +270,24 @@ func (c *CompanyController) UserEdit() { | ||
| 245 | msg = protocol.BadRequestParam("1") | 270 | msg = protocol.BadRequestParam("1") |
| 246 | return | 271 | return |
| 247 | } | 272 | } |
| 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 | + } | ||
| 248 | param.CompanyId = c.GetCompanyId() | 291 | param.CompanyId = c.GetCompanyId() |
| 249 | err := servecompany.UserEdit(param) | 292 | err := servecompany.UserEdit(param) |
| 250 | msg = protocol.NewReturnResponse(nil, err) | 293 | msg = protocol.NewReturnResponse(nil, err) |
| @@ -46,35 +46,6 @@ func (this *TemplateController) TemplateAdd() { | @@ -46,35 +46,6 @@ 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 | - | ||
| 78 | //TemplateUpdate | 49 | //TemplateUpdate |
| 79 | //@router /templateUpdate [post] | 50 | //@router /templateUpdate [post] |
| 80 | func (this *TemplateController) TemplateUpdate() { | 51 | func (this *TemplateController) TemplateUpdate() { |
| @@ -112,7 +83,7 @@ func (this *TemplateController) TemplateList() { | @@ -112,7 +83,7 @@ func (this *TemplateController) TemplateList() { | ||
| 112 | defer func() { | 83 | defer func() { |
| 113 | this.ResposeJson(msg) | 84 | this.ResposeJson(msg) |
| 114 | }() | 85 | }() |
| 115 | - var request *protocol.TemplateListRequest | 86 | + var request *protocol.TemplateUpdateRequest |
| 116 | 87 | ||
| 117 | if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { | 88 | if err := json.Unmarshal(this.Ctx.Input.RequestBody, &request); err != nil { |
| 118 | log.Error("json 解析失败", err) | 89 | log.Error("json 解析失败", err) |
| @@ -130,65 +101,7 @@ func (this *TemplateController) TemplateList() { | @@ -130,65 +101,7 @@ func (this *TemplateController) TemplateList() { | ||
| 130 | msg = m | 101 | msg = m |
| 131 | return | 102 | return |
| 132 | } | 103 | } |
| 133 | - rsp, err := audit.TemplateList(uid, companyId, request) | 104 | + rsp, err := audit.TemplateUpdate(uid, companyId, request) |
| 134 | msg = protocol.NewReturnResponse(rsp, err) | 105 | msg = protocol.NewReturnResponse(rsp, err) |
| 135 | return | 106 | return |
| 136 | } | 107 | } |
| 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,14 +82,3 @@ func DeleteAuditForm(id int) (err error) { | @@ -82,14 +82,3 @@ 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,33 +8,22 @@ import ( | @@ -8,33 +8,22 @@ 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 | - 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:"示例"` | 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:"示例"` | ||
| 26 | } | 25 | } |
| 27 | 26 | ||
| 28 | -const ( | ||
| 29 | - VisibleTypeAll = 0 | ||
| 30 | - VisibleTypeDepartment = 1 | ||
| 31 | -) | ||
| 32 | - | ||
| 33 | -const ( | ||
| 34 | - VisibleObject_Department = 1 | ||
| 35 | - VisibleObject_User = 2 | ||
| 36 | -) | ||
| 37 | - | ||
| 38 | func (t *AuditTemplate) TableName() string { | 27 | func (t *AuditTemplate) TableName() string { |
| 39 | return "audit_template" | 28 | return "audit_template" |
| 40 | } | 29 | } |
| @@ -91,14 +80,3 @@ func DeleteAuditTemplate(id int64) (err error) { | @@ -91,14 +80,3 @@ func DeleteAuditTemplate(id int64) (err error) { | ||
| 91 | } | 80 | } |
| 92 | return | 81 | return |
| 93 | } | 82 | } |
| 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 GetChanceTypeByCompany(companyId int) (v []*ChanceType, err error) { | 77 | +func GetChanceTypeAll() (v []*ChanceType, err error) { |
| 78 | o := orm.NewOrm() | 78 | o := orm.NewOrm() |
| 79 | - sql := "select * from chance_type where company_id=?" | ||
| 80 | - if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | 79 | + sql := "select * from chance_type " |
| 80 | + if _, err = o.Raw(sql).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 | - Admin_id int64 `orm:"column(admin_id)"` | 13 | + AdminId 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,27 +75,6 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | @@ -75,27 +75,6 @@ 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 | - | ||
| 99 | // AddDepartment insert a new Department into database and returns | 78 | // AddDepartment insert a new Department into database and returns |
| 100 | // last inserted Id on success. | 79 | // last inserted Id on success. |
| 101 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { | 80 | func AddDepartment(m *Department, om ...orm.Ormer) (id int64, err error) { |
| @@ -175,15 +154,3 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) { | @@ -175,15 +154,3 @@ func GetDepartmentByCompanyId(companyId int64) ([]Department, error) { | ||
| 175 | All(&result) | 154 | All(&result) |
| 176 | return result, err | 155 | return result, err |
| 177 | } | 156 | } |
| 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,7 +62,9 @@ func AddUser(m *User, om ...orm.Ormer) (id int64, err error) { | @@ -62,7 +62,9 @@ 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 | - | 65 | + m.DeleteAt = time.Unix(0, 0) |
| 66 | + m.EnableStatus = USER_ENABLE_YES | ||
| 67 | + m.CreateAt = time.Now() | ||
| 66 | id, err = o.Insert(m) | 68 | id, err = o.Insert(m) |
| 67 | return | 69 | return |
| 68 | } | 70 | } |
| @@ -80,15 +82,16 @@ func GetUserById(id int64) (v *User, err error) { | @@ -80,15 +82,16 @@ func GetUserById(id int64) (v *User, err error) { | ||
| 80 | 82 | ||
| 81 | // UpdateUser updates User by Id and returns error if | 83 | // UpdateUser updates User by Id and returns error if |
| 82 | // the record to be updated doesn't exist | 84 | // the record to be updated doesn't exist |
| 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 | - } | 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) | ||
| 92 | } | 95 | } |
| 93 | return | 96 | return |
| 94 | } | 97 | } |
| @@ -86,29 +86,18 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | @@ -86,29 +86,18 @@ func UpdateUserDepartmentById(m *UserDepartment) (err error) { | ||
| 86 | } | 86 | } |
| 87 | return | 87 | return |
| 88 | } | 88 | } |
| 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) { | 89 | +func GetUserDepartment(userid, companyid int64) ([]*UserDepartment, error) { |
| 93 | o := orm.NewOrm() | 90 | o := orm.NewOrm() |
| 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 | 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 | ||
| 112 | } | 101 | } |
| 113 | 102 | ||
| 114 | func CountUserDepartByDepart(departid int64) (int64, error) { | 103 | func CountUserDepartByDepart(departid int64) (int64, error) { |
| @@ -61,45 +61,18 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | @@ -61,45 +61,18 @@ func AddUserPosition(m *UserPosition) (id int64, err error) { | ||
| 61 | return | 61 | return |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | -// GetUserPositionById retrieves UserPosition by Id. Returns error if | ||
| 65 | -// Id doesn't exist | ||
| 66 | -func GetUserPositionById(id int64) (v *UserPosition, err error) { | 64 | +func GetUserPosition(userid, companyid int64) ([]*UserPosition, error) { |
| 67 | o := orm.NewOrm() | 65 | o := orm.NewOrm() |
| 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 | 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 | ||
| 103 | } | 76 | } |
| 104 | 77 | ||
| 105 | func CountUserPositionByPosition(positionid int64) (int64, error) { | 78 | func CountUserPositionByPosition(positionid int64) (int64, error) { |
| @@ -59,45 +59,18 @@ func AddUserRole(m *UserRole) (id int64, err error) { | @@ -59,45 +59,18 @@ func AddUserRole(m *UserRole) (id int64, err error) { | ||
| 59 | return | 59 | return |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | -// GetUserRoleById retrieves UserRole by Id. Returns error if | ||
| 63 | -// Id doesn't exist | ||
| 64 | -func GetUserRoleById(id int) (v *UserRole, err error) { | 62 | +func GetUserRole(userid, companyid int64) ([]*UserRole, error) { |
| 65 | o := orm.NewOrm() | 63 | o := orm.NewOrm() |
| 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 | 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 | ||
| 101 | } | 74 | } |
| 102 | 75 | ||
| 103 | func CountUserRoleByRole(roleid int64) (int64, error) { | 76 | 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:"-"` //"当前填写的值" | 19 | + CurrentValue string `json:"value"` //"当前填写的值" |
| 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,10 +106,9 @@ type TemplateUpdateResponse struct { | @@ -106,10 +106,9 @@ 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"` | ||
| 110 | } | 109 | } |
| 111 | 110 | ||
| 112 | -type TemplateList struct { | 111 | +type ChanceType struct { |
| 113 | Id int `json:"id"` | 112 | Id int `json:"id"` |
| 114 | Name string `json:"name"` | 113 | Name string `json:"name"` |
| 115 | Icon string `json:"icon"` | 114 | Icon string `json:"icon"` |
| @@ -128,33 +127,7 @@ type TemplateItem struct { | @@ -128,33 +127,7 @@ type TemplateItem struct { | ||
| 128 | } | 127 | } |
| 129 | 128 | ||
| 130 | type VisibleObject struct { | 129 | 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 { | ||
| 146 | Id int `json:"id"` | 130 | Id int `json:"id"` |
| 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"` //示例` | 131 | + Name string `json:"name,omitempty"` |
| 132 | + Type int //1:部门 2:指定人员 | ||
| 160 | } | 133 | } |
| @@ -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 []VisibleObject `json:"receiver" valid:"Required"` | ||
| 23 | - Question Question `json:"question"` | ||
| 24 | - Cover Cover `json:"cover" valid:"Required"` | 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"` | ||
| 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 []VisibleObject `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 []Receiver `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 []VisibleObject `json:"receiver" valid:"Required"` | ||
| 77 | - Question Question `json:"question"` | ||
| 78 | - Cover Cover `json:"cover" valid:"Required"` | 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"` | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | type Receiver struct { | 81 | type Receiver struct { |
| @@ -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 []VisibleObject `json:"receiver" valid:"Required"` | 95 | + Receiver []string `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,3 +12,26 @@ type ResponsePageInfo struct { | @@ -12,3 +12,26 @@ 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,11 +17,6 @@ type DepartmentManager struct { | @@ -17,11 +17,6 @@ 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 | - | ||
| 25 | //RequestDepartmentEdit 编辑 | 20 | //RequestDepartmentEdit 编辑 |
| 26 | type RequestDepartmentEdit struct { | 21 | type RequestDepartmentEdit struct { |
| 27 | ID int64 `json:"id"` | 22 | ID int64 `json:"id"` |
| @@ -94,7 +89,8 @@ type RequestUserEdit struct { | @@ -94,7 +89,8 @@ type RequestUserEdit struct { | ||
| 94 | //RequestUserList 获取用户列表 | 89 | //RequestUserList 获取用户列表 |
| 95 | type RequestUserList struct { | 90 | type RequestUserList struct { |
| 96 | RequestPageInfo | 91 | RequestPageInfo |
| 97 | - NickName string `json:"nick_name"` | 92 | + NickName string `json:"nick_name"` |
| 93 | + Companyid int64 `json:"company_id"` | ||
| 98 | } | 94 | } |
| 99 | 95 | ||
| 100 | //ResponseUserList 响应的用户列表 | 96 | //ResponseUserList 响应的用户列表 |
| @@ -21,6 +21,11 @@ var errmessge ErrorMap = map[string]string{ | @@ -21,6 +21,11 @@ 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": "用户的角色必填", | ||
| 24 | "10039": "用户已存在", | 29 | "10039": "用户已存在", |
| 25 | } | 30 | } |
| 26 | 31 |
| @@ -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:PositionDelete"), | 41 | + beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), |
| 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,13 +51,10 @@ func init() { | @@ -51,13 +51,10 @@ 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("/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"), | 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"), | ||
| 61 | ), | 58 | ), |
| 62 | ) | 59 | ) |
| 63 | 60 |
services/agg/common.go
已删除
100644 → 0
| 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,19 +2,16 @@ package audit | @@ -2,19 +2,16 @@ package audit | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "database/sql" | 4 | "database/sql" |
| 5 | - "encoding/json" | ||
| 6 | "fmt" | 5 | "fmt" |
| 7 | orm2 "github.com/astaxie/beego/orm" | 6 | orm2 "github.com/astaxie/beego/orm" |
| 8 | "oppmg/common/log" | 7 | "oppmg/common/log" |
| 9 | "oppmg/models" | 8 | "oppmg/models" |
| 10 | "oppmg/protocol" | 9 | "oppmg/protocol" |
| 11 | - "oppmg/services/agg" | ||
| 12 | "oppmg/utils" | 10 | "oppmg/utils" |
| 13 | "strings" | 11 | "strings" |
| 14 | "time" | 12 | "time" |
| 15 | ) | 13 | ) |
| 16 | 14 | ||
| 17 | -//添加模板 | ||
| 18 | func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) { | 15 | func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rsp *protocol.TemplateAddResponse, err error) { |
| 19 | var ( | 16 | var ( |
| 20 | auditForm *models.AuditForm | 17 | auditForm *models.AuditForm |
| @@ -30,7 +27,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -30,7 +27,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
| 30 | //模板 | 27 | //模板 |
| 31 | { | 28 | { |
| 32 | template = &models.AuditTemplate{ | 29 | template = &models.AuditTemplate{ |
| 33 | - ChanceTypeId: request.Template.ChanceTypeId, | ||
| 34 | CompanyId: int(companyId), | 30 | CompanyId: int(companyId), |
| 35 | Name: request.Template.Name, | 31 | Name: request.Template.Name, |
| 36 | Doc: request.Template.Doc, | 32 | Doc: request.Template.Doc, |
| @@ -78,7 +74,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -78,7 +74,6 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
| 78 | return | 74 | return |
| 79 | } | 75 | } |
| 80 | 76 | ||
| 81 | -//模板更新 | ||
| 82 | func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) { | 77 | func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) { |
| 83 | var ( | 78 | var ( |
| 84 | template *models.AuditTemplate | 79 | template *models.AuditTemplate |
| @@ -181,158 +176,8 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input | @@ -181,158 +176,8 @@ func insertOrUpdateInput(orm orm2.Ormer, companyId int64, templateId int, input | ||
| 181 | return | 176 | return |
| 182 | } | 177 | } |
| 183 | 178 | ||
| 184 | -//模板列表 | ||
| 185 | func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) { | 179 | func TemplateList(uid, companyId int64, request *protocol.TemplateListRequest) (rsp *protocol.TemplateListResponse, err error) { |
| 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 | - } | 180 | + var () |
| 194 | rsp = &protocol.TemplateListResponse{} | 181 | 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 | - } | ||
| 337 | return | 182 | return |
| 338 | } | 183 | } |
| @@ -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 | - "oppmg/services/agg" | 9 | + "strconv" |
| 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 = agg.GetVisibleObject(bulletin.Receiver); err != nil { | 113 | + if item.Receiver, err = getUsersName(bulletin.Receiver); err != nil { |
| 114 | log.Error(err.Error()) | 114 | log.Error(err.Error()) |
| 115 | continue | 115 | continue |
| 116 | } | 116 | } |
| @@ -120,6 +120,36 @@ func BulletinList(uid, companyId int64, request *protocol.BulletinListRequest) ( | @@ -120,6 +120,36 @@ 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 | + | ||
| 123 | //公告详情 | 153 | //公告详情 |
| 124 | func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) (rsp *protocol.GetBulletinResponse, err error) { | 154 | func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) (rsp *protocol.GetBulletinResponse, err error) { |
| 125 | var ( | 155 | var ( |
| @@ -165,7 +195,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) | @@ -165,7 +195,7 @@ func GetBulletin(id int, companyId int64, request *protocol.GetBulletinRequest) | ||
| 165 | return | 195 | return |
| 166 | } | 196 | } |
| 167 | } | 197 | } |
| 168 | - if rsp.Receiver, err = agg.GetVisibleObject(bulletin.Receiver); err != nil { | 198 | + if rsp.Receiver, err = getUsersName(bulletin.Receiver); err != nil { |
| 169 | log.Error(err.Error()) | 199 | log.Error(err.Error()) |
| 170 | return | 200 | return |
| 171 | } | 201 | } |
services/common/selector.go
0 → 100644
| 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,7 +308,6 @@ func DepartmentListAll(companyId int64) ([]protocol.ResponseDepartmentInfo, erro | @@ -308,7 +308,6 @@ 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() | ||
| 312 | departs = append(departs, depart) | 311 | departs = append(departs, depart) |
| 313 | } | 312 | } |
| 314 | 313 |
| @@ -160,22 +160,28 @@ func validCompanyUser(companyid int64, phone string) error { | @@ -160,22 +160,28 @@ func validCompanyUser(companyid int64, phone string) error { | ||
| 160 | //registUser 注册用户 | 160 | //registUser 注册用户 |
| 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 | ||
| 164 | - // usrData *models.User | 163 | + err error |
| 164 | + usrData *models.User | ||
| 165 | ) | 165 | ) |
| 166 | - _, err = models.GetUserByPhone(userIn.Phone) | ||
| 167 | - if err == nil { | ||
| 168 | - return nil | ||
| 169 | - } | 166 | + usrData, err = models.GetUserByPhone(userIn.Phone) |
| 170 | if err != nil && err != orm.ErrNoRows { | 167 | if err != nil && err != orm.ErrNoRows { |
| 171 | return err | 168 | return err |
| 172 | } | 169 | } |
| 173 | if err == orm.ErrNoRows { | 170 | if err == orm.ErrNoRows { |
| 171 | + //用户不存在 添加用户 | ||
| 174 | _, err := models.AddUser(userIn, o) | 172 | _, err := models.AddUser(userIn, o) |
| 175 | if err != nil { | 173 | if err != nil { |
| 176 | return err | 174 | return err |
| 177 | } | 175 | } |
| 178 | } | 176 | } |
| 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 | + } | ||
| 179 | musercompany := &models.UserCompany{ | 185 | musercompany := &models.UserCompany{ |
| 180 | CompanyId: companyid, | 186 | CompanyId: companyid, |
| 181 | UserId: userIn.Id, | 187 | UserId: userIn.Id, |
| @@ -369,7 +375,25 @@ func UserEdit(param protocol.RequestUserEdit) error { | @@ -369,7 +375,25 @@ func UserEdit(param protocol.RequestUserEdit) error { | ||
| 369 | return nil | 375 | return nil |
| 370 | } | 376 | } |
| 371 | 377 | ||
| 372 | -func UserDelete(param protocol.RequestUserAdd) error { | 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 | + } | ||
| 373 | return nil | 397 | return nil |
| 374 | } | 398 | } |
| 375 | 399 |
| @@ -64,4 +64,11 @@ func ExistLoginToken(userid int64) bool { | @@ -64,4 +64,11 @@ 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 | + | ||
| 67 | //消息发布订阅 | 74 | //消息发布订阅 |
utils/jwt.go
已删除
100644 → 0
| 1 | -package utils |
-
请 注册 或 登录 后发表评论