infoCollection.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/lib/wx"
  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. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "添加", var_)
  146. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_InfoCollection_id}
  147. c.ServeJSON()
  148. return
  149. }
  150. // 修改-
  151. func (c *InfoCollectionController) Up() {
  152. // 验证登录 User_is, User_r
  153. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  154. if !User_is {
  155. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  156. c.ServeJSON()
  157. return
  158. }
  159. T_name := c.GetString("T_name")
  160. T_InfoTemplate_class := c.GetString("T_InfoTemplate_class")
  161. T_InfoTemplate_id := c.GetString("T_InfoTemplate_id")
  162. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  163. T_status, _ := c.GetInt("T_status")
  164. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  165. if !is {
  166. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  167. c.ServeJSON()
  168. return
  169. }
  170. // .......
  171. clos := make([]string, 0)
  172. if len(T_name) > 0 {
  173. r.T_name = T_name
  174. clos = append(clos, "T_name")
  175. }
  176. if T_status > 0 {
  177. r.T_status = T_status
  178. clos = append(clos, "T_status")
  179. }
  180. if len(T_InfoTemplate_class) > 0 {
  181. r.T_InfoTemplate_class = T_InfoTemplate_class
  182. clos = append(clos, "T_InfoTemplate_class")
  183. }
  184. if T_InfoTemplate_id != r.T_InfoTemplate_id {
  185. // 修改任务信息采集模版
  186. Task.Update_Task_T_InfoTemplate_id(T_InfoCollection_id, T_InfoTemplate_id)
  187. }
  188. if len(T_InfoTemplate_id) > 0 {
  189. r.T_InfoTemplate_id = T_InfoTemplate_id
  190. clos = append(clos, "T_InfoTemplate_id")
  191. }
  192. if !InfoCollection.Update_InfoCollection(r, clos...) {
  193. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  194. c.ServeJSON()
  195. return
  196. }
  197. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改", r)
  198. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  199. c.ServeJSON()
  200. return
  201. }
  202. // 删除-
  203. func (c *InfoCollectionController) Del() {
  204. // 验证登录 User_is, User_r
  205. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  206. if !User_is {
  207. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  208. c.ServeJSON()
  209. return
  210. }
  211. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  212. if r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id); is {
  213. if !InfoCollection.Delete_InfoCollection(r) {
  214. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  215. c.ServeJSON()
  216. return
  217. }
  218. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "删除", r)
  219. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  220. c.ServeJSON()
  221. return
  222. }
  223. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  224. c.ServeJSON()
  225. return
  226. }
  227. // 修改状态
  228. func (c *InfoCollectionController) UpStatus() {
  229. // 验证登录 User_is, User_r
  230. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  231. if !User_is {
  232. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  233. c.ServeJSON()
  234. return
  235. }
  236. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  237. T_status, _ := c.GetInt("T_status")
  238. T_reason := c.GetString("T_reason") //退回原因
  239. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  240. if !is {
  241. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  242. c.ServeJSON()
  243. return
  244. }
  245. //_, user_r := Account.Read_User_ByT_uuid(r.T_uuid)
  246. if T_status == InfoCollection.InfoCollectionStatusSubmitted && (r.T_status != InfoCollection.InfoCollectionStatusWaitSubmit && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  247. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  248. c.ServeJSON()
  249. return
  250. }
  251. if T_status == InfoCollection.InfoCollectionStatusReturnedMoney && r.T_status != InfoCollection.InfoCollectionStatusReceipt {
  252. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  253. c.ServeJSON()
  254. return
  255. }
  256. if T_status == InfoCollection.InfoCollectionStatusReturn && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReturn) {
  257. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  258. c.ServeJSON()
  259. return
  260. }
  261. if T_status == InfoCollection.InfoCollectionStatusReceipt && (r.T_status != InfoCollection.InfoCollectionStatusSubmitted && r.T_status != InfoCollection.InfoCollectionStatusReceipt) {
  262. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("当前状态为%s,禁止提交为%s", InfoCollection.InfoCollectionStatusMap[r.T_status], InfoCollection.InfoCollectionStatusMap[T_status])}
  263. c.ServeJSON()
  264. return
  265. }
  266. // 1待提交 2已提交 3已接收 4已退回 5已回款
  267. clos := make([]string, 0)
  268. if T_status > 0 {
  269. r.T_status = T_status
  270. clos = append(clos, "T_status")
  271. }
  272. // 2已提交 ,计算时间
  273. if T_status == InfoCollection.InfoCollectionStatusSubmitted {
  274. if len(r.T_end_time) == 0 {
  275. r.T_end_time = time.Now().Format("2006-01-02 15:04:05")
  276. r.T_time_interval, _ = lib.MinutesDifference(r.T_start_time, r.T_end_time)
  277. clos = append(clos, "T_end_time")
  278. clos = append(clos, "T_time_interval")
  279. }
  280. }
  281. if T_status == InfoCollection.InfoCollectionStatusReturn {
  282. r.T_return_times += 1
  283. clos = append(clos, "T_return_times")
  284. }
  285. var returnRecordList []InfoCollection.AuditRecord
  286. if len(r.T_audit_record) > 0 {
  287. err := json.Unmarshal([]byte(r.T_audit_record), &returnRecordList)
  288. if err != nil {
  289. logs.Error("JSON 反序列化失败:", err)
  290. return
  291. }
  292. }
  293. returnRecordList = append(returnRecordList, InfoCollection.AuditRecord{
  294. T_uuid: User_r.T_uuid,
  295. T_status: T_status,
  296. T_reason: T_reason,
  297. T_time: time.Now().Format("2006-01-02 15:04:05"),
  298. })
  299. returnRecordJson, err := json.Marshal(returnRecordList)
  300. if err != nil {
  301. logs.Error("JSON 反序列化失败:", err)
  302. return
  303. }
  304. r.T_audit_record = string(returnRecordJson)
  305. clos = append(clos, "T_audit_record")
  306. if !InfoCollection.Update_InfoCollection(r, clos...) {
  307. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  308. c.ServeJSON()
  309. return
  310. }
  311. //AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  312. _, company_r := Account.Read_User_ByT_uuid(r.T_uuid)
  313. // 已提交 [报告负责人]
  314. if T_status == InfoCollection.InfoCollectionStatusSubmitted {
  315. go wx.WxSend(conf.VdelUuid, fmt.Sprintf("【%s-%s】信息采集 %s", company_r.T_name, r.T_name, InfoCollection.InfoCollectionStatusMap[T_status]))
  316. }
  317. // 已退回
  318. if T_status == InfoCollection.InfoCollectionStatusReturn {
  319. 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), "")
  320. 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))
  321. }
  322. if T_status == InfoCollection.InfoCollectionStatusReturnedMoney {
  323. go wx.WxSend(conf.BoosUuid, fmt.Sprintf("【%s-%s】已回款", company_r.T_name, r.T_name))
  324. }
  325. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "修改状态", r)
  326. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  327. c.ServeJSON()
  328. return
  329. }
  330. // 退回记录列表
  331. func (c *InfoCollectionController) AuditRecordList() {
  332. // 验证登录 User_is, User_r
  333. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  334. if !User_is {
  335. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  336. c.ServeJSON()
  337. return
  338. }
  339. T_InfoCollection_id := c.GetString("T_InfoCollection_id")
  340. T_status, _ := c.GetInt("T_status")
  341. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  342. if !is {
  343. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  344. c.ServeJSON()
  345. return
  346. }
  347. var auditRecordList []InfoCollection.AuditRecord
  348. if len(r.T_audit_record) > 0 {
  349. err := json.Unmarshal([]byte(r.T_audit_record), &auditRecordList)
  350. if err != nil {
  351. logs.Error("JSON 反序列化失败:", err)
  352. return
  353. }
  354. }
  355. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  356. var auditRecordList2 []InfoCollection.AuditRecord
  357. if T_status == 0 {
  358. for i := 0; i < len(auditRecordList); i++ {
  359. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  360. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  361. }
  362. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  363. c.ServeJSON()
  364. return
  365. }
  366. for i := 0; i < len(auditRecordList); i++ {
  367. if auditRecordList[i].T_status == T_status {
  368. auditRecordList[i].T_uuid_name = AdminMap[auditRecordList[i].T_uuid]
  369. auditRecordList2 = append(auditRecordList2, auditRecordList[i])
  370. }
  371. }
  372. c.Data["json"] = lib.JSONS{Data: auditRecordList2, Code: 200, Msg: "ok!"}
  373. c.ServeJSON()
  374. return
  375. }
  376. // 信息采集统计
  377. func (c *InfoCollectionController) Statistics() {
  378. // 验证登录 User_is, User_r
  379. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  380. if !User_is {
  381. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  382. c.ServeJSON()
  383. return
  384. }
  385. 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)
  386. res := make(map[int]int)
  387. for k, _ := range InfoCollection.InfoCollectionStatusMap {
  388. res[k] = 0
  389. }
  390. res[0] = cnt
  391. for _, r := range List {
  392. res[r.T_status] += 1
  393. }
  394. c.Data["json"] = lib.JSONS{Data: res, Code: 200, Msg: "ok!"}
  395. c.ServeJSON()
  396. return
  397. }
  398. // 修改-
  399. func (c *InfoCollectionController) Copy() {
  400. // 验证登录 User_is, User_r
  401. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  402. if !User_is {
  403. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  404. c.ServeJSON()
  405. return
  406. }
  407. T_name := c.GetString("T_name")
  408. T_InfoCollection_id := c.GetString("T_InfoCollection_id") // 信息采集id
  409. r, is := InfoCollection.Read_InfoCollection(T_InfoCollection_id)
  410. if !is {
  411. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  412. c.ServeJSON()
  413. return
  414. }
  415. var_ := InfoCollection.InfoCollection{
  416. T_uuid: r.T_uuid,
  417. T_name: T_name,
  418. T_InfoTemplate_class: r.T_InfoTemplate_class,
  419. T_InfoTemplate_id: r.T_InfoTemplate_id,
  420. T_status: 1,
  421. T_State: 1,
  422. T_submit_uuid: User_r.T_uuid,
  423. }
  424. T_InfoCollection_id, err := InfoCollection.Add_InfoCollection(var_)
  425. if err != nil {
  426. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  427. c.ServeJSON()
  428. return
  429. }
  430. System.Add_UserLogs_T(User_r.T_uuid, "信息采集管理", "复制", r)
  431. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  432. c.ServeJSON()
  433. return
  434. }