infoCollection.go 20 KB

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