package org.jeecg.modules.shop.user.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.shop.user.entity.PartnerUser;
import org.jeecg.modules.shop.user.entity.dto.UserInfoDTO;
import org.jeecg.modules.shop.user.entity.dto.UserLoginDTO;
import org.jeecg.modules.shop.user.entity.vo.UserInfoVO;
import org.jeecg.modules.shop.user.entity.vo.UserLoginVO;
import org.jeecg.modules.shop.user.service.IPartnerUserService;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: partner_user
 * @Author: jeecg-boot
 * @Date:   2025-07-09
 * @Version: V1.0
 */
@Api(tags="合作伙伴-合作伙伴用户接口")
@RestController
@RequestMapping("/partner/partnerUser")
@Slf4j
public class PartnerUserController extends JeecgController<PartnerUser, IPartnerUserService> {
	@Autowired
	private IPartnerUserService partnerUserService;

	 @ApiOperation(value = "登录", notes = "登录。<span style='color:red'>注：仅当用户状态为正常时，才会签发token，请注意判断。</span>")
	 @PostMapping(value = "/login")
	 @IgnoreAuth
	 public Result<UserLoginVO> login(@RequestBody @Valid UserLoginDTO loginDTO) {
		 UserLoginVO loginVO = partnerUserService.login(loginDTO);
		 return Result.OK(loginVO);
	 }

	 @ApiOperation(value = "退出登录", notes = "退出登录")
	 @GetMapping(value = "/logout")
	 public Result<?> logout(HttpServletRequest request) {
		 String token = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
		 partnerUserService.logout(token);
		 return Result.OK();
	 }

	 @ApiOperation(value = "查询个人信息", notes = "查询个人信息")
	 @GetMapping(value = "/userinfo")
	 public Result<UserInfoVO> getUserInfo() {
		 return Result.OK(partnerUserService.getUserInfo());
	 }


	 @ApiOperation(value = "更新个人信息", notes = "更新个人信息")
	 @PostMapping(value = "/userinfo")
	 public Result<?> updateUserinfo(@RequestBody @Valid UserInfoDTO dto) {
		 partnerUserService.updateUserInfo(dto);
		 return Result.OK();
	 }
	 @ApiOperation(value = "完善信息", notes = "完善信息")
	 @PostMapping(value = "/submitInfo")
	 public Result<?> submitInfo(@RequestBody @Valid UserInfoDTO dto) {
		 partnerUserService.submitInfo(dto);
		 return Result.OK();
	 }
}
