package com.jeeplus.centerservice.controller.ccpm;

import cn.hutool.extra.spring.SpringUtil;
import com.jeeplus.aop.demo.annotation.DemoMode;
import com.jeeplus.centerservice.utils.RestTemplateService;
import com.jeeplus.common.TokenProvider;
import com.jeeplus.logging.annotation.ApiLog;
import com.jeeplus.sys.feign.IUserApi;
import com.jeeplus.sys.service.dto.UserDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author: 王强
 * @create: 2023-05-08 11:53
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RestTemplateService restTemplateService;

    @DemoMode
    @ApiLog("修改密码")
    @RequestMapping("savePwd")
    @ApiOperation(value = "修改密码")
    public ResponseEntity savePwd(String newPassword) {
        UserDTO userDTO = SpringUtil.getBean(IUserApi.class).getByToken(TokenProvider.getCurrentToken());
        //调用服务端的修改密码接口
//        User user = new User ( userDTO.getId ( ) );
//        user.setPassword ( SecurityUtils.encryptPassword ( newPassword ) );
//        user.setUpPassword("1"); // 密码修改状态改为”已修改“
//        userService.updateById ( user );
//        UserUtils.deleteCache ( userDTO );
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("name", userDTO.getName());
        paramMap.put("password", newPassword);
        paramMap.put("mobile", userDTO.getMobile());
        String token = "";

        Object res = restTemplateService.getCas("/test/update", token, null);


        return ResponseEntity.ok ( "修改密码成功！" );

    }
}
