123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- package com.fdkankan.fusion.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.jwt.JWT;
- import cn.hutool.jwt.JWTUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.fdkankan.fusion.common.ResultCode;
- import com.fdkankan.fusion.common.ResultData;
- import com.fdkankan.fusion.common.util.NumTypeUtils;
- import com.fdkankan.fusion.entity.*;
- import com.fdkankan.fusion.exception.BusinessException;
- import com.fdkankan.fusion.common.PageInfo;
- import com.fdkankan.fusion.httpClient.client.FdKKClient;
- import com.fdkankan.fusion.mapper.ICaseMapper;
- import com.fdkankan.fusion.request.CaseParam;
- import com.fdkankan.fusion.request.ScenePram;
- import com.fdkankan.fusion.response.CaseVo;
- import com.fdkankan.fusion.response.HotVo;
- import com.fdkankan.fusion.response.SceneVo;
- import com.fdkankan.fusion.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.lang.model.element.TypeElement;
- import java.time.Period;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2022-07-27
- */
- @Service
- @Slf4j
- public class CaseServiceImpl extends ServiceImpl<ICaseMapper, CaseEntity> implements ICaseService {
- @Autowired
- ISceneService sceneService;
- @Autowired
- ICaseNumService caseNumService;
- @Autowired
- ICaseFilesService caseFilesService;
- @Autowired
- IModelService modelService;
- @Autowired
- IFusionNumService fusionNumService;
- @Autowired
- ITmProjectService tmProjectService;
- @Autowired
- ITmDepartmentService tmDepartmentService;
- @Autowired
- ITmUserService tmUserService;
- @Autowired
- ITmCameraService tmCameraService;
- @Autowired
- IMapConfigService mapConfigService;
- @Autowired
- ICaseFusionService caseFusionService;
- @Autowired
- FdKKClient fdKKClient;
- @Override
- public PageInfo pageList(CaseParam param) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- if(StringUtils.isNotBlank(param.getCaseTitle())){
- wrapper.like(CaseEntity::getCaseTitle,param.getCaseTitle());
- }
- //wrapper.eq(CaseEntity::getUserName,userName);
- wrapper.eq(CaseEntity::getType,0);
- wrapper.orderByDesc(CaseEntity::getCreateTime);
- Page<CaseEntity> page = this.page( new Page<>(param.getPageNum(), param.getPageSize()), wrapper);
- List<Integer> mapIds = page.getRecords().stream().map(CaseEntity::getMapId).collect(Collectors.toList());
- if(!mapIds.isEmpty()){
- HashMap<Integer,MapConfig> map = mapConfigService.getMapByIds(mapIds);
- for (CaseEntity caseEntity : page.getRecords()) {
- if(caseEntity.getMapId() != null && map.get(caseEntity.getMapId()) != null){
- MapConfig mapConfig = map.get(caseEntity.getMapId());
- caseEntity.setMapConfig(mapConfig);
- }
- }
- }
- return PageInfo.PageInfo(page);
- }
- @Override
- public List<SceneVo> sceneList(CaseParam param) {
- if(param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getTypeMap() == null){
- HashMap<Integer, List<String>> typeMap = caseNumService.getTypeMap(param.getCaseId());
- param.setTypeMap(typeMap);
- }
- List<SceneVo> listAll = new ArrayList<>();
- for (Integer type : param.getTypeMap().keySet()) {
- List<String> numList = param.getTypeMap().get(type);
- if(numList ==null || numList.size() <=0 || type ==3){
- continue;
- }
- if(param.getTypeList() != null && !param.getTypeList().contains(type)){
- continue;
- }
- ScenePram scenePram = new ScenePram();
- scenePram.setType(type);
- scenePram.setPageNum(1);
- scenePram.setPageSize(99999);
- scenePram.setNumList(param.getTypeMap().get(type));
- scenePram.setShare("1");
- if(param.getTypeList() != null){
- scenePram.setStatus(2);
- }
- scenePram.setSceneName(param.getSceneName());
- PageInfo pageInfo = sceneService.pageList(scenePram);
- List<SceneVo> list1 = (List<SceneVo>) pageInfo.getList();
- listAll.addAll(list1);
- }
- return listAll;
- }
- @Override
- public void addOrUpdate(CaseEntity param) {
- this.saveOrUpdate(param);
- }
- @Override
- public void addScene(CaseParam param) {
- if(param.getCaseId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- CaseEntity caseEntity = this.getById(param.getCaseId());
- if(caseEntity == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- caseNumService.addBatch(param.getCaseId(),param.getSceneNumParam());
- }
- @Override
- public void delete(Integer caseId) {
- if(caseId == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- //删除关联的场景
- caseNumService.deleteByCaseId(caseId);
- caseFilesService.deleteByCaseId(caseId);
- this.removeById(caseId);
- }
- @Override
- public List<CaseEntity> getByIds(List<Integer> caseIdIds) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- wrapper.in(CaseEntity::getCaseId,caseIdIds);
- return this.list(wrapper);
- }
- @Override
- public CaseEntity getByTmProjectId(String projectId) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CaseEntity::getTmProjectId,projectId);
- return this.getOne(wrapper);
- }
- @Override
- public void updateIdenTityStatus(Integer caseId, Integer status) {
- CaseEntity caseEntity = this.getById(caseId);
- if(caseEntity != null && StringUtils.isNotBlank(caseEntity.getTmProjectId())){
- tmProjectService.updateIdenTityStatus(caseEntity.getTmProjectId(),status);
- }
- }
- @Override
- public String getDeptId(Integer caseId) {
- CaseEntity caseEntity = this.getById(caseId);
- String deptId = caseEntity.getDeptId();
- if(caseEntity.getType() ==1){
- deptId = tmProjectService.getById(caseEntity.getTmProjectId()).getDeptId();
- }
- return deptId;
- }
- @Override
- public CaseVo getInfo(Integer caseId) {
- CaseEntity caseEntity = this.getById(caseId);
- if(caseEntity == null){
- throw new BusinessException(ResultCode.CASE_NOT_EXITS);
- }
- CaseVo caseVo = new CaseVo();
- BeanUtil.copyProperties(caseEntity,caseVo);
- if(caseEntity.getTmProjectId() != null){
- TmProject tmProject = tmProjectService.getById(caseEntity.getTmProjectId());
- if(tmProject!= null && tmProject.getIsDelete()!=0){
- throw new BusinessException(ResultCode.CASE_NOT_EXITS);
- }
- caseVo.setTmProject(tmProject);
- caseVo.setCaseTitle(tmProject.getProjectName());
- }
- if(!StpUtil.isLogin()){
- return caseVo;
- }
- if(Long.valueOf(StpUtil.getLoginId().toString()).equals(caseVo.getSysUserId())){
- caseVo.setViewAuth(true);
- caseVo.setIsAuthor(true);
- caseVo.setEditAuth(true);
- return caseVo;
- }
- Integer platform_id = (Integer) StpUtil.getExtra("platformId");
- String roleType = (String) StpUtil.getExtra("roleType");
- if("super-admin".equals(roleType)){
- caseVo.setViewAuth(true);
- caseVo.setEditAuth(true);
- caseVo.setIsAuthor(true);
- return caseVo;
- }
- if(roleType.contains("admin") && caseVo.getPlatformId().equals(platform_id)){
- caseVo.setViewAuth(true);
- caseVo.setEditAuth(true);
- caseVo.setIsAuthor(true);
- return caseVo;
- }
- try {
- JSONObject jsonObject = fdKKClient.checkCaseAuth(caseId.toString(),"case",StpUtil.getTokenValue());
- Integer code = jsonObject.getInteger("code");
- String message = jsonObject.getString("message");
- if(code != 0){
- throw new BusinessException(code,message);
- }
- JSONObject data = jsonObject.getJSONObject("data");
- caseVo.setViewAuth( data.getBoolean("viewAuth"));
- caseVo.setEditAuth( data.getBoolean("editAuth"));
- // redisUtil.set(format,data.toJSONString(),60);
- }catch (Exception e){
- log.info("checkCaseAuth-error:",e);
- }
- return caseVo;
- }
- @Override
- public void addFusionIds(CaseParam param) {
- if(param.getCaseId() == null || param.getFusionIds() == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getFusionIds().isEmpty()){
- List<CaseNumEntity> byCaseId = caseNumService.getByCaseId(param.getCaseId());
- if(byCaseId.isEmpty()){
- throw new BusinessException(ResultCode.REMOVE_ERROR);
- }
- }
- caseFusionService.addFusionIds(param.getFusionIds(),param.getCaseId());
- }
- @Override
- public CaseEntity getKnumber(String kNumber) {
- LambdaQueryWrapper<CaseEntity> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(CaseEntity::getKNumber,kNumber);
- List<CaseEntity> list = this.list(wrapper);
- if(list != null && !list.isEmpty()){
- return list.get(0);
- }
- return null;
- }
- }
|