MerchantServiceImpl.java 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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.MerchantService;
  7. import com.fuint.common.util.CommonUtil;
  8. import com.fuint.framework.annoation.OperationServiceLog;
  9. import com.fuint.framework.exception.BusinessCheckException;
  10. import com.fuint.framework.pagination.PaginationRequest;
  11. import com.fuint.framework.pagination.PaginationResponse;
  12. import com.fuint.repository.mapper.MtMerchantMapper;
  13. import com.fuint.repository.mapper.MtStoreMapper;
  14. import com.fuint.repository.model.MtMerchant;
  15. import com.fuint.repository.model.MtStore;
  16. import com.fuint.utils.StringUtil;
  17. import com.github.pagehelper.Page;
  18. import com.github.pagehelper.PageHelper;
  19. import org.apache.commons.lang.StringUtils;
  20. import org.springframework.data.domain.PageImpl;
  21. import org.springframework.data.domain.PageRequest;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import javax.annotation.Resource;
  25. import java.util.*;
  26. /**
  27. * 商户业务实现类
  28. *
  29. * Created by FSQ
  30. * CopyRight https://www.fuint.cn
  31. */
  32. @Service
  33. public class MerchantServiceImpl extends ServiceImpl<MtMerchantMapper, MtMerchant> implements MerchantService {
  34. @Resource
  35. private MtMerchantMapper mtMerchantMapper;
  36. @Resource
  37. private MtStoreMapper mtStoreMapper;
  38. /**
  39. * 分页查询商户列表
  40. *
  41. * @param paginationRequest
  42. * @return
  43. */
  44. @Override
  45. public PaginationResponse<MtMerchant> queryMerchantListByPagination(PaginationRequest paginationRequest) {
  46. Page<MtMerchant> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  47. LambdaQueryWrapper<MtMerchant> lambdaQueryWrapper = Wrappers.lambdaQuery();
  48. lambdaQueryWrapper.ne(MtMerchant::getStatus, StatusEnum.DISABLE.getKey());
  49. String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
  50. if (StringUtils.isNotBlank(name)) {
  51. lambdaQueryWrapper.like(MtMerchant::getName, name);
  52. }
  53. String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
  54. if (StringUtils.isNotBlank(status)) {
  55. lambdaQueryWrapper.eq(MtMerchant::getStatus, status);
  56. }
  57. String id = paginationRequest.getSearchParams().get("id") == null ? "" : paginationRequest.getSearchParams().get("id").toString();
  58. if (StringUtils.isNotBlank(id)) {
  59. lambdaQueryWrapper.eq(MtMerchant::getId, id);
  60. }
  61. lambdaQueryWrapper.orderByAsc(MtMerchant::getStatus).orderByDesc(MtMerchant::getId);
  62. List<MtMerchant> dataList = mtMerchantMapper.selectList(lambdaQueryWrapper);
  63. PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  64. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  65. PaginationResponse<MtMerchant> paginationResponse = new PaginationResponse(pageImpl, MtMerchant.class);
  66. paginationResponse.setTotalPages(pageHelper.getPages());
  67. paginationResponse.setTotalElements(pageHelper.getTotal());
  68. paginationResponse.setContent(dataList);
  69. return paginationResponse;
  70. }
  71. /**
  72. * 保存商户信息
  73. *
  74. * @param merchant
  75. * @throws BusinessCheckException
  76. */
  77. @Override
  78. @Transactional
  79. @OperationServiceLog(description = "保存商户信息")
  80. public MtMerchant saveMerchant(MtMerchant merchant) {
  81. MtMerchant mtMerchant = new MtMerchant();
  82. // 编辑商户
  83. if (merchant.getId() != null) {
  84. mtMerchant = queryMerchantById(merchant.getId());
  85. }
  86. if (merchant.getNo() == null || StringUtil.isEmpty(merchant.getNo())) {
  87. mtMerchant.setNo(CommonUtil.createMerchantNo());
  88. } else {
  89. mtMerchant.setNo(merchant.getNo());
  90. }
  91. if (merchant.getType() != null) {
  92. mtMerchant.setType(merchant.getType());
  93. }
  94. mtMerchant.setName(merchant.getName());
  95. mtMerchant.setLogo(merchant.getLogo());
  96. mtMerchant.setContact(merchant.getContact());
  97. mtMerchant.setOperator(merchant.getOperator());
  98. mtMerchant.setUpdateTime(new Date());
  99. if (merchant.getId() == null) {
  100. mtMerchant.setCreateTime(new Date());
  101. }
  102. mtMerchant.setWxAppId(merchant.getWxAppId());
  103. mtMerchant.setWxAppSecret(merchant.getWxAppSecret());
  104. mtMerchant.setWxOfficialAppId(merchant.getWxOfficialAppId());
  105. mtMerchant.setWxOfficialAppSecret(merchant.getWxOfficialAppSecret());
  106. mtMerchant.setDescription(merchant.getDescription());
  107. mtMerchant.setPhone(merchant.getPhone());
  108. mtMerchant.setAddress(merchant.getAddress());
  109. if (mtMerchant.getStatus() == null) {
  110. mtMerchant.setStatus(StatusEnum.ENABLED.getKey());
  111. }
  112. if (mtMerchant.getId() == null || mtMerchant.getId() < 1) {
  113. this.save(mtMerchant);
  114. } else {
  115. mtMerchantMapper.updateById(mtMerchant);
  116. }
  117. return mtMerchant;
  118. }
  119. /**
  120. * 根据ID获取商户信息
  121. *
  122. * @param id 商户ID
  123. * @throws BusinessCheckException
  124. */
  125. @Override
  126. public MtMerchant queryMerchantById(Integer id) {
  127. if (id == null || id < 1) {
  128. return null;
  129. }
  130. return mtMerchantMapper.selectById(id);
  131. }
  132. /**
  133. * 根据名称获取商户信息
  134. *
  135. * @param name 商户名称
  136. * @throws BusinessCheckException
  137. */
  138. @Override
  139. public MtMerchant queryMerchantByName(String name) {
  140. MtMerchant mtMerchant = mtMerchantMapper.queryMerchantByName(name);
  141. return mtMerchant;
  142. }
  143. /**
  144. * 根据商户号获取商户信息
  145. *
  146. * @param merchantNo 商户号
  147. * @return
  148. */
  149. @Override
  150. public MtMerchant queryMerchantByNo(String merchantNo) {
  151. return mtMerchantMapper.queryMerchantByNo(merchantNo);
  152. }
  153. /**
  154. * 根据商户号获取商户ID
  155. *
  156. * @param merchantNo 商户号
  157. * @return
  158. */
  159. @Override
  160. public Integer getMerchantId(String merchantNo) {
  161. if (merchantNo == null || StringUtil.isEmpty(merchantNo)) {
  162. return 0;
  163. }
  164. MtMerchant mtMerchant = queryMerchantByNo(merchantNo);
  165. if (mtMerchant != null) {
  166. return mtMerchant.getId();
  167. } else {
  168. return 0;
  169. }
  170. }
  171. /**
  172. * 更新商户状态
  173. *
  174. * @param id 商户ID
  175. * @param operator 操作人
  176. * @param status 状态
  177. * @throws BusinessCheckException
  178. */
  179. @Override
  180. @Transactional
  181. @OperationServiceLog(description = "修改商户状态")
  182. public void updateStatus(Integer id, String operator, String status) throws BusinessCheckException {
  183. MtMerchant mtMerchant = queryMerchantById(id);
  184. if (null == mtMerchant) {
  185. throw new BusinessCheckException("该商户不存在.");
  186. }
  187. mtMerchant.setStatus(status);
  188. mtMerchant.setUpdateTime(new Date());
  189. mtMerchant.setOperator(operator);
  190. mtMerchantMapper.updateById(mtMerchant);
  191. }
  192. @Override
  193. public List<MtMerchant> queryMerchantByParams(Map<String, Object> params) {
  194. LambdaQueryWrapper<MtMerchant> lambdaQueryWrapper = Wrappers.lambdaQuery();
  195. lambdaQueryWrapper.ne(MtMerchant::getStatus, StatusEnum.DISABLE.getKey());
  196. String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
  197. if (StringUtils.isNotBlank(merchantId)) {
  198. lambdaQueryWrapper.eq(MtMerchant::getId, merchantId);
  199. }
  200. String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
  201. if (StringUtils.isNotBlank(storeId) && StringUtil.isEmpty(merchantId)) {
  202. MtStore mtStore = mtStoreMapper.selectById(storeId);
  203. if (mtStore != null && mtStore.getMerchantId() > 0) {
  204. lambdaQueryWrapper.eq(MtMerchant::getId, mtStore.getMerchantId());
  205. }
  206. }
  207. String name = params.get("name") == null ? "" : params.get("name").toString();
  208. if (StringUtils.isNotBlank(name)) {
  209. lambdaQueryWrapper.like(MtMerchant::getName, name);
  210. }
  211. String status = params.get("status") == null ? "" : params.get("status").toString();
  212. if (StringUtils.isNotBlank(status)) {
  213. lambdaQueryWrapper.eq(MtMerchant::getStatus, status);
  214. }
  215. lambdaQueryWrapper.orderByAsc(MtMerchant::getStatus).orderByDesc(MtMerchant::getId);
  216. List<MtMerchant> dataList = mtMerchantMapper.selectList(lambdaQueryWrapper);
  217. return dataList;
  218. }
  219. }