package org.springblade.app.controller;

import lombok.RequiredArgsConstructor;
import org.springblade.app.dto.EnterpriseStaffDto;
import org.springblade.core.tool.api.R;

import org.springblade.enterprise.entity.Staff;
import org.springblade.enterprise.feign.IStaffClient;
import org.springblade.enterprise.vo.StaffVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lidexi
 * @date 2021/5/12 15:43
 */
@RequestMapping("/app/login")
@RestController
@RequiredArgsConstructor
public class LoginController {
	private final IStaffClient staffClient;

	@PostMapping("/login")
	public R<StaffVO> login(@RequestBody EnterpriseStaffDto enterpriseStaffDto) {
		Staff searchEntity = new Staff();
		if (enterpriseStaffDto.getLoginType() == 0){//员工登录：根据手机号获取
			searchEntity.setPhone(enterpriseStaffDto.getPhone());
			return R.data(this.staffClient.detail(searchEntity));
		}else if(enterpriseStaffDto.getLoginType() == 1){//企业登录：根据企业id,企业账号，企业密码获取
			searchEntity.setEnterpriseId(enterpriseStaffDto.getEnterpriseId());
			searchEntity.setIsEnterpriseManager(1);
			searchEntity.setEnterpriseAccount(enterpriseStaffDto.getEnterpriseAccount());
			searchEntity.setEnterprisePassword(enterpriseStaffDto.getEnterprisePassword());
			searchEntity.setOpenId(enterpriseStaffDto.getOpenId());
			return R.data(this.staffClient.detail(searchEntity));
		}else if(enterpriseStaffDto.getLoginType() == 2){//管理员登录：根据园区id，园区管理员账号，园区管理员密码获取
			searchEntity.setAgencyId(enterpriseStaffDto.getAgencyId());
			searchEntity.setIsAgencyManager(1);
			searchEntity.setAgencyAccount(enterpriseStaffDto.getAgencyAccount());
			searchEntity.setAgencyPassword(enterpriseStaffDto.getAgencyPassword());
			searchEntity.setOpenId(enterpriseStaffDto.getOpenId());
			return R.data(this.staffClient.detail(searchEntity));
		}
		return R.fail("用户登录类型不存在");
	}
}
