|
@@ -1,11 +1,29 @@
|
|
package com.management.platform.service.impl;
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.management.platform.constant.Constant;
|
|
|
|
+import com.management.platform.entity.PicContentKeywords;
|
|
import com.management.platform.entity.Screenshot;
|
|
import com.management.platform.entity.Screenshot;
|
|
|
|
+import com.management.platform.entity.vo.ScreenshotVO;
|
|
import com.management.platform.mapper.ScreenshotMapper;
|
|
import com.management.platform.mapper.ScreenshotMapper;
|
|
import com.management.platform.service.ScreenshotService;
|
|
import com.management.platform.service.ScreenshotService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.management.platform.util.*;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.annotation.Resources;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
* 服务实现类
|
|
* 服务实现类
|
|
@@ -17,4 +35,50 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screenshot> implements ScreenshotService {
|
|
public class ScreenshotServiceImpl extends ServiceImpl<ScreenshotMapper, Screenshot> implements ScreenshotService {
|
|
|
|
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
|
+ private String path;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private ScreenshotMapper screenshotMapper;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg saveAndProcessImage(ScreenshotVO screenshotvo) {
|
|
|
|
+ String filePath = UploadFileToFileNameUtil.uploadFile(screenshotvo.getFile(), path);
|
|
|
|
+ Screenshot screenshot = new Screenshot();
|
|
|
|
+ BeanUtils.copyProperties(screenshotvo,screenshot);
|
|
|
|
+ screenshot.setPicUrl(filePath);
|
|
|
|
+ screenshot.setDateStr(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(screenshotvo.getIndate()));
|
|
|
|
+ String accessToken = "";
|
|
|
|
+ if (redisUtil.existsKey("accessToken")) {
|
|
|
|
+ accessToken = redisUtil.getKey("accessToken");
|
|
|
|
+ } else {
|
|
|
|
+ Map<String, Object> map = AuthService.getAuth(Constant.API_KEY, Constant.SECRET_KEY);
|
|
|
|
+ accessToken = (String) map.get("access_token");
|
|
|
|
+ redisUtil.setKeyWithExpireTime("accessToken", accessToken, (Long) map.get("expires_in"));
|
|
|
|
+ }
|
|
|
|
+ //利用token去检测
|
|
|
|
+// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
+// LocalDateTime l = LocalDateTime.parse("2019-02-03",dateTimeFormatter);
|
|
|
|
+ Map<String, Object> picResultMap = CheckPicUtil.generalPicTextContentMap(path + filePath.substring("/upload/".length()), accessToken);
|
|
|
|
+ List<String> textContents = (List<String>)picResultMap.get("wordsList");
|
|
|
|
+ screenshot.setPicContext((String)picResultMap.get("picContent"));
|
|
|
|
+ Set<Object> members = redisUtil.members(Constant.COMMON_SOFTWARE_KEYWORDS);
|
|
|
|
+ for (String textContent : textContents) {
|
|
|
|
+ for (Object member : members) {
|
|
|
|
+ //由于redis里存储的member是一个PicContentKeywords类型的json字符串,所以取出关键字内容比较
|
|
|
|
+ JSONObject jsonMember = JSON.parseObject((String)member);
|
|
|
|
+ if (textContent.contains(jsonMember.getString("content"))) {
|
|
|
|
+ //包含关键字们可以简单认为是在用常用开发软件
|
|
|
|
+ screenshot.setIsHandle(1);
|
|
|
|
+ //确定图片是哪个类型的图片
|
|
|
|
+ screenshot.setPicType(jsonMember.getInteger("type"));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ screenshotMapper.insert(screenshot);
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
}
|
|
}
|