TemplateConfigService.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.gitee.gen.service;
  2. import com.gitee.gen.entity.TemplateConfig;
  3. import com.gitee.gen.mapper.TemplateConfigMapper;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Service;
  6. import org.springframework.util.CollectionUtils;
  7. import java.util.Collections;
  8. import java.util.List;
  9. import java.util.Objects;
  10. /**
  11. * @author tanghc
  12. */
  13. @Service
  14. public class TemplateConfigService {
  15. @Autowired
  16. private TemplateConfigMapper templateConfigMapper;
  17. public List<TemplateConfig> listTemplate(List<Integer> idList) {
  18. if (CollectionUtils.isEmpty(idList)) {
  19. return Collections.emptyList();
  20. }
  21. return templateConfigMapper.listTemplate(idList);
  22. }
  23. public TemplateConfig getById(int id) {
  24. return templateConfigMapper.getById(id);
  25. }
  26. public List<TemplateConfig> listAll() {
  27. return templateConfigMapper.listAll();
  28. }
  29. public void insert(TemplateConfig templateConfig) {
  30. // TemplateConfig existObj = templateConfigMapper.getByName(templateConfig.getName());
  31. // if (existObj != null) {
  32. // throw new RuntimeException("模板名称已存在");
  33. // }
  34. templateConfig.setIsDeleted(0);
  35. templateConfigMapper.insert(templateConfig);
  36. }
  37. public void update(TemplateConfig templateConfig) {
  38. TemplateConfig existObj = templateConfigMapper.getByName(templateConfig.getName());
  39. if (existObj != null && !Objects.equals(templateConfig.getId(), existObj.getId())) {
  40. throw new RuntimeException("模板名称已存在");
  41. }
  42. templateConfigMapper.updateIgnoreNull(templateConfig);
  43. }
  44. public void delete(TemplateConfig templateConfig) {
  45. templateConfigMapper.delete(templateConfig);
  46. }
  47. public List<TemplateConfig> listByGroupId(String groupId) {
  48. return templateConfigMapper.listByGroupId(groupId);
  49. }
  50. }