|
|
@@ -1,19 +1,24 @@
|
|
|
package com.fs.company.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
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.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,16 @@ 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.hisStore.domain.FsStoreProductAttrScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
|
|
|
+import com.fs.hisStore.domain.FsStoreProductScrm;
|
|
|
+import com.fs.hisStore.dto.ProductArrtDTO;
|
|
|
+import com.fs.hisStore.vo.FsStoreProductExportVO;
|
|
|
+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;
|
|
|
@@ -38,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -83,6 +97,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;
|
|
|
+
|
|
|
/**
|
|
|
* 查询物业公司管理员信息
|
|
|
*
|
|
|
@@ -135,6 +161,163 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
return companyUserMapper.insertCompanyUser(companyUser);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String importCompanyUser(List<CompanyUserImportVO> list, boolean updateSupport) {
|
|
|
+
|
|
|
+ if (com.fs.common.utils.StringUtils.isNull(list) || list.size() == 0)
|
|
|
+ {
|
|
|
+ throw new CustomException("导入销售信息不能为空!");
|
|
|
+ }
|
|
|
+ int successNum = 0;
|
|
|
+ int failureNum = 0;
|
|
|
+ StringBuilder successMsg = new StringBuilder();
|
|
|
+ StringBuilder failureMsg = new StringBuilder();
|
|
|
+ for (CompanyUserImportVO importVO : list){
|
|
|
+ try
|
|
|
+ {
|
|
|
+ CompanyUser copy = BeanCopyUtils.copy(importVO, CompanyUser.class);
|
|
|
+
|
|
|
+ assert copy != null;
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(copy.getPassword())){
|
|
|
+ throw new CustomException("密码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!PatternUtils.checkPassword(copy.getPassword())) {
|
|
|
+ throw new CustomException("密码格式不正确,需包含字母、数字和特殊字符,长度为 8-20 位");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (copy.getCompanyId() == null){
|
|
|
+ throw new CustomException("公司ID不能为空,且为数字!");
|
|
|
+ } else if (!String.valueOf(copy.getCompanyId()).matches("\\d+")) {
|
|
|
+ throw new CustomException("公司ID必须为数字!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (copy.getDeptId() == null){
|
|
|
+ throw new CustomException("部门编号不能为空,且为数字!");
|
|
|
+ } else if (!String.valueOf(copy.getDeptId()).matches("\\d+")) {
|
|
|
+ throw new CustomException("部门编号必须为数字!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(copy.getPhonenumber())){
|
|
|
+ throw new CustomException("手机号不能为空");
|
|
|
+ } else if (!copy.getPhonenumber().matches("\\d+")) {
|
|
|
+ throw new CustomException("手机号必须为数字!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(copy.getAddressId())){
|
|
|
+ throw new CustomException("区域不能为空");
|
|
|
+ } else if (!copy.getAddressId().matches("\\d+")) {
|
|
|
+ throw new CustomException("区域ID必须为数字!");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer count=companyUserService.selectCompanyUserCountByCompanyId(copy.getCompanyId());
|
|
|
+ Company company=companyService.selectCompanyById(copy.getCompanyId());
|
|
|
+
|
|
|
+ if(count>company.getLimitUserCount()){
|
|
|
+ throw new CustomException("销售公司的销售数量已达到上限!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (UserConstants.NOT_UNIQUE.equals(String.valueOf(companyUserService.checkUserName(copy.getUserName()))))
|
|
|
+ {
|
|
|
+ throw new CustomException("新增用户'" + copy.getUserName() + "'失败,登录账号已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(copy.getNickName())){
|
|
|
+ throw new CustomException("用户昵称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(importVO.getRoleString())){
|
|
|
+ throw new CustomException("角色-不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String[] splitRoles = splitRoles(importVO.getRoleString());
|
|
|
+
|
|
|
+ // 新增用户与岗位管理
|
|
|
+ Set<Long> setList= new HashSet<>();
|
|
|
+
|
|
|
+ for (String stringRole : splitRoles) {
|
|
|
+ Long rolesId = roleMapper.selectRolesByUserNameAndCompanyId(stringRole, copy.getCompanyId());
|
|
|
+
|
|
|
+ if (StringUtils.isNotNull(rolesId)) {
|
|
|
+ setList.add(rolesId);
|
|
|
+ }else {
|
|
|
+ throw new CustomException("当前销售公司没有此角色");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为 Long[]
|
|
|
+ Long[] roleIds = setList.toArray(new Long[0]);
|
|
|
+ copy.setRoleIds(roleIds);
|
|
|
+
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new CustomException("角色-格式不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ copy.setUserType("01");//一般用户
|
|
|
+ copy.setIsAudit(1);
|
|
|
+ copy.setPassword(SecurityUtils.encryptPassword(copy.getPassword()));
|
|
|
+ copy.setCreateTime(new Date());
|
|
|
+ copy.setStatus("0");
|
|
|
+
|
|
|
+ int rows = companyUserMapper.insertCompanyUser(copy);
|
|
|
+ if (rows>0){
|
|
|
+ // 新增用户与角色管理
|
|
|
+ insertUserRole(copy);
|
|
|
+ }else {
|
|
|
+ throw new CustomException("新增用户'" + copy.getUserName() + "'失败");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ successNum++;
|
|
|
+ successMsg.append("<br/>" + successNum + "、销售账号 " + copy.getUserName() + " 导入成功");
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+
|
|
|
+ failureNum++;
|
|
|
+ String msg = "<br/>" + failureNum + "、销售账号 " + importVO.getUserName() + " 导入失败:";
|
|
|
+ failureMsg.append(msg + e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (failureNum > 0)
|
|
|
+ {
|
|
|
+ failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
|
|
|
+ throw new CustomException(failureMsg.toString());
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
+ }
|
|
|
+ return successMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String[] splitRoles(String roleString) {
|
|
|
+ if (roleString == null || roleString.trim().isEmpty()) {
|
|
|
+ return new String[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 预处理:替换中文标点,去除首尾空格
|
|
|
+ String processed = roleString
|
|
|
+ .replace(",", ",")
|
|
|
+ .replace(";", ";")
|
|
|
+ .replace("、", ",")
|
|
|
+ .trim();
|
|
|
+
|
|
|
+ // 分割并过滤空值
|
|
|
+ return Arrays.stream(processed.split("[,;\\s]+"))
|
|
|
+ .filter(s -> !s.isEmpty())
|
|
|
+ .map(String::trim)
|
|
|
+ .toArray(String[]::new);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改物业公司管理员信息
|
|
|
*
|
|
|
@@ -264,6 +447,106 @@ 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.setDeptId(userCodeParam.getDeptId());
|
|
|
+ user.setPhonenumber(userCodeParam.getPhonenumber());
|
|
|
+ user.setRoleIds(userCodeParam.getRoleIds());
|
|
|
+ user.setAddressId(userCodeParam.getAddressId());
|
|
|
+ user.setCompanyId(userCodeParam.getCompanyId());
|
|
|
+ user.setCreateBy(userCodeParam.getQwUserIdByStr());
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 修改保存用户信息
|
|
|
*
|
|
|
@@ -532,6 +815,7 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void auditUsers(List<Long> userIds,Long companyId) {
|
|
|
if (userIds.isEmpty()) {
|
|
|
return;
|
|
|
@@ -558,10 +842,14 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
companyUserList.stream().forEach(c->{
|
|
|
//判断角色是否为空
|
|
|
if(ObjectUtil.isNotNull(role)){
|
|
|
- CompanyUserRole userRole=new CompanyUserRole();
|
|
|
- userRole.setRoleId(role.getRoleId());
|
|
|
- userRole.setUserId(c.getUserId());
|
|
|
- companyUserRoleList.add(userRole);
|
|
|
+ //判断该用户角色是否存在
|
|
|
+ CompanyUserRole companyUserRole = userRoleMapper.selectCompanyUserRoleById(c.getUserId());
|
|
|
+ if(companyUserRole == null || !Objects.equals(companyUserRole.getRoleId(), role.getRoleId())){
|
|
|
+ CompanyUserRole userRole=new CompanyUserRole();
|
|
|
+ userRole.setRoleId(role.getRoleId());
|
|
|
+ userRole.setUserId(c.getUserId());
|
|
|
+ companyUserRoleList.add(userRole);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//判断部门
|
|
|
@@ -571,13 +859,16 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
|
|
|
//判断岗位
|
|
|
if(ObjectUtil.isNotNull(companyPost)){
|
|
|
- //添加用户岗位表
|
|
|
- CompanyUserPost userPost=new CompanyUserPost();
|
|
|
- userPost.setPostId(companyPost.getPostId());
|
|
|
- userPost.setUserId(c.getUserId());
|
|
|
- companyUserPosts.add(userPost);
|
|
|
+ //判断该岗位是否存在
|
|
|
+ CompanyUserPost companyUserPost = userPostMapper.selectCompanyUserPostById(c.getUserId());
|
|
|
+ if(companyUserPost == null || !Objects.equals(companyUserPost.getPostId(), companyPost.getPostId())){
|
|
|
+ //添加用户岗位表
|
|
|
+ CompanyUserPost userPost=new CompanyUserPost();
|
|
|
+ userPost.setPostId(companyPost.getPostId());
|
|
|
+ userPost.setUserId(c.getUserId());
|
|
|
+ companyUserPosts.add(userPost);
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
|
|
|
//批量插入角色用户中间表
|
|
|
@@ -660,4 +951,27 @@ public class CompanyUserServiceImpl implements ICompanyUserService
|
|
|
companyUserMapper.uploadQrCode(userId,url);
|
|
|
return url;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R bindDoctor(CompanyUser companyUser) {
|
|
|
+ CompanyUser map = new CompanyUser();
|
|
|
+ map.setUserId(companyUser.getUserId());
|
|
|
+ map.setDoctorId(companyUser.getDoctorId());
|
|
|
+ int i = companyUserMapper.updateCompanyUser(map);
|
|
|
+ if (i > 0) {
|
|
|
+ return R.ok();
|
|
|
+ } else {
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R unBindDoctor(Long userId) {
|
|
|
+ int i = companyUserMapper.unBindDoctorId(userId);
|
|
|
+ if (i > 0) {
|
|
|
+ return R.ok();
|
|
|
+ } else {
|
|
|
+ return R.error();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|