package com.hfkj.service.meal.impl;

import com.hfkj.dao.BsMealTableOrderChildMapper;
import com.hfkj.dao.BsMealTableOrderChildProductMapper;
import com.hfkj.entity.BsMealTableOrderChild;
import com.hfkj.entity.BsMealTableOrderChildProduct;
import com.hfkj.entity.BsMealTableOrderChildProductExample;
import com.hfkj.service.meal.BsMealTableOrderChildProductService;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsMealTableOrderChildProductServiceImpl
 * @author: HuRui
 * @date: 2023/12/11
 **/
@Service("mealTableOrderChildProductService")
public class BsMealTableOrderChildProductServiceImpl implements BsMealTableOrderChildProductService {

    @Resource
    private BsMealTableOrderChildProductMapper mealTableOrderChildProductMapper;

    @Override
    public void editData(BsMealTableOrderChildProduct data) {
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            data.setUpdateTime(new Date());
            mealTableOrderChildProductMapper.insert(data);
        } else {
            data.setUpdateTime(new Date());
            mealTableOrderChildProductMapper.updateByPrimaryKeySelective(data);
        }
    }

    @Override
    public List<BsMealTableOrderChildProduct> getProductList(Map<String, Object> param) {
        BsMealTableOrderChildProductExample example = new BsMealTableOrderChildProductExample();
        BsMealTableOrderChildProductExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotBlank(MapUtils.getString(param, "childOrderNo"))) {
            criteria.andChildOrderNoEqualTo(MapUtils.getString(param, "childOrderNo"));
        }

        example.setOrderByClause("create_time desc");
        return mealTableOrderChildProductMapper.selectByExample(example);
    }
}
