package com.zcxk.charge.web.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zcxk.charge.core.dao.SystemSettingMapper;
import com.zcxk.charge.core.entity.SystemSetting;
import org.springframework.stereotype.Service;

/**
 * 系统设置服务接口
 *
 * @author yjy
 * @since 2020-11-16
 */
@Service
public class SystemSettingService  extends ServiceImpl<SystemSettingMapper, SystemSetting> {

    /**
     * 根据机构查询单条数据
     *
     * @param companyOrgId 所属公司
     * @param deptOrgId 所属部门
     * @return 单条数据
     */
    public SystemSetting selectSystem(Integer companyOrgId,Integer deptOrgId){
        SystemSetting res=new SystemSetting();
        if(deptOrgId!=null) {
            res = this.getOne(new QueryWrapper<SystemSetting>().eq("DEPT_ORG_ID", deptOrgId));
        } else if(companyOrgId!=null){
            res = this.getOne(new QueryWrapper<SystemSetting>().eq("COMPANY_ORG_ID", companyOrgId));
        }
        return res;
    }
    /**
     * 保存数据
     *
     * @param systemSetting 系统设置信息
     * @return
     */
    public boolean saveSystem(SystemSetting systemSetting) {
        return this.saveOrUpdate(systemSetting);
    }

    /**
     * 根据条件获取id
     *
     * @param companyOrgId 所属公司
     * @param deptOrgId 所属部门
     * @return
     */
    public Integer getId(Integer companyOrgId,Integer deptOrgId) {
        Integer id = null;
        SystemSetting res=new SystemSetting();
        if(deptOrgId != null) {
            res= this.getOne(new QueryWrapper<SystemSetting>().eq("DEPT_ORG_ID",deptOrgId));
        }else if(companyOrgId != null){
            res= this.getOne(new QueryWrapper<SystemSetting>().eq("COMPANY_ORG_ID",companyOrgId));
        }
        if(res != null) {
            id=res.getId();
        }
        return id;
    }



}