liusheng
2024-09-04 9526971c403417c1c007804f24884c443b9e6cd7
smartor/src/main/java/com/smartor/service/impl/PatMedOuthospServiceImpl.java
@@ -1,12 +1,23 @@
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业务层处理
@@ -15,10 +26,13 @@
 * @date 2023-03-04
 */
@Service
public class PatMedOuthospServiceImpl implements IPatMedOuthospService
{
public class PatMedOuthospServiceImpl implements IPatMedOuthospService {
    @Autowired
    private PatMedOuthospMapper patMedOuthospMapper;
    @Autowired
    private SysUserDeptMapper sysUserDeptMapper;
    /**
     * 查询患者门诊记录
@@ -27,8 +41,7 @@
     * @return 患者门诊记录
     */
    @Override
    public PatMedOuthosp selectPatMedOuthospById(Long id)
    {
    public PatMedOuthosp selectPatMedOuthospById(Long id) {
        return patMedOuthospMapper.selectPatMedOuthospById(id);
    }
@@ -39,8 +52,7 @@
     * @return 患者门诊记录
     */
    @Override
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp)
    {
    public List<PatMedOuthosp> selectPatMedOuthospList(PatMedOuthosp patMedOuthosp) {
        return patMedOuthospMapper.selectPatMedOuthospList(patMedOuthosp);
    }
@@ -51,8 +63,7 @@
     * @return 结果
     */
    @Override
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp)
    {
    public int insertPatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        patMedOuthosp.setCreateTime(DateUtils.getNowDate());
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.insertPatMedOuthosp(patMedOuthosp);
@@ -65,8 +76,7 @@
     * @return 结果
     */
    @Override
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp)
    {
    public int updatePatMedOuthosp(PatMedOuthosp patMedOuthosp) {
        patMedOuthosp.setUpdateTime(DateUtils.getNowDate());
        return patMedOuthospMapper.updatePatMedOuthosp(patMedOuthosp);
    }
@@ -78,8 +88,7 @@
     * @return 结果
     */
    @Override
    public int deletePatMedOuthospByIds(Long[] ids)
    {
    public int deletePatMedOuthospByIds(Long[] ids) {
        return patMedOuthospMapper.deletePatMedOuthospByIds(ids);
    }
@@ -90,8 +99,31 @@
     * @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);
    }
}