更新dao返回值类型

This commit is contained in:
liuchengqian 2022-03-01 10:20:08 +08:00
parent 9cf2698ec8
commit 5ef4df2d6f
8 changed files with 59 additions and 59 deletions

View File

@ -36,53 +36,59 @@ public class DataDictController {
/**
* 添加字典变量数据
*
* @param dataDictQo
* @return
*/
@PostMapping("/insertDataDict")
public String insertDataDict(@RequestBody DataDictQo dataDictQo){
public String insertDataDict(@RequestBody DataDictQo dataDictQo) {
return dataDictService.insertDataDict(dataDictQo);
}
/**
* 动态多条件查询字典信息
* @param dictChineseName
* @param dictEnglishName
*
* @param inspectionItemName
* @param inspectionItemCode
* @return
*/
@GetMapping("/selectDataDict")
public String selectDataDict(@RequestParam("dictChineseName") String dictChineseName,
@RequestParam("dictEnglishName") String dictEnglishName){
public String selectDataDict(@RequestParam("inspectionItemName") String inspectionItemName, @RequestParam("inspectionItemCode") String inspectionItemCode) {
Locale locale = LocaleContextHolder.getLocale();
List<DataDict> dataDict = query.selectDataDict(dictChineseName, dictEnglishName);
if(dataDict == null || dataDict.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该型号类型的字典信息!",locale);
List<DataDict> dataDict = query.selectDataDict(inspectionItemName, inspectionItemCode);
if (dataDict == null || dataDict.size() == 0) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该型号类型的字典信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataDict, locale);
}
/**
* 根据id查询字典信息用于数据回显方便进行修改操作
*
* @param id
* @return
*/
@GetMapping("/selectDataDictById")
public String selectDataDictById(@RequestParam("id") Integer id){
public String selectDataDictById(@RequestParam("id") Integer id) {
Locale locale = LocaleContextHolder.getLocale();
DataDict dataDict = dataDictDao.findById(id).get();
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,dataDict,locale);
Optional<DataDict> byId = dataDictDao.findById(id);
if (byId.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时还没有该型号类型的字典信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, byId.get(), locale);
}
/**
* 根据id修改字典信息
*
* @param dataDictUpdateQo
* @return
*/
@PostMapping("/updateDict")
@Transactional(rollbackOn = Exception.class)
public String updateDict(@RequestBody DataDictUpdateQo dataDictUpdateQo){
public String updateDict(@RequestBody DataDictUpdateQo dataDictUpdateQo) {
Locale locale = LocaleContextHolder.getLocale();
dataDictDao.updateDict(dataDictUpdateQo.getId(),dataDictUpdateQo.getInspectionItemName());
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"修改成功!",locale);
dataDictDao.updateDict(dataDictUpdateQo.getId(), dataDictUpdateQo.getInspectionItemName());
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
}
}

View File

@ -3,14 +3,11 @@ package com.xkrs.controller;
import com.xkrs.dao.PictureDao;
import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.model.entity.PictureEntity;
import com.xkrs.model.entity.SpecEntity;
import com.xkrs.model.qo.FileQo;
import com.xkrs.model.qo.PictureQo;
import com.xkrs.service.PictureService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
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;
@ -18,6 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Locale;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -45,18 +43,17 @@ public class PictureController {
/**
* 查询图片
*/
@PostMapping("/selectPicture")
public String selectPicture(@RequestBody PictureQo pictureQo) throws IOException, InvalidFormatException {
@GetMapping("/selectPicture")
public String selectPicture(@RequestParam("lotNo") String lotNo,
@RequestParam("machineNo") String machineNo,
@RequestParam("materialNo") String materialNo,
@RequestParam("modelNo") String modelNo,
@RequestParam("partNo") String partNo) {
Locale locale = LocaleContextHolder.getLocale();
String lotNo = pictureQo.getLotNo();
String machineNo = pictureQo.getMachineNo();
String materialNo = pictureQo.getMaterialNo();
String modelNo = pictureQo.getModelNo();
String partNo = pictureQo.getPartNo();
PictureEntity pictureEntity = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo).get();
if (pictureEntity == null) {
Optional<PictureEntity> pictureEntity1 = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo);
if (pictureEntity1.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该零件的图片!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntity, locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntity1.get(), locale);
}
}

View File

@ -7,6 +7,8 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;
import java.util.Optional;
/**
* @Author: XinYi Song
* @Date: 2022/1/20 15:23
@ -25,7 +27,7 @@ public interface FileDao extends JpaRepository<FileEntity, Long>, JpaSpecificati
* @return
*/
@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);
Optional<FileEntity> selectFile(String lotNo, String machineNo, String materialNo, String modelNo, String partNo);
/**
* 修改模板上传信息

View File

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Locale;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -32,14 +33,8 @@ public class DataDictServiceImpl implements DataDictService {
@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 dataDict1 = dataDictDao.findByInspectionItemCode(dataDictQo.getInspectionItemCode()).get();
if (dataDict1 != null) {
Optional<DataDict> byInspectionItemCode = dataDictDao.findByInspectionItemCode(dataDictQo.getInspectionItemCode());
if (byInspectionItemCode.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该产品变量已存在,请勿重复添加!", locale);
}
DataDict dataDict = new DataDict();

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Locale;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -30,15 +31,16 @@ public class DataSourceServiceImpl implements DataSourceService {
/**
* 添加测量数据
*
* @param dataSourceQo
* @return
*/
@Override
public String insertDataSource(DataSourceQo dataSourceQo) {
Locale locale = LocaleContextHolder.getLocale();
DataDict dataDict = dataDictDao.findByInspectionItemCode(dataSourceQo.getInspectionItemCode()).get();
if(dataDict == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"不存在该字典类型!",locale);
Optional<DataDict> byInspectionItemCode = dataDictDao.findByInspectionItemCode(dataSourceQo.getInspectionItemCode());
if (byInspectionItemCode.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "已存在该字典类型!", locale);
}
DataSource dataSource = new DataSource();
dataSource.setLotNo(dataSourceQo.getLotNo());
@ -49,6 +51,6 @@ public class DataSourceServiceImpl implements DataSourceService {
dataSource.setInspectionItemCode(dataSourceQo.getInspectionItemCode());
dataSource.setInspectValue(dataSourceQo.getInspectValue());
dataSourceDao.save(dataSource);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"添加成功!",locale);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
}
}

View File

@ -18,10 +18,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
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 java.util.*;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -50,8 +47,8 @@ public class FileServiceImpl implements FileService {
@Override
public String insertFileExcel(FileQo fileQo, MultipartFile fileExcel) throws IOException {
Locale locale = LocaleContextHolder.getLocale();
FileEntity fileEntity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (fileEntity != null) {
Optional<FileEntity> fileEntity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (fileEntity.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该产品的模板!", locale);
}
if (fileExcel == null) {
@ -79,11 +76,11 @@ public class FileServiceImpl implements FileService {
@Override
public String exportExcel(FileQo fileQo) throws IOException, InvalidFormatException {
Locale locale = LocaleContextHolder.getLocale();
FileEntity entity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (entity == null) {
Optional<FileEntity> fileEntity = fileDao.selectFile(fileQo.getLotNo(), fileQo.getMachineNo(), fileQo.getMaterialNo(), fileQo.getModelNo(), fileQo.getPartNo());
if (fileEntity.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的模板,请添加!", locale);
}
String fileUploadPath = entity.getFileUploadPath();
String fileUploadPath = fileEntity.get().getFileUploadPath();
List<DataSource> dataSources = dataSourceDao.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

@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Locale;
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@ -30,8 +31,8 @@ public class PictureServiceImpl implements PictureService {
String materialNo = pictureQo.getMaterialNo();
String modelNo = pictureQo.getModelNo();
String partNo = pictureQo.getPartNo();
PictureEntity pictureEntity = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo).get();
if (pictureEntity != null) {
Optional<PictureEntity> pictureEntity2 = pictureDao.selectPicture(lotNo, machineNo, materialNo, modelNo, partNo);
if (pictureEntity2.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "请勿重复添加!", locale);
}
String file = ExcelUploadUtil.memoryFile(pictureFile);

View File

@ -4,7 +4,6 @@ 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;
@ -26,18 +25,19 @@ public class Query {
/**
* 动态多条件查询字典信息
*
* @return
*/
public List<DataDict> selectDataDict(String dictChineseName,String dictEnglishName) {
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(dictChineseName != null && !"".equals(dictChineseName)){
list.add(criteriaBuilder.equal(root.get("dictChineseName").as(String.class), dictChineseName));
if (inspectionItemName != null && !"".equals(inspectionItemName)) {
list.add(criteriaBuilder.equal(root.get("inspectionItemName").as(String.class), inspectionItemName));
}
if(dictEnglishName != null && !"".equals(dictEnglishName)){
list.add(criteriaBuilder.equal(root.get("dictEnglishName").as(String.class), dictEnglishName));
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));