From 67546e6cc983cfa6bde8b725a7dfb39358f1c4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 19 Jul 2020 20:24:57 +0800 Subject: [PATCH 01/70] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=80=83=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/juzi/oerp/controller/user/ExamController.java | 5 +++-- src/main/java/com/juzi/oerp/service/ExamService.java | 5 +++-- .../java/com/juzi/oerp/service/impl/ExamServiceImpl.java | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/user/ExamController.java b/src/main/java/com/juzi/oerp/controller/user/ExamController.java index 0fd02fb..97e54e0 100644 --- a/src/main/java/com/juzi/oerp/controller/user/ExamController.java +++ b/src/main/java/com/juzi/oerp/controller/user/ExamController.java @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -38,8 +39,8 @@ public class ExamController { */ @GetMapping @ApiOperation("获取考试简要信息") - public ResponseVO> getExamPlainInfoByPage(PageParamDTO pageParamDTO) { - IPage result = examService.getExamPlainInfoByPage(pageParamDTO); + public ResponseVO> getExamPlainInfoByPage(PageParamDTO pageParamDTO, @ApiParam("搜索关键字") @RequestParam(required = false) String keyword) { + IPage result = examService.getExamPlainInfoByPage(pageParamDTO,keyword); return new ResponseVO<>(result); } diff --git a/src/main/java/com/juzi/oerp/service/ExamService.java b/src/main/java/com/juzi/oerp/service/ExamService.java index 511f6e2..c63a183 100644 --- a/src/main/java/com/juzi/oerp/service/ExamService.java +++ b/src/main/java/com/juzi/oerp/service/ExamService.java @@ -5,7 +5,6 @@ import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.ExamApplyInfoVO; -import org.apache.ibatis.annotations.Param; /** *

@@ -20,9 +19,10 @@ public interface ExamService extends IService { * 获取考试简要信息_分页 * * @param pageParamDTO 分页参数 + * @param keyword 搜索关键字 * @return 考试简要信息 */ - IPage getExamPlainInfoByPage(@Param("pageParamDTO") PageParamDTO pageParamDTO); + IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO, String keyword); /** * 获取考试详细信息 @@ -34,6 +34,7 @@ public interface ExamService extends IService { /** * 获取考试报名信息 + * * @param examId 考试id * @return 考试报名信息 */ diff --git a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java index 28140c7..f8a5d68 100644 --- a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java @@ -16,6 +16,7 @@ import com.juzi.oerp.service.ExamService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import java.time.LocalDateTime; import java.util.List; @@ -41,10 +42,11 @@ public class ExamServiceImpl extends ServiceImpl implements private ExamDAO examDAO; @Override - public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO) { + public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO, String keyword) { IPage page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .select(ExamPO::getTitle, ExamPO::getImageUrl, ExamPO::getDescription, ExamPO::getId) + .like(!StringUtils.isEmpty(keyword), ExamPO::getTitle, keyword) .orderByDesc(ExamPO::getCreateTime); return examMapper.selectPage(page, queryWrapper); } From 5127c289907dbb1e6aa421468874c81af194ea83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 19 Jul 2020 20:44:24 +0800 Subject: [PATCH 02/70] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthenticationController.java | 41 ++++-------- ...oginDTO.java => UserPasswordLoginDTO.java} | 2 +- .../juzi/oerp/model/dto/UserSMSLoginDTO.java | 19 ++++++ .../oerp/service/AuthenticationService.java | 21 +++++-- .../impl/AuthenticationServiceImpl.java | 62 ++++++++++++++----- 5 files changed, 94 insertions(+), 51 deletions(-) rename src/main/java/com/juzi/oerp/model/dto/{UserLoginDTO.java => UserPasswordLoginDTO.java} (92%) create mode 100644 src/main/java/com/juzi/oerp/model/dto/UserSMSLoginDTO.java diff --git a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java index d3ab0db..2a185da 100644 --- a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java +++ b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java @@ -1,10 +1,11 @@ package com.juzi.oerp.controller; import com.fasterxml.jackson.core.JsonProcessingException; +import com.juzi.oerp.model.dto.UserPasswordLoginDTO; +import com.juzi.oerp.model.dto.UserRegistionDTO; +import com.juzi.oerp.model.dto.UserSMSLoginDTO; import com.juzi.oerp.model.dto.param.CheckImageCaptchaParamDTO; import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; -import com.juzi.oerp.model.dto.UserLoginDTO; -import com.juzi.oerp.model.dto.UserRegistionDTO; import com.juzi.oerp.model.vo.CaptchaVO; import com.juzi.oerp.model.vo.UserLoginVO; import com.juzi.oerp.model.vo.response.CreateResponseVO; @@ -31,19 +32,20 @@ public class AuthenticationController { @Autowired private AuthenticationService authenticationService; - /** - * 用户登录 - */ @PostMapping("/login") - @ApiOperation(value = "登录",notes = "用户和管理员均使用此接口登录") - public ResponseVO login(@RequestBody UserLoginDTO userLoginDTO) { - UserLoginVO result = authenticationService.login(userLoginDTO); + @ApiOperation(value = "密码登录") + public ResponseVO loginByPassword(@RequestBody UserPasswordLoginDTO userPasswordLoginDTO) { + UserLoginVO result = authenticationService.loginByPassword(userPasswordLoginDTO); + return new ResponseVO<>(result); + } + + @PostMapping("/loginByPassword/sms") + @ApiOperation(value = "短信登录") + public ResponseVO loginBySMS(@RequestBody UserSMSLoginDTO userSMSLoginDTO) { + UserLoginVO result = authenticationService.loginBySMS(userSMSLoginDTO); return new ResponseVO<>(result); } - /** - * 用户注册 - */ @PostMapping("/registion") @ApiOperation("注册") public ResponseVO registion(UserRegistionDTO userRegistionDTO) { @@ -51,11 +53,6 @@ public ResponseVO registion(UserRegistionDTO userRegistionDTO) { return new ResponseVO<>(result); } - /** - * 获取图片验证码 - * - * @return 图片验证码信息 - */ @GetMapping("/captcha/image") @ApiOperation("获取图片验证码") public ResponseVO getImageCaptcha() { @@ -63,11 +60,6 @@ public ResponseVO getImageCaptcha() { return new ResponseVO<>(captcha); } - /** - * 校验图片验证码 - * @param checkImageCaptchaParamDTO 校验验证码参数 - * @return 校验成功 - */ @PostMapping("/captcha/image") @ApiOperation("校验图片验证码") public ResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamDTO checkImageCaptchaParamDTO) { @@ -75,13 +67,6 @@ public ResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamD return new CreateResponseVO(); } - /** - * 获取短信验证码 - * - * @param smsCaptchaParamDTO 短信验证码参数 - * @return 发送成功信息 - * @throws JsonProcessingException 发送短信验证码时转换 JSON 异常 - */ @GetMapping("/captcha/sms") @ApiOperation("获取短信验证码") public ResponseVO getSMSCaptcha(@RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { diff --git a/src/main/java/com/juzi/oerp/model/dto/UserLoginDTO.java b/src/main/java/com/juzi/oerp/model/dto/UserPasswordLoginDTO.java similarity index 92% rename from src/main/java/com/juzi/oerp/model/dto/UserLoginDTO.java rename to src/main/java/com/juzi/oerp/model/dto/UserPasswordLoginDTO.java index 8ecaf9e..6a74e84 100644 --- a/src/main/java/com/juzi/oerp/model/dto/UserLoginDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/UserPasswordLoginDTO.java @@ -12,7 +12,7 @@ @Data @Accessors(chain = true) @ApiModel(description = "登录参数") -public class UserLoginDTO { +public class UserPasswordLoginDTO { @ApiModelProperty("账号") private String username; diff --git a/src/main/java/com/juzi/oerp/model/dto/UserSMSLoginDTO.java b/src/main/java/com/juzi/oerp/model/dto/UserSMSLoginDTO.java new file mode 100644 index 0000000..2a318fa --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/dto/UserSMSLoginDTO.java @@ -0,0 +1,19 @@ +package com.juzi.oerp.model.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author Juzi + * @date 2020/7/19 20:34 + */ +@Data +@ApiModel(description = "短信登录参数") +public class UserSMSLoginDTO { + @ApiModelProperty("手机号") + private String phoneNumber; + + @ApiModelProperty("验证码") + private String captcha; +} diff --git a/src/main/java/com/juzi/oerp/service/AuthenticationService.java b/src/main/java/com/juzi/oerp/service/AuthenticationService.java index 061a106..eaa8f1e 100644 --- a/src/main/java/com/juzi/oerp/service/AuthenticationService.java +++ b/src/main/java/com/juzi/oerp/service/AuthenticationService.java @@ -1,11 +1,12 @@ package com.juzi.oerp.service; import com.fasterxml.jackson.core.JsonProcessingException; +import com.juzi.oerp.model.dto.UserPasswordLoginDTO; +import com.juzi.oerp.model.dto.UserRegistionDTO; +import com.juzi.oerp.model.dto.UserSMSLoginDTO; import com.juzi.oerp.model.dto.param.CheckImageCaptchaParamDTO; import com.juzi.oerp.model.dto.param.CheckSMSCaptchaParamDTO; import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; -import com.juzi.oerp.model.dto.UserLoginDTO; -import com.juzi.oerp.model.dto.UserRegistionDTO; import com.juzi.oerp.model.vo.CaptchaVO; import com.juzi.oerp.model.vo.UserLoginVO; @@ -18,12 +19,20 @@ public interface AuthenticationService { /** - * 用户登录 + * 密码登录 * - * @param userLoginDTO 登录参数 + * @param userPasswordLoginDTO 密码登录参数 * @return token 和用户信息 */ - UserLoginVO login(UserLoginDTO userLoginDTO); + UserLoginVO loginByPassword(UserPasswordLoginDTO userPasswordLoginDTO); + + /** + * 短信登录 + * + * @param userSMSLoginDTO 短信登录参数 + * @return token 和用户信息 + */ + UserLoginVO loginBySMS(UserSMSLoginDTO userSMSLoginDTO); /** * 用户注册 @@ -41,6 +50,7 @@ public interface AuthenticationService { /** * 校验图片验证码 + * * @param checkImageCaptchaParamDTO 校验图片验证码参数 */ void checkImageCaptcha(CheckImageCaptchaParamDTO checkImageCaptchaParamDTO); @@ -55,6 +65,7 @@ public interface AuthenticationService { /** * 校验短信验证码 + * * @param checkSMSCaptchaParamDTO 校验短信验证码参数 */ void checkSMSCaptcha(CheckSMSCaptchaParamDTO checkSMSCaptchaParamDTO); diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index 5593b39..58f673c 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -20,8 +20,9 @@ import com.juzi.oerp.common.exception.CaptchaException; import com.juzi.oerp.mapper.UserInfoMapper; import com.juzi.oerp.mapper.UserMapper; -import com.juzi.oerp.model.dto.UserLoginDTO; +import com.juzi.oerp.model.dto.UserPasswordLoginDTO; import com.juzi.oerp.model.dto.UserRegistionDTO; +import com.juzi.oerp.model.dto.UserSMSLoginDTO; import com.juzi.oerp.model.dto.param.CheckImageCaptchaParamDTO; import com.juzi.oerp.model.dto.param.CheckSMSCaptchaParamDTO; import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; @@ -30,12 +31,10 @@ import com.juzi.oerp.model.vo.CaptchaVO; import com.juzi.oerp.model.vo.UserLoginVO; import com.juzi.oerp.service.AuthenticationService; -import com.juzi.oerp.util.CacheUtils; import com.juzi.oerp.util.JWTUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @@ -69,11 +68,11 @@ public class AuthenticationServiceImpl implements AuthenticationService { private Cache imageCaptchaCache; @Override - public UserLoginVO login(UserLoginDTO userLoginDTO) { + public UserLoginVO loginByPassword(UserPasswordLoginDTO userPasswordLoginDTO) { UserPO userPO = new UserPO(); userPO - .setUsername(userLoginDTO.getUsername()) - .setPassword(SecureUtil.md5(userLoginDTO.getPassword())); + .setUsername(userPasswordLoginDTO.getUsername()) + .setPassword(SecureUtil.md5(userPasswordLoginDTO.getPassword())); UserPO user = userMapper.selectOne(new QueryWrapper<>(userPO)); @@ -91,14 +90,31 @@ public UserLoginVO login(UserLoginDTO userLoginDTO) { } @Override - @Transactional(rollbackFor = RuntimeException.class) - public UserLoginVO registion(UserRegistionDTO userRegistionDTO) { + public UserLoginVO loginBySMS(UserSMSLoginDTO userSMSLoginDTO) { + String phoneNumber = userSMSLoginDTO.getPhoneNumber(); + this.checkPhoneNumberValidated(phoneNumber); - String reallySMSCaptcha = smsCaptchaCache.get(userRegistionDTO.getPhoneNumber(), String.class); - if (StringUtils.isEmpty(reallySMSCaptcha) || CacheConstants.CAPTCHA_CHECKED.equals(reallySMSCaptcha)) { - throw new AuthenticationException(40006); + LambdaQueryWrapper query = new LambdaQueryWrapper().eq(UserPO::getPhoneNumber, phoneNumber); + UserPO user = userMapper.selectOne(query); + + if (user == null || user.getStatus() == 1) { + throw new AuthenticationException(40002); } + String token = JWTUtils.createToken(user.getId()); + UserInfoPO userInfo = userInfoMapper.selectOne(new LambdaQueryWrapper().eq(UserInfoPO::getUserId, user.getId())); + UserLoginVO userLoginVO = new UserLoginVO(); + userLoginVO + .setToken(token) + .setUserInfo(userInfo); + return userLoginVO; + } + + @Override + @Transactional(rollbackFor = RuntimeException.class) + public UserLoginVO registion(UserRegistionDTO userRegistionDTO) { + this.checkPhoneNumberValidated(userRegistionDTO.getPhoneNumber()); + // 插入用户账号 UserPO newUserPO = new UserPO(); newUserPO @@ -117,11 +133,11 @@ public UserLoginVO registion(UserRegistionDTO userRegistionDTO) { smsCaptchaCache.evict(userRegistionDTO.getPhoneNumber()); // 进行登录操作 - UserLoginDTO userLoginDTO = new UserLoginDTO(); - userLoginDTO + UserPasswordLoginDTO userPasswordLoginDTO = new UserPasswordLoginDTO(); + userPasswordLoginDTO .setUsername(userRegistionDTO.getUsername()) .setPassword(userRegistionDTO.getPassword()); - return this.login(userLoginDTO); + return this.loginByPassword(userPasswordLoginDTO); } @Override @@ -158,7 +174,7 @@ public void checkImageCaptcha(CheckImageCaptchaParamDTO checkImageCaptchaParamDT @Override public void getSMSCaptcha(SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { // 检查手机号是否可用 - this.checkPhoneNumber(smsCaptchaParamDTO.getPhoneNumber()); + this.checkPhoneNumberUsed(smsCaptchaParamDTO.getPhoneNumber()); // 生成短信验证码 String smsCaptcha = RandomUtil.randomNumbers(6); @@ -209,15 +225,27 @@ public void checkSMSCaptcha(CheckSMSCaptchaParamDTO checkSMSCaptchaParamDTO) { } /** - * 检测手机号是否已经注册 + * 检测手机号是否已经被使用 * * @param phoneNumber 手机号 */ - private void checkPhoneNumber(String phoneNumber) { + private void checkPhoneNumberUsed(String phoneNumber) { UserPO user = userMapper.selectOne(new LambdaQueryWrapper().eq(UserPO::getPhoneNumber, phoneNumber)); // 手机号已被注册 if (user != null) { throw new AuthenticationException(40001); } } + + /** + * 检测手机号是否经过验证 + * + * @param phoneNumber 手机号 + */ + private void checkPhoneNumberValidated(String phoneNumber) { + String reallySMSCaptcha = smsCaptchaCache.get(phoneNumber, String.class); + if (StringUtils.isEmpty(reallySMSCaptcha) || CacheConstants.CAPTCHA_CHECKED.equals(reallySMSCaptcha)) { + throw new AuthenticationException(40006); + } + } } From 8a409523e03988c9b82d146d4a85a65ec2c24d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 19 Jul 2020 20:55:37 +0800 Subject: [PATCH 03/70] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/user/UserController.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/com/juzi/oerp/controller/user/UserController.java diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java new file mode 100644 index 0000000..807ff64 --- /dev/null +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -0,0 +1,35 @@ +package com.juzi.oerp.controller.user; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.juzi.oerp.common.store.LocalUserStore; +import com.juzi.oerp.model.po.UserInfoPO; +import com.juzi.oerp.model.vo.response.ResponseVO; +import com.juzi.oerp.service.UserInfoService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author Juzi + * @date 2020/7/19 20:48 + */ +@RestController +@RequestMapping("/user") +@Api(tags = "用户信息") +public class UserController { + + @Autowired + private UserInfoService userInfoService; + + @GetMapping + @ApiOperation(value = "个人信息", notes = "获取当前已登录用户的个人信息") + public ResponseVO getUserInfo() { + Integer userId = LocalUserStore.getLocalUser(); + UserInfoPO userInfo = userInfoService.getOne(new LambdaQueryWrapper().eq(UserInfoPO::getUserId, userId)); + return new ResponseVO<>(userInfo); + } + +} From 87ab7be20ef2ee6fd25f78f5980d78528de26c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 19 Jul 2020 21:03:16 +0800 Subject: [PATCH 04/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20UserControlle?= =?UTF-8?q?r=20bean=20=E5=90=8D=E7=A7=B0=E5=86=B2=E7=AA=81=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/juzi/oerp/controller/user/UserController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java index 807ff64..bc107c3 100644 --- a/src/main/java/com/juzi/oerp/controller/user/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -16,7 +16,7 @@ * @author Juzi * @date 2020/7/19 20:48 */ -@RestController +@RestController("userUserController") @RequestMapping("/user") @Api(tags = "用户信息") public class UserController { From fc11a70ed434107f3847e629e090036843f2fe7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 09:40:49 +0800 Subject: [PATCH 05/70] =?UTF-8?q?feat:=20Swagger=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9D=83=E9=99=90=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/common/constant/JWTConstants.java | 5 +++ .../configuration/SwaggerConfiguration.java | 38 +++++++++++++++++-- .../com/juzi/oerp/util/BearerTokenUtils.java | 12 ++++-- .../java/com/juzi/oerp/util/JWTUtils.java | 4 +- 4 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/juzi/oerp/common/constant/JWTConstants.java b/src/main/java/com/juzi/oerp/common/constant/JWTConstants.java index 37d7a68..847c3e7 100644 --- a/src/main/java/com/juzi/oerp/common/constant/JWTConstants.java +++ b/src/main/java/com/juzi/oerp/common/constant/JWTConstants.java @@ -11,4 +11,9 @@ public class JWTConstants { * JWT 签名密钥 */ public static final String JWT_SECRET = "OERP is good!"; + + /** + * Token 头部字符串 + */ + public static final String TOKEN_HEAD = "Bearer "; } diff --git a/src/main/java/com/juzi/oerp/configuration/SwaggerConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SwaggerConfiguration.java index e7f74ec..a65603f 100644 --- a/src/main/java/com/juzi/oerp/configuration/SwaggerConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SwaggerConfiguration.java @@ -2,6 +2,7 @@ import cn.hutool.core.collection.CollectionUtil; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; +import com.google.common.collect.Lists; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -10,11 +11,18 @@ import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.ApiKey; +import springfox.documentation.service.AuthorizationScope; import springfox.documentation.service.Contact; +import springfox.documentation.service.SecurityReference; +import springfox.documentation.service.SecurityScheme; import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; +import java.util.List; + /** * @author Juzi * @date 2020/7/19 01:06 @@ -26,7 +34,7 @@ public class SwaggerConfiguration { @Bean public Docket userDocket() { - return new Docket(DocumentationType.SWAGGER_2) + return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) //分组名称 .groupName("用户端") @@ -34,7 +42,9 @@ public Docket userDocket() { //这里指定Controller扫描包路径 .apis(RequestHandlerSelectors.basePackage("com.juzi.oerp.controller.user")) .paths(PathSelectors.any()) - .build(); + .build() + .securityContexts(Lists.newArrayList(securityContext())) + .securitySchemes(Lists.newArrayList(apiKey())); } @Bean @@ -46,7 +56,9 @@ public Docket adminDocket() { .select() .apis(RequestHandlerSelectors.basePackage("com.juzi.oerp.controller.admin")) .paths(PathSelectors.any()) - .build(); + .build() + .securityContexts(Lists.newArrayList(securityContext())) + .securitySchemes(Lists.newArrayList(apiKey())); } @Bean @@ -73,4 +85,24 @@ public ApiInfo apiInfo() { .version("1.0.0") .build(); } + + private ApiKey apiKey() { + return new ApiKey("BearerToken", "Authorization", "header"); + } + + private SecurityContext securityContext() { + return SecurityContext.builder() + .securityReferences(defaultAuth()) + .forPaths(PathSelectors.regex("/.*")) + .build(); + } + + List defaultAuth() { + AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything"); + AuthorizationScope[] authorizationScopes = new AuthorizationScope[1]; + authorizationScopes[0] = authorizationScope; + return Lists.newArrayList(new SecurityReference("BearerToken", authorizationScopes)); + } + + } diff --git a/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java b/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java index 3287287..c450690 100644 --- a/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java +++ b/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java @@ -1,22 +1,25 @@ package com.juzi.oerp.util; +import com.juzi.oerp.common.constant.JWTConstants; import com.juzi.oerp.common.exception.AuthenticationException; /** * Bearer Token 工具类 + * * @author Juzi * @date 2020/7/15 23:44 */ public class BearerTokenUtils { /** * 解析 token,将首部的 Bearer 删掉 + * * @param bearerToken token * @return JWT Token */ - public static String parseToken(String bearerToken){ + public static String parseToken(String bearerToken) { boolean bearerTokenIsValid = BearerTokenUtils.checkToken(bearerToken); // bearerToken 无效 - if(!bearerTokenIsValid){ + if (!bearerTokenIsValid) { throw new AuthenticationException(40003); } return bearerToken.substring(7); @@ -24,10 +27,11 @@ public static String parseToken(String bearerToken){ /** * 检测是否是 Bearer Token + * * @param bearerToken token * @return 是否为 Bearer Token */ - public static boolean checkToken(String bearerToken){ - return bearerToken.startsWith("Bearer "); + public static boolean checkToken(String bearerToken) { + return bearerToken.startsWith(JWTConstants.TOKEN_HEAD); } } diff --git a/src/main/java/com/juzi/oerp/util/JWTUtils.java b/src/main/java/com/juzi/oerp/util/JWTUtils.java index ccd8606..00c037b 100644 --- a/src/main/java/com/juzi/oerp/util/JWTUtils.java +++ b/src/main/java/com/juzi/oerp/util/JWTUtils.java @@ -31,11 +31,13 @@ public static String createToken(Integer userId) { LocalDateTime expireDateTime = LocalDateTime.now().plusDays(7); Date expireDate = Date.from(expireDateTime.atZone(ZoneId.of("Asia/Shanghai")).toInstant()); - return JWT.create() + String token = JWT.create() .withIssuer("OERM") .withExpiresAt(expireDate) .withClaim("userId", userId) .sign(Algorithm.HMAC256(JWTConstants.JWT_SECRET)); + + return JWTConstants.TOKEN_HEAD + token; } /** From 0567a0da9c83bcaa503208da8523433014727059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 09:53:34 +0800 Subject: [PATCH 06/70] =?UTF-8?q?refacotr:=20=E9=87=8D=E6=9E=84=20JWTUtils?= =?UTF-8?q?=20=E5=92=8C=20BearerTokenUtils=20=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AuthenticationInterceptor.java | 4 +- .../com/juzi/oerp/util/BearerTokenUtils.java | 37 ------------------- .../java/com/juzi/oerp/util/JWTUtils.java | 24 +++++++++--- 3 files changed, 19 insertions(+), 46 deletions(-) delete mode 100644 src/main/java/com/juzi/oerp/util/BearerTokenUtils.java diff --git a/src/main/java/com/juzi/oerp/common/interceptor/AuthenticationInterceptor.java b/src/main/java/com/juzi/oerp/common/interceptor/AuthenticationInterceptor.java index ddccda5..2a0ea97 100644 --- a/src/main/java/com/juzi/oerp/common/interceptor/AuthenticationInterceptor.java +++ b/src/main/java/com/juzi/oerp/common/interceptor/AuthenticationInterceptor.java @@ -3,7 +3,6 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.juzi.oerp.common.exception.AuthenticationException; import com.juzi.oerp.common.store.LocalUserStore; -import com.juzi.oerp.util.BearerTokenUtils; import com.juzi.oerp.util.JWTUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -29,8 +28,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons throw new AuthenticationException(40009); } - String jwtToken = BearerTokenUtils.parseToken(bearerToken); - Integer userId = JWTUtils.parseToken(jwtToken); + Integer userId = JWTUtils.parseToken(bearerToken); log.debug("当前登录用户id为{}",userId); LocalUserStore.setLocalUser(userId); return true; diff --git a/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java b/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java deleted file mode 100644 index c450690..0000000 --- a/src/main/java/com/juzi/oerp/util/BearerTokenUtils.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.juzi.oerp.util; - -import com.juzi.oerp.common.constant.JWTConstants; -import com.juzi.oerp.common.exception.AuthenticationException; - -/** - * Bearer Token 工具类 - * - * @author Juzi - * @date 2020/7/15 23:44 - */ -public class BearerTokenUtils { - /** - * 解析 token,将首部的 Bearer 删掉 - * - * @param bearerToken token - * @return JWT Token - */ - public static String parseToken(String bearerToken) { - boolean bearerTokenIsValid = BearerTokenUtils.checkToken(bearerToken); - // bearerToken 无效 - if (!bearerTokenIsValid) { - throw new AuthenticationException(40003); - } - return bearerToken.substring(7); - } - - /** - * 检测是否是 Bearer Token - * - * @param bearerToken token - * @return 是否为 Bearer Token - */ - public static boolean checkToken(String bearerToken) { - return bearerToken.startsWith(JWTConstants.TOKEN_HEAD); - } -} diff --git a/src/main/java/com/juzi/oerp/util/JWTUtils.java b/src/main/java/com/juzi/oerp/util/JWTUtils.java index 00c037b..bb25451 100644 --- a/src/main/java/com/juzi/oerp/util/JWTUtils.java +++ b/src/main/java/com/juzi/oerp/util/JWTUtils.java @@ -5,6 +5,7 @@ import com.auth0.jwt.algorithms.Algorithm; import com.auth0.jwt.exceptions.JWTDecodeException; import com.juzi.oerp.common.constant.JWTConstants; +import com.juzi.oerp.common.exception.AuthenticationException; import java.time.LocalDateTime; import java.time.ZoneId; @@ -43,12 +44,14 @@ public static String createToken(Integer userId) { /** * 解析 token * - * @param token accessToken + * @param bearerToken token * @return 用户id */ - public static Integer parseToken(String token) { + public static Integer parseToken(String bearerToken) { + String jwtToken = JWTUtils.extractJwtToken(bearerToken); + return JWTUtils.JWT_VERIFIER - .verify(token) + .verify(jwtToken) .getClaim("userId") .asInt(); } @@ -56,15 +59,24 @@ public static Integer parseToken(String token) { /** * 校验 token 是否有效 * - * @param token accessToken + * @param bearerToken * @return 是否有效 */ - public static boolean checkToken(String token) { + public static boolean checkToken(String bearerToken) { + String jwtToken = JWTUtils.extractJwtToken(bearerToken); + try { - JWTUtils.JWT_VERIFIER.verify(token); + JWTUtils.JWT_VERIFIER.verify(jwtToken); return true; } catch (JWTDecodeException e) { return false; } } + + private static String extractJwtToken(String bearerToken) { + if (!bearerToken.startsWith(JWTConstants.TOKEN_HEAD)) { + throw new AuthenticationException(40003); + } + return bearerToken.substring(7); + } } From dd6086d59cb17d7d6b023cba1565628560f47865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 10:43:02 +0800 Subject: [PATCH 07/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Github=20Acti?= =?UTF-8?q?on=20=E6=97=A0=E6=B3=95=E5=90=AF=E5=8A=A8=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/maven.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index eab2ee6..a3463a7 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -47,4 +47,6 @@ jobs: host: ${{ secrets.HOST }} username: ${{ secrets.USER }} key: ${{ secrets.SERVER_SSH_KEY }} - script: sh /www/wwwroot/oerp.juzibiji.top/springboot/restart.sh \ No newline at end of file + script: | + cd /www/wwwroot/oerp.juzibiji.top/springboot + sh restart.sh \ No newline at end of file From 59d62c39f5373c961e36f8b34e0458133282d35d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 10:55:05 +0800 Subject: [PATCH 08/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=80=83=E8=AF=95=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/juzi/oerp/configuration/SpringMvcConfiguration.java | 1 + src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java | 2 +- src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index 5489349..d18331f 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -86,6 +86,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/error", "/auth/**", "/user/exam", + "/user/exam/*", "/webjars/**", "/doc.html/**", "/swagger-resources/**" diff --git a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java index 49e644f..7295ac0 100644 --- a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java @@ -14,7 +14,7 @@ @ApiModel(value = "分页参数") public class PageParamDTO { - @ApiModelProperty("当前页码-从 0 开始") + @ApiModelProperty("当前页码-从 1 开始") private Integer pageOn; @ApiModelProperty("每页条数") diff --git a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java index f8a5d68..3e91a1a 100644 --- a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java @@ -54,7 +54,8 @@ public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO, String ke @Override public ExamPO getExamDetailInfoById(Integer examId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() - .select(ExamPO::getTitle, ExamPO::getImageUrl, ExamPO::getDescription, ExamPO::getId, ExamPO::getDetail, ExamPO::getPrice); + .select(ExamPO::getTitle, ExamPO::getImageUrl, ExamPO::getDescription, ExamPO::getId, ExamPO::getDetail, ExamPO::getPrice) + .eq(ExamPO::getId, examId); return examMapper.selectOne(queryWrapper); } From 23c9cf5f13e1fc031164066132afacbd510c3966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 13:26:46 +0800 Subject: [PATCH 09/70] =?UTF-8?q?feat:=20=E5=9B=BE=E7=89=87=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=20Base64=20=E5=A2=9E=E5=8A=A0=E5=A4=B4?= =?UTF-8?q?=E9=83=A8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/juzi/oerp/service/impl/AuthenticationServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index 58f673c..6e018fe 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -153,7 +153,7 @@ public CaptchaVO getImageCaptcha() { CaptchaVO captchaVO = new CaptchaVO(); captchaVO .setCaptchaId(captchaId) - .setCaptchaImageBase64(lineCaptcha.getImageBase64()); + .setCaptchaImageBase64("data:image/png;base64,"+lineCaptcha.getImageBase64()); return captchaVO; } From 395abc7c2b08bb6dd88c944969f308fe59201ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 13:33:22 +0800 Subject: [PATCH 10/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=9F=AD=E4=BF=A1=E9=AA=8C=E8=AF=81=E7=A0=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=96=B9=E6=B3=95=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/juzi/oerp/controller/AuthenticationController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java index 2a185da..73f7ee8 100644 --- a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java +++ b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java @@ -67,7 +67,7 @@ public ResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamD return new CreateResponseVO(); } - @GetMapping("/captcha/sms") + @PostMapping("/captcha/sms") @ApiOperation("获取短信验证码") public ResponseVO getSMSCaptcha(@RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { authenticationService.getSMSCaptcha(smsCaptchaParamDTO); From c57d7d61d0c8cc567b6336047399fc3565d3a7cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 14:00:42 +0800 Subject: [PATCH 11/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E4=BA=91=E7=9F=AD=E4=BF=A1=E9=85=8D=E7=BD=AE=E6=9C=AA?= =?UTF-8?q?=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../com/juzi/oerp/configuration/AliYunConfiguration.java | 2 +- src/main/resources/application-dev.yml | 6 ------ src/main/resources/application.yml | 5 +---- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index ad0cc8c..78eda15 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ ge/ *.iws *.iml *.ipr +config/ \ No newline at end of file diff --git a/src/main/java/com/juzi/oerp/configuration/AliYunConfiguration.java b/src/main/java/com/juzi/oerp/configuration/AliYunConfiguration.java index 25851eb..2fccce4 100644 --- a/src/main/java/com/juzi/oerp/configuration/AliYunConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/AliYunConfiguration.java @@ -19,7 +19,7 @@ public class AliYunConfiguration { private AliYunProperties aliYunProperties; @Bean - public IAcsClient iAcsClient(){ + public IAcsClient iAcsClient() { DefaultProfile profile = DefaultProfile.getProfile(aliYunProperties.getRegionId(), aliYunProperties.getAccessKeyId(), aliYunProperties.getSecret()); return new DefaultAcsClient(profile); } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 4c89417..9b3268b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -1,9 +1,3 @@ -oerp: - aliyun: - sms: - access-key-id: "****" - secret: "****" - logging: level: com.juzi.oerp: debug diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index fc01947..54df32c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -15,8 +15,6 @@ spring: - SMS_CAPTCHA_CACHE couchbase: expiration: 300 - profiles: - active: dev mybatis-plus: configuration: @@ -27,5 +25,4 @@ mybatis-plus: server: port: 8080 servlet: - context-path: /api/v1 - + context-path: /api/v1 \ No newline at end of file From c3969e7d23b80ed548facd56305ed773b79f699e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 14:28:00 +0800 Subject: [PATCH 12/70] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=20AOP=20?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=20Controller=20=E8=BF=94=E5=9B=9E=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E8=AE=BE=E7=BD=AE=E5=93=8D=E5=BA=94=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +++ .../common/aop/ControllerResponseAOP.java | 34 +++++++++++++++++++ .../controller/AuthenticationController.java | 10 +++--- .../admin/AduitApplicationController.java | 5 +-- .../oerp/controller/admin/ExamController.java | 10 +++--- .../oerp/controller/admin/UserController.java | 9 ++--- .../oerp/controller/user/ApplyController.java | 5 +-- .../model/vo/response/MessageResponseVO.java | 19 +++++++++++ .../oerp/model/vo/response/ResponseVO.java | 4 +++ src/main/resources/code-message.properties | 9 +++++ 10 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java create mode 100644 src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java diff --git a/pom.xml b/pom.xml index d0cf878..3e1426a 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-aop + org.springframework.boot diff --git a/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java b/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java new file mode 100644 index 0000000..36f7a24 --- /dev/null +++ b/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java @@ -0,0 +1,34 @@ +package com.juzi.oerp.common.aop; + +import cn.hutool.core.util.StrUtil; +import com.juzi.oerp.configuration.properties.CodeMessageProperties; +import com.juzi.oerp.model.vo.response.MessageResponseVO; +import com.juzi.oerp.model.vo.response.ResponseVO; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +/** + * @author Juzi + * @date 2020/7/20 14:11 + */ +@Aspect +@Component +public class ControllerResponseAOP { + @Autowired + private CodeMessageProperties codeMessageProperties; + + @AfterReturning(returning = "messageResponseVO", pointcut = "execution(public * com.juzi.oerp.controller..*.*(..))") + public void doAfterReturning(MessageResponseVO messageResponseVO) { + int code = messageResponseVO.getCode(); + String oldMessage = messageResponseVO.getMessage(); + String newMessage = codeMessageProperties.getCodeMessage().get(code); + + if(StringUtils.isEmpty(oldMessage)){ + messageResponseVO.setMessage(newMessage); + } + + } +} diff --git a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java index 73f7ee8..9bb35fc 100644 --- a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java +++ b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java @@ -8,7 +8,7 @@ import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; import com.juzi.oerp.model.vo.CaptchaVO; import com.juzi.oerp.model.vo.UserLoginVO; -import com.juzi.oerp.model.vo.response.CreateResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.AuthenticationService; import io.swagger.annotations.Api; @@ -62,16 +62,16 @@ public ResponseVO getImageCaptcha() { @PostMapping("/captcha/image") @ApiOperation("校验图片验证码") - public ResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamDTO checkImageCaptchaParamDTO) { + public MessageResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamDTO checkImageCaptchaParamDTO) { authenticationService.checkImageCaptcha(checkImageCaptchaParamDTO); - return new CreateResponseVO(); + return new MessageResponseVO(20001); } @PostMapping("/captcha/sms") @ApiOperation("获取短信验证码") - public ResponseVO getSMSCaptcha(@RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { + public MessageResponseVO getSMSCaptcha(@RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { authenticationService.getSMSCaptcha(smsCaptchaParamDTO); - return new CreateResponseVO(); + return new MessageResponseVO(20002); } } diff --git a/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java b/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java index 3d4e0b5..c94caff 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java @@ -2,6 +2,7 @@ import com.juzi.oerp.model.dto.param.AuditApplicationParamDTO; import com.juzi.oerp.model.vo.response.CreateResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.AuditApplicationService; import io.swagger.annotations.Api; @@ -33,9 +34,9 @@ public class AduitApplicationController { */ @PostMapping("/aduit") @ApiOperation("审核报名") - public ResponseVO auditApply(@RequestBody AuditApplicationParamDTO auditApplicationParamDTO) { + public MessageResponseVO auditApply(@RequestBody AuditApplicationParamDTO auditApplicationParamDTO) { auditApplicationService.auditApplication(auditApplicationParamDTO); - return new CreateResponseVO(); + return new MessageResponseVO(20004); } } diff --git a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java index 94dac94..f77a8ff 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java @@ -1,10 +1,10 @@ package com.juzi.oerp.controller.admin; -import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.dto.UpdateExamDTO; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; -import com.juzi.oerp.model.vo.response.CreateResponseVO; import com.juzi.oerp.model.vo.response.DeleteResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -35,7 +35,7 @@ public class ExamController { * @param pageParamDTO 分页参数 */ @GetMapping - @ApiOperation(value = "获取考试信息列表",notes = "分页获取考试列表") + @ApiOperation(value = "获取考试信息列表", notes = "分页获取考试列表") public ResponseVO getExamByPage(PageParamDTO pageParamDTO) { return null; } @@ -73,8 +73,8 @@ public ResponseVO updateExamById(@RequestBody UpdateExamDTO updateExamDT */ @PostMapping @ApiOperation("创建考试") - public ResponseVO createExam(@RequestBody UpdateExamDTO updateExamDTO) { - return new CreateResponseVO(); + public MessageResponseVO createExam(@RequestBody UpdateExamDTO updateExamDTO) { + return new MessageResponseVO(20003); } /** diff --git a/src/main/java/com/juzi/oerp/controller/admin/UserController.java b/src/main/java/com/juzi/oerp/controller/admin/UserController.java index ff009c3..f510f1a 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/UserController.java @@ -7,6 +7,7 @@ import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.model.vo.response.CreateResponseVO; import com.juzi.oerp.model.vo.response.DeleteResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.UserService; import io.swagger.annotations.Api; @@ -80,9 +81,9 @@ public ResponseVO deleteUserByUserId(@PathVariable Integer userId) { */ @PostMapping @ApiOperation("新增用户") - public ResponseVO createUser(@RequestBody CreateUserDTO createUserDTO) { + public MessageResponseVO createUser(@RequestBody CreateUserDTO createUserDTO) { userService.createUser(createUserDTO); - return new CreateResponseVO(); + return new MessageResponseVO(20006); } /** @@ -93,8 +94,8 @@ public ResponseVO createUser(@RequestBody CreateUserDTO createUserDTO) { */ @PutMapping @ApiOperation("修改用户") - public ResponseVO updateUser(@RequestBody UpdateUserDTO updateUserDTO) { + public MessageResponseVO updateUser(@RequestBody UpdateUserDTO updateUserDTO) { userService.updateUser(updateUserDTO); - return new CreateResponseVO(); + return new MessageResponseVO(20007); } } diff --git a/src/main/java/com/juzi/oerp/controller/user/ApplyController.java b/src/main/java/com/juzi/oerp/controller/user/ApplyController.java index ab61b43..8e1475a 100644 --- a/src/main/java/com/juzi/oerp/controller/user/ApplyController.java +++ b/src/main/java/com/juzi/oerp/controller/user/ApplyController.java @@ -3,6 +3,7 @@ import com.juzi.oerp.model.dto.param.ApplyExamParamDTO; import com.juzi.oerp.model.po.UserExamPO; import com.juzi.oerp.model.vo.response.CreateResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.ApplyService; import io.swagger.annotations.Api; @@ -50,9 +51,9 @@ public ResponseVO applyExam(@RequestBody ApplyExamParamDTO applyExam */ @PostMapping("/pay/{applyId}") @ApiOperation("考试支付") - public ResponseVO pay(@ApiParam("报名 id") @PathVariable Integer applyId) { + public MessageResponseVO pay(@ApiParam("报名 id") @PathVariable Integer applyId) { applyService.pay(applyId); - return new CreateResponseVO(); + return new MessageResponseVO(20005); } } diff --git a/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java b/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java new file mode 100644 index 0000000..701353c --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java @@ -0,0 +1,19 @@ +package com.juzi.oerp.model.vo.response; + +import lombok.Data; + +/** + * @author Juzi + * @date 2020/7/20 14:21 + */ +@Data +public class MessageResponseVO extends ResponseVO { + + public MessageResponseVO(Integer code) { + super(code); + } + + public MessageResponseVO(Integer code, String message) { + super(code, message); + } +} diff --git a/src/main/java/com/juzi/oerp/model/vo/response/ResponseVO.java b/src/main/java/com/juzi/oerp/model/vo/response/ResponseVO.java index 2554358..e18afdb 100644 --- a/src/main/java/com/juzi/oerp/model/vo/response/ResponseVO.java +++ b/src/main/java/com/juzi/oerp/model/vo/response/ResponseVO.java @@ -26,6 +26,10 @@ public class ResponseVO { @ApiModelProperty("响应数据") private T data; + public ResponseVO(Integer code) { + this.code = code; + } + public ResponseVO(Integer code, String message) { this.code = code; this.message = message; diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 474fbad..2f7aab6 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -1,3 +1,12 @@ +codeMessage[20001]=\u9A8C\u8BC1\u7801\u9A8C\u8BC1\u6210\u529F +codeMessage[20002]=\u9A8C\u8BC1\u7801\u53D1\u9001\u6210\u529F +codeMessage[20003]=\u8003\u8BD5\u521B\u5EFA\u6210\u529F +codeMessage[20004]=\u5BA1\u6838\u5B8C\u6210 +codeMessage[20005]=\u652F\u4ED8\u6210\u529F +codeMessage[20006]=\u65B0\u589E\u7528\u6237\u6210\u529F +codeMessage[20007]=\u4FEE\u6539\u7528\u6237\u6210\u529F + + codeMessage[40000]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 codeMessage[40001]=\u624B\u673A\u53F7\u5DF2\u88AB\u6CE8\u518C\uFF0C\u8BF7\u66F4\u6362\u624B\u673A\u53F7\u518D\u8BD5 codeMessage[40002]=\u8D26\u53F7\u6216\u5BC6\u7801\u9519\u8BEF From 97f566449634d0c19d265f15abc6090548d5ee37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 14:37:35 +0800 Subject: [PATCH 13/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/user/UserController.java | 21 ++++++++++++-- .../oerp/model/dto/UpdateUserInfoDTO.java | 29 +++++++++++++++++++ .../model/vo/response/UpdatedResponseVO.java | 11 +++++++ src/main/resources/code-message.properties | 2 ++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java create mode 100644 src/main/java/com/juzi/oerp/model/vo/response/UpdatedResponseVO.java diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java index bc107c3..89b0ef1 100644 --- a/src/main/java/com/juzi/oerp/controller/user/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -2,13 +2,18 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.juzi.oerp.common.store.LocalUserStore; +import com.juzi.oerp.model.dto.UpdateUserInfoDTO; import com.juzi.oerp.model.po.UserInfoPO; import com.juzi.oerp.model.vo.response.ResponseVO; +import com.juzi.oerp.model.vo.response.UpdatedResponseVO; import com.juzi.oerp.service.UserInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -16,9 +21,9 @@ * @author Juzi * @date 2020/7/19 20:48 */ -@RestController("userUserController") -@RequestMapping("/user") @Api(tags = "用户信息") +@RequestMapping("/user") +@RestController("userUserController") public class UserController { @Autowired @@ -32,4 +37,16 @@ public ResponseVO getUserInfo() { return new ResponseVO<>(userInfo); } + @PutMapping + @ApiOperation(value = "修改个人信息") + public UpdatedResponseVO updateUserInfo(@RequestBody UpdateUserInfoDTO updateUserInfoDTO) { + Integer userId = LocalUserStore.getLocalUser(); + UserInfoPO userInfoPO = new UserInfoPO(); + userInfoPO.setUserId(userId); + BeanUtils.copyProperties(updateUserInfoDTO, userInfoPO); + + userInfoService.updateById(userInfoPO); + return new UpdatedResponseVO(); + } + } diff --git a/src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java b/src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java new file mode 100644 index 0000000..455da34 --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java @@ -0,0 +1,29 @@ +package com.juzi.oerp.model.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * 更新用户信息 + * + * @author Juzi + * @date 2020/7/20 14:32 + */ +@Data +@ApiModel(description = "修改用户信息参数") +public class UpdateUserInfoDTO { + + @ApiModelProperty("姓名") + private String name; + + @ApiModelProperty("身份证号") + private String identityNo; + + @ApiModelProperty("性别") + private Integer gender; + + @ApiModelProperty("学历") + private String education; + +} diff --git a/src/main/java/com/juzi/oerp/model/vo/response/UpdatedResponseVO.java b/src/main/java/com/juzi/oerp/model/vo/response/UpdatedResponseVO.java new file mode 100644 index 0000000..210a5db --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/vo/response/UpdatedResponseVO.java @@ -0,0 +1,11 @@ +package com.juzi.oerp.model.vo.response; + +/** + * @author Juzi + * @date 2020/7/20 14:30 + */ +public class UpdatedResponseVO extends ResponseVO { + public UpdatedResponseVO() { + super(20010, "修改成功"); + } +} diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 2f7aab6..b895266 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -6,6 +6,8 @@ codeMessage[20005]=\u652F\u4ED8\u6210\u529F codeMessage[20006]=\u65B0\u589E\u7528\u6237\u6210\u529F codeMessage[20007]=\u4FEE\u6539\u7528\u6237\u6210\u529F +codeMessage[20010]=\u4FEE\u6539\u6210\u529F + codeMessage[40000]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 codeMessage[40001]=\u624B\u673A\u53F7\u5DF2\u88AB\u6CE8\u518C\uFF0C\u8BF7\u66F4\u6362\u624B\u673A\u53F7\u518D\u8BD5 From b39d01157f7f07788699696e6e6269833e745ab9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 20:13:11 +0800 Subject: [PATCH 14/70] =?UTF-8?q?feat:=20=E5=88=86=E9=A1=B5=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java index 7295ac0..c86a444 100644 --- a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java @@ -15,8 +15,8 @@ public class PageParamDTO { @ApiModelProperty("当前页码-从 1 开始") - private Integer pageOn; + private Integer pageOn = 1; @ApiModelProperty("每页条数") - private Integer pageSize; + private Integer pageSize = 10; } From 2c06685f2986a0479609f4e5a05b92ee497d0ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Mon, 20 Jul 2020 20:13:32 +0800 Subject: [PATCH 15/70] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=93=8D=E5=BA=94=E5=80=BC=E5=A2=9E=E5=8A=A0=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mybatis/xml/dao/UserDAO.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/mybatis/xml/dao/UserDAO.xml b/src/main/resources/mybatis/xml/dao/UserDAO.xml index 3b24cdb..8dfc35b 100644 --- a/src/main/resources/mybatis/xml/dao/UserDAO.xml +++ b/src/main/resources/mybatis/xml/dao/UserDAO.xml @@ -6,6 +6,7 @@ `user`.id AS userId, `user`.username, `user`.role, + `user`.phone_number, `user`.`status`, `user`.create_time, `user`.update_time, From c01e5a013b53a3f91bbe346bc16b8d6801166812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Tue, 21 Jul 2020 14:10:30 +0800 Subject: [PATCH 16/70] =?UTF-8?q?feat:=20=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=A2=9E=E5=8A=A0=E5=AD=A6=E5=8E=86=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java | 3 +++ src/main/resources/mybatis/xml/dao/UserDAO.xml | 1 + 2 files changed, 4 insertions(+) diff --git a/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java b/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java index 43600a6..efdda66 100644 --- a/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java +++ b/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java @@ -34,6 +34,9 @@ public class UserInfoVO { @ApiModelProperty("性别") private Integer gender; + @ApiModelProperty("学历") + private String education; + @ApiModelProperty("角色:0普通;1管理员") private Integer role; diff --git a/src/main/resources/mybatis/xml/dao/UserDAO.xml b/src/main/resources/mybatis/xml/dao/UserDAO.xml index 8dfc35b..147dade 100644 --- a/src/main/resources/mybatis/xml/dao/UserDAO.xml +++ b/src/main/resources/mybatis/xml/dao/UserDAO.xml @@ -14,6 +14,7 @@ user_info.avatar_url, user_info.`name`, user_info.gender, + user_info.education, user_info.identity_no, user_info.birthday FROM From 0ca724dd8a5b32db1aebea3a02fae4ad603ba18b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Wed, 22 Jul 2020 08:46:33 +0800 Subject: [PATCH 17/70] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../juzi/oerp/controller/admin/UserController.java | 5 ++--- src/main/java/com/juzi/oerp/dao/UserDAO.java | 7 +++++-- .../com/juzi/oerp/model/dto/param/PageParamDTO.java | 3 +++ src/main/java/com/juzi/oerp/service/UserService.java | 6 +++++- .../com/juzi/oerp/service/impl/UserServiceImpl.java | 12 ++++++------ src/main/resources/mybatis/xml/dao/UserDAO.xml | 4 ++++ 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/admin/UserController.java b/src/main/java/com/juzi/oerp/controller/admin/UserController.java index f510f1a..71bb17e 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/UserController.java @@ -2,10 +2,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.juzi.oerp.model.dto.CreateUserDTO; -import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.dto.UpdateUserDTO; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.vo.UserInfoVO; -import com.juzi.oerp.model.vo.response.CreateResponseVO; import com.juzi.oerp.model.vo.response.DeleteResponseVO; import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; @@ -41,7 +40,7 @@ public class UserController { * @return 用户信息 */ @GetMapping - @ApiOperation(value = "获取用户列表",notes = "根据分页参数获取用户列表") + @ApiOperation(value = "获取用户列表", notes = "根据分页参数获取用户列表") public ResponseVO> getUserByPage(PageParamDTO pageParamDTO) { Page result = userService.getUserByPage(pageParamDTO); return new ResponseVO<>(result); diff --git a/src/main/java/com/juzi/oerp/dao/UserDAO.java b/src/main/java/com/juzi/oerp/dao/UserDAO.java index 2d6a126..eee4c27 100644 --- a/src/main/java/com/juzi/oerp/dao/UserDAO.java +++ b/src/main/java/com/juzi/oerp/dao/UserDAO.java @@ -12,13 +12,16 @@ public interface UserDAO { /** * 获取用户_分页 - * @param page 分页参数 + * + * @param page 分页参数 + * @param keyword 搜索关键词 * @return 用户信息 */ - IPage getUserByPage(Page page); + IPage getUserByPage(@Param("page") Page page, @Param("keyword") String keyword); /** * 获取用户_根据用户 id + * * @param userId 用户 id * @return 用户信息 */ diff --git a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java index c86a444..a7611a4 100644 --- a/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/param/PageParamDTO.java @@ -19,4 +19,7 @@ public class PageParamDTO { @ApiModelProperty("每页条数") private Integer pageSize = 10; + + @ApiModelProperty("搜索关键字") + private String keyword = ""; } diff --git a/src/main/java/com/juzi/oerp/service/UserService.java b/src/main/java/com/juzi/oerp/service/UserService.java index 09520aa..3b99832 100644 --- a/src/main/java/com/juzi/oerp/service/UserService.java +++ b/src/main/java/com/juzi/oerp/service/UserService.java @@ -3,8 +3,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.juzi.oerp.model.dto.CreateUserDTO; -import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.dto.UpdateUserDTO; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.UserPO; import com.juzi.oerp.model.vo.UserInfoVO; @@ -27,6 +27,7 @@ public interface UserService extends IService { /** * 获取用户_根据 userId + * * @param userId 用户 id * @return 单条用户信息 */ @@ -34,18 +35,21 @@ public interface UserService extends IService { /** * 删除用户_根据 userId + * * @param userId 用户 id */ void deleteUserByUserId(Integer userId); /** * 新增用户 + * * @param createUserDTO 用户信息 */ void createUser(CreateUserDTO createUserDTO); /** * 修改用户信息 + * * @param updateUserDTO 用户信息 */ void updateUser(UpdateUserDTO updateUserDTO); diff --git a/src/main/java/com/juzi/oerp/service/impl/UserServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/UserServiceImpl.java index 0cd591c..8702e8f 100644 --- a/src/main/java/com/juzi/oerp/service/impl/UserServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/UserServiceImpl.java @@ -6,8 +6,8 @@ import com.juzi.oerp.mapper.UserInfoMapper; import com.juzi.oerp.mapper.UserMapper; import com.juzi.oerp.model.dto.CreateUserDTO; -import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.dto.UpdateUserDTO; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.UserInfoPO; import com.juzi.oerp.model.po.UserPO; import com.juzi.oerp.model.vo.UserInfoVO; @@ -40,7 +40,7 @@ public class UserServiceImpl extends ServiceImpl implements @Override public Page getUserByPage(PageParamDTO pageParamDTO) { Page page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); - userDAO.getUserByPage(page); + userDAO.getUserByPage(page, pageParamDTO.getKeyword()); return page; } @@ -62,8 +62,8 @@ public void createUser(CreateUserDTO createUserDTO) { UserPO userPO = new UserPO(); UserInfoPO userInfoPO = new UserInfoPO(); - BeanUtils.copyProperties(createUserDTO,userPO); - BeanUtils.copyProperties(createUserDTO,userInfoPO); + BeanUtils.copyProperties(createUserDTO, userPO); + BeanUtils.copyProperties(createUserDTO, userInfoPO); userMapper.insert(userPO); @@ -77,8 +77,8 @@ public void updateUser(UpdateUserDTO updateUserDTO) { UserPO userPO = new UserPO(); UserInfoPO userInfoPO = new UserInfoPO(); - BeanUtils.copyProperties(updateUserDTO,userPO); - BeanUtils.copyProperties(updateUserDTO,userInfoPO); + BeanUtils.copyProperties(updateUserDTO, userPO); + BeanUtils.copyProperties(updateUserDTO, userInfoPO); userMapper.updateById(userPO); diff --git a/src/main/resources/mybatis/xml/dao/UserDAO.xml b/src/main/resources/mybatis/xml/dao/UserDAO.xml index 147dade..c5ffc81 100644 --- a/src/main/resources/mybatis/xml/dao/UserDAO.xml +++ b/src/main/resources/mybatis/xml/dao/UserDAO.xml @@ -23,6 +23,10 @@ user_info ON `user`.id = user_info.user_id + WHERE + user_info.`name` LIKE CONCAT('%',#{keyword,jdbcType=VARCHAR},'%') + ORDER BY + `user`.create_time DESC + SELECT DATE_FORMAT(user_exam.create_time, '%c月') AS `month`, + IF + ( + user_info.gender = 1, + '男', + IF + (user_info.gender = 2, '女', '未知')) AS 'gender', + count(1) AS `value` + FROM user_exam + INNER JOIN user_info ON user_exam.user_id = user_info.user_id + WHERE DATE_SUB(NOW(), INTERVAL 6 MONTH) user_exam.create_time + AND user_exam.create_time NOW() + GROUP BY DATE_FORMAT(user_exam.create_time, '%Y%m'), + user_info.gender + + + + + + + \ No newline at end of file From 1c121bf2ea8419a29e702f261e2b550189e94bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Fri, 24 Jul 2020 16:24:30 +0800 Subject: [PATCH 51/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E5=99=A8=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/configuration/SpringMvcConfiguration.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index db211ff..50c2618 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -3,31 +3,22 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StringSerializer; import com.juzi.oerp.common.interceptor.AuthenticationInterceptor; import com.juzi.oerp.common.jackson.LocalDateTimeDeserializer; import com.juzi.oerp.common.jackson.LocalDateTimeKeySerializer; import com.juzi.oerp.common.jackson.LocalDateTimeSerializer; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.bind.Binder; -import org.springframework.boot.web.servlet.server.Encoding; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.env.Environment; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.List; @@ -75,13 +66,12 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { /** * 配置拦截器 * - * @param registry + * @param registry 拦截器注册表 */ @Override public void addInterceptors(InterceptorRegistry registry) { registry .addInterceptor(authenticationInterceptor) - .addPathPatterns("/auth/change") .excludePathPatterns( "/", "/error", @@ -94,6 +84,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/doc.html/**", "/swagger-resources/**" ); + } /** From 2797415784e12daf23ca88c85a0c5dd0bcef9198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Fri, 24 Jul 2020 16:27:16 +0800 Subject: [PATCH 52/70] =?UTF-8?q?refactor:=20=E5=8E=BB=E9=99=A4=E6=97=A0?= =?UTF-8?q?=E7=94=A8=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../juzi/oerp/common/jackson/LocalDateTimeDeserializer.java | 2 +- .../juzi/oerp/controller/admin/AduitApplicationController.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/juzi/oerp/common/jackson/LocalDateTimeDeserializer.java b/src/main/java/com/juzi/oerp/common/jackson/LocalDateTimeDeserializer.java index d64a255..940ac86 100644 --- a/src/main/java/com/juzi/oerp/common/jackson/LocalDateTimeDeserializer.java +++ b/src/main/java/com/juzi/oerp/common/jackson/LocalDateTimeDeserializer.java @@ -18,7 +18,7 @@ public class LocalDateTimeDeserializer extends JsonDeserializer { @Override - public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { + public LocalDateTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { long timestamp = jsonParser.getLongValue(); return LocalDateTime.ofEpochSecond(timestamp / 1000, 0, ZoneOffset.ofHours(8)); } diff --git a/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java b/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java index c94caff..56b5eb4 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/AduitApplicationController.java @@ -1,9 +1,7 @@ package com.juzi.oerp.controller.admin; import com.juzi.oerp.model.dto.param.AuditApplicationParamDTO; -import com.juzi.oerp.model.vo.response.CreateResponseVO; import com.juzi.oerp.model.vo.response.MessageResponseVO; -import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.AuditApplicationService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -15,6 +13,7 @@ /** * 审核报名 + * * @author Juzi * @date 2020/7/17 17:35 */ From 535fe48ac32ffac76b0092cc8fd0fbd744fbdbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Fri, 24 Jul 2020 17:13:34 +0800 Subject: [PATCH 53/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=20controller?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E8=BD=AC=E6=8D=A2=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/ExceptionController.java | 20 +++++++++++++++++++ .../impl/AuthenticationServiceImpl.java | 2 +- src/main/resources/code-message.properties | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/ExceptionController.java b/src/main/java/com/juzi/oerp/controller/ExceptionController.java index 937de59..a8b8a59 100644 --- a/src/main/java/com/juzi/oerp/controller/ExceptionController.java +++ b/src/main/java/com/juzi/oerp/controller/ExceptionController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; /** * 异常统一处理 @@ -57,10 +58,29 @@ public ExceptionResponseVO methodArgumentNotValidException(MethodArgumentNotVali return new ExceptionResponseVO(40000, validMessage); } + /** + * controller 层参数格式转换异常 + * + * @param e 参数转换异常 + * @return 异常信息 + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public ExceptionResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { + return new ExceptionResponseVO(40000, "参数转换错误,请检查参数格式"); + } + + /** + * 其他未知异常 + * + * @param runtimeException 运行时异常 + * @return 异常信息 + */ @ExceptionHandler(RuntimeException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public ExceptionResponseVO runtimeException(RuntimeException runtimeException) { log.error("系统出现未知错误", runtimeException); return new ExceptionResponseVO(50000, "系统未知错误"); } + } diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index 0634629..e7d5937 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -199,7 +199,7 @@ public void getSMSCaptcha(SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProc String imageCaptcha = imageCaptchaCache.get(smsCaptchaParamDTO.getCaptchaId(), String.class); if (StringUtils.isEmpty(imageCaptcha)) { - throw new CaptchaException(40000); + throw new CaptchaException(40001); } if (!CacheConstants.CAPTCHA_CHECKED.equals(imageCaptcha)) { diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 89c7b88..5f53bda 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -9,7 +9,6 @@ codeMessage[20008]=\u624B\u673A\u53F7\u6B63\u786E codeMessage[20010]=\u4FEE\u6539\u6210\u529F -codeMessage[40000]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 codeMessage[40001]=\u624B\u673A\u53F7\u5DF2\u88AB\u6CE8\u518C\uFF0C\u8BF7\u66F4\u6362\u624B\u673A\u53F7\u518D\u8BD5 codeMessage[40002]=\u8D26\u53F7\u6216\u5BC6\u7801\u9519\u8BEF codeMessage[40003]=Bearer Token \u65E0\u6548 @@ -21,6 +20,7 @@ codeMessage[40008]=\u62A5\u540D\u4EBA\u6570\u5DF2\u6EE1 codeMessage[40009]=\u8BF7\u5148\u767B\u5F55 codeMessage[40010]=\u624B\u673A\u53F7\u9519\u8BEF codeMessage[40011]=\u65E7\u5BC6\u7801\u8F93\u5165\u9519\u8BEF +codeMessage[40012]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 codeMessage[50001]=\u9A8C\u8BC1\u7801\u670D\u52A1\u914D\u7F6E\u51FA\u9519 codeMessage[50002]=\u7F13\u5B58\u52A0\u8F7D\u5931\u8D25 From c335f8f9574c609521647fc2155ac6321bbf2a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 09:10:40 +0800 Subject: [PATCH 54/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=B8=A6=20toke?= =?UTF-8?q?n=20=E6=8E=A5=E5=8F=A3=E8=B7=A8=E5=9F=9F=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/juzi/oerp/configuration/SpringMvcConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index 50c2618..b45a288 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -50,6 +50,7 @@ public class SpringMvcConfiguration implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") + .allowedHeaders("Authorization") .maxAge(3000) .allowedOrigins("*") .allowCredentials(true) From 9d7f75fff043e8cb7e9341d7342682b8470eec38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 09:18:01 +0800 Subject: [PATCH 55/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=9F=AD?= =?UTF-8?q?=E4=BF=A1=E7=99=BB=E5=BD=95=E6=97=B6=E6=97=A0=E6=B3=95=E5=8F=91?= =?UTF-8?q?=E9=80=81=E9=AA=8C=E8=AF=81=E7=A0=81=E7=9F=AD=E4=BF=A1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../juzi/oerp/service/impl/AuthenticationServiceImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index e7d5937..7709e41 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -131,7 +131,10 @@ public UserLoginVO loginBySMS(UserSMSLoginDTO userSMSLoginDTO) { @Override @Transactional(rollbackFor = RuntimeException.class) public UserLoginVO registion(UserRegistionDTO userRegistionDTO) { + // 检查手机号是否已经过验证 this.checkPhoneNumberValidated(userRegistionDTO.getPhoneNumber()); + // 检查手机号是否可用 + this.checkPhoneNumberUsed(userRegistionDTO.getPhoneNumber()); // 插入用户账号 UserPO newUserPO = new UserPO(); @@ -191,8 +194,6 @@ public void checkImageCaptcha(CheckImageCaptchaParamDTO checkImageCaptchaParamDT @Override public void getSMSCaptcha(SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { - // 检查手机号是否可用 - this.checkPhoneNumberUsed(smsCaptchaParamDTO.getPhoneNumber()); // 生成短信验证码 String smsCaptcha = RandomUtil.randomNumbers(6); log.debug("本次生成短信验证码为:{}", smsCaptcha); From 7feef6114203d0bc6b14a564c38a39d1a41c6a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 09:33:41 +0800 Subject: [PATCH 56/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/juzi/oerp/configuration/SpringMvcConfiguration.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index b45a288..d4ca347 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -50,7 +50,7 @@ public class SpringMvcConfiguration implements WebMvcConfigurer { public void addCorsMappings(CorsRegistry registry) { registry .addMapping("/**") - .allowedHeaders("Authorization") + .allowedHeaders("*") .maxAge(3000) .allowedOrigins("*") .allowCredentials(true) From 675b4df21bb3ea6a1285eb0275293ff0df820912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 10:28:34 +0800 Subject: [PATCH 57/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B7=A8=E5=9F=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configuration/SpringMvcConfiguration.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index d4ca347..319419b 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -8,11 +8,15 @@ import com.juzi.oerp.common.jackson.LocalDateTimeKeySerializer; import com.juzi.oerp.common.jackson.LocalDateTimeSerializer; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; @@ -46,15 +50,16 @@ public class SpringMvcConfiguration implements WebMvcConfigurer { @Autowired private LocalDateTimeDeserializer localDateTimeDeserializer; - @Override - public void addCorsMappings(CorsRegistry registry) { - registry - .addMapping("/**") - .allowedHeaders("*") - .maxAge(3000) - .allowedOrigins("*") - .allowCredentials(true) - .allowedMethods("GET", "POST", "PUT", "DELETE"); + @Bean + public CorsFilter corsFilter() { + CorsConfiguration config = new CorsConfiguration(); + config.addAllowedOrigin("*"); + config.setAllowCredentials(true); + config.addAllowedMethod("*"); + config.addAllowedHeader("*"); + UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource(); + configSource.registerCorsConfiguration("/**", config); + return new CorsFilter(configSource); } @Override From 2aa6f7d06c1cb537f53097d2eac1514b3460a15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 11:31:34 +0800 Subject: [PATCH 58/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=B7=B2=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3=E5=AD=97=E6=AE=B5=E4=B8=8D=E5=85=A8?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/user/UserController.java | 14 +++++++---- .../oerp/service/AuthenticationService.java | 8 ++++++- .../juzi/oerp/service/UserInfoService.java | 10 +++++++- .../impl/AuthenticationServiceImpl.java | 23 +++++-------------- .../service/impl/UserInfoServiceImpl.java | 19 +++++++++++++++ 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java index 89b0ef1..6644e33 100644 --- a/src/main/java/com/juzi/oerp/controller/user/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -1,12 +1,14 @@ package com.juzi.oerp.controller.user; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.juzi.oerp.common.store.LocalUserStore; import com.juzi.oerp.model.dto.UpdateUserInfoDTO; import com.juzi.oerp.model.po.UserInfoPO; +import com.juzi.oerp.model.po.UserPO; +import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.model.vo.response.UpdatedResponseVO; import com.juzi.oerp.service.UserInfoService; +import com.juzi.oerp.service.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; @@ -29,12 +31,16 @@ public class UserController { @Autowired private UserInfoService userInfoService; + @Autowired + private UserService userService; + @GetMapping @ApiOperation(value = "个人信息", notes = "获取当前已登录用户的个人信息") - public ResponseVO getUserInfo() { + public ResponseVO getUserInfo() { Integer userId = LocalUserStore.getLocalUser(); - UserInfoPO userInfo = userInfoService.getOne(new LambdaQueryWrapper().eq(UserInfoPO::getUserId, userId)); - return new ResponseVO<>(userInfo); + UserPO userPO = userService.getById(userId); + UserInfoVO userInfoVO = userInfoService.getUserInfoAll(userPO); + return new ResponseVO<>(userInfoVO); } @PutMapping diff --git a/src/main/java/com/juzi/oerp/service/AuthenticationService.java b/src/main/java/com/juzi/oerp/service/AuthenticationService.java index cb443b9..633664c 100644 --- a/src/main/java/com/juzi/oerp/service/AuthenticationService.java +++ b/src/main/java/com/juzi/oerp/service/AuthenticationService.java @@ -1,7 +1,11 @@ package com.juzi.oerp.service; import com.fasterxml.jackson.core.JsonProcessingException; -import com.juzi.oerp.model.dto.*; +import com.juzi.oerp.model.dto.ChangePasswordDTO; +import com.juzi.oerp.model.dto.RetrieveUserDTO; +import com.juzi.oerp.model.dto.UserPasswordLoginDTO; +import com.juzi.oerp.model.dto.UserRegistionDTO; +import com.juzi.oerp.model.dto.UserSMSLoginDTO; import com.juzi.oerp.model.dto.param.CheckImageCaptchaParamDTO; import com.juzi.oerp.model.dto.param.CheckSMSCaptchaParamDTO; import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; @@ -70,12 +74,14 @@ public interface AuthenticationService { /** * 修改用户密码 + * * @param changePasswordDTO 用户修改密码 */ void updatePassword(ChangePasswordDTO changePasswordDTO); /** * 重置密码 + * * @param retrieveUserDTO * @return */ diff --git a/src/main/java/com/juzi/oerp/service/UserInfoService.java b/src/main/java/com/juzi/oerp/service/UserInfoService.java index 4263b80..c2bc520 100644 --- a/src/main/java/com/juzi/oerp/service/UserInfoService.java +++ b/src/main/java/com/juzi/oerp/service/UserInfoService.java @@ -2,6 +2,8 @@ import com.juzi.oerp.model.po.UserInfoPO; import com.baomidou.mybatisplus.extension.service.IService; +import com.juzi.oerp.model.po.UserPO; +import com.juzi.oerp.model.vo.UserInfoVO; /** *

@@ -12,5 +14,11 @@ * @since 2020-07-14 */ public interface UserInfoService extends IService { - + /** + * 获取用户完整信息 + * + * @param userPO 用户账号手机号信息 + * @return 用户完整信息 + */ + UserInfoVO getUserInfoAll(UserPO userPO); } diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index 7709e41..ea89142 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -34,9 +34,9 @@ import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.model.vo.UserLoginVO; import com.juzi.oerp.service.AuthenticationService; +import com.juzi.oerp.service.UserInfoService; import com.juzi.oerp.util.JWTUtils; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.stereotype.Service; @@ -71,6 +71,9 @@ public class AuthenticationServiceImpl implements AuthenticationService { @Resource private Cache imageCaptchaCache; + @Autowired + private UserInfoService userInfoService; + @Override public UserLoginVO loginByPassword(UserPasswordLoginDTO userPasswordLoginDTO) { UserPO userPO = new UserPO(); @@ -85,14 +88,7 @@ public UserLoginVO loginByPassword(UserPasswordLoginDTO userPasswordLoginDTO) { } String token = JWTUtils.createToken(user.getId()); - UserInfoPO userInfo = userInfoMapper.selectOne(new LambdaQueryWrapper().eq(UserInfoPO::getUserId, user.getId())); - - UserInfoVO userInfoVO = new UserInfoVO(); - BeanUtils.copyProperties(userInfo,userInfoVO); - userInfoVO - .setUsername(user.getUsername()) - .setPhoneNumber(user.getPhoneNumber()); - + UserInfoVO userInfoVO = userInfoService.getUserInfoAll(user); UserLoginVO userLoginVO = new UserLoginVO(); userLoginVO .setToken(token) @@ -113,14 +109,7 @@ public UserLoginVO loginBySMS(UserSMSLoginDTO userSMSLoginDTO) { } String token = JWTUtils.createToken(user.getId()); - UserInfoPO userInfo = userInfoMapper.selectOne(new LambdaQueryWrapper().eq(UserInfoPO::getUserId, user.getId())); - - UserInfoVO userInfoVO = new UserInfoVO(); - BeanUtils.copyProperties(userInfo,userInfoVO); - userInfoVO - .setUsername(user.getUsername()) - .setPhoneNumber(user.getPhoneNumber()); - + UserInfoVO userInfoVO = userInfoService.getUserInfoAll(user); UserLoginVO userLoginVO = new UserLoginVO(); userLoginVO .setToken(token) diff --git a/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java index aeaadb7..2db70c0 100644 --- a/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java @@ -1,9 +1,14 @@ package com.juzi.oerp.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.juzi.oerp.mapper.UserInfoMapper; import com.juzi.oerp.model.po.UserInfoPO; +import com.juzi.oerp.model.po.UserPO; +import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.service.UserInfoService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; /** @@ -17,4 +22,18 @@ @Service public class UserInfoServiceImpl extends ServiceImpl implements UserInfoService { + @Autowired + private UserInfoMapper userInfoMapper; + + @Override + public UserInfoVO getUserInfoAll(UserPO user) { + UserInfoPO userInfo = userInfoMapper.selectById(user.getId()); + + UserInfoVO userInfoVO = new UserInfoVO(); + BeanUtils.copyProperties(userInfo,userInfoVO); + userInfoVO + .setUsername(user.getUsername()) + .setPhoneNumber(user.getPhoneNumber()); + return userInfoVO; + } } From e830b2c5d8d661c1497a4b38d332cca4e076a338 Mon Sep 17 00:00:00 2001 From: zshifu <33325044+zshifu@users.noreply.github.com> Date: Sat, 25 Jul 2020 12:08:23 +0800 Subject: [PATCH 59/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=83=A8?= =?UTF-8?q?=E5=88=86=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增接口: 修改密码 找回密码 修改手机 --- .../controller/AuthenticationController.java | 23 +++++++----- .../dto/ChangePasswordByPhoneNumDTO.java | 17 +++++++++ .../oerp/service/AuthenticationService.java | 16 +++++++++ .../impl/AuthenticationServiceImpl.java | 36 ++++++++++++------- src/main/resources/code-message.properties | 1 + 5 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/juzi/oerp/model/dto/ChangePasswordByPhoneNumDTO.java diff --git a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java index 4861b46..6b27b67 100644 --- a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java +++ b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java @@ -1,6 +1,6 @@ package com.juzi.oerp.controller; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.core.JsonProcessingException; import com.juzi.oerp.common.exception.AuthenticationException; import com.juzi.oerp.mapper.UserMapper; @@ -94,25 +94,32 @@ public MessageResponseVO checkSMSCaptcha(@RequestBody CheckSMSCaptchaParamDTO ch return new MessageResponseVO(20001); } - @PutMapping("/change") - @ApiOperation("修改密码") - public MessageResponseVO passwordChange(@RequestBody ChangePasswordDTO changePasswordDTO) { + @PutMapping("/password") + @ApiOperation(value = "修改密码", notes = "通过原密码修改密码") + public MessageResponseVO updatePassword(@RequestBody ChangePasswordDTO changePasswordDTO) { authenticationService.updatePassword(changePasswordDTO); return new MessageResponseVO(20010); } - @GetMapping("/retrieve/{phoneNumber}") + @PutMapping("/phone/{phoneNumber}") + @ApiOperation(value = "修改手机号") + public MessageResponseVO updatePhoneNumber(@PathVariable String phoneNumber) { + authenticationService.updatePhoneNumber(phoneNumber); + return new MessageResponseVO(20010); + } + + @GetMapping("/phone/{phoneNumber}") @ApiOperation(value = "检测手机号", notes = "判断该手机号是否已经注册过") public MessageResponseVO retrieveUserByPhone(@PathVariable String phoneNumber) { - UserPO userPO = userMapper.selectOne(new QueryWrapper().eq("phone_number", phoneNumber)); + UserPO userPO = userMapper.selectOne(new LambdaQueryWrapper().eq(UserPO::getPhoneNumber, phoneNumber)); if (userPO == null) { throw new AuthenticationException(40010); } return new MessageResponseVO(20008); } - @PutMapping("/retrieve") - @ApiOperation(value = "重置密码", notes = "通过手机验证码重置密码") + @PutMapping("/password/sms") + @ApiOperation(value = "重置密码", notes = "通过短信验证码重置密码") public MessageResponseVO retrieveUser(@RequestBody RetrieveUserDTO retrieveUserDTO) { authenticationService.resetPassword(retrieveUserDTO); return new MessageResponseVO(20010); diff --git a/src/main/java/com/juzi/oerp/model/dto/ChangePasswordByPhoneNumDTO.java b/src/main/java/com/juzi/oerp/model/dto/ChangePasswordByPhoneNumDTO.java new file mode 100644 index 0000000..10caa6d --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/dto/ChangePasswordByPhoneNumDTO.java @@ -0,0 +1,17 @@ +package com.juzi.oerp.model.dto; + +import lombok.Data; + +@Data +public class ChangePasswordByPhoneNumDTO { + + /** + * 用户新密码 + */ + private String newPassword; + + /** + * 用户手机号 + */ + private String phoneNumber; +} diff --git a/src/main/java/com/juzi/oerp/service/AuthenticationService.java b/src/main/java/com/juzi/oerp/service/AuthenticationService.java index 633664c..1e961f8 100644 --- a/src/main/java/com/juzi/oerp/service/AuthenticationService.java +++ b/src/main/java/com/juzi/oerp/service/AuthenticationService.java @@ -1,6 +1,7 @@ package com.juzi.oerp.service; import com.fasterxml.jackson.core.JsonProcessingException; +import com.juzi.oerp.model.dto.ChangePasswordByPhoneNumDTO; import com.juzi.oerp.model.dto.ChangePasswordDTO; import com.juzi.oerp.model.dto.RetrieveUserDTO; import com.juzi.oerp.model.dto.UserPasswordLoginDTO; @@ -40,6 +41,7 @@ public interface AuthenticationService { * 用户注册 * * @param userRegistionDTO 注册信息 + * @return 用户 token 和个人信息 */ UserLoginVO registion(UserRegistionDTO userRegistionDTO); @@ -79,6 +81,20 @@ public interface AuthenticationService { */ void updatePassword(ChangePasswordDTO changePasswordDTO); + /** + * 修改用户密码,通过手机号 + * + * @param changePasswordByPhoneNumDTO 用户修改密码 + */ + void updatePassword(ChangePasswordByPhoneNumDTO changePasswordByPhoneNumDTO); + + /** + * 修改用户手机号 + * + * @param phoneNumber 手机号 + */ + void updatePhoneNumber(String phoneNumber); + /** * 重置密码 * diff --git a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java index ea89142..94ca0b5 100644 --- a/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/AuthenticationServiceImpl.java @@ -20,11 +20,7 @@ import com.juzi.oerp.common.store.LocalUserStore; import com.juzi.oerp.mapper.UserInfoMapper; import com.juzi.oerp.mapper.UserMapper; -import com.juzi.oerp.model.dto.ChangePasswordDTO; -import com.juzi.oerp.model.dto.RetrieveUserDTO; -import com.juzi.oerp.model.dto.UserPasswordLoginDTO; -import com.juzi.oerp.model.dto.UserRegistionDTO; -import com.juzi.oerp.model.dto.UserSMSLoginDTO; +import com.juzi.oerp.model.dto.*; import com.juzi.oerp.model.dto.param.CheckImageCaptchaParamDTO; import com.juzi.oerp.model.dto.param.CheckSMSCaptchaParamDTO; import com.juzi.oerp.model.dto.param.SMSCaptchaParamDTO; @@ -258,21 +254,37 @@ private void checkPhoneNumberValidated(String phoneNumber) { } @Override - @Transactional(rollbackFor = RuntimeException.class) + public void updatePhoneNumber(String phoneNumber) { + checkPhoneNumberValidated(phoneNumber); + + UserPO userPO=userMapper.selectById(LocalUserStore.getLocalUser()); + userPO.setPhoneNumber(phoneNumber); + userMapper.updateById(userPO); + } + + @Override public void updatePassword(ChangePasswordDTO changePasswordDTO) { - UserPO userPO = null; - //如果未登录会出现空指针异常 - userPO = userMapper.selectById(LocalUserStore.getLocalUser()); + UserPO userPO = userMapper.selectById(LocalUserStore.getLocalUser()); String oldPassword = userPO.getPassword(); //传过来的密码加密 String dtoNewPassword = SecureUtil.md5(changePasswordDTO.getNewPassword()); String dtoOldPassword = SecureUtil.md5(changePasswordDTO.getOldPassword()); if (!oldPassword.equals(dtoOldPassword)) { throw new AuthenticationException(40011); - } else { - userPO.setPassword(dtoNewPassword); - userMapper.updateById(userPO); } + + userPO.setPassword(dtoNewPassword); + userMapper.updateById(userPO); + } + + @Override + public void updatePassword(ChangePasswordByPhoneNumDTO changePasswordByPhoneNumDTO) { + this.checkPhoneNumberValidated(changePasswordByPhoneNumDTO.getPhoneNumber()); + UserPO userPO = userMapper.selectById(LocalUserStore.getLocalUser()); + //传过来的密码加密 + String dtoNewPassword= SecureUtil.md5(changePasswordByPhoneNumDTO.getNewPassword()); + userPO.setPassword(dtoNewPassword); + userMapper.updateById(userPO); } @Override diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 5f53bda..9b3e764 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -6,6 +6,7 @@ codeMessage[20005]=\u652F\u4ED8\u6210\u529F codeMessage[20006]=\u65B0\u589E\u7528\u6237\u6210\u529F codeMessage[20007]=\u4FEE\u6539\u7528\u6237\u6210\u529F codeMessage[20008]=\u624B\u673A\u53F7\u6B63\u786E +codeMessage[20009]=\u624B\u673A\u53F7\u5DF2\u9A8C\u8BC1 codeMessage[20010]=\u4FEE\u6539\u6210\u529F From 95680f2afd23df2079277185d5c4cdd33f96913f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 12:13:48 +0800 Subject: [PATCH 60/70] =?UTF-8?q?refacotr:=20=E9=87=8D=E6=9E=84=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E8=80=83=E8=AF=95=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/juzi/oerp/controller/user/ExamController.java | 9 ++++----- src/main/java/com/juzi/oerp/service/ExamService.java | 3 +-- .../java/com/juzi/oerp/service/impl/ExamServiceImpl.java | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/user/ExamController.java b/src/main/java/com/juzi/oerp/controller/user/ExamController.java index 97e54e0..0216a6c 100644 --- a/src/main/java/com/juzi/oerp/controller/user/ExamController.java +++ b/src/main/java/com/juzi/oerp/controller/user/ExamController.java @@ -1,7 +1,6 @@ package com.juzi.oerp.controller.user; import com.baomidou.mybatisplus.core.metadata.IPage; -import com.fasterxml.jackson.databind.ObjectMapper; import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.ExamApplyInfoVO; @@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -39,8 +37,8 @@ public class ExamController { */ @GetMapping @ApiOperation("获取考试简要信息") - public ResponseVO> getExamPlainInfoByPage(PageParamDTO pageParamDTO, @ApiParam("搜索关键字") @RequestParam(required = false) String keyword) { - IPage result = examService.getExamPlainInfoByPage(pageParamDTO,keyword); + public ResponseVO> getExamPlainInfoByPage(PageParamDTO pageParamDTO) { + IPage result = examService.getExamPlainInfoByPage(pageParamDTO); return new ResponseVO<>(result); } @@ -59,12 +57,13 @@ public ResponseVO getExamDetailInfoById(@ApiParam("考试id") @PathVaria /** * 获取考试报名信息 + * * @param examId 考试id * @return 考试报名信息 */ @GetMapping("/apply/{examId}") @ApiOperation("获取考试报名信息") - public ResponseVO getExamApplyInfoById(@ApiParam("考试id") @PathVariable Integer examId){ + public ResponseVO getExamApplyInfoById(@ApiParam("考试id") @PathVariable Integer examId) { ExamApplyInfoVO result = examService.getExamApplyInfoById(examId); return new ResponseVO<>(result); } diff --git a/src/main/java/com/juzi/oerp/service/ExamService.java b/src/main/java/com/juzi/oerp/service/ExamService.java index c63a183..d4a1c26 100644 --- a/src/main/java/com/juzi/oerp/service/ExamService.java +++ b/src/main/java/com/juzi/oerp/service/ExamService.java @@ -19,10 +19,9 @@ public interface ExamService extends IService { * 获取考试简要信息_分页 * * @param pageParamDTO 分页参数 - * @param keyword 搜索关键字 * @return 考试简要信息 */ - IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO, String keyword); + IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO); /** * 获取考试详细信息 diff --git a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java index 3e91a1a..42fe892 100644 --- a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java @@ -42,11 +42,11 @@ public class ExamServiceImpl extends ServiceImpl implements private ExamDAO examDAO; @Override - public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO, String keyword) { + public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO) { IPage page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .select(ExamPO::getTitle, ExamPO::getImageUrl, ExamPO::getDescription, ExamPO::getId) - .like(!StringUtils.isEmpty(keyword), ExamPO::getTitle, keyword) + .like(!StringUtils.isEmpty(pageParamDTO.getKeyword()), ExamPO::getTitle, pageParamDTO.getKeyword()) .orderByDesc(ExamPO::getCreateTime); return examMapper.selectPage(page, queryWrapper); } From 5b73b57fb32302ac703be70f20bac78f5b71e24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 14:32:35 +0800 Subject: [PATCH 61/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E8=BF=87=E5=A4=A7=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/ExceptionController.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/ExceptionController.java b/src/main/java/com/juzi/oerp/controller/ExceptionController.java index a8b8a59..083e815 100644 --- a/src/main/java/com/juzi/oerp/controller/ExceptionController.java +++ b/src/main/java/com/juzi/oerp/controller/ExceptionController.java @@ -2,7 +2,7 @@ import com.juzi.oerp.common.exception.OERPException; import com.juzi.oerp.configuration.properties.CodeMessageProperties; -import com.juzi.oerp.model.vo.response.ExceptionResponseVO; +import com.juzi.oerp.model.vo.response.MessageResponseVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; +import org.springframework.web.multipart.MaxUploadSizeExceededException; /** * 异常统一处理 @@ -34,7 +35,7 @@ public class ExceptionController { */ @ExceptionHandler(OERPException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public ExceptionResponseVO exceptionResponseVO(OERPException oerpException) { + public MessageResponseVO exceptionResponseVO(OERPException oerpException) { Integer code = oerpException.getCode(); String codeMessage = codeMessageProperties.getCodeMessage().get(code); if (StringUtils.isEmpty(codeMessage)) { @@ -42,7 +43,7 @@ public ExceptionResponseVO exceptionResponseVO(OERPException oerpException) { } log.error(codeMessage); - return new ExceptionResponseVO(code, codeMessage); + return new MessageResponseVO(code, codeMessage); } /** @@ -53,9 +54,9 @@ public ExceptionResponseVO exceptionResponseVO(OERPException oerpException) { */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) - public ExceptionResponseVO methodArgumentNotValidException(MethodArgumentNotValidException methodArgumentNotValidException) { + public MessageResponseVO methodArgumentNotValidException(MethodArgumentNotValidException methodArgumentNotValidException) { String validMessage = methodArgumentNotValidException.getBindingResult().getAllErrors().get(0).getDefaultMessage(); - return new ExceptionResponseVO(40000, validMessage); + return new MessageResponseVO(40000, validMessage); } /** @@ -66,8 +67,20 @@ public ExceptionResponseVO methodArgumentNotValidException(MethodArgumentNotVali */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentTypeMismatchException.class) - public ExceptionResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { - return new ExceptionResponseVO(40000, "参数转换错误,请检查参数格式"); + public MessageResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { + return new MessageResponseVO(40000); + } + + /** + * 上传的文件超时限制的大小 + * + * @param e 文件过大异常 + * @return 异常信息 + */ + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MaxUploadSizeExceededException.class) + public MessageResponseVO maxUploadSizeExceededException(MaxUploadSizeExceededException e) { + return new MessageResponseVO(40013); } /** @@ -78,9 +91,9 @@ public ExceptionResponseVO methodArgumentTypeMismatchException(MethodArgumentTyp */ @ExceptionHandler(RuntimeException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public ExceptionResponseVO runtimeException(RuntimeException runtimeException) { + public MessageResponseVO runtimeException(RuntimeException runtimeException) { log.error("系统出现未知错误", runtimeException); - return new ExceptionResponseVO(50000, "系统未知错误"); + return new MessageResponseVO(50000); } } From 84fe4d9f00792587f85991522cfcd039a0791121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 14:38:58 +0800 Subject: [PATCH 62/70] =?UTF-8?q?refacotr:=20=E8=AE=A4=E8=AF=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=87=8D=E6=96=B0=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AuthenticationController.java | 24 +++++++++---------- src/main/resources/code-message.properties | 3 +++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java index 6b27b67..4a52fda 100644 --- a/src/main/java/com/juzi/oerp/controller/AuthenticationController.java +++ b/src/main/java/com/juzi/oerp/controller/AuthenticationController.java @@ -18,7 +18,6 @@ import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.AuthenticationService; -import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; @@ -35,7 +34,6 @@ * @date 2020/7/14 14:40 */ @RestController -@Api(tags = "身份认证") @RequestMapping("/auth") public class AuthenticationController { @@ -46,70 +44,70 @@ public class AuthenticationController { private UserMapper userMapper; @PostMapping("/login") - @ApiOperation(value = "密码登录") + @ApiOperation(value = "密码登录", tags = "登录注册") public ResponseVO loginByPassword(@RequestBody @Validated UserPasswordLoginDTO userPasswordLoginDTO) { UserLoginVO result = authenticationService.loginByPassword(userPasswordLoginDTO); return new ResponseVO<>(result); } @PostMapping("/login/sms") - @ApiOperation(value = "短信登录") + @ApiOperation(value = "短信登录", tags = "登录注册") public ResponseVO loginBySMS(@RequestBody UserSMSLoginDTO userSMSLoginDTO) { UserLoginVO result = authenticationService.loginBySMS(userSMSLoginDTO); return new ResponseVO<>(result); } @PostMapping("/registion") - @ApiOperation("账号注册") + @ApiOperation(value = "账号注册", tags = "登录注册") public ResponseVO registion(@RequestBody UserRegistionDTO userRegistionDTO) { UserLoginVO result = authenticationService.registion(userRegistionDTO); return new ResponseVO<>(result); } @GetMapping("/captcha/image") - @ApiOperation("获取图片验证码") + @ApiOperation(value = "获取图片验证码", tags = "验证码") public ResponseVO getImageCaptcha() { CaptchaVO captcha = authenticationService.getImageCaptcha(); return new ResponseVO<>(captcha); } @PostMapping("/captcha/image") - @ApiOperation("校验图片验证码") + @ApiOperation(value = "校验图片验证码", tags = "验证码") public MessageResponseVO checkImageCaptcha(@RequestBody CheckImageCaptchaParamDTO checkImageCaptchaParamDTO) { authenticationService.checkImageCaptcha(checkImageCaptchaParamDTO); return new MessageResponseVO(20001); } @PostMapping("/captcha/sms") - @ApiOperation("获取短信验证码") + @ApiOperation(value = "获取短信验证码", tags = "验证码") public MessageResponseVO getSMSCaptcha(@RequestBody SMSCaptchaParamDTO smsCaptchaParamDTO) throws JsonProcessingException { authenticationService.getSMSCaptcha(smsCaptchaParamDTO); return new MessageResponseVO(20002); } @PostMapping("/captcha/sms/check") - @ApiOperation("校验短信验证码") + @ApiOperation(value = "校验短信验证码", tags = "验证码") public MessageResponseVO checkSMSCaptcha(@RequestBody CheckSMSCaptchaParamDTO checkSMSCaptchaParamDTO) { authenticationService.checkSMSCaptcha(checkSMSCaptchaParamDTO); return new MessageResponseVO(20001); } @PutMapping("/password") - @ApiOperation(value = "修改密码", notes = "通过原密码修改密码") + @ApiOperation(value = "修改密码", notes = "通过原密码修改密码", tags = "账户信息") public MessageResponseVO updatePassword(@RequestBody ChangePasswordDTO changePasswordDTO) { authenticationService.updatePassword(changePasswordDTO); return new MessageResponseVO(20010); } @PutMapping("/phone/{phoneNumber}") - @ApiOperation(value = "修改手机号") + @ApiOperation(value = "修改手机号", tags = "账户信息") public MessageResponseVO updatePhoneNumber(@PathVariable String phoneNumber) { authenticationService.updatePhoneNumber(phoneNumber); return new MessageResponseVO(20010); } @GetMapping("/phone/{phoneNumber}") - @ApiOperation(value = "检测手机号", notes = "判断该手机号是否已经注册过") + @ApiOperation(value = "检测手机号", notes = "判断该手机号是否已经注册过", tags = "登录注册") public MessageResponseVO retrieveUserByPhone(@PathVariable String phoneNumber) { UserPO userPO = userMapper.selectOne(new LambdaQueryWrapper().eq(UserPO::getPhoneNumber, phoneNumber)); if (userPO == null) { @@ -119,7 +117,7 @@ public MessageResponseVO retrieveUserByPhone(@PathVariable String phoneNumber) { } @PutMapping("/password/sms") - @ApiOperation(value = "重置密码", notes = "通过短信验证码重置密码") + @ApiOperation(value = "重置密码", notes = "通过短信验证码重置密码", tags = "账户信息") public MessageResponseVO retrieveUser(@RequestBody RetrieveUserDTO retrieveUserDTO) { authenticationService.resetPassword(retrieveUserDTO); return new MessageResponseVO(20010); diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 9b3e764..0b1585a 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -22,6 +22,9 @@ codeMessage[40009]=\u8BF7\u5148\u767B\u5F55 codeMessage[40010]=\u624B\u673A\u53F7\u9519\u8BEF codeMessage[40011]=\u65E7\u5BC6\u7801\u8F93\u5165\u9519\u8BEF codeMessage[40012]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 +codeMessage[40013]=\u6587\u4EF6\u8FC7\u5927\uFF0C\u8BF7\u66F4\u6362\u6587\u4EF6 +codeMessage[40014]=\u53C2\u6570\u8F6C\u6362\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u53C2\u6570\u683C\u5F0F +codeMessage[50000]=\u7CFB\u7EDF\u672A\u77E5\u9519\u8BEF codeMessage[50001]=\u9A8C\u8BC1\u7801\u670D\u52A1\u914D\u7F6E\u51FA\u9519 codeMessage[50002]=\u7F13\u5B58\u52A0\u8F7D\u5931\u8D25 From 5a8e1256d08fa3b78487614f6315aaf742194a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 14:40:12 +0800 Subject: [PATCH 63/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E9=99=90?= =?UTF-8?q?=E5=88=B6=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2eeed0b..db7e174 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,6 +12,9 @@ spring: - SMS_CAPTCHA_CACHE couchbase: expiration: 300 + servlet: + multipart: + max-file-size: 10MB mybatis-plus: configuration: From 7707db916c1b135790a949945617f83e07ce882a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 16:39:31 +0800 Subject: [PATCH 64/70] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Controller=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=BF=94=E5=9B=9E=20null=20aop=20=E6=8A=A5?= =?UTF-8?q?=20NPE=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/juzi/oerp/common/aop/ControllerResponseAOP.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java b/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java index a11f72d..be3e78f 100644 --- a/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java +++ b/src/main/java/com/juzi/oerp/common/aop/ControllerResponseAOP.java @@ -20,6 +20,10 @@ public class ControllerResponseAOP { @AfterReturning(returning = "messageResponseVO", pointcut = "execution(public * com.juzi.oerp.controller..*.*(..))") public void doAfterReturning(MessageResponseVO messageResponseVO) { + if(messageResponseVO==null){ + return; + } + int code = messageResponseVO.getCode(); String oldMessage = messageResponseVO.getMessage(); String newMessage = codeMessageProperties.getCodeMessage().get(code); From e58cf9b2e61c0b404f94d7a7f8e565dc30e11dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 17:03:53 +0800 Subject: [PATCH 65/70] =?UTF-8?q?fix:=20=E5=B0=86=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E6=8E=A5=E5=8F=A3=E4=BB=8E=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E5=99=A8=E4=B8=AD=E6=8E=92=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/juzi/oerp/configuration/SpringMvcConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index 319419b..c355fe0 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -84,6 +84,7 @@ public void addInterceptors(InterceptorRegistry registry) { "/auth/login/**", "/auth/registion", "/auth/captcha/**", + "/auth/password/sms", "/user/exam", "/user/exam/*", "/webjars/**", From 09b94d68c151b6bce5198a809ad34feb59e26809 Mon Sep 17 00:00:00 2001 From: zshifu <33325044+zshifu@users.noreply.github.com> Date: Sun, 26 Jul 2020 16:44:09 +0800 Subject: [PATCH 66/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=94=A8=E6=88=B7=E5=B7=B2=E6=8A=A5=E5=90=8D=E8=80=83?= =?UTF-8?q?=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/user/UserController.java | 8 +++++ src/main/java/com/juzi/oerp/dao/UserDAO.java | 5 +++ .../juzi/oerp/model/vo/UserApplyExamVO.java | 35 +++++++++++++++++++ .../juzi/oerp/service/UserInfoService.java | 5 +++ .../service/impl/UserInfoServiceImpl.java | 15 +++++++- .../resources/mybatis/xml/dao/UserDAO.xml | 32 +++++++++++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/juzi/oerp/model/vo/UserApplyExamVO.java diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java index 6644e33..7ffd79f 100644 --- a/src/main/java/com/juzi/oerp/controller/user/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -1,10 +1,13 @@ package com.juzi.oerp.controller.user; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.juzi.oerp.common.store.LocalUserStore; import com.juzi.oerp.model.dto.UpdateUserInfoDTO; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.UserInfoPO; import com.juzi.oerp.model.po.UserPO; import com.juzi.oerp.model.vo.UserInfoVO; +import com.juzi.oerp.model.vo.UserApplyExamVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.model.vo.response.UpdatedResponseVO; import com.juzi.oerp.service.UserInfoService; @@ -55,4 +58,9 @@ public UpdatedResponseVO updateUserInfo(@RequestBody UpdateUserInfoDTO updateUse return new UpdatedResponseVO(); } + @GetMapping("/apply") + public ResponseVO> getUserApplyExam(@RequestBody PageParamDTO pageParamDTO){ + Page result = userInfoService.queryUserApplyExam(pageParamDTO); + return new ResponseVO<>(result); + } } diff --git a/src/main/java/com/juzi/oerp/dao/UserDAO.java b/src/main/java/com/juzi/oerp/dao/UserDAO.java index eee4c27..c2c521a 100644 --- a/src/main/java/com/juzi/oerp/dao/UserDAO.java +++ b/src/main/java/com/juzi/oerp/dao/UserDAO.java @@ -2,9 +2,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.juzi.oerp.model.vo.UserApplyExamVO; import com.juzi.oerp.model.vo.UserInfoVO; import org.apache.ibatis.annotations.Param; +import java.util.List; + /** * @author Juzi * @date 2020/7/15 14:08 @@ -26,4 +29,6 @@ public interface UserDAO { * @return 用户信息 */ UserInfoVO getUserByUserId(@Param("userId") Integer userId); + + IPage getUserApplyExam(@Param("page") Page page, @Param("userId") Integer userId,@Param("title")String title); } diff --git a/src/main/java/com/juzi/oerp/model/vo/UserApplyExamVO.java b/src/main/java/com/juzi/oerp/model/vo/UserApplyExamVO.java new file mode 100644 index 0000000..e11be53 --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/vo/UserApplyExamVO.java @@ -0,0 +1,35 @@ +package com.juzi.oerp.model.vo; + +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +public class UserApplyExamVO { + + /** + * 考试名称 + */ + private String title; + + /** + * 考试地点 + */ + private String examPlace; + + /** + * 开始时间 + */ + private LocalDateTime beginTime; + + /** + * 结束时间 + */ + private LocalDateTime endTime; + + /** + * 状态 + */ + private Integer status; + +} diff --git a/src/main/java/com/juzi/oerp/service/UserInfoService.java b/src/main/java/com/juzi/oerp/service/UserInfoService.java index c2bc520..db1ef47 100644 --- a/src/main/java/com/juzi/oerp/service/UserInfoService.java +++ b/src/main/java/com/juzi/oerp/service/UserInfoService.java @@ -1,9 +1,12 @@ package com.juzi.oerp.service; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.UserInfoPO; import com.baomidou.mybatisplus.extension.service.IService; import com.juzi.oerp.model.po.UserPO; import com.juzi.oerp.model.vo.UserInfoVO; +import com.juzi.oerp.model.vo.UserApplyExamVO; /** *

@@ -21,4 +24,6 @@ public interface UserInfoService extends IService { * @return 用户完整信息 */ UserInfoVO getUserInfoAll(UserPO userPO); + + Page queryUserApplyExam(PageParamDTO pageParamDTO); } diff --git a/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java index 2db70c0..02f71bf 100644 --- a/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/UserInfoServiceImpl.java @@ -1,8 +1,12 @@ package com.juzi.oerp.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.juzi.oerp.common.store.LocalUserStore; +import com.juzi.oerp.dao.UserDAO; import com.juzi.oerp.mapper.UserInfoMapper; +import com.juzi.oerp.model.dto.param.PageParamDTO; +import com.juzi.oerp.model.vo.UserApplyExamVO; import com.juzi.oerp.model.po.UserInfoPO; import com.juzi.oerp.model.po.UserPO; import com.juzi.oerp.model.vo.UserInfoVO; @@ -25,6 +29,9 @@ public class UserInfoServiceImpl extends ServiceImpl @Autowired private UserInfoMapper userInfoMapper; + @Autowired + private UserDAO userDAO; + @Override public UserInfoVO getUserInfoAll(UserPO user) { UserInfoPO userInfo = userInfoMapper.selectById(user.getId()); @@ -36,4 +43,10 @@ public UserInfoVO getUserInfoAll(UserPO user) { .setPhoneNumber(user.getPhoneNumber()); return userInfoVO; } + public Page queryUserApplyExam(PageParamDTO pageParamDTO){ + Page page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); + Integer userId= LocalUserStore.getLocalUser(); + userDAO.getUserApplyExam(page,userId,pageParamDTO.getKeyword()); + return page; + } } diff --git a/src/main/resources/mybatis/xml/dao/UserDAO.xml b/src/main/resources/mybatis/xml/dao/UserDAO.xml index c5ffc81..056a2ff 100644 --- a/src/main/resources/mybatis/xml/dao/UserDAO.xml +++ b/src/main/resources/mybatis/xml/dao/UserDAO.xml @@ -52,4 +52,36 @@ WHERE `user`.id = #{userId,jdbcType=INTEGER} + From 1cfc89f20d22bae3540904689cdf3e051bb607af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sat, 25 Jul 2020 20:56:55 +0800 Subject: [PATCH 67/70] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/ExceptionController.java | 37 +++++++++++-------- .../vo/response/ExceptionResponseVO.java | 23 +++++++++++- .../model/vo/response/MessageResponseVO.java | 2 + 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/juzi/oerp/controller/ExceptionController.java b/src/main/java/com/juzi/oerp/controller/ExceptionController.java index 083e815..aba5130 100644 --- a/src/main/java/com/juzi/oerp/controller/ExceptionController.java +++ b/src/main/java/com/juzi/oerp/controller/ExceptionController.java @@ -2,7 +2,7 @@ import com.juzi.oerp.common.exception.OERPException; import com.juzi.oerp.configuration.properties.CodeMessageProperties; -import com.juzi.oerp.model.vo.response.MessageResponseVO; +import com.juzi.oerp.model.vo.response.ExceptionResponseVO; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.multipart.MaxUploadSizeExceededException; +import org.springframework.web.multipart.support.MissingServletRequestPartException; /** * 异常统一处理 @@ -30,33 +31,33 @@ public class ExceptionController { /** * 系统自定义异常统一处理 * - * @param oerpException 系统异常 + * @param e 系统异常 * @return 异常信息 */ @ExceptionHandler(OERPException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) - public MessageResponseVO exceptionResponseVO(OERPException oerpException) { - Integer code = oerpException.getCode(); + public ExceptionResponseVO exceptionResponseVO(OERPException e) { + Integer code = e.getCode(); String codeMessage = codeMessageProperties.getCodeMessage().get(code); if (StringUtils.isEmpty(codeMessage)) { codeMessage = "未知错误"; } log.error(codeMessage); - return new MessageResponseVO(code, codeMessage); + return new ExceptionResponseVO(code, codeMessage, e.getMessage()); } /** * Bean Validator 参数校验异常处理 * - * @param methodArgumentNotValidException 参数校验异常 + * @param e 参数校验异常 * @return 异常信息 */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentNotValidException.class) - public MessageResponseVO methodArgumentNotValidException(MethodArgumentNotValidException methodArgumentNotValidException) { - String validMessage = methodArgumentNotValidException.getBindingResult().getAllErrors().get(0).getDefaultMessage(); - return new MessageResponseVO(40000, validMessage); + public ExceptionResponseVO methodArgumentNotValidException(MethodArgumentNotValidException e) { + String validMessage = e.getBindingResult().getAllErrors().get(0).getDefaultMessage(); + return new ExceptionResponseVO(40000, validMessage, e.getMessage()); } /** @@ -67,8 +68,8 @@ public MessageResponseVO methodArgumentNotValidException(MethodArgumentNotValidE */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentTypeMismatchException.class) - public MessageResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { - return new MessageResponseVO(40000); + public ExceptionResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { + return new ExceptionResponseVO(40000, e.getMessage()); } /** @@ -79,8 +80,14 @@ public MessageResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeM */ @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MaxUploadSizeExceededException.class) - public MessageResponseVO maxUploadSizeExceededException(MaxUploadSizeExceededException e) { - return new MessageResponseVO(40013); + public ExceptionResponseVO maxUploadSizeExceededException(MaxUploadSizeExceededException e) { + return new ExceptionResponseVO(40013, e.getMessage()); + } + + @ResponseStatus(HttpStatus.BAD_REQUEST) + @ExceptionHandler(MissingServletRequestPartException.class) + public ExceptionResponseVO missingServletRequestPartException(MissingServletRequestPartException e) { + return new ExceptionResponseVO(40015, e.getMessage()); } /** @@ -91,9 +98,9 @@ public MessageResponseVO maxUploadSizeExceededException(MaxUploadSizeExceededExc */ @ExceptionHandler(RuntimeException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public MessageResponseVO runtimeException(RuntimeException runtimeException) { + public ExceptionResponseVO runtimeException(RuntimeException runtimeException) { log.error("系统出现未知错误", runtimeException); - return new MessageResponseVO(50000); + return new ExceptionResponseVO(50000); } } diff --git a/src/main/java/com/juzi/oerp/model/vo/response/ExceptionResponseVO.java b/src/main/java/com/juzi/oerp/model/vo/response/ExceptionResponseVO.java index 235785e..4e76f10 100644 --- a/src/main/java/com/juzi/oerp/model/vo/response/ExceptionResponseVO.java +++ b/src/main/java/com/juzi/oerp/model/vo/response/ExceptionResponseVO.java @@ -1,13 +1,32 @@ package com.juzi.oerp.model.vo.response; +import lombok.Data; +import lombok.EqualsAndHashCode; + /** * 异常返回信息 * * @author Juzi * @date 2020/7/17 09:02 */ -public class ExceptionResponseVO extends ResponseVO { - public ExceptionResponseVO(Integer code, String message) { +@Data +@EqualsAndHashCode(callSuper = true) +public class ExceptionResponseVO extends MessageResponseVO { + + private String detail; + + public ExceptionResponseVO(Integer code) { + super(code); + } + + public ExceptionResponseVO(Integer code, String detail) { + super(code); + this.detail = detail; + } + + public ExceptionResponseVO(Integer code, String message, String detail) { super(code, message); + this.detail = detail; } + } diff --git a/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java b/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java index 701353c..4c4e82d 100644 --- a/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java +++ b/src/main/java/com/juzi/oerp/model/vo/response/MessageResponseVO.java @@ -1,12 +1,14 @@ package com.juzi.oerp.model.vo.response; import lombok.Data; +import lombok.EqualsAndHashCode; /** * @author Juzi * @date 2020/7/20 14:21 */ @Data +@EqualsAndHashCode(callSuper = true) public class MessageResponseVO extends ResponseVO { public MessageResponseVO(Integer code) { From 45c9b574a03fd02aa01aaf1cc21692a654159c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 26 Jul 2020 19:25:46 +0800 Subject: [PATCH 68/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E8=80=83=E8=AF=95=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + pom.xml | 7 ++ .../jackson/CreateExamParamDeserializer.java | 74 +++++++++++++++++++ .../configuration/SpringMvcConfiguration.java | 25 ++++--- .../oerp/controller/ExceptionController.java | 2 +- .../oerp/controller/admin/ExamController.java | 31 +++++++- .../model/dto/param/CreateExamParamDTO.java | 44 +++++++++++ .../dto/param/CreateExamPlaceParamDTO.java | 23 ++++++ .../com/juzi/oerp/service/ExamService.java | 13 ++++ .../oerp/service/impl/ExamServiceImpl.java | 55 +++++++++++++- .../com/juzi/oerp/util/UploadFileUtils.java | 45 +++++++++++ .../java/com/juzi/oerp/util/WordUtils.java | 31 ++++++++ src/main/resources/code-message.properties | 2 + 13 files changed, 339 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java create mode 100644 src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java create mode 100644 src/main/java/com/juzi/oerp/model/dto/param/CreateExamPlaceParamDTO.java create mode 100644 src/main/java/com/juzi/oerp/util/UploadFileUtils.java create mode 100644 src/main/java/com/juzi/oerp/util/WordUtils.java diff --git a/.gitignore b/.gitignore index 78eda15..7df938d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +assets/ #代码生成文件夹 ge/ ### IntelliJ IDEA ### diff --git a/pom.xml b/pom.xml index 33933df..2fa59fd 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,13 @@ org.springframework.boot spring-boot-starter-validation + + + fr.opensagres.xdocreport + fr.opensagres.poi.xwpf.converter.xhtml + 2.0.2 + + diff --git a/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java b/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java new file mode 100644 index 0000000..0644989 --- /dev/null +++ b/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java @@ -0,0 +1,74 @@ +package com.juzi.oerp.common.jackson; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.TreeNode; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.juzi.oerp.model.dto.param.CreateExamParamDTO; +import com.juzi.oerp.model.dto.param.CreateExamPlaceParamDTO; +import org.springframework.stereotype.Component; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Juzi + * @date 2020/7/25 21:10 + */ +@Component +public class CreateExamParamDeserializer extends JsonDeserializer { + @Override + public Class handledType() { + return CreateExamParamDTO.class; + } + + @Override + public CreateExamParamDTO deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + TreeNode treeNode = p.readValueAsTree(); + String title = treeNode.get("title").toString().replaceAll("\"", ""); + String description = treeNode.get("description").toString().replaceAll("\"", ""); + BigDecimal price = new BigDecimal(treeNode.get("price").toString()); + long beginTime = Long.parseLong(treeNode.get("beginTime").toString()) / 1000; + ZoneOffset zone = ZoneOffset.ofHours(8); + LocalDateTime beginTimeLocalDateTime = LocalDateTime.ofEpochSecond(beginTime, 0, zone); + + long endTime = Long.parseLong(treeNode.get("endTime").toString()) / 1000; + LocalDateTime endTimeLocalDateTime = LocalDateTime.ofEpochSecond(endTime, 0, zone); + + Map> timePlace = new HashMap<>(); + TreeNode timePlaceTreeNode = treeNode.get("timePlace"); + timePlaceTreeNode.fieldNames().forEachRemaining(time -> { + LocalDateTime examTime = LocalDateTime.ofEpochSecond(Long.parseLong(time) / 1000, 0, zone); + TreeNode timePlaceTressNodeArray = timePlaceTreeNode.get(time); + List createExamPlaceParamDTOList = new ArrayList<>(); + for (int i = 0; i < timePlaceTressNodeArray.size(); i++) { + // 考试地点 + String examPlace = timePlaceTressNodeArray.get(i).get("examPlace").toString().replaceAll("\"", ""); + // 考试人数 + int peopleNumber = Integer.parseInt(timePlaceTressNodeArray.get(i).get("peopleNumber").toString()); + CreateExamPlaceParamDTO createExamPlaceParamDTO = new CreateExamPlaceParamDTO(); + createExamPlaceParamDTO + .setExamPlace(examPlace) + .setPeopleNumber(peopleNumber); + createExamPlaceParamDTOList.add(createExamPlaceParamDTO); + } + timePlace.put(examTime, createExamPlaceParamDTOList); + }); + + CreateExamParamDTO createExamParamDTO = new CreateExamParamDTO(); + createExamParamDTO + .setTitle(title) + .setDescription(description) + .setPrice(price) + .setBeginTime(beginTimeLocalDateTime) + .setEndTime(endTimeLocalDateTime) + .setTimePlace(timePlace); + return createExamParamDTO; + } +} diff --git a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java index c355fe0..6a760ae 100644 --- a/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java +++ b/src/main/java/com/juzi/oerp/configuration/SpringMvcConfiguration.java @@ -7,6 +7,7 @@ import com.juzi.oerp.common.jackson.LocalDateTimeDeserializer; import com.juzi.oerp.common.jackson.LocalDateTimeKeySerializer; import com.juzi.oerp.common.jackson.LocalDateTimeSerializer; +import com.juzi.oerp.util.UploadFileUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -17,7 +18,6 @@ import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; -import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; @@ -67,6 +67,10 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) { registry .addResourceHandler("doc.html", "/webjars/**") .addResourceLocations("classpath:/META-INF/resources/", "classpath:/META-INF/resources/webjars/"); + + // classpath: or file: + registry.addResourceHandler("/assets/**/") + .addResourceLocations("file:" + UploadFileUtils.getAbsoluteWorkDirectory()); } /** @@ -81,14 +85,15 @@ public void addInterceptors(InterceptorRegistry registry) { .excludePathPatterns( "/", "/error", + "/user/exam", + "/assets/**", + "/webjars/**", + "/user/exam/*", + "/doc.html/**", "/auth/login/**", "/auth/registion", "/auth/captcha/**", "/auth/password/sms", - "/user/exam", - "/user/exam/*", - "/webjars/**", - "/doc.html/**", "/swagger-resources/**" ); @@ -101,13 +106,15 @@ public void addInterceptors(InterceptorRegistry registry) { */ @Override public void configureMessageConverters(List> converters) { - SimpleModule simpleModule = new SimpleModule(); - simpleModule.addKeySerializer(LocalDateTime.class, localDateTimeKeySerializer); + SimpleModule customModule = new SimpleModule(); + // Map 的 key 为 LocalDateTime 时,使用此序列化器 + customModule.addKeySerializer(LocalDateTime.class, localDateTimeKeySerializer); ObjectMapper objectMapper = Jackson2ObjectMapperBuilder .json() // 属性为 null 时不进行序列化 .serializationInclusion(JsonInclude.Include.NON_NULL) - .modules(simpleModule) + // 添加自定义模块 + .modules(customModule) // 指定 LocalDateTime 序列化器 .serializers(localDateTimeSerializer) // 指定 LocalDateTime 反序列化器 @@ -120,4 +127,4 @@ public void configureMessageConverters(List> converters) converters.add(stringHttpMessageConverter); } -} +} \ No newline at end of file diff --git a/src/main/java/com/juzi/oerp/controller/ExceptionController.java b/src/main/java/com/juzi/oerp/controller/ExceptionController.java index aba5130..cbc503e 100644 --- a/src/main/java/com/juzi/oerp/controller/ExceptionController.java +++ b/src/main/java/com/juzi/oerp/controller/ExceptionController.java @@ -69,7 +69,7 @@ public ExceptionResponseVO methodArgumentNotValidException(MethodArgumentNotVali @ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(MethodArgumentTypeMismatchException.class) public ExceptionResponseVO methodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { - return new ExceptionResponseVO(40000, e.getMessage()); + return new ExceptionResponseVO(40000, "参数格式错误", e.getMessage()); } /** diff --git a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java index f77a8ff..9aab3b1 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java @@ -1,14 +1,18 @@ package com.juzi.oerp.controller.admin; +import com.fasterxml.jackson.databind.ObjectMapper; import com.juzi.oerp.model.dto.UpdateExamDTO; +import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.response.DeleteResponseVO; import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; +import com.juzi.oerp.service.ExamService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -16,7 +20,11 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; /** * 考试管理 @@ -29,6 +37,17 @@ @RequestMapping("/admin/exam") public class ExamController { + @Autowired + private ExamService examService; + + @Autowired + private ObjectMapper objectMapper; + + @PostMapping("/test/test") + public void test(@RequestBody CreateExamParamDTO createExamParamDTO) { + + } + /** * 获取考试_分页 * @@ -68,13 +87,19 @@ public ResponseVO updateExamById(@RequestBody UpdateExamDTO updateExamDT /** * 创建考试 * - * @param updateExamDTO 考试信息 + * @param createExamParamDTO 考试信息 + * @param image 图片 + * @param word word 文档 * @return 创建成功信息 */ @PostMapping @ApiOperation("创建考试") - public MessageResponseVO createExam(@RequestBody UpdateExamDTO updateExamDTO) { - return new MessageResponseVO(20003); + public MessageResponseVO createExam( + @RequestPart(value = "exam") CreateExamParamDTO createExamParamDTO, + @RequestPart("image") MultipartFile image, + @RequestPart("word") MultipartFile word) throws IOException { + examService.createExam(createExamParamDTO, image, word); + return new MessageResponseVO(20011); } /** diff --git a/src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java new file mode 100644 index 0000000..7638c63 --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java @@ -0,0 +1,44 @@ +package com.juzi.oerp.model.dto.param; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.juzi.oerp.common.jackson.CreateExamParamDeserializer; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; + +/** + * 创建考试 + * + * @author Juzi + * @date 2020/7/25 13:48 + */ +@Data +@Accessors(chain = true) +@ApiModel(description = "创建考试参数") +@JsonDeserialize(using = CreateExamParamDeserializer.class) +public class CreateExamParamDTO { + + @ApiModelProperty("考试名称") + private String title; + + @ApiModelProperty("考试描述") + private String description; + + @ApiModelProperty("报名开始时间") + private LocalDateTime beginTime; + + @ApiModelProperty("报名截止时间") + private LocalDateTime endTime; + + @ApiModelProperty("报名费用") + private BigDecimal price; + + @ApiModelProperty("时间地点") + private Map> timePlace; +} diff --git a/src/main/java/com/juzi/oerp/model/dto/param/CreateExamPlaceParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/CreateExamPlaceParamDTO.java new file mode 100644 index 0000000..2cd8bdf --- /dev/null +++ b/src/main/java/com/juzi/oerp/model/dto/param/CreateExamPlaceParamDTO.java @@ -0,0 +1,23 @@ +package com.juzi.oerp.model.dto.param; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +/** + * @author Juzi + * @date 2020/7/25 20:10 + */ +@Data +@Accessors(chain = true) +@ApiModel(description = "创建考试参数") +public class CreateExamPlaceParamDTO { + + @ApiModelProperty("考试地点") + private String examPlace; + + @ApiModelProperty("限制人数;-1 无限制") + private Integer peopleNumber; + +} diff --git a/src/main/java/com/juzi/oerp/service/ExamService.java b/src/main/java/com/juzi/oerp/service/ExamService.java index d4a1c26..b97d265 100644 --- a/src/main/java/com/juzi/oerp/service/ExamService.java +++ b/src/main/java/com/juzi/oerp/service/ExamService.java @@ -2,9 +2,13 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; +import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.ExamApplyInfoVO; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; /** *

@@ -38,4 +42,13 @@ public interface ExamService extends IService { * @return 考试报名信息 */ ExamApplyInfoVO getExamApplyInfoById(Integer examId); + + /** + * 创建考试 - 管理员 + * + * @param createExamParamDTO 考试信息 + * @param image 图片 + * @param word 文档 + */ + void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile image, MultipartFile word) throws IOException; } diff --git a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java index 42fe892..8ac0a5b 100644 --- a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java @@ -1,6 +1,7 @@ package com.juzi.oerp.service.impl; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.io.FileUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -9,15 +10,25 @@ import com.juzi.oerp.dao.ExamDAO; import com.juzi.oerp.mapper.ExamMapper; import com.juzi.oerp.model.dto.ExamApplyInfoDTO; +import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.po.ExamPlacePO; +import com.juzi.oerp.model.po.ExamTimePO; import com.juzi.oerp.model.vo.ExamApplyInfoVO; +import com.juzi.oerp.service.ExamPlaceService; import com.juzi.oerp.service.ExamService; +import com.juzi.oerp.service.ExamTimeService; +import com.juzi.oerp.util.UploadFileUtils; +import com.juzi.oerp.util.WordUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -35,11 +46,17 @@ @Service public class ExamServiceImpl extends ServiceImpl implements ExamService { + @Autowired + private ExamDAO examDAO; + @Autowired private ExamMapper examMapper; @Autowired - private ExamDAO examDAO; + private ExamTimeService examTimeService; + + @Autowired + private ExamPlaceService examPlaceService; @Override public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO) { @@ -83,4 +100,40 @@ public ExamApplyInfoVO getExamApplyInfoById(Integer examId) { return examApplyInfoVO; } + + @Override + @Transactional(rollbackFor = RuntimeException.class) + public void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile image, MultipartFile word) throws IOException { + // 将 word 转换为 html + String html = WordUtils.docxToHTML(word.getInputStream()); + + // 上传图片 + String imagePath = UploadFileUtils.upload(image.getInputStream(), FileUtil.extName(image.getOriginalFilename())); + + ExamPO examPO = new ExamPO(); + BeanUtils.copyProperties(createExamParamDTO, examPO); + examPO + .setImageUrl(imagePath) + .setDetail(html); + examMapper.insert(examPO); + + // 批量插入考试时间 + List examTimePOList = createExamParamDTO.getTimePlace().keySet() + .stream().map(examTime -> new ExamTimePO() + .setExamId(examPO.getId()) + .setExamTime(examTime)).collect(toList()); + examTimeService.saveBatch(examTimePOList); + + // 批量插入考试地点 + List examPlacePOList = examTimePOList.stream().flatMap(examTime -> + createExamParamDTO.getTimePlace().get(examTime.getExamTime()).stream().map(examPlace -> { + ExamPlacePO examPlacePO = new ExamPlacePO(); + // 将参数信息 copy 到 PO 对象中 + BeanUtils.copyProperties(examPlace, examPlacePO); + // 将考试时间 id 和考试地点绑定 + return examPlacePO.setExamTimeId(examTime.getId()); + }).collect(toList()).stream() + ).collect(toList()); + examPlaceService.saveBatch(examPlacePOList); + } } diff --git a/src/main/java/com/juzi/oerp/util/UploadFileUtils.java b/src/main/java/com/juzi/oerp/util/UploadFileUtils.java new file mode 100644 index 0000000..4cb87f1 --- /dev/null +++ b/src/main/java/com/juzi/oerp/util/UploadFileUtils.java @@ -0,0 +1,45 @@ +package com.juzi.oerp.util; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.crypto.SecureUtil; +import lombok.extern.slf4j.Slf4j; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +/** + * 上传文件工具类 + * + * @author Juzi + * @date 2020/7/25 18:59 + */ +@Slf4j +public class UploadFileUtils { + + /** + * 上传文件工具类 + * + * @param inputStream 文件数据流 + * @param ext 扩展名(不带 .) + * @return 文件存储路径 + */ + public static String upload(InputStream inputStream, String ext) { + byte[] fileBytes = IoUtil.readBytes(inputStream); + + String workDirectory = FileUtil.normalize(System.getProperty("user.dir")); + String dateDirectory = LocalDate.now().format(DateTimeFormatter.ofPattern("/'assets'/yyyy/MM/dd/")); + String fileName = SecureUtil.md5(new ByteArrayInputStream(fileBytes)) + "." + ext; + + String fullDirectory = workDirectory + dateDirectory + fileName; + FileUtil.writeFromStream(new ByteArrayInputStream(fileBytes), fullDirectory); + return dateDirectory + fileName; + } + + public static String getAbsoluteWorkDirectory() { + return FileUtil.normalize(System.getProperty("user.dir")) + "/assets/"; + } + +} diff --git a/src/main/java/com/juzi/oerp/util/WordUtils.java b/src/main/java/com/juzi/oerp/util/WordUtils.java new file mode 100644 index 0000000..4a2140a --- /dev/null +++ b/src/main/java/com/juzi/oerp/util/WordUtils.java @@ -0,0 +1,31 @@ +package com.juzi.oerp.util; + +import fr.opensagres.poi.xwpf.converter.xhtml.Base64EmbedImgManager; +import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLConverter; +import fr.opensagres.poi.xwpf.converter.xhtml.XHTMLOptions; +import org.apache.poi.xwpf.usermodel.XWPFDocument; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Juzi + * @date 2020/7/25 20:17 + */ +public class WordUtils { + /** + * 将 word(docx) 转换为 html + * + * @param inputStream 文件数据流 + * @return html 文本 + * @throws IOException IO异常 + */ + public static String docxToHTML(InputStream inputStream) throws IOException { + XWPFDocument document = new XWPFDocument(inputStream); + XHTMLOptions options = XHTMLOptions.create().indent(4).setImageManager(new Base64EmbedImgManager()); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + XHTMLConverter.getInstance().convert(document, byteArrayOutputStream, options); + return byteArrayOutputStream.toString(); + } +} diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 0b1585a..5f05421 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -8,6 +8,7 @@ codeMessage[20007]=\u4FEE\u6539\u7528\u6237\u6210\u529F codeMessage[20008]=\u624B\u673A\u53F7\u6B63\u786E codeMessage[20009]=\u624B\u673A\u53F7\u5DF2\u9A8C\u8BC1 codeMessage[20010]=\u4FEE\u6539\u6210\u529F +codeMessage[20011]=\u521B\u5EFA\u6210\u529F codeMessage[40001]=\u624B\u673A\u53F7\u5DF2\u88AB\u6CE8\u518C\uFF0C\u8BF7\u66F4\u6362\u624B\u673A\u53F7\u518D\u8BD5 @@ -24,6 +25,7 @@ codeMessage[40011]=\u65E7\u5BC6\u7801\u8F93\u5165\u9519\u8BEF codeMessage[40012]=\u9A8C\u8BC1\u7801 ID \u65E0\u6548 codeMessage[40013]=\u6587\u4EF6\u8FC7\u5927\uFF0C\u8BF7\u66F4\u6362\u6587\u4EF6 codeMessage[40014]=\u53C2\u6570\u8F6C\u6362\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u53C2\u6570\u683C\u5F0F +codeMessage[40015]=\u8BF7\u6C42\u53C2\u6570\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u68C0\u67E5\u53C2\u6570\u5217\u8868 codeMessage[50000]=\u7CFB\u7EDF\u672A\u77E5\u9519\u8BEF codeMessage[50001]=\u9A8C\u8BC1\u7801\u670D\u52A1\u914D\u7F6E\u51FA\u9519 From 8170cd4274051003bbf40f5b6a577df50d506c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 26 Jul 2020 20:53:11 +0800 Subject: [PATCH 69/70] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E6=9F=A5=E5=88=A0=E8=80=83=E8=AF=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jackson/CreateExamParamDeserializer.java | 14 ++--- .../oerp/controller/admin/ExamController.java | 41 ++++++-------- .../juzi/oerp/model/dto/UpdateExamDTO.java | 44 --------------- ...mParamDTO.java => UpdateExamParamDTO.java} | 2 +- .../com/juzi/oerp/service/ExamService.java | 22 +++++++- .../oerp/service/impl/ExamServiceImpl.java | 56 +++++++++++++++++-- 6 files changed, 96 insertions(+), 83 deletions(-) delete mode 100644 src/main/java/com/juzi/oerp/model/dto/UpdateExamDTO.java rename src/main/java/com/juzi/oerp/model/dto/param/{CreateExamParamDTO.java => UpdateExamParamDTO.java} (97%) diff --git a/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java b/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java index 0644989..c5c00f3 100644 --- a/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java +++ b/src/main/java/com/juzi/oerp/common/jackson/CreateExamParamDeserializer.java @@ -4,8 +4,8 @@ import com.fasterxml.jackson.core.TreeNode; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; -import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.CreateExamPlaceParamDTO; +import com.juzi.oerp.model.dto.param.UpdateExamParamDTO; import org.springframework.stereotype.Component; import java.io.IOException; @@ -22,14 +22,14 @@ * @date 2020/7/25 21:10 */ @Component -public class CreateExamParamDeserializer extends JsonDeserializer { +public class CreateExamParamDeserializer extends JsonDeserializer { @Override public Class handledType() { - return CreateExamParamDTO.class; + return UpdateExamParamDTO.class; } @Override - public CreateExamParamDTO deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { + public UpdateExamParamDTO deserialize(JsonParser p, DeserializationContext ctxt) throws IOException { TreeNode treeNode = p.readValueAsTree(); String title = treeNode.get("title").toString().replaceAll("\"", ""); String description = treeNode.get("description").toString().replaceAll("\"", ""); @@ -61,14 +61,14 @@ public CreateExamParamDTO deserialize(JsonParser p, DeserializationContext ctxt) timePlace.put(examTime, createExamPlaceParamDTOList); }); - CreateExamParamDTO createExamParamDTO = new CreateExamParamDTO(); - createExamParamDTO + UpdateExamParamDTO updateExamParamDTO = new UpdateExamParamDTO(); + updateExamParamDTO .setTitle(title) .setDescription(description) .setPrice(price) .setBeginTime(beginTimeLocalDateTime) .setEndTime(endTimeLocalDateTime) .setTimePlace(timePlace); - return createExamParamDTO; + return updateExamParamDTO; } } diff --git a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java index 9aab3b1..69fad3d 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/ExamController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/ExamController.java @@ -1,9 +1,8 @@ package com.juzi.oerp.controller.admin; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.juzi.oerp.model.dto.UpdateExamDTO; -import com.juzi.oerp.model.dto.param.CreateExamParamDTO; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.juzi.oerp.model.dto.param.PageParamDTO; +import com.juzi.oerp.model.dto.param.UpdateExamParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.response.DeleteResponseVO; import com.juzi.oerp.model.vo.response.MessageResponseVO; @@ -40,14 +39,6 @@ public class ExamController { @Autowired private ExamService examService; - @Autowired - private ObjectMapper objectMapper; - - @PostMapping("/test/test") - public void test(@RequestBody CreateExamParamDTO createExamParamDTO) { - - } - /** * 获取考试_分页 * @@ -55,8 +46,9 @@ public void test(@RequestBody CreateExamParamDTO createExamParamDTO) { */ @GetMapping @ApiOperation(value = "获取考试信息列表", notes = "分页获取考试列表") - public ResponseVO getExamByPage(PageParamDTO pageParamDTO) { - return null; + public ResponseVO> getExamByPage(@RequestBody PageParamDTO pageParamDTO) { + IPage result = examService.getExamListByPage(pageParamDTO); + return new ResponseVO<>(result); } /** @@ -67,27 +59,30 @@ public ResponseVO getExamByPage(PageParamDTO pageParamDTO) { */ @GetMapping("/{examId}") @ApiOperation(value = "获取考试信息") - public ExamPO getExamById(@ApiParam("考试id") @PathVariable Integer examId) { - return null; + public ResponseVO getExamById(@ApiParam("考试id") @PathVariable Integer examId) { + ExamPO result = examService.getById(examId); + return new ResponseVO<>(result); } /** * 修改考试 * - * @param updateExamDTO 考试信息 - * @param examId 考试 id + * @param updateExamParamDTO 考试信息 * @return 修改成功信息 */ - @PutMapping("/{examId}") - @ApiOperation("修改考试信息") - public ResponseVO updateExamById(@RequestBody UpdateExamDTO updateExamDTO, @PathVariable Integer examId) { + @PutMapping + // @ApiOperation("修改考试信息") + public MessageResponseVO updateExamById(@RequestPart(value = "exam") UpdateExamParamDTO updateExamParamDTO, + @RequestPart("image") MultipartFile image, + @RequestPart("word") MultipartFile word) { + return null; } /** * 创建考试 * - * @param createExamParamDTO 考试信息 + * @param updateExamParamDTO 考试信息 * @param image 图片 * @param word word 文档 * @return 创建成功信息 @@ -95,10 +90,10 @@ public ResponseVO updateExamById(@RequestBody UpdateExamDTO updateExamDT @PostMapping @ApiOperation("创建考试") public MessageResponseVO createExam( - @RequestPart(value = "exam") CreateExamParamDTO createExamParamDTO, + @RequestPart(value = "exam") UpdateExamParamDTO updateExamParamDTO, @RequestPart("image") MultipartFile image, @RequestPart("word") MultipartFile word) throws IOException { - examService.createExam(createExamParamDTO, image, word); + examService.createExam(updateExamParamDTO, image, word); return new MessageResponseVO(20011); } diff --git a/src/main/java/com/juzi/oerp/model/dto/UpdateExamDTO.java b/src/main/java/com/juzi/oerp/model/dto/UpdateExamDTO.java deleted file mode 100644 index 3f0cbe7..0000000 --- a/src/main/java/com/juzi/oerp/model/dto/UpdateExamDTO.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.juzi.oerp.model.dto; - -import lombok.Data; - -import java.time.LocalDateTime; - -/** - * @author Juzi - * @date 2020/7/15 22:48 - */ -@Data -public class UpdateExamDTO { - - /** - * 考试名称 - */ - private String title; - - /** - * 描述 - */ - private String description; - - /** - * 报名开始时间 - */ - private LocalDateTime beginTime; - - /** - * 报名截止时间 - */ - private LocalDateTime endTime; - - /** - * 考试时间 - */ - private LocalDateTime examTime; - - /** - * 最多可报名多少人:-1 无限制 - */ - private Integer peopleNumber; - -} diff --git a/src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/UpdateExamParamDTO.java similarity index 97% rename from src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java rename to src/main/java/com/juzi/oerp/model/dto/param/UpdateExamParamDTO.java index 7638c63..20e9784 100644 --- a/src/main/java/com/juzi/oerp/model/dto/param/CreateExamParamDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/param/UpdateExamParamDTO.java @@ -22,7 +22,7 @@ @Accessors(chain = true) @ApiModel(description = "创建考试参数") @JsonDeserialize(using = CreateExamParamDeserializer.class) -public class CreateExamParamDTO { +public class UpdateExamParamDTO { @ApiModelProperty("考试名称") private String title; diff --git a/src/main/java/com/juzi/oerp/service/ExamService.java b/src/main/java/com/juzi/oerp/service/ExamService.java index b97d265..2ff38c9 100644 --- a/src/main/java/com/juzi/oerp/service/ExamService.java +++ b/src/main/java/com/juzi/oerp/service/ExamService.java @@ -2,8 +2,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; -import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; +import com.juzi.oerp.model.dto.param.UpdateExamParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.vo.ExamApplyInfoVO; import org.springframework.web.multipart.MultipartFile; @@ -46,9 +46,25 @@ public interface ExamService extends IService { /** * 创建考试 - 管理员 * - * @param createExamParamDTO 考试信息 + * @param updateExamParamDTO 考试信息 * @param image 图片 * @param word 文档 + * @throws IOException IO异常 */ - void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile image, MultipartFile word) throws IOException; + void createExam(UpdateExamParamDTO updateExamParamDTO, MultipartFile image, MultipartFile word) throws IOException; + + /** + * 获取考试列表 - 管理员 + * + * @param pageParamDTO 分页参数 + * @return 分页结果 + */ + IPage getExamListByPage(PageParamDTO pageParamDTO); + + /** + * 删除考试 + * + * @param examId 考试 id + */ + void deleteExam(Integer examId); } diff --git a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java index 8ac0a5b..e7e8cb5 100644 --- a/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java +++ b/src/main/java/com/juzi/oerp/service/impl/ExamServiceImpl.java @@ -7,11 +7,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.juzi.oerp.common.exception.ApplyException; +import com.juzi.oerp.common.exception.OERPException; import com.juzi.oerp.dao.ExamDAO; import com.juzi.oerp.mapper.ExamMapper; +import com.juzi.oerp.mapper.ExamPlaceMapper; +import com.juzi.oerp.mapper.ExamTimeMapper; import com.juzi.oerp.model.dto.ExamApplyInfoDTO; -import com.juzi.oerp.model.dto.param.CreateExamParamDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; +import com.juzi.oerp.model.dto.param.UpdateExamParamDTO; import com.juzi.oerp.model.po.ExamPO; import com.juzi.oerp.model.po.ExamPlacePO; import com.juzi.oerp.model.po.ExamTimePO; @@ -52,12 +55,18 @@ public class ExamServiceImpl extends ServiceImpl implements @Autowired private ExamMapper examMapper; + @Autowired + private ExamTimeMapper examTimeMapper; + @Autowired private ExamTimeService examTimeService; @Autowired private ExamPlaceService examPlaceService; + @Autowired + private ExamPlaceMapper examPlaceMapper; + @Override public IPage getExamPlainInfoByPage(PageParamDTO pageParamDTO) { IPage page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); @@ -103,7 +112,7 @@ public ExamApplyInfoVO getExamApplyInfoById(Integer examId) { @Override @Transactional(rollbackFor = RuntimeException.class) - public void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile image, MultipartFile word) throws IOException { + public void createExam(UpdateExamParamDTO updateExamParamDTO, MultipartFile image, MultipartFile word) throws IOException { // 将 word 转换为 html String html = WordUtils.docxToHTML(word.getInputStream()); @@ -111,14 +120,14 @@ public void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile imag String imagePath = UploadFileUtils.upload(image.getInputStream(), FileUtil.extName(image.getOriginalFilename())); ExamPO examPO = new ExamPO(); - BeanUtils.copyProperties(createExamParamDTO, examPO); + BeanUtils.copyProperties(updateExamParamDTO, examPO); examPO .setImageUrl(imagePath) .setDetail(html); examMapper.insert(examPO); // 批量插入考试时间 - List examTimePOList = createExamParamDTO.getTimePlace().keySet() + List examTimePOList = updateExamParamDTO.getTimePlace().keySet() .stream().map(examTime -> new ExamTimePO() .setExamId(examPO.getId()) .setExamTime(examTime)).collect(toList()); @@ -126,7 +135,7 @@ public void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile imag // 批量插入考试地点 List examPlacePOList = examTimePOList.stream().flatMap(examTime -> - createExamParamDTO.getTimePlace().get(examTime.getExamTime()).stream().map(examPlace -> { + updateExamParamDTO.getTimePlace().get(examTime.getExamTime()).stream().map(examPlace -> { ExamPlacePO examPlacePO = new ExamPlacePO(); // 将参数信息 copy 到 PO 对象中 BeanUtils.copyProperties(examPlace, examPlacePO); @@ -136,4 +145,41 @@ public void createExam(CreateExamParamDTO createExamParamDTO, MultipartFile imag ).collect(toList()); examPlaceService.saveBatch(examPlacePOList); } + + @Override + public IPage getExamListByPage(PageParamDTO pageParamDTO) { + String keyword = pageParamDTO.getKeyword(); + IPage page = new Page<>(pageParamDTO.getPageOn(), pageParamDTO.getPageSize()); + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .like(!StringUtils.isEmpty(keyword), ExamPO::getTitle, keyword) + .orderByDesc(ExamPO::getCreateTime); + return examMapper.selectPage(page, queryWrapper); + } + + @Override + public void deleteExam(Integer examId) { + ExamPO examPO = examMapper.selectById(examId); + // 考试不存在 + if (examPO == null) { + throw new OERPException(40007); + } + // 删除考试 + examMapper.deleteById(examId); + + // 删除考试时间 + List examTimePOList = examTimeMapper.selectList(new LambdaQueryWrapper().eq(ExamTimePO::getExamId, examId)); + List examTimeIdList = examTimePOList + .stream() + .map(ExamTimePO::getId) + .collect(toList()); + examTimeMapper.deleteBatchIds(examTimeIdList); + + // 删除考试地点 + List examPlaceIdList = examTimeIdList + .stream() + .flatMap(examTimeId -> examPlaceMapper.selectList(new LambdaQueryWrapper().eq(ExamPlacePO::getExamTimeId, examTimeId)).stream()) + .map(ExamPlacePO::getId) + .collect(toList()); + examPlaceMapper.deleteBatchIds(examPlaceIdList); + } } From e4b2cc5a350dcd9283cc9870c04009e781c5fb28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A1=94=E5=AD=90?= Date: Sun, 26 Jul 2020 21:05:47 +0800 Subject: [PATCH 70/70] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=96=B0=E5=A2=9E=E5=AD=A6=E6=A0=A1=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oerp/controller/admin/UserController.java | 5 +-- .../oerp/controller/user/UserController.java | 15 +++---- .../UpdateUserInfoParamDTO.java} | 7 +++- .../com/juzi/oerp/model/po/UserInfoPO.java | 3 ++ .../com/juzi/oerp/model/vo/UserInfoVO.java | 3 ++ src/main/resources/code-message.properties | 1 + .../resources/mybatis/xml/dao/UserDAO.xml | 41 ++++++++++--------- 7 files changed, 44 insertions(+), 31 deletions(-) rename src/main/java/com/juzi/oerp/model/dto/{UpdateUserInfoDTO.java => param/UpdateUserInfoParamDTO.java} (78%) diff --git a/src/main/java/com/juzi/oerp/controller/admin/UserController.java b/src/main/java/com/juzi/oerp/controller/admin/UserController.java index 71bb17e..1cff303 100644 --- a/src/main/java/com/juzi/oerp/controller/admin/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/admin/UserController.java @@ -5,7 +5,6 @@ import com.juzi.oerp.model.dto.UpdateUserDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; import com.juzi.oerp.model.vo.UserInfoVO; -import com.juzi.oerp.model.vo.response.DeleteResponseVO; import com.juzi.oerp.model.vo.response.MessageResponseVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.service.UserService; @@ -67,9 +66,9 @@ public ResponseVO getUserByUserId(@PathVariable Integer userId) { */ @DeleteMapping("/{userId}") @ApiOperation("删除用户") - public ResponseVO deleteUserByUserId(@PathVariable Integer userId) { + public MessageResponseVO deleteUserByUserId(@PathVariable Integer userId) { userService.deleteUserByUserId(userId); - return new DeleteResponseVO(); + return new MessageResponseVO(20012); } /** diff --git a/src/main/java/com/juzi/oerp/controller/user/UserController.java b/src/main/java/com/juzi/oerp/controller/user/UserController.java index 7ffd79f..6fc2a37 100644 --- a/src/main/java/com/juzi/oerp/controller/user/UserController.java +++ b/src/main/java/com/juzi/oerp/controller/user/UserController.java @@ -2,12 +2,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.juzi.oerp.common.store.LocalUserStore; -import com.juzi.oerp.model.dto.UpdateUserInfoDTO; import com.juzi.oerp.model.dto.param.PageParamDTO; +import com.juzi.oerp.model.dto.param.UpdateUserInfoParamDTO; import com.juzi.oerp.model.po.UserInfoPO; import com.juzi.oerp.model.po.UserPO; -import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.model.vo.UserApplyExamVO; +import com.juzi.oerp.model.vo.UserInfoVO; import com.juzi.oerp.model.vo.response.ResponseVO; import com.juzi.oerp.model.vo.response.UpdatedResponseVO; import com.juzi.oerp.service.UserInfoService; @@ -26,7 +26,7 @@ * @author Juzi * @date 2020/7/19 20:48 */ -@Api(tags = "用户信息") +@Api(tags = "个人中心") @RequestMapping("/user") @RestController("userUserController") public class UserController { @@ -38,7 +38,7 @@ public class UserController { private UserService userService; @GetMapping - @ApiOperation(value = "个人信息", notes = "获取当前已登录用户的个人信息") + @ApiOperation(value = "获取个人信息", notes = "获取当前已登录用户的个人信息") public ResponseVO getUserInfo() { Integer userId = LocalUserStore.getLocalUser(); UserPO userPO = userService.getById(userId); @@ -47,18 +47,19 @@ public ResponseVO getUserInfo() { } @PutMapping - @ApiOperation(value = "修改个人信息") - public UpdatedResponseVO updateUserInfo(@RequestBody UpdateUserInfoDTO updateUserInfoDTO) { + @ApiOperation("修改个人信息") + public UpdatedResponseVO updateUserInfo(@RequestBody UpdateUserInfoParamDTO updateUserInfoParamDTO) { Integer userId = LocalUserStore.getLocalUser(); UserInfoPO userInfoPO = new UserInfoPO(); userInfoPO.setUserId(userId); - BeanUtils.copyProperties(updateUserInfoDTO, userInfoPO); + BeanUtils.copyProperties(updateUserInfoParamDTO, userInfoPO); userInfoService.updateById(userInfoPO); return new UpdatedResponseVO(); } @GetMapping("/apply") + @ApiOperation("获取报名信息") public ResponseVO> getUserApplyExam(@RequestBody PageParamDTO pageParamDTO){ Page result = userInfoService.queryUserApplyExam(pageParamDTO); return new ResponseVO<>(result); diff --git a/src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java b/src/main/java/com/juzi/oerp/model/dto/param/UpdateUserInfoParamDTO.java similarity index 78% rename from src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java rename to src/main/java/com/juzi/oerp/model/dto/param/UpdateUserInfoParamDTO.java index 455da34..3a94784 100644 --- a/src/main/java/com/juzi/oerp/model/dto/UpdateUserInfoDTO.java +++ b/src/main/java/com/juzi/oerp/model/dto/param/UpdateUserInfoParamDTO.java @@ -1,4 +1,4 @@ -package com.juzi.oerp.model.dto; +package com.juzi.oerp.model.dto.param; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -12,7 +12,7 @@ */ @Data @ApiModel(description = "修改用户信息参数") -public class UpdateUserInfoDTO { +public class UpdateUserInfoParamDTO { @ApiModelProperty("姓名") private String name; @@ -23,6 +23,9 @@ public class UpdateUserInfoDTO { @ApiModelProperty("性别") private Integer gender; + @ApiModelProperty("学校") + private String school; + @ApiModelProperty("学历") private String education; diff --git a/src/main/java/com/juzi/oerp/model/po/UserInfoPO.java b/src/main/java/com/juzi/oerp/model/po/UserInfoPO.java index c6d14e2..c9a7776 100644 --- a/src/main/java/com/juzi/oerp/model/po/UserInfoPO.java +++ b/src/main/java/com/juzi/oerp/model/po/UserInfoPO.java @@ -46,6 +46,9 @@ public class UserInfoPO { @ApiModelProperty("身份证号码") private String identityNo; + @ApiModelProperty("学校") + private String school; + @ApiModelProperty("学历") private String education; diff --git a/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java b/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java index 9ced169..b9d4c37 100644 --- a/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java +++ b/src/main/java/com/juzi/oerp/model/vo/UserInfoVO.java @@ -36,6 +36,9 @@ public class UserInfoVO { @ApiModelProperty("性别") private Integer gender; + @ApiModelProperty("学校") + private String school; + @ApiModelProperty("学历") private String education; diff --git a/src/main/resources/code-message.properties b/src/main/resources/code-message.properties index 5f05421..b7420cd 100644 --- a/src/main/resources/code-message.properties +++ b/src/main/resources/code-message.properties @@ -9,6 +9,7 @@ codeMessage[20008]=\u624B\u673A\u53F7\u6B63\u786E codeMessage[20009]=\u624B\u673A\u53F7\u5DF2\u9A8C\u8BC1 codeMessage[20010]=\u4FEE\u6539\u6210\u529F codeMessage[20011]=\u521B\u5EFA\u6210\u529F +codeMessage[20012]=\u5220\u9664\u6210\u529F codeMessage[40001]=\u624B\u673A\u53F7\u5DF2\u88AB\u6CE8\u518C\uFF0C\u8BF7\u66F4\u6362\u624B\u673A\u53F7\u518D\u8BD5 diff --git a/src/main/resources/mybatis/xml/dao/UserDAO.xml b/src/main/resources/mybatis/xml/dao/UserDAO.xml index 056a2ff..89eb82c 100644 --- a/src/main/resources/mybatis/xml/dao/UserDAO.xml +++ b/src/main/resources/mybatis/xml/dao/UserDAO.xml @@ -14,7 +14,8 @@ user_info.avatar_url, user_info.`name`, user_info.gender, - user_info.education, + user_info.school, + user_info.education, user_info.identity_no, user_info.birthday FROM @@ -31,26 +32,28 @@