src/main/kotlin/cn/flightfeather/supervision/business/autooutput/dataanalysis/AopDataDeviceMap.kt
@@ -11,6 +11,7 @@ import cn.flightfeather.supervision.domain.ds3.repository.JSDustSiteRep import cn.flightfeather.supervision.domain.ds3.repository.XHFumeSiteMapRep 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 @@ -84,6 +85,153 @@ } } 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 区域条件 src/main/kotlin/cn/flightfeather/supervision/domain/ds2/repository/JADustSiteRep.kt
@@ -1,12 +1,15 @@ package cn.flightfeather.supervision.domain.ds2.repository import cn.flightfeather.supervision.domain.ds2.entity.DustSiteInfo import cn.flightfeather.supervision.domain.ds2.entity.DustSiteMap import cn.flightfeather.supervision.domain.ds2.mapper.DustSiteInfoMapper import cn.flightfeather.supervision.domain.ds2.mapper.DustSiteMapMapper import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo import cn.flightfeather.supervision.lightshare.vo.DeviceSiteVo import com.github.pagehelper.PageHelper import org.springframework.stereotype.Repository import tk.mybatis.mapper.entity.Example import java.util.* /** * 静安工地扬尘监测点位数据库相关操作 @@ -37,4 +40,37 @@ val res = dustSiteInfoMapper.selectAll() return DeviceSiteVo.fromJADustSiteInfo(res) } fun searchSiteInfo(keyword: String): List<DeviceSiteVo> { val res = dustSiteInfoMapper.selectByExample(Example(DustSiteInfo::class.java).apply { createCriteria().andLike("name", "%$keyword%") }) return DeviceSiteVo.fromJADustSiteInfo(res) } /** * 根据id查询 */ fun findByPrimaryKey(id: Int?): DustSiteMap? { if (id == null) { return null } return dustSiteMapMapper.selectByPrimaryKey(id) } /** * 新增 */ fun insert(dustSiteMap: DustSiteMap): Int { dustSiteMap.createTime = Date() return dustSiteMapMapper.insert(dustSiteMap) } /** * 更新 */ fun update(dustSiteMap: DustSiteMap): Int { dustSiteMap.createTime = Date() return dustSiteMapMapper.updateByPrimaryKeySelective(dustSiteMap) } } src/main/kotlin/cn/flightfeather/supervision/domain/ds3/repository/JSDustSiteRep.kt
@@ -1,5 +1,6 @@ package cn.flightfeather.supervision.domain.ds3.repository import cn.flightfeather.supervision.domain.ds3.entity.JSDustSiteInfo import cn.flightfeather.supervision.domain.ds3.entity.JSDustSiteMap import cn.flightfeather.supervision.domain.ds3.mapper.JSDustSiteInfoMapper import cn.flightfeather.supervision.domain.ds3.mapper.JSDustSiteMapMapper @@ -7,6 +8,7 @@ import cn.flightfeather.supervision.lightshare.vo.DeviceSiteVo import org.springframework.stereotype.Repository import tk.mybatis.mapper.entity.Example import java.util.* /** * 金山扬尘监测点位和系统用户映射关系数据库相关操作 @@ -37,4 +39,37 @@ val res = jsDustSiteInfoMapper.selectAll() return DeviceSiteVo.fromJSDustSiteInfo(res) } fun searchSiteInfo(keyword: String): List<DeviceSiteVo> { val res = jsDustSiteInfoMapper.selectByExample(Example(JSDustSiteInfo::class.java).apply { createCriteria().andLike("name", "%$keyword%") }) return DeviceSiteVo.fromJSDustSiteInfo(res) } /** * 根据id查询 */ fun findByPrimaryKey(id: Int?): JSDustSiteMap? { if (id == null) { return null } return jsDustSiteMapMapper.selectByPrimaryKey(id) } /** * 新增 */ fun insert(jsDustSiteMap: JSDustSiteMap): Int { jsDustSiteMap.createTime = Date() return jsDustSiteMapMapper.insert(jsDustSiteMap) } /** * 更新 */ fun update(jsDustSiteMap: JSDustSiteMap): Int { jsDustSiteMap.createTime = Date() return jsDustSiteMapMapper.updateByPrimaryKeySelective(jsDustSiteMap) } } src/main/kotlin/cn/flightfeather/supervision/domain/ds3/repository/XHFumeSiteMapRep.kt
@@ -5,6 +5,7 @@ import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo import org.springframework.stereotype.Repository import tk.mybatis.mapper.entity.Example import java.util.* /** * 徐汇油烟监测点位和系统用户映射关系数据库相关操作 @@ -23,4 +24,30 @@ }) return DeviceMapVo.fromXHFumeSiteMap(res) } /** * 新增 */ fun insert(fumeSiteMap: FumeSiteMap): Int { fumeSiteMap.createTime = Date() return fumeSiteMapMapper.insert(fumeSiteMap) } /** * 更新 */ fun update(fumeSiteMap: FumeSiteMap): Int { fumeSiteMap.createTime = Date() return fumeSiteMapMapper.updateByPrimaryKeySelective(fumeSiteMap) } /** * 根据id查询 */ fun findByPrimaryKey(id: Int?): FumeSiteMap? { if (id == null) { return null } return fumeSiteMapMapper.selectByPrimaryKey(id) } } src/main/kotlin/cn/flightfeather/supervision/lightshare/service/UserMapService.kt
@@ -4,7 +4,9 @@ import cn.flightfeather.supervision.domain.ds1.entity.Userinfo import cn.flightfeather.supervision.domain.ds2.entity.UserMap import cn.flightfeather.supervision.lightshare.vo.AreaVo import cn.flightfeather.supervision.lightshare.vo.DataHead import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo import cn.flightfeather.supervision.lightshare.vo.DeviceSiteVo interface UserMapService { @@ -18,7 +20,23 @@ */ fun getSceneByTZId(tzUserId: String): Scense? /** * 自动创建飞羽监管和飞羽环境的账户匹配记录 */ fun autoCreateMap(userList: List<Userinfo?>) /** * 获取监测设备和监管账户的匹配记录 */ fun fetchDeviceMap(page: Int?, perPage: Int?, areaVo: AreaVo): List<DeviceMapVo?> /** * 新增或更新 */ fun insertOrUpdate(param: Pair<AreaVo, DeviceMapVo>): Int /** * 搜索第三方设备 */ fun searchThirdPartyDevice(areaVo: AreaVo, keyword: String, page: Int?, perPage: Int?): Pair<DataHead, List<DeviceSiteVo>> } src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/UserMapServiceImpl.kt
@@ -17,7 +17,9 @@ import cn.flightfeather.supervision.domain.ds2.repository.UserMapRep import cn.flightfeather.supervision.lightshare.service.UserMapService import cn.flightfeather.supervision.lightshare.vo.AreaVo import cn.flightfeather.supervision.lightshare.vo.DataHead import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo import cn.flightfeather.supervision.lightshare.vo.DeviceSiteVo import org.springframework.stereotype.Service import tk.mybatis.mapper.entity.Example import java.util.* @@ -102,18 +104,64 @@ //以飞羽环境系统中的用户为主体 1 -> { val u = userInfoTZRep.findEnterpriseUser(areaVo.districtname, areaVo.scensetypeid?.toInt()) u.map { it?.guid } u.map { it?.guid to it?.realname } } //以飞羽监管系统中的用户为主体 2 -> { val task = taskRep.findOneTask(areaVo) ?: throw BizException("当前查询条件下未找到对应顶层任务") val scenes = sceneRep.findSceneList(task.tguid!!, areaVo.scensetypeid?.toInt(), areaVo.towncode) .map { it?.guid } userInfoSVRep.findUser(scenes).map { it?.guid } userInfoSVRep.findUser(scenes).map { it?.guid to it?.realname } } else -> emptyList() } // 2.通过区域条件决定匹配的数据来源 return aopDataDeviceMap.findMapSet(areaVo, userIdList) val mapSet = aopDataDeviceMap.findMapSet(areaVo, userIdList.map { it.first }) val result = mutableListOf<DeviceMapVo>() // 将不在mapSet中的用户,添加到结果集中 userIdList.forEach {u -> val ddm = mapSet.find { m-> when (areaVo.sourceType) { //以飞羽环境系统中的用户为主体 1 -> m.tzUserId == u.first //以飞羽监管系统中的用户为主体 2 -> m.svUserId == u.first else -> false } } if (ddm == null) { result.add(DeviceMapVo().apply { when (areaVo.sourceType) { //以飞羽环境系统中的用户为主体 1 -> { tzUserId = u.first tzUserName = u.second } //以飞羽监管系统中的用户为主体 2 -> { svUserId = u.first svUserName = u.second } } }) } } // 将mapSet中的数据添加到结果集中 result.addAll(mapSet) return result.sortedBy { it.svUserId } } override fun insertOrUpdate(param: Pair<AreaVo, DeviceMapVo>): Int { return aopDataDeviceMap.insertOrUpdate(param.first, listOf(param.second)) } override fun searchThirdPartyDevice( areaVo: AreaVo, keyword: String, page: Int?, perPage: Int?, ): Pair<DataHead, List<DeviceSiteVo>> { return aopDataDeviceMap.searchDevice(areaVo, keyword, page ?: 1, perPage ?: 30) } } src/main/kotlin/cn/flightfeather/supervision/lightshare/vo/DeviceMapVo.kt
@@ -10,6 +10,7 @@ * 监测设备和飞羽监管系统、飞羽环境系统用户的匹配关系 */ class DeviceMapVo { var id: Int? = null // 监测设备id var deviceCode:String?=null // 监测设备或站点名称 @@ -31,6 +32,7 @@ list.forEach { it ?: return@forEach res.add(DeviceMapVo().apply { id = it.id deviceCode = it.jaMnCode deviceName = it.jaSceneName svUserId = it.svUserId @@ -43,11 +45,25 @@ return res } fun toJADustSiteMap(deviceMapVo: DeviceMapVo?): DustSiteMap { return DustSiteMap().apply { id = deviceMapVo?.id jaMnCode = deviceMapVo?.deviceCode jaSceneName = deviceMapVo?.deviceName svUserId = deviceMapVo?.svUserId svUserName = deviceMapVo?.svUserName tzUserId = deviceMapVo?.tzUserId tzUserName = deviceMapVo?.tzUserName createTime = deviceMapVo?.createTime } } fun fromJSDustSiteMap(list: List<JSDustSiteMap?>): List<DeviceMapVo> { val res = mutableListOf<DeviceMapVo>() list.forEach { it ?: return@forEach res.add(DeviceMapVo().apply { id = it.id deviceCode = it.jsDeviceCode deviceName = it.jsDeviceName svUserId = it.svUserId @@ -60,11 +76,25 @@ return res } fun toJSDustSiteMap(deviceMapVo: DeviceMapVo?): JSDustSiteMap { return JSDustSiteMap().apply { id = deviceMapVo?.id jsDeviceCode = deviceMapVo?.deviceCode jsDeviceName = deviceMapVo?.deviceName svUserId = deviceMapVo?.svUserId svUserName = deviceMapVo?.svUserName tzUserId = deviceMapVo?.tzUserId tzUserName = deviceMapVo?.tzUserName createTime = deviceMapVo?.createTime } } fun fromXHFumeSiteMap(list: List<FumeSiteMap?>): List<DeviceMapVo> { val res = mutableListOf<DeviceMapVo>() list.forEach { it ?: return@forEach res.add(DeviceMapVo().apply { id = it.id deviceCode = it.xhDeviceCode deviceName = it.xhDeviceName svUserId = it.svUserId @@ -76,6 +106,19 @@ } return res } fun toXHFumeSiteMap(deviceMapVo: DeviceMapVo?): FumeSiteMap { return FumeSiteMap().apply { id = deviceMapVo?.id xhDeviceCode = deviceMapVo?.deviceCode xhDeviceName = deviceMapVo?.deviceName svUserId = deviceMapVo?.svUserId svUserName = deviceMapVo?.svUserName tzUserId = deviceMapVo?.tzUserId tzUserName = deviceMapVo?.tzUserName createTime = deviceMapVo?.createTime } } } } src/main/kotlin/cn/flightfeather/supervision/lightshare/web/UserMapController.kt
@@ -2,6 +2,7 @@ import cn.flightfeather.supervision.lightshare.service.UserMapService import cn.flightfeather.supervision.lightshare.vo.AreaVo import cn.flightfeather.supervision.lightshare.vo.DeviceMapVo import io.swagger.annotations.Api import io.swagger.annotations.ApiOperation import io.swagger.annotations.ApiParam @@ -30,4 +31,24 @@ @ApiParam("区域条件信息") @RequestBody areaVo: AreaVo ) = resPack { userMapService.fetchDeviceMap(page, perPage, areaVo) } @ApiOperation(value = "新增或更新用户监测设备映射关系") @PostMapping("/insertOrUpdate") fun insertOrUpdate( @ApiParam("用户监测设备映射关系") @RequestBody param: Pair<AreaVo, DeviceMapVo>, ) = resPack { userMapService.insertOrUpdate(param) } @ApiOperation(value = "搜索第三方设备") @PostMapping("/searchThirdPartyDevice") fun searchThirdPartyDevice( @ApiParam("区域条件信息") @RequestBody areaVo: AreaVo, @ApiParam("搜索关键字,匹配设备名") @RequestParam keyword: String, @ApiParam("查询页码", defaultValue = "1", required = false) @RequestParam("page", required = false) page: Int?, @ApiParam("单页数据量", defaultValue = "30", required = false) @RequestParam("per_page", required = false) perPage: Int?, ) = resPack { userMapService.searchThirdPartyDevice(areaVo, keyword, page, perPage) } }