|
@@ -2,26 +2,35 @@ package com.management.platform.controller;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
-import com.management.platform.constant.Constant;
|
|
|
|
-import com.management.platform.entity.*;
|
|
|
|
|
|
+import com.management.platform.entity.Project;
|
|
|
|
+import com.management.platform.entity.ProjectRequirement;
|
|
|
|
+import com.management.platform.entity.TaskGroup;
|
|
import com.management.platform.mapper.ProjectMapper;
|
|
import com.management.platform.mapper.ProjectMapper;
|
|
import com.management.platform.mapper.ProjectRequirementMapper;
|
|
import com.management.platform.mapper.ProjectRequirementMapper;
|
|
import com.management.platform.mapper.TaskGroupMapper;
|
|
import com.management.platform.mapper.TaskGroupMapper;
|
|
import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.mapper.UserMapper;
|
|
import com.management.platform.service.ProjectRequirementService;
|
|
import com.management.platform.service.ProjectRequirementService;
|
|
|
|
+import com.management.platform.util.ExcelUtil;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import org.apache.poi.EncryptedDocumentException;
|
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
-
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.io.*;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.HashMap;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -35,6 +44,8 @@ import java.util.stream.Collectors;
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/project-requirement")
|
|
@RequestMapping("/project-requirement")
|
|
public class ProjectRequirementController {
|
|
public class ProjectRequirementController {
|
|
|
|
+ @Value(value = "${upload.path}")
|
|
|
|
+ private String path;
|
|
@Resource
|
|
@Resource
|
|
private HttpServletRequest request;
|
|
private HttpServletRequest request;
|
|
@Resource
|
|
@Resource
|
|
@@ -65,16 +76,19 @@ public class ProjectRequirementController {
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
int startIndex = (pageIndex-1)*pageSize;
|
|
int startIndex = (pageIndex-1)*pageSize;
|
|
- long total = projectMapper.selectCount(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
|
LocalDate now = LocalDate.now();
|
|
LocalDate now = LocalDate.now();
|
|
now = now.minusDays(7);
|
|
now = now.minusDays(7);
|
|
String startDate = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
|
|
String startDate = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
|
|
List<Integer> projectIds = new ArrayList<>();
|
|
List<Integer> projectIds = new ArrayList<>();
|
|
|
|
+ long total;
|
|
if (!StringUtils.isEmpty(groupName)) {
|
|
if (!StringUtils.isEmpty(groupName)) {
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
List<Integer> collect = projectList.stream().map(Project::getId).collect(Collectors.toList());
|
|
List<Integer> collect = projectList.stream().map(Project::getId).collect(Collectors.toList());
|
|
List<TaskGroup> taskGroups = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().eq("name", groupName).in("project_id", collect));
|
|
List<TaskGroup> taskGroups = taskGroupMapper.selectList(new QueryWrapper<TaskGroup>().eq("name", groupName).in("project_id", collect));
|
|
projectIds = taskGroups.stream().map(TaskGroup::getProjectId).collect(Collectors.toList());
|
|
projectIds = taskGroups.stream().map(TaskGroup::getProjectId).collect(Collectors.toList());
|
|
|
|
+ total=projectIds.size();
|
|
|
|
+ }else{
|
|
|
|
+ total = projectMapper.selectCount(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
}
|
|
}
|
|
List<ProjectRequirement> projectRequirements = projectRequirementMapper.customSelect(companyId, startDate, projectId, projectIds.size()==0?null:projectIds, startIndex, pageSize);
|
|
List<ProjectRequirement> projectRequirements = projectRequirementMapper.customSelect(companyId, startDate, projectId, projectIds.size()==0?null:projectIds, startIndex, pageSize);
|
|
HashMap map = new HashMap();
|
|
HashMap map = new HashMap();
|
|
@@ -84,6 +98,139 @@ public class ProjectRequirementController {
|
|
|
|
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
+ @RequestMapping("/exportData")
|
|
|
|
+ public HttpRespMsg exportData(){
|
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
|
+ now = now.minusDays(7);
|
|
|
|
+ String startDate = DateTimeFormatter.ofPattern("yyyy-MM-dd").format(now);
|
|
|
|
+ List<ProjectRequirement> projectRequirementList = projectRequirementMapper.customSelect(companyId,startDate, null, null, null, null);
|
|
|
|
+ List<List<String>> dataList=new ArrayList<>();
|
|
|
|
+ String[] titleString={"项目编号","项目名称","近七日活跃人员","人员需求","任务需求"};
|
|
|
|
+ List<String> nameList = Arrays.asList(titleString);
|
|
|
|
+ dataList.add(nameList);
|
|
|
|
+ projectRequirementList.forEach(pr->{
|
|
|
|
+ List<String> resultData=new ArrayList<>();
|
|
|
|
+ resultData.add(pr.getProjectCode());
|
|
|
|
+ resultData.add(pr.getProjectName());
|
|
|
|
+ resultData.add(pr.getActiveUsers());
|
|
|
|
+ resultData.add(pr.getMembReq());
|
|
|
|
+ resultData.add(pr.getTaskReq());
|
|
|
|
+ dataList.add(resultData);
|
|
|
|
+ });
|
|
|
|
+ //生成excel文件导出
|
|
|
|
+ String fileName = "资源需求统计报表_"+System.currentTimeMillis();
|
|
|
|
+ String resp = ExcelUtil.exportGeneralExcelByTitleAndList(fileName , dataList, path);
|
|
|
|
+ httpRespMsg.data=resp;
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ @RequestMapping("/importData")
|
|
|
|
+ public HttpRespMsg importData(MultipartFile multipartFile){
|
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
|
+ //然后处理文件
|
|
|
|
+ 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);
|
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
|
+ List<ProjectRequirement> projectRequirementList = projectRequirementMapper.selectList(null);
|
|
|
|
+ List<ProjectRequirement> projectRequirements=new ArrayList<>();
|
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
|
+ if (row == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //跳过空行
|
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //项目编号 任务需求 人员需求
|
|
|
|
+ XSSFCell codeCell = row.getCell(0);
|
|
|
|
+ XSSFCell nameCell = row.getCell(1);
|
|
|
|
+ XSSFCell taskReqCell = row.getCell(2);
|
|
|
|
+ XSSFCell membReqCell = row.getCell(3);
|
|
|
|
+ if(nameCell==null&&codeCell==null){
|
|
|
|
+ throw new Exception("项目编号以及名称不能同时不存在");
|
|
|
|
+ }
|
|
|
|
+ if (codeCell != null)codeCell.setCellType(CellType.STRING);
|
|
|
|
+ if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
|
+ if (taskReqCell != null)taskReqCell.setCellType(CellType.STRING);
|
|
|
|
+ if (membReqCell != null)membReqCell.setCellType(CellType.STRING);
|
|
|
|
+ ProjectRequirement projectRequirement=new ProjectRequirement();
|
|
|
|
+ List<Project> list = projectList.stream().filter(project ->
|
|
|
|
+ (StringUtils.isEmpty(project.getProjectCode())?"":project.getProjectCode()).equals(codeCell.getStringCellValue())
|
|
|
|
+ || (StringUtils.isEmpty(project.getProjectName())?"":project.getProjectName()).equals(nameCell.getStringCellValue())
|
|
|
|
+ ).collect(Collectors.toList());
|
|
|
|
+ if(StringUtils.isEmpty(list)){
|
|
|
|
+ msg.setError("项目编号/名称"+codeCell.getStringCellValue()+"/"+nameCell.getStringCellValue()+"不存在");
|
|
|
|
+ }else{
|
|
|
|
+ list.forEach(li->{
|
|
|
|
+ projectRequirement.setProjectId(li.getId());
|
|
|
|
+ projectRequirement.setTaskReq(StringUtils.isEmpty(taskReqCell.getStringCellValue())?"":taskReqCell.getStringCellValue());
|
|
|
|
+ projectRequirement.setMembReq(StringUtils.isEmpty(membReqCell.getStringCellValue())?"":membReqCell.getStringCellValue());
|
|
|
|
+ boolean flag = projectRequirementList.stream().anyMatch(pr -> pr.getProjectId().equals(li.getId()));
|
|
|
|
+ if(flag){
|
|
|
|
+ Optional<ProjectRequirement> first = projectRequirementList.stream().filter(pr -> pr.getProjectId().equals(li.getId())).findFirst();
|
|
|
|
+ projectRequirement.setId(first.get().getId());
|
|
|
|
+ }
|
|
|
|
+ projectRequirements.add(projectRequirement);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ projectRequirementService.saveOrUpdateBatch(projectRequirements);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("文件处理出错");
|
|
|
|
+ return msg;
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
|
+ return msg;
|
|
|
|
+ }catch (InvalidFormatException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
|
+ }catch (EncryptedDocumentException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("文件加密状态,需要先解除加密状态再上传");
|
|
|
|
+ return msg;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("上传失败:"+e.getMessage());
|
|
|
|
+ return msg;
|
|
|
|
+ } finally {
|
|
|
|
+ //关闭流
|
|
|
|
+ try {
|
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
|
+ outputStream.close();
|
|
|
|
+ inputStream.close();
|
|
|
|
+ System.out.println("流已关闭");
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+// file.deleteOnExit();//程序退出时删除临时文件
|
|
|
|
+ System.out.println(file.delete());
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
|
|
@RequestMapping("/delete")
|
|
@RequestMapping("/delete")
|
|
public HttpRespMsg delete(Integer id) {
|
|
public HttpRespMsg delete(Integer id) {
|