AdTheatreServiceImpl.java 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package com.ylcm.sys.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.ylcm.sys.domain.AdTheatre;
  5. import com.ylcm.sys.domain.AdTheatreTv;
  6. import com.ylcm.sys.form.AdTheatreForm;
  7. import com.ylcm.sys.mapper.AdTheatreMapper;
  8. import com.ylcm.sys.service.AdTheatreService;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.ylcm.sys.service.AdTheatreTvService;
  11. import com.ylcm.sys.service.AdTheatreTvStatService;
  12. import com.ylcm.sys.vo.AdTheatreVO;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.apache.commons.lang.StringUtils;
  15. import org.springframework.cache.annotation.Cacheable;
  16. import org.springframework.stereotype.Service;
  17. import org.springframework.transaction.annotation.Transactional;
  18. import javax.annotation.Resource;
  19. import java.util.List;
  20. /**
  21. * <p>
  22. * 剧场管理表 服务实现类
  23. * </p>
  24. *
  25. * @author admin
  26. * @since 2020-07-01
  27. */
  28. @Slf4j
  29. @Service
  30. public class AdTheatreServiceImpl extends ServiceImpl<AdTheatreMapper, AdTheatre> implements AdTheatreService {
  31. @Resource
  32. private AdTheatreMapper adTheatreMapper;
  33. @Resource
  34. private AdTheatreTvService adTheatreTvService;
  35. @Resource
  36. private AdTheatreTvStatService adTheatreTvStatService;
  37. @Override
  38. public IPage<AdTheatreVO> page(IPage<AdTheatre> page, AdTheatreForm form) {
  39. form.trim();
  40. return adTheatreMapper.getListByCondition(page, form);
  41. }
  42. @Override
  43. public AdTheatre getUniqu(AdTheatre params) {
  44. LambdaQueryWrapper<AdTheatre> queryWrapper = new LambdaQueryWrapper<AdTheatre>();
  45. queryWrapper.eq(AdTheatre::getName, params.getName().trim())
  46. .eq(AdTheatre::getMediaName, params.getMediaName().trim())
  47. .eq(AdTheatre::getStatus, 0)
  48. .eq(AdTheatre::getMediaNum, params.getMediaNum())
  49. .eq(AdTheatre::getShowDate, params.getShowDate())
  50. .eq(AdTheatre::getShowTime, params.getShowTime());
  51. if (params.getType() == null){
  52. queryWrapper.isNull(AdTheatre::getType);
  53. } else {
  54. queryWrapper.eq(AdTheatre::getType, params.getType());
  55. }
  56. if (StringUtils.isBlank(params.getTypeName())){
  57. queryWrapper.and(wrapper -> wrapper.isNull(AdTheatre::getTypeName)
  58. .or().eq(AdTheatre::getTypeName, ""));
  59. } else {
  60. queryWrapper.eq(AdTheatre::getTypeName, params.getTypeName().trim());
  61. }
  62. queryWrapper.last("LIMIT 1");
  63. return baseMapper.selectOne(queryWrapper);
  64. }
  65. @Override
  66. @Transactional(rollbackFor = Exception.class)
  67. public String batchAdd(List<AdTheatre> list, List<AdTheatreTv> tvList) throws Exception {
  68. if (list.size() != tvList.size()){
  69. throw new Exception("批量新增error:剧场ListSize != 收视率ListSize");
  70. }
  71. for (int i = 0; i < list.size(); i++){
  72. /*
  73. * insert 剧场数据
  74. */
  75. AdTheatre record = list.get(i);
  76. AdTheatre old = getUniqu(record);
  77. if (old != null) {
  78. throw new Exception("第"+ (i + 3) + "行数据重复");
  79. }
  80. baseMapper.insert(record);
  81. /*
  82. * insert 电视剧收视率数据
  83. */
  84. AdTheatreTv theatreTv = tvList.get(i);
  85. theatreTv.setAdTheatreId(record.getId());
  86. adTheatreTvService.add(theatreTv);
  87. }
  88. return "ok";
  89. }
  90. @Transactional(rollbackFor = Exception.class)
  91. @Override
  92. public String deleteById(Integer id) {
  93. AdTheatre adTheatre = baseMapper.selectById(id);
  94. baseMapper.deleteById(id);
  95. adTheatreTvService.removeById(id);
  96. adTheatreTvStatService.saveStatByTheatreTv(adTheatre);
  97. return null;
  98. }
  99. @Transactional(rollbackFor = Exception.class)
  100. @Override
  101. public void saveOrUpd(AdTheatre adTheatre) {
  102. if (adTheatre.getId() == null) {
  103. baseMapper.insert(adTheatre);
  104. // 创建“电视剧数据”记录
  105. AdTheatreTv adTheatreTv = new AdTheatreTv();
  106. adTheatreTv.setAdTheatreId(adTheatre.getId());
  107. adTheatreTvService.add(adTheatreTv);
  108. } else {
  109. AdTheatre old = baseMapper.selectById(adTheatre.getId());
  110. baseMapper.updateById(adTheatre);
  111. adTheatreTvStatService.saveStatByTheatreTv(old);
  112. }
  113. adTheatreTvStatService.saveStatByTheatreTv(adTheatre);
  114. }
  115. @Override
  116. public void updateProductName(Integer type, String oldName, String newName) {
  117. AdTheatre adTheatre = new AdTheatre();
  118. adTheatre.setTypeName(newName);
  119. LambdaQueryWrapper<AdTheatre> queryWrapper = new LambdaQueryWrapper<AdTheatre>();
  120. queryWrapper.eq(AdTheatre::getTypeName, oldName);
  121. queryWrapper.eq(AdTheatre::getType, type);
  122. baseMapper.update(adTheatre, queryWrapper);
  123. }
  124. @Transactional(rollbackFor = Exception.class)
  125. @Override
  126. public void updateTvName(String oldName, String newName,
  127. String newFirstTheme, String oldFirstTheme, String newSecondTheme) {
  128. log.info("修改了剧名 或者 题材 {}, {}, {}, {}", oldName, newName, newFirstTheme, newSecondTheme);
  129. AdTheatre adTheatre = new AdTheatre();
  130. adTheatre.setName(newName);
  131. adTheatre.setFirstTheme(newFirstTheme);
  132. adTheatre.setSecondTheme(newSecondTheme);
  133. LambdaQueryWrapper<AdTheatre> queryWrapper = new LambdaQueryWrapper<AdTheatre>();
  134. queryWrapper.eq(AdTheatre::getName, oldName);
  135. // 更新adTheatre
  136. baseMapper.update(adTheatre, queryWrapper);
  137. // 更新adTheatreStat
  138. adTheatreTvStatService.batchUpdateByName(newName, oldName, newFirstTheme, oldFirstTheme, newSecondTheme);
  139. }
  140. @Override
  141. public void updateMediaName(String oldName, String newName) {
  142. AdTheatre adTheatre = new AdTheatre();
  143. adTheatre.setMediaName(newName);
  144. LambdaQueryWrapper<AdTheatre> queryWrapper = new LambdaQueryWrapper<AdTheatre>();
  145. queryWrapper.eq(AdTheatre::getMediaName, oldName);
  146. baseMapper.update(adTheatre, queryWrapper);
  147. }
  148. @Cacheable(value = "TheatreAnalysis",keyGenerator = "cacheKeyGenerator")
  149. @Override
  150. public int countTvNum(String name, String mediaName, String startDate, String endDate) {
  151. return baseMapper.countTvNum(name, mediaName, startDate, endDate);
  152. }
  153. @Cacheable(value = "TheatreAnalysis",keyGenerator = "cacheKeyGenerator")
  154. @Override
  155. public int countThemeNum(String firstTheme, String mediaName, String timeQuery, String startDate, String endDate) {
  156. return baseMapper.countThemeNum(firstTheme, mediaName, timeQuery, startDate, endDate);
  157. }
  158. }