GoodsServiceImpl.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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.Constants;
  6. import com.fuint.common.dto.GoodsDto;
  7. import com.fuint.common.dto.GoodsSpecValueDto;
  8. import com.fuint.common.dto.GoodsTopDto;
  9. import com.fuint.common.enums.GoodsTypeEnum;
  10. import com.fuint.common.enums.StatusEnum;
  11. import com.fuint.common.enums.YesOrNoEnum;
  12. import com.fuint.common.service.CateService;
  13. import com.fuint.common.service.GoodsService;
  14. import com.fuint.common.service.SettingService;
  15. import com.fuint.common.service.StoreService;
  16. import com.fuint.framework.annoation.OperationServiceLog;
  17. import com.fuint.framework.exception.BusinessCheckException;
  18. import com.fuint.framework.pagination.PaginationRequest;
  19. import com.fuint.framework.pagination.PaginationResponse;
  20. import com.fuint.repository.bean.GoodsBean;
  21. import com.fuint.repository.bean.GoodsTopBean;
  22. import com.fuint.repository.mapper.MtGoodsMapper;
  23. import com.fuint.repository.mapper.MtGoodsSkuMapper;
  24. import com.fuint.repository.mapper.MtGoodsSpecMapper;
  25. import com.fuint.repository.model.*;
  26. import com.fuint.utils.StringUtil;
  27. import com.github.pagehelper.Page;
  28. import com.github.pagehelper.PageHelper;
  29. import lombok.AllArgsConstructor;
  30. import org.apache.commons.lang.StringUtils;
  31. import org.springframework.beans.BeanUtils;
  32. import org.springframework.data.domain.PageImpl;
  33. import org.springframework.data.domain.PageRequest;
  34. import org.springframework.stereotype.Service;
  35. import org.springframework.transaction.annotation.Transactional;
  36. import java.math.BigDecimal;
  37. import java.util.*;
  38. /**
  39. * 商品业务实现类
  40. *
  41. * Created by FSQ
  42. * CopyRight https://www.fuint.cn
  43. */
  44. @Service
  45. @AllArgsConstructor
  46. public class GoodsServiceImpl extends ServiceImpl<MtGoodsMapper, MtGoods> implements GoodsService {
  47. private MtGoodsMapper mtGoodsMapper;
  48. private MtGoodsSpecMapper mtGoodsSpecMapper;
  49. private MtGoodsSkuMapper mtGoodsSkuMapper;
  50. /**
  51. * 系统设置服务接口
  52. * */
  53. private SettingService settingService;
  54. /**
  55. * 商品分类服务接口
  56. * */
  57. private CateService cateService;
  58. /**
  59. * 店铺服务接口
  60. * */
  61. private StoreService storeService;
  62. /**
  63. * 分页查询商品列表
  64. *
  65. * @param paginationRequest
  66. * @return
  67. */
  68. @Override
  69. public PaginationResponse<GoodsDto> queryGoodsListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException {
  70. Page<MtGoods> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  71. LambdaQueryWrapper<MtGoods> lambdaQueryWrapper = Wrappers.lambdaQuery();
  72. lambdaQueryWrapper.ne(MtGoods::getStatus, StatusEnum.DISABLE.getKey());
  73. String name = paginationRequest.getSearchParams().get("name") == null ? "" : paginationRequest.getSearchParams().get("name").toString();
  74. if (StringUtils.isNotBlank(name)) {
  75. lambdaQueryWrapper.like(MtGoods::getName, name);
  76. }
  77. String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
  78. if (StringUtils.isNotBlank(status)) {
  79. lambdaQueryWrapper.eq(MtGoods::getStatus, status);
  80. }
  81. String goodsNo = paginationRequest.getSearchParams().get("goodsNo") == null ? "" : paginationRequest.getSearchParams().get("goodsNo").toString();
  82. if (StringUtils.isNotBlank(goodsNo)) {
  83. lambdaQueryWrapper.eq(MtGoods::getGoodsNo, goodsNo);
  84. }
  85. String isSingleSpec = paginationRequest.getSearchParams().get("isSingleSpec") == null ? "" : paginationRequest.getSearchParams().get("isSingleSpec").toString();
  86. if (StringUtils.isNotBlank(isSingleSpec)) {
  87. lambdaQueryWrapper.eq(MtGoods::getIsSingleSpec, isSingleSpec);
  88. }
  89. String merchantId = paginationRequest.getSearchParams().get("merchantId") == null ? "" : paginationRequest.getSearchParams().get("merchantId").toString();
  90. if (StringUtils.isNotBlank(merchantId)) {
  91. lambdaQueryWrapper.eq(MtGoods::getMerchantId, merchantId);
  92. }
  93. String storeId = paginationRequest.getSearchParams().get("storeId") == null ? "" : paginationRequest.getSearchParams().get("storeId").toString();
  94. if (StringUtils.isNotBlank(storeId)) {
  95. lambdaQueryWrapper.and(wq -> wq
  96. .eq(MtGoods::getStoreId, 0)
  97. .or()
  98. .eq(MtGoods::getStoreId, storeId));
  99. }
  100. String type = paginationRequest.getSearchParams().get("type") == null ? "" : paginationRequest.getSearchParams().get("type").toString();
  101. if (StringUtils.isNotBlank(type)) {
  102. lambdaQueryWrapper.eq(MtGoods::getType, type);
  103. }
  104. String hasStock = paginationRequest.getSearchParams().get("stock") == null ? "" : paginationRequest.getSearchParams().get("stock").toString();
  105. if (StringUtils.isNotBlank(hasStock)) {
  106. if (hasStock.equals(YesOrNoEnum.YES.getKey())) {
  107. lambdaQueryWrapper.gt(MtGoods::getStock, 0);
  108. } else {
  109. lambdaQueryWrapper.lt(MtGoods::getStock, 1);
  110. }
  111. }
  112. lambdaQueryWrapper.orderByAsc(MtGoods::getSort);
  113. List<MtGoods> goodsList = mtGoodsMapper.selectList(lambdaQueryWrapper);
  114. List<GoodsDto> dataList = new ArrayList<>();
  115. String basePath = settingService.getUploadBasePath();
  116. for (MtGoods mtGoods : goodsList) {
  117. MtGoodsCate cateInfo = null;
  118. if (mtGoods.getCateId() != null) {
  119. cateInfo = cateService.queryCateById(mtGoods.getCateId());
  120. }
  121. GoodsDto item = new GoodsDto();
  122. item.setId(mtGoods.getId());
  123. item.setInitSale(mtGoods.getInitSale());
  124. if (StringUtil.isNotEmpty(mtGoods.getLogo())) {
  125. item.setLogo(basePath + mtGoods.getLogo());
  126. }
  127. item.setStoreId(mtGoods.getStoreId());
  128. if (mtGoods.getStoreId() != null) {
  129. MtStore storeInfo = storeService.queryStoreById(mtGoods.getStoreId());
  130. item.setStoreInfo(storeInfo);
  131. }
  132. item.setName(mtGoods.getName());
  133. item.setGoodsNo(mtGoods.getGoodsNo());
  134. item.setCateId(mtGoods.getCateId());
  135. item.setStock(mtGoods.getStock());
  136. item.setCateInfo(cateInfo);
  137. item.setType(mtGoods.getType());
  138. item.setPrice(mtGoods.getPrice());
  139. item.setLinePrice(mtGoods.getLinePrice());
  140. item.setSalePoint(mtGoods.getSalePoint());
  141. item.setDescription(mtGoods.getDescription());
  142. item.setCreateTime(mtGoods.getCreateTime());
  143. item.setUpdateTime(mtGoods.getUpdateTime());
  144. item.setStatus(mtGoods.getStatus());
  145. item.setOperator(mtGoods.getOperator());
  146. dataList.add(item);
  147. }
  148. PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
  149. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  150. PaginationResponse<GoodsDto> paginationResponse = new PaginationResponse(pageImpl, GoodsDto.class);
  151. paginationResponse.setTotalPages(pageHelper.getPages());
  152. paginationResponse.setTotalElements(pageHelper.getTotal());
  153. paginationResponse.setContent(dataList);
  154. return paginationResponse;
  155. }
  156. /**
  157. * 保存商品信息
  158. *
  159. * @param reqDto
  160. * @throws BusinessCheckException
  161. */
  162. @Override
  163. @Transactional(rollbackFor = Exception.class)
  164. @OperationServiceLog(description = "保存商品信息")
  165. public MtGoods saveGoods(MtGoods reqDto) {
  166. MtGoods mtGoods = new MtGoods();
  167. if (reqDto.getId() > 0) {
  168. mtGoods = queryGoodsById(reqDto.getId());
  169. reqDto.setMerchantId(mtGoods.getMerchantId());
  170. }
  171. if (reqDto.getMerchantId() != null) {
  172. mtGoods.setMerchantId(reqDto.getMerchantId() >= 0 ? reqDto.getMerchantId() : 0);
  173. }
  174. if (reqDto.getStoreId() != null) {
  175. mtGoods.setStoreId(reqDto.getStoreId() >= 0 ? reqDto.getStoreId() : 0);
  176. }
  177. if (StringUtil.isNotEmpty(reqDto.getIsSingleSpec())) {
  178. mtGoods.setIsSingleSpec(reqDto.getIsSingleSpec());
  179. }
  180. if (reqDto.getId() <= 0 && StringUtil.isEmpty(reqDto.getIsSingleSpec())) {
  181. mtGoods.setIsSingleSpec(YesOrNoEnum.YES.getKey());
  182. }
  183. if (StringUtil.isNotEmpty(reqDto.getName())) {
  184. mtGoods.setName(reqDto.getName());
  185. }
  186. if (StringUtil.isNotEmpty(reqDto.getStatus())) {
  187. mtGoods.setStatus(reqDto.getStatus());
  188. }
  189. if (StringUtil.isNotEmpty(reqDto.getLogo())) {
  190. mtGoods.setLogo(reqDto.getLogo());
  191. }
  192. if (StringUtil.isNotEmpty(reqDto.getIsSingleSpec())) {
  193. mtGoods.setIsSingleSpec(reqDto.getIsSingleSpec());
  194. }
  195. if (StringUtil.isNotEmpty(reqDto.getDescription())) {
  196. mtGoods.setDescription(reqDto.getDescription());
  197. }
  198. if (StringUtil.isNotEmpty(reqDto.getOperator())) {
  199. mtGoods.setOperator(reqDto.getOperator());
  200. }
  201. if (StringUtil.isNotEmpty(reqDto.getType())) {
  202. mtGoods.setType(reqDto.getType());
  203. }
  204. if (reqDto.getCateId() != null && reqDto.getCateId() > 0) {
  205. mtGoods.setCateId(reqDto.getCateId());
  206. }
  207. if (reqDto.getServiceTime() != null && reqDto.getServiceTime() > 0) {
  208. mtGoods.setServiceTime(reqDto.getServiceTime());
  209. }
  210. if (StringUtil.isNotEmpty(reqDto.getGoodsNo())) {
  211. mtGoods.setGoodsNo(reqDto.getGoodsNo());
  212. }
  213. if (reqDto.getSort() != null) {
  214. mtGoods.setSort(reqDto.getSort());
  215. }
  216. if (reqDto.getId() == null && (mtGoods.getSort().equals("") || mtGoods.getSort() == null )) {
  217. mtGoods.setSort(0);
  218. }
  219. if (reqDto.getPrice() != null) {
  220. mtGoods.setPrice(reqDto.getPrice());
  221. }
  222. if (reqDto.getPrice() == null && reqDto.getId() <= 0) {
  223. mtGoods.setPrice(new BigDecimal("0.00"));
  224. }
  225. if (reqDto.getLinePrice() != null) {
  226. mtGoods.setLinePrice(reqDto.getLinePrice());
  227. }
  228. if (reqDto.getLinePrice() == null && reqDto.getId() <= 0) {
  229. mtGoods.setLinePrice(new BigDecimal("0.00"));
  230. }
  231. if (StringUtil.isNotEmpty(reqDto.getCouponIds())) {
  232. mtGoods.setCouponIds(reqDto.getCouponIds());
  233. }
  234. if (reqDto.getWeight() != null) {
  235. mtGoods.setWeight(reqDto.getWeight());
  236. }
  237. if (reqDto.getInitSale() != null) {
  238. mtGoods.setInitSale(reqDto.getInitSale());
  239. }
  240. if (reqDto.getStock() != null) {
  241. mtGoods.setStock(reqDto.getStock());
  242. }
  243. if (StringUtil.isNotEmpty(reqDto.getSalePoint())) {
  244. mtGoods.setSalePoint(reqDto.getSalePoint());
  245. }
  246. if (StringUtil.isEmpty(reqDto.getSalePoint()) && reqDto.getId() <= 0) {
  247. reqDto.setSalePoint("");
  248. }
  249. if (StringUtil.isNotEmpty(reqDto.getCanUsePoint())) {
  250. mtGoods.setCanUsePoint(reqDto.getCanUsePoint());
  251. }
  252. if (StringUtil.isNotEmpty(reqDto.getIsMemberDiscount())) {
  253. mtGoods.setIsMemberDiscount(reqDto.getIsMemberDiscount());
  254. }
  255. if (StringUtil.isNotEmpty(reqDto.getImages())) {
  256. mtGoods.setImages(reqDto.getImages());
  257. }
  258. if (!mtGoods.getType().equals(GoodsTypeEnum.COUPON.getKey())) {
  259. mtGoods.setCouponIds("");
  260. }
  261. mtGoods.setUpdateTime(new Date());
  262. if (reqDto.getId() == null || reqDto.getId() <= 0) {
  263. mtGoods.setCreateTime(new Date());
  264. this.save(mtGoods);
  265. } else {
  266. this.updateById(mtGoods);
  267. }
  268. return mtGoods;
  269. }
  270. /**
  271. * 根据ID获取商品信息
  272. *
  273. * @param id 商品ID
  274. * @throws BusinessCheckException
  275. */
  276. @Override
  277. public MtGoods queryGoodsById(Integer id) {
  278. MtGoods mtGoods = mtGoodsMapper.selectById(id);
  279. if (mtGoods == null) {
  280. return null;
  281. }
  282. return mtGoods;
  283. }
  284. /**
  285. * 根据编码获取商品信息
  286. *
  287. * @param merchantId
  288. * @param goodsNo
  289. * @throws BusinessCheckException
  290. */
  291. @Override
  292. public MtGoods queryGoodsByGoodsNo(Integer merchantId, String goodsNo) {
  293. return mtGoodsMapper.getByGoodsNo(merchantId, goodsNo);
  294. }
  295. /**
  296. * 根据条码获取sku信息
  297. *
  298. * @param skuNo skuNo
  299. * @throws BusinessCheckException
  300. * */
  301. @Override
  302. public MtGoodsSku getSkuInfoBySkuNo(String skuNo) {
  303. List<MtGoodsSku> mtGoodsSkuList = mtGoodsSkuMapper.getBySkuNo(skuNo);
  304. if (mtGoodsSkuList.size() > 0) {
  305. return mtGoodsSkuList.get(0);
  306. }
  307. return null;
  308. }
  309. /**
  310. * 根据ID获取商品详情
  311. *
  312. * @param id 商品ID
  313. * @throws BusinessCheckException
  314. */
  315. @Override
  316. public GoodsDto getGoodsDetail(Integer id, boolean getDeleteSpec) {
  317. if (id == null || id < 1) {
  318. return null;
  319. }
  320. MtGoods mtGoods = mtGoodsMapper.selectById(id);
  321. GoodsDto goodsInfo = new GoodsDto();
  322. if (mtGoods != null) {
  323. try {
  324. BeanUtils.copyProperties(mtGoods, goodsInfo);
  325. } catch (Exception e) {
  326. goodsInfo.setId(mtGoods.getId());
  327. goodsInfo.setType(mtGoods.getType());
  328. goodsInfo.setStoreId(mtGoods.getStoreId());
  329. goodsInfo.setName(mtGoods.getName());
  330. goodsInfo.setCateId(mtGoods.getCateId());
  331. goodsInfo.setGoodsNo(mtGoods.getGoodsNo());
  332. goodsInfo.setIsSingleSpec(mtGoods.getIsSingleSpec());
  333. goodsInfo.setLogo(mtGoods.getLogo());
  334. goodsInfo.setImages(mtGoods.getImages());
  335. goodsInfo.setStatus(mtGoods.getStatus());
  336. goodsInfo.setSort(mtGoods.getSort());
  337. goodsInfo.setPrice(mtGoods.getPrice());
  338. goodsInfo.setLinePrice(mtGoods.getLinePrice());
  339. goodsInfo.setServiceTime(mtGoods.getServiceTime());
  340. goodsInfo.setCouponIds(mtGoods.getCouponIds());
  341. }
  342. }
  343. String basePath = settingService.getUploadBasePath();
  344. if (StringUtil.isNotEmpty(goodsInfo.getLogo())) {
  345. goodsInfo.setLogo(basePath + goodsInfo.getLogo());
  346. }
  347. // 规格列表
  348. Map<String, Object> param = new HashMap<>();
  349. param.put("goods_id", id.toString());
  350. if (getDeleteSpec == false) {
  351. param.put("status", StatusEnum.ENABLED.getKey());
  352. }
  353. List<MtGoodsSpec> goodsSpecList = mtGoodsSpecMapper.selectByMap(param);
  354. goodsInfo.setSpecList(goodsSpecList);
  355. // sku列表
  356. if (goodsInfo.getIsSingleSpec().equals(YesOrNoEnum.NO.getKey())) {
  357. List<MtGoodsSku> goodsSkuList = mtGoodsSkuMapper.selectByMap(param);
  358. goodsInfo.setSkuList(goodsSkuList);
  359. // 多规格商品的价格、库存数量
  360. if (goodsSkuList.size() > 0) {
  361. goodsInfo.setPrice(goodsSkuList.get(0).getPrice());
  362. goodsInfo.setLinePrice(goodsSkuList.get(0).getLinePrice());
  363. Integer stock = 0;
  364. for (MtGoodsSku mtGoodsSku : goodsSkuList) {
  365. stock = stock + mtGoodsSku.getStock();
  366. }
  367. goodsInfo.setStock(stock);
  368. } else {
  369. goodsInfo.setStock(0);
  370. }
  371. } else {
  372. goodsInfo.setSkuList(new ArrayList<>());
  373. }
  374. return goodsInfo;
  375. }
  376. /**
  377. * 根据ID删除商品信息
  378. *
  379. * @param id ID
  380. * @param operator 操作人
  381. * @throws BusinessCheckException
  382. */
  383. @Override
  384. @OperationServiceLog(description = "删除商品信息")
  385. public void deleteGoods(Integer id, String operator) throws BusinessCheckException {
  386. MtGoods cateInfo = queryGoodsById(id);
  387. if (null == cateInfo) {
  388. throw new BusinessCheckException("该商品不存在");
  389. }
  390. cateInfo.setStatus(StatusEnum.DISABLE.getKey());
  391. cateInfo.setUpdateTime(new Date());
  392. mtGoodsMapper.updateById(cateInfo);
  393. }
  394. /**
  395. * 获取店铺的商品列表
  396. *
  397. * @param storeId
  398. * @param keyword
  399. * @param cateId
  400. * @param page
  401. * @param pageSize
  402. * @return
  403. * */
  404. @Override
  405. public Map<String, Object> getStoreGoodsList(Integer storeId, String keyword, Integer cateId, Integer page, Integer pageSize) throws BusinessCheckException {
  406. MtStore mtStore = storeService.queryStoreById(storeId);
  407. if (mtStore == null) {
  408. Map<String, Object> result = new HashMap<>();
  409. result.put("goodsList", new ArrayList<>());
  410. result.put("total", 0);
  411. return result;
  412. }
  413. Integer merchantId = mtStore.getMerchantId() == null ? 0 : mtStore.getMerchantId();
  414. Page<MtGoods> pageHelper = PageHelper.startPage(page, pageSize);
  415. List<MtGoods> goodsList = new ArrayList<>();
  416. List<MtGoodsSku> skuList = new ArrayList<>();
  417. if (StringUtil.isNotEmpty(keyword)) {
  418. skuList = mtGoodsSkuMapper.getBySkuNo(keyword);
  419. }
  420. if (skuList != null && skuList.size() > 0) {
  421. MtGoods goods = mtGoodsMapper.selectById(skuList.get(0).getGoodsId());
  422. goodsList.add(goods);
  423. } else {
  424. pageHelper = PageHelper.startPage(page, pageSize);
  425. if (keyword != null && StringUtil.isNotEmpty(keyword)) {
  426. goodsList = mtGoodsMapper.searchStoreGoodsList(merchantId, storeId, keyword);
  427. } else {
  428. goodsList = mtGoodsMapper.getStoreGoodsList(merchantId, storeId, cateId);
  429. }
  430. }
  431. List<MtGoods> dataList = new ArrayList<>();
  432. if (goodsList.size() > 0) {
  433. for (MtGoods mtGoods : goodsList) {
  434. // 多规格商品价格、库存数量
  435. if (mtGoods.getIsSingleSpec().equals(YesOrNoEnum.NO.getKey())) {
  436. Map<String, Object> param = new HashMap<>();
  437. param.put("goods_id", mtGoods.getId().toString());
  438. param.put("status", StatusEnum.ENABLED.getKey());
  439. List<MtGoodsSku> goodsSkuList = mtGoodsSkuMapper.selectByMap(param);
  440. if (goodsSkuList.size() > 0) {
  441. mtGoods.setPrice(goodsSkuList.get(0).getPrice());
  442. mtGoods.setLinePrice(goodsSkuList.get(0).getLinePrice());
  443. Integer stock = 0;
  444. for (MtGoodsSku mtGoodsSku : goodsSkuList) {
  445. stock = stock + mtGoodsSku.getStock();
  446. }
  447. mtGoods.setStock(stock);
  448. } else {
  449. mtGoods.setStock(0);
  450. }
  451. }
  452. dataList.add(mtGoods);
  453. }
  454. }
  455. Map<String, Object> data = new HashMap<>();
  456. data.put("goodsList", dataList);
  457. data.put("total", pageHelper.getTotal());
  458. return data;
  459. }
  460. /**
  461. * 通过SKU获取规格列表
  462. *
  463. * @param skuId
  464. * @return
  465. * */
  466. @Override
  467. public List<GoodsSpecValueDto> getSpecListBySkuId(Integer skuId) {
  468. if (skuId < 0 || skuId == null) {
  469. return new ArrayList<>();
  470. }
  471. List<GoodsSpecValueDto> result = new ArrayList<>();
  472. MtGoodsSku goodsSku = mtGoodsSkuMapper.selectById(skuId);
  473. if (goodsSku == null) {
  474. return result;
  475. }
  476. String specIds = goodsSku.getSpecIds();
  477. String specIdArr[] = specIds.split("-");
  478. for (String specId : specIdArr) {
  479. MtGoodsSpec mtGoodsSpec = mtGoodsSpecMapper.selectById(Integer.parseInt(specId));
  480. GoodsSpecValueDto dto = new GoodsSpecValueDto();
  481. dto.setSpecValueId(mtGoodsSpec.getId());
  482. dto.setSpecName(mtGoodsSpec.getName());
  483. dto.setSpecValue(mtGoodsSpec.getValue());
  484. result.add(dto);
  485. }
  486. return result;
  487. }
  488. /**
  489. * 获取商品规格详情
  490. *
  491. * @param specId
  492. * @return
  493. * */
  494. @Override
  495. public MtGoodsSpec getSpecDetail(Integer specId) {
  496. MtGoodsSpec mtGoodsSpec = mtGoodsSpecMapper.selectById(specId);
  497. return mtGoodsSpec;
  498. }
  499. /**
  500. * 更新已售数量
  501. *
  502. * @param goodsId
  503. * @return
  504. * */
  505. @Override
  506. public Boolean updateInitSale(Integer goodsId) {
  507. return mtGoodsMapper.updateInitSale(goodsId);
  508. }
  509. /**
  510. * 获取选择商品列表
  511. *
  512. * @param params
  513. * @return
  514. */
  515. @Override
  516. public PaginationResponse<GoodsDto> selectGoodsList(Map<String, Object> params) throws BusinessCheckException {
  517. Integer page = params.get("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(params.get("page").toString());
  518. Integer pageSize = params.get("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(params.get("pageSize").toString());
  519. Integer storeId = (params.get("storeId") == null || StringUtil.isEmpty(params.get("storeId").toString()))? 0 : Integer.parseInt(params.get("storeId").toString());
  520. Integer cateId = (params.get("cateId") == null || StringUtil.isEmpty(params.get("cateId").toString())) ? 0 : Integer.parseInt(params.get("cateId").toString());
  521. String keyword = params.get("keyword") == null ? "" : params.get("keyword").toString();
  522. Integer merchantId = 0;
  523. MtStore mtStore = storeService.queryStoreById(storeId);
  524. if (mtStore != null) {
  525. merchantId = mtStore.getMerchantId();
  526. }
  527. Page<MtGoods> pageHelper = PageHelper.startPage(page, pageSize);
  528. List<GoodsDto> dataList = new ArrayList<>();
  529. List<GoodsBean> goodsList = mtGoodsMapper.selectGoodsList(merchantId, storeId, cateId, keyword);
  530. for (GoodsBean goodsBean : goodsList) {
  531. GoodsDto goodsDto = new GoodsDto();
  532. goodsDto.setId(goodsBean.getGoodsId());
  533. goodsDto.setLogo(goodsBean.getLogo());
  534. goodsDto.setName(goodsBean.getName());
  535. goodsDto.setGoodsNo(goodsBean.getGoodsNo());
  536. goodsDto.setStoreId(goodsBean.getStoreId());
  537. goodsDto.setPrice(goodsBean.getPrice());
  538. goodsDto.setCateId(goodsBean.getCateId());
  539. goodsDto.setStock(goodsBean.getStock());
  540. if (goodsBean.getSpecIds() != null) {
  541. Map<String, Object> param = new HashMap<>();
  542. param.put("GOODS_ID", goodsBean.getGoodsId());
  543. param.put("SPEC_IDS", goodsBean.getSpecIds());
  544. param.put("STATUS", StatusEnum.ENABLED.getKey());
  545. List<MtGoodsSku> goodsSkuList = mtGoodsSkuMapper.selectByMap(param);
  546. if (goodsSkuList != null && goodsSkuList.size() > 0) {
  547. goodsDto.setSkuId(goodsSkuList.get(0).getId());
  548. goodsDto.setPrice(goodsSkuList.get(0).getPrice());
  549. if (goodsSkuList.get(0).getLogo() != null && StringUtil.isNotEmpty(goodsSkuList.get(0).getLogo())) {
  550. goodsDto.setLogo(goodsSkuList.get(0).getLogo());
  551. }
  552. goodsDto.setStock(goodsSkuList.get(0).getStock());
  553. List<MtGoodsSpec> specList = new ArrayList<>();
  554. String[] specIds = goodsBean.getSpecIds().split("-");
  555. if (specIds.length > 0) {
  556. for (String specId : specIds) {
  557. MtGoodsSpec mtGoodsSpec = mtGoodsSpecMapper.selectById(Integer.parseInt(specId));
  558. if (mtGoodsSpec != null) {
  559. specList.add(mtGoodsSpec);
  560. }
  561. }
  562. }
  563. goodsDto.setSpecList(specList);
  564. }
  565. }
  566. dataList.add(goodsDto);
  567. }
  568. PageRequest pageRequest = PageRequest.of(page, pageSize);
  569. PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
  570. PaginationResponse<GoodsDto> paginationResponse = new PaginationResponse(pageImpl, GoodsDto.class);
  571. paginationResponse.setTotalPages(pageHelper.getPages());
  572. paginationResponse.setTotalElements(pageHelper.getTotal());
  573. paginationResponse.setContent(dataList);
  574. return paginationResponse;
  575. }
  576. /**
  577. * 获取商品销售排行榜
  578. *
  579. * @param merchantId
  580. * @param storeId
  581. * @param startTime
  582. * @param endTime
  583. * @return
  584. * */
  585. @Override
  586. public List<GoodsTopDto> getGoodsSaleTopList(Integer merchantId, Integer storeId, Date startTime, Date endTime) {
  587. List<GoodsTopBean> dataList = mtGoodsMapper.getGoodsSaleTopList(merchantId, storeId, startTime, endTime);
  588. List<GoodsTopDto> goodsList = new ArrayList<>();
  589. if (dataList != null && dataList.size() > 0) {
  590. for (GoodsTopBean bean : dataList) {
  591. GoodsTopDto dto = new GoodsTopDto();
  592. BeanUtils.copyProperties(bean, dto);
  593. goodsList.add(dto);
  594. }
  595. }
  596. return goodsList;
  597. }
  598. }