package com.huyi.service.common;

import com.huyi.service.base.entity.SysCompany;
import com.huyi.service.base.service.ISysCompanyService;
import com.tianhu.common.core.domain.R;
import com.tianhu.common.core.utils.CommonUtil;
import com.tianhu.common.core.utils.DateUtils;
import com.tianhu.common.core.web.controller.BaseController;
import com.tianhu.common.security.service.TokenService;
import com.tianhu.system.api.domain.SysUser;
import com.tianhu.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;

/**
 * 获取编号及人员信息
 */
@RestController
@RequestMapping("/ownRandom")
public class OwnRandomController extends BaseController
{
    //token
    @Autowired
    private TokenService tokenService;
    //自动生成的企业服务类
    @Autowired
    private ISysCompanyService sysCompanyService;

    /**
     * 获取编号及信息
     * @return
     */
    @GetMapping("/getInfo")
    public R getInfo() {
        //查询当前操作员
        LoginUser userInfo = tokenService.getLoginUser();
        SysUser use = userInfo.getSysUser();
        //获取人员姓名
        String userName = use.getNickName();
        //获取当前时间
        String currentTime = DateUtils.dateTimeNow();
        Map<String,String> map = new HashMap<>();
        //创建人
        map.put("createUserName",userName);
        //创建时间
        map.put("currentTime",DateUtils.getTime());
        //获取当前用户的公司
        String companyId  = use.getCompanyId();
        String companyName = "";
        if(CommonUtil.isNotEmpty(companyId)){
          SysCompany company =  sysCompanyService.getById(companyId);
          if(company != null){
              companyName = company.getScyName();
          }
        }
        map.put("companyName",companyName);
        return R.ok(map);
    }









}
