kimi
2020-05-27 2893347bf72477c4d108e8589a0f61e3e97a990c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.highdatas.mdm.controller;
 
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.mdm.entity.MasterAuthor;
import com.highdatas.mdm.entity.MasterAuthorDetail;
import com.highdatas.mdm.entity.SysField;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.MasterAuthorType;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.*;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2020-03-23
 */
@RestController
@RequestMapping("/masterAuthor/detail")
public class MasterAuthorDetailController {
    @Autowired
    IMasterAuthorService masterAuthorService;
    @Autowired
    IMasterAuthorDetailService masterAuthorDetailService;
    @Autowired
    ISysFieldService fieldService;
    @Autowired
    IMaintainFieldService maintainFieldService;
    @Autowired
    IMenuMappingService menuMappingService;
 
 
    /**
     *
     * @description: 删除一条权限字段id
     * @param id 权限 字段id
     * @param field 字段名称
     * @return 具体数据
     *
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public Result addRole(@PathVariable String id,@RequestParam String field){
        MasterAuthor masterAuthor = masterAuthorService.selectById(id);
        if (masterAuthor == null) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        boolean delete = masterAuthorDetailService.delete(new EntityWrapper<MasterAuthorDetail>()
                .eq(Constant.PARENT_ID, masterAuthor.getId()).eq(Constant.FIELD, field));
        if (delete) {
            return Result.success(CodeMsg.DELETE_SUCCESS);
        }else {
            return Result.error(CodeMsg.DELETE_ERROR);
        }
    }
 
    /**
     *
     * @description: 通过字段版本获取字段list
     * @param id 字段版本
     * @param isGroup 是否为用户组
     * @param type 用户类型
     * @return 字段list
     *
     */
    @RequestMapping(value = "/getFieldByMaintainFieldId/{id}", method = RequestMethod.GET)
    public Result getFieldByMaintainFieldId(@PathVariable String id, @RequestParam boolean isGroup, @RequestParam MasterAuthorType type, @RequestParam String characterId, HttpServletRequest request)  {
        List<SysField> result;
 
        String menuId = request.getParameter("menuId");
        String tableName = menuMappingService.getTableNameByMenu(menuId);
        if (Constant.Default.equalsIgnoreCase(id)) {
            if (StringUtils.isEmpty(tableName)) {
                return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
            }
            result = fieldService.getDefaultTableField(tableName);
        }else if (Constant.All.equalsIgnoreCase(id)) {
            if (StringUtils.isEmpty(tableName)) {
                return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
            }
            result = fieldService.getTotalTableField(tableName);
        }else {
            result = fieldService.getFieldByMaintainField(id);
        }
        JSONObject resultObj = new JSONObject();
        MasterAuthor masterAuthor = masterAuthorService.selectOne(new EntityWrapper<MasterAuthor>()
                .eq(Constant.TYPE, type)
                .eq("user_group", isGroup)
                .eq("table_name", tableName)
                .eq("character_id", characterId)
                .eq("maintain_field_id", id));
 
        if (masterAuthor == null && type.equals(MasterAuthorType.user)) {
            Set<String> roleIdSet;
            if (isGroup) {
                roleIdSet = DbUtils.getRoleByGroup(characterId);
            } else {
                roleIdSet = DbUtils.getRoleByUser(characterId);
            }
            if (roleIdSet == null || roleIdSet.isEmpty()) {
                masterAuthor = null;
            } else {
                HashMap<String, MasterAuthor> tableMasterAuthor = masterAuthorService.merageRoleAuthor(roleIdSet);
                String key = DbUtils.getFieldRedisKey(tableName, id);
                masterAuthor = tableMasterAuthor.get(key);
            }
        }
 
        if (masterAuthor == null) {
 
            resultObj.fluentPut("unchecked", result);
            return  Result.success(resultObj);
        }
        List<MasterAuthorDetail> fields = masterAuthorDetailService.selectList(new EntityWrapper<MasterAuthorDetail>().eq(Constant.PARENT_ID, masterAuthor.getId()));
        if (fields != null) {
            List<String> checkedFieldStrList = fields.stream().map(masterAuthorDetail -> masterAuthorDetail.getField()).collect(Collectors.toList());
            result = result.stream().filter(sysField -> !checkedFieldStrList.contains(sysField.getField())).collect(Collectors.toList());
        }
 
        resultObj.fluentPut("unchecked", result);
        resultObj.fluentPut("checked", fields);
        return Result.success(resultObj);
    }
}