diff --git a/src/main/java/com/xkrs/controller/DataDictController.java b/src/main/java/com/xkrs/controller/DataDictController.java index d4943c1..4744f1d 100644 --- a/src/main/java/com/xkrs/controller/DataDictController.java +++ b/src/main/java/com/xkrs/controller/DataDictController.java @@ -14,6 +14,7 @@ import javax.annotation.Resource; import javax.transaction.Transactional; import java.util.List; import java.util.Locale; +import java.util.Optional; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -68,7 +69,7 @@ public class DataDictController { @GetMapping("/selectDataDictById") public String selectDataDictById(@RequestParam("id") Integer id){ Locale locale = LocaleContextHolder.getLocale(); - DataDict dataDict = dataDictDao.findById(id); + DataDict dataDict = dataDictDao.findById(id).get(); return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale); } diff --git a/src/main/java/com/xkrs/controller/DataSourceController.java b/src/main/java/com/xkrs/controller/DataSourceController.java index 4a36e25..a72e129 100644 --- a/src/main/java/com/xkrs/controller/DataSourceController.java +++ b/src/main/java/com/xkrs/controller/DataSourceController.java @@ -2,6 +2,7 @@ package com.xkrs.controller; import com.xkrs.dao.DataSourceDao; import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.model.entity.DataSource; import com.xkrs.model.qo.DataSourceQo; import com.xkrs.service.DataSourceService; import org.springframework.context.i18n.LocaleContextHolder; @@ -29,46 +30,50 @@ public class DataSourceController { /** * 添加测量数据 + * * @param dataSourceQo * @return */ @PostMapping("/insertDataSource") - public String insertDataSource(@RequestBody DataSourceQo dataSourceQo){ + public String insertDataSource(@RequestBody DataSourceQo dataSourceQo) { return dataSourceService.insertDataSource(dataSourceQo); } /** * 查询某一产品的测量信息 - * @param dataModelNumber - * @param dataBatchNumber - * @param dataMachineCode - * @param productNumber + * @param lotNo 批次号 + * @param machineNo 机器号 + * @param materialNo 物料号 + * @param modelNo 模具号 + * @param partNo 零件号 * @return */ @GetMapping("/selectDataSource") - public String selectDataSource(@RequestParam("dataModelNumber") String dataModelNumber, - @RequestParam("dataBatchNumber") String dataBatchNumber, - @RequestParam("dataMachineCode") String dataMachineCode, - @RequestParam("productNumber") String productNumber){ + public String selectDataSource(@RequestParam("lotNo") String lotNo, + @RequestParam("machineNo") String machineNo, + @RequestParam("materialNo") String materialNo, + @RequestParam("modelNo") String modelNo, + @RequestParam("partNo") String partNo) { Locale locale = LocaleContextHolder.getLocale(); - List> maps = dataSourceDao.selectDataSource(dataModelNumber, dataBatchNumber, dataMachineCode, productNumber); - if(maps == null || maps.size() == 0){ - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的测量信息!",locale); + List dataSources = dataSourceDao.selectDataSource(lotNo, machineNo, materialNo, modelNo, partNo); + if (dataSources == null || dataSources.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale); } /** * 查询全部的测量信息 + * * @return */ @GetMapping("/selectAllSource") - public String selectAllSource(){ + public String selectAllSource() { Locale locale = LocaleContextHolder.getLocale(); - List> maps = dataSourceDao.selectAllSource(); - if(maps == null || maps.size() == 0){ - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的测量信息!",locale); + List dataSources = dataSourceDao.selectAllSource(); + if (dataSources == null || dataSources.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale); } } diff --git a/src/main/java/com/xkrs/controller/FileController.java b/src/main/java/com/xkrs/controller/FileController.java index ff66370..88eda8f 100644 --- a/src/main/java/com/xkrs/controller/FileController.java +++ b/src/main/java/com/xkrs/controller/FileController.java @@ -8,11 +8,13 @@ import com.xkrs.service.FileService; import com.xkrs.util.ExcelUploadUtil; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import javax.transaction.Transactional; import java.io.IOException; import java.util.Locale; @@ -34,6 +36,7 @@ public class FileController { /** * 上传模板信息 + * * @param fileQo * @param fileExcel * @return @@ -41,11 +44,12 @@ public class FileController { */ @PostMapping("/insertFileExcel") public String insertFileExcel(FileQo fileQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { - return fileService.insertFileExcel(fileQo,fileExcel); + return fileService.insertFileExcel(fileQo, fileExcel); } /** * 修改上传的模板信息 + * * @param fileUpdateQo * @param fileExcel * @return @@ -53,11 +57,11 @@ public class FileController { */ @PostMapping("/updateFileUploadPath") @Transactional(rollbackOn = Exception.class) - public String updateFileUploadPath(FileUpdateQo fileUpdateQo,@RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { + public String updateFileUploadPath(FileUpdateQo fileUpdateQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { Locale locale = LocaleContextHolder.getLocale(); String file = ExcelUploadUtil.memoryFile(fileExcel); - fileDao.updateFileUploadPath(fileUpdateQo.getFileModelNumber(),fileUpdateQo.getFileBatchNumber(),fileUpdateQo.getFileMachineCode(),fileUpdateQo.getFileProductNumber(),file); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale); + fileDao.updateFileUploadPath(fileUpdateQo.getLotNo(), fileUpdateQo.getMachineNo(), fileUpdateQo.getMaterialNo(), fileUpdateQo.getModelNo(), fileUpdateQo.getPartNo(), file); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale); } /** diff --git a/src/main/java/com/xkrs/dao/DataDictDao.java b/src/main/java/com/xkrs/dao/DataDictDao.java index e916427..3979fab 100644 --- a/src/main/java/com/xkrs/dao/DataDictDao.java +++ b/src/main/java/com/xkrs/dao/DataDictDao.java @@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; import java.util.List; +import java.util.Optional; /** * @Author: XinYi Song @@ -17,25 +18,18 @@ import java.util.List; public interface DataDictDao extends JpaRepository, JpaSpecificationExecutor { /** - * 通过中文名称查询字典表数据 - * @param chineseName + * 通过质检项代码查询字典表的数据 + * @param inspectionItemCode * @return */ - DataDict findByDictChineseName(String chineseName); - - /** - * 通过英文变量查询字典表的数据 - * @param englishName - * @return - */ - DataDict findByDictEnglishName(String englishName); + Optional findByInspectionItemCode(String inspectionItemCode); /** * 根据id查询字典信息 * @param id * @return */ - DataDict findById(Integer id); + Optional findById(Integer id); /** * 根据id修改字典的信息 diff --git a/src/main/java/com/xkrs/dao/DataSourceDao.java b/src/main/java/com/xkrs/dao/DataSourceDao.java index eeec162..6fd175c 100644 --- a/src/main/java/com/xkrs/dao/DataSourceDao.java +++ b/src/main/java/com/xkrs/dao/DataSourceDao.java @@ -7,58 +7,33 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; import java.util.List; -import java.util.Map; +import java.util.Optional; /** * @Author: XinYi Song * @Date: 2022/1/19 16:41 */ @Component -public interface DataSourceDao extends JpaRepository, JpaSpecificationExecutor { +public interface DataSourceDao extends JpaRepository, JpaSpecificationExecutor { /** * 查询测量数据信息 - * @param dataModelNumber - * @param dataBatchNumber - * @param dataMachineCode - * @param productNumber + * + * @param lotNo 批次号 + * @param machineNo 机器号 + * @param materialNo 物料号 + * @param modelNo 模具号 + * @param partNo 零件号 * @return */ - @Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + - "ds.data_machine_code datamachinecode, ds.product_number productnumber, ds.material material, dd.dict_chinese_name chinesename, " + - "ds.data_name dataname,ds.numerical_value numericalvalue " + - "from data_dict dd,data_source ds where ds.data_name = dd.dict_english_name and " + - "ds.data_model_number = :dataModelNumber and ds.data_batch_number = :dataBatchNumber and " + - "ds.data_machine_code = :dataMachineCode and ds.product_number = :productNumber",nativeQuery = true) - List> selectDataSource(String dataModelNumber, String dataBatchNumber, String dataMachineCode, String productNumber); - - /** - * 查询测量信息变量和测量值,用于模板的导入 - * @param dataModelNumber - * @param dataBatchNumber - * @param dataMachineCode - * @param productNumber - * @return - */ - @Query(value = "select data_name dataname,numerical_value numericalvalue from data_source " + - "where data_model_number = :dataModelNumber and data_batch_number = :dataBatchNumber " + - "and data_machine_code = :dataMachineCode and product_number = :productNumber",nativeQuery = true) - List> selectDataNameAndData(String dataModelNumber, String dataBatchNumber, String dataMachineCode, String productNumber); - - /** - * 通过英文变量查询信息 - * @param dataname - * @return - */ - DataSource findByDataName(String dataname); + @Query(value = "SELECT * FROM qc_inspection_data_source WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true) + List selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo); /** * 查询全部的测量信息 + * * @return */ - @Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + - "ds.data_machine_code datamachinecode, ds.product_number productnumber, ds.material material, dd.dict_chinese_name chinesename," + - "ds.data_name dataname,ds.numerical_value numericalvalue from data_dict dd,data_source ds " + - "where ds.data_name = dd.dict_english_name",nativeQuery = true) - List> selectAllSource(); + @Query(value = "SELECT * FROM qc_inspection_data_source", nativeQuery = true) + List selectAllSource(); } diff --git a/src/main/java/com/xkrs/dao/FileDao.java b/src/main/java/com/xkrs/dao/FileDao.java index 96ca8e3..d9fbca7 100644 --- a/src/main/java/com/xkrs/dao/FileDao.java +++ b/src/main/java/com/xkrs/dao/FileDao.java @@ -12,41 +12,48 @@ import org.springframework.stereotype.Component; * @Date: 2022/1/20 15:23 */ @Component -public interface FileDao extends JpaRepository, JpaSpecificationExecutor { +public interface FileDao extends JpaRepository, JpaSpecificationExecutor { /** - * 根据机种号,批次号,机器号,产品号查询文件信息 - * @param fileModelNumber - * @param fileBatchNumber - * @param fileMachineCode - * @param fileProductNumber + * 查询文件信息 + * + * @param lotNo 批次号 + * @param machineNo 机器号 + * @param materialNo 物料号 + * @param modelNo 模具号 + * @param partNo 零件号 * @return */ - FileEntity findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber); + @Query(value = "SELECT * FROM qc_inspection_file WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true) + FileEntity selectFile(String lotNo, String machineNo, String materialNo, String modelNo, String partNo); /** - * 根据机种号,批次号,机器号,产品号修改模板上传信息 - * @param fileModelNumber - * @param fileBatchNumber - * @param fileMachineCode - * @param fileProductNumber - * @param fileUploadPath + * 修改模板上传信息 + * + * @param lotNo 批次号 + * @param machineNo 机器号 + * @param materialNo 物料号 + * @param modelNo 模具号 + * @param partNo 零件号 + * @param fileUploadPath 模板路径 */ - @Modifying(clearAutomatically=true) - @Query(value = "update file set file_upload_path = ?5 where file_model_number = ?1 and file_batch_number = ?2 and file_machine_code = ?3 and file_product_number = ?4",nativeQuery = true) - void updateFileUploadPath(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber,String fileUploadPath); + @Modifying(clearAutomatically = true) + @Query(value = "UPDATE qc_inspection_file SET file_upload_path = ?6 WHERE lot_no = ?1 AND machine_no = ?2 AND material_no = ?3 AND model_no = ?4 AND part_no = ?5 ", nativeQuery = true) + void updateFileUploadPath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String fileUploadPath); /** - * 根据机种号,批次号,机器号,产品号修改模板下载信息 - * @param fileModelNumber - * @param fileBatchNumber - * @param fileMachineCode - * @param fileProductNumber - * @param fileDownloadPath + * 修改文件下载信息 + * + * @param lotNo 批次号 + * @param machineNo 机器号 + * @param materialNo 物料号 + * @param modelNo 模具号 + * @param partNo 零件号 + * @param fileDownloadPath 文件下载路径 */ - @Modifying(clearAutomatically=true) - @Query(value = "update file set file_download_path = ?5 where file_model_number = ?1 and file_batch_number = ?2 and file_machine_code = ?3 and file_product_number = ?4",nativeQuery = true) - void updateFileDownloadPath(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber,String fileDownloadPath); + @Modifying(clearAutomatically = true) + @Query(value = "UPDATE qc_inspection_file SET file_download_path = ?6 WHERE lot_no = ?1 AND machine_no = ?2 AND material_no = ?3 AND model_no = ?4 AND part_no = ?5 ", nativeQuery = true) + void updateFileDownloadPath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String fileDownloadPath); } diff --git a/src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java b/src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java index 6d50b88..d16df05 100644 --- a/src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java @@ -38,8 +38,8 @@ public class DataDictServiceImpl implements DataDictService { return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该产品变量已存在,请勿重复添加!",locale); }*/ //DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataDictQo.getDictEnglishName()); - DataDict englishName = dataDictDao.findByDictEnglishName(dataDictQo.getInspectionItemCode()); - if (englishName != null) { + DataDict dataDict1 = dataDictDao.findByInspectionItemCode(dataDictQo.getInspectionItemCode()).get(); + if (dataDict1 != null) { return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该产品变量已存在,请勿重复添加!", locale); } DataDict dataDict = new DataDict(); diff --git a/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java b/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java index b776468..e84a6f3 100644 --- a/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java @@ -36,8 +36,8 @@ public class DataSourceServiceImpl implements DataSourceService { @Override public String insertDataSource(DataSourceQo dataSourceQo) { Locale locale = LocaleContextHolder.getLocale(); - DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataSourceQo.getInspectionItemCode()); - if(byDictEnglishName == null){ + DataDict dataDict = dataDictDao.findByInspectionItemCode(dataSourceQo.getInspectionItemCode()).get(); + if(dataDict == null){ return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"不存在该字典类型!",locale); } DataSource dataSource = new DataSource(); diff --git a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java index a47f2d0..6595dd1 100644 --- a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java @@ -4,6 +4,7 @@ import com.xkrs.dao.DataDictDao; import com.xkrs.dao.DataSourceDao; import com.xkrs.dao.FileDao; import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.model.entity.DataSource; import com.xkrs.model.entity.FileEntity; import com.xkrs.model.qo.FileQo; import com.xkrs.service.FileService; @@ -15,7 +16,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; import javax.transaction.Transactional; import java.io.IOException; import java.util.HashMap; @@ -43,18 +43,19 @@ public class FileServiceImpl implements FileService { /** * 添加模板信息 + * * @param fileQo * @return */ @Override public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException { Locale locale = LocaleContextHolder.getLocale(); - FileEntity fileEntity = fileDao.findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); - if(fileEntity != null){ - return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"已存在该产品的模板!",locale); + FileEntity fileEntity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo()); + if (fileEntity != null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale); } - if(fileExcel == null){ - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"模板不能为空!",locale); + if (fileExcel == null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale); } String file = ExcelUploadUtil.memoryFile(fileExcel); FileEntity fileEntity1 = new FileEntity(); @@ -65,11 +66,12 @@ public class FileServiceImpl implements FileService { fileEntity1.setPartNo(fileQo.getPartNo()); fileEntity1.setFileUploadPath(file); fileDao.save(fileEntity1); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功!",locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } /** * 导出excel + * * @param fileQo * @return */ @@ -77,21 +79,21 @@ public class FileServiceImpl implements FileService { @Override public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException { Locale locale = LocaleContextHolder.getLocale(); - FileEntity entity = fileDao.findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); - if(entity == null){ - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的模板,请添加!",locale); + FileEntity entity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo()); + if (entity == null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); } String fileUploadPath = entity.getFileUploadPath(); - List> maps = dataSourceDao.selectDataNameAndData(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); - if(maps == null || maps.size() == 0){ - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的信息!",locale); + List dataSources = dataSourceDao.selectDataSource(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo()); + if (dataSources == null || dataSources.size() == 0) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); } - Map map = new HashMap<>(); - for(Map stringMap : maps){ - map.put(stringMap.get("dataname"),stringMap.get("numericalvalue")); + Map map = new HashMap<>(); + for (DataSource dataSource : dataSources) { + map.put(dataSource.getInspectionItemCode(), dataSource.getInspectValue()); } - String fill = ExportExcel.exportToProveExcel(map,fileUploadPath); - fileDao.updateFileDownloadPath(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber(),fill); - return outputEncapsulationObject(PromptMessageEnum.SUCCESS,fill,locale); + String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); + fileDao.updateFileDownloadPath(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo(), fill); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale); } }