|
|
@@ -0,0 +1,147 @@
|
|
|
+package org.dromara.business.service.impl;
|
|
|
+
|
|
|
+import org.dromara.business.domain.RechargeProducts;
|
|
|
+import org.dromara.business.domain.bo.RechargeProductsBo;
|
|
|
+import org.dromara.business.domain.vo.ItemsVo;
|
|
|
+import org.dromara.business.domain.vo.RechargeProductsVo;
|
|
|
+import org.dromara.business.mapper.ItemsMapper;
|
|
|
+import org.dromara.business.mapper.RechargeProductsMapper;
|
|
|
+import org.dromara.business.service.IRechargeProductsService;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 充值商品Service业务层处理
|
|
|
+ *
|
|
|
+ * @author Lion Li
|
|
|
+ * @date 2025-08-13
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class RechargeProductsServiceImpl implements IRechargeProductsService {
|
|
|
+
|
|
|
+ private final RechargeProductsMapper baseMapper;
|
|
|
+
|
|
|
+ private final ItemsMapper itemsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询充值商品
|
|
|
+ *
|
|
|
+ * @param id 主键
|
|
|
+ * @return 充值商品
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public RechargeProductsVo queryById(Long id){
|
|
|
+ return baseMapper.selectRechargeProductsById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询充值商品列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 充值商品分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<RechargeProductsVo> queryPageList(RechargeProductsBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<RechargeProducts> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<RechargeProductsVo> result = baseMapper.selectRechargeProductsAll(pageQuery.build(), lqw);
|
|
|
+ List<RechargeProductsVo> rechargeProductsVos = result.getRecords();
|
|
|
+ for (RechargeProductsVo record : rechargeProductsVos) {
|
|
|
+ ItemsVo itemsVo = itemsMapper.selectVoByIdInfo(Long.valueOf(record.getRelatedItemId()));
|
|
|
+ record.setItemsName(itemsVo.getName());
|
|
|
+ }
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的充值商品列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 充值商品列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<RechargeProductsVo> queryList(RechargeProductsBo bo) {
|
|
|
+ LambdaQueryWrapper<RechargeProducts> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectExportRechargeProductsAll(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<RechargeProducts> buildQueryWrapper(RechargeProductsBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<RechargeProducts> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(RechargeProducts::getId);
|
|
|
+ lqw.like(StringUtils.isNotBlank(bo.getProductName()), RechargeProducts::getProductName, bo.getProductName());
|
|
|
+ lqw.eq(bo.getProductPrice() != null, RechargeProducts::getProductPrice, bo.getProductPrice());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getDescription()), RechargeProducts::getDescription, bo.getDescription());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getRelatedItemId()), RechargeProducts::getRelatedItemId, bo.getRelatedItemId());
|
|
|
+ lqw.eq(bo.getQuantity() != null, RechargeProducts::getQuantity, bo.getQuantity());
|
|
|
+ lqw.eq(bo.getCreatedAt() != null, RechargeProducts::getCreatedAt, bo.getCreatedAt());
|
|
|
+ lqw.eq(bo.getUpdatedAt() != null, RechargeProducts::getUpdatedAt, bo.getUpdatedAt());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增充值商品
|
|
|
+ *
|
|
|
+ * @param bo 充值商品
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(RechargeProductsBo bo) {
|
|
|
+ RechargeProducts add = MapstructUtils.convert(bo, RechargeProducts.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insertRechargeProducts(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setId(add.getId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改充值商品
|
|
|
+ *
|
|
|
+ * @param bo 充值商品
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(RechargeProductsBo bo) {
|
|
|
+ RechargeProducts update = MapstructUtils.convert(bo, RechargeProducts.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateRechargeProducts(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(RechargeProducts entity){
|
|
|
+ //TODO 做一些数据校验,如唯一约束
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除充值商品信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteRechargeProductsById(ids) > 0;
|
|
|
+ }
|
|
|
+}
|