package com.bcxin.ins.service.common.impl;

import com.bcxin.ins.dao.common.ComAreaCodeAPIDao;
import com.bcxin.ins.service.common.ComAreaCodeAPIService;
import com.bcxin.ins.entity.common.ComAreaCode;
import com.bcxin.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class ComAreaCodeAPIServiceImpl extends ServiceImpl<ComAreaCodeAPIDao, ComAreaCode> implements ComAreaCodeAPIService {

	@Autowired
	private ComAreaCodeAPIDao dao;

	@Override
	public List<ComAreaCode> findComAreaCodeByCode(String insComCode, String code, String value) {
		List<ComAreaCode> list = null;
		try {
			list = dao.findComAreaCodeByCode(insComCode, code, value);
		}catch (Exception e){
			e.printStackTrace();
		}
		return list;
	}

	public ComAreaCode findComAreaCodeByName(String insComCode, String cityName,String proName) {
		String val_ = cityName.substring(0, cityName.length()-1);
		List<ComAreaCode> list_1 = findComAreaCodeByCode(insComCode,"",val_);
		ComAreaCode tb = null;
		if(list_1.size()>0){
			tb = list_1.get(0);
			if(tb == null){
				String valp_ = proName.substring(0, proName.length()-1);
				List<ComAreaCode> list_2 = findComAreaCodeByCode(insComCode,"",valp_);
				tb = list_2.get(0);
			}
		}
		return tb;
	}
}
