infoCollection.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. package controllers
  2. import (
  3. "ColdVerify_server/Nats/NatsServer"
  4. "ColdVerify_server/conf"
  5. "ColdVerify_server/lib"
  6. "ColdVerify_server/logs"
  7. "ColdVerify_server/models/Account"
  8. "ColdVerify_server/models/InfoCollection"
  9. "ColdVerify_server/models/System"
  10. "ColdVerify_server/models/Task"
  11. "encoding/json"
  12. "fmt"
  13. beego "github.com/beego/beego/v2/server/web"
  14. "math"
  15. "time"
  16. )
  17. type InfoCollectionController struct {
  18. beego.Controller
  19. }
  20. // 列表 -
  21. func (c *InfoCollectionController) List() {
  22. // 验证登录 User_is, User_r
  23. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  24. if !User_is {
  25. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  26. c.ServeJSON()
  27. return
  28. }
  29. var r_jsons lib.R_JSONS
  30. page, _ := c.GetInt("page")
  31. if page < 1 {
  32. page = 1
  33. }
  34. page_z, _ := c.GetInt("page_z")
  35. if page_z < 1 {
  36. page_z = conf.Page_size
  37. }
  38. T_name := c.GetString("T_name")
  39. T_uuid := c.GetString("T_uuid")
  40. T_status, _ := c.GetInt("T_status")
  41. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  42. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  43. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  44. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  45. var cnt int
  46. List, cnt := InfoCollection.Read_InfoCollection_List(T_uuid, T_name, T_status, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap, page, page_z)
  47. page_size := math.Ceil(float64(cnt) / float64(page_z))
  48. r_jsons.List = List
  49. r_jsons.Page = page
  50. r_jsons.Page_size = int(page_size)
  51. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  52. r_jsons.Num = cnt
  53. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  54. c.ServeJSON()
  55. return
  56. }
  57. // 用户列表
  58. func (c *InfoCollectionController) UserList() {
  59. // 验证登录 User_is, User_r
  60. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  61. if !User_is {
  62. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  63. c.ServeJSON()
  64. return
  65. }
  66. var r_jsons lib.R_JSONS
  67. page, _ := c.GetInt("page")
  68. if page < 1 {
  69. page = 1
  70. }
  71. page_z, _ := c.GetInt("page_z")
  72. if page_z < 1 {
  73. page_z = conf.Page_size
  74. }
  75. T_name := c.GetString("T_name")
  76. T_status, _ := c.GetInt("T_status")
  77. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  78. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  79. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  80. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  81. var cnt int
  82. List, cnt := InfoCollection.Read_UserInfoCollection_List(User_r.T_uuid, T_name, T_status, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap, page, page_z)
  83. page_size := math.Ceil(float64(cnt) / float64(page_z))
  84. r_jsons.List = List
  85. r_jsons.Page = page
  86. r_jsons.Page_size = int(page_size)
  87. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  88. r_jsons.Num = cnt
  89. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  90. c.ServeJSON()
  91. return
  92. }
  93. // 获取-
  94. func (c *InfoCollectionController) Get() {
  95. // 验证登录 User_is, User_r
  96. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  97. if !User_is {
  98. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  99. c.ServeJSON()
  100. return
  101. }
  102. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  103. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  104. if !is {
  105. c.Data["json"] = lib.JSONS{Code: 202, Msg: "获取信息采集失败!"}
  106. c.ServeJSON()
  107. return
  108. }
  109. UserMap := Account.UserListToMap(Account.Read_User_List_ALL_1())
  110. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  111. InfoTemplateMap := InfoCollection.InfoTemplateListToMap(InfoCollection.Read_InfoTemplate_List_ALL())
  112. InfoTemplateClassMap := InfoCollection.InfoTemplateClassListToMap(InfoCollection.Read_InfoTemplateClass_List_ALL())
  113. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: InfoCollection.InfoCollectionToInfoCollection_R(r, UserMap, AdminMap, InfoTemplateMap, InfoTemplateClassMap)}
  114. c.ServeJSON()
  115. return
  116. }
  117. // 添加-
  118. func (c *InfoCollectionController) Add() {
  119. // 验证登录 User_is, User_r
  120. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  121. if !User_is {
  122. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  123. c.ServeJSON()
  124. return
  125. }
  126. T_name := c.GetString("T_name")
  127. T_uuid := c.GetString("T_uuid") // 用户uuid
  128. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  129. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  130. var_ := InfoCollection.InfoCollection{
  131. T_uuid: T_uuid,
  132. T_name: T_name,
  133. T_InfoTemplate_class: T_InfoTemplate_class,
  134. T_InfoTemplate_id: T_InfoTemplate_id,
  135. T_status: 1,
  136. T_State: 1,
  137. T_submit_uuid: User_r.T_uuid,
  138. }
  139. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  140. if err != nil {
  141. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  142. c.ServeJSON()
  143. return
  144. }
  145. NatsServer.Create_Local_Table(T_InfoCollection_id)
  146. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_)
  147. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id}
  148. c.ServeJSON()
  149. return
  150. }
  151. // 修改-
  152. func (c *InfoCollectionController) Up() {
  153. // 验证登录 User_is, User_r
  154. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  155. if !User_is {
  156. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  157. c.ServeJSON()
  158. return
  159. }
  160. T_name := c.GetString("T_name")
  161. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  162. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  163. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  164. T_status, _ := c.GetInt("T_status")
  165. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  166. if !is {
  167. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  168. c.ServeJSON()
  169. return
  170. }
  171. // .......
  172. clos := make([]string, 0)
  173. if len(T_name) > 0 {
  174. r.T_name = T_name
  175. clos = append(clos, "T_name")
  176. }
  177. if T_status > 0 {
  178. r.T_status = T_status
  179. clos = append(clos, "T_status")
  180. }
  181. if len(T_InfoTemplate_class) > 0 {
  182. r.T_InfoTemplate_class = T_InfoTemplate_class
  183. clos = append(clos, "T_InfoTemplate_class")
  184. }
  185. if T_InfoTemplate_id != r.T_InfoTemplate_id {
  186. // 修改任务信息采集模板
  187. Task.Update_Task_T_InfoTemplate_id(T_InfoCollection_id, T_InfoTemplate_id)
  188. }
  189. if len(T_InfoTemplate_id) > 0 {
  190. r.T_InfoTemplate_id = T_InfoTemplate_id
  191. clos = append(clos, "T_InfoTemplate_id")
  192. }
  193. if !InfoCollection.Update_InfoCollection(r, clos...) {
  194. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  195. c.ServeJSON()
  196. return
  197. }
  198. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改", r)
  199. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  200. c.ServeJSON()
  201. return
  202. }
  203. // 删除-
  204. func (c *InfoCollectionController) Del() {
  205. // 验证登录 User_is, User_r
  206. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  207. if !User_is {
  208. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  209. c.ServeJSON()
  210. return
  211. }
  212. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  213. if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is {
  214. if !InfoCollection.Delete_InfoCollection(r) {
  215. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  216. c.ServeJSON()
  217. return
  218. }
  219. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "删除", r)
  220. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  221. c.ServeJSON()
  222. return
  223. }
  224. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  225. c.ServeJSON()
  226. return
  227. }
  228. // 修改状态
  229. func (c *InfoCollectionController) UpStatus() {
  230. // 验证登录 User_is, User_r
  231. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  232. if !User_is {
  233. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  234. c.ServeJSON()
  235. return
  236. }
  237. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  238. T_status, _ := c.GetInt("T_status")
  239. T_reason := c.GetString("T_reason") //退回原因
  240. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  241. if !is {
  242. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  243. c.ServeJSON()
  244. return
  245. }
  246. _, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  247. if T_status == InfoCollection.InfoCollectionStatusSubmitted && (r.T_status != InfoCollection.InfoCollectionStatusWaitSubmit && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  248. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  249. c.ServeJSON()
  250. return
  251. }
  252. if T_status == InfoCollection.InfoCollectionStatusReturnedMoney && r.T_status != InfoCollection.InfoCollectionStatusReceipt {
  253. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  254. c.ServeJSON()
  255. return
  256. }
  257. if T_status == InfoCollection.InfoCollectionStatusReturn && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  258. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  259. c.ServeJSON()
  260. return
  261. }
  262. if T_status == InfoCollection.InfoCollectionStatusReceipt && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReceipt) {
  263. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  264. c.ServeJSON()
  265. return
  266. }
  267. // 1待提交 2已提交 3已接收 4已退回 5已回款
  268. clos := make([]string, 0)
  269. if T_status > 0 {
  270. r.T_status = T_status
  271. clos = append(clos, "T_status")
  272. }
  273. if T_status == InfoCollection.InfoCollectionStatusReturn {
  274. r.T_return_times += 1
  275. clos = append(clos, "T_return_times")
  276. }
  277. var returnRecordList []InfoCollection.AuditRecord
  278. if len(r.T_audit_record) > 0 {
  279. err := json.Unmarshal([]byte(r.T_audit_record), &returnRecordList)
  280. if err != nil {
  281. logs.Error("JSON 反序列化失败:", err)
  282. return
  283. }
  284. }
  285. returnRecordList = append(returnRecordList, InfoCollection.AuditRecord{
  286. T_uuid: User_r.T_uuid,
  287. T_status: T_status,
  288. T_reason: T_reason,
  289. T_time: time.Now().Format("2006-01-02 15:04:05"),
  290. })
  291. returnRecordJson, err := json.Marshal(returnRecordList)
  292. if err != nil {
  293. logs.Error("JSON 反序列化失败:", err)
  294. return
  295. }
  296. r.T_audit_record = string(returnRecordJson)
  297. clos = append(clos, "T_audit_record")
  298. if !InfoCollection.Update_InfoCollection(r, clos...) {
  299. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  300. c.ServeJSON()
  301. return
  302. }
  303. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  304. if T_status == InfoCollection.InfoCollectionStatusReceipt || T_status == InfoCollection.InfoCollectionStatusReturn {
  305. System.Add_News(r.T_submit_uuid, fmt.Sprintf("【信息采集】您提交的信息采集【%s-%s】%s", user_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status]), "")
  306. System.Send_Weichat_News(AdminMap[r.T_submit_uuid], fmt.Sprintf("【信息采集】您提交的信息采集【%s-%s】%s", user_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status]), "")
  307. }
  308. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改状态", r)
  309. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  310. c.ServeJSON()
  311. return
  312. }
  313. // 退回记录列表
  314. func (c *InfoCollectionController) AuditRecordList() {
  315. // 验证登录 User_is, User_r
  316. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  317. if !User_is {
  318. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  319. c.ServeJSON()
  320. return
  321. }
  322. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  323. T_status, _ := c.GetInt("T_status")
  324. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  325. if !is {
  326. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  327. c.ServeJSON()
  328. return
  329. }
  330. var auditRecordList []InfoCollection.AuditRecord
  331. if len(r.T_audit_record) > 0 {
  332. err := json.Unmarshal([]byte(r.T_audit_record), &auditRecordList)
  333. if err != nil {
  334. logs.Error("JSON 反序列化失败:", err)
  335. return
  336. }
  337. }
  338. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  339. var auditRecordList2 []InfoCollection.AuditRecord
  340. if T_status == 0 {
  341. for i := 0; i < len(auditRecordList); i++ {
  342. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  343. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  344. }
  345. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  346. c.ServeJSON()
  347. return
  348. }
  349. for i := 0; i < len(auditRecordList); i++ {
  350. if auditRecordList[i].T_status == T_status {
  351. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  352. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  353. }
  354. }
  355. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  356. c.ServeJSON()
  357. return
  358. }
  359. // 信息采集统计
  360. func (c *InfoCollectionController) Statistics() {
  361. // 验证登录 User_is, User_r
  362. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  363. if !User_is {
  364. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  365. c.ServeJSON()
  366. return
  367. }
  368. 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)
  369. res := make(map[int]int)
  370. for k, _ := range InfoCollection.InfoCollectionStatusMap {
  371. res[k] = 0
  372. }
  373. res[0] = cnt
  374. for _, r := range List {
  375. res[r.T_status] += 1
  376. }
  377. c.Data["json"] = lib.JSONS{Data: res, Code: 200, Msg: "ok!"}
  378. c.ServeJSON()
  379. return
  380. }