package com.openhis.web.appointmentmanage.appservice.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.core.common.core.domain.R;
import com.openhis.appointmentmanage.domain.Dept;
import com.openhis.appointmentmanage.service.IDeptService;
import com.openhis.web.appointmentmanage.appservice.IDeptAppService;
import org.springframework.stereotype.Service;

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

@Service
public class DeptAppServiceImpl implements IDeptAppService {

    @Resource
    private IDeptService deptService;

    @Override
    public R<?> getDeptList() {
        List<Dept> list = deptService.list();
        return R.ok(list);
    }

    @Override
    public R<?> searchDept(Integer pageNo, Integer pageSize, String orgName, String deptName) {
        LambdaQueryWrapper<Dept> wrapper = new LambdaQueryWrapper<>();
        if (orgName != null && ObjectUtil.isNotEmpty(orgName)) {
            wrapper.eq(Dept::getOrgName, orgName);
        }
        if (deptName != null && ObjectUtil.isNotEmpty(deptName)) {
            wrapper.eq(Dept::getDeptName, deptName);
        }
        List<Dept> list = deptService.list(wrapper);
        return R.ok(list);
    }

}
