Browse Source

机构入驻申请

liujc 2 years ago
parent
commit
fd6f3b5bf0

+ 4 - 3
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/entity/TenantApplyRecord.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
 import lombok.Data;
 
 import io.swagger.annotations.ApiModel;
@@ -23,8 +24,8 @@ import java.util.Date;
 public class TenantApplyRecord implements Serializable {
 
     @ApiModelProperty("主键ID") 
-	    @TableId(value = "id_")
-	    private Long id;
+    @TableId(value = "id_")
+    private Long id;
 
     @ApiModelProperty("机构ID") 
 	@TableField(value = "tenant_id_")
@@ -60,7 +61,7 @@ public class TenantApplyRecord implements Serializable {
 
     @ApiModelProperty("审核状态 DOING、审核中 PASS、通过 UNPASS、不通过") 
 	@TableField(value = "status_")
-    private String status;
+    private AuthStatusEnum status;
 
     @ApiModelProperty("审核人") 
 	@TableField(value = "verify_user_id_")

+ 3 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/mapper/TenantStaffMapper.java

@@ -23,5 +23,7 @@ public interface TenantStaffMapper extends BaseMapper<TenantStaff> {
 	 * @return List<TenantStaffWrapper.TenantStaff>
 	 */
 	List<TenantStaff> selectPage(@Param("page") IPage<TenantStaff> page, @Param("param") TenantStaffWrapper.TenantStaffQuery param);
-	
+
+    TenantStaff getByPhone(@Param("phone") String phone);
+
 }

+ 6 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantApplyRecordService.java

@@ -39,5 +39,10 @@ public interface TenantApplyRecordService extends IService<TenantApplyRecord>  {
      * @return Boolean
      */
      Boolean update(TenantApplyRecordWrapper.TenantApplyRecord tenantApplyRecord);
-     
+
+    /**
+     * 申请入驻
+     *
+     */
+    void apply(TenantApplyRecordWrapper.TenantApply tenantApply);
 }

+ 2 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/TenantStaffService.java

@@ -39,5 +39,6 @@ public interface TenantStaffService extends IService<TenantStaff>  {
      * @return Boolean
      */
      Boolean update(TenantStaffWrapper.TenantStaff tenantStaff);
-     
+
+    TenantStaff getByPhone(String phone);
 }

+ 69 - 5
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/TenantApplyRecordServiceImpl.java

@@ -3,6 +3,13 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.microsvc.toolkit.common.webportal.exception.BizException;
+import com.yonge.cooleshow.biz.dal.entity.TenantStaff;
+import com.yonge.cooleshow.biz.dal.enums.AuthStatusEnum;
+import com.yonge.cooleshow.biz.dal.service.SmsCodeService;
+import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
+import com.yonge.cooleshow.biz.dal.service.TenantStaffService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.beans.BeanUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -10,6 +17,9 @@ import com.yonge.cooleshow.biz.dal.entity.TenantApplyRecord;
 import com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper;
 import com.yonge.cooleshow.biz.dal.mapper.TenantApplyRecordMapper;
 import com.yonge.cooleshow.biz.dal.service.TenantApplyRecordService;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
 
 /**
  * 机构入驻申请记录
@@ -19,12 +29,19 @@ import com.yonge.cooleshow.biz.dal.service.TenantApplyRecordService;
 @Service
 public class TenantApplyRecordServiceImpl extends ServiceImpl<TenantApplyRecordMapper, TenantApplyRecord> implements TenantApplyRecordService {
 
-	/**
+
+    @Autowired
+    private TenantStaffService tenantStaffService;
+
+    @Autowired
+    private SmsCodeService smsCodeService;
+
+    /**
      * 查询详情
      * @param id 详情ID
      * @return TenantApplyRecord
      */
-	@Override
+    @Override
     public TenantApplyRecord detail(Long id) {
         
         return baseMapper.selectById(id);
@@ -41,15 +58,15 @@ public class TenantApplyRecordServiceImpl extends ServiceImpl<TenantApplyRecordM
         
         return page.setRecords(baseMapper.selectPage(page, query));
     }
-	
+
     /**
      * 添加
      * @param tenantApplyRecord TenantApplyRecordWrapper.TenantApplyRecord
      * @return Boolean
      */
     @Override
-    public Boolean add(TenantApplyRecordWrapper.TenantApplyRecord tenantApplyRecord) {    	
-        
+    public Boolean add(TenantApplyRecordWrapper.TenantApplyRecord tenantApplyRecord) {
+
         return this.save(JSON.parseObject(tenantApplyRecord.jsonString(), TenantApplyRecord.class));
     }
 
@@ -63,4 +80,51 @@ public class TenantApplyRecordServiceImpl extends ServiceImpl<TenantApplyRecordM
 
         return this.updateById(JSON.parseObject(tenantApplyRecord.jsonString(), TenantApplyRecord.class));       
     }
+
+    /**
+     * 申请入驻
+     *
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void apply(TenantApplyRecordWrapper.TenantApply tenantApply) {
+
+        // 检测验证码
+        boolean b = smsCodeService.verifyValidCode(tenantApply.getPhone(), tenantApply.getCode(), null);
+        if (!b) {
+            throw new BizException("验证码错误");
+        }
+
+
+        // 根据手机号 判断是否已经有机构账户
+        TenantStaff tenantStaff = tenantStaffService.getByPhone(tenantApply.getPhone());
+        if (tenantStaff != null) {
+            throw new BizException("该手机号已经有机构账户");
+        }
+
+        // 查询申请记录 是否存在正在申请中的
+        TenantApplyRecord record = this.lambdaQuery()
+                .eq(TenantApplyRecord::getPhone, tenantApply.getPhone())
+                .in(TenantApplyRecord::getStatus, AuthStatusEnum.DOING, AuthStatusEnum.UNPASS)
+                .last("limit 1")
+                .one();
+
+        // 保存申请记录
+        TenantApplyRecord tenantApplyRecord = JSON.parseObject(tenantApply.jsonString(), TenantApplyRecord.class);
+        if (record != null) {
+            tenantApplyRecord.setId(record.getId());
+        }
+        tenantApplyRecord.setStatus(AuthStatusEnum.DOING);
+        tenantApplyRecord.setUpdateTime(new Date());
+        this.saveOrUpdate(tenantApplyRecord);
+
+        // 审核人  审核理由 null
+        this.lambdaUpdate()
+                .eq(TenantApplyRecord::getId, tenantApplyRecord.getId())
+                .set(TenantApplyRecord::getVerifyUserId, null)
+                .set(TenantApplyRecord::getReason, null)
+                .update();
+
+
+    }
 }

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

@@ -63,4 +63,10 @@ public class TenantStaffServiceImpl extends ServiceImpl<TenantStaffMapper, Tenan
 
         return this.updateById(JSON.parseObject(tenantStaff.jsonString(), TenantStaff.class));       
     }
+
+    @Override
+    public TenantStaff getByPhone(String phone) {
+        return baseMapper.getByPhone(phone);
+
+    }
 }

+ 47 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/wrapper/TenantApplyRecordWrapper.java

@@ -1,6 +1,7 @@
 package com.yonge.cooleshow.biz.dal.wrapper;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.microsvc.toolkit.common.response.paging.QueryInfo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -12,6 +13,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 import org.apache.commons.lang3.StringUtils;
 
+import javax.validation.constraints.NotNull;
+
 /**
  * 机构入驻申请记录
  * 2023-07-21 17:32:49
@@ -60,4 +63,48 @@ public class TenantApplyRecordWrapper {
         }
 	}
 
+
+    @Data
+    @ApiModel(" TenantApply-机构入驻申请")
+    public static class TenantApply {
+
+
+
+        @ApiModelProperty("名称")
+        private String name;
+
+        @ApiModelProperty("logo")
+        private String logo;
+
+        @ApiModelProperty("简介")
+        private String briefIntroduction;
+
+        @ApiModelProperty("省份编码")
+        private Integer provinceCode;
+
+        @ApiModelProperty("城市编码")
+        private Integer cityCode;
+
+        @ApiModelProperty("地区/街道")
+        private Integer regionCode;
+
+        @ApiModelProperty("联系人")
+        private String username;
+
+        @ApiModelProperty("手机号")
+        @NotNull(message = "手机号不能为空")
+        private String phone;
+
+        @ApiModelProperty("验证码")
+        @NotNull(message = "验证码不能为空")
+        private String code;
+
+        public String jsonString() {
+            return JSON.toJSONString(this);
+        }
+
+        public static TenantApplyRecord from(String json) {
+            return JSON.parseObject(json, TenantApplyRecord.class);
+        }
+    }
 }

+ 7 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/TenantStaffMapper.xml

@@ -27,5 +27,11 @@
         	<include refid="baseColumns" />
 		FROM tenant_staff t
 	</select>
-    
+
+    <select id="getByPhone" resultType="com.yonge.cooleshow.biz.dal.entity.TenantStaff">
+        select *
+        from tenant_staff t
+        left join sys_user t1 on t1.id_ = t.user_id_
+        where t1.phone_ = #{phone}
+    </select>
 </mapper>

+ 53 - 0
cooleshow-user/user-tenant/src/main/java/com/yonge/cooleshow/tenant/controller/open/OpenTenantController.java

@@ -0,0 +1,53 @@
+package com.yonge.cooleshow.tenant.controller.open;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.google.common.collect.Lists;
+import com.microsvc.toolkit.common.response.paging.PageInfo;
+import com.microsvc.toolkit.common.response.paging.QueryInfo;
+import com.yonge.cooleshow.biz.dal.entity.SysArea;
+import com.yonge.cooleshow.biz.dal.entity.TenantInfo;
+import com.yonge.cooleshow.biz.dal.service.SysAreaService;
+import com.yonge.cooleshow.biz.dal.service.TenantApplyRecordService;
+import com.yonge.cooleshow.biz.dal.service.TenantInfoService;
+import com.yonge.cooleshow.biz.dal.wrapper.StudentWrapper;
+import com.yonge.cooleshow.biz.dal.wrapper.SysAreaWrapper;
+import com.yonge.cooleshow.biz.dal.wrapper.TenantApplyRecordWrapper;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.cooleshow.tenant.io.request.SysAreaVo;
+import com.yonge.toolset.base.exception.BizException;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+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 java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Validated
+@RestController
+@RequestMapping("/open/tenant")
+@Api(tags = "机构")
+public class OpenTenantController {
+
+
+    @Autowired
+    private TenantApplyRecordService tenantApplyRecordService;
+
+
+    @PostMapping("/apply")
+    @ApiOperation(value = "申请")
+    public HttpResponseResult<Boolean> save(
+            @Validated @RequestBody TenantApplyRecordWrapper.TenantApply tenantApply) {
+
+        tenantApplyRecordService.apply(tenantApply);
+
+        return HttpResponseResult.status(true);
+    }
+}