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.pojo.PageResult;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.framework.common.util.object.BeanUtils;
|
import com.iailab.framework.common.util.object.ConvertUtils;
|
import com.iailab.module.data.dev.controller.admin.camera.vo.DevCameraPageReqVO;
|
import com.iailab.module.data.dev.dao.DevCameraDao;
|
import com.iailab.module.data.dev.dto.DevCameraDTO;
|
import com.iailab.module.data.dev.entity.DevCameraEntity;
|
import com.iailab.module.data.dev.service.DevCameraService;
|
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import javax.validation.Valid;
|
import java.util.*;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年02月27日
|
*/
|
@Service
|
public class DevCameraServiceImpl extends BaseServiceImpl<DevCameraDao, DevCameraEntity> implements DevCameraService {
|
|
@Resource
|
private DevCameraDao devCameraDao;
|
|
@Override
|
public PageResult<DevCameraDTO> getPage(DevCameraPageReqVO cameraPageReqVO) {
|
PageResult<DevCameraEntity> pageResult = devCameraDao.selectPage(cameraPageReqVO);
|
return BeanUtils.toBean(pageResult, DevCameraDTO.class);
|
}
|
|
@Override
|
public List<DevCameraDTO> list(@Valid DevCameraPageReqVO cameraPageReqVO) {
|
QueryWrapper<DevCameraEntity> queryWrapper = getWrapper(cameraPageReqVO);
|
queryWrapper.orderByDesc(Constant.CREATE_DATE);
|
List<DevCameraEntity> list = baseDao.selectList(queryWrapper);
|
return ConvertUtils.sourceToTarget(list, DevCameraDTO.class);
|
}
|
|
@Override
|
public List<DevCameraDTO> apiCameraList(Map<String, Object> params) {
|
return baseDao.apiCameraList();
|
}
|
|
@Override
|
public List<DevCameraDTO> getByNVRId(String nvrId) {
|
QueryWrapper<DevCameraEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("nvr_id", nvrId).orderByAsc("channel");
|
List<DevCameraEntity> list = baseDao.selectList(queryWrapper);
|
return ConvertUtils.sourceToTarget(list, DevCameraDTO.class);
|
}
|
|
@Override
|
public DevCameraDTO get(String id) {
|
DevCameraEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, DevCameraDTO.class);
|
}
|
|
@Override
|
public DevCameraDTO getByCode(Integer code) {
|
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("code", code);
|
DevCameraEntity entity = baseDao.selectOne(wrapper);
|
|
return ConvertUtils.sourceToTarget(entity, DevCameraDTO.class);
|
}
|
|
private QueryWrapper<DevCameraEntity> getWrapper(DevCameraPageReqVO cameraPageReqVO){
|
String location = cameraPageReqVO.getLocation();
|
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>();
|
wrapper.like(StringUtils.isNotBlank(location), "location", location);
|
return wrapper;
|
}
|
|
@Override
|
public void save(DevCameraDTO dto) {
|
DevCameraEntity entity = ConvertUtils.sourceToTarget(dto, DevCameraEntity.class);
|
entity.setCreateDate(new Date());
|
insert(entity);
|
}
|
|
@Override
|
public void update(DevCameraDTO dto) {
|
DevCameraEntity entity = ConvertUtils.sourceToTarget(dto, DevCameraEntity.class);
|
entity.setUpdateDate(new Date());
|
updateById(entity);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(String[] ids) {
|
baseDao.deleteBatchIds(Arrays.asList(ids));
|
}
|
|
@Override
|
public Long cheack(DevCameraDTO dto) {
|
String id = dto.getId();
|
Integer code = dto.getCode();
|
QueryWrapper<DevCameraEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.ne(StringUtils.isNotBlank(id), "id", id);
|
queryWrapper.and(wrapper -> wrapper.eq("code", code));
|
return baseDao.selectCount(queryWrapper);
|
}
|
|
@Override
|
public List<String> getLocation() {
|
QueryWrapper<DevCameraEntity> wrapper = new QueryWrapper<>();
|
List<DevCameraEntity> devCameraEntities = baseDao.selectList(wrapper);
|
List<String> locations = new ArrayList<>();
|
if(ObjectUtils.isNotEmpty(devCameraEntities)) {
|
devCameraEntities.stream().forEach(cameraEntity -> {
|
locations.add(cameraEntity.getLocation());
|
});
|
}
|
return locations;
|
}
|
|
}
|