96 lines
3.6 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 20:09:26 +08:00
import com.xkrs.encapsulation.PromptMessageEnum;
2022-03-11 17:30:56 +08:00
import com.xkrs.dao.QcItemDao;
2022-03-11 17:33:03 +08:00
import com.xkrs.model.entity.QcItemEntity;
import com.xkrs.model.qo.QcItemQoDelete;
import com.xkrs.model.qo.QcItemQoInsert;
import com.xkrs.model.qo.QcItemQoUpdate;
import com.xkrs.service.QcItemService;
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 10:28:36 +08:00
import javax.transaction.Transactional;
import java.util.List;
2022-03-10 20:09:26 +08:00
import java.util.Locale;
2022-03-11 10:28:36 +08:00
import java.util.Map;
2022-03-10 20:09:26 +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 QcItemServiceImpl implements QcItemService {
2022-03-10 20:09:26 +08:00
private Locale locale = LocaleContextHolder.getLocale();
@Resource
private QcItemDao qcItemDao;
/**
2022-03-11 11:55:54 +08:00
* 添加检验项目
2022-03-10 20:09:26 +08:00
*/
2022-03-10 19:33:25 +08:00
@Override
public String insertQcItem(QcItemQoInsert insertQo) {
2022-03-10 20:09:26 +08:00
String no = insertQo.getNo();
String name = insertQo.getName();
String type = insertQo.getType();
Optional<QcItemEntity> entityByNo = qcItemDao.findByNo(no);
if (entityByNo.isPresent()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该检验项目已存在,请勿重复添加!", locale);
}
QcItemEntity entity = new QcItemEntity();
2022-03-10 21:18:49 +08:00
entity.setCreateTime(LocalDateUtils.getCurrentSecond());
2022-03-10 20:09:26 +08:00
entity.setUpdateTime("");
2022-03-11 14:58:46 +08:00
entity.setNo(LocalStringUtils.formatEmptyValue(no));
entity.setName(LocalStringUtils.formatEmptyValue(name));
entity.setType(LocalStringUtils.formatEmptyValue(type));
2022-03-10 20:09:26 +08:00
qcItemDao.save(entity);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale);
2022-03-10 19:33:25 +08:00
}
2022-03-11 15:37:06 +08:00
/**
* 删除检验项目
*/
@Override
public String deleteQcItem(QcItemQoDelete deleteQo) {
Integer id = deleteQo.getId();
Optional<QcItemEntity> entityById = qcItemDao.findById(id);
if (entityById.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
}
qcItemDao.deleteById(id);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale);
}
2022-03-11 08:58:20 +08:00
/**
2022-03-11 11:55:54 +08:00
* 更新检验项目名称
2022-03-11 08:58:20 +08:00
*/
2022-03-11 10:28:36 +08:00
@Transactional(rollbackOn = Exception.class)
2022-03-10 19:33:25 +08:00
@Override
public String updateQcItem(QcItemQoUpdate updateQo) {
2022-03-11 08:58:20 +08:00
Integer id = updateQo.getId();
String name = updateQo.getName();
Optional<QcItemEntity> entityById = qcItemDao.findById(id);
if (entityById.isEmpty()) {
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale);
}
2022-03-11 14:58:46 +08:00
qcItemDao.updateNameById(id, LocalDateUtils.getCurrentSecond(), LocalStringUtils.formatEmptyValue(name));
2022-03-11 15:37: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 11:55:54 +08:00
* 查询检验项目
2022-03-11 10:28:36 +08:00
*/
@Override
2022-03-11 16:07:31 +08:00
public String queryQcItem(String no, String name) {
2022-03-11 11:55:54 +08:00
List<Map<String, Object>> resultList = qcItemDao.queryQcItem(LocalStringUtils.formatEmptyValue(no), LocalStringUtils.formatEmptyValue(name));
2022-03-11 10:28:36 +08:00
if (resultList == null || resultList.isEmpty()) {
2022-03-11 11:55:54 +08:00
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验项目的信息!", locale);
2022-03-11 10:28:36 +08:00
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale);
}
2022-03-10 19:24:42 +08:00
}