package com.xkrs.service.impl; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.dao.QcItemDao; 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; 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 QcItemServiceImpl implements QcItemService { private Locale locale = LocaleContextHolder.getLocale(); @Resource private QcItemDao qcItemDao; /** * 添加检验项目 */ @Override public String insertQcItem(QcItemQoInsert insertQo) { String no = insertQo.getNo(); String name = insertQo.getName(); String type = insertQo.getType(); Optional entityByNo = qcItemDao.findByNo(no); if (entityByNo.isPresent()) { return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该检验项目已存在,请勿重复添加!", locale); } QcItemEntity entity = new QcItemEntity(); entity.setCreateTime(LocalDateUtils.getCurrentSecond()); entity.setUpdateTime(""); entity.setNo(LocalStringUtils.formatEmptyValue(no)); entity.setName(LocalStringUtils.formatEmptyValue(name)); entity.setType(LocalStringUtils.formatEmptyValue(type)); qcItemDao.save(entity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } /** * 删除检验项目 */ @Override public String deleteQcItem(QcItemQoDelete deleteQo) { Integer id = deleteQo.getId(); Optional entityById = qcItemDao.findById(id); if (entityById.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale); } qcItemDao.deleteById(id); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale); } /** * 更新检验项目名称 */ @Transactional(rollbackOn = Exception.class) @Override public String updateQcItem(QcItemQoUpdate updateQo) { Integer id = updateQo.getId(); String name = updateQo.getName(); Optional entityById = qcItemDao.findById(id); if (entityById.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该检验项目,请先添加检验项目!", locale); } qcItemDao.updateNameById(id, LocalDateUtils.getCurrentSecond(), LocalStringUtils.formatEmptyValue(name)); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "更新成功!", locale); } /** * 查询检验项目 */ @Override public String queryQcItem(String no, String name) { List> resultList = qcItemDao.queryQcItem(LocalStringUtils.formatEmptyValue(no), LocalStringUtils.formatEmptyValue(name)); if (resultList == null || resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该检验项目的信息!", locale); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale); } }