/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.ldt.channel.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.common.enums.PointChannelType;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.ldt.channel.entity.PointChannel;
import org.springblade.ldt.channel.mapper.PointChannelMapper;
import org.springblade.ldt.channel.service.IPointChannelService;
import org.springblade.ldt.channel.vo.PointChannelVO;
import org.springblade.ldt.mall.dto.MallDTO;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 服务实现类
 *
 * @author BladeX
 * @since 2021-09-23
 */
@Service
public class PointChannelServiceImpl extends BaseServiceImpl<PointChannelMapper, PointChannel> implements IPointChannelService {

	@Override
	public IPage<PointChannelVO> selectPointChannelPage(IPage<PointChannelVO> page, PointChannelVO pointChannel) {
		return page.setRecords(baseMapper.selectPointChannelPage(page, pointChannel));
	}

	@Override
	public Boolean saveChannel(MallDTO mallDTO) {
		PointChannel pointChannel = new PointChannel();
		pointChannel.setTenantId(mallDTO.getTenantId());
		pointChannel.setName(mallDTO.getMallName());
		pointChannel.setLogo(mallDTO.getLogo());
		pointChannel.setPointRate(mallDTO.getPointRate());
		pointChannel.setType(PointChannelType.MALL);
		pointChannel.setPaymentDays(mallDTO.getBillDelay());
		pointChannel.setSort(1);
		pointChannel.setDiscount(BigDecimal.ONE);
		pointChannel.setRelationId(mallDTO.getId());
		return saveOrUpdate(pointChannel);
	}
}
