12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748 |
- package controllers
- /*
- 核心控制器
- 所有api均通过该控制器进行业务分发
- 请求路由由router.go自动注册,通过在控制器中的方法注释注册为路由
- */
- import (
- "bufio"
- "crypto/md5"
- "encoding/hex"
- "encoding/json"
- "fmt"
- "log"
- "net"
- "os"
- "path/filepath"
- "regexp"
- "runtime"
- "scd_check_tools/conf"
- "scd_check_tools/global"
- "scd_check_tools/logger"
- "scd_check_tools/models/bo"
- "scd_check_tools/models/enum"
- "scd_check_tools/mqtt"
- "scd_check_tools/tools"
- "strconv"
- "strings"
- "time"
- "github.com/astaxie/beego/orm"
- //"github.com/shopspring/decimal"
- "github.com/patrickmn/go-cache"
- )
- //基础功能服务
- type ApiController struct {
- BaseController
- }
- func (this *ApiController) Prepare() {
- fmt.Println(this.Data["RouterPattern"].(string))
- }
- func init() {
- global.GoCahce = cache.New(5*time.Minute, 60*time.Second)
- //GlobalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid","gclifetime":300}`)
- //go GlobalSessions.GC()
- }
- // @Title 语音播放
- // @Summary 语音播放
- // @Description 语音播放
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param filename query string false "文件名称"
- // @Success 200 status 成功
- // @Failure 500 status 失败
- // @router /playWav [POST]
- func (c *ApiController) PlayWav() {
- filename := c.GetString("filename", "")
- buf := make([]byte, 4096)
- n, _ := c.Ctx.Request.Body.Read(buf)
- if filename == "" && n > 0 {
- jsondata := map[string]string{}
- json.Unmarshal(buf[0:n], &jsondata)
- filename = jsondata["filename"]
- }
- if filename != "" {
- dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
- fmt.Println(dir)
- }
- c.Data["json"] = map[string]interface{}{"result": "1", "success": true}
- c.ServeJSON()
- }
- // @Summary 视频播放
- // @router /net/video/play [post]
- func (c *ApiController) PlayNetVideo() {
- filename := c.GetString("url", "")
- title := c.GetString("title")
- clientname := c.GetString("clientname")
- videoinfo := map[string]string{"url": filename, "title": title}
- msg, _ := json.Marshal(videoinfo)
- if clientname == "" {
- ip := c.Ctx.Request.Header.Get("X-Real-IP")
- if net.ParseIP(ip) == nil {
- ips := c.Ctx.Request.Header.Get("X-Forward-For")
- for _, i := range strings.Split(ips, ",") {
- if net.ParseIP(i) != nil {
- ip = i
- break
- }
- }
- if ip == "" {
- ip, _, _ = net.SplitHostPort(c.Ctx.Request.RemoteAddr)
- }
- }
- clientname = ip
- }
- mqtt.PublishMessage("/jujutong/police/videoplayer/"+clientname, string(msg))
- c.Data["json"] = c.WarpOK("")
- c.ServeJSON()
- }
- // @Summary 获取当前程序版本
- // @NotAuth 不需要授权可访问
- // @Description 获取当前程序版本
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /getVersion [get]
- func (c *ApiController) GetVersion() {
- exename := conf.GlobalConfig["appid"]
- if string(runtime.GOOS) == "windows" {
- exename = exename + ".exe"
- }
- f, err1 := os.Open(exename)
- if err1 != nil {
- fmt.Println(tools.NowTime()+":", err1.Error())
- c.Data["json"] = c.WarpError("获取版本号失败")
- c.ServeJSON()
- return
- }
- fi, err2 := f.Stat()
- if err2 != nil {
- fmt.Println(tools.NowTime()+":", err2.Error())
- c.Data["json"] = c.WarpError("获取版本号失败")
- c.ServeJSON()
- return
- }
- data := fi.ModTime().Format("20060102-15")
- c.Data["json"] = c.WarpOK(data)
- c.ServeJSON()
- }
- func (c *ApiController) CheckSeesion() bool {
- userid := c.Ctx.Input.Session("userid")
- r := c.GetSession(userid)
- if r == nil || r == "" {
- return false
- }
- return true
- }
- func (c *ApiController) GetUserToken() string {
- Authorization := c.Ctx.Request.Header.Get("Authorization")
- if Authorization == "" {
- return ""
- }
- return strings.TrimLeft(Authorization, "Bearer ")
- }
- // @Summary 正则表达式匹配验证
- // @NotAuth 不需要授权可访问
- // @Description 正则表达式匹配验证
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Param regstr query string true "正则表达式"
- // @Param str query string true "用于匹配的目标字符串"
- // @Produce json
- // @Success 200 status 成功
- // @Failure 500 status 失败
- // @router /reg/test [get]
- func (c *ApiController) RegTest() {
- r, err := tools.RexGroupTestMatch(c.GetString("regstr"), c.GetString("str"))
- if err != nil {
- c.Data["json"] = c.ResultError(err)
- } else {
- if !r {
- c.Data["json"] = c.ResultError("验证未通过,请检查正则表达式是否正确")
- } else {
- c.Data["json"] = c.ResultOK(r, 1)
- }
- }
- c.ServeJSON()
- }
- // @Summary 客户端心跳
- // @NotAuth 不需要授权可访问
- // @Description 客户端心跳保持,由浏览器或客户端发起请求,以表示其还处于使用中
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 status 成功
- // @Failure 500 status 失败
- // @router /keep-alive [get]
- func (c *ApiController) KeepAlive() {
- loginip := c.GetClientIP()
- fmt.Println("keep-alive IP:" + loginip)
- if loginip != "" {
- curtoken := c.GetUserToken()
- if curtoken == "" {
- global.GoCahce.Delete(loginip)
- } else {
- global.GoCahce.Set(loginip, "", 62*time.Second)
- }
- }
- c.Data["json"] = "ok"
- c.ServeJSON()
- }
- // @Summary 登出
- // @NotAuth 不需要授权可访问
- // @Description 登出系统。系统会自动清理当前用户的相关信息,如缓存、token等
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param sessionid query string true "用户token码"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /logout [post]
- func (c *ApiController) Logout() {
- loginip := c.GetClientIP()
- sessionid := c.GetString("sessionid", "")
- bo.RemoveSession(sessionid)
- //清除缓存的该token的ip地址数据
- global.GoCahce.Delete(sessionid + "-ip")
- if loginip != "" {
- global.GoCahce.Delete(loginip)
- }
- c.Data["json"] = "ok"
- c.ServeJSON()
- }
- // @Summary 登录
- // @Description 登录系统。系统会返回当前用户的相关信息,如基本信息、token等
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param login_account query string true "用户帐号"
- // @Param pwd query string true "用户密码"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /login [post]
- func (c *ApiController) Login() {
- username := c.GetString("login_account", "")
- password := c.GetString("pwd", "")
- loginip := c.GetClientIP()
- userInfo := map[string]interface{}{}
- userInfo["ip"] = loginip
- userInfo["name"] = username
- if loginip != "" {
- if global.AllowAccessIps != "*" {
- //判断当前客户端是否在允许范围内
- ips := strings.Split(global.AllowAccessIps, ",")
- allowLogin := false
- for _, iplimt := range ips {
- if iplimt == loginip {
- allowLogin = true
- break
- }
- tmppos := strings.Index(iplimt, ".*")
- if tmppos > 1 {
- //ip段
- if len(loginip) < tmppos {
- continue
- }
- if loginip[:tmppos] == iplimt[:tmppos] {
- allowLogin = true
- break
- }
- }
- }
- if !allowLogin {
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("帐号%s在未授权终端(IP:%s)尝试访问系统。被拦截!", username, loginip), userInfo)
- c.Ctx.Redirect(430, "/static/430.html")
- return
- }
- }
- //判断当前客户端是否已存在登录用户
- _, ok := global.GoCahce.Get(loginip)
- if ok && global.UserLoginClientLimt == "o2o" {
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("登录失败:帐号%s在多个终端登录", username), userInfo)
- c.Data["json"] = c.WarpError("系统限制:同时只能登录一个用户帐号!")
- c.ServeJSON()
- return
- }
- }
- if password == "" {
- c.Data["json"] = c.WarpError("密码不能为空")
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("登录失败:帐号%s尝试使用空密码登录!", username), userInfo)
- } else if username == "" {
- c.Data["json"] = c.WarpError("帐号不能为空")
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("登录失败:用户尝试使用空帐号登录!"), userInfo)
- } else {
- logininfo2 := map[string]interface{}{}
- if info, ok := bo.LoginInfo.Load(username); ok {
- logininfo2 = info.(map[string]interface{})
- count := logininfo2["count"].(int)
- lasttime := logininfo2["lasttime"].(int64)
- timeout := global.LoginFailLockTime
- if count >= 6 {
- timeout = timeout + 60
- } else if count >= 7 {
- timeout = timeout + 1800
- } else if count >= 8 {
- timeout = timeout + 3600
- }
- if count >= global.LoginFailMaxCount {
- subtime := lasttime + int64(timeout) - time.Now().Unix()
- if subtime > 0 {
- if subtime > 60 {
- min := subtime / 60
- sen := subtime % 60
- c.Data["json"] = c.WarpError(fmt.Sprintf("连续失败超过%d次,帐号已被锁定,请%d分%d秒后重试", global.LoginFailMaxCount, min, sen))
- } else {
- c.Data["json"] = c.WarpError(fmt.Sprintf("连续失败超过%d次,帐号已被锁定,请%d秒后重试", global.LoginFailMaxCount, subtime))
- }
- userInfo := map[string]interface{}{}
- userInfo["name"] = username
- userInfo["ip"] = c.GetClientIP()
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("帐号%s连续失败超过%d次,帐号已被锁定", username, global.LoginFailMaxCount), userInfo)
- c.ServeJSON()
- return
- }
- }
- }
- password = tools.OriginalCode(password)
- user := make(map[string]interface{})
- userInfo, err := bo.UserLogin(username, password)
- if err != nil {
- logger.Logger.Debug(password)
- logger.Logger.Error(err, "登录失败:"+err.Error())
- c.Data["json"] = c.WarpError(err.Error())
- userInfo = map[string]interface{}{}
- userInfo["name"] = username
- userInfo["ip"] = loginip
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, "登录失败:帐号"+username+"登录失败:"+err.Error(), userInfo)
- //bo.SaveSyslog("用户帐号或密码不正确", "系统登录", false, username)
- } else {
- bindip := tools.IsEmpty(userInfo["bind_ips"])
- userInfo["ip"] = loginip
- if bindip != "" {
- //限制登录IP
- allowLogin := false
- ips := strings.Split(bindip, ",")
- for _, ipitem := range ips {
- if ipitem == loginip {
- allowLogin = true
- break
- }
- tmppos := strings.Index(ipitem, ".*")
- if tmppos > 1 {
- //ip段
- if len(loginip) < tmppos {
- continue
- }
- if loginip[:tmppos] == ipitem[:tmppos] {
- allowLogin = true
- break
- }
- }
- }
- if !allowLogin {
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("未授权终端(IP:%s)尝试访问系统被拦截", loginip), userInfo)
- c.Ctx.Redirect(430, "/static/430.html")
- return
- }
- }
- //判断是否有日期限制
- datelimit_start := tools.IsEmpty(userInfo["datelimit_start"])
- if datelimit_start != "" {
- nowDay := time.Now().Format("2006-01-02")
- if nowDay < datelimit_start {
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("帐号%s在当前日期内禁止访问系统", username), userInfo)
- c.Ctx.Redirect(431, "/static/431.html")
- return
- }
- datelimit_end := tools.IsEmpty(userInfo["datelimit_end"])
- if datelimit_end != "" {
- if nowDay > datelimit_end {
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("帐号%s在当前日期内禁止访问系统", username), userInfo)
- c.Ctx.Redirect(431, "/static/431.html")
- return
- }
- }
- }
- user["userid"] = userInfo["userid"].(string)
- //生成sessionid
- h := md5.New()
- h.Write([]byte(tools.NowTime()))
- cipherStr := h.Sum(nil)
- sessionid := hex.EncodeToString(cipherStr) // 输出加密结果
- err = bo.SetSession(sessionid, userInfo["userid"].(string))
- if err != nil {
- logger.Logger.Error(err)
- c.Data["json"] = c.WarpError(err.Error())
- new(bo.SystemLog).Fail(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, fmt.Sprintf("帐号%s登录系统失败:%s", username, err.Error()), userInfo)
- //bo.SaveSyslog(err.Error(), "系统登录", false, username)
- c.ServeJSON()
- return
- }
- //获取用户权限
- useridint, _ := strconv.Atoi(userInfo["userid"].(string))
- funcs, err2 := bo.GetUserFunc(useridint)
- if err2 != nil {
- tools.Log(err2)
- }
- userInfo["funcs"] = funcs
- //获取系统的帐号密码修改模式
- pwd_edit_mod, _ := bo.GetSysParamValue("user_pwd_edit_mod", "admin")
- userInfo["pwdeditmod"] = pwd_edit_mod
- user["userinfo"] = userInfo
- user["sessionid"] = sessionid
- //c.SetSession("sessionid", sessionid)
- c.Data["json"] = c.WarpOK(user)
- thrid_uer_roleid := ""
- thrid_uer_role, has := global.GoCahce.Get("global_code_pl_role_coderole_third_user")
- if has && thrid_uer_role != nil {
- thrid_uer_roleid = tools.IsEmpty(thrid_uer_role.(orm.Params)["id"])
- }
- if tools.IsEmpty(userInfo["role"]) != thrid_uer_roleid {
- new(bo.SystemLog).Success(enum.AuditType_Login, enum.LogType_Logon, enum.OptEventType_System, enum.OptEventLevel_Hight, "帐号"+username+"登录系统成功", userInfo)
- //bo.SaveSyslog("登录系统成功", "系统登录", true, userInfo["name"].(string))
- }
- global.GoCahce.Set(loginip, username, 62*time.Second)
- }
- }
- c.ServeJSON()
- }
- // @Summary 保存用户信息(已废弃)
- // @router /saveUser [post]
- func (c *ApiController) SaveUser() {
- name := c.GetString("name", "")
- reg := regexp.MustCompile(`(#|\?|%|,)`)
- if len(reg.FindAllString(name, -1)) > 0 {
- c.Data["json"] = c.WarpError("名称不能包含特殊字符:#?%,")
- c.ServeJSON()
- return
- }
- var err error
- id, _ := strconv.Atoi(c.GetString("id", "0"))
- memo := c.GetString("memo", "")
- account := c.GetString("account", "")
- pwd := c.GetString("pwd", "")
- obj := bo.T_data_user{Id: id, Name: name, Memo: memo, Account: account, Pwd: pwd}
- obj.Createtime = strings.Trim(tools.NowTime(), " ")
- userid, err2 := strconv.Atoi(c.GetUserToken())
- if err2 != nil {
- c.Ctx.ResponseWriter.WriteHeader(401) //token获取失败或无效时,直接返回401
- return
- }
- obj.Createuser = userid
- insertId, err := bo.SaveUser(obj, c.GetCurrentUserInfo())
- //tmp, _ := json.Marshal(obj)
- //fmt.Println(string(tmp))
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(insertId)
- }
- c.ServeJSON()
- }
- // @Summary 查询指定用户的详细信息
- // @Description 查询用户信息
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "用户ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /getUser [get]
- func (c *ApiController) GetUser() {
- var id = 0
- id, _ = strconv.Atoi(c.GetString("id", "0"))
- param := tools.ParseFormParam(c.Ctx.Request.Form)
- obj := bo.T_data_user{Id: id}
- datalist, err := bo.QueryUserList(param, obj, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpPageOk(datalist["meta"].(map[string]interface{}), datalist["data"])
- }
- c.ServeJSON()
- }
- // @Summary 创建用户
- // @Description 查询用户信息
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param userid query int true "用户ID"
- // @Param role query int true "角色ID"
- // @Param username query string true "姓名"
- // @Param account query string true "登录帐号"
- // @Param password query string true "登录密码"
- // @Param mobilephone query string false "手机号"
- // @Param pwd_expire query string false "密码过期日期"
- // @Param bind_ips query string false "允许登录的IP"
- // @Param datelimit_start query string false "帐号有效期开始日期"
- // @Param datelimit_end query string false "帐号有效期结束日期"
- // @Param memo query string false "其他说明"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /createuser [post]
- func (c *ApiController) CreateUser() {
- parameter := map[string]interface{}{}
- parameter["userid"] = c.GetString("userid", "0")
- parameter["role"] = c.GetString("role", "")
- username := c.GetString("username", "")
- parameter["username"] = username
- reg := regexp.MustCompile(`(#|\?|%|,',\*,&)`)
- if len(reg.FindAllString(username, -1)) > 0 {
- c.Data["json"] = c.WarpError("名称不能包含特殊字符:#?%,'*&")
- c.ServeJSON()
- return
- }
- parameter["account"] = c.GetString("account", "")
- parameter["password"] = c.GetString("password", "")
- parameter["memo"] = c.GetString("memo", "")
- parameter["mobilephone"] = c.GetString("mobilephone", "")
- parameter["pwd_expire"] = c.GetString("pwd_expire") //密码过期日期
- parameter["bind_ips"] = c.GetString("bind_ips", "") //允许登录的IP
- parameter["datelimit_start"] = c.GetString("datelimit_start", "") //帐号有效期开始日期
- parameter["datelimit_end"] = c.GetString("datelimit_end", "") //帐号有效期结束日期
- status, err := bo.CreateUser(parameter, c.GetCurrentUserInfo())
- tools.CheckErr(err)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(status)
- }
- c.ServeJSON()
- }
- //修改密码。只能修改自己的密码
- // @Summary 修改自己密码
- // @Description 修改密码。只能修改自己的密码
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param newpwd query int true "原密码"
- // @Param oldpwd query int true "新密码"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /resetUserPwd [post]
- func (c *ApiController) ResetUserPwd() {
- newPwd := c.GetString("newpwd")
- oldpwd := c.GetString("oldpwd")
- if oldpwd == "" {
- c.Data["json"] = c.WarpError("原密码不能为空")
- c.ServeJSON()
- return
- }
- if newPwd == "" {
- c.Data["json"] = c.WarpError("密码不能为空")
- } else {
- editmod, _ := bo.GetSysParamValue("user_pwd_edit_mod", "admin")
- if editmod == "" || editmod == "admin" {
- c.Data["json"] = c.WarpError("当前不允许修改密码,请联系管理员!")
- c.ServeJSON()
- return
- }
- if len(newPwd) > 32 {
- newPwd = tools.OriginalCode(newPwd)
- }
- check, msg := bo.PwdRuleCheck(newPwd)
- if !check {
- c.Data["json"] = c.WarpError(msg)
- c.ServeJSON()
- return
- }
- //原密码
- if len(oldpwd) > 32 {
- oldpwd = tools.OriginalCode(oldpwd)
- }
- logger.Logger.Debug(fmt.Sprintf("用户修改密码:新密码:%s \n 原密码:%s", newPwd, oldpwd))
- has := md5.Sum([]byte(oldpwd))
- oldpwd = fmt.Sprintf("%x", has)
- userinfo := c.GetCurrentUserInfo()
- userid := tools.IsEmpty(userinfo["userid"])
- obj := bo.T_data_user{Id: 0}
- obj.Id, _ = strconv.Atoi(userid)
- userOneInfo := bo.OneUser(obj)
- if userOneInfo.Pwd != oldpwd {
- c.Data["json"] = c.WarpError("原密码不正确!")
- c.ServeJSON()
- return
- }
- obj.Pwd = newPwd
- _, err := bo.SavePwd(obj, userinfo)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK("")
- }
- }
- c.ServeJSON()
- }
- // @Summary 指定用户的功能列表
- // @Description 指定用户的功能列表。非RBAC模式下有效
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "用户ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /getUserPrivList [get]
- func (c *ApiController) GetUserPrivListUser() {
- var id = 0
- id, _ = strconv.Atoi(c.GetString("id", "0"))
- obj := bo.T_data_user_func{Userid: id}
- datalist, err := bo.QueryUserPrivList(obj, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(datalist["data"])
- }
- c.ServeJSON()
- }
- // @Summary 保存指定用户的功能列表
- // @Description 保存指定用户的功能列表。非RBAC模式下有效
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "用户ID"
- // @Param privids query string true "功能ID列表,使用逗号分隔"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /saveUserPrivList [post]
- func (c *ApiController) SaveUserPrivList() {
- uid, _ := strconv.Atoi(c.GetString("id", "0"))
- privids := c.GetString("privids")
- datalist, err := bo.SaveUserPrivList(uid, privids, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(datalist)
- }
- c.ServeJSON()
- }
- // @Summary 搜索查询用户
- // @Description 查询用户
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param name query int false "姓名"
- // @Param pageindex query int false "分页页码,默认为1"
- // @Param pagesize query int false "每页最大记录数,默认为20"
- // @Param area_id query int false "区域ID"
- // @Param role_id query int false "角色ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /searchUserInfo [get]
- func (c *ApiController) SearchUserInfo() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- name := c.GetString("name")
- area_id := c.GetString("area_id")
- role_id := c.GetString("role_id")
- tableData, number, err := bo.SearchUserInfo(area_id, name, role_id, pageIndex, pageSize, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, number)
- }
- c.ServeJSON()
- }
- // 获取指定用户所管理的区域列表
- // @Summary 获取指定用户所管理的区域列表
- // @Description 获取指定用户所管理的区域列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param userid query int true "用户ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getUserAreaList [get]
- func (c *ApiController) GetUserAreaList() {
- uid, _ := c.GetInt("userid", 0)
- if uid == 0 {
- c.Data["json"] = c.ResultError("无效的用户ID")
- c.ServeJSON()
- return
- }
- obj := new(bo.UserAreaRelationObject)
- obj.Model.Userid = uid
- tableData, err := obj.List()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, len(tableData))
- }
- c.ServeJSON()
- }
- //保存用户所管理的区域列表
- // @Summary 保存指定用户所管理的区域列表
- // @Description 保存指定用户所管理的区域列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param userid query int true "用户ID"
- // @Param areaid query string true "区域列表。JSON串,格式如:[{"id":"区域ID","allchecked":"all|空"}]"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /saveUserAreaList [post]
- func (c *ApiController) SaveUserAreaList() {
- uid, _ := c.GetInt("userid", 0)
- if uid == 0 {
- c.Data["json"] = c.ResultError("无效的用户ID")
- c.ServeJSON()
- return
- }
- areaids := c.GetString("areaid")
- obj := new(bo.UserAreaRelationObject)
- obj.SetUserInfo(c.GetCurrentUserInfo())
- obj.Model.Userid = uid
- err := obj.Delete() //清除原来的数据
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- c.ServeJSON()
- return
- }
- if areaids != "" {
- ids := []map[string]string{}
- json.Unmarshal([]byte(areaids), &ids)
- for _, id := range ids {
- obj.Model.Areaid, _ = strconv.Atoi(id["id"])
- //如果是该节点是全选的,需要将节点下的所有节点添加到关系表
- isall := id["allchecked"]
- if isall == "all" {
- err = obj.AppendNodeAll(uid, obj.Model.Areaid)
- } else {
- //添加单个节点
- err = obj.Save()
- }
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- c.ServeJSON()
- return
- }
- }
- }
- c.Data["json"] = c.ResultOK("", 0)
- c.ServeJSON()
- }
- // @Summary 获取指定角色的功能点列表
- // @Description 获取指定角色的功能点列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param roleid query int true "角色ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /getRoleFuncList [get]
- func (c *ApiController) GetRoleFuncList() {
- roleid := c.GetString("roleid", "")
- if roleid == "" {
- c.Data["json"] = c.WarpError("角色ID不能为空")
- c.ServeJSON()
- return
- }
- roleidint, _ := strconv.Atoi(roleid)
- datalist, err := bo.GetRoleFunc(roleidint)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(datalist)
- }
- c.ServeJSON()
- }
- // @Summary 保存指定角色的功能点列表
- // @Description 保存指定角色的功能点列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param roleid query int true "角色ID"
- // @Param areaid query string true "区域列表。JSON串,格式如:[{"id":"区域ID","allchecked":"all|空"}]"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /saveRoleFunc [post]
- func (c *ApiController) SaveRoleFunc() {
- roleid := c.GetString("roleid", "")
- if roleid == "" {
- c.Data["json"] = c.WarpError("角色ID不能为空")
- c.ServeJSON()
- return
- }
- funcids := c.GetString("funcids", "")
- tmpAry := strings.Split(funcids, ",")
- roleidint, _ := strconv.Atoi(roleid)
- err := bo.SaveRoleFunc(roleidint, tmpAry, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK("")
- }
- c.ServeJSON()
- }
- // @Summary 初始化系统数据
- // @router /sys/init [post]
- func (c *ApiController) SysInit() {
- orgname := c.GetString("orgname")
- sn := c.GetString("sn")
- account := c.GetString("account")
- pwd := c.GetString("pwd")
- if orgname == "" || sn == "" {
- c.Data["json"] = c.WarpError("参数不正确")
- c.ServeJSON()
- return
- }
- pm := bo.Global_sys_param{Param_name: "orgname", Param_value: orgname, Param_memo: "单位"}
- _, err := bo.SaveSysParam(pm)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- c.ServeJSON()
- return
- }
- if account != "" && pwd != "" {
- //清除原来的非超级管理员帐号
- bo.InitUser()
- bo.ClearAllSyslog()
- parameter := map[string]interface{}{}
- parameter["userid"] = ""
- parameter["role"] = c.GetString("role", "0")
- parameter["username"] = c.GetString("username", "")
- parameter["account"] = account
- parameter["password"] = pwd
- parameter["memo"] = c.GetString("memo", "")
- _, err = bo.CreateUser(parameter)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- c.ServeJSON()
- return
- }
- }
- c.Data["json"] = c.WarpOK("")
- c.ServeJSON()
- }
- // @Summary 查询操作日志列表
- // @Description 查询操作日志列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int true "当前查询页码。默认为1"
- // @Param pagesize query int true "每页显示数据条数。默认20"
- // @Param enddate query string false "查询条件:结束日期"
- // @Param startdate query string false "查询条件:开始日期"
- // @Param description query string false "查询条件:日志内容。模糊匹配"
- // @Param staff query string false "查询条件:操作人姓名。模糊匹配"
- // @Param ip query string false "查询条件:操作IP地址。模糊匹配"
- // @Param success query int false "查询条件:操作结果。关联系统字典log_optresult。0: 失败 1:成功"
- // @Param opttype query int false "查询条件:操作类型。关联系统字典log_opttype。"
- // @Param audittype query int false "查询条件:审计类型。关联系统字典log_audittype。"
- // @Param eventtype query int false "查询条件:事件类型。关联系统字典log_eventtype。"
- // @Param eventlevel query int false "查询条件:事件等级。关联系统字典log_eventlevel。"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getSyslogList [get]
- func (c *ApiController) GetSysLog() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- con["description"] = c.GetString("description", "")
- con["staff"] = c.GetString("staff", "")
- con["ip"] = c.GetString("ip", "")
- con["success"] = c.GetString("success", "")
- con["logtype"] = c.GetString("opttype", "")
- con["audittype"] = c.GetString("audittype", "")
- con["eventtype"] = c.GetString("eventtype", "")
- con["eventlevel"] = c.GetString("eventlevel", "")
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemLog)
- syslog.SetUserInfo(userinfo)
- tableData, number, err := syslog.SearchLogList(con, pageIndex, pageSize)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, number)
- }
- c.ServeJSON()
- }
- // @Summary 操作日志分类(图形)统计
- // @Description 操作日志分类(图形)统计
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param enddate query string false "统计条件:结束日期"
- // @Param startdate query string false "统计条件:开始日期"
- // @Param description query string false "统计条件:日志内容。模糊匹配"
- // @Param staff query string false "统计条件:操作人姓名。模糊匹配"
- // @Param ip query string false "统计条件:操作IP地址。模糊匹配"
- // @Param success query int false "统计条件:操作结果。关联系统字典log_optresult。0: 失败 1:成功"
- // @Param opttype query int false "统计条件:操作类型。关联系统字典log_opttype。"
- // @Param audittype query int false "统计条件:审计类型。关联系统字典log_audittype。"
- // @Param eventtype query int false "统计条件:事件类型。关联系统字典log_eventtype。"
- // @Param eventlevel query int false "统计条件:事件等级。关联系统字典log_eventlevel。"
- // @Param cycletype query int false "统计周期。值列表为:year,month,day,hour,week,默认为hour。"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/chartstat [get]
- func (c *ApiController) GetECharsSysLogStat() {
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- con["description"] = c.GetString("description", "")
- con["staff"] = c.GetString("staff", "")
- con["ip"] = c.GetString("ip", "")
- con["success"] = c.GetString("success", "")
- con["logtype"] = c.GetString("opttype", "")
- con["audittype"] = c.GetString("audittype", "")
- con["eventtype"] = c.GetString("eventtype", "")
- con["eventlevel"] = c.GetString("eventlevel", "")
- con["cycletype"] = c.GetString("cycletype", "")
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemLog)
- syslog.SetUserInfo(userinfo)
- tableData, err := syslog.EchartStat(con)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @Summary 操作日志分类(数据列表)统计
- // @Description 操作日志分类(数据列表)统计
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param enddate query int false "统计条件:结束日期"
- // @Param startdate query int false "统计条件:开始日期"
- // @Param description query int false "统计条件:日志内容。模糊匹配"
- // @Param staff query string false "统计条件:操作人姓名。模糊匹配"
- // @Param ip query string false "统计条件:操作IP地址。模糊匹配"
- // @Param success query int false "统计条件:操作结果。关联系统字典log_optresult。0: 失败 1:成功"
- // @Param opttype query int false "统计条件:操作类型。关联系统字典log_opttype。"
- // @Param audittype query int false "统计条件:审计类型。关联系统字典log_audittype。"
- // @Param eventtype query int false "统计条件:事件类型。关联系统字典log_eventtype。"
- // @Param eventlevel query int false "统计条件:事件等级。关联系统字典log_eventlevel。"
- // @Param stattype query int false "统计类型。值为:logtype或者空。"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/datastat [get]
- func (c *ApiController) GetDataSysLogStat() {
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- con["description"] = c.GetString("description", "")
- con["staff"] = c.GetString("staff", "")
- con["ip"] = c.GetString("ip", "")
- con["success"] = c.GetString("success", "")
- con["logtype"] = c.GetString("opttype", "")
- con["audittype"] = c.GetString("audittype", "")
- con["eventtype"] = c.GetString("eventtype", "")
- con["eventlevel"] = c.GetString("eventlevel", "")
- con["stattype"] = c.GetString("stattype", "") //统计字段
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemLog)
- syslog.SetUserInfo(userinfo)
- tableData, err := syslog.DataStat(con)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @Summary 操作日志备份
- // @Description 操作日志备份
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param enddate query string false "备份结束日期"
- // @Param startdate query string false "备份开始日期"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/backup [post]
- func (c *ApiController) BackupSysLog() {
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemLog)
- syslog.SetUserInfo(userinfo)
- err := syslog.Backup(con)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 获取操作日志备份列表
- // @Description 获取操作日志备份列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int false "当前查询的分页页码,默认为1"
- // @Param pagesize query int false "每页显示的数据条数,默认为20"
- // @Param enddate query string false "备份结束日期"
- // @Param startdate query string false "备份开始日期"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/backup/list [get]
- func (c *ApiController) BackupSysLogList() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemLog)
- syslog.SetUserInfo(userinfo)
- lst, total, err := syslog.BackupList(con, pageIndex, pageSize)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(lst, total)
- }
- c.ServeJSON()
- }
- // @Summary 操作日志备份删除
- // @Description 操作日志备份删除
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "备份记录ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/backup/del [post]
- func (c *ApiController) DelBackupLog() {
- userinfo := c.GetCurrentUserInfo()
- sysdb := new(bo.SystemLog)
- sysdb.SetUserInfo(userinfo)
- id, _ := c.GetInt("id")
- err := sysdb.Delete(id)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 获取数据备份列表
- // @Description 获取数据备份列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int false "当前查询的分页页码,默认为1"
- // @Param pagesize query int false "每页显示的数据条数,默认为20"
- // @Param enddate query string false "备份结束日期"
- // @Param startdate query string false "备份开始日期"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /db/backup/list [get]
- func (c *ApiController) BackupDBList() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- userinfo := c.GetCurrentUserInfo()
- sysdb := new(bo.GlobalBackupMgr)
- sysdb.SetUserInfo(userinfo)
- lst, total, err := sysdb.List(con, pageIndex, pageSize)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(lst, total)
- }
- c.ServeJSON()
- }
- // @Summary 创建新数据备份
- // @Description 创建新数据备份
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /db/backup/new [post]
- func (c *ApiController) NewBackupDB() {
- userinfo := c.GetCurrentUserInfo()
- sysdb := new(bo.GlobalBackupMgr)
- sysdb.SetUserInfo(userinfo)
- err := sysdb.Save()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 删除指定的数据备份
- // @Description 删除指定的数据备份
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int false "备份记录ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /db/backup/del [post]
- func (c *ApiController) DelBackupDB() {
- userinfo := c.GetCurrentUserInfo()
- sysdb := new(bo.GlobalBackupMgr)
- sysdb.SetUserInfo(userinfo)
- sysdb.Model.Id, _ = c.GetInt("id")
- err := sysdb.Delete()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 数据还原
- // @Description 还原指定的数据备份
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "备份记录ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /db/backup/recover [post]
- func (c *ApiController) RecorverBackupDB() {
- cid, _ := c.GetInt("id")
- userinfo := c.GetCurrentUserInfo()
- sysdb := new(bo.GlobalBackupMgr)
- sysdb.SetUserInfo(userinfo)
- err := sysdb.Recover(cid)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 获取当前的服务器运行日志
- // @Description 获取当前的服务器运行日志。每次获取10Kb的日志内容,第一次获取时默认为0,继续获取时需要将上次的最大位置传给offset参数。
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param offset query int true "获取的日志起始字节位置。"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /log/runtime_log [get]
- func (c *ApiController) GetSystemRuntimeLog() {
- logfilename := "./" + time.Now().Format("20060102") + ".log"
- fH, ferr := os.Stat(logfilename)
- if ferr != nil {
- c.Data["json"] = c.ResultError(ferr.Error())
- c.ServeJSON()
- return
- }
- logsize := fH.Size()
- if logsize == 0 {
- c.Data["json"] = c.ResultOK("", 0)
- c.ServeJSON()
- return
- }
- offsetkb, _ := c.GetInt64("offset", 0)
- loghander, err2 := os.Open(logfilename)
- if err2 != nil {
- logger.Logger.Error(err2)
- c.Data["json"] = c.ResultError(ferr.Error())
- c.ServeJSON()
- return
- }
- defer loghander.Close()
- logreader := bufio.NewReader(loghander)
- if offsetkb == 0 {
- //初始加载,只获取最新的日志(10Kb)
- if logsize > int64(1024*10) {
- offsetkb = logsize - int64(1024*10)
- }
- }
- _, ferr = loghander.Seek(offsetkb, 0)
- if ferr != nil {
- logger.Logger.Error(ferr)
- c.Data["json"] = c.ResultError(ferr.Error())
- c.ServeJSON()
- return
- }
- var buf []byte
- if (logsize - offsetkb) > int64(1024*10) {
- buf = make([]byte, 1024*10)
- } else {
- buf = make([]byte, logsize-offsetkb)
- }
- n, ferr := logreader.Read(buf)
- if ferr != nil {
- logger.Logger.Error(ferr)
- c.Data["json"] = c.ResultError(ferr.Error())
- c.ServeJSON()
- return
- }
- c.Data["json"] = c.ResultOK(string(buf), offsetkb+int64(n))
- c.ServeJSON()
- }
- // @Summary 获取系统告警列表
- // @Description 获取系统告警列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int false "当前查询的分页页码,默认为1"
- // @Param pagesize query int false "每页显示的数据条数,默认为20"
- // @Param enddate query string false "查询条件:结束日期"
- // @Param startdate query string false "查询条件:开始日期"
- // @Param eventtype query int false "查询条件:事件类型。关联系统字典代码log_eventtype。"
- // @Param alarmtype query string false "查询条件:告警类型。值为disk|cpu|mem之一。"
- // @Param description query string false "查询条件:告警内容。模糊查询"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /sys/alarm/list [get]
- func (c *ApiController) GetSysAlarmList() {
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 20)
- con := map[string]string{}
- con["enddate"] = c.GetString("enddate", "")
- con["startdate"] = c.GetString("startdate", "")
- con["eventtype"] = c.GetString("eventtype", "")
- con["alarmtype"] = c.GetString("alarmtype", "")
- con["description"] = c.GetString("description")
- userinfo := c.GetCurrentUserInfo()
- syslog := new(bo.SystemAlarm)
- syslog.SetUserInfo(userinfo)
- lst, total, err := syslog.SearchList(con, pageIndex, pageSize)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(lst, total)
- }
- c.ServeJSON()
- }
- // @Summary 获取全部或者指定的系统参数列表
- // @NotAuth 不需要授权可访问
- // @Description 获取全部或者指定的系统参数列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param param_name query string false "参数名"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getSysParamList [get]
- func (c *ApiController) GetSystemParam() {
- param_name := c.GetString("param_name")
- obj := bo.Global_sys_param{Param_name: param_name}
- datalist, err := bo.GetSysParamList(obj, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(datalist, len(datalist))
- }
- c.ServeJSON()
- }
- // 保存系统参数 godoc
- // @Summary 保存系统参数
- // @Description 保存系统参数
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param param_name query string false "参数缟编码"
- // @Param param_value query string false "参数值"
- // @Param param_memo query string false "参数描述"
- // @Success 200 {object} ResultOK 成功
- // @Success 200 {object} ResultError 错误
- // @Failure 500 status 失败
- // @router /saveSysParam [post]
- func (c *ApiController) SaveSystemParam() {
- param_name := c.GetString("param_name")
- param_value := c.GetString("param_value")
- param_memo := c.GetString("param_memo")
- obj := bo.Global_sys_param{Param_name: param_name, Param_memo: param_memo, Param_value: param_value}
- _, err := bo.SaveSysParam(obj, c.GetCurrentUserInfo())
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- c.ServeJSON()
- }
- // @Summary 获取指定系统字典的下级字典码定义
- // @Description 获取指定系统字典的下级字典码定义
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param code query string false "未指定code时,将返回根字典下的子字典定义列表。"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getGlobalChildrenCode [get]
- func (c *ApiController) GetGlobalChildrenCode() {
- param := tools.ParseFormParam(c.Ctx.Request.Form)
- param["code"] = c.GetString("code", "")
- obj := new(bo.Global)
- tableData, err := obj.GetChildrenGlobalCode(tools.IsEmpty(param["code"]))
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @Summary 根据id获取字典定义
- // @Description 根据id获取字典定义
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query string false "系统字典码ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getGlobalCode/byid [get]
- func (c *ApiController) GetGlobalCodeByID() {
- param := tools.ParseFormParam(c.Ctx.Request.Form)
- param["id"] = c.GetString("id", "")
- param["pageindex"] = c.GetString("pageindex", "1")
- param["pagesize"] = c.GetString("pagesize", "1")
- obj := new(bo.Global)
- tableData, number, err := obj.QueryGlobalCodeList(param)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, number)
- }
- c.ServeJSON()
- }
- // @Summary 查询系统字典列表
- // @Description 查询系统字典列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int false "当前查询的页码。默认为1"
- // @Param pagesize query int false "每页显示的数据记录数,默认为20"
- // @Param pcode query string false "查询条件:指定的父级字典码"
- // @Param code query string false "查询条件:指定的字典码"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /getGlobalCode [get]
- func (c *ApiController) GetGlobalCode() {
- param := tools.ParseFormParam(c.Ctx.Request.Form)
- param["pcode"] = c.GetString("pcode", "")
- param["code"] = c.GetString("code", "")
- param["pageindex"] = c.GetString("pageindex", "1")
- param["pagesize"] = c.GetString("pagesize", "20")
- obj := new(bo.Global)
- tableData, number, err := obj.QueryGlobalCodeList(param)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, number)
- }
- c.ServeJSON()
- }
- // @Summary 获取区域列表
- // @Description 获取区域列表。以tree结构形式返回。
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /area/tree [get]
- func (c *ApiController) GetAdminAreaTree() {
- obj := bo.BasicArea{}
- obj.SetUserInfo(c.GetCurrentUserInfo())
- gettype := c.GetString("type")
- if gettype == "1" {
- tableData, err := new(bo.Global).GetCategoryTree()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- } else {
- tableData, err := obj.GetAreaTree()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- }
- c.ServeJSON()
- }
- // @Summary 获取指定获取的下级区域列表
- // @Description 获取指定获取的下级区域列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query string true "查询条件:区域ID"
- // @Param all query int false "查询条件:是否获取全部子区域。1表示是,反之表示否。默认为0"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /area/children/list [get]
- func (c *ApiController) GetAdminAreaChildren() {
- obj := new(bo.BasicArea)
- obj.SetUserInfo(c.GetCurrentUserInfo())
- isall := c.GetString("all")
- ext_datatype := c.GetString("ext_datatype") //扩展。需要追加节点的数据类型。支持电梯equ、摄像头camera、电子围栏ele、停车场park、门禁access_control等
- var err error
- var tableData []orm.Params
- areaIdStr := c.GetString("id")
- if isall == "1" {
- tableData, err = obj.GetAreaAllChildrens(areaIdStr)
- } else {
- tableData, err = obj.GetAreaChildrens(areaIdStr)
- }
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- areaId, _ := c.GetInt("id", -1)
- //是否需要追加业务数据节点
- if areaId > -1 && ext_datatype != "" {
- statCountLst := []orm.Params{}
- //根据统计的下级区域子元素数量,设置区域节点的相关属性
- if err != nil {
- log.Println(err)
- } else if len(statCountLst) > 0 {
- for k1, row := range tableData {
- //判断是否有子节点(isParent:true),已有子节点时不需要再次处理
- if tools.IsEmpty(row["isParent"]) != "false" {
- continue
- }
- tmpareaid := tools.IsEmpty(row["id"]) + tools.IsEmpty(row["ID"])
- for _, row2 := range statCountLst {
- area_id := tools.IsEmpty(row2["area_id"]) + tools.IsEmpty(row2["AREA_ID"])
- if tmpareaid == area_id {
- tableData[k1]["isParent"] = row2["isParent"]
- tableData[k1]["count"] = row2["cnt"]
- }
- }
- }
- }
- }
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @router /code/tree [get]
- func (c *ApiController) GetCategoryTree() {
- obj := new(bo.Global)
- tableData, err := obj.GetCategoryTree()
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @Summary 获取角色的已分配资源ID列表
- // @Description 获取角色的已分配资源ID列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param roleid query string true "角色ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /get_menu_tree [get]
- func (c *ApiController) GetMenuTree() {
- Roleid, _ := c.GetInt("roleid", -1)
- obj := new(bo.Global)
- tableData, err := obj.GetMenuTree(Roleid)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- c.ServeJSON()
- }
- // @Summary 保存系统字典
- // @Description 保存系统字典
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param name query string true "系统字典名称"
- // @Param parentcode query string true "上级系统字典编码"
- // @Param code query string true "系统字典编码"
- // @Param id query string false "系统字典ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /saveGlobalcode [post]
- func (c *ApiController) SaveGlobalCode() {
- name := c.GetString("name")
- parentcode := c.GetString("parentcode")
- code := c.GetString("code")
- id, _ := strconv.Atoi(c.GetString("id", "0"))
- obj := bo.Global_const_code{Id: id, Code: code, Parentcode: parentcode, Name: name}
- user := c.GetCurrentUserInfo()
- _, err := bo.SaveGlobalCode(obj, user)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK("")
- }
- c.ServeJSON()
- }
- // @Summary 删除指定系统字典定义
- // @Description 根据字典编码或ID删除指定系统字典定义
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param code query string false "系统字典编码"
- // @Param id query string false "系统字典ID"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /deleteGlobalcode [post]
- func (c *ApiController) DelGlobalCode() {
- code := c.GetString("code")
- id, _ := strconv.Atoi(c.GetString("id", "0"))
- obj := bo.Global_const_code{Code: code, Id: id}
- user := c.GetCurrentUserInfo()
- datalist, err := bo.DeleteGlobalCode(obj, user)
- if err != nil {
- c.Data["json"] = c.WarpError(err.Error())
- } else {
- c.Data["json"] = c.WarpOK(datalist)
- }
- c.ServeJSON()
- }
- // @Summary 删除指定模型的某条数据记录
- // @Description 删除指定模型的某条数据记录
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param tablename query string true "数据模型名称"
- // @Param id query string true "数据记录ID"
- // @Param primaryfield query string false "数据记录ID列名。默认为id"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /record/delete [post]
- func (c *ApiController) DeleteRecord() {
- primaryField := c.GetString("primaryfield", "id")
- Id := c.GetString("id", "")
- tableName := c.GetString("tablename", "")
- if Id == "" {
- c.Data["json"] = c.ResultError("id参数不允许为空!")
- } else if tableName == "" {
- c.Data["json"] = c.ResultError("tablename参数不允许为空!")
- } else {
- err := tools.DeleteTableReorce(tableName, primaryField, Id)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", 0)
- }
- }
- c.ServeJSON()
- }
- // @Summary 获取指定模型的某条数据记录
- // @Description 获取指定模型的某条数据记录
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param tablename query string true "数据模型名称"
- // @Param id query string true "数据记录ID"
- // @Param primaryfield query string false "数据记录ID列名。默认为id"
- // @Success 200 {object} WarpOK 成功
- // @Failure 500 {object} WarpError 失败
- // @router /record/get [get]
- func (c *ApiController) GetSingleRecord() {
- primaryField := c.GetString("primaryfield", "id")
- Id := c.GetString("id", "")
- tableName := c.GetString("tablename", "")
- if Id == "" {
- c.Data["json"] = c.ResultError("id参数不允许为空!")
- } else if tableName == "" {
- c.Data["json"] = c.ResultError("tablename参数不允许为空!")
- } else {
- tableData, err := tools.GetSingleRecord(tableName, primaryField, Id)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, 0)
- }
- }
- c.ServeJSON()
- }
- // @Summary 根据查询条件搜索区域(变电站)列表
- // @Description 根据查询条件搜索区域(变电站)列表
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pageindex query int false "当前查询的分页页码,默认为1"
- // @Param pagesize query int false "每页显示的数据条数,默认为20"
- // @Param name query string false "查询条件:区域名称。模糊匹配"
- // @Param id query int false "查询条件:区域ID"
- // @Param pid query int false "查询条件:父级区域ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /basic_area/list [get]
- func (c *ApiController) BasicAreaList() {
- enableOrgCode, _ := bo.GetSysParamValue("xrootcode", "")
- areaObject := new(bo.BasicArea)
- areaObject.SetUserInfo(c.GetCurrentUserInfo())
- pageIndex, _ := c.GetInt("pageindex", 1)
- pageSize, _ := c.GetInt("pagesize", 1000)
- areaObject.Model.Pid, _ = c.GetInt("pid", -1)
- if areaObject.Model.Pid > -1 {
- enableOrgCode = ""
- }
- areaObject.Model.AreaName = c.GetString("name", "")
- areaObject.Model.AreaKind = c.GetString("area_kind", "")
- areaObject.Model.AreaType = c.GetString("area_type", enableOrgCode)
- areaObject.Model.AreaLevel, _ = c.GetInt("area_level", 0)
- areaObject.Model.Id, _ = c.GetInt("id", 0)
- tableData, number, err := areaObject.SearchArea(pageIndex, pageSize)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(tableData, number)
- }
- c.ServeJSON()
- }
- // @Summary 查询指定区域的下级区域数量
- // @Description 查询指定区域的下级区域数量
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param pid query int true "查询条件:父级区域ID"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /basic_area/getchildrencount [get]
- func (c *ApiController) BasicAreaChildrenCount() {
- areaObject := new(bo.BasicArea)
- pid, _ := c.GetInt("pid", -1)
- if pid == -1 {
- c.Data["json"] = c.ResultError("pid不能为空")
- c.ServeJSON()
- return
- }
- number, err := areaObject.GetAreaTotal(pid)
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK("", number)
- }
- c.ServeJSON()
- }
- // @Summary 保存区域信息
- // @Description 保存区域信息
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "区域ID。编辑时必填。"
- // @Param pid query int true "父级区域ID"
- // @Param area_type query int true "区域类型"
- // @Param area_name query string true "区域名称"
- // @Param area_addr query string false "区域地址"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /basic_area/save [post]
- func (c *ApiController) BasicAreaSave() {
- object := new(bo.BasicArea)
- object.Model.Id, _ = c.GetInt("id", 0)
- object.Model.Pid, _ = c.GetInt("pid", 0)
- object.Model.AreaType = c.GetString("area_type", "")
- object.Model.AreaName = c.GetString("area_name", "")
- object.Model.AreaCode = ""
- object.Model.AreaKind = c.GetString("area_kind", "")
- object.Model.Jd, _ = strconv.ParseFloat(c.GetString("jd", "0"), 32)
- object.Model.Wd, _ = strconv.ParseFloat(c.GetString("wd", "0"), 32)
- object.Model.LiveNum, _ = c.GetInt("live_number", 0)
- object.Model.AreaLevel, _ = c.GetInt("area_level", 0)
- object.Model.IsLeaf, _ = c.GetInt("leaf", 0)
- object.Model.AreaSort, _ = c.GetInt("area_sort", 0)
- object.Model.AreaAddr = c.GetString("area_addr", "")
- object.Model.Apmac = c.GetString("apmac", "")
- RoomColor := c.GetString("room_color", "")
- var unit = c.GetString("unit", "")
- object.SetUserInfo(c.GetCurrentUserInfo())
- AreaId, err := object.SaveArea(unit, RoomColor)
- if err != nil {
- if strings.Contains(err.Error(), "") {
- c.Data["json"] = c.ResultError(object.Model.AreaName + "已存在")
- } else {
- c.Data["json"] = c.ResultError(err.Error())
- }
- } else {
- c.Data["json"] = c.ResultOK(AreaId, 0)
- }
- c.ServeJSON()
- }
- // @Summary 删除指定区域信息
- // @Description 删除指定区域信息
- // @Tags 基础服务接口
- // @Accept x-www-form-urlencoded
- // @Produce json
- // @Param id query int true "区域ID。"
- // @Param isall query int false "是否同时删除所有下级区域。1为是,反之为否。默认为否"
- // @Success 200 {object} ResultOK 成功
- // @Failure 500 {object} ResultError 失败
- // @router /basic_area/del [post]
- func (c *ApiController) BasicAreaDelete() {
- areaObject := new(bo.BasicArea)
- id, _ := c.GetInt("id")
- //是否批量删除所有下级节点
- isall := c.GetString("isall")
- var err error
- if isall == "1" {
- err = areaObject.DelAreaInfo(id)
- } else {
- err = areaObject.DeleteArea()
- }
- if err != nil {
- c.Data["json"] = c.ResultError(err.Error())
- } else {
- c.Data["json"] = c.ResultOK(nil, 0)
- }
- c.ServeJSON()
- }
|