package com.srs.comprehensive.service.impl;

import java.util.Arrays;
import java.util.List;
import com.srs.common.utils.DateUtils;
import com.srs.comprehensive.domain.SrsAddRecord;
import com.srs.comprehensive.domain.Vo.CphRecord;
import com.srs.comprehensive.mapper.SrsAddRecordMapper;
import com.srs.comprehensive.service.ISrsAddRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.srs.common.utils.SecurityUtils.getUserId;
import static com.srs.common.utils.SecurityUtils.getUsername;

/**
 * 【加分记录】Service业务层处理
 * 
 * @author srs
 * @date 2023-06-20
 */
@Service
public class SrsAddRecordServiceImpl implements ISrsAddRecordService
{
    @Autowired
    private SrsAddRecordMapper srsAddRecordMapper;

    /**
     * 查询【请填写功能名称】
     * 
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public SrsAddRecord selectSrsAddRecordById(Long id)
    {
        return srsAddRecordMapper.selectSrsAddRecordById(id);
    }

    @Override
    public List<CphRecord> listOwnRecord(String stuNo){
        return srsAddRecordMapper.listOwnRecord(stuNo);
    }


    /**
     * 查询【请填写功能名称】列表
     * 
     * @param srsAddRecord 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<SrsAddRecord> selectSrsAddRecordList(SrsAddRecord srsAddRecord)
    {
        return srsAddRecordMapper.selectSrsAddRecordList(srsAddRecord);
    }

    /**
     * 新增【加分记录】
     * 
     * @param srsAddRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertSrsAddRecord(SrsAddRecord srsAddRecord)
    {
        //1:思想品德
//        if (srsAddRecord.getTypeId()==1){
//            srsAddRecord.setAddPointsPerson(getUsername());
//        }
//        //3：第二课堂
//        if (srsAddRecord.getTypeId()==3){
//            String[] split = srsAddRecord.getAddPointsPerson().split(",");//切割学号
//            int number=0;
//            //循环前端传回来的学号
//            for (String i:split){
//                srsAddRecord.setAddPointsPerson(i);
//                srsAddRecord.setApplicant(getUserId());
//                //System.out.println(defaults(srsAddRecord));
//                srsAddRecordMapper.insertSrsAddRecord(defaults(srsAddRecord));
//                number++;
//            }
//            return number;
//        }
//        srsAddRecord.setApplicant(getUserId());
        return srsAddRecordMapper.insertSrsAddRecord(defaults(srsAddRecord));
    }

    //填入默认字段
    public SrsAddRecord defaults(SrsAddRecord srsAddRecord){
        srsAddRecord.setCreateBy(getUsername());
        srsAddRecord.setCreateTime(DateUtils.getNowDate());
        srsAddRecord.setUpdateBy(getUsername());
        srsAddRecord.setUpdateTime(DateUtils.getNowDate());
        return srsAddRecord;
    }

    /**
     * 修改【请填写功能名称】
     * 
     * @param srsAddRecord 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateSrsAddRecord(SrsAddRecord srsAddRecord)
    {
        srsAddRecord.setUpdateBy(getUsername());
        srsAddRecord.setUpdateTime(DateUtils.getNowDate());
        return srsAddRecordMapper.updateSrsAddRecord(srsAddRecord);
    }

    /**
     * 批量删除【请填写功能名称】
     * 
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSrsAddRecordByIds(Long[] ids)
    {
        return srsAddRecordMapper.deleteSrsAddRecordByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     * 
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteSrsAddRecordById(Long id)
    {
        return srsAddRecordMapper.deleteSrsAddRecordById(id);
    }

    /**
     * 修改删除字段
     * @param id
     * @return 结果
     */
    @Override
    public int updateSrsAddRecordDelFlag(Long id) {
        SrsAddRecord srsAddRecord = new SrsAddRecord();
        srsAddRecord.setId(id);
        srsAddRecord.setDelFlag("2");
        return srsAddRecordMapper.updateSrsAddRecord(srsAddRecord);
    }


}
