Hai Lin 2 miesięcy temu
rodzic
commit
e28240c631

+ 6 - 6
mirage-service/src/main/java/com/mirage/mirageservice/controller/WxController.java

@@ -93,13 +93,13 @@ public class WxController {
     }
 
     @Auth(value = AuthType.COOKIES)
-    @RequestMapping(value = "/user/unbind", method = RequestMethod.POST)
-    public Object unbind(@RequestBody BindRequest bindRequest){
-        if(null == bindRequest
-                || StringUtils.isBlank(bindRequest.getOpenId())){
-            throw new AppRuntimeException(AppCode.BAD_REQUEST);
+    @RequestMapping(value = "/user/unbind")
+    public Object unbind(){
+        String openId = AppContext.getUserInfo().getOpenId();
+        if(StringUtils.isBlank(openId)){
+            throw new AppRuntimeException(AppCode.UNAUTHORIZED);
         }
-        return userService.unBind(bindRequest);
+        return userService.unBind(openId);
     }
 
     @Auth(value = AuthType.COOKIES)

+ 4 - 0
mirage-service/src/main/java/com/mirage/mirageservice/mapper/mysql/CsMinWechatUserMapper.java

@@ -20,4 +20,8 @@ public interface CsMinWechatUserMapper {
     int updateByPrimaryKey(CsMinWechatUser record);
 
     CsMinWechatUser selectOneByPhoneAndWechatAppIdAndIsDeleted(@Param("phone") String phone, @Param("wechatAppId") String wechatAppId, @Param("isDeleted") Integer isDeleted);
+
+    CsMinWechatUser selectOneByOpenIdAndIsDeleted(@Param("openId")String openId,@Param("isDeleted")Integer isDeleted);
+
+
 }

+ 7 - 3
mirage-service/src/main/java/com/mirage/mirageservice/service/UserService.java

@@ -29,7 +29,6 @@ import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
-import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -77,8 +76,9 @@ public class UserService {
     public StudentDataReport getReportDetail(Integer id){
         return studentDataReportMapper.selectByPrimaryKey(id);
     }
-    public boolean unBind(BindRequest bindRequest){
-        WechatBind wechatBind = wechatBindMapper.selectOneByOpenid(bindRequest.getOpenId());
+
+    public boolean unBind(String openId){
+        WechatBind wechatBind = wechatBindMapper.selectOneByOpenid(openId);
         if(null == wechatBind){
             return true;
         }
@@ -97,6 +97,7 @@ public class UserService {
         }
         WechatBind wechatBind = wechatBindMapper.selectOneByOpenid(bindRequest.getOpenId());
         if(null == wechatBind){
+            wechatBind = new WechatBind();
             wechatBind.setStudentid(student.getId());
             wechatBind.setStudentname(student.getName());
             wechatBind.setPhone(bindRequest.getPhone());
@@ -105,6 +106,9 @@ public class UserService {
             wechatBindMapper.insertSelective(wechatBind);
         }
         BindRequest bindResponse = BeanConvertUtil.safeConvert(bindRequest, BindRequest.class, BindRequest.class);
+        if(null == bindResponse){
+            return null;
+        }
         bindResponse.setStudentId(student.getId());
         bindResponse.setStudentName(wechatBind.getStudentname());
         return bindResponse;

+ 8 - 0
mirage-service/src/main/resources/com/mirage/mirageservice/mapper/mysql/CsMinWechatUserMapper.xml

@@ -197,4 +197,12 @@
     where phone=#{phone,jdbcType=VARCHAR} and wechat_app_id=#{wechatAppId,jdbcType=VARCHAR} and
     is_deleted=#{isDeleted,jdbcType=INTEGER}
   </select>
+
+<!--auto generated by MybatisCodeHelper on 2025-08-28-->
+  <select id="selectOneByOpenIdAndIsDeleted" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from cs_min_wechat_user
+        where open_id=#{openId,jdbcType=VARCHAR} and is_deleted=#{isDeleted,jdbcType=INTEGER}
+    </select>
 </mapper>