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 implements DevNvrService { @Resource private DevNvrDao devNvrDao; @Resource private DHClientFactory dhClientFactory; @Override public PageResult getPage(DevNvrPageReqVO pageReqVO) { PageResult pageResult = devNvrDao.selectPage(pageReqVO); // List list = pageResult.getList(); // dhClientFactory.getNvrOnlineStatus(list); return BeanUtils.toBean(pageResult, DevNvrDTO.class); } @Override public List list(Map params) { QueryWrapper queryWrapper = getWrapper(params); queryWrapper.orderByDesc(Constant.CREATE_DATE); List 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 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 wrapper = new QueryWrapper<>(); wrapper.eq("code", code); DevNvrEntity entity = baseDao.selectOne(wrapper); return ConvertUtils.sourceToTarget(entity, DevNvrDTO.class); } private QueryWrapper getWrapper(Map 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 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 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 wrapper = new QueryWrapper<>(); wrapper.eq("ip", ip); DevNvrEntity entity = new DevNvrEntity(); entity.setIp(ip); entity.setStatus(status); baseDao.update(entity, wrapper); } }