Han Lichun's work on the 21st

Database Design

The database was redesigned according to project requirements, and the table is as follows:
user table:

Field name type of data length Primary key
userid varchar 64 Primary key
name varchar 64
pwd varchar 64
money varchar 64

history table:

Field name type of data length Primary key
userid varchar 64 Foreign key
time datetime
amount decimal 64
operate varchar 128

Description: The
User table is used to manage the user’s id, password, and the user’s balance.
Name is the user’s account.
userid is the user’s id.
Pwd is the user’s password.
Money is the user’s balance.

The History table is used to manage historical records.
Userid is the foreign key of userid in the user table.
Time is the time to record user operations.
Amount is the amount of user operations. Operate
is the user's specific operations such as deposits and withdrawals.

Because there is no name field in the history table, if you want to display the user's name in the background, you have to perform a joint check of two tables:Insert picture description here

Preliminary preparation of some functions of the project background

The project structure is as follows:
Insert picture description here
ums calls the notice microservice code through the server name:

 //notice的url
    public static final String NOTICE_URL="http://NOTICE-SERVICE";

    @Resource
    private RestTemplate restTemplate;

    @ApiOperation(value = "根据userid进行查询历史操作记录", notes = "根据userid进行查询历史操作记录")
    @GetMapping(value="/sel/{userid}")
    public JsonResult follow(@PathVariable String userid ){
    
    

        //推送消息,是调用另一个微服务
        return restTemplate.getForObject(NOTICE_URL+"/api/select/"+userid,JsonResult.class);
    }
    @ApiOperation(value = "根据userid进行存款", notes = "根据userid进行存款")
    @PostMapping(value="/add/{userid}/{money}")
    public JsonResult add(@PathVariable String userid,@PathVariable double money ){
    
    
        User user=new User(userid,money);
        return restTemplate.postForObject(NOTICE_URL+"/api/add/",user, JsonResult.class);
    }
    @ApiOperation(value = "根据userid,money进行取款", notes = "根据userid,money进行取款")
    @PostMapping(value="/subtract/{userid}/{money}")
    public JsonResult sub(@PathVariable String userid,@PathVariable double money ){
    
    
        User user=new User(userid,money);
        return restTemplate.postForObject(NOTICE_URL+"/api/subtract/",user, JsonResult.class);
    }

Notice microservice cluster code:

 @Resource
    private UserSrvImpl userSrv;
    @Resource
    private HistorySrvImpl historySrv;
    @ApiOperation(value = "根据userid,money进行存款", notes = "根据userid,money进行存款")
    @ApiImplicitParam(name = "userid", value = "用户id", required = true, dataType = "String", paramType = "path")
    @PostMapping("/add")

    public JsonResult addMoney(@RequestBody User user) {
    
    
        JsonResult res=new JsonResult(0,"成功");
        userSrv.addMoney(user);
        History history = new History(user.getUserid(), "存款", user.getMoney(), new Date());
        historySrv.insertHistory(history);
        return res;
    }

    @ApiOperation(value = "根据userid,money进行取款", notes = "根据userid,money进行取款")
    @ApiImplicitParam(name = "userid", value = "用户id", required = true, dataType = "String", paramType = "path")
    @PostMapping("/subtract")
    public JsonResult subtractMoney(@RequestBody User user) {
    
    
        JsonResult res=new JsonResult(0,"取款成功");

      User user1=  selMoneyByUserid(user.getUserid());
        if (user.getMoney()>user1.getMoney()){
    
    
            res.setCode(1);
            res.setMsg("账户余额不足");
        }else{
    
    

            userSrv.subtractMoney(user);
            History history = new History(user.getUserid(), "取款", user.getMoney(), new Date());
            historySrv.insertHistory(history);
        }
        return res;
    }
    @ApiOperation(value = "根据userid进行账户余额查询", notes = "根据userid查询余额")
    @ApiImplicitParam(name = "userid", value = "用户id", required = true, dataType = "String", paramType = "path")
    @PostMapping("/selMoneyByUserid/{userid}")
    public User selMoneyByUserid(@PathVariable String userid) {
    
    

        User user = userSrv.selMoneyByUserid(userid);
        return  user;

    }

Guess you like

Origin blog.csdn.net/weixin_42661959/article/details/112976963