更新数据表

This commit is contained in:
liuchengqian 2022-03-01 09:12:50 +08:00
parent 9d463735c6
commit 480e505396
9 changed files with 110 additions and 122 deletions

View File

@ -14,6 +14,7 @@ import javax.annotation.Resource;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -68,7 +69,7 @@ public class DataDictController {
@GetMapping("/selectDataDictById") @GetMapping("/selectDataDictById")
public String selectDataDictById(@RequestParam("id") Integer id){ public String selectDataDictById(@RequestParam("id") Integer id){
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
DataDict dataDict = dataDictDao.findById(id); DataDict dataDict = dataDictDao.findById(id).get();
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale);
} }

View File

@ -2,6 +2,7 @@ package com.xkrs.controller;
import com.xkrs.dao.DataSourceDao; import com.xkrs.dao.DataSourceDao;
import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.DataSource;
import com.xkrs.model.qo.DataSourceQo; import com.xkrs.model.qo.DataSourceQo;
import com.xkrs.service.DataSourceService; import com.xkrs.service.DataSourceService;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
@ -29,6 +30,7 @@ public class DataSourceController {
/** /**
* 添加测量数据 * 添加测量数据
*
* @param dataSourceQo * @param dataSourceQo
* @return * @return
*/ */
@ -39,36 +41,39 @@ public class DataSourceController {
/** /**
* 查询某一产品的测量信息 * 查询某一产品的测量信息
* @param dataModelNumber * @param lotNo 批次号
* @param dataBatchNumber * @param machineNo 机器号
* @param dataMachineCode * @param materialNo 物料号
* @param productNumber * @param modelNo 模具号
* @param partNo 零件号
* @return * @return
*/ */
@GetMapping("/selectDataSource") @GetMapping("/selectDataSource")
public String selectDataSource(@RequestParam("dataModelNumber") String dataModelNumber, public String selectDataSource(@RequestParam("lotNo") String lotNo,
@RequestParam("dataBatchNumber") String dataBatchNumber, @RequestParam("machineNo") String machineNo,
@RequestParam("dataMachineCode") String dataMachineCode, @RequestParam("materialNo") String materialNo,
@RequestParam("productNumber") String productNumber){ @RequestParam("modelNo") String modelNo,
@RequestParam("partNo") String partNo) {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
List<Map<String, String>> maps = dataSourceDao.selectDataSource(dataModelNumber, dataBatchNumber, dataMachineCode, productNumber); List<DataSource> dataSources = dataSourceDao.selectDataSource(lotNo, machineNo, materialNo, modelNo, partNo);
if(maps == null || maps.size() == 0){ if (dataSources == null || dataSources.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale);
} }
/** /**
* 查询全部的测量信息 * 查询全部的测量信息
*
* @return * @return
*/ */
@GetMapping("/selectAllSource") @GetMapping("/selectAllSource")
public String selectAllSource() { public String selectAllSource() {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
List<Map<String, String>> maps = dataSourceDao.selectAllSource(); List<DataSource> dataSources = dataSourceDao.selectAllSource();
if(maps == null || maps.size() == 0){ if (dataSources == null || dataSources.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale);
} }
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,maps,locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale);
} }
} }

View File

@ -8,11 +8,13 @@ import com.xkrs.service.FileService;
import com.xkrs.util.ExcelUploadUtil; import com.xkrs.util.ExcelUploadUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
@ -34,6 +36,7 @@ public class FileController {
/** /**
* 上传模板信息 * 上传模板信息
*
* @param fileQo * @param fileQo
* @param fileExcel * @param fileExcel
* @return * @return
@ -46,6 +49,7 @@ public class FileController {
/** /**
* 修改上传的模板信息 * 修改上传的模板信息
*
* @param fileUpdateQo * @param fileUpdateQo
* @param fileExcel * @param fileExcel
* @return * @return
@ -56,7 +60,7 @@ public class FileController {
public String updateFileUploadPath(FileUpdateQo fileUpdateQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException { public String updateFileUploadPath(FileUpdateQo fileUpdateQo, @RequestParam("fileExcel") MultipartFile fileExcel) throws IOException {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
String file = ExcelUploadUtil.memoryFile(fileExcel); String file = ExcelUploadUtil.memoryFile(fileExcel);
fileDao.updateFileUploadPath(fileUpdateQo.getFileModelNumber(),fileUpdateQo.getFileBatchNumber(),fileUpdateQo.getFileMachineCode(),fileUpdateQo.getFileProductNumber(),file); fileDao.updateFileUploadPath(fileUpdateQo.getLotNo(), fileUpdateQo.getMachineNo(), fileUpdateQo.getMaterialNo(), fileUpdateQo.getModelNo(), fileUpdateQo.getPartNo(), file);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
} }

View File

@ -8,6 +8,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Optional;
/** /**
* @Author: XinYi Song * @Author: XinYi Song
@ -17,25 +18,18 @@ import java.util.List;
public interface DataDictDao extends JpaRepository<DataDict,Long>, JpaSpecificationExecutor<DataDict> { public interface DataDictDao extends JpaRepository<DataDict,Long>, JpaSpecificationExecutor<DataDict> {
/** /**
* 通过中文名称查询字典表数据 * 通过质检项代码查询字典表的数据
* @param chineseName * @param inspectionItemCode
* @return * @return
*/ */
DataDict findByDictChineseName(String chineseName); Optional<DataDict> findByInspectionItemCode(String inspectionItemCode);
/**
* 通过英文变量查询字典表的数据
* @param englishName
* @return
*/
DataDict findByDictEnglishName(String englishName);
/** /**
* 根据id查询字典信息 * 根据id查询字典信息
* @param id * @param id
* @return * @return
*/ */
DataDict findById(Integer id); Optional<DataDict> findById(Integer id);
/** /**
* 根据id修改字典的信息 * 根据id修改字典的信息

View File

@ -7,7 +7,7 @@ import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Optional;
/** /**
* @Author: XinYi Song * @Author: XinYi Song
@ -18,47 +18,22 @@ public interface DataSourceDao extends JpaRepository<DataSource,Long>, JpaSpecif
/** /**
* 查询测量数据信息 * 查询测量数据信息
* @param dataModelNumber *
* @param dataBatchNumber * @param lotNo 批次号
* @param dataMachineCode * @param machineNo 机器号
* @param productNumber * @param materialNo 物料号
* @param modelNo 模具号
* @param partNo 零件号
* @return * @return
*/ */
@Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + @Query(value = "SELECT * FROM qc_inspection_data_source WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true)
"ds.data_machine_code datamachinecode, ds.product_number productnumber, ds.material material, dd.dict_chinese_name chinesename, " + List<DataSource> selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo);
"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 * @return
*/ */
@Query(value = "select ds.data_model_number datamodelnumber, ds.data_batch_number databatchnumber, " + @Query(value = "SELECT * FROM qc_inspection_data_source", nativeQuery = true)
"ds.data_machine_code datamachinecode, ds.product_number productnumber, ds.material material, dd.dict_chinese_name chinesename," + List<DataSource> selectAllSource();
"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();
} }

View File

@ -15,38 +15,45 @@ import org.springframework.stereotype.Component;
public interface FileDao extends JpaRepository<FileEntity, Long>, JpaSpecificationExecutor<FileEntity> { public interface FileDao extends JpaRepository<FileEntity, Long>, JpaSpecificationExecutor<FileEntity> {
/** /**
* 根据机种号批次号机器号产品号查询文件信息 * 查询文件信息
* @param fileModelNumber *
* @param fileBatchNumber * @param lotNo 批次号
* @param fileMachineCode * @param machineNo 机器号
* @param fileProductNumber * @param materialNo 物料号
* @param modelNo 模具号
* @param partNo 零件号
* @return * @return
*/ */
FileEntity findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber); @Query(value = "SELECT * FROM qc_inspection_file WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true)
FileEntity selectFile(String lotNo, String machineNo, String materialNo, String modelNo, String partNo);
/** /**
* 根据机种号批次号机器号产品号修改模板上传信息 * 修改模板上传信息
* @param fileModelNumber *
* @param fileBatchNumber * @param lotNo 批次号
* @param fileMachineCode * @param machineNo 机器号
* @param fileProductNumber * @param materialNo 物料号
* @param fileUploadPath * @param modelNo 模具号
* @param partNo 零件号
* @param fileUploadPath 模板路径
*/ */
@Modifying(clearAutomatically = true) @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) @Query(value = "UPDATE qc_inspection_file SET file_upload_path = ?6 WHERE lot_no = ?1 AND machine_no = ?2 AND material_no = ?3 AND model_no = ?4 AND part_no = ?5 ", nativeQuery = true)
void updateFileUploadPath(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber,String fileUploadPath); void updateFileUploadPath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String fileUploadPath);
/** /**
* 根据机种号批次号机器号产品号修改模板下载信息 * 修改文件下载信息
* @param fileModelNumber *
* @param fileBatchNumber * @param lotNo 批次号
* @param fileMachineCode * @param machineNo 机器号
* @param fileProductNumber * @param materialNo 物料号
* @param fileDownloadPath * @param modelNo 模具号
* @param partNo 零件号
* @param fileDownloadPath 文件下载路径
*/ */
@Modifying(clearAutomatically = true) @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) @Query(value = "UPDATE qc_inspection_file SET file_download_path = ?6 WHERE lot_no = ?1 AND machine_no = ?2 AND material_no = ?3 AND model_no = ?4 AND part_no = ?5 ", nativeQuery = true)
void updateFileDownloadPath(String fileModelNumber,String fileBatchNumber,String fileMachineCode,String fileProductNumber,String fileDownloadPath); void updateFileDownloadPath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String fileDownloadPath);
} }

View File

@ -38,8 +38,8 @@ public class DataDictServiceImpl implements DataDictService {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该产品变量已存在,请勿重复添加!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT,"该产品变量已存在,请勿重复添加!",locale);
}*/ }*/
//DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataDictQo.getDictEnglishName()); //DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataDictQo.getDictEnglishName());
DataDict englishName = dataDictDao.findByDictEnglishName(dataDictQo.getInspectionItemCode()); DataDict dataDict1 = dataDictDao.findByInspectionItemCode(dataDictQo.getInspectionItemCode()).get();
if (englishName != null) { if (dataDict1 != null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该产品变量已存在,请勿重复添加!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该产品变量已存在,请勿重复添加!", locale);
} }
DataDict dataDict = new DataDict(); DataDict dataDict = new DataDict();

View File

@ -36,8 +36,8 @@ public class DataSourceServiceImpl implements DataSourceService {
@Override @Override
public String insertDataSource(DataSourceQo dataSourceQo) { public String insertDataSource(DataSourceQo dataSourceQo) {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
DataDict byDictEnglishName = dataDictDao.findByDictEnglishName(dataSourceQo.getInspectionItemCode()); DataDict dataDict = dataDictDao.findByInspectionItemCode(dataSourceQo.getInspectionItemCode()).get();
if(byDictEnglishName == null){ if(dataDict == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"不存在该字典类型!",locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"不存在该字典类型!",locale);
} }
DataSource dataSource = new DataSource(); DataSource dataSource = new DataSource();

View File

@ -4,6 +4,7 @@ import com.xkrs.dao.DataDictDao;
import com.xkrs.dao.DataSourceDao; import com.xkrs.dao.DataSourceDao;
import com.xkrs.dao.FileDao; import com.xkrs.dao.FileDao;
import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.DataSource;
import com.xkrs.model.entity.FileEntity; import com.xkrs.model.entity.FileEntity;
import com.xkrs.model.qo.FileQo; import com.xkrs.model.qo.FileQo;
import com.xkrs.service.FileService; import com.xkrs.service.FileService;
@ -15,7 +16,6 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.Transactional; import javax.transaction.Transactional;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
@ -43,13 +43,14 @@ public class FileServiceImpl implements FileService {
/** /**
* 添加模板信息 * 添加模板信息
*
* @param fileQo * @param fileQo
* @return * @return
*/ */
@Override @Override
public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException { public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
FileEntity fileEntity = fileDao.findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); FileEntity fileEntity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (fileEntity != null) { if (fileEntity != null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale);
} }
@ -70,6 +71,7 @@ public class FileServiceImpl implements FileService {
/** /**
* 导出excel * 导出excel
*
* @param fileQo * @param fileQo
* @return * @return
*/ */
@ -77,21 +79,21 @@ public class FileServiceImpl implements FileService {
@Override @Override
public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException { public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
FileEntity entity = fileDao.findByFileModelNumberAndFileBatchNumberAndFileMachineCodeAndFileProductNumber(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); FileEntity entity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (entity == null) { if (entity == null) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
} }
String fileUploadPath = entity.getFileUploadPath(); String fileUploadPath = entity.getFileUploadPath();
List<Map<String, String>> maps = dataSourceDao.selectDataNameAndData(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber()); List<DataSource> dataSources = dataSourceDao.selectDataSource(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if(maps == null || maps.size() == 0){ if (dataSources == null || dataSources.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale);
} }
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
for(Map<String,String> stringMap : maps){ for (DataSource dataSource : dataSources) {
map.put(stringMap.get("dataname"),stringMap.get("numericalvalue")); map.put(dataSource.getInspectionItemCode(), dataSource.getInspectValue());
} }
String fill = ExportExcel.exportToProveExcel(map, fileUploadPath); String fill = ExportExcel.exportToProveExcel(map, fileUploadPath);
fileDao.updateFileDownloadPath(fileQo.getFileModelNumber(), fileQo.getFileBatchNumber(), fileQo.getFileMachineCode(), fileQo.getFileProductNumber(),fill); fileDao.updateFileDownloadPath(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo(), fill);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, fill, locale);
} }
} }