From e86b8716d51ee451f73b41f332d1fb1d605a5343 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Fri, 11 Mar 2022 17:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A3=80=E9=AA=8C=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../newpro/model/entity/QcItemEntity.java | 11 +--- .../service/impl/QcSourceServiceImpl.java | 63 ++++++++++++++----- .../java/com/xkrs/newpro/utils/Constant.java | 14 +++++ 3 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/xkrs/newpro/utils/Constant.java diff --git a/src/main/java/com/xkrs/newpro/model/entity/QcItemEntity.java b/src/main/java/com/xkrs/newpro/model/entity/QcItemEntity.java index 43760dc..c3ef773 100644 --- a/src/main/java/com/xkrs/newpro/model/entity/QcItemEntity.java +++ b/src/main/java/com/xkrs/newpro/model/entity/QcItemEntity.java @@ -43,6 +43,8 @@ public class QcItemEntity { /** * 类型 + * "0":文本格式 + * "1":图片格式 */ @Column(length = 85, columnDefinition = "varchar(85)") private String type; @@ -100,13 +102,6 @@ public class QcItemEntity { @Override public String toString() { - return "QcItemEntity{" + - "id=" + id + - ", createTime='" + createTime + '\'' + - ", updateTime='" + updateTime + '\'' + - ", no='" + no + '\'' + - ", name='" + name + '\'' + - ", type='" + type + '\'' + - '}'; + return "QcItemEntity{" + "id=" + id + ", createTime='" + createTime + '\'' + ", updateTime='" + updateTime + '\'' + ", no='" + no + '\'' + ", name='" + name + '\'' + ", type='" + type + '\'' + '}'; } } diff --git a/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java b/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java index a6862e7..3ab5ddb 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java @@ -1,18 +1,23 @@ package com.xkrs.newpro.service.impl; import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.newpro.dao.QcItemDao; import com.xkrs.newpro.dao.QcSourceDao; +import com.xkrs.newpro.model.entity.QcItemEntity; import com.xkrs.newpro.model.entity.QcSourceEntity; import com.xkrs.newpro.model.qo.QcSourceQoDelete; import com.xkrs.newpro.model.qo.QcSourceQoInsert; import com.xkrs.newpro.service.QcSourceService; +import com.xkrs.newpro.utils.Constant; import com.xkrs.newpro.utils.LocalDateUtils; import com.xkrs.newpro.utils.LocalStringUtils; +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.List; import java.util.Locale; import java.util.Map; @@ -25,6 +30,9 @@ public class QcSourceServiceImpl implements QcSourceService { private Locale locale = LocaleContextHolder.getLocale(); + @Resource + private QcItemDao qcItemDao; + @Resource private QcSourceDao qcSourceDao; @@ -33,7 +41,6 @@ public class QcSourceServiceImpl implements QcSourceService { */ @Override public String insertQcSource(QcSourceQoInsert insertQo, MultipartFile picture) { - String batchNo = insertQo.getBatchNo(); String machineNo = insertQo.getMachineNo(); String materialNo = insertQo.getMaterialNo(); @@ -41,19 +48,47 @@ public class QcSourceServiceImpl implements QcSourceService { String varietyNo = insertQo.getVarietyNo(); String qcItemNo = insertQo.getQcItemNo(); String qcValue = insertQo.getQcValue(); - - QcSourceEntity entity = new QcSourceEntity(); - entity.setCreateTime(LocalDateUtils.getCurrentSecond()); - entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo)); - entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo)); - entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo)); - entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo)); - entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo)); - entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo)); - entity.setQcValue(LocalStringUtils.formatEmptyValue(qcValue)); - qcSourceDao.save(entity); - - return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); + Optional qcItemEntityByNo = qcItemDao.findByNo(qcItemNo); + if (qcItemEntityByNo.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale); + } + if (Constant.QC_ITEM_TYPE_STRING.equals(qcItemEntityByNo.get().getType())) { + QcSourceEntity entity = new QcSourceEntity(); + entity.setCreateTime(LocalDateUtils.getCurrentSecond()); + entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo)); + entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo)); + entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo)); + entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo)); + entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo)); + entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo)); + entity.setQcValue(LocalStringUtils.formatEmptyValue(qcValue)); + qcSourceDao.save(entity); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); + } + if (Constant.QC_ITEM_TYPE_PICTURE.equals(qcItemEntityByNo.get().getType())) { + if (picture == null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "上传图片不能为空!", locale); + } + String picturePath; + try { + picturePath = ExcelUploadUtil.memoryFile(picture, 2); + } catch (IOException e) { + e.printStackTrace(); + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "上传图片失败!", locale); + } + QcSourceEntity entity = new QcSourceEntity(); + entity.setCreateTime(LocalDateUtils.getCurrentSecond()); + entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo)); + entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo)); + entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo)); + entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo)); + entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo)); + entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo)); + entity.setQcValue(LocalStringUtils.formatEmptyValue(picturePath)); + qcSourceDao.save(entity); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); + } + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "添加失败!", locale); } /** diff --git a/src/main/java/com/xkrs/newpro/utils/Constant.java b/src/main/java/com/xkrs/newpro/utils/Constant.java new file mode 100644 index 0000000..80c3fc7 --- /dev/null +++ b/src/main/java/com/xkrs/newpro/utils/Constant.java @@ -0,0 +1,14 @@ +package com.xkrs.newpro.utils; + +public interface Constant { + + /** + * 检验项目类型:文本 + */ + String QC_ITEM_TYPE_STRING = "0"; + + /** + * 检验项目类型:图片 + */ + String QC_ITEM_TYPE_PICTURE = "1"; +}