package controllers import ( "ColdVerify_server/conf" "ColdVerify_server/lib" "ColdVerify_server/models/Account" "ColdVerify_server/models/System" "ColdVerify_server/models/Task" "ColdVerify_server/models/VerifyTemplate" "encoding/json" beego "github.com/beego/beego/v2/server/web" "math" "strconv" ) type VerifyTemplateController struct { beego.Controller } // 列表 - func (c *VerifyTemplateController) List() { // 验证登录 User_is, User_r _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } var r_jsons lib.R_JSONS page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } T_class, _ := c.GetInt("T_class") if T_class <= 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class Err!"} c.ServeJSON() return } T_name := c.GetString("T_name") var cnt int64 List, cnt := VerifyTemplate.Read_VerifyTemplate_List(T_class, T_name, page, page_z) page_size := math.Ceil(float64(cnt) / float64(page_z)) r_jsons.List = List r_jsons.Page = page r_jsons.Page_size = int(page_size) r_jsons.Pages = lib.Func_page(int64(page), int64(page_size)) r_jsons.Num = int(cnt) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 添加- func (c *VerifyTemplateController) Add() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_sort, _ := c.GetInt("T_sort") T_class, _ := c.GetInt("T_class") var_ := VerifyTemplate.VerifyTemplate{ T_class: T_class, T_name: T_name, T_sort: T_sort, } Id, is := VerifyTemplate.Add_VerifyTemplate(var_) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } // 修改- func (c *VerifyTemplateController) Up() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_sort, T_sort_err := c.GetInt("T_sort") T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") T_scheme := c.GetString("T_scheme") T_reporting := c.GetString("T_reporting") r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } // ....... if len(T_name) > 0 { r.T_name = T_name } if len(T_scheme) > 0 { r.T_scheme = T_scheme } if len(T_reporting) > 0 { r.T_reporting = T_reporting } if T_sort_err == nil { r.T_sort = T_sort } // ....... if !VerifyTemplate.Update_VerifyTemplate(r, "T_name", "T_sort", "T_scheme", "T_reporting") { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "修改", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 删除- func (c *VerifyTemplateController) Del() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } if !VerifyTemplate.Delete_VerifyTemplate(r) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0) for _, v := range mapList { if vtm, is := VerifyTemplate.Read_VerifyTemplateMap(v.T_id); is { VerifyTemplate.Delete_VerifyTemplateMap(vtm) } } System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "删除", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 复制- func (c *VerifyTemplateController) Copy() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") T_name := c.GetString("T_name") r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } var_ := VerifyTemplate.VerifyTemplate{ T_class: r.T_class, T_name: T_name, T_sort: r.T_sort, } new_id, is := VerifyTemplate.Add_VerifyTemplate(var_) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"} c.ServeJSON() return } mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0) tempMap := make(map[string]struct{}) idList := make([]string, len(mapList)) // 生成mapList长度的T_id for i := 0; i < len(mapList); i++ { // 生成编号 rand_x := 0 T_id := "" for true { T_id = lib.GetRandstring(4, "", int64(rand_x)) _, is = VerifyTemplate.Read_VerifyTemplateMap(T_id) if !is { if _, ok := tempMap[T_id]; !ok { break } } rand_x += 1 } tempMap[T_id] = struct{}{} idList[i] = T_id } mapInsertList := make([]VerifyTemplate.VerifyTemplateMap, 0) for i, v := range mapList { vtm := VerifyTemplate.VerifyTemplateMap{ T_id: idList[i], T_VerifyTemplate_id: new_id, T_name: v.T_name, T_text: v.T_text, T_label: v.T_label, T_source: v.T_source, T_sort: v.T_sort, T_flow_sort: v.T_flow_sort, T_max_time: v.T_max_time, T_min_time: v.T_min_time, } mapInsertList = append(mapInsertList, vtm) } _, is = VerifyTemplate.Add_VerifyTemplateMapMulti(mapInsertList) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板", "复制", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: new_id} c.ServeJSON() return } /// ----------------------------------------------------------------------------- // 标签列表 - func (c *VerifyTemplateController) Map_List() { // 验证登录 User_is, User_r _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } var r_jsons lib.R_JSONS // page, _ := c.GetInt("page") // // if page < 1 { // page = 1 // } // // page_z, _ := c.GetInt("page_z") // // if page_z < 1 { // page_z = conf.Page_size // } T_sort, _ := c.GetInt("T_sort") // 排序 T_flow_sort, _ := c.GetInt("T_flow_sort") // 验证流程排序 T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") var cnt int64 List, cnt := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, T_sort, T_flow_sort) r_jsons.List = List r_jsons.Num = int(cnt) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 标签添加- func (c *VerifyTemplateController) Map_Add() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") T_name := c.GetString("T_name") T_text := c.GetString("T_text") T_label, _ := c.GetInt("T_label") T_source, _ := c.GetInt("T_source") T_sort, _ := c.GetInt("T_sort") T_flow_sort, _ := c.GetInt("T_flow_sort") T_max_time, _ := c.GetInt("T_max_time") T_min_time, _ := c.GetInt("T_min_time") var_ := VerifyTemplate.VerifyTemplateMap{ T_VerifyTemplate_id: T_VerifyTemplate_id, T_name: T_name, T_text: T_text, T_label: T_label, T_source: T_source, T_sort: T_sort, T_flow_sort: T_flow_sort, T_max_time: T_max_time, T_min_time: T_min_time, } Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } // 标签修改- func (c *VerifyTemplateController) Map_Up() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_text := c.GetString("T_text") T_label, T_label_err := c.GetInt("T_label") T_sort, T_sort_err := c.GetInt("T_sort") T_source, T_source_err := c.GetInt("T_source") T_min_time, T_min_time_err := c.GetInt("T_min_time") T_max_time, T_max_time_err := c.GetInt("T_max_time") T_flow_sort, T_flow_sort_err := c.GetInt("T_flow_sort") T_id := c.GetString("T_id") r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } // ....... if len(T_name) > 0 { r.T_name = T_name } if len(T_text) > 0 { r.T_text = T_text } if T_label_err == nil { r.T_label = T_label } if T_sort_err == nil { r.T_sort = T_sort } if T_source_err == nil { r.T_source = T_source } if T_min_time_err == nil { r.T_min_time = T_min_time } if T_max_time_err == nil { r.T_max_time = T_max_time } if T_flow_sort_err == nil { r.T_flow_sort = T_flow_sort } if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_sort", "T_source", "T_min_time", "T_max_time", "T_flow_sort") { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "修改", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 标签删除- func (c *VerifyTemplateController) Map_Del() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_id := c.GetString("T_id") if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is { if !VerifyTemplate.Delete_VerifyTemplateMap(r) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模板标签", "删除", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } /// ----------------------------------------------------------------------------- // 标签数据列表 - func (c *VerifyTemplateController) Map_Data_List() { // 验证登录 User_is, User_r _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id") T_source, _ := c.GetInt("T_source") T_flow, _ := c.GetInt("T_flow") // app 时间流程 if T_flow == 0 && T_source == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"} c.ServeJSON() return } T_task_id := c.GetString("T_task_id") _, is := Task.Read_Task(T_task_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"} c.ServeJSON() return } Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source, T_flow) Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Data} c.ServeJSON() return } // 添加标签数据 func (c *VerifyTemplateController) Map_Data_Pu() { //验证登录 User_is, User_r //token := c.Ctx.Request.Header.Get("user_tokey") //User_r, User_is := Account.Verification_Admin(token, "") //if !User_is { // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} // c.ServeJSON() // return //} type RequestBody struct { User_tokey string T_source int T_task_id string T_VerifyTemplate_id string VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R } var body RequestBody data := c.Ctx.Input.RequestBody err := json.Unmarshal(data, &body) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "json.Unmarshal is err:" + err.Error()} c.ServeJSON() } User_r, User_is := Account.Verification_Admin(body.User_tokey, "") if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } _, is := Task.Read_Task(body.T_task_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"} c.ServeJSON() return } MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0) for _, v := range body.VerifyTemplateMapData { val := VerifyTemplate.VerifyTemplateMapData{ T_source: v.T_source, T_task_id: body.T_task_id, T_VerifyTemplate_id: body.T_VerifyTemplate_id, T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id, T_flow_sort: v.T_flow_sort, T_max_time: v.T_max_time, T_min_time: v.T_min_time, T_value: v.T_value, } MapDataList = append(MapDataList, val) } ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids} c.ServeJSON() return } func (c *VerifyTemplateController) Map_Data_Copy() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_source, _ := c.GetInt("T_source") T_flow, _ := c.GetInt("T_flow") if T_flow == 0 && T_source == 0 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"} c.ServeJSON() return } T_copy_task_id := c.GetString("T_copy_task_id") copy_task, is := Task.Read_Task(T_copy_task_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"} c.ServeJSON() return } T_paste_task_id := c.GetString("T_paste_task_id") paste_task, is := Task.Read_Task(T_paste_task_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"} c.ServeJSON() return } if copy_task.T_VerifyTemplate_id != paste_task.T_VerifyTemplate_id { c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅支持相同模板间复制!"} c.ServeJSON() return } list := VerifyTemplate.Read_MapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id) MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0) for _, v := range list { val := VerifyTemplate.VerifyTemplateMapData{ T_source: T_source, T_task_id: paste_task.T_task_id, T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id, T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id, T_flow_sort: v.T_flow_sort, T_max_time: v.T_max_time, T_min_time: v.T_min_time, T_value: v.T_value, } MapDataList = append(MapDataList, val) } var ids []int64 ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "复制", MapDataList) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids} c.ServeJSON() return } func (c *VerifyTemplateController) Class_List() { // 验证登录 User_is, User_r _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateClass_List()} c.ServeJSON() return } func (c *VerifyTemplateController) Class_Add() { // 验证登录 User_is, User_r User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_name := c.GetString("T_name") T_fid, _ := c.GetInt("T_fid") var_ := VerifyTemplate.VerifyTemplateClass{ T_name: T_name, T_fid: T_fid, T_State: 1, } Id, err := VerifyTemplate.Add_VerifyTemplateClass(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *VerifyTemplateController) Class_Up() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_id, _ := c.GetInt("T_id") T_name := c.GetString("T_name") R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } if len(T_name) > 0 { R_VerifyTemplateToolClass.T_name = T_name } if is := VerifyTemplate.Update_VerifyTemplateClass(R_VerifyTemplateToolClass, "T_name"); !is { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "模板分类", "修改", R_VerifyTemplateToolClass) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func (c *VerifyTemplateController) Class_Del() { User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey")) if !User_is { c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"} c.ServeJSON() return } T_id, _ := c.GetInt("T_id") R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"} c.ServeJSON() return } ids := VerifyTemplate.ReadVerifyTemplateClassIds_T_path(R_VerifyTemplateToolClass.T_path) if is := VerifyTemplate.Delete_VerifyTemplateClass_ByIds(ids); !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } System.Add_UserLogs(User_r.T_uuid, "模板分类", "删除", strconv.Itoa(T_id)) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }