GoldenRewardQuestionServiceImpl.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package com.crm.custom.service.impl;
  2. import com.crm.custom.dao.mapper.GoldenRewardQuestionMapper;
  3. import com.crm.custom.dao.repository.GoldenRewardQuestionRepository;
  4. import com.crm.custom.service.GoldenRewardQuestionService;
  5. import com.crm.rely.backend.core.constant.Constants;
  6. import com.crm.rely.backend.core.dto.base.PageDto;
  7. import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
  8. import com.crm.rely.backend.core.entity.base.SingleLongEntity;
  9. import com.crm.rely.backend.core.exception.ServiceException;
  10. import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionListDto;
  11. import com.crm.rely.backend.model.entity.golden.question.GoldenRewardQuestionAddEntity;
  12. import com.crm.rely.backend.model.entity.golden.question.GoldenRewardQuestionDeleteEntitys;
  13. import com.crm.rely.backend.model.entity.golden.question.GoldenRewardQuestionSearchEntity;
  14. import com.crm.rely.backend.model.entity.golden.question.GoldenRewardQuestionUpdateEntity;
  15. import com.crm.rely.backend.model.pojo.table.GoldenRewardQuestionTable;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. @Service
  23. public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionService {
  24. @Autowired
  25. private GoldenRewardQuestionRepository repository;
  26. @Autowired
  27. private GoldenRewardQuestionMapper mapper;
  28. @Override
  29. @Transactional(rollbackFor = Exception.class)
  30. public void add(GoldenRewardQuestionAddEntity entity) throws ServiceException {
  31. GoldenRewardQuestionTable table = new GoldenRewardQuestionTable();
  32. BeanUtils.copyProperties(entity, table);
  33. repository.save(table);
  34. }
  35. @Override
  36. @Transactional(rollbackFor = Exception.class)
  37. public void delete(GoldenRewardQuestionDeleteEntitys entity) throws ServiceException {
  38. List<GoldenRewardQuestionTable> tables = repository.findAllByIdIn(entity.getIds());
  39. if (tables == null) {
  40. throw ServiceException.exception(Constants.INFO_NOT_FOUND);
  41. }
  42. repository.delete(tables);
  43. }
  44. @Override
  45. @Transactional(rollbackFor = Exception.class)
  46. public void update(GoldenRewardQuestionUpdateEntity entity) throws ServiceException {
  47. GoldenRewardQuestionTable table = repository.findFirstById(entity.getId());
  48. if (table == null) {
  49. throw ServiceException.exception(Constants.INFO_NOT_FOUND);
  50. }
  51. BeanUtils.copyProperties(entity, table);
  52. repository.save(table);
  53. }
  54. @Override
  55. public ResultWithPagerDto<GoldenRewardQuestionListDto> searchPageList(GoldenRewardQuestionSearchEntity entity) throws ServiceException {
  56. Integer count = mapper.countList(entity);
  57. PageDto pageDto = PageDto.format(entity, count);
  58. if (count == null || count <= 0) {
  59. return ResultWithPagerDto.success(pageDto);
  60. }
  61. List<GoldenRewardQuestionTable> tables = mapper.pageList(entity);
  62. if (tables == null || tables.size() <= 0) {
  63. throw new ServiceException(Constants.SYSTEM_ERROR);
  64. }
  65. List<GoldenRewardQuestionListDto> dtos = new ArrayList<>(tables.size());
  66. for (GoldenRewardQuestionTable table : tables) {
  67. GoldenRewardQuestionListDto dto = transformSearchListDto(table);
  68. dtos.add(dto);
  69. }
  70. return ResultWithPagerDto.success(pageDto, dtos);
  71. }
  72. @Override
  73. public GoldenRewardQuestionListDto searchSingle(SingleLongEntity entity) throws ServiceException {
  74. GoldenRewardQuestionTable table = repository.getFirstById(entity.getId());
  75. if (table == null) {
  76. throw ServiceException.exception(Constants.INFO_NOT_FOUND);
  77. }
  78. return transformSearchListDto(table);
  79. }
  80. private GoldenRewardQuestionListDto transformSearchListDto(GoldenRewardQuestionTable table) {
  81. GoldenRewardQuestionListDto dto = new GoldenRewardQuestionListDto();
  82. BeanUtils.copyProperties(table, dto);
  83. return dto;
  84. }
  85. }