PlaceService.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.bofeng.service;
  2. import com.baomidou.mybatisplus.toolkit.IdWorker;
  3. import com.bofeng.dao.PlaceMapper;
  4. import com.bofeng.dao.RoomMapper;
  5. import com.bofeng.entity.Place;
  6. import com.google.common.base.Strings;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import java.util.List;
  11. @Service
  12. @Transactional(readOnly = true)
  13. public class PlaceService {
  14. @Autowired
  15. private PlaceMapper placeMapper;
  16. @Autowired
  17. private RoomMapper roomMapper;
  18. public List<Place> selectAll() {
  19. return placeMapper.selectAll();
  20. }
  21. public List<Place> selectAllPlace() {
  22. return placeMapper.selectAllPlace();
  23. }
  24. @Transactional
  25. public String insert(Place place) {
  26. if (Strings.isNullOrEmpty(place.getPlaceName())) {
  27. return "场次名称不能为空";
  28. }
  29. place.setPlaceId(IdWorker.getId());
  30. int count = placeMapper.checkPlaceNameCount(place);
  31. if (count > 0) {
  32. return "场次名称不能重复";
  33. }
  34. placeMapper.insert(place);
  35. return "";
  36. }
  37. @Transactional
  38. public String updateById(Place place) {
  39. if (Strings.isNullOrEmpty(place.getPlaceName())) {
  40. return "场次名称不能为空";
  41. }
  42. int count = placeMapper.checkPlaceNameCount(place);
  43. if (count > 0) {
  44. return "场次名称不能重复";
  45. }
  46. placeMapper.updateById(place);
  47. return "";
  48. }
  49. public Place getById(Long placeId) {
  50. return placeMapper.selectById(placeId);
  51. }
  52. public List<Place> getByUserId(Long userId) {
  53. return placeMapper.selectByUserId(userId);
  54. }
  55. @Transactional
  56. public int deleteById(Long placeId) {
  57. int effect = 0;
  58. effect += roomMapper.deleteByPlaceId(placeId);
  59. effect += placeMapper.deleteById(placeId);
  60. return effect;
  61. }
  62. }