VerifyTemplate.go 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127
  1. package controllers
  2. import (
  3. "ColdVerify_server/conf"
  4. "ColdVerify_server/lib"
  5. "ColdVerify_server/logs"
  6. "ColdVerify_server/models/Account"
  7. "ColdVerify_server/models/System"
  8. "ColdVerify_server/models/Task"
  9. "ColdVerify_server/models/VerifyTemplate"
  10. "encoding/json"
  11. "fmt"
  12. beego "github.com/beego/beego/v2/server/web"
  13. "math"
  14. "strconv"
  15. "strings"
  16. )
  17. type VerifyTemplateController struct {
  18. beego.Controller
  19. User_r Account.Admin // 登陆的用户
  20. }
  21. func (c *VerifyTemplateController) Prepare() {
  22. GetCookie := c.Ctx.GetCookie("User_tokey")
  23. GetString := c.GetString("User_tokey")
  24. fmt.Println(c.Ctx.Request.URL.Path)
  25. if strings.Contains(c.Ctx.Request.URL.Path, "/VerifyTemplateMapData/Pu") {
  26. return
  27. }
  28. // 验证登录 User_is, User_r
  29. User_r, User_is := Account.Verification_Admin(GetCookie, GetString)
  30. if !User_is {
  31. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  32. c.ServeJSON()
  33. return
  34. }
  35. // 经销商只能访问列表接口,不能操作
  36. //if len(User_r.T_Distributor_id) > 0 {
  37. // checkUrl := []string{"Add", "Up", "Del"}
  38. // for _, v := range checkUrl {
  39. // if strings.Contains(c.Ctx.Request.URL.Path, v) {
  40. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "没有操作权限!"}
  41. // c.ServeJSON()
  42. // return
  43. // }
  44. // }
  45. //}
  46. c.User_r = User_r
  47. }
  48. // 列表 -
  49. func (c *VerifyTemplateController) List() {
  50. // 验证登录 User_is, User_r
  51. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  52. if !User_is {
  53. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  54. c.ServeJSON()
  55. return
  56. }
  57. var r_jsons lib.R_JSONS
  58. page, _ := c.GetInt("page")
  59. if page < 1 {
  60. page = 1
  61. }
  62. page_z, _ := c.GetInt("page_z")
  63. if page_z < 1 {
  64. page_z = conf.Page_size
  65. }
  66. T_class, _ := c.GetInt("T_class")
  67. if T_class <= 0 {
  68. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_class Err!"}
  69. c.ServeJSON()
  70. return
  71. }
  72. T_name := c.GetString("T_name")
  73. logs.Debug("经销商id", User_r.T_Distributor_id)
  74. // Fixme 经销商只能获取绑定的验证模版 绑定功能做好之后再打开此注释
  75. //if len(User_r.T_Distributor_id) > 0 {
  76. // var cnt int64
  77. // List, cnt := Distributor.Read_DistributorVerifyTemplate_List(User_r.T_Distributor_id, T_class, T_name, page, page_z)
  78. // page_size := math.Ceil(float64(cnt) / float64(page_z))
  79. // r_jsons.List = List
  80. // r_jsons.Page = page
  81. // r_jsons.Page_size = int(page_size)
  82. // r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  83. // r_jsons.Num = int(cnt)
  84. //
  85. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  86. // c.ServeJSON()
  87. // return
  88. //}
  89. var cnt int64
  90. List, cnt := VerifyTemplate.Read_VerifyTemplate_List(T_class, T_name, page, page_z)
  91. page_size := math.Ceil(float64(cnt) / float64(page_z))
  92. r_jsons.List = List
  93. r_jsons.Page = page
  94. r_jsons.Page_size = int(page_size)
  95. r_jsons.Pages = lib.Func_page(int64(page), int64(page_size))
  96. r_jsons.Num = int(cnt)
  97. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  98. c.ServeJSON()
  99. return
  100. }
  101. // 添加-
  102. func (c *VerifyTemplateController) Add() {
  103. // 验证登录 User_is, User_r
  104. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  105. if !User_is {
  106. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  107. c.ServeJSON()
  108. return
  109. }
  110. T_name := c.GetString("T_name")
  111. T_sort, _ := c.GetInt("T_sort")
  112. T_class, _ := c.GetInt("T_class")
  113. var_ := VerifyTemplate.VerifyTemplate{
  114. T_class: T_class,
  115. T_name: T_name,
  116. T_sort: T_sort,
  117. }
  118. Id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  119. if !is {
  120. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  121. c.ServeJSON()
  122. return
  123. }
  124. System.Add_UserLogs_T(User_r.T_uuid, "验证模版", "添加", var_)
  125. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  126. c.ServeJSON()
  127. return
  128. }
  129. // 修改-
  130. func (c *VerifyTemplateController) Up() {
  131. // 验证登录 User_is, User_r
  132. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  133. if !User_is {
  134. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  135. c.ServeJSON()
  136. return
  137. }
  138. T_name := c.GetString("T_name")
  139. T_sort, T_sort_err := c.GetInt("T_sort")
  140. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  141. T_scheme := c.GetString("T_scheme")
  142. T_reporting := c.GetString("T_reporting")
  143. T_inspect := c.GetString("T_inspect")
  144. T_marking := c.GetString("T_marking")
  145. T_cover := c.GetString("T_cover")
  146. T_deploy := c.GetString("T_deploy")
  147. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  148. if !is {
  149. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  150. c.ServeJSON()
  151. return
  152. }
  153. // .......
  154. if len(T_name) > 0 {
  155. r.T_name = T_name
  156. }
  157. if len(T_scheme) > 0 {
  158. r.T_scheme = T_scheme
  159. }
  160. if len(T_reporting) > 0 {
  161. r.T_reporting = T_reporting
  162. }
  163. if len(T_inspect) > 0 {
  164. r.T_inspect = T_inspect
  165. }
  166. if len(T_marking) > 0 {
  167. r.T_marking = T_marking
  168. }
  169. if len(T_cover) > 0 {
  170. r.T_cover = T_cover
  171. }
  172. if len(T_deploy) > 0 {
  173. var deployList []VerifyTemplate.VerifyTemplateDeploy
  174. // 将 布点1|布点2|布点3| 格式替换为 [{"T_name":"布点1","T_scope":"布点范围1"},{"T_name":"布点2","T_scope":"布点范围2"}]
  175. if strings.Contains(T_deploy, "|") {
  176. deploys := strings.Split(strings.Trim(T_deploy, "|"), "|")
  177. for _, v := range deploys {
  178. deployList = append(deployList, VerifyTemplate.VerifyTemplateDeploy{T_name: v})
  179. }
  180. deploy, err := json.Marshal(deployList)
  181. if err != nil {
  182. logs.Error("JSON 序列化失败:", err)
  183. return
  184. }
  185. T_deploy = string(deploy)
  186. } else {
  187. err := json.Unmarshal([]byte(T_deploy), &deployList)
  188. if err != nil {
  189. logs.Error("JSON 反序列化失败:", err)
  190. return
  191. }
  192. }
  193. r.T_deploy = T_deploy
  194. }
  195. if T_sort_err == nil {
  196. r.T_sort = T_sort
  197. }
  198. // .......
  199. if !VerifyTemplate.Update_VerifyTemplate(r, "T_name", "T_sort", "T_scheme", "T_reporting", "T_inspect", "T_marking", "T_cover", "T_deploy") {
  200. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  201. c.ServeJSON()
  202. return
  203. }
  204. System.Add_UserLogs_T(User_r.T_uuid, "验证模版", "修改", r)
  205. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  206. c.ServeJSON()
  207. return
  208. }
  209. // 删除-
  210. func (c *VerifyTemplateController) Del() {
  211. // 验证登录 User_is, User_r
  212. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  213. if !User_is {
  214. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  215. c.ServeJSON()
  216. return
  217. }
  218. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  219. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  220. if !is {
  221. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  222. c.ServeJSON()
  223. return
  224. }
  225. if !VerifyTemplate.Delete_VerifyTemplate(r) {
  226. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  227. c.ServeJSON()
  228. return
  229. }
  230. mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0)
  231. for _, v := range mapList {
  232. if vtm, is := VerifyTemplate.Read_VerifyTemplateMap(v.T_id); is {
  233. VerifyTemplate.Delete_VerifyTemplateMap(vtm)
  234. }
  235. }
  236. System.Add_UserLogs_T(User_r.T_uuid, "验证模版", "删除", r)
  237. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  238. c.ServeJSON()
  239. return
  240. }
  241. // 删除-
  242. func (c *VerifyTemplateController) Get() {
  243. // 验证登录 User_is, User_r
  244. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  245. if !User_is {
  246. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  247. c.ServeJSON()
  248. return
  249. }
  250. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  251. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  252. if !is {
  253. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  254. c.ServeJSON()
  255. return
  256. }
  257. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.VerifyTemplateToVerifyTemplate_R(r)}
  258. c.ServeJSON()
  259. return
  260. }
  261. // 复制-
  262. func (c *VerifyTemplateController) Copy() {
  263. // 验证登录 User_is, User_r
  264. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  265. if !User_is {
  266. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  267. c.ServeJSON()
  268. return
  269. }
  270. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  271. T_name := c.GetString("T_name")
  272. r, is := VerifyTemplate.Read_VerifyTemplate(T_VerifyTemplate_id)
  273. if !is {
  274. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  275. c.ServeJSON()
  276. return
  277. }
  278. var_ := VerifyTemplate.VerifyTemplate{
  279. T_class: r.T_class,
  280. T_name: T_name,
  281. T_sort: r.T_sort,
  282. T_deploy: r.T_deploy,
  283. }
  284. new_id, is := VerifyTemplate.Add_VerifyTemplate(var_)
  285. if !is {
  286. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  287. c.ServeJSON()
  288. return
  289. }
  290. mapList, _ := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, 0, 0)
  291. tempMap := make(map[string]struct{})
  292. idList := make([]string, len(mapList))
  293. // 生成mapList长度的T_id
  294. for i := 0; i < len(mapList); i++ {
  295. // 生成编号
  296. rand_x := 0
  297. T_id := ""
  298. for true {
  299. T_id = lib.GetRandstring(4, "", int64(rand_x))
  300. _, is = VerifyTemplate.Read_VerifyTemplateMap(T_id)
  301. if !is {
  302. if _, ok := tempMap[T_id]; !ok {
  303. break
  304. }
  305. }
  306. rand_x += 1
  307. }
  308. tempMap[T_id] = struct{}{}
  309. idList[i] = T_id
  310. }
  311. mapInsertList := make([]VerifyTemplate.VerifyTemplateMap, 0)
  312. for i, v := range mapList {
  313. vtm := VerifyTemplate.VerifyTemplateMap{
  314. T_id: idList[i],
  315. T_VerifyTemplate_id: new_id,
  316. T_name: v.T_name,
  317. T_text: v.T_text,
  318. T_label: v.T_label,
  319. T_source: v.T_source,
  320. T_sort: v.T_sort,
  321. T_Required: v.T_Required,
  322. T_Construction: v.T_Construction,
  323. T_flow_sort: v.T_flow_sort,
  324. T_max_time: v.T_max_time,
  325. T_min_time: v.T_min_time,
  326. }
  327. mapInsertList = append(mapInsertList, vtm)
  328. }
  329. _, is = VerifyTemplate.Add_VerifyTemplateMapMulti(mapInsertList)
  330. if !is {
  331. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制失败!"}
  332. c.ServeJSON()
  333. return
  334. }
  335. System.Add_UserLogs_T(User_r.T_uuid, "验证模版", "复制", var_)
  336. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: new_id}
  337. c.ServeJSON()
  338. return
  339. }
  340. /// -----------------------------------------------------------------------------
  341. // 标签列表 -
  342. func (c *VerifyTemplateController) Map_List() {
  343. // 验证登录 User_is, User_r
  344. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  345. if !User_is {
  346. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  347. c.ServeJSON()
  348. return
  349. }
  350. var r_jsons lib.R_JSONS
  351. // page, _ := c.GetInt("page")
  352. //
  353. // if page < 1 {
  354. // page = 1
  355. // }
  356. //
  357. // page_z, _ := c.GetInt("page_z")
  358. //
  359. // if page_z < 1 {
  360. // page_z = conf.Page_size
  361. // }
  362. T_sort, _ := c.GetInt("T_sort") // 排序
  363. T_flow_sort, _ := c.GetInt("T_flow_sort") // 验证流程排序
  364. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  365. var cnt int64
  366. List, cnt := VerifyTemplate.Read_VerifyTemplateMap_List(T_VerifyTemplate_id, T_sort, T_flow_sort)
  367. r_jsons.List = List
  368. r_jsons.Num = int(cnt)
  369. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  370. c.ServeJSON()
  371. return
  372. }
  373. // 标签添加-
  374. func (c *VerifyTemplateController) Map_Add() {
  375. // 验证登录 User_is, User_r
  376. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  377. if !User_is {
  378. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  379. c.ServeJSON()
  380. return
  381. }
  382. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  383. T_name := c.GetString("T_name")
  384. T_text := c.GetString("T_text")
  385. T_label, _ := c.GetInt("T_label")
  386. T_source, _ := c.GetInt("T_source")
  387. T_sort, _ := c.GetInt("T_sort")
  388. T_Required, _ := c.GetInt("T_Required")
  389. T_Construction, _ := c.GetInt("T_Construction")
  390. T_flow_sort, _ := c.GetInt("T_flow_sort")
  391. T_max_time, _ := c.GetInt("T_max_time")
  392. T_min_time, _ := c.GetInt("T_min_time")
  393. var_ := VerifyTemplate.VerifyTemplateMap{
  394. T_VerifyTemplate_id: T_VerifyTemplate_id,
  395. T_name: T_name,
  396. T_text: T_text,
  397. T_label: T_label,
  398. T_source: T_source,
  399. T_sort: T_sort,
  400. T_Required: T_Required,
  401. T_Construction: T_Construction,
  402. T_flow_sort: T_flow_sort,
  403. T_max_time: T_max_time,
  404. T_min_time: T_min_time,
  405. }
  406. Id, is := VerifyTemplate.Add_VerifyTemplateMap(var_)
  407. if !is {
  408. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  409. c.ServeJSON()
  410. return
  411. }
  412. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签", "添加", var_)
  413. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  414. c.ServeJSON()
  415. return
  416. }
  417. // 标签修改-
  418. func (c *VerifyTemplateController) Map_Up() {
  419. // 验证登录 User_is, User_r
  420. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  421. if !User_is {
  422. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  423. c.ServeJSON()
  424. return
  425. }
  426. T_name := c.GetString("T_name")
  427. T_text := c.GetString("T_text")
  428. T_label, T_label_err := c.GetInt("T_label")
  429. T_sort, T_sort_err := c.GetInt("T_sort")
  430. T_source, T_source_err := c.GetInt("T_source")
  431. T_Required, _ := c.GetInt("T_Required")
  432. T_Construction, _ := c.GetInt("T_Construction")
  433. T_min_time, T_min_time_err := c.GetInt("T_min_time")
  434. T_max_time, T_max_time_err := c.GetInt("T_max_time")
  435. T_flow_sort, T_flow_sort_err := c.GetInt("T_flow_sort")
  436. T_id := c.GetString("T_id")
  437. r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id)
  438. if !is {
  439. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  440. c.ServeJSON()
  441. return
  442. }
  443. // .......
  444. if len(T_name) > 0 {
  445. r.T_name = T_name
  446. }
  447. if len(T_text) > 0 {
  448. r.T_text = T_text
  449. }
  450. if T_label_err == nil {
  451. r.T_label = T_label
  452. }
  453. if T_sort_err == nil {
  454. r.T_sort = T_sort
  455. }
  456. if T_source_err == nil {
  457. r.T_source = T_source
  458. }
  459. if T_min_time_err == nil {
  460. r.T_min_time = T_min_time
  461. }
  462. if T_max_time_err == nil {
  463. r.T_max_time = T_max_time
  464. }
  465. if T_flow_sort_err == nil {
  466. r.T_flow_sort = T_flow_sort
  467. }
  468. r.T_Required = T_Required
  469. r.T_Construction = T_Construction
  470. if !VerifyTemplate.Update_VerifyTemplateMap(r, "T_name", "T_label", "T_text", "T_sort", "T_source", "T_min_time", "T_max_time", "T_flow_sort", "T_Required", "T_Construction") {
  471. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  472. c.ServeJSON()
  473. return
  474. }
  475. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签", "修改", r)
  476. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  477. c.ServeJSON()
  478. return
  479. }
  480. // 标签删除-
  481. func (c *VerifyTemplateController) Map_Del() {
  482. // 验证登录 User_is, User_r
  483. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  484. if !User_is {
  485. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  486. c.ServeJSON()
  487. return
  488. }
  489. T_id := c.GetString("T_id")
  490. if r, is := VerifyTemplate.Read_VerifyTemplateMap(T_id); is {
  491. if !VerifyTemplate.Delete_VerifyTemplateMap(r) {
  492. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  493. c.ServeJSON()
  494. return
  495. }
  496. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签", "删除", r)
  497. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  498. c.ServeJSON()
  499. return
  500. }
  501. c.Data["json"] = lib.JSONS{Code: 202, Msg: "Id 错误!"}
  502. c.ServeJSON()
  503. return
  504. }
  505. /// -----------------------------------------------------------------------------
  506. // 标签数据列表 -
  507. func (c *VerifyTemplateController) Map_Data_List() {
  508. // 验证登录 User_is, User_r
  509. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  510. if !User_is {
  511. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  512. c.ServeJSON()
  513. return
  514. }
  515. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  516. T_source, _ := c.GetInt("T_source")
  517. T_flow, _ := c.GetInt("T_flow") // app 时间流程
  518. if T_flow == 0 && T_source == 0 {
  519. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  520. c.ServeJSON()
  521. return
  522. }
  523. T_task_id := c.GetString("T_task_id")
  524. task, is := Task.Read_Task(T_task_id)
  525. if !is {
  526. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  527. c.ServeJSON()
  528. return
  529. }
  530. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(T_VerifyTemplate_id, T_source, T_flow)
  531. Data := VerifyTemplate.Read_VerifyTemplateMapData_List(T_source, T_task_id, T_VerifyTemplate_id, Map_List)
  532. type JSONS struct {
  533. //必须的大写开头
  534. Code int16
  535. Msg string
  536. Data interface{} // 泛型
  537. T_step int
  538. }
  539. c.Data["json"] = JSONS{Code: 200, Msg: "ok!", Data: Data, T_step: task.T_step}
  540. c.ServeJSON()
  541. return
  542. }
  543. // 添加标签数据
  544. func (c *VerifyTemplateController) Map_Data_Pu() {
  545. //验证登录 User_is, User_r
  546. var err error
  547. //token := c.Ctx.Request.Header.Get("user_tokey")
  548. //User_r, User_is := Account.Verification_Admin(token, "")
  549. //if !User_is {
  550. // c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  551. // c.ServeJSON()
  552. // return
  553. //}
  554. //err = albb.DescribeInstances()
  555. ////err := RunInstances(tea.StringSlice(os.Args[1:]))
  556. //if err != nil {
  557. // c.Data["json"] = lib.JSONS{Code: 202, Msg: "服务启动失败!"}
  558. // c.ServeJSON()
  559. // return
  560. //}
  561. type RequestBody struct {
  562. User_tokey string
  563. T_source int
  564. T_task_id string
  565. T_VerifyTemplate_id string
  566. T_step int // 进行步骤下标
  567. VerifyTemplateMapData []VerifyTemplate.VerifyTemplateMapData_R
  568. }
  569. var body RequestBody
  570. data := c.Ctx.Input.RequestBody
  571. err = json.Unmarshal(data, &body)
  572. if err != nil {
  573. c.Data["json"] = lib.JSONS{Code: 202, Msg: "json返序列化失败:" + err.Error()}
  574. c.ServeJSON()
  575. }
  576. User_r, User_is := Account.Verification_Admin(body.User_tokey, "")
  577. if !User_is {
  578. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "未登录-保存", body)
  579. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  580. c.ServeJSON()
  581. return
  582. }
  583. task, is := Task.Read_Task(body.T_task_id)
  584. if !is {
  585. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  586. c.ServeJSON()
  587. return
  588. }
  589. task.T_step = body.T_step
  590. if !Task.Update_Task(task, "T_step") {
  591. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改任务步骤失败!"}
  592. c.ServeJSON()
  593. return
  594. }
  595. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  596. for _, v := range body.VerifyTemplateMapData {
  597. val := VerifyTemplate.VerifyTemplateMapData{
  598. T_source: v.T_source,
  599. T_task_id: body.T_task_id,
  600. T_VerifyTemplate_id: body.T_VerifyTemplate_id,
  601. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  602. T_Required: v.T_Required,
  603. T_Construction: v.T_Construction,
  604. T_flow_sort: v.T_flow_sort,
  605. T_max_time: v.T_max_time,
  606. T_min_time: v.T_min_time,
  607. T_value: v.T_value,
  608. T_start_time: v.T_start_time,
  609. }
  610. MapDataList = append(MapDataList, val)
  611. }
  612. ids, is := VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, body.T_source, User_r.T_uuid)
  613. if !is {
  614. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  615. c.ServeJSON()
  616. return
  617. }
  618. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "保存", body)
  619. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  620. c.ServeJSON()
  621. return
  622. }
  623. func (c *VerifyTemplateController) Map_Data_Copy() {
  624. // 验证登录 User_is, User_r
  625. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  626. if !User_is {
  627. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  628. c.ServeJSON()
  629. return
  630. }
  631. T_source, _ := c.GetInt("T_source")
  632. T_flow, _ := c.GetInt("T_flow")
  633. if T_flow == 0 && T_source == 0 {
  634. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  635. c.ServeJSON()
  636. return
  637. }
  638. T_copy_task_id := c.GetString("T_copy_task_id")
  639. copy_task, is := Task.Read_Task(T_copy_task_id)
  640. if !is {
  641. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_copy_task_id 错误!"}
  642. c.ServeJSON()
  643. return
  644. }
  645. T_paste_task_id := c.GetString("T_paste_task_id")
  646. paste_task, is := Task.Read_Task(T_paste_task_id)
  647. if !is {
  648. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_paste_task_id 错误!"}
  649. c.ServeJSON()
  650. return
  651. }
  652. if copy_task.T_VerifyTemplate_id != paste_task.T_VerifyTemplate_id {
  653. c.Data["json"] = lib.JSONS{Code: 202, Msg: "仅支持相同模版间复制!"}
  654. c.ServeJSON()
  655. return
  656. }
  657. list := VerifyTemplate.Read_MapData_List(T_source, T_copy_task_id, copy_task.T_VerifyTemplate_id)
  658. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  659. for _, v := range list {
  660. val := VerifyTemplate.VerifyTemplateMapData{
  661. T_source: T_source,
  662. T_task_id: paste_task.T_task_id,
  663. T_VerifyTemplate_id: paste_task.T_VerifyTemplate_id,
  664. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  665. T_Required: v.T_Required,
  666. T_Construction: v.T_Construction,
  667. T_flow_sort: v.T_flow_sort,
  668. T_max_time: v.T_max_time,
  669. T_min_time: v.T_min_time,
  670. T_value: v.T_value,
  671. }
  672. MapDataList = append(MapDataList, val)
  673. }
  674. var ids []int64
  675. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData_ADD_History(MapDataList, T_source, User_r.T_uuid)
  676. if !is {
  677. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  678. c.ServeJSON()
  679. return
  680. }
  681. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "复制", MapDataList)
  682. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  683. c.ServeJSON()
  684. return
  685. }
  686. // 添加标签数据
  687. func (c *VerifyTemplateController) Map_Data_History_List() {
  688. // 验证登录 User_is, User_r
  689. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  690. if !User_is {
  691. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  692. c.ServeJSON()
  693. return
  694. }
  695. T_task_id := c.GetString("T_task_id")
  696. T_source, _ := c.GetInt("T_source")
  697. _, is := Task.Read_Task(T_task_id)
  698. if !is {
  699. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  700. c.ServeJSON()
  701. return
  702. }
  703. AdminMap := Account.AdminListToMap(Account.Read_Admin_List_ALL_1())
  704. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateMapDataHistory_History_List(T_task_id, T_source, AdminMap)}
  705. c.ServeJSON()
  706. return
  707. }
  708. // 标签数据列表 -
  709. func (c *VerifyTemplateController) Map_Data_History_Data_List() {
  710. // 验证登录 User_is, User_r
  711. _, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  712. if !User_is {
  713. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  714. c.ServeJSON()
  715. return
  716. }
  717. T_time := c.GetString("T_time")
  718. if len(T_time) == 0 {
  719. c.Data["json"] = lib.JSONS{Code: 202, Msg: "请选择时间点!"}
  720. c.ServeJSON()
  721. return
  722. }
  723. T_source, _ := c.GetInt("T_source")
  724. if T_source == 0 {
  725. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  726. c.ServeJSON()
  727. return
  728. }
  729. T_task_id := c.GetString("T_task_id")
  730. task, is := Task.Read_Task(T_task_id)
  731. if !is {
  732. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  733. c.ServeJSON()
  734. return
  735. }
  736. Map_List := VerifyTemplate.Read_VerifyTemplateMap_List_For_Data(task.T_VerifyTemplate_id, T_source, 0)
  737. Data := VerifyTemplate.Read_VerifyTemplateMapDataHistory_List(T_source, T_task_id, task.T_VerifyTemplate_id, T_time, Map_List)
  738. type JSONS struct {
  739. //必须的大写开头
  740. Code int16
  741. Msg string
  742. Data interface{} // 泛型
  743. T_step int
  744. }
  745. c.Data["json"] = JSONS{Code: 200, Msg: "ok!", Data: Data, T_step: task.T_step}
  746. c.ServeJSON()
  747. return
  748. }
  749. // 清除数据
  750. func (c *VerifyTemplateController) Map_Data_Clear_Value() {
  751. // 验证登录 User_is, User_r
  752. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  753. if !User_is {
  754. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  755. c.ServeJSON()
  756. return
  757. }
  758. T_VerifyTemplate_id := c.GetString("T_VerifyTemplate_id")
  759. T_VerifyTemplateMap_id := c.GetString("T_VerifyTemplateMap_id")
  760. T_task_id := c.GetString("T_task_id")
  761. _, is := Task.Read_Task(T_task_id)
  762. if !is {
  763. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  764. c.ServeJSON()
  765. return
  766. }
  767. VerifyTemplate.Clear_VerifyTemplateMapData_T_value(T_task_id, T_VerifyTemplate_id, T_VerifyTemplateMap_id)
  768. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "清除数据", fmt.Sprintf("T_task_id:%s T_VerifyTemplate_id:%s T_VerifyTemplateMap_id:%s", T_task_id, T_VerifyTemplate_id, T_VerifyTemplateMap_id))
  769. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  770. c.ServeJSON()
  771. return
  772. }
  773. // 历史数据恢复
  774. func (c *VerifyTemplateController) Map_Data_History_Recover() {
  775. // 验证登录 User_is, User_r
  776. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  777. if !User_is {
  778. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  779. c.ServeJSON()
  780. return
  781. }
  782. T_time := c.GetString("T_time")
  783. if len(T_time) == 0 {
  784. c.Data["json"] = lib.JSONS{Code: 202, Msg: "请选择时间点!"}
  785. c.ServeJSON()
  786. return
  787. }
  788. T_source, _ := c.GetInt("T_source")
  789. if T_source == 0 {
  790. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_source Err!"}
  791. c.ServeJSON()
  792. return
  793. }
  794. T_task_id := c.GetString("T_task_id")
  795. task, is := Task.Read_Task(T_task_id)
  796. if !is {
  797. c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_task_id 错误!"}
  798. c.ServeJSON()
  799. return
  800. }
  801. HistoryList := VerifyTemplate.Read_MapDataHistory_List(T_source, T_task_id, task.T_VerifyTemplate_id, T_time)
  802. list := VerifyTemplate.Read_MapData_List(T_source, T_task_id, task.T_VerifyTemplate_id)
  803. HistoryListMap := make(map[string]VerifyTemplate.VerifyTemplateMapDataHistory)
  804. for _, data := range HistoryList {
  805. HistoryListMap[data.T_VerifyTemplateMap_id] = data
  806. }
  807. MapDataList := make([]VerifyTemplate.VerifyTemplateMapData, 0)
  808. for _, v := range list {
  809. if len(v.T_value) > 0 {
  810. continue
  811. }
  812. if HistoryListMap[v.T_VerifyTemplateMap_id].T_value == "" {
  813. continue
  814. }
  815. val := VerifyTemplate.VerifyTemplateMapData{
  816. T_source: T_source,
  817. T_task_id: task.T_task_id,
  818. T_VerifyTemplate_id: task.T_VerifyTemplate_id,
  819. T_VerifyTemplateMap_id: v.T_VerifyTemplateMap_id,
  820. T_Required: v.T_Required,
  821. T_Construction: v.T_Construction,
  822. T_flow_sort: v.T_flow_sort,
  823. T_max_time: v.T_max_time,
  824. T_min_time: v.T_min_time,
  825. T_value: HistoryListMap[v.T_VerifyTemplateMap_id].T_value,
  826. }
  827. MapDataList = append(MapDataList, val)
  828. }
  829. var ids []int64
  830. ids, is = VerifyTemplate.AddOrUpdate_VerifyTemplateMapData(MapDataList)
  831. if !is {
  832. c.Data["json"] = lib.JSONS{Code: 202, Msg: "保存失败"}
  833. c.ServeJSON()
  834. return
  835. }
  836. System.Add_UserLogs_T(User_r.T_uuid, "验证模版标签数据", "恢复", MapDataList)
  837. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: ids}
  838. c.ServeJSON()
  839. return
  840. }
  841. func (c *VerifyTemplateController) Class_List() {
  842. // 验证登录 User_is, User_r
  843. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  844. if !User_is {
  845. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  846. c.ServeJSON()
  847. return
  848. }
  849. logs.Debug("经销商id", User_r.T_Distributor_id)
  850. // Fixme 经销商只能获取绑定的验证模版分类 绑定功能做好之后再打开此注释
  851. //if len(User_r.T_Distributor_id) > 0 {
  852. // c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Distributor.Read_DistributorVerifyTemplateClass_List(User_r.T_Distributor_id)}
  853. // c.ServeJSON()
  854. // return
  855. //}
  856. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: VerifyTemplate.Read_VerifyTemplateClass_List()}
  857. c.ServeJSON()
  858. return
  859. }
  860. func (c *VerifyTemplateController) Class_Add() {
  861. // 验证登录 User_is, User_r
  862. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  863. if !User_is {
  864. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  865. c.ServeJSON()
  866. return
  867. }
  868. T_name := c.GetString("T_name")
  869. T_fid, _ := c.GetInt("T_fid")
  870. var_ := VerifyTemplate.VerifyTemplateClass{
  871. T_name: T_name,
  872. T_fid: T_fid,
  873. T_State: 1,
  874. }
  875. Id, err := VerifyTemplate.Add_VerifyTemplateClass(var_)
  876. if err != nil {
  877. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  878. c.ServeJSON()
  879. return
  880. }
  881. System.Add_UserLogs_T(User_r.T_uuid, "模版分类", "添加", var_)
  882. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  883. c.ServeJSON()
  884. return
  885. }
  886. func (c *VerifyTemplateController) Class_Up() {
  887. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  888. if !User_is {
  889. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  890. c.ServeJSON()
  891. return
  892. }
  893. T_id, _ := c.GetInt("T_id")
  894. T_name := c.GetString("T_name")
  895. R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id)
  896. if err != nil {
  897. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  898. c.ServeJSON()
  899. return
  900. }
  901. if len(T_name) > 0 {
  902. R_VerifyTemplateToolClass.T_name = T_name
  903. }
  904. if is := VerifyTemplate.Update_VerifyTemplateClass(R_VerifyTemplateToolClass, "T_name"); !is {
  905. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  906. c.ServeJSON()
  907. return
  908. }
  909. System.Add_UserLogs_T(User_r.T_uuid, "模版分类", "修改", R_VerifyTemplateToolClass)
  910. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  911. c.ServeJSON()
  912. return
  913. }
  914. func (c *VerifyTemplateController) Class_Del() {
  915. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  916. if !User_is {
  917. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  918. c.ServeJSON()
  919. return
  920. }
  921. T_id, _ := c.GetInt("T_id")
  922. R_VerifyTemplateToolClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id)
  923. if err != nil {
  924. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  925. c.ServeJSON()
  926. return
  927. }
  928. ids := VerifyTemplate.ReadVerifyTemplateClassIds_T_path(R_VerifyTemplateToolClass.T_path)
  929. if is := VerifyTemplate.Delete_VerifyTemplateClass_ByIds(ids); !is {
  930. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  931. c.ServeJSON()
  932. return
  933. }
  934. System.Add_UserLogs(User_r.T_uuid, "模版分类", "删除", strconv.Itoa(T_id))
  935. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  936. c.ServeJSON()
  937. return
  938. }
  939. // 复制验证模版-分类-标签
  940. func (c *VerifyTemplateController) Class_Copy() {
  941. // 验证登录 User_is, User_r
  942. User_r, User_is := Account.Verification_Admin(c.Ctx.GetCookie("User_tokey"), c.GetString("User_tokey"))
  943. if !User_is {
  944. c.Data["json"] = lib.JSONS{Code: 201, Msg: "请重新登录!"}
  945. c.ServeJSON()
  946. return
  947. }
  948. T_id, _ := c.GetInt("T_id") // 要复制的信息采集分类id
  949. T_name := c.GetString("T_name")
  950. // 查询要复制的信息采集分类id
  951. R_VerifyTemplateClass, err := VerifyTemplate.Read_VerifyTemplateClass_ById(T_id)
  952. if err != nil {
  953. c.Data["json"] = lib.JSONS{Code: 203, Msg: "T_id Err!"}
  954. c.ServeJSON()
  955. return
  956. }
  957. if len(T_name) > 0 && T_name != R_VerifyTemplateClass.T_name {
  958. R_VerifyTemplateClass.T_name = T_name
  959. } else {
  960. R_VerifyTemplateClass.T_name = R_VerifyTemplateClass.T_name + "_副本"
  961. }
  962. _, err = VerifyTemplate.CopyVerifyTemplateClassTree(R_VerifyTemplateClass.T_path, R_VerifyTemplateClass.T_fid, R_VerifyTemplateClass.T_name)
  963. if err != nil {
  964. c.Data["json"] = lib.JSONS{Code: 202, Msg: "复制验证模版分类失败"}
  965. c.ServeJSON()
  966. return
  967. }
  968. System.Add_UserLogs_T(User_r.T_uuid, "验证模版分类", "复制", T_id)
  969. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  970. c.ServeJSON()
  971. return
  972. }