|
@@ -104,6 +104,15 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
private TaskCommentMapper taskCommentMapper;
|
|
private TaskCommentMapper taskCommentMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private InformationMapper informationMapper;
|
|
private InformationMapper informationMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private TaskTypeMapper taskTypeMapper;
|
|
|
|
+ @Resource
|
|
|
|
+ CustomerInfoMapper customerInfoMapper;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private InformationService informationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ReportExtraDegreeMapper reportExtraDegreeMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
public HttpRespMsg getExecutorPanel(Integer projectId) {
|
|
@@ -581,6 +590,308 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public HttpRespMsg importTaskNew(Integer isMultiProject, Integer projectId, Integer groupId, MultipartFile multipartFile, HttpServletRequest request) throws Exception {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ //首先先搞到公司id
|
|
|
|
+ String userId = request.getHeader("Token");
|
|
|
|
+ User creator = userMapper.selectById(userId);
|
|
|
|
+ Integer companyId = creator.getCompanyId();
|
|
|
|
+ List<Project> allProjectList = null;
|
|
|
|
+ List<TaskGroup> allGroupList = null;
|
|
|
|
+ List<Stages> stagesList =new ArrayList<>();
|
|
|
|
+ if (isMultiProject == 1) {
|
|
|
|
+ allProjectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
|
+ //全部任务分组
|
|
|
|
+ allGroupList = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().in("project_id", allProjectList.stream().map(Project::getId).collect(Collectors.toList())));
|
|
|
|
+
|
|
|
|
+ stagesList = stagesMapper.selectList(new QueryWrapper<Stages>().in("group_id", allGroupList.stream().map(TaskGroup::getId).collect(Collectors.toList())));
|
|
|
|
+ }
|
|
|
|
+ List<User> allUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
+ //类型
|
|
|
|
+ List<TaskType> taskTypeList = taskTypeMapper.selectList(new QueryWrapper<TaskType>().eq("company_id", companyId));
|
|
|
|
+
|
|
|
|
+ List<ReportExtraDegree> customerInfoList = reportExtraDegreeMapper.getAll(companyId);
|
|
|
|
+ List<Department> departmentList = departmentService.list(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+
|
|
|
|
+ //然后处理文件
|
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
+ OutputStream outputStream = null;
|
|
|
|
+ try {
|
|
|
|
+ inputStream = multipartFile.getInputStream();
|
|
|
|
+ outputStream = new FileOutputStream(file);
|
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
|
+ int temp = 0;
|
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
|
+ }
|
|
|
|
+ inputStream.close();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ //然后解析表格
|
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
|
+ //我们只需要第一个sheet
|
|
|
|
+ XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
|
+
|
|
|
|
+ HttpRespMsg respMsg=new HttpRespMsg();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
|
+ System.out.println("lastRowNum==>"+lastRowNum);
|
|
|
|
+ for (int rowIndex = 1; rowIndex <= sheet.getLastRowNum(); rowIndex++) {
|
|
|
|
+ ArrayList<TaskExecutor> taskExecutors = new ArrayList<>();
|
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
|
+ Task task = new Task();
|
|
|
|
+ if (row == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ for (int i = 0; i < 5; i++) {
|
|
|
|
+ XSSFCell cell = row.getCell(0);
|
|
|
|
+ if (cell!=null) {
|
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ XSSFCell typeCell = row.getCell(0);
|
|
|
|
+ if (typeCell == null||StringUtils.isEmpty(typeCell.getStringCellValue())) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,类型为空");
|
|
|
|
+ }else {
|
|
|
|
+ Optional<TaskType> first = taskTypeList.stream().filter(t -> t.getName().equals(typeCell.getStringCellValue())).findFirst();
|
|
|
|
+ if (first.isPresent()){
|
|
|
|
+ task.setTaskPlanType(first.get().getId());
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,类型填写有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //类型不为请假
|
|
|
|
+ if (task.getTaskPlanType()!=3){
|
|
|
|
+ XSSFCell projectCell = row.getCell(1);
|
|
|
|
+ if (projectCell == null||StringUtils.isEmpty(projectCell.getStringCellValue())) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,项目为空");
|
|
|
|
+ }else {
|
|
|
|
+ Optional<Project> first = allProjectList.stream().filter(t -> t.getProjectName().equals(projectCell.getStringCellValue())).findFirst();
|
|
|
|
+ if (first.isPresent()){
|
|
|
|
+ task.setProjectId(first.get().getId());
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,项目名称填写有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell researchCell = row.getCell(2);//研究中心
|
|
|
|
+ if (researchCell != null||StringUtils.isNotEmpty(researchCell.getStringCellValue())) {
|
|
|
|
+ Optional<ReportExtraDegree> first = customerInfoList.stream().filter(c -> c.getName().equals(researchCell.getStringCellValue().trim())).findFirst();
|
|
|
|
+ if (first.isPresent()){
|
|
|
|
+ task.setCenterId(first.get().getId());
|
|
|
|
+ task.setCenterName(first.get().getName());
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,研究中心填写有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell taskGroupCell = row.getCell(3);//所属任务分组
|
|
|
|
+ if (taskGroupCell == null||StringUtils.isEmpty(taskGroupCell.getStringCellValue())) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,任务分组为空");
|
|
|
|
+ }else {
|
|
|
|
+ Optional<TaskGroup> first = allGroupList.stream().filter(t -> t.getProjectId().equals(task.getProjectId())&&t.getName().equals(taskGroupCell.getStringCellValue())).findFirst();
|
|
|
|
+ if (first.isPresent()){
|
|
|
|
+ task.setGroupId(first.get().getId());
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,任务分组填写有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell taskStageCell = row.getCell(4);//所属任务列表
|
|
|
|
+ if (taskStageCell == null||StringUtils.isEmpty(taskStageCell.getStringCellValue())) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,任务列表为空");
|
|
|
|
+ }else {
|
|
|
|
+ Optional<Stages> first = stagesList.stream().filter(t -> t.getGroupId().equals(task.getGroupId())&&t.getStagesName().equals(taskStageCell.getStringCellValue())).findFirst();
|
|
|
|
+ if (first.isPresent()){
|
|
|
|
+ task.setStagesId(first.get().getId());
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,任务列表填写有误");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell taskContentCell = row.getCell(5);//任务内容
|
|
|
|
+ if (taskContentCell == null||StringUtils.isEmpty(taskContentCell.getStringCellValue())) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,任务内容为空");
|
|
|
|
+ }else {
|
|
|
|
+ task.setName(taskContentCell.getStringCellValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell planHoursCell = row.getCell(9);//计划工时
|
|
|
|
+ if(planHoursCell!=null){
|
|
|
|
+ planHoursCell.setCellType(CellType.STRING);
|
|
|
|
+ task.setPlanHours(Integer.parseInt(planHoursCell.getStringCellValue()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell priorityCell = row.getCell(10);//优先级
|
|
|
|
+ if(priorityCell!=null){
|
|
|
|
+ priorityCell.setCellType(CellType.STRING);
|
|
|
|
+ String stringCellValue = priorityCell.getStringCellValue();
|
|
|
|
+ if(StringUtils.isNotEmpty(stringCellValue)){
|
|
|
|
+ switch (stringCellValue){
|
|
|
|
+ case "一般":
|
|
|
|
+ task.setTaskLevel(0);
|
|
|
|
+ break;
|
|
|
|
+ case "重要":
|
|
|
|
+ task.setTaskLevel(1);
|
|
|
|
+ break;
|
|
|
|
+ case "紧急":
|
|
|
|
+ task.setTaskLevel(2);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ task.setTaskLevel(0);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ task.setTaskLevel(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell descCell = row.getCell(11);//详细描述
|
|
|
|
+ if(descCell!=null){
|
|
|
|
+ descCell.setCellType(CellType.STRING);
|
|
|
|
+ String stringCellValue = descCell.getStringCellValue();
|
|
|
|
+ task.setTaskDesc(stringCellValue);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ XSSFCell startDateCell = row.getCell(6);//开始时间
|
|
|
|
+ if (startDateCell != null) {
|
|
|
|
+ startDateCell.setCellType(CellType.NUMERIC);
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,开始时间为空");
|
|
|
|
+ }
|
|
|
|
+ if(startDateCell.getDateCellValue() != null){
|
|
|
|
+ Date dateCellValue = startDateCell.getDateCellValue();
|
|
|
|
+ System.out.println("开始日期=="+dateCellValue.toString());
|
|
|
|
+ String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
|
|
|
|
+ LocalDateTime startDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ task.setStartDate(startDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell endDateCell = row.getCell(7);//结束时间
|
|
|
|
+ if (endDateCell != null) {
|
|
|
|
+ endDateCell.setCellType(CellType.NUMERIC);
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,截止时间为空");
|
|
|
|
+ }
|
|
|
|
+ if(endDateCell.getDateCellValue() != null){
|
|
|
|
+ Date dateCellValue = endDateCell.getDateCellValue();
|
|
|
|
+ System.out.println("开始日期=="+dateCellValue.toString());
|
|
|
|
+ String formatValue = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dateCellValue);
|
|
|
|
+ LocalDateTime endDate = LocalDateTime.parse(formatValue, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
+ task.setEndDate(endDate);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ XSSFCell executorCell = row.getCell(8);//执行人
|
|
|
|
+ if (executorCell!=null){
|
|
|
|
+ executorCell.setCellType(CellType.STRING);
|
|
|
|
+ if (executorCell.getStringCellValue().isEmpty()){
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,执行人为空");
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,执行人为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ task.setCompanyId(companyId);
|
|
|
|
+ task.setCreaterId(userId);
|
|
|
|
+ task.setCreaterName(creator.getName());
|
|
|
|
+ task.setCreatorColor(creator.getColor());
|
|
|
|
+ task.setCreateDate(LocalDate.now());
|
|
|
|
+ task.setIndate(LocalDateTime.now());
|
|
|
|
+ taskMapper.insert(task);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ executorCell.setCellType(CellType.STRING);
|
|
|
|
+ String executorStr = executorCell.getStringCellValue();
|
|
|
|
+
|
|
|
|
+ String[] strings = executorStr.split(",");
|
|
|
|
+
|
|
|
|
+ StringJoiner exectorIds = new StringJoiner(",");
|
|
|
|
+ StringJoiner exectorColors = new StringJoiner(",");
|
|
|
|
+ for (int i = 0; i < strings.length; i++) {
|
|
|
|
+ TaskExecutor taskExecutor = new TaskExecutor();
|
|
|
|
+ String string = strings[i];
|
|
|
|
+ Optional<User> first = allUserList.stream().filter(u -> u.getName().equals(string)).findFirst();
|
|
|
|
+ if (!first.isPresent()) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,执行人填写有误");
|
|
|
|
+ }
|
|
|
|
+ taskExecutor.setTaskId(task.getId());
|
|
|
|
+ User user = first.get();
|
|
|
|
+ taskExecutor.setExecutorId(user.getId());
|
|
|
|
+ taskExecutor.setExecutorName(user.getName());
|
|
|
|
+ taskExecutor.setExecutorColor(user.getColor());
|
|
|
|
+ taskExecutor.setPlanHours(task.getPlanHours());
|
|
|
|
+ taskExecutor.setProjectId(task.getProjectId());
|
|
|
|
+
|
|
|
|
+ Integer count = taskMapper.getUserConflitTaskCount(user.getId(), task.getId(), task.getStartDate(), task.getEndDate());
|
|
|
|
+ if (count > 0) {
|
|
|
|
+ throw new Exception("第"+(rowIndex+1)+"行,执行人"+user.getName()+"在其他任务上有时间冲突");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(task.getProjectId())).findFirst();
|
|
|
|
+ projectFirst.ifPresent(project -> taskExecutor.setFirstAuditorId(project.getInchargerId()));
|
|
|
|
+ Optional<Department> departmentOptional = departmentList.stream().filter(t -> t.getDepartmentId().equals(user.getDepartmentId())).findFirst();
|
|
|
|
+ departmentOptional.ifPresent(department -> taskExecutor.setSecondAuditorId(department.getManagerId()));
|
|
|
|
+ taskExecutor.setAuditStatus(TaskController.STATUS_FIRST_CHECK);
|
|
|
|
+ taskExecutors.add(taskExecutor);
|
|
|
|
+
|
|
|
|
+ exectorIds.add(user.getId());
|
|
|
|
+ exectorColors.add(user.getColor());
|
|
|
|
+ }
|
|
|
|
+ task.setExecutorName(executorStr);
|
|
|
|
+ task.setExecutorId(exectorIds.toString());
|
|
|
|
+ task.setExecutorColor(exectorColors.toString());
|
|
|
|
+
|
|
|
|
+ taskMapper.updateById(task);
|
|
|
|
+ taskExecutorService.saveBatch(taskExecutors);
|
|
|
|
+
|
|
|
|
+ //给第一审核人发送信息提醒
|
|
|
|
+ log.info("添加工作计划,给第一审核人发送信息提醒");
|
|
|
|
+ Optional<Project> projectFirst = allProjectList.stream().filter(t -> t.getId().equals(task.getProjectId())).findFirst();
|
|
|
|
+ if (projectFirst.isPresent()) {
|
|
|
|
+ Project project = projectFirst.get();
|
|
|
|
+ Information information = new Information();
|
|
|
|
+ information.setMsg(project.getProjectName()+"项目有新的预计FTE计划审批任务,请您查收.");
|
|
|
|
+ information.setTaskId(task.getId());
|
|
|
|
+ information.setType(11);
|
|
|
|
+ information.setTime(LocalDateTime.now());
|
|
|
|
+ Optional<User> first = allUserList.stream().filter(u -> u.getId().equals(project.getInchargerId())).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ User owner = first.get();
|
|
|
|
+ information.setUserId(owner.getId());
|
|
|
|
+ }
|
|
|
|
+ informationService.save(information);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ //httpRespMsg.setError("文件处理出错");
|
|
|
|
+ httpRespMsg.setError(MessageUtils.message("file.error"));
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ } finally {
|
|
|
|
+ //关闭流
|
|
|
|
+ try {
|
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
|
+ outputStream.close();
|
|
|
|
+ inputStream.close();
|
|
|
|
+ System.out.println("流已关闭");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ System.out.println(file.delete());
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public HttpRespMsg delete(TaskGroup item) {
|
|
public HttpRespMsg delete(TaskGroup item) {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|