UserActionServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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.enums.StatusEnum;
  6. import com.fuint.common.service.UserActionService;
  7. import com.fuint.framework.annoation.OperationServiceLog;
  8. import com.fuint.framework.pagination.PaginationRequest;
  9. import com.fuint.framework.pagination.PaginationResponse;
  10. import com.fuint.repository.mapper.MtUserActionMapper;
  11. import com.fuint.repository.model.MtUserAction;
  12. import com.github.pagehelper.Page;
  13. import com.github.pagehelper.PageHelper;
  14. import lombok.AllArgsConstructor;
  15. import org.apache.commons.lang.StringUtils;
  16. import org.springframework.data.domain.PageImpl;
  17. import org.springframework.data.domain.PageRequest;
  18. import org.springframework.stereotype.Service;
  19. import java.util.Date;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * 会员行为业务接口
  25. *
  26. * Created by FSQ
  27. * CopyRight https://www.fuint.cn
  28. */
  29. @Service
  30. @AllArgsConstructor
  31. public class UserActionServiceImpl extends ServiceImpl<MtUserActionMapper, MtUserAction> implements UserActionService {
  32. private MtUserActionMapper mtUserActionMapper;
  33. /**
  34. * 分页查询会员行为记录列表
  35. *
  36. * @param paginationRequest
  37. * @return
  38. */
  39. @Override
  40. public PaginationResponse<MtUserAction> queryUserActionListByPagination(PaginationRequest paginationRequest) {
  41. Page<MtUserAction> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  42. LambdaQueryWrapper<MtUserAction> lambdaQueryWrapper = Wrappers.lambdaQuery();
  43. lambdaQueryWrapper.ne(MtUserAction::getStatus, StatusEnum.DISABLE.getKey());
  44. String description = paginationRequest.getSearchParams().get("description") == null ? "" : paginationRequest.getSearchParams().get("description").toString();
  45. if (StringUtils.isNotBlank(description)) {
  46. lambdaQueryWrapper.like(MtUserAction::getDescription, description);
  47. }
  48. String merchantId = paginationRequest.getSearchParams().get("merchantId") == null ? "" : paginationRequest.getSearchParams().get("merchantId").toString();
  49. if (StringUtils.isNotBlank(merchantId)) {
  50. lambdaQueryWrapper.eq(MtUserAction::getMerchantId, merchantId);
  51. }
  52. String storeId = paginationRequest.getSearchParams().get("storeId") == null ? "" : paginationRequest.getSearchParams().get("storeId").toString();
  53. if (StringUtils.isNotBlank(storeId)) {
  54. lambdaQueryWrapper.eq(MtUserAction::getStoreId, storeId);
  55. }
  56. String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
  57. if (StringUtils.isNotBlank(status)) {
  58. lambdaQueryWrapper.eq(MtUserAction::getStatus, status);
  59. }
  60. lambdaQueryWrapper.orderByDesc(MtUserAction::getId);
  61. List<MtUserAction> dataList = mtUserActionMapper.selectList(lambdaQueryWrapper);
  62. PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  63. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  64. PaginationResponse<MtUserAction> paginationResponse = new PaginationResponse(pageImpl, MtUserAction.class);
  65. paginationResponse.setTotalPages(pageHelper.getPages());
  66. paginationResponse.setTotalElements(pageHelper.getTotal());
  67. paginationResponse.setContent(dataList);
  68. return paginationResponse;
  69. }
  70. /**
  71. * 新增会员行为
  72. *
  73. * @param reqUserAction 会员行为
  74. * @return
  75. */
  76. @Override
  77. public boolean addUserAction(MtUserAction reqUserAction) {
  78. if (reqUserAction.getAction() == null || reqUserAction.getUserId() == null) {
  79. return false;
  80. }
  81. Map<String, Object> params = new HashMap<>();
  82. params.put("USER_ID", reqUserAction.getUserId());
  83. params.put("action", reqUserAction.getAction());
  84. if (reqUserAction.getParam() != null) {
  85. params.put("param", reqUserAction.getParam());
  86. }
  87. List<MtUserAction> dataList = mtUserActionMapper.selectByMap(params);
  88. // 防止重复
  89. if (dataList.size() == 0) {
  90. MtUserAction mtUserAction = new MtUserAction();
  91. mtUserAction.setAction(reqUserAction.getAction());
  92. mtUserAction.setUserId(reqUserAction.getUserId());
  93. mtUserAction.setMerchantId(reqUserAction.getMerchantId());
  94. mtUserAction.setStoreId(reqUserAction.getStoreId());
  95. mtUserAction.setParam(reqUserAction.getParam());
  96. mtUserAction.setOperator(reqUserAction.getOperator());
  97. mtUserAction.setDescription(reqUserAction.getDescription());
  98. mtUserAction.setStatus(StatusEnum.ENABLED.getKey());
  99. mtUserAction.setCreateTime(new Date());
  100. mtUserAction.setUpdateTime(new Date());
  101. mtUserActionMapper.insert(mtUserAction);
  102. }
  103. return true;
  104. }
  105. /**
  106. * 根据ID获取信息
  107. *
  108. * @param id
  109. * @return
  110. */
  111. @Override
  112. public MtUserAction getUserActionDetail(Integer id) {
  113. return mtUserActionMapper.selectById(id);
  114. }
  115. /**
  116. * 根据ID删除
  117. *
  118. * @param id
  119. * @param operator 操作人
  120. * @return
  121. */
  122. @Override
  123. @OperationServiceLog(description = "删除会员行为")
  124. public void deleteUserAction(Integer id, String operator) {
  125. MtUserAction mtUserAction = this.getUserActionDetail(id);
  126. if (mtUserAction == null) {
  127. return;
  128. }
  129. mtUserAction.setStatus(StatusEnum.DISABLE.getKey());
  130. mtUserAction.setUpdateTime(new Date());
  131. mtUserActionMapper.updateById(mtUserAction);
  132. }
  133. }