package com.fs.app.controller;


import com.fs.app.annotation.Login;
import com.fs.app.exception.FSException;
import com.fs.app.utils.JwtUtils;
import com.fs.common.config.FSConfig;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.domain.entity.SysUser;
import com.fs.common.core.redis.RedisCache;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.file.FileUploadUtils;
import com.fs.company.domain.CompanyUser;
import com.fs.company.service.ICompanyUserService;
import com.fs.core.config.ServerConfig;
import com.fs.crm.domain.CrmEvent;
import com.fs.crm.service.ICrmCustomerService;
import com.fs.crm.service.ICrmCustomerUserService;
import com.fs.crm.service.ICrmEventService;
import com.fs.crm.service.ICrmMsgService;
import com.fs.store.domain.FsUser;
import com.fs.store.service.IFsUserService;
import com.fs.system.service.ISysConfigService;
import com.fs.system.service.ISysDictDataService;
import com.fs.system.service.ISysUserService;
import com.fs.system.vo.DictVO;
import com.fs.voice.service.IVoiceService;
import com.github.xiaoymin.swaggerbootstrapui.util.CommonUtils;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.TimeUnit;


public class AppBaseController {
	@Autowired
	JwtUtils jwtUtils;
	@Autowired
	RedisCache redisCache;

	@Autowired
	private ICompanyUserService companyUserService;
	@Autowired
	private IFsUserService userService;
	public Long getCompanyId() {
		String headValue =  ServletUtils.getRequest().getHeader("APPToken");
		Claims claims=jwtUtils.getClaimByToken(headValue);
		String userId = claims.getSubject().toString();
		Long companyId =(Long)redisCache.getCacheObject("companyId:"+userId);
		return companyId;
	}
	public String getUserId()
	{
		String headValue =  ServletUtils.getRequest().getHeader("APPToken");
		Claims claims=jwtUtils.getClaimByToken(headValue);
		String userId = claims.getSubject().toString();
		return userId;
	}
	//获取商城手机号
	public Long getUserId(Long companyUserId)
	{
		CompanyUser companyUser=companyUserService.selectCompanyUserById(companyUserId);
		FsUser user=userService.selectFsUserByPhone(companyUser.getPhonenumber());
		if(user==null){
			throw new FSException("未授权,请用员工手机号登录商城");
		}
		return user.getUserId();
	}




}
