ScanTaskBaseService.kt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. package com.persagy.server.services.task
  27. import com.google.gson.Gson
  28. import com.google.gson.reflect.TypeToken
  29. import com.persagy.database.SFilter
  30. import com.persagy.database.SPageQueryInfo
  31. import com.persagy.mybatis.SMybatisDao
  32. import com.persagy.server.datacenter.models.entities.task.*
  33. import com.persagy.server.datacenter.models.entities.task.base.ScanTaskBase
  34. import com.persagy.server.mappers.StatisticsCountMapper
  35. import com.persagy.server.services.base.RService
  36. import com.persagy.service.SBaseService
  37. import com.persagy.service.SPageContext
  38. import com.persagy.service.models.enums.SResponseType
  39. import com.persagy.service.models.requests.SQueryRequest
  40. import com.persagy.service.models.responses.SQueryResponse
  41. import com.persagy.service.utils.SSpringContextUtil
  42. /**
  43. * 任务父表
  44. *
  45. * @author 邓婷婷
  46. */
  47. object ScanTaskBaseService : RService<ScanTaskBase>(SMybatisDao(ScanTaskBase::class.java)) {
  48. /** 实例化 mapper 对象 */
  49. val mapper by lazy {
  50. SSpringContextUtil.getBean(StatisticsCountMapper::class.java) as StatisticsCountMapper
  51. }
  52. /**
  53. * 查询所有设备类型或设备族
  54. */
  55. fun equipCategoryQuery(type: String): SQueryResponse<EquipCategoryDic> {
  56. val pageQuery: SPageQueryInfo<EquipCategoryDic>
  57. return try {
  58. val equipCategoryDicService = SBaseService(SMybatisDao(EquipCategoryDic::class.java))
  59. var request = SQueryRequest()
  60. val queryBuilder = equipCategoryDicService.select(request.filters)
  61. val projectId = SPageContext.getHeader("projectId").toString()
  62. queryBuilder.tableName = "scantask.f_get_category('$type','$projectId')"
  63. pageQuery = queryBuilder.pageQuery(1, 1000)
  64. SQueryResponse(pageQuery)
  65. } catch (e: Exception) {
  66. e.printStackTrace()
  67. SQueryResponse(SResponseType.failure, e.message!!)
  68. }
  69. } // Fun equipCategoryQuery
  70. /**
  71. * 查询所有建筑和楼层
  72. */
  73. fun buildingQuery(type: String): SQueryResponse<BuildingDic> {
  74. val pageQuery: SPageQueryInfo<BuildingDic>
  75. val gson = Gson()
  76. return try {
  77. val projectId = SPageContext.getHeader("projectId").toString()
  78. var request = SQueryRequest()
  79. val service = SBaseService(SMybatisDao(BuildingDic::class.java))
  80. val queryBuilder = service.select(request.filters)
  81. queryBuilder.tableName = "scantask.f_get_building_dic('$type','$projectId')"
  82. pageQuery = queryBuilder.pageQuery(1, 1000)
  83. if (pageQuery.content!=null&&pageQuery.content!!.size>0){
  84. for(floor in pageQuery.content!!){
  85. if(floor.floorListStr != null){
  86. val listStr = floor.floorListStr!!.replace("/\\","")
  87. val newStr = "["+listStr.substring(1,listStr.length-1)+"]"
  88. val type = object : TypeToken<ArrayList<FloorDic>>() {
  89. }.type
  90. val siInSpList = gson.fromJson<ArrayList<FloorDic>>(newStr, type)
  91. floor.floor = siInSpList
  92. floor.floorListStr = null
  93. }
  94. }
  95. if (type == "equip"||type == "property"){
  96. var taskSource: String
  97. if (type == "equip"){
  98. taskSource = "2"
  99. }else {
  100. taskSource = "3"
  101. }
  102. /** 处理楼层是否有未明确楼层 */
  103. for(building in pageQuery.content!!){
  104. if (building.floor!=null&&building.floor!!.size>0){
  105. val equipScanTaskList = select(
  106. SFilter.eq("projectId", projectId), SFilter.eq("buildingId", building.id!!),
  107. SFilter.isNull("floorId"),SFilter.eq("taskSource", taskSource)).exec()
  108. if (equipScanTaskList.size>0){
  109. val floorDic = FloorDic()
  110. floorDic.localName = "未明确楼层"
  111. building.floor!!.add(0,floorDic)
  112. }
  113. }else{
  114. val equipScanTaskList = select(SFilter.eq("projectId", projectId), SFilter.eq("buildingId", building.id!!),
  115. SFilter.isNull("floorId"),SFilter.eq("taskSource", taskSource)).exec()
  116. if (equipScanTaskList.size>0){
  117. val list = ArrayList<FloorDic>()
  118. val floorDic = FloorDic()
  119. floorDic.localName = "未明确楼层"
  120. list.add(floorDic)
  121. building.floor= list
  122. }
  123. }
  124. }
  125. /** 未明确建筑 */
  126. val equipScanTaskList = select(SFilter.eq("projectId", projectId), SFilter.isNull("buildingId"),SFilter.eq("taskSource", taskSource)).exec()
  127. if (equipScanTaskList.size>0){
  128. val buildingDic = BuildingDic()
  129. buildingDic.localName = "未明确建筑"
  130. pageQuery.content!!.add(0,buildingDic)
  131. }
  132. }
  133. }else{
  134. if (type == "equip"||type == "property") {
  135. var taskSource: String
  136. if (type == "equip") {
  137. taskSource = "2"
  138. } else {
  139. taskSource = "3"
  140. }
  141. val equipScanTaskList = select(SFilter.eq("projectId", projectId), SFilter.isNull("buildingId")
  142. ,SFilter.eq("taskSource", taskSource)).exec()
  143. if (equipScanTaskList.size > 0) {
  144. val list = ArrayList<BuildingDic>()
  145. val buildingDic = BuildingDic()
  146. buildingDic.localName = "未明确建筑"
  147. list.add(buildingDic)
  148. pageQuery.content = list
  149. }
  150. }
  151. }
  152. SQueryResponse(pageQuery)
  153. } catch (e: Exception) {
  154. e.printStackTrace()
  155. SQueryResponse(SResponseType.failure, e.message!!)
  156. }
  157. } // Fun modelFileQuery
  158. /**
  159. * 统计设备下部件的类型以及数量
  160. */
  161. fun categoryCounts(equipScanTask: EquipScanTask): SQueryResponse<CategoryStatistics>{
  162. try {
  163. val projectId = SPageContext.getHeader("projectId").toString()
  164. if (!equipScanTask.id.isNullOrEmpty()&&!equipScanTask.equipId.isNullOrEmpty()){
  165. val categoryStatistics = mapper.categoryStatistics(projectId,equipScanTask.id!!, equipScanTask.equipId!!)
  166. val sQueryResponse = SQueryResponse<CategoryStatistics>()
  167. sQueryResponse.total = categoryStatistics.size.toLong()
  168. sQueryResponse.content = categoryStatistics
  169. sQueryResponse.result = SResponseType.success
  170. return sQueryResponse
  171. }else{
  172. val sQueryResponse = SQueryResponse<CategoryStatistics>(SResponseType.failure)
  173. sQueryResponse.message = "入参错误"
  174. return sQueryResponse
  175. }
  176. } catch (e: Exception) {
  177. e.printStackTrace()
  178. return SQueryResponse(SResponseType.failure,e.message.toString())
  179. }
  180. } // Fun
  181. /**
  182. * 统计设备下部件的类型以及数量
  183. */
  184. fun categoryCountsModel(type: String?,equipScanTask: ModelScanTask): SQueryResponse<CategoryStatistics>{
  185. try {
  186. val projectId = SPageContext.getHeader("projectId")
  187. if (!equipScanTask.id.isNullOrEmpty()&&!equipScanTask.equipId.isNullOrEmpty()){
  188. if (!type.isNullOrEmpty()&&type == "model"){
  189. val categoryStatistics = ModelScanTaskService.mapper.categoryStatisticsModel(projectId!!,equipScanTask.id!!, equipScanTask.equipId!!)
  190. val sQueryResponse = SQueryResponse<CategoryStatistics>()
  191. sQueryResponse.total = categoryStatistics.size.toLong()
  192. sQueryResponse.content = categoryStatistics
  193. sQueryResponse.result = SResponseType.success
  194. return sQueryResponse
  195. }else{
  196. val categoryStatistics = mapper.categoryStatistics(projectId!!,equipScanTask.id!!, equipScanTask.equipId!!)
  197. val sQueryResponse = SQueryResponse<CategoryStatistics>()
  198. sQueryResponse.total = categoryStatistics.size.toLong()
  199. sQueryResponse.content = categoryStatistics
  200. sQueryResponse.result = SResponseType.success
  201. return sQueryResponse
  202. }
  203. }else{
  204. val sQueryResponse = SQueryResponse<CategoryStatistics>(SResponseType.failure)
  205. sQueryResponse.message = "入参错误"
  206. return sQueryResponse
  207. }
  208. } catch (e: Exception) {
  209. e.printStackTrace()
  210. return SQueryResponse(SResponseType.failure,e.message.toString())
  211. }
  212. } // Fun
  213. } // Fun