package com.xxfc.platform.vehicle.biz;

import com.xxfc.platform.vehicle.entity.VehicleCategory;
import org.springframework.stereotype.Service;

import com.xxfc.platform.vehicle.entity.VehicleBrand;
import com.xxfc.platform.vehicle.mapper.VehicleBrandMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * 
 *
 * @author libin
 * @email 18178966185@163.com
 * @date 2020-09-19 17:48:20
 */
@Service
public class VehicleBrandBiz extends BaseBiz<VehicleBrandMapper, VehicleBrand> {


    public  Integer addBrand(VehicleCategory vehicleCategory){
        Example example = new Example(VehicleBrand.class);
        example.createCriteria().andEqualTo("cnName",vehicleCategory.getBrandName()).andEqualTo("isDel",0);

        List<VehicleBrand> list = selectByExample(example);
        Integer id;
        if (list.size() == 0){
            VehicleBrand vehicleBrand = new VehicleBrand();
            vehicleBrand.setCnName(vehicleCategory.getBrandName());
            vehicleBrand.setGoodsType(vehicleCategory.getGoodsType());
            insertSelective(vehicleBrand);
            id = vehicleBrand.getId();
        }else {
            id = list.get(0).getId();
        }
        return  id;
    }
}