|
@@ -1,21 +1,42 @@
|
|
package com.nokia.financeapi.service.house;
|
|
package com.nokia.financeapi.service.house;
|
|
|
|
|
|
import com.nokia.financeapi.common.R;
|
|
import com.nokia.financeapi.common.R;
|
|
|
|
+import com.nokia.financeapi.config.ImportHouseDataConfig;
|
|
import com.nokia.financeapi.dao.house.HouseReportDao;
|
|
import com.nokia.financeapi.dao.house.HouseReportDao;
|
|
import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
|
|
import com.nokia.financeapi.pojo.dto.GetHouseReportDto;
|
|
|
|
+import com.nokia.financeapi.pojo.dto.ImportHouseDataDto;
|
|
import com.nokia.financeapi.pojo.po.house.HouseReportsPo;
|
|
import com.nokia.financeapi.pojo.po.house.HouseReportsPo;
|
|
import com.nokia.financeapi.pojo.vo.GetHouseReportVo;
|
|
import com.nokia.financeapi.pojo.vo.GetHouseReportVo;
|
|
|
|
+import com.nokia.financeapi.pojo.vo.GetHouseTemplatesVo;
|
|
import com.nokia.financeapi.service.common.file.FileService;
|
|
import com.nokia.financeapi.service.common.file.FileService;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class HouseReportService {
|
|
public class HouseReportService {
|
|
private final FileService fileService;
|
|
private final FileService fileService;
|
|
private final HouseReportDao houseReportDao;
|
|
private final HouseReportDao houseReportDao;
|
|
|
|
+ private final ImportHouseDataConfig importHouseDataConfig;
|
|
|
|
|
|
- public HouseReportService(FileService fileService, HouseReportDao houseReportDao) {
|
|
|
|
|
|
+ public HouseReportService(FileService fileService, HouseReportDao houseReportDao,
|
|
|
|
+ ImportHouseDataConfig importHouseDataConfig) {
|
|
this.fileService = fileService;
|
|
this.fileService = fileService;
|
|
this.houseReportDao = houseReportDao;
|
|
this.houseReportDao = houseReportDao;
|
|
|
|
+ this.importHouseDataConfig = importHouseDataConfig;
|
|
}
|
|
}
|
|
|
|
|
|
public R<GetHouseReportVo> getReportWord(GetHouseReportDto dto) {
|
|
public R<GetHouseReportVo> getReportWord(GetHouseReportDto dto) {
|
|
@@ -48,4 +69,79 @@ public class HouseReportService {
|
|
vo.setUrl(url);
|
|
vo.setUrl(url);
|
|
return R.ok(vo);
|
|
return R.ok(vo);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public R<List<GetHouseTemplatesVo>> getTemplates() {
|
|
|
|
+ List<GetHouseTemplatesVo> vos = new ArrayList<>();
|
|
|
|
+ GetHouseTemplatesVo wxys = new GetHouseTemplatesVo();
|
|
|
|
+ wxys.setId("wxys");
|
|
|
|
+ wxys.setName("维修费用预算(第二年预算)");
|
|
|
|
+ wxys.setUrl(fileService.getBucket() + "/" + "oss/public/template/house/wxys.xlsx");
|
|
|
|
+ vos.add(wxys);
|
|
|
|
+ GetHouseTemplatesVo czys = new GetHouseTemplatesVo();
|
|
|
|
+ czys.setId("czys");
|
|
|
|
+ czys.setName("对外出租费用预算(第二年预算)");
|
|
|
|
+ czys.setUrl(fileService.getBucket() + "/" + "oss/public/template/house/czys.xlsx");
|
|
|
|
+ vos.add(czys);
|
|
|
|
+ return R.ok(vos);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public R<Object> importData(ImportHouseDataDto dto, MultipartFile file) {
|
|
|
|
+ if ("wxys".equals(dto.getId())) {
|
|
|
|
+ return importWxys(dto, file);
|
|
|
|
+ }
|
|
|
|
+ if ("czys".equals(dto.getId())) {
|
|
|
|
+ return importCzys(dto, file);
|
|
|
|
+ }
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized R<Object> importWxys(ImportHouseDataDto dto, MultipartFile file) {
|
|
|
|
+ try {
|
|
|
|
+ Files.createDirectories(Paths.get(importHouseDataConfig.getWxys()));
|
|
|
|
+ File fileNew = new File(importHouseDataConfig.getWxys() + dto.getYear() + ".xlsx");
|
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), fileNew);
|
|
|
|
+ try(InputStream inputStream = Files.newInputStream(fileNew.toPath());
|
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream)
|
|
|
|
+ ) {
|
|
|
|
+ // 读取第一个工作表
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
+ // 表头行
|
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
|
+ // 列数
|
|
|
|
+ int columnCount = headerRow.getPhysicalNumberOfCells();
|
|
|
|
+ if (5 != columnCount) {
|
|
|
|
+ return R.error("列数和模板不一致");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ return R.error("导入失败");
|
|
|
|
+ }
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public synchronized R<Object> importCzys(ImportHouseDataDto dto, MultipartFile file) {
|
|
|
|
+ try {
|
|
|
|
+ Files.createDirectories(Paths.get(importHouseDataConfig.getCzys()));
|
|
|
|
+ File fileNew = new File(importHouseDataConfig.getCzys() + dto.getYear() + ".xlsx");
|
|
|
|
+ FileUtils.copyInputStreamToFile(file.getInputStream(), fileNew);
|
|
|
|
+ try(InputStream inputStream = Files.newInputStream(fileNew.toPath());
|
|
|
|
+ Workbook workbook = new XSSFWorkbook(inputStream)
|
|
|
|
+ ) {
|
|
|
|
+ // 读取第一个工作表
|
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
+ // 表头行
|
|
|
|
+ Row headerRow = sheet.getRow(0);
|
|
|
|
+ // 列数
|
|
|
|
+ int columnCount = headerRow.getPhysicalNumberOfCells();
|
|
|
|
+ if (5 != columnCount) {
|
|
|
|
+ return R.error("列数和模板不一致");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
|
+ return R.error("导入失败");
|
|
|
|
+ }
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
}
|
|
}
|