package com.xt.hb.data.cbyj.ctl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xt.hb.data.cbyj.mapper.CbyjAreaMapper;
import com.xt.hb.data.cbyj.mapper.CbyjMapper;
import com.xt.hb.data.cbyj.model.Cbyj;
import com.xt.hb.data.cbyj.model.CbyjArea;
import com.yuanxd.tools.utils.string.StringUtils;

@Controller
public class CbyjCtl {
	@Autowired
	private CbyjMapper cbyjMapper;
	@Autowired
	private CbyjAreaMapper cbyjAreaMapper;

	@RequestMapping("cbyj/{id}")
	@ResponseBody
	public Cbyj lscx(@PathVariable String id) {
		Cbyj yj = cbyjMapper.selectByPrimaryKey(id);
		CbyjArea area = cbyjAreaMapper.selectByPrimaryKey(Long.parseLong(yj.getArea()));
		yj.setArea(area.getAreaname());
		return yj;
	}

	@RequestMapping("cbyjArea/{id}")
	@ResponseBody
	public CbyjArea cbyjArea(@PathVariable long id) {
		CbyjArea yj = cbyjAreaMapper.selectByPrimaryKey(id);
		return yj;
	}

	@RequestMapping("shipName/{name}")
	@ResponseBody
	public String shipName(@PathVariable String name) {
		if (StringUtils.isEmpty(name)) {
			return "";
		} else {
			name = name.replace(" ", "");
		}
		List<String> zwcms = cbyjMapper.selectCbmcByEnName(name.replaceAll(" ", ""));
		if (zwcms == null || zwcms.size() == 0) {
			return name;
		} else {
			if (StringUtils.isEmpty(zwcms.get(0))) {
				return name;
			}
			return zwcms.get(0);
		}
	}
}
