ProductGoodsServiceImpl.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package jnpf.service.impl;
  2. import jnpf.base.service.SuperServiceImpl;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.core.metadata.IPage;
  5. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  6. import jnpf.entity.ProductGoodsEntity;
  7. import jnpf.mapper.ProductGoodsMapper;
  8. import jnpf.model.productgoods.ProductGoodsPagination;
  9. import jnpf.service.ProductGoodsService;
  10. import jnpf.util.RandomUtil;
  11. import jnpf.util.StringUtil;
  12. import jnpf.util.UserProvider;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.util.Date;
  16. import java.util.List;
  17. /**
  18. * 产品商品
  19. * 版本: V3.1.0
  20. * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
  21. * 作者: JNPF开发平台组
  22. * 日期: 2021-07-10 15:57:50
  23. */
  24. @Service
  25. public class ProductGoodsServiceImpl extends SuperServiceImpl<ProductGoodsMapper, ProductGoodsEntity> implements ProductGoodsService {
  26. @Override
  27. public List<ProductGoodsEntity> getGoodList(String type) {
  28. QueryWrapper<ProductGoodsEntity> queryWrapper = new QueryWrapper<>();
  29. if (StringUtil.isNotEmpty(type)) {
  30. queryWrapper.lambda().eq(ProductGoodsEntity::getType, type);
  31. }
  32. return this.list(queryWrapper);
  33. }
  34. @Override
  35. public List<ProductGoodsEntity> getList(ProductGoodsPagination goodsPagination) {
  36. QueryWrapper<ProductGoodsEntity> queryWrapper = new QueryWrapper<>();
  37. if (StringUtil.isNotEmpty(goodsPagination.getCode())) {
  38. queryWrapper.lambda().like(ProductGoodsEntity::getEnCode, goodsPagination.getCode());
  39. }
  40. if (StringUtil.isNotEmpty(goodsPagination.getFullName())) {
  41. queryWrapper.lambda().like(ProductGoodsEntity::getFullName, goodsPagination.getFullName());
  42. }
  43. if (StringUtil.isNotEmpty(goodsPagination.getClassifyId())) {
  44. queryWrapper.lambda().like(ProductGoodsEntity::getClassifyId, goodsPagination.getClassifyId());
  45. }
  46. if (StringUtil.isNotEmpty(goodsPagination.getKeyword())) {
  47. queryWrapper.lambda().and(
  48. t -> t.like(ProductGoodsEntity::getFullName, goodsPagination.getKeyword())
  49. .or().like(ProductGoodsEntity::getEnCode, goodsPagination.getKeyword())
  50. .or().like(ProductGoodsEntity::getProductSpecification, goodsPagination.getKeyword())
  51. );
  52. }
  53. //排序
  54. if (StringUtil.isEmpty(goodsPagination.getSidx())) {
  55. queryWrapper.lambda().orderByDesc(ProductGoodsEntity::getId);
  56. } else {
  57. queryWrapper = "asc".equals(goodsPagination.getSort().toLowerCase()) ? queryWrapper.orderByAsc(goodsPagination.getSidx()) : queryWrapper.orderByDesc(goodsPagination.getSidx());
  58. }
  59. Page<ProductGoodsEntity> page = new Page<>(goodsPagination.getCurrentPage(), goodsPagination.getPageSize());
  60. IPage<ProductGoodsEntity> userIPage = this.page(page, queryWrapper);
  61. return goodsPagination.setData(userIPage.getRecords(), userIPage.getTotal());
  62. }
  63. @Override
  64. public ProductGoodsEntity getInfo(String id) {
  65. QueryWrapper<ProductGoodsEntity> queryWrapper = new QueryWrapper<>();
  66. queryWrapper.lambda().eq(ProductGoodsEntity::getId, id);
  67. return this.getOne(queryWrapper);
  68. }
  69. @Override
  70. public void create(ProductGoodsEntity entity) {
  71. entity.setId(RandomUtil.uuId());
  72. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  73. entity.setCreatorTime(new Date());
  74. this.save(entity);
  75. }
  76. @Override
  77. public boolean update(String id, ProductGoodsEntity entity) {
  78. entity.setId(id);
  79. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  80. entity.setLastModifyTime(new Date());
  81. return this.updateById(entity);
  82. }
  83. @Override
  84. public void delete(ProductGoodsEntity entity) {
  85. if (entity != null) {
  86. this.removeById(entity.getId());
  87. }
  88. }
  89. }