DictFileServiceImpl.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. package com.fdkankan.manage.service.impl;
  2. import cn.dev33.satoken.stp.StpUtil;
  3. import cn.hutool.core.bean.BeanUtil;
  4. import cn.hutool.core.io.FileUtil;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alibaba.fastjson.JSONObject;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.fdkankan.fyun.face.FYunFileServiceInterface;
  11. import com.fdkankan.manage.common.CommandEnum;
  12. import com.fdkankan.manage.common.OssPath;
  13. import com.fdkankan.manage.common.PageInfo;
  14. import com.fdkankan.manage.common.ResultCode;
  15. import com.fdkankan.manage.config.ManageConfig;
  16. import com.fdkankan.manage.constant.FileTypeEnum;
  17. import com.fdkankan.manage.entity.*;
  18. import com.fdkankan.manage.exception.BusinessException;
  19. import com.fdkankan.manage.httpClient.client.HaixinClient;
  20. import com.fdkankan.manage.httpClient.client.OtherClient;
  21. import com.fdkankan.manage.httpClient.param.HaixinParam;
  22. import com.fdkankan.manage.mapper.IDictFileMapper;
  23. import com.fdkankan.manage.service.*;
  24. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  25. import com.fdkankan.manage.util.MD5Checksum;
  26. import com.fdkankan.manage.util.ShellUtil;
  27. import com.fdkankan.manage.vo.EvidenceVo;
  28. import com.fdkankan.manage.vo.request.DictFileParam;
  29. import com.fdkankan.manage.vo.request.SubmitPhotoHaixinVo;
  30. import com.fdkankan.manage.vo.request.addMediaLibraryParam;
  31. import com.fdkankan.manage.vo.response.DictFileVo;
  32. import lombok.extern.slf4j.Slf4j;
  33. import org.apache.commons.lang3.StringUtils;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.stereotype.Service;
  36. import java.io.File;
  37. import java.io.IOException;
  38. import java.util.*;
  39. import java.util.stream.Collectors;
  40. /**
  41. * <p>
  42. * 服务实现类
  43. * </p>
  44. *
  45. * @author
  46. * @since 2024-12-02
  47. */
  48. @Service
  49. @Slf4j
  50. public class DictFileServiceImpl extends ServiceImpl<IDictFileMapper, DictFile> implements IDictFileService {
  51. @Autowired
  52. ICommonUploadService commonUploadService;
  53. @Autowired
  54. IDictService dictService;
  55. @Autowired
  56. IScenePlusService scenePlusService;
  57. @Autowired
  58. ICaseService caseService;
  59. @Autowired
  60. IDictIconService dictIconService;
  61. @Autowired
  62. IDictFileCaseService dictFileCaseService;
  63. @Override
  64. public Object pageList(DictFileParam param) {
  65. if(StringUtils.isBlank(param.getTypeKey())){
  66. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  67. }
  68. if(StpUtil.isLogin()){
  69. param.setSysUserId( Long.valueOf( StpUtil.getLoginId().toString()));
  70. }
  71. Page<DictFileVo> pageVo = this.getBaseMapper().pageList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  72. List<Integer> dictIds = pageVo.getRecords().stream().map(DictFile::getDictId).collect(Collectors.toList());
  73. HashMap<Integer,List<DictIcon>> map = dictIconService.getMapGroupDict(dictIds);
  74. List<Integer> ids = pageVo.getRecords().stream().map(DictFile::getId).collect(Collectors.toList());
  75. HashMap<Integer, List<Case>> byDictIds = dictFileCaseService.getByDictIds(ids);
  76. for (DictFileVo dictFileVo : pageVo.getRecords()) {
  77. dictFileVo.setDictIconList(map.get(dictFileVo.getDictId()));
  78. dictFileVo.setCaseList(byDictIds.get(dictFileVo.getId()));
  79. }
  80. return PageInfo.PageInfo(pageVo);
  81. }
  82. @Override
  83. public Object traceEvidenceInfoList(DictFileParam param) {
  84. if(StringUtils.isBlank(param.getTypeKey())){
  85. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  86. }
  87. if(!StpUtil.isLogin()){
  88. throw new BusinessException(ResultCode.USER_NOT_LOGIN);
  89. }
  90. param.setSysUserId( Long.valueOf( StpUtil.getLoginId().toString()));
  91. if(StringUtils.isNotBlank(param.getNum())){
  92. List<Case> caseList = caseService.getCaseByNum(param.getNum());
  93. List<Integer> caseIds = caseList.stream().map(Case::getCaseId).collect(Collectors.toList());
  94. List<DictFileCase> dictFileCases = dictFileCaseService.getByCaseIds(caseIds);
  95. Set<Integer> ids = dictFileCases.stream().map(DictFileCase::getDictFileId).collect(Collectors.toSet());
  96. if(!ids.isEmpty()){
  97. param.setDictFileIds(ids);
  98. }
  99. }
  100. if(StringUtils.isNotBlank(param.getKno())){
  101. List<DictFileCase> dictFileCases = dictFileCaseService.getByCaseId(param.getKno());
  102. Set<Integer> ids = dictFileCases.stream().map(DictFileCase::getDictFileId).collect(Collectors.toSet());
  103. if(ids.isEmpty()){
  104. return PageInfo.PageInfoEmpty(param.getPageNum(),param.getPageSize());
  105. }
  106. param.setDictFileIds(ids);
  107. }
  108. Page<DictFileVo> pageVo = this.getBaseMapper().traceEvidenceInfoList(new Page<>(param.getPageNum(),param.getPageSize()),param);
  109. List<Integer> dictIds = pageVo.getRecords().stream().map(DictFile::getDictId).collect(Collectors.toList());
  110. HashMap<Integer,List<DictIcon>> map = dictIconService.getMapGroupDict(dictIds);
  111. List<Integer> ids = pageVo.getRecords().stream().map(DictFile::getId).collect(Collectors.toList());
  112. HashMap<Integer, List<Case>> byDictIds = dictFileCaseService.getByDictIds(ids);
  113. for (DictFileVo dictFileVo : pageVo.getRecords()) {
  114. dictFileVo.setDictIconList(map.get(dictFileVo.getDictId()));
  115. dictFileVo.setCaseList(byDictIds.get(dictFileVo.getId()));
  116. }
  117. return PageInfo.PageInfo(pageVo);
  118. }
  119. @Override
  120. public void addOrUpdate(DictFile dictFile) {
  121. if(StringUtils.isBlank(dictFile.getTypeKey())
  122. || dictFile.getDictId() == null ){
  123. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  124. }
  125. this.saveOrUpdate(dictFile);
  126. }
  127. @Override
  128. public void del(DictFile dictFile) {
  129. if(dictFile.getId() == null){
  130. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  131. }
  132. DictFile byId = this.getById(dictFile.getId());
  133. if(byId != null && StringUtils.isNotBlank(byId.getUseType()) && !"ordinary".equals(byId.getUseType())){
  134. throw new BusinessException(ResultCode.DEL_ERROR);
  135. }
  136. this.removeById(dictFile.getId());
  137. }
  138. @Override
  139. public void updateDictId(Integer dictId, Integer UpDictId) {
  140. LambdaUpdateWrapper<DictFile> wrapper = new LambdaUpdateWrapper<>();
  141. wrapper.eq(DictFile::getDictId,dictId);
  142. wrapper.set(DictFile::getDictId,UpDictId);
  143. this.update(wrapper);
  144. }
  145. @Override
  146. public DictFile getByEvidenceNo(String evidenceNo) {
  147. LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
  148. wrapper.eq(DictFile::getEvidenceNo,evidenceNo);
  149. List<DictFile> list = this.list(wrapper);
  150. if(list.isEmpty()){
  151. return null;
  152. }
  153. return list.get(0);
  154. }
  155. @Autowired
  156. private FYunFileServiceInterface fYunFileServiceInterface;
  157. @Autowired
  158. ManageConfig manageConfig;
  159. @Autowired
  160. HaixinClient haixinClient;
  161. @Autowired
  162. OtherClient otherClient;
  163. @Override
  164. public void checkMediaLibrary(addMediaLibraryParam param) {
  165. if(StringUtils.isBlank(param.getFilePath())){
  166. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  167. }
  168. String extName = param.getFilePath().substring(param.getFilePath().lastIndexOf(".")).toLowerCase();
  169. FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(extName.replace(".", ""));
  170. if(fileTypeEnum == null){
  171. throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
  172. }
  173. }
  174. @Override
  175. public DictFile addMediaLibrary(addMediaLibraryParam param) {
  176. if(StringUtils.isBlank(param.getFilePath())){
  177. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  178. }
  179. if(param.getToHaixin() == 1 && StringUtils.isBlank(param.getNum())){
  180. throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
  181. }
  182. CommonUpload commonUpload = null;
  183. if(StringUtils.isNotBlank(param.getFileMd5())){
  184. //param.setFileMd5( MD5Checksum.getMD5( "/oss/4dkankan/" + param.getFilePath()));
  185. commonUpload = commonUploadService.getByFileMd5(param.getFileMd5());
  186. }
  187. if(commonUpload == null){
  188. String uuid = UUID.randomUUID().toString().replace("-","");
  189. String extName = param.getFilePath().substring(param.getFilePath().lastIndexOf(".")).toLowerCase();
  190. String formart = extName.replace(".", "");
  191. FileTypeEnum fileTypeEnum = FileTypeEnum.getByType(formart);
  192. if(fileTypeEnum == null){
  193. throw new BusinessException(ResultCode.FILE_TYPE_ERROR2);
  194. }
  195. String ossPath = String.format(OssPath.MANAGE_MODEL_FILE_PATH, uuid+ extName);
  196. fYunFileServiceInterface.copyFileInBucket(param.getFilePath(),ossPath);
  197. commonUpload = new CommonUpload();
  198. commonUpload.setFileName(param.getFileName());
  199. commonUpload.setFileUrl(manageConfig.getQueryPath() + ossPath);
  200. commonUpload.setFileSize(param.getFileSize());
  201. commonUpload.setFileType(fileTypeEnum.getCode());
  202. commonUpload.setFileTypeStr(fileTypeEnum.getMsg());
  203. commonUpload.setFileFormat(formart);
  204. commonUpload.setResultFileFormat(formart);
  205. commonUpload.setStatus(1);
  206. commonUpload.setUseType("ordinary");
  207. commonUpload.setFileMd5(param.getFileMd5());
  208. commonUploadService.saveOrUpdate(commonUpload);
  209. }
  210. DictFile dictFile = null;
  211. if(StpUtil.isLogin()){
  212. dictFile = this.getByUploadIdAndSysId(commonUpload.getId(),Long.valueOf(StpUtil.getLoginId().toString()));
  213. }
  214. if(dictFile == null){
  215. dictFile = new DictFile();
  216. dictFile.setName(param.getFileName());
  217. dictFile.setTypeKey("media-library");
  218. if(StpUtil.isLogin()){
  219. dictFile.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
  220. }
  221. dictFile.setDictId(param.getDictId());
  222. dictFile.setUseType("ordinary");
  223. dictFile.setUploadId(commonUpload.getId());
  224. dictFile.setKno(param.getKno());
  225. dictFile.setSid(param.getSid());
  226. dictFile.setContent(JSONObject.toJSONString(param.getContent()));
  227. this.saveOrUpdate(dictFile);
  228. dictFileCaseService.add(dictFile.getId(),param.getNum());
  229. }
  230. try {
  231. if(param.getDelSource() == 1){
  232. fYunFileServiceInterface.deleteFile(param.getFilePath());
  233. }
  234. } catch (IOException e) {
  235. log.info("删除原文件失败");
  236. }
  237. if(param.getToHaixin() ==1){
  238. String pushUrl = manageConfig.getHaixinApiBasePath();
  239. ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
  240. if(scenePlus == null){
  241. return dictFile;
  242. }
  243. if(StringUtils.isNotBlank(scenePlus.getPushAddress())){
  244. pushUrl = scenePlus.getPushAddress();
  245. }
  246. Case caseEntity = caseService.getByKno(scenePlus.getKNo());
  247. if(caseEntity == null){
  248. return dictFile;
  249. }
  250. if(StringUtils.isBlank(pushUrl)){
  251. return dictFile;
  252. }
  253. SubmitPhotoHaixinVo vo = new SubmitPhotoHaixinVo();
  254. vo.setKno(scenePlus.getKNo());
  255. vo.setCaseId(caseEntity.getCaseId().toString());
  256. vo.setProjectId(scenePlus.getTaskId());
  257. vo.setPhotoId(dictFile.getId().toString());
  258. vo.setFileUrl( commonUpload.getFileUrl());
  259. if(StringUtils.isBlank(param.getFileMd5())){
  260. param.setFileMd5( MD5Checksum.getMD5( "/oss/4dkankan/" + param.getFilePath()));
  261. }
  262. vo.setMd5(param.getFileMd5());
  263. vo.setCategory(param.getCategory());
  264. vo.setServerUrl(manageConfig.getServerUrl());
  265. // String jsonObject = haixinClient.submitPhoto(vo);
  266. String jsonObject = otherClient.postJson(pushUrl +"/ecs/api/panoramicImageService/submitPhoto", BeanUtil.beanToMap(vo));
  267. log.info("submitPhoto-tohaixin-result:{}",jsonObject);
  268. }
  269. return dictFile;
  270. }
  271. private DictFile getByUploadIdAndSysId(Integer uploadId, Long sysId) {
  272. LambdaQueryWrapper<DictFile> wrapper = new LambdaQueryWrapper<>();
  273. wrapper.eq(DictFile::getUploadId,uploadId);
  274. wrapper.eq(DictFile::getSysUserId,sysId);
  275. List<DictFile> list = this.list(wrapper);
  276. if(list== null || list.isEmpty()){
  277. return null;
  278. }
  279. return list.get(0);
  280. }
  281. @Override
  282. public void updateByKno(String kno) {
  283. try {
  284. JSONObject jsonObject = haixinClient.queryEvidence(new HaixinParam(kno));
  285. JSONObject data = jsonObject.getJSONObject("data");
  286. JSONArray jsonArray = data.getJSONArray("sceneMaterialEvidence");
  287. for (Object object : jsonArray) {
  288. JSONObject obj = (JSONObject) object;
  289. String evidenceNo = obj.getString("materialEvidenceNo"); //痕迹物证唯一编码
  290. String category = obj.getString("category");
  291. String fileServerPath = obj.getString("fileServerPath");
  292. String materialEvidenceName = obj.getString("materialEvidenceName");
  293. String leftPosition = obj.getString("leftPosition");
  294. String feature = obj.getString("feature");
  295. String collectionModeName = obj.getString("collectionModeName");
  296. if(StringUtils.isBlank(collectionModeName)){
  297. collectionModeName =obj.getString("collectionMode");
  298. }
  299. String collectedTime = obj.getString("collectedTime");
  300. String createAccount = obj.getString("createAccount");
  301. JSONArray jsonArray1 = obj.getJSONArray("sceneCollectedPerson");
  302. StringBuilder collectedPerson = new StringBuilder();
  303. for (Object o : jsonArray1) {
  304. JSONObject jsonObject1 = (JSONObject) o;
  305. collectedPerson.append(jsonObject1.getString("collectedPerson")).append(",");
  306. }
  307. if(collectedPerson.toString().contains(",")){
  308. collectedPerson.delete(collectedPerson.lastIndexOf(","),collectedPerson.length() -1);
  309. }
  310. EvidenceVo vo = new EvidenceVo(materialEvidenceName,leftPosition,feature,collectionModeName,collectedTime,collectedPerson.toString(),0,null);
  311. DictFile dictFile = this.getByEvidenceNo(evidenceNo);
  312. if(dictFile == null){
  313. dictFile = new DictFile();
  314. }
  315. CommonUpload commonUpload = commonUploadService.getById(dictFile.getUploadId());
  316. if(commonUpload == null){
  317. commonUpload = new CommonUpload();
  318. }
  319. commonUpload.setFileName(materialEvidenceName);
  320. String formart = FileUtil.extName(fileServerPath);
  321. commonUpload.setFileUrl(manageConfig.getHaixinApiBasePath() + "/"+ fileServerPath);
  322. commonUpload.setFileSize("0");
  323. commonUpload.setFileType(0);
  324. commonUpload.setFileTypeStr("图片");
  325. commonUpload.setFileFormat(formart);
  326. commonUpload.setResultFileFormat(formart);
  327. commonUpload.setStatus(1);
  328. commonUpload.setUseType("trace_evidence");
  329. commonUpload.setUpdateTime(new Date());
  330. commonUploadService.saveOrUpdate(commonUpload);
  331. Dict dict = dictService.getByResourceId(category);
  332. dictFile.setName(materialEvidenceName);
  333. dictFile.setTypeKey("media-library");
  334. dictFile.setDictId(dict != null?dict.getId() : null);
  335. if(StpUtil.isLogin()){
  336. dictFile.setSysUserId(Long.valueOf(StpUtil.getLoginId().toString()));
  337. }
  338. dictFile.setUseType("trace_evidence");
  339. dictFile.setUploadId(commonUpload.getId());
  340. dictFile.setKno(kno);
  341. dictFile.setContent(JSONObject.toJSONString(vo));
  342. dictFile.setEvidenceNo(evidenceNo);
  343. dictFile.setUpdateTime(new Date());
  344. this.saveOrUpdate(dictFile);
  345. Case byKno = caseService.getByKno(kno);
  346. if(byKno !=null){
  347. dictFileCaseService.add(dictFile.getId(),byKno.getCaseId());
  348. }
  349. }
  350. }catch (Exception e){
  351. }
  352. }
  353. }