package org.jeecg.modules.apiService.impl;

import org.jeecg.common.api.vo.Result;
import org.jeecg.config.shiro.ShiroRealm;
import org.jeecg.modules.apiService.CompanyService;
import org.jeecg.modules.employAhthenticationCompany.entity.EmployAhthenticationCompany;
import org.jeecg.modules.employAhthenticationCompany.service.IEmployAhthenticationCompanyService;
import org.jeecg.modules.employCompany.service.IEmployCompanyService;
import org.jeecg.modules.employJob.entity.EmployJob;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;

import javax.annotation.Resource;

public class CompanyServiceImpl implements CompanyService {

    /******************************************************************************************************************/
    //权限验证
    @Resource
    private ShiroRealm shiroRealm;

    //企业实名认证表
    @Resource
    private IEmployAhthenticationCompanyService employAhthenticationCompanyService;

    /******************************************************************************************************************/

    //查看企业信息
    @Override
    public Result<?> queryCompany(String token) {
        String message = "企业信息查询失败";

        try{
            //权限验证
            HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);
            //获取工作详情
            EmployAhthenticationCompany one = employAhthenticationCompanyService
                    .lambdaQuery()
                    .eq(EmployAhthenticationCompany::getUserId, hanHaiMember.getId())
                    .one();

            if(null != one){
                message = "企业信息！";
            }else {
                message = "没有企业信息！";
            }

            return Result.OK(message, one);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(message);
        }
    }

    //修改企业信息
    @Override
    public Result<?> updateCompany(String token, EmployAhthenticationCompany company) {
        String message = "修改企业信息失败！";

        try{
            //权限验证
            HanHaiMember hanHaiMember = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token);

            boolean result = employAhthenticationCompanyService.updateById(company);

            if(result){
                message = "修改企业信息成功！";
            }else {
                message = "修改企业信息失败！";
            }

            return Result.OK(message);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(message);
        }
    }
}
