package com.kxs.system.biz.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kxs.common.core.constant.enums.ErrorTypeEnum;
import com.kxs.common.core.util.R;
import com.kxs.system.api.model.KxsSchoolStudy;
import com.kxs.system.biz.mapper.KxsMorningMapper;
import com.kxs.system.api.model.KxsMorning;
import com.kxs.system.biz.mapper.KxsSchoolStudyMapper;
import com.kxs.system.biz.service.KxsMorningService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 商学院晨会表(KxsMorning)表服务实现类
 *
 * @author 系统
 * @since 2023-12-15 12:16:31
 */
@Service("kxsMorningService")
@RequiredArgsConstructor
public class KxsMorningServiceImpl extends ServiceImpl<KxsMorningMapper, KxsMorning> implements KxsMorningService {
    private final KxsSchoolStudyMapper kxsSchoolStudyMapper;
    @Override
    public R addStudyPerson(long id, int type) {
        if (type == 1){
            //1为每日晨会
            KxsMorning byId = getById(id);
            if (byId == null){
                return R.failed(ErrorTypeEnum.SYS_MORNING_IS_NULL.getDescription());
            }
            Integer studyPerson = byId.getStudyPerson();
            byId.setStudyPerson(++studyPerson);
            updateById(byId);
        } else if (type == 2) {
            //2为创客学堂
            KxsSchoolStudy kxsSchoolStudy = kxsSchoolStudyMapper.selectById(id);
            if (kxsSchoolStudy == null){
                return R.failed(ErrorTypeEnum.SYS_MORNING_IS_NULL.getDescription());
            }
            Integer studyPerson = kxsSchoolStudy.getStudyPerson();
            kxsSchoolStudy.setStudyPerson(++studyPerson);
            kxsSchoolStudyMapper.updateById(kxsSchoolStudy);
        }else {
            return R.failed(ErrorTypeEnum.SYS_TYPE_ERROR.getDescription());
        }
        return R.ok();
    }
}

