更新图片表

This commit is contained in:
liuchengqian 2022-03-01 10:04:28 +08:00
parent daf1d0a14c
commit 9cf2698ec8
7 changed files with 267 additions and 1 deletions

View File

@ -0,0 +1,62 @@
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.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;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Locale;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* @Author: XinYi Song
* @Date: 2022/1/20 16:01
*/
@RestController
public class PictureController {
@Resource
private PictureService pictureService;
@Resource
private PictureDao pictureDao;
/**
* 上传图片
*/
@PostMapping("/insertPicture")
public String insertPicture(PictureQo pictureQo, @RequestParam("filePicture") MultipartFile filePicture) throws IOException {
return pictureService.insertPicture(pictureQo, filePicture);
}
/**
* 查询图片
*/
@PostMapping("/selectPicture")
public String selectPicture(@RequestBody PictureQo pictureQo) throws IOException, InvalidFormatException {
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) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该零件的图片!", locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, pictureEntity, locale);
}
}

View File

@ -0,0 +1,46 @@
package com.xkrs.dao;
import com.xkrs.model.entity.PictureEntity;
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;
/**
* @Author: XinYi Song
* @Date: 2022/1/19 16:41
*/
@Component
public interface PictureDao extends JpaRepository<PictureEntity, Long>, JpaSpecificationExecutor<PictureEntity> {
/**
* 查询图片信息
*
* @param lotNo 批次号
* @param machineNo 机器号
* @param materialNo 物料号
* @param modelNo 模具号
* @param partNo 零件号
* @return
*/
@Query(value = "SELECT * FROM qc_inspection_picture WHERE lot_no = ? AND machine_no = ? AND material_no = ? AND model_no = ? AND part_no = ? ", nativeQuery = true)
Optional<PictureEntity> selectPicture(String lotNo, String machineNo, String materialNo, String modelNo, String partNo);
/**
* 修改图片路径信息
*
* @param lotNo 批次号
* @param machineNo 机器号
* @param materialNo 物料号
* @param modelNo 模具号
* @param partNo 零件号
* @param picturePath 图片路径
*/
@Modifying(clearAutomatically = true)
@Query(value = "UPDATE qc_inspection_picture SET picture_path = ?6 where lot_no = ?1 and machine_no = ?2 and material_no = ?3 and model_no = ?4 and part_no = ?5",nativeQuery = true)
void updatePicturePath(String lotNo, String machineNo, String materialNo, String modelNo, String partNo, String picturePath);
}

View File

@ -0,0 +1,82 @@
package com.xkrs.model.qo;
import com.xkrs.model.validation.PictureQoInsert;
import javax.validation.constraints.NotBlank;
public class PictureQo {
/**
* 批次号
*/
@NotBlank(message = "{PictureEntity.lotNo.blank}", groups = {PictureQoInsert.class})
private String lotNo;
/**
* 机器号
*/
@NotBlank(message = "{PictureEntity.machineNo.blank}", groups = {PictureQoInsert.class})
private String machineNo;
/**
* 物料号
*/
@NotBlank(message = "{PictureEntity.materialNo.blank}", groups = {PictureQoInsert.class})
private String materialNo;
/**
* 模具号
*/
@NotBlank(message = "{PictureEntity.modelNo.blank}", groups = {PictureQoInsert.class})
private String modelNo;
/**
* 零件号
*/
@NotBlank(message = "{PictureEntity.partNo.blank}", groups = {PictureQoInsert.class})
private String partNo;
public PictureQo() {
}
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 getPartNo() {
return partNo;
}
public void setPartNo(String partNo) {
this.partNo = partNo;
}
}

View File

@ -0,0 +1,8 @@
package com.xkrs.model.validation;
/**
* @Author: XinYi Song
* @Date: 2022/1/20 15:26
*/
public interface PictureQoInsert {
}

View File

@ -0,0 +1,19 @@
package com.xkrs.service;
import com.xkrs.model.qo.PictureQo;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
/**
* @Author: XinYi Song
* @Date: 2022/1/20 15:24
*/
public interface PictureService {
/**
* 添加图片
*/
String insertPicture(PictureQo pictureQo, MultipartFile pictureFile)throws IOException;
}

View File

@ -0,0 +1,48 @@
package com.xkrs.service.impl;
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.ExcelUploadUtil;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.Locale;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
@Service
public class PictureServiceImpl implements PictureService {
@Resource
private PictureDao pictureDao;
@Override
public String insertPicture(PictureQo pictureQo, MultipartFile pictureFile) throws IOException {
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) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "请勿重复添加!", locale);
}
String file = ExcelUploadUtil.memoryFile(pictureFile);
PictureEntity pictureEntity1 = new PictureEntity();
pictureEntity1.setLotNo(lotNo);
pictureEntity1.setMachineNo(machineNo);
pictureEntity1.setMaterialNo(materialNo);
pictureEntity1.setModelNo(modelNo);
pictureEntity1.setPartNo(partNo);
pictureEntity1.setPicturePath(file);
pictureDao.save(pictureEntity1);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
}
}

View File

@ -29,7 +29,8 @@ public class ExcelUploadUtil {
*/ */
public static String memoryFile(MultipartFile fileExcel) throws IOException { public static String memoryFile(MultipartFile fileExcel) throws IOException {
//String uploadPath = "http://139.199.98.175:2088/wfTaskImage/"; //String uploadPath = "http://139.199.98.175:2088/wfTaskImage/";
String uploadPath = "http://192.168.2.9:2088/"; // String uploadPath = "http://192.168.2.9:2088/";
String uploadPath = "http://118.24.27.47:4096/";
//获取原始文件名 //获取原始文件名
String originalFilename = fileExcel.getOriginalFilename(); String originalFilename = fileExcel.getOriginalFilename();
if (originalFilename != null && !"".equals(originalFilename)) { if (originalFilename != null && !"".equals(originalFilename)) {