| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package controllers
- import (
- "encoding/json"
- "fmt"
- "dashoo.cn/base_common/utils"
- "dashoo.cn/mcs_common/business/actions"
- )
- // 报警项目接口说明
- type ActionsController struct {
- BaseController
- }
- type ActionModel struct {
- Name string `json:"name"`
- Item string `json:"item"`
- SendTo string `json:"sendto"`
- Wdid string `json:"wdid"`
- }
- // @Title 报警项目列表
- // @Description 报警项目列表
- // @Success 200 {object} business.device.DeviceChannels
- // @router /list [get]
- func (this *ActionsController) List() {
- var list []actions.Actions
- svc := actions.GetActionsService(utils.DBE)
- fmt.Println("-----lisasdasfdft-------")
- page := this.GetPageInfoForm()
- keyword := this.GetString("keyword123")
- where := " CreateUserId='" + utils.ToStr(this.User.Id) + "' "
- if keyword != "" {
- where = where + " and AName='" + keyword + "'"
- }
- println("message:", where)
- total := svc.GetPagingEntitiesWithOrder(page.CurrentPage, page.Size, "CreateOn", false, &list, where)
- var datainfo DataInfo
- fmt.Println("-----list-------", list)
- datainfo.Items = list
- 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 *ActionsController) AddPost() {
- var model ActionModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- var errinfo ErrorInfo
- var status Status
- var action actions.Actions
- u, p := this.GetuAndp()
- action.AName = model.Name
- action.AItem, _ = utils.StrTo(model.Item).Int()
- if action.AItem == 1 {
- action.ItemName = "电子邮件"
- action.SPara1 = model.SendTo
- } else if action.AItem == 2 {
- action.ItemName = "网址推送"
- action.SPara2 = model.SendTo
- } else if action.AItem == 5 {
- action.ItemName = "短信"
- action.SPara3 = model.SendTo
- } else if action.AItem == 6 {
- action.ItemName = "语音"
- action.SPara6 = model.SendTo
- } else if action.AItem == 8 {
- action.ItemName = "网页消息"
- action.SPara5 = this.User.Id
- }
- strUrl := utils.Cfg.MustValue("server", "apiurl") + "/actions/?u=" + u + "&p=" + p
- json.Unmarshal(Apipost(strUrl, "POST", action), &status)
- if status.Status != 0 {
- errinfo.Message = utils.AlertProcess("添加失败!" + status.Message)
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- svc := actions.GetActionsService(utils.DBE)
- action.AccCode = this.GetAccode()
- action.Wdid = status.Id
- action.Id, _ = utils.StrTo(status.Id).Int()
- action.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
- action.CreateBy = this.User.Realname
- _, err := svc.InsertEntity(&action) //插入数据库
- 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 = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- }
- // @Title 编辑报警项目
- // @Description 编辑报警项目
- // @Param id path string true "需要修改的报警项目编号"
- // @Param body body business.device.DeviceChannels "报警项目信息"
- // @Success 200 {object} ErrorInfo
- // @router /:id [put]
- func (this *ActionsController) EditPost() {
- var model ActionModel
- var jsonblob = this.Ctx.Input.RequestBody
- json.Unmarshal(jsonblob, &model)
- id := this.Ctx.Input.Param(":id")
- var action actions.Actions
- var actionempty actions.Actions
- var status Status
- var errinfo ErrorInfo
- u, p := this.GetuAndp()
- action.AName = model.Name
- action.AItem, _ = utils.StrTo(model.Item).Int()
- if action.AItem == 1 {
- action.ItemName = "电子邮件"
- action.SPara1 = model.SendTo
- } else if action.AItem == 2 {
- action.ItemName = "网址推送"
- action.SPara2 = model.SendTo
- } else if action.AItem == 5 {
- action.ItemName = "短信"
- action.SPara3 = model.SendTo
- } else if action.AItem == 6 {
- action.ItemName = "语音"
- action.SPara6 = model.SendTo
- } else if action.AItem == 8 {
- action.ItemName = "网页消息"
- action.SPara5 = this.User.Id
- }
- strUrl := utils.Cfg.MustValue("server", "apiurl") + "/actions/" + model.Wdid + "?u=" + u + "&p=" + p
- json.Unmarshal(Apipost(strUrl, "PUT", &action), &status)
- if status.Status != 0 {
- errinfo.Message = utils.AlertProcess("保存失败!" + status.Message)
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- svc := actions.GetActionsService(utils.DBE)
- var cols []string = []string{"AName", "AItem", "ItemName", "SPara1", "SPara2", "SPara3", "SPara4", "SPara5", "SPara6"}
- svc.UpdateEntityAndBackupByCols(id, &action, &actionempty, cols, utils.ToStr(this.User.Id), this.User.Realname)
- errinfo.Message = utils.AlertProcess("保存成功!")
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- // @Title 删除报警项目
- // @Description 删除报警项目
- // @Param id path string true "需要删除的报警项目编号"
- // @Success 200 {object} ErrorInfo
- // @Failure 403 :id 为空
- // @router /:id [delete]
- func (this *ActionsController) Delete() {
- id := this.Ctx.Input.Param(":id")
- wdid := this.GetString("wdid")
- var errinfo ErrorInfo
- svc := actions.GetActionsService(utils.DBE)
- if svc.IsUsed_TriggerAbnormal(id) {
- errinfo.Message = "删除失败!此设置已在【异常提醒设置】中使用"
- errinfo.Code = -2
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else {
- var entity actions.Actions
- var status Status
- u, p := this.GetuAndp()
- strUrl := utils.Cfg.MustValue("server", "apiurl") + "/actions/" + wdid + "?u=" + u + "&p=" + p
- json.Unmarshal(Apipost(strUrl, "DELETE", &entity), &status)
- if status.Status == 0 {
- svc.DeleteEntityById(id, entity)
- errinfo.Message = "删除成功!"
- errinfo.Code = 0
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else if status.Status == -1 {
- errinfo.Message = "删除失败!无删除权限!"
- errinfo.Code = -1
- this.Data["json"] = &errinfo
- this.ServeJSON()
- } else if status.Status == -3 {
- errinfo.Message = "删除失败!此项目设置已在设备【" + status.Message + "】中使用"
- errinfo.Code = -3
- this.Data["json"] = &errinfo
- this.ServeJSON()
- }
- }
- }
|