devicestatistics.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. package lims
  2. import (
  3. "dashoo.cn/backend/api/business/devicestatistics"
  4. "dashoo.cn/backend/api/business/organize"
  5. . "dashoo.cn/backend/api/controllers"
  6. "dashoo.cn/utils"
  7. "fmt"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type DeviceStatisticsController struct {
  13. BaseController
  14. }
  15. // @Title 获取列表
  16. // @Description get user by token
  17. // @Success 200 {object}
  18. // @router /list [get]
  19. func (this *DeviceStatisticsController) GetEntityList() {
  20. unitId := this.GetString("unitCheckId")
  21. // svcPerm := permission.GetPermissionService(utils.DBE)
  22. //isauth := svcPerm.IsAuthorized(this.User.Id, "Administrator")
  23. // organizeSvc := organize.GetOrganizeService(utils.DBE)
  24. // thrunitId := organizeSvc.GetMyThrUnitDepartmentId(this.User.DepartmentId)
  25. var devicelist []devicestatistics.DeviceStatistics
  26. svc := devicestatistics.GetDeviceStatisticsService(utils.DBE)
  27. //fromdate := GetFirstDateOfMonth(time.Now()).Format("2006-01-02 15:04:05")
  28. //todate := GetLastDateOfMonth(time.Now()).Format("2006-01-02") + " 23:59:59"
  29. organizeSvc := organize.GetOrganizeService(utils.DBE)
  30. thrId := organizeSvc.GetMyThrUnitDepartmentId(this.User.DepartmentId)
  31. thrIds := ""
  32. ethrIds := ""
  33. //unitId := ""
  34. wheret := ""
  35. if thrId == "100001219" || thrId == "100001215" {
  36. if unitId != "" {
  37. throrg := organizeSvc.GetAllThirdChildByTopId(unitId, "")
  38. if throrg == nil {
  39. thrIds = "-1"
  40. } else {
  41. for _, item := range throrg {
  42. thrIds += strconv.Itoa(item.Id) + ","
  43. }
  44. thrIds = strings.Trim(thrIds, ",")
  45. ethrIds = organizeSvc.GetAllChildById(unitId)
  46. }
  47. }
  48. } else {
  49. //if thrId == this.User.DepartmentId {
  50. unitId = organizeSvc.GetMyUnitDepartmentId(this.User.DepartmentId)
  51. //var throrg []organize.Base_Organize
  52. throrg := organizeSvc.GetAllThirdChildByTopId(unitId, "")
  53. for _, item := range throrg {
  54. thrIds += strconv.Itoa(item.Id) + ","
  55. }
  56. ethrIds = organizeSvc.GetAllChildById(unitId)
  57. thrIds = strings.Trim(thrIds, ",")
  58. //} else {
  59. // ethrIds = thrId
  60. //}
  61. }
  62. if thrIds != "" {
  63. wheret = " and b.TestDepartId in (" + thrIds + ")"
  64. }
  65. wheree := ""
  66. if ethrIds != "" {
  67. wheree = " and DepartmentId in (" + ethrIds + ")"
  68. }
  69. where := "(a.CreateOn < DATE_ADD(CURDATE()-DAY(CURDATE())+1,INTERVAL 1 MONTH)) and a.CheckResult != ''" + wheret
  70. whereYno := "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult='×' " + wheret
  71. whereY := "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult='○' " + wheret
  72. if thrId != "100001219" {
  73. // 防雷装置(等电位)
  74. var deviceEQ devicestatistics.DeviceStatistics
  75. totalYearNo := svc.GetCountsByDate(this.User.AccCode+LimsReportEquipotentName, whereYno)
  76. totalYear := svc.GetCountsByDate(this.User.AccCode+LimsReportEquipotentName, whereY)
  77. num := svc.GetCountsByDate(this.User.AccCode+LimsReportEquipotentName, where)
  78. whereN := "TemplateTypeId=187 " + wheree
  79. numEQ := svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  80. numWM := svc.GetWaitCountsMonth("187")
  81. numWY := svc.GetWaitCountsYear("187")
  82. deviceEQ.DeviceName = "防雷装置(等电位)"
  83. deviceEQ.DeviceQty = int(numEQ)
  84. deviceEQ.WaitYear = int(numWY)
  85. deviceEQ.WaitMonth = int(numWM)
  86. deviceEQ.FinishMonth = int(num)
  87. deviceEQ.FinishYear = int(totalYearNo) + int(totalYear)
  88. if deviceEQ.FinishYear != 0 {
  89. deviceEQ.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  90. }
  91. devicelist = append(devicelist, deviceEQ)
  92. // 防雷装置
  93. var deviceLPT devicestatistics.DeviceStatistics
  94. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportLightProtectName, whereYno)
  95. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportLightProtectName, whereY)
  96. num = svc.GetCountsByDate(this.User.AccCode+LimsReportLightProtectName, where)
  97. whereN = "TemplateTypeId=286 " + wheree
  98. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  99. numWM = svc.GetWaitCountsMonth("286")
  100. numWY = svc.GetWaitCountsYear("286")
  101. deviceLPT.DeviceName = "防雷装置"
  102. deviceLPT.DeviceQty = numEQ
  103. deviceLPT.WaitYear = int(numWY)
  104. deviceLPT.WaitMonth = int(numWM)
  105. deviceLPT.FinishMonth = int(num)
  106. deviceLPT.FinishYear = int(totalYearNo) + int(totalYear)
  107. if deviceLPT.FinishYear != 0 {
  108. deviceLPT.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  109. }
  110. devicelist = append(devicelist, deviceLPT)
  111. // 漏电保护器
  112. var deviceLP devicestatistics.DeviceStatistics
  113. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportLeakProtectName, whereYno)
  114. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportLeakProtectName, whereY)
  115. num = svc.GetCountsByDate(this.User.AccCode+LimsReportLeakProtectName, where)
  116. whereN = "TemplateTypeId=181" + wheree
  117. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  118. numWM = svc.GetWaitCountsMonth("181")
  119. numWY = svc.GetWaitCountsYear("181")
  120. deviceLP.DeviceName = "漏电保护器"
  121. deviceLP.DeviceQty = numEQ
  122. deviceLP.WaitYear = int(numWY)
  123. deviceLP.WaitMonth = int(numWM)
  124. deviceLP.FinishMonth = int(num)
  125. deviceLP.FinishYear = int(totalYearNo) + int(totalYear)
  126. if deviceLP.FinishYear != 0 {
  127. deviceLP.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  128. }
  129. devicelist = append(devicelist, deviceLP)
  130. // 电气接地
  131. var deviceEG devicestatistics.DeviceStatistics
  132. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportElecGroundName, whereYno)
  133. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportElecGroundName, whereY)
  134. num = svc.GetCountsByDate(this.User.AccCode+LimsReportElecGroundName, where)
  135. whereN = "TemplateTypeId=179 " + wheree
  136. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  137. numWM = svc.GetWaitCountsMonth("179")
  138. numWY = svc.GetWaitCountsYear("179")
  139. deviceEG.DeviceName = "电气接地"
  140. deviceEG.DeviceQty = numEQ
  141. deviceEG.WaitYear = int(numWY)
  142. deviceEG.WaitMonth = int(numWM)
  143. deviceEG.FinishMonth = int(num)
  144. deviceEG.FinishYear = int(totalYearNo) + int(totalYear)
  145. if deviceEG.FinishYear != 0 {
  146. deviceEG.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  147. }
  148. devicelist = append(devicelist, deviceEG)
  149. }
  150. if thrId != "100001215" {
  151. whereYno = "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult LIKE '%不合格%'" + wheret
  152. whereY = "(a.CreateOn < DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAYOFYEAR(NOW())-1 DAY),INTERVAL 1 YEAR)) and a.CheckResult LIKE '%合格%' AND CheckResult NOT LIKE '%不合格%' " + wheret
  153. //阻火器 LimsReportZuhq
  154. var deviceZHQ devicestatistics.DeviceStatistics
  155. totalYearNo := svc.GetCountsByDate(this.User.AccCode+LimsReportZuhqName, whereYno)
  156. totalYear := svc.GetCountsByDate(this.User.AccCode+LimsReportZuhqName, whereY)
  157. num := svc.GetCountsByDate(this.User.AccCode+LimsReportZuhqName, where)
  158. whereN := "TemplateTypeId=156" + wheree
  159. numEQ := svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  160. numWM := svc.GetWaitCountsMonth("156")
  161. numWY := svc.GetWaitCountsYear("156")
  162. deviceZHQ.DeviceName = "阻火器"
  163. deviceZHQ.DeviceQty = numEQ
  164. deviceZHQ.WaitYear = int(numWY)
  165. deviceZHQ.WaitMonth = int(numWM)
  166. deviceZHQ.FinishMonth = int(num)
  167. deviceZHQ.FinishYear = int(totalYearNo) + int(totalYear)
  168. if deviceZHQ.FinishYear != 0 {
  169. deviceZHQ.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  170. }
  171. devicelist = append(devicelist, deviceZHQ)
  172. // 呼吸阀 LimsReportHuxf
  173. var deviceHXF devicestatistics.DeviceStatistics
  174. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportHuxfName, whereYno)
  175. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportHuxfName, whereY)
  176. num = svc.GetCountsByDate(this.User.AccCode+LimsReportHuxfName, where)
  177. whereN = "TemplateTypeId=183 " + wheree
  178. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  179. numWM = svc.GetWaitCountsMonth("183")
  180. numWY = svc.GetWaitCountsYear("183")
  181. deviceHXF.DeviceName = "呼吸阀"
  182. deviceHXF.DeviceQty = numEQ
  183. deviceHXF.WaitYear = int(numWY)
  184. deviceHXF.WaitMonth = int(numWM)
  185. deviceHXF.FinishMonth = int(num)
  186. deviceHXF.FinishYear = int(totalYearNo) + int(totalYear)
  187. if deviceHXF.FinishYear != 0 {
  188. deviceHXF.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  189. }
  190. devicelist = append(devicelist, deviceHXF)
  191. // 液压安全阀 LimsReportYeyaqf
  192. var deviceYYF devicestatistics.DeviceStatistics
  193. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportYeyaqfName, whereYno)
  194. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportYeyaqfName, whereY)
  195. num = svc.GetCountsByDate(this.User.AccCode+LimsReportYeyaqfName, where)
  196. whereN = "TemplateTypeId=154 " + wheree
  197. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  198. numWM = svc.GetWaitCountsMonth("154")
  199. numWY = svc.GetWaitCountsYear("154")
  200. deviceYYF.DeviceName = "液压安全阀"
  201. deviceYYF.DeviceQty = numEQ
  202. deviceYYF.WaitYear = int(numWY)
  203. deviceYYF.WaitMonth = int(numWM)
  204. deviceYYF.FinishMonth = int(num)
  205. deviceYYF.FinishYear = int(totalYearNo) + int(totalYear)
  206. if deviceYYF.FinishYear != 0 {
  207. deviceYYF.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  208. }
  209. devicelist = append(devicelist, deviceYYF)
  210. // 空气泡沫产生器 LimsReportAirFoamGenerator
  211. var deviceKQPM devicestatistics.DeviceStatistics
  212. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportKqpmName, whereYno)
  213. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportKqpmName, whereY)
  214. num = svc.GetCountsByDate(this.User.AccCode+LimsReportKqpmName, where)
  215. whereN = "TemplateTypeId=189 " + wheree
  216. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  217. numWM = svc.GetWaitCountsMonth("189")
  218. numWY = svc.GetWaitCountsYear("189")
  219. deviceKQPM.DeviceName = "空气泡沫产生器"
  220. deviceKQPM.DeviceQty = numEQ
  221. deviceKQPM.WaitYear = int(numWY)
  222. deviceKQPM.WaitMonth = int(numWM)
  223. deviceKQPM.FinishMonth = int(num)
  224. deviceKQPM.FinishYear = int(totalYearNo) + int(totalYear)
  225. if deviceKQPM.FinishYear != 0 {
  226. deviceKQPM.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  227. }
  228. devicelist = append(devicelist, deviceKQPM)
  229. // 游梁式抽油机 LimsReportBeamPumpingUnits
  230. var deviceYL devicestatistics.DeviceStatistics
  231. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportBeamPumpingUnitName, whereYno)
  232. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportBeamPumpingUnitName, whereY)
  233. num = svc.GetCountsByDate(this.User.AccCode+LimsReportBeamPumpingUnitName, where)
  234. whereN = "TemplateTypeId=141 " + wheree
  235. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  236. numWM = svc.GetWaitCountsMonth("141")
  237. numWY = svc.GetWaitCountsYear("141")
  238. deviceYL.DeviceName = "游梁式抽油机"
  239. deviceYL.DeviceQty = numEQ
  240. deviceYL.WaitYear = int(numWY)
  241. deviceYL.WaitMonth = int(numWM)
  242. deviceYL.FinishMonth = int(num)
  243. deviceYL.FinishYear = int(totalYearNo) + int(totalYear)
  244. if deviceYL.FinishYear != 0 {
  245. deviceYL.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  246. }
  247. devicelist = append(devicelist, deviceYL)
  248. // 无游梁式抽油机 LimsReportNoBeamPumpingUnit
  249. var deviceWYL devicestatistics.DeviceStatistics
  250. totalYearNo = svc.GetCountsByDate(this.User.AccCode+LimsReportNoBeamPumpingUnitName, whereYno)
  251. totalYear = svc.GetCountsByDate(this.User.AccCode+LimsReportNoBeamPumpingUnitName, whereY)
  252. num = svc.GetCountsByDate(this.User.AccCode+LimsReportNoBeamPumpingUnitName, where)
  253. whereN = "TemplateTypeId=173 " + wheree
  254. numEQ = svc.GetCountsByDateEquipment(this.User.AccCode+LimsCheckEquipmentListName, whereN)
  255. numWM = svc.GetWaitCountsMonth("173")
  256. numWY = svc.GetWaitCountsYear("173")
  257. deviceWYL.DeviceName = "无游梁式抽油机"
  258. deviceWYL.DeviceQty = numEQ
  259. deviceWYL.WaitYear = int(numWY)
  260. deviceWYL.WaitMonth = int(numWM)
  261. deviceWYL.FinishMonth = int(num)
  262. deviceWYL.FinishYear = int(totalYearNo) + int(totalYear)
  263. if deviceWYL.FinishYear != 0 {
  264. deviceWYL.PassRate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", (float64(totalYear)/(float64(totalYearNo)+float64(totalYear)))*100), 64)
  265. }
  266. devicelist = append(devicelist, deviceWYL)
  267. }
  268. var datainfo ErrorDataInfo
  269. datainfo.Item = devicelist
  270. this.Data["json"] = &datainfo
  271. this.ServeJSON()
  272. }
  273. // @Title 获取字典列表
  274. // @Description get user by token
  275. // @Success 200 {object} map[string]interface{}
  276. // @router /dictlist [get]
  277. func (this *DeviceStatisticsController) GetDictList() {
  278. dictList := make(map[string]interface{})
  279. var unitorg []organize.Base_Organize
  280. svc := organize.GetOrganizeService(utils.DBE)
  281. //unitId := svc.GetMyUnitDepartmentId(this.User.DepartmentId)
  282. //unitorg = svc.GetAllThirdChildByTopId(unitId, "")
  283. where := "Category='unit'"
  284. svc.GetEntities(&unitorg, where)
  285. dictList["unitorg"] = unitorg
  286. var datainfo DataInfo
  287. datainfo.Items = dictList
  288. this.Data["json"] = &datainfo
  289. this.ServeJSON()
  290. }
  291. //获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
  292. func GetFirstDateOfMonth(d time.Time) time.Time {
  293. d = d.AddDate(0, 0, -d.Day()+1)
  294. return GetZeroTime(d)
  295. }
  296. //获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。
  297. func GetLastDateOfMonth(d time.Time) time.Time {
  298. return GetFirstDateOfMonth(d).AddDate(0, 1, -1)
  299. }
  300. //获取某一天的0点时间
  301. func GetZeroTime(d time.Time) time.Time {
  302. return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location())
  303. }