package com.younike.store.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.younike.service.pojo.TAppUser;
import com.younike.service.service.ITAppUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import com.younike.common.bean.APIResult;
import com.younike.common.bean.ResultGenerator;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import com.younike.common.core.page.PageParam;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.OpLog;
import com.younike.common.core.controller.BaseController;
import com.younike.common.constant.BusinessType;

/**
 * app用户Controller
 *
 * @author jiay
 * @date 2022-02-25
 */
@RestController
@RequestMapping("/tAppUser")
public class TAppUserController extends BaseController {
    @Autowired
    private ITAppUserService tAppUserService;

    /**
     * 查询app用户列表
     */
    @RequiresPermissions("user:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<TAppUser> page) {

        return tAppUserService.page(page);
    }


    /**
     * 获取app用户详细信息
     */
    @RequiresPermissions("user:query")
    @GetMapping(value = "/{id}")
    public APIResult getInfo(@PathVariable("id") String id) {
        return ResultGenerator.getSuccessResult(tAppUserService.getById(id));
    }

    /**
     * 新增app用户
     */
    @RequiresPermissions("user:add")
    @OpLog(title = "app用户", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody TAppUser tAppUser) {
        return ResultGenerator.getSuccessResult(tAppUserService.save(tAppUser));
    }

    /**
     * 修改app用户
     */
    @RequiresPermissions("user:edit")
    @OpLog(title = "app用户", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody TAppUser tAppUser) {
        return ResultGenerator.getSuccessResult(tAppUserService.updateById(tAppUser));
    }

    /**
     * 删除app用户
     */
    @RequiresPermissions("user:remove")
    @OpLog(title = "app用户", type = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public APIResult remove(@PathVariable List<String> ids) {
        return ResultGenerator.getSuccessResult(tAppUserService.removeByIds(ids));
    }
}
