|
|
@@ -23,9 +23,12 @@ import com.fs.company.param.CompanyUserQwParam;
|
|
|
import com.fs.company.service.*;
|
|
|
import com.fs.company.vo.*;
|
|
|
import com.fs.course.service.IFsUserCompanyUserService;
|
|
|
+import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.service.IFsCityService;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
import com.fs.his.vo.CitysAreaVO;
|
|
|
+import com.fs.his.vo.CompanyUserBindUserVO;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
import com.fs.hisStore.domain.FsStoreProductAttrScrm;
|
|
|
import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
@@ -131,6 +134,9 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
@Autowired
|
|
|
private CompanyMapper companyMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyFsUserMapper companyFsUserMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 邀请码缓存
|
|
|
*/
|
|
|
@@ -1161,6 +1167,79 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public int bindCompanyUserAndFsUser(Long companyUserId, Long fsUserId) {
|
|
|
+ // 检查该用户是否已经与其他销售绑定
|
|
|
+ CompanyFsUser existingBinding = companyFsUserMapper.selectByFsUserId(fsUserId);
|
|
|
+
|
|
|
+ if (existingBinding != null) {
|
|
|
+ // 如果已存在绑定关系,检查是否是同一个销售
|
|
|
+ if (existingBinding.getCompanyUserId().equals(companyUserId)) {
|
|
|
+ // 已经是同一个销售,更新状态并返回成功
|
|
|
+ existingBinding.setStatus(1);
|
|
|
+ existingBinding.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return companyFsUserMapper.updateCompanyFsUser(existingBinding);
|
|
|
+ } else {
|
|
|
+ // 已绑定其他销售,需要先解绑
|
|
|
+ throw new CustomException("该用户已绑定销售:" +
|
|
|
+ companyUserService.selectCompanyUserNameUserById(existingBinding.getCompanyUserId()) +
|
|
|
+ ",需先解绑后才能重新绑定");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 没有绑定记录,创建新的绑定关系
|
|
|
+ CompanyFsUser companyFsUser = new CompanyFsUser();
|
|
|
+ companyFsUser.setCompanyUserId(companyUserId);
|
|
|
+ companyFsUser.setFsUserId(fsUserId);
|
|
|
+ companyFsUser.setStatus(1);
|
|
|
+ companyFsUser.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return companyFsUserMapper.insertCompanyFsUser(companyFsUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean unbindCompanyUserAndFsUser(Long companyUserId, Long userId) {
|
|
|
+ // 校验参数
|
|
|
+ if (companyUserId == null || userId == null) {
|
|
|
+ throw new IllegalArgumentException("销售 ID 或用户 ID 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询是否存在绑定关系
|
|
|
+ CompanyFsUser relation = companyFsUserMapper.selectByCompanyUserIdAndUserId(companyUserId, userId);
|
|
|
+ if (relation == null) {
|
|
|
+ throw new RuntimeException("未找到销售与用户之间的绑定关系");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除绑定关系
|
|
|
+ int rows = companyFsUserMapper.deleteById(relation.getId());
|
|
|
+ return rows > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CompanyUserBindUserVO> getFsUserByCompanyUserId(FsUser fsUser) {
|
|
|
+ //加密手机号
|
|
|
+ if (StringUtils.isNotBlank(fsUser.getPhone())) {
|
|
|
+ fsUser.setPhone(PhoneUtil.encryptPhone(fsUser.getPhone()));
|
|
|
+ }
|
|
|
+ List<CompanyUserBindUserVO> fsUsers = companyFsUserMapper.selecUserList(fsUser);
|
|
|
+ for (CompanyUserBindUserVO user : fsUsers) {
|
|
|
+ if (StringUtils.isNotBlank(user.getPhone())) {
|
|
|
+ user.setPhone(PhoneUtil.decryptPhone(user.getPhone()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return fsUsers;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int countCompanyUserByUserId(Long userId) {
|
|
|
+ CompanyFsUser existingBinding = companyFsUserMapper.selectByFsUserId(userId);
|
|
|
+ if(existingBinding!=null){
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 生成基础邀请码
|
|
|
*/
|