| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- package com.fdkankan.manage.service.impl;
- import cn.dev33.satoken.stp.StpUtil;
- import cn.hutool.core.bean.BeanUtil;
- import cn.hutool.core.io.FileUtil;
- 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.fyun.face.FYunFileServiceInterface;
- import com.fdkankan.manage.common.CommandEnum;
- import com.fdkankan.manage.common.OssPath;
- import com.fdkankan.manage.common.PageInfo;
- import com.fdkankan.manage.common.ResultCode;
- import com.fdkankan.manage.config.ManageConfig;
- import com.fdkankan.manage.constant.FileTypeEnum;
- import com.fdkankan.manage.entity.*;
- import com.fdkankan.manage.exception.BusinessException;
- import com.fdkankan.manage.httpClient.client.HaixinClient;
- import com.fdkankan.manage.httpClient.client.OtherClient;
- import com.fdkankan.manage.httpClient.param.HaixinParam;
- import com.fdkankan.manage.mapper.IDictFileMapper;
- import com.fdkankan.manage.service.*;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.fdkankan.manage.util.MD5Checksum;
- import com.fdkankan.manage.util.ShellUtil;
- import com.fdkankan.manage.vo.EvidenceVo;
- import com.fdkankan.manage.vo.request.DictFileParam;
- import com.fdkankan.manage.vo.request.SubmitPhotoHaixinVo;
- import com.fdkankan.manage.vo.request.addMediaLibraryParam;
- import com.fdkankan.manage.vo.response.DictFileVo;
- import lombok.extern.slf4j.Slf4j;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.io.IOException;
- import java.util.*;
- import java.util.stream.Collectors;
- /**
- * <p>
- * 服务实现类
- * </p>
- *
- * @author
- * @since 2024-12-02
- */
- @Service
- @Slf4j
- public class DictFileServiceImpl extends ServiceImpl<IDictFileMapper, DictFile> implements IDictFileService {
- @Autowired
- ICommonUploadService commonUploadService;
- @Autowired
- IDictService dictService;
- @Autowired
- IScenePlusService scenePlusService;
- @Autowired
- ICaseService caseService;
- @Autowired
- IDictIconService dictIconService;
- @Autowired
- IDictFileCaseService dictFileCaseService;
- @Override
- public Object pageList(DictFileParam param) {
- if(StringUtils.isBlank(param.getTypeKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(StpUtil.isLogin()){
- param.setSysUserId( Long.valueOf( StpUtil.getLoginId().toString()));
- }
- Page<DictFileVo> pageVo = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<Integer> dictIds = pageVo.getRecords().stream().map(DictFile::getDictId).collect(Collectors.toList());
- HashMap<Integer,List<DictIcon>> map = dictIconService.getMapGroupDict(dictIds);
- List<Integer> ids = pageVo.getRecords().stream().map(DictFile::getId).collect(Collectors.toList());
- HashMap<Integer, List<Case>> byDictIds = dictFileCaseService.getByDictIds(ids);
- for (DictFileVo dictFileVo : pageVo.getRecords()) {
- dictFileVo.setDictIconList(map.get(dictFileVo.getDictId()));
- dictFileVo.setCaseList(byDictIds.get(dictFileVo.getId()));
- }
- return PageInfo.PageInfo(pageVo);
- }
- @Override
- public Object traceEvidenceInfoList(DictFileParam param) {
- if(StringUtils.isBlank(param.getTypeKey())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(!StpUtil.isLogin()){
- throw new BusinessException(ResultCode.USER_NOT_LOGIN);
- }
- param.setSysUserId( Long.valueOf( StpUtil.getLoginId().toString()));
- if(StringUtils.isNotBlank(param.getNum())){
- List<Case> caseList = caseService.getCaseByNum(param.getNum());
- List<Integer> caseIds = caseList.stream().map(Case::getCaseId).collect(Collectors.toList());
- List<DictFileCase> dictFileCases = dictFileCaseService.getByCaseIds(caseIds);
- Set<Integer> ids = dictFileCases.stream().map(DictFileCase::getDictFileId).collect(Collectors.toSet());
- if(!ids.isEmpty()){
- param.setDictFileIds(ids);
- }
- }
- if(StringUtils.isNotBlank(param.getKno())){
- List<DictFileCase> dictFileCases = dictFileCaseService.getByCaseId(param.getKno());
- Set<Integer> ids = dictFileCases.stream().map(DictFileCase::getDictFileId).collect(Collectors.toSet());
- if(ids.isEmpty()){
- return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
- }
- param.setDictFileIds(ids);
- }
- Page<DictFileVo> pageVo = this.getBaseMapper().traceEvidenceInfoList(new Page<>(param.getPageNum(),param.getPageSize()),param);
- List<Integer> dictIds = pageVo.getRecords().stream().map(DictFile::getDictId).collect(Collectors.toList());
- HashMap<Integer,List<DictIcon>> map = dictIconService.getMapGroupDict(dictIds);
- List<Integer> ids = pageVo.getRecords().stream().map(DictFile::getId).collect(Collectors.toList());
- HashMap<Integer, List<Case>> byDictIds = dictFileCaseService.getByDictIds(ids);
- for (DictFileVo dictFileVo : pageVo.getRecords()) {
- dictFileVo.setDictIconList(map.get(dictFileVo.getDictId()));
- dictFileVo.setCaseList(byDictIds.get(dictFileVo.getId()));
- }
- return PageInfo.PageInfo(pageVo);
- }
- @Override
- public void addOrUpdate(DictFile dictFile) {
- if(StringUtils.isBlank(dictFile.getTypeKey())
- || dictFile.getDictId() == null ){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- this.saveOrUpdate(dictFile);
- }
- @Override
- public void del(DictFile dictFile) {
- if(dictFile.getId() == null){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- DictFile byId = this.getById(dictFile.getId());
- if(byId != null && StringUtils.isNotBlank(byId.getUseType()) && !"ordinary".equals(byId.getUseType())){
- throw new BusinessException(ResultCode.DEL_ERROR);
- }
- this.removeById(dictFile.getId());
- }
- @Override
- public void updateDictId(Integer dictId, Integer UpDictId) {
- LambdaUpdateWrapper<DictFile> wrapper = new LambdaUpdateWrapper<>();
- wrapper.eq(DictFile::getDictId,dictId);
- wrapper.set(DictFile::getDictId,UpDictId);
- this.update(wrapper);
- }
- @Override
- public DictFile getByEvidenceNo(String evidenceNo) {
- LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(DictFile::getEvidenceNo,evidenceNo);
- List<DictFile> list = this.list(wrapper);
- if(list.isEmpty()){
- return null;
- }
- return list.get(0);
- }
- @Autowired
- private FYunFileServiceInterface fYunFileServiceInterface;
- @Autowired
- ManageConfig manageConfig;
- @Autowired
- HaixinClient haixinClient;
- @Autowired
- OtherClient otherClient;
- @Override
- public void checkMediaLibrary(addMediaLibraryParam param) {
- if(StringUtils.isBlank(param.getFilePath())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- String extName = param.getFilePath().substring(param.getFilePath().lastIndexOf(".")).toLowerCase();
- FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
- if(fileTypeEnum == null){
- throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
- }
- }
- @Override
- public DictFile addMediaLibrary(addMediaLibraryParam param) {
- if(StringUtils.isBlank(param.getFilePath())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- if(param.getToHaixin() == 1 && StringUtils.isBlank(param.getNum())){
- throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
- }
- CommonUpload commonUpload = null;
- if(StringUtils.isNotBlank(param.getFileMd5())){
- //param.setFileMd5( MD5Checksum.getMD5( "/oss/4dkankan/" + param.getFilePath()));
- commonUpload = commonUploadService.getByFileMd5(param.getFileMd5());
- }
- if(commonUpload == null){
- String uuid = UUID.randomUUID().toString().replace("-","");
- String extName = param.getFilePath().substring(param.getFilePath().lastIndexOf(".")).toLowerCase();
- String formart = extName.replace(".", "");
- FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(formart);
- if(fileTypeEnum == null){
- throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
- }
- String ossPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, uuid+ extName);
- fYunFileServiceInterface.copyFileInBucket(param.getFilePath(),ossPath);
- commonUpload = new CommonUpload();
- commonUpload.setFileName(param.getFileName());
- commonUpload.setFileUrl(manageConfig.getQueryPath() + ossPath);
- commonUpload.setFileSize(param.getFileSize());
- commonUpload.setFileType(fileTypeEnum.getCode());
- commonUpload.setFileTypeStr(fileTypeEnum.getMsg());
- commonUpload.setFileFormat(formart);
- commonUpload.setResultFileFormat(formart);
- commonUpload.setStatus(1);
- commonUpload.setUseType("ordinary");
- commonUpload.setFileMd5(param.getFileMd5());
- commonUploadService.saveOrUpdate(commonUpload);
- }
- DictFile dictFile = null;
- if(StpUtil.isLogin()){
- dictFile = this.getByUploadIdAndSysId(commonUpload.getId(),Long.valueOf(StpUtil.getLoginId().toString()));
- }
- if(dictFile == null){
- dictFile = new DictFile();
- dictFile.setName(param.getFileName());
- dictFile.setTypeKey("media-library");
- if(StpUtil.isLogin()){
- dictFile.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
- }
- dictFile.setDictId(param.getDictId());
- dictFile.setUseType("ordinary");
- dictFile.setUploadId(commonUpload.getId());
- dictFile.setKno(param.getKno());
- dictFile.setSid(param.getSid());
- dictFile.setContent(JSONObject.toJSONString(param.getContent()));
- this.saveOrUpdate(dictFile);
- dictFileCaseService.add(dictFile.getId(),param.getNum());
- }
- try {
- if(param.getDelSource() == 1){
- fYunFileServiceInterface.deleteFile(param.getFilePath());
- }
- } catch (IOException e) {
- log.info("删除原文件失败");
- }
- if(param.getToHaixin() ==1){
- String pushUrl = manageConfig.getHaixinApiBasePath();
- ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
- if(scenePlus == null){
- return dictFile;
- }
- if(StringUtils.isNotBlank(scenePlus.getPushAddress())){
- pushUrl = scenePlus.getPushAddress();
- }
- Case caseEntity = caseService.getByKno(scenePlus.getKNo());
- if(caseEntity == null){
- return dictFile;
- }
- if(StringUtils.isBlank(pushUrl)){
- return dictFile;
- }
- SubmitPhotoHaixinVo vo = new SubmitPhotoHaixinVo();
- vo.setKno(scenePlus.getKNo());
- vo.setCaseId(caseEntity.getCaseId().toString());
- vo.setProjectId(scenePlus.getTaskId());
- vo.setPhotoId(dictFile.getId().toString());
- vo.setFileUrl( commonUpload.getFileUrl());
- if(StringUtils.isBlank(param.getFileMd5())){
- param.setFileMd5( MD5Checksum.getMD5( "/oss/4dkankan/" + param.getFilePath()));
- }
- vo.setMd5(param.getFileMd5());
- vo.setCategory(param.getCategory());
- vo.setServerUrl(manageConfig.getServerUrl());
- // String jsonObject = haixinClient.submitPhoto(vo);
- String jsonObject = otherClient.postJson(pushUrl +"/ecs/api/panoramicImageService/submitPhoto", BeanUtil.beanToMap(vo));
- log.info("submitPhoto-tohaixin-result:{}",jsonObject);
- }
- return dictFile;
- }
- private DictFile getByUploadIdAndSysId(Integer uploadId, Long sysId) {
- LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(DictFile::getUploadId,uploadId);
- wrapper.eq(DictFile::getSysUserId,sysId);
- List<DictFile> list = this.list(wrapper);
- if(list== null || list.isEmpty()){
- return null;
- }
- return list.get(0);
- }
- @Override
- public void updateByKno(String kno) {
- try {
- JSONObject jsonObject = haixinClient.queryEvidence(new HaixinParam(kno));
- JSONObject data = jsonObject.getJSONObject("data");
- JSONArray jsonArray = data.getJSONArray("sceneMaterialEvidence");
- for (Object object : jsonArray) {
- JSONObject obj = (JSONObject) object;
- String evidenceNo = obj.getString("materialEvidenceNo"); //痕迹物证唯一编码
- String category = obj.getString("category");
- String fileServerPath = obj.getString("fileServerPath");
- String materialEvidenceName = obj.getString("materialEvidenceName");
- String leftPosition = obj.getString("leftPosition");
- String feature = obj.getString("feature");
- String collectionModeName = obj.getString("collectionModeName");
- if(StringUtils.isBlank(collectionModeName)){
- collectionModeName =obj.getString("collectionMode");
- }
- String collectedTime = obj.getString("collectedTime");
- String createAccount = obj.getString("createAccount");
- JSONArray jsonArray1 = obj.getJSONArray("sceneCollectedPerson");
- StringBuilder collectedPerson = new StringBuilder();
- for (Object o : jsonArray1) {
- JSONObject jsonObject1 = (JSONObject) o;
- collectedPerson.append(jsonObject1.getString("collectedPerson")).append(",");
- }
- if(collectedPerson.toString().contains(",")){
- collectedPerson.delete(collectedPerson.lastIndexOf(","),collectedPerson.length() -1);
- }
- EvidenceVo vo = new EvidenceVo(materialEvidenceName,leftPosition,feature,collectionModeName,collectedTime,collectedPerson.toString(),0,null);
- DictFile dictFile = this.getByEvidenceNo(evidenceNo);
- if(dictFile == null){
- dictFile = new DictFile();
- }
- CommonUpload commonUpload = commonUploadService.getById(dictFile.getUploadId());
- if(commonUpload == null){
- commonUpload = new CommonUpload();
- }
- commonUpload.setFileName(materialEvidenceName);
- String formart = FileUtil.extName(fileServerPath);
- commonUpload.setFileUrl(manageConfig.getHaixinApiBasePath() + "/"+ fileServerPath);
- commonUpload.setFileSize("0");
- commonUpload.setFileType(0);
- commonUpload.setFileTypeStr("图片");
- commonUpload.setFileFormat(formart);
- commonUpload.setResultFileFormat(formart);
- commonUpload.setStatus(1);
- commonUpload.setUseType("trace_evidence");
- commonUpload.setUpdateTime(new Date());
- commonUploadService.saveOrUpdate(commonUpload);
- Dict dict = dictService.getByResourceId(category);
- dictFile.setName(materialEvidenceName);
- dictFile.setTypeKey("media-library");
- dictFile.setDictId(dict != null?dict.getId() : null);
- if(StpUtil.isLogin()){
- dictFile.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
- }
- dictFile.setUseType("trace_evidence");
- dictFile.setUploadId(commonUpload.getId());
- dictFile.setKno(kno);
- dictFile.setContent(JSONObject.toJSONString(vo));
- dictFile.setEvidenceNo(evidenceNo);
- dictFile.setUpdateTime(new Date());
- this.saveOrUpdate(dictFile);
- Case byKno = caseService.getByKno(kno);
- if(byKno !=null){
- dictFileCaseService.add(dictFile.getId(),byKno.getCaseId());
- }
- }
- }catch (Exception e){
- }
- }
- }
|