package cn.superdesk.uniorder.controller.organisation;

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.controller.base.BaseController;
import cn.superdesk.uniorder.dao.entity.organisation.SysOrganization;
import cn.superdesk.uniorder.dubbo.consumer.organisation.SysOrganizationDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import io.swagger.annotations.Api;
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;

@Api(value = "企业信息 -项目企业(数据来源-服务之窗)", tags = {"企业信息 -项目企业(数据来源-服务之窗)"})
@Slf4j
@RestController
@RequestMapping("/organization")
public class SysOrganizationController extends BaseController {


	@Autowired
	private SysOrganizationDubboConsumerService organizationDubboConsumerService;

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

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

		try {

			List<SysOrganization> ls = organizationDubboConsumerService.findByOutOrgName(getString("name"));

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

		} catch (Exception e) {

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

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

		return result;
	}
}
