|
@@ -0,0 +1,219 @@
|
|
|
+package com.fdkankan.fusion.service.impl;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.fdkankan.fusion.common.PageInfo;
|
|
|
+import com.fdkankan.fusion.common.ResultCode;
|
|
|
+import com.fdkankan.fusion.common.enums.IdPreEnum;
|
|
|
+import com.fdkankan.fusion.common.util.IdUtils;
|
|
|
+import com.fdkankan.fusion.entity.TmCamera;
|
|
|
+import com.fdkankan.fusion.entity.TmDepartment;
|
|
|
+import com.fdkankan.fusion.entity.TmUser;
|
|
|
+import com.fdkankan.fusion.exception.BusinessException;
|
|
|
+import com.fdkankan.fusion.httpClient.FdService;
|
|
|
+import com.fdkankan.fusion.httpClient.client.FdKKClient;
|
|
|
+import com.fdkankan.fusion.httpClient.request.FdkkCameraParam;
|
|
|
+import com.fdkankan.fusion.httpClient.response.FdkkResponse;
|
|
|
+import com.fdkankan.fusion.mapper.ITmCameraMapper;
|
|
|
+import com.fdkankan.fusion.response.BindCameraDto;
|
|
|
+import com.fdkankan.fusion.response.CameraVo;
|
|
|
+import com.fdkankan.fusion.service.ITmCameraService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.fusion.service.ITmDepartmentService;
|
|
|
+import com.fdkankan.fusion.service.ITmUserService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.ibatis.annotations.Param;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 相机关联关系表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-07-28
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TmCameraServiceImpl extends ServiceImpl<ITmCameraMapper, TmCamera> implements ITmCameraService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FdService fdService;
|
|
|
+ @Autowired
|
|
|
+ ITmDepartmentService tmDepartmentService;
|
|
|
+ @Autowired
|
|
|
+ ITmUserService tmUserService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TmCamera> getByUserId(String userId) {
|
|
|
+ LambdaQueryWrapper<TmCamera> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TmCamera::getUserId,userId);
|
|
|
+ return list(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TmCamera getBySnCode(String snCode) {
|
|
|
+ LambdaQueryWrapper<TmCamera> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TmCamera::getCameraSn,snCode);
|
|
|
+ return getOne(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bind(BindCameraDto param) {
|
|
|
+ if(StringUtils.isNoneBlank(param.getCameraSn(),param.getDeptId(),param.getUserId())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ TmUser tmUser = tmUserService.getById(param.getUserId());
|
|
|
+ if(tmUser == null || tmUser.getStatus() == 0){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ TmDepartment tmDepartment = tmDepartmentService.getById(param.getDeptId());
|
|
|
+ if(tmDepartment == null){
|
|
|
+ throw new BusinessException(ResultCode.DEPT_NOT_EXITS);
|
|
|
+ }
|
|
|
+ TmCamera tmCamera = this.getBySnCode(param.getCameraSn());
|
|
|
+ if(tmCamera != null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_EXITS);
|
|
|
+ }
|
|
|
+ FdkkResponse<CameraVo> fdkkResponse = fdService.getCameraDetail(param.getCameraSn());
|
|
|
+ if(fdkkResponse.getCode() !=0 || fdkkResponse.getData() == null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXITS);
|
|
|
+ }
|
|
|
+ FdkkResponse fdkkResponse2 = fdService.fdkKBind(param.getCameraSn());
|
|
|
+ if(fdkkResponse2.getCode() != 0){
|
|
|
+ throw new BusinessException(fdkkResponse2.getCode(),fdkkResponse2.getMsg());
|
|
|
+ }
|
|
|
+ tmCamera = new TmCamera();
|
|
|
+ tmCamera.setId(IdUtils.genId(IdPreEnum.CAMERA_PRE.getPre()));
|
|
|
+ tmCamera.setCameraSn(param.getCameraSn());
|
|
|
+ tmCamera.setDeptId(param.getDeptId());
|
|
|
+ tmCamera.setUserId(param.getUserId());
|
|
|
+ tmCamera.setFdCameraId(fdkkResponse.getData().getId());
|
|
|
+ tmCamera.setCreatorId((String) StpUtil.getLoginId());
|
|
|
+ this.save(tmCamera);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unBind(BindCameraDto param) {
|
|
|
+ if(StringUtils.isBlank(param.getCameraSn())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ TmCamera tmCamera = this.getBySnCode(param.getCameraSn());
|
|
|
+ if(tmCamera == null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXITS);
|
|
|
+ }
|
|
|
+ this.unBind(Arrays.asList(tmCamera));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void unBind(List<TmCamera> cameras) {
|
|
|
+ if(CollectionUtil.isNotEmpty(cameras)){
|
|
|
+ //四维解绑相机
|
|
|
+ List<String> tmCameraIds = cameras.stream().map(TmCamera::getId).collect(Collectors.toList());
|
|
|
+ FdkkResponse fdkkResponse = fdService.fdkkUnbind(cameras);
|
|
|
+ if(fdkkResponse.getCode() == 0 ){
|
|
|
+ this.removeByIds(tmCameraIds);
|
|
|
+ }else {
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(BindCameraDto param) {
|
|
|
+ if(StringUtils.isNoneBlank(param.getCameraSn(),param.getUserId())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ TmUser tmUser = tmUserService.getById(param.getUserId());
|
|
|
+ if(tmUser == null || tmUser.getStatus() == 0){
|
|
|
+ throw new BusinessException(ResultCode.USER_NOT_EXIST);
|
|
|
+ }
|
|
|
+ TmCamera tmCamera = this.getBySnCode(param.getCameraSn());
|
|
|
+ if(tmCamera == null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXITS);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<TmCamera> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(TmCamera::getCameraSn,param.getCameraSn());
|
|
|
+ wrapper.set(TmCamera::getUserId,param.getUserId());
|
|
|
+ this.update(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object getDetail(String snCode) {
|
|
|
+ if(StringUtils.isBlank(snCode)){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+
|
|
|
+ TmCamera tmCamera = this.getBySnCode(snCode);
|
|
|
+ if(tmCamera == null){
|
|
|
+ throw new BusinessException(ResultCode.CAMERA_NOT_EXITS);
|
|
|
+ }
|
|
|
+ return fdService.getCameraDetail(snCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pageList(Long pageNum, Long pageSize, String snCode, String deptId, Integer type) {
|
|
|
+ LambdaQueryWrapper<TmCamera> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(snCode)) {
|
|
|
+ wrapper.like(TmCamera::getCameraSn,snCode);
|
|
|
+ }
|
|
|
+ if(StringUtils.isNotBlank(deptId)){
|
|
|
+ wrapper.eq(TmCamera::getDeptId,deptId);
|
|
|
+ }
|
|
|
+ List<String> deptIds = tmDepartmentService.getDeptIds();
|
|
|
+ wrapper.in(TmCamera::getDeptId,deptIds);
|
|
|
+ wrapper.orderByDesc(TmCamera::getCreateTime);
|
|
|
+ Page<TmCamera> page = this.page(new Page<>(pageNum, pageSize), wrapper);
|
|
|
+ List<String> snCodes = page.getRecords().stream().map(TmCamera::getCameraSn).collect(Collectors.toList());
|
|
|
+ FdkkResponse<List<CameraVo>> fdkkResponse = fdService.getCameraDetails(snCodes);
|
|
|
+
|
|
|
+ HashMap<String,String> deptIdMap = new HashMap<>();
|
|
|
+ HashMap<String,String> deptNameMap = new HashMap<>();
|
|
|
+ for (TmCamera record : page.getRecords()) {
|
|
|
+ deptIdMap.put(record.getCameraSn(),record.getDeptId());
|
|
|
+ }
|
|
|
+ Set<String> strings = deptIdMap.keySet();
|
|
|
+ List<TmDepartment> departments = tmDepartmentService.listByIds(strings);
|
|
|
+ for (TmDepartment department : departments) {
|
|
|
+ deptNameMap.put(department.getId(),department.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<CameraVo> list = fdkkResponse.getData();
|
|
|
+ for (CameraVo cameraVo : list) {
|
|
|
+ String deptIdO = deptIdMap.get(cameraVo.getSnCode());
|
|
|
+ cameraVo.setDeptId(deptIdO);
|
|
|
+ cameraVo.setDeptName(deptNameMap.get(deptIdO));
|
|
|
+ }
|
|
|
+ Page<CameraVo> objectPage = new Page<>(pageNum, pageSize);
|
|
|
+ objectPage.setRecords(list);
|
|
|
+ objectPage.setTotal(page.getTotal());
|
|
|
+ return PageInfo.PageInfo(objectPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TmCamera> getByDeptIds() {
|
|
|
+ List<String> deptIds = tmDepartmentService.getDeptIds();
|
|
|
+
|
|
|
+ return getByDeptIds(deptIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TmCamera> getByDeptIds(List<String> deptIds) {
|
|
|
+ if(CollectionUtil.isEmpty(deptIds)){
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<TmCamera> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.in(TmCamera::getDeptId,deptIds);
|
|
|
+ return this.list(wrapper);
|
|
|
+ }
|
|
|
+}
|