BookServiceImpl.java 9.8 KB

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