package com.kingtom.shengtai.api.controller;

import java.util.Date;

import com.kingtom.kirin.api.security.SaSecurityUtils;
import com.kingtom.kirin.app.system.model.SystemUser;
import com.kingtom.kirin.app.system.service.ISystemUserService;
import com.kingtom.kirin.core.common.base.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 应用模块名称</p>
 * 代码描述</p>
 * Copyright: Copyright (C) 2024 , Inc. All rights reserved. <p>
 * Company: 成都诚唐科技有限责任公司</p>
 *
 * @author wany
 * @since 2024/1/18
 */
@RestController
@RequestMapping("/system_ext")
@Tag(name = "SystemExtController", description = "系统相关扩展接口。")
public class SystemExtController{

    @Autowired
    private ISystemUserService systemUserService;

    @Operation(summary = "更新用户的uniapp客户端Id")
    @PostMapping("/user/client_info")
    public Result<String> updateUserClientId(@RequestBody String clientId){
        String userId = SaSecurityUtils.findSessionData().getUserId();
        SystemUser update = new SystemUser();
        update.setId(userId);
        update.setExt1(clientId);
        update.setGmtModified(new Date());
        boolean b = systemUserService.updateById(update);
        if(b){
            return Result.ok("操作成功！");
        } else{
            return Result.fail("操作失败！");
        }
    }
    @Operation(summary = "更新用户的uniapp客户端Id")
    @PostMapping("/user/client")
    public Result<String> removeUserClientId(@RequestBody String clientId){
        String userId = SaSecurityUtils.findSessionData().getUserId();
        SystemUser update = new SystemUser();
        update.setId(userId);
        update.setExt1("");
        update.setGmtModified(new Date());
        boolean b = systemUserService.updateById(update);
        if(b){
            return Result.ok("操作成功！");
        } else{
            return Result.fail("操作失败！");
        }
    }

}
