导出Excel表格
This commit is contained in:
parent
3dd86a12bf
commit
1e6c1143da
@ -42,7 +42,7 @@ public class QcSourceController {
|
||||
/**
|
||||
* 导出Excel表格
|
||||
*/
|
||||
@GetMapping("/exportExcel")
|
||||
@PostMapping("/exportExcel")
|
||||
public String exportExcel(@RequestBody ExportExcelQo exportExcelQo) throws Exception {
|
||||
return qcSourceService.exportExcel(exportExcelQo);
|
||||
}
|
||||
|
@ -15,7 +15,10 @@ import java.util.Map;
|
||||
@Component
|
||||
public interface QcSourceDao extends JpaRepository<QcSourceEntity, Integer>, JpaSpecificationExecutor<QcSourceEntity> {
|
||||
|
||||
@Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% AND craft_item_no LIKE %?6% ORDER BY create_time DESC", nativeQuery = true)
|
||||
@Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% ORDER BY create_time DESC", nativeQuery = true)
|
||||
List<Map<String, Object>> queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo);
|
||||
|
||||
@Query(value = "SELECT id, batch_no AS batchNo, machine_no AS machineNo, material_no AS materialNo, mould_no AS mouldNo, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, qc_value AS qcValue FROM qc_source WHERE batch_no LIKE %?1% AND machine_no LIKE %?2% AND material_no LIKE %?3% AND mould_no LIKE %?4% AND variety_no LIKE %?5% AND craft_item_no = ?6 ORDER BY create_time DESC", nativeQuery = true)
|
||||
List<Map<String, Object>> queryQcSource(String batchNo, String machineNo, String materialNo, String mouldNo, String varietyNo, String craftItemNo);
|
||||
|
||||
}
|
@ -27,6 +27,12 @@ public interface QcSpecDao extends JpaRepository<QcSpecEntity, Integer>, JpaSpec
|
||||
/**
|
||||
* 查询检验规格
|
||||
*/
|
||||
@Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND craft_item_no LIKE %?2% AND qc_item_no LIKE %?3% ORDER BY create_time ASC", nativeQuery = true)
|
||||
@Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND qc_item_no LIKE %?2% ORDER BY create_time ASC", nativeQuery = true)
|
||||
List<Map<String, Object>> queryQcSpec(String varietyNo, String qcItemNo);
|
||||
|
||||
/**
|
||||
* 查询检验规格
|
||||
*/
|
||||
@Query(value = "SELECT id, variety_no AS varietyNo, craft_item_no AS craftItemNo, qc_item_no AS qcItemNo, max, mean, min, unit, method, standard, remark FROM qc_spec WHERE variety_no LIKE %?1% AND craft_item_no = ?2 AND qc_item_no LIKE %?3% ORDER BY create_time ASC", nativeQuery = true)
|
||||
List<Map<String, Object>> queryQcSpec(String varietyNo, String craftItemNo, String qcItemNo);
|
||||
}
|
@ -3,11 +3,8 @@ package com.xkrs.service.impl;
|
||||
import com.xkrs.dao.FileDao;
|
||||
import com.xkrs.dao.QcSourceDao;
|
||||
import com.xkrs.encapsulation.PromptMessageEnum;
|
||||
import com.xkrs.model.entity.FileEntity;
|
||||
import com.xkrs.model.qo.FileQo;
|
||||
import com.xkrs.service.FileService;
|
||||
import com.xkrs.util.ExcelUploadUtil;
|
||||
import com.xkrs.util.ExportExcel;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -16,7 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import javax.annotation.Resource;
|
||||
import javax.transaction.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.Locale;
|
||||
|
||||
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
||||
|
||||
@ -41,29 +38,29 @@ public class FileServiceImpl implements FileService {
|
||||
*/
|
||||
@Override
|
||||
public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException {
|
||||
String lotNo = fileQo.getLotNo();
|
||||
String machineNo = fileQo.getMachineNo();
|
||||
String materialNo = fileQo.getMaterialNo();
|
||||
String modelNo = fileQo.getModelNo();
|
||||
String machineTypeNo = fileQo.getMachineTypeNo();
|
||||
String craftItemName = fileQo.getCraftItemName();
|
||||
// String lotNo = fileQo.getLotNo();
|
||||
// String machineNo = fileQo.getMachineNo();
|
||||
// String materialNo = fileQo.getMaterialNo();
|
||||
// String modelNo = fileQo.getModelNo();
|
||||
// String machineTypeNo = fileQo.getMachineTypeNo();
|
||||
// String craftItemName = fileQo.getCraftItemName();
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
|
||||
if (fileEntity.isPresent()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale);
|
||||
}
|
||||
if (fileExcel == null) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale);
|
||||
}
|
||||
String file = ExcelUploadUtil.memoryFile(fileExcel, 1);
|
||||
FileEntity fileEntity1 = new FileEntity();
|
||||
fileEntity1.setLotNo(fileQo.getLotNo());
|
||||
fileEntity1.setMachineNo(fileQo.getMachineNo());
|
||||
fileEntity1.setMaterialNo(fileQo.getMaterialNo());
|
||||
fileEntity1.setModelNo(fileQo.getModelNo());
|
||||
fileEntity1.setMachineTypeNo(fileQo.getMachineTypeNo());
|
||||
fileEntity1.setFileUploadPath(file);
|
||||
fileDao.save(fileEntity1);
|
||||
// Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
|
||||
// if (fileEntity.isPresent()) {
|
||||
// return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale);
|
||||
// }
|
||||
// if (fileExcel == null) {
|
||||
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale);
|
||||
// }
|
||||
// String file = ExcelUploadUtil.memoryFile(fileExcel, 1);
|
||||
// FileEntity fileEntity1 = new FileEntity();
|
||||
// fileEntity1.setLotNo(fileQo.getLotNo());
|
||||
// fileEntity1.setMachineNo(fileQo.getMachineNo());
|
||||
// fileEntity1.setMaterialNo(fileQo.getMaterialNo());
|
||||
// fileEntity1.setModelNo(fileQo.getModelNo());
|
||||
// fileEntity1.setMachineTypeNo(fileQo.getMachineTypeNo());
|
||||
// fileEntity1.setFileUploadPath(file);
|
||||
// fileDao.save(fileEntity1);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
|
||||
}
|
||||
|
||||
@ -76,28 +73,28 @@ public class FileServiceImpl implements FileService {
|
||||
@Transactional(rollbackOn = Exception.class)
|
||||
@Override
|
||||
public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException {
|
||||
String lotNo = fileQo.getLotNo();
|
||||
String machineNo = fileQo.getMachineNo();
|
||||
String materialNo = fileQo.getMaterialNo();
|
||||
String modelNo = fileQo.getModelNo();
|
||||
String machineTypeNo = fileQo.getMachineTypeNo();
|
||||
String craftItemName = fileQo.getCraftItemName();
|
||||
// String lotNo = fileQo.getLotNo();
|
||||
// String machineNo = fileQo.getMachineNo();
|
||||
// String materialNo = fileQo.getMaterialNo();
|
||||
// String modelNo = fileQo.getModelNo();
|
||||
// String machineTypeNo = fileQo.getMachineTypeNo();
|
||||
// String craftItemName = fileQo.getCraftItemName();
|
||||
Locale locale = LocaleContextHolder.getLocale();
|
||||
Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
|
||||
if (fileEntity.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
|
||||
}
|
||||
String fileUploadPath = fileEntity.get().getFileUploadPath();
|
||||
List<Map<String, Object>> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, "");
|
||||
if (resultList == null || resultList.size() == 0) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale);
|
||||
}
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (Map<String, Object> result : resultList) {
|
||||
map.put((String) result.get("qcItemNo"), (String) result.get("qcValue"));
|
||||
}
|
||||
String fill = ExportExcel.exportToProveExcel(map, fileUploadPath);
|
||||
fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale);
|
||||
// Optional<FileEntity> fileEntity = fileDao.selectFile(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
|
||||
// if (fileEntity.isEmpty()) {
|
||||
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
|
||||
// }
|
||||
// String fileUploadPath = fileEntity.get().getFileUploadPath();
|
||||
// List<Map<String, Object>> resultList = qcSourceDao.queryQcSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, "");
|
||||
// if (resultList == null || resultList.size() == 0) {
|
||||
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale);
|
||||
// }
|
||||
// Map<String, String> map = new HashMap<>();
|
||||
// for (Map<String, Object> result : resultList) {
|
||||
// map.put((String) result.get("qcItemNo"), (String) result.get("qcValue"));
|
||||
// }
|
||||
// String fill = ExportExcel.exportToProveExcel(map, fileUploadPath);
|
||||
// fileDao.updateFileDownloadPath(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName, fill);
|
||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "导出成功", locale);
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,17 @@ public class QcSourceServiceImpl implements QcSourceService {
|
||||
if (qcItemList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "未添加检验项目,请先添加检验项目!", locale);
|
||||
}
|
||||
List<Map<String, Object>> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo));
|
||||
String finalBatchNo = LocalStringUtils.formatEmptyValue(batchNo).trim();
|
||||
String finalMachineNo = LocalStringUtils.formatEmptyValue(machineNo).trim();
|
||||
String finalMaterialNo = LocalStringUtils.formatEmptyValue(materialNo).trim();
|
||||
String finalMouldNo = LocalStringUtils.formatEmptyValue(mouldNo).trim();
|
||||
String finalVarietyNo = LocalStringUtils.formatEmptyValue(varietyNo).trim();
|
||||
List<Map<String, Object>> sourceList;
|
||||
if (TextUtils.isEmpty(craftItemNo)) {
|
||||
sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo);
|
||||
} else {
|
||||
sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo, craftItemNo.trim());
|
||||
}
|
||||
List<Map<String, Object>> resultList = generateResultList(sourceList);
|
||||
if (resultList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验数据的信息!", locale);
|
||||
@ -252,11 +262,11 @@ public class QcSourceServiceImpl implements QcSourceService {
|
||||
@Override
|
||||
public String exportExcel(ExportExcelQo exportExcelQo) throws Exception {
|
||||
String host = exportExcelQo.getHost();
|
||||
String batchNo = exportExcelQo.getBatchNo();
|
||||
String machineNo = exportExcelQo.getMachineNo();
|
||||
String materialNo = exportExcelQo.getMaterialNo();
|
||||
String mouldNo = exportExcelQo.getMouldNo();
|
||||
String varietyNo = exportExcelQo.getVarietyNo();
|
||||
String finalBatchNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getBatchNo()).trim();
|
||||
String finalMachineNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMachineNo()).trim();
|
||||
String finalMaterialNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMaterialNo()).trim();
|
||||
String finalMouldNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getMouldNo()).trim();
|
||||
String finalVarietyNo = LocalStringUtils.formatEmptyValue(exportExcelQo.getVarietyNo()).trim();
|
||||
String craftItemNo = exportExcelQo.getCraftItemNo();
|
||||
List<CraftItemEntity> craftItemList = craftItemDao.findAll();
|
||||
if (craftItemList.isEmpty()) {
|
||||
@ -266,7 +276,12 @@ public class QcSourceServiceImpl implements QcSourceService {
|
||||
if (qcItemList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "未添加检验项目,请先添加检验项目!", locale);
|
||||
}
|
||||
List<Map<String, Object>> sourceList = qcSourceDao.queryQcSource(LocalStringUtils.formatEmptyValue(batchNo), LocalStringUtils.formatEmptyValue(machineNo), LocalStringUtils.formatEmptyValue(materialNo), LocalStringUtils.formatEmptyValue(mouldNo), LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo));
|
||||
List<Map<String, Object>> sourceList;
|
||||
if (TextUtils.isEmpty(craftItemNo)) {
|
||||
sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo);
|
||||
} else {
|
||||
sourceList = qcSourceDao.queryQcSource(finalBatchNo, finalMachineNo, finalMaterialNo, finalMouldNo, finalVarietyNo, craftItemNo.trim());
|
||||
}
|
||||
List<Map<String, Object>> resultList = generateResultList(sourceList);
|
||||
String finalHost = host.endsWith("/") ? host : host + "/";
|
||||
List<List<String>> formattedResultList = formatResultList(finalHost, resultList, qcItemList);
|
||||
|
@ -13,6 +13,7 @@ import com.xkrs.model.qo.QcSpecQoUpdate;
|
||||
import com.xkrs.service.QcSpecService;
|
||||
import com.xkrs.util.LocalDateUtils;
|
||||
import com.xkrs.util.LocalStringUtils;
|
||||
import org.apache.http.util.TextUtils;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -132,7 +133,14 @@ public class QcSpecServiceImpl implements QcSpecService {
|
||||
*/
|
||||
@Override
|
||||
public String queryQcSpec(String varietyNo, String craftItemNo, String qcItemNo) {
|
||||
List<Map<String, Object>> resultList = qcSpecDao.queryQcSpec(LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(craftItemNo), LocalStringUtils.formatEmptyValue(qcItemNo));
|
||||
String finalVarietyNo = LocalStringUtils.formatEmptyValue(varietyNo).trim();
|
||||
String finalQcItemNo = LocalStringUtils.formatEmptyValue(qcItemNo).trim();
|
||||
List<Map<String, Object>> resultList;
|
||||
if (TextUtils.isEmpty(craftItemNo)) {
|
||||
resultList = qcSpecDao.queryQcSpec(finalVarietyNo, finalQcItemNo);
|
||||
} else {
|
||||
resultList = qcSpecDao.queryQcSpec(finalVarietyNo, craftItemNo.trim(), finalQcItemNo);
|
||||
}
|
||||
if (resultList == null || resultList.isEmpty()) {
|
||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验规格的信息!", locale);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user