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

import com.org.hktshop.base.BaseService;
import com.org.hktshop.base.UserContext;
import com.org.hktshop.entity.user.HktUsersInvoice;
import com.org.hktshop.service.user.HktUsersInvoiceService;
import com.org.hktshop.utils.ExecSqlLib;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HktUsersInvoiceServiceImpl extends BaseService<HktUsersInvoice> implements HktUsersInvoiceService {
    @Autowired
    private UserContext userContext;

    @Override
    public void saveHktUsersInvoice(HktUsersInvoice hktUsersInvoice) {
        hktUsersInvoice.setUserId(userContext.getUserInfo().getId());
        this.updateJdbc(hktUsersInvoice);
    }

    @Override
    public void updateHktUsersInvoice(HktUsersInvoice hktUsersInvoice) {
        this.updateJdbc(hktUsersInvoice);
    }

    @Override
    public HktUsersInvoice getHktUsersInvoice() {
        HktUsersInvoice usersInvoice = new HktUsersInvoice();
        usersInvoice.setUserId(userContext.getUserInfo().getId());
        String sql = ExecSqlLib.GetQuerySql(usersInvoice);
        HktUsersInvoice hktUsersInvoice = this.baseJdbcDao.query(sql, usersInvoice);
        return hktUsersInvoice;
    }

    @Override
    public void deleteHktUsersInvoice(HktUsersInvoice hktUsersInvoice) {
        this.delete(hktUsersInvoice);
    }

    @Override
    public List<HktUsersInvoice> getHktUsersInvoicesByUserIds(String userIds) {
        String sql = ExecSqlLib.GetQuerySql(new HktUsersInvoice()).replace("order by id", "") +
                String.format(" WHERE user_id in (%s)", userIds);
        return this.baseJdbcDao.queryList(sql, new HktUsersInvoice());
    }

    @Override
    public HktUsersInvoice getHktUsersInvoiceByUserId(String userId) {
        HktUsersInvoice usersInvoice = new HktUsersInvoice();
        usersInvoice.setUserId(userId);
        String sql = ExecSqlLib.GetQuerySql(usersInvoice);
        HktUsersInvoice hktUsersInvoice = this.baseJdbcDao.query(sql, usersInvoice);
        return hktUsersInvoice;
    }
}
