|
@@ -2,18 +2,23 @@ package com.fs.company.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.fs.common.BeanCopyUtils;
|
|
|
import com.fs.common.annotation.DataScope;
|
|
|
+import com.fs.common.constant.UserConstants;
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.domain.model.LoginUser;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.exception.file.OssException;
|
|
|
-import com.fs.common.utils.DateUtils;
|
|
|
-import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.*;
|
|
|
import com.fs.company.domain.*;
|
|
|
import com.fs.company.mapper.*;
|
|
|
import com.fs.company.param.CompanyUserAreaParam;
|
|
|
+import com.fs.company.param.CompanyUserCodeParam;
|
|
|
import com.fs.company.param.CompanyUserQwParam;
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.company.vo.*;
|
|
|
import com.fs.course.service.IFsUserCompanyUserService;
|
|
@@ -21,8 +26,11 @@ import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.service.IFsCityService;
|
|
|
import com.fs.his.vo.CitysAreaVO;
|
|
|
import com.fs.his.vo.OptionsVO;
|
|
|
+import com.fs.qw.domain.QwUser;
|
|
|
import com.fs.qw.dto.UserProjectDTO;
|
|
|
import com.fs.qw.mapper.QwUserMapper;
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
+import com.fs.qw.service.IQwUserService;
|
|
|
import com.fs.qw.vo.CompanyUserQwVO;
|
|
|
import com.fs.qw.vo.QwOptionsVO;
|
|
|
import com.fs.qw.vo.QwUserVO;
|
|
@@ -83,6 +91,18 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
@Autowired
|
|
|
private IFsUserCompanyUserService userCompanyUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICompanyService companyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwUserService qwUserService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询物业公司管理员信息
|
|
|
*
|
|
@@ -264,6 +284,105 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
return rows;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R registerCompany(CompanyUserCodeParam userCodeParam) {
|
|
|
+ CompanyUser user=new CompanyUser();
|
|
|
+
|
|
|
+ QwUser qwUser = qwUserMapper.selectQwUserByCorpIdAndUserId(userCodeParam.getCorpId(),userCodeParam.getQwUserIdByStr());
|
|
|
+
|
|
|
+ if (qwUser==null){
|
|
|
+ return R.error("无企微员工信息,无法处理,请先同步员工:"+ userCodeParam.getQwUserIdByStr()+"--"+userCodeParam.getCorpId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (qwUser.getCompanyUserId()!=null&&!qwUser.getCompanyUserId().equals(qwUser.getCompanyUserId())){
|
|
|
+ return R.error( qwUser.getQwUserName()+"已经被其他人绑定,请先解绑");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userCodeParam.getBindType()==1){
|
|
|
+
|
|
|
+ if (!PatternUtils.checkPassword(userCodeParam.getPassword())) {
|
|
|
+ return R.error("密码格式不正确,需包含字母、数字和特殊字符,长度为 8-20 位");
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断用户数量是否已达到上线
|
|
|
+ Integer count=companyUserService.selectCompanyUserCountByCompanyId(userCodeParam.getCompanyId());
|
|
|
+ Company company=companyService.selectCompanyById(userCodeParam.getCompanyId());
|
|
|
+
|
|
|
+ if(count>company.getLimitUserCount()){
|
|
|
+ return R.error("用户数量已达到上限");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(String.valueOf(companyUserService.checkUserName(userCodeParam.getUserName()))))
|
|
|
+ {
|
|
|
+ return R.error("新增用户'" + userCodeParam.getUserName() + "'失败,登录账号已存在");
|
|
|
+ }
|
|
|
+ user.setNickName(userCodeParam.getNickName());
|
|
|
+ user.setUserName(userCodeParam.getUserName());
|
|
|
+ user.setSex(userCodeParam.getSex());
|
|
|
+ user.setStatus("1");
|
|
|
+ user.setDept(userCodeParam.getDept());
|
|
|
+ user.setRoleIds(userCodeParam.getRoleIds());
|
|
|
+ user.setAddressId(userCodeParam.getAddressId());
|
|
|
+ user.setCompanyId(userCodeParam.getCompanyId());
|
|
|
+ user.setCreateBy(userCodeParam.getQwUserId());
|
|
|
+ user.setPassword(SecurityUtils.encryptPassword(userCodeParam.getPassword()));
|
|
|
+ user.setCreateTime(new Date());
|
|
|
+ user.setUserType("01");//一般用户
|
|
|
+ user.setIsAudit(1);
|
|
|
+
|
|
|
+ int i = companyUserService.insertUser(user);
|
|
|
+ if (i>0){
|
|
|
+
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectUserByUserName(userCodeParam.getUserName());
|
|
|
+
|
|
|
+ bindQwUserToCompanyUser(qwUser, companyUser);
|
|
|
+
|
|
|
+ }else {
|
|
|
+ return R.error("销售创建失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok();
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (userCodeParam.getBindType()==2){
|
|
|
+
|
|
|
+ // 绑定到现有用户
|
|
|
+ CompanyUser companyUser = companyUserMapper.selectUserByUserName(userCodeParam.getUserName());
|
|
|
+ if (companyUser == null) {
|
|
|
+ return R.error("指定的用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ bindQwUserToCompanyUser(qwUser, companyUser);
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void bindQwUserToCompanyUser(QwUser qwUser, CompanyUser companyUser) {
|
|
|
+ // 更新公司用户的企微ID列表
|
|
|
+ Set<String> qwUserIdSet = new HashSet<>();
|
|
|
+
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(companyUser.getQwUserId())) {
|
|
|
+ String[] existingIds = companyUser.getQwUserId().split(",");
|
|
|
+ qwUserIdSet.addAll(Arrays.stream(existingIds)
|
|
|
+ .filter(id -> !id.isEmpty())
|
|
|
+ .collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+
|
|
|
+ qwUserIdSet.add(String.valueOf(qwUser.getId()));
|
|
|
+ companyUser.setQwUserId(String.join(",", qwUserIdSet));
|
|
|
+ companyUser.setQwStatus(1);
|
|
|
+ companyUserMapper.updateCompanyUser(companyUser);
|
|
|
+
|
|
|
+ // 更新企微用户信息
|
|
|
+ QwUser qw = new QwUser();
|
|
|
+ qw.setCompanyUserId(companyUser.getUserId());
|
|
|
+ qw.setId(qwUser.getId());
|
|
|
+ qw.setStatus(1);
|
|
|
+ qw.setCompanyId(companyUser.getCompanyId());
|
|
|
+ qwUserService.updateQwUser(qw);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改保存用户信息
|
|
|
*
|