liuxm
2024-06-13 f823fa4a9283debfa7cb6d79fc1f3c7099f9b3ae
去掉原controller中的try catch 和BindingResult
7个文件已修改
411 ■■■■■ 已修改文件
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/MarkQrCode/MarkQrCodeCtrl.java 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java 79 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java 156 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserSv.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java 79 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/MarkQrCode/MarkQrCodeCtrl.java
@@ -33,23 +33,18 @@
     * @return
     */
    @GetMapping(path = "show")
    public BaseResponse<List<ResultVo>> show() {
        try{
            List<ResultVo> list = new ArrayList<>() ;
            String[][] marks = QrCodeConstant.Marks() ;
            for(String[] mark : marks){
                ResultVo vo = new ResultVo() ;
                vo.code = mark[0] ;
                vo.name = mark[1] ;
                byte[] codes = QrCodeUtil.genQrCode(vo.code);
                vo.imgBase64 = "data:image/jpeg;base64," + Base64.encode(codes);
                list.add(vo) ;
            }
            return BaseResponseUtils.buildSuccess(list);
        }catch (Exception e){
            log.error("生成标识类二维码时异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
    public BaseResponse<List<ResultVo>> show() throws Exception{
        List<ResultVo> list = new ArrayList<>() ;
        String[][] marks = QrCodeConstant.Marks() ;
        for(String[] mark : marks){
            ResultVo vo = new ResultVo() ;
            vo.code = mark[0] ;
            vo.name = mark[1] ;
            byte[] codes = QrCodeUtil.genQrCode(vo.code);
            vo.imgBase64 = "data:image/jpeg;base64," + Base64.encode(codes);
            list.add(vo) ;
        }
        return BaseResponseUtils.buildSuccess(list);
    }
    /**
@@ -57,20 +52,16 @@
     * @return
     */
    @GetMapping(path = "download")
    public void download(HttpServletResponse response){
        try{
            List<Converter> list = new ArrayList<>() ;
            String[][] marks = QrCodeConstant.Marks() ;
            for(String[] mark : marks){
                ExcelVo vo = new ExcelVo() ;
                vo.code = mark[0] ;
                vo.name = mark[1] ;
                vo.image = QrCodeUtil.genQrCode(vo.code);
                list.add(vo) ;
            }
            QrCodeUtil.downloadExcel(response, fileName, sheetName, list);
        }catch (Exception e){
            log.error("下载标识类二维码时异常", e);
    public void download(HttpServletResponse response) throws Exception{
        List<Converter> list = new ArrayList<>() ;
        String[][] marks = QrCodeConstant.Marks() ;
        for(String[] mark : marks){
            ExcelVo vo = new ExcelVo() ;
            vo.code = mark[0] ;
            vo.name = mark[1] ;
            vo.image = QrCodeUtil.genQrCode(vo.code);
            list.add(vo) ;
        }
        QrCodeUtil.downloadExcel(response, fileName, sheetName, list);
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/log/LogCtrl.java
@@ -33,12 +33,7 @@
    @SsoPowerAop(power = "10100006") //登录与权限同时验证
    @Log("查询单条日志")
    public BaseResponse<BaLog> one(String id){
        try {
            return BaseResponseUtils.buildSuccess(sv.selectById(Long.parseLong(id)));
        } catch (Exception e) {
            log.error("查询单条日志数据异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        return BaseResponseUtils.buildSuccess(sv.selectById(Long.parseLong(id)));
    }
    /**
@@ -49,13 +44,8 @@
    @SsoPowerAop(power = "10100006") //登录与权限同时验证
    @Log("查询日志")
    public BaseResponse<QueryResultVo<List<BaLog>>> some(@RequestBody QueryVo vo){
        try {
            QueryResultVo<List<BaLog>> res = sv.selectSome(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询日志异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        QueryResultVo<List<BaLog>> res = sv.selectSome(vo);
        return BaseResponseUtils.buildSuccess(res);
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/privilege/PrivilegeCtrl.java
@@ -38,12 +38,7 @@
    @GetMapping(path="getByType")
    @SsoPowerAop(power = "10100004")
    public BaseResponse<List<Map<String, Object>>> getByType(){
       try {
           return BaseResponseUtils.buildSuccess(sv.selectByType());
       }catch (Exception e){
            log.error("分类型获取权限",e);
            return BaseResponseUtils.buildException(e.getMessage());
       }
        return BaseResponseUtils.buildSuccess(sv.selectByType());
    }
    /**
@@ -55,12 +50,7 @@
    @SsoPowerAop(power = "10100004")
    @Log("查询权限信息")
    public BaseResponse<QueryResultVo<List<BaPrivilege>>> some(@RequestBody QueryVo vo){
        try {
            return BaseResponseUtils.buildSuccess(sv.selectSome(vo));
        }catch (Exception e){
            log.error("分页获取权限",e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        return BaseResponseUtils.buildSuccess(sv.selectSome(vo));
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/role/RoleCtrl.java
@@ -10,11 +10,9 @@
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
 * 角色管理
@@ -33,25 +31,16 @@
    /**
     * 保存角色信息
     * @param role
     * @param bindingResult
     * @return
     */
    @PostMapping(path="save")
    @SsoPowerAop(power = "10100003")
    @Log("保存角色信息")
    public BaseResponse<Boolean> save(@RequestBody @Valid BaRole role,BindingResult bindingResult){
    public BaseResponse<Boolean> save(@RequestBody @Valid BaRole role){
        int count;
        try {
            if (bindingResult != null && bindingResult.hasErrors()) {
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            role.setDeleted(false);
            role.setDisabled(false);
            count = roleSv.save(role);
        }catch (Exception e){
            log.error("保存角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        role.setDeleted(false);
        role.setDisabled(false);
        count = roleSv.save(role);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -63,23 +52,14 @@
    /**
     * 更新角色信息
     * @param role
     * @param bindingResult
     * @return
     */
    @PostMapping(path="update")
    @SsoPowerAop(power = "10100003")
    @Log("更新角色信息")
    public BaseResponse<BaRole> update(@RequestBody @Valid BaRole role,BindingResult bindingResult){
        int count;
        try {
            if (bindingResult != null && bindingResult.hasErrors()) {
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            count = roleSv.update(role);
        }catch (Exception e){
            log.error("更新角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    public BaseResponse<BaRole> update(@RequestBody @Valid BaRole role){
        int count = roleSv.update(role);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -96,13 +76,8 @@
    @SsoPowerAop(power = "10100003")
    @Log("删除角色信息")
    public BaseResponse<Boolean> delete(String id){
        int count;
        try {
            count = roleSv.delete(Long.parseLong(id));
        }catch (Exception e){
            log.error("删除角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        int count = roleSv.delete(Long.parseLong(id));
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -119,13 +94,8 @@
    @SsoPowerAop(power = "10100003")
    @Log("禁用或启用角色信息")
    public BaseResponse<Boolean> disabled(@RequestBody BaRole role){
        int count;
        try {
            count = roleSv.disabled(role.id,role.disabled);
        }catch (Exception e){
            log.error("禁用角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        int count = roleSv.disabled(role.id,role.disabled);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -142,13 +112,8 @@
    @SsoPowerAop(power = "10100004") //登录与权限同时验证
    @Log("根据ID查询角色信息")
    public BaseResponse<BaRole> one(String id){
        try{
            BaRole role=roleSv.selectById(id);
            return BaseResponseUtils.buildSuccess(JSON.toJSON(role));
        }catch (Exception e){
            log.error("查询角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        BaRole role=roleSv.selectById(id);
        return BaseResponseUtils.buildSuccess(JSON.toJSON(role));
    }
    /**
@@ -159,13 +124,8 @@
    @SsoPowerAop(power = "10100004") //登录与权限同时验证
    @Log("查询所有角色")
    public BaseResponse<List<BaRole>> all(String id){
        try{
            List<BaRole> roles=roleSv.selectAll();
            return BaseResponseUtils.buildSuccess(roles);
        }catch (Exception e){
            log.error("查询所有角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        List<BaRole> roles=roleSv.selectAll();
        return BaseResponseUtils.buildSuccess(roles);
    }
    /**
@@ -177,13 +137,8 @@
    @SsoPowerAop(power = "10100004")
    @Log("查询角色信息")
    public BaseResponse<QueryResultVo<List<BaRole>>> some(@RequestBody QueryVo vo){
        try {
            QueryResultVo<List<BaRole>> list = roleSv.selectSome(vo) ;
            return BaseResponseUtils.buildSuccess(list);
        }catch (Exception e){
            log.error("查询角色异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        QueryResultVo<List<BaRole>> list = roleSv.selectSome(vo) ;
        return BaseResponseUtils.buildSuccess(list);
    }
}
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserCtrl.java
@@ -16,7 +16,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -64,13 +63,8 @@
    @SsoPowerAop(power = "10100000") //登录与权限同时验证
    @Log("查询用户")
    public BaseResponse<QueryResultVo<List<BaUser>>> some(@RequestBody QueryVo vo) {
        try {
            QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo);
            return BaseResponseUtils.buildSuccess(res);
        } catch (Exception e) {
            log.error("查询用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        QueryResultVo<List<BaUser>> res = this.sv.selectSome(vo);
        return BaseResponseUtils.buildSuccess(res);
    }
    /**
@@ -83,48 +77,34 @@
    @SsoPowerAop(power = "10100000") //登录与权限同时验证
    @Log("查询单个用户")
    public BaseResponse<BaUser> one(String id) {
        try {
            return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id)));
        } catch (Exception e) {
            log.error("查询一个用户数据异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        return BaseResponseUtils.buildSuccess(this.sv.selectById(Long.parseLong(id)));
    }
    /**
     * 保存用户信息
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "save", consumes = MediaType.APPLICATION_JSON_VALUE)
    //@SsoAop() //只有登录验证,没有权限验证
    @SsoPowerAop(power = "10100001") //登录与权限同时验证
    @Log("保存用户信息")
    public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po, BindingResult bindingResult) {
        if (bindingResult != null && bindingResult.hasErrors()) {
            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
        }
    public BaseResponse<Boolean> save(@RequestBody @Valid BaUser po) throws Exception{
        po.id = null;
        Long id;
        try {
            po.supperAdmin = Constant.no.byteValue() ;
        po.supperAdmin = Constant.no.byteValue() ;
//            po.disabled = false ;//默认不禁用
            po.deleted = false;//默认不删除
            if (!StringUtils.isNullOrEmpty(po.password)) {
        po.deleted = false;//默认不删除
        if (!StringUtils.isNullOrEmpty(po.password)) {
                /*
                如果前端进行了base64加密
                po.password = new String(Base64.getDecoder().decode(po.password)) ;
                */
                po.password = MD5.encrypt(po.password);//进行加密码
            } else {
                po.password = MD5.encrypt(defaultPassword);
            }
            id = this.sv.save(po);
        } catch (Exception e) {
            log.error("保存用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
            po.password = MD5.encrypt(po.password);//进行加密码
        } else {
            po.password = MD5.encrypt(defaultPassword);
        }
        id = this.sv.save(po);
        if (id <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -135,30 +115,17 @@
    /**
     * 更新用户信息
     * @param po
     * @param bindingResult
     * @return
     */
    @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
    //@SsoAop() //只有登录验证,没有权限验证
    @SsoPowerAop(power = "10100001") //登录与权限同时验证
    @Log("更新用户信息")
    public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po, BindingResult bindingResult) {
        int count;
        try {
            if (bindingResult != null && bindingResult.hasErrors()) {
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            if (po.id == null) {
                return BaseResponseUtils.buildFail("无数据实体ID");
            }
            po.password = null;//设置为null,不做更新
            po.supperAdmin = null;//设置为null,不做更新
            po.deleted = null;//设置为null,不做更新
            count = this.sv.update(po);
        } catch (Exception e) {
            log.error("修改用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
    public BaseResponse<Boolean> update(@RequestBody @Validated BaUser po) {
        po.password = null;//设置为null,不做更新
        po.supperAdmin = null;//设置为null,不做更新
        po.deleted = null;//设置为null,不做更新
        int count = this.sv.update(po);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -175,11 +142,11 @@
    @SsoPowerAop(power = "10100001")
    @Log("禁用或启用用户信息")
    public BaseResponse<BaRole> disabled(@RequestBody BaUser po){
        try {
            return BaseResponseUtils.buildSuccess(sv.disabled(po.id,po.disabled));
        }catch (Exception e){
            log.error("禁用或启用用户信息异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        int count = sv.disabled(po.id,po.disabled);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
            return BaseResponseUtils.buildSuccess(true);
        }
    }
@@ -192,16 +159,10 @@
    @SsoPowerAop(power = "10100001") //登录与权限同时验证
    @Log("删除用户")
    public BaseResponse<Boolean> delete(Long id) {
        int count;
        try {
            BaUser po = new BaUser();
            po.id = id;
            po.deleted = true;
            count = this.sv.update(po);
        } catch (Exception e) {
            log.error("删除用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        BaUser po = new BaUser();
        po.id = id;
        po.deleted = true;
        int count = this.sv.update(po);
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
        } else {
@@ -218,41 +179,36 @@
    @GetMapping(path = "changePassword")
    @SsoAop()
    @Log("修改密码")
    public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) {
    public BaseResponse<Boolean> changePassword(String id, String oldPassword, String newPassword) throws Exception{
        int count;
        try {
            if (id == null) {
        if (id == null) {
            return BaseResponseUtils.buildFail("id不能为空");
            }
            if (StringUtils.isNullOrEmpty(oldPassword)) {
                return BaseResponseUtils.buildFail("旧密码不能为空");
            }
            if (StringUtils.isNullOrEmpty(newPassword)) {
                return BaseResponseUtils.buildFail("新密码不能为空");
            }
        }
        if (StringUtils.isNullOrEmpty(oldPassword)) {
            return BaseResponseUtils.buildFail("旧密码不能为空");
        }
        if (StringUtils.isNullOrEmpty(newPassword)) {
            return BaseResponseUtils.buildFail("新密码不能为空");
        }
            /*
            如果前端进行了base64加密
            oldPassword = new String(Base64.getDecoder().decode(oldPassword)) ;
            newPassword = new String(Base64.getDecoder().decode(newPassword)) ;
            */
            oldPassword = MD5.encrypt(oldPassword);//进行加密码
            newPassword = MD5.encrypt(newPassword);//进行加密码
        oldPassword = MD5.encrypt(oldPassword);//进行加密码
        newPassword = MD5.encrypt(newPassword);//进行加密码
            Long idLg = Long.parseLong(id) ;
        Long idLg = Long.parseLong(id) ;
            BaUser po = this.sv.selectById(idLg);
            if (Objects.isNull(po)) {
                return BaseResponseUtils.buildFail("未得到用户,请求失败");
        BaUser po = this.sv.selectById(idLg);
        if (Objects.isNull(po)) {
            return BaseResponseUtils.buildFail("未得到用户,请求失败");
        } else {
            if (!po.password.equalsIgnoreCase(oldPassword)) {
                return BaseResponseUtils.buildFail("旧密码不正确,请求失败");
            } else {
                if (!po.password.equalsIgnoreCase(oldPassword)) {
                    return BaseResponseUtils.buildFail("旧密码不正确,请求失败");
                } else {
                    count = this.sv.changePassword(idLg, newPassword);
                }
                count = this.sv.changePassword(idLg, newPassword);
            }
        } catch (Exception e) {
            log.error("修改密码异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        }
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
@@ -271,23 +227,15 @@
    //@SsoAop() //只有登录验证,没有权限验证
    @SsoPowerAop(power = "10100001") //登录与权限同时验证
    @Log("重置密码")
    public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo, BindingResult bindingResult) {
    public BaseResponse<Boolean> resetPassword(@RequestBody @Validated ResetPasswordVo vo) throws Exception {
        int count;
        try {
            if (bindingResult != null && bindingResult.hasErrors()) {
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            String password = MD5.encrypt(vo.password);//进行加密码
            Long idLg = Long.parseLong(vo.id);
             BaUser po = this.sv.selectById(idLg);
            if (Objects.isNull(po)) {
                return BaseResponseUtils.buildFail("未得到用户,请求失败");
            } else {
                count = this.sv.changePassword(idLg, password);
            }
        } catch (Exception e) {
            log.error("保存用户异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        String password = MD5.encrypt(vo.password);//进行加密码
        Long idLg = Long.parseLong(vo.id);
        BaUser po = this.sv.selectById(idLg);
        if (Objects.isNull(po)) {
            return BaseResponseUtils.buildFail("未得到用户,请求失败");
        } else {
            count = this.sv.changePassword(idLg, password);
        }
        if (count <= 0) {
            return BaseResponseUtils.buildFail("数据库存储失败");
pms-parent/pms-web-base/src/main/java/com/dy/pmsBase/user/UserSv.java
@@ -11,6 +11,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -96,7 +97,12 @@
     */
    @Transactional
    public Long save(BaUser po){
        this.dao.insertSelective(po) ;
        try{
            dao.insertSelective(po) ;
        }catch(DuplicateKeyException e){
            log.error(e.getMessage());
            throw new RuntimeException("手机号码重复");
        }
        Long id = po.getId();
        this.saveUserRoles(id, po.roleIds) ;
        return id ;
@@ -109,7 +115,13 @@
     */
    @Transactional
    public int update(BaUser po) {
        int count = this.dao.updateByPrimaryKeySelective(po);
        int count=0;
        try{
            count = this.dao.updateByPrimaryKeySelective(po);
        }catch(DuplicateKeyException e){
            log.error(e.getMessage());
            throw new RuntimeException("手机号码重复");
        }
        this.saveUserRoles(po.id, po.roleIds) ;
        return count ;
    }
pms-parent/pms-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -14,15 +14,12 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Objects;
import java.util.Random;
import java.util.UUID;
/**
@@ -49,31 +46,20 @@
    /**
     * 客户端请求用户登录,客户端提交Json数据
     * @param vo 用户登录值对象
     * @param bindingResult 输入验证
     * @return 登录用户值对象
     */
    @PostMapping(path = "login", consumes = MediaType.APPLICATION_JSON_VALUE)//前端提交json数据
    @Log("用户登录")
    public BaseResponse<UserVo> login(@RequestBody  @Valid LoginVo vo,BindingResult bindingResult,
                                      HttpSession session) {
        try {
            if(bindingResult != null && bindingResult.hasErrors()){
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            // 从Session中获取保存的验证码
            String sessionCaptcha = (String) session.getAttribute("captcha");
            // 首先验证验证码
            if (vo.captcha != null && vo.captcha.equalsIgnoreCase(sessionCaptcha)) {
                session.removeAttribute("captcha");
                return this.doLogin(vo) ;
            } else {
                // 验证码错误,返回登录页面并显示错误信息
                return BaseResponseUtils.buildFail("验证码错误");
            }
        } catch (Exception e) {
            log.error("用户登录异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
    public BaseResponse<UserVo> login(@RequestBody  @Valid LoginVo vo,HttpSession session) {
        // 从Session中获取保存的验证码
        String sessionCaptcha = (String) session.getAttribute("captcha");
        // 首先验证验证码
        if (vo.captcha != null && vo.captcha.equalsIgnoreCase(sessionCaptcha)) {
            session.removeAttribute("captcha");
            return this.doLogin(vo) ;
        } else {
            // 验证码错误,返回登录页面并显示错误信息
            return BaseResponseUtils.buildFail("验证码错误");
        }
    }
@@ -83,24 +69,16 @@
     * @return 登录用户值对象
     */
    @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)//前端提交form表单数据
    public BaseResponse<UserVo> loginForm(@Valid LoginVo loginVo, BindingResult bindingResult,HttpSession session){
        try{
            if(bindingResult != null && bindingResult.hasErrors()){
                return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
            }
            // 从Session中获取保存的验证码
            String sessionCaptcha = (String) session.getAttribute("captcha");
            // 首先验证验证码
            if (loginVo.captcha != null && loginVo.captcha.equalsIgnoreCase(sessionCaptcha)) {
                session.removeAttribute("captcha");
                return this.doLogin(loginVo) ;
            } else {
                // 验证码错误,返回登录页面并显示错误信息
                return BaseResponseUtils.buildFail("验证码错误");
            }
        } catch (Exception e) {
            log.error("用户登录异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
    public BaseResponse<UserVo> loginForm(@Valid LoginVo loginVo,HttpSession session){
        // 从Session中获取保存的验证码
        String sessionCaptcha = (String) session.getAttribute("captcha");
        // 首先验证验证码
        if (loginVo.captcha != null && loginVo.captcha.equalsIgnoreCase(sessionCaptcha)) {
            session.removeAttribute("captcha");
            return this.doLogin(loginVo) ;
        } else {
            // 验证码错误,返回登录页面并显示错误信息
            return BaseResponseUtils.buildFail("验证码错误");
        }
    }
@@ -113,17 +91,12 @@
    @GetMapping(path = "logout")
    @Log("退出登录")
    public BaseResponse<Boolean> logout(HttpServletRequest hr){
        try{
            String token = hr.getHeader("token") ;
            if(token != null){
                this.sv.logout(token) ;
                return BaseResponseUtils.buildSuccess(true);
            }else{
                return BaseResponseUtils.buildFail("未从header中得到token");
            }
        } catch (Exception e) {
            log.error("查询一个用户数据异常", e);
            return BaseResponseUtils.buildException(e.getMessage());
        String token = hr.getHeader("token") ;
        if(token != null){
            this.sv.logout(token) ;
            return BaseResponseUtils.buildSuccess(true);
        }else{
            return BaseResponseUtils.buildFail("未从header中得到token");
        }
    }