GoodsServiceImpl.java 22 KB

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