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

import java.util.List;

import com.dev.swms.server.model.rules.WaveRule;
import com.dev.swms.server.service.rule.WaveRuleManager;
import com.dev.swms.server.web.filter.WarehouseHolder;
import com.dev.energy.client.utils.StringUtils;
import com.dev.energy.server.exception.BusinessException;
import com.dev.energy.server.service.pojo.DefaultBaseManager;

public class DefaultWaveRuleManager extends DefaultBaseManager implements
		WaveRuleManager {

	public void storeWaveRule(WaveRule waveRule) {
		waveRule.setWarehouse(WarehouseHolder.getWarehouse());
		
//		如果填写了高级规则，则订单开始时间、结束时间、优先级、运输方式、货主分组、收货人分组全部忽略
		if(!StringUtils.isEmpty(waveRule.getWaveRules())){
			waveRule.setOrderEndTime("");
			waveRule.setOrderStartTime("");
			waveRule.setSortIndex(null);
			waveRule.setShipmentMethod("");
			waveRule.setCompanyGroupStr("");
			waveRule.setCustomerGroupStr("");
		}
		this.commonDao.store(waveRule);
	}

	public void deleteWaveRule(List<Long> ids) {
		for(Long id:ids){
			WaveRule wr = this.commonDao.load(WaveRule.class,id);
			this.commonDao.delete(wr);
		}
	}
}
