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.iailab.framework.common.constant.Constant;
|
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.framework.web.core.util.WebFrameworkUtils;
|
import com.iailab.module.data.video.controller.admin.nvr.vo.NvrPageReqVO;
|
import com.iailab.module.data.video.controller.admin.nvr.vo.NvrSaveReqVO;
|
import com.iailab.module.data.video.dahua.DHClientFactory;
|
import com.iailab.module.data.video.dao.NvrDao;
|
import com.iailab.module.data.video.dto.NvrDTO;
|
import com.iailab.module.data.video.entity.NvrEntity;
|
import com.iailab.module.data.video.service.NvrService;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年03月07日
|
*/
|
@Service
|
public class NvrServiceImpl extends BaseServiceImpl<NvrDao, NvrEntity> implements NvrService {
|
|
@Resource
|
private NvrDao nvrDao;
|
|
@Resource
|
private DHClientFactory dhClientFactory;
|
|
@Override
|
public PageResult<NvrDTO> getPage(NvrPageReqVO pageReqVO) {
|
PageResult<NvrEntity> pageResult = nvrDao.selectPage(pageReqVO);
|
// List<DevNvrEntity> list = pageResult.getList();
|
// dhClientFactory.getNvrOnlineStatus(list);
|
return BeanUtils.toBean(pageResult, NvrDTO.class);
|
}
|
|
@Override
|
public List<NvrDTO> list(Map<String, Object> params) {
|
QueryWrapper<NvrEntity> queryWrapper = getWrapper(params);
|
queryWrapper.orderByDesc(Constant.CREATE_DATE);
|
List<NvrEntity> list = baseDao.selectList(queryWrapper);
|
return ConvertUtils.sourceToTarget(list, NvrDTO.class);
|
}
|
|
@Override
|
public NvrDTO get(String id) {
|
NvrEntity entity = baseDao.selectById(id);
|
|
return ConvertUtils.sourceToTarget(entity, NvrDTO.class);
|
}
|
|
@Override
|
public NvrDTO getByIp(String ip) {
|
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("ip", ip);
|
NvrEntity entity = baseDao.selectOne(wrapper);
|
|
return ConvertUtils.sourceToTarget(entity, NvrDTO.class);
|
}
|
|
@Override
|
public NvrDTO getByCode(String code) {
|
QueryWrapper<NvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("code", code);
|
NvrEntity entity = baseDao.selectOne(wrapper);
|
|
return ConvertUtils.sourceToTarget(entity, NvrDTO.class);
|
}
|
|
private QueryWrapper<NvrEntity> 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<NvrEntity> 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(NvrSaveReqVO saveReqVO) {
|
NvrEntity entity = BeanUtils.toBean(saveReqVO, NvrEntity.class);
|
entity.setCreateDate(new Date());
|
entity.setUpdater(WebFrameworkUtils.getLoginUserId());
|
insert(entity);
|
return entity.getId();
|
}
|
|
@Override
|
public String update(NvrSaveReqVO saveReqVO) {
|
NvrEntity entity = BeanUtils.toBean(saveReqVO, NvrEntity.class);
|
entity.setUpdateDate(new Date());
|
entity.setUpdater(WebFrameworkUtils.getLoginUserId());
|
updateById(entity);
|
return entity.getId();
|
}
|
|
@Override
|
@DSTransactional(rollbackFor = Exception.class)
|
public void delete(String id) {
|
nvrDao.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<NvrEntity> wrapper = new QueryWrapper<>();
|
wrapper.eq("ip", ip);
|
NvrEntity entity = new NvrEntity();
|
entity.setIp(ip);
|
entity.setStatus(status);
|
baseDao.update(entity, wrapper);
|
}
|
}
|