package abacus.springboot.example.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.abacus.xpos.foundation.dao.Dept;
import com.abacus.xpos.foundation.dao.Employee;

import abacus.config.dao.AbacusConfigItem;
import abacus.springboot.example.config.JcConfigKey;
import abacus.springboot.example.dao.JcBill;
import abacus.springboot.example.pi.AutoCompleteAccessIF;

/**
 * <p>
 * Title:AutoCompleteController
 * </p>
 * <p>
 * Description: 前端检索查询-api
 * </p>
 * 
 * @author chuanZeng
 * @date 2022年4月26日
 */
@RestController()
@RequestMapping(value = "/autoComplete")
public class AutoCompleteController extends BaseServlet {

	private static final Logger LOG = LoggerFactory.getLogger(AutoCompleteController.class);

	@Autowired
	private AutoCompleteAccessIF autoCompleteAccess;
	
	/**
	 * 	检索：收货仓库
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Throwable
	 */
	@RequestMapping(value = "abacusConfigItemGroupAutoComplete", method = RequestMethod.POST)
	public List<AbacusConfigItem> abacusConfigItemGroupAutoComplete(@RequestParam(required = false) String keyCode) throws Throwable {
		try {
			List<AbacusConfigItem> objs = this.autoCompleteAccess.abacusConfigItemGroupAutoComplete(keyCode, JcConfigKey.KEY_GROUP, JcConfigKey.KEY_JC_WAREHOUSE);
			return objs;
		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
			e.printStackTrace();
			throw e;
		}
	}
	
	/**
	 * 检索：稽查
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Throwable
	 */
	@RequestMapping(value = "jcBillAutoComplete", method = RequestMethod.POST)
	public List<JcBill> jcBillAutoComplete(@RequestParam(required = false) String keyCode) throws Throwable {
		try {
			List<JcBill> objs = this.autoCompleteAccess.jcBillAutoComplete(keyCode);
			return objs;
		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
			e.printStackTrace();
			throw e;
		}
	}

	/**
	 * 检索：门店
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Throwable
	 */
	@RequestMapping(value = "deptAutoComplete", method = RequestMethod.POST)
	public List<Dept> deptAutoComplete(@RequestParam(required = false) String keyCode,
			@RequestParam(required = false) String type) throws Throwable {
		try {
			List<Dept> objs = this.autoCompleteAccess.deptAutoComplete(keyCode, type);
			return objs;
		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
			e.printStackTrace();
			throw e;
		}
	}
	
	/**
	 * 检索：分销门店
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Throwable
	 */
	@RequestMapping(value = "deptFxAutoComplete", method = RequestMethod.POST)
	public List<Dept> deptFxAutoComplete(@RequestParam(required = false) String keyCode) throws Throwable {
		try {
			List<Dept> objs = this.autoCompleteAccess.deptAutoComplete(keyCode, "17");
			return objs;
		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
			e.printStackTrace();
			throw e;
		}
	}



	/**
	 * 	检索：员工
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Throwable
	 */
	@RequestMapping(value = "employeeAutoComplete", method = RequestMethod.POST)
	public List<Employee> employeeAutoComplete(@RequestParam(required = false) String keyCode) throws Throwable {
		try {
			List<Employee> objs = this.autoCompleteAccess.employeeAutoComplete(keyCode);
			return objs;
		} catch (Throwable e) {
			LOG.error(e.getMessage(), e);
			e.printStackTrace();
			throw e;
		}
	}
}

























