Commit 3f0b7b6d by jscat

nyx jaapp: 功能更新

1. 添加图片监测then上传功能
2. 添加redis支持
parent ae455641
......@@ -216,6 +216,27 @@
<version>1.4.9</version>
</dependency>
<!--集成redis-->
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-redis -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.0</version>
</dependency>
<!-- &lt;!&ndash; https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.springframework.data</groupId>-->
<!-- <artifactId>spring-data-redis</artifactId>-->
<!-- <version>2.4.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
<build>
......
......@@ -29,7 +29,9 @@ public enum ExceptionMsg {
ResubmitError("000601", "重复提交错误!"),
EditMemberError("000701", "更新商家信息错误!"),
AddAddressError("000701", "新增地址信息错误!")
AddAddressError("000701", "新增地址信息错误!"),
RedisOpIncrError("000801", "Redis加值操作错误!")
;
......
package cn.com.fun.nyxkey.api.config;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
@Configuration
@Slf4j
public class RedisConfig {
@Value("${spring.redis.host}")
private String host;
@Value("${spring.redis.port}")
private int port;
@Value("${spring.redis.timeout}")
private int timeout;
@Value("${spring.redis.jedis.pool.max-idle}")
private int maxIdle;
@Value("${spring.redis.jedis.pool.max-wait}")
private long maxWaitMillis;
@Value("${spring.redis.password}")
private String password;
@Value("${spring.redis.block-when-exhausted}")
private boolean blockWhenExhausted;
@Bean
public JedisPool redisPoolFactory() throws Exception{
log.info("JedisPool注入成功!!");
log.info("redis地址:" + host + ":" + port);
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
jedisPoolConfig.setMaxIdle(maxIdle);
jedisPoolConfig.setMaxWaitMillis(maxWaitMillis);
// 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true
jedisPoolConfig.setBlockWhenExhausted(blockWhenExhausted);
// 是否启用pool的jmx管理功能, 默认true
jedisPoolConfig.setJmxEnabled(true);
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, password);
return jedisPool;
}
}
\ No newline at end of file
......@@ -166,6 +166,18 @@ public class Rockwell_checkServiceImpl implements Rockwell_checkService {
return checkPic(token, multipartFile);
}
/*
接口api: 小程序图片验证
*/
public JSONResult Rockwell_checkServiceCheckAndUploadPic(MultipartFile multipartFile){
LOGGER.debug("find Rockwell_checkServiceCheckPic");
JSONObject json = getAccessToken();
String token = json.getString("access_token")+"";
return checkPic(token, multipartFile);
}
public void getPicInfo(MultipartFile multipartFile) {
System.out.println("图片名称: "+multipartFile.getName());
System.out.println("图片原名: "+multipartFile.getOriginalFilename());
......
......@@ -2,16 +2,26 @@ package cn.com.fun.nyxkey.api.web.controller;
import cn.com.fun.nyxkey.api.common.JSONResult;
import cn.com.fun.nyxkey.api.service.Rockwell_checkService;
import cn.com.fun.nyxkey.api.utils.UploadFile;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static cn.com.fun.nyxkey.api.common.ExceptionMsg.FileEmpty;
/*
API接口
用于小程序的相关验证
......@@ -23,6 +33,10 @@ import org.springframework.web.multipart.MultipartFile;
@RequestMapping("/api")
public class CheckApiController {
//上传文件的路径
@Value("${upload.image}")
public String imagePath;
private static final Logger LOGGER = LoggerFactory.getLogger(CheckApiController.class);
@Autowired
......@@ -62,4 +76,54 @@ public class CheckApiController {
return checkService.Rockwell_checkServiceCheckPic(multipartFile);
}
/*
JSONObject object = (JSONObject)json.getData();
{
errcode: "0",
errmsg: "ok"
}
output
{
resultCode: "200",
totalCount: n,
resultMsg: "OK",
data: {
errcode: "0",
errmsg: "ok",
paths: "[123]",
}
}
*/
@ApiOperation(value="图片敏感信息检测并上传", notes="图片敏感信息检测并上传")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/wx/check/upload/pic", method = RequestMethod.POST)
@ResponseBody
public JSONResult checkAndUploadPic(
@RequestParam(value = "file", required = false, defaultValue = "0") MultipartFile multipartFile
) throws Exception {
JSONResult result = checkService.Rockwell_checkServiceCheckPic(multipartFile);
JSONObject json = (JSONObject)result.getData();
//pass image test
if(json.get("errcode").equals(0))
{
List<MultipartFile> files = new ArrayList<>();
files.add(multipartFile);
Date date=new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String subpath = sdf.format(date) + "/";
List<String> paths = UploadFile.uploadFiles(files, imagePath, subpath);
int totalCount = paths.size();
json.put("paths",paths);
result.setData(json);
result.setTotalCount(totalCount);
}
return result;
}
}
\ No newline at end of file
......@@ -414,7 +414,8 @@ public class NyxApiController {
return keyService.Rockwell_keyServiceGetV_activity_stat(activityType, cityName);
}
// 4.0 post info api
// 4.0 post info api, 用activity替代
@Deprecated
@ApiOperation(value="获取用户的post info", notes="获取用户的post info")
@ApiImplicitParams({
@ApiImplicitParam(name = "tag", value = "标签; 饮事", required = false, dataType = "String"),
......@@ -435,6 +436,7 @@ public class NyxApiController {
}
// 4.1 为post添加点赞 2020-05-19
@Deprecated
@ApiOperation(value="添加点赞", notes="添加点赞")
@ApiImplicitParams({
@ApiImplicitParam(name = "postId", value = "postId", required = false, dataType = "String", defaultValue = "pid_123"),
......
package cn.com.fun.nyxkey.api.web.controller;
import cn.com.fun.nyxkey.api.common.ExceptionMsg;
import cn.com.fun.nyxkey.api.common.JSONResult;
import cn.com.fun.nyxkey.api.utils.JedisUtil;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
/**
* Created by jscat on 2020-11-21.
*/
@RestController
@RequestMapping("/api")
public class RedisController {
@Autowired
JedisUtil jedisUtil;
private static final Logger LOGGER = LoggerFactory.getLogger(PayApiController.class);
/**
* @Description update redis like
*
* 流程:
* 1)
* postman测试
* single: https://blog.csdn.net/maowendi/article/details/80537304/
* multi : https://blog.csdn.net/weixin_45739720/article/details/103724064
* 1. POST
* 2. Headers: Key:Content-Type/Value:multipart/form-data
* 3. body:
* single: Key: file/选择文件file/Value:mid_123.jpg
* multi : Key:files/选择文件file/Value:mid_123.jpg
* Key:files/选择文件file/Value:微信截图_20201018200554.png
*
* @param
* @return Map
*/
@ApiOperation(value="更新热度值", notes="更新热度值")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/redis/update/like", method = RequestMethod.GET)
public JSONResult updateLike(
@RequestParam(value = "keyString", required = true, defaultValue = "0") String keyString
) throws Exception {
try
{
String [] list = keyString.split("::");
for (String key: list){
jedisUtil.incr(key);
}
return new JSONResult(list.length, list);
}
catch (Exception e)
{
return new JSONResult(ExceptionMsg.RedisOpIncrError);
}
}
/*
refer:
1. redis 成批get性能提高-mget https://blog.csdn.net/czw698/article/details/41546369
*/
@ApiOperation(value="搜索热度值", notes="搜索热度值")
@ApiImplicitParams({
})
@RequestMapping(value = "/nyx/redis/search/like", method = RequestMethod.GET)
public JSONResult searchLike() throws Exception {
// 返回json显示的话 把MAP转json toJsonFromMap
String pattern = "[@#]*";
Set<String> keys = jedisUtil.keys(pattern);
Map<String, String> map = new HashMap<>();
List<String> list = new ArrayList<>(keys);
List<String> valueList = jedisUtil.mget(list.toArray(new String[list.size()]));
int i = 0;
for (String key : keys) {
map.put(key, valueList.get(i));
i++;
}
return new JSONResult(i, map);
}
}
......@@ -60,6 +60,18 @@ spring:
max-lifetime: 100000
connection-timeout: 30000
connection-test-query: SELECT 1
redis:
host: 47.99.110.89
port: 6379
password: nyx123456
timeout: 30000
block-when-exhausted: true
jedis:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
aliyun:
oss:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论