limsZuhq.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. package lims
  2. import (
  3. "dashoo.cn/business2/parameter"
  4. "dashoo.cn/backend/api/business/instrument"
  5. "dashoo.cn/backend/api/business/limscustomerposition"
  6. "dashoo.cn/backend/api/business/limsdataentry"
  7. "encoding/json"
  8. "strings"
  9. "time"
  10. "dashoo.cn/business2/userRole"
  11. "dashoo.cn/backend/api/business/baseUser"
  12. "dashoo.cn/backend/api/business/items"
  13. "dashoo.cn/backend/api/business/Limsreportzuhq"
  14. svccustomer "dashoo.cn/backend/api/business/customer"
  15. . "dashoo.cn/backend/api/controllers"
  16. "dashoo.cn/utils"
  17. )
  18. type LimsReportZuhqController struct {
  19. BaseController
  20. }
  21. // @Title 获取列表
  22. // @Description get user by token
  23. // @Success 200 {object} []limsreportzuhq.LimsReportZuhq
  24. // @router /list [get]
  25. func (this *LimsReportZuhqController) GetEntityList() {
  26. //获取分页信息
  27. page := this.GetPageInfoForm()
  28. where := " 1=1 "
  29. orderby := "OrderNo,Id"
  30. asc := true
  31. Order := this.GetString("Order")
  32. Prop := this.GetString("Prop")
  33. if Order != "" && Prop != "" {
  34. orderby = Prop
  35. if Order == "asc" {
  36. asc = true
  37. }
  38. }
  39. OrderNo := this.GetString("OrderNo")
  40. Position := this.GetString("Position")
  41. CustNo := this.GetString("CustNo")
  42. CheckDate := this.GetString("CheckDate")
  43. Temperature := this.GetString("Temperature")
  44. Spec := this.GetString("Spec")
  45. Manufacturer := this.GetString("Manufacturer")
  46. StatusA := this.GetString("Status")
  47. StandardCode := this.GetString("StandardCode")
  48. MainProducts := this.GetString("MainProducts")
  49. Remark1 := this.GetString("Remark1")
  50. Remark2 := this.GetString("Remark2")
  51. DataEntryId := this.GetString("DataEntryId")
  52. if DataEntryId != "" {
  53. where = where + " and DataEntryId =" + DataEntryId
  54. } else {
  55. where = where + " and DataEntryId =" + "0"
  56. }
  57. if OrderNo != "" {
  58. where = where + " and OrderNo like '%" + OrderNo + "%'"
  59. }
  60. if Position != "" {
  61. where = where + " and Position like '%" + Position + "%'"
  62. }
  63. if CustNo != "" {
  64. where = where + " and CustNo like '%" + CustNo + "%'"
  65. }
  66. if Temperature != "" {
  67. where = where + " and Temperature like '%" + Temperature + "%'"
  68. }
  69. if Spec != "" {
  70. where = where + " and Spec like '%" + Spec + "%'"
  71. }
  72. if Manufacturer != "" {
  73. where = where + " and Manufacturer like '%" + Manufacturer + "%'"
  74. }
  75. if StatusA != "" {
  76. where = where + " and Status like '%" + StatusA + "%'"
  77. }
  78. if StandardCode != "" {
  79. where = where + " and StandardCode like '%" + StandardCode + "%'"
  80. }
  81. if MainProducts != "" {
  82. where = where + " and MainProducts like '%" + MainProducts + "%'"
  83. }
  84. if Remark1 != "" {
  85. where = where + " and Remark1 like '%" + Remark1 + "%'"
  86. }
  87. if Remark2 != "" {
  88. where = where + " and Remark2 like '%" + Remark2 + "%'"
  89. }
  90. if CheckDate != "" {
  91. dates := strings.Split(CheckDate, ",")
  92. if len(dates) == 2 {
  93. minDate := dates[0]
  94. maxDate := dates[1]
  95. where = where + " and CheckDate>='" + minDate + "' and CheckDate<='" + maxDate + "'"
  96. }
  97. }
  98. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  99. var list []Limsreportzuhq.LimsReportZuhq
  100. total := svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, page.CurrentPage, page.Size, orderby, asc, &list, where)
  101. var list1 []Limsreportzuhq.LimsReportZuhq
  102. svc.GetPagingEntitiesWithOrderBytbl(this.User.AccCode, 1,total, orderby, asc, &list1, where)
  103. var maxorderno = 0
  104. for i := 0; i < len(list1); i++ {
  105. if maxorderno < list1[i].OrderNo {
  106. maxorderno = list1[i].OrderNo
  107. }
  108. }
  109. var datainfo DataInfo
  110. datainfo.Items = list
  111. datainfo.CurrentItemCount = total
  112. datainfo.PageIndex = page.CurrentPage
  113. datainfo.ItemsPerPage = page.Size
  114. datainfo.StartIndex = int64(maxorderno)
  115. this.Data["json"] = &datainfo
  116. this.ServeJSON()
  117. }
  118. // @Title 获取字典列表
  119. // @Description get user by token
  120. // @Success 200 {object} map[string]interface{}
  121. // @router /dictlist [get]
  122. func (this *LimsReportZuhqController) GetDictList() {
  123. dictList := make(map[string]interface{})
  124. dictSvc := items.GetItemsService(utils.DBE)
  125. userSvc := baseUser.GetBaseUserService(utils.DBE)
  126. customerSvc := svccustomer.GetCustomerService(utils.DBE)
  127. paramSvc := baseparameter.GetBaseparameterService(utils.DBE)
  128. itemSvc := items.GetItemsService(utils.DBE)
  129. instsvc := instrument.GetInstrumentService(utils.DBE)
  130. dictList["Position"] = dictSvc.GetKeyValueItems("Position", this.User.AccCode)
  131. dictList["PositionCheck"] = dictSvc.GetKeyValueItems("PositionCheck", this.User.AccCode)
  132. dictList["ProductStatus"] = dictSvc.GetKeyValueItems("ProductStatus", this.User.AccCode)
  133. dictList["YxCheckForm"] = dictSvc.GetKeyValueItems("YxCheckForm", this.User.AccCode)
  134. var userEntity userRole.Base_User
  135. userSvc.GetEntityById(this.User.Id, &userEntity)
  136. dictList["Supervisers"] = userSvc.GetUserListByDepartmentId(this.User.AccCode, userEntity.Departmentid)
  137. var dictCustomer []svccustomer.Customer
  138. customerSvc.GetEntitysByWhere(this.User.AccCode + CustomerName, "", &dictCustomer)
  139. dictList["EntrustCorp"] = &dictCustomer
  140. where := "ItemsId=246"
  141. dictList["StandardItems"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  142. dictList["DefaultStandardZhq"] = paramSvc.GetBaseparameterMessage("s5OVE", "paramset", "StandardZhq")
  143. ////安全附件检测仪
  144. //where = "ParentId=193"
  145. //dictList["SafAccDetector"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  146. //
  147. ////热式气体质量流量计
  148. //where = "ParentId=198"
  149. //dictList["GasFlowMeter"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  150. //
  151. ////差压变送器
  152. //where = "ParentId=203"
  153. //dictList["DifPressTran"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  154. //常见问题
  155. where = "ParentId=126"
  156. dictList["ProblemItems"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  157. //常见问题位置
  158. where = "ParentId=120"
  159. dictList["ProblemLocation"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  160. //规格型号
  161. where = "ParentId=286"
  162. dictList["Spec1"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  163. where = "ParentId=290"
  164. dictList["Spec2"] = itemSvc.GetTreeitemsdetailByWhere(Base_ItemTreeDetailsName, where)
  165. var PressureLeak []items.LimsPressureLeak
  166. customerSvc.GetEntitysByWhere(this.User.AccCode + LimsPressureLeakName, "", &PressureLeak)
  167. dictList["PressureLeak"] = &PressureLeak
  168. // 检测仪器--压力变送器
  169. var list []instrument.Instrument
  170. where = "Classification='压力变送器'"
  171. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list)
  172. dictList["DifPressTran"] = list
  173. // 检测仪器--安全附件检测仪
  174. var list1 []instrument.Instrument
  175. where = "Classification='安全附件检测仪'"
  176. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list1)
  177. dictList["SafAccDetector"] = list1
  178. // 检测仪器--热式气体质量流量计
  179. var list2 []instrument.Instrument
  180. where = "Classification='热式气体质量流量计'"
  181. instsvc.GetEntitysByWhere(this.User.AccCode+InstrumentName, where,&list2)
  182. dictList["GasFlowMeter"] = list2
  183. // 相关联的检测仪器
  184. var instrumentgroup []instrument.LimsInstrumentGroup
  185. where = "1 = 1"
  186. instsvc.GetEntitysByWhere(this.User.AccCode+LimsInstrumentGroup, where,&instrumentgroup)
  187. dictList["instrumentgroup"] = instrumentgroup
  188. var datainfo DataInfo
  189. datainfo.Items = dictList
  190. this.Data["json"] = &datainfo
  191. this.ServeJSON()
  192. }
  193. // @Title 获取实体
  194. // @Description 获取实体
  195. // @Success 200 {object} limsreportzuhq.LimsReportZuhq
  196. // @router /get/:id [get]
  197. func (this *LimsReportZuhqController) GetEntity() {
  198. Id := this.Ctx.Input.Param(":id")
  199. var model Limsreportzuhq.LimsReportZuhq
  200. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  201. svc.GetEntityByIdBytbl(this.User.AccCode+LimsReportZuhqName, Id, &model)
  202. this.Data["json"] = &model
  203. this.ServeJSON()
  204. }
  205. // @Title 添加
  206. // @Description 新增
  207. // @Param body body limsreportzuhq.LimsReportZuhq
  208. // @Success 200 {object} controllers.Request
  209. // @router /add [post]
  210. func (this *LimsReportZuhqController) AddEntity() {
  211. var model Limsreportzuhq.LimsReportZuhq
  212. var jsonBlob = this.Ctx.Input.RequestBody
  213. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  214. json.Unmarshal(jsonBlob, &model)
  215. model.CreateOn = time.Now()
  216. model.CreateBy = this.User.Realname
  217. model.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  218. //model.OrganizeId, _ = utils.StrTo(this.User.DepartmentId).Int()
  219. _, err := svc.InsertEntityBytbl(this.User.AccCode+LimsReportZuhqName, &model)
  220. var errinfo ErrorDataInfo
  221. if err == nil {
  222. //新增
  223. errinfo.Message = "添加成功!"
  224. errinfo.Code = 0
  225. errinfo.Item = model.Id
  226. this.Data["json"] = &errinfo
  227. this.ServeJSON()
  228. } else {
  229. errinfo.Message = "添加失败!" + utils.AlertProcess(err.Error())
  230. errinfo.Code = -1
  231. this.Data["json"] = &errinfo
  232. this.ServeJSON()
  233. }
  234. }
  235. // @Title 修改实体
  236. // @Description 修改实体
  237. // @Param body body limsreportzuhq.LimsReportZuhq
  238. // @Success 200 {object} controllers.Request
  239. // @router /update/:id [post]
  240. func (this *LimsReportZuhqController) UpdateEntity() {
  241. id := this.Ctx.Input.Param(":id")
  242. var errinfo ErrorInfo
  243. if id == "" {
  244. errinfo.Message = "操作失败!请求信息不完整"
  245. errinfo.Code = -2
  246. this.Data["json"] = &errinfo
  247. this.ServeJSON()
  248. return
  249. }
  250. var model Limsreportzuhq.LimsReportZuhq
  251. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  252. var jsonBlob = this.Ctx.Input.RequestBody
  253. json.Unmarshal(jsonBlob, &model)
  254. model.ModifiedOn = time.Now()
  255. model.ModifiedBy = this.User.Realname
  256. model.ModifiedUserId, _ = utils.StrTo(this.User.Id).Int()
  257. cols := []string{
  258. "Id",
  259. "EId",
  260. "TaskBalanceId",
  261. "DataEntryId",
  262. "OrderNo",
  263. "Position",
  264. "PositionId",
  265. "PositionCheck",
  266. "PositionCheckId",
  267. "StandardDesc",
  268. "CustNo",
  269. "PUType",
  270. "SafAccDetector",
  271. "GasFlowMeter",
  272. "DifPressTran",
  273. "CheckDate",
  274. "PaDiff",
  275. "Temperature",
  276. "Spec",
  277. "Manufacturer",
  278. "Status",
  279. "StandardCode",
  280. "MainProducts",
  281. "VentVolume1",
  282. "VentVolume2",
  283. "VentVolume3",
  284. "VentVolume4",
  285. "PyPapot",
  286. "PyPa1",
  287. "PyPa2",
  288. "PyPa3",
  289. "PyPaAvg",
  290. "PwPa1",
  291. "PwPa2",
  292. "PwPa3",
  293. "PwPaAvg",
  294. "Remark1",
  295. "Remark2",
  296. "CreateOn",
  297. "CreateUserId",
  298. "CreateBy",
  299. "ModifiedOn",
  300. "ModifiedUserId",
  301. "ModifiedBy",
  302. }
  303. err := svc.UpdateEntityBytbl(this.User.AccCode+LimsReportZuhqName, id, &model, cols)
  304. if err == nil {
  305. errinfo.Message = "修改成功!"
  306. errinfo.Code = 0
  307. this.Data["json"] = &errinfo
  308. this.ServeJSON()
  309. } else {
  310. errinfo.Message = "修改失败!" + utils.AlertProcess(err.Error())
  311. errinfo.Code = -1
  312. this.Data["json"] = &errinfo
  313. this.ServeJSON()
  314. }
  315. }
  316. // @Title 删除单条信息
  317. // @Description
  318. // @Success 200 {object} ErrorInfo
  319. // @Failure 403 :id 为空
  320. // @router /delete/:Id [delete]
  321. func (this *LimsReportZuhqController) DeleteEntity() {
  322. Id := this.Ctx.Input.Param(":Id")
  323. var errinfo ErrorInfo
  324. if Id == "" {
  325. errinfo.Message = "操作失败!请求信息不完整"
  326. errinfo.Code = -2
  327. this.Data["json"] = &errinfo
  328. this.ServeJSON()
  329. return
  330. }
  331. var model Limsreportzuhq.LimsReportZuhq
  332. var entityempty Limsreportzuhq.LimsReportZuhq
  333. svc := Limsreportzuhq.GetLimsreportzuhqService(utils.DBE)
  334. opdesc := "删除-" + Id
  335. err := svc.DeleteOperationAndWriteLogBytbl(this.User.AccCode+LimsReportZuhqName, BaseOperationLogName, Id, &model, &entityempty, utils.ToStr(this.User.Id), this.User.Username, opdesc, this.User.AccCode, "钻井日报")
  336. if err == nil {
  337. errinfo.Message = "删除成功"
  338. errinfo.Code = 0
  339. this.Data["json"] = &errinfo
  340. this.ServeJSON()
  341. } else {
  342. errinfo.Message = "删除失败!" + utils.AlertProcess(err.Error())
  343. errinfo.Code = -1
  344. this.Data["json"] = &errinfo
  345. this.ServeJSON()
  346. }
  347. }
  348. // @Title 获取委托方信息
  349. // @Description 获取委托方信息
  350. // @Success 200 object} map[string]interface{}
  351. // @router /getEntrustCorp/:id [get]
  352. func (this *LimsReportZuhqController) GetEntrustCorpItems() {
  353. dictList := make(map[string]interface{})
  354. cId := this.Ctx.Input.Param(":id")
  355. var model []limscustomerposition.LimsCustomerPosition
  356. svc := limscustomerposition.GetLimsCustomerpositionService(utils.DBE)
  357. where := "CustomerId=" + cId + " and ParentId = 0"
  358. svc.GetEntitysByWhere(this.User.AccCode+LimsCustomerpositionName, where,&model)
  359. dictList["PositionCheck"] = model
  360. var Positionmodel []limscustomerposition.LimsCustomerPosition
  361. where = "CustomerId=" + cId + " and ParentId <> 0"
  362. svc.GetEntitysByWhere(this.User.AccCode+LimsCustomerpositionName,where, &Positionmodel)
  363. dictList["Position"] = Positionmodel
  364. var datainfo DataInfo
  365. datainfo.Items = dictList
  366. this.Data["json"] = &datainfo
  367. this.ServeJSON()
  368. }
  369. // @Title 添加运行记录
  370. // @Description 新增
  371. // @Param body body instrument.InstrumenRunRecord
  372. // @Success 200 {object} controllers.Request
  373. // @router /addRunRecord/:Id [post]
  374. func (this *LimsReportZuhqController) AddRunRecord() {
  375. Id := this.Ctx.Input.Param(":Id")
  376. var dataentry limsdataentry.LimsDateEntry
  377. svc := limsdataentry.GetLimsDataEntryService(utils.DBE)
  378. svc.GetEntityByIdBytbl(this.User.AccCode+LimsDateEntryName, Id, &dataentry)
  379. where := "ContractNo = '" + dataentry.DataEntryCode + "'"
  380. svc.DeleteEntityBytbl(this.User.AccCode+InstrumenRunRecordName, where)
  381. instruments1 := strings.Split(dataentry.Instrument1, ",")
  382. for i := 0; i < len(instruments1); i++ {
  383. if instruments1[i] != "" {
  384. var instlist instrument.Instrument
  385. var runrecord instrument.InstrumenRunRecord
  386. where := "Code='" + instruments1[i] + "'"
  387. svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
  388. runrecord.InstrumentId = instlist.Id
  389. runrecord.InstrumenCode = instlist.Code
  390. runrecord.InstrumenName = instlist.Name
  391. runrecord.ContractNo = dataentry.DataEntryCode
  392. runrecord.CreateOn = time.Now()
  393. runrecord.CreateBy = this.User.Realname
  394. runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  395. svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
  396. }
  397. }
  398. instruments2 := strings.Split(dataentry.Instrument2, ",")
  399. for i := 0; i < len(instruments2); i++ {
  400. if instruments2[i] != "" {
  401. var instlist instrument.Instrument
  402. var runrecord instrument.InstrumenRunRecord
  403. where := "Code='" + instruments2[i] + "'"
  404. svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
  405. runrecord.InstrumentId = instlist.Id
  406. runrecord.InstrumenCode = instlist.Code
  407. runrecord.InstrumenName = instlist.Name
  408. runrecord.ContractNo = dataentry.DataEntryCode
  409. runrecord.CreateOn = time.Now()
  410. runrecord.CreateBy = this.User.Realname
  411. runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  412. svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
  413. }
  414. }
  415. instruments3 := strings.Split(dataentry.Instrument3, ",")
  416. for i := 0; i < len(instruments3); i++ {
  417. if instruments3[i] != "" {
  418. var instlist instrument.Instrument
  419. var runrecord instrument.InstrumenRunRecord
  420. where := "Code='" + instruments3[i] + "'"
  421. svc.GetEntityByWhere(this.User.AccCode+InstrumentName, where, &instlist)
  422. runrecord.InstrumentId = instlist.Id
  423. runrecord.InstrumenCode = instlist.Code
  424. runrecord.InstrumenName = instlist.Name
  425. runrecord.ContractNo = dataentry.DataEntryCode
  426. runrecord.CreateOn = time.Now()
  427. runrecord.CreateBy = this.User.Realname
  428. runrecord.CreateUserId, _ = utils.StrTo(this.User.Id).Int()
  429. svc.InsertEntityBytbl(this.User.AccCode+InstrumenRunRecordName, &runrecord)
  430. }
  431. }
  432. }