package com.ag.account.dao;

import com.ag.base.IBaseRepository;
import com.ag.entity.fee.AccountPoints;
import com.ag.entity.fee.BaseChargingItem;
import com.ag.util.StrUtil;
import org.springframework.stereotype.Repository;

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

/**
 * Created by Administrator on 2017/5/15 0015.
 */
@Repository
public class AccountPointsCalcDao {
    @Resource(name="baseRepositoryImpl")
    private IBaseRepository<AccountPoints> pointRepo;
    @Resource(name="baseRepositoryImpl")
    private IBaseRepository<BaseChargingItem> itemRepo;

    public int delete(AccountPoints delAP) {
        return pointRepo.delete(delAP, "POINT_CODE");
    }

    public int[] save(List<AccountPoints> accountPoints) {
        return pointRepo.saveAll(accountPoints);
    }

    public List<AccountPoints> findByPointId(AccountPoints point) {
        return pointRepo.findByEntity(point, AccountPoints.class);
    }

    public int save(AccountPoints point){
        return pointRepo.save(point);
    }


    public List<BaseChargingItem> findInItemId(String items, String tenancyId) {
        BaseChargingItem entity = new BaseChargingItem();
        entity.setTenancyId(tenancyId);
        String sql = itemRepo.getSelectByEntity(entity, false);
        sql = StrUtil.join(sql, " and ID in(", items, ")");
        return itemRepo.list(sql, BaseChargingItem.class);
    }

    public List<BaseChargingItem> findAll(String tenancyId){
        BaseChargingItem entity = new BaseChargingItem();
        entity.setTenancyId(tenancyId);
        return itemRepo.findByEntity(entity, BaseChargingItem.class);
    }

    public List<AccountPoints> findAll(AccountPoints point) {
        return pointRepo.findByEntity(point, AccountPoints.class, true);
    }
}
