infoCollection.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package controllers
  2. import (
  3. "ColdVerify_server/Nats/NatsServer"
  4. "ColdVerify_server/conf"
  5. "ColdVerify_server/lib"
  6. "ColdVerify_server/lib/wx"
  7. "ColdVerify_server/logs"
  8. "ColdVerify_server/models/Account"
  9. "ColdVerify_server/models/AllotTask"
  10. "ColdVerify_server/models/Device"
  11. "ColdVerify_server/models/InfoCollection"
  12. "ColdVerify_server/models/System"
  13. "ColdVerify_server/models/Task"
  14. "ColdVerify_server/models/VerifyTemplate"
  15. "encoding/json"
  16. "fmt"
  17. beego "github.com/beego/beego/v2/server/web"
  18. "math"
  19. "time"
  20. )
  21. type InfoCollectionController struct {
  22. beego.Controller
  23. }
  24. // 列表 -
  25. func (c *InfoCollectionController) List() {
  26. // 验证登录 User_is, User_r
  27. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  28. if !User_is {
  29. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  30. c.ServeJSON()
  31. return
  32. }
  33. var r_jsons lib.R_JSONS
  34. page, _ := c.GetInt("page")
  35. if page < 1 {
  36. page = 1
  37. }
  38. page_z, _ := c.GetInt("page_z")
  39. if page_z < 1 {
  40. page_z = conf.Page_size
  41. }
  42. T_name := c.GetString("T_name")
  43. T_uuid := c.GetString("T_uuid")
  44. T_allot_task_id := c.GetString("T_allot_task_id")
  45. T_status, _ := c.GetInt("T_status")
  46. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  47. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  48. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  49. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  50. var cnt int
  51. List, cnt := InfoCollection.Read_InfoCollection_List(T_uuid, T_allot_task_id, T_name, T_status, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap, page, page_z)
  52. page_size := math.Ceil(float64(cnt) / float64(page_z))
  53. r_jsons.List = List
  54. r_jsons.Page = page
  55. r_jsons.Page_size = int(page_size)
  56. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  57. r_jsons.Num = cnt
  58. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  59. c.ServeJSON()
  60. return
  61. }
  62. // 用户列表
  63. func (c *InfoCollectionController) UserList() {
  64. // 验证登录 User_is, User_r
  65. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  66. if !User_is {
  67. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  68. c.ServeJSON()
  69. return
  70. }
  71. var r_jsons lib.R_JSONS
  72. page, _ := c.GetInt("page")
  73. if page < 1 {
  74. page = 1
  75. }
  76. page_z, _ := c.GetInt("page_z")
  77. if page_z < 1 {
  78. page_z = conf.Page_size
  79. }
  80. T_name := c.GetString("T_name")
  81. T_allot_task_id := c.GetString("T_allot_task_id")
  82. T_status, _ := c.GetInt("T_status")
  83. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  84. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  85. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  86. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  87. var cnt int
  88. 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)
  89. page_size := math.Ceil(float64(cnt) / float64(page_z))
  90. r_jsons.List = List
  91. r_jsons.Page = page
  92. r_jsons.Page_size = int(page_size)
  93. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  94. r_jsons.Num = cnt
  95. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  96. c.ServeJSON()
  97. return
  98. }
  99. // 获取-
  100. func (c *InfoCollectionController) Get() {
  101. // 验证登录 User_is, User_r
  102. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  103. if !User_is {
  104. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  105. c.ServeJSON()
  106. return
  107. }
  108. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  109. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  110. if !is {
  111. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  112. c.ServeJSON()
  113. return
  114. }
  115. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  116. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  117. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  118. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  119. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: InfoCollection.InfoCollectionToInfoCollection_R(r, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap)}
  120. c.ServeJSON()
  121. return
  122. }
  123. // 添加-
  124. func (c *InfoCollectionController) Add() {
  125. // 验证登录 User_is, User_r
  126. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  127. if !User_is {
  128. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  129. c.ServeJSON()
  130. return
  131. }
  132. T_name := c.GetString("T_name")
  133. T_uuid := c.GetString("T_uuid") // 用户uuid
  134. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  135. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  136. T_allot_task_id := c.GetString("T_allot_task_id")
  137. if len(T_allot_task_id) > 0 {
  138. allotTask, is := AllotTask.Read_AllotTask(T_allot_task_id)
  139. if !is {
  140. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取采集任务信息失败!"}
  141. c.ServeJSON()
  142. return
  143. }
  144. T_uuid = allotTask.T_uuid
  145. }
  146. var_ := InfoCollection.InfoCollection{
  147. T_uuid: T_uuid,
  148. T_name: T_name,
  149. T_InfoTemplate_class: T_InfoTemplate_class,
  150. T_InfoTemplate_id: T_InfoTemplate_id,
  151. T_status: 1,
  152. T_State: 1,
  153. T_submit_uuid: User_r.T_uuid,
  154. T_allot_task_id: T_allot_task_id,
  155. }
  156. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  157. if err != nil {
  158. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  159. c.ServeJSON()
  160. return
  161. }
  162. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_)
  163. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id}
  164. c.ServeJSON()
  165. return
  166. }
  167. // 修改-
  168. func (c *InfoCollectionController) Up() {
  169. // 验证登录 User_is, User_r
  170. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  171. if !User_is {
  172. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  173. c.ServeJSON()
  174. return
  175. }
  176. T_name := c.GetString("T_name")
  177. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  178. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  179. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  180. T_status, _ := c.GetInt("T_status")
  181. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  182. if !is {
  183. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  184. c.ServeJSON()
  185. return
  186. }
  187. // .......
  188. clos := make([]string, 0)
  189. if len(T_name) > 0 {
  190. r.T_name = T_name
  191. clos = append(clos, "T_name")
  192. }
  193. if T_status > 0 {
  194. r.T_status = T_status
  195. clos = append(clos, "T_status")
  196. }
  197. if len(T_InfoTemplate_class) > 0 {
  198. r.T_InfoTemplate_class = T_InfoTemplate_class
  199. clos = append(clos, "T_InfoTemplate_class")
  200. }
  201. if T_InfoTemplate_id != r.T_InfoTemplate_id {
  202. // 修改任务信息采集模版
  203. Task.Update_Task_T_InfoTemplate_id(T_InfoCollection_id, T_InfoTemplate_id)
  204. }
  205. if len(T_InfoTemplate_id) > 0 {
  206. r.T_InfoTemplate_id = T_InfoTemplate_id
  207. clos = append(clos, "T_InfoTemplate_id")
  208. }
  209. if !InfoCollection.Update_InfoCollection(r, clos...) {
  210. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  211. c.ServeJSON()
  212. return
  213. }
  214. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改", r)
  215. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. // 删除-
  220. func (c *InfoCollectionController) Del() {
  221. // 验证登录 User_is, User_r
  222. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  223. if !User_is {
  224. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  225. c.ServeJSON()
  226. return
  227. }
  228. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  229. if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is {
  230. if !InfoCollection.Delete_InfoCollection(r) {
  231. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  232. c.ServeJSON()
  233. return
  234. }
  235. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "删除", r)
  236. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  237. c.ServeJSON()
  238. return
  239. }
  240. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  241. c.ServeJSON()
  242. return
  243. }
  244. // 修改状态
  245. func (c *InfoCollectionController) UpStatus() {
  246. // 验证登录 User_is, User_r
  247. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  248. if !User_is {
  249. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  250. c.ServeJSON()
  251. return
  252. }
  253. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  254. T_status, _ := c.GetInt("T_status")
  255. T_reason := c.GetString("T_reason") //退回原因
  256. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  257. if !is {
  258. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  259. c.ServeJSON()
  260. return
  261. }
  262. //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  263. if T_status == InfoCollection.InfoCollectionStatusSubmitted && (r.T_status != InfoCollection.InfoCollectionStatusWaitSubmit && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  264. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  265. c.ServeJSON()
  266. return
  267. }
  268. if T_status == InfoCollection.InfoCollectionStatusReturnedMoney && r.T_status != InfoCollection.InfoCollectionStatusReceipt {
  269. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  270. c.ServeJSON()
  271. return
  272. }
  273. if T_status == InfoCollection.InfoCollectionStatusReturn && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  274. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  275. c.ServeJSON()
  276. return
  277. }
  278. if T_status == InfoCollection.InfoCollectionStatusReceipt && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReceipt) {
  279. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  280. c.ServeJSON()
  281. return
  282. }
  283. // 1待提交 2已提交 3已接收 4已退回 5已回款
  284. clos := make([]string, 0)
  285. if T_status > 0 {
  286. r.T_status = T_status
  287. clos = append(clos, "T_status")
  288. }
  289. // 2已提交 ,计算时间
  290. if T_status == InfoCollection.InfoCollectionStatusSubmitted {
  291. if len(r.T_end_time) == 0 {
  292. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  293. r.T_time_interval, _ = lib.MinutesDifference(r.T_start_time, r.T_end_time)
  294. clos = append(clos, "T_end_time")
  295. clos = append(clos, "T_time_interval")
  296. }
  297. }
  298. if T_status == InfoCollection.InfoCollectionStatusReturn {
  299. r.T_return_times += 1
  300. clos = append(clos, "T_return_times")
  301. }
  302. var returnRecordList []InfoCollection.AuditRecord
  303. if len(r.T_audit_record) > 0 {
  304. err := json.Unmarshal([]byte(r.T_audit_record), &returnRecordList)
  305. if err != nil {
  306. logs.Error("JSON 反序列化失败:", err)
  307. return
  308. }
  309. }
  310. returnRecordList = append(returnRecordList, InfoCollection.AuditRecord{
  311. T_uuid: User_r.T_uuid,
  312. T_status: T_status,
  313. T_reason: T_reason,
  314. T_time: time.Now().Format("2006-01-02 15:04:05"),
  315. })
  316. returnRecordJson, err := json.Marshal(returnRecordList)
  317. if err != nil {
  318. logs.Error("JSON 反序列化失败:", err)
  319. return
  320. }
  321. r.T_audit_record = string(returnRecordJson)
  322. clos = append(clos, "T_audit_record")
  323. if !InfoCollection.Update_InfoCollection(r, clos...) {
  324. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  325. c.ServeJSON()
  326. return
  327. }
  328. //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  329. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  330. // 已提交 [报告负责人]
  331. if T_status == InfoCollection.InfoCollectionStatusSubmitted {
  332. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 %s", company_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status]))
  333. }
  334. // 已退回
  335. if T_status == InfoCollection.InfoCollectionStatusReturn {
  336. 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), "")
  337. 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))
  338. }
  339. if T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
  340. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("【%s-%s】已回款", company_r.T_name, r.T_name))
  341. }
  342. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改状态", r)
  343. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  344. c.ServeJSON()
  345. return
  346. }
  347. // 退回记录列表
  348. func (c *InfoCollectionController) AuditRecordList() {
  349. // 验证登录 User_is, User_r
  350. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  351. if !User_is {
  352. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  353. c.ServeJSON()
  354. return
  355. }
  356. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  357. T_status, _ := c.GetInt("T_status")
  358. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  359. if !is {
  360. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  361. c.ServeJSON()
  362. return
  363. }
  364. var auditRecordList []InfoCollection.AuditRecord
  365. if len(r.T_audit_record) > 0 {
  366. err := json.Unmarshal([]byte(r.T_audit_record), &auditRecordList)
  367. if err != nil {
  368. logs.Error("JSON 反序列化失败:", err)
  369. return
  370. }
  371. }
  372. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  373. var auditRecordList2 []InfoCollection.AuditRecord
  374. if T_status == 0 {
  375. for i := 0; i < len(auditRecordList); i++ {
  376. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  377. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  378. }
  379. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  380. c.ServeJSON()
  381. return
  382. }
  383. for i := 0; i < len(auditRecordList); i++ {
  384. if auditRecordList[i].T_status == T_status {
  385. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  386. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  387. }
  388. }
  389. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  390. c.ServeJSON()
  391. return
  392. }
  393. // 信息采集统计
  394. func (c *InfoCollectionController) Statistics() {
  395. // 验证登录 User_is, User_r
  396. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  397. if !User_is {
  398. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  399. c.ServeJSON()
  400. return
  401. }
  402. T_allot_task_id := c.GetString("T_allot_task_id")
  403. 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)
  404. res := make(map[int]int)
  405. for k, _ := range InfoCollection.InfoCollectionStatusMap {
  406. res[k] = 0
  407. }
  408. res[0] = cnt
  409. for _, r := range List {
  410. res[r.T_status] += 1
  411. }
  412. c.Data["json"] = lib.JSONS{Data: res, Code: 200, Msg: "ok!"}
  413. c.ServeJSON()
  414. return
  415. }
  416. // 修改-
  417. func (c *InfoCollectionController) Copy() {
  418. // 验证登录 User_is, User_r
  419. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  420. if !User_is {
  421. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  422. c.ServeJSON()
  423. return
  424. }
  425. T_name := c.GetString("T_name")
  426. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  427. info, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  428. if !is {
  429. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  430. c.ServeJSON()
  431. return
  432. }
  433. var_ := InfoCollection.InfoCollection{
  434. T_uuid: info.T_uuid,
  435. T_name: T_name,
  436. T_InfoTemplate_class: info.T_InfoTemplate_class,
  437. T_InfoTemplate_id: info.T_InfoTemplate_id,
  438. T_status: 1,
  439. T_State: 1,
  440. T_submit_uuid: User_r.T_uuid,
  441. T_allot_task_id: info.T_allot_task_id,
  442. T_start_time: time.Now().Format("2006-01-02 15:04:05"),
  443. }
  444. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  445. if err != nil {
  446. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  447. c.ServeJSON()
  448. return
  449. }
  450. // 查询信息采集下的任务列表
  451. taskList, _ := Task.Read_Task_List_By_T_InfoCollection_id(info.T_InfoCollection_id)
  452. for _, r := range taskList {
  453. dc := Device.DeviceClass{
  454. T_uuid: User_r.T_uuid,
  455. T_State: 1,
  456. }
  457. T_class_id, is2 := Device.Add_DeviceClass(dc)
  458. if !is2 {
  459. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加分类失败!"}
  460. c.ServeJSON()
  461. return
  462. }
  463. System.Add_UserLogs_T(User_r.T_uuid, "分类管理", "添加", dc)
  464. ta := Task.Task{
  465. T_Distributor_id: r.T_Distributor_id,
  466. T_InfoCollection_id: T_InfoCollection_id,
  467. T_InfoTemplate_id: info.T_InfoTemplate_id,
  468. T_start_time: time.Now().Format("2006-01-02 15:04:05"), // 项目开始时间使用信息采集开始时间
  469. T_class: int(T_class_id),
  470. T_uuid: r.T_uuid,
  471. T_name: r.T_name,
  472. T_VerifyTemplate_class: r.T_VerifyTemplate_class,
  473. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  474. T_deadline: r.T_deadline,
  475. T_scheme: r.T_scheme,
  476. T_collection: r.T_collection,
  477. T_reporting: r.T_reporting,
  478. T_delivery: r.T_delivery,
  479. T_Show: 1,
  480. T_State: 1,
  481. T_project: r.T_project,
  482. T_province: r.T_province,
  483. T_city: r.T_city,
  484. T_district: r.T_district,
  485. T_province_code: r.T_province_code,
  486. T_city_code: r.T_city_code,
  487. T_district_code: r.T_district_code,
  488. T_category: r.T_category,
  489. T_device_type: r.T_device_type,
  490. T_volume: r.T_volume,
  491. T_verify_type: r.T_verify_type,
  492. T_subject_matter: r.T_subject_matter,
  493. T_temp_range: r.T_temp_range,
  494. T_report_type: r.T_report_type,
  495. T_device_quantity: r.T_device_quantity,
  496. T_cnas: r.T_cnas,
  497. }
  498. ta.T_report_number, _ = Task.GenerateNextT_report_number(ta.T_device_type)
  499. T_paste_task_id, is := Task.Add_Task(ta)
  500. if !is {
  501. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  502. c.ServeJSON()
  503. return
  504. }
  505. NatsServer.Create_Local_Table(T_paste_task_id)
  506. Task.Redis_Task_T_report_number_DelK(ta.T_report_number) // 删除redis内的任务编号
  507. // 复制验证模版数据
  508. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(r.T_VerifyTemplate_id, 0, 0)
  509. copy_task_Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, r.T_task_id, r.T_VerifyTemplate_id, Map_List)
  510. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(0, T_paste_task_id, r.T_VerifyTemplate_id, Map_List)
  511. copyDataMap := make(map[string]string)
  512. for _, data := range copy_task_Data {
  513. copyDataMap[data.T_name] = data.T_value
  514. }
  515. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  516. for _, v := range Data {
  517. // 已有值则不复制
  518. if len(v.T_value) > 0 {
  519. continue
  520. }
  521. if copyDataMap[v.T_name] == "" {
  522. continue
  523. }
  524. val := VerifyTemplate.VerifyTemplateMapData{
  525. T_source: v.T_source,
  526. T_task_id: T_paste_task_id,
  527. T_VerifyTemplate_id: r.T_VerifyTemplate_id,
  528. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  529. T_Required: v.T_Required,
  530. T_Construction: v.T_Construction,
  531. T_flow_sort: v.T_flow_sort,
  532. T_max_time: v.T_max_time,
  533. T_min_time: v.T_min_time,
  534. T_value: copyDataMap[v.T_name],
  535. }
  536. MapDataList = append(MapDataList, val)
  537. }
  538. _, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, 0, "复制", 0, 0, 1)
  539. if !is {
  540. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  541. c.ServeJSON()
  542. return
  543. }
  544. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制标签数据", MapDataList)
  545. // 通知
  546. _, company_r := Account.Read_User_ByT_uuid(var_.T_uuid)
  547. go wx.WxSend(ta.T_scheme, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  548. go wx.WxSend(ta.T_collection, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  549. go wx.WxSend(ta.T_reporting, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  550. go wx.WxSend(ta.T_delivery, fmt.Sprintf("【%s-%s】任务派发", company_r.T_name, var_.T_name))
  551. // 添加任务操作日志
  552. Task.Add_TaskLogs_T(User_r.T_uuid, T_paste_task_id, "任务管理", "复制", var_)
  553. System.Add_UserLogs_T(User_r.T_uuid, "任务管理", "复制", var_)
  554. }
  555. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "复制", info)
  556. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  557. c.ServeJSON()
  558. return
  559. }