package com.openhis.administration.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.openhis.administration.domain.BodyStructure;
import com.openhis.administration.mapper.BodyStructureMapper;
import com.openhis.administration.service.IBodyStructureService;
import com.openhis.common.enums.PublicationStatus;

/**
 * 身体部位管理Service业务层处理
 *
 * @author liuhr
 * @date 2025-07-22
 */
@Service
public class BodyStructureServiceImpl extends ServiceImpl<BodyStructureMapper, BodyStructure>
    implements IBodyStructureService {

    /**
     * 身体部位启用
     *
     * @param id 身体部位id
     * @return 操作结果
     */
    @Override
    public boolean activeBodyStructure(Long id) {

        int updateCount = baseMapper.update(new BodyStructure().setStatusEnum(PublicationStatus.ACTIVE.getValue()),
            new LambdaUpdateWrapper<BodyStructure>().eq(BodyStructure::getId, id));
        return updateCount > 0;

    }

    /**
     * 身体部位停用
     *
     * @param id 身体部位id
     * @return 操作结果
     */
    @Override
    public boolean inactiveBodyStructure(Long id) {

        int updateCount = baseMapper.update(new BodyStructure().setStatusEnum(PublicationStatus.RETIRED.getValue()),
            new LambdaUpdateWrapper<BodyStructure>().eq(BodyStructure::getId, id));
        return updateCount > 0;
    }

    /**
     * 获取身体部位下拉列表
     *
     * @return 身体部位下拉列表
     */
    @Override
    public List<BodyStructure> getList() {
         return baseMapper.selectList(new LambdaQueryWrapper<BodyStructure>()
         .select(BodyStructure::getId, BodyStructure::getName).eq(BodyStructure::getDeleteFlag, '0'));
  
    }
}