完善 添加检验数据

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

View File

@ -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<QcItemEntity> 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);
}
/**

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";
}