Răsfoiți Sursa

用户导入

cr 14 ore în urmă
părinte
comite
101777fd62
17 a modificat fișierele cu 964 adăugiri și 17 ștergeri
  1. 10 0
      blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ContractClient.java
  2. 59 0
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/ExcelUserTemp.java
  3. 19 0
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/ImportUserLog.java
  4. 85 0
      blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/UserImporterNew.java
  5. 1 0
      blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java
  6. 20 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ContractClientImpl.java
  7. 2 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.java
  8. 10 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.xml
  9. 3 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ProjectInfoMapper.java
  10. 9 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ProjectInfoMapper.xml
  11. 2 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/IContractInfoService.java
  12. 5 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/IProjectInfoService.java
  13. 5 0
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java
  14. 14 4
      blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ProjectInfoServiceImpl.java
  15. 45 13
      blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java
  16. 3 0
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java
  17. 672 0
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

+ 10 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/feign/ContractClient.java

@@ -4,6 +4,7 @@ package org.springblade.manager.feign;
 import org.springblade.core.tool.api.R;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
 import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.ProjectInfo;
 import org.springblade.manager.vo.RoleSignPfxUserVO3;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.transaction.annotation.Transactional;
@@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
+import java.util.Set;
 
 import static org.springblade.core.launch.constant.AppConstant.APPLICATION_NAME_PREFIX;
 
@@ -80,4 +82,12 @@ public interface ContractClient {
     @GetMapping(API_PREFIX+"/findAllUserAndRoleList")
     RoleSignPfxUserVO3 findAllUserAndRoleList(@RequestParam Long contractId, @RequestParam(required = false) Long roleId);
 
+    @PostMapping(API_PREFIX+"/queryProjectList")
+    List<ProjectInfo> queryProjectList(@RequestBody Set<String> projectId);
+
+    @PostMapping(API_PREFIX+"/queryProjectIds")
+    List<String> queryProjectIds(@RequestBody Set<String> projectId);
+
+    @GetMapping(API_PREFIX+"/queryContractNamesListByProjectId")
+    List<ContractInfo> queryContractNamesListByProjectId(@RequestParam String projectId);
 }

+ 59 - 0
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/ExcelUserTemp.java

@@ -0,0 +1,59 @@
+package org.springblade.system.user.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+@Data
+public class ExcelUserTemp {
+    // A列:登录账号 → index=0
+    @ExcelProperty(index = 0)
+    private String account;
+
+    // B列:登录密码 → index=1
+    @ExcelProperty(index = 1)
+    private String password;
+
+    // C列:用户姓名 → index=2
+    @ExcelProperty(index = 2)
+    private String realName;
+
+    // D列:用户平台 → index=3
+    @ExcelProperty(index = 3)
+    private String userType;
+
+    // E列:手机号码 → index=4
+    @ExcelProperty(index = 4)
+    private String phone;
+
+    // F列:身份证号码 → index=5
+    @ExcelProperty(index = 5)
+    private String idNumber;
+
+    // G列:所属部门 → index=6
+    @ExcelProperty(index = 6)
+    private String deptName;
+
+    // H列:电签信息 → index=7
+    @ExcelProperty(index = 7)
+    private String accCode;
+
+    // I列:项目id → index=8
+    @ExcelProperty(index = 8)
+    private String projectName;
+
+    // J列:合同段名称/编号 → index=9
+    @ExcelProperty(index = 9)
+    private String contractInfo;
+
+    // K列:所属方 → index=10
+    @ExcelProperty(index = 10)
+    private String owner;
+
+    // L列:岗位名称 → index=11
+    @ExcelProperty(index = 11)
+    private String roleName;
+
+    // M列:登录状态 → index=12
+    @ExcelProperty(index = 12)
+    private String status;
+}

+ 19 - 0
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/ImportUserLog.java

@@ -0,0 +1,19 @@
+package org.springblade.system.user.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class ImportUserLog {
+    private Long id;
+    private String account;
+    private String name;
+    private String message;
+    private String importTime;
+    private Long importId;
+    private Long importUser;
+    private String filePath;
+}

+ 85 - 0
blade-service-api/blade-user-api/src/main/java/org/springblade/system/user/dto/UserImporterNew.java

@@ -0,0 +1,85 @@
+package org.springblade.system.user.dto;
+
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Data
+public class UserImporterNew {
+    /**
+     * 登录账号
+     */
+    private String account;
+    /**
+     * 登录密码
+     */
+    private String password;
+
+    /**
+     * 用户姓名
+     */
+    private String realName;
+
+    /**
+     * 用户平台
+     */
+    private String userType;
+
+    /**
+     * 手机号码
+     */
+    private String phone;
+
+    /**
+     * 身份证号码
+     */
+    private String idNumber;
+
+    /**
+     * 所属部门(中文名称)
+     */
+    private String deptName;
+
+    /**
+     * 电签信息(东方中迅电签码)
+     */
+    private String accCode;
+
+    /**
+     * 项目id
+     */
+    private String projectId;
+
+    /**
+     * 合同段名称/编号
+     */
+    private String contractInfo;
+
+    /**
+     * 所属方(1业主方 2监理方 3施工方)
+     */
+    private String owner;
+
+    /**
+     * 岗位名称(中文匹配)
+     */
+    private String roleName;
+
+    /**
+     * 登录状态(允许为空,默认为是)
+     */
+    private String status;
+
+
+
+    private String contractId;
+
+    private Long roleId;
+
+    private Long deptId;
+
+    private Map<String, List<String>> porjectAndContractMap=new HashMap<>();
+
+}

+ 1 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -5756,6 +5756,7 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 					auto.setId(SnowFlakeUtil.getId());
 					auto.setName(saveVolumeDto1.getArchiveName());
 					auto.setIsVolume(2);
+
 					archiveId= auto.getId();
 					baseMapper.insert(auto);
 				}else {

+ 20 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/feign/ContractClientImpl.java

@@ -8,14 +8,18 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.StringUtil;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
 import org.springblade.manager.entity.ContractInfo;
+import org.springblade.manager.entity.ProjectInfo;
 import org.springblade.manager.mapper.SaveUserInfoByProjectMapper;
 import org.springblade.manager.service.IContractInfoService;
+import org.springblade.manager.service.IProjectInfoService;
 import org.springblade.manager.service.impl.SaveUserInfoByProjectServiceImpl;
 import org.springblade.manager.vo.RoleSignPfxUserVO3;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 @RestController
 @AllArgsConstructor
@@ -24,6 +28,7 @@ public class ContractClientImpl implements ContractClient {
     private final IContractInfoService contractInfoService;
     private final SaveUserInfoByProjectMapper saveUserInfoByProjectMapper;
     private final SaveUserInfoByProjectServiceImpl saveUserInfoByProject;
+    private final IProjectInfoService projectInfoService;
 
     @Override
     public List<String> getProcessContractByJLContractId(String contractId) {
@@ -107,5 +112,20 @@ public class ContractClientImpl implements ContractClient {
         return contractInfoService.findAllUserAndRoleList(contractId,roleId);
     }
 
+    @Override
+    public List<ProjectInfo> queryProjectList(Set<String> projectIds) {
+        return projectInfoService.selectProjectList(projectIds);
+    }
+
+    @Override
+    public List<String> queryProjectIds(Set<String> projectId) {
+        return projectInfoService.queryProjectIds(projectId);
+    }
+
+    @Override
+    public List<ContractInfo> queryContractNamesListByProjectId(String projectId) {
+        return contractInfoService.queryContractNamesListByProjectId(projectId);
+    }
+
 
 }

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.java

@@ -77,4 +77,6 @@ public interface ContractInfoMapper extends BaseMapper<ContractInfo> {
     List<RoleSignPfxUserVO1> findAllUserAndRoleList1(Long contractId, Long roleId);
 
     List<RoleSignPfxUserVO2> findAllUserAndRoleList2(Long contractId, Long roleId);
+
+    List<ContractInfo> queryContractNamesListByProjectId(@Param("projectId") String projectId);
 }

+ 10 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ContractInfoMapper.xml

@@ -585,5 +585,15 @@
             And r.id=#{roleId}
         </if>
     </select>
+    <select id="queryContractNamesListByProjectId" resultType="org.springblade.manager.entity.ContractInfo">
+        SELECT
+        *
+        FROM
+        m_contract_info
+        WHERE
+        is_deleted = 0
+        AND p_id = #{projectId}
+    </select>
+
 
 </mapper>

+ 3 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ProjectInfoMapper.java

@@ -10,6 +10,7 @@ import org.springblade.manager.vo.ProjectUserAmountVO;
 import org.springblade.manager.vo.SingPfxManagementVO;
 
 import java.util.List;
+import java.util.Set;
 
 public interface ProjectInfoMapper extends BaseMapper<ProjectInfo> {
 
@@ -32,4 +33,6 @@ public interface ProjectInfoMapper extends BaseMapper<ProjectInfo> {
     ProjectInfo selectOneAndWbsTypeById(Long id);
 
     IPage<ProjectInfoVO> pageList(IPage<ProjectInfoVO> page, @Param("vo") ProjectInfoVO3 vo);
+
+    List<String> queryProjectIds(@Param("projectIds") Set<String> projectIds);
 }

+ 9 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ProjectInfoMapper.xml

@@ -191,5 +191,14 @@
             </when>
         </choose>
     </select>
+    <select id="queryProjectIds" resultType="java.lang.String">
+        select id from m_project_info where is_deleted = 0
+        <if test="projectIds != null">
+            and id in
+            <foreach item="projectId" collection="projectIds" open="(" separator="," close=")">
+                #{projectId}
+            </foreach>
+        </if>
+    </select>
 
 </mapper>

+ 2 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IContractInfoService.java

@@ -91,4 +91,6 @@ public interface IContractInfoService extends BaseService<ContractInfo> {
 
     R<Object> getCollectTreeNode(String contractId, String tableOwner, Long folderId, String queryValue, Long pKeyId);
     R<Object> getCollectTreeNodeByQuery(String contractId, String tableOwner, Long folderId, String queryValue);
+
+    List<ContractInfo> queryContractNamesListByProjectId(String projectId);
 }

+ 5 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/IProjectInfoService.java

@@ -6,6 +6,7 @@ import org.springblade.core.mp.base.BaseService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
 import java.util.List;
+import java.util.Set;
 
 public interface IProjectInfoService extends BaseService<ProjectInfo> {
 
@@ -15,6 +16,8 @@ public interface IProjectInfoService extends BaseService<ProjectInfo> {
 
     List<ProjectInfo> selectProjectList(List<String> projectIds);
 
+    List<ProjectInfo> selectProjectList(Set<String> projectIds);
+
     IPage<ProjectInfoVO> selectProjectInfoPage(IPage<ProjectInfoVO> page, ProjectInfoVO projectInfo);
 
     List<ContractlnfoCountVO> selectContractInfoCount();
@@ -28,4 +31,6 @@ public interface IProjectInfoService extends BaseService<ProjectInfo> {
     Long getProjectIdbyName(String projectName);
 
     IPage<ProjectInfoVO> pageList(IPage<ProjectInfoVO> page, ProjectInfoVO3 vo);
+
+    List<String> queryProjectIds(Set<String> projectId);
 }

+ 5 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ContractInfoServiceImpl.java

@@ -1849,4 +1849,9 @@ public class ContractInfoServiceImpl extends BaseServiceImpl<ContractInfoMapper,
         }
         return null;
     }
+
+    @Override
+    public List<ContractInfo> queryContractNamesListByProjectId(String projectId) {
+        return contractInfoMapper.queryContractNamesListByProjectId(projectId);
+    }
 }

+ 14 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ProjectInfoServiceImpl.java

@@ -14,16 +14,14 @@ import org.springblade.manager.mapper.*;
 import org.springblade.manager.service.IProjectInfoService;
 import org.springblade.core.mp.base.BaseServiceImpl;
 import org.springblade.manager.wrapper.ProjectInfoWrapper;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -41,6 +39,8 @@ public class ProjectInfoServiceImpl extends BaseServiceImpl<ProjectInfoMapper, P
 
     @Resource
     private JdbcTemplate jdbcTemplate;
+    @Autowired
+    private ProjectInfoMapper projectInfoMapper;
 
     public List<ProjectUserAmountVO> queryProjectUserAmount() {
         return this.baseMapper.queryProjectUserAmount();
@@ -85,6 +85,11 @@ public class ProjectInfoServiceImpl extends BaseServiceImpl<ProjectInfoMapper, P
         return this.baseMapper.selectProjectList(projectIds);
     }
 
+    @Override
+    public List<ProjectInfo> selectProjectList(Set<String> projectIds) {
+        return this.baseMapper.selectProjectList((List<String>) projectIds);
+    }
+
     @Override
     public IPage<ProjectInfoVO> selectProjectInfoPage(IPage<ProjectInfoVO> page, ProjectInfoVO projectInfo) {
         return page.setRecords(baseMapper.selectProjectInfoPage(page, projectInfo));
@@ -186,4 +191,9 @@ public class ProjectInfoServiceImpl extends BaseServiceImpl<ProjectInfoMapper, P
         return pagedList;
     }
 
+    @Override
+    public List<String> queryProjectIds(Set<String> projectId) {
+        return projectInfoMapper.queryProjectIds(projectId);
+    }
+
 }

+ 45 - 13
blade-service/blade-user/src/main/java/org/springblade/system/user/controller/UserController.java

@@ -17,6 +17,8 @@
 package org.springblade.system.user.controller;
 
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.read.metadata.ReadSheet;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.nacos.common.utils.MD5Utils;
@@ -26,6 +28,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
+import org.apache.commons.codec.Charsets;
 import org.apache.http.Consts;
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;
@@ -37,6 +40,8 @@ import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.http.message.BasicNameValuePair;
 import org.springblade.common.cache.CacheNames;
 import org.springblade.common.constant.CommonConstant;
+import org.springblade.common.utils.CommonUtil;
+import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.cache.utils.CacheUtil;
 import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.mp.support.Condition;
@@ -56,8 +61,7 @@ import org.springblade.system.cache.ParamCache;
 import org.springblade.system.user.bean.CyGetToken;
 import org.springblade.system.user.bean.ResultCYData;
 import org.springblade.system.user.bean.ResultCYKey;
-import org.springblade.system.user.dto.TokenVerifyResult;
-import org.springblade.system.user.dto.UserDTO;
+import org.springblade.system.user.dto.*;
 import org.springblade.system.user.entity.User;
 import org.springblade.system.user.excel.UserExcel;
 import org.springblade.system.user.excel.UserExcel2;
@@ -75,9 +79,10 @@ import springfox.documentation.annotations.ApiIgnore;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
+import java.net.URLEncoder;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 
 import static org.springblade.core.cache.constant.CacheConstant.USER_CACHE;
@@ -342,18 +347,27 @@ public class UserController {
         return R.data(list);
     }
 
-    /**
-     * 导入用户
-     */
+//    /**
+//     * 导入用户
+//     */
+//    @PostMapping("import-user")
+//    @ApiOperationSupport(order = 12)
+//    @ApiOperation(value = "导入用户", notes = "传入excel")
+//    public R importUser(MultipartFile file, Integer isCovered) {
+//        UserImporter userImporter = new UserImporter(userService, isCovered == 1);
+//        ExcelUtil.save(file, userImporter, UserExcel.class);
+//        return R.success("操作成功");
+//    }
+
     @PostMapping("import-user")
     @ApiOperationSupport(order = 12)
-    @ApiOperation(value = "导入用户", notes = "传入excel")
-    public R importUser(MultipartFile file, Integer isCovered) {
-        UserImporter userImporter = new UserImporter(userService, isCovered == 1);
-        ExcelUtil.save(file, userImporter, UserExcel.class);
-        return R.success("操作成功");
+    @ApiOperation(value = "导入用户", notes = "传入excel(多sheet+纵向合同段逗号拼接+过滤全null行)")
+    public R importUserNew(@RequestParam("file") MultipartFile file) {
+        return userService.importUserNew(file);
     }
 
+
+
     /**
      * 导出全部用户
      */
@@ -377,6 +391,24 @@ public class UserController {
         ExcelUtil.export(response, "用户数据模板" + DateUtil.time(), "用户数据表", list, UserExcel.class);
     }
 
+    @GetMapping("/downloadImportUserExcel")
+    @ApiOperationSupport(order = 31)
+    @ApiOperation(value = "下载excel数据")
+    @ApiImplicitParam(name = "fileId", value = "fileId")
+    public void downloadImportUserExcel(HttpServletResponse response) throws Exception {
+        String fileName = URLEncoder.encode("用户数据模版", Charsets.UTF_8.name());
+        String filePath="https://xinan1.zos.ctyun.cn/blade-oss-chongqing/upload/20251203/f42a9c6956903e8bd3d9559ffcaf1326.xlsx";
+        InputStream redio = CommonUtil.getOSSInputStream(filePath);
+        byte[] buffer = IoUtil.readToByteArray(redio);
+        OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+        toClient.write(buffer);
+        toClient.flush();
+        toClient.close();
+    }
+
 
     /**
      * 第三方注册用户

+ 3 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/service/IUserService.java

@@ -20,6 +20,7 @@ import org.springblade.system.user.excel.UserExcel;
 import org.springblade.system.user.vo.InformationQueryBIMVO;
 import org.springblade.system.user.vo.InformationQueryVO1;
 import org.springblade.system.user.vo.UserVO;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -248,4 +249,6 @@ public interface IUserService extends BaseService<User> {
     List<InformationQueryVO1> queryInformationByContractIdAndName(String contractId, String name);
 
     R queryInformationByFileNumber(String contractId, String fieldNumber);
+
+    R importUserNew(MultipartFile file);
 }

+ 672 - 0
blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

@@ -1,10 +1,13 @@
 package org.springblade.system.user.service.impl;
 
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.read.metadata.ReadSheet;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.nacos.common.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -35,6 +38,7 @@ import org.springblade.core.tool.utils.*;
 import org.springblade.manager.dto.SaveUserInfoByProjectDTO;
 import org.springblade.manager.entity.*;
 import org.springblade.manager.feign.ContractClient;
+import org.springblade.manager.feign.ProjectAssignmentUserClient;
 import org.springblade.manager.vo.PrivateTreeVO;
 import org.springblade.manager.vo.PrivateTreeVO2;
 import org.springblade.manager.vo.WbsTreeContractLazyQueryInfoVO;
@@ -45,12 +49,16 @@ import org.springblade.system.cache.DictCache;
 import org.springblade.system.cache.ParamCache;
 import org.springblade.system.cache.SysCache;
 import org.springblade.system.entity.Dept;
+import org.springblade.system.entity.Role;
 import org.springblade.system.entity.Tenant;
 import org.springblade.system.enums.DictEnum;
 import org.springblade.system.feign.ISysClient;
 import org.springblade.system.user.bean.NodeVO;
 import org.springblade.system.user.cache.UserCache;
+import org.springblade.system.user.dto.ExcelUserTemp;
+import org.springblade.system.user.dto.ImportUserLog;
 import org.springblade.system.user.dto.UserDTO;
+import org.springblade.system.user.dto.UserImporterNew;
 import org.springblade.system.user.entity.*;
 import org.springblade.system.user.enums.UserEnum;
 import org.springblade.system.user.excel.UserExcel;
@@ -75,9 +83,14 @@ import org.springframework.jdbc.core.SingleColumnRowMapper;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
@@ -85,6 +98,7 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.function.Function;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -2366,4 +2380,662 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
         return R.data(information);
     }
 
+    @Override
+    public R importUserNew(MultipartFile file) {
+        List<UserImporterNew> finalUserList = new ArrayList<>();
+        List<ImportUserLog>logs=new ArrayList<>();
+        LocalDateTime now = LocalDateTime.now();
+        String importTime = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        Long importId= SnowFlakeUtil.getId();
+        Long importUser=AuthUtil.getUserId();
+        List<User> insertUserList=new ArrayList<>();
+        List<UserDept> insertUserDeptList=new ArrayList<>();
+        List<SaveUserInfoByProjectDTO> insertUserInfoByProjectList=new ArrayList<>();
+        List<User>updateUserList=new ArrayList<>();
+        List<SaveUserInfoByProjectDTO>updateUserInfoByProjectList=new ArrayList<>();
+        try {
+            // 1. 获取所有sheet元数据
+            List<ReadSheet> allSheets = EasyExcel.read(file.getInputStream())
+                    .head(ExcelUserTemp.class)
+                    .build()
+                    .excelExecutor()
+                    .sheetList();
+
+            // 2. 遍历每个sheet处理
+            for (ReadSheet sheet : allSheets) {
+                System.out.println("正在读取sheet:" + sheet.getSheetName() + "(索引:" + sheet.getSheetNo() + ")");
+
+                // 读取当前sheet数据(从第3行开始,跳过前2行表头)
+                List<ExcelUserTemp> sheetData = EasyExcel.read(file.getInputStream())
+                        .head(ExcelUserTemp.class)
+                        .sheet(sheet.getSheetNo())
+                        .headRowNumber(2)
+                        .doReadSync();
+
+                // 3. 核心逻辑:收集同一用户的多个合同段,用逗号拼接
+                ExcelUserTemp currentUser = null; // 记录当前用户核心信息
+                List<String> contractList = new ArrayList<>(); // 收集当前用户的所有合同段
+
+                for (ExcelUserTemp row : sheetData) {
+                    // 判断当前行是否是“新用户行”(核心字段有值)
+                    if (!isAllCoreFieldsNull(row)) {
+                        // 先处理上一个用户(若存在)
+                        if (currentUser != null) {
+                            generateSingleUserRecord(currentUser, contractList, finalUserList);
+                        }
+                        // 初始化新用户信息
+                        currentUser = row;
+                        contractList = new ArrayList<>();
+                        // 收集当前行的合同段(首行可能带合同段)
+                        addValidContract(row.getContractInfo(), contractList);
+                    } else {
+                        // 当前行是“合同段补充行”(核心字段空,仅合同段有值)
+                        if (currentUser != null) {
+                            addValidContract(row.getContractInfo(), contractList);
+                        }
+                    }
+                }
+                // 处理最后一个用户
+                if (currentUser != null) {
+                    generateSingleUserRecord(currentUser, contractList, finalUserList);
+                }
+            }
+            // 5. 后续业务逻辑(批量保存等)
+            if (!finalUserList.isEmpty()) {
+                //查出所有的部门名
+                List<Dept>deptNames=jdbcTemplate.query("select id,dept_name from blade_dept where is_deleted=0",new BeanPropertyRowMapper<>(Dept.class));
+                //查出所有的角色名
+                List<Role>roleNamesSG=jdbcTemplate.query("select id,role_name from blade_role where parent_id=(select id from blade_role where role_name='施工方' and is_deleted=0 limit 1)",new BeanPropertyRowMapper<>(Role.class));
+                List<Role>roleNamesJL=jdbcTemplate.query("select id,role_name from blade_role where parent_id=(select id from blade_role where role_name='监理方' and is_deleted=0 limit 1)",new BeanPropertyRowMapper<>(Role.class));
+                List<Role>roleNamesYZ=jdbcTemplate.query("select id,role_name from blade_role where parent_id=(select id from blade_role where role_name='业主方' and is_deleted=0 limit 1)",new BeanPropertyRowMapper<>(Role.class));
+                Map<String,List<Role>> roleMap= new HashMap<>();
+                roleMap.put("3",roleNamesSG);
+                roleMap.put("2",roleNamesJL);
+                roleMap.put("1",roleNamesYZ);
+                //查出所有的项目的合同段名
+                // 查出所有的项目的合同段名
+                Set<String> projectIdData = finalUserList.stream()
+                        .filter(userImporterNew -> !StringUtil.isEmpty(userImporterNew.getProjectId()))
+                        .flatMap(userImporterNew -> Arrays.stream(userImporterNew.getProjectId().split(",")))
+                        .map(String::trim)
+                        .filter(projectId -> !projectId.isEmpty())
+                        .collect(Collectors.toSet());
+                List<String>projectIds=contractClient.queryProjectIds(projectIdData);
+                //根据项目id查询合同段
+                Map<String,List<ContractInfo>> contractNamesMap=new HashMap<>();
+                if(!projectIds.isEmpty()){
+                    for (String projectId : projectIds) {
+                      List<ContractInfo>contractNames=contractClient.queryContractNamesListByProjectId(projectId);
+                      contractNamesMap.put(projectId,contractNames);
+                    }
+                }
+                for (UserImporterNew userImporterNew : finalUserList) {
+                    //首先 根据账号查询用户
+                    //账号为null
+                    if(StringUtil.isEmpty(userImporterNew.getAccount())){
+                        //姓名不为null
+                        if(!StringUtil.isEmpty(userImporterNew.getRealName())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),userImporterNew.getRealName()+"的账号为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                        }else {
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"账号姓名都为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                        }
+                        continue;
+                    }
+                    User user=this.getOne(new QueryWrapper<User>().lambda().eq(User::getAccount,userImporterNew.getAccount()));
+                    //账号不存在 则新增
+                    if(user==null){
+                        //前置条件判断
+                        /**
+                         * 验证姓名
+                         */
+                        if(StringUtil.isEmpty(userImporterNew.getRealName())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"姓名为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                            continue;
+                        }
+                        /**
+                         * 验证手机号
+                         */
+                        if(StringUtil.isEmpty(userImporterNew.getPhone())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"手机号为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                            continue;
+                        }else {
+                            boolean b = isValidChinesePhoneNumber(userImporterNew.getPhone());
+                            if(!b){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"手机号格式错误",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }
+                        }
+                        /**
+                         * 验证身份证号
+                         */
+                        if(StringUtil.isEmpty(userImporterNew.getIdNumber())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"身份证号为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                            continue;
+                        }else {
+                            boolean b = isValidIdCard(userImporterNew.getIdNumber());
+                            if(!b){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"身份证号格式错误",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }
+                        }
+                        /**
+                         * 验证用户平台
+                         */
+                        if(StringUtil.isEmpty(userImporterNew.getUserType())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"用户平台为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                            continue;
+                        }else {
+                            String userType = userImporterNew.getUserType();
+                            List<String> types = new ArrayList<>();
+                            if (userType != null && !userType.isEmpty()) {
+                                Pattern pattern = Pattern.compile("\\d+");
+                                java.util.regex.Matcher matcher = pattern.matcher(userType);
+                                while (matcher.find()) {
+                                    types.add(matcher.group());
+                                }
+                            }
+                            //判断是否只包含1,2,3,7
+                            Set<String> allowedTypes = new HashSet<>(Arrays.asList("1", "2", "3", "7"));
+                            boolean isValid = types.stream().allMatch(allowedTypes::contains);
+                            if(!isValid){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"用户平台格式错误",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }else {
+                                userImporterNew.setUserType(String.join(",", types));
+                            }
+                        }
+                        /**
+                         * 验证部门
+                         */
+                        if(StringUtil.isEmpty(userImporterNew.getDeptName())){
+                            ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属部门为空",importTime,importId,importUser,file.getOriginalFilename());
+                            logs.add(log);
+                            continue;
+                        }else {
+                            Optional<Dept> dept = deptNames.stream().filter(deptName -> !StringUtil.isEmpty(deptName) && deptName.equals(userImporterNew.getDeptName())).findFirst();
+                            if(!dept.isPresent()){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属部门不存在",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }else {
+                                userImporterNew.setDeptId(dept.get().getId());
+                            }
+                        }
+                        //如果部门信息全都为null 就跳过验证
+                        if(!(StringUtil.isEmpty(userImporterNew.getProjectId())&&StringUtil.isEmpty(userImporterNew.getContractInfo())&&StringUtil.isEmpty(userImporterNew.getOwner())&&StringUtil.isEmpty(userImporterNew.getRoleName()))){
+                            /**
+                             * 验证项目信息
+                             */
+                            if(StringUtil.isEmpty(userImporterNew.getProjectId())){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属项目为空",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }else {
+                                if(!projectIds.contains(userImporterNew.getProjectId())){
+                                    ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属项目Id没找到对应的项目",importTime,importId,importUser,file.getOriginalFilename());
+                                    logs.add(log);
+                                    continue;
+                                }
+                            }
+                            /**
+                             * 验证合同段
+                             */
+                            if(StringUtil.isEmpty(userImporterNew.getContractInfo())){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"合同段名称/编号为空",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }else {
+                                StringBuilder contractId=new StringBuilder();
+                                String contractInfo = userImporterNew.getContractInfo();
+                                String[] contractInfoData = contractInfo.split(",");
+                                //根据名称或编号来查找
+                                List<ContractInfo> contractInfos = contractNamesMap.get(userImporterNew.getProjectId());
+                                for (String info : contractInfoData) {
+                                    Optional<ContractInfo> nameOptional = contractInfos.stream().filter(c -> !StringUtil.isEmpty(c.getContractName()) && c.getContractName().equals(info)).findFirst();
+                                    Optional<ContractInfo> numberOptional  = contractInfos.stream().filter(c -> !StringUtil.isEmpty(c.getContractNumber()) && c.getContractNumber().equals(info)).findFirst();
+                                    if(!(nameOptional.isPresent()||numberOptional.isPresent())){
+                                        ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"合同段名称/编号不存在",importTime,importId,importUser,file.getOriginalFilename());
+                                        logs.add(log);
+                                    }else {
+                                        if(nameOptional.isPresent()){
+                                            contractId.append(",").append(nameOptional.get().getId());
+                                        }else {
+                                            contractId.append(",").append(numberOptional.get().getId());
+                                        }
+                                    }
+                                }
+                                userImporterNew.setContractId(contractId.substring(1));
+                            }
+                            /**
+                             * 验证所属方
+                             */
+                            if(StringUtil.isEmpty(userImporterNew.getOwner())){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属方为空",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                                continue;
+                            }else {
+                                String owner = userImporterNew.getOwner();
+                                if(!(owner.equals("1")||owner.equals("2")||owner.equals("3"))){
+                                    ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属方格式错误",importTime,importId,importUser,file.getOriginalFilename());
+                                    logs.add(log);
+                                    continue;
+                                }
+                            }
+                            /**
+                             * 验证岗位
+                             */
+                            if(StringUtil.isEmpty(userImporterNew.getRoleName())){
+                                ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"角色为空",importTime,importId,importUser,file.getOriginalFilename());
+                                logs.add(log);
+                            }else {
+                                List<Role> roles = roleMap.get(userImporterNew.getOwner());
+                                Optional<Role> role = roles.stream().filter(r -> r.getRoleName().equals(userImporterNew.getRoleName())).findFirst();
+                                if (role.isPresent()) {
+                                    userImporterNew.setRoleId(role.get().getId());
+                                } else {
+                                    ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"角色不存在",importTime,importId,importUser,file.getOriginalFilename());
+                                    logs.add(log);
+                                }
+                            }
+                        }
+                         //验证完毕 开始新增
+                        /**
+                         * 用户账号表
+                         */
+                        user.setId(SnowFlakeUtil.getId());
+                        user.setTenantId(AuthUtil.getTenantId());
+                        user.setAccount(userImporterNew.getAccount());
+                        user.setUserType(userImporterNew.getUserType());
+                        user.setPassword(DigestUtil.encrypt(userImporterNew.getPassword()));
+                        user.setPlaintextPassword(userImporterNew.getPassword());
+                        user.setName(userImporterNew.getRealName());
+                        user.setRealName(userImporterNew.getRealName());
+                        user.setIdNumber(userImporterNew.getIdNumber());
+                        user.setPhone(userImporterNew.getPhone());
+                        user.setRoleId(userImporterNew.getRoleId()+"");
+                        user.setDeptId(userImporterNew.getDeptId()+"");
+                        user.setStatus("是".equals(userImporterNew.getStatus()) ? 1 : 0);
+                        user.setAccCode(userImporterNew.getAccCode());
+                        insertUserList.add(user);
+                        /**
+                         * 用户部门表
+                         */
+                        UserDept userDept = new UserDept();
+                        userDept.setUserId(user.getId());
+                        userDept.setDeptId(userImporterNew.getDeptId());
+                        insertUserDeptList.add(userDept);
+                        /**
+                         * 项目分配用户关系表
+                         */
+                        if(!StringUtil.isEmpty(userImporterNew.getProjectId())&&!StringUtil.isEmpty(userImporterNew.getContractId())){
+                            String contractIds = userImporterNew.getContractId();
+                            String[] contractList = contractIds.split(",");
+                            for (String contractId : contractList) {
+                                SaveUserInfoByProjectDTO dto = new SaveUserInfoByProjectDTO();
+                                dto.setId(SnowFlakeUtil.getId());
+                                dto.setProjectId(userImporterNew.getProjectId());
+                                dto.setContractId(contractId);
+                                dto.setRoleId(user.getRoleId());
+                                dto.setUserId(user.getId()+"");
+                                dto.setStatus(1);
+                                insertUserInfoByProjectList.add(dto);
+                            }
+                        }
+                    }else {
+                        //账号存在 则更新
+                        //模板上姓名和数据库的姓名相同则修改
+                        if(!StringUtil.isEmpty(userImporterNew.getRealName())){
+                           if(user.getRealName().equals(userImporterNew.getRealName())){
+                               //拿到项目和合同段
+                               //如果部门信息全都为null 就跳过验证
+                               if(!(StringUtil.isEmpty(userImporterNew.getProjectId())&&StringUtil.isEmpty(userImporterNew.getContractInfo())&&StringUtil.isEmpty(userImporterNew.getOwner())&&StringUtil.isEmpty(userImporterNew.getRoleName()))){
+                                   /**
+                                    * 验证项目信息
+                                    */
+                                   if(StringUtil.isEmpty(userImporterNew.getProjectId())){
+                                       ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属项目为空",importTime,importId,importUser,file.getOriginalFilename());
+                                       logs.add(log);
+                                       continue;
+                                   }else {
+                                       if(!projectIds.contains(userImporterNew.getProjectId())){
+                                           ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属项目Id没找到对应的项目",importTime,importId,importUser,file.getOriginalFilename());
+                                           logs.add(log);
+                                           continue;
+                                       }
+                                   }
+                                   /**
+                                    * 验证合同段
+                                    */
+                                   if(StringUtil.isEmpty(userImporterNew.getContractInfo())){
+                                       ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"合同段名称/编号为空",importTime,importId,importUser,file.getOriginalFilename());
+                                       logs.add(log);
+                                       continue;
+                                   }else {
+                                       StringBuilder contractId=new StringBuilder();
+                                       String contractInfo = userImporterNew.getContractInfo();
+                                       String[] contractInfoData = contractInfo.split(",");
+                                       //根据名称或编号来查找
+                                       List<ContractInfo> contractInfos = contractNamesMap.get(userImporterNew.getProjectId());
+                                       for (String info : contractInfoData) {
+                                           Optional<ContractInfo> nameOptional = contractInfos.stream().filter(c -> !StringUtil.isEmpty(c.getContractName()) && c.getContractName().equals(info)).findFirst();
+                                           Optional<ContractInfo> numberOptional  = contractInfos.stream().filter(c -> !StringUtil.isEmpty(c.getContractNumber()) && c.getContractNumber().equals(info)).findFirst();
+                                           if(!(nameOptional.isPresent()||numberOptional.isPresent())){
+                                               ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"合同段名称/编号不存在",importTime,importId,importUser,file.getOriginalFilename());
+                                               logs.add(log);
+                                           }else {
+                                               if(nameOptional.isPresent()){
+                                                   contractId.append(",").append(nameOptional.get().getId());
+                                               }else {
+                                                   contractId.append(",").append(numberOptional.get().getId());
+                                               }
+                                           }
+                                       }
+                                       userImporterNew.setContractId(contractId.substring(1));
+                                   }
+                                   /**
+                                    * 验证所属方
+                                    */
+                                   if(StringUtil.isEmpty(userImporterNew.getOwner())){
+                                       ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属方为空",importTime,importId,importUser,file.getOriginalFilename());
+                                       logs.add(log);
+                                       continue;
+                                   }else {
+                                       String owner = userImporterNew.getOwner();
+                                       if(!(owner.equals("1")||owner.equals("2")||owner.equals("3"))){
+                                           ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"所属方格式错误",importTime,importId,importUser,file.getOriginalFilename());
+                                           logs.add(log);
+                                           continue;
+                                       }
+                                   }
+                                   /**
+                                    * 验证岗位
+                                    */
+                                   if(StringUtil.isEmpty(userImporterNew.getRoleName())){
+                                       ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"角色为空",importTime,importId,importUser,file.getOriginalFilename());
+                                       logs.add(log);
+                                   }else {
+                                       List<Role> roles = roleMap.get(userImporterNew.getOwner());
+                                       Optional<Role> role = roles.stream().filter(r -> r.getRoleName().equals(userImporterNew.getRoleName())).findFirst();
+                                       if (role.isPresent()) {
+                                           userImporterNew.setRoleId(role.get().getId());
+                                       } else {
+                                           ImportUserLog log=new ImportUserLog(SnowFlakeUtil.getId(),userImporterNew.getAccount(),userImporterNew.getRealName(),"角色不存在",importTime,importId,importUser,file.getOriginalFilename());
+                                           logs.add(log);
+                                       }
+                                   }
+                               }
+                               //将当前的项目以及合同段做比较
+                               //查出当前用户分配的项目和合同段
+                               String sql="select * from m_project_assignment_user where user_id="+user.getId()+" and is_deleted=0 and project_id="+userImporterNew.getProjectId();
+                               List<SaveUserInfoByProjectDTO> projectAssignmentUsers = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SaveUserInfoByProjectDTO.class));
+                               //说明该项目是新增的
+                               if(projectAssignmentUsers.isEmpty()){
+                                   user.setRoleId(user.getRoleId()+","+userImporterNew.getRoleId());
+                                   user.setStatus("是".equals(userImporterNew.getStatus()) ? 1 : 0);
+                                   updateUserList.add(user);
+                                   if(!StringUtil.isEmpty(userImporterNew.getProjectId())&&!StringUtil.isEmpty(userImporterNew.getContractId())){
+                                       String contractIds = userImporterNew.getContractId();
+                                       String[] contractList = contractIds.split(",");
+                                       for (String contractId : contractList) {
+                                           SaveUserInfoByProjectDTO dto = new SaveUserInfoByProjectDTO();
+                                           dto.setId(SnowFlakeUtil.getId());
+                                           dto.setProjectId(userImporterNew.getProjectId());
+                                           dto.setContractId(contractId);
+                                           dto.setRoleId(user.getRoleId());
+                                           dto.setUserId(user.getId()+"");
+                                           dto.setStatus(1);
+                                           insertUserInfoByProjectList.add(dto);
+                                       }
+                                   }
+                               }else {
+                                   //不是新增的项目 但是是新增的合同段
+
+                                   //不是新增的项目 但是新增了合同段其中的老合同段
+
+                                   //不是新增的项目 也没有新增的合同段
+                               }
+
+                           }
+                        }
+                    }
+                }
+
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return R.fail("导入失败:" + e.getMessage());
+        }
+
+        return R.success("导入成功,共生成" + finalUserList.size() + "条有效记录");
+    }
+
+    /**
+     * 校验并添加有效合同段(过滤空值和纯空格)
+     */
+    private void addValidContract(String contract, List<String> contractList) {
+        if (Objects.nonNull(contract) && !contract.trim().isEmpty()) {
+            contractList.add(contract.trim());
+        }
+    }
+
+    /**
+     * 生成单个用户记录(多个合同段用逗号拼接)
+     */
+    private void generateSingleUserRecord(ExcelUserTemp currentUser, List<String> contractList, List<UserImporterNew> finalList) {
+        // 处理默认值
+        String defaultPwd = Objects.isNull(currentUser.getPassword()) ? "user123456" : currentUser.getPassword();
+        String defaultStatus = Objects.isNull(currentUser.getStatus()) ? "是" : currentUser.getStatus();
+
+        // 拼接合同段(空列表则存空字符串)
+        String joinedContract = contractList.isEmpty() ? "" : String.join(",", contractList);
+
+        // 构建用户记录(仅一条)
+        UserImporterNew user = new UserImporterNew();
+        user.setAccount(currentUser.getAccount());
+        user.setPassword(defaultPwd);
+        user.setRealName(currentUser.getRealName());
+        user.setUserType(currentUser.getUserType());
+        user.setPhone(currentUser.getPhone());
+        user.setIdNumber(currentUser.getIdNumber());
+        user.setDeptName(currentUser.getDeptName());
+        user.setAccCode(currentUser.getAccCode());
+        user.setProjectId(currentUser.getProjectName());
+        user.setContractInfo(joinedContract); // 逗号拼接后的合同段
+        user.setOwner(currentUser.getOwner());
+        user.setRoleName(currentUser.getRoleName());
+        user.setStatus(defaultStatus);
+
+        finalList.add(user);
+        System.out.println("用户" + currentUser.getRealName() + "的合同段:" + joinedContract);
+    }
+
+    /**
+     * 判断核心字段是否全为空(识别新用户行)
+     */
+    private boolean isAllCoreFieldsNull(ExcelUserTemp temp) {
+        return (Objects.isNull(temp.getAccount()) || temp.getAccount().trim().isEmpty())
+                && (Objects.isNull(temp.getRealName()) || temp.getRealName().trim().isEmpty())
+                && (Objects.isNull(temp.getPhone()) || temp.getPhone().trim().isEmpty())
+                && (Objects.isNull(temp.getIdNumber()) || temp.getIdNumber().trim().isEmpty());
+    }
+    /**
+     * 判断中国大陆手机号格式是否正确
+     *
+     * @param phoneNumber 手机号
+     * @return true表示格式正确,false表示格式错误
+     */
+    public static boolean isValidChinesePhoneNumber(String phoneNumber) {
+        if (phoneNumber == null || phoneNumber.length() != 11) {
+            return false;
+        }
+
+        // 使用正则表达式匹配手机号格式
+        String regex = "^1[3-9]\\d{9}$";
+        return phoneNumber.matches(regex);
+    }
+
+    /**
+     * 判断身份证格式是否正确
+     *
+     * @param idCard 身份证号码
+     * @return true表示格式正确,false表示格式错误
+     */
+    public static boolean isValidIdCard(String idCard) {
+        if (idCard == null || idCard.trim().isEmpty()) {
+            return false;
+        }
+
+        idCard = idCard.trim();
+
+        // 长度验证
+        if (idCard.length() == 15) {
+            return isValidIdCard15(idCard);
+        } else if (idCard.length() == 18) {
+            return isValidIdCard18(idCard);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 验证15位身份证号码
+     *
+     * @param idCard 15位身份证号码
+     * @return true表示格式正确,false表示格式错误
+     */
+    private static boolean isValidIdCard15(String idCard) {
+        // 15位身份证号码为纯数字
+        if (!Pattern.matches("\\d{15}", idCard)) {
+            return false;
+        }
+
+        // 验证出生日期
+        String birthDay = "19" + idCard.substring(6, 12); // 15位身份证年份默认为19XX年
+        return isValidDate(birthDay, "yyyyMMdd");
+    }
+
+    /**
+     * 验证18位身份证号码
+     *
+     * @param idCard 18位身份证号码
+     * @return true表示格式正确,false表示格式错误
+     */
+    private static boolean isValidIdCard18(String idCard) {
+        // 18位身份证号码前17位为数字,最后一位为数字或X
+        if (!Pattern.matches("\\d{17}[\\dXx]", idCard)) {
+            return false;
+        }
+
+        // 验证地址码(简单验证前两位)
+        String areaCode = idCard.substring(0, 2);
+        if (!AREA_CODES.contains(areaCode)) {
+            return false;
+        }
+
+        // 验证出生日期
+        String birthDay = idCard.substring(6, 14);
+        if (!isValidDate(birthDay, "yyyyMMdd")) {
+            return false;
+        }
+
+        // 验证校验码
+        return checkIdCard18(idCard);
+    }
+
+    /**
+     * 验证日期格式是否正确
+     *
+     * @param date   日期字符串
+     * @param format 日期格式
+     * @return true表示日期格式正确,false表示日期格式错误
+     */
+    private static boolean isValidDate(String date, String format) {
+        SimpleDateFormat sdf = new SimpleDateFormat(format);
+        sdf.setLenient(false); // 严格模式,不允许不合理的日期
+        try {
+            sdf.parse(date);
+            // 检查年份范围(例如:1900年至今)
+            Calendar calendar = new GregorianCalendar();
+            calendar.setTime(sdf.parse(date));
+            int year = calendar.get(Calendar.YEAR);
+            int currentYear = Calendar.getInstance().get(Calendar.YEAR);
+            return year >= 1900 && year <= currentYear;
+        } catch (ParseException e) {
+            return false;
+        }
+    }
+
+    /**
+     * 验证18位身份证号码的校验码
+     *
+     * @param idCard 18位身份证号码
+     * @return true表示校验码正确,false表示校验码错误
+     */
+    private static boolean checkIdCard18(String idCard) {
+        char[] idCardArray = idCard.toCharArray();
+        int[] weight = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
+        char[] validate = {'1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'};
+        int sum = 0;
+
+        for (int i = 0; i < 17; i++) {
+            sum += (idCardArray[i] - '0') * weight[i];
+        }
+
+        int mod = sum % 11;
+        char validateCode = validate[mod];
+
+        return Character.toUpperCase(idCardArray[17]) == validateCode;
+    }
+
+    // 简化的省份代码列表(前两位)
+    private static final java.util.Set<String> AREA_CODES = new java.util.HashSet<>();
+    static {
+        AREA_CODES.add("11"); // 北京
+        AREA_CODES.add("12"); // 天津
+        AREA_CODES.add("13"); // 河北
+        AREA_CODES.add("14"); // 山西
+        AREA_CODES.add("15"); // 内蒙古
+        AREA_CODES.add("21"); // 辽宁
+        AREA_CODES.add("22"); // 吉林
+        AREA_CODES.add("23"); // 黑龙江
+        AREA_CODES.add("31"); // 上海
+        AREA_CODES.add("32"); // 江苏
+        AREA_CODES.add("33"); // 浙江
+        AREA_CODES.add("34"); // 安徽
+        AREA_CODES.add("35"); // 福建
+        AREA_CODES.add("36"); // 江西
+        AREA_CODES.add("37"); // 山东
+        AREA_CODES.add("41"); // 河南
+        AREA_CODES.add("42"); // 湖北
+        AREA_CODES.add("43"); // 湖南
+        AREA_CODES.add("44"); // 广东
+        AREA_CODES.add("45"); // 广西
+        AREA_CODES.add("46"); // 海南
+        AREA_CODES.add("50"); // 重庆
+        AREA_CODES.add("51"); // 四川
+        AREA_CODES.add("52"); // 贵州
+        AREA_CODES.add("53"); // 云南
+        AREA_CODES.add("54"); // 西藏
+        AREA_CODES.add("61"); // 陕西
+        AREA_CODES.add("62"); // 甘肃
+        AREA_CODES.add("63"); // 青海
+        AREA_CODES.add("64"); // 宁夏
+        AREA_CODES.add("65"); // 新疆
+        AREA_CODES.add("71"); // 台湾
+        AREA_CODES.add("81"); // 香港
+        AREA_CODES.add("82"); // 澳门
+        AREA_CODES.add("91"); // 国外
+    }
+
+
 }