BookCateServiceImpl.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.service.BookCateService;
  6. import com.fuint.common.service.StoreService;
  7. import com.fuint.framework.annoation.OperationServiceLog;
  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.MtBookCateMapper;
  12. import com.fuint.common.service.SettingService;
  13. import com.fuint.common.enums.StatusEnum;
  14. import com.fuint.repository.model.MtBookCate;
  15. import com.fuint.repository.model.MtGoodsCate;
  16. import com.fuint.repository.model.MtStore;
  17. import com.fuint.utils.StringUtil;
  18. import com.github.pagehelper.PageHelper;
  19. import lombok.AllArgsConstructor;
  20. import org.apache.commons.lang.StringUtils;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import com.github.pagehelper.Page;
  24. import org.springframework.data.domain.PageImpl;
  25. import org.springframework.data.domain.PageRequest;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.transaction.annotation.Transactional;
  28. import java.util.*;
  29. /**
  30. * 预约分类服务接口
  31. *
  32. * Created by FSQ
  33. * CopyRight https://www.fuint.cn
  34. */
  35. @Service
  36. @AllArgsConstructor
  37. public class BookCateServiceImpl extends ServiceImpl<MtBookCateMapper, MtBookCate> implements BookCateService {
  38. private static final Logger logger = LoggerFactory.getLogger(BookCateServiceImpl.class);
  39. private MtBookCateMapper mtBookCateMapper;
  40. /**
  41. * 系统设置服务接口
  42. * */
  43. private SettingService settingService;
  44. /**
  45. * 店铺接口
  46. */
  47. private StoreService storeService;
  48. /**
  49. * 分页查询预约分类列表
  50. *
  51. * @param paginationRequest
  52. * @return
  53. */
  54. @Override
  55. public PaginationResponse<MtBookCate> queryBookCateListByPagination(PaginationRequest paginationRequest) {
  56. Page<MtBookCate> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  57. LambdaQueryWrapper<MtBookCate> lambdaQueryWrapper = Wrappers.lambdaQuery();
  58. lambdaQueryWrapper.ne(MtBookCate::getStatus, StatusEnum.DISABLE.getKey());
  59. String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
  60. if (StringUtils.isNotBlank(name)) {
  61. lambdaQueryWrapper.like(MtBookCate::getName, name);
  62. }
  63. String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
  64. if (StringUtils.isNotBlank(status)) {
  65. lambdaQueryWrapper.eq(MtBookCate::getStatus, status);
  66. }
  67. String merchantId = paginationRequest.getSearchParams().get("merchantId") == null ? "" : paginationRequest.getSearchParams().get("merchantId").toString();
  68. if (StringUtils.isNotBlank(merchantId)) {
  69. lambdaQueryWrapper.eq(MtBookCate::getMerchantId, merchantId);
  70. }
  71. String storeId = paginationRequest.getSearchParams().get("storeId") == null ? "" : paginationRequest.getSearchParams().get("storeId").toString();
  72. if (StringUtils.isNotBlank(storeId)) {
  73. lambdaQueryWrapper.eq(MtBookCate::getStoreId, storeId);
  74. }
  75. lambdaQueryWrapper.orderByAsc(MtBookCate::getSort);
  76. List<MtBookCate> dataList = mtBookCateMapper.selectList(lambdaQueryWrapper);
  77. PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  78. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  79. PaginationResponse<MtBookCate> paginationResponse = new PaginationResponse(pageImpl, MtBookCate.class);
  80. paginationResponse.setTotalPages(pageHelper.getPages());
  81. paginationResponse.setTotalElements(pageHelper.getTotal());
  82. paginationResponse.setContent(dataList);
  83. return paginationResponse;
  84. }
  85. /**
  86. * 添加预约分类
  87. *
  88. * @param mtBookCate 分类信息
  89. * @return
  90. */
  91. @Override
  92. @OperationServiceLog(description = "添加预约分类")
  93. public MtBookCate addBookCate(MtBookCate mtBookCate) throws BusinessCheckException {
  94. MtBookCate bookCate = new MtBookCate();
  95. Integer storeId = mtBookCate.getStoreId() == null ? 0 : mtBookCate.getStoreId();
  96. if (mtBookCate.getMerchantId() == null || mtBookCate.getMerchantId() <= 0) {
  97. MtStore mtStore = storeService.queryStoreById(storeId);
  98. if (mtStore != null && mtStore.getMerchantId() != null) {
  99. bookCate.setMerchantId(mtStore.getMerchantId());
  100. }
  101. }
  102. if (mtBookCate.getMerchantId() == null || mtBookCate.getMerchantId() <= 0) {
  103. throw new BusinessCheckException("新增预约分类失败:所属商户不能为空!");
  104. }
  105. if (StringUtil.isEmpty(mtBookCate.getName())) {
  106. throw new BusinessCheckException("新增预约分类失败:分类名称不能为空!");
  107. }
  108. bookCate.setStoreId(storeId);
  109. bookCate.setName(mtBookCate.getName());
  110. bookCate.setLogo(mtBookCate.getLogo());
  111. bookCate.setDescription(mtBookCate.getDescription());
  112. bookCate.setStatus(StatusEnum.ENABLED.getKey());
  113. bookCate.setUpdateTime(new Date());
  114. bookCate.setCreateTime(new Date());
  115. bookCate.setSort(mtBookCate.getSort());
  116. bookCate.setOperator(mtBookCate.getOperator());
  117. bookCate.setMerchantId(mtBookCate.getMerchantId());
  118. Integer id = mtBookCateMapper.insert(bookCate);
  119. if (id > 0) {
  120. return bookCate;
  121. } else {
  122. logger.error("新增预约分类失败.");
  123. throw new BusinessCheckException("抱歉,新增预约分类失败!");
  124. }
  125. }
  126. /**
  127. * 根据ID获取预约分类信息
  128. *
  129. * @param id 预约分类ID
  130. * @return
  131. */
  132. @Override
  133. public MtBookCate getBookCateById(Integer id) {
  134. return mtBookCateMapper.selectById(id);
  135. }
  136. /**
  137. * 修改预约分类
  138. *
  139. * @param mtBookCate
  140. * @throws BusinessCheckException
  141. * @return
  142. */
  143. @Override
  144. @Transactional(rollbackFor = Exception.class)
  145. @OperationServiceLog(description = "修改预约分类")
  146. public MtBookCate updateBookCate(MtBookCate mtBookCate) throws BusinessCheckException {
  147. MtBookCate bookCate = getBookCateById(mtBookCate.getId());
  148. if (bookCate == null) {
  149. throw new BusinessCheckException("该预约分类状态异常");
  150. }
  151. bookCate.setId(mtBookCate.getId());
  152. if (mtBookCate.getLogo() != null) {
  153. bookCate.setLogo(mtBookCate.getLogo());
  154. }
  155. if (mtBookCate.getName() != null) {
  156. bookCate.setName(mtBookCate.getName());
  157. }
  158. if (mtBookCate.getStoreId() != null) {
  159. bookCate.setStoreId(mtBookCate.getStoreId());
  160. }
  161. if (mtBookCate.getDescription() != null) {
  162. bookCate.setDescription(mtBookCate.getDescription());
  163. }
  164. if (mtBookCate.getOperator() != null) {
  165. bookCate.setOperator(mtBookCate.getOperator());
  166. }
  167. if (mtBookCate.getStatus() != null) {
  168. bookCate.setStatus(mtBookCate.getStatus());
  169. }
  170. if (mtBookCate.getSort() != null) {
  171. bookCate.setSort(mtBookCate.getSort());
  172. }
  173. bookCate.setUpdateTime(new Date());
  174. mtBookCateMapper.updateById(bookCate);
  175. return bookCate;
  176. }
  177. /**
  178. * 根据条件搜索焦点图
  179. *
  180. * @param params 查询参数
  181. * @throws BusinessCheckException
  182. * @return
  183. * */
  184. @Override
  185. public List<MtBookCate> queryBookCateListByParams(Map<String, Object> params) {
  186. String status = params.get("status") == null ? StatusEnum.ENABLED.getKey(): params.get("status").toString();
  187. String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
  188. String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
  189. String name = params.get("name") == null ? "" : params.get("name").toString();
  190. LambdaQueryWrapper<MtBookCate> lambdaQueryWrapper = Wrappers.lambdaQuery();
  191. if (StringUtils.isNotBlank(name)) {
  192. lambdaQueryWrapper.like(MtBookCate::getName, name);
  193. }
  194. if (StringUtils.isNotBlank(status)) {
  195. lambdaQueryWrapper.eq(MtBookCate::getStatus, status);
  196. }
  197. if (StringUtils.isNotBlank(merchantId)) {
  198. lambdaQueryWrapper.eq(MtBookCate::getMerchantId, merchantId);
  199. }
  200. if (StringUtils.isNotBlank(storeId)) {
  201. lambdaQueryWrapper.and(wq -> wq
  202. .eq(MtBookCate::getStoreId, 0)
  203. .or()
  204. .eq(MtBookCate::getStoreId, storeId));
  205. }
  206. lambdaQueryWrapper.orderByAsc(MtBookCate::getSort);
  207. List<MtBookCate> dataList = mtBookCateMapper.selectList(lambdaQueryWrapper);
  208. String baseImage = settingService.getUploadBasePath();
  209. if (dataList.size() > 0) {
  210. for (MtBookCate mtBookCate : dataList) {
  211. mtBookCate.setLogo(baseImage + mtBookCate.getLogo());
  212. }
  213. }
  214. return dataList;
  215. }
  216. }