package com.pj.project.tb_app;

import java.util.Date;
import java.util.List;

import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service: tb_app -- APK管理
 *
 * @author lbl
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class TbAppService extends ServiceImpl<TbAppMapper, TbApp> implements IService<TbApp> {

    /**
     * 底层 Mapper 对象
     */
    @Autowired
    TbAppMapper tbAppMapper;

    /**
     * 增
     */
    void add(TbApp t) {
        t.setCreateTime(new Date());
        save(t);
    }

    /**
     * 删
     */
    void delete(Long id) {
        removeById(id);
    }

    /**
     * 改
     */
    void update(TbApp t) {
        updateById(t);

    }

    /**
     * 查
     */
    TbApp getById(Long id) {
        return super.getById(id);
    }

    /**
     * 查集合 - 根据条件（参数为空时代表忽略指定条件）
     */
    List<TbApp> getList(SoMap so) {
        return tbAppMapper.getList(so);
    }


    public int updateStatus(Long id, Integer status) {
        TbApp app = super.getById(id);
        if (app == null) {
            return 0;
        }
        app.setStatus(status);
        app.setUpdateTime(new Date());
        return super.updateById(app) ? 1 : 0;
    }

    public TbApp findUpApk() {
        SoMap so = new SoMap();
        so.put("status", 1);
        List<TbApp> list = getList(so);
        if (list!= null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
