|
|
@@ -0,0 +1,138 @@
|
|
|
+package org.dromara.backstage.consumption.service.impl;
|
|
|
+
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+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 org.springframework.stereotype.Service;
|
|
|
+import org.dromara.backstage.consumption.domain.bo.XfDiscountBo;
|
|
|
+import org.dromara.backstage.consumption.domain.vo.XfDiscountVo;
|
|
|
+import org.dromara.backstage.consumption.domain.XfDiscount;
|
|
|
+import org.dromara.backstage.consumption.mapper.XfDiscountMapper;
|
|
|
+import org.dromara.backstage.consumption.service.IXfDiscountService;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 折扣管理Service业务层处理
|
|
|
+ *
|
|
|
+ * @author bing
|
|
|
+ * @date 2024-08-13
|
|
|
+ */
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class XfDiscountServiceImpl implements IXfDiscountService {
|
|
|
+
|
|
|
+ private final XfDiscountMapper baseMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询折扣管理
|
|
|
+ *
|
|
|
+ * @param discountId 主键
|
|
|
+ * @return 折扣管理
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public XfDiscountVo queryById(Long discountId){
|
|
|
+ return baseMapper.selectVoById(discountId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询折扣管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 折扣管理分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<XfDiscountVo> queryPageList(XfDiscountBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<XfDiscount> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<XfDiscountVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的折扣管理列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 折扣管理列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<XfDiscountVo> queryList(XfDiscountBo bo) {
|
|
|
+ LambdaQueryWrapper<XfDiscount> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<XfDiscount> buildQueryWrapper(XfDiscountBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<XfDiscount> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.eq(bo.getCardType() != null, XfDiscount::getCardType, bo.getCardType());
|
|
|
+ lqw.eq(bo.getMealType() != null, XfDiscount::getMealType, bo.getMealType());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getStatus()), XfDiscount::getStatus, bo.getStatus());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增折扣管理
|
|
|
+ *
|
|
|
+ * @param bo 折扣管理
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertByBo(XfDiscountBo bo) {
|
|
|
+ XfDiscount add = MapstructUtils.convert(bo, XfDiscount.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+ if (flag) {
|
|
|
+ bo.setDiscountId(add.getDiscountId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改折扣管理
|
|
|
+ *
|
|
|
+ * @param bo 折扣管理
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean updateByBo(XfDiscountBo bo) {
|
|
|
+ XfDiscount update = MapstructUtils.convert(bo, XfDiscount.class);
|
|
|
+ validEntityBeforeSave(update);
|
|
|
+ return baseMapper.updateById(update) > 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(XfDiscount entity){
|
|
|
+ LambdaQueryWrapper<XfDiscount> lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
|
+ lambdaQueryWrapper.eq(XfDiscount::getCardType, entity.getCardType())
|
|
|
+ .eq(XfDiscount::getMealType, entity.getMealType())
|
|
|
+ .ne(entity.getDiscountId() != null,XfDiscount::getDiscountId, entity.getDiscountId());
|
|
|
+ if (baseMapper.selectCount(lambdaQueryWrapper) > 0) {
|
|
|
+ throw new ServiceException("数据已经存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除折扣管理信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //可以删除
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|