diff --git a/src/main/java/com/gxwebsoft/common/system/controller/UserRefereeController.java b/src/main/java/com/gxwebsoft/common/system/controller/UserRefereeController.java index 83e1d8e..743173a 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/UserRefereeController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/UserRefereeController.java @@ -70,7 +70,7 @@ public class UserRefereeController extends BaseController { // 记录当前登录用户id User loginUser = getLoginUser(); if (loginUser != null) { - userReferee.setUserId(loginUser.getUserId()); + userReferee.setUserId(loginUser.getUserId()); } if (userRefereeService.save(userReferee)) { return success("添加成功"); @@ -136,23 +136,48 @@ public class UserRefereeController extends BaseController { @ApiOperation("查询推荐人信息") @GetMapping("/getReferee/{id}") public ApiResult getReferee(@PathVariable("id") Integer id) { - if(id == null){ - return fail("参数错误",null); - } + if (id == null) { + return fail("参数错误", null); + } - final UserReferee referee = userRefereeService.getOne(new LambdaQueryWrapper() - .eq(UserReferee::getUserId, id) - .eq(UserReferee::getDeleted,0)); + final UserReferee referee = userRefereeService.getOne(new LambdaQueryWrapper() + .eq(UserReferee::getUserId, id) + .eq(UserReferee::getDeleted, 0)); - if (ObjectUtil.isEmpty(referee)) { - return fail("查询失败",null); - } + if (ObjectUtil.isEmpty(referee)) { + return fail("查询失败", null); + } - final User user = userService.getByIdRel(referee.getDealerId()); - if (ObjectUtil.isNotEmpty(user)) { - return success(user); - } - return fail("查询失败",null); + final User user = userService.getByIdRel(referee.getDealerId()); + if (ObjectUtil.isNotEmpty(user)) { + return success(user); + } + return fail("查询失败", null); + } + + @ApiOperation("查询推荐人列表") + @GetMapping("/getRefereeList/{id}") + public ApiResult> getRefereeList(@PathVariable("id") Integer id) { + if (id == null) { + return fail("参数错误", null); + } + + final List refereeList = userRefereeService.list(new LambdaQueryWrapper() + .eq(UserReferee::getUserId, id) + .eq(UserReferee::getDeleted, 0)); + + if (ObjectUtil.isEmpty(refereeList)) { + return fail("查询失败", null); + } + + final List users = userService.list( + new LambdaQueryWrapper() + .in(User::getUserId, refereeList.stream().map(UserReferee::getDealerId).toList()) + ); + if (ObjectUtil.isNotEmpty(users)) { + return success(users); + } + return fail("查询失败", null); } } diff --git a/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java b/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java index b27e89c..f3e0efa 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/WxLoginController.java @@ -42,369 +42,381 @@ import static com.gxwebsoft.common.core.constants.RedisConstants.ACCESS_TOKEN_KE @RequestMapping("/api/wx-login") @Api(tags = "微信小程序登录API") public class WxLoginController extends BaseController { - private final StringRedisTemplate redisTemplate; - @Resource - private SettingService settingService; - @Resource - private UserService userService; - @Resource - private ConfigProperties configProperties; - @Resource - private UserRoleService userRoleService; - @Resource - private LoginRecordService loginRecordService; - @Resource - private RoleService roleService; - @Resource - private RedisUtil redisUtil; - @Resource - private ConfigProperties config; + private final StringRedisTemplate redisTemplate; + @Resource + private SettingService settingService; + @Resource + private UserService userService; + @Resource + private ConfigProperties configProperties; + @Resource + private UserRoleService userRoleService; + @Resource + private LoginRecordService loginRecordService; + @Resource + private RoleService roleService; + @Resource + private RedisUtil redisUtil; + @Resource + private ConfigProperties config; + @Resource + private UserRefereeService userRefereeService; - public WxLoginController(StringRedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } + public WxLoginController(StringRedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } - @ApiOperation("获取微信openId") - @Transactional(rollbackFor = {Exception.class}) - @PostMapping("/getOpenId") - public ApiResult getOpenId(@RequestBody UserParam userParam, HttpServletRequest request) { - // 1.获取openid - JSONObject result = getOpenIdByCode(userParam); - String openid = result.getString("openid"); - String unionid = result.getString("unionid"); - if (openid == null) { - return fail("获取openid失败", null); + @ApiOperation("获取微信openId") + @Transactional(rollbackFor = {Exception.class}) + @PostMapping("/getOpenId") + public ApiResult getOpenId(@RequestBody UserParam userParam, HttpServletRequest request) { + // 1.获取openid + JSONObject result = getOpenIdByCode(userParam); + String openid = result.getString("openid"); + String unionid = result.getString("unionid"); + if (openid == null) { + return fail("获取openid失败", null); + } + // 2.通过openid查询用户是否已存在 + User user = userService.getByOauthId(userParam); + // 3.存在则签发token并返回登录成功,不存在则注册新用户 + if (user == null) { + user = addUser(userParam); + } + // 4.签发token + loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request); + String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()), + configProperties.getTokenExpireTime(), configProperties.getTokenKey()); + return success("登录成功", new LoginResult(access_token, user)); } - // 2.通过openid查询用户是否已存在 - User user = userService.getByOauthId(userParam); - // 3.存在则签发token并返回登录成功,不存在则注册新用户 - if (user == null) { - user = addUser(userParam); - } - // 4.签发token - loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_LOGIN, null, user.getTenantId(), request); - String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()), - configProperties.getTokenExpireTime(), configProperties.getTokenKey()); - return success("登录成功", new LoginResult(access_token, user)); - } - @ApiOperation("微信授权手机号码并登录") - @Transactional(rollbackFor = {Exception.class}) - @PostMapping("/loginByMpWxPhone") - public ApiResult loginByMpWxPhone(@RequestBody UserParam userParam, HttpServletRequest request) { - // 获取手机号码 - String phone = getPhoneByCode(userParam); - if(phone == null){ - String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); - redisTemplate.delete(key); - throw new BusinessException("授权失败,请重试"); - } - // 查询是否存在 - User user = userService.getByPhone(phone); - // 不存在则注册 - if (user == null) { - userParam.setPhone(phone); - user = addUser(userParam); - user.setRecommend(1); - } - // 签发token - String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()), - configProperties.getTokenExpireTime(), configProperties.getTokenKey()); - loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_REGISTER, null, user.getTenantId(), request); - // 附加体育中心项目用户信息 + @ApiOperation("微信授权手机号码并登录") + @Transactional(rollbackFor = {Exception.class}) + @PostMapping("/loginByMpWxPhone") + public ApiResult loginByMpWxPhone(@RequestBody UserParam userParam, HttpServletRequest request) { + // 获取手机号码 + String phone = getPhoneByCode(userParam); + if (phone == null) { + String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); + redisTemplate.delete(key); + throw new BusinessException("授权失败,请重试"); + } + // 查询是否存在 + User user = userService.getByPhone(phone); + // 不存在则注册 + if (user == null) { + userParam.setPhone(phone); + user = addUser(userParam); + user.setRecommend(1); + } + // 签发token + String access_token = JwtUtil.buildToken(new JwtSubject(user.getUsername(), user.getTenantId()), + configProperties.getTokenExpireTime(), configProperties.getTokenKey()); + loginRecordService.saveAsync(user.getUsername(), LoginRecord.TYPE_REGISTER, null, user.getTenantId(), request); + // 附加体育中心项目用户信息 // user.setBookingUser(); - return success("登录成功", new LoginResult(access_token, user)); - } + return success("登录成功", new LoginResult(access_token, user)); + } - @ApiOperation("微信授权手机号码并更新") - @Transactional(rollbackFor = {Exception.class}) - @PostMapping("/updatePhoneByMpWx") - public ApiResult updatePhoneByMpWx(@RequestBody UserParam userParam) { - // 获取微信授权手机号 - String phone = getPhoneByCode(userParam); - // 查询当前用户 - User user = userService.getById(userParam.getUserId()); - if (user != null && phone != null) { - user.setPhone(phone); - userService.updateUser(user); - return success("更新成功",phone); + @ApiOperation("微信授权手机号码并更新") + @Transactional(rollbackFor = {Exception.class}) + @PostMapping("/updatePhoneByMpWx") + public ApiResult updatePhoneByMpWx(@RequestBody UserParam userParam) { + // 获取微信授权手机号 + String phone = getPhoneByCode(userParam); + // 查询当前用户 + User user = userService.getById(userParam.getUserId()); + if (user != null && phone != null) { + user.setPhone(phone); + userService.updateUser(user); + return success("更新成功", phone); + } + return fail("更新失败"); } - return fail("更新失败"); - } - /** - * 新用户注册 - */ - private User addUser(UserParam userParam) { - User addUser = new User(); - // 注册用户 - addUser.setStatus(0); - addUser.setUsername(createUsername("wx_")); - addUser.setNickname("微信用户"); - addUser.setPlatform(MP_WEIXIN); - addUser.setGradeId(2); - if(userParam.getGradeId() != null){ - addUser.setGradeId(userParam.getGradeId()); + /** + * 新用户注册 + */ + private User addUser(UserParam userParam) { + User addUser = new User(); + // 注册用户 + addUser.setStatus(0); + addUser.setUsername(createUsername("wx_")); + addUser.setNickname("微信用户"); + addUser.setPlatform(MP_WEIXIN); + addUser.setGradeId(2); + if (userParam.getGradeId() != null) { + addUser.setGradeId(userParam.getGradeId()); + } + if (userParam.getPhone() != null) { + addUser.setPhone(userParam.getPhone()); + } + if (StrUtil.isNotBlank(userParam.getOpenid())) { + addUser.setOpenid(userParam.getOpenid()); + } + if (StrUtil.isNotBlank(userParam.getUnionid())) { + addUser.setUnionid(userParam.getUnionid()); + } + addUser.setPassword(userService.encodePassword(CommonUtil.randomUUID16())); + addUser.setTenantId(getTenantId()); + addUser.setRecommend(1); + Role role = roleService.getOne(new QueryWrapper().eq("role_code", "user"), false); + addUser.setRoleId(role.getRoleId()); + if (userService.saveUser(addUser)) { + // 添加用户角色 + final UserRole userRole = new UserRole(); + userRole.setUserId(addUser.getUserId()); + userRole.setTenantId(addUser.getTenantId()); + userRole.setRoleId(addUser.getRoleId()); + userRoleService.save(userRole); + } + // 绑定关系 + if (userParam.getSceneType() != null && userParam.getSceneType().equals("save_referee") && userParam.getRefereeId() != null) { + UserReferee check = userRefereeService.check(addUser.getUserId(), userParam.getRefereeId()); + if (check == null) { + UserReferee userReferee = new UserReferee(); + userReferee.setDealerId(addUser.getUserId()); + userReferee.setUserId(userParam.getRefereeId()); + userRefereeService.save(userReferee); + } + } + return addUser; } - if(userParam.getPhone() != null){ - addUser.setPhone(userParam.getPhone()); - } - if(StrUtil.isNotBlank(userParam.getOpenid())){ - addUser.setOpenid(userParam.getOpenid()); - } - if(StrUtil.isNotBlank(userParam.getUnionid())){ - addUser.setUnionid(userParam.getUnionid()); - } - addUser.setPassword(userService.encodePassword(CommonUtil.randomUUID16())); - addUser.setTenantId(getTenantId()); - addUser.setRecommend(1); - Role role = roleService.getOne(new QueryWrapper().eq("role_code", "user"), false); - addUser.setRoleId(role.getRoleId()); - if (userService.saveUser(addUser)) { - // 添加用户角色 - final UserRole userRole = new UserRole(); - userRole.setUserId(addUser.getUserId()); - userRole.setTenantId(addUser.getTenantId()); - userRole.setRoleId(addUser.getRoleId()); - userRoleService.save(userRole); - } - return addUser; - } - // 获取openid - private JSONObject getOpenIdByCode(UserParam userParam) { - // 获取微信小程序配置信息 - JSONObject setting = settingService.getBySettingKey("mp-weixin"); - // 获取openId - String apiUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + setting.getString("appId") + "&secret=" + setting.getString("appSecret") + "&js_code=" + userParam.getCode() + "&grant_type=authorization_code"; - // 执行get请求 - String result = HttpUtil.get(apiUrl); - // 解析access_token - return JSON.parseObject(result); - } - - /** - * 获取微信手机号码 - * - * @param userParam 需要传微信凭证code - */ - private String getPhoneByCode(UserParam userParam) { - // 获取手机号码 - String apiUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken(); - HashMap paramMap = new HashMap<>(); - if (StrUtil.isBlank(userParam.getCode())) { - throw new BusinessException("code不能为空"); + // 获取openid + private JSONObject getOpenIdByCode(UserParam userParam) { + // 获取微信小程序配置信息 + JSONObject setting = settingService.getBySettingKey("mp-weixin"); + // 获取openId + String apiUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + setting.getString("appId") + "&secret=" + setting.getString("appSecret") + "&js_code=" + userParam.getCode() + "&grant_type=authorization_code"; + // 执行get请求 + String result = HttpUtil.get(apiUrl); + // 解析access_token + return JSON.parseObject(result); } - paramMap.put("code", userParam.getCode()); - // 执行post请求 - String post = HttpUtil.post(apiUrl, JSON.toJSONString(paramMap)); - JSONObject json = JSON.parseObject(post); - if (json.get("errcode").equals(0)) { - JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info")); - // 微信用户的手机号码 - final String phoneNumber = phoneInfo.getString("phoneNumber"); - // 验证手机号码 - if(userParam.getNotVerifyPhone() == null && !Validator.isMobile(phoneNumber)){ + + /** + * 获取微信手机号码 + * + * @param userParam 需要传微信凭证code + */ + private String getPhoneByCode(UserParam userParam) { + // 获取手机号码 + String apiUrl = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + getAccessToken(); + HashMap paramMap = new HashMap<>(); + if (StrUtil.isBlank(userParam.getCode())) { + throw new BusinessException("code不能为空"); + } + paramMap.put("code", userParam.getCode()); + // 执行post请求 + String post = HttpUtil.post(apiUrl, JSON.toJSONString(paramMap)); + JSONObject json = JSON.parseObject(post); + if (json.get("errcode").equals(0)) { + JSONObject phoneInfo = JSON.parseObject(json.getString("phone_info")); + // 微信用户的手机号码 + final String phoneNumber = phoneInfo.getString("phoneNumber"); + // 验证手机号码 + if (userParam.getNotVerifyPhone() == null && !Validator.isMobile(phoneNumber)) { + String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); + redisTemplate.delete(key); + throw new BusinessException("手机号码格式不正确"); + } + return phoneNumber; + } + return null; + } + + /** + * 生成随机账号 + * + * @return username + */ + private String createUsername(String type) { + return type.concat(RandomUtil.randomString(12)); + } + + /** + * 获取接口调用凭据AccessToken + * ... + */ + private String getAccessToken() { String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); - redisTemplate.delete(key); - throw new BusinessException("手机号码格式不正确"); - } - return phoneNumber; - } - return null; - } - - /** - * 生成随机账号 - * - * @return username - */ - private String createUsername(String type) { - return type.concat(RandomUtil.randomString(12)); - } - - /** - * 获取接口调用凭据AccessToken - * ... - */ - private String getAccessToken() { - String key = ACCESS_TOKEN_KEY.concat(":").concat(getTenantId().toString()); - // 获取微信小程序配置信息 - JSONObject setting = settingService.getBySettingKey("mp-weixin"); - if(setting == null){ - throw new BusinessException("请先配置小程序"); - } - // 从缓存获取access_token - String value = redisTemplate.opsForValue().get(key); - if (value != null) { - // 解析access_token - JSONObject response = JSON.parseObject(value); + // 获取微信小程序配置信息 + JSONObject setting = settingService.getBySettingKey("mp-weixin"); + if (setting == null) { + throw new BusinessException("请先配置小程序"); + } + // 从缓存获取access_token + String value = redisTemplate.opsForValue().get(key); + if (value != null) { + // 解析access_token + JSONObject response = JSON.parseObject(value); // return response.getString("access_token"); + } + // 微信获取凭证接口 + String apiUrl = "https://api.weixin.qq.com/cgi-bin/token"; + // 组装url参数 + String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(setting.getString("appId")).concat("&secret=").concat(setting.getString("appSecret")); + // 执行get请求 + String result = HttpUtil.get(url); + System.out.println("result = " + result); + // 解析access_token + JSONObject response = JSON.parseObject(result); + if (response.getString("access_token") != null) { + // 存入缓存 + redisTemplate.opsForValue().set(key, result, 7000L, TimeUnit.SECONDS); + return response.getString("access_token"); + } + throw new BusinessException("小程序配置不正确"); } - // 微信获取凭证接口 - String apiUrl = "https://api.weixin.qq.com/cgi-bin/token"; - // 组装url参数 - String url = apiUrl.concat("?grant_type=client_credential").concat("&appid=").concat(setting.getString("appId")).concat("&secret=").concat(setting.getString("appSecret")); - // 执行get请求 - String result = HttpUtil.get(url); - System.out.println("result = " + result); - // 解析access_token - JSONObject response = JSON.parseObject(result); - if (response.getString("access_token") != null) { - // 存入缓存 - redisTemplate.opsForValue().set(key, result,7000L, TimeUnit.SECONDS); - return response.getString("access_token"); - } - throw new BusinessException("小程序配置不正确"); - } - @ApiOperation("获取微信openId") - @PostMapping("/getWxOpenId") - public ApiResult getWxOpenId(@RequestBody UserParam userParam) { - final User loginUser = getLoginUser(); - if(loginUser == null){ - return fail("请先登录"); + @ApiOperation("获取微信openId") + @PostMapping("/getWxOpenId") + public ApiResult getWxOpenId(@RequestBody UserParam userParam) { + final User loginUser = getLoginUser(); + if (loginUser == null) { + return fail("请先登录"); + } + // 已存在直接返回 + if (StrUtil.isNotBlank(loginUser.getOpenid())) { + return success(loginUser); + } + // 请求微信接口获取openid + String apiUrl = "https://api.weixin.qq.com/sns/jscode2session"; + final HashMap map = new HashMap<>(); + final JSONObject setting = settingService.getBySettingKey("mp-weixin"); + final String appId = setting.getString("appId"); + final String appSecret = setting.getString("appSecret"); + map.put("appid", appId); + map.put("secret", appSecret); + map.put("js_code", userParam.getCode()); + map.put("grant_type", "authorization_code"); + final String response = HttpUtil.get(apiUrl, map); + final JSONObject jsonObject = JSONObject.parseObject(response); + String openid = jsonObject.getString("openid"); + String sessionKey = jsonObject.getString("session_key"); + String unionid = jsonObject.getString("unionid"); + // 保存openID + if (loginUser.getOpenid() == null || StrUtil.isBlank(loginUser.getOpenid())) { + loginUser.setOpenid(openid); + loginUser.setUnionid(unionid); + userService.updateById(loginUser); + } + return success("获取成功", jsonObject); } - // 已存在直接返回 - if(StrUtil.isNotBlank(loginUser.getOpenid())){ - return success(loginUser); - } - // 请求微信接口获取openid - String apiUrl = "https://api.weixin.qq.com/sns/jscode2session"; - final HashMap map = new HashMap<>(); - final JSONObject setting = settingService.getBySettingKey("mp-weixin"); - final String appId = setting.getString("appId"); - final String appSecret = setting.getString("appSecret"); - map.put("appid",appId); - map.put("secret",appSecret); - map.put("js_code",userParam.getCode()); - map.put("grant_type","authorization_code"); - final String response = HttpUtil.get(apiUrl,map); - final JSONObject jsonObject = JSONObject.parseObject(response); - String openid = jsonObject.getString("openid"); - String sessionKey = jsonObject.getString("session_key"); - String unionid = jsonObject.getString("unionid"); - // 保存openID - if(loginUser.getOpenid() == null || StrUtil.isBlank(loginUser.getOpenid())){ - loginUser.setOpenid(openid); - loginUser.setUnionid(unionid); - userService.updateById(loginUser); - } - return success("获取成功",jsonObject); - } - @ApiOperation("获取微信小程序码-用户ID") - @GetMapping("/getUserQRCode") - public ApiResult getQRCode() { - String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken(); - final HashMap map = new HashMap<>(); - map.put("path","/package/user/qrcode?user_id="+getLoginUserId()); + @ApiOperation("获取微信小程序码-用户ID") + @GetMapping("/getUserQRCode") + public ApiResult getQRCode() { + String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken(); + final HashMap map = new HashMap<>(); + map.put("path", "/package/user/qrcode?user_id=" + getLoginUserId()); // map.put("env_version","trial"); - // 获取图片 Buffer - byte[] qrCode = HttpRequest.post(apiUrl) - .body(JSON.toJSONString(map)) - .execute().bodyBytes(); + // 获取图片 Buffer + byte[] qrCode = HttpRequest.post(apiUrl) + .body(JSON.toJSONString(map)) + .execute().bodyBytes(); - // 保存的文件名称 - final String fileName = CommonUtil.randomUUID8().concat(".png"); - // 保存路径 - String filePath = getUploadDir().concat("qrcode/") + fileName; - File file = FileUtil.writeBytes(qrCode, filePath); - if(file != null){ - return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + // 保存的文件名称 + final String fileName = CommonUtil.randomUUID8().concat(".png"); + // 保存路径 + String filePath = getUploadDir().concat("qrcode/") + fileName; + File file = FileUtil.writeBytes(qrCode, filePath); + if (file != null) { + return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + } + return fail("获取失败", null); } - return fail("获取失败",null); - } - @ApiOperation("获取微信小程序码-订单核销码") - @GetMapping("/getOrderQRCode/{orderNo}") - public ApiResult getOrderQRCode(@PathVariable("orderNo") String orderNo) { - String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken(); - final HashMap map = new HashMap<>(); - map.put("path","/package/admin/order-scan?orderNo=".concat(orderNo)); - map.put("env_version","trial"); - // 获取图片 Buffer - byte[] qrCode = HttpRequest.post(apiUrl) - .body(JSON.toJSONString(map)) - .execute().bodyBytes(); + @ApiOperation("获取微信小程序码-订单核销码") + @GetMapping("/getOrderQRCode/{orderNo}") + public ApiResult getOrderQRCode(@PathVariable("orderNo") String orderNo) { + String apiUrl = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + getAccessToken(); + final HashMap map = new HashMap<>(); + map.put("path", "/package/admin/order-scan?orderNo=".concat(orderNo)); + map.put("env_version", "trial"); + // 获取图片 Buffer + byte[] qrCode = HttpRequest.post(apiUrl) + .body(JSON.toJSONString(map)) + .execute().bodyBytes(); - // 保存的文件名称 - final String fileName = CommonUtil.randomUUID8().concat(".png"); - // 保存路径 - String filePath = getUploadDir().concat("qrcode/") + fileName; - File file = FileUtil.writeBytes(qrCode, filePath); - if(file != null){ - return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + // 保存的文件名称 + final String fileName = CommonUtil.randomUUID8().concat(".png"); + // 保存路径 + String filePath = getUploadDir().concat("qrcode/") + fileName; + File file = FileUtil.writeBytes(qrCode, filePath); + if (file != null) { + return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + } + return fail("获取失败", null); } - return fail("获取失败",null); - } - @ApiOperation("获取微信小程序码-订单核销码-数量极多的业务场景") - @GetMapping("/getOrderQRCodeUnlimited/{orderNo}") - public ApiResult getOrderQRCodeUnlimited(@PathVariable("orderNo") String orderNo) { - String apiUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + getAccessToken(); - final HashMap map = new HashMap<>(); - map.put("scene","orderNo=".concat(orderNo)); - map.put("page","package/admin/order-scan"); - map.put("env_version","trial"); - // 获取图片 Buffer - byte[] qrCode = HttpRequest.post(apiUrl) - .body(JSON.toJSONString(map)) - .execute().bodyBytes(); - System.out.println("qrCode = " + qrCode); + @ApiOperation("获取微信小程序码-订单核销码-数量极多的业务场景") + @GetMapping("/getOrderQRCodeUnlimited/{orderNo}") + public ApiResult getOrderQRCodeUnlimited(@PathVariable("orderNo") String orderNo) { + String apiUrl = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + getAccessToken(); + final HashMap map = new HashMap<>(); + map.put("scene", "orderNo=".concat(orderNo)); + map.put("page", "package/admin/order-scan"); + map.put("env_version", "trial"); + // 获取图片 Buffer + byte[] qrCode = HttpRequest.post(apiUrl) + .body(JSON.toJSONString(map)) + .execute().bodyBytes(); + System.out.println("qrCode = " + qrCode); - // 保存的文件名称 - final String fileName = CommonUtil.randomUUID8().concat(".png"); - // 保存路径 - String filePath = getUploadDir().concat("qrcode/") + fileName; - File file = FileUtil.writeBytes(qrCode, filePath); - if(file != null){ - return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + // 保存的文件名称 + final String fileName = CommonUtil.randomUUID8().concat(".png"); + // 保存路径 + String filePath = getUploadDir().concat("qrcode/") + fileName; + File file = FileUtil.writeBytes(qrCode, filePath); + if (file != null) { + return success(config.getFileServer().concat("/qrcode/").concat(fileName)); + } + return fail("获取失败", null); } - return fail("获取失败",null); - } - @ApiOperation("openid无感登录") - @PostMapping("/loginByOpenId") - public ApiResult loginByOpenId(@RequestBody Mp mp) { - System.out.println("mp = " + mp); - String key1 = "AppId:".concat(mp.getTenantId().toString()); - String key2 = "AppSecret:".concat(mp.getTenantId().toString()); - String AppId = redisUtil.get(key1); - String AppSecret = redisUtil.get(key2); + @ApiOperation("openid无感登录") + @PostMapping("/loginByOpenId") + public ApiResult loginByOpenId(@RequestBody Mp mp) { + System.out.println("mp = " + mp); + String key1 = "AppId:".concat(mp.getTenantId().toString()); + String key2 = "AppSecret:".concat(mp.getTenantId().toString()); + String AppId = redisUtil.get(key1); + String AppSecret = redisUtil.get(key2); - // 请求微信接口获取openid - String apiUrl = "https://api.weixin.qq.com/sns/jscode2session"; - final HashMap map = new HashMap<>(); - map.put("appid",AppId); - map.put("secret",AppSecret); - map.put("js_code",mp.getCode()); - map.put("grant_type","authorization_code"); - final String response = HttpUtil.get(apiUrl,map); - final JSONObject jsonObject = JSONObject.parseObject(response); - String openid = jsonObject.getString("openid"); - String sessionKey = jsonObject.getString("session_key"); - String unionid = jsonObject.getString("unionid"); - System.out.println("openid = " + openid); - System.out.println("unionid = " + unionid); + // 请求微信接口获取openid + String apiUrl = "https://api.weixin.qq.com/sns/jscode2session"; + final HashMap map = new HashMap<>(); + map.put("appid", AppId); + map.put("secret", AppSecret); + map.put("js_code", mp.getCode()); + map.put("grant_type", "authorization_code"); + final String response = HttpUtil.get(apiUrl, map); + final JSONObject jsonObject = JSONObject.parseObject(response); + String openid = jsonObject.getString("openid"); + String sessionKey = jsonObject.getString("session_key"); + String unionid = jsonObject.getString("unionid"); + System.out.println("openid = " + openid); + System.out.println("unionid = " + unionid); - if (StrUtil.isNotBlank(openid)) { - User user = userService.getOne(new LambdaQueryWrapper().eq(User::getOpenid, openid).last("limit 1")); - if(ObjectUtil.isNotEmpty(user)){ - return success("登录成功", user); - } - return fail("用户未注册",openid); + if (StrUtil.isNotBlank(openid)) { + User user = userService.getOne(new LambdaQueryWrapper().eq(User::getOpenid, openid).last("limit 1")); + if (ObjectUtil.isNotEmpty(user)) { + return success("登录成功", user); + } + return fail("用户未注册", openid); + } + return fail("openId获取失败"); } - return fail("openId获取失败"); - } - /** - * 文件上传位置(服务器) - */ - private String getUploadDir() { - return config.getUploadPath() + "file/"; - } + /** + * 文件上传位置(服务器) + */ + private String getUploadDir() { + return config.getUploadPath() + "file/"; + } } diff --git a/src/main/java/com/gxwebsoft/common/system/entity/Organization.java b/src/main/java/com/gxwebsoft/common/system/entity/Organization.java index 7d2c2f8..46f6d76 100644 --- a/src/main/java/com/gxwebsoft/common/system/entity/Organization.java +++ b/src/main/java/com/gxwebsoft/common/system/entity/Organization.java @@ -86,6 +86,9 @@ public class Organization implements Serializable { @ApiModelProperty(value = "所属行业") private String industry; + @ApiModelProperty(value = "所属产业") + private String estate; + @ApiModelProperty(value = "负责人id") private Integer leaderId; diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrganizationMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrganizationMapper.xml index 03176b1..47721a3 100644 --- a/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrganizationMapper.xml +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/OrganizationMapper.xml @@ -67,6 +67,9 @@ AND a.leader_id = #{param.leaderId} + + + AND a.estate IS NOT null AND a.comments LIKE CONCAT('%', #{param.comments}, '%') diff --git a/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml b/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml index 4a19718..33501a5 100644 --- a/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml +++ b/src/main/java/com/gxwebsoft/common/system/mapper/xml/UserMapper.xml @@ -137,6 +137,12 @@ #{item} + + AND a.organization_id IN + + #{item} + + AND a.phone IN diff --git a/src/main/java/com/gxwebsoft/common/system/param/OrganizationParam.java b/src/main/java/com/gxwebsoft/common/system/param/OrganizationParam.java index 0252f60..92ac123 100644 --- a/src/main/java/com/gxwebsoft/common/system/param/OrganizationParam.java +++ b/src/main/java/com/gxwebsoft/common/system/param/OrganizationParam.java @@ -66,6 +66,10 @@ public class OrganizationParam extends BaseParam { @QueryField(type = QueryType.EQ) private String park; + @ApiModelProperty(value = "有所属产业的企业") + @TableField(exist = false) + private Boolean estateOnly; + @ApiModelProperty(value = "机构图片") @QueryField(type = QueryType.EQ) private String image; diff --git a/src/main/java/com/gxwebsoft/common/system/param/UserParam.java b/src/main/java/com/gxwebsoft/common/system/param/UserParam.java index 9f2b3e5..367fb06 100644 --- a/src/main/java/com/gxwebsoft/common/system/param/UserParam.java +++ b/src/main/java/com/gxwebsoft/common/system/param/UserParam.java @@ -13,6 +13,7 @@ import lombok.EqualsAndHashCode; import java.math.BigDecimal; import java.util.Date; +import java.util.List; import java.util.Set; /** @@ -86,6 +87,10 @@ public class UserParam extends BaseParam { @QueryField(type = QueryType.EQ) private Integer organizationId; + @ApiModelProperty("机构id合集") + @TableField(exist = false) + private Set organizationIds; + @ApiModelProperty("用户分组ID") @QueryField(type = QueryType.EQ) private Integer groupId; diff --git a/src/main/java/com/gxwebsoft/common/system/service/UserRefereeService.java b/src/main/java/com/gxwebsoft/common/system/service/UserRefereeService.java index 476a01f..72a8370 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/UserRefereeService.java +++ b/src/main/java/com/gxwebsoft/common/system/service/UserRefereeService.java @@ -39,4 +39,5 @@ public interface UserRefereeService extends IService { */ UserReferee getByIdRel(Integer id); + UserReferee check(Integer dealerId, Integer userId); } diff --git a/src/main/java/com/gxwebsoft/common/system/service/impl/UserRefereeServiceImpl.java b/src/main/java/com/gxwebsoft/common/system/service/impl/UserRefereeServiceImpl.java index ddb6ef4..420c133 100644 --- a/src/main/java/com/gxwebsoft/common/system/service/impl/UserRefereeServiceImpl.java +++ b/src/main/java/com/gxwebsoft/common/system/service/impl/UserRefereeServiceImpl.java @@ -1,5 +1,6 @@ package com.gxwebsoft.common.system.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gxwebsoft.common.system.mapper.UserRefereeMapper; import com.gxwebsoft.common.system.service.UserRefereeService; @@ -44,4 +45,13 @@ public class UserRefereeServiceImpl extends ServiceImpl() + .eq(UserReferee::getDealerId, dealerId) + .eq(UserReferee::getUserId, userId) + ); + } + }