TableController.java 2.26 KB
package com.huaheng.auth.controller;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.huaheng.auth.form.TableInfo;
import com.huaheng.common.core.constant.CacheConstants;
import com.huaheng.common.core.domain.R;
import com.huaheng.common.log.annotation.Log;
import com.huaheng.common.log.enums.BusinessType;
import com.huaheng.common.redis.service.RedisService;
import com.huaheng.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 *
 */
@RestController
@Api(tags="表格")
@RequestMapping("/table")
public class TableController {

    @Resource
    private RedisService redisService;

    @ApiOperation(value = "表格显示字段保存")
    @PostMapping
    @Log(title = "表格显示字段保存", businessType= BusinessType.INSERT)
    public void save(@RequestBody TableInfo tableInfo) {
        tableInfo.setUserId(SecurityUtils.getUserId());
        tableInfo.setWarehouseCode(SecurityUtils.getWarehouseCode());
        List<String> fieldNames = redisService.getCacheList(CacheConstants.TABLE_VIEW + tableInfo.getUserId() +"_"+ tableInfo.getWarehouseCode()+"_"+ tableInfo.getTableName());
        if (CollectionUtils.isEmpty(fieldNames)) {
            redisService.setCacheObject(CacheConstants.TABLE_VIEW + tableInfo.getUserId() +"_"+ tableInfo.getWarehouseCode()+"_"+ tableInfo.getTableName(), tableInfo.getFieldNames());
        } else {
            redisService.deleteObject(CacheConstants.TABLE_VIEW + tableInfo.getUserId() +"_"+ tableInfo.getWarehouseCode()+"_"+ tableInfo.getTableName());
            redisService.setCacheObject(CacheConstants.TABLE_VIEW + tableInfo.getUserId() +"_"+ tableInfo.getWarehouseCode()+"_"+ tableInfo.getTableName(), tableInfo.getFieldNames());
        }
    }

    @ApiOperation(value = "表格显示字段查询")
    @GetMapping
    @Log(title = "表格显示字段查询", businessType= BusinessType.GRANT)
    public R<?> get(String tableName) {
        List<String> fieldNames = redisService.getCacheObject(CacheConstants.TABLE_VIEW + SecurityUtils.getUserId() +"_"+ SecurityUtils.getWarehouseCode()+"_"+ tableName);
        return  R.ok(fieldNames);
    }
}