package cn.superdesk.uniorder.controller.sys;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.sys.SysOderUser;
import cn.superdesk.uniorder.dubbo.consumer.sys.SysOderUserDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/orderUser")
public class SysOrderUserController extends BaseController {


	@Autowired
	private SysOderUserDubboConsumerService sysOderUserDubboConsumerService;

	@PostMapping("/findByName")
	@ResponseBody
	public R<List<SysOderUser>> findByName() {

		R<List<SysOderUser>> result = new R<>();

		try {

			List<SysOderUser> ls = sysOderUserDubboConsumerService.findByName(
					getLong("organizationId"),
					getLong("enterpriseId"),
					getString("name")
			);

			result.setSuccess(true);
			result.setData(ls);

		} catch (Exception e) {

			result.setCode(String.valueOf(e.hashCode()));
			result.setSuccess(false);
			result.setMessage("系统查找失败！");

			log.error(ExceptionUtils.getMessage(e));
			e.printStackTrace();
		}

		return result;
	}
}
