完善 添加检验数据

This commit is contained in:
liuchengqian 2022-03-11 17:03:37 +08:00
parent 9f33ffdd1f
commit e86b8716d5
3 changed files with 66 additions and 22 deletions

View File

@ -43,6 +43,8 @@ public class QcItemEntity {
/** /**
* 类型 * 类型
* "0":文本格式
* "1":图片格式
*/ */
@Column(length = 85, columnDefinition = "varchar(85)") @Column(length = 85, columnDefinition = "varchar(85)")
private String type; private String type;
@ -100,13 +102,6 @@ public class QcItemEntity {
@Override @Override
public String toString() { public String toString() {
return "QcItemEntity{" + return "QcItemEntity{" + "id=" + id + ", createTime='" + createTime + '\'' + ", updateTime='" + updateTime + '\'' + ", no='" + no + '\'' + ", name='" + name + '\'' + ", type='" + type + '\'' + '}';
"id=" + id +
", createTime='" + createTime + '\'' +
", updateTime='" + updateTime + '\'' +
", no='" + no + '\'' +
", name='" + name + '\'' +
", type='" + type + '\'' +
'}';
} }
} }

View File

@ -1,18 +1,23 @@
package com.xkrs.newpro.service.impl; package com.xkrs.newpro.service.impl;
import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.encapsulation.PromptMessageEnum;
import com.xkrs.newpro.dao.QcItemDao;
import com.xkrs.newpro.dao.QcSourceDao; 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.entity.QcSourceEntity;
import com.xkrs.newpro.model.qo.QcSourceQoDelete; import com.xkrs.newpro.model.qo.QcSourceQoDelete;
import com.xkrs.newpro.model.qo.QcSourceQoInsert; import com.xkrs.newpro.model.qo.QcSourceQoInsert;
import com.xkrs.newpro.service.QcSourceService; import com.xkrs.newpro.service.QcSourceService;
import com.xkrs.newpro.utils.Constant;
import com.xkrs.newpro.utils.LocalDateUtils; import com.xkrs.newpro.utils.LocalDateUtils;
import com.xkrs.newpro.utils.LocalStringUtils; import com.xkrs.newpro.utils.LocalStringUtils;
import com.xkrs.util.ExcelUploadUtil;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -25,6 +30,9 @@ public class QcSourceServiceImpl implements QcSourceService {
private Locale locale = LocaleContextHolder.getLocale(); private Locale locale = LocaleContextHolder.getLocale();
@Resource
private QcItemDao qcItemDao;
@Resource @Resource
private QcSourceDao qcSourceDao; private QcSourceDao qcSourceDao;
@ -33,7 +41,6 @@ public class QcSourceServiceImpl implements QcSourceService {
*/ */
@Override @Override
public String insertQcSource(QcSourceQoInsert insertQo, MultipartFile picture) { public String insertQcSource(QcSourceQoInsert insertQo, MultipartFile picture) {
String batchNo = insertQo.getBatchNo(); String batchNo = insertQo.getBatchNo();
String machineNo = insertQo.getMachineNo(); String machineNo = insertQo.getMachineNo();
String materialNo = insertQo.getMaterialNo(); String materialNo = insertQo.getMaterialNo();
@ -41,19 +48,47 @@ public class QcSourceServiceImpl implements QcSourceService {
String varietyNo = insertQo.getVarietyNo(); String varietyNo = insertQo.getVarietyNo();
String qcItemNo = insertQo.getQcItemNo(); String qcItemNo = insertQo.getQcItemNo();
String qcValue = insertQo.getQcValue(); String qcValue = insertQo.getQcValue();
Optional<QcItemEntity> qcItemEntityByNo = qcItemDao.findByNo(qcItemNo);
QcSourceEntity entity = new QcSourceEntity(); if (qcItemEntityByNo.isEmpty()) {
entity.setCreateTime(LocalDateUtils.getCurrentSecond()); return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo)); }
entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo)); if (Constant.QC_ITEM_TYPE_STRING.equals(qcItemEntityByNo.get().getType())) {
entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo)); QcSourceEntity entity = new QcSourceEntity();
entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo)); entity.setCreateTime(LocalDateUtils.getCurrentSecond());
entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo)); entity.setBatchNo(LocalStringUtils.formatEmptyValue(batchNo));
entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo)); entity.setMachineNo(LocalStringUtils.formatEmptyValue(machineNo));
entity.setQcValue(LocalStringUtils.formatEmptyValue(qcValue)); entity.setMaterialNo(LocalStringUtils.formatEmptyValue(materialNo));
qcSourceDao.save(entity); entity.setMouldNo(LocalStringUtils.formatEmptyValue(mouldNo));
entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo));
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); 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);
} }
/** /**

View File

@ -0,0 +1,14 @@
package com.xkrs.newpro.utils;
public interface Constant {
/**
* 检验项目类型文本
*/
String QC_ITEM_TYPE_STRING = "0";
/**
* 检验项目类型图片
*/
String QC_ITEM_TYPE_PICTURE = "1";
}