package com.ecep.contract.converter;

import com.ecep.contract.service.ContractTypeService;
import com.ecep.contract.vo.ContractTypeVo;
import javafx.util.StringConverter;

/**
 * 合同类型字符串转换器
 *
 * @author songqq
 */
public class ContractTypeStringConverter extends StringConverter<ContractTypeVo> {
    ContractTypeService contractTypeService;

    public ContractTypeStringConverter(ContractTypeService contractTypeService) {
        this.contractTypeService = contractTypeService;
    }

    @Override
    public String toString(ContractTypeVo object) {
        return object.getCode() + " " + object.getCatalog() + " " + object.getName() + " " + object.getTitle()
                + "("
                + object.getDirection() + ")";
    }

    @Override
    public ContractTypeVo fromString(String string) {
        return contractTypeService.findByCode(string);
    }

}
