package com.fs.user;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.his.vo.OptionsVO;
import com.fs.store.param.h5.FsUserPageListParam;
import com.fs.store.service.IFsUserService;
import com.fs.store.vo.h5.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.fs.store.vo.h5.FsUserPageListVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "会员管理接口")
@RestController
@RequestMapping("/user/fsUser")
@AllArgsConstructor
public class FsUserAdminController extends BaseController {

    @Autowired
    private IFsUserService fsUserService;

    @PreAuthorize("@ss.hasPermi('user:fsUser:list')")
    @PostMapping("/list")
    @ApiOperation("会员列表(与移动端使用的相同查询)")
    public R pageList(@RequestBody FsUserPageListParam param) {
//        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        TableDataInfo tableDataInfo = fsUserService.selectFsUserPageListNew(param);
//        PageInfo<FsUserPageListVO> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>();
        result.put("rows", tableDataInfo.getRows());
        result.put("total", tableDataInfo.getTotal());
        return R.ok(result);
    }

    /**
     * 根据会员名称模糊查询
     * @param name  名称
     * @return  list
     */
    @GetMapping("/getUserListLikeName")
    public R getUserListLikeName(@RequestParam(required = false) String name,
                                 @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                 @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Map<String,Object> params = new HashMap<>();
        params.put("nickName", name);

        PageHelper.startPage(pageNum, pageSize);
        List<OptionsVO> userList = fsUserService.selectUserListByMap(params);
        return R.ok().put("data", new PageInfo<>(userList));
    }
}
