package cn.flightfeather.supervision.lightshare.service.impl
|
|
import cn.flightfeather.supervision.domain.ds1.entity.*
|
import cn.flightfeather.supervision.domain.ds1.mapper.*
|
import cn.flightfeather.supervision.common.utils.Constant
|
import cn.flightfeather.supervision.lightshare.service.*
|
import cn.flightfeather.supervision.lightshare.vo.*
|
import com.github.pagehelper.PageHelper
|
import com.google.gson.Gson
|
import org.springframework.beans.BeanUtils
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Service
|
import org.springframework.transaction.annotation.Transactional
|
import tk.mybatis.mapper.entity.Example
|
import tk.mybatis.mapper.util.StringUtil
|
|
@Service
|
class ScenseServiceImpl(
|
val scenseMapper: ScenseMapper,
|
val sceneConstructionSiteMapper: SceneConstructionSiteMapper,
|
val sceneDeviceMapper: SceneDeviceMapper,
|
val sceneMixingPlantMapper: SceneMixingPlantMapper,
|
val sceneStorageYardMapper: SceneStorageYardMapper,
|
val sceneWharfMapper: SceneWharfMapper,
|
val userinfoService: UserinfoService
|
) : ScenseService {
|
|
@Autowired
|
lateinit var taskService: TaskService
|
|
@Autowired
|
lateinit var domainitemService: DomainitemService
|
|
@Autowired
|
lateinit var monitorobjectversionService: MonitorobjectversionService
|
|
//根据顶层任务ID及已经建立的任务ID列表,查询可用的任务
|
override fun getUserByTaskId(list: List<String>, taskId: String): List<ScenseVo> {
|
val scenseVos = mutableListOf<ScenseVo>()
|
val example = Example(Scense::class.java)
|
val criteria = example.createCriteria()
|
val taskvo = taskService.findByID(taskId)
|
//根据地址获取对应场景
|
criteria.andEqualTo("districtcode", taskvo.districtcode)
|
criteria.andEqualTo("provincecode", taskvo.provincecode)
|
criteria.andEqualTo("citycode", taskvo.citycode)
|
criteria.andEqualTo("towncode", taskvo.towncode)
|
if (list.isNotEmpty()) {
|
//过滤已经选择的ID
|
criteria.andNotIn("guid", list)
|
}
|
val re = scenseMapper.selectByExample(example)
|
if (re.isNotEmpty()) {
|
re.forEach {
|
val scenseVo = ScenseVo()
|
BeanUtils.copyProperties(it, scenseVo)
|
scenseVos.add(scenseVo)
|
}
|
}
|
return scenseVos
|
}
|
|
//根据scense条件查询场景
|
override fun search(scense: Scense): MutableList<ScenseVo> {
|
val scenseVos = mutableListOf<ScenseVo>()
|
val name = scense.name ?: ""
|
val example = Example(Scense::class.java)
|
val criteria = example.createCriteria()
|
//如果有type信息,就构建type查询
|
if (StringUtil.isNotEmpty(scense.type)) {
|
criteria.andEqualTo("type", scense.type)
|
}
|
if (StringUtil.isNotEmpty(scense.provincecode)) {
|
criteria.andEqualTo("provincecode", scense.provincecode)
|
}
|
if (StringUtil.isNotEmpty(scense.citycode)) {
|
criteria.andEqualTo("citycode", scense.citycode)
|
}
|
if (StringUtil.isNotEmpty(scense.districtcode)) {
|
criteria.andEqualTo("districtcode", scense.districtcode)
|
}
|
if (StringUtil.isNotEmpty(scense.towncode)) {
|
criteria.andEqualTo("towncode", scense.towncode)
|
}
|
//name查询
|
criteria.andLike("name", "%$name%")
|
val re = scenseMapper.selectByExample(example)
|
if (re.isNotEmpty()) {
|
re.forEach {
|
val scenseVo = ScenseVo()
|
BeanUtils.copyProperties(it, scenseVo)
|
scenseVos.add(scenseVo)
|
}
|
}
|
return scenseVos
|
}
|
|
//根据name查询
|
override fun findByName(name: String): ScenseVo {
|
val scenseVo = ScenseVo()
|
val scense = Scense()
|
scense.name = name
|
val re = scenseMapper.select(scense)
|
if (re.isNotEmpty()) {
|
BeanUtils.copyProperties(re[0], scenseVo)
|
}
|
return scenseVo
|
}
|
|
//根据ID查询
|
override fun findOne(id: String): ScenseVo {
|
val scenseVo = ScenseVo()
|
val scense = scenseMapper.selectByPrimaryKey(id)
|
if (scense != null) {
|
BeanUtils.copyProperties(scense, scenseVo)
|
}
|
return scenseVo
|
}
|
|
//获取全部
|
override fun findAll(): MutableList<ScenseVo> {
|
val scenseVoList = mutableListOf<ScenseVo>()
|
val scenseList = scenseMapper.selectAll()
|
scenseList.forEach {
|
val scenseVo = ScenseVo()
|
BeanUtils.copyProperties(it, scenseVo)
|
scenseVoList.add(scenseVo)
|
}
|
return scenseVoList
|
}
|
|
override fun save(scense: Scense): Int {
|
// TODO: 2021/7/20 新增场景的同时生成账户
|
val r = scenseMapper.insert(scense)
|
if (r == 1) {
|
scense.guid?.let { userinfoService.createAccount(it) }
|
}
|
return r
|
}
|
|
override fun update(scense: Scense): Int = scenseMapper.updateByPrimaryKeySelective(scense)
|
|
@Transactional
|
override fun updateList(sceneList: MutableList<Scense>): Int {
|
var result = 0
|
sceneList.forEach {
|
result += scenseMapper.updateByPrimaryKeySelective(it)
|
}
|
return result
|
}
|
|
override fun delete(id: String): Int = scenseMapper.deleteByPrimaryKey(id)
|
|
override fun getSceneType(): List<SceneTypeVo> {
|
val d = domainitemService.findByLogName("场景类型")
|
val res = mutableListOf<SceneTypeVo>()
|
d.forEach {
|
val typeId = it.value?.toInt() ?: 0
|
res.add(SceneTypeVo(typeId, it.text))
|
}
|
return res
|
}
|
|
/**
|
*
|
* @param task 总任务
|
* @param mode 0:只会获取总任务对应的监管版本中存在的场景;1:除了监管版本中存在的场景,还会获取剩余的可用场景
|
* @return 场景列表
|
*/
|
override fun getByTaskId(task: Task, mode: Int): ArrayList<ScenseVo> {
|
val movList = monitorobjectversionService.findByTaskId(task.tguid ?: "")
|
val sceneList = scenseMapper.selectByExample(
|
Example(Scense::class.java).apply {
|
createCriteria().andEqualTo("provincecode", task.provincecode)
|
.andEqualTo("citycode", task.citycode)
|
.andEqualTo("districtcode", task.districtcode)
|
|
orderBy("index").asc()
|
}
|
)
|
|
val sceneVoList = mutableListOf<ScenseVo>()
|
sceneList.forEach {
|
val vo = ScenseVo()
|
BeanUtils.copyProperties(it, vo)
|
sceneVoList.add(vo)
|
}
|
|
val result = ArrayList<ScenseVo>()
|
|
when (mode) {
|
0 -> {
|
movList.forEach m@{ m ->
|
sceneVoList.forEach {s ->
|
if (s.guid == m.sguid) {
|
s.monitorNum = m.monitornum ?: 0
|
s.inspectedNum = m.extension1?.toInt() ?: 0
|
result.add(s)
|
return@m
|
}
|
}
|
}
|
}
|
1 -> {
|
movList.forEach m@{ m ->
|
sceneVoList.forEach {s ->
|
if (s.guid == m.sguid) {
|
s.monitorNum = 1
|
s.inspectedNum = 0
|
result.add(s)
|
return@m
|
}
|
}
|
}
|
sceneVoList.forEach {
|
//获取新的场景。extension1:是否完工;monitorNum==0:表示不在上次监管版本中,即新场景
|
if (it.extension1 != "0" && it.monitorNum == 0) {
|
result.add(it)
|
}
|
}
|
}
|
}
|
|
return result
|
}
|
|
override fun getSceneByToken(token: String, page: Int?, perPage: Int?): BaseResponse<BaseSearchResultVo> {
|
if (token != "jinshan") {
|
return BaseResponse(false, "请求token错误")
|
}
|
|
val p = PageHelper.startPage<Scense>(page ?: 1, perPage ?: 30)
|
|
val sceneList = scenseMapper.selectByExample(Example(Scense::class.java).apply {
|
createCriteria().andEqualTo("districtcode", "310116")
|
.andNotEqualTo("extension1", "0")
|
})
|
|
val result = BaseSearchResultVo()
|
|
result.head = DataHead().apply {
|
this.page = p.pageNum
|
this.totalPage = p.pages
|
}
|
|
sceneList.forEach {
|
it.typeid = null
|
it.contactswx = null
|
it.createdate = null
|
it.updatedate = null
|
it.extension1 = null
|
it.index = null
|
}
|
|
result.data.addAll(sceneList)
|
|
return BaseResponse(true, "请求成功", data = result)
|
}
|
|
override fun getSceneDetail(sceneId: String): BaseResponse<SceneDetail> {
|
val sceneDetail = SceneDetail()
|
|
val scene = scenseMapper.selectByPrimaryKey(sceneId)
|
sceneDetail.scense = scene
|
|
val mapper = when (scene.typeid.toString()) {
|
Constant.SceneType.TYPE1.value -> sceneConstructionSiteMapper
|
Constant.SceneType.TYPE2.value -> sceneWharfMapper
|
Constant.SceneType.TYPE3.value -> sceneMixingPlantMapper
|
Constant.SceneType.TYPE14.value -> sceneStorageYardMapper
|
else -> null
|
}
|
|
mapper?.run {
|
val subScene = selectByPrimaryKey(sceneId)
|
sceneDetail.subScene = subScene
|
}
|
|
val sceneDevice = sceneDeviceMapper.selectByPrimaryKey(sceneId)
|
sceneDetail.sceneDevice = sceneDevice
|
|
return BaseResponse(true, data = sceneDetail)
|
}
|
|
override fun updateSceneDetail(typeId: Int, sceneDetailStr: SceneDetailStr): BaseResponse<String> {
|
val result = StringBuilder()
|
|
if (sceneDetailStr.scense?.guid != null) {
|
val r = scenseMapper.updateByPrimaryKeySelective(sceneDetailStr.scense)
|
result.append("场景基本信息更新: $r; ")
|
}
|
if (sceneDetailStr.sceneDevice?.getsGuid() != null) {
|
val record = sceneDeviceMapper.selectByPrimaryKey(sceneDetailStr.sceneDevice?.getsGuid())
|
if (record == null) {
|
val r = sceneDeviceMapper.insert(sceneDetailStr.sceneDevice)
|
result.append("场景设备信息新增: $r; ")
|
} else {
|
val r = sceneDeviceMapper.updateByPrimaryKeySelective(sceneDetailStr.sceneDevice)
|
result.append("场景设备信息更新: $r; ")
|
}
|
}
|
|
if (sceneDetailStr.subScene != null) {
|
var r = 0
|
var isUpdate = true
|
when (typeId.toString()) {
|
Constant.SceneType.TYPE1.value -> {
|
val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneConstructionSite::class.java)
|
if (subScene.getsGuid() != null) {
|
val record = sceneConstructionSiteMapper.selectByPrimaryKey(subScene.getsGuid())
|
isUpdate = record != null
|
r = if (record == null) {
|
sceneConstructionSiteMapper.insert(subScene)
|
} else {
|
sceneConstructionSiteMapper.updateByPrimaryKeySelective(subScene)
|
}
|
}
|
}
|
Constant.SceneType.TYPE2.value -> {
|
val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneWharf::class.java)
|
if (subScene.getsGuid() != null) {
|
val record = sceneWharfMapper.selectByPrimaryKey(subScene.getsGuid())
|
isUpdate = record != null
|
r = if (record == null) {
|
sceneWharfMapper.insert(subScene)
|
} else {
|
sceneWharfMapper.updateByPrimaryKeySelective(subScene)
|
}
|
}
|
}
|
Constant.SceneType.TYPE3.value -> {
|
val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneMixingPlant::class.java)
|
if (subScene.getsGuid() != null) {
|
val record = sceneMixingPlantMapper.selectByPrimaryKey(subScene.getsGuid())
|
isUpdate = record != null
|
r = if (record == null) {
|
sceneMixingPlantMapper.insert(subScene)
|
} else {
|
sceneMixingPlantMapper.updateByPrimaryKeySelective(subScene)
|
}
|
}
|
}
|
Constant.SceneType.TYPE14.value -> {
|
val subScene = Gson().fromJson(sceneDetailStr.subScene, SceneStorageYard::class.java)
|
if (subScene.getsGuid() != null) {
|
val record = sceneStorageYardMapper.selectByPrimaryKey(subScene.getsGuid())
|
isUpdate = record != null
|
r = if (record == null) {
|
sceneStorageYardMapper.insert(subScene)
|
} else {
|
sceneStorageYardMapper.updateByPrimaryKeySelective(subScene)
|
}
|
}
|
}
|
}
|
result.append("场景特有信息${if (isUpdate) "更新" else "新增"}: $r; ")
|
}
|
|
return BaseResponse(true, data = result.toString())
|
}
|
|
override fun searchScene(areaVo: AreaVo, page: Int?, perPage: Int?): BaseResponse<List<Scense>> {
|
val p = PageHelper.startPage<Scense>(page ?: 1, perPage ?: 30)
|
val list = scenseMapper.selectByExample(Example(Scense::class.java).apply {
|
createCriteria().apply {
|
areaVo.provincecode?.let { andEqualTo("provincecode", it) }
|
areaVo.citycode?.let { andEqualTo("citycode", it) }
|
areaVo.districtcode?.let { andEqualTo("districtcode", it) }
|
areaVo.towncode?.let { andEqualTo("towncode", it) }
|
areaVo.scensetypeid?.let { andEqualTo("typeid", it) }
|
areaVo.sceneName?.let { andLike("name", "%${it}%") }
|
|
}
|
areaVo.online?.let {
|
and(createCriteria().apply {
|
if (it) {
|
orNotEqualTo("extension1", "0").orIsNull("extension1")
|
} else {
|
andEqualTo("extension1", "0")
|
}
|
})
|
}
|
orderBy("typeid").orderBy("index")
|
})
|
return BaseResponse(true, head = DataHead(p.pageNum, p.pages, p.total), data = list)
|
}
|
}
|