skyouc
2024-12-21 c635d78b479510ebe2556a420948effcd30a0731
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
package com.zy.asrs.common.sys.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.common.sys.entity.Host;
import com.zy.asrs.common.sys.service.HostService;
import com.zy.asrs.common.web.BaseController;
import com.zy.asrs.framework.annotations.ManagerAuth;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.sql.Wrapper;
import java.util.*;
 
@RestController
public class HostController extends BaseController {
 
    @Autowired
    private HostService hostService;
 
    @RequestMapping(value = "/host/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") Long id) {
        return R.ok(hostService.getById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/host/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1")Integer curr,
                  @RequestParam(defaultValue = "10")Integer limit,
                  @RequestParam(required = false)String orderByField,
                  @RequestParam(required = false)String orderByType,
                  @RequestParam Map<String, Object> param){
        LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
        return R.ok(hostService.page(new Page<>(curr, limit), wrapper));
    }
 
    @RequestMapping(value = "/host/edit/auth")
    @ManagerAuth
    public R edit(Host host) {
        if (Cools.isEmpty(host)){
            return R.error();
        }
        if (null == host.getId()){
            hostService.save(host);
        } else {
            hostService.updateById(host);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/host/add/auth")
    @ManagerAuth
    public R add(Host host) {
        host.setStatus(1);
        host.setCreateTime(new Date());
        hostService.save(host);
        return R.ok();
    }
 
    @RequestMapping(value = "/host/update/auth")
    @ManagerAuth
    public R update(Host host){
        if (Cools.isEmpty(host) || null==host.getId()){
            return R.error();
        }
        host.setUpdateTime(new Date());
        hostService.updateById(host);
        return R.ok();
    }
 
    @RequestMapping(value = "/host/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value = "ids[]") Integer[] ids) {
        if (Cools.isEmpty(ids)) {
            return R.error();
        }
        hostService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
 
 
    @RequestMapping(value = "/hostQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(Host::getName, condition);
        Page<Host> page = hostService.page(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (Host host : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", host.getId());
            map.put("value", host.getName());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping(value = "/host/delete/one/auth")
    @ManagerAuth
    public R deleteOne(@RequestParam String param){
        if (getUserId() != 9527) {
            if (getUser().getRoleId() != 2) {
                return R.error("权限不足");
            }
        }
        Host host = JSONArray.parseObject(param, Host.class);
        if (Cools.isEmpty(host)){
            return R.error();
        }
        hostService.removeById(host.getId());
        return R.ok();
    }
 
}