package com.xhkjedu.sstudy.service.bk;

import com.xhkjedu.constant.PlatformConstant;
import com.xhkjedu.sstudy.mapper.bk.TBkMapper;
import com.xhkjedu.sstudy.mapper.system.SchoolMapper;
import com.xhkjedu.sstudy.model.bk.TBk;
import com.xhkjedu.utils.N_Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description：课堂备课
 * @Author: WN
 * @Date: 2024/6/5 10:03:54
 **/
@Slf4j
@Service
public class BkService {
    @Resource
    private TBkMapper bkMapper;
    @Resource
    private SchoolMapper schoolMapper;
    @Resource
    private HttpServletRequest request;


    /*
     * @Description 我的备课列表
     * @Date 2024/6/5 10:22:33
     * @Author WN
     * @Param [bk]
     * @Return java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
     **/
    public List<Map<String,Object>> listBks(TBk bk){
        if(N_Utils.isTrueInteger(bk.getCreateid())){
            return bkMapper.listBks(bk);
        }else{
            log.error("我的备课列表：缺少用户信息！");
            return new ArrayList<>();
        }
    }


    /*
     * @Description 保存我的备课
     * @Date 2024/6/5 10:58:45
     * @Author WN
     * @Param [bk]
     * @Return void
     **/
    public void save(TBk bk){
        Integer createid = request.getIntHeader(PlatformConstant.XH_USER_ID);
        Integer schoolid = schoolMapper.getSchoolIdByUserid(createid);
        Integer timestamp = N_Utils.getSecondTimestamp();
        bk.setCreateid(createid);
        bk.setCreatetime(timestamp);
        bk.setUpdateid(createid);
        bk.setUpdatetime(timestamp);
        bk.setSchoolid(schoolid);

        bkMapper.insert(bk);
    }

    /*
     * @Description 修改我的备课
     * @Date 2024/6/5 11:02:30
     * @Author WN
     * @Param [bk]
     * @Return void
     **/
    public void update(TBk bk){
        Integer timestamp = N_Utils.getSecondTimestamp();
        bk.setUpdateid(timestamp);

        bkMapper.updateByPrimaryKeySelective(bk);
    }

    /*
     * @Description 删除我的备课
     * @Date 2024/6/5 11:03:00
     * @Author WN
     * @Param [bkid]
     * @Return void
     **/
    public void delete(Integer bkid){
        bkMapper.deleteByPrimaryKey(bkid);
    }

    /*
     * @Description 备课详情
     * @Date 2024/6/5 11:03:51
     * @Author WN
     * @Param [bkid]
     * @Return com.xhkjedu.sstudy.model.bk.TBk
     **/
    public TBk detail(Integer bkid){
        return bkMapper.selectByPrimaryKey(bkid);
    }
}
