package cn.superdesk.uniorder.controller.organisation;

import cn.superdesk.uniorder.common.json.AnJsonUtils;
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.dto.param.organisation.SysOrgQueryParam;
import cn.superdesk.uniorder.dto.vo.sys.SysOrgVo;
import cn.superdesk.uniorder.dto.vo.sys.SysSelectVo;
import cn.superdesk.uniorder.dubbo.consumer.organisation.SysOrganizationDubboConsumerService;
import cn.superdesk.uniorder.common.exception.utils.ExceptionUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@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;
	}

	@ApiOperation(value = "项目数据列表", notes = "项目数据列表")
	@RequestMapping(value = "getOrgList", method = RequestMethod.POST)
	@ResponseBody
	public R<List<SysOrgVo>> getOrgList(@RequestBody @Validated SysOrgQueryParam param) {
		log.info("SysOrganizationController -> SysOrgVo:{}", AnJsonUtils.toJson(param));
		R<List<SysOrgVo>> result = new R<>();
		result = organizationDubboConsumerService.getOrgList(param);
		return result;
	}


	/**
	 * 数据权限-关联项目的查询列表
	 *
	 * 业务方的关联关系  运营商 和 项目存在关系
	 *
	 * 分两种情况 福利商城：通过企业找项目
	 *          服务之窗：直接项目表中
	 */
	@ApiOperation(value = "查询项目下拉列表", notes = "")
	@PostMapping("/selectList")
	@ResponseBody
	public R<List<SysSelectVo>> selectList(@RequestBody  SysOrgQueryParam param) {

		R<List<SysSelectVo>> result = new R<>();
		result.setData(organizationDubboConsumerService.selectList(param));
		return result;
	}
}
