package com.xkrs.service.impl; import com.xkrs.dao.DataDictDao; import com.xkrs.dao.DataSourceDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.DataDict; import com.xkrs.model.entity.DataSource; import com.xkrs.model.qo.DataSourceQo; import com.xkrs.service.DataSourceService; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Locale; import java.util.Optional; import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject; /** * @Author: XinYi Song * @Date: 2022/1/19 16:43 */ @Service public class DataSourceServiceImpl implements DataSourceService { @Resource private DataSourceDao dataSourceDao; @Resource private DataDictDao dataDictDao; /** * 添加测量数据 * * @param dataSourceQo * @return */ @Override public String insertDataSource(DataSourceQo dataSourceQo) { Locale locale = LocaleContextHolder.getLocale(); Optional byInspectionItemCode = dataDictDao.findByInspectionItemCode(dataSourceQo.getInspectionItemCode()); if (byInspectionItemCode.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该字典类型!", locale); } DataSource dataSource = new DataSource(); initDataSource(dataSource); dataSource.setLotNo(dataSourceQo.getLotNo()); dataSource.setMachineNo(dataSourceQo.getMachineNo()); dataSource.setMaterialNo(dataSourceQo.getMaterialNo()); dataSource.setModelNo(dataSourceQo.getModelNo()); dataSource.setMachineTypeNo(dataSourceQo.getMachineTypeNo()); dataSource.setCraftItemName(dataSourceQo.getCraftItemName()); dataSource.setInspectionItemCode(dataSourceQo.getInspectionItemCode()); dataSource.setInspectValue(dataSourceQo.getInspectValue()); dataSourceDao.save(dataSource); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } private void initDataSource(DataSource dataSource) { dataSource.setLotNo(""); dataSource.setMachineNo(""); dataSource.setMaterialNo(""); dataSource.setModelNo(""); dataSource.setMachineTypeNo(""); dataSource.setInspectionItemCode(""); dataSource.setCraftItemName(""); dataSource.setInspectValue(""); dataSource.setPicturePath(""); } }