| | |
| | | package cn.flightfeather.supervision.lightshare.service.impl |
| | | |
| | | import cn.flightfeather.supervision.common.exception.BizException |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Mediafile |
| | | import cn.flightfeather.supervision.domain.ds1.mapper.MediafileMapper |
| | | import cn.flightfeather.supervision.common.utils.Constant |
| | | import cn.flightfeather.supervision.common.utils.FileUtil |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Inspection |
| | | import cn.flightfeather.supervision.domain.ds1.repository.InspectionRep |
| | | import cn.flightfeather.supervision.domain.ds1.repository.MediaFileRep |
| | | import cn.flightfeather.supervision.domain.ds1.repository.SceneRep |
| | | import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep |
| | | import cn.flightfeather.supervision.lightshare.service.DomainitemService |
| | | import cn.flightfeather.supervision.lightshare.service.MediafileService |
| | | import cn.flightfeather.supervision.lightshare.vo.MediaFileVo |
| | | import com.fasterxml.jackson.core.type.TypeReference |
| | |
| | | class MediafileServiceImpl( |
| | | val mediafileMapper: MediafileMapper, |
| | | private val mediaFileRep: MediaFileRep, |
| | | private val inspectionRep: InspectionRep, |
| | | private val subTaskRep: SubTaskRep, |
| | | private val sceneRep: SceneRep, |
| | | private val domainItemService: DomainitemService, |
| | | @Value("\${filePath}") var filePath: String, |
| | | @Value("\${imgPath}") var imgPath: String, |
| | | ) : MediafileService { |
| | |
| | | val mediafilelist = mediafileMapper.select(mediafile) |
| | | mediafilelist.sortBy { it.savetime } |
| | | return mediafilelist |
| | | } |
| | | |
| | | /** |
| | | * 获取所有任意拍常规记录图片 |
| | | * @param iGuid |
| | | */ |
| | | override fun getRoutineRecord(iGuid: String?, stGuid: String?): List<Mediafile?> { |
| | | var inspectionGuid = iGuid |
| | | val sceneId = if (iGuid != null) { |
| | | inspectionRep.findOne(iGuid)?.sguid |
| | | } else if (stGuid != null) { |
| | | val s = subTaskRep.findOne(stGuid) |
| | | val ins = inspectionRep.findOne(Inspection().apply { stguid = stGuid }) |
| | | inspectionGuid = ins?.guid |
| | | s?.scenseid |
| | | } else { |
| | | throw BizException("巡查记录id和巡查任务id至少填写其中一个") |
| | | } |
| | | sceneId ?: throw BizException("记录对应的场景不存在") |
| | | val sceneInfo = sceneRep.findScene(sceneId = sceneId) ?: throw BizException("场景不存在,获取场景图片失败") |
| | | val mediaFileTypeList = domainItemService.getMediaFileType(sceneInfo.typeid?.toInt()).entries.map { it.key?.toInt() } |
| | | return mediaFileRep.findList(inspectionGuid, mediaFileTypeList) |
| | | } |
| | | |
| | | //根据问题id获取媒体文件 |
| | |
| | | |
| | | override fun save(mediafile: Mediafile): Int = mediafileMapper.updateByPrimaryKey(mediafile) |
| | | |
| | | override fun saveMediaFile(files: Array<MultipartFile>, getMediaFile: () -> Mediafile): Int { |
| | | var res = 0 |
| | | // 保存图片 |
| | | for (image in files) { |
| | | val mediaFile = getMediaFile() |
| | | res += mediafileMapper.insert(mediaFile) |
| | | |
| | | val path = mediaFile.extension1 |
| | | val fileName = mediaFile.guid + ".jpg" |
| | | val filePath = "${imgPath}/$path/" |
| | | try { |
| | | //调用文件保存方法 |
| | | FileUtil.uploadFile(image.bytes, filePath, fileName) |
| | | } catch (e: Exception) { |
| | | // TODO: handle exception |
| | | } |
| | | } |
| | | return res |
| | | } |
| | | |
| | | override fun update(mediafile: Mediafile): Int = mediafileMapper.updateByPrimaryKey(mediafile) |
| | | |
| | | //删除媒体文件 |
| | |
| | | |
| | | override fun deleteList(idList: List<String>): Int { |
| | | var res = 0 |
| | | if (idList.isEmpty()) return res |
| | | mediaFileRep.findList(idList).forEach { |
| | | //服务器保存路径 |
| | | val path = it?.extension1 |