|
@@ -1,25 +1,31 @@
|
|
|
package com.migao.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.migao.config.constant.ExamineStatus;
|
|
|
import com.migao.config.constant.FinancesStatus;
|
|
|
import com.migao.config.constant.ProjectStatus;
|
|
|
+import com.migao.config.constant.SystemConstant;
|
|
|
+import com.migao.config.listener.ExcelListener;
|
|
|
+import com.migao.config.properties.SystemProperties;
|
|
|
import com.migao.config.response.PageBean;
|
|
|
import com.migao.config.response.ResponseBean;
|
|
|
import com.migao.config.response.ResponseBuilder;
|
|
|
+import com.migao.entity.po.FileInfo;
|
|
|
import com.migao.entity.po.Milestone;
|
|
|
import com.migao.entity.po.Project;
|
|
|
import com.migao.entity.vo.req.*;
|
|
|
import com.migao.entity.vo.res.DictionaryListRes;
|
|
|
import com.migao.entity.vo.res.ProjectQueryRes;
|
|
|
-import com.migao.mapper.DictionaryMapper;
|
|
|
-import com.migao.mapper.MilestoneMapper;
|
|
|
-import com.migao.mapper.ProjectMapper;
|
|
|
-import com.migao.mapper.ProjectRepository;
|
|
|
+import com.migao.mapper.*;
|
|
|
import com.migao.service.ProjectService;
|
|
|
import com.migao.util.EntityUtils;
|
|
|
+import com.migao.util.FileUtils;
|
|
|
import com.migao.util.ProjectNoUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -28,8 +34,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.validation.constraints.NotEmpty;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
public class ProjectServiceImpl implements ProjectService {
|
|
@@ -43,7 +52,10 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
private DictionaryMapper dictionaryMapper;
|
|
|
@Resource
|
|
|
private MilestoneMapper milestoneMapper;
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private FileInfoRepository fileInfoRepository;
|
|
|
+ @Resource
|
|
|
+ private SystemProperties systemProperties;
|
|
|
|
|
|
/**
|
|
|
* 增
|
|
@@ -70,7 +82,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseBean<PageBean<ProjectQueryRes>> pageQuery(ProjectPageQueryReq projectPageQueryReq) {
|
|
|
- //1。分页查询所有供公司
|
|
|
+ //返回储备状态为拒绝/待审批
|
|
|
Integer page = projectPageQueryReq.getPage();
|
|
|
page = page == null ? 1 : page <= 0 ? 1 : page;
|
|
|
Integer size = projectPageQueryReq.getSize();
|
|
@@ -84,7 +96,7 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
if (StringUtils.isNotBlank(projectPageQueryReq.getOrderStatus())) {
|
|
|
queryWrapper.eq(Project::getOrderStatus, projectPageQueryReq.getOrderStatus());
|
|
|
}
|
|
|
- queryWrapper.eq(Project::getReserveStatus, ProjectStatus.TO_APPROVAL.getName());
|
|
|
+ queryWrapper.eq(Project::getReserveStatus, ProjectStatus.TO_APPROVAL.getName()).or().eq(Project::getReserveStatus, ProjectStatus.REJECT.getName());
|
|
|
Page<Project> all = projectMapper.selectPage(new Page<>(page, size), queryWrapper);
|
|
|
return ResponseBuilder.ok(
|
|
|
all,
|
|
@@ -96,8 +108,6 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
.content(element.getContent())
|
|
|
.cost(String.valueOf(element.getCost()))
|
|
|
.createTime(element.getCreateTime())
|
|
|
- .createUserId(element.getCreateUserId())
|
|
|
- .deleted(element.getDeleted())
|
|
|
.level(element.getLevel())
|
|
|
.name(element.getName())
|
|
|
.progress(element.getProgress())
|
|
@@ -203,7 +213,6 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
ResponseBuilder.fail("项目不存在");
|
|
|
}
|
|
|
if (status.equals(FinancesStatus.PASS)){
|
|
|
- project.setOrderStatus(ProjectStatus.RESERVES_ISSUED.getName());
|
|
|
project.setReserveStatus(ProjectStatus.APPROVE.getName());
|
|
|
projectMapper.updateById(project);
|
|
|
}else {
|
|
@@ -215,13 +224,52 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public ResponseBean<?> importData(String fileId) {
|
|
|
- return null;
|
|
|
+ public ResponseBean<?> importData(Integer fileId) {
|
|
|
+
|
|
|
+ //1.读取文件
|
|
|
+ List<ImportProjectReq> list = new ArrayList<>();
|
|
|
+ Optional<FileInfo> byId =
|
|
|
+ fileInfoRepository.findById(fileId);
|
|
|
+ byId.ifPresent(
|
|
|
+ fileInfo -> {
|
|
|
+ EasyExcel.read(
|
|
|
+ fileInfo.getDiskPath(),
|
|
|
+ ImportProjectReq.class,
|
|
|
+ new ExcelListener<>(list)
|
|
|
+ ).sheet().doRead();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ log.info("读取结果:{}", list.size());
|
|
|
+ //去除重复数据
|
|
|
+ list.forEach(
|
|
|
+ data -> {
|
|
|
+ Project project = EntityUtils.copyProperties(data, Project.class);
|
|
|
+ projectMapper.insert(project);
|
|
|
+ }
|
|
|
+ );
|
|
|
+ //手动提交
|
|
|
+ log.info("保存项目储备数量:{}", list.size());
|
|
|
+ return ResponseBuilder.ok(list.size());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ResponseBean<?> export(ProjectPageQueryReq projectPageQueryReq) {
|
|
|
- return null;
|
|
|
+ List<ProjectQueryRes> data = pageQuery(projectPageQueryReq).getData().getRow();
|
|
|
+ String fileName = StringUtils.join(
|
|
|
+ FileUtils.getFileNo(), SystemConstant.EXCEL_SUFFIX
|
|
|
+ );
|
|
|
+ String filePath = StringUtils.join(
|
|
|
+ systemProperties.getFileStoreDirPath(), fileName
|
|
|
+ );
|
|
|
+ String fileUrl = StringUtils.join(
|
|
|
+ systemProperties.getDownloadPrefix(), fileName
|
|
|
+ );
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(filePath, ProjectQueryRes.class).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet("项目储备数据").build();
|
|
|
+ excelWriter.write(data, writeSheet);
|
|
|
+ //关闭流
|
|
|
+ excelWriter.finish();
|
|
|
+ return ResponseBuilder.ok(fileUrl);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -252,8 +300,6 @@ public class ProjectServiceImpl implements ProjectService {
|
|
|
.content(element.getContent())
|
|
|
.cost(String.valueOf(element.getCost()))
|
|
|
.createTime(element.getCreateTime())
|
|
|
- .createUserId(element.getCreateUserId())
|
|
|
- .deleted(element.getDeleted())
|
|
|
.level(element.getLevel())
|
|
|
.name(element.getName())
|
|
|
.progress(element.getProgress())
|