package controllers import ( "encoding/json" "strings" "dashoo.cn/backend/api/business/device" "dashoo.cn/backend/api/business/logsinfo" "dashoo.cn/backend/api/business/organize" "dashoo.cn/backend/api/business/role" "dashoo.cn/backend/api/business/userchannels" "dashoo.cn/backend/api/models" "dashoo.cn/business2/auth" "dashoo.cn/business2/permission" "dashoo.cn/business2/userRole" "dashoo.cn/utils" ) // Operations about Users type UserController struct { BaseController } type UserModel struct { Username string `json:"username"` Realname string `json:"realname"` Telephone string `json:"telephone"` Mobile string `json:"mobile"` Description string `json:"description"` Photo string `json:"photo"` Role string `json:"role"` Id int `json:"id"` ChannelIds string `json:"channelids"` Password string `json:"password"` DepartmentId string `json:"departmentid"` DepartmentName string `json:"departmentname"` Sign string `json:"sign"` } type Note struct { Surplus int `json:"surplus"` } type UserAccountModel struct { ChannelOffNum int64 `json:"channeloffnum"` ChannelTriggerNum int64 `json:"channeltriggernum"` ChannelNormalNum int64 `json:"channelnormalnum"` NoteNum int64 `json:"notenum"` VoiceNum int64 `json:"voicenum"` } type ChangePwdModel struct { Pwd string `json:"pass"` NwePwd string `json:"newpass"` } type UserModuleModel struct { A1list string `json:"a1"` // 第一级菜单 A2list string `json:"a2"` // 第二级菜单 } type RegisteModel struct { Companyname string `json:"companyname"` Username string `json:"username"` Password string `json:"password"` Source string `json:"source"` } // @Title get // @Description get user by token // @Param uid path string true "The key for staticblock" // @Success 200 {object} models.User // @Failure 403 :uid is empty // @router /me [get] func (this *UserController) Get() { svc := userRole.GetUserService(utils.DBE) usermodel := svc.GetUserInfoSelf(this.User.Username) // var companyentity company.Base_Company // svc.GetEntityById(usermodel.AccCode, &companyentity) var user models.User user.Id = utils.ToStr(usermodel.Id) user.Username = usermodel.Username user.Profile.Address = usermodel.Homeaddress user.Profile.Email = usermodel.Email user.Profile.Realname = usermodel.Realname user.Profile.Roleid = usermodel.Roleid user.Profile.Mobile = usermodel.Mobile user.Profile.Telephone = usermodel.Telephone user.Profile.Photo = usermodel.Photo user.Profile.Description = usermodel.Description user.Profile.Host = this.Ctx.Request.Host user.Profile.AccCode = usermodel.AccCode user.Profile.DepartmentId = usermodel.Departmentid user.Profile.Id = usermodel.Id // todo 从this.User获取用户名,再查询出具体用户 // user := models.User{"user01", "张三", models.Profile{Gender: "male", Age: 20, Address: "china", Email: "123zs@gmail.com", Realname: "ppppppp"}} this.Data["json"] = user this.ServeJSON() } // @Title 获取账户信息 // @Description 获取账户信息 // @Success 200 {object} models.User // @router /account [get] func (this *UserController) GetAccount() { u, p := this.GetuAndp() var model UserAccountModel svc := userchannels.GetUserChannelService(utils.DBE) channelid := svc.GetChannelids(utils.ToStr(this.User.Id)) where := " (CreateUserId=" + utils.ToStr(this.User.Id) + " or Id in (" + strings.Join(channelid, ",") + ")) and DataItem in (" + ChannelItem_Sensor + ")" var entity device.Channels model.ChannelNormalNum, _ = svc.GetCount(&entity, where+" and ChannelState in (1,0)") model.ChannelOffNum, _ = svc.GetCount(&entity, where+" and ChannelState in (2)") model.ChannelTriggerNum, _ = svc.GetCount(&entity, where+" and ChannelState in (3)") var note Note strUrlnote := utils.Cfg.MustValue("server", "apiurl") + "/accountinfos/get?u=" + u + "&p=" + p + "&source=coldchain&account=" + this.GetAccode() + "&atype=sms" json.Unmarshal(Apiget(strUrlnote), ¬e) model.NoteNum = int64(note.Surplus) //语音剩余 var voice Note strUrlvoice := utils.Cfg.MustValue("server", "apiurl") + "/accountinfos/get?u=" + u + "&p=" + p + "&source=coldchain&account=" + this.GetAccode() + "&atype=voice" json.Unmarshal(Apiget(strUrlvoice), &voice) model.VoiceNum = int64(voice.Surplus) this.Data["json"] = model this.ServeJSON() } // @Title 获取账户统计信息 // @Description 获取账户统计信息 // @Success 200 {object} controllers.Request // @router /getaccountingo [get] func (this *UserController) GetAccountInfo() { // svcs := equipment.GetEquipmentService(utils.DBE) // svcrole := role.GetRoleService(utils.DBE) // roleids := svcrole.GetRoleidsByuid(utils.ToStr(this.User.Id)) // where := " a.AccCode = '" + this.User.AccCode + "'" // where = where + " and (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (select EquipmentId Id FROM Base_RoleEquipment where RoleId in (" + strings.Join(roleids, ",") + ")))" // devicetotal, _ := svcs.GetEquipmenViewtList(1, 1, "a.Id", where) // //已录入样本 // where1 := " IState =1 and DeletionStateCode=0 " // poweeids := svcs.GetPowerEquipmentids(this.User.AccCode, utils.ToStr(this.User.Id)) // where1 = where1 + " and a.EquipmentId in(" + strings.Join(poweeids, ",") + ")" // svc := samplesinfo.GetSamplesInfoService(utils.DBE) // yilurutotal, _ := svc.GetPagingEntitiesWithOrderSearch(this.User.AccCode, 1, 1, "Id desc", where1) // // 预录入 // where2 := " a.IState in (2,3,4,7,8) and a.DeletionStateCode=0 " // yulurutotal, _ := svc.GetPagingEntitiesWithOrderSearch(this.User.AccCode, 1, 1, "Id desc", where2) // //待复存 // where3 := " DeletionStateCode=0 and (IState=6 or ( IState=5 and a.EquipmentId in(" + strings.Join(poweeids, ",") + ")))" // daifuchuntotal, _ := svc.GetPagingEntitiesWithOrderSearch(this.User.AccCode, 1, 1, "Id desc", where3) // //已归档 // svcf := samplesfileinfo.GetSamplesFileInfoService(utils.DBE) // where4 := " DeletionStateCode=0 " // yiguidangtotal, _ := svcf.GetPagingEntitiesWithOrderSearch(this.User.AccCode, 1, 1, "Id desc", where4) // //待办事项 // svcw := samplesapply.GetSamplesApplyService(utils.DBE) // where_rk := " ApplyType = 1 and ApplyStatus = 0 " // rktotal, rklist := svcw.GetApplyViewtList(1, 1, this.User.AccCode+SamplesApplyName, "Id", where_rk) // where_ck := " ApplyType = 2 and ApplyStatus = 0 " // cktotal, cklist := svcw.GetApplyViewtList(1, 1, this.User.AccCode+SamplesApplyName, "Id", where_ck) // //待随访 // svcsf := flupplan.GetFlupPlanService(utils.DBE) // where_sf := " a.AccCode='" + this.User.AccCode + "' and a.DeletionStateCode=0 " // sftotal, _ := svcsf.GetPagingEntitiesWithOrderSearch(1, 1, "a.Id desc", where_sf, this.User.AccCode+DonorstbName) // this.Data["json"] = AccountTjModel{devicetotal, yilurutotal, yulurutotal, daifuchuntotal, yiguidangtotal, sftotal, rktotal, rklist, cktotal, cklist} // this.ServeJSON() } // @Title get // @Description get user by token // @Success 200 {object} models.User // @router /list [get] func (this *UserController) List() { page := this.GetPageInfoForm() keyword := this.GetString("keyword") svc := permission.GetPermissionService(utils.DBE) var users []userRole.Base_User //是否开启组织结构 // isopenorg := IsAuthorized(this.User.Id, "coldclouds.user.openorg") // var orgtree []organize.Base_Organizetree // svc1 := device.GetDeviceService(utils.DBE) // uid := utils.ToStr(this.User.Id) // wherebindingcompany := "CreateUserId=" + uid // wheredevice := " a.DataItem in (" + ChannelItem_Sensor + ") and a.CreateUserId=" + utils.ToStr(this.User.Id) // tree := svc1.GetTree_OrgAndDevice(wherebindingcompany, wheredevice, uid, isopenorg) //orgtree = append(tree, organize.Base_Organizetree{Id: 0, ParentId: -1, FullName: this.User.Realname, Icon: "/static/img/1_open.png"}) // orgtree = append(tree, organize.Base_Organizetree{Id: 0, ParentId: -1, FullName: this.User.Realname}) // this.Data["orgtree"] = orgtree where := "IsVisible=1 and CreateUserId='" + utils.ToStr(this.User.Id) + "' or Id = '" + utils.ToStr(this.User.Id) + "' " if keyword != "" { where = where + " and Realname like '%" + keyword + "%'" } total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "Id", false, &users, where) var datainfo DataInfo datainfo.Items = users datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title get // @Description get user by token // @Success 200 {object} models.User // @router /usualwithrole [get] func (this *UserController) UsualWithRole() { page := this.GetPageInfoForm() keyword := this.GetString("keyword") svc := permission.GetPermissionService(utils.DBE) var users []userRole.UserRoleModel orderby := "a.Id desc" Order := this.GetString("Order") Prop := this.GetString("Prop") if Order != "" && Prop != "" { orderby = Prop + " " + Order } where := "a.IsVisible=1 and d.GroupId is NULL " where += " and ( a.CreateUserId='" + utils.ToStr(this.User.Id) + "' or a.Id = '" + utils.ToStr(this.User.Id) + "' )" if keyword != "" { where = where + " and a.UserName like '%" + keyword + "%'" } total, users := svc.GetUserListWithRole(page.CurrentPage, page.Size, orderby, where) var datainfo DataInfo datainfo.Items = users datainfo.CurrentItemCount = total this.Data["json"] = &datainfo this.ServeJSON() } // @Title get // @Description get user by token // @Success 200 {object} models.User // @router /listwithrole [get] func (this *UserController) ListWithRole() { //page := this.GetPageInfoForm() //keyword := this.GetString("keyword") //svc := permission.GetPermissionService(utils.DBE) //var users []userRole.UserRoleModel //orderby := "m.Id desc" //Order := this.GetString("Order") //Prop := this.GetString("Prop") //if Order != "" && Prop != "" { // orderby = Prop + " " + Order //} //where := "a.IsVisible=1 and a.CreateUserId='" + utils.ToStr(this.User.Id) + "' or a.Id = '" + utils.ToStr(this.User.Id) + "' " //if keyword != "" { // where = where + " and a.Realname like '%" + keyword + "%'" //} //total, users := svc.GetPartnerListWithRole(page.CurrentPage, page.Size, this.User.AccCode+GroupDetailName, orderby, where) //var datainfo DataInfo //datainfo.Items = users //datainfo.CurrentItemCount = total //this.Data["json"] = &datainfo //this.ServeJSON() } // @Title 创建用户 // @Description 创建用户 // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router / [post] func (this *UserController) AddUser() { /*var model UserModel var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var errinfo ErrorDataInfo departidint, _ := utils.StrTo(model.DepartmentId).Int() if departidint < 1 { errinfo.Message = "请选择所属组织!" errinfo.Code = -3 this.Data["json"] = &errinfo this.ServeJSON() return } //获取组织名称 svcorg := organize.GetOrganizeService(utils.DBE) model.DepartmentName = svcorg.GetNameById(model.DepartmentId) var userentity userRole.Base_User userentity.Roleid, _ = utils.StrTo(model.Role).Int() if userentity.Roleid == 0 { //userentity.Roleid = 10000123 //普通用户 } userentity.Username = model.Username userentity.Realname = model.Realname userentity.Telephone = model.Telephone userentity.Mobile = model.Mobile if model.Sign == "" { userentity.Description = model.Description } else { userentity.Description = model.Sign } userentity.Photo = model.Photo currentuser := this.User userentity.Createuserid, _ = utils.StrTo(currentuser.Id).Int() userentity.Createby = currentuser.Realname userentity.AccCode = this.GetAccode() userentity.QRCode = utils.GetGuid() userentity.Departmentid = model.DepartmentId userentity.Departmentname = model.DepartmentName //salt := utils.GetRandomString(5) //userentity.Userpassword = fmt.Sprintf("%s$%s", salt, utils.EncodePassword("123456", salt)) //更改密码算法2014-11-21 pwd, key, errrk := utils.TripleDesEncrypt("123456") if errrk != nil { errinfo.Message = "添加失败!" + utils.AlertProcess(errrk.Error()) errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } userentity.Userpassword = pwd userentity.Publickey = key userentity.Auditstatus = 1 userentity.Email = userentity.Username svc := userRole.GetUserService(utils.DBE) err := svc.AddUser(&userentity) if err == nil { errinfo.Message = "添加用户成功,初始密码为123456!" errinfo.Code = 0 errinfo.Item = userentity.Id this.Data["json"] = &errinfo this.ServeJSON() return } else { errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return }*/ } // @Title 编辑用户 // @Description 编辑用户 // @Param id path string true "需要修改的传感器编号" // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /:id [put] func (this *UserController) EditUser() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model UserModel var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var userentity userRole.Base_User var userentityempty userRole.Base_User svc := userRole.GetUserService(utils.DBE) has := svc.GetEntityById(id, &userentity) if has { //获取组织名称 svcorg := organize.GetOrganizeService(utils.DBE) model.DepartmentName = svcorg.GetNameById(model.DepartmentId) // roleid, _ := utils.StrTo(model.Role).Int() // if userentity.Roleid != roleid { // svc.ClearUserRole(id) // svc.AddUserToRole(id, model.Role, userentity) // } userentity.Realname = model.Realname userentity.Telephone = model.Telephone userentity.Mobile = model.Mobile if model.Sign == "" { userentity.Description = model.Description } else { userentity.Description = model.Sign } userentity.Photo = model.Photo // userentity.Roleid = roleid userentity.Modifieduserid, _ = utils.StrTo(this.User.Id).Int() userentity.Modifiedby = this.User.Realname userentity.Departmentid = model.DepartmentId userentity.Departmentname = model.DepartmentName var cols []string = []string{"Realname", "DepartmentId", "DepartmentName", "Telephone", "Mobile", "Description", "Photo", "Modifieduserid", "Modifiedby"} err := svc.UpdateEntityAndBackupByCols(id, &userentity, &userentityempty, cols, utils.ToStr(this.User.Id), this.User.Realname) if err == nil { errinfo.Message = "保存成功!" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "操作失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } else { errinfo.Message = "操作失败!操作数据不存在" errinfo.Code = -3 this.Data["json"] = &errinfo this.ServeJSON() return } } // @Title 删除用户 // @Description 删除用户 // @Param id path string true "需要删除的用户编号" // @Success 200 {object} ErrorInfo // @Failure 403 :id 为空 // @router /:id [delete] func (this *UserController) Delete() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var entity userRole.Base_User var entityempty userRole.Base_User svc := userRole.GetUserService(utils.DBE) err := svc.DeleteEntityAndBackup(id, &entity, &entityempty, utils.ToStr(this.User.Id), this.User.Username) if err == nil { svc.ClearUserRole(id) //清除角色 errinfo.Message = "删除成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 创建用户 // @Description 创建用户 // @Param id path string true "需要修改的传感器编号" // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /permission/:id [put] func (this *UserController) SetPermission() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo if id == "" { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() return } var model UserModel var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) svc := userchannels.GetUserChannelService(utils.DBE) ids := strings.Split(model.ChannelIds, ",") uid, _ := utils.StrTo(id).Int() svc.ClearUserChannel(uid) var uc userchannels.Base_UserChannels uc.UserId = uid uc.AccCode = this.GetAccode() uc.Createuserid, _ = utils.StrTo(this.User.Id).Int() uc.Createby = this.User.Realname for i := 0; i < len(ids); i++ { id, _ := utils.StrTo(ids[i]).Int() if id != 0 { uc.ChannelsId = id svc.InsertEntity(&uc) } } errinfo.Message = "权限调整成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } // @Title 创建用户 // @Description 创建用户 // @Param id path string true "需要修改的传感器编号" // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /permission/:id [get] func (this *UserController) GetPermission() { id := this.Ctx.Input.Param(":id") svc := userchannels.GetUserChannelService(utils.DBE) this.Data["json"] = svc.GetChannelids(id) this.ServeJSON() } // @Title 创建用户 // @Description 创建用户 // @Param id path string true "需要修改的传感器编号" // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /resetpwd/:id [put] func (this *UserController) ResetPassWord() { id := this.Ctx.Input.Param(":id") var errinfo ErrorInfo uid, err := utils.StrTo(id).Int() if err == nil { svcauth := auth.GetAuthServic(utils.DBE) var umodel userRole.Base_User = userRole.Base_User{Id: uid} var entitypaw1, entitypaw2 logsinfo.Userpassword svcauth.UpdateLog(id, &entitypaw1, &entitypaw2, utils.ToStr(this.User.Id), this.User.Realname) errset := svcauth.SetNewPassword3DES(&umodel, "123456") if errset == nil { errinfo.Message = "密码重置成功!已重置为:123456" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "密码重置失败!" + utils.AlertProcess(err.Error()) errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } } else { errinfo.Message = "操作失败!请求信息不完整" errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 创建用户 // @Description 创建用户 // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /uploadphoto [post] func (this *UserController) UploadPhoto() { var path string path = "/static/upload/img/user/" photopath := UploadImage("png", path, this.Ctx.Request) this.Data["json"] = photopath this.ServeJSON() } // @Title 创建用户 // @Description 创建用户 // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /membersetting [put] func (this *UserController) MemberSetting() { var model models.Profile var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var errinfo ErrorInfo svc := userRole.GetUserService(utils.DBE) userentity := svc.GetUserInfoSelf(this.User.Username) userentity.Homeaddress = model.Address userentity.Email = model.Email userentity.Realname = model.Realname userentity.Mobile = model.Mobile userentity.Telephone = model.CompanyCode userentity.Photo = model.Photo userentity.Description = model.Description var userentityempty userRole.Base_User userentity.Modifieduserid = userentity.Id userentity.Modifiedby = userentity.Realname var cols []string = []string{"Realname", "Telephone", "Email", "Photo", "Description", "Modifieduserid", "Modifiedby", "Homeaddress", "Mobile"} err := svc.UpdateEntityAndBackupByCols(userentity.Id, &userentity, &userentityempty, cols, utils.ToStr(this.User.Id), this.User.Realname) if err == nil { // var companyentity company.Base_Company // companyentity.Fullname = userentity.Realname // companyentity.Address = userentity.Homeaddress // var cols []string = []string{"Fullname", "Address", "OuterPhone", "Manager", "Code"} // svc.UpdateEntityByIdCols(userentity.AccCode, &companyentity, cols) if "10000120" == this.User.Roles { // 企业管理员 //修改根组织 var orgentity organize.Base_Organize orgentity.Fullname = userentity.Realname var orgcols []string = []string{"Fullname"} svc.UpdateEntityByIdCols(userentity.Departmentid, &orgentity, orgcols) } errinfo.Message = "设置成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "设置失败!" + utils.AlertProcess(err.Error()) errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } } // @Title 修改密码 // @Description 修改密码 // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /userchangepwd [put] func (this *UserController) UserChangePWD() { var model ChangePwdModel var jsonblob = this.Ctx.Input.RequestBody json.Unmarshal(jsonblob, &model) var errinfo ErrorInfo svcauth := auth.GetAuthServic(utils.DBE) var user userRole.Base_User if svcauth.VerifyUser3DES(this.User.Username, model.Pwd, &user) { var entitypaw1, entitypaw2 logsinfo.Userpassword idint, _ := utils.StrTo(this.User.Id).Int() var umodel userRole.Base_User = userRole.Base_User{Id: idint} svcauth.UpdateLog(this.User.Id, &entitypaw1, &entitypaw2, this.User.Id, this.User.Realname) err := svcauth.SetNewPassword3DES(&umodel, model.NwePwd) if err != nil { errinfo.Message = "修改失败!" + err.Error() errinfo.Code = -2 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "密码修改成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } } else { errinfo.Message = "修改失败!当前密码输入错误" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } } // @Title 按样本类型统计样本数量 // @Description 按样本类型统计样本数量 // @Success 200 {object} controllers.Request // @router /gettotalbysampletype [get] //func (this *UserController) GetTotalByGroupbysampletype() { // diseases := this.GetString("diseases") // svc := samplesinfo.GetSamplesInfoService(utils.DBE) // where := " a.DeletionStateCode=0 " // if diseases != "" { // where = where + " and c.PathologicalNum = '" + diseases + "'" // } // this.Data["json"] = svc.GetTJBysampletype(this.User.AccCode, where) // this.ServeJSON() //} // @Title 按设备统计样本数量 // @Description 按设备统计样本数量 // @Success 200 {object} controllers.Request // @router /gettotalbygroupbydevice [get] //func (this *UserController) GetTotalByGroupbydevice() { // svcrole := role.GetRoleService(utils.DBE) // roleids := svcrole.GetRoleidsByuid(utils.ToStr(this.User.Id)) // where := " a.AccCode = '" + this.User.AccCode + "'" // where = where + " and b.IState =1 and b.DeletionStateCode=0 and (a.CreateUserId=" + utils.ToStr(this.User.Id) + " or a.Id in (select EquipmentId Id FROM Base_RoleEquipment where RoleId in (" + strings.Join(roleids, ",") + ")))" // svc := samplesinfo.GetSamplesInfoService(utils.DBE) // this.Data["json"] = svc.GetTJBydevice(this.User.AccCode, where) // this.ServeJSON() //} // @Title 用户角色设置 // @Description 用户角色设置 // @Success 200 {object} controllers.Request // @router /setuserrole/:id [put] func (this *UserController) UserPowerPostRole() { //svc := userRole.GetUserService(utils.DBE) //inputstr := this.Ctx.Input.Param(":id") //serial := strings.Split(inputstr, "_") //userid := serial[0] //var errinfo ErrorInfo //if userid == "" || userid == "0" { // errinfo.Message = "操作失败!请求信息不完整" // errinfo.Code = -2 // this.Data["json"] = &errinfo // this.ServeJSON() // return //} //roleids := strings.Split(serial[1], ",") //svc.ClearUserRole(userid) //entity := svc.GetReport(userid) //var err error = nil //for i := 0; i < len(roleids); i++ { // if roleids[i] != "0" && roleids[i] != "" { // err = svc.AddUserToRole(userid, roleids[i], entity[0]) // } //} //if err == nil { // errinfo.Message = utils.AlertProcess("用户角色调整成功!") // errinfo.Code = 0 // this.Data["json"] = &errinfo // this.ServeJSON() //} else { // errinfo.Message = utils.AlertProcess("用户角色调整失败!" + err.Error()) // errinfo.Code = -1 // this.Data["json"] = &errinfo // this.ServeJSON() //} } // @Title 获得用户角色id // @Description 获得用户角色id // @Success 200 {object} controllers.Request // @router /getuserrole/:id [get] func (this *UserController) UserPowerCheckRole() { userid := this.Ctx.Input.Param(":id") svc := role.GetRoleService(utils.DBE) roleofuser := svc.GetSelfRoleids(userid) this.Data["json"] = &roleofuser this.ServeJSON() } // @Title 注册管理账号 // @Description 注册管理账号 // @Param body body business.device.DeviceChannels "传感器信息" // @Success 200 {object} controllers.Request // @router /registemanage [put] //func (this *UserController) Registerput() { // var model RegisteModel // var jsonblob = this.Ctx.Input.RequestBody // json.Unmarshal(jsonblob, &model) // var errinfo ErrorInfo // var user userRole.Base_User // user.Username = model.Username // user.Realname = model.Companyname // // this.ParseForm(&user) //去页面数值 // svc := company.GetCompanyService(utils.DBE) // err, comacccode := svc.AddCompany(user.Realname, user.Username) //这两个参数传到company库,返回id // if err == nil { // svcuser := userRole.GetUserService(utils.DBE) // user.AccCode = comacccode //id传到 user库的acccode // pass := model.Password //取到前台密码 // //更改密码算法2014-11-21 // pwd, key, errrk := utils.TripleDesEncrypt(pass) // if errrk != nil { // errinfo.Message = "添加失败!" + utils.AlertProcess(errrk.Error()) // errinfo.Code = -2 // this.Data["json"] = &errinfo // this.ServeJSON() // return // } // user.Roleid = 10000120 //企业用户 // user.Auditstatus = 1 // user.Userpassword = pwd // user.Publickey = key // user.Email = user.Username // err = svcuser.AddUser(&user) // svcSampleOrgan := sampleorgan.GetSampleOrganService(utils.DBE) // var entityOrgan sampleorgan.SampleOrgan // entityOrgan.AccCode = comacccode // entityOrgan.TNode = "SystemInner" // entityOrgan.TNodeParent = "0" // entityOrgan.Item = 1 // entityOrgan.Code = "ALL" // entityOrgan.Name = "全部" // entityOrgan.CreateBy = user.Username // entityOrgan.CreateUserId = user.Id // _, err = svcSampleOrgan.InsertEntity(&entityOrgan) // svcPrintScheme := printscheme.GetPrintSchemeService(utils.DBE) // var listPrintScheme []printscheme.PrintScheme // var listPrintScheme_new []printscheme.PrintScheme // listPrintScheme = svcPrintScheme.GetPrintSchemeList("IsSystem=2") // for i := 0; i < len(listPrintScheme); i++ { // listPrintScheme[i].IsSystem = 1 // listPrintScheme[i].CreateBy = user.Username // listPrintScheme[i].CreateUserId = user.Id // listPrintScheme[i].AccCode = user.AccCode // listPrintScheme_new = append(listPrintScheme_new, listPrintScheme[i]) // } // svc.InsertEntity(&listPrintScheme_new) // if err == nil { // //创建表结构 // err := svc.CreateSampleDonorTable(user.AccCode, model.Source) // if err != nil { // fmt.Println(err.Error()) // } // //写入账户信息,赠送短信 // var accountinfo accountinfo.AccountInfo // accountinfo.ProjectSourse = "biobank" // accountinfo.ProjectAccount = user.AccCode // accountinfo.ProjectAccountName = user.Realname // accountinfo.SurplusCount = 50 // accountinfo.ActionType = "sms" // u, p := this.GetuAndp() // strUrl := utils.Cfg.MustValue("server", "apiurl") + "/accountinfos/?u=" + u + "&p=" + p // Apipost(strUrl, "POST", accountinfo) // //添加一条组织根节点 // var entityorg organize.Base_Organize // // 编辑后添加一条数据 // entityorg.Fullname = model.Companyname // entityorg.Parentid = 0 // entityorg.Createuserid = user.Id // entityorg.Createby = user.Realname // entityorg.AccCode = user.AccCode // svcuser.InsertEntity(&entityorg) // //修改用户的组织id // user.Departmentid = utils.ToStr(entityorg.Id) // user.Departmentname = entityorg.Fullname // var usercols []string = []string{"Departmentid", "Departmentname"} // svcuser.UpdateEntityByIdCols(user.Id, &user, usercols) // errinfo.Message = "注册用户成功!" // errinfo.Code = 0 // this.Data["json"] = &errinfo // this.ServeJSON() // } else { // errinfo.Message = "注册失败!" + utils.AlertProcess(err.Error()) // errinfo.Code = -2 // this.Data["json"] = &errinfo // this.ServeJSON() // return // } // } else { // errinfo.Message = "注册失败!" + utils.AlertProcess(err.Error()) // errinfo.Code = -3 // this.Data["json"] = &errinfo // this.ServeJSON() // return // } //} // @Title 获取用户菜单权限 // @Description 获取用户菜单权限 // @Success 200 {object} controllers.Request // @router /getusermodule [get] func (this *UserController) GetUserModule() { //svc := permission.GetPermissionService(utils.DBE) //var model UserModuleModel //model.A1list = svc.GetModuleAllNamesByCode(this.User.Id, "A1") //model.A2list = svc.GetModuleAllNamesByCode(this.User.Id, "A2") //this.Data["json"] = model //this.ServeJSON() } // @Title 获取用户菜单权限 // @Description 获取用户菜单权限 // @Success 200 {object} controllers.Request // @router /getusermoduletree [get] func (this *UserController) GetUserModuleTree() { svc := permission.GetPermissionService(utils.DBE) list := svc.GetModuleAll(this.User.Id, "30000000") this.Data["json"] = list this.ServeJSON() } // @Title CheckToken // @Description create token // @Param body body models.User4CreateToken true "The user info for create token" // @Success 200 {object} models.UserToken // @Failure 403 body is empty // @router /checkUserPwd [post] func (this *UserController) CheckUserPwd() { var errinfo ErrorInfo realName := this.GetString("RealName") if len(realName) == 0 { errinfo.Message = "参数错误" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } svc := auth.GetAuthServic(utils.DBE) var user4CreateToken models.User4CreateToken json.Unmarshal(this.Ctx.Input.RequestBody, &user4CreateToken) svc2 := userRole.GetUserService(utils.DBE) usermodel := svc2.GetUserInfoByRealName(realName) var user userRole.Base_User if svc.VerifyUser3DES(usermodel.Username, user4CreateToken.Password, &user) { if user.Realname != realName { errinfo.Message = "账号不匹配,无权进行此操作!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() return } errinfo.Message = "登录成功" errinfo.Code = 0 this.Data["json"] = &errinfo this.ServeJSON() } else { errinfo.Message = "密码错误,无权进行此操作!" errinfo.Code = -1 this.Data["json"] = &errinfo this.ServeJSON() } }