package com.yc.ship.module.trade.service.orderpolicy;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.yc.ship.module.trade.controller.admin.orderpolicy.vo.*;
import com.yc.ship.module.trade.dal.dataobject.orderpolicy.OrderPolicyDO;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.pojo.PageParam;
import com.yc.ship.framework.common.util.object.BeanUtils;

import com.yc.ship.module.trade.dal.mysql.orderpolicy.OrderPolicyMapper;

import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yc.ship.module.trade.enums.ErrorCodeConstants.*;

/**
 * 订单使用的优惠政策 Service 实现类
 *
 * @author 管理员
 */
@Service
@Validated
public class OrderPolicyServiceImpl implements OrderPolicyService {

    @Resource
    private OrderPolicyMapper orderPolicyMapper;

    @Override
    public Long createOrderPolicy(OrderPolicySaveReqVO createReqVO) {
        // 插入
        OrderPolicyDO orderPolicy = BeanUtils.toBean(createReqVO, OrderPolicyDO.class);
        orderPolicyMapper.insert(orderPolicy);
        // 返回
        return orderPolicy.getId();
    }

    @Override
    public void updateOrderPolicy(OrderPolicySaveReqVO updateReqVO) {
        // 更新
        OrderPolicyDO updateObj = BeanUtils.toBean(updateReqVO, OrderPolicyDO.class);
        orderPolicyMapper.updateById(updateObj);
    }

    @Override
    public void deleteOrderPolicy(Long id) {
        // 删除
        orderPolicyMapper.deleteById(id);
    }

    @Override
    public OrderPolicyDO getOrderPolicy(Long id) {
        return orderPolicyMapper.selectById(id);
    }

    @Override
    public PageResult<OrderPolicyDO> getOrderPolicyPage(OrderPolicyPageReqVO pageReqVO) {
        return orderPolicyMapper.selectPage(pageReqVO);
    }

}