package controllers import ( "ColdVerify_server/Nats/NatsServer" "ColdVerify_server/conf" "ColdVerify_server/lib" "ColdVerify_server/lib/wx" "ColdVerify_server/logs" "ColdVerify_server/models/Account" "ColdVerify_server/models/AllotTask" "ColdVerify_server/models/Device" "ColdVerify_server/models/InfoCollection" "ColdVerify_server/models/System" "ColdVerify_server/models/Task" "ColdVerify_server/models/VerifyTemplate" "encoding/json" "fmt" beego "github.com/beego/beego/v2/server/web" "math" "time" ) type InfoCollectionController struct { beego.Controller } // 列表 - func (c *InfoCollectionController) 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_name := c.GetString("T_name") T_uuid := c.GetString("T_uuid") T_allot_task_id := c.GetString("T_allot_task_id") T_status, _ := c.GetInt("T_status") UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1()) AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1()) InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL()) InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL()) var cnt int List, cnt := InfoCollection.Read_InfoCollection_List(T_uuid, T_allot_task_id, T_name, T_status, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap, 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 = cnt c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 用户列表 func (c *InfoCollectionController) UserList() { // 验证登录 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 } 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_name := c.GetString("T_name") T_allot_task_id := c.GetString("T_allot_task_id") T_status, _ := c.GetInt("T_status") UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1()) AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1()) InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL()) InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL()) var cnt int List, cnt := InfoCollection.Read_UserInfoCollection_List(T_allot_task_id, User_r.T_uuid, T_name, T_status, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap, 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 = cnt c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 获取- func (c *InfoCollectionController) Get() { // 验证登录 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_InfoCollection_id := c.GetString("T_InfoCollection_id") r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"} c.ServeJSON() return } UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1()) AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1()) InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL()) InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL()) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: InfoCollection.InfoCollectionToInfoCollection_R(r, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap)} c.ServeJSON() return } // 添加- func (c *InfoCollectionController) 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_uuid := c.GetString("T_uuid") // 用户uuid T_InfoTemplate_class := c.GetString("T_InfoTemplate_class") T_InfoTemplate_id := c.GetString("T_InfoTemplate_id") T_allot_task_id := c.GetString("T_allot_task_id") if len(T_allot_task_id) > 0 { allotTask, is := AllotTask.Read_AllotTask(T_allot_task_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取采集任务信息失败!"} c.ServeJSON() return } T_uuid = allotTask.T_uuid } var_ := InfoCollection.InfoCollection{ T_uuid: T_uuid, T_name: T_name, T_InfoTemplate_class: T_InfoTemplate_class, T_InfoTemplate_id: T_InfoTemplate_id, T_status: 1, T_State: 1, T_submit_uuid: User_r.T_uuid, T_allot_task_id: T_allot_task_id, } T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id} c.ServeJSON() return } // 修改- func (c *InfoCollectionController) 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_InfoTemplate_class := c.GetString("T_InfoTemplate_class") T_InfoTemplate_id := c.GetString("T_InfoTemplate_id") T_InfoCollection_id := c.GetString("T_InfoCollection_id") T_status, _ := c.GetInt("T_status") r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } // ....... clos := make([]string, 0) if len(T_name) > 0 { r.T_name = T_name clos = append(clos, "T_name") } if T_status > 0 { r.T_status = T_status clos = append(clos, "T_status") } if len(T_InfoTemplate_class) > 0 { r.T_InfoTemplate_class = T_InfoTemplate_class clos = append(clos, "T_InfoTemplate_class") } if T_InfoTemplate_id != r.T_InfoTemplate_id { // 修改任务信息采集模版 Task.Update_Task_T_InfoTemplate_id(T_InfoCollection_id, T_InfoTemplate_id) } if len(T_InfoTemplate_id) > 0 { r.T_InfoTemplate_id = T_InfoTemplate_id clos = append(clos, "T_InfoTemplate_id") } if !InfoCollection.Update_InfoCollection(r, clos...) { 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 *InfoCollectionController) 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_InfoCollection_id := c.GetString("T_InfoCollection_id") if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is { if !InfoCollection.Delete_InfoCollection(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 *InfoCollectionController) UpStatus() { // 验证登录 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_InfoCollection_id := c.GetString("T_InfoCollection_id") T_status, _ := c.GetInt("T_status") T_reason := c.GetString("T_reason") //退回原因 r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid) if T_status == InfoCollection.InfoCollectionStatusSubmitted && (r.T_status != InfoCollection.InfoCollectionStatusWaitSubmit && r.T_status != InfoCollection.InfoCollectionStatusReturn) { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])} c.ServeJSON() return } if T_status == InfoCollection.InfoCollectionStatusReturnedMoney && r.T_status != InfoCollection.InfoCollectionStatusReceipt { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])} c.ServeJSON() return } if T_status == InfoCollection.InfoCollectionStatusReturn && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReturn) { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])} c.ServeJSON() return } if T_status == InfoCollection.InfoCollectionStatusReceipt && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReceipt) { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])} c.ServeJSON() return } // 1待提交 2已提交 3已接收 4已退回 5已回款 clos := make([]string, 0) if T_status > 0 { r.T_status = T_status clos = append(clos, "T_status") } // 2已提交 ,计算时间 if T_status == InfoCollection.InfoCollectionStatusSubmitted { if len(r.T_end_time) == 0 { r.T_end_time = time.Now().Format("2006-01-02 15:04:05") r.T_time_interval, _ = lib.MinutesDifference(r.T_start_time, r.T_end_time) clos = append(clos, "T_end_time") clos = append(clos, "T_time_interval") } } if T_status == InfoCollection.InfoCollectionStatusReturn { r.T_return_times += 1 clos = append(clos, "T_return_times") } var returnRecordList []InfoCollection.AuditRecord if len(r.T_audit_record) > 0 { err := json.Unmarshal([]byte(r.T_audit_record), &returnRecordList) if err != nil { logs.Error("JSON 反序列化失败:", err) return } } returnRecordList = append(returnRecordList, InfoCollection.AuditRecord{ T_uuid: User_r.T_uuid, T_status: T_status, T_reason: T_reason, T_time: time.Now().Format("2006-01-02 15:04:05"), }) returnRecordJson, err := json.Marshal(returnRecordList) if err != nil { logs.Error("JSON 反序列化失败:", err) return } r.T_audit_record = string(returnRecordJson) clos = append(clos, "T_audit_record") if !InfoCollection.Update_InfoCollection(r, clos...) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1()) _, company_r := Account.Read_User_ByT_uuid(r.T_uuid) // 已提交 [报告负责人] if T_status == InfoCollection.InfoCollectionStatusSubmitted { go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 %s", company_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status])) } // 已退回 if T_status == InfoCollection.InfoCollectionStatusReturn { System.Add_News(r.T_submit_uuid, fmt.Sprintf("【%s-%s】信息采集 %s,%s", company_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status], T_reason), "") go wx.WxSend(r.T_submit_uuid, fmt.Sprintf("【%s-%s】信息采集 %s,%s", company_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status], T_reason)) } if T_status == InfoCollection.InfoCollectionStatusReturnedMoney { go wx.WxSend(conf.BoosUuid, fmt.Sprintf("【%s-%s】已回款", company_r.T_name, r.T_name)) } System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改状态", r) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } // 退回记录列表 func (c *InfoCollectionController) AuditRecordList() { // 验证登录 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_InfoCollection_id := c.GetString("T_InfoCollection_id") T_status, _ := c.GetInt("T_status") r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } var auditRecordList []InfoCollection.AuditRecord if len(r.T_audit_record) > 0 { err := json.Unmarshal([]byte(r.T_audit_record), &auditRecordList) if err != nil { logs.Error("JSON 反序列化失败:", err) return } } AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1()) var auditRecordList2 []InfoCollection.AuditRecord if T_status == 0 { for i := 0; i < len(auditRecordList); i++ { auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid] auditRecordList2 = append(auditRecordList2, auditRecordList[i]) } c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"} c.ServeJSON() return } for i := 0; i < len(auditRecordList); i++ { if auditRecordList[i].T_status == T_status { auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid] auditRecordList2 = append(auditRecordList2, auditRecordList[i]) } } c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"} c.ServeJSON() return } // 信息采集统计 func (c *InfoCollectionController) Statistics() { // 验证登录 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_allot_task_id := c.GetString("T_allot_task_id") List, cnt := InfoCollection.Read_UserInfoCollection_List(T_allot_task_id, User_r.T_uuid, "", 0, map[string]string{}, map[string]string{}, map[string]string{}, map[string]string{}, 0, 9999) res := make(map[int]int) for k, _ := range InfoCollection.InfoCollectionStatusMap { res[k] = 0 } res[0] = cnt for _, r := range List { res[r.T_status] += 1 } c.Data["json"] = lib.JSONS{Data: res, Code: 200, Msg: "ok!"} c.ServeJSON() return } // 修改- func (c *InfoCollectionController) 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_name := c.GetString("T_name") T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id info, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"} c.ServeJSON() return } var_ := InfoCollection.InfoCollection{ T_uuid: info.T_uuid, T_name: T_name, T_InfoTemplate_class: info.T_InfoTemplate_class, T_InfoTemplate_id: info.T_InfoTemplate_id, T_status: 1, T_State: 1, T_submit_uuid: User_r.T_uuid, T_allot_task_id: info.T_allot_task_id, T_start_time: time.Now().Format("2006-01-02 15:04:05"), } T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()} c.ServeJSON() return } // 查询信息采集下的任务列表 taskList, _ := Task.Read_Task_List_By_T_InfoCollection_id(info.T_InfoCollection_id) for _, r := range taskList { dc := Device.DeviceClass{ T_uuid: User_r.T_uuid, T_State: 1, } T_class_id, is2 := Device.Add_DeviceClass(dc) if !is2 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc) ta := Task.Task{ T_Distributor_id: r.T_Distributor_id, T_InfoCollection_id: T_InfoCollection_id, T_InfoTemplate_id: info.T_InfoTemplate_id, T_start_time: time.Now().Format("2006-01-02 15:04:05"), // 项目开始时间使用信息采集开始时间 T_class: int(T_class_id), T_uuid: r.T_uuid, T_name: r.T_name, T_VerifyTemplate_class: r.T_VerifyTemplate_class, T_VerifyTemplate_id: r.T_VerifyTemplate_id, T_deadline: r.T_deadline, T_scheme: r.T_scheme, T_collection: r.T_collection, T_reporting: r.T_reporting, T_delivery: r.T_delivery, T_Show: 1, T_State: 1, T_project: r.T_project, T_province: r.T_province, T_city: r.T_city, T_district: r.T_district, T_province_code: r.T_province_code, T_city_code: r.T_city_code, T_district_code: r.T_district_code, T_category: r.T_category, T_device_type: r.T_device_type, T_volume: r.T_volume, T_verify_type: r.T_verify_type, T_subject_matter: r.T_subject_matter, T_temp_range: r.T_temp_range, T_report_type: r.T_report_type, T_device_quantity: r.T_device_quantity, T_cnas: r.T_cnas, } ta.T_report_number, _ = Task.GenerateNextT_report_number(ta.T_device_type) T_paste_task_id, is := Task.Add_Task(ta) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } NatsServer.Create_Local_Table(T_paste_task_id) Task.Redis_Task_T_report_number_DelK(ta.T_report_number) // 删除redis内的任务编号 // 复制验证模版数据 Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(r.T_VerifyTemplate_id, 0, 0) copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, r.T_task_id, r.T_VerifyTemplate_id, Map_List) Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_paste_task_id, r.T_VerifyTemplate_id, Map_List) copyDataMap := make(map[string]string) for _, data := range copy_task_Data { copyDataMap[data.T_name] = data.T_value } MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0) for _, v := range Data { // 已有值则不复制 if len(v.T_value) > 0 { continue } if copyDataMap[v.T_name] == "" { continue } val := VerifyTemplate.VerifyTemplateMapData{ T_source: v.T_source, T_task_id: T_paste_task_id, T_VerifyTemplate_id: r.T_VerifyTemplate_id, T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id, T_Required: v.T_Required, T_Construction: v.T_Construction, T_flow_sort: v.T_flow_sort, T_max_time: v.T_max_time, T_min_time: v.T_min_time, T_value: copyDataMap[v.T_name], } MapDataList = append(MapDataList, val) } _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "复制", 0, 0, 1) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"} c.ServeJSON() return } System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制标签数据", MapDataList) // 通知 _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid) go wx.WxSend(ta.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name)) go wx.WxSend(ta.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name)) go wx.WxSend(ta.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name)) go wx.WxSend(ta.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name)) // 添加任务操作日志 Task.Add_TaskLogs_T(User_r.T_uuid, T_paste_task_id, "任务管理", "复制", var_) System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制", var_) } System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "复制", info) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return }