package com.bocloud.ims.repository.resource;

import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.FlavorExtraSpecs;
import com.bocloud.ims.repository.resource.common.EnhancedBaseRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 额外配置DAO接口实现
 *
 * @author tanshaolong
 */
@Repository("flavorExtraSpecsRepository")
public class FlavorExtraSpecsRepository extends EnhancedBaseRepository<FlavorExtraSpecs, Long> {

	public Boolean remove(Long id) {
		String sql = "delete from flavor_extra_specs where id = :id";
		Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
		return this.update(sql, params) > 0;
	}

	public Boolean removeByFlavorId(Long flavorId) {
		String sql = "delete from flavor_extra_specs where id in (select extra_specs_id from flavor where id = :flavorId)";
		Map<String, Object> params = MapTools.simpleMap("flavorId", flavorId);
		return this.update(sql, params) > 0;
	}

	public Boolean removeByVendorId(Long vendorId) {
		String sql = "delete from flavor_extra_specs where id in (select extra_specs_id from flavor where vendor_id = :vendorId)";
		Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
		return this.update(sql, params) > 0;
	}

	public FlavorExtraSpecs query(Long id) {
		String sql = "select a.* from flavor_extra_specs a where a.id = :id";
		Map<String, Object> param = MapTools.simpleMap("id", id);
		List<FlavorExtraSpecs> list = this.list(FlavorExtraSpecs.class, sql, param);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
}
