|
|
@@ -0,0 +1,676 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "ColdVerify_server/conf"
|
|
|
+ "ColdVerify_server/lib"
|
|
|
+ "ColdVerify_server/lib/wx"
|
|
|
+ "ColdVerify_server/models/Account"
|
|
|
+ "ColdVerify_server/models/AllotTask"
|
|
|
+ "ColdVerify_server/models/InfoCollection"
|
|
|
+ "ColdVerify_server/models/System"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "math"
|
|
|
+ "time"
|
|
|
+
|
|
|
+ beego "github.com/beego/beego/v2/server/web"
|
|
|
+)
|
|
|
+
|
|
|
+type AllotTaskController struct {
|
|
|
+ beego.Controller
|
|
|
+}
|
|
|
+
|
|
|
+// 列表 -
|
|
|
+func (c *AllotTaskController) List() {
|
|
|
+ // 验证登录 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_company := c.GetString("T_company") // 公司名称
|
|
|
+ T_uuid := c.GetString("T_uuid")
|
|
|
+
|
|
|
+ T_scheme := c.GetString("T_scheme") // 实施方案 负责人UUID
|
|
|
+ T_project := c.GetString("T_project") // 实施方案 负责人UUID
|
|
|
+ T_collection := c.GetString("T_collection") // 数据采集 负责人UUID
|
|
|
+ T_reporting := c.GetString("T_reporting") // 报告编写 负责人UUID
|
|
|
+ T_delivery := c.GetString("T_delivery") // 交付审核 负责人UUID
|
|
|
+ T_status, _ := c.GetInt("T_status")
|
|
|
+
|
|
|
+ UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
|
|
|
+ AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
|
|
|
+
|
|
|
+ var T_company_list []string
|
|
|
+ if len(T_company) > 0 {
|
|
|
+ T_company_list = Account.Read_User_T_uuid_ListByT_name(T_company)
|
|
|
+ }
|
|
|
+
|
|
|
+ var T_admin string
|
|
|
+ if User_r.T_power > 2 {
|
|
|
+ T_admin = User_r.T_uuid
|
|
|
+ }
|
|
|
+ // 经销商下管理员可查看自己经销商下所有的任务
|
|
|
+ // 经销商下其他角色只能查看分配给自己的任务
|
|
|
+ if len(User_r.T_Distributor_id) > 0 && User_r.T_power <= 2 {
|
|
|
+ T_admin = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ var cnt int
|
|
|
+
|
|
|
+ List, cnt := AllotTask.Read_AllotTask_List(User_r.T_Distributor_id, T_admin, T_uuid, T_name, T_project, T_scheme, T_collection, T_reporting, T_delivery,
|
|
|
+ T_status, T_company_list, UserMap, AdminMap, 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 *AllotTaskController) 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_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ r, is := AllotTask.Read_AllotTask(T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ userMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
|
|
|
+ adminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: AllotTask.AllotTaskToAllotTask_(r, userMap, adminMap)}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 添加-
|
|
|
+func (c *AllotTaskController) 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_approach_time := c.GetString("T_approach_time") // 用户uuid
|
|
|
+ T_scheme := c.GetString("T_scheme")
|
|
|
+ T_collection := c.GetString("T_collection")
|
|
|
+ T_reporting := c.GetString("T_reporting")
|
|
|
+ T_delivery := c.GetString("T_delivery")
|
|
|
+
|
|
|
+ T_project := c.GetString("T_project") // 项目 负责人UUID
|
|
|
+ T_province := c.GetString("T_province") // 省
|
|
|
+ T_city := c.GetString("T_city") // 市
|
|
|
+ T_district := c.GetString("T_district") // 区
|
|
|
+ T_province_code := c.GetString("T_province_code") // 省 code
|
|
|
+ T_city_code := c.GetString("T_city_code") // 市 code
|
|
|
+ T_district_code := c.GetString("T_district_code") // 区 code
|
|
|
+ T_category := c.GetString("T_category") // 类别
|
|
|
+ T_attachment := c.GetString("T_attachment") // 合同附件
|
|
|
+
|
|
|
+ // 查询信息采集信息
|
|
|
+ user, is := Account.Read_User(T_uuid)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_uuid 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var_ := AllotTask.AllotTask{
|
|
|
+ T_Distributor_id: user.T_Distributor_id,
|
|
|
+ T_uuid: T_uuid,
|
|
|
+ T_name: T_name,
|
|
|
+ T_approach_time: T_approach_time,
|
|
|
+ T_scheme: T_scheme,
|
|
|
+ T_collection: T_collection,
|
|
|
+ T_reporting: T_reporting,
|
|
|
+ T_delivery: T_delivery,
|
|
|
+
|
|
|
+ T_project: T_project,
|
|
|
+ T_province: T_province,
|
|
|
+ T_city: T_city,
|
|
|
+ T_district: T_district,
|
|
|
+ T_province_code: T_province_code,
|
|
|
+ T_city_code: T_city_code,
|
|
|
+ T_district_code: T_district_code,
|
|
|
+ T_category: T_category,
|
|
|
+ T_attachment: T_attachment,
|
|
|
+
|
|
|
+ T_state: 1,
|
|
|
+ T_status: AllotTask.AllotTaskStatusWaitReceive,
|
|
|
+
|
|
|
+ T_allot_time: time.Now(),
|
|
|
+ }
|
|
|
+
|
|
|
+ T_sllot_task_id, is := AllotTask.Add_AllotTask(var_)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 通知
|
|
|
+ _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
|
|
|
+ go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】采集任务已派发,进场时间:%s,请及时接收并提交信息确认表", company_r.T_name, var_.T_name, T_approach_time))
|
|
|
+
|
|
|
+ System.Add_UserLogs_T(User_r.T_uuid, "采集任务管理", "添加", var_)
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_sllot_task_id}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 修改-
|
|
|
+func (c *AllotTaskController) 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_approach_time := c.GetString("T_approach_time")
|
|
|
+ T_scheme := c.GetString("T_scheme")
|
|
|
+ T_collection := c.GetString("T_collection")
|
|
|
+ T_reporting := c.GetString("T_reporting")
|
|
|
+ T_delivery := c.GetString("T_delivery")
|
|
|
+ T_project := c.GetString("T_project") // 项目 负责人UUID
|
|
|
+ T_province := c.GetString("T_province") // 省
|
|
|
+ T_city := c.GetString("T_city") // 市
|
|
|
+ T_district := c.GetString("T_district") // 区
|
|
|
+ T_province_code := c.GetString("T_province_code") // 省 code
|
|
|
+ T_city_code := c.GetString("T_city_code") // 市 code
|
|
|
+ T_district_code := c.GetString("T_district_code") // 区 code
|
|
|
+ T_category := c.GetString("T_category") // 类别
|
|
|
+ T_attachment := c.GetString("T_attachment") // 合同附件
|
|
|
+
|
|
|
+ T_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ r, is := AllotTask.Read_AllotTask(T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ old_collection := r.T_collection
|
|
|
+ // .......
|
|
|
+ clos := make([]string, 0)
|
|
|
+ r.T_attachment = T_attachment
|
|
|
+ if len(T_name) > 0 {
|
|
|
+ r.T_name = T_name
|
|
|
+ clos = append(clos, "T_name")
|
|
|
+ }
|
|
|
+ if len(T_approach_time) > 0 {
|
|
|
+ r.T_approach_time = T_approach_time
|
|
|
+ clos = append(clos, "T_approach_time")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(T_scheme) > 0 {
|
|
|
+ r.T_scheme = T_scheme
|
|
|
+ clos = append(clos, "T_scheme")
|
|
|
+
|
|
|
+ }
|
|
|
+ if len(T_collection) > 0 {
|
|
|
+ r.T_collection = T_collection
|
|
|
+ clos = append(clos, "T_collection")
|
|
|
+ }
|
|
|
+ if len(T_reporting) > 0 {
|
|
|
+ r.T_reporting = T_reporting
|
|
|
+ clos = append(clos, "T_reporting")
|
|
|
+ }
|
|
|
+ if len(T_delivery) > 0 {
|
|
|
+ r.T_delivery = T_delivery
|
|
|
+ clos = append(clos, "T_delivery")
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(T_project) > 0 {
|
|
|
+ r.T_project = T_project
|
|
|
+ clos = append(clos, "T_project")
|
|
|
+ }
|
|
|
+ if len(T_province) > 0 {
|
|
|
+ r.T_province = T_province
|
|
|
+ clos = append(clos, "T_province")
|
|
|
+ }
|
|
|
+ if len(T_city) > 0 {
|
|
|
+ r.T_city = T_city
|
|
|
+ clos = append(clos, "T_city")
|
|
|
+ }
|
|
|
+ if len(T_district) > 0 {
|
|
|
+ r.T_district = T_district
|
|
|
+ clos = append(clos, "T_district")
|
|
|
+ }
|
|
|
+ if len(T_province_code) > 0 {
|
|
|
+ r.T_province_code = T_province_code
|
|
|
+ clos = append(clos, "T_province_code")
|
|
|
+ }
|
|
|
+ if len(T_city_code) > 0 {
|
|
|
+ r.T_city_code = T_city_code
|
|
|
+ clos = append(clos, "T_city_code")
|
|
|
+ }
|
|
|
+ if len(T_district_code) > 0 {
|
|
|
+ r.T_district_code = T_district_code
|
|
|
+ clos = append(clos, "T_district_code")
|
|
|
+ }
|
|
|
+ if len(T_category) > 0 {
|
|
|
+ r.T_category = T_category
|
|
|
+ clos = append(clos, "T_category")
|
|
|
+ }
|
|
|
+ if len(T_attachment) > 0 {
|
|
|
+ r.T_attachment = T_attachment
|
|
|
+ clos = append(clos, "T_attachment")
|
|
|
+ }
|
|
|
+
|
|
|
+ if r.T_status == AllotTask.AllotTaskStatusRefused {
|
|
|
+ r.T_status = AllotTask.AllotTaskStatusWaitReceive
|
|
|
+ r.T_allot_time = time.Now()
|
|
|
+ clos = append(clos, "T_status")
|
|
|
+ _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
|
|
|
+ go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】采集任务已派发,进场时间:%s,请及时接收并提交信息确认表", company_r.T_name, r.T_name, T_approach_time))
|
|
|
+
|
|
|
+ } else if r.T_collection != old_collection {
|
|
|
+ _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
|
|
|
+ go wx.WxSend(r.T_collection, fmt.Sprintf("【%s-%s】采集任务已派发,进场时间:%s,请及时接收并提交信息确认表", company_r.T_name, r.T_name, T_approach_time))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if !AllotTask.Update_AllotTask(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 *AllotTaskController) 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_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ if r, is := AllotTask.Read_AllotTask(T_allot_task_id); is {
|
|
|
+ if !AllotTask.Delete_AllotTask(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 *AllotTaskController) 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_approach_time := c.GetString("T_approach_time")
|
|
|
+ T_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ r, is := AllotTask.Read_AllotTask(T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var_ := AllotTask.AllotTask{
|
|
|
+ T_Distributor_id: r.T_Distributor_id,
|
|
|
+ T_uuid: r.T_uuid,
|
|
|
+ T_name: T_name,
|
|
|
+ T_approach_time: T_approach_time,
|
|
|
+ T_scheme: r.T_scheme,
|
|
|
+ T_collection: r.T_collection,
|
|
|
+ T_reporting: r.T_reporting,
|
|
|
+ T_delivery: r.T_delivery,
|
|
|
+ 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_state: 1,
|
|
|
+ T_status: AllotTask.AllotTaskStatusWaitReceive,
|
|
|
+ T_allot_time: time.Now(),
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通知
|
|
|
+ _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
|
|
|
+ go wx.WxSend(var_.T_collection, fmt.Sprintf("【%s-%s】采集任务已派发,进场时间:%s,请及时接收并提交信息确认表", company_r.T_name, var_.T_name, T_approach_time))
|
|
|
+ T_sllot_task_id, is := AllotTask.Add_AllotTask(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: T_sllot_task_id}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 接收
|
|
|
+func (c *AllotTaskController) Receive() {
|
|
|
+ // 验证登录 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_status, _ := c.GetInt("T_status") // 2-接收 3-拒绝
|
|
|
+ T_reason := c.GetString("T_reason")
|
|
|
+
|
|
|
+ T_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ r, is := AllotTask.Read_AllotTask(T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证权限
|
|
|
+ if User_r.T_uuid != r.T_collection {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "您不是该任务单的接收人!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取r.T_record,转换为json,添加新的记录
|
|
|
+ var existingRecords = make([]AllotTask.AllotTaskRecord, 0)
|
|
|
+ if len(r.T_record) > 0 {
|
|
|
+ json.Unmarshal([]byte(r.T_record), &existingRecords)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建新的记录条目
|
|
|
+ newRecord := AllotTask.AllotTaskRecord{
|
|
|
+ T_collection: User_r.T_uuid,
|
|
|
+ T_status: T_status,
|
|
|
+ T_reason: T_reason,
|
|
|
+ T_time: time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ }
|
|
|
+
|
|
|
+ existingRecords = append(existingRecords, newRecord)
|
|
|
+
|
|
|
+ // 将更新后的记录数组转换为JSON字符串
|
|
|
+ updatedRecordsJSON, err := json.Marshal(existingRecords)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "记录更新失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新r.T_record字段
|
|
|
+ r.T_record = string(updatedRecordsJSON)
|
|
|
+ r.T_status = T_status
|
|
|
+ if r.T_status == AllotTask.AllotTaskStatusRefused && len(T_reason) > 0 {
|
|
|
+ r.T_reason = T_reason
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新数据库中的记录
|
|
|
+ if !AllotTask.Update_AllotTask(r, "T_record", "T_status", "T_reason") {
|
|
|
+ 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 *AllotTaskController) UploadConfirmForm() {
|
|
|
+ // 验证登录 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_confirm_form := c.GetString("T_confirm_form")
|
|
|
+
|
|
|
+ T_allot_task_id := c.GetString("T_allot_task_id")
|
|
|
+ r, is := AllotTask.Read_AllotTask(T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(T_confirm_form) > 0 {
|
|
|
+ r.T_confirm_form = T_confirm_form
|
|
|
+ if r.T_status == AllotTask.AllotTaskStatusReceived {
|
|
|
+ r.T_status = AllotTask.AllotTaskStatusSubmit // 修改为已提交
|
|
|
+ }
|
|
|
+ if len(r.T_submit_time) == 0 {
|
|
|
+ r.T_submit_time = time.Now().Format("2006-01-02 15:04:05") // 设置提交时间
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取r.T_record,转换为json,添加新的记录
|
|
|
+ var existingRecords = make([]AllotTask.AllotTaskRecord, 0)
|
|
|
+ if len(r.T_record) > 0 {
|
|
|
+ json.Unmarshal([]byte(r.T_record), &existingRecords)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建新的记录条目
|
|
|
+ newRecord := AllotTask.AllotTaskRecord{
|
|
|
+ T_collection: User_r.T_uuid,
|
|
|
+ T_status: AllotTask.AllotTaskStatusSubmit,
|
|
|
+ T_reason: "",
|
|
|
+ T_time: time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ }
|
|
|
+
|
|
|
+ existingRecords = append(existingRecords, newRecord)
|
|
|
+
|
|
|
+ // 将更新后的记录数组转换为JSON字符串
|
|
|
+ updatedRecordsJSON, err := json.Marshal(existingRecords)
|
|
|
+ if err != nil {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "记录更新失败!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新r.T_record字段
|
|
|
+ r.T_record = string(updatedRecordsJSON)
|
|
|
+
|
|
|
+ if !AllotTask.Update_AllotTask(r, "T_confirm_form", "T_status", "T_submit_time", "T_record") {
|
|
|
+ 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 *AllotTaskController) 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
|
|
|
+ }
|
|
|
+
|
|
|
+ List, cnt := AllotTask.Read_AllotTask_List(User_r.T_Distributor_id, User_r.T_uuid, "", "", "", "", "", "", "",
|
|
|
+ 0, []string{}, map[string]string{}, map[string]string{}, 0, 9999)
|
|
|
+
|
|
|
+ res := make(map[int]int)
|
|
|
+ for k, _ := range AllotTask.AllotTaskStateMap {
|
|
|
+ res[k] = 0
|
|
|
+ }
|
|
|
+ res[0] = cnt
|
|
|
+ for _, r := range List {
|
|
|
+ res[r.T_status] += 1
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按指定格式返回统计结果
|
|
|
+ result := []map[string]interface{}{
|
|
|
+ {
|
|
|
+ "name": "全部",
|
|
|
+ "num": res[0],
|
|
|
+ "T_status": 0,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "待接收",
|
|
|
+ "num": res[AllotTask.AllotTaskStatusWaitReceive],
|
|
|
+ "T_status": AllotTask.AllotTaskStatusWaitReceive,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "已接收",
|
|
|
+ "num": res[AllotTask.AllotTaskStatusReceived],
|
|
|
+ "T_status": AllotTask.AllotTaskStatusReceived,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "已提交",
|
|
|
+ "num": res[AllotTask.AllotTaskStatusSubmit],
|
|
|
+ "T_status": AllotTask.AllotTaskStatusSubmit,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "name": "已拒绝",
|
|
|
+ "num": res[AllotTask.AllotTaskStatusRefused],
|
|
|
+ "T_status": AllotTask.AllotTaskStatusRefused,
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Data: result, Code: 200, Msg: "ok!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 获取任务负责人列表
|
|
|
+func (c *AllotTaskController) GetAllotTaskUserList() {
|
|
|
+ // 验证登录 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_type := c.GetString("T_type") // T_project项目 T_scheme方案 T_collection数据采集 T_reporting报告
|
|
|
+
|
|
|
+ list := AllotTask.Get_AllotTask_UserList(T_type)
|
|
|
+ AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
|
|
|
+
|
|
|
+ var User_list []Account.Admin_R
|
|
|
+ for _, v := range list {
|
|
|
+ if len(v) == 0 {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ User_list = append(User_list, Account.Admin_R{T_uuid: v, T_name: AdminMap[v]})
|
|
|
+ }
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: User_list}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// 通过信息采集ID获取指派任务详情
|
|
|
+func (c *AllotTaskController) GetByInfoCollectionId() {
|
|
|
+ // 验证登录
|
|
|
+ _, 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 len(T_InfoCollection_id) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "信息采集ID不能为空!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 先通过信息采集ID获取信息采集详情
|
|
|
+ infoCollection, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "信息采集ID错误!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有关联的指派任务ID
|
|
|
+ if len(infoCollection.T_allot_task_id) == 0 {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Data: AllotTask.AllotTask_{}, Msg: "该信息采集没有关联的指派任务!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通过指派任务ID获取指派任务详情
|
|
|
+ allotTask, is := AllotTask.Read_AllotTask(infoCollection.T_allot_task_id)
|
|
|
+ if !is {
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 202, Msg: "指派任务不存在!"}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ allotTaskDetail := AllotTask.AllotTaskToAllotTask_(allotTask, map[string]string{}, map[string]string{})
|
|
|
+
|
|
|
+ c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: allotTaskDetail}
|
|
|
+ c.ServeJSON()
|
|
|
+ return
|
|
|
+}
|