@ApiOperation("登录接口")@RequestMapping(value = "/login", method = RequestMethod.POST)public Result<JSONObject> login(@RequestBody SysLoginModel sysLoginModel){Result<JSONObject> result = new Result<JSONObject>();// by wangh 测试System.out.println("1.result = " + result);String username = sysLoginModel.getUsername();String password = sysLoginModel.getPassword();//update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户if(isLoginFailOvertimes(username)){return result.error500("该用户登录失败次数过多,请于10分钟后再次登录!");}//update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题//前端密码加密,后端进行密码解密//password = AesEncryptUtil.desEncrypt(sysLoginModel.getPassword().replaceAll("%2B", "\\+")).trim();//密码解密//update-begin--Author:scott Date:20190805 for:暂时注释掉密码加密逻辑,有点问题//update-begin-author:taoyan date:20190828 for:校验验证码String captcha = sysLoginModel.getCaptcha();if(captcha==null){result.error500("验证码无效");// by wangh 测试System.out.println("3.result = " + result);return result;}String lowerCaseCaptcha = captcha.toLowerCase();//update-begin-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906// 加入密钥作为混淆,避免简单的拼接,被外部利用,用户自定义该密钥即可String origin = lowerCaseCaptcha+sysLoginModel.getCheckKey()+jeecgBaseConfig.getSignatureSecret();String realKey = Md5Util.md5Encode(origin, "utf-8");//update-end-author:taoyan date:2022-9-13 for: VUEN-2245 【漏洞】发现新漏洞待处理20220906Object checkCode = redisUtil.get(realKey);//当进入登录页时,有一定几率出现验证码错误 #1714if(checkCode==null || !checkCode.toString().equals(lowerCaseCaptcha)) {log.warn("验证码错误,key= {} , Ui checkCode= {}, Redis checkCode = {}", sysLoginModel.getCheckKey(), lowerCaseCaptcha, checkCode);result.error500("验证码错误");// 改成特殊的code 便于前端判断result.setCode(HttpStatus.PRECONDITION_FAILED.value());// by wangh 测试System.out.println("4.result = " + result);return result;}//update-end-author:taoyan date:20190828 for:校验验证码//1. 校验用户是否有效//update-begin-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为falseLambdaQueryWrapper<SysUser> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(SysUser::getUsername,username);SysUser sysUser = sysUserService.getOne(queryWrapper);//update-end-author:wangshuai date:20200601 for: 登录代码验证用户是否注销bug,if条件永远为falseresult = sysUserService.checkUserIsEffective(sysUser);if(!result.isSuccess()) {// by wangh 测试System.out.println("5.result = " + result);return result;}//2. 校验用户名或密码是否正确String userpassword = PasswordUtil.encrypt(username, password, sysUser.getSalt());String syspassword = sysUser.getPassword(); // sysUser取自数据库,密码是md5加密的if (!syspassword.equals(userpassword)) {//update-begin-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户addLoginFailOvertimes(username);//update-end-author:taoyan date:2022-11-7 for: issues/4109 平台用户登录失败锁定用户result.error500("用户名或密码错误");// by wangh 测试System.out.println("6.result = " + result);return result;}// by wangh 测试System.out.println("7.调用userinfo前 result = " + result);//用户登录信息userInfo(sysUser, result);// by wangh 测试System.out.println("8.调用userinfo后result = " + result);//update-begin--Author:liusq Date:20210126 for:登录成功,删除redis中的验证码redisUtil.del(realKey);//update-begin--Author:liusq Date:20210126 for:登录成功,删除redis中的验证码redisUtil.del(CommonConstant.LOGIN_FAIL + username);LoginUser loginUser = new LoginUser();BeanUtils.copyProperties(sysUser, loginUser);baseCommonService.addLog("用户名: " + username + ",登录成功!", CommonConstant.LOG_TYPE_1, null,loginUser);//update-end--Author:wangshuai Date:20200714 for:登录日志没有记录人员// by wangh 测试System.out.println("9.result = " + result);return result;}
方法中的userInfo(sysUser, result);函数没有返回值,但是却修改了result的属性,使得最终返回的result中添加了用户信息
为了验证result是否被userInfo()修改,分别在userInfo()前后加入打印:
// by wangh 测试 System.out.println("7.调用userinfo前 result = " + result);//用户登录信息 userInfo(sysUser, result);// by wangh 测试 System.out.println("8.调用userinfo后result = " + result);
输出结果:
7.调用userinfo前 result = Result(success=true, message=, code=0, result=null, timestamp=1697524486057, onlTable=null)8.调用userinfo后 result = Result(success=true, message=登录成功, code=200, result={"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTc1Njc2ODYsInVzZXJuYW1lIjoiYWRtaW4ifQ.8_WcvyNnonDRkSWvwCbFCMhwHm2Ggkfo_snCdbKcrUc","userInfo":{"activitiSync":1,"avatar":"https://static.jeecg.com/temp/国炬软件logo_1606575029126.png","birthday":1543939200000,"createTime":1561110850000,"delFlag":0,"departIds":"c6d7cb4deeac411cb3384b1b31278596","email":"jeecg@163.com","id":"e9ca23d68d884d4ebb19d07889727dae","loginTenantId":0,"orgCode":"A01","password":"cb362cfeefbf3d8d","phone":"18611111111","post":"总经理","realname":"管理员","salt":"RCGTeGiH","sex":1,"status":1,"updateBy":"admin","updateTime":1646837420000,"userIdentity":2,"username":"admin","workNo":"00001"},"departs":[{"createBy":"admin","createTime":1549866111000,"delFlag":"0","departName":"xxx网络公司","departOrder":0,"id":"c6d7cb4deeac411cb3384b1b31278596","izLeaf":0,"orgCategory":"1","orgCode":"A01","orgType":"1","parentId":"","tenantId":1,"updateBy":"test","updateTime":1665902900000}],"multi_depart":1,"sysAllDictItems":{"ol_form_biz_type":[{"label":"官方示例","text":"官方示例","title":"官方示例","value":"demo"},{"label":"流程表单","text":"流程表单","title":"流程表单","value":"bpm"},{"label":"测试表单","text":"测试表单","title":"测试表单","value":"temp"},{"label":"导入表单","text":"导入表单","title":"导入表单","value":"bdfl_include"}],"account_type":[{"label":"分享收入","text":"分享收入","title":"分享收入","value":"1"},{"label":"提现支出","text":"提现支出","title":"提现支出","value":"2"}],"education":[],"position_rank":[{"label":"员级","text":"员级","title":"员级","value":"1"},{"label":"助级","text":"助级","title":"助级","value":"2"},{"label":"中级","text":"中级","title":"中级","value":"3"},{"label":"副高级","text":"副高级","title":"副高级","value":"4"},{"label":"正高级","text":"正高级","title":"正高级","value":"5"}],"rule_conditions":[{"label":"大于","text":"大于","title":"大于","value":">"},{"label":"小于","text":"小于","title":"小于","value":"<"},{"label":"不等于","text":"不等于","title":"不等于","value":"!="},{"label":"等于","text":"等于","title":"等于","value":"="},{"label":"大于等于","text":"大于等于","title":"大于等于","value":">="},{"label":"小于等于","text":"小于等于","title":"小于等于","value":"<="},{"label":"左模糊","text":"左模糊","title":"左模糊","value":"LEFT_LIKE"},{"label":"右模糊","text":"右模糊","title":"右模糊","value":"RIGHT_LIKE"},{"label":"模糊","text":"模糊","title":"模糊","value":"LIKE"},{"label":"包含","text":"包含","title":"包含","value":"IN"},{"label":"自定义SQL表达式","text":"自定义SQL表达式","title":"自定义SQL表达式","value":"USE_SQL_RULES"}],"company_nature":[],"integral_resource":[{"label":"打卡","text":"打卡","title":"打卡","value":"1"},{"label":"答题","text":"答题","title":"答题","value":"2"},{"label":"留言","text":"留言","title":"留言","value":"3"},{"label":"兑换商品","text":"兑换商品","title":"兑换商品","value":"4"}],"staff_size":[],"ceshi_online":[{"label":"000","text":"000","title":"000","value":"00"},{"label":"easyui","text":"easyui","title":"easyui","value":"3"},{"label":"booostrap","text":"booostrap","title":"booostrap","value":"1"}],"online_graph_data_type":[{"label":"SQL","text":"SQL","title":"SQL","value":"sql"},{"label":"JSON","text":"JSON","title":"JSON","value":"json"},{"label":"API","text":"API","title":"API","value":"api"}],"online_graph_display_template":[{"label":"Tab风格","text":"Tab风格","title":"Tab风格","value":"tab"},{"label":"单排布局","text":"单排布局","title":"单排布局","value":"single"},{"label":"双排布局","text":"双排布局","title":"双排布局","value":"double"},{"label":"组合布局","text":"组合布局","title":"组合布局","value":"combination"}],"user_type":[{"label":"333","text":"333","title":"333","value":"333"}],"messageType":[{"label":"系统消息","text":"系统消息","title":"系统消息","value":"system"},{"label":"邮件消息","text":"邮件消息","title":"邮件消息","value":"email"},{"label":"钉钉消息","text":"钉钉消息","title":"钉钉消息","value":"dingtalk"},{"label":"企业微信","text":"企业微信","title":"企业微信","value":"wechat_enterprise"}],"remindMode":[{"label":"邮件提醒","text":"邮件提醒","title":"邮件提醒","value":"1"},{"label":"短信提醒","text":"短信提醒","title":"短信提醒","value":"2"},{"label":"系统消息","text":"系统消息","title":"系统消息","value":"4"}],"yn":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"0"}],"verify_status":[{"label":"默认","text":"默认","title":"默认","value":"0"},{"label":"待审核","text":"待审核","title":"待审核","value":"1"},{"label":"审核失败","text":"审核失败","title":"审核失败","value":"2"},{"label":"审核通过","text":"审核通过","title":"审核通过","value":"3"}],"has_next":[{"label":"有","text":"有","title":"有","value":"1"},{"label":"无","text":"无","title":"无","value":"0"}],"tenant_status":[{"label":"正常","text":"正常","title":"正常","value":"1"},{"label":"冻结","text":"冻结","title":"冻结","value":"0"}],"position_type":[{"label":"普通职位","text":"普通职位","title":"普通职位","value":"1"},{"label":"灵活用工","text":"灵活用工","title":"灵活用工","value":"2"},{"label":"共享用工","text":"共享用工","title":"共享用工","value":"3"}],"browse_type":[{"label":"浏览职位","text":"浏览职位","title":"浏览职位","value":"1"},{"label":"浏览简历","text":"浏览简历","title":"浏览简历","value":"2"},{"label":"浏览任务","text":"浏览任务","title":"浏览任务","value":"3"},{"label":"浏览培训","text":"浏览培训","title":"浏览培训","value":"4"}],"area":[{"label":"章贡区","text":"章贡区","title":"章贡区","value":"1"},{"label":"南康区","text":"南康区","title":"南康区","value":"2"},{"label":"赣县","text":"赣县","title":"赣县","value":"3"}],"rangeDate":[{"label":"今天","text":"今天","title":"今天","value":"jt"},{"label":"昨天","text":"昨天","title":"昨天","value":"zt"},{"label":"前天","text":"前天","title":"前天","value":"qt"},{"label":"本周","text":"本周","title":"本周","value":"bz"},{"label":"上周","text":"上周","title":"上周","value":"sz"},{"label":"本月","text":"本月","title":"本月","value":"by"},{"label":"上月","text":"上月","title":"上月","value":"sy"},{"label":"自定义日期","text":"自定义日期","title":"自定义日期","value":"zdy"}],"del_flag":[{"label":"已删除","text":"已删除","title":"已删除","value":"1"},{"label":"正常","text":"正常","title":"正常","value":"0"}],"messageHref":[{"label":"/task/myHandleTaskInfo","text":"/task/myHandleTaskInfo","title":"/task/myHandleTaskInfo","value":"bpm"},{"label":"/task/myHandleTaskInfo","text":"/task/myHandleTaskInfo","title":"/task/myHandleTaskInfo","value":"bpm_task"},{"label":"/eoa/email","text":"/eoa/email","title":"/eoa/email","value":"email"}],"cgform_table_type":[{"label":"单表","text":"单表","title":"单表","value":"1"},{"label":"主表","text":"主表","title":"主表","value":"2"},{"label":"附表","text":"附表","title":"附表","value":"3"}],"is_open":[{"label":"是","text":"是","title":"是","value":"Y"},{"label":"否","text":"否","title":"否","value":"N"}],"withdraw_status":[{"label":"待审核","text":"待审核","title":"待审核","value":"0"},{"label":"审核通过","text":"审核通过","title":"审核通过","value":"1"},{"label":"审核失败","text":"审核失败","title":"审核失败","value":"2"}],"url_type":[{"label":"内部链接","text":"内部链接","title":"内部链接","value":"1"},{"label":"外部链接","text":"外部链接","title":"外部链接","value":"2"}],"msg_category":[{"label":"通知公告","text":"通知公告","title":"通知公告","value":"1"},{"label":"系统消息","text":"系统消息","title":"系统消息","value":"2"}],"if_recommend":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"2"}],"org_category":[{"label":"岗位","text":"岗位","title":"岗位","value":"3"},{"label":"公司","text":"公司","title":"公司","value":"1"},{"label":"部门","text":"部门","title":"部门","value":"2"}],"priority":[{"label":"高","text":"高","title":"高","value":"H"},{"label":"中","text":"中","title":"中","value":"M"},{"label":"低","text":"低","title":"低","value":"L"}],"set_top":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"0"}],"dict_item_status":[{"label":"启用","text":"启用","title":"启用","value":"1"},{"label":"不启用","text":"不启用","title":"不启用","value":"0"}],"show_first":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"0"}],"job_status":[],"activiti_sync":[{"label":"同步","text":"同步","title":"同步","value":"1"},{"label":"不同步","text":"不同步","title":"不同步","value":"0"}],"if_common":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"0"}],"exp_require":[],"msgSendStatus":[{"label":"未发送","text":"未发送","title":"未发送","value":"0"},{"label":"发送成功","text":"发送成功","title":"发送成功","value":"1"},{"label":"发送失败","text":"发送失败","title":"发送失败","value":"2"}],"msg_type":[{"label":"指定用户","text":"指定用户","title":"指定用户","value":"USER"},{"label":"全体用户","text":"全体用户","title":"全体用户","value":"ALL"}],"eoa_plan_type":[{"label":"日常记录","text":"日常记录","title":"日常记录","value":"1"},{"label":"本周工作","text":"本周工作","title":"本周工作","value":"2"},{"label":"下周计划","text":"下周计划","title":"下周计划","value":"3"}],"serial_no":[{"label":"A","text":"A","title":"A","value":"A"},{"label":"B","text":"B","title":"B","value":"B"},{"label":"C","text":"C","title":"C","value":"C"},{"label":"D","text":"D","title":"D","value":"D"}],"status":[{"label":"正常","text":"正常","title":"正常","value":"1"},{"label":"停用","text":"停用","title":"停用","value":"2"}],"job_type":[],"msgType":[{"label":"文本","text":"文本","title":"文本","value":"1"},{"label":"富文本","text":"富文本","title":"富文本","value":"2"}],"eoa_plan_status":[{"label":"未开始","text":"未开始","title":"未开始","value":"0"},{"label":"进行中","text":"进行中","title":"进行中","value":"1"},{"label":"已完成","text":"已完成","title":"已完成","value":"2"}],"expect_salary":[],"reboot_type":[],"add_sign":[{"label":"正","text":"正","title":"正","value":"1"},{"label":"负","text":"负","title":"负","value":"0"}],"database_type":[{"label":"MySQL5.5","text":"MySQL5.5","title":"MySQL5.5","value":"1"},{"label":"MYSQL5.7+","text":"MYSQL5.7+","title":"MYSQL5.7+","value":"4"},{"label":"Oracle","text":"Oracle","title":"Oracle","value":"2"},{"label":"SQLServer","text":"SQLServer","title":"SQLServer","value":"3"},{"label":"postgresql","text":"postgresql","title":"postgresql","value":"6"},{"label":"marialDB","text":"marialDB","title":"marialDB","value":"5"},{"label":"达梦","text":"达梦","title":"达梦","value":"7"},{"label":"人大金仓","text":"人大金仓","title":"人大金仓","value":"8"},{"label":"神通","text":"神通","title":"神通","value":"9"},{"label":"SQLite","text":"SQLite","title":"SQLite","value":"10"},{"label":"DB2","text":"DB2","title":"DB2","value":"11"},{"label":"Hsqldb","text":"Hsqldb","title":"Hsqldb","value":"12"},{"label":"Derby","text":"Derby","title":"Derby","value":"13"},{"label":"H2","text":"H2","title":"H2","value":"14"},{"label":"其他数据库","text":"其他数据库","title":"其他数据库","value":"15"}],"log_type":[{"label":"操作日志","text":"操作日志","title":"操作日志","value":"2"},{"label":"登录日志","text":"登录日志","title":"登录日志","value":"1"}],"sub_type":[{"label":"单选题","text":"单选题","title":"单选题","value":"1"}],"show_dot":[{"label":"显示","text":"显示","title":"显示","value":"1"},{"label":"不显示","text":"不显示","title":"不显示","value":"0"}],"send_status":[{"label":"未发布","text":"未发布","title":"未发布","value":"0"},{"label":"已发布","text":"已发布","title":"已发布","value":"1"},{"label":"已撤销","text":"已撤销","title":"已撤销","value":"2"}],"pay_type":[{"label":"支付宝","text":"支付宝","title":"支付宝","value":"0"},{"label":"微信","text":"微信","title":"微信","value":"1"},{"label":"银联","text":"银联","title":"银联","value":"2"}],"eoa_cms_menu_type":[{"label":"列表","text":"列表","title":"列表","value":"1"},{"label":"链接","text":"链接","title":"链接","value":"2"}],"if_hot":[{"label":"是","text":"是","title":"是","value":"1"},{"label":"否","text":"否","title":"否","value":"0"}],"bpm_process_type":[{"label":"测试流程","text":"测试流程","title":"测试流程","value":"test"},{"label":"OA办公","text":"OA办公","title":"OA办公","value":"oa"},{"label":"业务办理","text":"业务办理","title":"业务办理","value":"business"}],"form_perms_type":[{"label":"可见(未授权不可见)","text":"可见(未授权不可见)","title":"可见(未授权不可见)","value":"1"},{"label":"可编辑(未授权禁用)","text":"可编辑(未授权禁用)","title":"可编辑(未授权禁用)","value":"2"}],"valid_status":[{"label":"无效","text":"无效","title":"无效","value":"0"},{"label":"有效","text":"有效","title":"有效","value":"1"}],"urgent_level":[{"label":"一般","text":"一般","title":"一般","value":"1"},{"label":"重要","text":"重要","title":"重要","value":"2"},{"label":"紧急","text":"紧急","title":"紧急","value":"3"}],"user_status":[{"label":"正常","text":"正常","title":"正常","value":"1"},{"label":"冻结","text":"冻结","title":"冻结","value":"2"}],"operate_type":[{"label":"查询","text":"查询","title":"查询","value":"1"},{"label":"添加","text":"添加","title":"添加","value":"2"},{"label":"修改","text":"修改","title":"修改","value":"3"},{"label":"删除","text":"删除","title":"删除","value":"4"},{"label":"导入","text":"导入","title":"导入","value":"5"},{"label":"导出","text":"导出","title":"导出","value":"6"}],"quartz_status":[{"label":"正常","text":"正常","title":"正常","value":"0"},{"label":"停止","text":"停止","title":"停止","value":"-1"}],"menu_type":[{"label":"按钮权限","text":"按钮权限","title":"按钮权限","value":"2"},{"label":"子菜单","text":"子菜单","title":"子菜单","value":"1"},{"label":"一级菜单","text":"一级菜单","title":"一级菜单","value":"0"}],"app_sort":[{"label":"默认排序","text":"默认排序","title":"默认排序","value":"0"},{"label":"打卡数量降序","text":"打卡数量降序","title":"打卡数量降序","value":"1"},{"label":"打卡数量升序","text":"打卡数量升序","title":"打卡数量升序","value":"2"},{"label":"浏览数量降序","text":"浏览数量降序","title":"浏览数量降序","value":"3"},{"label":"浏览数量升序","text":"浏览数量升序","title":"浏览数量升序","value":"4"}],"sex":[{"label":"男","text":"男","title":"男","value":"1"},{"label":"女","text":"女","title":"女","value":"2"}],"perms_type":[{"label":"显示","text":"显示","title":"显示","value":"1"},{"label":"禁用","text":"禁用","title":"禁用","value":"2"}],"global_perms_type":[{"label":"可见/可访问(授权后可见/可访问)","text":"可见/可访问(授权后可见/可访问)","title":"可见/可访问(授权后可见/可访问)","value":"1"},{"label":"可编辑(未授权时禁用)","text":"可编辑(未授权时禁用)","title":"可编辑(未授权时禁用)","value":"2"}],"cover_type":[{"label":"县市名称","text":"县市名称","title":"县市名称","value":"1"},{"label":"基地信息","text":"基地信息","title":"基地信息","value":"2"}],"online_graph_type":[{"label":"柱状图","text":"柱状图","title":"柱状图","value":"bar"},{"label":"曲线图","text":"曲线图","title":"曲线图","value":"line"},{"label":"饼图","text":"饼图","title":"饼图","value":"pie"},{"label":"数据列表","text":"数据列表","title":"数据列表","value":"table"}],"run_mode":[{"label":"正式","text":"正式","title":"正式","value":"1"},{"label":"测试","text":"测试","title":"测试","value":"0"}],"if_parttime":[{"label":"兼职","text":"兼职","title":"兼职","value":"1"},{"label":"全职","text":"全职","title":"全职","value":"0"}],"gz_district":[{"label":"不限","text":"不限","title":"不限","value":"0"},{"label":"章贡区","text":"章贡区","title":"章贡区","value":"章贡区"},{"label":"南康区","text":"南康区","title":"南康区","value":"南康区"},{"label":"赣县区","text":"赣县区","title":"赣县区","value":"赣县区"},{"label":"信丰县","text":"信丰县","title":"信丰县","value":"信丰县"},{"label":"大余县","text":"大余县","title":"大余县","value":"大余县"},{"label":"上犹县","text":"上犹县","title":"上犹县","value":"上犹县"},{"label":"崇义县","text":"崇义县","title":"崇义县","value":"崇义县"},{"label":"安远县","text":"安远县","title":"安远县","value":"安远县"},{"label":"龙南市","text":"龙南市","title":"龙南市","value":"龙南市"},{"label":"定南县","text":"定南县","title":"定南县","value":"定南县"},{"label":"全南县","text":"全南县","title":"全南县","value":"全南县"},{"label":"宁都县","text":"宁都县","title":"宁都县","value":"宁都县"},{"label":"于都县","text":"于都县","title":"于都县","value":"于都县"},{"label":"兴国县","text":"兴国县","title":"兴国县","value":"兴国县"},{"label":"会昌县","text":"会昌县","title":"会昌县","value":"会昌县"},{"label":"寻乌县","text":"寻乌县","title":"寻乌县","value":"寻乌县"},{"label":"石城县","text":"石城县","title":"石城县","value":"石城县"},{"label":"瑞金市","text":"瑞金市","title":"瑞金市","value":"瑞金市"}],"bpm_status":[{"label":"待提交","text":"待提交","title":"待提交","value":"1"},{"label":"处理中","text":"处理中","title":"处理中","value":"2"},{"label":"已完成","text":"已完成","title":"已完成","value":"3"},{"label":"已作废","text":"已作废","title":"已作废","value":"4"}],"work_overtime":[],"depart_status":[{"label":"不启用","text":"不启用","title":"不启用","value":"0"},{"label":"启用","text":"启用","title":"启用","value":"1"}],"task_type":[]}}, timestamp=1697524486057, onlTable=null)
这也解决了我之前看代码时的疑惑,为什么下面的代码会放在userInfo(sysUser, result)内,他们能影响最终的返回值吗?
obj.put("token", token);
obj.put("userInfo", sysUser);
result.setResult(obj);
private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {String username = sysUser.getUsername();String syspassword = sysUser.getPassword();// 获取用户部门信息JSONObject obj = new JSONObject(new LinkedHashMap<>());//1.生成tokenString token = JwtUtil.sign(username, syspassword);// 设置token缓存有效时间redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000);obj.put("token", token);//2.设置登录租户Result<JSONObject> loginTenantError = sysUserService.setLoginTenant(sysUser, obj, username,result);if (loginTenantError != null) {return loginTenantError;}//3.设置登录用户信息obj.put("userInfo", sysUser);//4.设置登录部门 分別處理單用戶0部門單部門和多部門情況List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());obj.put("departs", departs);if (departs == null || departs.size() == 0) {obj.put("multi_depart", 0);} else if (departs.size() == 1) {sysUserService.updateUserDepart(username, departs.get(0).getOrgCode(),null);obj.put("multi_depart", 1);} else {//查询当前是否有登录部门// update-begin--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去SysUser sysUserById = sysUserService.getById(sysUser.getId());if(oConvertUtils.isEmpty(sysUserById.getOrgCode())){sysUserService.updateUserDepart(username, departs.get(0).getOrgCode(),null);}// update-end--Author:wangshuai Date:20200805 for:如果用戶为选择部门,数据库为存在上一次登录部门,则取一条存进去obj.put("multi_depart", 2);}obj.put("sysAllDictItems", sysDictService.queryAllDictItems());result.setResult(obj);result.success("登录成功");return result;}
得出结论,即使不使用返回值,也可以通过修改传入参数对象的属性来影响主程序中的对象属性。