package com.dev.swms.server.service.fee.pojo;

import java.util.Date;
import java.util.List;
import java.util.Set;
import com.dev.energy.server.service.pojo.DefaultBaseManager;
import com.dev.energy.server.web.security.UserHolder;
import com.dev.swms.server.model.fee.BillFee;
import com.dev.swms.server.model.fee.Fee;
import com.dev.swms.server.service.fee.BillFeeManager;



public class DefaultBillFeeManager extends DefaultBaseManager implements BillFeeManager{

	/**保存对账单信息*/
	@Override
	public void saveBillFee(BillFee billFee) {
		if(billFee.getCode()==null || billFee.getCode().equals("")){
			/*billFee.setCode();*/
			
		}
		if(billFee.isNew()){
			billFee.setCreatPeople(UserHolder.getUser().getName());//创建人
			billFee.setCreatDate(new Date());//创建时间
		}
			
		commonDao.store(billFee);
		
	}
	
	/**删除对账单信息*/
	@Override
	public void deleteBillFee(List<Long> ids) {
		for(Long id : ids) {
			BillFee billFee = this.load(BillFee.class, id);
			Set<Fee> fee=billFee.getFee();
			for(Fee f:fee) {
				 f=commonDao.load(Fee.class, f.getId());
				 this.delete(f);
			}
			this.delete(billFee);
		}
		
	}
	
	/**添加对账单明细(客户费用)*/
	@Override
	public void addbillFeeDetail(Long bid, List<Long> ids) {
		BillFee billFee=commonDao.load(BillFee.class, bid);
		for(Long id : ids) {
			Fee f=commonDao.load(Fee.class,id);
			f.setBillFee(billFee);			
			commonDao.store(f);	
		}
		
	}
	
	/**移除对账单明细(客户费用)*/
	@Override
	public void removebillFeeDetail(Long bid, List<Long> ids) {
		BillFee billFee=commonDao.load(BillFee.class, bid);
		for(Long id:ids){
			Fee f=commonDao.load(Fee.class, id);
			f.setBillFee(null);			
			commonDao.store(f);
			
		}
		
	}

}
