Commit bf5435fe authored by Zachary's avatar Zachary

test(测试IP):测试国别

parent 1c076006
......@@ -80,7 +80,11 @@
<artifactId>protobuf-java</artifactId>
<version>3.5.1</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip2</groupId>
<artifactId>geoip2</artifactId>
<version>4.2.1</version>
</dependency>
</dependencies>
<build>
......@@ -124,6 +128,7 @@
</build>
<repositories>
<repository>
<id>nexus-91isoft-release</id>
<name>local release nexus</name>
......
package org.rcisoft.business.test;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class CertificateGenerator {
public static void main(String[] args) throws Exception{
// 1. 加载模板
BufferedImage template = ImageIO.read(new File("D:\\All_Server_Projects\\91soft\\tea\\tea_resource_api\\src\\main\\java\\org\\rcisoft\\business\\test\\temp.jpg"));
BufferedImage certificate = new BufferedImage(
template.getWidth(),
template.getHeight(),
BufferedImage.TYPE_INT_RGB
);
Graphics2D g = certificate.createGraphics();
g.drawImage(template, 0, 0, null);
// 2. 设置字体(支持中文)
Font font = Font.createFont(Font.TRUETYPE_FONT, new File("D:\\All_Server_Projects\\91soft\\tea\\tea_resource_api\\src\\main\\java\\org\\rcisoft\\business\\test\\Alibaba-PuHuiTi-Bold.ttf")).deriveFont(100f);
g.setFont(font);
g.setColor(new Color(49, 145, 184));
// 3. 动态绘制数据
String name = "徐豪泽";
String score = "100分";
FontMetrics metrics = g.getFontMetrics();
int x = (certificate.getWidth() - metrics.stringWidth(name)) / 2; // 水平居中
int y = 700; // 垂直位置(需根据模板调整)
g.drawString(name, x, y);
g.drawString(score,500,600);
// 4. 保存证书
g.dispose();
ImageIO.write(certificate, "png", new File("certificate_output.png"));
}
}
package org.rcisoft.business.test.controller;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.model.CountryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.test.entity.TestData;
import org.rcisoft.business.test.service.TestService;
import org.rcisoft.core.constant.CyMessCons;
import org.rcisoft.core.model.CyPersistModel;
import org.rcisoft.core.result.CyResult;
import org.rcisoft.core.util.CyResultGenUtil;
import org.springframework.core.io.ClassPathResource;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
@RestController
@RequestMapping("/test")
@Api(tags = "测试类")
public class TestController {
@Resource
private TestService testService;
@ApiOperation(value = "测试查询")
@GetMapping("/query")
public CyResult testQuery(){
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
testService.queryList()
);
}
@ApiOperation(value = "测试添加")
@PostMapping("/add")
public CyResult testAdd(@RequestBody TestData testData, BindingResult bindingResult){
CyPersistModel data = testService.add(testData);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
testData
);
}
@ApiOperation(value = "测试删除")
@DeleteMapping("/del/{id}")
public CyResult testDel(@PathVariable Integer id){
CyPersistModel data = testService.del(id);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
id
);
}
@ApiOperation("测试修改")
@PutMapping("/update/{id}")
public CyResult testUpdate(@PathVariable Integer id, @RequestBody TestData testData){
testData.setId(id);
CyPersistModel data = testService.update(testData);
return CyResultGenUtil.builder(data,
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
testData
);
}
@GetMapping("/geo")
public CyResult testDetectIp(HttpServletRequest request) throws Exception {
File geoIpDataBase = new ClassPathResource("geoip/GeoLite2-Country.mmdb").getFile();
DatabaseReader reader = new DatabaseReader.Builder(geoIpDataBase).build();
String ip = request.getRemoteAddr();
InetAddress ipAddress = InetAddress.getByName(ip);
CountryResponse country = reader.country(ipAddress);
System.out.println(country.getCountry().getName());
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
country.getCountry().getName()
);
}
}
package org.rcisoft.business.test.dao;
import org.apache.ibatis.annotations.Mapper;
import org.rcisoft.business.test.entity.TestData;
import org.rcisoft.core.mapper.CyBaseMapper;
import java.util.List;
@Mapper
public interface TestRepository extends CyBaseMapper<TestData> {
List<TestData> query();
int del(Integer id);
int add(TestData testData);
int update(TestData testData);
}
package org.rcisoft.business.test.entity;
import lombok.Data;
import org.rcisoft.core.entity.CyIdIncreEntity;
@Data
public class TestData extends CyIdIncreEntity<TestData> {
private Integer id;
private String data;
}
package org.rcisoft.business.test.geoip;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.model.CityResponse;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import org.springframework.core.io.ClassPathResource;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
public class GeoIpTest {
public static void main(String[] args) throws Exception {
File geoIpDataBase = new ClassPathResource("geoip/GeoLite2-Country.mmdb").getFile();
DatabaseReader reader = new DatabaseReader.Builder(geoIpDataBase).build();
InetAddress ipAddress = InetAddress.getByName("111.163.121.235");
CountryResponse country = reader.country(ipAddress);
System.out.println(country.getCountry().getName());
}
}
package org.rcisoft.business.test.service;
import org.rcisoft.business.test.entity.TestData;
import org.rcisoft.core.model.CyPersistModel;
import org.springframework.stereotype.Service;
import java.util.List;
public interface TestService {
CyPersistModel add(TestData testData);
List<TestData> queryList();
CyPersistModel del(Integer id);
CyPersistModel update(TestData testData);
}
package org.rcisoft.business.test.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.test.dao.TestRepository;
import org.rcisoft.business.test.entity.TestData;
import org.rcisoft.business.test.service.TestService;
import org.rcisoft.core.model.CyPersistModel;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
@Slf4j
public class TestServiceImpl extends ServiceImpl<TestRepository,TestData> implements TestService {
@Resource
private TestRepository testRepository;
@Override
public CyPersistModel add(TestData testData) {
int add = testRepository.add(testData);
return new CyPersistModel(add);
}
@Override
public List<TestData> queryList() {
return testRepository.query();
}
@Override
public CyPersistModel del(Integer id) {
int del = testRepository.del(id);
return new CyPersistModel(del);
}
@Override
public CyPersistModel update(TestData testData) {
int update = testRepository.update(testData);
return new CyPersistModel(update);
}
}
This diff is collapsed.
......@@ -2,7 +2,7 @@
cy_redis:
ip: 127.0.0.1
port: 6379
password: 123456
password:
database: 10
# rabbitMq
......@@ -31,14 +31,20 @@ cy_mq:
# # password: root
# db: demo
#cy_db:
# # ip: 106.3.97.198
# ip: 127.0.0.1
# port: 3306
# username: root
# password: 123456
# db: tea
cy_db:
# ip: 106.3.97.198
ip: 127.0.0.1
port: 3306
username: root
password: 123456
password: root
db: tea
# mongodb
cy_mongodb:
ip: 127.0.0.1
......@@ -141,6 +147,7 @@ cy:
- "/pc/sysuser/updatePassword"
- "/ossinfo/uploadVideoToOss"
- "/ossinfo/uploadZipToOss"
- "/test/**"
# - "/**/**"
permitStatic: [ "/", "/*.html", "/favicon.ico", "/**/*.html", "/**/*.js", "/**/*.css" ]
......
......@@ -204,6 +204,7 @@
and remainingDate = 0
</if>
ORDER BY tln.create_date DESC
</select>
<select id="pagingBLessonObligatory" resultType="org.rcisoft.business.blesson.entity.BLesson">
SELECT
......
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