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.nvr.vo.DevNvrPageReqVO;
|
import com.iailab.module.data.dev.controller.admin.nvr.vo.DevNvrSaveReqVO;
|
import com.iailab.module.data.dev.dahua.DHCapturePictureClient;
|
import com.iailab.module.data.dev.dahua.DHClientFactory;
|
import com.iailab.module.data.dev.dao.DevNvrDao;
|
import com.iailab.module.data.dev.dto.DevNvrDTO;
|
import com.iailab.module.data.dev.entity.DevNvrEntity;
|
import com.iailab.module.data.dev.service.DevNvrService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年03月07日
|
*/
|
@Service
|
public class DevNvrServiceImpl extends BaseServiceImpl<DevNvrDao, DevNvrEntity> implements DevNvrService {
|
|
@Resource
|
private DevNvrDao devNvrDao;
|
|
@Resource
|
private DHClientFactory dhClientFactory;
|
|
@Override
|
public PageResult<DevNvrDTO> getPage(DevNvrPageReqVO pageReqVO) {
|
PageResult<DevNvrEntity> pageResult = devNvrDao.selectPage(pageReqVO);
|
// List<DevNvrEntity> list = pageResult.getList();
|
// dhClientFactory.getNvrOnlineStatus(list);
|
return BeanUtils.toBean(pageResult, DevNvrDTO.class);
|
}
|
|
@Override
|
public List<DevNvrDTO> list(Map<String, Object> params) {
|
QueryWrapper<DevNvrEntity> queryWrapper = getWrapper(params);
|
queryWrapper.orderByDesc(Constant.CREATE_DATE);
|
List<DevNvrEntity> list = baseDao.selectList(queryWrapper);
|
return ConvertUtils.sourceToTarget(list, DevNvrDTO.class);
|
}
|
|
@Override
|
public DevNvrDTO get(String id) {
|
DevNvrEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, DevNvrDTO.class);
|
}
|
|
@Override
|
public DevNvrDTO getByIp(String ip) {
|
QueryWrapper<DevNvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("ip", ip);
|
DevNvrEntity entity = baseDao.selectOne(wrapper);
|
|
return ConvertUtils.sourceToTarget(entity, DevNvrDTO.class);
|
}
|
|
@Override
|
public DevNvrDTO getByCode(String code) {
|
QueryWrapper<DevNvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("code", code);
|
DevNvrEntity entity = baseDao.selectOne(wrapper);
|
|
return ConvertUtils.sourceToTarget(entity, DevNvrDTO.class);
|
}
|
|
private QueryWrapper<DevNvrEntity> getWrapper(Map<String, Object> params) {
|
String code = (String) params.get("code");
|
String location = (String) params.get("location");
|
String nvrId = (String) params.get("nvrId");
|
Integer status = params.get("status") == null ? null : Integer.parseInt(params.get("status").toString());
|
|
QueryWrapper<DevNvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.like(StringUtils.isNotBlank(code), "code", code)
|
.like(StringUtils.isNotBlank(location), "location", location)
|
.eq(StringUtils.isNotBlank(nvrId), "nvr_id", nvrId)
|
.eq(status != null, "status", status);
|
|
return wrapper;
|
}
|
|
@Override
|
public String save(DevNvrSaveReqVO saveReqVO) {
|
DevNvrEntity entity = BeanUtils.toBean(saveReqVO, DevNvrEntity.class);
|
entity.setCreateDate(new Date());
|
insert(entity);
|
return entity.getId();
|
}
|
|
@Override
|
public String update(DevNvrSaveReqVO saveReqVO) {
|
DevNvrEntity entity = BeanUtils.toBean(saveReqVO, DevNvrEntity.class);
|
entity.setCreateDate(new Date());
|
updateById(entity);
|
return entity.getId();
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void delete(Long id) {
|
devNvrDao.deleteById(id);
|
}
|
|
// @Override
|
// public Long cheack(DevNvrDTO dto) {
|
// Long id = dto.getId();
|
// String code = dto.getCode();
|
// String name = dto.getName();
|
// QueryWrapper<DevNvrEntity> queryWrapper = new QueryWrapper<>();
|
// queryWrapper.ne(StringUtils.isNotBlank(id.toString()), "id", id);
|
// queryWrapper.and(wrapper -> wrapper.eq("code", code).or().
|
// eq(StringUtils.isNotBlank(name), "name", name));
|
// return baseDao.selectCount(queryWrapper);
|
// }
|
|
@Override
|
public void setStatus(String ip, Integer status) {
|
QueryWrapper<DevNvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("ip", ip);
|
DevNvrEntity entity = new DevNvrEntity();
|
entity.setIp(ip);
|
entity.setStatus(status);
|
baseDao.update(entity, wrapper);
|
}
|
}
|