package com.fs.user;

import com.fs.common.constant.HttpStatus;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.R;
import com.fs.common.core.domain.ResponseResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.utils.ServletUtils;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.store.param.h5.FsUserPageListParam;
import com.fs.store.service.IFsUserService;
import com.fs.store.vo.h5.FsUserPageListVO;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

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

    @Autowired
    private IFsUserService fsUserService;

    @Autowired
    private TokenService tokenService;

    @PreAuthorize("@ss.hasPermi('user:fsUser:list')")
    @PostMapping("/list")
    @ApiOperation("会员列表(与移动端使用的相同查询)")
    public TableDataInfo pageList(@RequestBody FsUserPageListParam param) {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId(loginUser.getCompany().getCompanyId());
        param.setPcLoginUserId(loginUser.getUser().getUserId());

        List<FsUserPageListVO> list = fsUserService.selectFsUserPageListNew(param);
        Long total = fsUserService.selectFsUserCount(param);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(list);
        rspData.setTotal(total);
        return rspData;
    }

    @PostMapping("/auditUser")
    @ApiOperation("审核用户（移除小黑屋）")
    public R auditUser(@RequestBody String[] userIds) {
        Boolean r = fsUserService.disabledUser(userIds, true);
        if (r) {
            return R.ok();
        }
        return R.error();
    }


}
