From daf1d0a14c205bad33cdf3e2fe715e73ff3a3033 Mon Sep 17 00:00:00 2001 From: liuchengqian Date: Tue, 1 Mar 2022 09:36:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=A7=84=E6=A0=BC=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xkrs/controller/SpecController.java | 55 +++++++ src/main/java/com/xkrs/dao/SpecDao.java | 19 +++ src/main/java/com/xkrs/model/qo/SpecQo.java | 136 ++++++++++++++++++ .../xkrs/model/validation/SpecQoInsert.java | 8 ++ .../java/com/xkrs/service/SpecService.java | 19 +++ .../xkrs/service/impl/SpecServiceImpl.java | 42 ++++++ 6 files changed, 279 insertions(+) create mode 100644 src/main/java/com/xkrs/controller/SpecController.java create mode 100644 src/main/java/com/xkrs/dao/SpecDao.java create mode 100644 src/main/java/com/xkrs/model/qo/SpecQo.java create mode 100644 src/main/java/com/xkrs/model/validation/SpecQoInsert.java create mode 100644 src/main/java/com/xkrs/service/SpecService.java create mode 100644 src/main/java/com/xkrs/service/impl/SpecServiceImpl.java diff --git a/src/main/java/com/xkrs/controller/SpecController.java b/src/main/java/com/xkrs/controller/SpecController.java new file mode 100644 index 0000000..8a1b718 --- /dev/null +++ b/src/main/java/com/xkrs/controller/SpecController.java @@ -0,0 +1,55 @@ +package com.xkrs.controller; + +import com.xkrs.dao.SpecDao; +import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.model.entity.SpecEntity; +import com.xkrs.model.qo.SpecQo; +import com.xkrs.service.SpecService; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Locale; + +import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; + +/** + * @Author: XinYi Song + * @Date: 2022/1/20 16:01 + */ +@RestController +public class SpecController { + + @Resource + private SpecService specService; + + @Resource + private SpecDao specDao; + + /** + * 添加规格数据 + * + * @param specQo + */ + @PostMapping("/insertSpec") + public String insertSpec(SpecQo specQo) { + return specService.insertSpec(specQo); + } + + /** + * 查询规格信息 + */ + @PostMapping("/selectSpec") + public String selectSpec(@RequestBody SpecQo specQo) { + Locale locale = LocaleContextHolder.getLocale(); + String partNo = specQo.getPartNo(); + String inspectionItemCode = specQo.getInspectionItemCode(); + SpecEntity specEntity = specDao.findByPartNoAndInspectionItemCode(partNo, inspectionItemCode).get(); + if (specEntity == null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该零件的规格信息!", locale); + } + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, specEntity, locale); + } +} diff --git a/src/main/java/com/xkrs/dao/SpecDao.java b/src/main/java/com/xkrs/dao/SpecDao.java new file mode 100644 index 0000000..57638e7 --- /dev/null +++ b/src/main/java/com/xkrs/dao/SpecDao.java @@ -0,0 +1,19 @@ +package com.xkrs.dao; + +import com.xkrs.model.entity.SpecEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.stereotype.Component; + +import java.util.Optional; + +/** + * @Author: XinYi Song + * @Date: 2022/1/19 16:41 + */ +@Component +public interface SpecDao extends JpaRepository, JpaSpecificationExecutor { + + Optional findByPartNoAndInspectionItemCode(String partNo, String inspectionItemCode); + +} diff --git a/src/main/java/com/xkrs/model/qo/SpecQo.java b/src/main/java/com/xkrs/model/qo/SpecQo.java new file mode 100644 index 0000000..6984bc1 --- /dev/null +++ b/src/main/java/com/xkrs/model/qo/SpecQo.java @@ -0,0 +1,136 @@ +package com.xkrs.model.qo; + +import com.xkrs.model.validation.SpecQoInsert; + +import javax.validation.constraints.NotBlank; + +public class SpecQo { + + /** + * 零件号 + */ + @NotBlank(message = "{SpecEntity.partNo.blank}", groups = {SpecQoInsert.class}) + private String partNo; + + /** + * 检验项代码 + */ + @NotBlank(message = "{SpecEntity.inspectionItemCode.blank}", groups = {SpecQoInsert.class}) + private String inspectionItemCode; + + /** + * 最大值 + */ + @NotBlank(message = "{SpecEntity.max.blank}", groups = {SpecQoInsert.class}) + private String max; + + /** + * 平均值 + */ + @NotBlank(message = "{SpecEntity.mean.blank}", groups = {SpecQoInsert.class}) + private String mean; + + /** + * 最小值 + */ + @NotBlank(message = "{SpecEntity.min.blank}", groups = {SpecQoInsert.class}) + private String min; + + /** + * 单位 + */ + @NotBlank(message = "{SpecEntity.unit.blank}", groups = {SpecQoInsert.class}) + private String unit; + + /** + * 检验方法 + */ + @NotBlank(message = "{SpecEntity.inspectionMethod.blank}", groups = {SpecQoInsert.class}) + private String inspectionMethod; + + /** + * 检验标准 + */ + @NotBlank(message = "{SpecEntity.inspectionStandard.blank}", groups = {SpecQoInsert.class}) + private String inspectionStandard; + + /** + * 备注 + */ + private String remark; + + public SpecQo() { + } + + public String getPartNo() { + return partNo; + } + + public void setPartNo(String partNo) { + this.partNo = partNo; + } + + public String getInspectionItemCode() { + return inspectionItemCode; + } + + public void setInspectionItemCode(String inspectionItemCode) { + this.inspectionItemCode = inspectionItemCode; + } + + public String getMax() { + return max; + } + + public void setMax(String max) { + this.max = max; + } + + public String getMean() { + return mean; + } + + public void setMean(String mean) { + this.mean = mean; + } + + public String getMin() { + return min; + } + + public void setMin(String min) { + this.min = min; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getInspectionMethod() { + return inspectionMethod; + } + + public void setInspectionMethod(String inspectionMethod) { + this.inspectionMethod = inspectionMethod; + } + + public String getInspectionStandard() { + return inspectionStandard; + } + + public void setInspectionStandard(String inspectionStandard) { + this.inspectionStandard = inspectionStandard; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } +} diff --git a/src/main/java/com/xkrs/model/validation/SpecQoInsert.java b/src/main/java/com/xkrs/model/validation/SpecQoInsert.java new file mode 100644 index 0000000..93f09aa --- /dev/null +++ b/src/main/java/com/xkrs/model/validation/SpecQoInsert.java @@ -0,0 +1,8 @@ +package com.xkrs.model.validation; + +/** + * @Author: XinYi Song + * @Date: 2022/1/19 10:22 + */ +public interface SpecQoInsert { +} diff --git a/src/main/java/com/xkrs/service/SpecService.java b/src/main/java/com/xkrs/service/SpecService.java new file mode 100644 index 0000000..d215ea4 --- /dev/null +++ b/src/main/java/com/xkrs/service/SpecService.java @@ -0,0 +1,19 @@ +package com.xkrs.service; + +import com.xkrs.model.qo.SpecQo; + +/** + * @Author: XinYi Song + * @Date: 2022/1/20 15:24 + */ +public interface SpecService { + + /** + * 添加规格数据 + * + * @param specQo + * @return + */ + String insertSpec(SpecQo specQo); + +} diff --git a/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java b/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java new file mode 100644 index 0000000..66fbb4b --- /dev/null +++ b/src/main/java/com/xkrs/service/impl/SpecServiceImpl.java @@ -0,0 +1,42 @@ +package com.xkrs.service.impl; + +import com.xkrs.dao.SpecDao; +import com.xkrs.encapsulation.PromptMessageEnum; +import com.xkrs.model.entity.SpecEntity; +import com.xkrs.model.qo.SpecQo; +import com.xkrs.service.SpecService; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.Locale; + +import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; + +@Service +public class SpecServiceImpl implements SpecService { + + @Resource + private SpecDao specDao; + + @Override + public String insertSpec(SpecQo specQo) { + Locale locale = LocaleContextHolder.getLocale(); + SpecEntity specEntity = specDao.findByPartNoAndInspectionItemCode(specQo.getPartNo(), specQo.getInspectionItemCode()).get(); + if (specEntity != null) { + return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "已存在该测量规格!", locale); + } + SpecEntity specEntity1 = new SpecEntity(); + specEntity1.setPartNo(specQo.getPartNo()); + specEntity1.setInspectionItemCode(specQo.getInspectionItemCode()); + specEntity1.setMax(specQo.getMax()); + specEntity1.setMean(specQo.getMean()); + specEntity1.setMin(specQo.getMin()); + specEntity1.setUnit(specQo.getUnit()); + specEntity1.setInspectionMethod(specQo.getInspectionMethod()); + specEntity1.setInspectionStandard(specQo.getInspectionStandard()); + specEntity1.setRemark(specQo.getRemark()); + specDao.save(specEntity1); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); + } +}