package com.hai.service.impl;

import com.hai.dao.HighDiscountPackageDeliverMapper;
import com.hai.dao.HighDiscountPackageDeliverUserMapper;
import com.hai.entity.HighDiscountPackageDeliver;
import com.hai.entity.HighDiscountPackageDeliverExample;
import com.hai.entity.HighDiscountPackageDeliverUser;
import com.hai.service.HighDiscountPackageDeliverService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service("discountPackageDeliverService")
public class HighDiscountPackageDeliverServiceImpl implements HighDiscountPackageDeliverService {

    @Resource
    HighDiscountPackageDeliverMapper discountPackageDeliverMapper;

    @Resource
    HighDiscountPackageDeliverUserMapper discountPackageDeliverUserMapper;

    @Override
    public void insertDeliver(HighDiscountPackageDeliver discountPackageDeliver) {
        discountPackageDeliver.setCreateTime(new Date());
        discountPackageDeliver.setStatus(1);
        discountPackageDeliverMapper.insert(discountPackageDeliver);
    }

    @Override
    public void updateDeliver(HighDiscountPackageDeliver discountPackageDeliver) {
        discountPackageDeliverMapper.updateByPrimaryKey(discountPackageDeliver);
    }

    @Override
    public HighDiscountPackageDeliver getHandleByPackageId(Long packageId) {
        HighDiscountPackageDeliverExample example = new HighDiscountPackageDeliverExample();
        example.createCriteria().andPackageIdEqualTo(packageId).andStatusEqualTo(1);
        List<HighDiscountPackageDeliver> list = discountPackageDeliverMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public void insertDeliverUser(HighDiscountPackageDeliverUser discountPackageDeliverUser) {
        discountPackageDeliverUser.setCreateTime(new Date());
        discountPackageDeliverUserMapper.insert(discountPackageDeliverUser);
    }
}
