zss
2025-02-17 087991c76f078defe5eb55d84223021b4199fb3d
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
package com.yuanchu.mom.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.pojo.DeviceBorrow;
import com.yuanchu.mom.service.DeviceBorrowService;
import com.yuanchu.mom.utils.JackSonUtil;
import com.yuanchu.mom.vo.Result;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 江苏鵷雏网络科技有限公司
 * @since 2024-09-21 10:53:51
 */
@RestController
@RequestMapping("/deviceBorrow")
public class DeviceBorrowController {
 
    @Resource
    private DeviceBorrowService deviceBorrowService;
 
 
    //分页
    @PostMapping("/deviceBorrowPage")
    @ValueAuth
    public Result deviceBorrowPage(@RequestBody Map<String, Object> data) throws Exception {
        Page page = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("page")), Page.class);
        DeviceBorrow deviceBorrow = JackSonUtil.unmarshal(JackSonUtil.marshal(data.get("entity")), DeviceBorrow.class);
        return Result.success(deviceBorrowService.deviceBorrowPage(page, deviceBorrow));
    }
 
    //查询
    @GetMapping("/getDeviceBorrow")
    @ValueAuth
    public Result getDeviceBorrow(Integer id) {
        return Result.success(deviceBorrowService.getDeviceBorrow(id));
    }
 
    //新增
    @PostMapping("/saveDeviceBorrow")
    @ValueAuth
    public Result saveDeviceBorrow(@RequestBody DeviceBorrow deviceBorrow) {
        return Result.success(deviceBorrowService.saveDeviceBorrow(deviceBorrow));
    }
 
    //删除
    @PostMapping("/deleteDeviceBorrow")
    @ValueAuth
    public Result deleteDeviceBorrow(Integer id) {
        return Result.success(deviceBorrowService.removeById(id));
    }
 
    //导出
    @PostMapping("/deviceBorrowExport")
    @ValueAuth
    public Result deviceBorrowExport(@RequestParam("deviceId") Integer deviceId, HttpServletResponse response) throws Exception {
        List<DeviceBorrow> deviceBorrows = deviceBorrowService.getDeviceBorrowBydeviceId(deviceId);
        response.setHeader("requestType", "excel");
        response.setHeader("Access-Control-Expose-Headers", "requestType");
        // 设置单元格样式
        // 保存到第一个sheet中
        EasyExcel.write(response.getOutputStream())
                .head(DeviceBorrow.class)
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) // 自适应列宽
                .sheet()
                .doWrite(deviceBorrows);
        return Result.success();
    }
 
 
}