123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- package com.iden.bms.service;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.util.StrUtil;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.iden.common.entity.IdenCamera;
- import com.iden.common.enums.CameraTypeEnum;
- import com.iden.common.enums.ConnectStatusEnum;
- import com.iden.common.service.IdenCameraService;
- import com.iden.common.util.MyBeanUtils;
- import com.iden.common.vo.CameraVO;
- import com.iden.common.vo.PageReqVO;
- import com.iden.common.vo.UserLoginedConvertVO;
- import org.springframework.beans.BeanUtils;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- *
- * @author makejava
- * @since 2021-05-21 00:08:38
- */
- @Service
- public class CameraService {
- @Resource
- private IdenCameraService idenCameraService;
- public Integer countCamera(String type, String district, String subdistrict, Long communityId, String name, UserLoginedConvertVO loginUser) {
- QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().like(StrUtil.isNotEmpty(name),IdenCamera::getName,name)
- .eq(StrUtil.isNotEmpty(district),IdenCamera::getDistrict,district)
- .eq(StrUtil.isNotEmpty(subdistrict),IdenCamera::getSubdistrict,subdistrict)
- .eq(communityId != null,IdenCamera::getCommunityId,communityId)
- .eq(StrUtil.isNotEmpty(type),IdenCamera::getType,type);
- return this.idenCameraService.count(queryWrapper);
- }
- /**
- * 查询摄像头列表
- * @return
- */
- public IPage<CameraVO> listCamera(String type, String district, String subdistrict, Long communityId, String name, UserLoginedConvertVO loginUser, PageReqVO pageReqVo) {
- IPage<IdenCamera> page = new Page<>(pageReqVo.getCurrent(), pageReqVo.getPageSize());
- QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().like(StrUtil.isNotEmpty(name),IdenCamera::getName,name)
- .eq(StrUtil.isNotEmpty(district),IdenCamera::getDistrict,district)
- .eq(StrUtil.isNotEmpty(subdistrict),IdenCamera::getSubdistrict,subdistrict)
- .eq(communityId != null,IdenCamera::getCommunityId,communityId)
- .eq(StrUtil.isNotEmpty(type),IdenCamera::getType,type)
- .orderByAsc(IdenCamera::getCode);
- IPage<IdenCamera> pageRes = this.idenCameraService.page(page, queryWrapper);
- IPage<CameraVO> results = new Page<>(pageRes.getCurrent(),pageRes.getSize(),pageRes.getTotal());
- if(CollUtil.isNotEmpty(pageRes.getRecords())){
- List<CameraVO> list = new ArrayList<>();
- pageRes.getRecords().forEach(item -> {
- CameraVO resVO = new CameraVO();
- BeanUtils.copyProperties(item,resVO);
- resVO.setStatusName(ConnectStatusEnum.getValueToName(resVO.getCode()));
- resVO.setTypeName(CameraTypeEnum.getValueToName(resVO.getType()));
- list.add(resVO);
- });
- results.setRecords(list);
- }
- return results;
- }
- /**
- * 删除摄像头
- * @param id
- * @return
- */
- public boolean deleteById(Long id){
- return this.idenCameraService.removeById(id);
- }
- /**
- * 详情
- * @param id
- * @return
- */
- public CameraVO getCameraById(Long id){
- IdenCamera idenCamera = this.idenCameraService.getById(id);
- if (idenCamera!=null){
- CameraVO resVO = new CameraVO();
- BeanUtil.copyProperties(idenCamera,resVO);
- resVO.setStatusName(ConnectStatusEnum.getValueToName(resVO.getCode()));
- resVO.setTypeName(CameraTypeEnum.getValueToName(resVO.getType()));
- return resVO;
- }
- return null;
- }
- /**
- * 保存摄像头
- * @param vo
- */
- @Transactional(rollbackFor = Exception.class)
- public int createCamera(CameraVO vo, UserLoginedConvertVO loginUser){
- QueryWrapper<IdenCamera> queryWrapper = new QueryWrapper<>();
- queryWrapper.lambda().eq(IdenCamera::getName,vo.getName());
- if(idenCameraService.count(queryWrapper) > 0){
- return 1;
- }
- QueryWrapper<IdenCamera> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.lambda().eq(IdenCamera::getCode,vo.getCode());
- if(idenCameraService.count(queryWrapper2) > 0){
- return 2;
- }
- //保存摄像头
- IdenCamera idenCamera = new IdenCamera();
- BeanUtil.copyProperties(vo,idenCamera);
- idenCamera.setCreateTime(new Date());
- this.idenCameraService.save(idenCamera);
- return 0;
- }
- /**
- * 修改摄像头
- * @param vo
- */
- @Transactional(rollbackFor = Exception.class)
- public void updateCamera(CameraVO vo){
- //保存摄像头
- IdenCamera idenCamera = this.idenCameraService.getById(vo.getId());
- MyBeanUtils.copyProperties(vo,idenCamera);
- idenCamera.setModifyTime(new Date());
- this.idenCameraService.updateById(idenCamera);
- }
- }
|