SceneProServiceImpl.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package com.fdkankan.agent.service.impl;
  2. import cn.hutool.core.io.FileUtil;
  3. import cn.hutool.json.JSONUtil;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  6. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fdkankan.agent.common.OssPath;
  9. import com.fdkankan.agent.common.PageInfo;
  10. import com.fdkankan.agent.common.ResultCode;
  11. import com.fdkankan.agent.common.ResultData;
  12. import com.fdkankan.agent.entity.*;
  13. import com.fdkankan.agent.exception.BusinessException;
  14. import com.fdkankan.agent.httpClient.client.FdKKClient;
  15. import com.fdkankan.agent.httpClient.service.LaserService;
  16. import com.fdkankan.agent.mapper.ISceneProMapper;
  17. import com.fdkankan.agent.request.SceneParam;
  18. import com.fdkankan.agent.response.GroupByCount;
  19. import com.fdkankan.agent.response.SceneVo;
  20. import com.fdkankan.agent.service.*;
  21. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  22. import com.fdkankan.agent.util.MangerUploadToOssUtil;
  23. import com.fdkankan.agent.util.SceneStatusUtil;
  24. import com.fdkankan.common.constant.SceneConstant;
  25. import com.fdkankan.common.util.FileUtils;
  26. import lombok.extern.slf4j.Slf4j;
  27. import org.apache.commons.lang3.StringUtils;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.stereotype.Service;
  30. import javax.annotation.Resource;
  31. import java.util.ArrayList;
  32. import java.util.HashMap;
  33. import java.util.List;
  34. import java.util.stream.Collectors;
  35. /**
  36. * <p>
  37. * pro场景表 服务实现类
  38. * </p>
  39. *
  40. * @author
  41. * @since 2022-11-09
  42. */
  43. @Service
  44. @Slf4j
  45. public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro> implements ISceneProService {
  46. @Autowired
  47. LaserService laserService;
  48. @Autowired
  49. IScenePlusService scenePlusService;
  50. @Autowired
  51. IScenePlusExtService scenePlusExtService;
  52. @Resource
  53. FdKKClient fdKKClient;
  54. @Autowired
  55. ICameraService cameraService;
  56. @Autowired
  57. ICameraDetailService cameraDetailService;
  58. @Autowired
  59. IUserIncrementService userIncrementService;
  60. @Autowired
  61. IIncrementTypeService incrementTypeService;
  62. @Autowired
  63. MangerUploadToOssUtil mangerUploadToOssUtil;
  64. @Autowired
  65. IFolderSceneService folderSceneService;
  66. @Autowired
  67. ISceneService sceneService;
  68. @Autowired
  69. ISceneCopyLogService sceneCopyLogService;
  70. @Autowired
  71. IUserService userService;
  72. @Autowired
  73. IAgentNewService agentNewService;
  74. @Autowired
  75. IAgentNewCameraService agentNewCameraService;
  76. @Override
  77. public Object pageList(SceneParam param) {
  78. if(param.getAgentId() == null){
  79. throw new BusinessException(ResultCode.PARAM_MISS);
  80. }
  81. if(param.getType() == 3){ //双目lite
  82. return sceneService.pageList(param);
  83. }
  84. if(StringUtils.isNotBlank(param.getUserName())){
  85. List<User> userList = userService.getLikeByUserName(param.getUserName());
  86. List<Long> userIds = userList.stream().map(User::getId).collect(Collectors.toList());
  87. if(userIds.isEmpty()){
  88. return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
  89. }
  90. param.setUserIds(userIds);
  91. }
  92. List<CameraDetail> details = cameraDetailService.getListByAgentId(param.getAgentId());
  93. List<Long> cameraIds = details.stream().map(CameraDetail::getCameraId).collect(Collectors.toList());
  94. List<Long> authCameraIds = agentNewCameraService.getBySubAgent(param.getAgentId());
  95. if(!authCameraIds.isEmpty()) {
  96. cameraIds.addAll(authCameraIds);
  97. }
  98. if(cameraIds.isEmpty()){
  99. return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
  100. }
  101. param.setCameraIds(cameraIds);
  102. Page<SceneVo> page = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  103. List<SceneVo> records = page.getRecords();
  104. HashMap<String,SceneCopyLog> map = null;
  105. HashMap<Long, User> userMap = null;
  106. HashMap<Long, Camera> cameraMap = null;
  107. HashMap<String,JSONObject> ssSceneMap = null;
  108. List<String> sceneNumList = page.getRecords().stream().map(SceneVo::getNum).collect(Collectors.toList());
  109. if(!records.isEmpty()){
  110. map = sceneCopyLogService.getByNewNumList(sceneNumList);
  111. List<Long> userIds = records.parallelStream().map(SceneVo::getUserId).collect(Collectors.toList());
  112. userMap = userService.getByIds(userIds);
  113. List<Long> cameraIds2 = records.parallelStream().map(SceneVo::getCameraId).collect(Collectors.toList());
  114. cameraMap = cameraService.getByIds(cameraIds2);
  115. if(param.getType() == 2 ){
  116. ssSceneMap = laserService.list(sceneNumList,4);
  117. }
  118. if(param.getType() == 6){
  119. ssSceneMap = laserService.list(sceneNumList,5);
  120. }
  121. }
  122. for (SceneVo record : page.getRecords()) {
  123. if(param.getType() == 2 || param.getType() == 6){
  124. JSONObject ssObj = ssSceneMap.get(record.getNum());
  125. if(ssObj!=null){
  126. record.setSceneName(ssObj.getString("title"));
  127. record.setThumb(ssObj.getString("thumb"));
  128. record.setWebSite(ssObj.getString("webSite"));
  129. record.setIsObj(ssObj.getInteger("buildObjStatus"));
  130. record.setViewCount(ssObj.getInteger("viewCount"));
  131. record.setStatus(toFdStatus(ssObj.getInteger("status")));
  132. record.setAlgorithmTime(ssObj.getString("algorithmTime"));
  133. }else{
  134. record.setStatus(0);
  135. record.setWebSite(null);
  136. }
  137. }
  138. record.setStatusString(SceneStatusUtil.getStatusString(record));
  139. if(userMap != null){
  140. User user = userMap.get(record.getUserId());
  141. if(user != null){
  142. record.setUserName(user.getUserName());
  143. }
  144. }
  145. if(cameraMap != null){
  146. Camera camera = cameraMap.get(record.getCameraId());
  147. if(camera != null){
  148. record.setSnCode(camera.getSnCode());
  149. }
  150. }
  151. if(map !=null ){
  152. SceneCopyLog sceneCopyLog = map.get(record.getNum());
  153. if(sceneCopyLog != null){
  154. record.setCopyTime(sceneCopyLog.getCreateTime());
  155. record.setIsCopy(true);
  156. }
  157. }
  158. }
  159. return PageInfo.PageInfo(page);
  160. }
  161. @Override
  162. public void copy(String sceneNum) throws Exception {
  163. ScenePro scenePro = this.getByNum(sceneNum);
  164. ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
  165. if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
  166. throw new BusinessException(ResultCode.SCENE_EMPTY);
  167. }
  168. Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
  169. Camera camera = cameraService.getById(cameraId);
  170. if(camera == null){
  171. throw new BusinessException(ResultCode.CAMERA_EMPTY);
  172. }
  173. CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
  174. if(detailEntity == null){
  175. throw new BusinessException(ResultCode.CAMERA_EMPTY);
  176. }
  177. Long needSpace = 0L;
  178. if(scenePro != null){
  179. needSpace = scenePro.getSpace();
  180. }
  181. if(scenePlus != null){
  182. ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
  183. if(scenePlusExt != null && scenePlusExt.getSpace() != null){
  184. needSpace = scenePlusExt.getSpace();
  185. }
  186. }
  187. Boolean checkSpace = cameraDetailService.checkSpace(detailEntity, needSpace);
  188. if(!checkSpace){
  189. throw new BusinessException(ResultCode.CAMERA_SPACE_ERROR);
  190. }
  191. HashMap<String, Object> param = new HashMap<>();
  192. param.put("num",sceneNum);
  193. JSONObject jsonObject = fdKKClient.copyScene(param, "m_a_n_a_g_e");
  194. Integer code = jsonObject.getInteger("code");
  195. if(code != 0){
  196. throw new BusinessException(jsonObject.getInteger("code"),jsonObject.getString("msg"));
  197. }
  198. }
  199. @Override
  200. public ScenePro getByNum(String num) {
  201. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  202. wrapper.eq(ScenePro::getNum,num);
  203. wrapper.eq(ScenePro::getIsUpgrade,0);
  204. List<ScenePro> list = this.list(wrapper);
  205. if(list == null || list.size() <=0){
  206. return null;
  207. }
  208. return list.get(0);
  209. }
  210. @Override
  211. public Long getCountByCameraId(Long cameraId) {
  212. LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
  213. wrapper.eq(ScenePro::getIsUpgrade,0);
  214. wrapper.eq(ScenePro::getCameraId,cameraId);
  215. wrapper.in(ScenePro::getStatus,0,-2);
  216. return this.count(wrapper);
  217. }
  218. private Integer toFdStatus(Integer status) {
  219. //深时状态,-1:场景被删 0:计算中 1计算失败 2计算成功 3封存 4生成OBJ中
  220. switch (status) {
  221. case 0:
  222. case 4:
  223. return 0;
  224. case 2:
  225. return -2;
  226. case 3:
  227. return -3;
  228. default:
  229. return -1;
  230. }
  231. }
  232. @Override
  233. public HashMap<Long, Long> getCountGroupByUserId(List<Long> userIdList) {
  234. HashMap<Long,Long> map = new HashMap<>();
  235. List<GroupByCount> result = this.getBaseMapper().getCountGroupByUserId(userIdList);
  236. result.forEach(entity ->map.put(entity.getId(),entity.getCount()));
  237. return map;
  238. }
  239. }