package com.storlead.system.controller;

import com.storlead.framework.common.result.Result;
import com.storlead.framework.redis.RedisService;
import com.storlead.system.constant.ReidsCacheConstant;
import com.storlead.system.pojo.entity.SystemPersonalizeSettingEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

@RestController
@RequestMapping("/sys/set")
@Api(tags = "平台中心 - 系统: 系统设置")
public class SystemSettingApiController {

    @Resource
    private RedisService redisService;

    @PostMapping(value = "/orgSyncMode")
    @ApiOperation(value = "组织结构数据同步模式", notes = "组织结构数据同步模式")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = SystemPersonalizeSettingEntity.class)
    })
    public Result orgSyncMode(Integer mode) {
        if (mode == null) {
            mode = 0;
        }
        redisService.setCacheObject(ReidsCacheConstant.SYS_CACHE_ORG_SYNC_MODE,mode);
        return Result.ok();
    }

    @PostMapping(value = "/getOrgSyncMode")
    @ApiOperation(value = "获取组织结构数据同步模式", notes = "获取组织结构数据同步模式")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = SystemPersonalizeSettingEntity.class)
    })
    public Result getOrgSyncMode() {
        Object mode = redisService.getCacheObject(ReidsCacheConstant.SYS_CACHE_ORG_SYNC_MODE);
        if (Objects.isNull(mode)) {
            mode = 0;
        }
        return Result.result(mode);
    }
}
