更新动态多条件查询

This commit is contained in:
liuchengqian 2022-03-01 15:54:55 +08:00
parent 266c46fe16
commit 62703e1fe4
14 changed files with 243 additions and 111 deletions

View File

@ -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> dataDict = query.selectDataDict(inspectionItemName, inspectionItemCode);
List<DataDict> dataDict = dataDictQuery.selectDataDict(inspectionItemName, inspectionItemCode);
if (dataDict == null || dataDict.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该型号类型的字典信息!", locale);
}

View File

@ -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<DataSource> dataSources = dataSourceDao.selectDataSource(lotNo, machineNo, materialNo, modelNo, partNo);
List<DataSource> 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<DataSource> dataSources = dataSourceDao.selectAllSource();
if (dataSources == null || dataSources.size() == 0) {
List<DataSource> dataSources = dataSourceDao.findAll();
if (dataSources.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale);

View File

@ -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<PictureEntity> pictureEntity1 = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo);
if (pictureEntity1.isEmpty()) {
List<PictureEntity> 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);
}
}

View File

@ -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<SpecEntity> byPartNoAndInspectionItemCode = specDao.findByPartNoAndInspectionItemCode(partNo, inspectionItemCode);
if (byPartNoAndInspectionItemCode.isEmpty()) {
List<SpecEntity> 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);
}
}

View File

@ -16,24 +16,4 @@ import java.util.Optional;
@Component
public interface DataSourceDao extends JpaRepository<DataSource, Long>, JpaSpecificationExecutor<DataSource> {
/**
* 查询测量数据信息
*
* @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<DataSource> selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo);
/**
* 查询全部的测量信息
*
* @return
*/
@Query(value = "SELECT * FROM qc_inspection_data_source", nativeQuery = true)
List<DataSource> selectAllSource();
}

View File

@ -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<SpecEntity, Long>, JpaSpecificationExecutor<SpecEntity> {
Optional<SpecEntity> findByPartNoAndInspectionItemCode(String partNo, String inspectionItemCode);
}

View File

@ -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;
/**
* 添加模板信息
@ -81,7 +77,7 @@ public class FileServiceImpl implements FileService {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
}
String fileUploadPath = fileEntity.get().getFileUploadPath();
List<DataSource> dataSources = dataSourceDao.selectDataSource(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
List<DataSource> 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);
}

View File

@ -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<SpecEntity> inspectionItemCode = specDao.findByPartNoAndInspectionItemCode(specQo.getPartNo(), specQo.getInspectionItemCode());
if (inspectionItemCode.isPresent()) {
List<SpecEntity> specEntities = specQuery.selectSpec(specQo.getPartNo(), specQo.getInspectionItemCode());
if (!specEntities.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该测量规格!", locale);
}
SpecEntity specEntity1 = new SpecEntity();

View File

@ -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<DataDict> selectDataDict(String inspectionItemName, String inspectionItemCode) {
Specification<DataDict> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> 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);
}
}

View File

@ -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<DataSource> selectDataSource(String lotNo, String machineNo, String materialNo, String modelNo, String partNo) {
Specification<DataSource> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> 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);
}
}

View File

@ -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));

View File

@ -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<PictureEntity> selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String partNo) {
Specification<PictureEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> 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);
}
}

View File

@ -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<DataDict> selectDataDict(String inspectionItemName, String inspectionItemCode) {
Specification<DataDict> specification = new Specification<DataDict>() {
@Override
public Predicate toPredicate(Root<DataDict> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> 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);
}
}

View File

@ -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<SpecEntity> selectSpec(String partNo, String inspectionItemCode) {
Specification<SpecEntity> specification = (root, criteriaQuery, criteriaBuilder) -> {
List<Predicate> 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);
}
}