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();
|
}
|
}
|