package com.hotent.uc.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hotent.base.manager.impl.BaseManagerImpl;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.StringUtil;
import com.hotent.base.util.UniqueIdUtil;
import com.hotent.uc.dao.OrgExternalDao;
import com.hotent.uc.dao.OrgExternalSettingDao;
import com.hotent.uc.manager.OrgExternalManager;
import com.hotent.uc.manager.OrgExternalSettingManager;
import com.hotent.uc.model.OrgExternalOrg;
import com.hotent.uc.model.OrgExternalSetting;
import com.hotent.uc.params.org.OrgVo;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户与外部通讯录关系表 服务实现类
 *
 * @company 广州宏天软件股份有限公司
 * @author pangquan
 * @since 2020-10-30
 */
@Service
public class OrgExternalOrgManagerImpl extends BaseManagerImpl<OrgExternalDao, OrgExternalOrg> implements OrgExternalManager {


    @Override
    public void addOrEdit(OrgVo org,String demId) {
        LambdaQueryWrapper<OrgExternalOrg> qw=new LambdaQueryWrapper<>();
        qw.eq(OrgExternalOrg::getOrgId,org.getId());
        OrgExternalOrg extOrgTemp=this.baseMapper.selectOne(qw);
        if(extOrgTemp==null){
            extOrgTemp=new OrgExternalOrg();
        }
        extOrgTemp.setUpdateTime(LocalDateTime.now());
        extOrgTemp.setDemId(demId);
        extOrgTemp.setOrgId(org.getId());
        extOrgTemp.setExternalOrgName(org.getName());
        extOrgTemp.setExternalOrgCode(org.getCode());
        extOrgTemp.setOrgExtType(org.getOrgType()+"");
        extOrgTemp.setExternalOrgOrder(org.getOrderNo()+"");
        extOrgTemp.setExtDelete("0");
        extOrgTemp.setOrgExtParentId(org.getParentId());
        this.saveOrUpdate(extOrgTemp);
    }

    @Override
    public void deleteEnti(OrgVo org) {
        LambdaQueryWrapper<OrgExternalOrg> qw=new LambdaQueryWrapper<>();
        qw.eq(OrgExternalOrg::getExternalId,org.getId());
        OrgExternalOrg extOrgTemp=this.baseMapper.selectOne(qw);
        if(extOrgTemp!=null){
            extOrgTemp.setExtDelete("1");
            this.saveOrUpdate(extOrgTemp);
        }
    }
}
