package com.xhkjedu.sapi.service.appversion;

import com.xhkjedu.sapi.mapper.appversion.AppthirdManagerMapper;
import com.xhkjedu.sapi.model.appversion.TAppthirdManager;
import com.xhkjedu.sapi.utils.ApiUtil;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.stereotype.Service;

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

/**
 * @author ywx
 * @classname AppthirdManagerService
 * @description
 * @date 2020/11/11 16:24
 **/
@Service
public class AppthirdManagerService {
    @Resource
    private AppthirdManagerMapper appthirdManagerMapper;

    //添加
    public String save(TAppthirdManager model) {
        TAppthirdManager app = appthirdManagerMapper.getByPackage(model.getMpackage(), model.getSchoolid());
        if (app != null) return null;
        String id = ApiUtil.getId();
        model.setMid(id);
        model.setCreatetime(N_Utils.getSecondTimestamp());
        appthirdManagerMapper.insertSelective(model);
        return id;
    }

    //删除
    public Integer deleteById(String id) {
        return appthirdManagerMapper.deleteByPrimaryKey(id);
    }

    //修改
    public ResultVo update(TAppthirdManager model) {
        String mpackage = model.getMpackage();
        if (N_Utils.isNotEmpty(mpackage)) {
            TAppthirdManager app = appthirdManagerMapper.selectByPrimaryKey(model.getMid());
            if (!app.getMpackage().equals(mpackage)) {
                app = appthirdManagerMapper.getByPackage(model.getMpackage(), model.getSchoolid());
                if (app != null) return new ResultVo(1, "该包名已存在");
            }
        }

        appthirdManagerMapper.updateByPrimaryKeySelective(model);
        return new ResultVo(0,"修改成功");
    }

    //获取列表
    public List <TAppthirdManager> listAll(TAppthirdManager manager) {
        return appthirdManagerMapper.listAll(manager);
    }
}
