liusheng
2024-09-04 9526971c403417c1c007804f24884c443b9e6cd7
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,96 +1,129 @@
package com.smartor.service.impl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUserDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.smartor.domain.PatMedReq;
import com.smartor.domain.PatMedRes;
import com.smartor.mapper.SysUserDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smartor.mapper.PatMedOuthospMapper;
import com.smartor.domain.PatMedOuthosp;
import com.smartor.service.IPatMedOuthospService;
import org.springframework.util.CollectionUtils;
/**
 * 患者门诊记录Service业务层处理
 *
 *
 * @author smartor
 * @date 2023-03-04
 */
@Service
public class PatMedOuthospServiceImpl implements IPatMedOuthospService
{
public class PatMedOuthospServiceImpl implements IPatMedOuthospService {
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private SysUserDeptMapper sysUserDeptMapper;
    /**
     * 查询患者门诊记录
     *
     *
     * @param id 患者门诊记录主键
     * @return 患者门诊记录
     */
    @Override
    public PatMedOuthosp selectPatMedOuthospById(Long id)
    {
    public PatMedOuthosp selectPatMedOuthospById(Long id) {
        return patMedOuthospMapper.selectPatMedOuthospById(id);
    }
    /**
     * 查询患者门诊记录列表
     *
     *
     * @param patMedOuthosp 患者门诊记录
     * @return 患者门诊记录
     */
    @Override
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp)
    {
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
        return patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
    }
    /**
     * 新增患者门诊记录
     *
     *
     * @param patMedOuthosp 患者门诊记录
     * @return 结果
     */
    @Override
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp)
    {
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        patMedOuthosp.setCreateTime(DateUtils.getNowDate());
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
    }
    /**
     * 修改患者门诊记录
     *
     *
     * @param patMedOuthosp 患者门诊记录
     * @return 结果
     */
    @Override
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp)
    {
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
    }
    /**
     * 批量删除患者门诊记录
     *
     *
     * @param ids 需要删除的患者门诊记录主键
     * @return 结果
     */
    @Override
    public int deletePatMedOuthospByIds(Long[] ids)
    {
    public int deletePatMedOuthospByIds(Long[] ids) {
        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
    }
    /**
     * 删除患者门诊记录信息
     *
     *
     * @param id 患者门诊记录主键
     * @return 结果
     */
    @Override
    public int deletePatMedOuthospById(Long id)
    {
    public int deletePatMedOuthospById(Long id) {
        return patMedOuthospMapper.deletePatMedOuthospById(id);
    }
    @Override
    public PatMedRes selectPatMedOuthospCount(PatMedReq patMedReq) {
        // 获取当前登陆人的部门权限
        if (CollectionUtils.isEmpty(patMedReq.getDeptcodeList())) {
            Long userId = SecurityUtils.getUserId();
            List<SysDept> sysDepts = sysUserDeptMapper.selectDeptListByUserId(userId);
            List<String> deptCode = new ArrayList<>();
            for (SysDept sysDept : sysDepts) {
                deptCode.add(sysDept.getDeptId().toString());
            }
            patMedReq.setDeptcodeList(deptCode);
        }
        return patMedOuthospMapper.selectPatMedOuthospCount(patMedReq);
    }
    @Override
    public PatMedOuthosp getDeptCodeByPatId(PatMedOuthosp patMedOuthosp) {
        List<PatMedOuthosp> patMedOuthosps = selectPatMedOuthospList(patMedOuthosp);
        if (!CollectionUtils.isEmpty(patMedOuthosps)) {
            Collections.sort(patMedOuthosps, Comparator.comparing(PatMedOuthosp::getAdmitdate).reversed());
        }
        return patMedOuthosps.get(0);
    }
}