CaseServiceImpl.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. package com.fdkankan.fusion.service.impl;
  2. import cn.dev33.satoken.context.SaHolder;
  3. import cn.dev33.satoken.stp.StpUtil;
  4. import cn.hutool.core.bean.BeanUtil;
  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.fusion.common.ResultCode;
  9. import com.fdkankan.fusion.common.ResultData;
  10. import com.fdkankan.fusion.common.util.NumTypeUtils;
  11. import com.fdkankan.fusion.entity.*;
  12. import com.fdkankan.fusion.exception.BusinessException;
  13. import com.fdkankan.fusion.common.PageInfo;
  14. import com.fdkankan.fusion.mapper.ICaseMapper;
  15. import com.fdkankan.fusion.request.CaseParam;
  16. import com.fdkankan.fusion.request.ScenePram;
  17. import com.fdkankan.fusion.response.CaseVo;
  18. import com.fdkankan.fusion.response.FusionAndSceneVo;
  19. import com.fdkankan.fusion.response.HotVo;
  20. import com.fdkankan.fusion.response.SceneVo;
  21. import com.fdkankan.fusion.service.*;
  22. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import java.time.Period;
  28. import java.util.*;
  29. import java.util.stream.Collectors;
  30. /**
  31. * <p>
  32. * 服务实现类
  33. * </p>
  34. *
  35. * @author
  36. * @since 2022-07-27
  37. */
  38. @Service
  39. public class CaseServiceImpl extends ServiceImpl<ICaseMapper, CaseEntity> implements ICaseService {
  40. @Autowired
  41. ISceneService sceneService;
  42. @Autowired
  43. ICaseNumService caseNumService;
  44. @Autowired
  45. ICaseFilesService caseFilesService;
  46. @Autowired
  47. IModelService modelService;
  48. @Autowired
  49. IFusionNumService fusionNumService;
  50. @Autowired
  51. ITmProjectService tmProjectService;
  52. @Autowired
  53. ITmDepartmentService tmDepartmentService;
  54. @Autowired
  55. ITmUserService tmUserService;
  56. @Autowired
  57. ITmCameraService tmCameraService;
  58. @Autowired
  59. ICaseSettingsService caseSettingsService;
  60. @Autowired
  61. IMapConfigService mapConfigService;
  62. @Autowired
  63. IScenePlusService scenePlusService;
  64. @Autowired
  65. ICaseFusionService caseFusionService;
  66. @Autowired
  67. ISceneDeptShareService sceneDeptShareService;
  68. @Override
  69. public PageInfo pageList(CaseParam param) {
  70. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  71. if(StringUtils.isNotBlank(param.getCaseTitle())){
  72. wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
  73. }
  74. List<String> deptIds = new ArrayList<>();
  75. String share = SaHolder.getRequest().getHeader("sharePassword");
  76. if(StringUtils.isNotBlank(share) ){ //分享请求头
  77. wrapper.eq(CaseEntity::getMapShow,true);
  78. }else {
  79. String deptId = tmDepartmentService.getDeptId();
  80. if(param.getSearchType() == 0){
  81. deptIds.add(deptId);
  82. }
  83. if(param.getSearchType() == 1){ //下级共享给上级场景
  84. List<Integer> caseIds = sceneDeptShareService.getCaseIdsListByDeptId(deptId);
  85. param.setCaseIds(caseIds);
  86. }
  87. if(param.getSearchType() == 2){ //当前组织及下级组织的数据
  88. List<TmDepartment> sonByDeptId = tmDepartmentService.getSonByDeptId(deptId);
  89. deptIds.add(deptId);
  90. deptIds.addAll(sonByDeptId.stream().map(TmDepartment::getId).collect(Collectors.toList()));
  91. }
  92. if(param.getCaseIds().isEmpty() && deptIds.size() <=0){
  93. return PageInfo.PageInfo(new Page<>(param.getPageNum(),param.getPageSize()));
  94. }
  95. }
  96. if(!deptIds.isEmpty()){
  97. wrapper.in(CaseEntity::getDeptId,deptIds);
  98. }
  99. if(!param.getCaseIds().isEmpty()){
  100. wrapper.in(CaseEntity::getCaseId,param.getCaseIds());
  101. }
  102. wrapper.eq(CaseEntity::getType,0);
  103. wrapper.orderByDesc(CaseEntity::getCreateTime);
  104. Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
  105. Set<String> tmProIds = page.getRecords().stream().filter(entity -> StringUtils.isNotBlank(entity.getTmProjectId()))
  106. .map(CaseEntity::getTmProjectId).collect(Collectors.toSet());
  107. HashMap<String, TmProject> proMap = tmProjectService.getMapByIds(tmProIds);
  108. for (CaseEntity record : page.getRecords()) {
  109. if(StringUtils.isNotBlank(record.getTmProjectId())){
  110. TmProject project = proMap.get(record.getTmProjectId());
  111. if(project != null){
  112. record.setDeptId(project.getDeptId());
  113. }
  114. }
  115. }
  116. List<Integer> mapIds = page.getRecords().stream().map(CaseEntity::getMapId).collect(Collectors.toList());
  117. if(!mapIds.isEmpty()){
  118. HashMap<Integer,MapConfig> map = mapConfigService.getMapByIds(mapIds);
  119. for (CaseEntity caseEntity : page.getRecords()) {
  120. if(caseEntity.getMapId() != null && map.get(caseEntity.getMapId()) != null){
  121. MapConfig mapConfig = map.get(caseEntity.getMapId());
  122. caseEntity.setMapConfig(mapConfig);
  123. }
  124. }
  125. }
  126. Set<String> deptIds1 = page.getRecords().stream().filter(entity -> StringUtils.isNotBlank(entity.getDeptId()))
  127. .map(CaseEntity::getDeptId).collect(Collectors.toSet());
  128. HashMap<String, TmDepartment> mapByDeptIds = tmDepartmentService.getMapByDeptIds(deptIds1);
  129. for (CaseEntity record : page.getRecords()) {
  130. TmDepartment department = mapByDeptIds.get(record.getDeptId());
  131. if(department != null){
  132. record.setDeptName(department.getName());
  133. }
  134. List<CaseSettings> caseSettings = caseSettingsService.getByCaseId(record.getCaseId());
  135. if(!caseSettings.isEmpty()){
  136. CaseSettings caseSettings1 = caseSettings.get(0);
  137. if(caseSettings1 != null){
  138. record.setCover(caseSettings1.getCover());
  139. }
  140. }
  141. }
  142. return PageInfo.PageInfo(page);
  143. }
  144. @Override
  145. public List<SceneVo> sceneList(CaseParam param) {
  146. if(param.getCaseId() == null){
  147. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  148. }
  149. List<SceneVo> listAll = new ArrayList<>();
  150. List<CaseNumEntity> numListByCase = caseNumService.getByCaseId(param.getCaseId());
  151. List<String> meshNumList = numListByCase.stream().filter(e ->! NumTypeUtils.isLaser(e.getNumType())).map(CaseNumEntity::getNum).collect(Collectors.toList());
  152. List<String> laserNumList = numListByCase.stream().filter(e -> NumTypeUtils.isLaser(e.getNumType())).map(CaseNumEntity::getNum).collect(Collectors.toList());
  153. if(!meshNumList.isEmpty()){
  154. List<SceneVo> meshSceneList = scenePlusService.getMeshList(meshNumList);
  155. HashMap<String, Model> meshModelMap = modelService.getMapByNum(meshNumList,1);
  156. for (SceneVo sceneVo : meshSceneList) {
  157. Model model = meshModelMap.get(sceneVo.getNum());
  158. if(model != null){
  159. BeanUtils.copyProperties(model,sceneVo);
  160. }
  161. }
  162. listAll.addAll(meshSceneList);
  163. }
  164. if(!laserNumList.isEmpty()){
  165. List<SceneVo> laserSceneList = scenePlusService.getLaserList(laserNumList);
  166. HashMap<String, Model> laserModelMap = modelService.getMapByNum(laserNumList,0);
  167. for (SceneVo sceneVo : laserSceneList) {
  168. Model model = laserModelMap.get(sceneVo.getNum());
  169. if(model != null){
  170. BeanUtils.copyProperties(model,sceneVo);
  171. }
  172. }
  173. listAll.addAll(laserSceneList);
  174. }
  175. return listAll;
  176. }
  177. @Override
  178. public void addOrUpdate(CaseParam param, String userName) {
  179. if(StringUtils.isEmpty(param.getCaseTitle())){
  180. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  181. }
  182. CaseEntity caseEntity ;
  183. if(param.getCaseId() == null){
  184. caseEntity = new CaseEntity();
  185. TmUser tmUser = tmUserService.getByUserName(userName);
  186. caseEntity.setDeptId(tmUser.getDeptId());
  187. caseEntity.setUserName(userName);
  188. }else {
  189. caseEntity = this.getById(param.getCaseId());
  190. }
  191. caseEntity.setCaseTitle(param.getCaseTitle());
  192. caseEntity.setMapShow(param.getMapShow());
  193. caseEntity.setLatAndLong(param.getLatAndLong());
  194. caseEntity.setMapUrl(param.getMapUrl());
  195. caseEntity.setUpdateTime(null);
  196. this.saveOrUpdate(caseEntity);
  197. if(param.getSceneNumParam() != null && !param.getSceneNumParam().isEmpty()){
  198. caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
  199. }
  200. }
  201. @Override
  202. public void addScene(CaseParam param) {
  203. if(param.getCaseId() == null){
  204. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  205. }
  206. CaseEntity caseEntity = this.getById(param.getCaseId());
  207. if(caseEntity == null){
  208. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  209. }
  210. caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
  211. }
  212. @Override
  213. public void delete(Integer caseId) {
  214. if(caseId == null){
  215. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  216. }
  217. //删除关联的场景
  218. caseNumService.deleteByCaseId(caseId);
  219. caseFilesService.deleteByCaseId(caseId);
  220. this.removeById(caseId);
  221. }
  222. @Override
  223. public List<CaseEntity> getByIds(List<Integer> caseIdIds) {
  224. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  225. wrapper.in(CaseEntity::getCaseId,caseIdIds);
  226. return this.list(wrapper);
  227. }
  228. @Override
  229. public CaseEntity getByTmProjectId(String projectId) {
  230. LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
  231. wrapper.eq(CaseEntity::getTmProjectId,projectId);
  232. return this.getOne(wrapper);
  233. }
  234. @Override
  235. public void updateIdenTityStatus(Integer caseId, Integer status) {
  236. CaseEntity caseEntity = this.getById(caseId);
  237. if(caseEntity != null && StringUtils.isNotBlank(caseEntity.getTmProjectId())){
  238. tmProjectService.updateIdenTityStatus(caseEntity.getTmProjectId(),status);
  239. }
  240. }
  241. @Override
  242. public String getDeptId(Integer caseId) {
  243. CaseEntity caseEntity = this.getById(caseId);
  244. String deptId = caseEntity.getDeptId();
  245. if(caseEntity.getType() ==1){
  246. deptId = tmProjectService.getById(caseEntity.getTmProjectId()).getDeptId();
  247. }
  248. return deptId;
  249. }
  250. @Override
  251. public CaseVo getInfo(Integer caseId,Boolean isLogin) {
  252. CaseEntity caseEntity = this.getById(caseId);
  253. if(caseEntity == null){
  254. return null;
  255. }
  256. CaseVo caseVo = new CaseVo();
  257. BeanUtil.copyProperties(caseEntity,caseVo);
  258. if(caseEntity.getTmProjectId() != null){
  259. TmProject tmProject = tmProjectService.getById(caseEntity.getTmProjectId());
  260. if(tmProject!= null && tmProject.getIsDelete()!=0){
  261. throw new BusinessException(ResultCode.CASE_NOT_EXITS);
  262. }
  263. caseVo.setTmProject(tmProject);
  264. caseVo.setCaseTitle(tmProject.getProjectName());
  265. }
  266. if(isLogin){
  267. checkCaseAuth(caseVo);
  268. }
  269. return caseVo;
  270. }
  271. private void checkCaseAuth(CaseVo caseVo) {
  272. String share = SaHolder.getRequest().getHeader("sharePassword");
  273. if(StringUtils.isNotBlank(share) ) { //分享请求头
  274. return;
  275. }
  276. if(!StpUtil.isLogin()){
  277. throw new BusinessException(ResultCode.USER_NOT_LOGIN);
  278. }
  279. String page = SaHolder.getRequest().getHeader("page");
  280. if(StringUtils.isBlank(page) ) {
  281. throw new BusinessException(ResultCode.USER_NOT_LOGIN);
  282. }
  283. String deptId =(String) StpUtil.getExtra("deptId");
  284. //获取共享数据
  285. List<SceneDeptShare> sceneDeptShares = sceneDeptShareService.getByCaseIdAndDeptId(caseVo.getCaseId(),deptId);
  286. //0不共享,1查看,2编辑
  287. if(!sceneDeptShares.isEmpty()){
  288. for (SceneDeptShare sceneDeptShare : sceneDeptShares) {
  289. if(sceneDeptShare.getIsAuth() == 2){
  290. return;
  291. }
  292. if(sceneDeptShare.getIsAuth() == 1 && "view".equals(page)){
  293. return;
  294. }
  295. }
  296. }
  297. List<String> deptIds = tmDepartmentService.getDeptIds();
  298. if(deptIds.size() <=0){
  299. throw new BusinessException(ResultCode.NOT_PERMISSION);
  300. }
  301. String caseDeptId = caseVo.getDeptId();
  302. if(caseVo.getTmProject() != null){
  303. caseDeptId = caseVo.getTmProject().getDeptId();
  304. }
  305. List<String> deptIds2 = tmDepartmentService.getSonByDeptIdAndDeptIds(deptIds, deptId);
  306. if(!deptIds2.contains(caseDeptId)){
  307. throw new BusinessException(ResultCode.NOT_PERMISSION);
  308. }
  309. }
  310. @Override
  311. public void addFusionIds(CaseParam param) {
  312. if(param.getCaseId() == null || param.getFusionIds() == null ){
  313. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  314. }
  315. if(param.getFusionIds().isEmpty()){
  316. List<CaseNumEntity> byCaseId = caseNumService.getByCaseId(param.getCaseId());
  317. if(byCaseId.isEmpty()){
  318. throw new BusinessException(ResultCode.REMOVE_ERROR);
  319. }
  320. }
  321. caseFusionService.addFusionIds(param.getFusionIds(),param.getCaseId());
  322. }
  323. @Override
  324. public List<FusionAndSceneVo> getFusionAndScene(Integer caseId, String type) {
  325. if(caseId == null || StringUtils.isBlank(type)){
  326. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  327. }
  328. List<FusionAndSceneVo> voList = new ArrayList<>();
  329. if("fusion".equals(type)){
  330. List<CaseFusion> byCaseId = caseFusionService.getListByCaseId(caseId);
  331. for (CaseFusion caseFusion : byCaseId) {
  332. FusionAndSceneVo vo = new FusionAndSceneVo();
  333. vo.setTitle(caseFusion.getFusionTitle());
  334. vo.setFusionId(caseFusion.getFusionId());
  335. vo.setType("fusion");
  336. voList.add(vo);
  337. }
  338. return voList;
  339. }
  340. if("scene".equals(type)){
  341. List<CaseNumEntity> caseNums = caseNumService.getByCaseId(caseId);
  342. List<String> numList = caseNums.stream().map(CaseNumEntity::getNum).collect(Collectors.toList());
  343. List<ScenePlus> scenePlusList = scenePlusService.getByNumList(numList);
  344. HashMap<String, ScenePlus> map = new HashMap<>();
  345. scenePlusList.forEach(e-> map.put(e.getNum(),e));
  346. for (CaseNumEntity caseNum : caseNums) {
  347. ScenePlus scenePlus = map.get(caseNum.getNum());
  348. if(scenePlus == null){
  349. continue;
  350. }
  351. FusionAndSceneVo vo = new FusionAndSceneVo();
  352. vo.setSceneNumId(caseNum.getId());
  353. vo.setTitle(scenePlus.getTitle());
  354. vo.setNum(scenePlus.getNum());
  355. vo.setSceneType(caseNum.getNumType());
  356. vo.setType("scene");
  357. voList.add(vo);
  358. }
  359. return voList;
  360. }
  361. return voList;
  362. }
  363. @Override
  364. public void setMapShow(Integer caseId, Integer mapShow) {
  365. LambdaUpdateWrapper<CaseEntity> wrapper = new LambdaUpdateWrapper<>();
  366. wrapper.eq(CaseEntity::getCaseId,caseId);
  367. wrapper.set(CaseEntity::getMapShow,mapShow);
  368. this.update(wrapper);
  369. }
  370. }