package com.xhkjedu.sapi.controller.appversion;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.appversion.TAppthirdManager;
import com.xhkjedu.sapi.service.appversion.AppthirdManagerService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
* @author ywx
* @classname TAppthirdManagerController
* @description
* @date 2020/11/11 16:14
**/
@RestController
@RequestMapping("/appthird_manager")
public class AppthirdManagerController {
    @Resource
    private AppthirdManagerService appthirdManagerService;

    @PostMapping("/add")
    @Action("应用白名单-增加")
    public ResultVo add(@RequestBody TAppthirdManager manager) {
        String id = appthirdManagerService.save(manager);
        if (id == null) {
            return new ResultVo(1, "该包名已存在");
        } else {
            return new ResultVo(0, "保存成功", id);
        }
    }

    @PostMapping("/delete")
    @Action("应用白名单-删除")
    public ResultVo delete(@RequestBody TAppthirdManager manager) {
        appthirdManagerService.deleteById(manager.getMid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    @Action("应用白名单-修改")
    public ResultVo update(@RequestBody TAppthirdManager tAppthirdManager) {
        return appthirdManagerService.update(tAppthirdManager);
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody TAppthirdManager manager) {
        Integer page = manager.getPage();
        Integer pageSize = manager.getPageSize();
        N_Utils.validation(new Object[]{page,"显示页码",1,pageSize,"显示条数",1});
        PageHelper.startPage(page, pageSize);
        List<TAppthirdManager> list = appthirdManagerService.listAll(manager);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取应用管理列表成功",pageResult);
    }
}
