From e2f8fb1fbe26ba6d92f3e5dfcaeb0c69abe76b25 Mon Sep 17 00:00:00 2001 From: jiangping <jp@doumee.com> Date: 星期四, 14 十二月 2023 14:28:57 +0800 Subject: [PATCH] 海康接口对接开发 --- server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 101 insertions(+), 4 deletions(-) diff --git a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java index 9409027..7449ddc 100644 --- a/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java +++ b/server/dmvisit_service/src/main/java/com/doumee/service/business/impl/DeviceRoleServiceImpl.java @@ -1,19 +1,31 @@ package com.doumee.service.business.impl; +import com.doumee.core.constants.ResponseStatus; +import com.doumee.core.exception.BusinessException; +import com.doumee.core.model.LoginUserInfo; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; +import com.doumee.core.utils.Constants; import com.doumee.core.utils.Utils; import com.doumee.dao.business.DeviceRoleMapper; +import com.doumee.dao.business.model.Device; import com.doumee.dao.business.model.DeviceRole; +import com.doumee.dao.web.response.DeviceRoleVO; import com.doumee.service.business.DeviceRoleService; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.commons.collections.CollectionUtils; +import org.apache.shiro.SecurityUtils; +import org.checkerframework.checker.units.qual.C; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; + +import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -29,8 +41,40 @@ @Override public Integer create(DeviceRole deviceRole) { - deviceRoleMapper.insert(deviceRole); - return deviceRole.getId(); + + QueryWrapper<DeviceRole> query = new QueryWrapper<>(); + query.lambda() + .eq(DeviceRole::getIsdeleted,Constants.ZERO) + .eq(DeviceRole::getType,deviceRole.getType()) + .eq(DeviceRole::getStatus,Constants.ONE); + List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); + if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�"); + } + + LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); + DeviceRole insert = new DeviceRole(); + + insert.setCreator(loginUserInfo.getId().toString()); + insert.setCreateDate(new Date()); + insert.setEdirot(loginUserInfo.getId().toString()); + insert.setEditDate(new Date()); + insert.setIsdeleted(Constants.ZERO); + insert.setRemark(deviceRole.getRemark()); + insert.setName(deviceRole.getName()); + insert.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); + insert.setType(deviceRole.getType()); + insert.setDoorIds(deviceRole.getDoorIds()); + insert.setDoorNames(deviceRole.getDoorNames()); + insert.setParkIds(deviceRole.getParkIds()); + insert.setParkNames(deviceRole.getParkNames()); + insert.setStatus(deviceRole.getStatus()); + insert.setHkId(deviceRole.getHkId()); + insert.setHkStatus(deviceRole.getHkStatus()); + insert.setHkDate(deviceRole.getHkDate()); + + deviceRoleMapper.insert(insert); + return insert.getId(); } @Override @@ -54,7 +98,39 @@ @Override public void updateById(DeviceRole deviceRole) { + + QueryWrapper<DeviceRole> query = new QueryWrapper<>(); + query.lambda() + .eq(DeviceRole::getIsdeleted,Constants.ZERO) + .eq(DeviceRole::getType,deviceRole.getType()) + .eq(DeviceRole::getStatus,Constants.ONE); + List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); + if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�"); + } + deviceRole.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); deviceRoleMapper.updateById(deviceRole); + } + + @Override + public void updateStatusById(DeviceRole deviceRole) { + QueryWrapper<DeviceRole> query = new QueryWrapper<>(); + query.lambda() + .eq(DeviceRole::getIsdeleted,Constants.ZERO) + .eq(DeviceRole::getType,deviceRole.getType()) + .eq(DeviceRole::getStatus,Constants.ONE); + List<DeviceRole> deviceRoles = deviceRoleMapper.selectList(query); + if (CollectionUtils.isNotEmpty(deviceRoles) && Constants.equalsInteger(Constants.ONE,deviceRole.getStatus())){ + throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(),"鍚屼竴涓敤鎴风被鍨嬶紝鍙兘鏈変竴涓粯璁よ鑹�"); + } + LoginUserInfo loginUserInfo = (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); + DeviceRole update = new DeviceRole(); + update.setEdirot(loginUserInfo.getId().toString()); + update.setEditDate(new Date()); + update.setId(deviceRole.getId()); + update.setStatus(deviceRole.getStatus()); + update.setIsDefault(Constants.equalsInteger(Constants.ONE,deviceRole.getStatus()) ? 0 : 1); + deviceRoleMapper.updateById(update); } @Override @@ -83,7 +159,7 @@ QueryWrapper<DeviceRole> wrapper = new QueryWrapper<>(deviceRole); return deviceRoleMapper.selectList(wrapper); } - + @Override public PageData<DeviceRole> findPage(PageWrap<DeviceRole> pageWrap) { IPage<DeviceRole> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); @@ -136,6 +212,9 @@ if (pageWrap.getModel().getStatus() != null) { queryWrapper.lambda().eq(DeviceRole::getStatus, pageWrap.getModel().getStatus()); } + + queryWrapper.select("t_aa.*," + + "(SELECT count(DISTINCT `KEY`) FROM `test` WHERE `test`.`key` = `t_aa`.id ) "); for(PageWrap.SortData sortData: pageWrap.getSorts()) { if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { queryWrapper.orderByDesc(sortData.getProperty()); @@ -151,4 +230,22 @@ QueryWrapper<DeviceRole> wrapper = new QueryWrapper<>(deviceRole); return deviceRoleMapper.selectCount(wrapper); } + + @Override + public List<DeviceRoleVO> findListByType(Integer type) { + List<DeviceRole> deviceRoleList = deviceRoleMapper.selectList(new QueryWrapper<DeviceRole>().lambda() + .eq(DeviceRole::getType,type) + .eq(DeviceRole::getIsdeleted, Constants.ZERO) + .eq(DeviceRole::getStatus, Constants.ZERO) + ); + List<DeviceRoleVO> deviceRoleVOList = new ArrayList<>(); + for (DeviceRole deviceRole:deviceRoleList) { + DeviceRoleVO deviceRoleVO = new DeviceRoleVO(); + BeanUtils.copyProperties(deviceRole,deviceRoleVO); + deviceRoleVOList.add(deviceRoleVO); + } + return deviceRoleVOList; + } + + } -- Gitblit v1.9.3