package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.common.support.util.IdGenerator;
import com.yh.saas.plugin.yiliangyiyun.entity.EnabledInfo;
import com.yh.saas.plugin.yiliangyiyun.mapper.EnabledInfoMapper;
import com.yh.saas.plugin.yiliangyiyun.service.IEnabledInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 记录启用信息 服务实现类
 * </p>
 *
 * @author Gdc
 * @since 2021-12-15
 */
@Service
public class EnabledInfoServiceImpl extends ServiceImpl<EnabledInfoMapper, EnabledInfo> implements IEnabledInfoService {
    /**
     * 添加（编辑）启用信息
     * @param  enabledInfo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String setEnabledInfo(EnabledInfo enabledInfo){
        //判断id是否为空，空是新增
        if(StringUtils.isEmpty(enabledInfo.getId())){
            //新增主键id
            enabledInfo.setId(IdGenerator.generateUUID());
            enabledInfo.setCompId(AuthSecurityUtils.getCurrentUserInfo().getCompId());
            enabledInfo.setStaffId(AuthSecurityUtils.getCurrentUserInfo().getUserId());
            //操作主表数据
            this.insert(enabledInfo);
        }else{
            //有id是修改
            this.updateById(enabledInfo);
        }
        return enabledInfo.getId();
    }
    /**
     * 启用信息查看
     *
     * @param enabledInfo
     * @return
     */
    @Override
    public EnabledInfo getEnabledInfo(EnabledInfo enabledInfo) {
        //根据当前登录用户id查看启用信息
        EnabledInfo enabledInfo1 = this.selectOne(new EntityWrapper<EnabledInfo>()
                .eq("staff_id",AuthSecurityUtils.getCurrentUserInfo().getUserId())
                .eq("comp_id",AuthSecurityUtils.getCurrentUserInfo().getCompId())
                .eq("function_type",enabledInfo.getFunctionType()));
        return enabledInfo1;
    }
}
