package com.iailab.module.data.dev.service.impl; 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.dev.dao.DevImageDao; import com.iailab.module.data.dev.dto.DevImageDTO; import com.iailab.module.data.dev.entity.DataEntity; import com.iailab.module.data.dev.entity.DevImageEntity; import com.iailab.module.data.dev.service.DevImageService; 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 DevImageServiceImpl extends BaseServiceImpl implements DevImageService { @Override public PageData page(Map params) { IPage page = baseDao.selectPage( getPage(params, Constant.CREATE_DATE, false), getWrapper(params) ); return getPageData(page, DevImageDTO.class); } @Override public DevImageDTO get(String id) { DevImageEntity entity = baseDao.selectById(id); return ConvertUtils.sourceToTarget(entity, DevImageDTO.class); } private QueryWrapper getWrapper(Map params){ String cameraId = (String)params.get("cameraId"); String startTime = (String)params.get("startTime"); String endTime = (String)params.get("endTime"); QueryWrapper 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 getValueList(String cameraId, Date startTime, Date endTime) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq( "camera_id", cameraId) .ge( "create_date", startTime) .le( "create_date", endTime) .orderByAsc("create_date"); List result = new ArrayList<>(); List 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 wrapper = new QueryWrapper<>(); wrapper.eq( "camera_id", cameraId) .eq( "image_path", imagePath) .orderByDesc("create_date"); List devImageEntities = baseDao.selectList(wrapper); DevImageEntity entity = new DevImageEntity(); if (ObjectUtils.isNotEmpty(devImageEntities)) { entity = devImageEntities.get(0); } if (entity != null) { return entity.getImageUrl(); } return result; } @Override public void save(DevImageDTO dto) { DevImageEntity entity = ConvertUtils.sourceToTarget(dto, DevImageEntity.class); //保存菜单 insert(entity); } @Override public void update(DevImageDTO dto) { DevImageEntity entity = ConvertUtils.sourceToTarget(dto, DevImageEntity.class); //更新菜单 updateById(entity); } @Override @Transactional(rollbackFor = Exception.class) public void delete(String[] ids) { //删除菜单 baseDao.deleteBatchIds(Arrays.asList(ids)); } @Override public DevImageDTO get(String cameraId, Date createDate) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq( "camera_id", cameraId) .eq( "create_date", createDate); DevImageEntity entity = new DevImageEntity(); List devImageEntities = baseDao.selectList(wrapper); if (ObjectUtils.isNotEmpty(devImageEntities)) { entity = devImageEntities.get(0); } return ConvertUtils.sourceToTarget(entity, DevImageDTO.class); } }