package com.hfkj.service.goods.impl;

import com.hfkj.dao.BsOrderCinemaMapper;
import com.hfkj.entity.BsOrderCinema;
import com.hfkj.entity.BsOrderCinemaExample;
import com.hfkj.entity.BsOrderGoods;
import com.hfkj.entity.BsOrderGoodsExample;
import com.hfkj.service.goods.BsOrderCinemaService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

@Service("bsOrderCinemaService")
public class BsOrderCinemaServiceImpl implements BsOrderCinemaService {

    @Resource
    private BsOrderCinemaMapper bsOrderCinemaMapper;

    @Override
    public void create(BsOrderCinema orderCinema) {
        bsOrderCinemaMapper.insert(orderCinema);
    }

    @Override
    public void update(BsOrderCinema orderCinema) {
        bsOrderCinemaMapper.updateByPrimaryKeySelective(orderCinema);
    }

    @Override
    public void delete(Long id, Boolean fullDelete) {
        bsOrderCinemaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public BsOrderCinema queryDetail(Long id) {
        return bsOrderCinemaMapper.selectByPrimaryKey(id);
    }

    @Override
    public BsOrderCinema findGoodsOrder(String orderNo) {
        BsOrderCinemaExample example = new BsOrderCinemaExample();
        example.createCriteria().andOrderNoEqualTo(orderNo);

        List<BsOrderCinema> list = bsOrderCinemaMapper.selectByExample(example);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    @Override
    public BsOrderCinema queryDetailByMap(Map<String, Object> map) {
        return null;
    }

    @Override
    public List<BsOrderCinema> getList(Map<String, Object> map) {
        BsOrderCinemaExample example = new BsOrderCinemaExample();
        BsOrderCinemaExample.Criteria criteria = example.createCriteria();


        if (MapUtils.getLong(map, "merId") != null) {
            criteria.andMerIdEqualTo(MapUtils.getLong(map, "merId"));
        }

        if (StringUtils.isNotBlank(MapUtils.getString(map, "orderNo"))) {
            criteria.andOrderNoEqualTo(MapUtils.getString(map, "orderNo"));
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map, "childOrderNo"))) {
            criteria.andChildOrderNoEqualTo(MapUtils.getString(map, "childOrderNo"));
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map, "userPhone"))) {
            criteria.andUserPhoneEqualTo(MapUtils.getString(map, "userPhone"));
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map, "platformCode"))) {
            criteria.andPlatformCodeEqualTo(MapUtils.getString(map, "platformCode"));
        }
        if (StringUtils.isNotBlank(MapUtils.getString(map, "goodsSpecsName"))) {
            criteria.andGoodsSpecsNameEqualTo(MapUtils.getString(map, "goodsSpecsName"));
        }

        if (StringUtils.isNotBlank(MapUtils.getString(map, "goodsName"))) {
            criteria.andGoodsNameLike("%"+MapUtils.getString(map, "goodsName")+"%");
        }

        if (MapUtils.getInteger(map, "payType") != null) {
            criteria.andPayTypeEqualTo(MapUtils.getInteger(map, "payType"));
        }
        if (MapUtils.getLong(map, "createTimeS") != null) {
            criteria.andCreateTimeGreaterThanOrEqualTo(new Date(MapUtils.getLong(map, "createTimeS")));
        }
        if (MapUtils.getLong(map, "createTimeE") != null) {
            criteria.andCreateTimeLessThan(new Date(MapUtils.getLong(map, "createTimeE")));
        }
        if (MapUtils.getInteger(map, "status") != null) {
            criteria.andStatusEqualTo(MapUtils.getInteger(map, "status"));
        }
        example.setOrderByClause("exception_status desc");
        return bsOrderCinemaMapper.selectByExample(example);
    }
}
