Commit f3cef519 by 吴迪

【新增】新增与名配置代码

parent e099bd1e
package io.office.modules.manage.controller;
import io.office.common.utils.PageUtils;
import io.office.common.utils.R;
import io.office.modules.manage.entity.DomainListProperties;
import io.office.modules.manage.service.DocService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* 
 @description:
*
* @author wudi
* @date 10:33 2021/12/28
*/
@Slf4j
@EnableConfigurationProperties(DomainListProperties.class)
@RestController
@RequestMapping("/domain")
public class DomainListController {
@Autowired
private DomainListProperties domainListProperties;
@RequestMapping("/api/list")
// @RequiresPermissions("manage:doc:list")
public R list(@RequestParam Map<String, Object> params) {
return R.ok().put("page", domainListProperties.getList());
}
}
package io.office.modules.manage.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.office.common.utils.IPUtils;
import io.office.common.utils.R;
import io.office.modules.app.annotation.Login;
import io.office.modules.manage.entity.SearchgtinlogEntity;
import io.office.modules.manage.service.FirmService;
import io.office.modules.manage.service.SearchgtinlogService;
import io.office.modules.manage.utils.ESSearchUtils;
import io.office.modules.manage.utils.GLNSearchUtils;
import io.office.modules.manage.utils.UploadUtils;
import io.office.modules.manage.utils.*;
import io.office.modules.manage.vo.request.DomesticCodeDetailRequest;
import io.office.modules.manage.vo.request.DomesticCodeVo;
import io.office.modules.manage.vo.request.GLNRequestBo;
import io.office.modules.sys.service.SysCaptchaService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -40,9 +41,14 @@ public class GLNController {
@Autowired
private FirmService firmService;
@Autowired
private SearchLimitUtil searchLimitUtil;
@Login
@PostMapping("/api/gln")
public R uploadFile(@RequestBody GLNRequestBo glnRequestBo, HttpServletRequest request) {
String typeKey = "";
boolean captcha = sysCaptchaService.validate(glnRequestBo.getUuid(), glnRequestBo.getCaptcha());
if(!captcha){
return R.error("验证码不正确");
......@@ -57,6 +63,7 @@ public class GLNController {
// glnRequestBo.setCode("0"+glnRequestBo.getCode());
searchgtinlogEntity.setKeyword(glnRequestBo.getCode());
searchgtinlogEntity.setClassStr("GLN查询");
typeKey="GLN查询";
} else if(glnRequestBo.getType().equals("GTIN")){
if(glnRequestBo.getCode().length()<12) {
return R.error("GTIN不能少于12位!");
......@@ -68,6 +75,13 @@ public class GLNController {
glnRequestBo.setCode("0"+glnRequestBo.getCode());
}
searchgtinlogEntity.setClassStr("境外条码查询:厂商信息查询");
typeKey="境外条码查询:厂商信息查询";
}
//校验是否开启
String searchLimitStr = searchLimitUtil.checkSearchLimit(request,typeKey);
if(StringUtils.isNotBlank(searchLimitStr)) {
return R.error(searchLimitStr);
}
searchgtinlogEntity.setKeyword(glnRequestBo.getCode());
searchgtinlogEntity.setSearchsource(0);
......
package io.office.modules.manage.entity;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.List;
/**
*
* 
 @description:
*
* @author wudi
* @date 10:40 2021/12/28
*/
@Data
@ConfigurationProperties(prefix = "gs1.domain") //指定ly.upload开头的变量
public class DomainListProperties {
private List<String> list;
}
......@@ -255,6 +255,21 @@ public class DateUtils {
/**
* 得到n秒之后之后的日期
*/
public static String getAfterSecondCycleByHour(Date date, String second) {
int daysInt = Integer.parseInt(second);
Calendar canlendar = Calendar.getInstance();
canlendar.setTime(date);
canlendar.add(Calendar.SECOND, daysInt);
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = sdfd.format(canlendar.getTime());
return dateStr;
}
/**
* 得到n小时之后的日期
*/
public static String getAfterMinCycleByHour(Date date, String mins) {
......
package io.office.modules.manage.utils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.office.common.utils.IPUtils;
import io.office.common.utils.R;
import io.office.modules.manage.entity.SearchgtinlogEntity;
import io.office.modules.manage.service.SearchgtinlogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
/**
* 
 @description:
*
* @author wudi
* @date 14:45 2021/12/27
* <p>
* #是否开启查询限制 1 打开 0关闭
* searchLimitSwitch: 1
* #是否开启每次查询次数限制 1 打开 0关闭
* searchDayLimitSwitch: 1
* #查询次数限制上限
* searchDayCountLimitSwitch: 10
*/
@Component
public class SearchLimitUtil {
@Value("${searchLimitSwitch}")
private String searchLimitSwitch;
@Value("${searchDayLimitSwitch}")
private String searchDayLimitSwitch;
@Value("${searchDayCountLimitSwitch}")
private String searchDayCountLimitSwitch;
@Resource
private SearchgtinlogService searchgtinlogService;
public String checkSearchLimit(HttpServletRequest request, String typeKeyWord) {
if (StringUtils.isNotBlank(searchLimitSwitch) && searchLimitSwitch.equalsIgnoreCase("1")) {
Date date = new Date();
String ip = IPUtils.getIpAddr(request);
//查询最后查询的时间
QueryWrapper<SearchgtinlogEntity> searchgtinlogEntityQueryWrapper = new QueryWrapper<>();
searchgtinlogEntityQueryWrapper.eq("ip", ip);
searchgtinlogEntityQueryWrapper.eq("keyword", typeKeyWord);
searchgtinlogEntityQueryWrapper.between("createdate", DateUtils.getAfterSecondCycleByHour(date, "-5"), DateUtils.formatDateToString(date, DateUtils.FORMAT1));
int count = searchgtinlogService.count(searchgtinlogEntityQueryWrapper);
if (count >= 1) {
return "搜索频率过于频繁,请5s后重试!";
}
//是否开启当日查询次数限制
if (StringUtils.isNotBlank(searchDayLimitSwitch) && searchDayLimitSwitch.equalsIgnoreCase("1")) {
if (StringUtils.isNotBlank(searchDayCountLimitSwitch)) {
QueryWrapper<SearchgtinlogEntity> searchgtinlogEntityIpQueryWrapper = new QueryWrapper<>();
searchgtinlogEntityIpQueryWrapper.eq("ip", ip);
searchgtinlogEntityQueryWrapper.eq("keyword", typeKeyWord);
searchgtinlogEntityIpQueryWrapper.between("createdate", DateUtils.getDayStartTime(date), DateUtils.getDayEndTime(date));
int countIp = searchgtinlogService.count(searchgtinlogEntityIpQueryWrapper);
if (countIp >= Integer.parseInt(searchDayCountLimitSwitch)) {
return "今日搜索次数已达到上限,请明天再查询!";
}
}
}
}
return null;
}
}
......@@ -74,4 +74,21 @@ file:
prefix: http://81.68.189.225:9091/office/uploadFileResource/
ueditorSavePath: /uploadFileResource/
prefix_host: http://81.68.189.225:9091/office/
\ No newline at end of file
prefix_host: http://81.68.189.225:9091/office/
#是否开启查询限制 1 打开 0关闭
searchLimitSwitch: 1
#是否开启每次查询次数限制 1 打开 0关闭
searchDayLimitSwitch: 1
#查询次数限制上限
searchDayCountLimitSwitch: 10
#域名
gs1:
domain:
list:
- http://81.68.189.225
- http://81.68.189.225
......@@ -46,4 +46,12 @@ spring:
# driver-class-name: org.postgresql.Driver
# url: jdbc:postgresql://localhost:5432/renren_security
# username: renren
# password: 123456
\ No newline at end of file
# password: 123456
#域名
gs1:
domain:
list:
- http://www.gs1cn.orgc
- http://www.ancc.org.cn
\ No newline at end of file
......@@ -74,4 +74,14 @@ file:
prefix: http://192.168.0.77:9091/office/uploadFileResource/
ueditorSavePath: D:/uploadFileResource/
prefix_host: http://192.168.0.77:9091/office/
\ No newline at end of file
prefix_host: http://192.168.0.77:9091/office/
#是否开启查询限制 1 打开 0关闭
searchLimitSwitch: 1
#域名
gs1:
domain:
list:
- http://192.168.0.77
- http://192.168.0.77
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment