|
|
@@ -1,17 +1,21 @@
|
|
|
package com.zsElectric.boot.business.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.zsElectric.boot.business.mapper.UserFirmMapper;
|
|
|
+import com.zsElectric.boot.business.mapper.UserInfoMapper;
|
|
|
import com.zsElectric.boot.business.service.UserFirmService;
|
|
|
import com.zsElectric.boot.business.model.entity.UserFirm;
|
|
|
+import com.zsElectric.boot.business.model.entity.UserInfo;
|
|
|
import com.zsElectric.boot.business.model.form.UserFirmForm;
|
|
|
import com.zsElectric.boot.business.model.query.UserFirmQuery;
|
|
|
import com.zsElectric.boot.business.model.vo.UserFirmVO;
|
|
|
import com.zsElectric.boot.business.converter.UserFirmConverter;
|
|
|
+import com.zsElectric.boot.core.exception.BusinessException;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
@@ -40,6 +44,7 @@ public class UserFirmServiceImpl extends ServiceImpl<UserFirmMapper, UserFirm> i
|
|
|
|
|
|
private final UserFirmConverter userFirmConverter;
|
|
|
private final FirmInfoService firmInfoService;
|
|
|
+ private final UserInfoMapper userInfoMapper;
|
|
|
|
|
|
/**
|
|
|
* 获取企业与用户关系分页列表
|
|
|
@@ -84,6 +89,34 @@ public class UserFirmServiceImpl extends ServiceImpl<UserFirmMapper, UserFirm> i
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean saveUserFirm(UserFirmForm formData) {
|
|
|
+ // 通过手机号查询c_user_info表,验证用户是否存在
|
|
|
+ String phone = formData.getPhone();
|
|
|
+ Assert.isTrue(StrUtil.isNotBlank(phone), "手机号不能为空");
|
|
|
+
|
|
|
+ UserInfo userInfo = userInfoMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<UserInfo>()
|
|
|
+ .eq(UserInfo::getPhone, phone)
|
|
|
+ .eq(UserInfo::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (userInfo == null) {
|
|
|
+ throw new BusinessException("该手机号用户不存在,请先在小程序端注册");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查该用户是否已经关联了企业
|
|
|
+ UserFirm existingUserFirm = this.getOne(
|
|
|
+ new LambdaQueryWrapper<UserFirm>()
|
|
|
+ .eq(UserFirm::getUserId, userInfo.getId())
|
|
|
+ .eq(UserFirm::getIsDeleted, 0)
|
|
|
+ );
|
|
|
+
|
|
|
+ if (existingUserFirm != null) {
|
|
|
+ throw new BusinessException("该用户已经关联了企业,不能重复添加");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置用户ID
|
|
|
+ formData.setUserId(userInfo.getId());
|
|
|
+
|
|
|
UserFirm entity = userFirmConverter.toEntity(formData);
|
|
|
return this.save(entity);
|
|
|
}
|