132 lines
5.3 KiB
Java
132 lines
5.3 KiB
Java
package com.xkrs.service.impl;
|
|
|
|
import com.xkrs.dao.QcItemDao;
|
|
import com.xkrs.dao.QcSpecDao;
|
|
import com.xkrs.encapsulation.PromptMessageEnum;
|
|
import com.xkrs.model.entity.QcItemEntity;
|
|
import com.xkrs.model.entity.QcSpecEntity;
|
|
import com.xkrs.model.qo.QcSpecQoDelete;
|
|
import com.xkrs.model.qo.QcSpecQoInsert;
|
|
import com.xkrs.model.qo.QcSpecQoUpdate;
|
|
import com.xkrs.service.QcSpecService;
|
|
import com.xkrs.util.LocalDateUtils;
|
|
import com.xkrs.util.LocalStringUtils;
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.transaction.Transactional;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Optional;
|
|
|
|
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
|
|
|
|
@Service
|
|
public class QcSpecServiceImpl implements QcSpecService {
|
|
|
|
private Locale locale = LocaleContextHolder.getLocale();
|
|
|
|
@Resource
|
|
private QcItemDao qcItemDao;
|
|
|
|
@Resource
|
|
private QcSpecDao qcSpecDao;
|
|
|
|
/**
|
|
* 添加检验规格
|
|
*/
|
|
@Override
|
|
public String insertQcSpec(QcSpecQoInsert insertQo) {
|
|
|
|
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<QcItemEntity> entityByNo = qcItemDao.findByNo(qcItemNo);
|
|
if (entityByNo.isEmpty()) {
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
|
|
}
|
|
|
|
Optional<QcSpecEntity> 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(LocalStringUtils.formatEmptyValue(varietyNo));
|
|
entity.setQcItemNo(LocalStringUtils.formatEmptyValue(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);
|
|
}
|
|
|
|
/**
|
|
* 删除检验规格
|
|
*/
|
|
@Transactional(rollbackOn = Exception.class)
|
|
@Override
|
|
public String deleteQcSpec(QcSpecQoDelete deleteQo) {
|
|
Integer id = deleteQo.getId();
|
|
Optional<QcSpecEntity> entityById = qcSpecDao.findById(id);
|
|
if (entityById.isEmpty()) {
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验规格,请先添加检验规格!", locale);
|
|
}
|
|
qcSpecDao.deleteById(id);
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale);
|
|
}
|
|
|
|
/**
|
|
* 更新检验规格
|
|
*/
|
|
@Transactional(rollbackOn = Exception.class)
|
|
@Override
|
|
public String updateQcSpec(QcSpecQoUpdate updateQo) {
|
|
|
|
Integer id = updateQo.getId();
|
|
String max = updateQo.getMax();
|
|
String mean = updateQo.getMean();
|
|
String min = updateQo.getMin();
|
|
String unit = updateQo.getUnit();
|
|
String method = updateQo.getMethod();
|
|
String standard = updateQo.getStandard();
|
|
String remark = updateQo.getRemark();
|
|
|
|
Optional<QcSpecEntity> entityById = qcSpecDao.findById(id);
|
|
if (entityById.isEmpty()) {
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验规格,请先添加检验规格!", locale);
|
|
}
|
|
|
|
qcSpecDao.updateQcSpecById(id, LocalDateUtils.getCurrentSecond(), LocalStringUtils.formatEmptyValue(max), LocalStringUtils.formatEmptyValue(mean), LocalStringUtils.formatEmptyValue(min), LocalStringUtils.formatEmptyValue(unit), LocalStringUtils.formatEmptyValue(method), LocalStringUtils.formatEmptyValue(standard), LocalStringUtils.formatEmptyValue(remark));
|
|
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
|
|
}
|
|
|
|
/**
|
|
* 查询检验规格
|
|
*/
|
|
@Override
|
|
public String queryQcSpec(String varietyNo, String qcItemNo) {
|
|
List<Map<String, Object>> resultList = qcSpecDao.queryQcSpec(LocalStringUtils.formatEmptyValue(varietyNo), LocalStringUtils.formatEmptyValue(qcItemNo));
|
|
if (resultList == null || resultList.isEmpty()) {
|
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验规格的信息!", locale);
|
|
}
|
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale);
|
|
}
|
|
}
|