|
|
@ -17,25 +17,37 @@ import com.hnac.hzims.operational.access.service.IOperAccessLibraryDetailService |
|
|
|
import com.hnac.hzims.operational.access.service.IOperAccessLibraryService; |
|
|
|
import com.hnac.hzims.operational.access.service.IOperAccessLibraryService; |
|
|
|
import com.hnac.hzims.operational.access.vo.OperAccessLibraryVO; |
|
|
|
import com.hnac.hzims.operational.access.vo.OperAccessLibraryVO; |
|
|
|
import com.hnac.hzims.operational.access.wrapper.OperAccessLibraryWrapper; |
|
|
|
import com.hnac.hzims.operational.access.wrapper.OperAccessLibraryWrapper; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.util.ExcelUtil; |
|
|
|
|
|
|
|
import com.hnac.hzims.operational.util.PdfUtils; |
|
|
|
import com.hnac.hzims.safeproduct.feign.IDangerSourceClient; |
|
|
|
import com.hnac.hzims.safeproduct.feign.IDangerSourceClient; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.jfree.chart.util.ExportUtils; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
import org.springblade.core.tool.utils.CollectionUtil; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
|
|
|
|
import org.springblade.system.cache.DictCache; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
|
|
|
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
|
|
|
|
|
|
|
import org.springframework.core.io.support.ResourcePatternResolver; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.RequestContextHolder; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.*; |
|
|
|
import java.io.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.List; |
|
|
|
import java.nio.file.Files; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -99,10 +111,92 @@ public class OperAccessLibraryServiceImpl extends BaseServiceImpl<OperAccessLibr |
|
|
|
* . |
|
|
|
* . |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void downLoad() { |
|
|
|
public void downLoad(){ |
|
|
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
|
|
ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
|
|
|
HttpServletResponse response = servletRequestAttributes.getResponse(); |
|
|
|
HttpServletResponse response = servletRequestAttributes.getResponse(); |
|
|
|
|
|
|
|
response.setContentType("application/vnd.ms-excel"); |
|
|
|
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); |
|
|
|
|
|
|
|
InputStream inputStream = null; |
|
|
|
|
|
|
|
// 获取输入流,原始模板位置
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
Resource[] resources = resolver.getResources("template/excel/access_import_template.xlsx"); |
|
|
|
|
|
|
|
inputStream = resources[0].getInputStream(); |
|
|
|
|
|
|
|
//假如以中文名下载的话,设置下载文件名称
|
|
|
|
|
|
|
|
String filename = "检修导入模板.xlsx"; |
|
|
|
|
|
|
|
//转码,免得文件名中文乱码
|
|
|
|
|
|
|
|
filename = URLEncoder.encode(filename,"UTF-8"); |
|
|
|
|
|
|
|
//设置文件下载头
|
|
|
|
|
|
|
|
response.addHeader("Content-Disposition", "attachment;filename=" + filename); |
|
|
|
|
|
|
|
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); |
|
|
|
|
|
|
|
int len = 0; |
|
|
|
|
|
|
|
while((len = inputStream.read()) != -1){ |
|
|
|
|
|
|
|
out.write(len); |
|
|
|
|
|
|
|
out.flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
out.close(); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
throw new ServiceException("检修导入模板下载失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 检修库导入 |
|
|
|
|
|
|
|
* @param multipartFile |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void libraryImport(MultipartFile multipartFile){ |
|
|
|
|
|
|
|
// 文件名检查
|
|
|
|
|
|
|
|
String fileName = multipartFile.getOriginalFilename(); |
|
|
|
|
|
|
|
if(!fileName.endsWith(PdfUtils.XLS_SUFFIX) && !fileName.endsWith(PdfUtils.XLSX_SUFFIX)){ |
|
|
|
|
|
|
|
throw new ServiceException("导入文件类型错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Workbook workbook = null ; |
|
|
|
|
|
|
|
try{ |
|
|
|
|
|
|
|
workbook = new HSSFWorkbook(multipartFile.getInputStream()); |
|
|
|
|
|
|
|
}catch (IOException ioException){ |
|
|
|
|
|
|
|
throw new ServiceException("导入文件读取失败!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 读取sheet页
|
|
|
|
|
|
|
|
Sheet sheet = workbook.getSheet("Sheet1"); |
|
|
|
|
|
|
|
// 获取行数
|
|
|
|
|
|
|
|
int rows = sheet.getLastRowNum(); |
|
|
|
|
|
|
|
if(rows==0){ |
|
|
|
|
|
|
|
throw new ServiceException("请填写导入检修库数据!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<OperAccessLibraryDetailEntity> details = new ArrayList<>(); |
|
|
|
|
|
|
|
Long libraryId = null; |
|
|
|
|
|
|
|
for (int i = 2; i <= rows + 1; i++) { |
|
|
|
|
|
|
|
// 读取左上端单元格
|
|
|
|
|
|
|
|
Row row = sheet.getRow(i); |
|
|
|
|
|
|
|
// 行不为空
|
|
|
|
|
|
|
|
if (row == null) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if( (i - 1) % 4 == 1){ |
|
|
|
|
|
|
|
if(StringUtils.isEmpty(row.getCell(1).getStringCellValue())){ |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
OperAccessLibraryEntity library = new OperAccessLibraryEntity(); |
|
|
|
|
|
|
|
library.setEmName(row.getCell(1).getStringCellValue()); |
|
|
|
|
|
|
|
library.setGradeCode(DictCache.getValue("gradeCode",row.getCell(2).getStringCellValue())); |
|
|
|
|
|
|
|
library.setLastServiceTime(row.getCell(3).getDateCellValue()); |
|
|
|
|
|
|
|
library.setPeriod((int)row.getCell(4).getNumericCellValue()); |
|
|
|
|
|
|
|
library.setStopHours((int)row.getCell(5).getNumericCellValue()); |
|
|
|
|
|
|
|
this.save(library); |
|
|
|
|
|
|
|
libraryId = library.getId(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(StringUtils.isNotEmpty(row.getCell(6).getStringCellValue())){ |
|
|
|
|
|
|
|
OperAccessLibraryDetailEntity detail = new OperAccessLibraryDetailEntity(); |
|
|
|
|
|
|
|
detail.setName(row.getCell(6).getStringCellValue()); |
|
|
|
|
|
|
|
detail.setContent(row.getCell(7).getStringCellValue()); |
|
|
|
|
|
|
|
detail.setPid(libraryId); |
|
|
|
|
|
|
|
details.add(detail); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.libraryDetailService.saveBatch(details); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|