UserActionServiceImpl.java 5.7 KB

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