package com.younike.store.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.core.dto.AjaxResult;
import com.younike.common.constant.BusinessType;
import com.younike.service.pojo.AppUser;
import com.younike.service.service.IAppUserService;
import com.younike.common.core.page.TableResult;

/**
 * 商家（员工）用户Controller
 *
 * @author dail
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/appUser")
public class AppUserController extends BaseController {
    @Autowired
    private IAppUserService appUserService;

    /**
     * 查询商家（员工）用户列表
     */
    @RequiresPermissions("user:list")
    @PostMapping("/list")
    public Page list(@RequestBody PageParam<AppUser> page) {

        return appUserService.page(page);
    }


    /**
     * 获取商家（员工）用户详细信息
     */
    @RequiresPermissions("user:query")
    @GetMapping(value = "/{appUserId}")
    public APIResult getInfo(@PathVariable("appUserId") String appUserId) {
        return ResultGenerator.getSuccessResult(appUserService.getById(appUserId));
    }

    /**
     * 新增商家（员工）用户
     */
    @RequiresPermissions("user:add")
    @OpLog(title = "商家（员工）用户", type = BusinessType.INSERT)
    @PostMapping
    public APIResult add(@RequestBody AppUser appUser) {
        return ResultGenerator.getSuccessResult(appUserService.save(appUser));
    }

    /**
     * 修改商家（员工）用户
     */
    @RequiresPermissions("user:edit")
    @OpLog(title = "商家（员工）用户", type = BusinessType.UPDATE)
    @PutMapping
    public APIResult edit(@RequestBody AppUser appUser) {
        return ResultGenerator.getSuccessResult(appUserService.updateById(appUser));
    }

    /**
     * 删除商家（员工）用户
     */
    @RequiresPermissions("user:remove")
    @OpLog(title = "商家（员工）用户", type = BusinessType.DELETE)
    @DeleteMapping("/{appUserIds}")
    public APIResult remove(@PathVariable List<String> appUserIds) {
        return ResultGenerator.getSuccessResult(appUserService.removeByIds(appUserIds));
    }
}
