package org.jeecg.modules.system.app.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.modules.system.app.entity.AppInstructor;
import org.jeecg.modules.system.app.mapper.AppInstructorMapper;
import org.jeecg.modules.system.app.service.IAppInstructorService;
import org.jeecg.modules.system.app.vo.staff.StaffRequestVO;
import org.jeecg.modules.system.app.vo.staff.StaffResponseVO;
import org.jeecg.modules.system.app.vo.staff.StaffVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 教练表
 * @Author: jeecg-boot
 * @Date:   2025-07-04
 * @Version: V1.0
 */
@Service
public class AppInstructorServiceImpl extends ServiceImpl<AppInstructorMapper, AppInstructor> implements IAppInstructorService {

    @Autowired
    AppInstructorMapper appInstructorMapper;



    @Override
    public IPage<StaffResponseVO> findPage(Page<StaffResponseVO> page, StaffRequestVO staffRequestVO,String orgCode) {
        return appInstructorMapper.findPage(page,staffRequestVO,orgCode);
    }

    @Override
    public StaffVO findById(String id) {
        StaffVO staffVO = appInstructorMapper.findByStaffId(id);
        //图片
        List<String> trainingPrograms = new ArrayList<>();
        List<String> honor = new ArrayList<>();
        if (staffVO!=null){

            if (StringUtils.isNotEmpty(staffVO.getTrainingProgramsList())){
                if (staffVO.getTrainingProgramsList().contains(",")){
                    trainingPrograms = Arrays.asList(staffVO.getTrainingProgramsList().split(","));
                }else {
                    trainingPrograms.add(staffVO.getTrainingProgramsList());
                }
            }
            if (StringUtils.isNotEmpty(staffVO.getHonorList())){
                if (staffVO.getHonorList().contains(",")){
                    honor = Arrays.asList(staffVO.getHonorList().split(","));
                }else {
                    honor.add(staffVO.getHonorList());
                }
            }
            staffVO.setTrainingPrograms(trainingPrograms);
            staffVO.setHonor(honor);
        }

        return staffVO;
    }

    @Override
    public Integer updateDelStatus(AppInstructor appInstructor) {
        return appInstructorMapper.updateDelStatus(appInstructor);
    }
}
