TableController.java
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
}
}