package com.iailab.module.data.video.service.impl;
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.iailab.framework.common.constant.Constant;
|
import com.iailab.framework.common.page.PageData;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.data.video.dao.ImageDao;
|
import com.iailab.module.data.video.dto.ImageDTO;
|
import com.iailab.module.data.video.entity.DataEntity;
|
import com.iailab.module.data.video.entity.ImageEntity;
|
import com.iailab.module.data.video.service.ImageService;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年02月27日
|
*/
|
@Service
|
public class ImageServiceImpl extends BaseServiceImpl<ImageDao, ImageEntity> implements ImageService {
|
|
@Override
|
public PageData<ImageDTO> page(Map<String, Object> params) {
|
IPage<ImageEntity> page = baseDao.selectPage(
|
getPage(params, Constant.CREATE_DATE, false),
|
getWrapper(params)
|
);
|
return getPageData(page, ImageDTO.class);
|
}
|
|
@Override
|
public ImageDTO get(String id) {
|
ImageEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, ImageDTO.class);
|
}
|
|
private QueryWrapper<ImageEntity> getWrapper(Map<String, Object> params){
|
String cameraId = (String)params.get("cameraId");
|
String startTime = (String)params.get("startTime");
|
String endTime = (String)params.get("endTime");
|
|
QueryWrapper<ImageEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq(StringUtils.isNotBlank(cameraId), "camera_id", cameraId)
|
.ge(StringUtils.isNotBlank(startTime), "create_date", startTime)
|
.le(StringUtils.isNotBlank(endTime), "create_date", endTime);
|
|
return wrapper;
|
}
|
|
@Override
|
public List<DataEntity> getValueList(String cameraId, Date startTime, Date endTime) {
|
QueryWrapper<ImageEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq( "camera_id", cameraId)
|
.ge( "create_date", startTime)
|
.le( "create_date", endTime)
|
.orderByAsc("create_date");
|
List<DataEntity> result = new ArrayList<>();
|
List<ImageEntity> list = baseDao.selectList(wrapper);
|
if (CollectionUtils.isEmpty(list)) {
|
return result;
|
}
|
list.forEach(item -> {
|
DataEntity dataEntity = new DataEntity();
|
dataEntity.setDataValue(item.getImagePath());
|
dataEntity.setTimeStamp(item.getCreateDate());
|
result.add(dataEntity);
|
});
|
return result;
|
}
|
|
@Override
|
public String getUrl(String cameraId, String imagePath) {
|
String result = "";
|
QueryWrapper<ImageEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq( "camera_id", cameraId)
|
.eq( "image_path", imagePath)
|
.orderByDesc("create_date");
|
List<ImageEntity> devImageEntities = baseDao.selectList(wrapper);
|
ImageEntity entity = new ImageEntity();
|
if (ObjectUtils.isNotEmpty(devImageEntities)) {
|
entity = devImageEntities.get(0);
|
}
|
if (entity != null) {
|
return entity.getImageUrl();
|
}
|
return result;
|
}
|
|
@Override
|
public void save(ImageDTO dto) {
|
ImageEntity entity = ConvertUtils.sourceToTarget(dto, ImageEntity.class);
|
|
//保存菜单
|
insert(entity);
|
}
|
|
@Override
|
public void update(ImageDTO dto) {
|
ImageEntity entity = ConvertUtils.sourceToTarget(dto, ImageEntity.class);
|
|
//更新菜单
|
updateById(entity);
|
}
|
|
@Override
|
@DSTransactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
//删除菜单
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
@Override
|
public ImageDTO get(String cameraId, Date createDate) {
|
QueryWrapper<ImageEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq( "camera_id", cameraId)
|
.eq( "create_date", createDate);
|
ImageEntity entity = new ImageEntity();
|
List<ImageEntity> devImageEntities = baseDao.selectList(wrapper);
|
if (ObjectUtils.isNotEmpty(devImageEntities)) {
|
entity = devImageEntities.get(0);
|
}
|
return ConvertUtils.sourceToTarget(entity, ImageDTO.class);
|
}
|
|
}
|