liujie
2026-01-21 23c5aa9d00a2ba5c69d2b9375b854bed8597e4bf
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
package com.estate.expert.admin.controller.admin;
 
import com.estate.expert.admin.domain.business.screenaccount.*;
import com.estate.expert.admin.domain.user.User;
import com.estate.expert.admin.domain.common.request.BatchReq;
import com.estate.expert.admin.domain.common.request.PageReq;
import com.estate.expert.admin.service.ScreenAccountService;
import com.estate.expert.admin.utils.MD5Utils;
import com.estate.expert.common.domain.Session;
import com.estate.expert.common.rpc.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
 
@Slf4j
@CrossOrigin
@Api(tags = "管理后台/大屏账号")
@RequestMapping("/admin/screen-account")
@RestController
@Validated
public class ScreenAccountController {
 
    @Resource
    private ScreenAccountService screenAccountService;
 
    @ApiOperation(value = "大屏账号列表")
    @PostMapping("/list")
    public Result list(@ApiParam(value = "账号名称") @RequestParam(value = "name", required = false) String name,
                       @ApiParam(value = "关键词") @RequestParam(value = "keyword", required = false) String keyword,
                       @ApiParam(value = "账号类型 1委托方 2项目") @RequestParam(value = "type", required = false) Integer type,
                       @Validated @RequestBody PageReq pageReq) {
        return Result.success(screenAccountService.list(name, keyword, type,pageReq));
    }
 
 
    @ApiOperation(value = "大屏账号详情")
    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable Integer id) {
        ScreenAccount screenAccount = screenAccountService.getById(id);
        if (screenAccount == null) {
            return Result.error("账号不存在");
        }
        ScreenAccountDto vo = new ScreenAccountDto();
        BeanUtils.copyProperties(screenAccount, vo);
        return Result.success(vo);
    }
 
 
    @ApiOperation(value = "新增大屏账号")
    @PostMapping("/add")
    public Result add(@Validated @RequestBody ScreenAccountAddDto dto) {
        if (screenAccountService.existsByAccount(dto.getAccount())) {
            return Result.error("账号已存在");
        }
        ScreenAccount screenAccount = new ScreenAccount();
        BeanUtils.copyProperties(dto, screenAccount);
        screenAccount.setPassword(MD5Utils.encrypt(dto.getPassword()));
        return Result.success(screenAccountService.save(screenAccount));
    }
 
 
    @ApiOperation(value = "编辑大屏账号")
    @PostMapping("/edit")
    public Result edit(@Validated @RequestBody ScreenAccountEditDto dto) {
        ScreenAccount screenAccount = new ScreenAccount();
        BeanUtils.copyProperties(dto, screenAccount);
        return Result.success(screenAccountService.updateById(screenAccount));
    }
 
 
    @ApiOperation(value = "删除大屏账号")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        ScreenAccount screenAccount = screenAccountService.getById(id);
        if (screenAccount == null) {
            return Result.error("账号不存在");
        }
        screenAccount.setDeleted( true);
        screenAccount.setUpdateTime(LocalDateTime.now());
        return Result.success(screenAccountService.updateById(screenAccount));
    }
 
 
    @ApiOperation(value = "启用禁用账号")
    @PostMapping("/enable/{id}")
    public Result enable(@PathVariable Integer id) {
        ScreenAccount screenAccount = screenAccountService.getById(id);
        if (screenAccount == null) {
            return Result.error("账号不存在");
        }
        screenAccount.setState(screenAccount.getState() == 1 ? 2 : 1);
        screenAccount.setUpdateTime(LocalDateTime.now());
        return Result.success(screenAccountService.updateById(screenAccount));
    }
 
    @ApiOperation(value = "重置密码")
    @PostMapping("/resetPassword")
    public Result resetPassword(@Validated @RequestBody ScreenAccountEditPasswordDto dto) {
        ScreenAccount screenAccount = new ScreenAccount();
        BeanUtils.copyProperties(dto, screenAccount);
        screenAccount.setPassword(MD5Utils.encrypt(dto.getPassword()));
        return Result.success(screenAccountService.updateById(screenAccount));
    }
 
 
}