diff --git a/pom.xml b/pom.xml
index aadaab7..8ae430e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -65,7 +65,7 @@
org.springframework.boot
spring-boot-starter-websocket
-
+
org.springframework.boot
@@ -104,8 +104,8 @@
postgresql
- mysql
- mysql-connector-java
+ mysql
+ mysql-connector-java
io.jsonwebtoken
@@ -226,6 +226,10 @@
spring-kafka
2.5.10.RELEASE
+
+ junit
+ junit
+
diff --git a/src/main/java/com/xkrs/controller/StreetController.java b/src/main/java/com/xkrs/controller/StreetController.java
new file mode 100644
index 0000000..07fa55d
--- /dev/null
+++ b/src/main/java/com/xkrs/controller/StreetController.java
@@ -0,0 +1,80 @@
+package com.xkrs.controller;
+
+import cn.hutool.core.io.IoUtil;
+import com.xkrs.dao.CityDao;
+import com.xkrs.dao.CountyDao;
+import com.xkrs.dao.StreetDao;
+import com.xkrs.model.entity.CityEntity;
+import com.xkrs.model.entity.CountyEntity;
+import com.xkrs.model.entity.StreetEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.annotation.Resource;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Stream;
+
+@RestController
+public class StreetController {
+
+ @Resource
+ private CityDao cityDao;
+
+ @Resource
+ private CountyDao countyDao;
+
+ @Resource
+ private StreetDao streetDao;
+
+ @GetMapping("/formatStreetData")
+ public String formatStreetData() {
+ File file = new File("/Users/liuchengqian/Downloads/Administrative-divisions-of-China-master/dist/streets2.csv");
+ FileInputStream fileInputStream = IoUtil.toStream(file);
+ BufferedReader reader = IoUtil.getReader(fileInputStream, "UTF-8");
+ Stream lines = reader.lines();
+ AtomicInteger count = new AtomicInteger();
+ lines.forEach(content -> {
+ try {
+ content = content.replace("\"", "");
+ String[] split = content.split(",");
+ StreetEntity streetEntity = new StreetEntity();
+ streetEntity.setProCode(split[3] + "0000");
+ List byProCode1 = cityDao.findByProCode(streetEntity.getProCode());
+ if (byProCode1 == null || byProCode1.isEmpty()) {
+ streetEntity.setProName("");
+ } else {
+ streetEntity.setProName(byProCode1.get(0).getProName());
+ }
+ streetEntity.setCityCode(split[4] + "00");
+ List byCityCode1 = countyDao.findByCityCode(streetEntity.getCityCode());
+ if (byCityCode1 == null || byCityCode1.isEmpty()) {
+ streetEntity.setCityName("");
+ } else {
+ streetEntity.setCityName(byCityCode1.get(0).getCityName());
+ }
+ streetEntity.setCountyCode(split[2]);
+ List byCountyCode = countyDao.findByCountyCode(streetEntity.getCountyCode());
+ if (byCountyCode == null || byCountyCode.isEmpty()) {
+ streetEntity.setCountyName("");
+ } else {
+ streetEntity.setCountyName(byCountyCode.get(0).getCountyName());
+ }
+ streetEntity.setStreetCode(split[0]);
+ streetEntity.setStreetName(split[1]);
+ streetDao.save(streetEntity);
+ count.getAndIncrement();
+ System.out.println(content + " >>> " + count);
+ System.out.println(streetEntity.toString());
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.out.println("格式化街道数据时发生异常:" + e.getMessage());
+ }
+ });
+ return "666";
+ }
+
+}
diff --git a/src/main/java/com/xkrs/controller/SysUserController.java b/src/main/java/com/xkrs/controller/SysUserController.java
index e1acbf5..498f579 100644
--- a/src/main/java/com/xkrs/controller/SysUserController.java
+++ b/src/main/java/com/xkrs/controller/SysUserController.java
@@ -34,6 +34,7 @@ import static com.xkrs.utils.EncryptDecryptUtil.encry256;
/**
* 系统用户Controller
+ *
* @author tajocehn
*/
@RestController
@@ -51,38 +52,37 @@ public class SysUserController {
/**
* 登录用户Token验证
+ *
* @return
*/
- @RequestMapping(value = "/logged/check",method = RequestMethod.POST)
- public String loginUserTokenCheck(){
+ @RequestMapping(value = "/logged/check", method = RequestMethod.POST)
+ public String loginUserTokenCheck() {
Locale locale = LocaleContextHolder.getLocale();
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
@RequestMapping(value = "/check/duplicate", method = RequestMethod.POST)
- public String checkDuplicate(@RequestParam(value="userName", required=false) String userName){
+ public String checkDuplicate(@RequestParam(value = "userName", required = false) String userName) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 验证用户名是否重复
- if(!sysUserService.checkUserName(userName)){
- return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,"",locale);
+ if (!sysUserService.checkUserName(userName)) {
+ return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "", locale);
}
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"OK",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OK", locale);
}
-
@RequestMapping(value = "/add", method = RequestMethod.POST)
- public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo,
- BindingResult bindingResult){
+ public String addUser(@Validated({SysUserQoInsert.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 验证数据合法性
- if(bindingResult.hasErrors()){
- return outputEncapsulationErrorList(bindingResult.getFieldErrors(),locale);
+ if (bindingResult.hasErrors()) {
+ return outputEncapsulationErrorList(bindingResult.getFieldErrors(), locale);
}
// 验证用户名是否重复
- if(!sysUserService.checkUserName(userQo.getUserName())){
- return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,"该账号已经注册,请勿重复注册",locale);
+ if (!sysUserService.checkUserName(userQo.getUserName())) {
+ return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL, "该账号已经注册,请勿重复注册", locale);
}
// 添加新用户
return sysUserService.addUser(userQo);
@@ -90,89 +90,92 @@ public class SysUserController {
/**
* 软删除指定id的普通用户
+ *
* @param id
* @return
*/
@RequestMapping(value = "/general/delete", method = RequestMethod.DELETE)
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_general_user')")
- public String deleteCustomUser(@RequestParam(value="userId", required=false) int id){
+ public String deleteCustomUser(@RequestParam(value = "userId", required = false) int id) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 验证数据合法性
int res = sysUserService.softDeleteGeneralUser(id);
- if(res==1){
- return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"",locale);
+ if (res == 1) {
+ return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "", locale);
} else {
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
@PreAuthorize("hasAnyAuthority('auth_system_manager','auth_administor')")
- public String updateUser(@Validated({SysUserQoUpdate.class}) @RequestBody SysUserQo userQo,
- BindingResult bindingResult){
+ public String updateUser(@Validated({SysUserQoUpdate.class}) @RequestBody SysUserQo userQo, BindingResult bindingResult) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 验证数据合法性
- if(bindingResult.hasErrors()){
- return outputEncapsulationErrorList(bindingResult.getFieldErrors(),locale);
+ if (bindingResult.hasErrors()) {
+ return outputEncapsulationErrorList(bindingResult.getFieldErrors(), locale);
}
// 修改用户
sysUserService.updateSysUser(userQo);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"OK",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "OK", locale);
}
/**
* 判断用户名是否存在
+ *
* @param userName
* @return
*/
@GetMapping("/booleanUserName")
- public String booleanUserName(@RequestParam("userName") String userName){
+ public String booleanUserName(@RequestParam("userName") String userName) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
Map map = new HashMap(3);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(userName);
- if(sysUserEntity == null){
- map.put("status",0);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
- }else {
- map.put("status",1);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,map,locale);
+ if (sysUserEntity == null) {
+ map.put("status", 0);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
+ } else {
+ map.put("status", 1);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, map, locale);
}
}
/**
* 查看用户信息
+ *
* @return
*/
@GetMapping("/selectAllUser")
@PreAuthorize("hasAnyAuthority('auth_administor')")
- public String selectAllUser(@RequestHeader(value="Authorization") String token){
+ public String selectAllUser(@RequestHeader(value = "Authorization") String token) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 验证token
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
- if(sysUserEntity == null){
- return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
+ if (sysUserEntity == null) {
+ return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
}
List sysUserVos = sysUserService.selectAllUser();
- if(sysUserVos == null || sysUserVos.size() == 0){
- return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有任何用户数据",locale);
+ if (sysUserVos == null || sysUserVos.size() == 0) {
+ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有任何用户数据", locale);
}
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,sysUserVos,locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, sysUserVos, locale);
}
/**
* 管理员进行启用禁用的操作
+ *
* @param map
* @param token
* @return
*/
@PostMapping("/operateActiveFlag")
@PreAuthorize("hasAnyAuthority('auth_administor')")
- public String operateActiveFlag(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
+ public String operateActiveFlag(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId");
String keepType = (String) map.get("keepType");
// 获取区域信息
@@ -180,28 +183,29 @@ public class SysUserController {
// 验证token
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
- if(sysUserEntity == null){
- return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
+ if (sysUserEntity == null) {
+ return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
}
// 如果keepType等于1进行启用操作
- if("1".equals(keepType)){
+ if ("1".equals(keepType)) {
sysUserService.updateEnable(userId);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"启用成功",locale);
- }else {
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "启用成功", locale);
+ } else {
sysUserService.updateDisable(userId);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"禁用成功",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "禁用成功", locale);
}
}
/**
* 用户修改密码
+ *
* @param map
* @param token
* @return
*/
@PostMapping("/updatePassword")
@PreAuthorize("hasAnyAuthority('auth_administor','auth_general_user')")
- public String updatePassword(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
+ public String updatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String oldPassword = (String) map.get("oldPassword");
@@ -210,21 +214,22 @@ public class SysUserController {
// 验证token
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
- if(sysUserEntity == null){
- return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
+ if (sysUserEntity == null) {
+ return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
}
- return sysUserService.updatePassword(oldPassword,newPassword,confirmPassword,sysUserEntity);
+ return sysUserService.updatePassword(oldPassword, newPassword, confirmPassword, sysUserEntity);
}
/**
* 管理员修改用户的密码
+ *
* @param map
* @param token
* @return
*/
@PostMapping("/adminUpdatePassword")
@PreAuthorize("hasAnyAuthority('auth_administor')")
- public String adminUpdatePassword(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
+ public String adminUpdatePassword(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
// 要修改的用户的id
@@ -234,40 +239,42 @@ public class SysUserController {
// 验证token
String tokenUserName = TokenUtil.getTokenUserName(token);
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName);
- if(sysUserEntity == null){
- return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
+ if (sysUserEntity == null) {
+ return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
}
- return sysUserService.adminUpdatePassword(userId,newPassword,confirmPassword);
+ return sysUserService.adminUpdatePassword(userId, newPassword, confirmPassword);
}
/**
* 用户忘记密码
+ *
* @param map
* @param
* @return
*/
- @Transactional(rollbackFor=Exception.class)
+ @Transactional(rollbackFor = Exception.class)
@PostMapping("/userUnRememberPassword")
- public String userUnRememberPassword(@RequestBody Map map){
+ public String userUnRememberPassword(@RequestBody Map map) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String phone = (String) map.get("phone");
String newPassword = (String) map.get("newPassword");
String confirmPassword = (String) map.get("confirmPassword");
SysUserEntity sysUserEntity = sysUserDao.selectByUserName(phone);
- if(sysUserEntity == null){
- return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR,"您还没有注册登录,请先注册登录",locale);
+ if (sysUserEntity == null) {
+ return outputEncapsulationObject(PromptMessageEnum.USER_LOGIN_ERROR, "您还没有注册登录,请先注册登录", locale);
}
- if(!newPassword.equals(confirmPassword)){
- return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"两次密码输入不一致",locale);
+ if (!newPassword.equals(confirmPassword)) {
+ return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL, "两次密码输入不一致", locale);
}
String newAfterPassword = encry256(newPassword + sysUserEntity.getSalt());
- sysUserDao.updatePassword(sysUserEntity.getId(),newAfterPassword);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"密码修改成功",locale);
+ sysUserDao.updatePassword(sysUserEntity.getId(), newAfterPassword);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "密码修改成功", locale);
}
/**
* 发送手机号
+ *
* @param phone
* @return
* @throws ClientException
@@ -277,13 +284,14 @@ public class SysUserController {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String optCode = String.valueOf(RandomUtil.returnCode());
- redisService.set(phone,optCode,10, TimeUnit.MINUTES);
- SendSmsResponse response =sendSms(phone,optCode);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
+ redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
+ SendSmsResponse response = sendSms(phone, optCode);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
/**
* 填写手机号发送验证码,用于用户忘记密码
+ *
* @param phone
* @return
* @throws ClientException
@@ -293,67 +301,70 @@ public class SysUserController {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
SysUserVo sysUserVo = sysUserDao.selectUserByUserName(phone);
- if(sysUserVo == null){
- return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"手机号错误,请使用您注册的手机号",locale);
+ if (sysUserVo == null) {
+ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "手机号错误,请使用您注册的手机号", locale);
}
String optCode = String.valueOf(RandomUtil.returnCode());
- redisService.set(phone,optCode,10, TimeUnit.MINUTES);
- SendSmsResponse response =sendSms(phone,optCode);
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"",locale);
+ redisService.set(phone, optCode, 10, TimeUnit.MINUTES);
+ SendSmsResponse response = sendSms(phone, optCode);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "", locale);
}
/**
* 输入验证码进行判断
+ *
* @param phone
* @param verificationCode
* @return
*/
@GetMapping("/getVerificationCode")
- public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode){
+ public String getVerificationCode(@RequestParam("phone") String phone, @RequestParam("verificationCode") String verificationCode) {
Locale locale = LocaleContextHolder.getLocale();
String o = (String) redisService.get(phone);
- if("".equals(o) || o == null){
- return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"请先发送验证码!",locale);
+ if ("".equals(o) || o == null) {
+ return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "请先发送验证码!", locale);
}
- if(!redisService.get(phone).equals(verificationCode)){
- return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"验证码错误,请重新输入!",locale);
+ if (!redisService.get(phone).equals(verificationCode)) {
+ return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG, "验证码错误,请重新输入!", locale);
}
- return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"true",locale);
+ return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "true", locale);
}
/**
* 更改账号过期时间
+ *
* @return
*/
@PostMapping("/updateExpireDate")
@PreAuthorize("hasAnyAuthority('auth_administor')")
- public String updateExpireDate(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
+ public String updateExpireDate(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId");
Integer timeNum = (Integer) map.get("timeNum");
String keepType = (String) map.get("keepType");
- if("1".equals(keepType)){
+ if ("1".equals(keepType)) {
return sysUserService.updateExpireDateDay(userId, timeNum);
- }else if("2".equals(keepType)){
- return sysUserService.updateExpireDateMonth(userId,timeNum);
- }else if("3".equals(keepType)){
- return sysUserService.updateExpireDateYear(userId,timeNum);
- }else {
+ } else if ("2".equals(keepType)) {
+ return sysUserService.updateExpireDateMonth(userId, timeNum);
+ } else if ("3".equals(keepType)) {
+ return sysUserService.updateExpireDateYear(userId, timeNum);
+ } else {
return sysUserService.updatePermanent(userId);
}
}
/**
* 修改账号到期时间
+ *
* @param map
* @param token
* @return
*/
@PostMapping("/updateOverTime")
@PreAuthorize("hasAnyAuthority('auth_administor')")
- public String updateOverTime(@RequestBody Map map,@RequestHeader(value="Authorization") String token){
+ public String updateOverTime(@RequestBody Map map, @RequestHeader(value = "Authorization") String token) {
Integer userId = (Integer) map.get("userId");
String overTime = (String) map.get("overTime");
- return sysUserService.updateOverTime(userId,overTime);
+ return sysUserService.updateOverTime(userId, overTime);
}
}
diff --git a/src/main/java/com/xkrs/dao/CountyDao.java b/src/main/java/com/xkrs/dao/CountyDao.java
index 00bf312..e5400b0 100644
--- a/src/main/java/com/xkrs/dao/CountyDao.java
+++ b/src/main/java/com/xkrs/dao/CountyDao.java
@@ -12,17 +12,19 @@ import java.util.Map;
* @author XinYi Song
*/
@Component
-public interface CountyDao extends JpaRepository {
+public interface CountyDao extends JpaRepository {
/**
* 查询市包含的区县和编码
+ *
* @param code
* @return
*/
- @Query(value = "select county_name cityname,county_code citycode from county where city_code = :code",nativeQuery = true)
- List