|
@@ -1,20 +1,24 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
-import com.management.platform.entity.Company;
|
|
|
-import com.management.platform.entity.OperationLog;
|
|
|
-import com.management.platform.entity.User;
|
|
|
-import com.management.platform.mapper.CompanyMapper;
|
|
|
-import com.management.platform.mapper.OperationLogMapper;
|
|
|
-import com.management.platform.mapper.UserMapper;
|
|
|
-import com.management.platform.service.CompanyService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.api.R;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
+import com.management.platform.service.*;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
+import com.mysql.cj.util.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -34,6 +38,22 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
HttpServletRequest request;
|
|
|
@Resource
|
|
|
UserMapper userMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectMapper projectMapper;
|
|
|
+ @Resource
|
|
|
+ ReportMapper reportMapper;
|
|
|
+ @Resource
|
|
|
+ ReportService reportService;
|
|
|
+ @Resource
|
|
|
+ CustomerInfoMapper customerInfoMapper;
|
|
|
+ @Resource
|
|
|
+ ParticipationMapper participationMapper;
|
|
|
+ @Resource
|
|
|
+ DepartmentMapper departmentMapper;
|
|
|
+ @Resource
|
|
|
+ ProjectAuditorMapper projectAuditorMapper;
|
|
|
+ @Resource
|
|
|
+ UserService userService;
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg addMembCount(Integer companyId, int addCount) {
|
|
@@ -115,4 +135,162 @@ public class CompanyServiceImpl extends ServiceImpl<CompanyMapper, Company> impl
|
|
|
saveLog(str);
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public HttpRespMsg dataMigration(HttpServletRequest request,Integer oldCompanyId, Integer targetCompanyId,String oldUserName,String targetUserName) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ User oldManager = userMapper.selectOne(new QueryWrapper<User>().eq("name", oldUserName).eq("company_id",oldCompanyId));
|
|
|
+ User targetManager = userMapper.selectOne(new QueryWrapper<User>().eq("name", targetUserName).eq("company_id",targetCompanyId));
|
|
|
+ if(oldManager==null){
|
|
|
+ msg.setError("管理员["+oldUserName+"]不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(targetManager==null){
|
|
|
+ msg.setError("管理员["+targetManager+"]不存在");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(!oldManager.getRoleName().equals("超级管理员")){
|
|
|
+ msg.setError("原公司超级管理员不正确");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(!targetManager.getRoleName().equals("超级管理员")){
|
|
|
+ msg.setError("目标公司超级管理员不正确,当前角色是:"+targetManager.getRoleName());
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ List<User> oldUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", oldCompanyId));
|
|
|
+ List<User> targetUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", targetCompanyId));
|
|
|
+ List<Department> oldDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", oldCompanyId));
|
|
|
+ List<Department> targetDepartmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", targetCompanyId));
|
|
|
+ //处理部门负责人
|
|
|
+ List<User> updateUserList=new ArrayList<>();
|
|
|
+ for (Department oldDepartment : oldDepartmentList) {
|
|
|
+ for (Department targetDepartment : targetDepartmentList) {
|
|
|
+ if(oldDepartment.getDepartmentName().equals(targetDepartment.getDepartmentName())){
|
|
|
+ if(oldDepartment.getManagerId()!=null){
|
|
|
+ Optional<User> oldUser = oldUserList.stream().filter(ou -> ou.getId().equals(oldDepartment.getManagerId())).findFirst();
|
|
|
+ Optional<User> targetUser = targetUserList.stream().filter(tu -> tu.getDingdingUserid().equals(oldUser.get().getDingdingUserid())).findFirst();
|
|
|
+ targetDepartment.setManagerId(targetUser.get().getId());
|
|
|
+ targetUser.get().setDepartmentId(targetDepartment.getDepartmentId());
|
|
|
+ targetUser.get().setDepartmentName(targetDepartment.getDepartmentName());
|
|
|
+ updateUserList.add(targetUser.get());
|
|
|
+ departmentMapper.updateById(targetDepartment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<String> ids=new ArrayList<>();
|
|
|
+ //获取在目标公司也存在的人员
|
|
|
+ for (User targetUser : targetUserList) {
|
|
|
+ for (User oldUser : oldUserList) {
|
|
|
+ if(targetUser.getDingdingUserid().equals(oldUser.getDingdingUserid())){
|
|
|
+ ids.add(oldUser.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Participation> participationList = participationMapper.selectList(new QueryWrapper<Participation>().in("user_id", ids));
|
|
|
+ //取项目id 按照项目参与人
|
|
|
+ List<Integer> projectIds = participationList.stream().map(pc -> pc.getProjectId()).collect(Collectors.toList());
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().in("id", projectIds));
|
|
|
+ List<Project> targetProjectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", targetCompanyId));
|
|
|
+ List<String> list = targetProjectList.stream().map(tp -> tp.getProjectCode()).collect(Collectors.toList());
|
|
|
+ List<ProjectAuditor> oldProjectAuditorList = projectAuditorMapper.selectList(new QueryWrapper<ProjectAuditor>().in("project_id", projectIds));
|
|
|
+ //处理相关项目
|
|
|
+ for (Project pro: projectList) {
|
|
|
+ //此前的项目负责人不存在当前组织架构
|
|
|
+ Optional<User> inchargerUser = oldUserList.stream().filter(ou -> ou.getId().equals(pro.getInchargerId())).findFirst();
|
|
|
+ boolean flag = targetUserList.stream().anyMatch(tu -> tu.getDingdingUserid().equals(inchargerUser.get().getDingdingUserid()));
|
|
|
+ if(!flag){
|
|
|
+ msg.setError("当前项目["+pro.getProjectName()+"]负责人["+inchargerUser.get().getName()+"]不存在");
|
|
|
+ return msg;
|
|
|
+ }else {
|
|
|
+ Optional<User> targetInchargerUser = targetUserList.stream().filter(tu -> tu.getDingdingUserid().equals(inchargerUser.get().getDingdingUserid())).findFirst();
|
|
|
+ pro.setInchargerId(targetInchargerUser.get().getId());
|
|
|
+ }
|
|
|
+ /*//在新公司创建相同的客户信息
|
|
|
+ CustomerInfo customerInfo = customerInfoMapper.selectById(pro.getCustomerId());
|
|
|
+ customerInfo.setId(null);
|
|
|
+ customerInfo.setCompanyId(targetCompanyId);
|
|
|
+ customerInfoMapper.insert(customerInfo);
|
|
|
+ pro.setCustomerId(customerInfo.getId());*/
|
|
|
+ List<ProjectAuditor> projectAuditorList = oldProjectAuditorList.stream().filter(pa -> pa.getProjectId().equals(pro.getId())).collect(Collectors.toList());
|
|
|
+ Optional<User> creatorUser = oldUserList.stream().filter(ou -> ou.getName().equals("李婷婷")).findFirst();
|
|
|
+ Optional<User> targetCreatorUser = targetUserList.stream().filter(tu -> tu.getDingdingUserid().equals(creatorUser.get().getDingdingUserid())).findFirst();
|
|
|
+ pro.setCreatorId(targetCreatorUser.get().getId());
|
|
|
+ //当前项目的相关参与人
|
|
|
+ List<String> userList = participationList.stream().filter(pc -> pc.getProjectId().equals(pro.getId())).collect(Collectors.toList()).stream().map(o -> o.getUserId()).collect(Collectors.toList());
|
|
|
+ pro.setId(null);
|
|
|
+ pro.setCompanyId(targetCompanyId);
|
|
|
+ if(list.contains(pro.getProjectCode())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ projectMapper.insert(pro);
|
|
|
+ //处理项目审核人
|
|
|
+ for (ProjectAuditor projectAuditor : projectAuditorList) {
|
|
|
+ projectAuditor.setProjectId(pro.getId());
|
|
|
+ projectAuditor.setId(null);
|
|
|
+ Optional<User> first = targetUserList.stream().filter(tu -> tu.getName().equals(projectAuditor.getAuditorName())).findFirst();
|
|
|
+ if(first.isPresent()){
|
|
|
+ projectAuditor.setAuditorId(first.get().getId());
|
|
|
+ projectAuditor.setAuditorName(first.get().getName());
|
|
|
+ projectAuditorMapper.insert(projectAuditor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String s:userList){
|
|
|
+ Participation participation=new Participation();
|
|
|
+ participation.setProjectId(pro.getId());
|
|
|
+ Optional<User> user = oldUserList.stream().filter(ou -> ou.getId().equals(s)).findFirst();
|
|
|
+ Optional<User> targetUser = targetUserList.stream().filter(tu -> tu.getDingdingUserid().equals(user.get().getDingdingUserid())).findFirst();
|
|
|
+ participation.setUserId(targetUser.get().getId());
|
|
|
+ participationMapper.insert(participation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<Project> oldProjectList = projectMapper.selectList(new QueryWrapper<Project>().in("id", projectIds));
|
|
|
+ //处理日报
|
|
|
+ List<Report> reportList = reportMapper.selectList(new QueryWrapper<Report>().in("creator_id", ids));
|
|
|
+ List<Report> updateReportList = new ArrayList<>();
|
|
|
+ for (Report report : reportList) {
|
|
|
+ //项目关联
|
|
|
+
|
|
|
+ Optional<Project> oldProject = oldProjectList.stream().filter(op -> op.getId().equals(report.getProjectId())).findFirst();
|
|
|
+ Optional<Project> targetProject = projectList.stream().filter(pro -> pro.getProjectCode().equals(oldProject.get().getProjectCode())).findFirst();
|
|
|
+ report.setProjectId(targetProject.get().getId());
|
|
|
+ Optional<User> oldUser = oldUserList.stream().filter(ou -> ou.getId().equals(report.getCreatorId())).findFirst();
|
|
|
+ Optional<User> targetUser = targetUserList.stream().filter(tu -> tu.getDingdingUserid().equals(oldUser.get().getDingdingUserid())).findFirst();
|
|
|
+ report.setCreatorId(targetUser.get().getId());
|
|
|
+ //部门数据
|
|
|
+ Optional<Department> oldDepart = oldDepartmentList.stream().filter(od -> od.getDepartmentId().equals(report.getDeptId())).findFirst();
|
|
|
+ Optional<Department> targetDepart = targetDepartmentList.stream().filter(td -> td.getDepartmentName().equals(oldDepart.get().getDepartmentName())).findFirst();
|
|
|
+ report.setDeptId(targetDepart.get().getDepartmentId());
|
|
|
+ //当前审核部门数据
|
|
|
+ Optional<Department> oldAuditDepart = oldDepartmentList.stream().filter(od -> od.getDepartmentId().equals(report.getAuditDeptid())).findFirst();
|
|
|
+ if(oldAuditDepart.isPresent()){
|
|
|
+ Optional<Department> targetAuditDepart =targetDepartmentList.stream().filter(td -> td.getDepartmentName().equals(oldAuditDepart.get().getDepartmentName())).findFirst();
|
|
|
+ report.setAuditDeptid(targetAuditDepart.get().getDepartmentId());
|
|
|
+ report.setAuditDeptManagerid(targetAuditDepart.get().getManagerId());
|
|
|
+ }
|
|
|
+ //是否被驳回
|
|
|
+ if(!StringUtils.isNullOrEmpty(report.getRejectUsername())){
|
|
|
+ Optional<User> rejectUser = targetUserList.stream().filter(tu -> tu.getName().equals(report.getRejectUsername())).findFirst();
|
|
|
+ report.setRejectUserid(rejectUser.get().getId());
|
|
|
+ }
|
|
|
+ report.setCompanyId(targetCompanyId);
|
|
|
+// reportMapper.updateById(report);
|
|
|
+ Report newReport = new Report();
|
|
|
+ newReport.setId(report.getId());
|
|
|
+ newReport.setCompanyId(targetCompanyId);
|
|
|
+ newReport.setProjectId(report.getProjectId());
|
|
|
+ newReport.setCreatorId(report.getCreatorId());
|
|
|
+ newReport.setDeptId(report.getDeptId());
|
|
|
+ newReport.setAuditDeptid(report.getAuditDeptid());
|
|
|
+ newReport.setAuditDeptManagerid(report.getAuditDeptManagerid());
|
|
|
+ newReport.setRejectUserid(report.getRejectUserid());
|
|
|
+ updateReportList.add(newReport);
|
|
|
+ }
|
|
|
+ //改成批量更新
|
|
|
+ if (updateReportList.size() > 0) {
|
|
|
+ reportService.updateBatchById(updateReportList);
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
}
|