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 implements DevCameraService { @Resource private DevCameraDao devCameraDao; @Override public PageResult getPage(DevCameraPageReqVO cameraPageReqVO) { PageResult pageResult = devCameraDao.selectPage(cameraPageReqVO); return BeanUtils.toBean(pageResult, DevCameraDTO.class); } @Override public List list(@Valid DevCameraPageReqVO cameraPageReqVO) { QueryWrapper queryWrapper = getWrapper(cameraPageReqVO); queryWrapper.orderByDesc(Constant.CREATE_DATE); List list = baseDao.selectList(queryWrapper); return ConvertUtils.sourceToTarget(list, DevCameraDTO.class); } @Override public List apiCameraList(Map params) { return baseDao.apiCameraList(); } @Override public List getByNVRId(String nvrId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("nvr_id", nvrId).orderByAsc("channel"); List 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 wrapper = new QueryWrapper<>(); wrapper.eq("code", code); DevCameraEntity entity = baseDao.selectOne(wrapper); return ConvertUtils.sourceToTarget(entity, DevCameraDTO.class); } private QueryWrapper getWrapper(DevCameraPageReqVO cameraPageReqVO){ String location = cameraPageReqVO.getLocation(); QueryWrapper 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 queryWrapper = new QueryWrapper<>(); queryWrapper.ne(StringUtils.isNotBlank(id), "id", id); queryWrapper.and(wrapper -> wrapper.eq("code", code)); return baseDao.selectCount(queryWrapper); } @Override public List getLocation() { QueryWrapper wrapper = new QueryWrapper<>(); List devCameraEntities = baseDao.selectList(wrapper); List locations = new ArrayList<>(); if(ObjectUtils.isNotEmpty(devCameraEntities)) { devCameraEntities.stream().forEach(cameraEntity -> { locations.add(cameraEntity.getLocation()); }); } return locations; } }