更新规格表
This commit is contained in:
		
							
								
								
									
										55
									
								
								src/main/java/com/xkrs/controller/SpecController.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/main/java/com/xkrs/controller/SpecController.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								src/main/java/com/xkrs/dao/SpecDao.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/java/com/xkrs/dao/SpecDao.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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<SpecEntity, Long>, JpaSpecificationExecutor<SpecEntity> { | ||||
|  | ||||
|     Optional<SpecEntity> findByPartNoAndInspectionItemCode(String partNo, String inspectionItemCode); | ||||
|  | ||||
| } | ||||
							
								
								
									
										136
									
								
								src/main/java/com/xkrs/model/qo/SpecQo.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								src/main/java/com/xkrs/model/qo/SpecQo.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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; | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,8 @@ | ||||
| package com.xkrs.model.validation; | ||||
|  | ||||
| /** | ||||
|  * @Author: XinYi Song | ||||
|  * @Date: 2022/1/19 10:22 | ||||
|  */ | ||||
| public interface SpecQoInsert { | ||||
| } | ||||
							
								
								
									
										19
									
								
								src/main/java/com/xkrs/service/SpecService.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/main/java/com/xkrs/service/SpecService.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||
|  | ||||
| } | ||||
							
								
								
									
										42
									
								
								src/main/java/com/xkrs/service/impl/SpecServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								src/main/java/com/xkrs/service/impl/SpecServiceImpl.java
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user