package com.xhkjedu.sapi.service.appversion;

import com.xhkjedu.sapi.listener.MessageSender;
import com.xhkjedu.sapi.mapper.appversion.AppStuappMapper;
import com.xhkjedu.sapi.model.appversion.TAppStuapp;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.sapi.vo.appversion.AppversionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @author ywx
 * @classname AppversionService
 * @description 
 * @date 2020/6/17 13:33
 **/
@Service
public class AppStuappService {
    @Resource
    private AppStuappMapper appStuappMapper;
    @Autowired
    private MessageSender messageSender;

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

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

    //修改
    public Integer update(TAppStuapp model) {
        return appStuappMapper.updateByPrimaryKeySelective(model);
    }

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

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

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

    //获取app终端最新版本列表
    public List<Map> listNews() {
        return appStuappMapper.listNews();
    }
}
