Ver código fonte

销售账号导入

三七 3 dias atrás
pai
commit
e19541abf4

+ 23 - 1
fs-company/src/main/java/com/fs/company/controller/company/CompanyUserController.java

@@ -22,6 +22,7 @@ import com.fs.company.param.CompanyUserCodeParam;
 import com.fs.company.param.CompanyUserQwParam;
 import com.fs.company.service.*;
 import com.fs.company.utils.DomainUtil;
+import com.fs.company.vo.CompanyUserImportVO;
 import com.fs.company.vo.CompanyUserQwListVO;
 import com.fs.company.vo.CompanyUserVO;
 import com.fs.course.config.CourseConfig;
@@ -30,6 +31,7 @@ import com.fs.framework.security.SecurityUtils;
 import com.fs.framework.service.TokenService;
 import com.fs.his.utils.qrcode.QRCodeUtils;
 import com.fs.his.vo.OptionsVO;
+import com.fs.hisStore.vo.FsStoreProductExportVO;
 import com.fs.im.service.OpenIMService;
 import com.fs.qw.domain.QwCompany;
 import com.fs.qw.service.IQwCompanyService;
@@ -139,7 +141,7 @@ public class CompanyUserController extends BaseController
         }
         return getDataTable(list);
     }
-    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
+    @Log(title = "用户管理导出", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('company:user:export')")
     @GetMapping("/export")
     public AjaxResult export(CompanyUser user)
@@ -152,6 +154,26 @@ public class CompanyUserController extends BaseController
     }
 
 
+    @Log(title = "销售信息导入", businessType = BusinessType.IMPORT,isStoreLog = true,logParam = {"销售","信息导入"})
+    @PreAuthorize("@ss.hasPermi('company:user:import')")
+    @PostMapping("/importCompanyUser")
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
+    {
+        ExcelUtil<CompanyUserImportVO> util = new ExcelUtil<>(CompanyUserImportVO.class);
+        List<CompanyUserImportVO> list = util.importExcel(file.getInputStream());
+        String message = companyUserService.importCompanyUser(list, updateSupport);
+        return AjaxResult.success(message);
+    }
+
+
+    @GetMapping("/importTemplate")
+    public AjaxResult importTemplate()
+    {
+        ExcelUtil<CompanyUserImportVO> util = new ExcelUtil<>(CompanyUserImportVO.class);
+        return util.importTemplateExcel("销售数据");
+    }
+
+
 
     /**
      * 根据用户编号获取详细信息

+ 2 - 2
fs-service/src/main/java/com/fs/company/domain/CompanyUser.java

@@ -35,8 +35,8 @@ public class CompanyUser extends BaseEntity
 
     private String corpId;
 
-    /** 部门ID */
-    @Excel(name = "部门ID")
+    /** 部门编号 */
+    @Excel(name = "部门编号")
     private Long deptId;
 
     /** 用户账号 */

+ 1 - 0
fs-service/src/main/java/com/fs/company/mapper/CompanyRoleMapper.java

@@ -84,4 +84,5 @@ public interface CompanyRoleMapper
      * @return 角色信息
      * **/
     CompanyRole selectCompanyRoleByRoleKey(@Param("roleKey") String roleKey);
+    Long selectRolesByUserNameAndCompanyId(@Param("roleName") String roleName,@Param("companyId") Long companyId);
 }

+ 4 - 0
fs-service/src/main/java/com/fs/company/service/ICompanyUserService.java

@@ -8,6 +8,7 @@ import com.fs.company.param.CompanyUserQwParam;
 import com.fs.company.vo.*;
 import com.fs.his.vo.CitysAreaVO;
 import com.fs.his.vo.OptionsVO;
+import com.fs.hisStore.vo.FsStoreProductExportVO;
 import com.fs.qw.dto.UserProjectDTO;
 import com.fs.qw.vo.CompanyUserQwVO;
 import com.fs.qw.vo.QwOptionsVO;
@@ -53,6 +54,9 @@ public interface ICompanyUserService {
      */
     public int insertCompanyUser(CompanyUser companyUser);
 
+    String importCompanyUser(List<CompanyUserImportVO> list, boolean updateSupport);
+
+
     /**
      * 修改物业公司管理员信息
      *

+ 166 - 0
fs-service/src/main/java/com/fs/company/service/impl/CompanyUserServiceImpl.java

@@ -1,9 +1,12 @@
 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;
@@ -23,6 +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.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;
@@ -43,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;
@@ -152,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);
+    }
+
     /**
      * 修改物业公司管理员信息
      *

+ 17 - 350
fs-service/src/main/java/com/fs/company/vo/CompanyUserImportVO.java

@@ -5,32 +5,24 @@ import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
 import com.fs.company.domain.CompanyDept;
 import com.fs.company.domain.CompanyRole;
+import lombok.Data;
 
 import java.util.Date;
 import java.util.List;
 
+@Data
 public class CompanyUserImportVO extends BaseEntity {
     private static final long serialVersionUID = 1L;
 
     /** 用户ID */
     private Long userId;
 
-    /** 公司ID */
-    @Excel(name = "公司ID")
+    /** 公司编号 */
+    @Excel(name = "公司编号")
     private Long companyId;
 
-    public String getCorpId() {
-        return corpId;
-    }
-
-    public void setCorpId(String corpId) {
-        this.corpId = corpId;
-    }
-
-    private String corpId;
-
-    /** 部门ID */
-    @Excel(name = "部门ID")
+    /** 部门编号 */
+    @Excel(name = "部门编号")
     private Long deptId;
 
     /** 用户账号 */
@@ -41,8 +33,7 @@ public class CompanyUserImportVO extends BaseEntity {
     @Excel(name = "用户昵称")
     private String nickName;
 
-    /** 用户类型(00系统用户) */
-    @Excel(name = "用户类型", readConverterExp = "0=0系统用户")
+    /** 用户类型(00管理员 01员工 ) */
     private String userType;
 
     /** 用户邮箱 */
@@ -54,13 +45,9 @@ public class CompanyUserImportVO extends BaseEntity {
     private String phonenumber;
 
     /** 用户性别(0男 1女 2未知) */
-    @Excel(name = "用户性别", readConverterExp = "0=男,1=女,2=未知")
+    @Excel(name = "用户性别(0男 1女 2未知)", readConverterExp = "0=男,1=女,2=未知")
     private String sex;
 
-    /** 头像地址 */
-    @Excel(name = "头像地址")
-    private String avatar;
-
     /** 身份证号 */
     @Excel(name = "身份证号")
     private String idCard;
@@ -69,23 +56,24 @@ public class CompanyUserImportVO extends BaseEntity {
     @Excel(name = "密码")
     private String password;
 
+    /** 角色字符串 */
+    @Excel(name = "角色(多角色用逗号分割)")
+    private String roleString;
+
     /** 帐号状态(0正常 1停用) */
-    @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用")
     private String status;
 
+    private String corpId;
+
     /** 删除标志(0代表存在 2代表删除) */
     private String delFlag;
 
+    /** 头像地址 */
+    private String avatar;
+
     private String qwUserId;
     private Integer qwStatus;
 
-    public String getIdCard() {
-        return idCard;
-    }
-
-    public void setIdCard(String idCard) {
-        this.idCard = idCard;
-    }
 
     /** 最后登录IP */
     private String loginIp;
@@ -111,9 +99,6 @@ public class CompanyUserImportVO extends BaseEntity {
     /** 角色组 */
     private Long[] roleIds;
 
-    /** 角色字符串 */
-    @Excel(name = "角色(多角色用逗号分割)")
-    private String roleString;
 
     /** 岗位组 */
     private Long[] postIds;
@@ -137,322 +122,4 @@ public class CompanyUserImportVO extends BaseEntity {
     /** 看课域名 */
     private String domain;
 
-    public String getDomain() {
-        return domain;
-    }
-
-    public void setDomain(String domain) {
-        this.domain = domain;
-    }
-
-    public String getAddressId() {
-        return addressId;
-    }
-
-    public void setAddressId(String addressId) {
-        this.addressId = addressId;
-    }
-
-    public String getVoicePrintUrl() {
-        return voicePrintUrl;
-    }
-
-    public void setVoicePrintUrl(String voicePrintUrl) {
-        this.voicePrintUrl = voicePrintUrl;
-    }
-
-    public String getCallerNo() {
-        return callerNo;
-    }
-
-    public void setCallerNo(String callerNo) {
-        this.callerNo = callerNo;
-    }
-
-    public String getJpushId() {
-        return jpushId;
-    }
-
-    public String getQwUserId() {
-        return qwUserId;
-    }
-
-    public void setQwUserId(String qwUserId) {
-        this.qwUserId = qwUserId;
-    }
-
-    public Integer getQwStatus() {
-        return qwStatus;
-    }
-
-    public void setQwStatus(Integer qwStatus) {
-        this.qwStatus = qwStatus;
-    }
-
-    public void setJpushId(String jpushId) {
-        this.jpushId = jpushId;
-    }
-
-    public String getQrCodeWeixin() {
-        return qrCodeWeixin;
-    }
-
-    public void setQrCodeWeixin(String qrCodeWeixin) {
-        this.qrCodeWeixin = qrCodeWeixin;
-    }
-
-    public String getQrCodeWecom() {
-        return qrCodeWecom;
-    }
-
-    public void setQrCodeWecom(String qrCodeWecom) {
-        this.qrCodeWecom = qrCodeWecom;
-    }
-
-    public String getOpenId() {
-        return openId;
-    }
-
-    public void setOpenId(String openId) {
-        this.openId = openId;
-    }
-
-    public String getUserName() {
-        return userName;
-    }
-
-    public void setUserName(String userName) {
-        this.userName = userName;
-    }
-
-    public String getNickName() {
-        return nickName;
-    }
-
-
-    public void setNickName(String nickName) {
-        this.nickName = nickName;
-    }
-
-    public String getFirstchar() {
-        return firstchar;
-    }
-
-    public void setFirstchar(String firstchar) {
-        this.firstchar = firstchar;
-    }
-
-    public String getPostName() {
-        return postName;
-    }
-
-    public void setPostName(String postName) {
-        this.postName = postName;
-    }
-
-    public String getDeptName() {
-        return deptName;
-    }
-
-    public void setDeptName(String deptName) {
-        this.deptName = deptName;
-    }
-
-    public CompanyDept getDept() {
-        return dept;
-    }
-
-    public void setDept(CompanyDept dept) {
-        this.dept = dept;
-    }
-
-    public static long getSerialVersionUID() {
-        return serialVersionUID;
-    }
-
-    public boolean isAdmin()
-    {
-        return isAdmin(this.userType);
-    }
-
-    public static boolean isAdmin(String userType)
-    {
-        if(userType!=null&&(userType.equals("00") || userType.equals("02"))){
-            return true;
-        }
-        else return false;
-    }
-
-    public List<CompanyRole> getRoles() {
-        return roles;
-    }
-
-    public void setRoles(List<CompanyRole> roles) {
-        this.roles = roles;
-    }
-
-    public String getRoleString() {
-        return roleString;
-    }
-
-    public void setRoleString(String roleString) {
-        this.roleString = roleString;
-    }
-
-    public Long[] getRoleIds() {
-        return roleIds;
-    }
-
-    public void setRoleIds(Long[] roleIds) {
-        this.roleIds = roleIds;
-    }
-
-    public Long[] getPostIds() {
-        return postIds;
-    }
-
-    public void setPostIds(Long[] postIds) {
-        this.postIds = postIds;
-    }
-
-
-    public void setUserId(Long userId)
-    {
-        this.userId = userId;
-    }
-
-    public Long getUserId()
-    {
-        return userId;
-    }
-    public void setCompanyId(Long companyId)
-    {
-        this.companyId = companyId;
-    }
-
-    public Long getCompanyId()
-    {
-        return companyId;
-    }
-    public void setDeptId(Long deptId)
-    {
-        this.deptId = deptId;
-    }
-
-    public Long getDeptId()
-    {
-        return deptId;
-    }
-
-    public void setUserType(String userType)
-    {
-        this.userType = userType;
-    }
-
-    public String getUserType()
-    {
-        return userType;
-    }
-    public void setEmail(String email)
-    {
-        this.email = email;
-    }
-
-    public String getEmail()
-    {
-        return email;
-    }
-    public void setPhonenumber(String phonenumber)
-    {
-        this.phonenumber = phonenumber;
-    }
-
-    public String getPhonenumber()
-    {
-        return phonenumber;
-    }
-    public void setSex(String sex)
-    {
-        this.sex = sex;
-    }
-
-    public String getSex()
-    {
-        return sex;
-    }
-    public void setAvatar(String avatar)
-    {
-        this.avatar = avatar;
-    }
-
-    public String getAvatar()
-    {
-        return avatar;
-    }
-
-    public void setPassword(String password)
-    {
-        this.password = password;
-    }
-
-    public String getPassword()
-    {
-        return password;
-    }
-    public void setStatus(String status)
-    {
-        this.status = status;
-    }
-
-    public String getStatus()
-    {
-        return status;
-    }
-    public void setDelFlag(String delFlag)
-    {
-        this.delFlag = delFlag;
-    }
-
-    public String getDelFlag()
-    {
-        return delFlag;
-    }
-    public void setLoginIp(String loginIp)
-    {
-        this.loginIp = loginIp;
-    }
-
-    public String getLoginIp()
-    {
-        return loginIp;
-    }
-    public void setLoginDate(Date loginDate)
-    {
-        this.loginDate = loginDate;
-    }
-
-    public Date getLoginDate()
-    {
-        return loginDate;
-    }
-
-
-    public void setToken(String token)
-    {
-        this.token = token;
-    }
-
-    public String getToken()
-    {
-        return token;
-    }
-    public void setIsDel(Integer isDel)
-    {
-        this.isDel = isDel;
-    }
-
-    public Integer getIsDel()
-    {
-        return isDel;
-    }
 }

+ 5 - 0
fs-service/src/main/resources/mapper/company/CompanyRoleMapper.xml

@@ -181,4 +181,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     <select id="selectCompanyRoleByRoleKey" resultType="com.fs.company.domain.CompanyRole">
         SELECT * FROM company_role WHERE del_flag=0 AND role_key = #{roleKey}
     </select>
+
+    <select id="selectRolesByUserNameAndCompanyId" resultType="Long">
+        select role_id from company_role where  del_flag = '0' and status = '0' and  role_name= #{roleName}  and company_id = #{companyId}
+    </select>
+
 </mapper>