SmsFlashPromotionSessionServiceImpl.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.macro.mall.service.impl;
  2. import com.macro.mall.dto.SmsFlashPromotionSessionDetail;
  3. import com.macro.mall.mapper.SmsFlashPromotionSessionMapper;
  4. import com.macro.mall.model.SmsFlashPromotionSession;
  5. import com.macro.mall.model.SmsFlashPromotionSessionExample;
  6. import com.macro.mall.service.SmsFlashPromotionProductRelationService;
  7. import com.macro.mall.service.SmsFlashPromotionSessionService;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.util.ArrayList;
  12. import java.util.Date;
  13. import java.util.List;
  14. /**
  15. * 限时购场次管理Service实现类
  16. * Created by macro on 2018/11/16.
  17. */
  18. @Service
  19. public class SmsFlashPromotionSessionServiceImpl implements SmsFlashPromotionSessionService {
  20. @Autowired
  21. private SmsFlashPromotionSessionMapper promotionSessionMapper;
  22. @Autowired
  23. private SmsFlashPromotionProductRelationService relationService;
  24. @Override
  25. public int create(SmsFlashPromotionSession promotionSession) {
  26. promotionSession.setCreateTime(new Date());
  27. return promotionSessionMapper.insert(promotionSession);
  28. }
  29. @Override
  30. public int update(Long id, SmsFlashPromotionSession promotionSession) {
  31. promotionSession.setId(id);
  32. return promotionSessionMapper.updateByPrimaryKey(promotionSession);
  33. }
  34. @Override
  35. public int updateStatus(Long id, Integer status) {
  36. SmsFlashPromotionSession promotionSession = new SmsFlashPromotionSession();
  37. promotionSession.setId(id);
  38. promotionSession.setStatus(status);
  39. return promotionSessionMapper.updateByPrimaryKeySelective(promotionSession);
  40. }
  41. @Override
  42. public int delete(Long id) {
  43. return promotionSessionMapper.deleteByPrimaryKey(id);
  44. }
  45. @Override
  46. public SmsFlashPromotionSession getItem(Long id) {
  47. return promotionSessionMapper.selectByPrimaryKey(id);
  48. }
  49. @Override
  50. public List<SmsFlashPromotionSession> list() {
  51. SmsFlashPromotionSessionExample example = new SmsFlashPromotionSessionExample();
  52. return promotionSessionMapper.selectByExample(example);
  53. }
  54. @Override
  55. public List<SmsFlashPromotionSessionDetail> selectList(Long flashPromotionId) {
  56. List<SmsFlashPromotionSessionDetail> result = new ArrayList<>();
  57. SmsFlashPromotionSessionExample example = new SmsFlashPromotionSessionExample();
  58. example.createCriteria().andStatusEqualTo(1);
  59. List<SmsFlashPromotionSession> list = promotionSessionMapper.selectByExample(example);
  60. for (SmsFlashPromotionSession promotionSession : list) {
  61. SmsFlashPromotionSessionDetail detail = new SmsFlashPromotionSessionDetail();
  62. BeanUtils.copyProperties(promotionSession, detail);
  63. long count = relationService.getCount(flashPromotionId, promotionSession.getId());
  64. detail.setProductCount(count);
  65. result.add(detail);
  66. }
  67. return result;
  68. }
  69. }