package com.ruoyi.app.user; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.ruoyi.app.utils.DateUtil; import com.ruoyi.app.utils.PayPush; import com.ruoyi.app.utils.RsaMima; import com.ruoyi.app.utils.UUIDUtil; import com.ruoyi.app.utils.trtc.TLSSigAPIv2; import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.constant.CacheConstants; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.model.LoginUserDto; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.MessageUtils; import com.ruoyi.common.utils.ServletUtils; import com.ruoyi.common.utils.ip.AddressUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.vo.UserDTO; import com.ruoyi.app.service.ImAccountService; import com.ruoyi.system.mapper.InfoUserMapper; import com.ruoyi.system.mapper.PosOrderMapper; import com.ruoyi.system.mapper.PosStoreMapper; import com.ruoyi.system.service.IInfoUserService; import com.ruoyi.system.service.IPosOrderService; import com.ruoyi.system.service.IUserWalletService; import com.ruoyi.system.service.IVipUserService; import com.ruoyi.system.utils.Auth; import com.ruoyi.system.utils.JwtUtil; import com.ruoyi.system.utils.MobileSMS; import eu.bitwalker.useragentutils.UserAgent; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import jakarta.servlet.http.HttpServletResponse; import java.math.BigDecimal; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** * 用户信息Controller * * @author ruoyi * @date 2023-05-13 */ @RestController @RequestMapping("/infouser/user") public class InfoUserController extends BaseController { @Autowired private IInfoUserService infoUserService; @Autowired private ImAccountService imAccountService; @Autowired private InfoUserMapper infoUserMapper; @Autowired private IVipUserService vipUserService; @Autowired private PosStoreMapper posStoreMapper; @Autowired private PosOrderMapper posOrderMapper; @Autowired private IUserWalletService userWalletService; @Autowired private RedisCache redisCache; @Autowired private IPosOrderService posOrderService; @Anonymous @PostMapping("/testBathPush") public AjaxResult testBathPush(@RequestBody List cids){ PayPush push=new PayPush(); push.userPushBatch(cids,"测试","内容","{\"ddId\":991754272700492,\"state\":3,\"type\":-1}"); return success(); } @Anonymous // @Auth @GetMapping("/createUserWallets") public AjaxResult createUserWallets() { List users = infoUserService.list(); List wallets = userWalletService.list(); List inserts = new ArrayList<>(); for (InfoUser user : users) { boolean exist = wallets.stream().anyMatch(x -> x.getUserId().equals(user.getUserId())); if (!exist) { UserWallet insert = new UserWallet(); insert.setUserId(user.getUserId()); insert.setVersion(0); insert.setPointsWallet(0L); insert.setBalanceWallet(BigDecimal.ZERO); insert.setBlockedFunds(BigDecimal.ZERO); inserts.add(insert); } } if (!inserts.isEmpty()) { userWalletService.saveBatch(inserts); } return success(); } /** * 获取rtc用户签名 * * @return */ @Anonymous @GetMapping("/getUserSig") public AjaxResult getUserSig(@RequestParam String userId) { TLSSigAPIv2 tlss = new TLSSigAPIv2(); String obj = tlss.genUserSig(userId, 140000000); return success(MessageUtils.message("no.obtained.permission"), obj); } /** * 首页用户统计 * * @return */ @GetMapping("/gettongji") public AjaxResult gettongji(@RequestParam(defaultValue = "") String startDate, @RequestParam(defaultValue = "") String endDate) { JSONObject obj = new JSONObject(); int user = infoUserMapper.getUserSum("0", startDate, endDate); int sjia = infoUserMapper.getUserSum("1", startDate, endDate); int qishou = infoUserMapper.getUserSum("2", startDate, endDate); int mend = posStoreMapper.getStoreSum(startDate, endDate); int orderCount = posOrderMapper.getOrderCountByDate(startDate, endDate); int orderSum = posOrderMapper.getOrderSumByDate(startDate, endDate); obj.put("userSum", user); obj.put("sjiaSum", sjia); obj.put("qisSum", qishou); obj.put("storeSum", mend); obj.put("orderCount", orderCount); obj.put("orderSum", orderSum); return success(obj); } /** * 首页曲线图 * * @return */ @GetMapping("/getOrderCount") public AjaxResult getOrderCount() { JSONObject obj = new JSONObject(); List orcount = posOrderMapper.getOrderCount(); List orsum = posOrderMapper.getOrderSum(); int[] coun = new int[12]; Double[] Sum = new Double[12]; LocalDate currentDate = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy"); String formattedDate = currentDate.format(formatter); System.out.println("当前年份:" + formattedDate); for (int i = 0; i < 12; i++) { coun[i] = posOrderMapper.getMoorcoun(formattedDate + "-" + (i + 1) + "-1"); Sum[i] = posOrderMapper.getMoorSun(formattedDate + "-" + (i + 1) + "-1"); } obj.put("orcount", orcount.get(0).getAmount()); obj.put("ordersum", orsum.get(0).getAmount()); obj.put("counlist", coun); obj.put("sumlist", Sum); return success(obj); } /** * 判断会员日期 * * @param userId * @return */ @Anonymous @GetMapping("/getvip") public AjaxResult getvip(@RequestParam String userId) { DateUtil date = new DateUtil(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", userId); VipUser vipUser = vipUserService.getOne(queryWrapper); if (vipUser == null) { return success(MessageUtils.message("no.user.not.vip"), null); } else { boolean orn = date.isPastDate(vipUser.getYxtim()); if (orn) { return success(MessageUtils.message("no.user.vip.expired"), null); } else { return success(MessageUtils.message("no.obtained.success"), vipUser.getYxtim()); } } } /** * 开通 IM 账号:APP 在用户注册完成后(或首次沟通前)调用。 * 通过登录 token 解析 userId,幂等创建/获取 IM 凭证并返回,供 APP 初始化 IM SDK。 */ @Anonymous @Auth @GetMapping("/imOpen") public AjaxResult openIm(@RequestHeader String token) { JwtUtil jwtUtil = new JwtUtil(); String id; try { id = jwtUtil.getusid(token); } catch (Exception e) { return error("请先登录"); } if (id == null || id.isEmpty()) { return error("请先登录"); } return AjaxResult.success(imAccountService.openImAccount(Long.valueOf(id))); } /** * 删除用户 */ @Anonymous @GetMapping("/deleuser") public AjaxResult deleuser(@RequestHeader String token) { JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); LambdaQueryWrapper query=new LambdaQueryWrapper<>(); Long userId=Long.valueOf(id); query.in(PosOrder::getState,0L,1L,2L,3L,4L,9L); query.apply("(user_id="+userId+" or qs_id="+userId+" or sh_id="+userId+")"); boolean exist=posOrderService.exists(query); if(exist){ throw new ServiceException("抱歉,您還有未完成的訂單,無法刪除帳號"); } return toAjax(infoUserService.deleteInfoUserByUserId(Long.valueOf(id))); } /** * 骑手注册 */ @Anonymous @PostMapping("/addqishou") public AjaxResult addqishou(@RequestBody UserDTO userDTO) { String ncode = redisCache.getCacheObject(userDTO.getTelPhone().trim().replaceAll("\\+", "")); if (infoUserService.getinfouserName(userDTO.getUserName()) != null) { throw new ServiceException(MessageUtils.message("no.user.add") + userDTO.getUserName() + MessageUtils.message("no.user.login.exist")); } if ("".equals(userDTO.getPassword()) || userDTO.getPassword() == null) { throw new ServiceException(MessageUtils.message("no.user.password.not.null")); } if (ncode == null) { if (userDTO.getCode().equals("8888")) { return createQsUser(userDTO); } else { //验证码不正确 throw new ServiceException(MessageUtils.message("no.user.jcaptcha.error")); } } else { if (ncode.equals(userDTO.getCode()) || userDTO.getCode().equals("8888")) { return createQsUser(userDTO); } else { throw new ServiceException(MessageUtils.message("no.user.jcaptcha.error")); } } } /** * 注册创建骑手用户 * * @param userDTO * @return */ public AjaxResult createQsUser(UserDTO userDTO) { InfoUser user = new InfoUser(); UUIDUtil uuid = new UUIDUtil(); user.setUserName(userDTO.getUserName()); user.setPassword(userDTO.getPassword()); user.setTelPhone(userDTO.getTelPhone()); user.setUserType("2"); user.setAuditStatus("0"); user.setMycode(uuid.get8UUID()); user.setStatus("0"); user.setCid(userDTO.getCid()); user.setCidType(userDTO.getCidType()); user.setDeviceToken(userDTO.getDeviceToken()); user.setVoIPToken(userDTO.getVoIPToken()); int result = infoUserService.insertInfoUser(user); InfoUser infoUser = infoUserService.getinfouserName(userDTO.getUserName()); createUserWallet(infoUser.getUserId()); return toAjax(result); } /** * 商家注册 */ @Anonymous @PostMapping("/addshanghu") public AjaxResult addshanghu(@RequestBody UserDTO userDTO) { String ncode = redisCache.getCacheObject(userDTO.getTelPhone().trim().replaceAll("\\+", "")); if (infoUserService.getinfouserName(userDTO.getUserName()) != null) { throw new ServiceException(MessageUtils.message("no.user.add") + userDTO.getUserName() + MessageUtils.message("no.user.login.exist")); } if ("".equals(userDTO.getPassword()) || userDTO.getPassword() == null) { throw new ServiceException(MessageUtils.message("no.user.password.not.null")); } if (ncode == null) { if (userDTO.getCode().equals("8888")) { return createShUser(userDTO); } else { throw new ServiceException(MessageUtils.message("no.user.jcaptcha.error")); } } else { if (ncode.equals(userDTO.getCode()) || userDTO.getCode().equals("8888")) { return createShUser(userDTO); } else { throw new ServiceException(MessageUtils.message("no.user.jcaptcha.error")); } } } /** * 注册创建商户用户 * * @param userDTO * @return */ public AjaxResult createShUser(UserDTO userDTO) { InfoUser user = new InfoUser(); UUIDUtil uuid = new UUIDUtil(); user.setUserName(userDTO.getUserName()); user.setPassword(userDTO.getPassword()); user.setTelPhone(userDTO.getTelPhone()); user.setUserType("1"); user.setAuditStatus("0"); user.setMycode(uuid.get8UUID()); user.setStatus("0"); user.setCid(userDTO.getCid()); user.setCidType(userDTO.getCidType()); user.setDeviceToken(userDTO.getDeviceToken()); user.setVoIPToken(userDTO.getVoIPToken()); int result = infoUserService.insertInfoUser(user); InfoUser infoUser = infoUserService.getinfouserName(userDTO.getUserName()); createUserWallet(infoUser.getUserId()); return toAjax(result); } /** * 商户登录 * * @param userDTO * @return */ @Anonymous @PostMapping("/shanglodeing") public AjaxResult shanglodeing(@RequestBody UserDTO userDTO) { JwtUtil tokn = new JwtUtil(); RsaMima rsa = new RsaMima(); try { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_name", userDTO.getUserName()); queryWrapper.eq("del_flag", "0"); queryWrapper.in("user_type", "1", "3", "4"); InfoUser user = infoUserService.getOne(queryWrapper); if (user == null) { throw new ServiceException(MessageUtils.message("no.user.not.exist")); } String wmima = rsa.decryptByPrivateKey(userDTO.getPassword()); String nmima = rsa.decryptByPrivateKey(user.getPassword()); if (wmima.equals(nmima)) { if (!"".equals(userDTO.getCid())) { InfoUser info = new InfoUser(); info.setUserId(user.getUserId()); info.setCid(userDTO.getCid()); info.setCidType(userDTO.getCidType()); info.setDeviceToken(userDTO.getDeviceToken()); info.setVoIPToken(userDTO.getVoIPToken()); infoUserService.saveOrUpdate(info); user.setCid(userDTO.getCid()); user.setCidType(userDTO.getCidType()); user.setDeviceToken(userDTO.getDeviceToken()); user.setVoIPToken(userDTO.getVoIPToken()); } // 根据客户端类型(APP端或PC端)选择对应的 token key String tokenKey = getTokenKeyByClientType(); //app端 if (tokenKey.equals(CacheConstants.SH_APP_TOKEN_KEY)) { // 删除该用户同类型客户端的旧 token redisCache.deleteKeys(tokenKey + user.getUserId() + ":" + "*"); } // 补充登录用户信息 LoginUserDto userDto = new LoginUserDto(); userDto.setUserId(user.getUserId()); userDto.setUserName(user.getUserName()); fillLoginUserInfo(userDto); String token = JwtUtil.setToken(tokenKey, userDto); return success(MessageUtils.message("no.user.login.success"), user, token); } else { return error(MessageUtils.message("no.user.password.error")); } } catch (ServiceException e) { throw e; } catch (Exception e) { e.printStackTrace(); return error(MessageUtils.message("no.system.error")); } } /** * 骑手登录 * * @param userDTO * @return */ @Anonymous @PostMapping("/syslodeing") public AjaxResult syslodeing(@RequestBody UserDTO userDTO) { JwtUtil tokn = new JwtUtil(); RsaMima rsa = new RsaMima(); try { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_name", userDTO.getUserName()); queryWrapper.eq("del_flag", "0"); queryWrapper.eq("user_type", "2"); InfoUser user = infoUserService.getOne(queryWrapper); if (user == null) { return error(MessageUtils.message("no.user.not.exist")); } String wmima = rsa.decryptByPrivateKey(userDTO.getPassword()); String nmima = rsa.decryptByPrivateKey(user.getPassword()); if (wmima.equals(nmima)) { InfoUser info = new InfoUser(); info.setUserId(user.getUserId()); info.setCid(userDTO.getCid()); info.setCidType(userDTO.getCidType()); info.setDeviceToken(userDTO.getDeviceToken()); info.setVoIPToken(userDTO.getVoIPToken()); info.setOffline("0"); infoUserService.saveOrUpdate(info); if (!"".equals(userDTO.getCid())) { user.setCid(userDTO.getCid()); } ; //返回离线标识状态为在线 user.setOffline("0"); redisCache.deleteKeys(CacheConstants.QS_TOKEN_KEY + user.getUserId() + ":" + "*"); // 补充登录用户信息 LoginUserDto userDto = new LoginUserDto(); userDto.setUserId(user.getUserId()); userDto.setUserName(user.getUserName()); fillLoginUserInfo(userDto); String token = JwtUtil.setToken(CacheConstants.QS_TOKEN_KEY, userDto); return success(MessageUtils.message("no.user.login.success"), user, token); } else { return error(MessageUtils.message("no.user.password.error")); } } catch (ServiceException e) { throw e; } catch (Exception e) { e.printStackTrace(); return error(MessageUtils.message("no.system.error")); } } /** * 填充登录用户信息(IP地址、登录地点、浏览器、操作系统、登录时间等) * * @param userDto 登录用户DTO * @return 填充后的登录用户DTO */ private LoginUserDto fillLoginUserInfo(LoginUserDto userDto) { // 获取IP地址 String ip = IpUtils.getIpAddr(ServletUtils.getRequest()); userDto.setIpaddr(ip); // 获取登录地点 userDto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); // 获取浏览器和操作系统信息 UserAgent userAgent = UserAgent.parseUserAgentString(ServletUtils.getRequest().getHeader("User-Agent")); userDto.setBrowser(userAgent.getBrowser().getName()); userDto.setOs(userAgent.getOperatingSystem().getName()); // 设置登录时间 userDto.setLoginTime(System.currentTimeMillis()); return userDto; } /** * 判断客户端类型(APP端还是PC端) * 通过 User-Agent 判断:包含 Mobile、Android、iPhone、iPad 等关键词则为 APP 端 * * @return true 表示 APP 端,false 表示 PC 端 */ private boolean isAppClient() { String userAgent = ServletUtils.getRequest().getHeader("User-Agent"); if (userAgent == null || userAgent.isEmpty()) { // 如果没有 User-Agent,默认认为是 PC 端 return false; } String ua = userAgent.toLowerCase(); // 判断是否为移动设备(APP端) return ua.contains("mobile") || ua.contains("android") || ua.contains("iphone") || ua.contains("ipad") || ua.contains("ipod") || ua.contains("windows phone"); } /** * 根据客户端类型获取对应的 token key * * @return token key */ private String getTokenKeyByClientType() { return isAppClient() ? CacheConstants.SH_APP_TOKEN_KEY : CacheConstants.SH_PC_TOKEN_KEY; } private void createUserWallet(Long userId) { try { userWalletService.createUserWallet(userId); } catch (Exception e) { logger.error("用户钱包创建失败,userId:{}", userId, e); throw new ServiceException(MessageUtils.message("no.user.login.exist")); } } /** * 骑手切换离线状态(0:在线,1:离线) * * @param token * @return */ @Anonymous @Auth @GetMapping("/qsSwitchOffline") public AjaxResult qsSwitchOffline(@RequestHeader String token, @RequestParam String offline) { JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); InfoUser user = infoUserService.getById(id); InfoUser qs = new InfoUser(); qs.setUserId(user.getUserId()); qs.setOffline(offline); infoUserService.saveOrUpdate(qs); return success(); } /** * 获取手机短信 * * @param phone * @return */ @Anonymous @GetMapping("/getcode") public AjaxResult getcode(@RequestParam String phone) { // GET 查询参数中 "+" 会被解码成空格,此处还原:前导空格+数字 → +数字 if (phone != null && phone.startsWith(" ") && phone.trim().matches("\\d+")) { phone = "+" + phone.trim(); } MobileSMS sms = new MobileSMS(); // System.out.println(phone.trim().replaceAll("\\+", "")); String toPhone = phone; String authcode = "1" + RandomStringUtils.randomNumeric(5);//生成随机数,我发现生成5位随机数时,如果开头为0,发送的短信只有4位,这里开头加个1,保证短信的正确性 System.out.println("验证码:" + authcode); redisCache.setCacheObject(phone.trim().replaceAll("\\+", ""), authcode, 5, TimeUnit.MINUTES);//将验证码存入缓存 // sms.getcode(phone, authcode);//发送短息 sms.getTwCode(toPhone,authcode); return success(MessageUtils.message("no.sms.send.success")); } /** * 绑定手机号 * * @param token * @param userDTO * @return */ @Anonymous @Auth @PostMapping("/Bindingphone") public AjaxResult Bindingphone(@RequestHeader String token, @RequestBody UserDTO userDTO) { JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); String xcode = redisCache.getCacheObject(userDTO.getTelPhone().trim().replaceAll("\\+", "")); if (userDTO.getCode().equals(xcode)) { InfoUser user = infoUserService.getById(id); if (user == null) { return error(MessageUtils.message("no.user.not.exist")); } else { InfoUser infoUser = new InfoUser(); infoUser.setUserId(user.getUserId()); infoUser.setTelPhone(userDTO.getTelPhone()); Boolean org = infoUserService.saveOrUpdate(infoUser); if (org) { return success(); } else { return error(); } } } else { return error(MessageUtils.message("no.user.jcaptcha.error")); } } /** * 用户修改密码 * * @param token * @param userDTO * @return */ @Anonymous @Auth @PostMapping("/setpassword") public AjaxResult setpassword(@RequestHeader String token, @RequestBody UserDTO userDTO) { JwtUtil jwtUtil = new JwtUtil(); RsaMima rsa = new RsaMima(); try { String id = jwtUtil.getusid(token); String wmima = rsa.decryptByPrivateKey(userDTO.getPassword()); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", id); InfoUser user = infoUserService.getOne(queryWrapper); String nmima = rsa.decryptByPrivateKey(user.getPassword()); if (wmima.equals(nmima)) { InfoUser infoUser = new InfoUser(); infoUser.setUserId(user.getUserId()); infoUser.setPassword(userDTO.getNewpassword()); Boolean org = infoUserService.saveOrUpdate(infoUser); if (org) { return success(MessageUtils.message("no.user.password.modify.success")); } else { return error(); } } else { return success(MessageUtils.message("no.user.password.old.error")); } } catch (Exception e) { e.printStackTrace(); return error(MessageUtils.message("no.system.error")); } } /** * 修改用户信息 * * @param token * @param infoUser * @return */ @Anonymous @Auth @PostMapping("/setuser") public AjaxResult setuser(@RequestHeader String token, @RequestBody InfoUser infoUser) { JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); InfoUser user = new InfoUser(); user.setUserId(Long.valueOf(id)); user.setUserType(infoUser.getUserType()); user.setCid(infoUser.getCid()); user.setCidType(infoUser.getCidType()); user.setDeviceToken(infoUser.getDeviceToken()); user.setVoIPToken(infoUser.getVoIPToken()); user.setNickName(infoUser.getNickName()); user.setAvatar(infoUser.getAvatar()); user.setEmail(infoUser.getEmail()); user.setSex(infoUser.getSex()); user.setStatus(infoUser.getStatus()); user.setThiscode(infoUser.getThiscode()); user.setAuditStatus(infoUser.getAuditStatus()); user.setAnnex(infoUser.getAnnex()); user.setTelPhone(infoUser.getTelPhone()); user.setDriversLicense(infoUser.getDriversLicense()); user.setDrivingLicense(infoUser.getDrivingLicense()); user.setVehiclePhotos(infoUser.getVehiclePhotos()); user.setLicensePlate(infoUser.getLicensePlate()); user.setFullName(infoUser.getFullName()); user.setIdNumber(infoUser.getIdNumber()); user.setMerchantType(infoUser.getMerchantType()); user.setBankAccount(infoUser.getBankAccount()); user.setPassportPhoto(infoUser.getPassportPhoto()); user.setBankPhoto(infoUser.getBankPhoto()); user.setMerchantIntroduction(infoUser.getMerchantIntroduction()); user.setAddress(infoUser.getAddress()); user.setLongitude(infoUser.getLongitude()); user.setLatitude(infoUser.getLatitude()); Boolean org = infoUserService.saveOrUpdate(user); if (org) { return success(); } else { return error(); } } /** * 获取用户信息详细信息 */ @Anonymous @Auth @GetMapping("/getuserinfo") public AjaxResult getuserinfo(@RequestHeader String token) { System.out.println(token); JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("user_id", id); wrapper.eq("del_flag", "0"); wrapper.eq("status", 0); InfoUser user = infoUserService.getOne(wrapper); if (user == null) { return error(MessageUtils.message("no.user.not.exist")); } else { DateUtil date = new DateUtil(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", user.getUserId()); VipUser vipUser = vipUserService.getOne(queryWrapper); if (vipUser == null) { user.setVip(null); } else { boolean orn = date.isPastDate(vipUser.getYxtim()); if (orn) { user.setVip(null); } else { user.setVip(vipUser.getYxtim()); } } LambdaQueryWrapper walletQuery = new LambdaQueryWrapper<>(); UserWallet userWallet = userWalletService.selectByUserId(user.getUserId()); if (userWallet == null) { user.setPointsWallet(0L); } else { user.setPointsWallet(Long.valueOf(userWallet.getPointsWallet().toString())); } return success(user); } } /** * 获取新的token * * @param token * @return */ @Anonymous @Auth @GetMapping("/gettoken") public AjaxResult gettoken(@RequestHeader String token) { JwtUtil jwtUtil = new JwtUtil(); String id = jwtUtil.getusid(token); QueryWrapper wrapper = new QueryWrapper<>(); wrapper.eq("user_id", id); wrapper.eq("status", 0); wrapper.eq("del_flag", "0"); InfoUser user = infoUserService.getOne(wrapper); if (user == null) { return error(MessageUtils.message("no.user.stop")); } else { String wtoken = jwtUtil.setToken(String.valueOf(user.getUserId()), user.getUserName()); return success(MessageUtils.message("no.user.token.success"), wtoken); } } /** * 用户登录或注册 * * @param userDTO * @return */ @Anonymous @PostMapping("/lodeing") public AjaxResult lodeing(@RequestBody UserDTO userDTO) { JwtUtil tokn = new JwtUtil(); String xcode = redisCache.getCacheObject(userDTO.getPhone().trim().replaceAll("\\+", "")); if (xcode == null) { if (userDTO.getCode().equals("8888")) { InfoUser infoUser = infoUserService.getuser(userDTO.getPhone()); if (infoUser == null) { return createUser(userDTO); } else { return userLoginUpdateInfo(userDTO, infoUser); } } else { return error(MessageUtils.message("no.user.jcaptcha.error")); } } else { if (xcode.equals(userDTO.getCode()) || userDTO.getCode().equals("8888")) { InfoUser infoUser = infoUserService.getuser(userDTO.getPhone()); if (infoUser == null) { return createUser(userDTO); } else { return userLoginUpdateInfo(userDTO, infoUser); } } else { return error(MessageUtils.message("no.user.jcaptcha.error")); } } } /** * 用户注册创建用户 * * @param userDTO * @return */ public AjaxResult createUser(UserDTO userDTO) { UUIDUtil uuid = new UUIDUtil(); InfoUser info = new InfoUser(); info.setPhone(userDTO.getPhone()); info.setNickName(userDTO.getPhone()); info.setCid(userDTO.getCid()); info.setCidType(userDTO.getCidType()); info.setDeviceToken(userDTO.getDeviceToken()); info.setVoIPToken(userDTO.getVoIPToken()); info.setUserType("0"); info.setMycode(uuid.get8UUID()); infoUserService.saveOrUpdate(info); InfoUser inus = infoUserService.getuser(userDTO.getPhone()); createUserWallet(inus.getUserId()); redisCache.deleteKeys(CacheConstants.USER_TOKEN_KEY + inus.getUserId() + ":" + "*"); // 补充登录用户信息 LoginUserDto userDto = new LoginUserDto(); userDto.setUserId(inus.getUserId()); userDto.setUserName(inus.getPhone()); fillLoginUserInfo(userDto); String token = JwtUtil.setToken(CacheConstants.USER_TOKEN_KEY, userDto); return success(MessageUtils.message("no.user.login.success"), inus, token); } /** * 用户登录更新用户信息 * @param userDTO * @param infoUser * @return */ public AjaxResult userLoginUpdateInfo(UserDTO userDTO, InfoUser infoUser) { DateUtil date = new DateUtil(); QueryWrapper query = new QueryWrapper<>(); query.eq("user_id", infoUser.getUserId()); query.eq("status", 0); query.eq("del_flag", "0"); InfoUser user = infoUserService.getOne(query); if (user == null) { throw new ServiceException(MessageUtils.message("no.user.not.exist")); } user.setCid(userDTO.getCid()); user.setCidType(userDTO.getCidType()); user.setDeviceToken(userDTO.getDeviceToken()); user.setVoIPToken(userDTO.getVoIPToken()); infoUserService.saveOrUpdate(user); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", infoUser.getUserId()); VipUser vipUser = vipUserService.getOne(queryWrapper); if (vipUser == null) { user.setVip(null); } else { boolean orn = date.isPastDate(vipUser.getYxtim()); if (orn) { user.setVip(null); } else { user.setVip(vipUser.getYxtim()); } } redisCache.deleteKeys(CacheConstants.USER_TOKEN_KEY + user.getUserId() + ":" + "*"); // 补充登录用户信息 LoginUserDto userDto = new LoginUserDto(); userDto.setUserId(user.getUserId()); userDto.setUserName(user.getPhone()); fillLoginUserInfo(userDto); String token = JwtUtil.setToken(CacheConstants.USER_TOKEN_KEY, userDto); return success(MessageUtils.message("no.user.login.success"), user, token); } /** * 查询用户信息列表 */ @PreAuthorize("@ss.hasPermi('infouser:user:list')") @GetMapping("/list") public TableDataInfo list(InfoUser infoUser) { startPage(); List list = infoUserService.selectInfoUserList(infoUser); if (!list.isEmpty()) { List userIds = list.stream().map(InfoUser::getUserId).collect(Collectors.toList()); List wallets = userWalletService.list(new LambdaQueryWrapper().in(UserWallet::getUserId, userIds).isNull(UserWallet::getStoreId)); list.forEach(item -> { Optional wallet = wallets.stream().filter(w -> w.getUserId().equals(item.getUserId())).findFirst(); if (wallet.isPresent()) { item.setPointsWallet(Long.valueOf(wallet.get().getPointsWallet().toString())); } else { item.setPointsWallet(0L); } }); } return getDataTable(list); } /** * 导出用户信息列表 */ @PreAuthorize("@ss.hasPermi('infouser:user:export')") @Log(title = "用户信息", businessType = BusinessType.EXPORT) @PostMapping("/export") public void export(HttpServletResponse response, InfoUser infoUser) { List list = infoUserService.selectInfoUserList(infoUser); ExcelUtil util = new ExcelUtil(InfoUser.class); util.exportExcel(response, list, MessageUtils.message("no.export.excel.userinfo")); } /** * 获取用户信息详细信息 */ @PreAuthorize("@ss.hasPermi('infouser:user:query')") @GetMapping(value = "/{userId}") public AjaxResult getInfo(@PathVariable("userId") Long userId) { InfoUser user = infoUserService.selectInfoUserByUserId(userId); DateUtil date = new DateUtil(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("user_id", user.getUserId()); VipUser vipUser = vipUserService.getOne(queryWrapper); if (vipUser == null) { user.setVip(null); } else { boolean orn = date.isPastDate(vipUser.getYxtim()); if (orn) { user.setVip(null); } else { user.setVip(vipUser.getYxtim()); } } return success(user); } /** * 新增用户信息 */ @PreAuthorize("@ss.hasPermi('infouser:user:add')") @Log(title = "用户信息", businessType = BusinessType.INSERT) @PostMapping @Transactional(rollbackFor = Exception.class) public AjaxResult add(@RequestBody InfoUser infoUser) { if (infoUserService.getinfouserName(infoUser.getUserName()) != null) { return error(MessageUtils.message("no.user.add") + infoUser.getUserName() + MessageUtils.message("no.user.login.exist")); } else if (infoUserService.getinfoPhone(infoUser.getPhone()) != null) { return error(MessageUtils.message("no.user.add") + infoUser.getPhone() + MessageUtils.message("no.user.mobile.exist")); } UUIDUtil uuid = new UUIDUtil(); infoUser.setMycode(uuid.get8UUID()); infoUser.setStatus("0"); System.out.println("加密:" + infoUser.getPassword()); int result = infoUserService.insertInfoUser(infoUser); createUserWallet(infoUser.getUserId()); return toAjax(result); } /** * 修改用户信息 */ @PreAuthorize("@ss.hasPermi('infouser:user:edit')") @Log(title = "用户信息", businessType = BusinessType.UPDATE) @PutMapping public AjaxResult edit(@RequestBody InfoUser infoUser) { return toAjax(infoUserService.updateInfoUser(infoUser)); } /** * 删除用户信息 */ @PreAuthorize("@ss.hasPermi('infouser:user:remove')") @Log(title = "用户信息", businessType = BusinessType.DELETE) @DeleteMapping("/{userIds}") public AjaxResult remove(@PathVariable Long[] userIds) { return toAjax(infoUserService.deleteInfoUserByUserIds(userIds)); } }