package SysLoginpersonController import ( "dsBaseWeb/Business/SysLoginPerson/SysLoginpersonService" "dsBaseWeb/Model" "dsBaseWeb/Utils/CommonUtil" "fmt" "github.com/gin-gonic/gin" "net/http" "strings" ) //模块的路由配置 func Routers(r *gin.RouterGroup) { rr := r.Group("/loginperson") //教育局相关接口 rr.GET("/PageAreaManagerInfo", PageAreaManagerInfo) rr.GET("/PageBureauManagerInfo", PageBureauManagerInfo) rr.POST("/ResetManagerPassWord", ResetManagerPassWord) rr.POST("/EnableAccountInfo", EnableAccountInfo) rr.POST("/DisableAccountInfo", DisableAccountInfo) rr.GET("/ExportAreaManagerInfoExcel", ExportAreaManagerInfoExcel) rr.GET("/ExportBureauManagerInfoExcel", ExportBureauManagerInfoExcel) rr.GET("/RemoveCookie", RemoveCookie) rr.POST("/UpdateLoginPassWordInfo", UpdateLoginPassWordInfo) return } // @Summary 移除Cookie // @Description 移除Cookie // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Success 200 {object} Model.Res // @Router /base/loginperson/RemoveCookie [get] // @X-Sort [10] func RemoveCookie(c *gin.Context) { c.SetCookie("person_id", "", -1, "/", "", false, true) c.SetCookie("identity_id", "", -1, "/", "", false, true) c.SetCookie("token", "", -1, "/", "", false, true) c.JSON(http.StatusOK, Model.Res{ Success: true, Message: "操作成功!", }) } // @Summary 获取地区管理员列表(虚拟) // @Description 获取地区管理员列表(虚拟) // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param page query int true "第几页" // @Param limit query int true "一页显示多少条" // @Param areaCode query string true "地区码" // @Success 200 {object} Model.Res // @Router /base/loginperson/PageAreaManagerInfo [get] // @X-EmptyLimit ["page","limit","areaCode"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-IntRangeLimit [{"page":"1,1000"},{"limit":"1,1000"}] // @X-RoleLimit ["1"] // @X-InterfaceName ["PageSysLoginperson"] // @X-TableName ["t_sys_loginperson"] // @X-ExtendSwaggerField [{"column_name":"area_name","sample_data":"长春市","column_comment":"地区名称"}] // @X-RemoveSwaggerField ["last_updated_time"] // @X-Sort [3] func PageAreaManagerInfo(c *gin.Context) { //第几页 page := CommonUtil.ConvertStringToInt32(c.Query("page")) //一页显示多少条 limit := CommonUtil.ConvertStringToInt32(c.Query("limit")) //地区码 areaCode := c.Query("areaCode") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.PageAreaManagerInfo(page, limit, areaCode, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, List: CommonUtil.ConvertJsonStringToMapArray(r.List), Count: r.Count, }) } // @Summary 导出地区管理员到EXCEL(虚拟) // @Description 导出地区管理员到EXCEL(虚拟) // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode query string true "地区码" // @Success 200 {object} Model.Res // @Router /base/loginperson/ExportAreaManagerInfoExcel [get] // @X-EmptyLimit ["areaCode"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-RoleLimit ["1","2","3"] // @X-InterfaceName ["PageSysLoginperson"] // @X-Sort [4] func ExportAreaManagerInfoExcel(c *gin.Context) { //地区码 areaCode := c.Query("areaCode") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.ExportAreaManagerInfoExcel(areaCode, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "区域管理员账号.xlsx")) c.Writer.Header().Set("Content-Type", "application/octet-stream") c.File(r.ExcelPath) } // @Summary 获取单位管理员列表 // @Description 获取单位管理员列表 // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param page query int true "第几页" // @Param limit query int true "一页显示多少条" // @Param areaCode query string true "地区码" // @Param orgType query int true "单位类型 1:教育局 2:学校 7:教辅单位 -1:全部" // @Success 200 {object} Model.Res // @Router /base/loginperson/PageBureauManagerInfo [get] // @X-EmptyLimit ["page","limit","areaCode","orgType"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-IntRangeLimit [{"page":"1,1000"},{"limit":"1,1000"}] // @X-RoleLimit ["1","2","3","4","7"] // @X-InterfaceName ["PageSysLoginperson"] // @X-TableName ["t_sys_loginperson"] // @X-ExtendSwaggerField [{"column_name":"org_name","sample_data":"长春市第一中学","column_comment":"单位名称"}] // @X-Sort [5] func PageBureauManagerInfo(c *gin.Context) { //第几页 page := CommonUtil.ConvertStringToInt32(c.Query("page")) //一页显示多少条 limit := CommonUtil.ConvertStringToInt32(c.Query("limit")) //地区码 areaCode := c.Query("areaCode") //单位类型 1:教育局 2:学校 7:教辅单位 -1:全部 orgType := CommonUtil.ConvertStringToInt32(c.Query("orgType")) //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.PageBureauManagerInfo(page, limit, areaCode, orgType, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!" + err.Error(), }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, List: CommonUtil.ConvertJsonStringToMapArray(r.List), Count: r.Count, }) } // @Summary 导出单位管理员的EXCEL // @Description 导出单位管理员的EXCEL // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param areaCode query string true "地区码" // @Param orgType query int true "单位类型 1:教育局 2:学校 7:教辅单位 -1:全部" // @Success 200 {object} Model.Res // @Router /base/loginperson/ExportBureauManagerInfoExcel [get] // @X-EmptyLimit ["areaCode","orgType"] // @X-LengthLimit [{"areaCode":"6,6"}] // @X-RoleLimit ["1","2","3","4","7"] // @X-Sort [6] func ExportBureauManagerInfoExcel(c *gin.Context) { //地区码 areaCode := c.Query("areaCode") excelPrefix := "" excelSuffix := "" if strings.HasSuffix(areaCode, "00") { excelPrefix = "市级" } else { excelPrefix = "区(县)级" } //单位类型 2:学校 7:教辅单位 -1:全部 orgType := CommonUtil.ConvertStringToInt32(c.Query("orgType")) switch orgType { case 2: excelSuffix = "学校管理员账号.xlsx" break case 7: excelSuffix = "教辅单位管理员账号.xlsx" break default: excelSuffix = "单位管理员账号.xlsx" break } //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.ExportBureauManagerInfoExcel(areaCode, orgType, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!" + err.Error(), }) return } c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", excelPrefix+excelSuffix)) c.Writer.Header().Set("Content-Type", "application/octet-stream") c.File(r.ExcelPath) } // @Summary 重置管理员密码 // @Description 重置管理员密码 // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param ids formData string true "一个或多个ID,多个用逗号分隔" // @Success 200 {object} Model.Res // @Router /base/loginperson/ResetManagerPassWord [post] // @X-EmptyLimit ["ids"] // @X-LengthLimit [{"ids":"36,1800"}] // @X-RoleLimit ["1","2","3","4","7"] // @X-Sort [7] func ResetManagerPassWord(c *gin.Context) { //ID ids := c.PostForm("ids") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.ResetManagerPassWord(ids, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 启用账号信息 // @Description 启用账号信息 // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param personIds formData string true "一个或多个ID,多个用逗号分隔" // @Success 200 {object} Model.Res // @Router /base/loginperson/EnableAccountInfo [post] // @X-EmptyLimit ["personIds"] // @X-LengthLimit [{"personIds":"36,1800"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] // @X-Sort [8] func EnableAccountInfo(c *gin.Context) { personIds := c.PostForm("personIds") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.EnableAccountInfo(personIds, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 禁用账号信息 // @Description 禁用账号信息 // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param personIds formData string true "一个或多个ID,多个用逗号分隔" // @Success 200 {object} Model.Res // @Router /base/loginperson/DisableAccountInfo [post] // @X-EmptyLimit ["personIds"] // @X-LengthLimit [{"personIds":"36,1800"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] // @X-Sort [9] func DisableAccountInfo(c *gin.Context) { personIds := c.PostForm("personIds") //操作人 actionPersonId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.DisableAccountInfo(personIds, actionPersonId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) } // @Summary 修改登录密码 // @Description 修改登录密码 // @Tags 登录信息 // @Accept application/x-www-form-urlencoded // @Produce json // @Param oldPassWord formData string true "原密码" // @Param newPassWord formData string true "新密码" // @Success 200 {object} Model.Res // @Router /base/loginperson/UpdateLoginPassWordInfo [post] // @X-EmptyLimit ["oldPassWord","newPassWord"] // @X-LengthLimit [{"oldPassWord":"6,18"},{"newPassWord":"6,18"}] // @X-RoleLimit ["1","2","3","4","5","6","7"] // @X-Sort [11] func UpdateLoginPassWordInfo(c *gin.Context) { oldPassWord := c.PostForm("oldPassWord") newPassWord := c.PostForm("newPassWord") //cookie personId, err := c.Cookie("person_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的人员编码!", }) return } identityId, err := c.Cookie("identity_id") if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "未获取到Cookie中的身份编码!", }) return } //操作IP actionIpAddress := c.ClientIP() r, err := SysLoginpersonService.UpdateLoginPassWordInfo(personId, CommonUtil.ConvertStringToInt32(identityId), oldPassWord, newPassWord, personId, actionIpAddress) if err != nil { c.JSON(http.StatusOK, Model.Res{ Success: false, Message: "调用RPC服务失败!", }) return } c.JSON(http.StatusOK, Model.Res{ Success: r.Success, Message: r.Message, }) }