From a2c9d903c6ed5f85018809aa49f2029076cbca1a Mon Sep 17 00:00:00 2001 From: wangfukang <15630117759@163.com> Date: Thu, 9 Jan 2025 18:05:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=85=AC=E4=BC=97=E5=8F=B7?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=EF=BC=8C?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 2 ++ hiver-admin/test-output/test-report.html | 16 +++++++------- .../core/serviceimpl/UserServiceImpl.java | 7 ++++++ .../controller/manage/UserController.java | 22 +++++++++++++++++++ .../mall/pojo/query/ProductPageQuery.java | 3 +++ .../SalesAndDetailsServiceImpl.java | 12 ++-------- .../main/resources/mapper/CustomerMapper.xml | 2 +- .../main/resources/mapper/ProductMapper.xml | 5 +++++ 8 files changed, 50 insertions(+), 19 deletions(-) diff --git a/hiver-admin/src/main/resources/application.yml b/hiver-admin/src/main/resources/application.yml index 58f6409b..ef79b464 100644 --- a/hiver-admin/src/main/resources/application.yml +++ b/hiver-admin/src/main/resources/application.yml @@ -381,6 +381,8 @@ ignored: # 关注微信公众号回调 - /hiver/user/officialAccount - /hiver/social/wechat/echo + - /hiver/user/getUserInfo + - /hiver/app/customer/updateUserId # 临时增加 diff --git a/hiver-admin/test-output/test-report.html b/hiver-admin/test-output/test-report.html index e1c934ee..b015fda8 100644 --- a/hiver-admin/test-output/test-report.html +++ b/hiver-admin/test-output/test-report.html @@ -35,7 +35,7 @@ Hiver
  • -һ 07, 2025 16:21:35 +һ 09, 2025 17:32:09
  • @@ -84,7 +84,7 @@

    passTest

    -

    16:21:35 / 0.016 secs

    +

    17:32:10 / 0.028 secs

    @@ -92,9 +92,9 @@
    #test-id=1
    passTest
    -01.07.2025 16:21:35 -01.07.2025 16:21:35 -0.016 secs +01.09.2025 17:32:10 +01.09.2025 17:32:10 +0.028 secs
    @@ -104,7 +104,7 @@ Pass - 16:21:35 + 17:32:10 Test passed @@ -128,13 +128,13 @@

    Started

    -

    һ 07, 2025 16:21:35

    +

    һ 09, 2025 17:32:09

    Ended

    -

    һ 07, 2025 16:21:35

    +

    һ 09, 2025 17:32:10

    diff --git a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java index c9342859..df482615 100644 --- a/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java +++ b/hiver-core/src/main/java/cc/hiver/core/serviceimpl/UserServiceImpl.java @@ -4,6 +4,7 @@ import cc.hiver.core.common.constant.CommonConstant; import cc.hiver.core.common.constant.UserConstant; import cc.hiver.core.common.utils.PageUtil; import cc.hiver.core.common.utils.SecurityUtil; +import cc.hiver.core.common.utils.StringUtils; import cc.hiver.core.common.vo.PageVo; import cc.hiver.core.common.vo.SearchVo; import cc.hiver.core.dao.UserDao; @@ -280,6 +281,11 @@ public class UserServiceImpl implements UserService { final Map resultMap = new HashMap<>(); if (wechatUser != null) { wechatUser.setOfficialAccountOpenid(openid); + if (!wechatUser.getType().contains(UserConstant.USER_TYPE_CUSTOM)) { + // 不包含,赋予下游客户身份 + final String newUserType = StringUtils.isEmpty(wechatUser.getType()) ? UserConstant.USER_TYPE_CUSTOM : wechatUser.getType() + ',' + UserConstant.USER_TYPE_CUSTOM; + wechatUser.setType(newUserType); + } } else { try { // 新增用户信息 @@ -287,6 +293,7 @@ public class UserServiceImpl implements UserService { wechatUser.setUnionid(unionid); wechatUser.setOfficialAccountOpenid(openid); wechatUser.setStatus(UserConstant.USER_STATUS_NORMAL); + wechatUser.setType(UserConstant.USER_TYPE_CUSTOM); wechatUser = save(wechatUser); // 设置用户角色 final UserRole userRole = new UserRole(); diff --git a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java index 8d9a3216..e6c4bf1a 100644 --- a/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java +++ b/hiver-modules/hiver-base/src/main/java/cc/hiver/base/controller/manage/UserController.java @@ -593,6 +593,7 @@ public class UserController { final String sessionKey = jsonObject.get("session_key").getAsString(); final String openId = jsonObject.get("openid").getAsString(); final String unionid = jsonObject.get("unionid").getAsString(); + log.info("微信登录的传参==openId==:{};unionid==:{}",openId,unionid); // 判断是否绑定用户 User wechatUser = null; final Map resultMap = new HashMap<>(); @@ -600,12 +601,26 @@ public class UserController { wechatUser = userService.findByUnionid(unionid); }else{ wechatUser = userService.findById(wechatVo.getUserId()); + if (wechatUser == null) { + // 如果根据userid没查到,再根据unionid查询一遍 + wechatUser = userService.findByUnionid(unionid); + } } + if (wechatUser == null) { + log.info("微信登录未根据userid和unionid查询到用户,准备新增用户userId:{};unionid:{}",wechatVo.getUserId(),unionid); try { // 新增用户信息 wechatUser = new User(); wechatUser.setStatus(UserConstant.USER_STATUS_NORMAL); + // 去掉特殊符号(只保留字母和数字) + String cleanedOpenid = openId.replaceAll("[^a-zA-Z0-9]", ""); + // 截取前 10 位,作为username + String username = cleanedOpenid.length() > 10 ? cleanedOpenid.substring(0, 10) : cleanedOpenid; + wechatUser.setUsername(username); + final String encryptPass = new BCryptPasswordEncoder().encode("123456"); + wechatUser.setPassword(encryptPass); + wechatUser.setType(UserConstant.USER_TYPE_CUSTOM); wechatUser = userService.save(wechatUser); // 设置用户角色 final UserRole userRole = new UserRole(); @@ -630,6 +645,12 @@ public class UserController { } else { // 更新客户信息,绑定登录用户 customerService.updateUserId(wechatVo.getCustomId(), wechatUser.getId()); + final String type = wechatUser.getType(); + if (!type.contains(UserConstant.USER_TYPE_CUSTOM)) { + // 不包含,赋予下游客户身份 + final String newUserType = StringUtils.isEmpty(type) ? UserConstant.USER_TYPE_CUSTOM : type + ',' + UserConstant.USER_TYPE_CUSTOM; + wechatUser.setType(newUserType); + } } wechatUser.setUnionid(unionid); wechatUser.setWechatName(wechatVo.getWechatName()); @@ -688,6 +709,7 @@ public class UserController { wechatUser.setUnionid(unionid); wechatUser.setOfficialAccountOpenid(openid); wechatUser.setStatus(UserConstant.USER_STATUS_NORMAL); + wechatUser.setType(UserConstant.USER_TYPE_CUSTOM); wechatUser = userService.save(wechatUser); // 设置用户角色 final UserRole userRole = new UserRole(); diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java index 32488390..bb8f90ea 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/query/ProductPageQuery.java @@ -49,6 +49,9 @@ public class ProductPageQuery extends HiverBasePageQuery { @ApiModelProperty("货号") private String productSn; + @ApiModelProperty("供应商id") + private String supplierId; + @ApiModelProperty("供应商名称") private String supplierName; diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java index a3a06df2..f57f9e17 100644 --- a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/serviceimpl/SalesAndDetailsServiceImpl.java @@ -455,9 +455,8 @@ public class SalesAndDetailsServiceImpl implements SalesAndDetailsService { String customerId = ""; if (StringUtils.isNotEmpty(saleQueryDTO.getMobile())) { // 20240906如果前台传了客户id了,不要新增客户了就 - byMobile = userService.findByMobile(saleQueryDTO.getMobile()); if(StringUtils.isEmpty(saleQueryDTO.getUserId())){ - // byMobile = userService.findByMobile(saleQueryDTO.getMobile()); + byMobile = userService.findByMobile(saleQueryDTO.getMobile()); if (byMobile == null) { //默认密码 final String encryptPass = new BCryptPasswordEncoder().encode("123456"); @@ -544,14 +543,7 @@ public class SalesAndDetailsServiceImpl implements SalesAndDetailsService { dealingsRecordService.save(dealingsRecord); }else{ // 客户id拿前台传的 - String byMobileMobile = byMobile.getMobile(); - if(byMobileMobile.equals(saleQueryDTO.getUserId())){ - customerId = saleQueryDTO.getUserId(); - }else{ - // 根据手机号查询的用户id和前台传的不一样,则根据 userPhone 查customer表(所有数据)更新 userid 为传过来的这个 - customerService.updateUserIdByUserPhone(saleQueryDTO.getMobile(),saleQueryDTO.getUserId()); - } - + customerId = saleQueryDTO.getUserId(); } } else { log.error("下游客户未填写手机号!"); diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml index b9e906cc..b954e5f8 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/CustomerMapper.xml @@ -526,7 +526,7 @@ and a.shop_id = #{shopId,jdbcType=VARCHAR} - and a.user_id = #{userPhone,jdbcType=VARCHAR} + and (a.phone = #{userPhone,jdbcType=VARCHAR} or a.user_id = #{userPhone,jdbcType=VARCHAR}) diff --git a/hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml b/hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml index af774cac..158e8ca5 100644 --- a/hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml +++ b/hiver-modules/hiver-mall/src/main/resources/mapper/ProductMapper.xml @@ -631,6 +631,11 @@ AND t.category_id =#{queryParams.categoryId} + + + AND t.supplier_id =#{queryParams.supplierId} + + AND t.product_name like concat('%',#{queryParams.productName},'%')