diff --git a/src/main/java/com/xkrs/controller/DataDictController.java b/src/main/java/com/xkrs/controller/DataDictController.java index 3e1cec4..e842041 100644 --- a/src/main/java/com/xkrs/controller/DataDictController.java +++ b/src/main/java/com/xkrs/controller/DataDictController.java @@ -6,7 +6,7 @@ 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 com.xkrs.util.DataDictQuery; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.web.bind.annotation.*; @@ -32,7 +32,7 @@ public class DataDictController { private DataDictDao dataDictDao; @Resource - private Query query; + private DataDictQuery dataDictQuery; /** * 添加字典变量数据 @@ -55,7 +55,7 @@ public class DataDictController { @GetMapping("/selectDataDict") public String selectDataDict(@RequestParam("inspectionItemName") String inspectionItemName, @RequestParam("inspectionItemCode") String inspectionItemCode) { Locale locale = LocaleContextHolder.getLocale(); - List dataDict = query.selectDataDict(inspectionItemName, inspectionItemCode); + List dataDict = dataDictQuery.selectDataDict(inspectionItemName, inspectionItemCode); if (dataDict == null || dataDict.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该型号类型的字典信息!", locale); } diff --git a/src/main/java/com/xkrs/controller/DataSourceController.java b/src/main/java/com/xkrs/controller/DataSourceController.java index a72e129..7381f85 100644 --- a/src/main/java/com/xkrs/controller/DataSourceController.java +++ b/src/main/java/com/xkrs/controller/DataSourceController.java @@ -5,13 +5,13 @@ 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.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; @@ -25,6 +25,9 @@ public class DataSourceController { @Resource private DataSourceService dataSourceService; + @Resource + private DataSourceQuery dataSourceQuery; + @Resource private DataSourceDao dataSourceDao; @@ -41,6 +44,7 @@ public class DataSourceController { /** * 查询某一产品的测量信息 + * * @param lotNo 批次号 * @param machineNo 机器号 * @param materialNo 物料号 @@ -49,13 +53,13 @@ public class DataSourceController { * @return */ @GetMapping("/selectDataSource") - public String selectDataSource(@RequestParam("lotNo") String lotNo, - @RequestParam("machineNo") String machineNo, - @RequestParam("materialNo") String materialNo, - @RequestParam("modelNo") String modelNo, - @RequestParam("partNo") String partNo) { + 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 = "partNo") String partNo) { Locale locale = LocaleContextHolder.getLocale(); - List dataSources = dataSourceDao.selectDataSource(lotNo, machineNo, materialNo, modelNo, partNo); + List dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, partNo); if (dataSources == null || dataSources.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); } @@ -70,8 +74,8 @@ public class DataSourceController { @GetMapping("/selectAllSource") public String selectAllSource() { Locale locale = LocaleContextHolder.getLocale(); - List dataSources = dataSourceDao.selectAllSource(); - if (dataSources == null || dataSources.size() == 0) { + List dataSources = dataSourceDao.findAll(); + if (dataSources.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale); diff --git a/src/main/java/com/xkrs/controller/PictureController.java b/src/main/java/com/xkrs/controller/PictureController.java index 2683a7e..b7480f7 100644 --- a/src/main/java/com/xkrs/controller/PictureController.java +++ b/src/main/java/com/xkrs/controller/PictureController.java @@ -1,18 +1,21 @@ package com.xkrs.controller; -import com.xkrs.dao.PictureDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.PictureEntity; import com.xkrs.model.qo.PictureQo; import com.xkrs.service.PictureService; +import com.xkrs.util.PictureQuery; import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; +import java.util.List; import java.util.Locale; -import java.util.Optional; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -27,7 +30,7 @@ public class PictureController { private PictureService pictureService; @Resource - private PictureDao pictureDao; + private PictureQuery pictureQuery; /** * 上传图片 @@ -47,10 +50,10 @@ public class PictureController { @RequestParam("modelNo") String modelNo, @RequestParam("partNo") String partNo) { Locale locale = LocaleContextHolder.getLocale(); - Optional pictureEntity1 = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo); - if (pictureEntity1.isEmpty()) { + List pictureEntities = pictureQuery.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo); + if (pictureEntities.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该零件的图片!", locale); } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntity1.get(), locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntities.get(0), locale); } } diff --git a/src/main/java/com/xkrs/controller/SpecController.java b/src/main/java/com/xkrs/controller/SpecController.java index 937d40a..1ac5126 100644 --- a/src/main/java/com/xkrs/controller/SpecController.java +++ b/src/main/java/com/xkrs/controller/SpecController.java @@ -1,16 +1,16 @@ package com.xkrs.controller; -import com.xkrs.dao.SpecDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.SpecEntity; import com.xkrs.model.qo.SpecQo; import com.xkrs.service.SpecService; +import com.xkrs.util.SpecQuery; 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.Optional; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @@ -25,7 +25,7 @@ public class SpecController { private SpecService specService; @Resource - private SpecDao specDao; + private SpecQuery specQuery; /** * 添加规格数据 @@ -41,12 +41,14 @@ public class SpecController { * 查询规格信息 */ @GetMapping("/selectSpec") - public String selectSpec(@RequestParam("partNo") String partNo, @RequestParam("inspectionItemCode") String inspectionItemCode) { + public String selectSpec(@RequestParam(required = false, value = "partNo") String partNo, + @RequestParam(required = false, value = "inspectionItemCode") String inspectionItemCode) { Locale locale = LocaleContextHolder.getLocale(); - Optional byPartNoAndInspectionItemCode = specDao.findByPartNoAndInspectionItemCode(partNo, inspectionItemCode); - if (byPartNoAndInspectionItemCode.isEmpty()) { + List specEntities = specQuery.selectSpec(partNo, inspectionItemCode); + if (specEntities.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该零件的规格信息!", locale); } - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byPartNoAndInspectionItemCode.get(), locale); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, specEntities.get(0), locale); } + } diff --git a/src/main/java/com/xkrs/dao/DataSourceDao.java b/src/main/java/com/xkrs/dao/DataSourceDao.java index 6fd175c..23032d3 100644 --- a/src/main/java/com/xkrs/dao/DataSourceDao.java +++ b/src/main/java/com/xkrs/dao/DataSourceDao.java @@ -16,24 +16,4 @@ import java.util.Optional; @Component public interface DataSourceDao extends JpaRepository, JpaSpecificationExecutor { - /** - * 查询测量数据信息 - * - * @param lotNo 批次号 - * @param machineNo 机器号 - * @param materialNo 物料号 - * @param modelNo 模具号 - * @param partNo 零件号 - * @return - */ - @Query(value = "SELECT * FROM qc_inspection_data_source WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true) - List selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo); - - /** - * 查询全部的测量信息 - * - * @return - */ - @Query(value = "SELECT * FROM qc_inspection_data_source", nativeQuery = true) - List selectAllSource(); } diff --git a/src/main/java/com/xkrs/dao/SpecDao.java b/src/main/java/com/xkrs/dao/SpecDao.java index 57638e7..a81f3a0 100644 --- a/src/main/java/com/xkrs/dao/SpecDao.java +++ b/src/main/java/com/xkrs/dao/SpecDao.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Component; +import java.util.List; import java.util.Optional; /** @@ -14,6 +15,4 @@ import java.util.Optional; @Component public interface SpecDao extends JpaRepository, JpaSpecificationExecutor { - Optional findByPartNoAndInspectionItemCode(String partNo, String inspectionItemCode); - } diff --git a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java index 3a6319e..2f877c0 100644 --- a/src/main/java/com/xkrs/service/impl/FileServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FileServiceImpl.java @@ -1,13 +1,12 @@ 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.DataSource; import com.xkrs.model.entity.FileEntity; import com.xkrs.model.qo.FileQo; import com.xkrs.service.FileService; +import com.xkrs.util.DataSourceQuery; import com.xkrs.util.ExcelUploadUtil; import com.xkrs.util.ExportExcel; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; @@ -33,10 +32,7 @@ public class FileServiceImpl implements FileService { private FileDao fileDao; @Resource - private DataDictDao dataDictDao; - - @Resource - private DataSourceDao dataSourceDao; + private DataSourceQuery dataSourceQuery; /** * 添加模板信息 @@ -54,7 +50,7 @@ public class FileServiceImpl implements FileService { if (fileExcel == null) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "模板不能为空!", locale); } - String file = ExcelUploadUtil.memoryFile(fileExcel,1); + String file = ExcelUploadUtil.memoryFile(fileExcel, 1); FileEntity fileEntity1 = new FileEntity(); fileEntity1.setLotNo(fileQo.getLotNo()); fileEntity1.setMachineNo(fileQo.getMachineNo()); @@ -81,7 +77,7 @@ public class FileServiceImpl implements FileService { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale); } String fileUploadPath = fileEntity.get().getFileUploadPath(); - List dataSources = dataSourceDao.selectDataSource(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo()); + List dataSources = dataSourceQuery.selectDataSource(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo()); if (dataSources == null || dataSources.size() == 0) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的信息!", locale); } diff --git a/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java b/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java index f6e12a7..7c5322a 100644 --- a/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java @@ -5,26 +5,30 @@ import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.SpecEntity; import com.xkrs.model.qo.SpecQo; import com.xkrs.service.SpecService; +import com.xkrs.util.SpecQuery; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.util.List; import java.util.Locale; -import java.util.Optional; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; @Service public class SpecServiceImpl implements SpecService { + @Resource + private SpecQuery specQuery; + @Resource private SpecDao specDao; @Override public String insertSpec(SpecQo specQo) { Locale locale = LocaleContextHolder.getLocale(); - Optional inspectionItemCode = specDao.findByPartNoAndInspectionItemCode(specQo.getPartNo(), specQo.getInspectionItemCode()); - if (inspectionItemCode.isPresent()) { + List specEntities = specQuery.selectSpec(specQo.getPartNo(), specQo.getInspectionItemCode()); + if (!specEntities.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该测量规格!", locale); } SpecEntity specEntity1 = new SpecEntity(); diff --git a/src/main/java/com/xkrs/util/DataDictQuery.java b/src/main/java/com/xkrs/util/DataDictQuery.java new file mode 100644 index 0000000..4e5a544 --- /dev/null +++ b/src/main/java/com/xkrs/util/DataDictQuery.java @@ -0,0 +1,45 @@ +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 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 DataDictQuery { + + @Resource + private DataDictDao dataDictDao; + + /** + * 动态多条件查询字典信息 + * + * @return + */ + public List selectDataDict(String inspectionItemName, String inspectionItemCode) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (inspectionItemName != null && !"".equals(inspectionItemName)) { + list.add(criteriaBuilder.equal(root.get("inspectionItemName").as(String.class), inspectionItemName)); + } + if (inspectionItemCode != null && !"".equals(inspectionItemCode)) { + list.add(criteriaBuilder.equal(root.get("inspectionItemCode").as(String.class), inspectionItemCode)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + return dataDictDao.findAll(specification); + } +} diff --git a/src/main/java/com/xkrs/util/DataSourceQuery.java b/src/main/java/com/xkrs/util/DataSourceQuery.java new file mode 100644 index 0000000..eea61ed --- /dev/null +++ b/src/main/java/com/xkrs/util/DataSourceQuery.java @@ -0,0 +1,52 @@ +package com.xkrs.util; + +import com.xkrs.dao.DataSourceDao; +import com.xkrs.model.entity.DataSource; +import org.apache.http.util.TextUtils; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.persistence.criteria.Predicate; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: XinYi Song + * @Date: 2022/1/19 13:56 + */ +@Component +public class DataSourceQuery { + + @Resource + private DataSourceDao dataSourceDao; + + /** + * 动态多条件查询采集数据信息 + * + * @return + */ + public List selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (!TextUtils.isEmpty(lotNo)) { + list.add(criteriaBuilder.equal(root.get("lotNo").as(String.class), lotNo)); + } + if (!TextUtils.isEmpty(machineNo)) { + list.add(criteriaBuilder.equal(root.get("machineNo").as(String.class), machineNo)); + } + if (!TextUtils.isEmpty(materialNo)) { + list.add(criteriaBuilder.equal(root.get("materialNo").as(String.class), materialNo)); + } + if (!TextUtils.isEmpty(modelNo)) { + list.add(criteriaBuilder.equal(root.get("modelNo").as(String.class), modelNo)); + } + if (!TextUtils.isEmpty(partNo)) { + list.add(criteriaBuilder.equal(root.get("partNo").as(String.class), partNo)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + return dataSourceDao.findAll(specification); + } +} diff --git a/src/main/java/com/xkrs/util/ExcelUploadUtil.java b/src/main/java/com/xkrs/util/ExcelUploadUtil.java index d98ca96..918fddf 100644 --- a/src/main/java/com/xkrs/util/ExcelUploadUtil.java +++ b/src/main/java/com/xkrs/util/ExcelUploadUtil.java @@ -44,13 +44,13 @@ public class ExcelUploadUtil { String newName = UUID.randomUUID().toString() + suffix; //将图片保存到本地/usr/etc/images/Folder -// File file = new File("/Users/liuchengqian/Desktop/DaJiang/"); - File file = new File("/home/sxy/server/industrial_measurement/" + subDir); + File file = new File("/Users/liuchengqian/Desktop/DaJiang/"); +// File file = new File("/home/sxy/server/industrial_measurement/" + subDir); if (!file.exists()) { file.mkdirs(); } -// String path = "/Users/liuchengqian/Desktop/DaJiang/"+newName; - String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; + String path = "/Users/liuchengqian/Desktop/DaJiang/"+newName; +// String path = "/home/sxy/server/industrial_measurement/" + subDir + newName; String uploadsImage = uploadPath + newName; //实现上传 fileInput.transferTo(new File(path)); diff --git a/src/main/java/com/xkrs/util/PictureQuery.java b/src/main/java/com/xkrs/util/PictureQuery.java new file mode 100644 index 0000000..79dc2e2 --- /dev/null +++ b/src/main/java/com/xkrs/util/PictureQuery.java @@ -0,0 +1,52 @@ +package com.xkrs.util; + +import com.xkrs.dao.PictureDao; +import com.xkrs.model.entity.PictureEntity; +import org.apache.http.util.TextUtils; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.persistence.criteria.Predicate; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: XinYi Song + * @Date: 2022/1/19 13:56 + */ +@Component +public class PictureQuery { + + @Resource + private PictureDao pictureDao; + + /** + * 动态多条件查询图片信息 + * + * @return + */ + public List selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String partNo) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (!TextUtils.isEmpty(lotNo)) { + list.add(criteriaBuilder.equal(root.get("lotNo").as(String.class), lotNo)); + } + if (!TextUtils.isEmpty(machineNo)) { + list.add(criteriaBuilder.equal(root.get("machineNo").as(String.class), machineNo)); + } + if (!TextUtils.isEmpty(materialNo)) { + list.add(criteriaBuilder.equal(root.get("materialNo").as(String.class), materialNo)); + } + if (!TextUtils.isEmpty(modelNo)) { + list.add(criteriaBuilder.equal(root.get("modelNo").as(String.class), modelNo)); + } + if (!TextUtils.isEmpty(partNo)) { + list.add(criteriaBuilder.equal(root.get("partNo").as(String.class), partNo)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + return pictureDao.findAll(specification); + } +} diff --git a/src/main/java/com/xkrs/util/Query.java b/src/main/java/com/xkrs/util/Query.java deleted file mode 100644 index 08481ab..0000000 --- a/src/main/java/com/xkrs/util/Query.java +++ /dev/null @@ -1,48 +0,0 @@ -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 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 selectDataDict(String inspectionItemName, String inspectionItemCode) { - Specification specification = new Specification() { - @Override - public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { - List list = new ArrayList<>(); - if (inspectionItemName != null && !"".equals(inspectionItemName)) { - list.add(criteriaBuilder.equal(root.get("inspectionItemName").as(String.class), inspectionItemName)); - } - if (inspectionItemCode != null && !"".equals(inspectionItemCode)) { - list.add(criteriaBuilder.equal(root.get("inspectionItemCode").as(String.class), inspectionItemCode)); - } - Predicate[] predicates = new Predicate[list.size()]; - return criteriaBuilder.and(list.toArray(predicates)); - } - }; - return dataDictDao.findAll(specification); - } -} diff --git a/src/main/java/com/xkrs/util/SpecQuery.java b/src/main/java/com/xkrs/util/SpecQuery.java new file mode 100644 index 0000000..17ae43f --- /dev/null +++ b/src/main/java/com/xkrs/util/SpecQuery.java @@ -0,0 +1,43 @@ +package com.xkrs.util; + +import com.xkrs.dao.SpecDao; +import com.xkrs.model.entity.SpecEntity; +import org.apache.http.util.TextUtils; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import javax.persistence.criteria.Predicate; +import java.util.ArrayList; +import java.util.List; + +/** + * @Author: XinYi Song + * @Date: 2022/1/19 13:56 + */ +@Component +public class SpecQuery { + + @Resource + private SpecDao specDao; + + /** + * 动态多条件查询规格信息 + * + * @return + */ + public List selectSpec(String partNo, String inspectionItemCode) { + Specification specification = (root, criteriaQuery, criteriaBuilder) -> { + List list = new ArrayList<>(); + if (!TextUtils.isEmpty(partNo)) { + list.add(criteriaBuilder.equal(root.get("partNo").as(String.class), partNo)); + } + if (!TextUtils.isEmpty(inspectionItemCode)) { + list.add(criteriaBuilder.equal(root.get("inspectionItemCode").as(String.class), inspectionItemCode)); + } + Predicate[] predicates = new Predicate[list.size()]; + return criteriaBuilder.and(list.toArray(predicates)); + }; + return specDao.findAll(specification); + } +}