| | |
| | | package com.sinata.web.controller.applet; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.sinata.common.constant.Constants; |
| | | import com.sinata.common.core.domain.AjaxResult; |
| | | import com.sinata.common.core.domain.R; |
| | |
| | | import com.sinata.common.core.domain.entity.SysUser; |
| | | import com.sinata.common.core.domain.model.LoginBody; |
| | | import com.sinata.common.core.domain.model.LoginUser; |
| | | import com.sinata.common.core.redis.RedisCache; |
| | | import com.sinata.common.utils.SecurityUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.framework.web.service.SysLoginService; |
| | | import com.sinata.framework.web.service.SysPermissionService; |
| | | import com.sinata.framework.web.service.TokenService; |
| | | import com.sinata.system.domain.SysDepartment; |
| | | import com.sinata.system.domain.SysUserRole; |
| | | import com.sinata.system.domain.dto.UserInfoDTO; |
| | | import com.sinata.system.mapper.SysUserRoleMapper; |
| | | import com.sinata.system.service.ISysMenuService; |
| | | import com.sinata.system.service.ISysRoleService; |
| | | import com.sinata.system.service.ISysUserService; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import com.sinata.system.service.biz.AliSmsService; |
| | | import com.sinata.web.controller.tool.weChat.WXCore; |
| | | import com.sinata.web.controller.tool.weChat.WeChatUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private SysDepartmentService departmentService; |
| | | @Resource |
| | | private AliSmsService aliSmsService; |
| | | @Resource |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private RedisCache redisCache; |
| | | |
| | | |
| | | @PostMapping("/getCode") |
| | | @ApiOperation("获取验证码") |
| | | public AjaxResult getCode(String phone) |
| | | { |
| | | Random random = new Random(); |
| | | List<SysUser> list = userService.lambdaQuery().eq(SysUser::getPhonenumber, phone).list(); |
| | | if (list.isEmpty()){ |
| | | return AjaxResult.error("当前手机号没有对应用户,请联系管理员"); |
| | | } |
| | | int i = 100000 + random.nextInt(900000); |
| | | aliSmsService.sendLoginCode(phone, String.valueOf(i)); |
| | | redisCache.setCacheObject(String.valueOf(phone), String.valueOf(i)); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/set/getCode") |
| | | @ApiOperation("获取验证码") |
| | | public AjaxResult setgetCode(String phone) |
| | | { |
| | | Random random = new Random(); |
| | | int i = 100000 + random.nextInt(900000); |
| | | aliSmsService.sendLoginCode(phone, String.valueOf(i)); |
| | | redisCache.setCacheObject(String.valueOf(phone), String.valueOf(i)); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private WeChatUtil weChatUtil; |
| | | |
| | | |
| | | @PostMapping("/getPhone") |
| | | @ApiOperation("获取手机号") |
| | | public R getPhone(String jscoe, String EncryptedData_phone,String Iv_phone) |
| | | { |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(jscoe); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return R.fail(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | String sessionKey = map.get("sessionKey").toString(); |
| | | |
| | | |
| | | String decrypt = WXCore.decrypt(EncryptedData_phone, sessionKey, Iv_phone); |
| | | if (StringUtils.isEmpty(decrypt)) { |
| | | return R.fail("获取手机信息失败"); |
| | | } |
| | | JSONObject phone = JSON.parseObject(decrypt); |
| | | String purePhoneNumber = phone.getString("purePhoneNumber"); |
| | | return R.ok(purePhoneNumber); |
| | | |
| | | } |
| | | /** |
| | | * 登录方法 |
| | | * |
| | |
| | | // } |
| | | |
| | | List<SysMenu> menus = roleService.roleInfoFromUserId(loginUser.getUserId()); |
| | | |
| | | String string = redisCache.getCacheObject(loginBody.getUsername()).toString(); |
| | | if (!loginBody.getCode().equals(string)){ |
| | | return AjaxResult.error("验证码错误,请重试"); |
| | | } |
| | | // ajax.put("menus", menus); |
| | | ajax.put("userInfo", loginUser); |
| | | return ajax; |
| | |
| | | SysDepartment byId = departmentService.getById(user.getDepartmentId()); |
| | | return R.ok(byId); |
| | | } |
| | | @Resource |
| | | private SysUserRoleMapper sysUserRoleMapper; |
| | | @PostMapping("/get/user") |
| | | @ApiOperation("获取个人信息") |
| | | public R<UserInfoDTO> user() |
| | | { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | SysUser user1 = SecurityUtils.getLoginUser().getUser(); |
| | | SysUser user = userService.getById(user1.getUserId()); |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | | SysDepartment byId2 = departmentService.getById(user.getDepartmentId()); |
| | | UserInfoDTO userInfoDTO = new UserInfoDTO(); |
| | | userInfoDTO.setNickName(user.getNickName()); |
| | | userInfoDTO.setRoles(roles); |
| | | userInfoDTO.setDepartment(byId2); |
| | | userInfoDTO.setRoles(roles); |
| | | SysUserRole sysUserRole = sysUserRoleMapper.selectOne(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, user.getUserId())); |
| | | if (sysUserRole != null) { |
| | | SysRole byId = roleService.getById(sysUserRole.getRoleId()); |
| | | userInfoDTO.setRole(byId); |
| | | } |
| | | return R.ok(userInfoDTO); |
| | | } |
| | | |