diff --git a/doc/btn.sql b/doc/btn.sql
index a118ad1ba7fdbf13458795728370bc2bb78eaa88..010b655b0902ffbee0d64b5fd9cc9dcee6cdda97 100644
--- a/doc/btn.sql
+++ b/doc/btn.sql
@@ -18,6 +18,16 @@ CREATE TABLE `t_user` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='用户表';
+DROP TABLE IF EXISTS `t_uplocal_file`;
+CREATE TABLE `t_uplocal_file` (
+ `id` INT NOT NULL AUTO_INCREMENT COMMENT '主键',
+ `create_time` BIGINT DEFAULT 0 COMMENT '添加时间',
+ `update_time` BIGINT DEFAULT 0 COMMENT '更新时间',
+ `enabled` INT(1) DEFAULT '1' COMMENT '是否可见,0为不可见,1为可见',
+ `profile_photo` VARCHAR(255) DEFAULT NULL COMMENT '用户头像 (头像保存路径,第一次注册使用默认头像)',
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='上传图片表';
+
DROP TABLE IF EXISTS `t_user_friends`;
CREATE TABLE `t_user_friends` (
diff --git a/pom.xml b/pom.xml
index 92fab7a734ff5d6342e582a2b1eb9e37f9d055f7..fc3813da55645a058a1e097625393fd4817c7959 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,6 +71,12 @@
springfox-swagger-ui
2.2.2
+
+
+ cn.hutool
+ hutool-all
+ 4.1.14
+
@@ -87,6 +93,7 @@
**/*.yml
**/*.properties
+ **/log/**/logback.xml
diff --git a/src/main/java/com/library/nbt/config/MyWebMvcConfigurerAdapter.java b/src/main/java/com/library/nbt/config/MyWebMvcConfigurerAdapter.java
new file mode 100644
index 0000000000000000000000000000000000000000..9a9cf788f46cf0f2dfad7590884349e4d59700fa
--- /dev/null
+++ b/src/main/java/com/library/nbt/config/MyWebMvcConfigurerAdapter.java
@@ -0,0 +1,24 @@
+package com.library.nbt.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+@Configuration
+public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
+
+ //图片存放根路径
+ @Value("${file.rootPath}")
+ private String ROOT_PATH;
+ //图片存放根目录下的子目录
+ @Value("${file.sonPath}")
+ private String SON_PATH;
+ @Override
+ public void addResourceHandlers(ResourceHandlerRegistry registry){
+ String filePath = "file:" + ROOT_PATH + SON_PATH;
+ //指向外部目录
+ registry.addResourceHandler("img//**").addResourceLocations(filePath);
+ super.addResourceHandlers(registry);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/config/StepExecutorConfig.java b/src/main/java/com/library/nbt/config/StepExecutorConfig.java
index b9f38a23c689ec2b6b31b0ed477591259b9cee6f..04eaf71e4354213f76fc45f37a8d620878b13df5 100644
--- a/src/main/java/com/library/nbt/config/StepExecutorConfig.java
+++ b/src/main/java/com/library/nbt/config/StepExecutorConfig.java
@@ -28,19 +28,34 @@ public class StepExecutorConfig implements ApplicationRunner {
private boolean isOpen;
@Override
public void run(ApplicationArguments args){
- //启动http://localhost:9036/swagger-ui.html
- application();
+ //先判断当前环境
+ if (!exitisVersion()){
+ //启动swagger-ui
+ application();
+ }
+ }
+
+ private Boolean exitisVersion() {
+ String osName = System.getProperties().getProperty("os.name");
+ if(osName.equals("Linux")) {
+ LOG.info("running in Linux");
+ return true;
+ }
+ else{
+ LOG.info("don't running in Linux");
+ return false;
+ }
}
private void application() {
if (isOpen){
String cmd = googleExcutePath +" "+ loginUrl;
- System.out.println(cmd);
+ LOG.info("浏览地址:" + cmd);
Runtime run = Runtime.getRuntime();
try{
run.exec(cmd);
- LOG.debug("启动浏览器打开项目成功");
+ LOG.info("启动浏览器打开项目成功");
}catch (Exception e){
e.printStackTrace();
LOG.error(e.getMessage());
diff --git a/src/main/java/com/library/nbt/config/WebMvcConfig.java b/src/main/java/com/library/nbt/config/WebMvcConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..c580a101881121cd40eeea56e16ae49aff5bb738
--- /dev/null
+++ b/src/main/java/com/library/nbt/config/WebMvcConfig.java
@@ -0,0 +1,29 @@
+package com.library.nbt.config;
+
+
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+
+/**
+ * 解决跨域问题
+ */
+@Configuration
+public class WebMvcConfig extends WebMvcConfigurerAdapter {
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ System.out.println("我是MyWebConfig跨域");
+ //设置允许跨域的路径
+ registry.addMapping("/**")
+ //设置允许跨域请求的域名
+ .allowedOrigins("*")
+ //是否允许证书 不再默认开启
+ .allowCredentials(true)
+ //设置允许的方法
+ .allowedMethods("*")
+ //跨域允许时间
+ .maxAge(3600);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/controller/ArticleController.java b/src/main/java/com/library/nbt/controller/ArticleController.java
index c4a071d14163dc4ce7b128d340256ca81c2d9497..a2ca1144cacbf494a1511b632c2d25a62580b199 100644
--- a/src/main/java/com/library/nbt/controller/ArticleController.java
+++ b/src/main/java/com/library/nbt/controller/ArticleController.java
@@ -2,6 +2,7 @@ package com.library.nbt.controller;
import com.library.nbt.model.entity.ArticleEntity;
import com.library.nbt.model.entity.UserEntity;
+import com.library.nbt.model.view.ArticleEntityView;
import com.library.nbt.service.ArticleService;
import com.library.nbt.service.UserService;
import com.library.nbt.utils.Result;
@@ -36,8 +37,8 @@ public class ArticleController {
@RequestMapping(value = "/v1/article/select/{id}", method = RequestMethod.GET)
public Result> getEntity(@ApiParam(value = "用户ID", required = true) @PathVariable(value = "id") Integer id) {
try {
- ArticleEntity articleEntity = articleService.getEntity(id);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntity);
+ ArticleEntityView articleEntityView = articleService.getEntity(id);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntityView);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.SUCCESS_CODE_200, e.getMessage());
}
@@ -48,10 +49,10 @@ public class ArticleController {
@ApiResponse(code = 200, message = "successful request"),
@ApiResponse(code = 500, message = "internal server error")})
@RequestMapping(value = "/v1/article/insert", method = RequestMethod.POST)
- public Result> saveEntity(@RequestBody ArticleEntity articleEntity) {
+ public Result> saveEntity(@RequestBody ArticleEntityView articleEntityView) {
try {
- ArticleEntity articleEntityResult = articleService.saveEntity(articleEntity);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntityResult);
+ ArticleEntityView articleEntityViewResult = articleService.saveEntity(articleEntityView);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntityViewResult);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
}
@@ -63,7 +64,6 @@ public class ArticleController {
@ApiResponse(code = 500, message = "internal server error")})
@RequestMapping(value = "/v1/article/delete/{id}", method = RequestMethod.DELETE)
public Result> deleteEntity(@ApiParam(value = "文章ID", required = true) @PathVariable(value = "id") Integer id) {
-
try {
articleService.deleteEntity(id);
return ResultUtil.success();
@@ -77,24 +77,10 @@ public class ArticleController {
@ApiResponse(code = 200, message = "successful request"),
@ApiResponse(code = 500, message = "internal server error")})
@RequestMapping(value = "/v1/article/update", method = RequestMethod.POST)
- public Result> updateEntity(@RequestBody ArticleEntity articleEntity) {
- try {
- articleService.updateEntity(articleEntity);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntity);
- } catch (Exception e) {
- return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
- }
- }
-
- @ApiOperation(value = "获取所有文章", notes = "获取所有文章")
- @ApiResponses(value = {
- @ApiResponse(code = 200, message = "successful request"),
- @ApiResponse(code = 500, message = "internal server error")})
- @RequestMapping(value = "/v1/article/findAll", method = RequestMethod.POST)
- public Result> findAll() {
+ public Result> updateEntity(@RequestBody ArticleEntityView articleEntityView) {
try {
- List resultArtcle = articleService.findAll();
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, resultArtcle);
+ articleService.updateEntity(articleEntityView);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, articleEntityView);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
}
diff --git a/src/main/java/com/library/nbt/controller/CodeController.java b/src/main/java/com/library/nbt/controller/CodeController.java
new file mode 100644
index 0000000000000000000000000000000000000000..3c4752754b6ce4a2d895d779dcf98aaac2bec610
--- /dev/null
+++ b/src/main/java/com/library/nbt/controller/CodeController.java
@@ -0,0 +1,48 @@
+package com.library.nbt.controller;
+
+import com.library.nbt.utils.RandomValidateCodeUtil;
+import com.library.nbt.utils.VerifyUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.awt.image.BufferedImage;
+import java.io.OutputStream;
+
+@RestController
+@RequestMapping(value = "/api")
+@Api(value = "验证码接口", tags = "验证码接口", description = "")
+public class CodeController {
+ private static final Logger LOG = LoggerFactory.getLogger(RandomValidateCodeUtil.class);
+
+ @ApiOperation(value = "生成验证码", notes = "生成验证码")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "successful request"),
+ @ApiResponse(code = 500, message = "internal server error")})
+ @RequestMapping(value = "/v1/getcode", method = RequestMethod.GET)
+ public void getCode(HttpServletResponse response, HttpServletRequest request) throws Exception {
+ HttpSession session = request.getSession();
+ //利用图片工具生成图片
+ //第一个参数是生成的验证码,第二个参数是生成的图片
+ Object[] objs = VerifyUtil.createImage();
+ //将验证码存入Session
+ session.setAttribute("imageCode", objs[0]);
+ System.out.println("接收前的session:" + session.getId());
+
+ //将图片输出给浏览器
+ BufferedImage image = (BufferedImage) objs[1];
+ response.setContentType("image/png");
+ OutputStream os = response.getOutputStream();
+ ImageIO.write(image, "png", os);
+ }
+}
diff --git a/src/main/java/com/library/nbt/controller/SortsController.java b/src/main/java/com/library/nbt/controller/SortsController.java
new file mode 100644
index 0000000000000000000000000000000000000000..6f840aaaf7ce6d99fd6c6410c26d05f960f20e80
--- /dev/null
+++ b/src/main/java/com/library/nbt/controller/SortsController.java
@@ -0,0 +1,110 @@
+//package com.library.nbt.controller;
+//
+//import com.library.nbt.model.view.UserEntityView;
+//import com.library.nbt.service.UserService;
+//import com.library.nbt.utils.Result;
+//import com.library.nbt.utils.ResultUtil;
+//import io.swagger.annotations.*;
+//import org.slf4j.Logger;
+//import org.slf4j.LoggerFactory;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.web.bind.annotation.*;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import javax.servlet.http.HttpServletResponse;
+//
+//@RestController
+//@RequestMapping(value = "/api")
+//@Api(value = "用户表接口", tags = "用户表接口", description = "")
+//public class SortsController {
+//
+// private static Logger LOG = LoggerFactory.getLogger(SortsController.class);
+//
+// @Autowired
+// private UserService userService;
+//
+// @Value("${db.url}")
+// private String url;
+//
+//
+// @ApiOperation(value = "通过ID获取单个用户表", notes = "通过id获取用户信息")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "successful request"),
+// @ApiResponse(code = 500, message = "internal server error")})
+// @RequestMapping(value = "/v1/user/select/{id}", method = RequestMethod.GET)
+// public Result> getEntity(@ApiParam(value = "用户ID", required = true) @PathVariable(value = "id") Integer id) {
+// try {
+// UserEntityView userEntityView = userService.getEntity(id);
+// return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userEntityView);
+// } catch (Exception e) {
+// return ResultUtil.error(ResultUtil.SUCCESS_CODE_200, e.getMessage());
+// }
+// }
+//
+// @ApiOperation(value = "进行插入新的一条用户信息", notes = "进行插入新的一条用户信息")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "successful request"),
+// @ApiResponse(code = 500, message = "internal server error")})
+// @RequestMapping(value = "/v1/user/insert", method = RequestMethod.POST)
+// public Result> saveEntity(@RequestBody UserEntityView userEntityView) {
+// try {
+// UserEntityView resultUserView = userService.saveEntity(userEntityView);
+// return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, resultUserView);
+// } catch (Exception e) {
+// return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
+// }
+// }
+//
+// @ApiOperation(value = "通过ID删除一条用户信息", notes = "通过ID删除一条用户信息")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "successful request"),
+// @ApiResponse(code = 500, message = "internal server error")})
+// @RequestMapping(value = "/v1/user/delete/{id}", method = RequestMethod.DELETE)
+// public Result> deleteEntity(@ApiParam(value = "用户ID", required = true) @PathVariable(value = "id") Integer id) {
+//
+// try {
+// userService.deleteEntity(id);
+// return ResultUtil.success();
+// } catch (Exception e) {
+// return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
+// }
+// }
+//
+// @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "successful request"),
+// @ApiResponse(code = 500, message = "internal server error")})
+// @RequestMapping(value = "/v1/user/update", method = RequestMethod.POST)
+// public Result> updateEntity(@RequestBody UserEntityView userEntityView) {
+// try {
+// userService.updateEntity(userEntityView);
+// return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userEntityView);
+// } catch (Exception e) {
+// return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
+// }
+// }
+//
+//
+// /**
+// * 登录
+// * @param userEntityView
+// * @param response
+// * @param request
+// * @return
+// */
+// @ApiOperation(value = "登录界面", notes = "通过账户密码验证码登录")
+// @ApiResponses(value = {
+// @ApiResponse(code = 200, message = "successful request"),
+// @ApiResponse(code = 500, message = "internal server error")})
+// @RequestMapping(value = "/v1/user/login", method = RequestMethod.POST)
+// public Result> userLogin(@RequestBody UserEntityView userEntityView, HttpServletResponse response, HttpServletRequest request) {
+// try {
+// UserEntityView userEntityViewResult = userService.checkUserLogin(userEntityView,request);
+// return ResultUtil.success(ResultUtil.SUCCESS_CODE_200,userEntityViewResult);
+// } catch (Exception e) {
+// return ResultUtil.error(ResultUtil.ERROR_CODE_500,e.getMessage());
+// }
+//
+// }
+//}
diff --git a/src/main/java/com/library/nbt/controller/UpFileController.java b/src/main/java/com/library/nbt/controller/UpFileController.java
new file mode 100644
index 0000000000000000000000000000000000000000..d3f06de33b729f1da29d2a94ee3e2af5b3ab2c73
--- /dev/null
+++ b/src/main/java/com/library/nbt/controller/UpFileController.java
@@ -0,0 +1,37 @@
+package com.library.nbt.controller;
+
+import com.library.nbt.service.UploadFileService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+
+@RestController
+@RequestMapping(value = "/api")
+@Api(value = "上传图片接口", tags = "上传图片接口", description = "")
+public class UpFileController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UpFileController.class);
+
+
+
+ @Autowired
+ private UploadFileService uploadFileService;
+
+ @ApiOperation(value = "上传图片接口", notes = "上传图片接口")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "successful request"),
+ @ApiResponse(code = 500, message = "internal server error")})
+ @RequestMapping(value = "/v1/upload", method = RequestMethod.POST)
+ @ResponseBody
+ public String upload(@RequestParam("test") MultipartFile file) {
+ String path = uploadFileService.getUploadFilePath(file);
+ return path;
+ }
+}
diff --git a/src/main/java/com/library/nbt/controller/UserController.java b/src/main/java/com/library/nbt/controller/UserController.java
index 74f4195c096e86688af1999ce9661750bc081c1d..dd32395fa2e670d9de6f3cfcb5aa175df131f8d6 100644
--- a/src/main/java/com/library/nbt/controller/UserController.java
+++ b/src/main/java/com/library/nbt/controller/UserController.java
@@ -5,6 +5,7 @@ import com.library.nbt.model.view.UserEntityView;
import com.library.nbt.service.UserService;
import com.library.nbt.utils.Result;
import com.library.nbt.utils.ResultUtil;
+import com.library.nbt.utils.VerifyUtil;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,7 +13,14 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.awt.image.BufferedImage;
+import java.io.OutputStream;
import java.util.List;
+import java.util.Map;
@RestController
@RequestMapping(value = "/api")
@@ -49,8 +57,8 @@ public class UserController {
@RequestMapping(value = "/v1/user/insert", method = RequestMethod.POST)
public Result> saveEntity(@RequestBody UserEntityView userEntityView) {
try {
- UserEntity resultUser = userService.saveEntity(userEntityView);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, resultUser);
+ UserEntityView resultUserView = userService.saveEntity(userEntityView);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, resultUserView);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
}
@@ -85,17 +93,26 @@ public class UserController {
}
}
- @ApiOperation(value = "获取所有用户", notes = "获取所有用户")
+
+ /**
+ * 登录
+ * @param userEntityView
+ * @param response
+ * @param request
+ * @return
+ */
+ @ApiOperation(value = "登录界面", notes = "通过账户密码验证码登录")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "successful request"),
@ApiResponse(code = 500, message = "internal server error")})
- @RequestMapping(value = "/v1/user/findAll", method = RequestMethod.POST)
- public Result> findAll() {
+ @RequestMapping(value = "/v1/user/login", method = RequestMethod.POST)
+ public Result> userLogin(@RequestBody UserEntityView userEntityView, HttpServletResponse response, HttpServletRequest request) {
try {
- List resultUser = userService.findAll();
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, resultUser);
+ UserEntityView userEntityViewResult = userService.checkUserLogin(userEntityView,request);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200,userEntityViewResult);
} catch (Exception e) {
- return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
+ return ResultUtil.error(ResultUtil.ERROR_CODE_500,e.getMessage());
}
+
}
}
diff --git a/src/main/java/com/library/nbt/controller/UserFriendsController.java b/src/main/java/com/library/nbt/controller/UserFriendsController.java
index 0802cff7e43d63d9cb8153f3d1c4eace59bef65a..41757b86c7b02fdaa397ff5a894c04ab5eef42bf 100644
--- a/src/main/java/com/library/nbt/controller/UserFriendsController.java
+++ b/src/main/java/com/library/nbt/controller/UserFriendsController.java
@@ -2,6 +2,7 @@ package com.library.nbt.controller;
import com.library.nbt.model.entity.UserEntity;
import com.library.nbt.model.entity.UserFriendsEntity;
+import com.library.nbt.model.view.UserFriendsEntityView;
import com.library.nbt.service.UserFriendsService;
import com.library.nbt.service.UserService;
import com.library.nbt.utils.Result;
@@ -30,8 +31,8 @@ public class UserFriendsController {
@RequestMapping(value = "/v1/user/friends/select/{id}", method = RequestMethod.GET)
public Result> getEntity(@ApiParam(value = "ID主键", required = true) @PathVariable(value = "id") Integer id) {
try {
- UserFriendsEntity userFriendsEntity = userFriendsService.getEntity(id);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntity);
+ UserFriendsEntityView userFriendsEntityView = userFriendsService.getEntity(id);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntityView);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.SUCCESS_CODE_200, e.getMessage());
}
@@ -42,10 +43,10 @@ public class UserFriendsController {
@ApiResponse(code = 200, message = "successful request"),
@ApiResponse(code = 500, message = "internal server error")})
@RequestMapping(value = "/v1/user/friends/insert", method = RequestMethod.POST)
- public Result> saveEntiy(@RequestBody UserFriendsEntity userFriendsEntity) {
+ public Result> saveEntiy(@RequestBody UserFriendsEntityView userFriendsEntityView) {
try {
- UserFriendsEntity userFriendsEntityResult = userFriendsService.saveEntity(userFriendsEntity);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntityResult);
+ UserFriendsEntityView userFriendsEntityViewResult = userFriendsService.saveEntity(userFriendsEntityView);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntityViewResult);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
}
@@ -70,10 +71,10 @@ public class UserFriendsController {
@ApiResponse(code = 200, message = "successful request"),
@ApiResponse(code = 500, message = "internal server error")})
@RequestMapping(value = "/v1/user/friends/update", method = RequestMethod.POST)
- public Result> update(@RequestBody UserFriendsEntity userFriendsEntity) {
+ public Result> update(@RequestBody UserFriendsEntityView userFriendsEntityView) {
try {
- userFriendsService.updateEntity(userFriendsEntity);
- return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntity);
+ userFriendsService.updateEntity(userFriendsEntityView);
+ return ResultUtil.success(ResultUtil.SUCCESS_CODE_200, userFriendsEntityView);
} catch (Exception e) {
return ResultUtil.error(ResultUtil.ERROR_CODE_500, e.getMessage());
}
diff --git a/src/main/java/com/library/nbt/dao/UplocalFileEntityMapper.java b/src/main/java/com/library/nbt/dao/UplocalFileEntityMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..3ad46eaf7e1370bbf0da6edce43bee86fc0a6b29
--- /dev/null
+++ b/src/main/java/com/library/nbt/dao/UplocalFileEntityMapper.java
@@ -0,0 +1,23 @@
+package com.library.nbt.dao;
+
+import com.library.nbt.model.entity.UplocalFileEntity;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface UplocalFileEntityMapper {
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method corresponds to the database table t_uplocal_file
+ *
+ * @mbggenerated
+ */
+ int insert(UplocalFileEntity record);
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method corresponds to the database table t_uplocal_file
+ *
+ * @mbggenerated
+ */
+ int insertSelective(UplocalFileEntity record);
+}
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/dao/UserEntityMapper.java b/src/main/java/com/library/nbt/dao/UserEntityMapper.java
index eb03831b552575255e61b9d8fac5b2ff2a109be7..a900c066e1501d1aed5fdbcd2bb69e2a8eb13073 100644
--- a/src/main/java/com/library/nbt/dao/UserEntityMapper.java
+++ b/src/main/java/com/library/nbt/dao/UserEntityMapper.java
@@ -20,4 +20,6 @@ public interface UserEntityMapper {
int updateByPrimaryKey(UserEntity record);
List findAll();
+
+ UserEntity selectByPrimaryUsername(UserEntity userEntity);
}
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/dao/mapper/UplocalFileEntityMapper.xml b/src/main/java/com/library/nbt/dao/mapper/UplocalFileEntityMapper.xml
new file mode 100644
index 0000000000000000000000000000000000000000..58aeb2a907133c18abd4dd905b195fcdeb81c3c9
--- /dev/null
+++ b/src/main/java/com/library/nbt/dao/mapper/UplocalFileEntityMapper.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SELECT LAST_INSERT_ID()
+
+ insert into t_uplocal_file (create_time, update_time, enabled,
+ profile_photo)
+ values (#{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{enabled,jdbcType=INTEGER},
+ #{profilePhoto,jdbcType=VARCHAR})
+
+
+
+
+ SELECT LAST_INSERT_ID()
+
+ insert into t_uplocal_file
+
+
+ create_time,
+
+
+ update_time,
+
+
+ enabled,
+
+
+ profile_photo,
+
+
+
+
+ #{createTime,jdbcType=BIGINT},
+
+
+ #{updateTime,jdbcType=BIGINT},
+
+
+ #{enabled,jdbcType=INTEGER},
+
+
+ #{profilePhoto,jdbcType=VARCHAR},
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml b/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml
index a7a5a57ca61102ecd00a2700f3a94d19b86489b9..23a4936b8395d65d5c3ca8c3e0415cc6f0f4c53a 100644
--- a/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml
+++ b/src/main/java/com/library/nbt/dao/mapper/UserEntityMapper.xml
@@ -179,7 +179,7 @@
where id = #{id,jdbcType=INTEGER}
-
+
update t_user
set create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT},
@@ -201,4 +201,11 @@
from t_user
+
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/model/entity/UplocalFileEntity.java b/src/main/java/com/library/nbt/model/entity/UplocalFileEntity.java
new file mode 100644
index 0000000000000000000000000000000000000000..0c480881b0b43c62299b13012560e34be70b4467
--- /dev/null
+++ b/src/main/java/com/library/nbt/model/entity/UplocalFileEntity.java
@@ -0,0 +1,163 @@
+package com.library.nbt.model.entity;
+
+public class UplocalFileEntity {
+ /**
+ * This field was generated by MyBatis Generator.
+ * This field corresponds to the database column t_uplocal_file.id
+ *
+ * @mbggenerated
+ */
+ private Integer id;
+
+ /**
+ * This field was generated by MyBatis Generator.
+ * This field corresponds to the database column t_uplocal_file.create_time
+ *
+ * @mbggenerated
+ */
+ private Long createTime;
+
+ /**
+ * This field was generated by MyBatis Generator.
+ * This field corresponds to the database column t_uplocal_file.update_time
+ *
+ * @mbggenerated
+ */
+ private Long updateTime;
+
+ /**
+ * This field was generated by MyBatis Generator.
+ * This field corresponds to the database column t_uplocal_file.enabled
+ *
+ * @mbggenerated
+ */
+ private Integer enabled;
+
+ /**
+ * This field was generated by MyBatis Generator.
+ * This field corresponds to the database column t_uplocal_file.profile_photo
+ *
+ * @mbggenerated
+ */
+ private String profilePhoto;
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method returns the value of the database column t_uplocal_file.id
+ *
+ * @return the value of t_uplocal_file.id
+ *
+ * @mbggenerated
+ */
+ public Integer getId() {
+ return id;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method sets the value of the database column t_uplocal_file.id
+ *
+ * @param id the value for t_uplocal_file.id
+ *
+ * @mbggenerated
+ */
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method returns the value of the database column t_uplocal_file.create_time
+ *
+ * @return the value of t_uplocal_file.create_time
+ *
+ * @mbggenerated
+ */
+ public Long getCreateTime() {
+ return createTime;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method sets the value of the database column t_uplocal_file.create_time
+ *
+ * @param createTime the value for t_uplocal_file.create_time
+ *
+ * @mbggenerated
+ */
+ public void setCreateTime(Long createTime) {
+ this.createTime = createTime;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method returns the value of the database column t_uplocal_file.update_time
+ *
+ * @return the value of t_uplocal_file.update_time
+ *
+ * @mbggenerated
+ */
+ public Long getUpdateTime() {
+ return updateTime;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method sets the value of the database column t_uplocal_file.update_time
+ *
+ * @param updateTime the value for t_uplocal_file.update_time
+ *
+ * @mbggenerated
+ */
+ public void setUpdateTime(Long updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method returns the value of the database column t_uplocal_file.enabled
+ *
+ * @return the value of t_uplocal_file.enabled
+ *
+ * @mbggenerated
+ */
+ public Integer getEnabled() {
+ return enabled;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method sets the value of the database column t_uplocal_file.enabled
+ *
+ * @param enabled the value for t_uplocal_file.enabled
+ *
+ * @mbggenerated
+ */
+ public void setEnabled(Integer enabled) {
+ this.enabled = enabled;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method returns the value of the database column t_uplocal_file.profile_photo
+ *
+ * @return the value of t_uplocal_file.profile_photo
+ *
+ * @mbggenerated
+ */
+ public String getProfilePhoto() {
+ return profilePhoto;
+ }
+
+ /**
+ * This method was generated by MyBatis Generator.
+ * This method sets the value of the database column t_uplocal_file.profile_photo
+ *
+ * @param profilePhoto the value for t_uplocal_file.profile_photo
+ *
+ * @mbggenerated
+ */
+ public void setProfilePhoto(String profilePhoto) {
+ this.profilePhoto = profilePhoto == null ? null : profilePhoto.trim();
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/library/nbt/model/view/UserEntityView.java b/src/main/java/com/library/nbt/model/view/UserEntityView.java
index 09a7fc045cd8cba9b70694d63ec58bcffcfbe08d..24e8b23b72f8b654bf99fd97212cde7967f11935 100644
--- a/src/main/java/com/library/nbt/model/view/UserEntityView.java
+++ b/src/main/java/com/library/nbt/model/view/UserEntityView.java
@@ -3,4 +3,13 @@ package com.library.nbt.model.view;
import com.library.nbt.model.entity.UserEntity;
public class UserEntityView extends UserEntity {
+ private String code;
+
+ public String getCode() {
+ return code;
+ }
+
+ public void setCode(String code) {
+ this.code = code;
+ }
}
diff --git a/src/main/java/com/library/nbt/service/ArticleService.java b/src/main/java/com/library/nbt/service/ArticleService.java
index 6ae20592825a3c7b4a4e5784c0d48f04679a9db7..af4426942f14ea594c86b5851ea7772565ba595f 100644
--- a/src/main/java/com/library/nbt/service/ArticleService.java
+++ b/src/main/java/com/library/nbt/service/ArticleService.java
@@ -1,6 +1,7 @@
package com.library.nbt.service;
import com.library.nbt.model.entity.ArticleEntity;
+import com.library.nbt.model.view.ArticleEntityView;
-public interface ArticleService extends BaseService {
+public interface ArticleService extends BaseService {
}
diff --git a/src/main/java/com/library/nbt/service/BaseService.java b/src/main/java/com/library/nbt/service/BaseService.java
index f1b9068929caf3d3e20e4430e3a11aca450cf339..a726ae3f749123839e821998a7bfc4a1c003042b 100644
--- a/src/main/java/com/library/nbt/service/BaseService.java
+++ b/src/main/java/com/library/nbt/service/BaseService.java
@@ -61,10 +61,4 @@ public interface BaseService {
*/
public long getEntitiesCount();
- /**
- * 查找所有记录数,数据量大谨慎使用
- *
- * @return the list
- */
- public List findAll();
}
diff --git a/src/main/java/com/library/nbt/service/UploadFileService.java b/src/main/java/com/library/nbt/service/UploadFileService.java
new file mode 100644
index 0000000000000000000000000000000000000000..2ee2373c6c0d374df0cc12c71e75229539631c71
--- /dev/null
+++ b/src/main/java/com/library/nbt/service/UploadFileService.java
@@ -0,0 +1,7 @@
+package com.library.nbt.service;
+
+import org.springframework.web.multipart.MultipartFile;
+
+public interface UploadFileService {
+ String getUploadFilePath(MultipartFile file);
+}
diff --git a/src/main/java/com/library/nbt/service/UserFriendsService.java b/src/main/java/com/library/nbt/service/UserFriendsService.java
index c2a50f309589cc1b2d61fc485daf043a488ed281..acee5d3d3e6aaa1fa29982423d72b35aa9993a68 100644
--- a/src/main/java/com/library/nbt/service/UserFriendsService.java
+++ b/src/main/java/com/library/nbt/service/UserFriendsService.java
@@ -1,7 +1,8 @@
package com.library.nbt.service;
import com.library.nbt.model.entity.UserFriendsEntity;
+import com.library.nbt.model.view.UserFriendsEntityView;
-public interface UserFriendsService extends BaseService{
+public interface UserFriendsService extends BaseService{
}
diff --git a/src/main/java/com/library/nbt/service/UserService.java b/src/main/java/com/library/nbt/service/UserService.java
index aac1d30fb2c1613bad23db87fe5606e43749a38c..2941947b6ed618aeffcc95dd825b7a88d37094bc 100644
--- a/src/main/java/com/library/nbt/service/UserService.java
+++ b/src/main/java/com/library/nbt/service/UserService.java
@@ -3,5 +3,9 @@ package com.library.nbt.service;
import com.library.nbt.model.entity.UserEntity;
import com.library.nbt.model.view.UserEntityView;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
public interface UserService extends BaseService{
+ UserEntityView checkUserLogin(UserEntityView userEntityView, HttpServletRequest request) throws Exception;
}
diff --git a/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java b/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java
index 233b926a05b5b06aa9ca40492c3276df6302665a..e41375fd32cb576506154a6b47c0c9dd710adca6 100644
--- a/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java
+++ b/src/main/java/com/library/nbt/service/impl/ArticleServiceImpl.java
@@ -2,9 +2,11 @@ package com.library.nbt.service.impl;
import com.library.nbt.dao.ArticleEntityMapper;
import com.library.nbt.model.entity.ArticleEntity;
+import com.library.nbt.model.view.ArticleEntityView;
import com.library.nbt.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
@@ -19,20 +21,23 @@ public class ArticleServiceImpl implements ArticleService {
@Autowired
private ArticleEntityMapper articleEntityMapper;
@Override
- public ArticleEntity saveEntity(ArticleEntity articleEntity) throws Exception {
+ public ArticleEntityView saveEntity(ArticleEntityView articleEntityView) throws Exception {
//发布文章需要后台管理员进行审核,审核通过将Enabled设置为1
- articleEntity.setCreateTime(System.currentTimeMillis());
- articleEntity.setUpdateTime(System.currentTimeMillis());
- articleEntity.setEnabled(0);
- articleEntity.setViews(0);
- articleEntity.setCommentCount(0);
+ articleEntityView.setCreateTime(System.currentTimeMillis());
+ articleEntityView.setUpdateTime(System.currentTimeMillis());
+ articleEntityView.setEnabled(0);
+ articleEntityView.setViews(0);
+ articleEntityView.setCommentCount(0);
+ ArticleEntity articleEntity = new ArticleEntity();
+ BeanUtils.copyProperties(articleEntityView,articleEntity);
Integer result = articleEntityMapper.insert(articleEntity);
LOG.info("article表插入了" + result + "条数据");
if (result == 0){
LOG.warn("article表插入数据失败,请联系管理员");
throw new Exception("插入数据失败,请联系管理员");
}
- return articleEntity;
+ BeanUtils.copyProperties(articleEntity,articleEntityView);
+ return articleEntityView;
}
@Override
@@ -46,27 +51,30 @@ public class ArticleServiceImpl implements ArticleService {
}
@Override
- public void updateEntity(ArticleEntity articleEntity) throws Exception {
- Integer result = articleEntityMapper.updateByPrimaryKey(articleEntity);
+ public void updateEntity(ArticleEntityView articleEntityView){
+ ArticleEntity articleEntity = new ArticleEntity();
+ BeanUtils.copyProperties(articleEntityView,articleEntity);
+ Integer result = articleEntityMapper.updateByPrimaryKeySelective(articleEntity);
LOG.info("article表更新了" + result + "条数据");
- if (result == 0){
- LOG.warn("article表更新数据失败,请联系管理员");
- throw new Exception("更新数据失败,请联系管理员");
- }
+ ArticleEntity articleEntityRulet = articleEntityMapper.selectByPrimaryKey(articleEntity.getId());
+ BeanUtils.copyProperties(articleEntityRulet,articleEntityView);
}
+
@Override
- public ArticleEntity getEntity(int id) throws Exception {
+ public ArticleEntityView getEntity(int id) throws Exception {
ArticleEntity articleEntity = articleEntityMapper.selectByPrimaryKey(id);
if (ObjectUtils.isEmpty(articleEntity)){
LOG.warn("article表查询数据失败,查询的数据ID是:" + id);
throw new Exception("查询数据失败,请联系管理员");
}
- return articleEntity;
+ ArticleEntityView articleEntityView = new ArticleEntityView();
+ BeanUtils.copyProperties(articleEntity,articleEntityView);
+ return articleEntityView;
}
@Override
- public Page getEntitiesByParms(ArticleEntity articleEntity, int currentPage, int pageSize) {
+ public Page getEntitiesByParms(ArticleEntityView articleEntityView, int currentPage, int pageSize) {
return null;
}
@@ -75,8 +83,5 @@ public class ArticleServiceImpl implements ArticleService {
return 0;
}
- @Override
- public List findAll() {
- return null;
- }
+
}
diff --git a/src/main/java/com/library/nbt/service/impl/UploadFileServiceImpl.java b/src/main/java/com/library/nbt/service/impl/UploadFileServiceImpl.java
new file mode 100644
index 0000000000000000000000000000000000000000..c944a8b3f92331e6ca80d5213014d583c6640cc4
--- /dev/null
+++ b/src/main/java/com/library/nbt/service/impl/UploadFileServiceImpl.java
@@ -0,0 +1,96 @@
+package com.library.nbt.service.impl;
+
+import com.library.nbt.dao.UplocalFileEntityMapper;
+import com.library.nbt.model.entity.UplocalFileEntity;
+import com.library.nbt.service.UploadFileService;
+import com.library.nbt.utils.DateUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.File;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Random;
+
+@Service
+public class UploadFileServiceImpl implements UploadFileService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UploadFileServiceImpl.class);
+ //图片存放根路径
+ @Value("${file.rootPath}")
+ private String ROOT_PATH;
+ //图片存放根目录下的子目录
+ @Value("${file.sonPath}")
+ private String SON_PATH;
+
+ @Value("${server.port}")
+ //获取主机端口
+ private String POST;
+
+ @Autowired
+ private UplocalFileEntityMapper uplocalFileEntityMapper;
+
+
+ @Override
+ public String getUploadFilePath(MultipartFile file) {
+ //返回上传的文件是否为空,即没有选择任何文件,或者所选文件没有内容。
+ //防止上传空文件导致奔溃
+ if (file.isEmpty()) {
+ throw new NullPointerException("文件为空");
+ }
+ // 设置文件上传后的路径
+ String filePath = ROOT_PATH + SON_PATH;
+ // 获取文件名后缀名
+ String suffix = file.getOriginalFilename();
+ String prefix = suffix.substring(suffix.lastIndexOf(".")+1);
+ //为防止文件重名被覆盖,文件名取名为:当前日期 + 1-1000内随机数
+ Random random = new Random();
+ Integer randomFileName = random.nextInt(1000);
+ String fileName = DateUtils.timeStamp2Date(String.valueOf(System.currentTimeMillis() /100),"yyyyMMddHHmmss") + randomFileName +"." + prefix;
+ //创建文件路径
+ File dest = new File(filePath + fileName);
+ // 解决中文问题,liunx下中文路径,图片显示问题
+ // fileName = UUID.randomUUID() + suffixName;
+ // 检测是否存在目录
+ if (!dest.getParentFile().exists()) {
+ //假如文件不存在即重新创建新的文件已防止异常发生
+ dest.getParentFile().mkdirs();
+ }
+ try {
+ //transferTo(dest)方法将上传文件写到服务器上指定的文件
+ file.transferTo(dest);
+ //保存t_upload_file表中
+ String filePathNew = SON_PATH + fileName;
+ String profilePhoto = saveUploadFile(filePathNew);
+ System.out.println(profilePhoto);
+ return profilePhoto;
+ } catch (Exception e) {
+ return dest.toString();
+ }
+ }
+
+ private String saveUploadFile(String filePathNew) {
+ //获取本机IP
+ String host = null;
+ try {
+ host = InetAddress.getLocalHost().getHostAddress();
+ } catch (UnknownHostException e) {
+ LOG.error("get server host Exception e:", e);
+ }
+ UplocalFileEntity uplocalFileEntity = new UplocalFileEntity();
+ uplocalFileEntity.setCreateTime(System.currentTimeMillis());
+ uplocalFileEntity.setUpdateTime(System.currentTimeMillis());
+ uplocalFileEntity.setEnabled(1);
+ uplocalFileEntity.setProfilePhoto(host + ":" + POST + filePathNew);
+
+ Integer result = uplocalFileEntityMapper.insertSelective(uplocalFileEntity);
+ System.out.println("插入了" + result + "数据");
+
+ System.out.println("uplocalFileEntity.getProfilePhoto():" + uplocalFileEntity.getProfilePhoto());
+ return uplocalFileEntity.getProfilePhoto();
+ }
+}
diff --git a/src/main/java/com/library/nbt/service/impl/UserFriendsServiceImpl.java b/src/main/java/com/library/nbt/service/impl/UserFriendsServiceImpl.java
index b26e51942e643016cbc4c54ee4823b925abb282a..f91f6b70be1ff9bfe0b52145b67dd6bc52a18bf4 100644
--- a/src/main/java/com/library/nbt/service/impl/UserFriendsServiceImpl.java
+++ b/src/main/java/com/library/nbt/service/impl/UserFriendsServiceImpl.java
@@ -4,16 +4,21 @@ import com.library.nbt.dao.UserEntityMapper;
import com.library.nbt.dao.UserFriendsEntityMapper;
import com.library.nbt.model.entity.UserEntity;
import com.library.nbt.model.entity.UserFriendsEntity;
+import com.library.nbt.model.view.UserEntityView;
+import com.library.nbt.model.view.UserFriendsEntityView;
import com.library.nbt.service.UserFriendsService;
import com.library.nbt.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
@Service
public class UserFriendsServiceImpl implements UserFriendsService {
@@ -24,18 +29,20 @@ public class UserFriendsServiceImpl implements UserFriendsService {
private UserFriendsEntityMapper userFriendsEntityMapper;
@Override
- public UserFriendsEntity saveEntity(UserFriendsEntity userFriendsEntity) throws Exception {
-
- userFriendsEntity.setCreateTime(System.currentTimeMillis());
- userFriendsEntity.setUpdateTime(System.currentTimeMillis());
- userFriendsEntity.setEnabled(1);
+ public UserFriendsEntityView saveEntity(UserFriendsEntityView userFriendsEntityView) throws Exception {
+ userFriendsEntityView.setCreateTime(System.currentTimeMillis());
+ userFriendsEntityView.setUpdateTime(System.currentTimeMillis());
+ userFriendsEntityView.setEnabled(1);
+ UserFriendsEntity userFriendsEntity = new UserFriendsEntity();
+ BeanUtils.copyProperties(userFriendsEntityView,userFriendsEntity);
Integer result = userFriendsEntityMapper.insertSelective(userFriendsEntity);
LOG.info("在t_user表中插入了:" + result + "条信息");
if (result == 0){
throw new Exception("新增用户失败,请联系管理员");
}
- return userFriendsEntity;
+ BeanUtils.copyProperties(userFriendsEntity,userFriendsEntityView);
+ return userFriendsEntityView;
}
@Override
@@ -49,32 +56,29 @@ public class UserFriendsServiceImpl implements UserFriendsService {
}
@Override
- public void updateEntity(UserFriendsEntity userFriendsEntity) throws Exception {
- if (userFriendsEntity.getCreateTime() == 0){
- userFriendsEntity.setCreateTime(System.currentTimeMillis());
- }
- if (userFriendsEntity.getUpdateTime() == 0){
- userFriendsEntity.setUpdateTime(System.currentTimeMillis());
- }
- Integer result = userFriendsEntityMapper.updateByPrimaryKey(userFriendsEntity);
+ public void updateEntity(UserFriendsEntityView userFriendsEntityView) throws Exception {
+ UserFriendsEntity userFriendsEntity = new UserFriendsEntity();
+ BeanUtils.copyProperties(userFriendsEntityView,userFriendsEntity);
+ Integer result = userFriendsEntityMapper.updateByPrimaryKeySelective(userFriendsEntity);
LOG.info("userFriends更新的数据条数为:" + result);
- if (result == 0){
- throw new Exception("更新失败,请联系管理员");
- }
+ UserFriendsEntity userFriendsEntityRulet = userFriendsEntityMapper.selectByPrimaryKey(userFriendsEntity.getId());
+ BeanUtils.copyProperties(userFriendsEntityRulet,userFriendsEntityView);
}
@Override
- public UserFriendsEntity getEntity(int id) throws Exception {
+ public UserFriendsEntityView getEntity(int id) throws Exception {
UserFriendsEntity userFriendsEntity = userFriendsEntityMapper.selectByPrimaryKey(id);
if (ObjectUtils.isEmpty(userFriendsEntity)){
LOG.info("找不到user_iD为:" + id + "的数据记录");
throw new Exception("查无此用户");
}
- return userFriendsEntity;
+ UserFriendsEntityView userFriendsEntityView = new UserFriendsEntityView();
+ BeanUtils.copyProperties(userFriendsEntity,userFriendsEntityView);
+ return userFriendsEntityView;
}
@Override
- public Page getEntitiesByParms(UserFriendsEntity userFriendsEntity, int currentPage, int pageSize) {
+ public Page getEntitiesByParms(UserFriendsEntityView userFriendsEntityView, int currentPage, int pageSize) {
return null;
}
@@ -83,9 +87,5 @@ public class UserFriendsServiceImpl implements UserFriendsService {
return 0;
}
- @Override
- public List findAll() {
- List userEntities = userFriendsEntityMapper.findAll();
- return userEntities;
- }
+
}
diff --git a/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java b/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java
index 6e267e68762da9cad912cccc20f0075fe1608ab4..2c9cbfabe2c702b8daab89f31bfd87ad3c6ee43c 100644
--- a/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java
+++ b/src/main/java/com/library/nbt/service/impl/UserServiceImpl.java
@@ -1,9 +1,14 @@
package com.library.nbt.service.impl;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.bean.copier.CopyOptions;
+import com.alibaba.fastjson.JSON;
import com.library.nbt.dao.UserEntityMapper;
import com.library.nbt.model.entity.UserEntity;
import com.library.nbt.model.view.UserEntityView;
import com.library.nbt.service.UserService;
+import com.library.nbt.utils.CusAccessObjectUtil;
+import com.library.nbt.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -12,8 +17,11 @@ import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
@Service
public class UserServiceImpl implements UserService {
@@ -26,7 +34,7 @@ public class UserServiceImpl implements UserService {
@Override
public UserEntityView saveEntity(UserEntityView userEntityView) throws Exception {
UserEntity userEntity = new UserEntity();
- BeanUtils.copyProperties(userEntity,userEntityView);
+ BeanUtils.copyProperties(userEntityView,userEntity);
userEntity.setCreateTime(System.currentTimeMillis());
userEntity.setUpdateTime(System.currentTimeMillis());
@@ -41,7 +49,7 @@ public class UserServiceImpl implements UserService {
if (result == 0){
throw new Exception("新增用户失败,请联系管理员");
}
- BeanUtils.copyProperties(userEntityView,userEntity);
+ BeanUtils.copyProperties(userEntity,userEntityView);
return userEntityView;
}
@@ -56,21 +64,13 @@ public class UserServiceImpl implements UserService {
}
@Override
- public void updateEntity(UserEntityView userEntityView) throws Exception {
+ public void updateEntity(UserEntityView userEntityView){
UserEntity userEntity = new UserEntity();
- BeanUtils.copyProperties(userEntity,userEntityView);
-
- if (userEntity.getCreateTime() == 0){
- userEntity.setCreateTime(System.currentTimeMillis());
- }
- userEntity.setUpdateTime(System.currentTimeMillis());
- Integer userResult = userEntityMapper.updateByPrimaryKey(userEntity);
- if (userResult == 0){
- LOG.info("找不到user_iD为:" + userEntity.getId() + "的数据记录");
- throw new Exception("更新失败,请联系管理员");
- }
- LOG.info("user表更新的数据条数为:" + userResult);
BeanUtils.copyProperties(userEntityView,userEntity);
+ Integer userResult = userEntityMapper.updateByPrimaryKeySelective(userEntity);
+ LOG.info("user表更新的数据条数为:" + userResult);
+ UserEntity userEntityRulet = userEntityMapper.selectByPrimaryKey(userEntity.getId());
+ BeanUtils.copyProperties(userEntityRulet,userEntityView);
}
@Override
@@ -81,7 +81,7 @@ public class UserServiceImpl implements UserService {
throw new Exception("查无此用户");
}
UserEntityView userEntityView = new UserEntityView();
- BeanUtils.copyProperties(userEntityView,userEntity);
+ BeanUtils.copyProperties(userEntity,userEntityView);
return userEntityView;
}
@@ -96,11 +96,36 @@ public class UserServiceImpl implements UserService {
}
@Override
- public List findAll() {
- List userEntities = userEntityMapper.findAll();
- List userEntityView = new ArrayList<>();
-
- BeanUtils.copyProperties(userEntityView,userEntities);
- return userEntityView;
+ public UserEntityView checkUserLogin(UserEntityView userEntityView, HttpServletRequest request) throws Exception {
+ //校验验证码
+ HttpSession session = request.getSession();
+ System.out.println("接收后的session:" + session.getId());
+ System.out.println(session);
+ System.out.println(session.getAttribute("imageCode"));
+ if (session.getAttribute("imageCode") == null) {
+ throw new NullPointerException("重新获取验证码");
+ }
+ //验证码与seesion中的验证码一样再查询数据
+ if (session.getAttribute("imageCode").toString().equalsIgnoreCase(userEntityView.getCode())) {
+ UserEntity userEntity = new UserEntity();
+ BeanUtils.copyProperties(userEntityView,userEntity);
+ UserEntity userEntityResult = userEntityMapper.selectByPrimaryUsername(userEntity);
+ if (ObjectUtils.isEmpty(userEntityResult)){
+ throw new NullPointerException("账户不存在或密码错误");
+ }
+ //记录登录时间
+ userEntityResult.setLoginEndTime(System.currentTimeMillis());
+ //记录用户所在ip
+ String ip = CusAccessObjectUtil.getIpAddress(request);
+ userEntityResult.setIp(ip);
+ //分配默认头像
+// userEntityResult.setProfilePhoto();
+ Integer result = userEntityMapper.updateByPrimaryKeySelective(userEntityResult);
+ LOG.info("user表更新了" + result + "条数据");
+ BeanUtils.copyProperties(userEntityResult,userEntityView);
+ return userEntityView;
+ }else {
+ throw new Exception("验证码错误");
+ }
}
}
diff --git a/src/main/java/com/library/nbt/utils/CusAccessObjectUtil.java b/src/main/java/com/library/nbt/utils/CusAccessObjectUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..318d247c43c13d3a85fe830956ab4b6ef3f498db
--- /dev/null
+++ b/src/main/java/com/library/nbt/utils/CusAccessObjectUtil.java
@@ -0,0 +1,46 @@
+package com.library.nbt.utils;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * 自定义访问对象工具类
+ *
+ * 获取对象的IP地址等信息
+ * @author X-rapido
+ *
+ */
+public class CusAccessObjectUtil {
+ /**
+ * 获取用户真实IP地址,不使用request.getRemoteAddr();的原因是有可能用户使用了代理软件方式避免真实IP地址,
+ *
+ * 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢?
+ * 答案是取X-Forwarded-For中第一个非unknown的有效IP字符串。
+ *
+ * 如:X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130,
+ * 192.168.1.100
+ *
+ * 用户真实IP为: 192.168.1.110
+ *
+ * @param request
+ * @return
+ */
+ public static String getIpAddress(HttpServletRequest request) {
+ String ip = request.getHeader("x-forwarded-for");
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ return ip;
+ }
+}
diff --git a/src/main/java/com/library/nbt/utils/RandomValidateCodeUtil.java b/src/main/java/com/library/nbt/utils/RandomValidateCodeUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..4e627221fb94facc22ee0175bc0de7de757e67cf
--- /dev/null
+++ b/src/main/java/com/library/nbt/utils/RandomValidateCodeUtil.java
@@ -0,0 +1,116 @@
+package com.library.nbt.utils;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.util.Random;
+
+public class RandomValidateCodeUtil {
+ public static final String RANDOMCODEKEY= "RANDOMVALIDATECODEKEY";//放到session中的key
+ private String randString = "0123456789";//随机产生只有数字的字符串 private String
+ //private String randString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生只有字母的字符串
+ //private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
+ private int width = 95;// 图片宽
+ private int height = 25;// 图片高
+ private int lineSize = 40;// 干扰线数量
+ private int stringNum = 4;// 随机产生字符数量
+
+ private static final Logger LOG = LoggerFactory.getLogger(RandomValidateCodeUtil.class);
+
+ private Random random = new Random();
+
+ /**
+ * 获得字体
+ */
+ private Font getFont() {
+ return new Font("Fixedsys", Font.CENTER_BASELINE, 18);
+ }
+
+ /**
+ * 获得颜色
+ */
+ private Color getRandColor(int fc, int bc) {
+ if (fc > 255)
+ fc = 255;
+ if (bc > 255)
+ bc = 255;
+ int r = fc + random.nextInt(bc - fc - 16);
+ int g = fc + random.nextInt(bc - fc - 14);
+ int b = fc + random.nextInt(bc - fc - 18);
+ return new Color(r, g, b);
+ }
+
+ /**
+ * 生成随机图片
+ */
+ public void getRandcode(HttpServletRequest request, HttpServletResponse response) {
+ HttpSession session = request.getSession();
+ // BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);
+ Graphics g = image.getGraphics();// 产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
+ g.fillRect(0, 0, width, height);//图片大小
+ g.setFont(new Font("Times New Roman", Font.ROMAN_BASELINE, 18));//字体大小
+ g.setColor(getRandColor(110, 133));//字体颜色
+ // 绘制干扰线
+ for (int i = 0; i <= lineSize; i++) {
+ drowLine(g);
+ }
+ // 绘制随机字符
+ String randomString = "";
+ for (int i = 1; i <= stringNum; i++) {
+ randomString = drowString(g, randomString, i);
+ }
+ LOG.info(randomString);
+ //将生成的随机字符串保存到session中
+ session.removeAttribute(RANDOMCODEKEY);
+ session.setAttribute(RANDOMCODEKEY, randomString);
+ g.dispose();
+ try {
+ // 将内存中的图片通过流动形式输出到客户端
+ ImageIO.write(image, "JPEG", response.getOutputStream());
+ } catch (Exception e) {
+ LOG.error("将内存中的图片通过流动形式输出到客户端失败>>>> ", e);
+ }
+
+ }
+
+ /**
+ * 绘制字符串
+ */
+ private String drowString(Graphics g, String randomString, int i) {
+ g.setFont(getFont());
+ g.setColor(new Color(random.nextInt(101), random.nextInt(111), random
+ .nextInt(121)));
+ String rand = String.valueOf(getRandomString(random.nextInt(randString
+ .length())));
+ randomString += rand;
+ g.translate(random.nextInt(3), random.nextInt(3));
+ g.drawString(rand, 13 * i, 16);
+ return randomString;
+ }
+
+ /**
+ * 绘制干扰线
+ */
+ private void drowLine(Graphics g) {
+ int x = random.nextInt(width);
+ int y = random.nextInt(height);
+ int xl = random.nextInt(13);
+ int yl = random.nextInt(15);
+ g.drawLine(x, y, x + xl, y + yl);
+ }
+
+ /**
+ * 获取随机的字符
+ */
+ public String getRandomString(int num) {
+ return String.valueOf(randString.charAt(num));
+ }
+
+}
diff --git a/src/main/java/com/library/nbt/utils/VerifyUtil.java b/src/main/java/com/library/nbt/utils/VerifyUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..087934055bbf60f8d067a1e36f2bd0b2810d7406
--- /dev/null
+++ b/src/main/java/com/library/nbt/utils/VerifyUtil.java
@@ -0,0 +1,80 @@
+package com.library.nbt.utils;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.util.Random;
+
+public class VerifyUtil {
+ // 验证码字符集
+ private static final char[] chars = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
+ 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
+ // 字符数量
+ private static final int SIZE = 4;
+ // 干扰线数量
+ private static final int LINES = 5;
+ // 宽度
+ private static final int WIDTH = 80;
+ // 高度
+ private static final int HEIGHT = 40;
+ // 字体大小
+ private static final int FONT_SIZE = 30;
+
+ /**
+ * 生成随机验证码及图片
+ * Object[0]:验证码字符串;
+ * Object[1]:验证码图片。
+ */
+ public static Object[] createImage() {
+ StringBuffer sb = new StringBuffer();
+ // 1.创建空白图片
+ BufferedImage image = new BufferedImage(
+ WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
+ // 2.获取图片画笔
+ Graphics graphic = image.getGraphics();
+ // 3.设置画笔颜色
+ graphic.setColor(Color.LIGHT_GRAY);
+ // 4.绘制矩形背景
+ graphic.fillRect(0, 0, WIDTH, HEIGHT);
+ // 5.画随机字符
+ Random ran = new Random();
+ for (int i = 0; i
+
+
+
+ /btn/logs/btn-dev.log
+
+ /btn/btn_prd/btn.%d{yyyy-MM-dd}.%i.log.zip
+
+ 30
+
+
+
+
+ 10 MB
+
+
+
+ %date %level [%thread] %logger{10} [%file:%line] %msg%n
+ UTF-8
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/log/local/logback.xml b/src/main/resources/log/local/logback.xml
new file mode 100644
index 0000000000000000000000000000000000000000..3db1484921860895bd96d1af9615d493b072c2bb
--- /dev/null
+++ b/src/main/resources/log/local/logback.xml
@@ -0,0 +1,38 @@
+
+
+
+
+ /btn/logs/btn-local.log
+
+ /btn/btn_prd/btn.%d{yyyy-MM-dd}.%i.log.zip
+
+ 30
+
+
+
+
+ 10 MB
+
+
+
+ %date %level [%thread] %logger{10} [%file:%line] %msg%n
+ UTF-8
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/resources/log/prod/logback.xml b/src/main/resources/log/prod/logback.xml
new file mode 100644
index 0000000000000000000000000000000000000000..35fa57bb11f5e36f01e84573f9fc98c5983a1705
--- /dev/null
+++ b/src/main/resources/log/prod/logback.xml
@@ -0,0 +1,38 @@
+
+
+
+
+ /btn/logs/btn-prod.log
+
+ /btn/btn_prd/btn.%d{yyyy-MM-dd}.%i.log.zip
+
+ 30
+
+
+
+
+ 10 MB
+
+
+
+ %date %level [%thread] %logger{10} [%file:%line] %msg%n
+ UTF-8
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+