From c2b9050fd6eeab8e8bfe4a535e78aa600d2d81b4 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 10 Mar 2022 21:18:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A8=E6=A3=80=E8=A7=84?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xkrs/newpro/dao/QcSpecDao.java | 5 ++ .../xkrs/newpro/service/QcSpecService.java | 3 ++ .../service/impl/QcItemServiceImpl.java | 2 +- .../service/impl/QcSourceServiceImpl.java | 2 +- .../service/impl/QcSpecServiceImpl.java | 52 ++++++++++++++++++- .../com/xkrs/newpro/utils/LocalDateUtils.java | 7 ++- .../xkrs/newpro/utils/LocalStringUtils.java | 12 +++++ 7 files changed, 75 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/xkrs/newpro/utils/LocalStringUtils.java diff --git a/src/main/java/com/xkrs/newpro/dao/QcSpecDao.java b/src/main/java/com/xkrs/newpro/dao/QcSpecDao.java index ebf787e..407feef 100644 --- a/src/main/java/com/xkrs/newpro/dao/QcSpecDao.java +++ b/src/main/java/com/xkrs/newpro/dao/QcSpecDao.java @@ -5,6 +5,11 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.stereotype.Component; +import java.util.Optional; + @Component public interface QcSpecDao extends JpaRepository, JpaSpecificationExecutor { + + Optional findByVarietyNoAndQcItemNo(String varietyNo, String qcItemNo); + } \ No newline at end of file diff --git a/src/main/java/com/xkrs/newpro/service/QcSpecService.java b/src/main/java/com/xkrs/newpro/service/QcSpecService.java index 000cffc..de4fd10 100644 --- a/src/main/java/com/xkrs/newpro/service/QcSpecService.java +++ b/src/main/java/com/xkrs/newpro/service/QcSpecService.java @@ -5,6 +5,9 @@ import com.xkrs.newpro.model.qo.QcSpecQoUpdate; public interface QcSpecService { + /** + * 添加质检规格 + */ String insertQcSpec(QcSpecQoInsert insertQo); String updateQcSpec(QcSpecQoUpdate updateQo); diff --git a/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java b/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java index 3520d10..e5f164f 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java @@ -38,7 +38,7 @@ public class QcItemServiceImpl implements QcItemService { } QcItemEntity entity = new QcItemEntity(); - entity.setCreateTime(LocalDateUtils.getFormatDateToSecond()); + entity.setCreateTime(LocalDateUtils.getCurrentSecond()); entity.setUpdateTime(""); entity.setNo(no); entity.setName(name); 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 3c01ad0..b530790 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java @@ -35,7 +35,7 @@ public class QcSourceServiceImpl implements QcSourceService { String qcValue = insertQo.getQcValue(); QcSourceEntity entity = new QcSourceEntity(); - entity.setCreateTime(LocalDateUtils.getFormatDateToSecond()); + entity.setCreateTime(LocalDateUtils.getCurrentSecond()); entity.setBatchNo(batchNo); entity.setMachineNo(machineNo); entity.setMaterialNo(materialNo); diff --git a/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java b/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java index 6c2213d..9d2f4fb 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java @@ -1,25 +1,73 @@ package com.xkrs.newpro.service.impl; -import com.xkrs.newpro.dao.QcSourceDao; +import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.newpro.dao.QcItemDao; import com.xkrs.newpro.dao.QcSpecDao; +import com.xkrs.newpro.model.entity.QcItemEntity; +import com.xkrs.newpro.model.entity.QcSpecEntity; import com.xkrs.newpro.model.qo.QcSpecQoInsert; import com.xkrs.newpro.model.qo.QcSpecQoUpdate; import com.xkrs.newpro.service.QcSpecService; +import com.xkrs.newpro.utils.LocalDateUtils; +import com.xkrs.newpro.utils.LocalStringUtils; import org.springframework.context.i18n.LocaleContextHolder; import javax.annotation.Resource; import java.util.Locale; +import java.util.Optional; + +import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; public class QcSpecServiceImpl implements QcSpecService { private Locale locale = LocaleContextHolder.getLocale(); + @Resource + private QcItemDao qcItemDao; + @Resource private QcSpecDao qcSpecDao; + /** + * 添加质检规格 + */ @Override public String insertQcSpec(QcSpecQoInsert insertQo) { - return null; + + String varietyNo = insertQo.getVarietyNo(); + String qcItemNo = insertQo.getQcItemNo(); + String max = insertQo.getMax(); + String mean = insertQo.getMean(); + String min = insertQo.getMin(); + String unit = insertQo.getUnit(); + String method = insertQo.getMethod(); + String standard = insertQo.getStandard(); + String remark = insertQo.getRemark(); + + Optional entityByNo = qcItemDao.findByNo(qcItemNo); + if (entityByNo.isEmpty()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale); + } + + Optional entityByVarietyNoAndQcItemNo = qcSpecDao.findByVarietyNoAndQcItemNo(varietyNo, qcItemNo); + if (entityByVarietyNoAndQcItemNo.isPresent()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该检验规格已存在,请勿重复添加!", locale); + } + QcSpecEntity entity = new QcSpecEntity(); + entity.setCreateTime(LocalDateUtils.getCurrentSecond()); + entity.setUpdateTime(""); + entity.setVarietyNo(varietyNo); + entity.setQcItemNo(qcItemNo); + entity.setMax(LocalStringUtils.formatEmptyValue(max)); + entity.setMean(LocalStringUtils.formatEmptyValue(mean)); + entity.setMin(LocalStringUtils.formatEmptyValue(min)); + entity.setUnit(LocalStringUtils.formatEmptyValue(unit)); + entity.setMethod(LocalStringUtils.formatEmptyValue(method)); + entity.setStandard(LocalStringUtils.formatEmptyValue(standard)); + entity.setRemark(LocalStringUtils.formatEmptyValue(remark)); + qcSpecDao.save(entity); + + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } @Override diff --git a/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java b/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java index 58a6b74..4c7955d 100644 --- a/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java +++ b/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java @@ -1,7 +1,5 @@ package com.xkrs.newpro.utils; -import cn.hutool.core.date.DateUtil; - import java.util.Date; public class LocalDateUtils { @@ -9,9 +7,10 @@ public class LocalDateUtils { private LocalDateUtils() { } - public static String getFormatDateToSecond() { + public static String getCurrentSecond() { - return DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); +// return DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); + return String.valueOf(new Date().getTime() / 1000L); } } diff --git a/src/main/java/com/xkrs/newpro/utils/LocalStringUtils.java b/src/main/java/com/xkrs/newpro/utils/LocalStringUtils.java new file mode 100644 index 0000000..7797ff7 --- /dev/null +++ b/src/main/java/com/xkrs/newpro/utils/LocalStringUtils.java @@ -0,0 +1,12 @@ +package com.xkrs.newpro.utils; + +public class LocalStringUtils { + + private LocalStringUtils() { + } + + public static String formatEmptyValue(String value) { + return value == null ? "" : value; + } + +}