package com.org.hktshop.service.encapsulation.impl;

import com.org.hktshop.base.BaseException;
import com.org.hktshop.base.BaseService;
import com.org.hktshop.entity.Page;
import com.org.hktshop.entity.encapsulation.FcOrderGoods;
import com.org.hktshop.entity.order.HktOrder;
import com.org.hktshop.service.encapsulation.FcOrderGoodsService;
import com.org.hktshop.utils.ExecSqlLib;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class FcOrderGoodsServiceImpl extends BaseService<FcOrderGoods> implements FcOrderGoodsService {
    @Override
    public void saveFcOrderGoods(FcOrderGoods fcOrderGoods) {
        this.updateJdbc(fcOrderGoods);
    }

    @Override
    public void deleteFcOrderGoods(String id) {
        if (StringUtils.isEmpty(id)) {
            throw new BaseException("id 不能为空");
        }
        this.deleteById(id, new FcOrderGoods());
    }

    @Override
    public void updateFcOrderGoods(FcOrderGoods fcOrderGoods) {
        if (StringUtils.isEmpty(fcOrderGoods.getId())) {
            throw new BaseException("id 不能为空");
        }
        this.updateJdbc(fcOrderGoods);
    }

    @Override
    public FcOrderGoods getFcOrderGoods(String id) {
        if (StringUtils.isEmpty(id)) {
            throw new BaseException("id 不能为空");
        }
        return this.queryByIdJbdc(id, new FcOrderGoods());
    }

    @Override
    public Page<FcOrderGoods> getFcOrderGoodsPage(FcOrderGoods fcOrderGoods) {
        return this.queryPages(fcOrderGoods);
    }

    @Override
    public List<FcOrderGoods> getOrderGoodsListByOrderSns(List<String> orderSns) {
        StringBuilder sql = new StringBuilder();
        sql.append(ExecSqlLib.GetQuerySql(new FcOrderGoods()).replace("order by id", ""));
        StringBuilder orderSnStr = new StringBuilder();
        for (String orderSn : orderSns) {
            orderSnStr.append("'").append(orderSn).append("',");
        }
        orderSnStr.deleteCharAt(orderSnStr.length() - 1);
        sql.append(String.format(" WHERE order_sn in (%s)", orderSnStr));
        return this.baseJdbcDao.queryList(sql.toString(), new FcOrderGoods());
    }
}
