package com.xhkjedu.sapi.service.appversion;

import com.xhkjedu.sapi.listener.MessageSender;
import com.xhkjedu.sapi.mapper.appversion.AppTeacherappMapper;
import com.xhkjedu.sapi.model.appversion.TAppTeacherapp;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sapi.vo.appversion.AppteacherVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author ywx
 * @classname AppteacherService
 * @description 
 * @date 2020/11/27 9:43
 **/
@Service
public class AppTeacherappService {
    @Resource
    private AppTeacherappMapper appTeacherappMapper;
    @Autowired
    private MessageSender messageSender;

    //添加
    public Integer save(TAppTeacherapp model) {
        model.setCreatetime(N_Utils.getSecondTimestamp());
        appTeacherappMapper.insertUseGeneratedKeys(model);
        return model.getId();
    }

    //删除
    public Integer deleteById(Integer versionid) {
        List<String> resourceUrls = appTeacherappMapper.listApppath(versionid);//获取APP文件
        int result = appTeacherappMapper.deleteByPrimaryKey(versionid);
        if(N_Utils.isListNotEmpty(resourceUrls)){
            messageSender.resourceDel(resourceUrls);//给文件服务器发送mq删除文件
        }
        return result;
    }

    //修改
    public Integer update(TAppTeacherapp model) {
        return appTeacherappMapper.updateByPrimaryKeySelective(model);
    }

    //获取详情
    public TAppTeacherapp findById(Integer versionid) {
        return appTeacherappMapper.findById(versionid);
    }

    //获取列表
    public List <AppteacherVo> listAll() {
        return appTeacherappMapper.listAll();
    }

    /**
     * 获取最新app版本
     * @Param []
     * @Author ywx
     * @Date 2020/6/17 13:45
     * @return com.xhkjedu.model.appversion.TAppteacher
     **/
    public TAppTeacherapp getNew() {
        return appTeacherappMapper.getNew();
    }
}
