工业测量
This commit is contained in:
		
							
								
								
									
										13
									
								
								src/main/java/com/xkrs/WordAndExcelApplication.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/main/java/com/xkrs/WordAndExcelApplication.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| package com.xkrs; | ||||
|  | ||||
| import org.springframework.boot.SpringApplication; | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
|  | ||||
| @SpringBootApplication | ||||
| public class WordAndExcelApplication { | ||||
|  | ||||
|     public static void main(String[] args) { | ||||
|         SpringApplication.run(WordAndExcelApplication.class, args); | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										23
									
								
								src/main/java/com/xkrs/config/CorsConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/main/java/com/xkrs/config/CorsConfig.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| package com.xkrs.config; | ||||
|  | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| /** | ||||
|  * 系统跨域配置 | ||||
|  * @author tajochen | ||||
|  */ | ||||
| @Configuration | ||||
| public class CorsConfig implements WebMvcConfigurer { | ||||
|  | ||||
|     @Resource | ||||
|     private CorsInterceptor corsInterceptor; | ||||
|  | ||||
|     @Override | ||||
|     public void addInterceptors(InterceptorRegistry registry) { | ||||
|         registry.addInterceptor(corsInterceptor); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										29
									
								
								src/main/java/com/xkrs/config/CorsInterceptor.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/main/java/com/xkrs/config/CorsInterceptor.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| package com.xkrs.config; | ||||
|  | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.web.servlet.HandlerInterceptor; | ||||
|  | ||||
| import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
|  | ||||
| /** | ||||
|  * 跨域处理 | ||||
|  * @author tajochen | ||||
|  */ | ||||
| @Component | ||||
| public class CorsInterceptor implements HandlerInterceptor { | ||||
|  | ||||
|     @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { | ||||
|  | ||||
|         //添加跨域CORS | ||||
|         response.setHeader("Access-Control-Allow-Origin", "*"); | ||||
|         response.setHeader("Access-Control-Allow-Credentials", "false"); | ||||
|         response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); | ||||
|         response.setHeader("Access-Control-Allow-Headers", "Content-Type , Authorization," + | ||||
|                 "Accept,Origin,X-Requested-With"); | ||||
|         response.setHeader("Access-Control-Max-Age", "216000"); | ||||
|         response.setHeader("Content-Type","application/json;charset=UTF-8"); | ||||
|         return true; | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										37
									
								
								src/main/java/com/xkrs/config/MvcConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/main/java/com/xkrs/config/MvcConfig.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package com.xkrs.config; | ||||
|  | ||||
| import org.springframework.context.annotation.Bean; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.scheduling.TaskScheduler; | ||||
| import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; | ||||
| import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||||
|  | ||||
| /** | ||||
|  * WebMVC配置 | ||||
|  * @author Tajochen | ||||
|  */ | ||||
| @Configuration | ||||
| public class MvcConfig implements WebMvcConfigurer { | ||||
|  | ||||
|     /** | ||||
|      * 放行跨域请求 | ||||
|      */ | ||||
|     @Override | ||||
|     public void addCorsMappings(CorsRegistry registry) { | ||||
|         registry.addMapping("/**") | ||||
|                 .allowedOrigins("*") | ||||
|                 .allowedMethods("*") | ||||
|                 .allowedHeaders("*"); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 定时任务线程池更改,防止多个任务并行 | ||||
|      */ | ||||
|     @Bean | ||||
|     public TaskScheduler taskScheduler() { | ||||
|         final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); | ||||
|         scheduler.setPoolSize(5); | ||||
|         return scheduler; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										87
									
								
								src/main/java/com/xkrs/controller/DataDictController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								src/main/java/com/xkrs/controller/DataDictController.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| package com.xkrs.controller; | ||||
|  | ||||
| import com.xkrs.dao.DataDictDao; | ||||
| import com.xkrs.encapsulation.PromptMessageEnum; | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import com.xkrs.model.qo.DataDictQo; | ||||
| import com.xkrs.model.qo.DataDictUpdateQo; | ||||
| import com.xkrs.service.DataDictService; | ||||
| import com.xkrs.util.Query; | ||||
| import org.springframework.context.i18n.LocaleContextHolder; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.transaction.Transactional; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:54 | ||||
|  */ | ||||
| @RestController | ||||
| public class DataDictController { | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictService dataDictService; | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictDao dataDictDao; | ||||
|  | ||||
|     @Resource | ||||
|     private Query query; | ||||
|  | ||||
|     /** | ||||
|      * 添加字典变量数据 | ||||
|      * @param dataDictQo | ||||
|      * @return | ||||
|      */ | ||||
|     @PostMapping("/insertDataDict") | ||||
|     public String insertDataDict(@RequestBody DataDictQo dataDictQo){ | ||||
|         return dataDictService.insertDataDict(dataDictQo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 动态多条件查询字典信息 | ||||
|      * @param dictChineseName | ||||
|      * @param dictEnglishName | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping("/selectDataDict") | ||||
|     public String selectDataDict(@RequestParam("dictChineseName") String dictChineseName, | ||||
|                                  @RequestParam("dictEnglishName") String dictEnglishName){ | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         List<DataDict> dataDict = query.selectDataDict(dictChineseName, dictEnglishName); | ||||
|         if(dataDict == null || dataDict.size() == 0){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该型号类型的字典信息!",locale); | ||||
|         } | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据id查询字典信息,用于数据回显,方便进行修改操作 | ||||
|      * @param id | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping("/selectDataDictById") | ||||
|     public String selectDataDictById(@RequestParam("id") Integer id){ | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         DataDict dataDict = dataDictDao.findById(id); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 根据id修改字典信息 | ||||
|      * @param dataDictUpdateQo | ||||
|      * @return | ||||
|      */ | ||||
|     @PostMapping("/updateDict") | ||||
|     @Transactional(rollbackOn = Exception.class) | ||||
|     public String updateDict(@RequestBody DataDictUpdateQo dataDictUpdateQo){ | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         dataDictDao.updateDict(dataDictUpdateQo.getId(),dataDictUpdateQo.getDictChineseName()); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										74
									
								
								src/main/java/com/xkrs/controller/DataSourceController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								src/main/java/com/xkrs/controller/DataSourceController.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,74 @@ | ||||
| package com.xkrs.controller; | ||||
|  | ||||
| import com.xkrs.dao.DataSourceDao; | ||||
| import com.xkrs.encapsulation.PromptMessageEnum; | ||||
| import com.xkrs.model.qo.DataSourceQo; | ||||
| import com.xkrs.service.DataSourceService; | ||||
| import org.springframework.context.i18n.LocaleContextHolder; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| import java.util.Map; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 17:05 | ||||
|  */ | ||||
| @RestController | ||||
| public class DataSourceController { | ||||
|  | ||||
|     @Resource | ||||
|     private DataSourceService dataSourceService; | ||||
|  | ||||
|     @Resource | ||||
|     private DataSourceDao dataSourceDao; | ||||
|  | ||||
|     /** | ||||
|      * 添加测量数据 | ||||
|      * @param dataSourceQo | ||||
|      * @return | ||||
|      */ | ||||
|     @PostMapping("/insertDataSource") | ||||
|     public String insertDataSource(@RequestBody DataSourceQo dataSourceQo){ | ||||
|         return dataSourceService.insertDataSource(dataSourceQo); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询某一产品的测量信息 | ||||
|      * @param dataModelNumber | ||||
|      * @param dataBatchNumber | ||||
|      * @param dataMachineCode | ||||
|      * @param productNumber | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping("/selectDataSource") | ||||
|     public String selectDataSource(@RequestParam("dataModelNumber") String dataModelNumber, | ||||
|                                    @RequestParam("dataBatchNumber") String dataBatchNumber, | ||||
|                                    @RequestParam("dataMachineCode") String dataMachineCode, | ||||
|                                    @RequestParam("productNumber") String productNumber){ | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         List<Map<String, String>> maps = dataSourceDao.selectDataSource(dataModelNumber, dataBatchNumber, dataMachineCode, productNumber); | ||||
|         if(maps == null || maps.size() == 0){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的测量信息!",locale); | ||||
|         } | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 查询全部的测量信息 | ||||
|      * @return | ||||
|      */ | ||||
|     @GetMapping("/selectAllSource") | ||||
|     public String selectAllSource(){ | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         List<Map<String, String>> maps = dataSourceDao.selectAllSource(); | ||||
|         if(maps == null || maps.size() == 0){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的测量信息!",locale); | ||||
|         } | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										73
									
								
								src/main/java/com/xkrs/controller/FileController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/main/java/com/xkrs/controller/FileController.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| package com.xkrs.controller; | ||||
|  | ||||
| import com.xkrs.dao.FileDao; | ||||
| import com.xkrs.encapsulation.PromptMessageEnum; | ||||
| import com.xkrs.model.qo.FileQo; | ||||
| import com.xkrs.model.qo.FileUpdateQo; | ||||
| 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.multipart.MultipartFile; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import javax.transaction.Transactional; | ||||
| import java.io.IOException; | ||||
| import java.util.Locale; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 16:01 | ||||
|  */ | ||||
| @RestController | ||||
| public class FileController { | ||||
|  | ||||
|     @Resource | ||||
|     private FileService fileService; | ||||
|  | ||||
|     @Resource | ||||
|     private FileDao fileDao; | ||||
|  | ||||
|     /** | ||||
|      * 上传模板信息 | ||||
|      * @param fileQo | ||||
|      * @param fileExcel | ||||
|      * @return | ||||
|      * @throws IOException | ||||
|      */ | ||||
|     @PostMapping("/insertFileExcel") | ||||
|     public String insertFileExcel(FileQo fileQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { | ||||
|         return fileService.insertFileExcel(fileQo,fileExcel); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 修改上传的模板信息 | ||||
|      * @param fileUpdateQo | ||||
|      * @param fileExcel | ||||
|      * @return | ||||
|      * @throws IOException | ||||
|      */ | ||||
|     @PostMapping("/updateFileUploadPath") | ||||
|     @Transactional(rollbackOn = Exception.class) | ||||
|     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); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导出excel | ||||
|      * | ||||
|      * @param fileQo | ||||
|      * @return | ||||
|      */ | ||||
|     @PostMapping("/exportExcel") | ||||
|     public String exportExcel(@RequestBody FileQo fileQo) throws IOException, InvalidFormatException { | ||||
|         return fileService.exportExcel(fileQo); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										48
									
								
								src/main/java/com/xkrs/dao/DataDictDao.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/main/java/com/xkrs/dao/DataDictDao.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| package com.xkrs.dao; | ||||
|  | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||||
| import org.springframework.data.jpa.repository.Modifying; | ||||
| import org.springframework.data.jpa.repository.Query; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:03 | ||||
|  */ | ||||
| @Component | ||||
| public interface DataDictDao extends JpaRepository<DataDict,Long>, JpaSpecificationExecutor<DataDict> { | ||||
|  | ||||
|     /** | ||||
|      * 通过中文名称查询字典表数据 | ||||
|      * @param chineseName | ||||
|      * @return | ||||
|      */ | ||||
|     DataDict findByDictChineseName(String chineseName); | ||||
|  | ||||
|     /** | ||||
|      * 通过英文变量查询字典表的数据 | ||||
|      * @param englishName | ||||
|      * @return | ||||
|      */ | ||||
|     DataDict findByDictEnglishName(String englishName); | ||||
|  | ||||
|     /** | ||||
|      * 根据id查询字典信息 | ||||
|      * @param id | ||||
|      * @return | ||||
|      */ | ||||
|     DataDict findById(Integer id); | ||||
|  | ||||
|     /** | ||||
|      * 根据id修改字典的信息 | ||||
|      * @param id | ||||
|      * @param chineseName | ||||
|      */ | ||||
|     @Modifying(clearAutomatically=true) | ||||
|     @Query(value = "update data_dict set dict_chinese_name = ?2 where id = ?1",nativeQuery = true) | ||||
|     void updateDict(Integer id, String chineseName); | ||||
| } | ||||
							
								
								
									
										64
									
								
								src/main/java/com/xkrs/dao/DataSourceDao.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								src/main/java/com/xkrs/dao/DataSourceDao.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,64 @@ | ||||
| package com.xkrs.dao; | ||||
|  | ||||
| import com.xkrs.model.entity.DataSource; | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||||
| import org.springframework.data.jpa.repository.Query; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 16:41 | ||||
|  */ | ||||
| @Component | ||||
| public interface DataSourceDao extends JpaRepository<DataSource,Long>, JpaSpecificationExecutor<DataSource> { | ||||
|  | ||||
|     /** | ||||
|      * 查询测量数据信息 | ||||
|      * @param dataModelNumber | ||||
|      * @param dataBatchNumber | ||||
|      * @param dataMachineCode | ||||
|      * @param productNumber | ||||
|      * @return | ||||
|      */ | ||||
|     @Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + | ||||
|             "ds.data_machine_code datamachinecode, ds.product_number productnumber, 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<Map<String,String>> 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<Map<String,String>> selectDataNameAndData(String dataModelNumber, String dataBatchNumber, String dataMachineCode, String productNumber); | ||||
|  | ||||
|     /** | ||||
|      * 通过英文变量查询信息 | ||||
|      * @param dataname | ||||
|      * @return | ||||
|      */ | ||||
|     DataSource findByDataName(String dataname); | ||||
|  | ||||
|     /** | ||||
|      * 查询全部的测量信息 | ||||
|      * @return | ||||
|      */ | ||||
|     @Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + | ||||
|             "ds.data_machine_code datamachinecode, ds.product_number productnumber, 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<Map<String,String>> selectAllSource(); | ||||
| } | ||||
							
								
								
									
										52
									
								
								src/main/java/com/xkrs/dao/FileDao.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								src/main/java/com/xkrs/dao/FileDao.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| package com.xkrs.dao; | ||||
|  | ||||
| import com.xkrs.model.entity.FileEntity; | ||||
| import org.springframework.data.jpa.repository.JpaRepository; | ||||
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||||
| import org.springframework.data.jpa.repository.Modifying; | ||||
| import org.springframework.data.jpa.repository.Query; | ||||
| import org.springframework.stereotype.Component; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:23 | ||||
|  */ | ||||
| @Component | ||||
| public interface FileDao extends JpaRepository<FileEntity,Long>, JpaSpecificationExecutor<FileEntity> { | ||||
|  | ||||
|     /** | ||||
|      * 根据机种号,批次号,机器号,产品号查询文件信息 | ||||
|      * @param fileModelNumber | ||||
|      * @param fileBatchNumber | ||||
|      * @param fileMachineCode | ||||
|      * @param fileProductNumber | ||||
|      * @return | ||||
|      */ | ||||
|     FileEntity findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber); | ||||
|  | ||||
|     /** | ||||
|      * 根据机种号,批次号,机器号,产品号修改模板上传信息 | ||||
|      * @param fileModelNumber | ||||
|      * @param fileBatchNumber | ||||
|      * @param fileMachineCode | ||||
|      * @param fileProductNumber | ||||
|      * @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); | ||||
|  | ||||
|     /** | ||||
|      * 根据机种号,批次号,机器号,产品号修改模板下载信息 | ||||
|      * @param fileModelNumber | ||||
|      * @param fileBatchNumber | ||||
|      * @param fileMachineCode | ||||
|      * @param fileProductNumber | ||||
|      * @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); | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -0,0 +1,59 @@ | ||||
| package com.xkrs.encapsulation; | ||||
|  | ||||
| import java.io.Serializable; | ||||
|  | ||||
| /** | ||||
|  * 输出信息对象 | ||||
|  * @author tajochen | ||||
|  * @param <T> | ||||
|  */ | ||||
| public class EncapsulationObejct<T> implements Serializable { | ||||
|  | ||||
|     /** | ||||
|      * 状态码 | ||||
|      */ | ||||
|     int status; | ||||
|  | ||||
|     /** | ||||
|      * 提示信息 | ||||
|      */ | ||||
|     String msg; | ||||
|  | ||||
|     /** | ||||
|      * 数据 | ||||
|      */ | ||||
|     T data; | ||||
|  | ||||
|     public int getStatus() { | ||||
|         return status; | ||||
|     } | ||||
|  | ||||
|     public void setStatus(int status) { | ||||
|         this.status = status; | ||||
|     } | ||||
|  | ||||
|     public String getMsg() { | ||||
|         return msg; | ||||
|     } | ||||
|  | ||||
|     public void setMsg(String msg) { | ||||
|         this.msg = msg; | ||||
|     } | ||||
|  | ||||
|     public T getData() { | ||||
|         return data; | ||||
|     } | ||||
|  | ||||
|     public void setData(T data) { | ||||
|         this.data = data; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "EncapsulationObejct{" + | ||||
|                 "status=" + status + | ||||
|                 ", msg='" + msg + '\'' + | ||||
|                 ", data=" + data + | ||||
|                 '}'; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,96 @@ | ||||
| package com.xkrs.encapsulation; | ||||
|  | ||||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||||
| import com.fasterxml.jackson.databind.SerializationFeature; | ||||
| import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import org.springframework.context.MessageSource; | ||||
| import org.springframework.context.support.ResourceBundleMessageSource; | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.validation.FieldError; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| import java.util.Properties; | ||||
|  | ||||
| /** | ||||
|  * 输出信息封装 | ||||
|  * @author tajochen | ||||
|  */ | ||||
| @Component | ||||
| public class OutputEncapsulation { | ||||
|  | ||||
|     private static final Logger logger = LoggerFactory.getLogger(OutputEncapsulation.class); | ||||
|  | ||||
|     /** | ||||
|      * 读取多国语言文件 | ||||
|      * @return | ||||
|      */ | ||||
|     public static MessageSource messageSource() { | ||||
|         Properties properties = new Properties(); | ||||
|         // 使用ClassLoader加载properties配置文件生成对应的输入流 | ||||
|         InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"); | ||||
|         // 使用properties对象加载输入流 | ||||
|         try { | ||||
|             properties.load(in); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource(); | ||||
|         messageSource.setBasename("i18n/messages"); | ||||
|         messageSource.setDefaultEncoding("UTF-8"); | ||||
|         return messageSource; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 封装输出数据 | ||||
|      * @param promptMessageEnum | ||||
|      * @param obj | ||||
|      * @return | ||||
|      */ | ||||
|     public static String outputEncapsulationObject(PromptMessageEnum promptMessageEnum, Object obj, Locale locale) { | ||||
|  | ||||
|         EncapsulationObejct encapsulationObejct = new EncapsulationObejct(); | ||||
|         encapsulationObejct.setStatus(promptMessageEnum.getCode()); | ||||
|         encapsulationObejct.setMsg(messageSource().getMessage(promptMessageEnum.getText(),null,locale)); | ||||
|         encapsulationObejct.setData(obj); | ||||
|  | ||||
|         ObjectMapper objectMapper = new ObjectMapper(); | ||||
|         // 忽略无法转换的对象 | ||||
|         objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS,false); | ||||
|         // 忽略json字符串中不识别的属性 | ||||
|         objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||||
|         // 解决jackson无法反序列化LocalDateTime的问题,引入jsr310标准 | ||||
|         JavaTimeModule javaTimeModule = new JavaTimeModule(); | ||||
|         objectMapper.registerModule(javaTimeModule); | ||||
|         objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | ||||
|         String strByEo = ""; | ||||
|         try { | ||||
|             strByEo = objectMapper.writeValueAsString(encapsulationObejct); | ||||
|         } catch (JsonProcessingException e) { | ||||
|             e.printStackTrace(); | ||||
|             logger.warn(e.toString()); | ||||
|         } | ||||
|         return strByEo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 输出请求值检验错误信息 | ||||
|      * @param fieldErrors | ||||
|      * @return | ||||
|      */ | ||||
|     public static String outputEncapsulationErrorList(List<FieldError> fieldErrors, Locale locale){ | ||||
|         List<String> errorMsg = new ArrayList<>(); | ||||
|         for (FieldError fieldError : fieldErrors) { | ||||
|             String errMessage = fieldError.getDefaultMessage().subSequence(1,fieldError.getDefaultMessage().length()-1).toString(); | ||||
|             errorMsg.add(messageSource().getMessage(errMessage,null,locale)); | ||||
|         } | ||||
|         return outputEncapsulationObject(PromptMessageEnum.PARAM_ILLEGAL,errorMsg,locale); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										65
									
								
								src/main/java/com/xkrs/encapsulation/PromptMessageEnum.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/main/java/com/xkrs/encapsulation/PromptMessageEnum.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| package com.xkrs.encapsulation; | ||||
|  | ||||
| /** | ||||
|  * 提示信息枚举 | ||||
|  * @author tajochen | ||||
|  */ | ||||
| public enum PromptMessageEnum{ | ||||
|  | ||||
|     // 执行成功 | ||||
|     SUCCESS(0, "sys.message.success"), | ||||
|  | ||||
|  | ||||
|     // 用户权限错误或非法操作:  1001-1999 | ||||
|     USER_NOT_LOGGED(1001, "sys.message.user.not_logged_in"), | ||||
|     USER_LOGIN_ERROR(1002, "sys.message.user.login_error"), | ||||
|     USER_ACCOUNT_FORBIDDEN(1003, "sys.message.user.account_forbidden"), | ||||
|     USER_ACCOUNT_NOT_ACTIVATED(1004, "sys.message.user.account_not_activated"), | ||||
|     USER_HAS_OVERTIME(1005, "sys.message.user.overtime"), | ||||
|     USER_NO_PERMISSION(1006,"sys.message.user.no_permission"), | ||||
|     USER_ALREADY_LOGGED(1007, "sys.message.user.already_logged"), | ||||
|  | ||||
|     // 请求参数错误或非法:2001-2999 | ||||
|     PARAM_NULL(2001, "sys.message.param.null"), | ||||
|     PARAM_ILLEGAL(2002, "sys.message.param.illegal"), | ||||
|  | ||||
|     // 数据返回错误:3001-3999 | ||||
|     DATA_NONE(3001, "sys.message.data.none"), | ||||
|  | ||||
|     DATA_WRONG(3002, "sys.message.data.wrong"), | ||||
|     DATA_EXIT(3003,"sys.message.exit"), | ||||
|  | ||||
|     // 操作失败:4001-4999 | ||||
|     PROCESS_FAIL(4001,"sys.message.process.fail"), | ||||
|     PROCESS_OVERTIME(4002,"sys.message.process.overtime"), | ||||
|     FILE_EXISTS(4003,"sys.message.file.exists"), | ||||
|     FILE_WRITE_ERROR(4004,"sys.message.file.write.error"), | ||||
|     FILE_READ_ERROR(4005,"sys.message.file.read.error"), | ||||
|  | ||||
|     // 系统内部错误或异常:5001-5999 | ||||
|     SYSTEM_INNER_ERROR(5001,"sys.message.system.inner_error"), | ||||
|     SYSTEM_ABNORMAL(5002,"sys.message.system.abnormal"), | ||||
|     SYSTEM_BUSY(5003,"sys.message.system.busy"), | ||||
|     SYSTEM_MAINTAIN(5004,"sys.message.system.maintain"), | ||||
|  | ||||
|     // 数据库错误:6001-6999 | ||||
|     DATABASE_ERROR(6001,"sys.message.database.error"); | ||||
|  | ||||
|     private int code; | ||||
|  | ||||
|     private String text; | ||||
|  | ||||
|     private PromptMessageEnum(int code,String text) { | ||||
|         this.code = code; | ||||
|         this.text = text; | ||||
|     } | ||||
|  | ||||
|     public String getText() { | ||||
|         return this.text; | ||||
|     } | ||||
|  | ||||
|     public int getCode() { | ||||
|         return this.code; | ||||
|     } | ||||
|  | ||||
| } | ||||
							
								
								
									
										73
									
								
								src/main/java/com/xkrs/model/entity/DataDict.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								src/main/java/com/xkrs/model/entity/DataDict.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| package com.xkrs.model.entity; | ||||
|  | ||||
| import javax.persistence.*; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 9:26 | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "data_dict") | ||||
| public class DataDict { | ||||
|     /** | ||||
|      * 主键id | ||||
|      */ | ||||
|     @Id | ||||
|     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "data_dict_seq_gen") | ||||
|     @SequenceGenerator(name = "data_dict_seq_gen", sequenceName = "data_dict_id_seq",allocationSize = 1) | ||||
|     private Integer id; | ||||
|  | ||||
|     /** | ||||
|      * 中文名称 | ||||
|      */ | ||||
|     @Column(length = 65, columnDefinition = "varchar(65)") | ||||
|     private String dictChineseName; | ||||
|  | ||||
|     /** | ||||
|      * 英文变量值 | ||||
|      */ | ||||
|     @Column(length = 85, columnDefinition = "varchar(85)") | ||||
|     private String dictEnglishName; | ||||
|  | ||||
|     public DataDict() { | ||||
|     } | ||||
|  | ||||
|     public DataDict(Integer id, String dictChineseName, String dictEnglishName) { | ||||
|         this.id = id; | ||||
|         this.dictChineseName = dictChineseName; | ||||
|         this.dictEnglishName = dictEnglishName; | ||||
|     } | ||||
|  | ||||
|     public Integer getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(Integer id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getDictChineseName() { | ||||
|         return dictChineseName; | ||||
|     } | ||||
|  | ||||
|     public void setDictChineseName(String dictChineseName) { | ||||
|         this.dictChineseName = dictChineseName; | ||||
|     } | ||||
|  | ||||
|     public String getDictEnglishName() { | ||||
|         return dictEnglishName; | ||||
|     } | ||||
|  | ||||
|     public void setDictEnglishName(String dictEnglishName) { | ||||
|         this.dictEnglishName = dictEnglishName; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "DataDict{" + | ||||
|                 "id=" + id + | ||||
|                 ", dictChineseName='" + dictChineseName + '\'' + | ||||
|                 ", dictEnglishName='" + dictEnglishName + '\'' + | ||||
|                 '}'; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										137
									
								
								src/main/java/com/xkrs/model/entity/DataSource.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										137
									
								
								src/main/java/com/xkrs/model/entity/DataSource.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,137 @@ | ||||
| package com.xkrs.model.entity; | ||||
|  | ||||
| import javax.persistence.*; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 14:08 | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "data_source") | ||||
| public class DataSource { | ||||
|     /** | ||||
|      * 主键id | ||||
|      */ | ||||
|     @Id | ||||
|     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "data_source_seq_gen") | ||||
|     @SequenceGenerator(name = "data_source_seq_gen", sequenceName = "data_source_id_seq",allocationSize = 1) | ||||
|     private Integer id; | ||||
|  | ||||
|     /** | ||||
|      * 机种号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String dataModelNumber; | ||||
|  | ||||
|     /** | ||||
|      * 批次号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String dataBatchNumber; | ||||
|  | ||||
|     /** | ||||
|      * 机器号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String dataMachineCode; | ||||
|  | ||||
|     /** | ||||
|      * 产品编号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String productNumber; | ||||
|  | ||||
|     /** | ||||
|      * 变量值 | ||||
|      */ | ||||
|     @Column(length = 85, columnDefinition = "varchar(85)") | ||||
|     private String dataName; | ||||
|  | ||||
|     /** | ||||
|      * 监测的数值 | ||||
|      */ | ||||
|     @Column(length = 85, columnDefinition = "varchar(85)") | ||||
|     private String numericalValue; | ||||
|  | ||||
|     public DataSource() { | ||||
|     } | ||||
|  | ||||
|     public DataSource(Integer id, String dataModelNumber, String dataBatchNumber, String dataMachineCode, String productNumber, String dataName, String numericalValue) { | ||||
|         this.id = id; | ||||
|         this.dataModelNumber = dataModelNumber; | ||||
|         this.dataBatchNumber = dataBatchNumber; | ||||
|         this.dataMachineCode = dataMachineCode; | ||||
|         this.productNumber = productNumber; | ||||
|         this.dataName = dataName; | ||||
|         this.numericalValue = numericalValue; | ||||
|     } | ||||
|  | ||||
|     public Integer getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(Integer id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getDataModelNumber() { | ||||
|         return dataModelNumber; | ||||
|     } | ||||
|  | ||||
|     public void setDataModelNumber(String dataModelNumber) { | ||||
|         this.dataModelNumber = dataModelNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataBatchNumber() { | ||||
|         return dataBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public void setDataBatchNumber(String dataBatchNumber) { | ||||
|         this.dataBatchNumber = dataBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataMachineCode() { | ||||
|         return dataMachineCode; | ||||
|     } | ||||
|  | ||||
|     public void setDataMachineCode(String dataMachineCode) { | ||||
|         this.dataMachineCode = dataMachineCode; | ||||
|     } | ||||
|  | ||||
|     public String getProductNumber() { | ||||
|         return productNumber; | ||||
|     } | ||||
|  | ||||
|     public void setProductNumber(String productNumber) { | ||||
|         this.productNumber = productNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataName() { | ||||
|         return dataName; | ||||
|     } | ||||
|  | ||||
|     public void setDataName(String dataName) { | ||||
|         this.dataName = dataName; | ||||
|     } | ||||
|  | ||||
|     public String getNumericalValue() { | ||||
|         return numericalValue; | ||||
|     } | ||||
|  | ||||
|     public void setNumericalValue(String numericalValue) { | ||||
|         this.numericalValue = numericalValue; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "DataSource{" + | ||||
|                 "id=" + id + | ||||
|                 ", dataModelNumber='" + dataModelNumber + '\'' + | ||||
|                 ", dataBatchNumber='" + dataBatchNumber + '\'' + | ||||
|                 ", dataMachineCode='" + dataMachineCode + '\'' + | ||||
|                 ", productNumber='" + productNumber + '\'' + | ||||
|                 ", dataName='" + dataName + '\'' + | ||||
|                 ", numericalValue='" + numericalValue + '\'' + | ||||
|                 '}'; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										135
									
								
								src/main/java/com/xkrs/model/entity/FileEntity.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										135
									
								
								src/main/java/com/xkrs/model/entity/FileEntity.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,135 @@ | ||||
| package com.xkrs.model.entity; | ||||
|  | ||||
| import javax.persistence.*; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:01 | ||||
|  */ | ||||
| @Entity | ||||
| @Table(name = "file") | ||||
| public class FileEntity { | ||||
|     /** | ||||
|      * 主键id | ||||
|      */ | ||||
|     @Id | ||||
|     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "file_seq_gen") | ||||
|     @SequenceGenerator(name = "file_seq_gen", sequenceName = "file_id_seq",allocationSize = 1) | ||||
|     private Integer id; | ||||
|  | ||||
|     /** | ||||
|      * 机种号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String fileModelNumber; | ||||
|  | ||||
|     /** | ||||
|      * 批次号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String fileBatchNumber; | ||||
|  | ||||
|     /** | ||||
|      * 机器号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String fileMachineCode; | ||||
|  | ||||
|     /** | ||||
|      * 产品编号 | ||||
|      */ | ||||
|     @Column(length = 32, columnDefinition = "varchar(32)") | ||||
|     private String fileProductNumber; | ||||
|  | ||||
|     /** | ||||
|      * 上传模板的路径 | ||||
|      */ | ||||
|     private String fileUploadPath; | ||||
|  | ||||
|     /** | ||||
|      * 下载路径 | ||||
|      */ | ||||
|     private String fileDownloadPath; | ||||
|  | ||||
|     public FileEntity() { | ||||
|     } | ||||
|  | ||||
|     public FileEntity(Integer id, String fileModelNumber, String fileBatchNumber, String fileMachineCode, String fileProductNumber, String fileUploadPath, String fileDownloadPath) { | ||||
|         this.id = id; | ||||
|         this.fileModelNumber = fileModelNumber; | ||||
|         this.fileBatchNumber = fileBatchNumber; | ||||
|         this.fileMachineCode = fileMachineCode; | ||||
|         this.fileProductNumber = fileProductNumber; | ||||
|         this.fileUploadPath = fileUploadPath; | ||||
|         this.fileDownloadPath = fileDownloadPath; | ||||
|     } | ||||
|  | ||||
|     public Integer getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(Integer id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getFileModelNumber() { | ||||
|         return fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileModelNumber(String fileModelNumber) { | ||||
|         this.fileModelNumber = fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileBatchNumber() { | ||||
|         return fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileBatchNumber(String fileBatchNumber) { | ||||
|         this.fileBatchNumber = fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileMachineCode() { | ||||
|         return fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public void setFileMachineCode(String fileMachineCode) { | ||||
|         this.fileMachineCode = fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public String getFileProductNumber() { | ||||
|         return fileProductNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileProductNumber(String fileProductNumber) { | ||||
|         this.fileProductNumber = fileProductNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileUploadPath() { | ||||
|         return fileUploadPath; | ||||
|     } | ||||
|  | ||||
|     public void setFileUploadPath(String fileUploadPath) { | ||||
|         this.fileUploadPath = fileUploadPath; | ||||
|     } | ||||
|  | ||||
|     public String getFileDownloadPath() { | ||||
|         return fileDownloadPath; | ||||
|     } | ||||
|  | ||||
|     public void setFileDownloadPath(String fileDownloadPath) { | ||||
|         this.fileDownloadPath = fileDownloadPath; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public String toString() { | ||||
|         return "FileEntity{" + | ||||
|                 "id=" + id + | ||||
|                 ", fileModelNumber='" + fileModelNumber + '\'' + | ||||
|                 ", fileBatchNumber='" + fileBatchNumber + '\'' + | ||||
|                 ", fileMachineCode='" + fileMachineCode + '\'' + | ||||
|                 ", fileProductNumber='" + fileProductNumber + '\'' + | ||||
|                 ", fileUploadPath='" + fileUploadPath + '\'' + | ||||
|                 ", fileDownloadPath='" + fileDownloadPath + '\'' + | ||||
|                 '}'; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										39
									
								
								src/main/java/com/xkrs/model/qo/DataDictQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/main/java/com/xkrs/model/qo/DataDictQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| package com.xkrs.model.qo; | ||||
|  | ||||
| import com.xkrs.model.validation.DataDictQoInsert; | ||||
| import javax.validation.constraints.NotBlank; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:14 | ||||
|  */ | ||||
| public class DataDictQo { | ||||
|  | ||||
|     /** | ||||
|      * 中文名称 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataDict.dictChineseName.blank}",groups={DataDictQoInsert.class}) | ||||
|     private String dictChineseName; | ||||
|  | ||||
|     /** | ||||
|      * 英文变量值 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataDict.dictEnglishName.blank}",groups={DataDictQoInsert.class}) | ||||
|     private String dictEnglishName; | ||||
|  | ||||
|     public String getDictChineseName() { | ||||
|         return dictChineseName; | ||||
|     } | ||||
|  | ||||
|     public void setDictChineseName(String dictChineseName) { | ||||
|         this.dictChineseName = dictChineseName; | ||||
|     } | ||||
|  | ||||
|     public String getDictEnglishName() { | ||||
|         return dictEnglishName; | ||||
|     } | ||||
|  | ||||
|     public void setDictEnglishName(String dictEnglishName) { | ||||
|         this.dictEnglishName = dictEnglishName; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										37
									
								
								src/main/java/com/xkrs/model/qo/DataDictUpdateQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/main/java/com/xkrs/model/qo/DataDictUpdateQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package com.xkrs.model.qo; | ||||
|  | ||||
| import com.xkrs.model.validation.DataDictUpdateQoUpdate; | ||||
|  | ||||
| import javax.validation.constraints.NotBlank; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 11:23 | ||||
|  */ | ||||
| public class DataDictUpdateQo { | ||||
|  | ||||
|     @NotBlank(message = "{DataDict.id.blank}",groups={DataDictUpdateQoUpdate.class}) | ||||
|     private Integer id; | ||||
|  | ||||
|     /** | ||||
|      * 中文名称 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataDict.dictChineseName.blank}",groups={DataDictUpdateQoUpdate.class}) | ||||
|     private String dictChineseName; | ||||
|  | ||||
|     public Integer getId() { | ||||
|         return id; | ||||
|     } | ||||
|  | ||||
|     public void setId(Integer id) { | ||||
|         this.id = id; | ||||
|     } | ||||
|  | ||||
|     public String getDictChineseName() { | ||||
|         return dictChineseName; | ||||
|     } | ||||
|  | ||||
|     public void setDictChineseName(String dictChineseName) { | ||||
|         this.dictChineseName = dictChineseName; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										97
									
								
								src/main/java/com/xkrs/model/qo/DataSourceQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/main/java/com/xkrs/model/qo/DataSourceQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | ||||
| package com.xkrs.model.qo; | ||||
|  | ||||
| import com.xkrs.model.validation.DataDictQoInsert; | ||||
| import com.xkrs.model.validation.DataSourceQoInsert; | ||||
|  | ||||
| import javax.persistence.Column; | ||||
| import javax.validation.constraints.NotBlank; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 16:37 | ||||
|  */ | ||||
| public class DataSourceQo { | ||||
|     /** | ||||
|      * 机种号 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.dataModelNumber.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String dataModelNumber; | ||||
|  | ||||
|     /** | ||||
|      * 批次号 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.dataBatchNumber.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String dataBatchNumber; | ||||
|  | ||||
|     /** | ||||
|      * 机器号 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.dataMachineCode.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String dataMachineCode; | ||||
|  | ||||
|     /** | ||||
|      * 产品编号 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.productNumber.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String productNumber; | ||||
|  | ||||
|     /** | ||||
|      * 变量值 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.dataName.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String dataName; | ||||
|  | ||||
|     /** | ||||
|      * 监测的数值 | ||||
|      */ | ||||
|     @NotBlank(message = "{DataSource.numericalValue.blank}",groups={DataSourceQoInsert.class}) | ||||
|     private String numericalValue; | ||||
|  | ||||
|     public String getDataModelNumber() { | ||||
|         return dataModelNumber; | ||||
|     } | ||||
|  | ||||
|     public void setDataModelNumber(String dataModelNumber) { | ||||
|         this.dataModelNumber = dataModelNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataBatchNumber() { | ||||
|         return dataBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public void setDataBatchNumber(String dataBatchNumber) { | ||||
|         this.dataBatchNumber = dataBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataMachineCode() { | ||||
|         return dataMachineCode; | ||||
|     } | ||||
|  | ||||
|     public void setDataMachineCode(String dataMachineCode) { | ||||
|         this.dataMachineCode = dataMachineCode; | ||||
|     } | ||||
|  | ||||
|     public String getProductNumber() { | ||||
|         return productNumber; | ||||
|     } | ||||
|  | ||||
|     public void setProductNumber(String productNumber) { | ||||
|         this.productNumber = productNumber; | ||||
|     } | ||||
|  | ||||
|     public String getDataName() { | ||||
|         return dataName; | ||||
|     } | ||||
|  | ||||
|     public void setDataName(String dataName) { | ||||
|         this.dataName = dataName; | ||||
|     } | ||||
|  | ||||
|     public String getNumericalValue() { | ||||
|         return numericalValue; | ||||
|     } | ||||
|  | ||||
|     public void setNumericalValue(String numericalValue) { | ||||
|         this.numericalValue = numericalValue; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										81
									
								
								src/main/java/com/xkrs/model/qo/FileQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								src/main/java/com/xkrs/model/qo/FileQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,81 @@ | ||||
| package com.xkrs.model.qo; | ||||
|  | ||||
| import com.xkrs.model.validation.FileQoInsert; | ||||
| import javax.validation.constraints.NotBlank; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:26 | ||||
|  */ | ||||
| public class FileQo { | ||||
|  | ||||
|     /** | ||||
|      * 机种号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileModelNumber.blank}",groups={FileQoInsert.class}) | ||||
|     private String fileModelNumber; | ||||
|  | ||||
|     /** | ||||
|      * 批次号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileBatchNumber.blank}",groups={FileQoInsert.class}) | ||||
|     private String fileBatchNumber; | ||||
|  | ||||
|     /** | ||||
|      * 机器号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileMachineCode.blank}",groups={FileQoInsert.class}) | ||||
|     private String fileMachineCode; | ||||
|  | ||||
|     /** | ||||
|      * 产品编号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileProductNumber.blank}",groups={FileQoInsert.class}) | ||||
|     private String fileProductNumber; | ||||
|  | ||||
|     /** | ||||
|      * 上传模板的路径 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileUploadPath.blank}",groups={FileQoInsert.class}) | ||||
|     private String fileUploadPath; | ||||
|  | ||||
|     public String getFileModelNumber() { | ||||
|         return fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileModelNumber(String fileModelNumber) { | ||||
|         this.fileModelNumber = fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileBatchNumber() { | ||||
|         return fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileBatchNumber(String fileBatchNumber) { | ||||
|         this.fileBatchNumber = fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileMachineCode() { | ||||
|         return fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public void setFileMachineCode(String fileMachineCode) { | ||||
|         this.fileMachineCode = fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public String getFileProductNumber() { | ||||
|         return fileProductNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileProductNumber(String fileProductNumber) { | ||||
|         this.fileProductNumber = fileProductNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileUploadPath() { | ||||
|         return fileUploadPath; | ||||
|     } | ||||
|  | ||||
|     public void setFileUploadPath(String fileUploadPath) { | ||||
|         this.fileUploadPath = fileUploadPath; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										69
									
								
								src/main/java/com/xkrs/model/qo/FileUpdateQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								src/main/java/com/xkrs/model/qo/FileUpdateQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,69 @@ | ||||
| package com.xkrs.model.qo; | ||||
|  | ||||
|  | ||||
| import com.xkrs.model.validation.FileUpdateQoUpdate; | ||||
|  | ||||
| import javax.validation.constraints.NotBlank; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 16:20 | ||||
|  */ | ||||
| public class FileUpdateQo { | ||||
|  | ||||
|     /** | ||||
|      * 机种号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileModelNumber.blank}",groups={FileUpdateQoUpdate.class}) | ||||
|     private String fileModelNumber; | ||||
|  | ||||
|     /** | ||||
|      * 批次号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileBatchNumber.blank}",groups={FileUpdateQoUpdate.class}) | ||||
|     private String fileBatchNumber; | ||||
|  | ||||
|     /** | ||||
|      * 机器号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileMachineCode.blank}",groups={FileUpdateQoUpdate.class}) | ||||
|     private String fileMachineCode; | ||||
|  | ||||
|     /** | ||||
|      * 产品编号 | ||||
|      */ | ||||
|     @NotBlank(message = "{FileEntity.fileProductNumber.blank}",groups={FileUpdateQoUpdate.class}) | ||||
|     private String fileProductNumber; | ||||
|  | ||||
|     public String getFileModelNumber() { | ||||
|         return fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileModelNumber(String fileModelNumber) { | ||||
|         this.fileModelNumber = fileModelNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileBatchNumber() { | ||||
|         return fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileBatchNumber(String fileBatchNumber) { | ||||
|         this.fileBatchNumber = fileBatchNumber; | ||||
|     } | ||||
|  | ||||
|     public String getFileMachineCode() { | ||||
|         return fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public void setFileMachineCode(String fileMachineCode) { | ||||
|         this.fileMachineCode = fileMachineCode; | ||||
|     } | ||||
|  | ||||
|     public String getFileProductNumber() { | ||||
|         return fileProductNumber; | ||||
|     } | ||||
|  | ||||
|     public void setFileProductNumber(String fileProductNumber) { | ||||
|         this.fileProductNumber = fileProductNumber; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:22 | ||||
|  */ | ||||
| public interface DataDictQoInsert { | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 11:23 | ||||
|  */ | ||||
| public interface DataDictUpdateQoUpdate { | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 16:39 | ||||
|  */ | ||||
| public interface DataSourceQoInsert { | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:26 | ||||
|  */ | ||||
| public interface FileQoInsert { | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 16:21 | ||||
|  */ | ||||
| public interface FileUpdateQoUpdate { | ||||
| } | ||||
							
								
								
									
										18
									
								
								src/main/java/com/xkrs/service/DataDictService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/main/java/com/xkrs/service/DataDictService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| package com.xkrs.service; | ||||
|  | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import com.xkrs.model.qo.DataDictQo; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:10 | ||||
|  */ | ||||
| public interface DataDictService { | ||||
|  | ||||
|     /** | ||||
|      * 添加字典数据 | ||||
|      * @param dataDictQo | ||||
|      * @return | ||||
|      */ | ||||
|     String insertDataDict(DataDictQo dataDictQo); | ||||
| } | ||||
							
								
								
									
										17
									
								
								src/main/java/com/xkrs/service/DataSourceService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/main/java/com/xkrs/service/DataSourceService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| package com.xkrs.service; | ||||
|  | ||||
| import com.xkrs.model.qo.DataSourceQo; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 16:42 | ||||
|  */ | ||||
| public interface DataSourceService { | ||||
|  | ||||
|     /** | ||||
|      * 添加测量数据 | ||||
|      * @param dataSourceQo | ||||
|      * @return | ||||
|      */ | ||||
|     String insertDataSource(DataSourceQo dataSourceQo); | ||||
| } | ||||
							
								
								
									
										29
									
								
								src/main/java/com/xkrs/service/FileService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								src/main/java/com/xkrs/service/FileService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| package com.xkrs.service; | ||||
|  | ||||
| import com.xkrs.model.qo.FileQo; | ||||
| import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
|  | ||||
| import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:24 | ||||
|  */ | ||||
| public interface FileService { | ||||
|  | ||||
|     /** | ||||
|      * 添加模板信息 | ||||
|      * @param fileQo | ||||
|      * @return | ||||
|      */ | ||||
|     String insertFileExcel(FileQo fileQo,MultipartFile fileExcel) throws IOException; | ||||
|  | ||||
|     /** | ||||
|      * 导出excel | ||||
|      * @param fileQo | ||||
|      * @return | ||||
|      */ | ||||
|     String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException; | ||||
| } | ||||
							
								
								
									
										50
									
								
								src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/main/java/com/xkrs/service/impl/DataDictServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | ||||
| package com.xkrs.service.impl; | ||||
|  | ||||
| import com.xkrs.dao.DataDictDao; | ||||
| import com.xkrs.encapsulation.PromptMessageEnum; | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import com.xkrs.model.qo.DataDictQo; | ||||
| import com.xkrs.service.DataDictService; | ||||
| import org.springframework.context.i18n.LocaleContextHolder; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.Locale; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:28 | ||||
|  */ | ||||
| @Service | ||||
| public class DataDictServiceImpl implements DataDictService { | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictDao dataDictDao; | ||||
|  | ||||
|     /** | ||||
|      * 添加字典数据 | ||||
|      * @param dataDictQo | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public String insertDataDict(DataDictQo dataDictQo) { | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         //DataDict byDictChineseName = dataDictDao.findByDictChineseName(dataDictQo.getDictChineseName()); | ||||
|         /*DataDict chineseName = dataDictDao.findByModelNumberAndBatchNumberAndMachineCodeAndDictProductNumberAndDictChineseName(dataDictQo.getModelNumber(), dataDictQo.getBatchNumber(), dataDictQo.getMachineCode(), dataDictQo.getDictProductNumber(), dataDictQo.getDictChineseName()); | ||||
|         if(chineseName != null){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该产品变量已存在,请勿重复添加!",locale); | ||||
|         }*/ | ||||
|         //DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataDictQo.getDictEnglishName()); | ||||
|         DataDict englishName = dataDictDao.findByDictEnglishName(dataDictQo.getDictEnglishName()); | ||||
|         if(englishName != null){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该产品变量已存在,请勿重复添加!",locale); | ||||
|         } | ||||
|         DataDict dataDict = new DataDict(); | ||||
|         dataDict.setDictChineseName(dataDictQo.getDictChineseName()); | ||||
|         dataDict.setDictEnglishName(dataDictQo.getDictEnglishName()); | ||||
|         dataDictDao.save(dataDict); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功!",locale); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,57 @@ | ||||
| package com.xkrs.service.impl; | ||||
|  | ||||
| import com.xkrs.dao.DataDictDao; | ||||
| import com.xkrs.dao.DataSourceDao; | ||||
| import com.xkrs.encapsulation.PromptMessageEnum; | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import com.xkrs.model.entity.DataSource; | ||||
| import com.xkrs.model.qo.DataSourceQo; | ||||
| import com.xkrs.service.DataSourceService; | ||||
| import org.springframework.context.i18n.LocaleContextHolder; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.util.Locale; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 16:43 | ||||
|  */ | ||||
| @Service | ||||
| public class DataSourceServiceImpl implements DataSourceService { | ||||
|  | ||||
|     @Resource | ||||
|     private DataSourceDao dataSourceDao; | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictDao dataDictDao; | ||||
|  | ||||
|     /** | ||||
|      * 添加测量数据 | ||||
|      * @param dataSourceQo | ||||
|      * @return | ||||
|      */ | ||||
|     @Override | ||||
|     public String insertDataSource(DataSourceQo dataSourceQo) { | ||||
|         Locale locale = LocaleContextHolder.getLocale(); | ||||
|         DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataSourceQo.getDataName()); | ||||
|         if(byDictEnglishName == null){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"不存在该字典类型!",locale); | ||||
|         } | ||||
|         /*DataSource byDataName = dataSourceDao.findByDataName(dataSourceQo.getDataName()); | ||||
|         if(byDataName != null){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该字典类型数据已添加,请勿重复添加!",locale); | ||||
|         }*/ | ||||
|         DataSource dataSource = new DataSource(); | ||||
|         dataSource.setDataModelNumber(dataSourceQo.getDataModelNumber()); | ||||
|         dataSource.setDataBatchNumber(dataSourceQo.getDataBatchNumber()); | ||||
|         dataSource.setDataMachineCode(dataSourceQo.getDataMachineCode()); | ||||
|         dataSource.setProductNumber(dataSourceQo.getProductNumber()); | ||||
|         dataSource.setDataName(dataSourceQo.getDataName()); | ||||
|         dataSource.setNumericalValue(dataSourceQo.getNumericalValue()); | ||||
|         dataSourceDao.save(dataSource); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功!",locale); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										97
									
								
								src/main/java/com/xkrs/service/impl/FileServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								src/main/java/com/xkrs/service/impl/FileServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | ||||
| package com.xkrs.service.impl; | ||||
|  | ||||
| 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.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; | ||||
| 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; | ||||
| import java.util.List; | ||||
| import java.util.Locale; | ||||
| import java.util.Map; | ||||
|  | ||||
| import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/20 15:24 | ||||
|  */ | ||||
| @Service | ||||
| public class FileServiceImpl implements FileService { | ||||
|  | ||||
|     @Resource | ||||
|     private FileDao fileDao; | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictDao dataDictDao; | ||||
|  | ||||
|     @Resource | ||||
|     private DataSourceDao dataSourceDao; | ||||
|  | ||||
|     /** | ||||
|      * 添加模板信息 | ||||
|      * @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); | ||||
|         } | ||||
|         if(fileExcel == null){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"模板不能为空!",locale); | ||||
|         } | ||||
|         String file = ExcelUploadUtil.memoryFile(fileExcel); | ||||
|         FileEntity fileEntity1 = new FileEntity(); | ||||
|         fileEntity1.setFileModelNumber(fileQo.getFileModelNumber()); | ||||
|         fileEntity1.setFileBatchNumber(fileQo.getFileBatchNumber()); | ||||
|         fileEntity1.setFileMachineCode(fileQo.getFileMachineCode()); | ||||
|         fileEntity1.setFileProductNumber(fileQo.getFileProductNumber()); | ||||
|         fileEntity1.setFileUploadPath(file); | ||||
|  | ||||
|         fileDao.save(fileEntity1); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功!",locale); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 导出excel | ||||
|      * @param fileQo | ||||
|      * @return | ||||
|      */ | ||||
|     @Transactional(rollbackOn = Exception.class) | ||||
|     @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); | ||||
|         } | ||||
|         String fileUploadPath = entity.getFileUploadPath(); | ||||
|         List<Map<String, String>> maps = dataSourceDao.selectDataNameAndData(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); | ||||
|         if(maps == null || maps.size() == 0){ | ||||
|             return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时没有该产品的信息!",locale); | ||||
|         } | ||||
|         Map<String,String> map = new HashMap<String,String>(); | ||||
|         for(Map<String,String> stringMap : maps){ | ||||
|             map.put(stringMap.get("dataname"),stringMap.get("numericalvalue")); | ||||
|         } | ||||
|         String fill = ExportExcel.exportToProveExcel(map,fileUploadPath); | ||||
|         fileDao.updateFileDownloadPath(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber(),fill); | ||||
|         return outputEncapsulationObject(PromptMessageEnum.SUCCESS,fill,locale); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										191
									
								
								src/main/java/com/xkrs/util/ExcelUploadUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										191
									
								
								src/main/java/com/xkrs/util/ExcelUploadUtil.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,191 @@ | ||||
| package com.xkrs.util; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.net.URL; | ||||
| import java.util.ArrayList; | ||||
| import java.util.Date; | ||||
| import java.util.List; | ||||
| import java.util.UUID; | ||||
|  | ||||
| /** | ||||
|  * @author XinYi Song | ||||
|  */ | ||||
| public class ExcelUploadUtil { | ||||
|  | ||||
|     public static Logger log = LoggerFactory.getLogger(ExcelUploadUtil.class); | ||||
|  | ||||
|     /** | ||||
|      * 上传单张图片 | ||||
|      * @param fileExcel | ||||
|      * @return | ||||
|      * @throws IOException | ||||
|      */ | ||||
|     public static String memoryFile(MultipartFile fileExcel) throws IOException { | ||||
|         //String uploadPath = "http://139.199.98.175:2088/wfTaskImage/"; | ||||
|         String uploadPath = "http://192.168.2.9:2088/"; | ||||
|         //获取原始文件名 | ||||
|         String originalFilename = fileExcel.getOriginalFilename(); | ||||
|         if (originalFilename != null && !"".equals(originalFilename)) { | ||||
|             //找到 . 的位置 | ||||
|             int index = originalFilename.lastIndexOf("."); | ||||
|             //根据 . 的位置进行分割,拿到文件后缀名 | ||||
|             String suffix = originalFilename.substring(index); | ||||
|             //uuid生成新的文件名 | ||||
|             String newName = UUID.randomUUID().toString() + suffix; | ||||
|  | ||||
|             //将图片保存到本地/usr/etc/images/Folder | ||||
|             //File file = new File("E:/shoptest/"); | ||||
|             File file = new File("/home/sxy/server/industrial_measurement/excel/"); | ||||
|             if (!file.exists()) { | ||||
|                 file.mkdirs(); | ||||
|             } | ||||
|             //String path = "E:/shoptest/" + newName; | ||||
|             String path = "/home/sxy/server/industrial_measurement/excel/" + newName; | ||||
|             String uploadsImage = uploadPath + newName; | ||||
|             //实现上传 | ||||
|             fileExcel.transferTo(new File(path)); | ||||
|  | ||||
|  | ||||
|             return path; | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 以文件形式,批量上传图片 | ||||
|      * @param files | ||||
|      * @return | ||||
|      * @throws IOException | ||||
|      */ | ||||
|     /*public static List<FireTaskPhoto> uploadImage(MultipartFile[] files, String fireCode) throws IOException { | ||||
|         //String uploadPath = "http://139.199.98.175:2099/forestTaskImage/"; | ||||
|         String uploadPath = "http://118.24.27.47:2088/"; | ||||
|         String newName = ""; | ||||
|         String oldName = ""; | ||||
|         List<FireTaskPhoto> fireTaskPhotos = new ArrayList<>(); | ||||
|         for(MultipartFile file : files){ | ||||
|             //获取file图片名称 | ||||
|             oldName = file.getOriginalFilename(); | ||||
|             //找到 . 的位置 | ||||
|             int index = oldName.lastIndexOf("."); | ||||
|             //根据 . 的位置进行分割,拿到文件后缀名 | ||||
|             String suffix = oldName.substring(index); | ||||
|             //uuid生成新的文件名 | ||||
|             newName = UUID.randomUUID().toString() + suffix; | ||||
|             //将图片保存到本地/usr/etc/images/Folder | ||||
|             File file1 = new File("/home/sxy/server/fire_point/firePointImage/"); | ||||
|             //File file1 = new File("E:/file/work/image/"); | ||||
|             if (!file1.exists()) { | ||||
|                 file1.mkdirs(); | ||||
|             } | ||||
|             String path = "/home/sxy/server/fire_point/firePointImage/" + newName; | ||||
|             //String path = "E:/file/work/image/" + newName; | ||||
|             String uploadPaths = "/firePointImage/" + newName; | ||||
|             //实现上传 | ||||
|             file.transferTo(new File(path)); | ||||
|             FireTaskPhoto fireTaskPhoto = new FireTaskPhoto(); | ||||
|             fireTaskPhoto.setPhotoFireCode(fireCode); | ||||
|             fireTaskPhoto.setTaskPhoto(uploadPaths); | ||||
|  | ||||
|             fireTaskPhotos.add(fireTaskPhoto); | ||||
|         } | ||||
|         return fireTaskPhotos; | ||||
|     }*/ | ||||
|  | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * 删除本地或服务器储存的图片 | ||||
|      * @param path | ||||
|      * @return | ||||
|      */ | ||||
|     public static String delFile(String path){ | ||||
|         String resultInfo = null; | ||||
|         int lastIndexOf = path.lastIndexOf("/"); | ||||
|         String imgPath = path.substring(lastIndexOf + 1,path.length()); | ||||
|         System.out.println(imgPath); | ||||
|         imgPath = "/usr/local/etc/images/" + imgPath; | ||||
| //        img_path = "/usr/etc/images/Folder/" + img_path; | ||||
|         File file = new File(imgPath); | ||||
|         if(file.exists()){ | ||||
|             if(file.delete()){ | ||||
|                 resultInfo = "删除成功!"; | ||||
|             }else { | ||||
|                 resultInfo = "删除失败!"; | ||||
|             } | ||||
|         }else { | ||||
|             resultInfo = "文件不存在"; | ||||
|         } | ||||
|         return resultInfo; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 通过图片路径解析 ,上传保存 | ||||
|      * @param listImgSrc | ||||
|      * @return | ||||
|      */ | ||||
|     public static List downloadImage(List<String> listImgSrc) { | ||||
|         try { | ||||
|             List list = new ArrayList(); | ||||
|             //开始时间 | ||||
|             Date beginDate = new Date(); | ||||
|             for (String url : listImgSrc) { | ||||
|                 //开始时间 | ||||
|                 Date beginDate2 = new Date(); | ||||
|                 String imageName = url.substring(url.lastIndexOf("/") + 1, url.length()); | ||||
|                 URL uri = new URL(url); | ||||
|                 InputStream in = uri.openStream(); | ||||
|                 //String pathUpload = "E:/img/" + imageName; | ||||
|                 String pathUpload = "/home/web/wf-fire-service/wfimage/" + imageName; | ||||
|                 FileOutputStream fo = new FileOutputStream(new File(pathUpload)); | ||||
|                 byte[] buf = new byte[1024]; | ||||
|                 int length = 0; | ||||
|                 log.info("-------开始下载:" + url); | ||||
|                 while ((length = in.read(buf, 0, buf.length)) != -1) { | ||||
|                     fo.write(buf, 0, length); | ||||
|                 } | ||||
|                 in.close(); | ||||
|                 fo.close(); | ||||
|                 list.add(imageName); | ||||
|                 log.info(imageName + "------下载完成"); | ||||
|                 //结束时间 | ||||
|                 Date overDate2 = new Date(); | ||||
|                 double time = overDate2.getTime() - beginDate2.getTime(); | ||||
|                 log.info("-----耗时:" + time / 1000 + "s"); | ||||
|             } | ||||
|             Date overDate = new Date(); | ||||
|             double time = overDate.getTime() - beginDate.getTime(); | ||||
|             log.info("======总耗时:" + time / 1000 + "s"); | ||||
|             return list; | ||||
|         } catch (Exception e) { | ||||
|             log.info("++++++下载失败"); | ||||
|         } | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 删除本地文件夹图片 | ||||
|      * @param url | ||||
|      */ | ||||
|     public static void deleteImage(String url){ | ||||
|         File file=new File(url); | ||||
|         //判断file是否是文件目录 若是返回TRUE | ||||
|         if (file.isDirectory()){ | ||||
|             //name存储file文件夹中的文件名 | ||||
|             String[] name =file.list(); | ||||
|             for (int i=0; i<name.length; i++){ | ||||
|                 //此时就可得到文件夹中的文件 | ||||
|                 File f=new File(url, name[i]); | ||||
|                 //删除文件 | ||||
|                 f.delete(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										68
									
								
								src/main/java/com/xkrs/util/ExportExcel.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								src/main/java/com/xkrs/util/ExportExcel.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,68 @@ | ||||
| package com.xkrs.util; | ||||
|  | ||||
| import net.sf.jxls.transformer.XLSTransformer; | ||||
| import org.apache.poi.openxml4j.exceptions.InvalidFormatException; | ||||
| import java.io.*; | ||||
| import java.util.Map; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/17 8:56 | ||||
|  */ | ||||
| public class ExportExcel { | ||||
|  | ||||
|     /** | ||||
|      * 最简单的填充 | ||||
|      * | ||||
|      * @since 2.1.1 | ||||
|      */ | ||||
|     /*public static String simpleFill(Map<String, String> map,String templateFileName) { | ||||
|  | ||||
|  | ||||
|         String s = System.currentTimeMillis() + ".xlsx"; | ||||
|         // 方案2 根据Map填充 | ||||
|         String fileName = "/usr/local/excel/" + s; | ||||
|         //String fileName = "E:\\shoptest\\" + s; | ||||
|         // 这里 会填充到第一个sheet, 然后文件流会自动关闭 | ||||
|  | ||||
|         ExcelWriterBuilder write = EasyExcel.write(fileName); | ||||
|  | ||||
|         ExcelWriterBuilder excelWriterBuilder = write.withTemplate(templateFileName); | ||||
|  | ||||
|         ExcelWriter build = excelWriterBuilder.build(); | ||||
|         WriteSheet writeSheet = EasyExcel.writerSheet().build(); | ||||
|  | ||||
|         build.fill(map,writeSheet); | ||||
|         build.finish(); | ||||
|  | ||||
|         //EasyExcel.write(fileName).withTemplate(templateFileName).sheet().doFill(map); | ||||
|         return "http://118.24.27.47:2088/excel/"+s; | ||||
|         //return "http://192.168.2.139/"+s; | ||||
|     }*/ | ||||
|  | ||||
|  | ||||
|     public static String exportToProveExcel(Map<String, String> dataMap, String srcFilePath) throws IOException, InvalidFormatException { | ||||
|         String s = System.currentTimeMillis() + ".xlsx"; | ||||
|         //String path = "E:/shop/"+s; | ||||
|         String path = "/home/sxy/server/industrial_measurement/excel/" + s; | ||||
|  | ||||
|         //  开始转换。利用  transformer 转到Excel | ||||
|         XLSTransformer transformer = new XLSTransformer(); | ||||
|         // 参数:srcFilePath:模板源文件    cMap:需要导出的数据   destFile.getAbsolutePath():下载的目标文件 | ||||
|         transformer.transformXLS(srcFilePath, dataMap, path); | ||||
|         //return "http://192.168.2.139/"+s; | ||||
|         return "http://118.24.27.47:2088/excel/"+s; | ||||
|     } | ||||
|  | ||||
|     /*public static void main(String[] args) throws IOException, InvalidFormatException { | ||||
|         // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替 | ||||
|         String templateFileName = TestFileUtil.getPath() + "templates" + File.separator + "test.xlsx"; | ||||
|         Map<String, String> map = new HashMap<String, String>(); | ||||
|         map.put("name", "张三"); | ||||
|         map.put("sex", "男"); | ||||
|         //simpleFill(map,templateFileName); | ||||
|         HttpServletResponse response = null; | ||||
|         String s = exportToProveExcel(map); | ||||
|         System.out.println(s); | ||||
|     }*/ | ||||
| } | ||||
							
								
								
									
										48
									
								
								src/main/java/com/xkrs/util/Query.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/main/java/com/xkrs/util/Query.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| package com.xkrs.util; | ||||
|  | ||||
| import com.xkrs.dao.DataDictDao; | ||||
| import com.xkrs.model.entity.DataDict; | ||||
| import org.springframework.data.jpa.domain.Specification; | ||||
| import org.springframework.stereotype.Component; | ||||
| import org.springframework.web.bind.annotation.RequestParam; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import javax.persistence.criteria.CriteriaBuilder; | ||||
| import javax.persistence.criteria.CriteriaQuery; | ||||
| import javax.persistence.criteria.Predicate; | ||||
| import javax.persistence.criteria.Root; | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 13:56 | ||||
|  */ | ||||
| @Component | ||||
| public class Query { | ||||
|  | ||||
|     @Resource | ||||
|     private DataDictDao dataDictDao; | ||||
|  | ||||
|     /** | ||||
|      * 动态多条件查询字典信息 | ||||
|      * @return | ||||
|      */ | ||||
|     public List<DataDict> selectDataDict(String dictChineseName,String dictEnglishName) { | ||||
|         Specification<DataDict> specification = new Specification<DataDict>() { | ||||
|             @Override | ||||
|             public Predicate toPredicate(Root<DataDict> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { | ||||
|                 List<Predicate> list = new ArrayList<>(); | ||||
|                 if(dictChineseName != null && !"".equals(dictChineseName)){ | ||||
|                     list.add(criteriaBuilder.equal(root.get("dictChineseName").as(String.class), dictChineseName)); | ||||
|                 } | ||||
|                 if(dictEnglishName != null && !"".equals(dictEnglishName)){ | ||||
|                     list.add(criteriaBuilder.equal(root.get("dictEnglishName").as(String.class), dictEnglishName)); | ||||
|                 } | ||||
|                 Predicate[] predicates = new Predicate[list.size()]; | ||||
|                 return criteriaBuilder.and(list.toArray(predicates)); | ||||
|             } | ||||
|         }; | ||||
|         return dataDictDao.findAll(specification); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										38
									
								
								src/main/java/com/xkrs/util/TestFileUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/main/java/com/xkrs/util/TestFileUtil.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| package com.xkrs.util; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.InputStream; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/17 9:29 | ||||
|  */ | ||||
| public class TestFileUtil { | ||||
|     public static InputStream getResourcesFileInputStream(String fileName) { | ||||
|         return Thread.currentThread().getContextClassLoader().getResourceAsStream("" + fileName); | ||||
|     } | ||||
|  | ||||
|     public static String getPath() { | ||||
|         return TestFileUtil.class.getResource("/").getPath(); | ||||
|     } | ||||
|  | ||||
|     public static File createNewFile(String pathName) { | ||||
|         File file = new File(getPath() + pathName); | ||||
|         if (file.exists()) { | ||||
|             file.delete(); | ||||
|         } else { | ||||
|             if (!file.getParentFile().exists()) { | ||||
|                 file.getParentFile().mkdirs(); | ||||
|             } | ||||
|         } | ||||
|         return file; | ||||
|     } | ||||
|  | ||||
|     public static File readFile(String pathName) { | ||||
|         return new File(getPath() + pathName); | ||||
|     } | ||||
|  | ||||
|     public static File readUserHomeFile(String pathName) { | ||||
|         return new File(System.getProperty("user.home") + File.separator + pathName); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user