xiaoyi
4 天以前 05ab6e3f69a5e73624b2573db043f5923e8f7d8b
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package cn.iocoder.yudao.module.mes.controller.admin.safety;
 
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.controller.admin.safety.vo.material.*;
import cn.iocoder.yudao.module.mes.service.safety.SafetyMaterialService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
 
/**
 * 安全生产 - 应急物资台账与出入库(绝缘用具 / 危化品 / 消防物资)
 *
 * @author 超级管理员
 */
@Tag(name = "管理后台 - 安全生产-应急物资")
@RestController
@RequestMapping("/safety/material")
@Validated
public class SafetyMaterialController {
 
    @Resource
    private SafetyMaterialService materialService;
 
    @PostMapping("/create")
    @Operation(summary = "新增物资")
    @PreAuthorize("@ss.hasPermission('safety:material:create')")
    public CommonResult<Long> create(@Valid @RequestBody SafetyMaterialSaveReqVO reqVO) {
        return success(materialService.createMaterial(reqVO));
    }
 
    @PutMapping("/update")
    @Operation(summary = "修改物资(库存数量只能通过出入库变动)")
    @PreAuthorize("@ss.hasPermission('safety:material:update')")
    public CommonResult<Boolean> update(@Valid @RequestBody SafetyMaterialSaveReqVO reqVO) {
        materialService.updateMaterial(reqVO);
        return success(true);
    }
 
    @DeleteMapping("/delete")
    @Operation(summary = "删除物资")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:material:delete')")
    public CommonResult<Boolean> delete(@RequestParam("id") Long id) {
        materialService.deleteMaterial(id);
        return success(true);
    }
 
    @GetMapping("/get")
    @Operation(summary = "获得物资")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('safety:material:query')")
    public CommonResult<SafetyMaterialRespVO> get(@RequestParam("id") Long id) {
        var material = materialService.getMaterial(id);
        materialService.fillManagers(java.util.List.of(material));
        var resp = BeanUtils.toBean(material, SafetyMaterialRespVO.class);
        SafetyMaterialService.fillMaterialDisplay(material, resp);
        return success(resp);
    }
 
    @GetMapping("/page")
    @Operation(summary = "获得物资分页")
    @PreAuthorize("@ss.hasPermission('safety:material:query')")
    public CommonResult<PageResult<SafetyMaterialRespVO>> page(@Valid SafetyMaterialPageReqVO reqVO) {
        var page = materialService.getMaterialPage(reqVO);
        materialService.fillManagers(page.getList());
        var result = BeanUtils.toBean(page, SafetyMaterialRespVO.class);
        for (int i = 0; i < page.getList().size(); i++) {
            SafetyMaterialService.fillMaterialDisplay(page.getList().get(i), result.getList().get(i));
        }
        return success(result);
    }
 
    @GetMapping("/below-safe-stock")
    @Operation(summary = "获得低于安全库存的物资列表(预警)")
    @PreAuthorize("@ss.hasPermission('safety:material:query')")
    public CommonResult<List<SafetyMaterialRespVO>> belowSafeStock() {
        var materials = materialService.getBelowSafeStockList();
        materialService.fillManagers(materials);
        List<SafetyMaterialRespVO> list = materials.stream()
                .map(material -> {
                    var resp = BeanUtils.toBean(material, SafetyMaterialRespVO.class);
                    SafetyMaterialService.fillMaterialDisplay(material, resp);
                    return resp;
                }).toList();
        return success(list);
    }
 
    @GetMapping("/expiring-list")
    @Operation(summary = "获得即将到期的物资列表(预警)")
    @Parameter(name = "days", description = "提前预警天数,默认 30 天")
    @PreAuthorize("@ss.hasPermission('safety:material:query')")
    public CommonResult<List<SafetyMaterialRespVO>> expiringList(
            @RequestParam(value = "days", required = false) Integer days) {
        var materials = materialService.getExpiringList(days);
        materialService.fillManagers(materials);
        List<SafetyMaterialRespVO> list = materials.stream()
                .map(material -> {
                    var resp = BeanUtils.toBean(material, SafetyMaterialRespVO.class);
                    SafetyMaterialService.fillMaterialDisplay(material, resp);
                    return resp;
                }).toList();
        return success(list);
    }
 
    // ==================== 出入库 ====================
 
    @PostMapping("/stock/create")
    @Operation(summary = "出入库登记(自动更新库存)")
    @PreAuthorize("@ss.hasPermission('safety:material-stock:in') or @ss.hasPermission('safety:material-stock:out')")
    public CommonResult<Long> createStock(@Valid @RequestBody SafetyMaterialStockSaveReqVO reqVO) {
        return success(materialService.createStock(reqVO));
    }
 
    @GetMapping("/stock/page")
    @Operation(summary = "获得出入库流水分页")
    @PreAuthorize("@ss.hasPermission('safety:material-stock:query')")
    public CommonResult<PageResult<SafetyMaterialStockRespVO>> stockPage(
            @Valid SafetyMaterialStockPageReqVO reqVO) {
        var page = materialService.getStockPage(reqVO);
        var result = BeanUtils.toBean(page, SafetyMaterialStockRespVO.class);
        for (int i = 0; i < page.getList().size(); i++) {
            SafetyMaterialService.fillStockDisplay(page.getList().get(i), result.getList().get(i));
        }
        return success(result);
    }
 
}