From 4ec647932173854ea71ca65b652b2ab93d4420bd Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Thu, 10 Mar 2022 20:09:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B4=A8=E6=A3=80=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xkrs/newpro/dao/QcItemDao.java | 5 +++ .../xkrs/newpro/service/QcItemService.java | 3 ++ .../service/impl/QcItemServiceImpl.java | 40 ++++++++++++++++++- .../service/impl/QcSourceServiceImpl.java | 11 +++++ .../service/impl/QcSpecServiceImpl.java | 12 ++++++ .../com/xkrs/newpro/utils/LocalDateUtils.java | 17 ++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java diff --git a/src/main/java/com/xkrs/newpro/dao/QcItemDao.java b/src/main/java/com/xkrs/newpro/dao/QcItemDao.java index 00e01a9..c634c45 100644 --- a/src/main/java/com/xkrs/newpro/dao/QcItemDao.java +++ b/src/main/java/com/xkrs/newpro/dao/QcItemDao.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 QcItemDao extends JpaRepository, JpaSpecificationExecutor { + + Optional findByNo(String no); + } diff --git a/src/main/java/com/xkrs/newpro/service/QcItemService.java b/src/main/java/com/xkrs/newpro/service/QcItemService.java index b9f8aed..f7d676f 100644 --- a/src/main/java/com/xkrs/newpro/service/QcItemService.java +++ b/src/main/java/com/xkrs/newpro/service/QcItemService.java @@ -5,6 +5,9 @@ import com.xkrs.newpro.model.qo.QcItemQoUpdate; public interface QcItemService { + /** + * 添加质检项 + */ String insertQcItem(QcItemQoInsert insertQo); String updateQcItem(QcItemQoUpdate 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 b930417..3520d10 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcItemServiceImpl.java @@ -1,13 +1,51 @@ package com.xkrs.newpro.service.impl; +import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.newpro.dao.QcItemDao; +import com.xkrs.newpro.model.entity.QcItemEntity; import com.xkrs.newpro.model.qo.QcItemQoInsert; import com.xkrs.newpro.model.qo.QcItemQoUpdate; import com.xkrs.newpro.service.QcItemService; +import com.xkrs.newpro.utils.LocalDateUtils; +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 QcItemServiceImpl implements QcItemService { + + private Locale locale = LocaleContextHolder.getLocale(); + + @Resource + private QcItemDao qcItemDao; + + /** + * 添加质检项 + */ @Override public String insertQcItem(QcItemQoInsert insertQo) { - return null; + + String no = insertQo.getNo(); + String name = insertQo.getName(); + String type = insertQo.getType(); + + Optional entityByNo = qcItemDao.findByNo(no); + if (entityByNo.isPresent()) { + return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该检验项目已存在,请勿重复添加!", locale); + } + + QcItemEntity entity = new QcItemEntity(); + entity.setCreateTime(LocalDateUtils.getFormatDateToSecond()); + entity.setUpdateTime(""); + entity.setNo(no); + entity.setName(name); + entity.setType(type); + qcItemDao.save(entity); + + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } @Override 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 3f0d3a0..b83bc5b 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcSourceServiceImpl.java @@ -1,9 +1,20 @@ package com.xkrs.newpro.service.impl; +import com.xkrs.newpro.dao.QcSourceDao; import com.xkrs.newpro.model.qo.QcSourceQoInsert; import com.xkrs.newpro.service.QcSourceService; +import org.springframework.context.i18n.LocaleContextHolder; + +import javax.annotation.Resource; +import java.util.Locale; public class QcSourceServiceImpl implements QcSourceService { + + private Locale locale = LocaleContextHolder.getLocale(); + + @Resource + private QcSourceDao qcSourceDao; + @Override public String insertQcSource(QcSourceQoInsert insertQo) { return null; 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 9ed0410..6c2213d 100644 --- a/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java +++ b/src/main/java/com/xkrs/newpro/service/impl/QcSpecServiceImpl.java @@ -1,10 +1,22 @@ package com.xkrs.newpro.service.impl; +import com.xkrs.newpro.dao.QcSourceDao; +import com.xkrs.newpro.dao.QcSpecDao; import com.xkrs.newpro.model.qo.QcSpecQoInsert; import com.xkrs.newpro.model.qo.QcSpecQoUpdate; import com.xkrs.newpro.service.QcSpecService; +import org.springframework.context.i18n.LocaleContextHolder; + +import javax.annotation.Resource; +import java.util.Locale; public class QcSpecServiceImpl implements QcSpecService { + + private Locale locale = LocaleContextHolder.getLocale(); + + @Resource + private QcSpecDao qcSpecDao; + @Override public String insertQcSpec(QcSpecQoInsert insertQo) { return null; diff --git a/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java b/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java new file mode 100644 index 0000000..58a6b74 --- /dev/null +++ b/src/main/java/com/xkrs/newpro/utils/LocalDateUtils.java @@ -0,0 +1,17 @@ +package com.xkrs.newpro.utils; + +import cn.hutool.core.date.DateUtil; + +import java.util.Date; + +public class LocalDateUtils { + + private LocalDateUtils() { + } + + public static String getFormatDateToSecond() { + + return DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"); + + } +}