| | |
| | | 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, |
| | | ) { |
| | | |
| | | /** |
| | |
| | | //静安区 |
| | | "310106" -> when (areaVo.scensetypeid) { |
| | | //工地 |
| | | Constant.SceneType.TYPE1.value -> jaDustSiteMapRep.findBySVUserId(userIdList) |
| | | Constant.SceneType.TYPE1.value -> jaDustSiteRep.findMapBySVUserId(userIdList) |
| | | else -> emptyList() |
| | | } |
| | | //金山区 |
| | |
| | | Constant.SceneType.TYPE1.value, |
| | | Constant.SceneType.TYPE2.value, |
| | | Constant.SceneType.TYPE3.value, |
| | | -> jsDustSiteMapRep.findBySVUserId(userIdList) |
| | | -> jsDustSiteRep.findMapBySVUserId(userIdList) |
| | | else -> emptyList() |
| | | } |
| | | //徐汇区 |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | 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() |
| | | } |
| | | |
| | | } |