|
@@ -1,14 +1,24 @@
|
|
package com.fs.his.service.impl;
|
|
package com.fs.his.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
|
+import com.fs.common.exception.ServiceException;
|
|
import com.fs.common.utils.DateUtils;
|
|
import com.fs.common.utils.DateUtils;
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
|
+import com.fs.his.domain.FsUser;
|
|
import com.fs.his.domain.FsUserInfo;
|
|
import com.fs.his.domain.FsUserInfo;
|
|
import com.fs.his.mapper.FsUserInfoMapper;
|
|
import com.fs.his.mapper.FsUserInfoMapper;
|
|
|
|
+import com.fs.his.mapper.FsUserMapper;
|
|
import com.fs.his.service.IFsUserInfoService;
|
|
import com.fs.his.service.IFsUserInfoService;
|
|
|
|
+import com.fs.his.service.IFsUserService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
+import static com.fs.his.utils.PhoneUtil.encryptPhone;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 用户信息Service业务层处理
|
|
* 用户信息Service业务层处理
|
|
*
|
|
*
|
|
@@ -18,6 +28,12 @@ import java.util.List;
|
|
@Service
|
|
@Service
|
|
public class FsUserInfoServiceImpl extends ServiceImpl<FsUserInfoMapper, FsUserInfo> implements IFsUserInfoService {
|
|
public class FsUserInfoServiceImpl extends ServiceImpl<FsUserInfoMapper, FsUserInfo> implements IFsUserInfoService {
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFsUserService fsUserService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private FsUserMapper fsUserMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 查询用户信息
|
|
* 查询用户信息
|
|
*
|
|
*
|
|
@@ -59,8 +75,116 @@ public class FsUserInfoServiceImpl extends ServiceImpl<FsUserInfoMapper, FsUserI
|
|
* @return 结果
|
|
* @return 结果
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional
|
|
public int updateFsUserInfo(FsUserInfo fsUserInfo) {
|
|
public int updateFsUserInfo(FsUserInfo fsUserInfo) {
|
|
|
|
+ // 若手机号有修改 需校验手机号是否已存在 且不修改fs_user表的手机号
|
|
|
|
+ if(StringUtils.isNotEmpty(fsUserInfo.getPhone())){
|
|
|
|
+ FsUserInfo user = baseMapper.selectFsUserInfoById(fsUserInfo.getUserId());
|
|
|
|
+ if(user== null){
|
|
|
|
+ throw new ServiceException("用户已注销或不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(!user.getPhone().equals(fsUserInfo.getPhone())){// 若要修改手机号需要验证新的手机号是否存在
|
|
|
|
+ FsUserInfo userInfo = baseMapper.selectFsUserInfoByPhone(fsUserInfo.getPhone());
|
|
|
|
+ if(userInfo!=null){
|
|
|
|
+ throw new ServiceException("该手机号已存在");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 更新用户信息 不修改手机号
|
|
|
|
+ if(StringUtils.isNotEmpty(fsUserInfo.getAvatar()) || fsUserInfo.getSex()!= null || fsUserInfo.getCompanyUserId()!= null) {
|
|
|
|
+ FsUser user = new FsUser();
|
|
|
|
+ user.setUserId(fsUserInfo.getUserId());
|
|
|
|
+ user.setAvatar(fsUserInfo.getAvatar());
|
|
|
|
+ user.setSex(fsUserInfo.getSex());
|
|
|
|
+ user.setCompanyUserId(fsUserInfo.getCompanyUserId());
|
|
|
|
+ user.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
+ if (fsUserMapper.updateFsUser(user) <= 0) {
|
|
|
|
+ throw new ServiceException("用户信息修改失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
fsUserInfo.setUpdateTime(DateUtils.getNowDate());
|
|
fsUserInfo.setUpdateTime(DateUtils.getNowDate());
|
|
return baseMapper.updateFsUserInfo(fsUserInfo);
|
|
return baseMapper.updateFsUserInfo(fsUserInfo);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @Description: 新增用户
|
|
|
|
+ * @Param:
|
|
|
|
+ * @Return:
|
|
|
|
+ * @Author xgb
|
|
|
|
+ * @Date 2025/9/3 14:03
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void add(FsUserInfo fsUserInfo) {
|
|
|
|
+
|
|
|
|
+ // 判断手机号是否已经存在
|
|
|
|
+ if(StringUtils.isEmpty(fsUserInfo.getPhone())){
|
|
|
|
+ throw new ServiceException("手机号不能为空");
|
|
|
|
+ }
|
|
|
|
+ // 查询手机号
|
|
|
|
+ FsUserInfo userInfo = baseMapper.selectFsUserInfoByPhone(fsUserInfo.getPhone());
|
|
|
|
+ if(userInfo!=null){
|
|
|
|
+ throw new ServiceException("该手机号用户已存在");
|
|
|
|
+ }
|
|
|
|
+ FsUser user = fsUserService.selectFsUserByPhone(fsUserInfo.getPhone());
|
|
|
|
+ if(user!=null){
|
|
|
|
+ // 判断头像和姓名 性别是否一致 销售id
|
|
|
|
+ boolean updateFlag=false;
|
|
|
|
+ if(StringUtils.isNotEmpty(fsUserInfo.getAvatar())){
|
|
|
|
+ if(!fsUserInfo.getAvatar().equals(user.getAvatar())){
|
|
|
|
+ updateFlag=true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(fsUserInfo.getSex()!= null){
|
|
|
|
+ if(!fsUserInfo.getSex().equals(user.getSex())){
|
|
|
|
+ updateFlag=true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(fsUserInfo.getCompanyUserId()!= null){
|
|
|
|
+ if(!fsUserInfo.getCompanyUserId().equals(user.getCompanyUserId())){
|
|
|
|
+ updateFlag=true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(updateFlag) {
|
|
|
|
+ // 更新用户信息 不修改手机号
|
|
|
|
+ user.setAvatar(fsUserInfo.getAvatar());
|
|
|
|
+ user.setSex(fsUserInfo.getSex());
|
|
|
|
+ user.setCompanyUserId(fsUserInfo.getCompanyUserId());
|
|
|
|
+ user.setUpdateTime(DateUtils.getNowDate());
|
|
|
|
+ if (fsUserMapper.updateFsUser(user) <= 0) {
|
|
|
|
+ throw new ServiceException("用户信息修改失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 登记同一个userId
|
|
|
|
+ fsUserInfo.setUserId(user.getUserId());
|
|
|
|
+ if (insertFsUserInfo(fsUserInfo) <= 0) {
|
|
|
|
+ throw new ServiceException("用户信息登记失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else {
|
|
|
|
+ // 新增用户信息
|
|
|
|
+ FsUser fsUser = new FsUser();
|
|
|
|
+ fsUser.setCompanyUserId(fsUserInfo.getCompanyUserId());
|
|
|
|
+ fsUser.setAvatar(fsUserInfo.getAvatar());
|
|
|
|
+ fsUser.setPhone(fsUserInfo.getPhone());
|
|
|
|
+ fsUser.setSex(fsUserInfo.getSex());
|
|
|
|
+ fsUser.setCreateTime(DateUtils.getNowDate());
|
|
|
|
+ // 登记fsUser表
|
|
|
|
+ if (fsUserMapper.insertFsUser(fsUser) <= 0) {
|
|
|
|
+ throw new ServiceException("用户信息登记失败");
|
|
|
|
+ }
|
|
|
|
+ // 登记同一个userId
|
|
|
|
+ fsUserInfo.setUserId(fsUser.getUserId());
|
|
|
|
+ // 登记fsUserInfo表
|
|
|
|
+ if (insertFsUserInfo(fsUserInfo) <= 0) {
|
|
|
|
+ throw new ServiceException("用户信息登记失败");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|