Prechádzať zdrojové kódy

feat(applet): 新增用户绑定企业功能

- 在AppletUserController中新增用户绑定企业的接口
- 修改BannerInfoVO中的location字段类型为Integer
- 在BannerInfoMapper.xml中增加location字段映射
- 在UserInfoService中添加userBinding方法定义
- 在UserInfoServiceImpl中实现用户绑定企业的业务逻辑
- 注入FirmInfoMapper和UserFirmMapper依赖
- 实现用户与企业绑定关系的创建与更新逻辑
- 增加用户绑定前旧企业关系的删除操作
- 添加必要的参数校验和异常情况处理
- 返回绑定结果状态供前端使用
wzq 2 mesiacov pred
rodič
commit
a299d2f3a6

+ 7 - 4
src/main/java/com/zsElectric/boot/business/controller/applet/AppletUserController.java

@@ -5,10 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.zsElectric.boot.business.model.entity.UserFeedback;
 import com.zsElectric.boot.business.model.form.UserFeedbackForm;
 import com.zsElectric.boot.business.model.form.applet.AppFeedbackForm;
-import com.zsElectric.boot.business.model.query.CouponQuery;
 import com.zsElectric.boot.business.model.query.CouponTemplateQuery;
 import com.zsElectric.boot.business.model.query.applet.AppCouponQuery;
-import com.zsElectric.boot.business.model.query.applet.AppUserOrderInfoQuery;
 import com.zsElectric.boot.business.model.vo.CouponTemplateVO;
 import com.zsElectric.boot.business.model.vo.CouponVO;
 import com.zsElectric.boot.business.model.vo.applet.AppCouponStatusNumVO;
@@ -18,14 +16,12 @@ import com.zsElectric.boot.business.service.CouponTemplateService;
 import com.zsElectric.boot.business.service.UserFeedbackService;
 import com.zsElectric.boot.business.service.UserInfoService;
 import com.zsElectric.boot.common.constant.SystemConstants;
-import com.zsElectric.boot.core.web.PageResult;
 import com.zsElectric.boot.core.web.Result;
 import com.zsElectric.boot.security.util.SecurityUtils;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -51,6 +47,13 @@ public class AppletUserController {
         return Result.success(userInfoVO);
     }
 
+    @Operation(summary = "用户绑定企业")
+    @PostMapping("/userBinding/{userId}/{firmId}")
+    public Result<Boolean> userBinding(@PathVariable("userId") Long userId, @PathVariable("firmId") Long firmId) {
+        Boolean result = userInfoService.userBinding(userId, firmId);
+        return Result.judge(result);
+    }
+
     @Operation(summary = "小程序用户反馈")
     @PostMapping("/addUserFeedback")
     public Result<Void> addUserFeedback(@RequestBody @Valid AppFeedbackForm formData ) {

+ 1 - 1
src/main/java/com/zsElectric/boot/business/model/vo/BannerInfoVO.java

@@ -35,7 +35,7 @@ public class BannerInfoVO implements Serializable {
     @Schema(description = "跳转页面")
     private String jumpPage;
     @Schema(description = "位置 1-首页 2-个人中心")
-    private String location;
+    private Integer location;
     @Schema(description = "排序")
     private Integer sort;
     @Schema(description = "状态 0-禁用 1-启用")

+ 2 - 0
src/main/java/com/zsElectric/boot/business/service/UserInfoService.java

@@ -76,4 +76,6 @@ public interface UserInfoService extends IService<UserInfo> {
     UserInfo registerOrUpdateUserByPhone(String phone, String openId);
 
     AppletUserInfoVO getAppletUserInfo();
+
+    Boolean userBinding(Long userId, Long firmId);
 }

+ 33 - 0
src/main/java/com/zsElectric/boot/business/service/impl/UserInfoServiceImpl.java

@@ -1,8 +1,13 @@
 package com.zsElectric.boot.business.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.zsElectric.boot.business.mapper.FirmInfoMapper;
 import com.zsElectric.boot.business.mapper.UserAccountMapper;
+import com.zsElectric.boot.business.mapper.UserFirmMapper;
+import com.zsElectric.boot.business.model.entity.FirmInfo;
 import com.zsElectric.boot.business.model.entity.UserAccount;
+import com.zsElectric.boot.business.model.entity.UserFirm;
 import com.zsElectric.boot.business.model.vo.applet.AppletUserInfoVO;
 import com.zsElectric.boot.security.util.SecurityUtils;
 import lombok.RequiredArgsConstructor;
@@ -42,6 +47,10 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
 
     private final UserAccountMapper userAccountMapper;
 
+    private final FirmInfoMapper firmInfoMapper;
+
+    private final UserFirmMapper userFirmMapper;
+
     /**
     * 获取个人用户信息分页列表
     *
@@ -128,6 +137,30 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> i
         return null;
     }
 
+    @Override
+    public Boolean userBinding(Long userId, Long firmId) {
+        UserInfo userInfo = this.getById(userId);
+        FirmInfo firmInfo = firmInfoMapper.selectById(firmId);
+        if (ObjectUtil.isNotNull(userInfo) && ObjectUtil.isNotNull(firmInfo)) {
+
+            //删除用户旧绑定信息
+            userFirmMapper.delete(Wrappers.lambdaQuery(UserFirm.class).eq(UserFirm::getUserId, userId));
+
+            UserFirm userFirm = new UserFirm();
+            userFirm.setUserId(userId);
+            userFirm.setPhone(userInfo.getPhone());
+            userFirm.setFirmId(firmId);
+            userFirm.setType(1);
+            int insert = userFirmMapper.insert(userFirm);
+            if(insert > 0) {
+                return Boolean.TRUE;
+            }
+            return Boolean.FALSE;
+        }
+        log.info("用户不存在或企业不存在");
+        return Boolean.FALSE;
+    }
+
     /**
      * 根据openid获取用户信息
      *

+ 1 - 0
src/main/resources/mapper/business/BannerInfoMapper.xml

@@ -10,6 +10,7 @@
                 or_jump,
                 jump_appid,
                 jump_page,
+                location,
                 sort,
                 status,
                 create_time,