123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- package com.fdkankan.agent.service.impl;
- import cn.hutool.core.io.FileUtil;
- import cn.hutool.json.JSONUtil;
- 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.agent.common.OssPath;
- import com.fdkankan.agent.common.PageInfo;
- import com.fdkankan.agent.common.ResultCode;
- import com.fdkankan.agent.common.ResultData;
- import com.fdkankan.agent.entity.*;
- import com.fdkankan.agent.exception.BusinessException;
- import com.fdkankan.agent.httpClient.client.FdKKClient;
- import com.fdkankan.agent.httpClient.service.LaserService;
- import com.fdkankan.agent.mapper.ISceneProMapper;
- import com.fdkankan.agent.request.SceneParam;
- import com.fdkankan.agent.response.GroupByCount;
- import com.fdkankan.agent.response.SceneVo;
- import com.fdkankan.agent.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.agent.util.MangerUploadToOssUtil;
- import com.fdkankan.agent.util.SceneStatusUtil;
- import com.fdkankan.common.constant.SceneConstant;
- import com.fdkankan.common.util.FileUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.stream.Collectors;
- /**
- * <p>
- * pro场景表 服务实现类
- * </p>
- *
- * @author
- * @since 2022-11-09
- */
- @Service
- @Slf4j
- public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
- @Autowired
- LaserService laserService;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- IScenePlusExtService scenePlusExtService;
- @Resource
- FdKKClient fdKKClient;
- @Autowired
- ICameraService cameraService;
- @Autowired
- ICameraDetailService cameraDetailService;
- @Autowired
- IUserIncrementService userIncrementService;
- @Autowired
- IIncrementTypeService incrementTypeService;
- @Autowired
- MangerUploadToOssUtil mangerUploadToOssUtil;
- @Autowired
- IFolderSceneService folderSceneService;
- @Autowired
- ISceneService sceneService;
- @Autowired
- ISceneCopyLogService sceneCopyLogService;
- @Autowired
- IUserService userService;
- @Autowired
- IAgentNewService agentNewService;
- @Autowired
- IAgentNewCameraService agentNewCameraService;
- @Override
- public Object pageList(SceneParam param) {
- if(param.getAgentId() == null){
- throw new BusinessException(ResultCode.PARAM_MISS);
- }
- if(param.getType() == 3){ //双目lite
- return sceneService.pageList(param);
- }
- if(StringUtils.isNotBlank(param.getUserName())){
- List<User> userList = userService.getLikeByUserName(param.getUserName());
- List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
- if(userIds.isEmpty()){
- return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
- }
- param.setUserIds(userIds);
- }
- List<CameraDetail> details = cameraDetailService.getListByAgentId(param.getAgentId());
- List<Long> cameraIds = details.stream().map(CameraDetail::getCameraId).collect(Collectors.toList());
- List<Long> authCameraIds = agentNewCameraService.getBySubAgent(param.getAgentId());
- if(!authCameraIds.isEmpty()) {
- cameraIds.addAll(authCameraIds);
- }
- if(cameraIds.isEmpty()){
- return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
- }
- param.setCameraIds(cameraIds);
- Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<SceneVo> records = page.getRecords();
- HashMap<String,SceneCopyLog> map = null;
- HashMap<Long, User> userMap = null;
- HashMap<Long, Camera> cameraMap = null;
- HashMap<String,JSONObject> ssSceneMap = null;
- List<String> sceneNumList = page.getRecords().stream().map(SceneVo::getNum).collect(Collectors.toList());
- if(!records.isEmpty()){
- map = sceneCopyLogService.getByNewNumList(sceneNumList);
- List<Long> userIds = records.parallelStream().map(SceneVo::getUserId).collect(Collectors.toList());
- userMap = userService.getByIds(userIds);
- List<Long> cameraIds2 = records.parallelStream().map(SceneVo::getCameraId).collect(Collectors.toList());
- cameraMap = cameraService.getByIds(cameraIds2);
- if(param.getType() == 2 ){
- ssSceneMap = laserService.list(sceneNumList,4);
- }
- if(param.getType() == 6){
- ssSceneMap = laserService.list(sceneNumList,5);
- }
- }
- for (SceneVo record : page.getRecords()) {
- if(param.getType() == 2 || param.getType() == 6){
- JSONObject ssObj = ssSceneMap.get(record.getNum());
- if(ssObj!=null){
- record.setSceneName(ssObj.getString("title"));
- record.setThumb(ssObj.getString("thumb"));
- record.setWebSite(ssObj.getString("webSite"));
- record.setIsObj(ssObj.getInteger("buildObjStatus"));
- record.setViewCount(ssObj.getInteger("viewCount"));
- record.setStatus(toFdStatus(ssObj.getInteger("status")));
- record.setAlgorithmTime(ssObj.getString("algorithmTime"));
- }else{
- record.setStatus(0);
- record.setWebSite(null);
- }
- }
- record.setStatusString(SceneStatusUtil.getStatusString(record));
- if(userMap != null){
- User user = userMap.get(record.getUserId());
- if(user != null){
- record.setUserName(user.getUserName());
- }
- }
- if(cameraMap != null){
- Camera camera = cameraMap.get(record.getCameraId());
- if(camera != null){
- record.setSnCode(camera.getSnCode());
- }
- }
- if(map !=null ){
- SceneCopyLog sceneCopyLog = map.get(record.getNum());
- if(sceneCopyLog != null){
- record.setCopyTime(sceneCopyLog.getCreateTime());
- record.setIsCopy(true);
- }
- }
- }
- return PageInfo.PageInfo(page);
- }
- @Override
- public void copy(String sceneNum) throws Exception {
- ScenePro scenePro = this.getByNum(sceneNum);
- ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
- if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
- throw new BusinessException(ResultCode.SCENE_EMPTY);
- }
- Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
- Camera camera = cameraService.getById(cameraId);
- if(camera == null){
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
- }
- CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
- if(detailEntity == null){
- throw new BusinessException(ResultCode.CAMERA_EMPTY);
- }
- Long needSpace = 0L;
- if(scenePro != null){
- needSpace = scenePro.getSpace();
- }
- if(scenePlus != null){
- ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
- if(scenePlusExt != null && scenePlusExt.getSpace() != null){
- needSpace = scenePlusExt.getSpace();
- }
- }
- Boolean checkSpace = cameraDetailService.checkSpace(detailEntity, needSpace);
- if(!checkSpace){
- throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
- }
- HashMap<String, Object> param = new HashMap<>();
- param.put("num",sceneNum);
- JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
- Integer code = jsonObject.getInteger("code");
- if(code != 0){
- throw new BusinessException(jsonObject.getInteger("code"),jsonObject.getString("msg"));
- }
- }
- @Override
- public ScenePro getByNum(String num) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getNum,num);
- wrapper.eq(ScenePro::getIsUpgrade,0);
- List<ScenePro> list = this.list(wrapper);
- if(list == null || list.size() <=0){
- return null;
- }
- return list.get(0);
- }
- @Override
- public Long getCountByCameraId(Long cameraId) {
- LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ScenePro::getIsUpgrade,0);
- wrapper.eq(ScenePro::getCameraId,cameraId);
- wrapper.in(ScenePro::getStatus,0,-2);
- return this.count(wrapper);
- }
- private Integer toFdStatus(Integer status) {
- //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
- switch (status) {
- case 0:
- case 4:
- return 0;
- case 2:
- return -2;
- case 3:
- return -3;
- default:
- return -1;
- }
- }
- @Override
- public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
- HashMap<Long,Long> map = new HashMap<>();
- List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
- result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
- return map;
- }
- }
|