This commit is contained in:
liuchengqian 2022-03-10 11:53:03 +08:00
parent b74dd02f87
commit d6cda043fb
9 changed files with 264 additions and 51 deletions

View File

@ -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<DataSource> dataSources = dataSourceQuery.selectDataSource(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
if (dataSources == null || dataSources.size() == 0) {
List<Map<String, String>> groupList = dataSourceDao.selectAllDataSourceGroup();
if (groupList == null || groupList.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该产品的测量信息!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSources, locale);
List<List<DataSource>> dataSourceListList = new ArrayList<>();
for (Map<String, String> 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<DataSource> dataSourceList = dataSourceDao.selectDataSource(groupNameLotNo, groupNameMachineNo, groupNameMaterialNo, groupNameModelNo, groupNameMachineTypeNo, groupNameCraftItemName);
if (dataSourceList != null && dataSourceList.size() > 0) {
dataSourceListList.add(dataSourceList);
}
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, dataSourceListList, locale);
}
/**

View File

@ -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<PictureEntity> 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<PictureEntity> pictureEntities = pictureQuery.selectPicture(lotNo, machineNo, materialNo, modelNo, machineTypeNo, craftItemName);
// if (pictureEntities.isEmpty()) {
// return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该图片!", locale);
// }
// return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntities, locale);
// }
}

View File

@ -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<DataSource, Long>, JpaSpecificationExecutor<DataSource> {
@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<Map<String, String>> 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<DataSource> 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);
}

View File

@ -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<PictureEntity, Long>, 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<PictureEntity> 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<PictureEntity> selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String machineTypeNo, String craftItemName);
}

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -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<String> 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<String> getPicturePath() {
return picturePath;
}
public void setPicturePath(List<String> 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 +
'}';
}
}

View File

@ -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("");
}
}

View File

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

View File

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