EquipmentComService.kt 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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.service
  27. import com.persagy.base.extensions.rootCause
  28. import com.persagy.base.extensions.toJson
  29. import com.persagy.database.SFilter
  30. import com.persagy.database.SQueryBuilder
  31. import com.persagy.mybatis.SMybatisDao
  32. import com.persagy.server.datacenter.models.entities.dict.EquipCategory
  33. import com.persagy.server.datacenter.models.entities.dict.EquipFamily
  34. import com.persagy.server.datacenter.models.entities.dict.Family
  35. import com.persagy.server.datacenter.models.entities.dictnew.DefClass
  36. import com.persagy.server.datacenter.models.entities.graphtype.RelationTypeProject
  37. import com.persagy.server.datacenter.models.entities.objects.*
  38. import com.persagy.server.datacenter.models.entities.rel.REq2Sp
  39. import com.persagy.server.models.planar.PlanarEquip
  40. import com.persagy.server.models.requests.PlanarEquipRequests
  41. import com.persagy.server.service.base.Service
  42. import com.persagy.server.service.labsl.CustomSqlLabslService
  43. import com.persagy.server.service.objects.PropertyService
  44. import com.persagy.server.utils.IdUtils
  45. import com.persagy.server.utils.MatchingProperty
  46. import com.persagy.service.SBaseService
  47. import com.persagy.service.SObjectService
  48. import com.persagy.service.SPageContext
  49. import com.persagy.service.models.enums.SResponseType
  50. import com.persagy.service.models.requests.SQueryRequest
  51. import com.persagy.service.models.requests.SUpdateRequest
  52. import com.persagy.service.models.responses.SBaseResponse
  53. import com.persagy.service.models.responses.SQueryResponse
  54. import com.persagy.service.utils.SSpringContextUtil
  55. import org.slf4j.LoggerFactory
  56. import java.util.*
  57. import kotlin.collections.ArrayList
  58. /**
  59. * 设备和部件信息服务
  60. *
  61. * @author 张维新
  62. */
  63. object EquipmentComService : Service<Equipment>(SMybatisDao(Equipment::class.java)) {
  64. /** 日志 */
  65. private val logger = LoggerFactory.getLogger(EquipmentComService::class.java)
  66. /** MQ消息对象 */
  67. val customSqlLabslService by lazy {
  68. SSpringContextUtil.getBean(CustomSqlLabslService::class.java) as CustomSqlLabslService
  69. }
  70. /** 建筑服务 */
  71. val buildingService = SObjectService(SMybatisDao(Building::class.java))
  72. /** 楼层服务 */
  73. val floorService = SObjectService(SMybatisDao(Floor::class.java))
  74. /** 关系总览服务 */
  75. val relationTypeProjectservice = SBaseService(SMybatisDao(RelationTypeProject::class.java))
  76. /** 字典对象类型 */
  77. private val defClassService = SBaseService(SMybatisDao(DefClass::class.java))
  78. /** 平面图访问设备服务 */
  79. private val planarEquipService = SObjectService(SMybatisDao(PlanarEquip::class.java))
  80. /** 空间服务 */
  81. val spaceService = SObjectService(SMybatisDao(ZoneSpace::class.java))
  82. /**
  83. * 查询之前操作
  84. */
  85. override fun onQueryBefore(queryBuilder: SQueryBuilder<Equipment>) {
  86. queryBuilder.tableName = "v_equip_property_component"
  87. return
  88. }
  89. /**
  90. * 批量处理设备关联资产、 查询接口
  91. *
  92. * @param category 设备或部件类型
  93. * @param request 条件
  94. * @param spaceIdList 空间id列表
  95. * @param spacrType 空间类型
  96. * */
  97. fun equipProperty(category:String, request: SQueryRequest, spaceIdList: ArrayList<String>?, spacrType: String?):SQueryResponse<Equipment> {
  98. return try {
  99. /** 设备类型或设备族类型 */
  100. val rEq2SpService = SBaseService(SMybatisDao(REq2Sp::class.java))
  101. val equipFamilyService = SBaseService(SMybatisDao(EquipFamily::class.java))
  102. val projectId = SPageContext.getHeader("projectId")
  103. if (spaceIdList!=null&&spaceIdList.size>0){
  104. logger.debug("空间*************** ")
  105. /** 获取到空间关联的设备 */
  106. val rEqInSpBaseList = rEq2SpService.select(SFilter.inList("id2", spaceIdList), SFilter.eq("type","eq2sp_in")).exec()
  107. if ( !rEqInSpBaseList.isEmpty()){
  108. val setId = HashSet<String>()
  109. for (rEqInSpBase in rEqInSpBaseList){
  110. setId.add(rEqInSpBase.id1!!)
  111. }
  112. val sQueryResponse = SQueryResponse<Equipment>()
  113. val equipList = select(SFilter.inList("id", setId.toList())).exec()
  114. sQueryResponse.total = equipList.size.toLong()
  115. val iterator = equipList.iterator()
  116. while (iterator.hasNext()) {
  117. var equipment = iterator.next()
  118. if (category != equipment.classCode){
  119. iterator.remove()
  120. }
  121. }
  122. if (equipList.size>0){
  123. val iterator = equipList.iterator()
  124. while (iterator.hasNext()) {
  125. var equipment = iterator.next()
  126. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equipment.classCode!!)).entity()
  127. var propertyList = ArrayList<Property>()
  128. // if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
  129. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("floorId", equipment.floorId!!), SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  130. // }else if (!equipment.buildingId.isNullOrEmpty()&&equipment.floorId.isNullOrEmpty()){
  131. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("buildingId", equipment.buildingId!!),SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  132. // }else{
  133. propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("family", equipFamily!!.family!!),SFilter.isNull("equipId")).exec()
  134. // }
  135. logger.debug("category = ${equipment.classCode}")
  136. logger.debug("Family = ${equipFamily.family}")
  137. logger.debug("匹配长度 = ${propertyList.size}")
  138. if (propertyList.size>0){
  139. /** 计算匹配资产 */
  140. val equipMatchingProperty = MatchingProperty.equipMatchingProperty(equipment, propertyList)
  141. if (equipMatchingProperty.size>0){
  142. equipment.propertyList = equipMatchingProperty
  143. }else{
  144. iterator.remove()
  145. }
  146. }
  147. /** 编码审查 */
  148. IdUtils.codeExanine()
  149. }
  150. }
  151. sQueryResponse.result= SResponseType.success
  152. sQueryResponse.content = equipList
  153. sQueryResponse
  154. }else{
  155. val sQueryResponse = SQueryResponse<Equipment>()
  156. sQueryResponse.total = 0
  157. sQueryResponse.result=SResponseType.success
  158. sQueryResponse.content = ArrayList<Equipment>()
  159. sQueryResponse
  160. }
  161. }else if(!spacrType.isNullOrEmpty()&&spacrType == "noKnow"){
  162. logger.debug("空间类型*************** ")
  163. var floorId: String? = null
  164. var buildingId: String? = null
  165. val queryBuilder = select(request.filters)
  166. val filterList = queryBuilder.filterList
  167. for (filter in filterList){
  168. if (filter.first.toString() == "buildingId"){
  169. buildingId = filter.second.toString()
  170. }else if (filter.first.toString() == "floorId"){
  171. floorId = filter.second.toString()
  172. }
  173. }
  174. val rEqInSpBaseList =rEq2SpService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("type","eq2sp_in")).exec()
  175. // val rEqInSpBaseList = REqInSpBaseService.select(SFilter.eq("projectId", projectId!!)).exec()
  176. val setId = HashSet<String>()
  177. for (rEqInSpBase in rEqInSpBaseList){
  178. setId.add(rEqInSpBase.id1!!)
  179. }
  180. val equipList = select(SFilter.eq("projectId", projectId!!), SFilter.eq("classCode", category), SFilter.eq("buildingId", buildingId!!),
  181. SFilter.eq("floorId", floorId!!), SFilter.not(SFilter.inList("id", setId.toList()))).exec()
  182. if (!equipList.isEmpty()){
  183. val sQueryResponse = SQueryResponse<Equipment>()
  184. sQueryResponse.total = equipList.size.toLong()
  185. val iterator = equipList.iterator()
  186. while (iterator.hasNext()) {
  187. var equipment = iterator.next()
  188. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equipment.classCode!!)).entity()
  189. var propertyList = ArrayList<Property>()
  190. // if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
  191. propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("floorId", equipment.floorId!!), SFilter.isNull("equipId"), SFilter.eq("family", equipFamily!!.family!!)).exec()
  192. // }else if (!equipment.buildingId.isNullOrEmpty()&&equipment.floorId.isNullOrEmpty()){
  193. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("buildingId", equipment.buildingId!!),SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  194. // }else{
  195. propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("family", equipFamily!!.family!!),SFilter.isNull("equipId")).exec()
  196. // }
  197. if (propertyList.size>0){
  198. /** 计算匹配资产 */
  199. val equipMatchingProperty = MatchingProperty.equipMatchingProperty(equipment, propertyList)
  200. if (equipMatchingProperty.size>0){
  201. equipment.propertyList = equipMatchingProperty
  202. }else{
  203. iterator.remove()
  204. }
  205. }
  206. /** 编码审查 */
  207. IdUtils.codeExanine()
  208. }
  209. if (!equipList.isEmpty()){
  210. for (equip in equipList){
  211. if (!equip.buildingId.isNullOrEmpty()){
  212. val building = buildingService.select(SFilter.eq("id", equip.buildingId!!)).entity()
  213. if (building!=null){
  214. equip.building = building
  215. }
  216. }
  217. if (!equip.floorId.isNullOrEmpty()){
  218. val floor = floorService.select(SFilter.eq("id", equip.floorId!!)).entity()
  219. if (floor!=null){
  220. equip.floor = floor
  221. }
  222. }
  223. if (!equip.classCode.isNullOrEmpty()){
  224. val equipFamily = defClassService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("code", equip.classCode!!)).entity()
  225. if (equipFamily!=null){
  226. val equipCategory = EquipCategory()
  227. equipCategory.code = equipFamily.code
  228. equipCategory.name = equipFamily.name
  229. equip.equipCategory = equipCategory
  230. }
  231. }
  232. if (!equip.propertyList!!.isEmpty()){
  233. for ( property in equip.propertyList!!){
  234. if (!property.buildingId.isNullOrEmpty()){
  235. val building = buildingService.select(SFilter.eq("id", property.buildingId!!)).entity()
  236. if (building!=null){
  237. property.building = building
  238. }
  239. }
  240. if (!property.floorId.isNullOrEmpty()){
  241. val floor = floorService.select(SFilter.eq("id", property.floorId!!)).entity()
  242. if (floor!=null){
  243. property.floor = floor
  244. }
  245. }
  246. if (!property.family.isNullOrEmpty()){
  247. val equipFamily = equipFamilyService.select(SFilter.eq("family", property.family!!)).entity()
  248. if (equipFamily!=null){
  249. val family = Family()
  250. family.code = equipFamily.family
  251. family.name = equipFamily.familyName
  252. property.familyName = family
  253. }
  254. }
  255. }
  256. }
  257. }
  258. }
  259. sQueryResponse.result=SResponseType.success
  260. sQueryResponse.content = equipList
  261. sQueryResponse
  262. }else{
  263. val sQueryResponse = SQueryResponse<Equipment>()
  264. sQueryResponse.total = 0
  265. sQueryResponse.result=SResponseType.success
  266. sQueryResponse.content = ArrayList<Equipment>()
  267. sQueryResponse
  268. }
  269. }else if (!spacrType.isNullOrEmpty()){
  270. // logger.debug("空间类型2*************** ")
  271. var floorId: String? = null
  272. var buildingId: String? = null
  273. val zoneSpaceBaseTable = SObjectService(SMybatisDao(ZoneSpace::class.java))
  274. val queryBuilder = select(request.filters)
  275. val filterList = queryBuilder.filterList
  276. for (filter in filterList){
  277. if (filter.first.toString() == "buildingId"){
  278. buildingId = filter.second.toString()
  279. }else if (filter.first.toString() == "floorId"){
  280. floorId = filter.second.toString()
  281. }
  282. }
  283. /** 查询空间数据 */
  284. val zoneSpaceBaseList = zoneSpaceBaseTable.select(SFilter.eq("objectType", spacrType), SFilter.eq("projectId", projectId!!),
  285. SFilter.eq("buildingId", buildingId!!), SFilter.eq("floorId", floorId!!)).exec()
  286. if (!zoneSpaceBaseList.isEmpty()){
  287. val listId = ArrayList<String>()
  288. for (zoneSpaceBase in zoneSpaceBaseList){
  289. listId.add(zoneSpaceBase.id!!)
  290. }
  291. /** 获取到空间关联的设备 */
  292. val rEqInSpBaseList = rEq2SpService.select(SFilter.inList("id2", listId), SFilter.eq("type","eq2sp_in")).exec()
  293. // val rEqInSpBaseList = REqInSpBaseService.select(SFilter.inList("spaceId", listId)).exec()
  294. if ( !rEqInSpBaseList.isEmpty()){
  295. val setId = HashSet<String>()
  296. for (rEqInSpBase in rEqInSpBaseList){
  297. setId.add(rEqInSpBase.id1!!)
  298. }
  299. val sQueryResponse = SQueryResponse<Equipment>()
  300. val equipList = select(SFilter.inList("id", setId.toList())).exec()
  301. sQueryResponse.total = equipList.size.toLong()
  302. val iterator = equipList.iterator()
  303. while (iterator.hasNext()) {
  304. var equipment = iterator.next()
  305. if (category != equipment.classCode){
  306. iterator.remove()
  307. }
  308. }
  309. if (equipList.size>0){
  310. val iterator = equipList.iterator()
  311. while (iterator.hasNext()) {
  312. var equipment = iterator.next()
  313. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equipment.classCode!!)).entity()
  314. var propertyList = ArrayList<Property>()
  315. // if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
  316. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("floorId", equipment.floorId!!), SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  317. // }else if (!equipment.buildingId.isNullOrEmpty()&&equipment.floorId.isNullOrEmpty()){
  318. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("buildingId", equipment.buildingId!!),SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  319. // }else{
  320. propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("family", equipFamily!!.family!!),SFilter.isNull("equipId")).exec()
  321. // }
  322. if (propertyList.size>0){
  323. /** 计算匹配资产 */
  324. val equipMatchingProperty = MatchingProperty.equipMatchingProperty(equipment, propertyList)
  325. if (equipMatchingProperty.size>0){
  326. equipment.propertyList = equipMatchingProperty
  327. }else{
  328. iterator.remove()
  329. }
  330. }
  331. /** 编码审查 */
  332. IdUtils.codeExanine()
  333. }
  334. }
  335. if (!equipList.isEmpty()){
  336. for (equip in equipList){
  337. if (!equip.buildingId.isNullOrEmpty()){
  338. val building = buildingService.select(SFilter.eq("id", equip.buildingId!!)).entity()
  339. if (building!=null){
  340. equip.building = building
  341. }
  342. }
  343. if (!equip.floorId.isNullOrEmpty()){
  344. val floor = floorService.select(SFilter.eq("id", equip.floorId!!)).entity()
  345. if (floor!=null){
  346. equip.floor = floor
  347. }
  348. }
  349. if (!equip.classCode.isNullOrEmpty()){
  350. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equip.classCode!!)).entity()
  351. if (equipFamily!=null){
  352. val equipCategory = EquipCategory()
  353. equipCategory.code = equipFamily.equipCode
  354. equipCategory.name = equipFamily.equipName
  355. equip.equipCategory = equipCategory
  356. }
  357. }
  358. if (!equip.propertyList!!.isEmpty()){
  359. for ( property in equip.propertyList!!){
  360. if (!property.buildingId.isNullOrEmpty()){
  361. val building = buildingService.select(SFilter.eq("id", property.buildingId!!)).entity()
  362. if (building!=null){
  363. property.building = building
  364. }
  365. }
  366. if (!property.floorId.isNullOrEmpty()){
  367. val floor = floorService.select(SFilter.eq("id", property.floorId!!)).entity()
  368. if (floor!=null){
  369. property.floor = floor
  370. }
  371. }
  372. if (!property.family.isNullOrEmpty()){
  373. val equipFamily = equipFamilyService.select(SFilter.eq("family", property.family!!)).entity()
  374. if (equipFamily!=null){
  375. val family = Family()
  376. family.code = equipFamily.family
  377. family.name = equipFamily.familyName
  378. property.familyName = family
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. sQueryResponse.result=SResponseType.success
  386. sQueryResponse.content = equipList
  387. sQueryResponse
  388. }else{
  389. val sQueryResponse = SQueryResponse<Equipment>()
  390. sQueryResponse.total = 0
  391. sQueryResponse.result=SResponseType.success
  392. sQueryResponse.content = ArrayList<Equipment>()
  393. sQueryResponse
  394. }
  395. }else{
  396. val sQueryResponse = SQueryResponse<Equipment>()
  397. sQueryResponse.total = 0
  398. sQueryResponse.result=SResponseType.success
  399. sQueryResponse.content = ArrayList<Equipment>()
  400. sQueryResponse
  401. }
  402. }else{
  403. logger.debug("设备*************** ")
  404. request.pageSize = 100000
  405. SQueryRequest.maxRow = 100000
  406. val pageQuery = pageQuery(request, arrayListOf(SFilter.eq("classCode", category),
  407. SFilter.isNull("propertyId"),SFilter.eq("projectId", projectId!!)))
  408. var contentList :ArrayList<Equipment>? = null
  409. logger.debug("设备***************${pageQuery.toJson()} ")
  410. if (pageQuery.content!=null&&!pageQuery.content!!.isNullOrEmpty()){
  411. contentList = pageQuery.content as ArrayList<Equipment>
  412. }else{
  413. contentList = ArrayList<Equipment>()
  414. }
  415. if (contentList!=null&&!contentList.isEmpty()){
  416. try {
  417. // logger.debug("设备***************11111111111111111111111111")
  418. val iterator = contentList.iterator()
  419. while (iterator.hasNext()){
  420. var equipment = iterator.next()
  421. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equipment.classCode!!)).entity()
  422. var propertyList = ArrayList<Property>()
  423. // if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
  424. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("floorId", equipment.floorId!!), SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  425. // }else if (!equipment.buildingId.isNullOrEmpty()&&equipment.floorId.isNullOrEmpty()){
  426. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("buildingId", equipment.buildingId!!),SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  427. // }else{
  428. propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("family", equipFamily!!.family!!),SFilter.isNull("equipId")).exec()
  429. // }
  430. // logger.debug("category = ${equipment.category}")
  431. // logger.debug("Family = ${equipFamily.family}")
  432. // logger.debug("匹配长度 = ${propertyList.size}")
  433. if (propertyList.size>0){
  434. /** 计算匹配资产 */
  435. val equipMatchingProperty = MatchingProperty.equipMatchingProperty(equipment, propertyList)
  436. logger.debug("匹配到的数据 = ${equipMatchingProperty.size}")
  437. if (equipMatchingProperty.size>0){
  438. equipment.propertyList = equipMatchingProperty
  439. }else{
  440. iterator.remove()
  441. }
  442. /** 编码审查 */
  443. IdUtils.codeExanine()
  444. }else{
  445. iterator.remove()
  446. }
  447. }
  448. // for (equipment in contentList){
  449. // val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equipment.category!!)).entity()
  450. // var propertyList = ArrayList<Property>()
  451. // if (!equipment.buildingId.isNullOrEmpty()&&!equipment.floorId.isNullOrEmpty()){
  452. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("floorId", equipment.floorId!!), SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  453. // }else if (!equipment.buildingId.isNullOrEmpty()&&equipment.floorId.isNullOrEmpty()){
  454. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!),SFilter.eq("buildingId", equipment.buildingId!!),SFilter.isNull("EquipmentId"), SFilter.eq("Family", equipFamily!!.family!!)).exec()
  455. // }else{
  456. // propertyList = PropertyService.select(SFilter.eq("projectId", projectId!!), SFilter.eq("Family", equipFamily!!.family!!),SFilter.isNull("EquipmentId")).exec()
  457. // }
  458. // logger.debug("资产个数 =${propertyList.size}")
  459. // if (propertyList.size>0){
  460. // /** 计算匹配资产 */
  461. // val equipMatchingProperty = MatchingProperty.equipMatchingProperty(equipment, propertyList)
  462. //
  463. // if (equipMatchingProperty.size>0){
  464. // equipment.propertyList = equipMatchingProperty
  465. // }else{
  466. // contentList.remove(equipment)
  467. // }
  468. // try {
  469. // Thread.sleep(500)
  470. // } catch (e: InterruptedException) {
  471. // e.printStackTrace()
  472. // }
  473. // }else{
  474. // contentList.remove(equipment)
  475. // }
  476. // }
  477. } catch (e: Exception) {
  478. e.printStackTrace()
  479. }
  480. }
  481. if (!contentList.isEmpty()){
  482. for (equip in contentList){
  483. if (!equip.buildingId.isNullOrEmpty()){
  484. val building = buildingService.select(SFilter.eq("id", equip.buildingId!!)).entity()
  485. if (building!=null){
  486. equip.building = building
  487. }
  488. }
  489. if (!equip.floorId.isNullOrEmpty()){
  490. try {
  491. val floor = floorService.select(SFilter.eq("id", equip.floorId!!)).entity()
  492. if (floor!= null){
  493. equip.floor = floor
  494. }
  495. } catch (e: Exception) {
  496. e.printStackTrace()
  497. }
  498. }
  499. if (!equip.classCode.isNullOrEmpty()){
  500. val equipFamily = equipFamilyService.select(SFilter.eq("equipCode", equip.classCode!!)).entity()
  501. if (equipFamily!=null){
  502. val equipCategory = EquipCategory()
  503. equipCategory.code = equipFamily.equipCode
  504. equipCategory.name = equipFamily.equipName
  505. equip.equipCategory = equipCategory
  506. }
  507. }
  508. if (!equip.propertyList!!.isEmpty()){
  509. for ( property in equip.propertyList!!){
  510. if (!property.buildingId.isNullOrEmpty()){
  511. val building = buildingService.select(SFilter.eq("id", property.buildingId!!)).entity()
  512. if (building!=null){
  513. property.building = building
  514. }
  515. }
  516. if (!property.floorId.isNullOrEmpty()){
  517. val floor = floorService.select(SFilter.eq("id", property.floorId!!)).entity()
  518. if (floor!=null){
  519. property.floor = floor
  520. }
  521. }
  522. if (!property.family.isNullOrEmpty()){
  523. val equipFamily = equipFamilyService.select(SFilter.eq("family", property.family!!)).entity()
  524. if (equipFamily!=null){
  525. val family = Family()
  526. family.code = equipFamily.family
  527. family.name = equipFamily.familyName
  528. property.familyName = family
  529. }
  530. }
  531. }
  532. }
  533. }
  534. }
  535. pageQuery.content = contentList
  536. pageQuery
  537. }
  538. } catch (e : Exception){
  539. e.printStackTrace()
  540. SQueryResponse(SResponseType.failure, e.rootCause()?.message ?: e.message ?: "未知异常!")
  541. }
  542. }
  543. /**
  544. * 创建设备和资产的关系
  545. */
  546. fun equipPro(request: SUpdateRequest<Property>): SBaseResponse {
  547. return try {
  548. val projectId = SPageContext.getHeader("projectId")
  549. var projection = request.projection
  550. if (projection == null ){
  551. projection = ArrayList()
  552. projection.add("equipId")
  553. }
  554. if (projection!=null&&projection!!.isEmpty()){
  555. projection.add("equipId")
  556. }
  557. if (projection!=null&&!projection.isEmpty()){
  558. projection.clear()
  559. projection.add("equipId")
  560. }
  561. val updateList = PropertyService.updateList(request)
  562. try {
  563. /** 处理关系标记 */
  564. val listtype = ArrayList<String>()
  565. listtype.add("pe2bd")
  566. listtype.add("pe2fl")
  567. listtype.add("pe2sh")
  568. listtype.add("pe2sp")
  569. for (type in listtype){
  570. val entity = relationTypeProjectservice.select(SFilter.eq("projectId", projectId!!), SFilter.eq("relationType", type)).entity()
  571. if (entity!=null){
  572. entity.computationalState = 2
  573. relationTypeProjectservice.update(entity)
  574. }
  575. }
  576. } catch (e: Exception) {
  577. e.printStackTrace()
  578. }
  579. updateList
  580. } catch (e: Exception) {
  581. e.printStackTrace()
  582. SBaseResponse(SResponseType.failure, e.message.toString())
  583. }
  584. }
  585. /**
  586. * 查询设备
  587. *
  588. * @param request 请求条件
  589. */
  590. fun equipQuery(request: PlanarEquipRequests): SQueryResponse<PlanarEquip> {
  591. val sQueryResponse = SQueryResponse<PlanarEquip>()
  592. try {
  593. sQueryResponse.result = SResponseType.success
  594. if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()) {
  595. /** 先查询空间数据 */
  596. if (!request.spaceIds.isNullOrEmpty()) {
  597. // spaceService.select(SFilter.eq())
  598. } else {
  599. }
  600. } else if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()){
  601. } else if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()){
  602. } else if (!request.equipTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()){
  603. }else if (!request.equipTypes.isNullOrEmpty()){
  604. val planarEquipList = planarEquipService.select(
  605. SFilter.eq("buildingId", request.buildingId!!), SFilter.eq("floorId", request.floorId!!),
  606. SFilter.Companion.inList("classCode", request.equipTypes!!)
  607. ).exec()
  608. sQueryResponse.content = planarEquipList
  609. }else {
  610. sQueryResponse.result = SResponseType.failure
  611. }
  612. return sQueryResponse
  613. } catch (e: Exception) {
  614. return SQueryResponse(SResponseType.failure,e.message!!)
  615. }
  616. }
  617. /**
  618. * 查询设备类型统计数量
  619. *
  620. * @param request 请求条件
  621. */
  622. // fun equipQueryCount(request: PlanarEquipRequests): SQueryResponse<EquipQueryCount> {
  623. //
  624. // val sQueryResponse = SQueryResponse<EquipQueryCount>()
  625. // try {
  626. // sQueryResponse.result = SResponseType.success
  627. // if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()) {
  628. //
  629. // } else if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()){
  630. // /** 空间类型 和功能区类型组合查询 */
  631. //
  632. // if (!request.spaceIds.isNullOrEmpty()) {
  633. //
  634. //
  635. //
  636. // } else {
  637. //
  638. // }
  639. //
  640. //
  641. //
  642. // } else if (!request.equipTypes.isNullOrEmpty()&&!request.zoneTypes.isNullOrEmpty()){
  643. //
  644. // } else if (!request.equipTypes.isNullOrEmpty()&&!request.funcTypes.isNullOrEmpty()){
  645. //
  646. //
  647. // }else if (!request.equipTypes.isNullOrEmpty()){
  648. //
  649. //// val planarEquipList = planarEquipService.select(
  650. //// SFilter.eq("buildingId", request.buildingId!!), SFilter.eq("floorId", request.floorId!!),
  651. //// SFilter.inList("classCode", request.equipTypes!!)
  652. //// ).exec()
  653. // val equipTypeCounts = customSqlLabslService.equipTypeCounts(
  654. // Opt.projectId!!,
  655. // request.buildingId!!,
  656. // request.floorId!!,
  657. // request.equipTypes!!
  658. // )
  659. // sQueryResponse.content = equipTypeCounts
  660. // }else {
  661. //
  662. // sQueryResponse.result = SResponseType.failure
  663. // }
  664. // return sQueryResponse
  665. // } catch (e: Exception) {
  666. // return SQueryResponse(SResponseType.failure,e.message!!)
  667. // }
  668. // }
  669. } // Object EquipmentService