Helius
2021-06-16 5728be2af515b2200e782aa201ca5d4d67d9ea47
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
package com.ibeetl.admin.console.api;
 
import com.ibeetl.admin.console.model.AppRoleModel;
import com.ibeetl.admin.console.model.PunchChannelModel;
import com.ibeetl.admin.console.service.RedisService;
import com.ibeetl.admin.console.service.XzxUserAuthInfoService;
import com.ibeetl.admin.console.service.XzxUserRoleInfoService;
import com.ibeetl.admin.console.web.query.XzxUserRoleInfoQuery;
import com.ibeetl.admin.core.annotation.Function;
import com.ibeetl.admin.core.entity.XzxUserRoleInfo;
import com.ibeetl.admin.core.util.ConvertUtil;
import com.ibeetl.admin.core.util.ValidateConfig;
import com.ibeetl.admin.core.web.JsonResult;
import com.ibeetl.admin.core.web.dto.FunctionNodeView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.beetl.sql.core.engine.PageQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
 
/**
 * 用户管理
 */
//@Controller
@RestController
@Api(value = "APP管理的接口")
public class AppManagementApi {
 
    private static final String MODEL = "/admin/front/app";
    private final Logger log = LoggerFactory.getLogger(this.getClass());
 
    @Autowired
    RedisService redisService;
    @Autowired
    private XzxUserRoleInfoService xzxUserRoleInfoService;
    @Autowired
    private XzxUserAuthInfoService xzxUserAuthInfoService;
    static SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
    @PostMapping(MODEL + "/appRoleList.do")
    @ResponseBody
    @ApiOperation(value="APP管理-角色管理", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "page", value = "页码", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="query", name = "limit", value = "每页条数", required = true, dataType = "int")
    })
    public JsonResult<PageQuery> appRoleList(@RequestBody XzxUserRoleInfoQuery condtion)
    {
        PageQuery page = condtion.getPageQuery();
        xzxUserRoleInfoService.queryByCondition(page);
        return JsonResult.success(page);
    }
 
    @PostMapping(MODEL + "/tree.json")
    @ResponseBody
    @ApiOperation(value="APP管理-角色管理(构造树型结构列表)", notes="test: 仅0有正确返回")
    public JsonResult<List<FunctionNodeView>> getFunctionTree() {
        List<FunctionNodeView> tree =xzxUserAuthInfoService.buildViewList();
        return JsonResult.success(tree);
    }
 
    @PostMapping(MODEL + "/add.json")
    @ResponseBody
    @ApiOperation(value="APP管理-角色管理(添加角色)", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "authIds", value = "权限ID集合", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "roleName", value = "角色名称", required = true, dataType = "String")
            //@ApiImplicitParam(paramType="query", name = "roleCode", value = "角色短码", required = true, dataType = "String"),
    })
    public JsonResult add(@RequestBody XzxUserRoleInfo xzxUserRoleInfo)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY)-1);
        String dataNow = sdf3.format(calendar.getTime());
        xzxUserRoleInfo.setDelFlag("0");
        xzxUserRoleInfo.setCreateTime(dataNow);
        String[] strs = xzxUserRoleInfo.getAuthIds().split(",");
        StringBuffer buf = new StringBuffer();
        for (String str:strs) {
            if(Integer.parseInt(str)<10000){
                buf.append(str).append(",");
            }
        }
        if(null!=buf.toString()&&!"".equals(buf.toString())){
            String bufStr = buf.toString().substring(0,buf.toString().length()-1);
            xzxUserRoleInfo.setAuthIds(bufStr);
 
        }
        XzxUserRoleInfo roleInfo = xzxUserRoleInfoService.queryMaxAppRole();
        String userType = roleInfo.getRoleCode();
        xzxUserRoleInfo.setRoleCode((Integer.parseInt(userType)+1)+"");
        xzxUserRoleInfoService.save(xzxUserRoleInfo);
        return new JsonResult().success();
    }
 
    @PostMapping(MODEL + "/edit.json")
    @ResponseBody
    @ApiOperation(value="APP管理-角色管理(修改角色)", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "角色表Id", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "authIds", value = "权限ID集合", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "roleName", value = "角色名称", required = true, dataType = "String")
    })
    public JsonResult<String> update(@RequestBody XzxUserRoleInfo xzxUserRoleInfo) {
        XzxUserRoleInfo roleInfo = xzxUserRoleInfoService.queryById(xzxUserRoleInfo.getId());
        Calendar calendar = Calendar.getInstance();
         if(roleInfo==null){
             return JsonResult.failMessage("保存失败");
         }
        if(null!=xzxUserRoleInfo.getAuthIds()){
            String[] strs = xzxUserRoleInfo.getAuthIds().split(",");
            StringBuffer buf = new StringBuffer();
            for (String str:strs) {
                if(Integer.parseInt(str)<10000){
                    buf.append(str).append(",");
                }
            }
            if(null!=buf.toString()&&!"".equals(buf.toString())){
                String bufStr = buf.toString().substring(0,buf.toString().length()-1);
                roleInfo.setAuthIds(bufStr);
            }
            String dataNow = sdf3.format(calendar.getTime());
            roleInfo.setDelFlag("0");
            roleInfo.setUpdateTime(dataNow);
        }
        boolean success = xzxUserRoleInfoService.update(roleInfo);
        if (success) {
            return new JsonResult().success();
        } else {
            return JsonResult.failMessage("保存失败");
        }
    }
 
    @PostMapping(MODEL + "/delete.json")
    @ResponseBody
    @ApiOperation(value="APP管理-角色管理(删除角色)", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "ids", value = "角色表Id集合(多个角色用逗号隔开)", required = true, dataType = "String")
    })
    public JsonResult delete(@RequestBody AppRoleModel model) {
        String ids = model.getIds();
        if (ids.endsWith(",")) {
            ids = StringUtils.substringBeforeLast(ids, ",");
        }
        List<Long> idList = ConvertUtil.str2longs(ids);
        xzxUserRoleInfoService.batchDelXzxUserRoleInfo(idList);
        return new JsonResult().success();
    }
 
    @GetMapping(MODEL + "/view.json")
    @Function("xzxUserRoleInfo")
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "id", value = "角色表Id", required = true, dataType = "String")
    })
    public JsonResult<XzxUserRoleInfo> queryInfo(@RequestBody AppRoleModel model) {
        Long id = model.getId();
        XzxUserRoleInfo xzxUserRoleInfo = xzxUserRoleInfoService.queryById(id);
        return  JsonResult.success(xzxUserRoleInfo);
    }
 
 
    @PostMapping(MODEL + "/queryPunchChannel.do")
    @ResponseBody
    @ApiOperation(value="APP管理-打卡通道", notes="test: 仅0有正确返回")
    public JsonResult<String> queryPunchChannel() {
        String value = xzxUserRoleInfoService.queryPunchChannel();
        return JsonResult.success(value);
    }
 
    @PostMapping(MODEL + "/updatePunchChannel.json")
    @ResponseBody
    @ApiOperation(value="APP管理-打卡通道(保存)", notes="test: 仅0有正确返回")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "status", value = "打卡通道状态(0:打开,1:关闭)", required = true, dataType = "String")
    })
    public JsonResult updatePunchChannel (@RequestBody PunchChannelModel model) {
        xzxUserRoleInfoService.updatePunchChannel(model);
        return new JsonResult().success();
    }
 
 
}