|
@@ -12,18 +12,27 @@ import com.management.platform.service.ProjectService;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.ListUtil;
|
|
|
+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.assertj.core.util.Lists;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.servlet.http.Part;
|
|
|
+import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -43,6 +52,9 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements ProjectService {
|
|
|
+ String pathPrefix = "/upload/";
|
|
|
+ @Resource
|
|
|
+ private ProjectService projectService;
|
|
|
@Resource
|
|
|
private ProjectMapper projectMapper;
|
|
|
@Resource
|
|
@@ -58,6 +70,8 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
@Resource
|
|
|
private EarningSnapshotMapper earningSnapshotMapper;
|
|
|
@Resource
|
|
|
+ private ExpenseItemMapper expenseItemMapper;
|
|
|
+ @Resource
|
|
|
private TimeTypeMapper timeTypeMapper;
|
|
|
@Resource
|
|
|
private HttpServletResponse response;
|
|
@@ -172,7 +186,10 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
httpRespMsg.setError("请填写项目名称");
|
|
|
} else {
|
|
|
//检查项目编号不能重复
|
|
|
- Integer count = projectMapper.selectCount(new QueryWrapper<Project>().eq("company_id", companyId).eq("project_code", code));
|
|
|
+ Integer count = 0;
|
|
|
+ if (!StringUtils.isEmpty(code)) {
|
|
|
+ count = projectMapper.selectCount(new QueryWrapper<Project>().eq("company_id", companyId).eq("project_code", code));
|
|
|
+ }
|
|
|
if (count > 0) {
|
|
|
httpRespMsg.setError("提交失败:项目编号已存在");
|
|
|
} else {
|
|
@@ -349,7 +366,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
List<String> headList = new ArrayList<String>();
|
|
|
headList.add("项目");
|
|
|
headList.add("人员");
|
|
|
- headList.add("时间(h)");
|
|
|
+ headList.add("工时(h)");
|
|
|
headList.add("成本(元)");
|
|
|
List<List<String>> allList = new ArrayList<List<String>>();
|
|
|
allList.add(headList);
|
|
@@ -533,6 +550,7 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//获取某个项目每个人分别需要的工时
|
|
|
@Override
|
|
|
public HttpRespMsg getProjectCost(String startDate, String endDate, Integer projectId, HttpServletRequest request) {
|
|
@@ -595,4 +613,391 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> impl
|
|
|
}
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportProfit(HttpServletRequest request) {
|
|
|
+ String userId = request.getHeader("TOKEN");
|
|
|
+ Integer companyId = userMapper.selectById(userId).getCompanyId();
|
|
|
+ List<Project> projectList = projectMapper.selectList(new QueryWrapper<Project>().eq("company_id", companyId));
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportProject(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ //通过公司id获取该公司所有的项目列表
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ //判断用户的角色,如果是管理员和负责人,查看全部的。如果是普通员工,只能是看到参与的项目
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<Project> projectList = projectMapper.selectList(queryWrapper);
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ List<ProjectVO> list = new ArrayList<>();
|
|
|
+ String[] statusNames = {"-","进行中","已完成","已撤销"};
|
|
|
+ List<List<String>> exportList = new ArrayList<>();
|
|
|
+ String[] titles = {"项目编号", "项目名称", "负责人", "项目金额(元)", "状态","计划开始时间", "计划结束时间", "完成度"};
|
|
|
+ exportList.add(Lists.list(titles));
|
|
|
+ for (Project project : projectList) {
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(project.getProjectCode() == null?"":project.getProjectCode());
|
|
|
+ data.add(project.getProjectName() == null?"":project.getProjectName());
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getId().equals(project.getInchargerId())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ User incharger = first.get();
|
|
|
+ data.add(incharger.getName());
|
|
|
+ } else {
|
|
|
+ data.add("");
|
|
|
+ }
|
|
|
+ if (project.getContractAmount() != null) {
|
|
|
+ data.add(project.getContractAmount().doubleValue()+"");
|
|
|
+ }
|
|
|
+ data.add(project.getStatus()==null?"":statusNames[project.getStatus()]);
|
|
|
+ data.add(project.getPlanStartDate() != null?df.format(project.getPlanStartDate()):"");
|
|
|
+ data.add(project.getPlanEndDate() != null?df.format(project.getPlanEndDate()):"");
|
|
|
+ data.add(project.getProgress() != null?project.getProgress()+"%" :"");
|
|
|
+ exportList.add(data);
|
|
|
+ }
|
|
|
+ String fileName = "项目报表_"+System.currentTimeMillis();
|
|
|
+ ExcelUtil.exportGeneralExcelByTitleAndList(fileName, exportList, path);
|
|
|
+ httpRespMsg.data = pathPrefix + fileName+".xls";
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getProjectTask(Integer pageIndex, Integer pageSize, HttpServletRequest request) {
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ int total = taskMapper.getProjectTaskCount(companyId);
|
|
|
+ int pageStart = (pageIndex -1) * pageSize;
|
|
|
+ System.out.println("companyId="+companyId+", pageStart="+pageStart+", pageSize="+pageSize);
|
|
|
+ List projectTask = taskMapper.getProjectTask(companyId, pageStart, pageSize);
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("records", projectTask);
|
|
|
+ map.put("total", total);
|
|
|
+ httpRespMsg.data = map;
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportProjectTask(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<Map> projectList = taskMapper.getProjectTask(companyId, null, null);
|
|
|
+ List<ProjectVO> list = new ArrayList<>();
|
|
|
+ String[] statusNames = {"进行中","已完成","已撤销"};
|
|
|
+ String[] typeList = {"任务","里程碑","风险"};
|
|
|
+ List<List<String>> exportList = new ArrayList<>();
|
|
|
+ String[] titles = {"项目编号", "项目名称", "任务名称", "计划工时(h)", "实际工时(h)","状态", "类型", "截止日期"};
|
|
|
+ exportList.add(Lists.list(titles));
|
|
|
+ for (Map task : projectList) {
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(task.get("project_code") == null?"":task.get("project_code").toString());
|
|
|
+ data.add(task.get("project_name") == null?"":task.get("project_name").toString());
|
|
|
+ data.add(task.get("name") != null?task.get("name").toString():"");
|
|
|
+ data.add(task.get("plan_hours") != null?task.get("plan_hours").toString():"");
|
|
|
+ data.add(task.get("real_hours").toString());
|
|
|
+ data.add(task.get("task_status")==null?"":statusNames[Integer.parseInt(task.get("task_status").toString())]);
|
|
|
+ data.add(typeList[Integer.parseInt(task.get("task_type").toString())]);
|
|
|
+ data.add(task.get("end_date") != null? task.get("end_date").toString():"");
|
|
|
+ exportList.add(data);
|
|
|
+ }
|
|
|
+ String fileName = "项目任务报表_"+System.currentTimeMillis();
|
|
|
+ ExcelUtil.exportGeneralExcelByTitleAndList(fileName, exportList, path);
|
|
|
+ httpRespMsg.data = pathPrefix + fileName+".xls";
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getAllProjectCost(Integer pageIndex, Integer pageSize, HttpServletRequest request) {
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ //撤销的项目不算
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ queryWrapper.and(wrapper->wrapper.isNull("status").or().ne("status", 3));
|
|
|
+ int total = projectMapper.selectCount(queryWrapper);
|
|
|
+ int pageStart = (pageIndex -1) * pageSize;
|
|
|
+ System.out.println("companyId="+companyId+", pageStart="+pageStart+", pageSize="+pageSize);
|
|
|
+ List projectTask = projectMapper.getAllProjectCost(companyId, pageStart, pageSize);
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("records", projectTask);
|
|
|
+ map.put("total", total);
|
|
|
+ httpRespMsg.data = map;
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportAllProjectCost(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ //通过公司id获取该公司所有的项目列表
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ List<Project> projectList = projectMapper.getAllProjectCost(companyId, null, null);
|
|
|
+ List<List<String>> exportList = new ArrayList<>();
|
|
|
+ String[] titles = {"项目编号", "项目名称", "人工成本", "一般费用", "差旅费用","外包费用", "总费用"};
|
|
|
+ exportList.add(Lists.list(titles));
|
|
|
+ for (Project project : projectList) {
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(project.getProjectCode());
|
|
|
+ data.add(project.getProjectName());
|
|
|
+ data.add(project.getFeeMan().toString());
|
|
|
+ data.add(project.getFeeNormal().toString());
|
|
|
+ data.add(project.getFeeTravel().toString());
|
|
|
+ data.add(project.getFeeOutsourcing().toString());
|
|
|
+ double totalFee = project.getFeeMan() + project.getFeeNormal()+ project.getFeeTravel()+ project.getFeeOutsourcing();
|
|
|
+ data.add(totalFee+"");
|
|
|
+ exportList.add(data);
|
|
|
+ }
|
|
|
+ String fileName = "项目成本报表_"+System.currentTimeMillis();
|
|
|
+ ExcelUtil.exportGeneralExcelByTitleAndList(fileName, exportList, path);
|
|
|
+ httpRespMsg.data = pathPrefix + fileName+".xls";
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getProjectInAndOut(Integer pageIndex, Integer pageSize, HttpServletRequest request) {
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+ //撤销的项目不算
|
|
|
+ //撤销的项目不算
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ queryWrapper.and(wrapper->wrapper.isNull("status").or().ne("status", 3));
|
|
|
+ int total = projectMapper.selectCount(queryWrapper);
|
|
|
+ int pageStart = (pageIndex -1) * pageSize;
|
|
|
+ System.out.println("companyId="+companyId+", pageStart="+pageStart+", pageSize="+pageSize);
|
|
|
+ List projectTask = projectMapper.getProjectInAndOut(companyId, pageStart, pageSize);
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("records", projectTask);
|
|
|
+ map.put("total", total);
|
|
|
+ httpRespMsg.data = map;
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportProjectInAndOut(HttpServletRequest request) {
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
+ //通过公司id获取该公司所有的项目列表
|
|
|
+ User user = userMapper.selectById(request.getHeader("Token"));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+
|
|
|
+ QueryWrapper<Project> queryWrapper = new QueryWrapper<Project>().eq("company_id", companyId);
|
|
|
+ List<Project> projectList = projectMapper.getProjectInAndOut(companyId, null, null);
|
|
|
+ List<List<String>> exportList = new ArrayList<>();
|
|
|
+ String[] titles = {"项目编号", "项目名称", "合同金额", "人工成本", "一般费用", "差旅费用","外包费用", "总费用", "利润", "利润率"};
|
|
|
+ exportList.add(Lists.list(titles));
|
|
|
+ for (Project project : projectList) {
|
|
|
+ List<String> data = new ArrayList<>();
|
|
|
+ data.add(project.getProjectCode());
|
|
|
+ data.add(project.getProjectName());
|
|
|
+ data.add(project.getContractAmount() != null?project.getContractAmount().toString():"");
|
|
|
+ data.add(project.getFeeMan().toString());
|
|
|
+ data.add(project.getFeeNormal().toString());
|
|
|
+ data.add(project.getFeeTravel().toString());
|
|
|
+ data.add(project.getFeeOutsourcing().toString());
|
|
|
+ double totalFee = project.getFeeMan() + project.getFeeNormal()+ project.getFeeTravel()+ project.getFeeOutsourcing();
|
|
|
+ data.add(totalFee+"");
|
|
|
+ if (project.getContractAmount() != null && project.getContractAmount() > 0) {
|
|
|
+ double profitAmt = project.getContractAmount() - totalFee;
|
|
|
+ data.add(profitAmt+"");
|
|
|
+ data.add(new java.text.DecimalFormat("#.0").format((100*profitAmt/project.getContractAmount()))+"%");
|
|
|
+ } else {
|
|
|
+ double profitAmt = -totalFee;
|
|
|
+ data.add(profitAmt+"");
|
|
|
+ data.add("");
|
|
|
+ }
|
|
|
+ exportList.add(data);
|
|
|
+ }
|
|
|
+ String fileName = "项目收支平衡报表(利润表)_"+System.currentTimeMillis();
|
|
|
+ ExcelUtil.exportGeneralExcelByTitleAndList(fileName, exportList, path);
|
|
|
+ httpRespMsg.data = pathPrefix + fileName+".xls";
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importData(String userId, MultipartFile multipartFile, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ //然后处理文件
|
|
|
+ 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);
|
|
|
+ //获取全部人员
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<Project> projectList = new ArrayList<Project>();
|
|
|
+ //由于第一行需要指明列对应的标题
|
|
|
+ int rowNum = sheet.getLastRowNum();
|
|
|
+
|
|
|
+ HashMap<String, Integer> projectLevelMap = new HashMap<>();
|
|
|
+ projectLevelMap.put("正常", 1);
|
|
|
+ projectLevelMap.put("紧急", 2);
|
|
|
+ projectLevelMap.put("重要", 3);
|
|
|
+ projectLevelMap.put("重要且紧急", 4);
|
|
|
+ for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
|
|
|
+ XSSFRow row = sheet.getRow(rowIndex);
|
|
|
+ if (row == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //跳过空行
|
|
|
+ if (ExcelUtil.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ System.out.println("当前行="+rowIndex);
|
|
|
+ //项目编号 项目名称 参与人 负责人 级别 开始日期 截止日期 合同金额
|
|
|
+ XSSFCell codeCell = row.getCell(0);
|
|
|
+ XSSFCell nameCell = row.getCell(1);
|
|
|
+ XSSFCell participatorCell = row.getCell(2);
|
|
|
+ XSSFCell inchargerCell = row.getCell(3);
|
|
|
+ XSSFCell levelCell = row.getCell(4);
|
|
|
+ XSSFCell startDateCell = row.getCell(5);
|
|
|
+ XSSFCell endDateCell = row.getCell(6);
|
|
|
+ XSSFCell amountCell = row.getCell(7);
|
|
|
+
|
|
|
+
|
|
|
+ if (codeCell != null)codeCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell != null)nameCell.setCellType(CellType.STRING);
|
|
|
+ if (participatorCell != null)participatorCell.setCellType(CellType.STRING);
|
|
|
+ if (inchargerCell != null)inchargerCell.setCellType(CellType.STRING);
|
|
|
+ if (levelCell != null)levelCell.setCellType(CellType.STRING);
|
|
|
+ if (startDateCell != null)startDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ if (endDateCell != null)endDateCell.setCellType(CellType.NUMERIC);
|
|
|
+ if (amountCell != null)amountCell.setCellType(CellType.STRING);
|
|
|
+ if (nameCell == null) {//项目名称为空的直接跳过
|
|
|
+ throw new Exception("项目名称不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Project project = new Project();
|
|
|
+ if (codeCell != null) {
|
|
|
+ String code = codeCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ if (code.equals("项目编号") && rowIndex == 0) {
|
|
|
+ //跳过第一行标题
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //检查编号是否已经存在
|
|
|
+ if (!StringUtils.isEmpty(code)) {
|
|
|
+ int cnt = projectMapper.selectCount(new QueryWrapper<Project>().eq("project_code", code).eq("company_id", user.getCompanyId()));
|
|
|
+ if (cnt > 0) {
|
|
|
+ throw new Exception("项目编码存在重复: " + code);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ project.setProjectCode(code);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String name = nameCell.getStringCellValue().trim().replaceAll("\\u00a0", "");
|
|
|
+ project.setCompanyId(user.getCompanyId());
|
|
|
+ project.setCreatorId(userId);
|
|
|
+ project.setCreatorName(user.getName());
|
|
|
+ project.setProjectName(name);
|
|
|
+ //处理人员
|
|
|
+ if (inchargerCell != null) {
|
|
|
+ String inchargerName = inchargerCell.getStringCellValue();
|
|
|
+ if (!StringUtils.isEmpty(inchargerName)) {
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(inchargerName)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ project.setInchargerId(first.get().getId());
|
|
|
+ project.setInchargerName(inchargerName);
|
|
|
+ } else {
|
|
|
+ throw new Exception("项目负责人["+inchargerName+"]不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (levelCell != null) {
|
|
|
+ String levelStr = levelCell.getStringCellValue();
|
|
|
+ if (!StringUtils.isEmpty(levelStr)) {
|
|
|
+ project.setLevel(projectLevelMap.get(levelStr));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (startDateCell !=null && !StringUtils.isEmpty(startDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanStartDate(LocalDate.parse(sdf.format(startDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (endDateCell !=null && !StringUtils.isEmpty(endDateCell.getDateCellValue())) {
|
|
|
+ project.setPlanEndDate(LocalDate.parse(sdf.format(endDateCell.getDateCellValue()), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ }
|
|
|
+ if (amountCell !=null && !StringUtils.isEmpty(amountCell.getStringCellValue())) {
|
|
|
+ project.setContractAmount(Integer.parseInt(amountCell.getStringCellValue()));
|
|
|
+ }
|
|
|
+
|
|
|
+ projectMapper.insert(project);
|
|
|
+ //参与人
|
|
|
+ if (participatorCell != null) {
|
|
|
+ String part = participatorCell.getStringCellValue();
|
|
|
+ if (!StringUtils.isEmpty(part)) {
|
|
|
+ String[] split = part.split(",");
|
|
|
+ for (String str : split) {
|
|
|
+ Participation p = new Participation();
|
|
|
+ Optional<User> first = userList.stream().filter(u -> u.getName().equals(str)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ p.setUserId(first.get().getId());
|
|
|
+ p.setProjectId(project.getId());
|
|
|
+ participationMapper.insert(p);
|
|
|
+ } else {
|
|
|
+ projectMapper.deleteById(project.getId());
|
|
|
+ throw new Exception("参与人["+str+"]不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //批量插入
|
|
|
+ //projectService.saveOrUpdateBatch(projectList);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg.setError("文件处理出错");
|
|
|
+ return msg;
|
|
|
+ } catch (NullPointerException 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;
|
|
|
+ }
|
|
|
}
|