|
@@ -386,7 +386,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg importTask(Integer projectId, Integer groupId, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ public HttpRespMsg importTask(Integer isMultiProject, Integer projectId, Integer groupId, MultipartFile multipartFile, HttpServletRequest request) throws Exception {
|
|
|
HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
|
|
//首先先搞到公司id
|
|
@@ -394,6 +394,13 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
User creator = userMapper.selectById(userId);
|
|
|
Integer companyId = creator.getCompanyId();
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id",companyId));
|
|
|
+ List<Project> allProjectList = null;
|
|
|
+ List<TaskGroup> allGroupList = null;
|
|
|
+ if (isMultiProject == 1) {
|
|
|
+ allProjectList = projectMapper.selectList(new QueryWrapper<Project>().select("id, project_code, project_name").eq("company_id", companyId));
|
|
|
+ //全部任务分组
|
|
|
+ allGroupList = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().select("id, name, project_id").in("project_id", allProjectList.stream().map(Project::getId).collect(Collectors.toList())));
|
|
|
+ }
|
|
|
List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
HashMap<String, Integer> taskTypeMap = new HashMap<>();
|
|
|
//taskTypeMap.put("任务", 0);
|
|
@@ -433,6 +440,8 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
//要插入的账号列表
|
|
|
List<Task> taskList = new ArrayList<>();
|
|
|
List<String> userNameList=new ArrayList<>();
|
|
|
+ //Excel列下标从1开始
|
|
|
+ int taskListNameIndex = isMultiProject==0?0:3;//项目编号,项目名称,任务分组,任务列表; 在项目内导入时,任务列表作为第一列
|
|
|
for (int rowIndex = 0; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
|
if (row == null) {
|
|
@@ -442,12 +451,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
continue;
|
|
|
}
|
|
|
System.out.println("rowIndex==="+rowIndex);
|
|
|
- XSSFCell nameCell = row.getCell(1);
|
|
|
+ XSSFCell nameCell = row.getCell(taskListNameIndex+1);
|
|
|
if (nameCell == null) {
|
|
|
break;
|
|
|
}
|
|
|
System.out.println("name==="+nameCell.getStringCellValue());
|
|
|
- XSSFCell executorCell = row.getCell(3);
|
|
|
+ XSSFCell executorCell = row.getCell(taskListNameIndex + 3);
|
|
|
if (executorCell != null) {
|
|
|
String[] executorNameArray = executorCell.getStringCellValue().split(",");
|
|
|
for (String s : executorNameArray) {
|
|
@@ -478,34 +487,95 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
if (row == null) {
|
|
|
continue;
|
|
|
}
|
|
|
- //此处新建账号 默认密码为000000 默认 姓名第一列 手机号第二列 月薪第三列
|
|
|
- XSSFCell stagesCell = row.getCell(0);
|
|
|
- XSSFCell nameCell = row.getCell(1);
|
|
|
+
|
|
|
+ XSSFCell stagesCell = row.getCell(taskListNameIndex);
|
|
|
+ XSSFCell nameCell = row.getCell(taskListNameIndex + 1);
|
|
|
if (nameCell == null || stagesCell == null) {
|
|
|
break;
|
|
|
}
|
|
|
- XSSFCell typeCell = row.getCell(2);
|
|
|
- XSSFCell executorCell = row.getCell(3);
|
|
|
- XSSFCell levelCell = row.getCell(4);
|
|
|
- XSSFCell startDateCell = row.getCell(5);
|
|
|
- XSSFCell endDateCell = row.getCell(6);
|
|
|
- XSSFCell planHoursCell = row.getCell(7);
|
|
|
- XSSFCell descCell = row.getCell(8);
|
|
|
+ XSSFCell typeCell = row.getCell(taskListNameIndex + 2);
|
|
|
+ XSSFCell executorCell = row.getCell(taskListNameIndex + 3);
|
|
|
+ XSSFCell levelCell = row.getCell(taskListNameIndex + 4);
|
|
|
+ XSSFCell startDateCell = row.getCell(taskListNameIndex + 5);
|
|
|
+ XSSFCell endDateCell = row.getCell(taskListNameIndex + 6);
|
|
|
+ XSSFCell planHoursCell = row.getCell(taskListNameIndex + 7);
|
|
|
+ XSSFCell descCell = row.getCell(taskListNameIndex + 8);
|
|
|
nameCell.setCellType(CellType.STRING);
|
|
|
stagesCell.setCellType(CellType.STRING);
|
|
|
- typeCell.setCellType(CellType.STRING);
|
|
|
- endDateCell.setCellType(CellType.NUMERIC);
|
|
|
+
|
|
|
+ String type = "任务";//默认类型
|
|
|
+ if (typeCell != null) {
|
|
|
+ typeCell.setCellType(CellType.STRING);
|
|
|
+ type = typeCell.getStringCellValue();
|
|
|
+ }
|
|
|
+ if (endDateCell != null) {
|
|
|
+ endDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
if(planHoursCell!=null){
|
|
|
planHoursCell.setCellType(CellType.STRING);
|
|
|
}
|
|
|
String name = nameCell.getStringCellValue();
|
|
|
- String type = typeCell.getStringCellValue();
|
|
|
+
|
|
|
//忽略表头
|
|
|
if ((name.equals("任务内容") || name.equals("Task content")) && (type.equals("类型") || type.equals("type")) && rowIndex == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
Task task = new Task();
|
|
|
task.setCompanyId(companyId);
|
|
|
+ //多项目下任务导入和单项目下任务导入,两种模式的taskListNameIndex值不一样
|
|
|
+ String projectCode = null;
|
|
|
+ String projectName = null;
|
|
|
+ String taskGroupName = null;
|
|
|
+ //设置所属项目和任务分组ID
|
|
|
+ if (isMultiProject == 1) {
|
|
|
+ XSSFCell codeCell = row.getCell(0);
|
|
|
+ XSSFCell pnameCell = row.getCell(1);
|
|
|
+ XSSFCell tgoupNameCell = row.getCell(2);
|
|
|
+ if (codeCell != null) {
|
|
|
+ codeCell.setCellType(CellType.STRING);
|
|
|
+ projectCode = codeCell.getStringCellValue().trim();
|
|
|
+ }
|
|
|
+ if (pnameCell != null) {
|
|
|
+ pnameCell.setCellType(CellType.STRING);
|
|
|
+ projectName = pnameCell.getStringCellValue().trim();
|
|
|
+ }
|
|
|
+ if (tgoupNameCell != null) {
|
|
|
+ tgoupNameCell.setCellType(CellType.STRING);
|
|
|
+ taskGroupName = tgoupNameCell.getStringCellValue().trim();
|
|
|
+ }
|
|
|
+
|
|
|
+ //定位项目
|
|
|
+ projectId = null;
|
|
|
+ if (!StringUtil.isEmpty(projectCode)) {
|
|
|
+ final String code = projectCode;
|
|
|
+ Optional<Project> first = allProjectList.stream().filter(project -> code.equals(project.getProjectCode())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ projectId = first.get().getId();
|
|
|
+ }
|
|
|
+ } else if (!StringUtil.isEmpty(projectName)) {
|
|
|
+ final String pname = projectName;
|
|
|
+ Optional<Project> first = allProjectList.stream().filter(project -> pname.equals(project.getProjectName())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ projectId = first.get().getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (projectId == null) {
|
|
|
+ throw new Exception("项目不存在:(编号:"+projectCode+",名称:"+projectName+")");
|
|
|
+ }
|
|
|
+ //任务分组
|
|
|
+ groupId = null;//先清空
|
|
|
+ if (!StringUtil.isEmpty(taskGroupName)) {
|
|
|
+ final String groupName = taskGroupName;
|
|
|
+ final int pid = projectId;
|
|
|
+ Optional<TaskGroup> first = allGroupList.stream().filter(group -> groupName.equals(group.getName()) && group.getProjectId().equals(pid)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ groupId = first.get().getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (groupId == null) {
|
|
|
+ throw new Exception("任务分组不存在:"+taskGroupName);
|
|
|
+ }
|
|
|
+ }
|
|
|
task.setProjectId(projectId);
|
|
|
task.setGroupId(groupId);
|
|
|
if(executorCell!=null){
|
|
@@ -606,29 +676,12 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
|
for (List<TaskExecutor> executorList : executorListAll) {
|
|
|
taskExecutorService.saveBatch(executorList);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- //最后删掉这个文件
|
|
|
-// if (!file.delete()) {
|
|
|
-// System.out.println("临时文件" + file.getName() + "删除失败");
|
|
|
-// }
|
|
|
- //校验是否有重复账号
|
|
|
-
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
//httpRespMsg.setError("文件处理出错");
|
|
|
httpRespMsg.setError(MessageUtils.message("file.error"));
|
|
|
return httpRespMsg;
|
|
|
- } catch (NullPointerException e) {
|
|
|
- e.printStackTrace();
|
|
|
- //httpRespMsg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
- httpRespMsg.setError(MessageUtils.message("file.dataFormatError"));
|
|
|
- return httpRespMsg;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- //httpRespMsg.setError("发生其他错误");
|
|
|
- httpRespMsg.setError(MessageUtils.message("other.error"));
|
|
|
- return httpRespMsg;
|
|
|
} finally {
|
|
|
//关闭流
|
|
|
try {
|