package com.hs.api.service.Impl;

import com.hs.api.mapper.DicOrgMapper;
import com.hs.api.mapper.SysUserOrgRsMapper;
import com.hs.api.model.DicOrg;
import com.hs.api.model.SerDepartment;
import com.hs.api.model.SysUserOrgRs;
import com.hs.api.service.SysUserOrgRsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysUserOrgRsServiceImpl implements SysUserOrgRsService {
    @Resource
    private SysUserOrgRsMapper sysUserOrgRsMapper;
    @Resource
    private DicOrgMapper orgMapper;
    @Resource
    private DicOrgMapper dicOrgMapper;

    @Override
    public int add(SysUserOrgRs sysUserOrgRs) {
        return sysUserOrgRsMapper.insert(sysUserOrgRs);
    }

    @Override
    public List<SysUserOrgRs> findAll() {
        return sysUserOrgRsMapper.selectAll();
    }

    @Override
    public SysUserOrgRs find(Long id) {
        return sysUserOrgRsMapper.selectByPrimaryKey(id);
    }

    @Override
    public int delete(Long id) {
        return sysUserOrgRsMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int logicDelete(Long id) {
        return 0;
    }

    @Override
    public int update(SysUserOrgRs sysUserRoleRs) {
        return sysUserOrgRsMapper.updateByPrimaryKey(sysUserRoleRs);
    }

    @Override
    public List<SerDepartment> getUserOrg(Long userId, String disease, String date) {
        List<DicOrg> orgList = dicOrgMapper.selectByUser(userId);
        Long orgId = orgList != null && orgList.size() > 0 ? orgList.get(0).getId() : null;
        List<SerDepartment> list = null;
        if (disease != null) {
            list = orgMapper.selectDeptByDisease(userId, orgId, disease, date);
        } else {
            list = orgMapper.selectDeptByUser(userId, orgId);
        }
        return list;
    }

}
