From dc4f12f66685260ac357997680e5f3fe723c3c4a Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期五, 12 九月 2025 17:22:40 +0800 Subject: [PATCH] 2025.9.12 1. 新增监测设备和巡查场景信息的匹配功能 --- src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt | 267 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 259 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt index 18706fb..623d7b1 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt @@ -1,21 +1,33 @@ package cn.flightfeather.supervision.business.autooutput.dataanalysis +import cn.flightfeather.supervision.common.exception.BizException import cn.flightfeather.supervision.common.utils.Constant -import cn.flightfeather.supervision.domain.ds2.repository.JADustSiteMapRep -import cn.flightfeather.supervision.domain.ds3.repository.JSDustSiteMapRep +import cn.flightfeather.supervision.common.utils.ExcelUtil +import cn.flightfeather.supervision.domain.ds1.entity.Scense +import cn.flightfeather.supervision.domain.ds1.repository.SceneRep +import cn.flightfeather.supervision.domain.ds1.repository.TaskRep +import cn.flightfeather.supervision.domain.ds1.repository.UserInfoSVRep +import cn.flightfeather.supervision.domain.ds2.repository.JADustSiteRep +import cn.flightfeather.supervision.domain.ds3.repository.JSDustSiteRep import cn.flightfeather.supervision.domain.ds3.repository.XHFumeSiteMapRep -import cn.flightfeather.supervision.lightshare.vo.AreaVo -import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo +import cn.flightfeather.supervision.lightshare.vo.* +import com.github.pagehelper.PageHelper +import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.springframework.stereotype.Component +import java.io.FileOutputStream +import java.util.* /** * 鐩戞祴鏁版嵁鍜岀郴缁熺敤鎴风殑鏄犲皠绠$悊 */ @Component class AopDataDeviceMap( - private val jaDustSiteMapRep: JADustSiteMapRep, - private val jsDustSiteMapRep: JSDustSiteMapRep, + private val jaDustSiteRep: JADustSiteRep, + private val jsDustSiteRep: JSDustSiteRep, private val xhFumeSiteMapRep: XHFumeSiteMapRep, + private val taskRep: TaskRep, + private val sceneRep: SceneRep, + private val userInfoSVRep: UserInfoSVRep, ) { /** @@ -50,7 +62,7 @@ //闈欏畨鍖� "310106" -> when (areaVo.scensetypeid) { //宸ュ湴 - Constant.SceneType.TYPE1.value -> jaDustSiteMapRep.findBySVUserId(userIdList) + Constant.SceneType.TYPE1.value -> jaDustSiteRep.findMapBySVUserId(userIdList) else -> emptyList() } //閲戝北鍖� @@ -59,7 +71,7 @@ Constant.SceneType.TYPE1.value, Constant.SceneType.TYPE2.value, Constant.SceneType.TYPE3.value, - -> jsDustSiteMapRep.findBySVUserId(userIdList) + -> jsDustSiteRep.findMapBySVUserId(userIdList) else -> emptyList() } //寰愭眹鍖� @@ -72,4 +84,243 @@ } } + + fun insertOrUpdate(areaVo: AreaVo, mapSet: List<DeviceMapVo>):Int { + return when (areaVo.sourceType) { + //浠ラ缇界幆澧冪郴缁熶腑鐨勭敤鎴蜂负涓讳綋 + 1 -> { + insertOrUpdate1(areaVo,mapSet) + } + //浠ラ缇界洃绠$郴缁熶腑鐨勭敤鎴蜂负涓讳綋 + 2 -> { + insertOrUpdate2(areaVo,mapSet) + } + else -> 0 + } + } + + private fun insertOrUpdate1(areaVo: AreaVo, mapSet: List<DeviceMapVo>):Int { + return when (areaVo.districtcode) { + //寰愭眹鍖� + "310104" -> { + when (areaVo.scensetypeid) { + //姹戒慨 + Constant.SceneTypeTZ.VehicleRepair.value.toString() -> 0 + else -> 0 + } + } + else -> 0 + } + } + + private fun insertOrUpdate2(areaVo: AreaVo, mapSet: List<DeviceMapVo>):Int { + return when (areaVo.districtcode) { + //闈欏畨鍖� + "310106" -> { + val mapSet1 = mapSet.map { DeviceMapVo.toJADustSiteMap(it) } + when (areaVo.scensetypeid) { + //宸ュ湴 + Constant.SceneType.TYPE1.value -> { + var rc = 0 + mapSet1.forEach { + rc += if(jaDustSiteRep.findByPrimaryKey(it.id) == null) { + jaDustSiteRep.insert(it) + } else { + jaDustSiteRep.update(it) + } + } + rc + } + else -> 0 + } + } + //閲戝北鍖� + "310116" -> { + val mapSet1 = mapSet.map { DeviceMapVo.toJSDustSiteMap(it) } + when (areaVo.scensetypeid) { + //宸ュ湴,鐮佸ご姘存偿鎼呮媽绔� + Constant.SceneType.TYPE1.value, + Constant.SceneType.TYPE2.value, + Constant.SceneType.TYPE3.value, + -> { + var rc = 0 + mapSet1.forEach { + rc += if(jsDustSiteRep.findByPrimaryKey(it.id) == null) { + jsDustSiteRep.insert(it) + } else { + jsDustSiteRep.update(it) + } + } + rc + } + + else -> 0 + } + } + //寰愭眹鍖� + "310104" -> { + val mapSet1 = mapSet.map { DeviceMapVo.toXHFumeSiteMap(it) } + when (areaVo.scensetypeid) { + //椁愰ギ + Constant.SceneType.TYPE5.value -> { + var rc = 0 + mapSet1.forEach { + rc += if(xhFumeSiteMapRep.findByPrimaryKey(it.id) == null) { + xhFumeSiteMapRep.insert(it) + } else { + xhFumeSiteMapRep.update(it) + } + } + rc + } + else -> 0 + } + } + else -> 0 + + } + } + + /** + * 鎼滅储璁惧 + * @param areaVo 鍖哄煙鏉′欢 + * @param keyword 鎼滅储鍏抽敭璇� + * @param page 椤电爜 + * @param perPage 姣忛〉鏁伴噺 + * @return 璁惧鍒楄〃 + */ + fun searchDevice(areaVo: AreaVo, keyword: String, page: Int, perPage: Int): Pair<DataHead, List<DeviceSiteVo>> { + return when (areaVo.districtcode) { + //闈欏畨鍖� + "310106" -> when (areaVo.scensetypeid) { + //宸ュ湴 + Constant.SceneType.TYPE1.value -> { + val pageInfo = PageHelper.startPage<DeviceSiteVo>(page, perPage) + val list = jaDustSiteRep.searchSiteInfo(keyword) + DataHead(pageInfo.pageNum, pageInfo.pages, pageInfo.total) to list + } + + else -> DataHead() to emptyList() + } + //閲戝北鍖� + "310116" -> when (areaVo.scensetypeid) { + //宸ュ湴,鐮佸ご姘存偿鎼呮媽绔� + Constant.SceneType.TYPE1.value, + Constant.SceneType.TYPE2.value, + Constant.SceneType.TYPE3.value, + -> { + val pageInfo = PageHelper.startPage<DeviceSiteVo>(page, perPage) + val list = jsDustSiteRep.searchSiteInfo(keyword) + DataHead(pageInfo.pageNum, pageInfo.pages, pageInfo.total) to list + } + + else -> DataHead() to emptyList() + } + //寰愭眹鍖� + "310104" -> when (areaVo.scensetypeid) { + //椁愰ギ + Constant.SceneType.TYPE5.value -> { +// val pageInfo = PageHelper.startPage<DeviceSiteVo>(page, perPage) +// val list = xhFumeSiteRep.searchSiteInfo(keyword) +// DataHead(pageInfo.pageNum, pageInfo.pages, pageInfo.total) to list + DataHead() to emptyList() + } + else -> DataHead() to emptyList() + } + + else -> DataHead() to emptyList() + } + } + + /** + * 杈撳嚭鐩戞祴鐐逛綅鍜岀洃娴嬭澶囩殑瀵瑰簲鍖归厤鍏崇郴 + * @param areaVo 鍖哄煙鏉′欢 + */ + fun outputMapSet(areaVo: AreaVo) { + // 鐩戠鎬讳换鍔� + val task = taskRep.findOneTask(areaVo) ?: throw BizException("褰撳墠鏌ヨ鏉′欢涓嬫湭鎵惧埌瀵瑰簲椤跺眰浠诲姟") + // 鎬讳换鍔″寘鍚搴旂被鍨嬬殑鍦烘櫙 + val scenes = sceneRep.findSceneList(task.tguid!!, areaVo.scensetypeid?.toInt(), areaVo.towncode) + val sceneIds = scenes.map { it?.guid } + val userIdList = userInfoSVRep.findUser(sceneIds).map { it?.guid } + // 鍦烘櫙鍜岀洃娴嬬偣鐨勫尮閰嶅叧绯� + val mapSet = this.findMapSet(areaVo, userIdList) + // 鐩戞祴璁惧淇℃伅 + val deviceSiteList = when (areaVo.districtcode) { + //闈欏畨鍖� + "310106" -> when (areaVo.scensetypeid) { + //宸ュ湴 + Constant.SceneType.TYPE1.value -> jaDustSiteRep.findSiteInfo() + else -> emptyList() + } + //閲戝北鍖� + "310116" -> when (areaVo.scensetypeid) { + //宸ュ湴,鐮佸ご姘存偿鎼呮媽绔� + Constant.SceneType.TYPE1.value, + Constant.SceneType.TYPE2.value, + Constant.SceneType.TYPE3.value, + -> jsDustSiteRep.findSiteInfo() + else -> emptyList() + } + //寰愭眹鍖� + "310104" -> when (areaVo.scensetypeid) { + //椁愰ギ + Constant.SceneType.TYPE5.value -> emptyList() + else -> emptyList() + } + else -> emptyList() + } + + outputMapSetToFile(areaVo, scenes, mapSet, deviceSiteList) + } + + /** + * 杈撳嚭鐩戞祴鐐逛綅鍜岀洃娴嬭澶囩殑瀵瑰簲鍖归厤鍏崇郴鍒版枃浠朵腑 + * @param scenes 鍦烘櫙淇℃伅鍒楄〃 + * @param mapSet 鍦烘櫙鍜岀洃娴嬬偣瀵瑰簲鍏崇郴 + * @param siteList 鐩戞祴鐐逛俊鎭垪琛� + */ + private fun outputMapSetToFile(areaVo: AreaVo, scenes: List<Scense?>, mapSet: List<DeviceMapVo>, siteList: + List<DeviceSiteVo>) { + val _scenes = mutableListOf<Scense?>().also { it.addAll(scenes) } + val _siteList = mutableListOf<DeviceSiteVo>().also { it.addAll(siteList) } + + val sceneDeviceList = mutableListOf<SceneDeviceVo>() + //琛ㄥご + val head = sceneDeviceList.tableHead() + scenes.forEach { + val sceneDeviceVo = SceneDeviceVo() + sceneDeviceVo.scene = it + val user = userInfoSVRep.findUser(it?.guid) + mapSet.findBySVUserId(user?.guid).forEach { map -> + val site = siteList.findByMNCode(map.deviceCode) + sceneDeviceVo.deviceList.add(site) + _siteList.remove(site) + } + sceneDeviceList.add(sceneDeviceVo) + } + //鍐呭 + val contents = sceneDeviceList.tableContent() + + + val workbook = HSSFWorkbook() + ExcelUtil.write(head, contents, workbook, sheetName = "鍦烘櫙璁惧鍖归厤") + + val head2 = sceneDeviceList.tableHeadDevice() + val contents2 = mutableListOf<Array<Any>>() + _siteList.forEach { + contents2.add(arrayOf(it.id ?: "", it.mnCode ?: "", it.name ?: "", it.address ?: "", it.beginDate ?: "", it + .dutyCompany ?: "", it.groupName ?: "")) + } + ExcelUtil.write(head2, contents2, workbook, sheetName = "鏈尮閰嶈澶�") + + val path = "target/" + val fileName = "${areaVo.districtname}-鍦烘櫙璁惧淇℃伅-${Date().time}.xls" + val out = FileOutputStream(path + fileName) + workbook.write(out) + workbook.close() + out.flush() + out.close() + } + } \ No newline at end of file -- Gitblit v1.9.3