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
package com.hxzk.controller;
 
import com.github.pagehelper.PageInfo;
import com.hxzk.pojo.*;
import com.hxzk.service.CabineDoorService;
import com.hxzk.service.CabinetService;
import com.hxzk.service.FaKaService;
import com.hxzk.udp.Udp_Out;
import com.hxzk.util.SessionManager;
import com.hxzk.util.result;
import com.hxzk.util.resultutil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;
 
@RestController
@RequestMapping("/")
public class CabinetController {
    @Autowired
    CabinetService cabinetService;
    @Autowired
    CabineDoorService cabineDoorService;
    @Autowired
    FaKaService faKaService;
    @Autowired
    SessionManager sessionManager;
 
    @GetMapping("findGuiZi")
    result<List<TbCabinet>> findGuiZi(Integer page, Integer limit){
        PageInfo<TbCabinet> cz= cabinetService.findAll(page, limit);
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
    @PostMapping("addGuiZi")
    public void addGuiZi(TbCabinet cabinet, HttpServletResponse response, HttpServletRequest request) throws IOException {
        TbUser user = sessionManager.getCurrentUser(request);
        Random random = new Random();
        long randomNumber = 1000000000L + (long)(random.nextDouble() * 9000000000L);
        cabinet.setCabinetnum(String.valueOf(randomNumber));
        cabinetService.addGuiZi(cabinet);
        TbFakaji tbFakaji = new TbFakaji();
        for (int i = 1 ; i <=60; i ++){
            tbFakaji.setGuiziid(String.valueOf(randomNumber));
            tbFakaji.setKacaoid(String.valueOf(i));
            faKaService.InsertFaKa(tbFakaji);
        }
        String conent = "添加一个柜子:名称为"+cabinet.getCabinetname();
        SystemLogController.InsertSystemLog(user.getUsername(),conent,gettime());
        response.sendRedirect("/hxzkuwb/HouTai/FaKa/GuiZi.jsp");
    }
 
    public String gettime(){
        Date now = new Date();
        // 创建日期格式化对象,设置格式为 "yyyy-MM-dd HH:mm"
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        // 格式化日期对象,输出字符串结果
        String formattedDate = sdf.format(now);
        return formattedDate;
    }
}