package com.sqx.modules.bl.order.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.sqx.common.utils.Result;
import com.sqx.modules.bl.order.dao.UserPackageDao;
import com.sqx.modules.bl.order.entity.UserPackage;
import com.sqx.modules.bl.order.service.UserPackageService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserPackageServiceImpl extends ServiceImpl<UserPackageDao, UserPackage> implements UserPackageService {

    @Override
    public Result findList(UserPackage userPackage){
        List<UserPackage> list = Lists.newArrayList();
        if(userPackage.getStatus() == 0 || userPackage.getStatus() == 3){
            list = baseMapper.findListByMapping(userPackage);
            for(int i=0;i<list.size();i++){
                UserPackage up = list.get(i);
                up.setStatus(userPackage.getStatus());
            }
        }else{
            list = baseMapper.findList(userPackage);
        }
        return Result.success().put("data",list);
    }

    @Override
    public int insert(UserPackage userPackage){
        return baseMapper.insert(userPackage);
    }

    @Override
    public int updateStatusByOrder(UserPackage userPackage){
        return baseMapper.updateStatusByOrder(userPackage);
    }

    @Override
    public Result findMyPackageList(UserPackage userPackage){
        Page<UserPackage> pages=new Page<>(userPackage.getPage(),userPackage.getLimit());
        return Result.success().put("data",baseMapper.findMyPackageList(pages,userPackage));
    }

    @Override
    public UserPackage getMyPackageById(Long id){
        return baseMapper.getMyPackageById(id);
    }

    @Override
    public int deletePackageByOrders(Long ordersId){
        return baseMapper.deletePackageByOrders(ordersId);
    }

    @Override
    public List<UserPackage> findList(Long ordersId){
        UserPackage userPackage = new UserPackage();
        userPackage.setOrdersId(ordersId);
        return baseMapper.findList(userPackage);
    }

}