package org.jeecg.modules.system.app.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.system.app.dto.FindPageCUserInfoRequestDTO;
import org.jeecg.modules.system.app.dto.FindPageCUserInfoResponseDTO;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 家庭成员信息表
 * @Author: zx
 * @Date:   2025-07-07
 * @Version: V1.0
 */
@Tag(name="c端用户信息表")
@RestController
@RequestMapping("/cUserInfo")
@Slf4j
public class CUserInfoController {

    @Autowired
    ISysUserService iSysUserService;

    @Operation(summary="家庭成员信息表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<FindPageCUserInfoResponseDTO>> queryPageList(FindPageCUserInfoRequestDTO findPageCUserInfoRequestDTO,
                                                                     @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                                     @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                                     HttpServletRequest req) {
        Subject subject = SecurityUtils.getSubject();
        LoginUser loginUser =null;
        if (subject.isAuthenticated()) {
            // 获取当前登录的用户信息
            loginUser= (LoginUser) subject.getPrincipal();
        }
        if (loginUser==null){
            return Result.error("当前未登录,请先登录;或者未获取到用户信息，请联系管理员");
        }
        findPageCUserInfoRequestDTO.setOrgCode(loginUser.getOrgCode());
        return Result.OK(iSysUserService.findByCUserInfo(pageNo,pageSize,findPageCUserInfoRequestDTO));
    }
}
