|
|
@@ -0,0 +1,424 @@
|
|
|
+package com.inspur.face.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpResponse;
|
|
|
+import cn.hutool.http.HttpStatus;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.inspur.common.config.InspurConfig;
|
|
|
+import com.inspur.common.constant.Constants;
|
|
|
+import com.inspur.common.core.domain.AjaxResult;
|
|
|
+import com.inspur.common.utils.DateUtils;
|
|
|
+import com.inspur.common.utils.SecurityUtils;
|
|
|
+import com.inspur.common.utils.StringUtils;
|
|
|
+import com.inspur.common.utils.file.FileUploadUtils;
|
|
|
+import com.inspur.common.utils.file.FileUtils;
|
|
|
+import com.inspur.face.domain.PartyFaceRecognition;
|
|
|
+import com.inspur.face.domain.PartyMemberFace;
|
|
|
+import com.inspur.face.domain.SubjectBean;
|
|
|
+import com.inspur.face.mapper.PartyFaceRecognitionMapper;
|
|
|
+import com.inspur.face.service.CompreFaceService;
|
|
|
+import com.inspur.framework.config.ServerConfig;
|
|
|
+import com.inspur.system.domain.SysTableList;
|
|
|
+import com.inspur.system.domain.SysUserTableRel;
|
|
|
+import com.inspur.system.service.ISysUserTableRelService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+import static com.inspur.common.utils.PageUtils.startPage;
|
|
|
+
|
|
|
+/**
|
|
|
+ * compreface 算法接口 service
|
|
|
+ *
|
|
|
+ * @author lihao16
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CompreFaceServiceImpl implements CompreFaceService {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CompreFaceServiceImpl.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ServerConfig serverConfig;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PartyFaceRecognitionMapper partyFaceRecognitionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserTableRelService sysUserTableRelService;
|
|
|
+
|
|
|
+ private static final String FACE_RECOGNITION_TABLE_NAME = "party_face_recognition";
|
|
|
+
|
|
|
+ private final static String MEMBER_TABLE_NAME = "party_member_manage";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加subject URL
|
|
|
+ */
|
|
|
+ public static final String URL_ADD_SUBJECT = "http://117.73.13.40:8000/api/v1/recognition/subjects";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传人脸照片 URL
|
|
|
+ */
|
|
|
+ public static final String URL_UPLOAD_FACE = "http://117.73.13.40:8000/api/v1/recognition/faces?subject=";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 人脸识别 URL
|
|
|
+ */
|
|
|
+ // public static final String URL_FACE_RECOGNITION = "http://117.73.13.40:8000/api/v1/recognition/recognize?face_plugins=landmarks&face_plugins=gender&face_plugins=age&face_plugins=pose";
|
|
|
+ public static final String URL_FACE_RECOGNITION = "http://117.73.13.40:8000/api/v1/recognition/recognize";
|
|
|
+
|
|
|
+ private final static String API_KEY = "fccde51d-9b32-4468-97b1-cf454b473e55";
|
|
|
+
|
|
|
+ private static final String FILE_TEMP_PATH = "/home/inspur/party-admin/temp/";
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PartyFaceRecognition> selectPartyFaceRecognitionList(PartyFaceRecognition partyFaceRecognition) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ startPage();
|
|
|
+ return partyFaceRecognitionMapper.selectPartyFaceRecognitionList(partyFaceRecognition);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult addSubject(SubjectBean subject) {
|
|
|
+ // 数据库创建记录
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ PartyFaceRecognition partyFaceRecognition = new PartyFaceRecognition();
|
|
|
+ partyFaceRecognition.setReqParam(subject.getSubject());
|
|
|
+ partyFaceRecognition.setOpType(1);
|
|
|
+ partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
+ // 调用算法服务
|
|
|
+ String rspCode = "";
|
|
|
+ String rspMsg = "";
|
|
|
+ Integer opStatus = 1;
|
|
|
+ try {
|
|
|
+ // 发送请求添加subject
|
|
|
+ HttpResponse response = HttpRequest.post(URL_ADD_SUBJECT)
|
|
|
+ .body("{\"subject\":\"" + subject.getSubject() + "\"}")
|
|
|
+ .header("x-api-key", API_KEY)
|
|
|
+ .execute();
|
|
|
+ // 解析返回结果
|
|
|
+ rspCode = String.valueOf(response.getStatus());
|
|
|
+ rspMsg = response.body();
|
|
|
+ if (!String.valueOf(HttpStatus.HTTP_CREATED).equals(rspCode)) {
|
|
|
+ opStatus = 2;
|
|
|
+ log.info("addSubject error,subject:{},rspMsg:{}",subject.getSubject(),rspMsg);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ opStatus = 2;
|
|
|
+ rspMsg = e.getMessage();
|
|
|
+ log.info("addSubjectTask error,subject:{}",subject.getSubject(),e);
|
|
|
+ }finally {
|
|
|
+ partyFaceRecognition.setOpStatus(opStatus);
|
|
|
+ partyFaceRecognition.setRspCode(rspCode);
|
|
|
+ partyFaceRecognition.setRspMsg(rspMsg);
|
|
|
+ partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(partyFaceRecognition);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult uploadFace(String subject, MultipartFile file) {
|
|
|
+ // 保存数据库
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ Map<String,String> fileMap = uploadFile(file);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ reqParam.put("subject", subject);
|
|
|
+ reqParam.put("url", fileMap.get("url"));
|
|
|
+ String filePath = getFilePathByUrl(fileMap.get("url"));
|
|
|
+ reqParam.put("filePath", filePath);
|
|
|
+ PartyFaceRecognition partyFaceRecognition = new PartyFaceRecognition();
|
|
|
+ partyFaceRecognition.setReqParam(reqParam.toJSONString());
|
|
|
+ partyFaceRecognition.setOpType(2);
|
|
|
+ partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
+ // 调用算法服务
|
|
|
+ String rspCode = "";
|
|
|
+ String rspMsg = "";
|
|
|
+ Integer opStatus = 1;
|
|
|
+ try {
|
|
|
+ File imageFile = new File(filePath);
|
|
|
+ // 发送请求添加subject
|
|
|
+ HttpResponse response = HttpRequest.post(URL_UPLOAD_FACE + subject)
|
|
|
+ .form("file",imageFile)
|
|
|
+ .header("x-api-key", API_KEY)
|
|
|
+ .execute();
|
|
|
+ // 解析返回结果
|
|
|
+ rspCode = String.valueOf(response.getStatus());
|
|
|
+ rspMsg = response.body();
|
|
|
+ if (!String.valueOf(HttpStatus.HTTP_CREATED).equals(rspCode)) {
|
|
|
+ opStatus = 2;
|
|
|
+ log.info("uploadFace error,subject:{},rspMsg:{}",subject,rspMsg);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ opStatus = 2;
|
|
|
+ rspMsg = e.getMessage();
|
|
|
+ log.info("uploadFace error,reqParam:{}",partyFaceRecognition.getReqParam(),e);
|
|
|
+ }finally {
|
|
|
+ partyFaceRecognition.setOpStatus(opStatus);
|
|
|
+ partyFaceRecognition.setRspCode(rspCode);
|
|
|
+ partyFaceRecognition.setRspMsg(rspMsg);
|
|
|
+ partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(partyFaceRecognition);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult recognizeFace(MultipartFile file) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ Map<String,String> fileMap = uploadFile(file);
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ reqParam.put("url", fileMap.get("url"));
|
|
|
+ String filePath = getFilePathByUrl(fileMap.get("url"));
|
|
|
+ reqParam.put("filePath", filePath);
|
|
|
+ PartyFaceRecognition partyFaceRecognition = new PartyFaceRecognition();
|
|
|
+ partyFaceRecognition.setReqParam(reqParam.toJSONString());
|
|
|
+ partyFaceRecognition.setOpType(3);
|
|
|
+ partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
+ // 调用算法服务
|
|
|
+ String rspCode = "";
|
|
|
+ String rspMsg = "";
|
|
|
+ Integer opStatus = 1;
|
|
|
+ try {
|
|
|
+ File imageFile = new File(filePath);
|
|
|
+ // 发送请求添加subject
|
|
|
+ HttpResponse response = HttpRequest.post(URL_FACE_RECOGNITION)
|
|
|
+ .form("file",imageFile)
|
|
|
+ .header("x-api-key", API_KEY)
|
|
|
+ .execute();
|
|
|
+ // 解析返回结果
|
|
|
+ rspCode = String.valueOf(response.getStatus());
|
|
|
+ rspMsg = response.body();
|
|
|
+ if (!String.valueOf(HttpStatus.HTTP_OK).equals(rspCode)) {
|
|
|
+ opStatus = 2;
|
|
|
+ log.info("recognizeFace error,file:{},rspMsg:{}",fileMap.get("url"),rspMsg);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ opStatus = 2;
|
|
|
+ rspMsg = e.getMessage();
|
|
|
+ log.info("recognizeFace error,file:{}",fileMap.get("url"),e);
|
|
|
+ }finally {
|
|
|
+ partyFaceRecognition.setOpStatus(opStatus);
|
|
|
+ partyFaceRecognition.setRspCode(rspCode);
|
|
|
+ partyFaceRecognition.setRspMsg(rspMsg);
|
|
|
+ partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }
|
|
|
+ return AjaxResult.success(partyFaceRecognition);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult recordInfo(Long id) {
|
|
|
+ PartyFaceRecognition result = partyFaceRecognitionMapper.selectPartyFaceRecognitionById(id);
|
|
|
+ return AjaxResult.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<PartyMemberFace> selectPartyMemberFaceList(PartyMemberFace partyMemberFace) {
|
|
|
+ SysTableList tableInfo = sysUserTableRelService.selectTableInfoByName(MEMBER_TABLE_NAME,0);
|
|
|
+ Long tableId = tableInfo.getId();
|
|
|
+ SysUserTableRel tableRel = sysUserTableRelService.getRelByUserTableId(SecurityUtils.getLoginUser().getUserId(),tableId);
|
|
|
+ Long userTableId = tableRel.getUserTableId();
|
|
|
+ partyMemberFace.setUserTableId(userTableId);
|
|
|
+ startPage();
|
|
|
+ return partyFaceRecognitionMapper.selectPartyMemberFaceList(partyMemberFace);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public AjaxResult uploadFace2(PartyMemberFace partyMemberFace) {
|
|
|
+ // 查询当前党员是否已经增加subject
|
|
|
+ PartyFaceRecognition subjectParam = new PartyFaceRecognition();
|
|
|
+ subjectParam.setMemberId(partyMemberFace.getMemberId());
|
|
|
+ subjectParam.setOpStatus(1);
|
|
|
+ subjectParam.setOpType(1);
|
|
|
+ List<PartyFaceRecognition> subjectList = partyFaceRecognitionMapper.selectPartyFaceRecognitionList(subjectParam);
|
|
|
+ if (CollectionUtils.isEmpty(subjectList)) {
|
|
|
+ PartyFaceRecognition partyFaceRecognition1 = addSubject2(partyMemberFace);
|
|
|
+ if (StringUtils.isEmpty(partyFaceRecognition1.getRspCode()) || !String.valueOf(HttpStatus.HTTP_CREATED).equals(partyFaceRecognition1.getRspCode())) {
|
|
|
+ JSONObject rspMsgJson = JSON.parseObject(partyFaceRecognition1.getRspMsg());
|
|
|
+ return AjaxResult.error("上传人脸失败 : " + rspMsgJson.getString("message"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PartyFaceRecognition partyFaceRecognition2 = uploadFace2AI(partyMemberFace);
|
|
|
+ if (StringUtils.isEmpty(partyFaceRecognition2.getRspCode()) || !String.valueOf(HttpStatus.HTTP_CREATED).equals(partyFaceRecognition2.getRspCode())) {
|
|
|
+ JSONObject rspMsgJson = JSON.parseObject(partyFaceRecognition2.getRspMsg());
|
|
|
+ return AjaxResult.error("上传人脸失败 : " + rspMsgJson.getString("message"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ private PartyFaceRecognition uploadFace2AI(PartyMemberFace partyMemberFace) {
|
|
|
+ // 查询当前党员是否已经成功上传过人脸
|
|
|
+ PartyFaceRecognition subjectParam = new PartyFaceRecognition();
|
|
|
+ subjectParam.setMemberId(partyMemberFace.getMemberId());
|
|
|
+ subjectParam.setOpStatus(1);
|
|
|
+ subjectParam.setOpType(2);
|
|
|
+ List<PartyFaceRecognition> subjectList = partyFaceRecognitionMapper.selectPartyFaceRecognitionList(subjectParam);
|
|
|
+ String subject = partyMemberFace.getMemberId() + "_" + partyMemberFace.getName();
|
|
|
+ PartyFaceRecognition partyFaceRecognition = new PartyFaceRecognition();
|
|
|
+ if (CollectionUtils.isEmpty(subjectList)) {
|
|
|
+ // 保存数据库
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ JSONObject reqParam = new JSONObject();
|
|
|
+ reqParam.put("subject", subject);
|
|
|
+ reqParam.put("url", partyMemberFace.getPicPath());
|
|
|
+ partyFaceRecognition.setReqParam(reqParam.toJSONString());
|
|
|
+ partyFaceRecognition.setOpType(2);
|
|
|
+ partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognition.setMemberId(partyMemberFace.getMemberId());
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }else {
|
|
|
+ partyFaceRecognition = subjectList.get(0);
|
|
|
+ }
|
|
|
+ // 调用算法服务
|
|
|
+ String rspCode = "";
|
|
|
+ String rspMsg = "";
|
|
|
+ Integer opStatus = 1;
|
|
|
+ File imageFile = downloadFile(partyMemberFace.getPicPath());
|
|
|
+ try {
|
|
|
+ // 发送请求添加subject
|
|
|
+ HttpResponse response = HttpRequest.post(URL_UPLOAD_FACE + subject)
|
|
|
+ .form("file",imageFile)
|
|
|
+ .header("x-api-key", API_KEY)
|
|
|
+ .execute();
|
|
|
+ // 解析返回结果
|
|
|
+ rspCode = String.valueOf(response.getStatus());
|
|
|
+ rspMsg = response.body();
|
|
|
+ if (!String.valueOf(HttpStatus.HTTP_CREATED).equals(rspCode)) {
|
|
|
+ opStatus = 2;
|
|
|
+ log.info("uploadFace error,subject:{},rspMsg:{}",subject,rspMsg);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ opStatus = 2;
|
|
|
+ rspMsg = e.getMessage();
|
|
|
+ log.info("uploadFace error,reqParam:{}",partyFaceRecognition.getReqParam(),e);
|
|
|
+ }finally {
|
|
|
+ // 删除临时文件
|
|
|
+ if (imageFile.exists()) {
|
|
|
+ boolean delB = imageFile.delete();
|
|
|
+ log.info("delete txtFile file : {}",delB);
|
|
|
+ }
|
|
|
+ partyFaceRecognition.setOpStatus(opStatus);
|
|
|
+ partyFaceRecognition.setRspCode(rspCode);
|
|
|
+ partyFaceRecognition.setRspMsg(rspMsg);
|
|
|
+ partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }
|
|
|
+ return partyFaceRecognition;
|
|
|
+ }
|
|
|
+
|
|
|
+ private PartyFaceRecognition addSubject2(PartyMemberFace partyMemberFace) {
|
|
|
+ // 数据库创建记录
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ PartyFaceRecognition partyFaceRecognition = new PartyFaceRecognition();
|
|
|
+ String subject = partyMemberFace.getMemberId() + "_" + partyMemberFace.getName();
|
|
|
+ partyFaceRecognition.setReqParam(subject);
|
|
|
+ partyFaceRecognition.setOpType(1);
|
|
|
+ partyFaceRecognition.setOpStatus(0);
|
|
|
+ partyFaceRecognition.setCreateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognition.setUserTableId(getUserTableId(FACE_RECOGNITION_TABLE_NAME, userId, 0));
|
|
|
+ partyFaceRecognition.setMemberId(partyMemberFace.getMemberId());
|
|
|
+ partyFaceRecognitionMapper.insertPartyFaceRecognition(partyFaceRecognition);
|
|
|
+ // 调用算法服务
|
|
|
+ String rspCode = "";
|
|
|
+ String rspMsg = "";
|
|
|
+ Integer opStatus = 1;
|
|
|
+ try {
|
|
|
+ // 发送请求添加subject
|
|
|
+ HttpResponse response = HttpRequest.post(URL_ADD_SUBJECT)
|
|
|
+ .body("{\"subject\":\"" + subject + "\"}")
|
|
|
+ .header("x-api-key", API_KEY)
|
|
|
+ .execute();
|
|
|
+ // 解析返回结果
|
|
|
+ rspCode = String.valueOf(response.getStatus());
|
|
|
+ rspMsg = response.body();
|
|
|
+ if (!String.valueOf(HttpStatus.HTTP_CREATED).equals(rspCode)) {
|
|
|
+ opStatus = 2;
|
|
|
+ log.info("addSubject error,subject:{},rspMsg:{}",subject,rspMsg);
|
|
|
+ }
|
|
|
+ }catch (Exception e) {
|
|
|
+ opStatus = 2;
|
|
|
+ rspMsg = e.getMessage();
|
|
|
+ log.info("addSubjectTask error,subject:{}",subject,e);
|
|
|
+ }finally {
|
|
|
+ partyFaceRecognition.setOpStatus(opStatus);
|
|
|
+ partyFaceRecognition.setRspCode(rspCode);
|
|
|
+ partyFaceRecognition.setRspMsg(rspMsg);
|
|
|
+ partyFaceRecognition.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ partyFaceRecognitionMapper.updatePartyFaceRecognition(partyFaceRecognition);
|
|
|
+ }
|
|
|
+ return partyFaceRecognition;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, String> uploadFile(MultipartFile file) {
|
|
|
+ Map<String,String> resultMap = new HashMap<>();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ // 上传文件路径
|
|
|
+ String filePath = InspurConfig.getUploadPath();
|
|
|
+ // 上传并返回新文件名称
|
|
|
+ String fileName = FileUploadUtils.upload(filePath, file);
|
|
|
+ String url = serverConfig.getNewUrl() + fileName;
|
|
|
+ resultMap.put("url", url);
|
|
|
+ resultMap.put("fileName", fileName);
|
|
|
+ resultMap.put("newFileName", FileUtils.getName(fileName));
|
|
|
+ resultMap.put("originalFilename", file.getOriginalFilename());
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long getUserTableId(String tableName, Long userId,Integer dateType) {
|
|
|
+ SysTableList tableInfo = sysUserTableRelService.selectTableInfoByName(tableName,dateType);
|
|
|
+ Long tableId = tableInfo.getId();
|
|
|
+ SysUserTableRel tableRel = sysUserTableRelService.getRelByUserTableId(userId,tableId);
|
|
|
+ Long userTableId = tableRel.getUserTableId();
|
|
|
+ return userTableId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getFilePathByUrl(String url) {
|
|
|
+ // 本地资源路径
|
|
|
+ String basePath = InspurConfig.getProfile();
|
|
|
+ // 数据库资源地址
|
|
|
+ return basePath + StringUtils.substringAfter(url, Constants.RESOURCE_PREFIX);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static File downloadFile(String imageUrl) {
|
|
|
+ String filePath = FILE_TEMP_PATH + UUID.randomUUID().toString() + ".png";
|
|
|
+ // 下载文件
|
|
|
+ HttpUtil.downloadFile(imageUrl, filePath);
|
|
|
+ log.info("download file success,file path : {}:" ,filePath);
|
|
|
+ return new File(filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|