From d6cda043fbf780566bbd9d3c6f87cf23b2893384 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 10 Mar 2022 11:53:03 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/DataSourceController.java | 51 +++++++-- .../xkrs/controller/PictureController.java | 38 +++---- src/main/java/com/xkrs/dao/DataSourceDao.java | 16 ++- src/main/java/com/xkrs/dao/PictureDao.java | 5 +- .../com/xkrs/model/entity/DataSource.java | 27 ++++- .../java/com/xkrs/model/vo/DataSourceVo.java | 106 ++++++++++++++++++ .../service/impl/DataSourceServiceImpl.java | 14 +++ .../xkrs/service/impl/PictureServiceImpl.java | 49 ++++++-- .../java/com/xkrs/util/ExcelUploadUtil.java | 9 +- 9 files changed, 264 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/xkrs/model/vo/DataSourceVo.java diff --git a/src/main/java/com/xkrs/controller/DataSourceController.java b/src/main/java/com/xkrs/controller/DataSourceController.java index 2963a15..490336d 100644 --- a/src/main/java/com/xkrs/controller/DataSourceController.java +++ b/src/main/java/com/xkrs/controller/DataSourceController.java @@ -1,17 +1,21 @@ package com.xkrs.controller; import com.xkrs.dao.DataSourceDao; +import com.xkrs.dao.PictureDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.DataSource; import com.xkrs.model.qo.DataSourceQo; import com.xkrs.service.DataSourceService; import com.xkrs.util.DataSourceQuery; +import org.apache.http.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.Map; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -31,6 +35,9 @@ public class DataSourceController { @Resource private DataSourceDao dataSourceDao; + @Resource + private PictureDao pictureDao; + /** * 添加测量数据 * @@ -54,18 +61,44 @@ public class DataSourceController { * @return */ @GetMapping("/selectDataSource") - public String selectDataSource(@RequestParam(required = false, value = "lotNo") String lotNo, - @RequestParam(required = false, value = "machineNo") String machineNo, - @RequestParam(required = false, value = "materialNo") String materialNo, - @RequestParam(required = false, value = "modelNo") String modelNo, - @RequestParam(required = false, value = "machineTypeNo") String machineTypeNo, - @RequestParam(required = false, value = "craftItemName") String craftItemName) { + public String selectDataSource(@RequestParam(required = false, value = "lotNo") String lotNo, @RequestParam(required = false, value = "machineNo") String machineNo, @RequestParam(required = false, value = "materialNo") String materialNo, @RequestParam(required = false, value = "modelNo") String modelNo, @RequestParam(required = false, value = "machineTypeNo") String machineTypeNo, @RequestParam(required = false, value = "craftItemName") String craftItemName) { Locale locale = LocaleContextHolder.getLocale(); - List dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); - if (dataSources == null || dataSources.size() == 0) { + List> groupList = dataSourceDao.selectAllDataSourceGroup(); + if (groupList == null || groupList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale); + List> dataSourceListList = new ArrayList<>(); + for (Map group : groupList) { + String groupNameLotNo = group.get("lotNo"); + String groupNameMachineNo = group.get("machineNo"); + String groupNameMaterialNo = group.get("materialNo"); + String groupNameModelNo = group.get("modelNo"); + String groupNameMachineTypeNo = group.get("machineTypeNo"); + String groupNameCraftItemName = group.get("craftItemName"); + if (!TextUtils.isEmpty(lotNo) && !lotNo.equals(groupNameLotNo)) { + continue; + } + if (!TextUtils.isEmpty(machineNo) && !machineNo.equals(groupNameMachineNo)) { + continue; + } + if (!TextUtils.isEmpty(materialNo) && !materialNo.equals(groupNameMaterialNo)) { + continue; + } + if (!TextUtils.isEmpty(modelNo) && !modelNo.equals(groupNameModelNo)) { + continue; + } + if (!TextUtils.isEmpty(machineTypeNo) && !machineTypeNo.equals(groupNameMachineTypeNo)) { + continue; + } + if (!TextUtils.isEmpty(craftItemName) && !craftItemName.equals(groupNameCraftItemName)) { + continue; + } + List dataSourceList = dataSourceDao.selectDataSource(groupNameLotNo, groupNameMachineNo, groupNameMaterialNo, groupNameModelNo, groupNameMachineTypeNo, groupNameCraftItemName); + if (dataSourceList != null && dataSourceList.size() > 0) { + dataSourceListList.add(dataSourceList); + } + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSourceListList, locale); } /** diff --git a/src/main/java/com/xkrs/controller/PictureController.java b/src/main/java/com/xkrs/controller/PictureController.java index 7ababa5..6f8b2c1 100644 --- a/src/main/java/com/xkrs/controller/PictureController.java +++ b/src/main/java/com/xkrs/controller/PictureController.java @@ -38,24 +38,24 @@ public class PictureController { return pictureService.insertPicture(pictureQo, filePicture); } - /** - * 删除图片 - */ - @PostMapping("/deletePicture") - public String deletePicture(@RequestBody DeletePictureQo deletePictureQo) { - return pictureService.deletePicture(deletePictureQo.getPicturePath()); - } +// /** +// * 删除图片 +// */ +// @PostMapping("/deletePicture") +// public String deletePicture(@RequestBody DeletePictureQo deletePictureQo) { +// return pictureService.deletePicture(deletePictureQo.getPicturePath()); +// } - /** - * 查询图片 - */ - @GetMapping("/selectPicture") - public String selectPicture(@RequestParam(required = false, value = "lotNo") String lotNo, @RequestParam(required = false, value = "machineNo") String machineNo, @RequestParam(required = false, value = "materialNo") String materialNo, @RequestParam(required = false, value = "modelNo") String modelNo, @RequestParam(required = false, value = "machineTypeNo") String machineTypeNo, @RequestParam(required = false, value = "craftItemName") String craftItemName) { - Locale locale = LocaleContextHolder.getLocale(); - List pictureEntities = pictureQuery.selectPicture(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); - if (pictureEntities.isEmpty()) { - return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该图片!", locale); - } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntities, locale); - } +// /** +// * 查询图片 +// */ +// @GetMapping("/selectPicture") +// public String selectPicture(@RequestParam(required = false, value = "lotNo") String lotNo, @RequestParam(required = false, value = "machineNo") String machineNo, @RequestParam(required = false, value = "materialNo") String materialNo, @RequestParam(required = false, value = "modelNo") String modelNo, @RequestParam(required = false, value = "machineTypeNo") String machineTypeNo, @RequestParam(required = false, value = "craftItemName") String craftItemName) { +// Locale locale = LocaleContextHolder.getLocale(); +// List pictureEntities = pictureQuery.selectPicture(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName); +// if (pictureEntities.isEmpty()) { +// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该图片!", locale); +// } +// return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntities, locale); +// } } diff --git a/src/main/java/com/xkrs/dao/DataSourceDao.java b/src/main/java/com/xkrs/dao/DataSourceDao.java index 23032d3..74e70a4 100644 --- a/src/main/java/com/xkrs/dao/DataSourceDao.java +++ b/src/main/java/com/xkrs/dao/DataSourceDao.java @@ -3,17 +3,23 @@ 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.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; import java.util.List; -import java.util.Optional; +import java.util.Map; -/** - * @Author: XinYi Song - * @Date: 2022/1/19 16:41 - */ @Component public interface DataSourceDao extends JpaRepository, JpaSpecificationExecutor { + @Query(value = "SELECT lot_no AS lotNo, machine_no AS machineNo, material_no AS materialNo, model_no AS modelNo, machine_type_no AS machineTypeNo, craft_item_name AS craftItemName FROM qc_inspection_data_source GROUP BY lot_no, machine_no, material_no, model_no, machine_type_no, craft_item_name", nativeQuery = true) + List> selectAllDataSourceGroup(); + + @Query(value = "SELECT * FROM qc_inspection_data_source WHERE (lot_no IS NULL OR lot_no = ?1) AND (machine_no IS NULL OR machine_no = ?2) AND (material_no IS NULL OR material_no = ?3) AND (model_no IS NULL OR model_no = ?4) AND (machine_type_no IS NULL OR machine_type_no = ?5) AND (craft_item_name IS NULL OR craft_item_name = ?6)", nativeQuery = true) + List selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String machineTypeNo, String craftItemName); + + @Modifying(clearAutomatically = true) + @Query(value = "UPDATE qc_inspection_data_source SET picture_path = ?7 WHERE lot_no = ?1 AND machine_no = ?2 AND material_no = ?3 AND model_no = ?4 AND machine_type_no = ?5 AND craft_item_name = ?6", nativeQuery = true) + void updatePicturePath(String lotNo, String machineNo, String materialNo, String modelNo, String machineTypeNo, String craftItemName, String filePath); } diff --git a/src/main/java/com/xkrs/dao/PictureDao.java b/src/main/java/com/xkrs/dao/PictureDao.java index 7102728..b10191a 100644 --- a/src/main/java/com/xkrs/dao/PictureDao.java +++ b/src/main/java/com/xkrs/dao/PictureDao.java @@ -6,6 +6,7 @@ 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.Optional; /** @@ -26,7 +27,7 @@ public interface PictureDao extends JpaRepository, JpaSpeci * @param craftItemName 工艺项目名称 * @return */ - @Query(value = "SELECT * FROM qc_inspection_picture WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND machine_type_no = ? AND craft_item_name = ? ", nativeQuery = true) - Optional selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String machineTypeNo, String craftItemName); + @Query(value = "SELECT * FROM qc_inspection_picture WHERE (lot_no IS NULL OR lot_no = ?1) AND (machine_no IS NULL OR machine_no = ?2) AND (material_no IS NULL OR material_no = ?3) AND (model_no IS NULL OR model_no = ?4) AND (machine_type_no IS NULL OR machine_type_no = ?5) AND (craft_item_name IS NULL OR craft_item_name = ?6)", nativeQuery = true) + List selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String machineTypeNo, String craftItemName); } diff --git a/src/main/java/com/xkrs/model/entity/DataSource.java b/src/main/java/com/xkrs/model/entity/DataSource.java index 8b17eb0..6908315 100644 --- a/src/main/java/com/xkrs/model/entity/DataSource.java +++ b/src/main/java/com/xkrs/model/entity/DataSource.java @@ -66,6 +66,12 @@ public class DataSource { @Column(length = 85, columnDefinition = "varchar(85)") private String inspectValue; + /** + * 图片 + */ + @Column(length = 10240, columnDefinition = "varchar(10240)") + private String picturePath; + public DataSource() { } @@ -141,8 +147,27 @@ public class DataSource { this.inspectValue = inspectValue; } + public String getPicturePath() { + return picturePath; + } + + public void setPicturePath(String picturePath) { + this.picturePath = picturePath; + } + @Override public String toString() { - return "DataSource{" + "id=" + id + ", lotNo='" + lotNo + '\'' + ", machineNo='" + machineNo + '\'' + ", materialNo='" + materialNo + '\'' + ", modelNo='" + modelNo + '\'' + ", machineTypeNo='" + machineTypeNo + '\'' + ", inspectionItemCode='" + inspectionItemCode + '\'' + ", craftItemName='" + craftItemName + '\'' + ", inspectValue='" + inspectValue + '\'' + '}'; + return "DataSource{" + + "id=" + id + + ", lotNo='" + lotNo + '\'' + + ", machineNo='" + machineNo + '\'' + + ", materialNo='" + materialNo + '\'' + + ", modelNo='" + modelNo + '\'' + + ", machineTypeNo='" + machineTypeNo + '\'' + + ", inspectionItemCode='" + inspectionItemCode + '\'' + + ", craftItemName='" + craftItemName + '\'' + + ", inspectValue='" + inspectValue + '\'' + + ", picturePath='" + picturePath + '\'' + + '}'; } } diff --git a/src/main/java/com/xkrs/model/vo/DataSourceVo.java b/src/main/java/com/xkrs/model/vo/DataSourceVo.java new file mode 100644 index 0000000..9bb0de3 --- /dev/null +++ b/src/main/java/com/xkrs/model/vo/DataSourceVo.java @@ -0,0 +1,106 @@ +package com.xkrs.model.vo; + +import java.util.List; + +public class DataSourceVo { + + private String lotNo; + private String machineNo; + private String materialNo; + private String modelNo; + private String machineTypeNo; + private String inspectionItemCode; + private String craftItemName; + private String inspectValue; + private List picturePath; + + public DataSourceVo() { + } + + public String getLotNo() { + return lotNo; + } + + public void setLotNo(String lotNo) { + this.lotNo = lotNo; + } + + public String getMachineNo() { + return machineNo; + } + + public void setMachineNo(String machineNo) { + this.machineNo = machineNo; + } + + public String getMaterialNo() { + return materialNo; + } + + public void setMaterialNo(String materialNo) { + this.materialNo = materialNo; + } + + public String getModelNo() { + return modelNo; + } + + public void setModelNo(String modelNo) { + this.modelNo = modelNo; + } + + public String getMachineTypeNo() { + return machineTypeNo; + } + + public void setMachineTypeNo(String machineTypeNo) { + this.machineTypeNo = machineTypeNo; + } + + public String getInspectionItemCode() { + return inspectionItemCode; + } + + public void setInspectionItemCode(String inspectionItemCode) { + this.inspectionItemCode = inspectionItemCode; + } + + public String getCraftItemName() { + return craftItemName; + } + + public void setCraftItemName(String craftItemName) { + this.craftItemName = craftItemName; + } + + public String getInspectValue() { + return inspectValue; + } + + public void setInspectValue(String inspectValue) { + this.inspectValue = inspectValue; + } + + public List getPicturePath() { + return picturePath; + } + + public void setPicturePath(List picturePath) { + this.picturePath = picturePath; + } + + @Override + public String toString() { + return "DataSourceVo{" + + "lotNo='" + lotNo + '\'' + + ", machineNo='" + machineNo + '\'' + + ", materialNo='" + materialNo + '\'' + + ", modelNo='" + modelNo + '\'' + + ", machineTypeNo='" + machineTypeNo + '\'' + + ", inspectionItemCode='" + inspectionItemCode + '\'' + + ", craftItemName='" + craftItemName + '\'' + + ", inspectValue='" + inspectValue + '\'' + + ", picturePath=" + picturePath + + '}'; + } +} diff --git a/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java b/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java index 4b2d1ca..cb40870 100644 --- a/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/DataSourceServiceImpl.java @@ -43,6 +43,7 @@ public class DataSourceServiceImpl implements DataSourceService { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该字典类型!", locale); } DataSource dataSource = new DataSource(); + initDataSource(dataSource); dataSource.setLotNo(dataSourceQo.getLotNo()); dataSource.setMachineNo(dataSourceQo.getMachineNo()); dataSource.setMaterialNo(dataSourceQo.getMaterialNo()); @@ -54,4 +55,17 @@ public class DataSourceServiceImpl implements DataSourceService { dataSourceDao.save(dataSource); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } + + private void initDataSource(DataSource dataSource) { + dataSource.setLotNo(""); + dataSource.setMachineNo(""); + dataSource.setMaterialNo(""); + dataSource.setModelNo(""); + dataSource.setMachineTypeNo(""); + dataSource.setInspectionItemCode(""); + dataSource.setCraftItemName(""); + dataSource.setInspectValue(""); + dataSource.setPicturePath(""); + } + } diff --git a/src/main/java/com/xkrs/service/impl/PictureServiceImpl.java b/src/main/java/com/xkrs/service/impl/PictureServiceImpl.java index 90930a8..6163c4f 100644 --- a/src/main/java/com/xkrs/service/impl/PictureServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/PictureServiceImpl.java @@ -1,17 +1,22 @@ package com.xkrs.service.impl; +import com.xkrs.dao.DataSourceDao; import com.xkrs.dao.PictureDao; import com.xkrs.encapsulation.PromptMessageEnum; -import com.xkrs.model.entity.PictureEntity; +import com.xkrs.model.entity.DataSource; import com.xkrs.model.qo.PictureQo; import com.xkrs.service.PictureService; +import com.xkrs.util.DataSourceQuery; import com.xkrs.util.ExcelUploadUtil; +import org.apache.http.util.TextUtils; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import javax.transaction.Transactional; import java.io.IOException; +import java.util.List; import java.util.Locale; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -22,19 +27,41 @@ public class PictureServiceImpl implements PictureService { @Resource private PictureDao pictureDao; + @Resource + private DataSourceDao dataSourceDao; + + @Resource + private DataSourceQuery dataSourceQuery; + @Override + @Transactional(rollbackOn = Exception.class) public String insertPicture(PictureQo pictureQo, MultipartFile pictureFile) throws IOException { Locale locale = LocaleContextHolder.getLocale(); - String file = ExcelUploadUtil.memoryFile(pictureFile, 2); - PictureEntity pictureEntity = new PictureEntity(); - pictureEntity.setLotNo(pictureQo.getLotNo()); - pictureEntity.setMachineNo(pictureQo.getMachineNo()); - pictureEntity.setMaterialNo(pictureQo.getMaterialNo()); - pictureEntity.setModelNo(pictureQo.getModelNo()); - pictureEntity.setMachineTypeNo(pictureQo.getMachineTypeNo()); - pictureEntity.setCraftItemName(pictureQo.getCraftItemName()); - pictureEntity.setPicturePath(file); - pictureDao.save(pictureEntity); + String filePath = ExcelUploadUtil.memoryFile(pictureFile, 2); + List dataSourceList = dataSourceQuery.selectDataSource(pictureQo.getLotNo(), pictureQo.getMachineNo(), pictureQo.getMaterialNo(), pictureQo.getModelNo(), pictureQo.getMachineTypeNo(), pictureQo.getCraftItemName()); + if (dataSourceList == null || dataSourceList.isEmpty()) { + DataSource dataSource = new DataSource(); + dataSource.setLotNo(pictureQo.getLotNo()); + dataSource.setMachineNo(pictureQo.getMachineNo()); + dataSource.setMaterialNo(pictureQo.getMaterialNo()); + dataSource.setModelNo(pictureQo.getModelNo()); + dataSource.setMachineTypeNo(pictureQo.getMachineTypeNo()); + dataSource.setInspectionItemCode(""); + dataSource.setCraftItemName(pictureQo.getCraftItemName()); + dataSource.setInspectValue(""); + dataSource.setPicturePath(filePath); + dataSourceDao.save(dataSource); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); + } + for (DataSource dataSource : dataSourceList) { + String newFilePath; + if (TextUtils.isEmpty(dataSource.getPicturePath())) { + newFilePath = filePath; + } else { + newFilePath = dataSource.getPicturePath() + "," + filePath; + } + dataSourceDao.updatePicturePath(dataSource.getLotNo(), dataSource.getMachineNo(), dataSource.getMaterialNo(), dataSource.getModelNo(), dataSource.getMachineTypeNo(), dataSource.getCraftItemName(), newFilePath); + } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } diff --git a/src/main/java/com/xkrs/util/ExcelUploadUtil.java b/src/main/java/com/xkrs/util/ExcelUploadUtil.java index 78484f3..0c542cf 100644 --- a/src/main/java/com/xkrs/util/ExcelUploadUtil.java +++ b/src/main/java/com/xkrs/util/ExcelUploadUtil.java @@ -39,15 +39,16 @@ public class ExcelUploadUtil { String suffix = originalFilename.substring(index); //uuid生成新的文件名 String newName = UUID.randomUUID().toString() + suffix; - File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); -// File file = new File("/home/sxy/server/industrial_measurement/" + subDir); +// File file = new File("/Users/liuchengqian/Desktop/DaJiang/" + subDir); + File file = new File("/home/sxy/server/industrial_measurement/" + subDir); if (!file.exists()) { file.mkdirs(); } - String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; -// String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; +// String path = "/Users/liuchengqian/Desktop/DaJiang/" + subDir + newName; + String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; //实现上传 fileInput.transferTo(new File(path)); +// return path; return "http://118.24.27.47:2088/" + subDir + newName; } return null;