package com.ruoyi.web.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.user.service.UserService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/app/user")
@Slf4j
public class AppUserController extends BaseController {

    @Autowired
    private UserService userService;

    @ApiOperation("绑定用户到运营区")
    @PutMapping("/bindArea")
    @Anonymous
    @Log(title = "绑定用户到运营区", businessType = BusinessType.OTHER)
    public AjaxResult bindArea(Long areaId) {
        try {
            Long userId = getUserId();
            return toAjax(userService.updateAreaId(userId, areaId));
        } catch (Exception e) {
            log.error("绑定用户到运营区失败", e);
            return success();
        }
    }

}
