密码新增拼音字段,可通过拼音查找

This commit is contained in:
Yutousama 2021-11-06 16:07:02 +08:00
parent c2098ec827
commit bbaecbf976
7 changed files with 148 additions and 38 deletions

12
pom.xml
View File

@ -54,7 +54,7 @@
<dependency> <dependency>
<groupId>redis.clients</groupId> <groupId>redis.clients</groupId>
<artifactId>jedis</artifactId> <artifactId>jedis</artifactId>
<version>3.2.0</version> <version>3.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
@ -69,20 +69,20 @@
<dependency> <dependency>
<groupId>org.mybatis.spring.boot</groupId> <groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId> <artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.1</version> <version>2.2.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.12</version> <version>1.18.22</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.67</version> <version>1.2.78</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.jcraft/jsch --> <!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
<dependency> <dependency>
@ -93,13 +93,13 @@
<dependency> <dependency>
<groupId>com.aliyun.oss</groupId> <groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId> <artifactId>aliyun-sdk-oss</artifactId>
<version>3.8.0</version> <version>3.13.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.xerial</groupId> <groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId> <artifactId>sqlite-jdbc</artifactId>
<version>3.28.0</version> <version>3.36.0.2</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -10,6 +10,8 @@ import com.yutou.tools.mybatis.model.ToolsPasswordType;
import com.yutou.tools.mybatis.model.ToolsPasswordTypeExample; import com.yutou.tools.mybatis.model.ToolsPasswordTypeExample;
import com.yutou.tools.other.tools; import com.yutou.tools.other.tools;
import com.yutou.tools.utils.AESTools; import com.yutou.tools.utils.AESTools;
import com.yutou.tools.utils.HttpTools;
import com.yutou.tools.utils.Tools;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@ -156,6 +158,7 @@ public class PasswordManager {
} }
ToolsPassword toolsPassword=new ToolsPassword(); ToolsPassword toolsPassword=new ToolsPassword();
toolsPassword.setTitle(title); toolsPassword.setTitle(title);
toolsPassword.setTitlePinyin(Tools.getPinYin(title));
toolsPassword.setUsername(username); toolsPassword.setUsername(username);
toolsPassword.setPassword(AESTools.encrypt(password)); toolsPassword.setPassword(AESTools.encrypt(password));
toolsPassword.setType(Integer.parseInt(type)); toolsPassword.setType(Integer.parseInt(type));

View File

@ -5,7 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
public class ToolsApplication { public class ToolsApplication {
public static final String version="1.3"; public static final String version="1.4";
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("当前版本号:" + version); System.out.println("当前版本号:" + version);

View File

@ -13,6 +13,8 @@ public class ToolsPassword implements Serializable {
private String title; private String title;
private String titlePinyin;
private String username; private String username;
private String password; private String password;

View File

@ -105,7 +105,7 @@ public class ToolsPasswordExample {
} }
public Criteria search(String value){ public Criteria search(String value){
addCriterion("title like '%"+value+"%' or `info` like '%"+value+"%' or `url` like '%"+value+"%'"); addCriterion("title like '%"+value+"%' or `info` like '%"+value+"%' or `url` like '%"+value+"%' or `title_pinyin` like '%"+value+"%'");
return (Criteria) this; return (Criteria) this;
} }
@ -239,6 +239,76 @@ public class ToolsPasswordExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTitlePinyinIsNull() {
addCriterion("title_pinyin is null");
return (Criteria) this;
}
public Criteria andTitlePinyinIsNotNull() {
addCriterion("title_pinyin is not null");
return (Criteria) this;
}
public Criteria andTitlePinyinEqualTo(String value) {
addCriterion("title_pinyin =", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinNotEqualTo(String value) {
addCriterion("title_pinyin <>", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinGreaterThan(String value) {
addCriterion("title_pinyin >", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinGreaterThanOrEqualTo(String value) {
addCriterion("title_pinyin >=", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinLessThan(String value) {
addCriterion("title_pinyin <", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinLessThanOrEqualTo(String value) {
addCriterion("title_pinyin <=", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinLike(String value) {
addCriterion("title_pinyin like", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinNotLike(String value) {
addCriterion("title_pinyin not like", value, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinIn(List<String> values) {
addCriterion("title_pinyin in", values, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinNotIn(List<String> values) {
addCriterion("title_pinyin not in", values, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinBetween(String value1, String value2) {
addCriterion("title_pinyin between", value1, value2, "titlePinyin");
return (Criteria) this;
}
public Criteria andTitlePinyinNotBetween(String value1, String value2) {
addCriterion("title_pinyin not between", value1, value2, "titlePinyin");
return (Criteria) this;
}
public Criteria andUsernameIsNull() { public Criteria andUsernameIsNull() {
addCriterion("username is null"); addCriterion("username is null");
return (Criteria) this; return (Criteria) this;

View File

@ -1,6 +1,7 @@
package com.yutou.tools.utils; package com.yutou.tools.utils;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yutou.tools.interfaces.DownloadInterface; import com.yutou.tools.interfaces.DownloadInterface;
import com.yutou.tools.nas.UpdateIp; import com.yutou.tools.nas.UpdateIp;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -103,8 +104,8 @@ public class Tools {
try { try {
System.out.println("title=" + title + " msg=" + msg); System.out.println("title=" + title + " msg=" + msg);
HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send", HttpTools.post("https://sctapi.ftqq.com/SCT2619Tpqu93OYtQCrK4LOZYEfr2irm.send",
("title="+URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8)); ("title=" + URLEncoder.encode(title, "UTF-8") + "&desp=" + URLEncoder.encode(msg, "UTF-8")).getBytes(StandardCharsets.UTF_8));
if (!StringUtils.isEmpty(UpdateIp.nas_ip)) { if (!StringUtils.isEmpty(UpdateIp.nas_ip)) {
String img = null; String img = null;
msg = msg.replace("<br/>", "\n"); msg = msg.replace("<br/>", "\n");
if (msg.contains("![logo]")) { if (msg.contains("![logo]")) {
@ -268,7 +269,8 @@ public class Tools {
downloadInterface.onError(e); downloadInterface.onError(e);
} }
} }
public static ResponseEntity<FileSystemResource> getFile(File file,MediaType mediaType){
public static ResponseEntity<FileSystemResource> getFile(File file, MediaType mediaType) {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
//headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); //headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
try { try {
@ -277,14 +279,15 @@ public class Tools {
headers.add("Content-Disposition", "attachment; filename=" + file.getName()); headers.add("Content-Disposition", "attachment; filename=" + file.getName());
} }
//headers.add("Pragma", "no-cache"); //headers.add("Pragma", "no-cache");
// headers.add("Expires", "0"); // headers.add("Expires", "0");
// headers.add("Last-Modified", new Date().toString()); // headers.add("Last-Modified", new Date().toString());
// headers.add("ETag", String.valueOf(System.currentTimeMillis())); // headers.add("ETag", String.valueOf(System.currentTimeMillis()));
headers.remove("Vary"); headers.remove("Vary");
headers.remove("Connection"); headers.remove("Connection");
headers.remove("Content-Disposition"); headers.remove("Content-Disposition");
return ResponseEntity.ok().headers(headers).contentLength(file.length()).contentType(mediaType).body(new FileSystemResource(file)); return ResponseEntity.ok().headers(headers).contentLength(file.length()).contentType(mediaType).body(new FileSystemResource(file));
} }
/** /**
* 构造给前端的文件 * 构造给前端的文件
* *
@ -292,7 +295,7 @@ public class Tools {
* @return 前端获取的文件 * @return 前端获取的文件
*/ */
public static ResponseEntity<FileSystemResource> getFile(File file) { public static ResponseEntity<FileSystemResource> getFile(File file) {
return getFile(file,MediaType.parseMediaType("application/octet-stream")); return getFile(file, MediaType.parseMediaType("application/octet-stream"));
} }
public static String getFileMD5(File file) { public static String getFileMD5(File file) {
@ -369,8 +372,9 @@ public class Tools {
/** /**
* 扫描使用注解的类 * 扫描使用注解的类
*
* @param packageName 扫描包名 * @param packageName 扫描包名
* @param annotation 注解类 * @param annotation 注解类
* @return 扫描到的集合 * @return 扫描到的集合
*/ */
public static List<Class> scanClass(String packageName, Class<? extends Annotation> annotation) { public static List<Class> scanClass(String packageName, Class<? extends Annotation> annotation) {
@ -407,40 +411,43 @@ public class Tools {
/** /**
* 获取Url * 获取Url
*
* @param packageName 扫描包名 * @param packageName 扫描包名
* @param className 指定类如无指定类为null即可 * @param className 指定类如无指定类为null即可
* @return url集合 * @return url集合
*/ */
public static List<String> getUrls(String packageName,String className){ public static List<String> getUrls(String packageName, String className) {
List<Class> list= scanClass(packageName, Controller.class); List<Class> list = scanClass(packageName, Controller.class);
List<String> urls=new ArrayList<>(); List<String> urls = new ArrayList<>();
for (Class aClass : list) { for (Class aClass : list) {
if(className!=null&&!aClass.getSimpleName().equals(className)){ if (className != null && !aClass.getSimpleName().equals(className)) {
continue; continue;
} }
Method[] methods= aClass.getDeclaredMethods(); Method[] methods = aClass.getDeclaredMethods();
for (Method method : methods) { for (Method method : methods) {
RequestMapping ls=method.getAnnotation(RequestMapping.class); RequestMapping ls = method.getAnnotation(RequestMapping.class);
if(ls!=null) { if (ls != null) {
urls.add(ls.value()[0]); urls.add(ls.value()[0]);
} }
} }
} }
return urls; return urls;
} }
public static String getLoginUser(){
Object user= SecurityContextHolder.getContext().getAuthentication().getPrincipal(); public static String getLoginUser() {
if(user instanceof String){ Object user = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (user instanceof String) {
return (String) user; return (String) user;
}else { } else {
return ((User)user).getUsername(); return ((User) user).getUsername();
} }
} }
public static boolean isAdminLogin(){
public static boolean isAdminLogin() {
return "admin".equals(getLoginUser()); return "admin".equals(getLoginUser());
} }
public static String getMD5(String str){ public static String getMD5(String str) {
return DigestUtils.md5Hex(str); return DigestUtils.md5Hex(str);
} }
@ -448,4 +455,17 @@ public class Tools {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
} }
public static String getPinYin(String text) {
try {
String pinyin = HttpTools.get("https://hn216.api.yesapi.cn/?s=Ext.Pinyin.Convert&return_data=0&text=" + URLEncoder.encode(text, "UTF-8") + "&app_key=C0A906F8C2E21E8B31103458D7B38F93&sign=1B49164601BB2F2C9E189353598A56B5");
JSONObject json = JSONObject.parseObject(pinyin);
if (json.getInteger("ret") == 200) {
return json.getJSONObject("data").getString("pinyin").trim().replace(" ", "");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return "";
}
} }

View File

@ -4,6 +4,7 @@
<resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.ToolsPassword"> <resultMap id="BaseResultMap" type="com.yutou.tools.mybatis.model.ToolsPassword">
<id column="id" jdbcType="INTEGER" property="id" /> <id column="id" jdbcType="INTEGER" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" /> <result column="title" jdbcType="VARCHAR" property="title" />
<result column="title_pinyin" jdbcType="VARCHAR" property="titlePinyin" />
<result column="username" jdbcType="VARCHAR" property="username" /> <result column="username" jdbcType="VARCHAR" property="username" />
<result column="password" jdbcType="VARCHAR" property="password" /> <result column="password" jdbcType="VARCHAR" property="password" />
<result column="url" jdbcType="VARCHAR" property="url" /> <result column="url" jdbcType="VARCHAR" property="url" />
@ -70,7 +71,7 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, title, username, `password`, url, info, `type`, `uid` id, title, title_pinyin, username, `password`, url, info, `type`, `uid`
</sql> </sql>
<select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordExample" resultMap="BaseResultMap"> <select id="selectByExample" parameterType="com.yutou.tools.mybatis.model.ToolsPasswordExample" resultMap="BaseResultMap">
select select
@ -103,12 +104,12 @@
</if> </if>
</delete> </delete>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true"> <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true">
insert into tools_password (title, username, `password`, insert into tools_password (title, title_pinyin, username,
url, info, `type`, `uid` `password`, url, info,
) `type`, `uid`)
values (#{title,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, values (#{title,jdbcType=VARCHAR}, #{titlePinyin,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR},
#{url,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER} #{password,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, #{info,jdbcType=VARCHAR},
) #{type,jdbcType=INTEGER}, #{uid,jdbcType=INTEGER})
</insert> </insert>
<insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true"> <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.yutou.tools.mybatis.model.ToolsPassword" useGeneratedKeys="true">
insert into tools_password insert into tools_password
@ -116,6 +117,9 @@
<if test="title != null"> <if test="title != null">
title, title,
</if> </if>
<if test="titlePinyin != null">
title_pinyin,
</if>
<if test="username != null"> <if test="username != null">
username, username,
</if> </if>
@ -139,6 +143,9 @@
<if test="title != null"> <if test="title != null">
#{title,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
</if> </if>
<if test="titlePinyin != null">
#{titlePinyin,jdbcType=VARCHAR},
</if>
<if test="username != null"> <if test="username != null">
#{username,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR},
</if> </if>
@ -174,6 +181,9 @@
<if test="record.title != null"> <if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR}, title = #{record.title,jdbcType=VARCHAR},
</if> </if>
<if test="record.titlePinyin != null">
title_pinyin = #{record.titlePinyin,jdbcType=VARCHAR},
</if>
<if test="record.username != null"> <if test="record.username != null">
username = #{record.username,jdbcType=VARCHAR}, username = #{record.username,jdbcType=VARCHAR},
</if> </if>
@ -201,6 +211,7 @@
update tools_password update tools_password
set id = #{record.id,jdbcType=INTEGER}, set id = #{record.id,jdbcType=INTEGER},
title = #{record.title,jdbcType=VARCHAR}, title = #{record.title,jdbcType=VARCHAR},
title_pinyin = #{record.titlePinyin,jdbcType=VARCHAR},
username = #{record.username,jdbcType=VARCHAR}, username = #{record.username,jdbcType=VARCHAR},
`password` = #{record.password,jdbcType=VARCHAR}, `password` = #{record.password,jdbcType=VARCHAR},
url = #{record.url,jdbcType=VARCHAR}, url = #{record.url,jdbcType=VARCHAR},
@ -217,6 +228,9 @@
<if test="title != null"> <if test="title != null">
title = #{title,jdbcType=VARCHAR}, title = #{title,jdbcType=VARCHAR},
</if> </if>
<if test="titlePinyin != null">
title_pinyin = #{titlePinyin,jdbcType=VARCHAR},
</if>
<if test="username != null"> <if test="username != null">
username = #{username,jdbcType=VARCHAR}, username = #{username,jdbcType=VARCHAR},
</if> </if>
@ -241,6 +255,7 @@
<update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.ToolsPassword"> <update id="updateByPrimaryKey" parameterType="com.yutou.tools.mybatis.model.ToolsPassword">
update tools_password update tools_password
set title = #{title,jdbcType=VARCHAR}, set title = #{title,jdbcType=VARCHAR},
title_pinyin = #{titlePinyin,jdbcType=VARCHAR},
username = #{username,jdbcType=VARCHAR}, username = #{username,jdbcType=VARCHAR},
`password` = #{password,jdbcType=VARCHAR}, `password` = #{password,jdbcType=VARCHAR},
url = #{url,jdbcType=VARCHAR}, url = #{url,jdbcType=VARCHAR},