Przeglądaj źródła

Merge branch 'feature/0721-tenant' of http://git.dayaedu.com/yonge/cooleshow into develop

zouxuan 1 rok temu
rodzic
commit
f21ad9eb29

+ 1 - 1
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/api/client/SysUserFeignService.java

@@ -58,7 +58,7 @@ public interface SysUserFeignService {
 										   @RequestParam("clientId")String clientId,
 										   @RequestParam("clientSecret")String clientSecret);
 
-	@PostMapping(value = "user/getTenantByClient")
+	@GetMapping(value = "user/getTenantByClient")
 	@ApiOperation(value = "获取机构编号")
 	HttpResponseResult<Long> getTenantByClient(@RequestParam("userId")Long userId,@RequestParam("clientId")String clientId);
 

+ 5 - 0
cooleshow-auth/auth-api/src/main/java/com/yonge/cooleshow/auth/api/entity/SysUser.java

@@ -1,5 +1,6 @@
 package com.yonge.cooleshow.auth.api.entity;
 
+import com.alibaba.fastjson.JSON;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -119,4 +120,8 @@ public class SysUser implements Serializable{
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);
 	}
+
+	public String jsonString() {
+		return JSON.toJSONString(this);
+	}
 }

+ 3 - 9
cooleshow-auth/auth-server/src/main/java/com/yonge/cooleshow/auth/web/controller/UserController.java

@@ -40,13 +40,7 @@ import org.springframework.http.MediaType;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.text.MessageFormat;
@@ -135,8 +129,8 @@ public class UserController extends BaseController {
         return sysUserService.get(userId);
     }
 
-    @PostMapping(value = "/getTenantByClient", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
-    public HttpResponseResult<Long> getTenantByClient(Long userId,String clientId) {
+    @GetMapping(value = "/getTenantByClient")
+    public HttpResponseResult<Long> getTenantByClient(@RequestParam("userId")Long userId, @RequestParam("clientId")String clientId) {
         return HttpResponseResult.succeed(sysUserService.getTenantByClient(userId,clientId));
     }
 

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/TenantInfoMapper.java

@@ -65,4 +65,6 @@ public interface TenantInfoMapper extends BaseMapper<TenantInfo> {
 	String queryStudentCount(@Param("id") Long id);
 
 	String queryTeacherCount(@Param("id") Long id);
+
+    void updateIdPhone(@Param("newId") Long newId, @Param("phone") String phone, @Param("oldId") Long oldId);
 }

+ 2 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/TenantStaffMapper.java

@@ -27,4 +27,6 @@ public interface TenantStaffMapper extends BaseMapper<TenantStaff> {
     TenantStaff getByPhone(@Param("phone") String phone);
 
     TenantStaff selectByUserId(@Param("id") Long id);
+
+    void updateUserId(@Param("newId") Long newId, @Param("oldId") Long oldId, @Param("username") String username, @Param("avatar") String avatar);
 }

+ 2 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantActivationCodeServiceImpl.java

@@ -378,9 +378,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
                                 TenantActivationCode::getActivationStatus));
                 for (String code : codes) {
                     if (!codeStatusMap.containsKey(code)) {
-                        errMsg.add(String.format(errTemplate, codeRowMap.get(code), "验证码无效"));
+                        errMsg.add(String.format(errTemplate, codeRowMap.get(code), "激活码无效"));
                     } else if (Boolean.TRUE.equals(codeStatusMap.get(code))) {
-                        errMsg.add(String.format(errTemplate, codeRowMap.get(code), "验证码已经激活"));
+                        errMsg.add(String.format(errTemplate, codeRowMap.get(code), "激活码已经激活"));
                     }
                 }
             }

+ 3 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantInfoMapper.xml

@@ -80,6 +80,9 @@
       set status_ = 'UNPASS'
       where  id_ =#{id}
     </update>
+    <update id="updateIdPhone">
+        update tenant_info set user_id_ = #{newId} and phone_ =#{phone}  where user_id_ = #{oldId}
+    </update>
 
     <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper$TenantInfo">
         SELECT

+ 8 - 2
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantStaffMapper.xml

@@ -20,8 +20,14 @@
         , t.status_ AS status
         , t.update_time_ AS updateTime
         , t.create_time_ AS createTime
-        </sql> 
-    
+        </sql>
+    <update id="updateUserId">
+        update Tenant_staff set  user_id_ = #{newId}
+        <where>
+        </where>
+
+    </update>
+
     <select id="selectPage" resultType="com.yonge.cooleshow.biz.dal.entity.TenantStaff">
 		SELECT         
         	<include refid="baseColumns" />

+ 53 - 28
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/TenantInfoController.java

@@ -9,6 +9,9 @@ import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
 import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
 import com.yonge.cooleshow.biz.dal.entity.TenantStaff;
 import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
+import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
+import com.yonge.cooleshow.biz.dal.mapper.TenantInfoMapper;
+import com.yonge.cooleshow.biz.dal.mapper.TenantStaffMapper;
 import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
 import com.yonge.cooleshow.common.constant.SysConfigConstant;
@@ -31,6 +34,7 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
 import java.util.List;
+import java.util.Objects;
 
 /**
  * @Author:haonan
@@ -57,6 +61,15 @@ public class TenantInfoController extends BaseController {
     @Autowired
     private SysConfigService sysConfigService;
 
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Autowired
+    private TenantStaffMapper tenantStaffMapper;
+
+    @Autowired
+    private TenantInfoMapper tenantInfoMapper;
+
     @ApiOperation(value = "发送登录短信验证码")
     @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String"),
             @ApiImplicitParam(name = "type", value = "类型(PASSWD:修改密码,LOGIN:登录或注册,BANK:绑定银行卡,PHONE:修改手机号)", required =
@@ -155,40 +168,50 @@ public class TenantInfoController extends BaseController {
         if (StringUtils.isNotBlank(phone)){
             boolean re = smsCodeService.verifyValidCode(phone, code, "PHONE");
             if (re){
-                SysUser user = sysUserFeignService.queryUserInfo();
-                tenantInfoService.updateSysUser(sysUser1, user.getId());
-
-                //设置默认头像
-                if (StringUtils.isEmpty(sysUser.getAvatar())) {
-                    sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
-                }
-
-                //判断更改的手机所属的机构信息
-
-                String oldPhone = user.getPhone();
-                //查看原机构信息
-                List<TenantInfo> list = tenantInfoService.lambdaQuery().eq(TenantInfo::getPhone, oldPhone).list();
-                if (CollectionUtils.isNotEmpty(list)){
-                    TenantInfo info = list.get(0);
-                    if (ObjectUtil.isEmpty(info)) {
-                        //更新tennatInfo
-                        info.setPhone(phone);
-                        tenantInfoService.updateById(info);
+                //查询输入的手机号  是否存在于sysUser表中
+                SysUser user = sysUserMapper.findUserByPhone(phone);
+                if (Objects.nonNull(user)){
+                    //如果存在 判断是否为机构员工
+                    TenantStaff tenantStaff = tenantStaffService.getByUserId(user.getId());
+                    if (!ObjectUtil.isEmpty(tenantStaff)){
+                        throw new BizException("该手机号已绑定机构");
                     }
-                }
-
-                //更新员工表
-                Long id = user.getId();
-                TenantStaff staff = tenantStaffService.getByUserId(id);
-                if (staff != null){
-                    staff.setNickname(sysUser.getUsername());
-                    staff.setAvatar(sysUser.getAvatar());
-                    tenantStaffService.updateById(staff);
+                } else {
+                    //没有存在于sysUser表
+                    SysUser newUser = new SysUser();
+
+                    //查询当前登录账号
+                    SysUser OldUser = sysUserFeignService.queryUserInfo();
+
+                    //给新账户赋值
+                    newUser = JSON.parseObject(OldUser.jsonString(), SysUser.class);
+                    com.yonge.cooleshow.biz.dal.entity.SysUser sysUser2 = JSON.parseObject(newUser.jsonString(), com.yonge.cooleshow.biz.dal.entity.SysUser.class);
+                    sysUser2.setUsername(sysUser.getUsername());
+                    //设置默认头像
+                    if (StringUtils.isEmpty(sysUser.getAvatar())) {
+                        sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
+                    } else {
+                        sysUser2.setAvatar(sysUser.getAvatar());
+                    }
+                    sysUserMapper.insert(sysUser2);
+                    //查询当前登录用户的userId
+                    Long oldId = OldUser.getId();
+                    //查询新用户的userId
+                    Long newId = sysUser2.getId();
+
+                    //staff 更新userId
+                    tenantStaffMapper.updateUserId(newId,oldId, sysUser2.getUsername(),sysUser2.getAvatar());
+                    //tennatinfo  更新userId  和 phone
+                    tenantInfoMapper.updateIdPhone(newId,phone,oldId);
                 }
             } else {
                 throw new BizException("手机号校验有误");
             }
         }  else {
+            //更新当前用户的staff表
+
+
+
             SysUser user = sysUserFeignService.queryUserInfo();
             tenantInfoService.updateSysUser(sysUser1, user.getId());
 
@@ -205,6 +228,8 @@ public class TenantInfoController extends BaseController {
                 staff.setAvatar(sysUser.getAvatar());
                 tenantStaffService.updateById(staff);
             }
+
+            //更新tenantInfo的username
         }
             return HttpResponseResult.succeed(true);
         }