package com.xhkjedu.sapi.service.appversion;

import com.xhkjedu.sapi.mapper.appversion.AppMonitorMapper;
import com.xhkjedu.sapi.mapper.system.SchoolMapper;
import com.xhkjedu.sapi.model.appversion.TAppMonitor;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sapi.vo.appversion.AppMonitorPVo;
import com.xhkjedu.sapi.vo.appversion.AppMonitorVo;
import com.xhkjedu.sapi.vo.appversion.AppSearchVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ywx
 * @classname AppMonitorService
 * @description 
 * @date 2020/11/10 16:07
 **/
@Service
public class AppMonitorService {
    @Resource
    private AppMonitorMapper appMonitorMapper;
    @Resource
    private SchoolMapper schoolMapper;

    //添加
    public Integer save(TAppMonitor model) {
        model.setCreatetime(N_Utils.getSecondTimestamp());
        int year = schoolMapper.getYearById(model.getSchoolid());
        model.setYear(year);//保存学校当前学年
        appMonitorMapper.insertUseGeneratedKeys(model);
        return model.getId();
    }

    //按应用统计列表
    public List <AppMonitorVo> listAll(AppSearchVo monitor) {
        return appMonitorMapper.listAll(monitor);
    }

    //按人统计列表
    public List<AppMonitorPVo> listPeople(AppSearchVo monitor, Integer year) {
        return appMonitorMapper.listPeople(monitor, year);
    }

    public Integer getYear(Integer schoolid) {
        return schoolMapper.getYearById(schoolid);
    }
}
