SendLogServiceImpl.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package com.fuint.common.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  5. import com.fuint.common.dto.ReqSendLogDto;
  6. import com.fuint.common.enums.StatusEnum;
  7. import com.fuint.common.service.SendLogService;
  8. import com.fuint.framework.exception.BusinessCheckException;
  9. import com.fuint.framework.pagination.PaginationRequest;
  10. import com.fuint.framework.pagination.PaginationResponse;
  11. import com.fuint.repository.mapper.MtSendLogMapper;
  12. import com.fuint.repository.model.MtSendLog;
  13. import com.github.pagehelper.Page;
  14. import com.github.pagehelper.PageHelper;
  15. import lombok.AllArgsConstructor;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.data.domain.PageImpl;
  18. import org.springframework.data.domain.PageRequest;
  19. import org.springframework.stereotype.Service;
  20. import java.util.Date;
  21. import java.util.List;
  22. /**
  23. * 发送卡券记录业务实现类
  24. *
  25. * Created by FSQ
  26. * CopyRight https://www.fuint.cn
  27. */
  28. @Service
  29. @AllArgsConstructor
  30. public class SendLogServiceImpl extends ServiceImpl<MtSendLogMapper, MtSendLog> implements SendLogService {
  31. private MtSendLogMapper mtSendLogMapper;
  32. /**
  33. * 分页查询列表
  34. *
  35. * @param paginationRequest
  36. * @return
  37. */
  38. @Override
  39. public PaginationResponse<MtSendLog> querySendLogListByPagination(PaginationRequest paginationRequest) {
  40. Page<MtSendLog> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  41. LambdaQueryWrapper<MtSendLog> lambdaQueryWrapper = Wrappers.lambdaQuery();
  42. lambdaQueryWrapper.ne(MtSendLog::getStatus, StatusEnum.DISABLE.getKey());
  43. String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
  44. if (StringUtils.isNotBlank(status)) {
  45. lambdaQueryWrapper.eq(MtSendLog::getStatus, status);
  46. }
  47. String userId = paginationRequest.getSearchParams().get("userId") == null ? "" : paginationRequest.getSearchParams().get("userId").toString();
  48. if (StringUtils.isNotBlank(userId)) {
  49. lambdaQueryWrapper.eq(MtSendLog::getUserId, userId);
  50. }
  51. String merchantId = paginationRequest.getSearchParams().get("merchantId") == null ? "" : paginationRequest.getSearchParams().get("merchantId").toString();
  52. if (StringUtils.isNotBlank(merchantId)) {
  53. lambdaQueryWrapper.eq(MtSendLog::getMerchantId, merchantId);
  54. }
  55. String storeId = paginationRequest.getSearchParams().get("storeId") == null ? "" : paginationRequest.getSearchParams().get("storeId").toString();
  56. if (StringUtils.isNotBlank(storeId)) {
  57. lambdaQueryWrapper.eq(MtSendLog::getStoreId, storeId);
  58. }
  59. String couponId = paginationRequest.getSearchParams().get("couponId") == null ? "" : paginationRequest.getSearchParams().get("couponId").toString();
  60. if (StringUtils.isNotBlank(couponId)) {
  61. lambdaQueryWrapper.eq(MtSendLog::getCouponId, couponId);
  62. }
  63. String mobile = paginationRequest.getSearchParams().get("mobile") == null ? "" : paginationRequest.getSearchParams().get("mobile").toString();
  64. if (StringUtils.isNotBlank(mobile)) {
  65. lambdaQueryWrapper.eq(MtSendLog::getMobile, mobile);
  66. }
  67. lambdaQueryWrapper.orderByDesc(MtSendLog::getId);
  68. List<MtSendLog> dataList = mtSendLogMapper.selectList(lambdaQueryWrapper);
  69. PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  70. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  71. PaginationResponse<MtSendLog> paginationResponse = new PaginationResponse(pageImpl, MtSendLog.class);
  72. paginationResponse.setTotalPages(pageHelper.getPages());
  73. paginationResponse.setTotalElements(pageHelper.getTotal());
  74. paginationResponse.setContent(dataList);
  75. return paginationResponse;
  76. }
  77. /**
  78. * 添加发放记录
  79. *
  80. * @param reqSendLogDto
  81. * @throws BusinessCheckException
  82. * @return
  83. */
  84. @Override
  85. public MtSendLog addSendLog(ReqSendLogDto reqSendLogDto) {
  86. MtSendLog mtLog = new MtSendLog();
  87. mtLog.setMerchantId(reqSendLogDto.getMerchantId());
  88. mtLog.setStoreId(reqSendLogDto.getStoreId());
  89. mtLog.setType(reqSendLogDto.getType());
  90. mtLog.setUserId(reqSendLogDto.getUserId());
  91. mtLog.setFileName(reqSendLogDto.getFileName());
  92. mtLog.setFilePath(reqSendLogDto.getFilePath());
  93. mtLog.setMobile(reqSendLogDto.getMobile());
  94. mtLog.setCouponId(reqSendLogDto.getCouponId());
  95. mtLog.setGroupId(reqSendLogDto.getGroupId());
  96. mtLog.setGroupName(reqSendLogDto.getGroupName());
  97. mtLog.setSendNum(reqSendLogDto.getSendNum());
  98. mtLog.setRemoveSuccessNum(0);
  99. mtLog.setRemoveFailNum(0);
  100. mtLog.setStatus(StatusEnum.ENABLED.getKey());
  101. mtLog.setCreateTime(new Date());
  102. mtLog.setOperator(reqSendLogDto.getOperator());
  103. mtLog.setUuid(reqSendLogDto.getUuid());
  104. mtSendLogMapper.insert(mtLog);
  105. return mtLog;
  106. }
  107. /**
  108. * 根据ID查询发券记录
  109. *
  110. * @param id 发券记录ID
  111. * @throws BusinessCheckException
  112. * @return
  113. */
  114. @Override
  115. public MtSendLog querySendLogById(Long id) {
  116. return mtSendLogMapper.selectById(id.intValue());
  117. }
  118. /**
  119. * 根据ID删除发券记录
  120. *
  121. * @param id 发券记录ID
  122. * @param operator 操作人
  123. * @throws BusinessCheckException
  124. * @return
  125. */
  126. @Override
  127. public void deleteSendLog(Long id, String operator) {
  128. MtSendLog couponGroup = querySendLogById(id);
  129. if (null == couponGroup) {
  130. return;
  131. }
  132. couponGroup.setStatus(StatusEnum.DISABLE.getKey());
  133. couponGroup.setOperator(operator);
  134. mtSendLogMapper.updateById(couponGroup);
  135. }
  136. }