package com.xhkjedu.sapi.service.appversion;

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

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

/**
 * @author ywx
 * @classname ApppcService
 * @description
 * @date 2021/1/26 11:21
 **/
@Service
public class AppLiveService {
    @Resource
    private AppLiveMapper appLiveMapper;
    @Autowired
    private MessageSender messageSender;

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

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

    //修改
    public Integer update(TAppLive model) {
        return appLiveMapper.updateByPrimaryKeySelective(model);
    }

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

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

    /**
     * 获取最新app版本
     * @Param []
     **/
    public TAppLive getNew() {
        return appLiveMapper.getNew();
    }
}
