1
zj
2024-07-29 f6f3df18ea57ea4128fcccf3282e1520e867c631
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
package org.example.controller;
 
import org.example.common.ServerResponse;
import org.example.dao.ConfigCurrencyMapper;
import org.example.pojo.ConfigCurrency;
import org.example.pojo.User;
import org.example.pojo.vo.SaveConfigVo;
import org.example.server.impl.UserServiceImpl;
import org.example.util.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @program: demo
 * @description:
 * @create: 2024-07-29 10:47
 **/
@RestController
@RequestMapping("/user")
public class UserController {
 
    @Autowired
    private ConfigCurrencyMapper currencyMapper;
 
    @Autowired
    private UserServiceImpl userService;
 
    @PostMapping("/saveConfig")
    public ServerResponse saveConfig(SaveConfigVo saveConfigVo) {
        saveConfigVo.getCurrencyList().forEach(f->{
            ConfigCurrency currency = new ConfigCurrency();
            currency.setUserId(saveConfigVo.getUserId());
            currency.setCurrency(f.getCurrency());
            currency.setBuy(f.getBuy());
            currency.setSell(f.getSell());
            currencyMapper.insert(currency);
        });
        return ServerResponse.createBySuccess();
    }
 
    @PostMapping("/saveUser")
    public ServerResponse saveUser(User user) {
        user.setPassword(MD5Util.encrypt(user.getPassword()));
        userService.save(user);
        return ServerResponse.createBySuccess();
    }
 
    @PostMapping("/deleteUser")
    public ServerResponse deleteUser(@RequestParam("id") int id) {
        User byId = userService.getById(id);
        if(null == byId){
            return ServerResponse.createByErrorMsg("用户不存在");
        }
        userService.removeById(id);
        return ServerResponse.createBySuccess();
    }
 
    @PostMapping("/updateUser")
    public ServerResponse deleteUser(User user) {
        User byId = userService.getById(user.getId());
        if(null == byId){
            return ServerResponse.createByErrorMsg("用户不存在");
        }
        user.setPassword(MD5Util.encrypt(user.getPassword()));
        userService.updateById(user);
        return ServerResponse.createBySuccess();
    }
}