package com.xkrs.service.impl; import com.xkrs.dao.CraftItemDao; import com.xkrs.encapsulation.PromptMessageEnum; import com.xkrs.model.entity.CraftItemEntity; import com.xkrs.model.qo.CraftItemQoDelete; import com.xkrs.model.qo.CraftItemQoInsert; import com.xkrs.model.qo.CraftItemQoUpdate; import com.xkrs.service.CraftItemService; 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 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 CraftItemServiceImpl implements CraftItemService { private Locale locale = LocaleContextHolder.getLocale(); @Resource private CraftItemDao craftItemDao; /** * 添加工艺项目 */ @Override public String insertCraftItem(CraftItemQoInsert insertQo) { String no = insertQo.getNo(); String name = insertQo.getName(); Optional entityByNo = craftItemDao.findByNo(no); if (entityByNo.isPresent()) { return outputEncapsulationObject(PromptMessageEnum.DATA_EXIT, "该工艺项目已存在,请勿重复添加!", locale); } CraftItemEntity entity = new CraftItemEntity(); entity.setCreateTime(LocalDateUtils.getCurrentSecond()); entity.setUpdateTime(""); entity.setNo(LocalStringUtils.formatEmptyValue(no)); entity.setName(LocalStringUtils.formatEmptyValue(name)); craftItemDao.save(entity); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "添加成功!", locale); } /** * 删除工艺项目 */ @Override public String deleteCraftItem(CraftItemQoDelete deleteQo) { Integer id = deleteQo.getId(); Optional entityById = craftItemDao.findById(id); if (entityById.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该工艺项目,请先添加工艺项目!", locale); } craftItemDao.deleteById(id); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "删除成功!", locale); } /** * 更新工艺项目名称 */ @Override public String updateCraftItem(CraftItemQoUpdate updateQo) { Integer id = updateQo.getId(); String name = updateQo.getName(); Optional entityById = craftItemDao.findById(id); if (entityById.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "不存在该工艺项目,请先添加工艺项目!", locale); } craftItemDao.updateNameById(id, LocalDateUtils.getCurrentSecond(), LocalStringUtils.formatEmptyValue(name)); return outputEncapsulationObject(PromptMessageEnum.SUCCESS, "更新成功!", locale); } /** * 查询工艺项目 */ @Override public String queryCraftItem(String no, String name) { List> resultList = craftItemDao.queryCraftItem(LocalStringUtils.formatEmptyValue(no), LocalStringUtils.formatEmptyValue(name)); if (resultList == null || resultList.isEmpty()) { return outputEncapsulationObject(PromptMessageEnum.DATA_NONE, "暂时没有该工艺项目的信息!", locale); } return outputEncapsulationObject(PromptMessageEnum.SUCCESS, resultList, locale); } }