瀏覽代碼

机构fix

haonan 1 年之前
父節點
當前提交
85adda9a93

+ 5 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantInfoService.java

@@ -2,6 +2,7 @@ package com.yonge.cooleshow.biz.dal.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.yonge.cooleshow.biz.dal.entity.SysUser;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
 import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
@@ -98,4 +99,8 @@ public interface TenantInfoService extends IService<TenantInfo>  {
     Boolean entry(TenantInfoWrapper.TenantInfoQuery query);
 
     TenantInfoWrapper.TenantInfo Infodetail(Long id);
+
+    Boolean updateTenantInfo(TenantInfo tenantInfo, Long tenantId);
+
+    Boolean updateSysUser(SysUser sysUser, Long id);
 }

+ 59 - 6
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantInfoServiceImpl.java

@@ -192,7 +192,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
 
 
     /**
-     * 添加
+     * 新增
      *
      * @param tenantInfo TenantInfoWrapper.TenantInfo
      * @return Boolean
@@ -225,7 +225,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
         sysUserQueryWrapper.lambda().eq(SysUser::getPhone, tenantInfo.getPhone());
         List<SysUser> sysUsers = sysUserMapper.selectList(sysUserQueryWrapper);
-        SysUser sysUser = new SysUser();
+        SysUser sysUser;
         //若存在信息
         if (!sysUsers.isEmpty()) {
             sysUser = sysUsers.get(0);
@@ -248,7 +248,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
             sysUser.setUsername(tenantInfo.getUsername());
 
             sysUserMapper.updateById(sysUser);
-        } /*else {
+        } else {
             sysUser = new SysUser();
             sysUser.setPhone(tenantInfo.getPhone());
             sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
@@ -258,10 +258,44 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
             String password = new BCryptPasswordEncoder().encode(newPassword);
             sysUser.setPassword(password);
             sysUserMapper.insert(sysUser);
-        }*/
+        }
+        return sysUser;
+    }
+
+
+
+    private SysUser getAccount(TenantInfo tenantInfo, TenantInfo oldTenantInfo) {
+        QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
+        sysUserQueryWrapper.lambda().eq(SysUser::getPhone, tenantInfo.getPhone());
+        List<SysUser> sysUsers = sysUserMapper.selectList(sysUserQueryWrapper);
+        SysUser sysUser = new SysUser();
+        //若存在信息
+        if (!sysUsers.isEmpty()) {
+            sysUser = sysUsers.get(0);
+            TenantStaff tenantStaff = tenantStaffMapper.selectByUserId(sysUser.getId());
+            if (tenantStaff != null && oldTenantInfo != null &&
+                    !tenantStaff.getUserId().equals(oldTenantInfo.getUserId())) {
+                throw new BizException("手机号已经注册机构账号");
+            }
+            //获取当前账户的用户类型
+            String userType = sysUser.getUserType();
+            //设置默认机构类型
+            String tenantUserType = SysUserType.ORGANIZATION.getCode();
+            if (StringUtils.isEmpty(userType)) {
+                sysUser.setUserType(tenantUserType);
+            } else if (!userType.contains(tenantUserType)) {
+                sysUser.setUserType(userType + "," + tenantUserType);
+            }
+
+            //更新当前账号的用户名
+            sysUser.setUsername(tenantInfo.getUsername());
+
+            sysUserMapper.updateById(sysUser);
+        }
         return sysUser;
     }
-	
+
+
 
     /*@Override
     public Boolean add(TenantInfoWrapper.TenantInfo tenantInfo) {    	
@@ -344,7 +378,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         // todo  机构冻结状态是否允许修改
         //更新或创建sysUser
         TenantInfo oldTenantInfo = this.getById(info.getId());
-        SysUser sysUser = getOrCreateAccount(info, oldTenantInfo);
+        SysUser sysUser = getAccount(info, oldTenantInfo);
 
         tenantStaffMapper.update(null, Wrappers.<TenantStaff>lambdaUpdate()
                 .set(TenantStaff::getUserId, sysUser.getId())
@@ -519,6 +553,25 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoMapper, TenantI
         return null;
     }
 
+    @Override
+    public Boolean updateTenantInfo(TenantInfo info, Long tenantId) {
+        boolean update = this.lambdaUpdate().set(TenantInfo::getName, info.getName())
+                .set(TenantInfo::getLogo, info.getLogo())
+                .set(TenantInfo::getBriefIntroduction, info.getBriefIntroduction())
+                .set(TenantInfo::getProvinceCode, info.getProvinceCode())
+                .set(TenantInfo::getCityCode, info.getCityCode())
+                .set(TenantInfo::getRegionCode, info.getRegionCode())
+                .eq(TenantInfo::getId, tenantId).update();
+        return update;
+    }
+
+    @Override
+    public Boolean updateSysUser(SysUser sysUser, Long id) {
+        sysUser.setId(id);
+        sysUserMapper.updateById(sysUser);
+        return true;
+    }
+
 
     /**
      * 匹配地区码与省市区

+ 10 - 5
cooleshow-user/user-biz/src/main/resources/config/mybatis/StudentMapper.xml

@@ -325,10 +325,15 @@
     <select id="countTeacherByTenantIds" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper$UserCount">
         select tenant_id_ tenantId, count(tenant_id_) count
         from student
-        where tenant_id_ in
-        <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
-            #{item}
-        </foreach>
+        <where>
+            <if test="tenantIdList != null">
+                AND tenant_id_ in
+                <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            AND lock_flag_ = 0
+        </where>
         group by tenant_id_
     </select>
     <select id="queryStudentCounts" resultType="java.lang.Integer">
@@ -338,7 +343,7 @@
             <if test="id != null">
                 and  tenant_id_ = #{id}
             </if>
+            and lock_flag_ = 0
         </where>
-
     </select>
 </mapper>

+ 12 - 5
cooleshow-user/user-biz/src/main/resources/config/mybatis/TeacherMapper.xml

@@ -376,10 +376,16 @@
     <select id="countTeacherByTenantIds" resultType="com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper$UserCount">
         select tenant_id_ tenantId, count(tenant_id_) count
         from teacher
-        where tenant_id_ in
-        <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
-            #{item}
-        </foreach>
+        <where>
+            <if test="tenantIdList != null">
+                AND tenant_id_ in
+                <foreach collection="tenantIdList" item="item" separator="," open="(" close=")">
+                    #{item}
+                </foreach>
+            </if>
+            AND lock_flag_ = 0
+        </where>
+
         group by tenant_id_
     </select>
     <select id="queryTeacherCounts" resultType="java.lang.Integer">
@@ -387,8 +393,9 @@
         from teacher
         <where>
             <if test="id != null">
-              and   tenant_id_ = #{id}
+              and tenant_id_ = #{id}
             </if>
+            and lock_flag_ = 0
         </where>
     </select>
     <!--老师学生人数统计-->

+ 80 - 18
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/TenantInfoController.java

@@ -1,32 +1,28 @@
 package com.yonge.cooleshow.tenant.controller;
 
 import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.google.gson.JsonObject;
+import com.timevale.tech.sdk.seal.IFontsLoader;
 import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
 import com.yonge.cooleshow.auth.api.entity.SysUser;
+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.service.SmsCodeService;
-import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
+import com.yonge.cooleshow.biz.dal.service.*;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantInfoWrapper;
-import com.yonge.cooleshow.biz.dal.wrapper.TenantUnbindRecordWrapper;
+import com.yonge.cooleshow.common.constant.SysConfigConstant;
 import com.yonge.cooleshow.common.controller.BaseController;
 import com.yonge.cooleshow.common.entity.HttpResponseResult;
 import com.yonge.cooleshow.common.security.SecurityConstants;
+import com.yonge.cooleshow.tenant.io.request.SysUserWrapper;
 import com.yonge.cooleshow.tenant.io.request.TenantInfoVo;
-import com.yonge.toolset.base.exception.BizException;
-import com.yonge.toolset.base.page.PageInfo;
-import com.yonge.toolset.base.util.StringUtil;
-import com.yonge.toolset.mybatis.support.PageUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
@@ -50,6 +46,12 @@ public class TenantInfoController extends BaseController {
     @Autowired
     private SmsCodeService smsCodeService;
 
+    @Autowired
+    private TenantStaffService tenantStaffService;
+
+    @Autowired
+    private SysConfigService sysConfigService;
+
     @ApiOperation(value = "发送登录短信验证码")
     @ApiImplicitParams({@ApiImplicitParam(name = "mobile", value = "手机号", required = true, dataType = "String"),
             @ApiImplicitParam(name = "type", value = "类型(PASSWD:修改密码,LOGIN:登录或注册,BANK:绑定银行卡,PHONE:修改手机号)", required =
@@ -78,31 +80,91 @@ public class TenantInfoController extends BaseController {
 
 
     /**
-     * 修改数据
+     * 机构修改数据
      */
     @PostMapping("/update")
     @ApiOperation(value = "修改机构信息", notes = "传入TenantInfo")
 //    @PreAuthorize("@pcs.hasPermissions('tenantInfoUpdate/update')")
     public HttpResponseResult<Boolean> updateTenantInfo(@Valid @RequestBody TenantInfoVo.TenantInfo info) {
-
-        return succeed(tenantInfoService.update(JSON.parseObject(info.jsonString(), TenantInfo.class)));
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        Long id = sysUser.getId();
+        TenantStaff staff = tenantStaffService.lambdaQuery().eq(TenantStaff::getUserId, id).list().get(0);
+        Long tenantId = staff.getTenantId();
+        return succeed(tenantInfoService.updateTenantInfo(JSON.parseObject(info.jsonString(), TenantInfo.class), tenantId));
 
     }
 
+
+
+
     /**
-     * 查询详细
+     * 当前机构查询详细
      */
     @PostMapping("/detail")
     @ApiOperation(value = "查询详细", notes = "查询详细")
 //    @PreAuthorize("@pcs.hasPermissions('tenantInfoUpdate/detail')")
-    public HttpResponseResult<TenantInfoWrapper.TenantInfo> detail(@RequestParam("id") Long id) {
-        TenantInfoWrapper.TenantInfo info = tenantInfoService.detailTenantInfo(id);
-
+    public HttpResponseResult<TenantInfoWrapper.TenantInfo> detail() {
+        TenantInfoWrapper.TenantInfo info = new TenantInfoWrapper.TenantInfo();
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        Long id = sysUser.getId();
+        TenantStaff staff = tenantStaffService.lambdaQuery().eq(TenantStaff::getUserId, id).list().get(0);
+        Long tenantId = staff.getTenantId();
+        if (!(tenantId == null)){
+            info = tenantInfoService.detailTenantInfo(id);
+        }
         return succeed(info);
+    }
 
+
+
+    /**
+     * 当前用户查询详细
+     */
+    @PostMapping("/sysUserDetail")
+    @ApiOperation(value = "查询详细", notes = "查询详细")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfoUpdate/sysUserDetail')")
+    public HttpResponseResult<SysUser> sysUserDetail() {
+
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+
+
+        return HttpResponseResult.succeed(sysUser);
     }
 
+    /**
+     * 当前用户修改信息
+     */
+    @PostMapping("/sysUserUpdate")
+    @ApiOperation(value = "用户修改", notes = "用户修改")
+//    @PreAuthorize("@pcs.hasPermissions('tenantInfoUpdate/sysUserUpdate')")
+    public HttpResponseResult<Boolean> sysUserUpdate(SysUserWrapper.SysUser sysUser) {
+        com.yonge.cooleshow.biz.dal.entity.SysUser sysUser1 = JSON.parseObject(sysUser.jsonString(), com.yonge.cooleshow.biz.dal.entity.SysUser.class);
+        SysUser user = sysUserFeignService.queryUserInfo();
+        tenantInfoService.updateSysUser(sysUser1,user.getId());
+
+        //判断更改的手机所属的机构信息
+        String phone = sysUser.getPhone();
+
+        //设置默认头像
+        if (sysUser.getAvatar().isEmpty()){
+            sysUser.setAvatar(sysConfigService.findConfigValue(SysConfigConstant.DEFAULT_HEARD));
+        }
+
+        TenantInfo info = tenantInfoService.lambdaQuery().eq(TenantInfo::getPhone, phone).list().get(0);
+        if (!(info == null)){
+            //更新tennatInfo
+            tenantInfoService.lambdaUpdate().set(TenantInfo::getPhone,phone)
+                                            .eq(TenantInfo::getUserId,user.getId());
+
+            //更新员工表
+            tenantStaffService.lambdaUpdate().set(TenantStaff::getNickname,sysUser.getUsername())
+                                             .set(TenantStaff::getAvatar,sysUser.getAvatar())
+                                             .eq(TenantStaff::getUserId,user.getId());
+        }
+
 
 
+        return HttpResponseResult.succeed(true);
+    }
 
 }

+ 41 - 0
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/io/request/SysUserWrapper.java

@@ -0,0 +1,41 @@
+package com.yonge.cooleshow.tenant.io.request;
+
+import com.alibaba.fastjson.JSON;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * 用户信息
+ * 2023-08-21 15:55:00
+ */
+@ApiModel(value = "用户对象", description = "用户对象")
+public class SysUserWrapper {
+
+    @Data
+    @ApiModel("sysUer")
+    public static class SysUser {
+
+        @ApiModelProperty(value = "用户名")
+        private String username;
+
+        @ApiModelProperty(value = "手机号")
+        private String phone;
+
+        /** 头像 */
+        @ApiModelProperty(value = "头像")
+        private String avatar;
+
+
+        public String jsonString() {
+            return JSON.toJSONString(this);
+        }
+
+        public static SysUser from(String json) {
+            return JSON.parseObject(json, SysUser.class);
+        }
+    }
+
+}

+ 0 - 9
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/io/request/TenantInfoVo.java

@@ -45,15 +45,6 @@ public class TenantInfoVo {
         @NotNull
         private Integer regionCode;
 
-        @ApiModelProperty("联系人")
-        @Length(min = 1, max = 8, message = "联系人字符最大8位")
-        private String username;
-
-        @ApiModelProperty("手机号")
-        @NotNull
-        @Pattern(regexp = "^1\\d{10}$", message = "手机号码格式错误")
-        private String phone;
-
         public String jsonString() {
             return JSON.toJSONString(this);
         }