129 lines
5.2 KiB
Java
Raw Normal View History

2022-03-11 17:33:03 +08:00
package com.xkrs.service.impl;
2022-03-10 19:24:42 +08:00
2022-03-10 21:18:49 +08:00
import com.xkrs.encapsulation.PromptMessageEnum;
2022-03-11 17:30:56 +08:00
import com.xkrs.dao.QcItemDao;
import com.xkrs.dao.QcSpecDao;
2022-03-11 17:33:03 +08:00
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;
2022-03-10 20:09:26 +08:00
import org.springframework.context.i18n.LocaleContextHolder;
2022-03-11 16:07:31 +08:00
import org.springframework.stereotype.Service;
2022-03-10 20:09:26 +08:00
import javax.annotation.Resource;
2022-03-11 11:55:54 +08:00
import java.util.List;
2022-03-10 20:09:26 +08:00
import java.util.Locale;
2022-03-11 11:55:54 +08:00
import java.util.Map;
2022-03-10 21:18:49 +08:00
import java.util.Optional;
import static com.xkrs.encapsulation.OutputEncapsulation.outputEncapsulationObject;
2022-03-10 19:24:42 +08:00
2022-03-11 16:07:31 +08:00
@Service
2022-03-10 19:24:42 +08:00
public class QcSpecServiceImpl implements QcSpecService {
2022-03-10 20:09:26 +08:00
private Locale locale = LocaleContextHolder.getLocale();
2022-03-10 21:18:49 +08:00
@Resource
private QcItemDao qcItemDao;
2022-03-10 20:09:26 +08:00
@Resource
private QcSpecDao qcSpecDao;
2022-03-10 21:18:49 +08:00
/**
2022-03-11 15:37:06 +08:00
* 添加检验规格
2022-03-10 21:18:49 +08:00
*/
2022-03-10 19:33:25 +08:00
@Override
public String insertQcSpec(QcSpecQoInsert insertQo) {
2022-03-10 21:18:49 +08:00
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()) {
2022-03-11 16:30:05 +08:00
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
2022-03-10 21:18:49 +08:00
}
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("");
2022-03-11 14:58:46 +08:00
entity.setVarietyNo(LocalStringUtils.formatEmptyValue(varietyNo));
entity.setQcItemNo(LocalStringUtils.formatEmptyValue(qcItemNo));
2022-03-10 21:18:49 +08:00
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);
2022-03-10 19:33:25 +08:00
}
2022-03-11 09:11:06 +08:00
/**
2022-03-11 15:37:06 +08:00
* 删除检验规格
*/
@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);
}
/**
* 更新检验规格
2022-03-11 09:11:06 +08:00
*/
2022-03-10 19:33:25 +08:00
@Override
public String updateQcSpec(QcSpecQoUpdate updateQo) {
2022-03-11 09:11:06 +08:00
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);
}
2022-03-11 14:58:46 +08:00
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));
2022-03-11 09:11:06 +08:00
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "修改成功!", locale);
2022-03-10 19:33:25 +08:00
}
2022-03-11 10:28:36 +08:00
/**
2022-03-11 15:37:06 +08:00
* 查询检验规格
2022-03-11 10:28:36 +08:00
*/
@Override
2022-03-11 16:07:31 +08:00
public String queryQcSpec(String varietyNo, String qcItemNo) {
2022-03-11 11:55:54 +08:00
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);
2022-03-11 10:28:36 +08:00
}
2022-03-10 19:24:42 +08:00
}